blob: 213ace58a188bb3f4b5c71df151d94f891f6be70 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/init.h>
Haavard Skinnemoena148ecf2006-09-30 23:29:17 -070010#include <linux/io.h>
Thomas Gleixner3cbd09e2008-01-30 13:34:05 +010011#include <linux/module.h>
12#include <linux/slab.h>
13#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Thomas Gleixner3cbd09e2008-01-30 13:34:05 +010015#include <asm/cacheflush.h>
16#include <asm/e820.h>
17#include <asm/fixmap.h>
18#include <asm/pgtable.h>
19#include <asm/tlbflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 * Remap an arbitrary physical address space into the kernel virtual
23 * address space. Needed when the kernel wants to access high addresses
24 * directly.
25 *
26 * NOTE! We need to allow non-page-aligned mappings too: we will obviously
27 * have to convert them into an offset in a page-aligned mapping, but the
28 * caller shouldn't need to know that small detail.
29 */
Thomas Gleixner91eebf42008-01-30 13:34:05 +010030void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
31 unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Thomas Gleixner91eebf42008-01-30 13:34:05 +010033 void __iomem *addr;
34 struct vm_struct *area;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 unsigned long offset, last_addr;
Haavard Skinnemoena148ecf2006-09-30 23:29:17 -070036 pgprot_t prot;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38 /* Don't allow wraparound or zero size */
39 last_addr = phys_addr + size - 1;
40 if (!size || last_addr < phys_addr)
41 return NULL;
42
43 /*
44 * Don't remap the low PCI/ISA area, it's always mapped..
45 */
46 if (phys_addr >= ISA_START_ADDRESS && last_addr < ISA_END_ADDRESS)
47 return (void __iomem *) phys_to_virt(phys_addr);
48
49 /*
50 * Don't allow anybody to remap normal RAM that we're using..
51 */
52 if (phys_addr <= virt_to_phys(high_memory - 1)) {
53 char *t_addr, *t_end;
54 struct page *page;
55
56 t_addr = __va(phys_addr);
57 t_end = t_addr + (size - 1);
Thomas Gleixner91eebf42008-01-30 13:34:05 +010058
59 for (page = virt_to_page(t_addr);
60 page <= virt_to_page(t_end); page++)
61 if (!PageReserved(page))
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 return NULL;
63 }
64
Thomas Gleixnera4034342008-01-30 13:34:04 +010065 prot = MAKE_GLOBAL(__PAGE_KERNEL | flags);
Haavard Skinnemoena148ecf2006-09-30 23:29:17 -070066
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 /*
68 * Mappings have to be page-aligned
69 */
70 offset = phys_addr & ~PAGE_MASK;
71 phys_addr &= PAGE_MASK;
72 size = PAGE_ALIGN(last_addr+1) - phys_addr;
73
74 /*
75 * Ok, go for it..
76 */
Thomas Gleixner74ff2852008-01-30 13:34:05 +010077 area = get_vm_area(size, VM_IOREMAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 if (!area)
79 return NULL;
80 area->phys_addr = phys_addr;
81 addr = (void __iomem *) area->addr;
82 if (ioremap_page_range((unsigned long) addr,
Thomas Gleixner91eebf42008-01-30 13:34:05 +010083 (unsigned long) addr + size, phys_addr, prot)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 vunmap((void __force *) addr);
85 return NULL;
86 }
87 return (void __iomem *) (offset + (char __iomem *)addr);
88}
Alexey Dobriyan129f6942005-06-23 00:08:33 -070089EXPORT_SYMBOL(__ioremap);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91/**
92 * ioremap_nocache - map bus memory into CPU space
93 * @offset: bus address of the memory
94 * @size: size of the resource to map
95 *
96 * ioremap_nocache performs a platform specific sequence of operations to
97 * make bus memory CPU accessible via the readb/readw/readl/writeb/
98 * writew/writel functions and the other mmio helpers. The returned
99 * address is not guaranteed to be usable directly as a virtual
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100100 * address.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 *
102 * This version of ioremap ensures that the memory is marked uncachable
103 * on the CPU as well as honouring existing caching rules from things like
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100104 * the PCI bus. Note that there are other caches and buffers on many
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 * busses. In particular driver authors should read up on PCI writes
106 *
107 * It's useful if some control registers are in such an area and
108 * write combining or read caching is not desirable:
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100109 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 * Must be freed with iounmap.
111 */
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100112void __iomem *ioremap_nocache(unsigned long phys_addr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
114 unsigned long last_addr;
Siddha, Suresh B4138cc32008-01-30 13:33:43 +0100115 void __iomem *p = __ioremap(phys_addr, size, _PAGE_PCD | _PAGE_PWT);
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100116
117 if (!p)
118 return p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120 /* Guaranteed to be > phys_addr, as per __ioremap() */
121 last_addr = phys_addr + size - 1;
122
123 if (last_addr < virt_to_phys(high_memory) - 1) {
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100124 struct page *ppage = virt_to_page(__va(phys_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 unsigned long npages;
126
127 phys_addr &= PAGE_MASK;
128
129 /* This might overflow and become zero.. */
130 last_addr = PAGE_ALIGN(last_addr);
131
132 /* .. but that's ok, because modulo-2**n arithmetic will make
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100133 * the page-aligned "last - first" come out right.
134 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 npages = (last_addr - phys_addr) >> PAGE_SHIFT;
136
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100137 if (change_page_attr(ppage, npages, PAGE_KERNEL_NOCACHE) < 0) {
138 iounmap(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 p = NULL;
140 }
141 global_flush_tlb();
142 }
143
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100144 return p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
Alexey Dobriyan129f6942005-06-23 00:08:33 -0700146EXPORT_SYMBOL(ioremap_nocache);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Andi Kleenbf5421c2005-12-12 22:17:09 -0800148/**
149 * iounmap - Free a IO remapping
150 * @addr: virtual address from ioremap_*
151 *
152 * Caller must ensure there is only one unmapping for the same pointer.
153 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154void iounmap(volatile void __iomem *addr)
155{
Andi Kleenbf5421c2005-12-12 22:17:09 -0800156 struct vm_struct *p, *o;
Andrew Mortonc23a4e962005-07-07 17:56:02 -0700157
158 if ((void __force *)addr <= high_memory)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 return;
160
161 /*
162 * __ioremap special-cases the PCI/ISA range by not instantiating a
163 * vm_area and by simply returning an address into the kernel mapping
164 * of ISA space. So handle that here.
165 */
166 if (addr >= phys_to_virt(ISA_START_ADDRESS) &&
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100167 addr < phys_to_virt(ISA_END_ADDRESS))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return;
169
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100170 addr = (volatile void __iomem *)
171 (PAGE_MASK & (unsigned long __force)addr);
Andi Kleenbf5421c2005-12-12 22:17:09 -0800172
173 /* Use the vm area unlocked, assuming the caller
174 ensures there isn't another iounmap for the same address
175 in parallel. Reuse of the virtual address is prevented by
176 leaving it in the global lists until we're done with it.
177 cpa takes care of the direct mappings. */
178 read_lock(&vmlist_lock);
179 for (p = vmlist; p; p = p->next) {
180 if (p->addr == addr)
181 break;
182 }
183 read_unlock(&vmlist_lock);
184
185 if (!p) {
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100186 printk(KERN_ERR "iounmap: bad address %p\n", addr);
Andrew Mortonc23a4e962005-07-07 17:56:02 -0700187 dump_stack();
Andi Kleenbf5421c2005-12-12 22:17:09 -0800188 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 }
190
Andi Kleenbf5421c2005-12-12 22:17:09 -0800191 /* Reset the direct mapping. Can block */
Thomas Gleixner74ff2852008-01-30 13:34:05 +0100192 if (p->phys_addr < virt_to_phys(high_memory) - 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 change_page_attr(virt_to_page(__va(p->phys_addr)),
Jeremy Fitzhardinge95851162007-07-21 17:11:35 +0200194 get_vm_area_size(p) >> PAGE_SHIFT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 PAGE_KERNEL);
196 global_flush_tlb();
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100197 }
Andi Kleenbf5421c2005-12-12 22:17:09 -0800198
199 /* Finally remove it */
200 o = remove_vm_area((void *)addr);
201 BUG_ON(p != o || o == NULL);
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100202 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203}
Alexey Dobriyan129f6942005-06-23 00:08:33 -0700204EXPORT_SYMBOL(iounmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Ingo Molnard18d6d62008-01-30 13:33:45 +0100206
207int __initdata early_ioremap_debug;
208
209static int __init early_ioremap_debug_setup(char *str)
210{
211 early_ioremap_debug = 1;
212
Huang, Ying793b24a2008-01-30 13:33:45 +0100213 return 0;
Ingo Molnard18d6d62008-01-30 13:33:45 +0100214}
Huang, Ying793b24a2008-01-30 13:33:45 +0100215early_param("early_ioremap_debug", early_ioremap_debug_setup);
Ingo Molnard18d6d62008-01-30 13:33:45 +0100216
Huang, Ying0947b2f2008-01-30 13:33:44 +0100217static __initdata int after_paging_init;
218static __initdata unsigned long bm_pte[1024]
219 __attribute__((aligned(PAGE_SIZE)));
220
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100221static inline unsigned long * __init early_ioremap_pgd(unsigned long addr)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100222{
223 return (unsigned long *)swapper_pg_dir + ((addr >> 22) & 1023);
224}
225
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100226static inline unsigned long * __init early_ioremap_pte(unsigned long addr)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100227{
228 return bm_pte + ((addr >> PAGE_SHIFT) & 1023);
229}
230
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100231void __init early_ioremap_init(void)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100232{
233 unsigned long *pgd;
234
Ingo Molnard18d6d62008-01-30 13:33:45 +0100235 if (early_ioremap_debug)
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100236 printk(KERN_DEBUG "early_ioremap_init()\n");
Ingo Molnard18d6d62008-01-30 13:33:45 +0100237
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100238 pgd = early_ioremap_pgd(fix_to_virt(FIX_BTMAP_BEGIN));
Huang, Ying0947b2f2008-01-30 13:33:44 +0100239 *pgd = __pa(bm_pte) | _PAGE_TABLE;
240 memset(bm_pte, 0, sizeof(bm_pte));
Ingo Molnar0e3a9542008-01-30 13:33:49 +0100241 /*
242 * The boot-ioremap range spans multiple pgds, for which
243 * we are not prepared:
244 */
245 if (pgd != early_ioremap_pgd(fix_to_virt(FIX_BTMAP_END))) {
246 WARN_ON(1);
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100247 printk(KERN_WARNING "pgd %p != %p\n",
248 pgd, early_ioremap_pgd(fix_to_virt(FIX_BTMAP_END)));
249 printk(KERN_WARNING "fix_to_virt(FIX_BTMAP_BEGIN): %08lx\n",
250 fix_to_virt(FIX_BTMAP_BEGIN));
251 printk(KERN_WARNING "fix_to_virt(FIX_BTMAP_END): %08lx\n",
252 fix_to_virt(FIX_BTMAP_END));
Ingo Molnar0e3a9542008-01-30 13:33:49 +0100253
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100254 printk(KERN_WARNING "FIX_BTMAP_END: %d\n", FIX_BTMAP_END);
255 printk(KERN_WARNING "FIX_BTMAP_BEGIN: %d\n",
256 FIX_BTMAP_BEGIN);
Ingo Molnar0e3a9542008-01-30 13:33:49 +0100257 }
Huang, Ying0947b2f2008-01-30 13:33:44 +0100258}
259
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100260void __init early_ioremap_clear(void)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100261{
262 unsigned long *pgd;
263
Ingo Molnard18d6d62008-01-30 13:33:45 +0100264 if (early_ioremap_debug)
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100265 printk(KERN_DEBUG "early_ioremap_clear()\n");
Ingo Molnard18d6d62008-01-30 13:33:45 +0100266
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100267 pgd = early_ioremap_pgd(fix_to_virt(FIX_BTMAP_BEGIN));
Huang, Ying0947b2f2008-01-30 13:33:44 +0100268 *pgd = 0;
269 __flush_tlb_all();
270}
271
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100272void __init early_ioremap_reset(void)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100273{
274 enum fixed_addresses idx;
275 unsigned long *pte, phys, addr;
276
277 after_paging_init = 1;
Huang, Ying64a8f852008-01-30 13:33:44 +0100278 for (idx = FIX_BTMAP_BEGIN; idx >= FIX_BTMAP_END; idx--) {
Huang, Ying0947b2f2008-01-30 13:33:44 +0100279 addr = fix_to_virt(idx);
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100280 pte = early_ioremap_pte(addr);
Huang, Ying0947b2f2008-01-30 13:33:44 +0100281 if (!*pte & _PAGE_PRESENT) {
282 phys = *pte & PAGE_MASK;
283 set_fixmap(idx, phys);
284 }
285 }
286}
287
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100288static void __init __early_set_fixmap(enum fixed_addresses idx,
Huang, Ying0947b2f2008-01-30 13:33:44 +0100289 unsigned long phys, pgprot_t flags)
290{
291 unsigned long *pte, addr = __fix_to_virt(idx);
292
293 if (idx >= __end_of_fixed_addresses) {
294 BUG();
295 return;
296 }
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100297 pte = early_ioremap_pte(addr);
Huang, Ying0947b2f2008-01-30 13:33:44 +0100298 if (pgprot_val(flags))
299 *pte = (phys & PAGE_MASK) | pgprot_val(flags);
300 else
301 *pte = 0;
302 __flush_tlb_one(addr);
303}
304
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100305static inline void __init early_set_fixmap(enum fixed_addresses idx,
Huang, Ying0947b2f2008-01-30 13:33:44 +0100306 unsigned long phys)
307{
308 if (after_paging_init)
309 set_fixmap(idx, phys);
310 else
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100311 __early_set_fixmap(idx, phys, PAGE_KERNEL);
Huang, Ying0947b2f2008-01-30 13:33:44 +0100312}
313
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100314static inline void __init early_clear_fixmap(enum fixed_addresses idx)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100315{
316 if (after_paging_init)
317 clear_fixmap(idx);
318 else
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100319 __early_set_fixmap(idx, 0, __pgprot(0));
Huang, Ying0947b2f2008-01-30 13:33:44 +0100320}
321
Ingo Molnar1b42f512008-01-30 13:33:45 +0100322
323int __initdata early_ioremap_nested;
324
Ingo Molnard690b2a2008-01-30 13:33:47 +0100325static int __init check_early_ioremap_leak(void)
326{
327 if (!early_ioremap_nested)
328 return 0;
329
330 printk(KERN_WARNING
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100331 "Debug warning: early ioremap leak of %d areas detected.\n",
332 early_ioremap_nested);
Ingo Molnard690b2a2008-01-30 13:33:47 +0100333 printk(KERN_WARNING
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100334 "please boot with early_ioremap_debug and report the dmesg.\n");
Ingo Molnard690b2a2008-01-30 13:33:47 +0100335 WARN_ON(1);
336
337 return 1;
338}
339late_initcall(check_early_ioremap_leak);
340
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100341void __init *early_ioremap(unsigned long phys_addr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
343 unsigned long offset, last_addr;
Ingo Molnar1b42f512008-01-30 13:33:45 +0100344 unsigned int nrpages, nesting;
345 enum fixed_addresses idx0, idx;
346
347 WARN_ON(system_state != SYSTEM_BOOTING);
348
349 nesting = early_ioremap_nested;
Ingo Molnard18d6d62008-01-30 13:33:45 +0100350 if (early_ioremap_debug) {
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100351 printk(KERN_DEBUG "early_ioremap(%08lx, %08lx) [%d] => ",
352 phys_addr, size, nesting);
Ingo Molnard18d6d62008-01-30 13:33:45 +0100353 dump_stack();
354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 /* Don't allow wraparound or zero size */
357 last_addr = phys_addr + size - 1;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100358 if (!size || last_addr < phys_addr) {
359 WARN_ON(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 return NULL;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100361 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100363 if (nesting >= FIX_BTMAPS_NESTING) {
364 WARN_ON(1);
Ingo Molnar1b42f512008-01-30 13:33:45 +0100365 return NULL;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100366 }
Ingo Molnar1b42f512008-01-30 13:33:45 +0100367 early_ioremap_nested++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 /*
369 * Mappings have to be page-aligned
370 */
371 offset = phys_addr & ~PAGE_MASK;
372 phys_addr &= PAGE_MASK;
373 size = PAGE_ALIGN(last_addr) - phys_addr;
374
375 /*
376 * Mappings have to fit in the FIX_BTMAP area.
377 */
378 nrpages = size >> PAGE_SHIFT;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100379 if (nrpages > NR_FIX_BTMAPS) {
380 WARN_ON(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 return NULL;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100382 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 /*
385 * Ok, go for it..
386 */
Ingo Molnar1b42f512008-01-30 13:33:45 +0100387 idx0 = FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*nesting;
388 idx = idx0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 while (nrpages > 0) {
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100390 early_set_fixmap(idx, phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 phys_addr += PAGE_SIZE;
392 --idx;
393 --nrpages;
394 }
Ingo Molnard18d6d62008-01-30 13:33:45 +0100395 if (early_ioremap_debug)
396 printk(KERN_CONT "%08lx + %08lx\n", offset, fix_to_virt(idx0));
Ingo Molnar1b42f512008-01-30 13:33:45 +0100397
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100398 return (void *) (offset + fix_to_virt(idx0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399}
400
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100401void __init early_iounmap(void *addr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
403 unsigned long virt_addr;
404 unsigned long offset;
405 unsigned int nrpages;
406 enum fixed_addresses idx;
Ingo Molnar1b42f512008-01-30 13:33:45 +0100407 unsigned int nesting;
408
409 nesting = --early_ioremap_nested;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100410 WARN_ON(nesting < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Ingo Molnard18d6d62008-01-30 13:33:45 +0100412 if (early_ioremap_debug) {
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100413 printk(KERN_DEBUG "early_iounmap(%p, %08lx) [%d]\n", addr,
414 size, nesting);
Ingo Molnard18d6d62008-01-30 13:33:45 +0100415 dump_stack();
416 }
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 virt_addr = (unsigned long)addr;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100419 if (virt_addr < fix_to_virt(FIX_BTMAP_BEGIN)) {
420 WARN_ON(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 return;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100422 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 offset = virt_addr & ~PAGE_MASK;
424 nrpages = PAGE_ALIGN(offset + size - 1) >> PAGE_SHIFT;
425
Ingo Molnar1b42f512008-01-30 13:33:45 +0100426 idx = FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*nesting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 while (nrpages > 0) {
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100428 early_clear_fixmap(idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 --idx;
430 --nrpages;
431 }
432}
Ingo Molnar1b42f512008-01-30 13:33:45 +0100433
434void __this_fixmap_does_not_exist(void)
435{
436 WARN_ON(1);
437}