blob: e84c09e7d2c1270552eab5b1956922de710f7c13 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Re-map IO memory to kernel address space so that we can access it.
3 * This is needed for high PCI addresses that aren't mapped in the
4 * 640k-1MB IO memory area on PC's
5 *
6 * (C) Copyright 1995 1996 Linus Torvalds
7 */
8
Thomas Gleixnere9332ca2008-01-30 13:34:05 +01009#include <linux/bootmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/init.h>
Haavard Skinnemoena148ecf2006-09-30 23:29:17 -070011#include <linux/io.h>
Thomas Gleixner3cbd09e2008-01-30 13:34:05 +010012#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Thomas Gleixner3cbd09e2008-01-30 13:34:05 +010016#include <asm/cacheflush.h>
17#include <asm/e820.h>
18#include <asm/fixmap.h>
19#include <asm/pgtable.h>
20#include <asm/tlbflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Thomas Gleixner240d3a72008-01-30 13:34:05 +010022#ifdef CONFIG_X86_64
23
24unsigned long __phys_addr(unsigned long x)
25{
26 if (x >= __START_KERNEL_map)
27 return x - __START_KERNEL_map + phys_base;
28 return x - PAGE_OFFSET;
29}
30EXPORT_SYMBOL(__phys_addr);
31
32#endif
33
Thomas Gleixner5f5192b2008-01-30 13:34:06 +010034int page_is_ram(unsigned long pagenr)
35{
36 unsigned long addr, end;
37 int i;
38
39 for (i = 0; i < e820.nr_map; i++) {
40 /*
41 * Not usable memory:
42 */
43 if (e820.map[i].type != E820_RAM)
44 continue;
Thomas Gleixner5f5192b2008-01-30 13:34:06 +010045 addr = (e820.map[i].addr + PAGE_SIZE-1) >> PAGE_SHIFT;
46 end = (e820.map[i].addr + e820.map[i].size) >> PAGE_SHIFT;
Thomas Gleixner950f9d92008-01-30 13:34:06 +010047
48 /*
49 * Sanity check: Some BIOSen report areas as RAM that
50 * are not. Notably the 640->1Mb area, which is the
51 * PCI BIOS area.
52 */
53 if (addr >= (BIOS_BEGIN >> PAGE_SHIFT) &&
54 end < (BIOS_END >> PAGE_SHIFT))
55 continue;
56
Thomas Gleixner5f5192b2008-01-30 13:34:06 +010057 if ((pagenr >= addr) && (pagenr < end))
58 return 1;
59 }
60 return 0;
61}
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063/*
Thomas Gleixnere9332ca2008-01-30 13:34:05 +010064 * Fix up the linear direct mapping of the kernel to avoid cache attribute
65 * conflicts.
66 */
67static int ioremap_change_attr(unsigned long phys_addr, unsigned long size,
68 pgprot_t prot)
69{
70 unsigned long npages, vaddr, last_addr = phys_addr + size - 1;
71 int err, level;
72
73 /* No change for pages after the last mapping */
74 if (last_addr >= (max_pfn_mapped << PAGE_SHIFT))
75 return 0;
76
77 npages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
78 vaddr = (unsigned long) __va(phys_addr);
79
80 /*
81 * If there is no identity map for this address,
82 * change_page_attr_addr is unnecessary
83 */
84 if (!lookup_address(vaddr, &level))
85 return 0;
86
87 /*
88 * Must use an address here and not struct page because the
89 * phys addr can be a in hole between nodes and not have a
90 * memmap entry.
91 */
92 err = change_page_attr_addr(vaddr, npages, prot);
Thomas Gleixner240d3a72008-01-30 13:34:05 +010093
Thomas Gleixnere9332ca2008-01-30 13:34:05 +010094 if (!err)
95 global_flush_tlb();
96
97 return err;
98}
99
100/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 * Remap an arbitrary physical address space into the kernel virtual
102 * address space. Needed when the kernel wants to access high addresses
103 * directly.
104 *
105 * NOTE! We need to allow non-page-aligned mappings too: we will obviously
106 * have to convert them into an offset in a page-aligned mapping, but the
107 * caller shouldn't need to know that small detail.
108 */
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100109void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
110 unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100112 void __iomem *addr;
113 struct vm_struct *area;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 unsigned long offset, last_addr;
Thomas Gleixnere9332ca2008-01-30 13:34:05 +0100115 pgprot_t pgprot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 /* Don't allow wraparound or zero size */
118 last_addr = phys_addr + size - 1;
119 if (!size || last_addr < phys_addr)
120 return NULL;
121
122 /*
123 * Don't remap the low PCI/ISA area, it's always mapped..
124 */
125 if (phys_addr >= ISA_START_ADDRESS && last_addr < ISA_END_ADDRESS)
Thomas Gleixner4b40fce2008-01-30 13:34:05 +0100126 return (__force void __iomem *)phys_to_virt(phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 /*
129 * Don't allow anybody to remap normal RAM that we're using..
130 */
Thomas Gleixner266b9f82008-01-30 13:34:06 +0100131 for (offset = phys_addr >> PAGE_SHIFT; offset < max_pfn_mapped &&
132 (offset << PAGE_SHIFT) < last_addr; offset++) {
133 if (page_is_ram(offset))
134 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
136
Thomas Gleixnere9332ca2008-01-30 13:34:05 +0100137 pgprot = MAKE_GLOBAL(__PAGE_KERNEL | flags);
Haavard Skinnemoena148ecf2006-09-30 23:29:17 -0700138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 /*
140 * Mappings have to be page-aligned
141 */
142 offset = phys_addr & ~PAGE_MASK;
143 phys_addr &= PAGE_MASK;
144 size = PAGE_ALIGN(last_addr+1) - phys_addr;
145
146 /*
147 * Ok, go for it..
148 */
Thomas Gleixner74ff2852008-01-30 13:34:05 +0100149 area = get_vm_area(size, VM_IOREMAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 if (!area)
151 return NULL;
152 area->phys_addr = phys_addr;
153 addr = (void __iomem *) area->addr;
Thomas Gleixnere9332ca2008-01-30 13:34:05 +0100154 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
155 phys_addr, pgprot)) {
Thomas Gleixnere4c1b972008-01-30 13:34:05 +0100156 remove_vm_area((void *)(PAGE_MASK & (unsigned long) addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 return NULL;
158 }
Thomas Gleixnere9332ca2008-01-30 13:34:05 +0100159
160 if (ioremap_change_attr(phys_addr, size, pgprot) < 0) {
161 vunmap(addr);
162 return NULL;
163 }
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 return (void __iomem *) (offset + (char __iomem *)addr);
166}
Alexey Dobriyan129f6942005-06-23 00:08:33 -0700167EXPORT_SYMBOL(__ioremap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169/**
170 * ioremap_nocache - map bus memory into CPU space
171 * @offset: bus address of the memory
172 * @size: size of the resource to map
173 *
174 * ioremap_nocache performs a platform specific sequence of operations to
175 * make bus memory CPU accessible via the readb/readw/readl/writeb/
176 * writew/writel functions and the other mmio helpers. The returned
177 * address is not guaranteed to be usable directly as a virtual
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100178 * address.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 *
180 * This version of ioremap ensures that the memory is marked uncachable
181 * on the CPU as well as honouring existing caching rules from things like
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100182 * the PCI bus. Note that there are other caches and buffers on many
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 * busses. In particular driver authors should read up on PCI writes
184 *
185 * It's useful if some control registers are in such an area and
186 * write combining or read caching is not desirable:
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100187 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 * Must be freed with iounmap.
189 */
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100190void __iomem *ioremap_nocache(unsigned long phys_addr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
Thomas Gleixnere9332ca2008-01-30 13:34:05 +0100192 return __ioremap(phys_addr, size, _PAGE_PCD | _PAGE_PWT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}
Alexey Dobriyan129f6942005-06-23 00:08:33 -0700194EXPORT_SYMBOL(ioremap_nocache);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Andi Kleenbf5421c2005-12-12 22:17:09 -0800196/**
197 * iounmap - Free a IO remapping
198 * @addr: virtual address from ioremap_*
199 *
200 * Caller must ensure there is only one unmapping for the same pointer.
201 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202void iounmap(volatile void __iomem *addr)
203{
Andi Kleenbf5421c2005-12-12 22:17:09 -0800204 struct vm_struct *p, *o;
Andrew Mortonc23a4e92005-07-07 17:56:02 -0700205
206 if ((void __force *)addr <= high_memory)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 return;
208
209 /*
210 * __ioremap special-cases the PCI/ISA range by not instantiating a
211 * vm_area and by simply returning an address into the kernel mapping
212 * of ISA space. So handle that here.
213 */
214 if (addr >= phys_to_virt(ISA_START_ADDRESS) &&
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100215 addr < phys_to_virt(ISA_END_ADDRESS))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 return;
217
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100218 addr = (volatile void __iomem *)
219 (PAGE_MASK & (unsigned long __force)addr);
Andi Kleenbf5421c2005-12-12 22:17:09 -0800220
221 /* Use the vm area unlocked, assuming the caller
222 ensures there isn't another iounmap for the same address
223 in parallel. Reuse of the virtual address is prevented by
224 leaving it in the global lists until we're done with it.
225 cpa takes care of the direct mappings. */
226 read_lock(&vmlist_lock);
227 for (p = vmlist; p; p = p->next) {
228 if (p->addr == addr)
229 break;
230 }
231 read_unlock(&vmlist_lock);
232
233 if (!p) {
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100234 printk(KERN_ERR "iounmap: bad address %p\n", addr);
Andrew Mortonc23a4e92005-07-07 17:56:02 -0700235 dump_stack();
Andi Kleenbf5421c2005-12-12 22:17:09 -0800236 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 }
238
Andi Kleenbf5421c2005-12-12 22:17:09 -0800239 /* Reset the direct mapping. Can block */
Thomas Gleixnere9332ca2008-01-30 13:34:05 +0100240 ioremap_change_attr(p->phys_addr, p->size, PAGE_KERNEL);
Andi Kleenbf5421c2005-12-12 22:17:09 -0800241
242 /* Finally remove it */
243 o = remove_vm_area((void *)addr);
244 BUG_ON(p != o || o == NULL);
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100245 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246}
Alexey Dobriyan129f6942005-06-23 00:08:33 -0700247EXPORT_SYMBOL(iounmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Thomas Gleixner240d3a72008-01-30 13:34:05 +0100249#ifdef CONFIG_X86_32
Ingo Molnard18d6d62008-01-30 13:33:45 +0100250
251int __initdata early_ioremap_debug;
252
253static int __init early_ioremap_debug_setup(char *str)
254{
255 early_ioremap_debug = 1;
256
Huang, Ying793b24a2008-01-30 13:33:45 +0100257 return 0;
Ingo Molnard18d6d62008-01-30 13:33:45 +0100258}
Huang, Ying793b24a2008-01-30 13:33:45 +0100259early_param("early_ioremap_debug", early_ioremap_debug_setup);
Ingo Molnard18d6d62008-01-30 13:33:45 +0100260
Huang, Ying0947b2f2008-01-30 13:33:44 +0100261static __initdata int after_paging_init;
262static __initdata unsigned long bm_pte[1024]
263 __attribute__((aligned(PAGE_SIZE)));
264
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100265static inline unsigned long * __init early_ioremap_pgd(unsigned long addr)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100266{
267 return (unsigned long *)swapper_pg_dir + ((addr >> 22) & 1023);
268}
269
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100270static inline unsigned long * __init early_ioremap_pte(unsigned long addr)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100271{
272 return bm_pte + ((addr >> PAGE_SHIFT) & 1023);
273}
274
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100275void __init early_ioremap_init(void)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100276{
277 unsigned long *pgd;
278
Ingo Molnard18d6d62008-01-30 13:33:45 +0100279 if (early_ioremap_debug)
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100280 printk(KERN_DEBUG "early_ioremap_init()\n");
Ingo Molnard18d6d62008-01-30 13:33:45 +0100281
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100282 pgd = early_ioremap_pgd(fix_to_virt(FIX_BTMAP_BEGIN));
Huang, Ying0947b2f2008-01-30 13:33:44 +0100283 *pgd = __pa(bm_pte) | _PAGE_TABLE;
284 memset(bm_pte, 0, sizeof(bm_pte));
Ingo Molnar0e3a9542008-01-30 13:33:49 +0100285 /*
286 * The boot-ioremap range spans multiple pgds, for which
287 * we are not prepared:
288 */
289 if (pgd != early_ioremap_pgd(fix_to_virt(FIX_BTMAP_END))) {
290 WARN_ON(1);
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100291 printk(KERN_WARNING "pgd %p != %p\n",
292 pgd, early_ioremap_pgd(fix_to_virt(FIX_BTMAP_END)));
293 printk(KERN_WARNING "fix_to_virt(FIX_BTMAP_BEGIN): %08lx\n",
294 fix_to_virt(FIX_BTMAP_BEGIN));
295 printk(KERN_WARNING "fix_to_virt(FIX_BTMAP_END): %08lx\n",
296 fix_to_virt(FIX_BTMAP_END));
Ingo Molnar0e3a9542008-01-30 13:33:49 +0100297
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100298 printk(KERN_WARNING "FIX_BTMAP_END: %d\n", FIX_BTMAP_END);
299 printk(KERN_WARNING "FIX_BTMAP_BEGIN: %d\n",
300 FIX_BTMAP_BEGIN);
Ingo Molnar0e3a9542008-01-30 13:33:49 +0100301 }
Huang, Ying0947b2f2008-01-30 13:33:44 +0100302}
303
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100304void __init early_ioremap_clear(void)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100305{
306 unsigned long *pgd;
307
Ingo Molnard18d6d62008-01-30 13:33:45 +0100308 if (early_ioremap_debug)
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100309 printk(KERN_DEBUG "early_ioremap_clear()\n");
Ingo Molnard18d6d62008-01-30 13:33:45 +0100310
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100311 pgd = early_ioremap_pgd(fix_to_virt(FIX_BTMAP_BEGIN));
Huang, Ying0947b2f2008-01-30 13:33:44 +0100312 *pgd = 0;
313 __flush_tlb_all();
314}
315
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100316void __init early_ioremap_reset(void)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100317{
318 enum fixed_addresses idx;
319 unsigned long *pte, phys, addr;
320
321 after_paging_init = 1;
Huang, Ying64a8f852008-01-30 13:33:44 +0100322 for (idx = FIX_BTMAP_BEGIN; idx >= FIX_BTMAP_END; idx--) {
Huang, Ying0947b2f2008-01-30 13:33:44 +0100323 addr = fix_to_virt(idx);
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100324 pte = early_ioremap_pte(addr);
Huang, Ying0947b2f2008-01-30 13:33:44 +0100325 if (!*pte & _PAGE_PRESENT) {
326 phys = *pte & PAGE_MASK;
327 set_fixmap(idx, phys);
328 }
329 }
330}
331
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100332static void __init __early_set_fixmap(enum fixed_addresses idx,
Huang, Ying0947b2f2008-01-30 13:33:44 +0100333 unsigned long phys, pgprot_t flags)
334{
335 unsigned long *pte, addr = __fix_to_virt(idx);
336
337 if (idx >= __end_of_fixed_addresses) {
338 BUG();
339 return;
340 }
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100341 pte = early_ioremap_pte(addr);
Huang, Ying0947b2f2008-01-30 13:33:44 +0100342 if (pgprot_val(flags))
343 *pte = (phys & PAGE_MASK) | pgprot_val(flags);
344 else
345 *pte = 0;
346 __flush_tlb_one(addr);
347}
348
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100349static inline void __init early_set_fixmap(enum fixed_addresses idx,
Huang, Ying0947b2f2008-01-30 13:33:44 +0100350 unsigned long phys)
351{
352 if (after_paging_init)
353 set_fixmap(idx, phys);
354 else
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100355 __early_set_fixmap(idx, phys, PAGE_KERNEL);
Huang, Ying0947b2f2008-01-30 13:33:44 +0100356}
357
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100358static inline void __init early_clear_fixmap(enum fixed_addresses idx)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100359{
360 if (after_paging_init)
361 clear_fixmap(idx);
362 else
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100363 __early_set_fixmap(idx, 0, __pgprot(0));
Huang, Ying0947b2f2008-01-30 13:33:44 +0100364}
365
Ingo Molnar1b42f512008-01-30 13:33:45 +0100366
367int __initdata early_ioremap_nested;
368
Ingo Molnard690b2a2008-01-30 13:33:47 +0100369static int __init check_early_ioremap_leak(void)
370{
371 if (!early_ioremap_nested)
372 return 0;
373
374 printk(KERN_WARNING
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100375 "Debug warning: early ioremap leak of %d areas detected.\n",
376 early_ioremap_nested);
Ingo Molnard690b2a2008-01-30 13:33:47 +0100377 printk(KERN_WARNING
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100378 "please boot with early_ioremap_debug and report the dmesg.\n");
Ingo Molnard690b2a2008-01-30 13:33:47 +0100379 WARN_ON(1);
380
381 return 1;
382}
383late_initcall(check_early_ioremap_leak);
384
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100385void __init *early_ioremap(unsigned long phys_addr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
387 unsigned long offset, last_addr;
Ingo Molnar1b42f512008-01-30 13:33:45 +0100388 unsigned int nrpages, nesting;
389 enum fixed_addresses idx0, idx;
390
391 WARN_ON(system_state != SYSTEM_BOOTING);
392
393 nesting = early_ioremap_nested;
Ingo Molnard18d6d62008-01-30 13:33:45 +0100394 if (early_ioremap_debug) {
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100395 printk(KERN_DEBUG "early_ioremap(%08lx, %08lx) [%d] => ",
396 phys_addr, size, nesting);
Ingo Molnard18d6d62008-01-30 13:33:45 +0100397 dump_stack();
398 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 /* Don't allow wraparound or zero size */
401 last_addr = phys_addr + size - 1;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100402 if (!size || last_addr < phys_addr) {
403 WARN_ON(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 return NULL;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100405 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100407 if (nesting >= FIX_BTMAPS_NESTING) {
408 WARN_ON(1);
Ingo Molnar1b42f512008-01-30 13:33:45 +0100409 return NULL;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100410 }
Ingo Molnar1b42f512008-01-30 13:33:45 +0100411 early_ioremap_nested++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 /*
413 * Mappings have to be page-aligned
414 */
415 offset = phys_addr & ~PAGE_MASK;
416 phys_addr &= PAGE_MASK;
417 size = PAGE_ALIGN(last_addr) - phys_addr;
418
419 /*
420 * Mappings have to fit in the FIX_BTMAP area.
421 */
422 nrpages = size >> PAGE_SHIFT;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100423 if (nrpages > NR_FIX_BTMAPS) {
424 WARN_ON(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 return NULL;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
428 /*
429 * Ok, go for it..
430 */
Ingo Molnar1b42f512008-01-30 13:33:45 +0100431 idx0 = FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*nesting;
432 idx = idx0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 while (nrpages > 0) {
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100434 early_set_fixmap(idx, phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 phys_addr += PAGE_SIZE;
436 --idx;
437 --nrpages;
438 }
Ingo Molnard18d6d62008-01-30 13:33:45 +0100439 if (early_ioremap_debug)
440 printk(KERN_CONT "%08lx + %08lx\n", offset, fix_to_virt(idx0));
Ingo Molnar1b42f512008-01-30 13:33:45 +0100441
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100442 return (void *) (offset + fix_to_virt(idx0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443}
444
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100445void __init early_iounmap(void *addr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
447 unsigned long virt_addr;
448 unsigned long offset;
449 unsigned int nrpages;
450 enum fixed_addresses idx;
Ingo Molnar1b42f512008-01-30 13:33:45 +0100451 unsigned int nesting;
452
453 nesting = --early_ioremap_nested;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100454 WARN_ON(nesting < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Ingo Molnard18d6d62008-01-30 13:33:45 +0100456 if (early_ioremap_debug) {
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100457 printk(KERN_DEBUG "early_iounmap(%p, %08lx) [%d]\n", addr,
458 size, nesting);
Ingo Molnard18d6d62008-01-30 13:33:45 +0100459 dump_stack();
460 }
461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 virt_addr = (unsigned long)addr;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100463 if (virt_addr < fix_to_virt(FIX_BTMAP_BEGIN)) {
464 WARN_ON(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 return;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 offset = virt_addr & ~PAGE_MASK;
468 nrpages = PAGE_ALIGN(offset + size - 1) >> PAGE_SHIFT;
469
Ingo Molnar1b42f512008-01-30 13:33:45 +0100470 idx = FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*nesting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 while (nrpages > 0) {
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100472 early_clear_fixmap(idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 --idx;
474 --nrpages;
475 }
476}
Ingo Molnar1b42f512008-01-30 13:33:45 +0100477
478void __this_fixmap_does_not_exist(void)
479{
480 WARN_ON(1);
481}
Thomas Gleixner240d3a72008-01-30 13:34:05 +0100482
483#endif /* CONFIG_X86_32 */