blob: 24e42cab8d58a07c62aedc5da3d5fa40f3e2f54f [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
Thomas Gleixner240d3a72008-01-30 13:34:05 +0100128#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 /*
130 * Don't allow anybody to remap normal RAM that we're using..
131 */
132 if (phys_addr <= virt_to_phys(high_memory - 1)) {
133 char *t_addr, *t_end;
134 struct page *page;
135
136 t_addr = __va(phys_addr);
137 t_end = t_addr + (size - 1);
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100138
139 for (page = virt_to_page(t_addr);
140 page <= virt_to_page(t_end); page++)
141 if (!PageReserved(page))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 return NULL;
143 }
Thomas Gleixner240d3a72008-01-30 13:34:05 +0100144#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Thomas Gleixnere9332ca2008-01-30 13:34:05 +0100146 pgprot = MAKE_GLOBAL(__PAGE_KERNEL | flags);
Haavard Skinnemoena148ecf2006-09-30 23:29:17 -0700147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 /*
149 * Mappings have to be page-aligned
150 */
151 offset = phys_addr & ~PAGE_MASK;
152 phys_addr &= PAGE_MASK;
153 size = PAGE_ALIGN(last_addr+1) - phys_addr;
154
155 /*
156 * Ok, go for it..
157 */
Thomas Gleixner74ff2852008-01-30 13:34:05 +0100158 area = get_vm_area(size, VM_IOREMAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 if (!area)
160 return NULL;
161 area->phys_addr = phys_addr;
162 addr = (void __iomem *) area->addr;
Thomas Gleixnere9332ca2008-01-30 13:34:05 +0100163 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
164 phys_addr, pgprot)) {
Thomas Gleixnere4c1b972008-01-30 13:34:05 +0100165 remove_vm_area((void *)(PAGE_MASK & (unsigned long) addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 return NULL;
167 }
Thomas Gleixnere9332ca2008-01-30 13:34:05 +0100168
169 if (ioremap_change_attr(phys_addr, size, pgprot) < 0) {
170 vunmap(addr);
171 return NULL;
172 }
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 return (void __iomem *) (offset + (char __iomem *)addr);
175}
Alexey Dobriyan129f6942005-06-23 00:08:33 -0700176EXPORT_SYMBOL(__ioremap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178/**
179 * ioremap_nocache - map bus memory into CPU space
180 * @offset: bus address of the memory
181 * @size: size of the resource to map
182 *
183 * ioremap_nocache performs a platform specific sequence of operations to
184 * make bus memory CPU accessible via the readb/readw/readl/writeb/
185 * writew/writel functions and the other mmio helpers. The returned
186 * address is not guaranteed to be usable directly as a virtual
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100187 * address.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 *
189 * This version of ioremap ensures that the memory is marked uncachable
190 * on the CPU as well as honouring existing caching rules from things like
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100191 * the PCI bus. Note that there are other caches and buffers on many
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 * busses. In particular driver authors should read up on PCI writes
193 *
194 * It's useful if some control registers are in such an area and
195 * write combining or read caching is not desirable:
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100196 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 * Must be freed with iounmap.
198 */
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100199void __iomem *ioremap_nocache(unsigned long phys_addr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
Thomas Gleixnere9332ca2008-01-30 13:34:05 +0100201 return __ioremap(phys_addr, size, _PAGE_PCD | _PAGE_PWT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202}
Alexey Dobriyan129f6942005-06-23 00:08:33 -0700203EXPORT_SYMBOL(ioremap_nocache);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Andi Kleenbf5421c2005-12-12 22:17:09 -0800205/**
206 * iounmap - Free a IO remapping
207 * @addr: virtual address from ioremap_*
208 *
209 * Caller must ensure there is only one unmapping for the same pointer.
210 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211void iounmap(volatile void __iomem *addr)
212{
Andi Kleenbf5421c2005-12-12 22:17:09 -0800213 struct vm_struct *p, *o;
Andrew Mortonc23a4e962005-07-07 17:56:02 -0700214
215 if ((void __force *)addr <= high_memory)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 return;
217
218 /*
219 * __ioremap special-cases the PCI/ISA range by not instantiating a
220 * vm_area and by simply returning an address into the kernel mapping
221 * of ISA space. So handle that here.
222 */
223 if (addr >= phys_to_virt(ISA_START_ADDRESS) &&
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100224 addr < phys_to_virt(ISA_END_ADDRESS))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 return;
226
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100227 addr = (volatile void __iomem *)
228 (PAGE_MASK & (unsigned long __force)addr);
Andi Kleenbf5421c2005-12-12 22:17:09 -0800229
230 /* Use the vm area unlocked, assuming the caller
231 ensures there isn't another iounmap for the same address
232 in parallel. Reuse of the virtual address is prevented by
233 leaving it in the global lists until we're done with it.
234 cpa takes care of the direct mappings. */
235 read_lock(&vmlist_lock);
236 for (p = vmlist; p; p = p->next) {
237 if (p->addr == addr)
238 break;
239 }
240 read_unlock(&vmlist_lock);
241
242 if (!p) {
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100243 printk(KERN_ERR "iounmap: bad address %p\n", addr);
Andrew Mortonc23a4e962005-07-07 17:56:02 -0700244 dump_stack();
Andi Kleenbf5421c2005-12-12 22:17:09 -0800245 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
247
Andi Kleenbf5421c2005-12-12 22:17:09 -0800248 /* Reset the direct mapping. Can block */
Thomas Gleixnere9332ca2008-01-30 13:34:05 +0100249 ioremap_change_attr(p->phys_addr, p->size, PAGE_KERNEL);
Andi Kleenbf5421c2005-12-12 22:17:09 -0800250
251 /* Finally remove it */
252 o = remove_vm_area((void *)addr);
253 BUG_ON(p != o || o == NULL);
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100254 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255}
Alexey Dobriyan129f6942005-06-23 00:08:33 -0700256EXPORT_SYMBOL(iounmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Thomas Gleixner240d3a72008-01-30 13:34:05 +0100258#ifdef CONFIG_X86_32
Ingo Molnard18d6d62008-01-30 13:33:45 +0100259
260int __initdata early_ioremap_debug;
261
262static int __init early_ioremap_debug_setup(char *str)
263{
264 early_ioremap_debug = 1;
265
Huang, Ying793b24a2008-01-30 13:33:45 +0100266 return 0;
Ingo Molnard18d6d62008-01-30 13:33:45 +0100267}
Huang, Ying793b24a2008-01-30 13:33:45 +0100268early_param("early_ioremap_debug", early_ioremap_debug_setup);
Ingo Molnard18d6d62008-01-30 13:33:45 +0100269
Huang, Ying0947b2f2008-01-30 13:33:44 +0100270static __initdata int after_paging_init;
271static __initdata unsigned long bm_pte[1024]
272 __attribute__((aligned(PAGE_SIZE)));
273
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100274static inline unsigned long * __init early_ioremap_pgd(unsigned long addr)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100275{
276 return (unsigned long *)swapper_pg_dir + ((addr >> 22) & 1023);
277}
278
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100279static inline unsigned long * __init early_ioremap_pte(unsigned long addr)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100280{
281 return bm_pte + ((addr >> PAGE_SHIFT) & 1023);
282}
283
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100284void __init early_ioremap_init(void)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100285{
286 unsigned long *pgd;
287
Ingo Molnard18d6d62008-01-30 13:33:45 +0100288 if (early_ioremap_debug)
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100289 printk(KERN_DEBUG "early_ioremap_init()\n");
Ingo Molnard18d6d62008-01-30 13:33:45 +0100290
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100291 pgd = early_ioremap_pgd(fix_to_virt(FIX_BTMAP_BEGIN));
Huang, Ying0947b2f2008-01-30 13:33:44 +0100292 *pgd = __pa(bm_pte) | _PAGE_TABLE;
293 memset(bm_pte, 0, sizeof(bm_pte));
Ingo Molnar0e3a9542008-01-30 13:33:49 +0100294 /*
295 * The boot-ioremap range spans multiple pgds, for which
296 * we are not prepared:
297 */
298 if (pgd != early_ioremap_pgd(fix_to_virt(FIX_BTMAP_END))) {
299 WARN_ON(1);
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100300 printk(KERN_WARNING "pgd %p != %p\n",
301 pgd, early_ioremap_pgd(fix_to_virt(FIX_BTMAP_END)));
302 printk(KERN_WARNING "fix_to_virt(FIX_BTMAP_BEGIN): %08lx\n",
303 fix_to_virt(FIX_BTMAP_BEGIN));
304 printk(KERN_WARNING "fix_to_virt(FIX_BTMAP_END): %08lx\n",
305 fix_to_virt(FIX_BTMAP_END));
Ingo Molnar0e3a9542008-01-30 13:33:49 +0100306
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100307 printk(KERN_WARNING "FIX_BTMAP_END: %d\n", FIX_BTMAP_END);
308 printk(KERN_WARNING "FIX_BTMAP_BEGIN: %d\n",
309 FIX_BTMAP_BEGIN);
Ingo Molnar0e3a9542008-01-30 13:33:49 +0100310 }
Huang, Ying0947b2f2008-01-30 13:33:44 +0100311}
312
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100313void __init early_ioremap_clear(void)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100314{
315 unsigned long *pgd;
316
Ingo Molnard18d6d62008-01-30 13:33:45 +0100317 if (early_ioremap_debug)
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100318 printk(KERN_DEBUG "early_ioremap_clear()\n");
Ingo Molnard18d6d62008-01-30 13:33:45 +0100319
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100320 pgd = early_ioremap_pgd(fix_to_virt(FIX_BTMAP_BEGIN));
Huang, Ying0947b2f2008-01-30 13:33:44 +0100321 *pgd = 0;
322 __flush_tlb_all();
323}
324
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100325void __init early_ioremap_reset(void)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100326{
327 enum fixed_addresses idx;
328 unsigned long *pte, phys, addr;
329
330 after_paging_init = 1;
Huang, Ying64a8f852008-01-30 13:33:44 +0100331 for (idx = FIX_BTMAP_BEGIN; idx >= FIX_BTMAP_END; idx--) {
Huang, Ying0947b2f2008-01-30 13:33:44 +0100332 addr = fix_to_virt(idx);
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100333 pte = early_ioremap_pte(addr);
Huang, Ying0947b2f2008-01-30 13:33:44 +0100334 if (!*pte & _PAGE_PRESENT) {
335 phys = *pte & PAGE_MASK;
336 set_fixmap(idx, phys);
337 }
338 }
339}
340
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100341static void __init __early_set_fixmap(enum fixed_addresses idx,
Huang, Ying0947b2f2008-01-30 13:33:44 +0100342 unsigned long phys, pgprot_t flags)
343{
344 unsigned long *pte, addr = __fix_to_virt(idx);
345
346 if (idx >= __end_of_fixed_addresses) {
347 BUG();
348 return;
349 }
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100350 pte = early_ioremap_pte(addr);
Huang, Ying0947b2f2008-01-30 13:33:44 +0100351 if (pgprot_val(flags))
352 *pte = (phys & PAGE_MASK) | pgprot_val(flags);
353 else
354 *pte = 0;
355 __flush_tlb_one(addr);
356}
357
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100358static inline void __init early_set_fixmap(enum fixed_addresses idx,
Huang, Ying0947b2f2008-01-30 13:33:44 +0100359 unsigned long phys)
360{
361 if (after_paging_init)
362 set_fixmap(idx, phys);
363 else
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100364 __early_set_fixmap(idx, phys, PAGE_KERNEL);
Huang, Ying0947b2f2008-01-30 13:33:44 +0100365}
366
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100367static inline void __init early_clear_fixmap(enum fixed_addresses idx)
Huang, Ying0947b2f2008-01-30 13:33:44 +0100368{
369 if (after_paging_init)
370 clear_fixmap(idx);
371 else
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100372 __early_set_fixmap(idx, 0, __pgprot(0));
Huang, Ying0947b2f2008-01-30 13:33:44 +0100373}
374
Ingo Molnar1b42f512008-01-30 13:33:45 +0100375
376int __initdata early_ioremap_nested;
377
Ingo Molnard690b2a2008-01-30 13:33:47 +0100378static int __init check_early_ioremap_leak(void)
379{
380 if (!early_ioremap_nested)
381 return 0;
382
383 printk(KERN_WARNING
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100384 "Debug warning: early ioremap leak of %d areas detected.\n",
385 early_ioremap_nested);
Ingo Molnard690b2a2008-01-30 13:33:47 +0100386 printk(KERN_WARNING
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100387 "please boot with early_ioremap_debug and report the dmesg.\n");
Ingo Molnard690b2a2008-01-30 13:33:47 +0100388 WARN_ON(1);
389
390 return 1;
391}
392late_initcall(check_early_ioremap_leak);
393
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100394void __init *early_ioremap(unsigned long phys_addr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
396 unsigned long offset, last_addr;
Ingo Molnar1b42f512008-01-30 13:33:45 +0100397 unsigned int nrpages, nesting;
398 enum fixed_addresses idx0, idx;
399
400 WARN_ON(system_state != SYSTEM_BOOTING);
401
402 nesting = early_ioremap_nested;
Ingo Molnard18d6d62008-01-30 13:33:45 +0100403 if (early_ioremap_debug) {
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100404 printk(KERN_DEBUG "early_ioremap(%08lx, %08lx) [%d] => ",
405 phys_addr, size, nesting);
Ingo Molnard18d6d62008-01-30 13:33:45 +0100406 dump_stack();
407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 /* Don't allow wraparound or zero size */
410 last_addr = phys_addr + size - 1;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100411 if (!size || last_addr < phys_addr) {
412 WARN_ON(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 return NULL;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100414 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100416 if (nesting >= FIX_BTMAPS_NESTING) {
417 WARN_ON(1);
Ingo Molnar1b42f512008-01-30 13:33:45 +0100418 return NULL;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100419 }
Ingo Molnar1b42f512008-01-30 13:33:45 +0100420 early_ioremap_nested++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 /*
422 * Mappings have to be page-aligned
423 */
424 offset = phys_addr & ~PAGE_MASK;
425 phys_addr &= PAGE_MASK;
426 size = PAGE_ALIGN(last_addr) - phys_addr;
427
428 /*
429 * Mappings have to fit in the FIX_BTMAP area.
430 */
431 nrpages = size >> PAGE_SHIFT;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100432 if (nrpages > NR_FIX_BTMAPS) {
433 WARN_ON(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 return NULL;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437 /*
438 * Ok, go for it..
439 */
Ingo Molnar1b42f512008-01-30 13:33:45 +0100440 idx0 = FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*nesting;
441 idx = idx0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 while (nrpages > 0) {
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100443 early_set_fixmap(idx, phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 phys_addr += PAGE_SIZE;
445 --idx;
446 --nrpages;
447 }
Ingo Molnard18d6d62008-01-30 13:33:45 +0100448 if (early_ioremap_debug)
449 printk(KERN_CONT "%08lx + %08lx\n", offset, fix_to_virt(idx0));
Ingo Molnar1b42f512008-01-30 13:33:45 +0100450
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100451 return (void *) (offset + fix_to_virt(idx0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452}
453
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100454void __init early_iounmap(void *addr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
456 unsigned long virt_addr;
457 unsigned long offset;
458 unsigned int nrpages;
459 enum fixed_addresses idx;
Ingo Molnar1b42f512008-01-30 13:33:45 +0100460 unsigned int nesting;
461
462 nesting = --early_ioremap_nested;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100463 WARN_ON(nesting < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Ingo Molnard18d6d62008-01-30 13:33:45 +0100465 if (early_ioremap_debug) {
Thomas Gleixner91eebf42008-01-30 13:34:05 +0100466 printk(KERN_DEBUG "early_iounmap(%p, %08lx) [%d]\n", addr,
467 size, nesting);
Ingo Molnard18d6d62008-01-30 13:33:45 +0100468 dump_stack();
469 }
470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 virt_addr = (unsigned long)addr;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100472 if (virt_addr < fix_to_virt(FIX_BTMAP_BEGIN)) {
473 WARN_ON(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 return;
Ingo Molnarbd796ed2008-01-30 13:33:45 +0100475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 offset = virt_addr & ~PAGE_MASK;
477 nrpages = PAGE_ALIGN(offset + size - 1) >> PAGE_SHIFT;
478
Ingo Molnar1b42f512008-01-30 13:33:45 +0100479 idx = FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*nesting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 while (nrpages > 0) {
Huang, Yingbeacfaa2008-01-30 13:33:44 +0100481 early_clear_fixmap(idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 --idx;
483 --nrpages;
484 }
485}
Ingo Molnar1b42f512008-01-30 13:33:45 +0100486
487void __this_fixmap_does_not_exist(void)
488{
489 WARN_ON(1);
490}
Thomas Gleixner240d3a72008-01-30 13:34:05 +0100491
492#endif /* CONFIG_X86_32 */