12 #include <linux/module.h>
13 #include <linux/slab.h>
17 #include <asm/cacheflush.h>
19 #include <asm/fixmap.h>
20 #include <asm/pgtable.h>
21 #include <asm/tlbflush.h>
22 #include <asm/pgalloc.h>
32 unsigned long prot_val)
63 unsigned long size,
unsigned long prot_val,
void *
caller)
68 const unsigned long unaligned_size =
size;
70 unsigned long new_prot_val;
76 last_addr = phys_addr + size - 1;
77 if (!size || last_addr < phys_addr)
80 if (!phys_addr_valid(phys_addr)) {
82 (
unsigned long long)phys_addr);
90 if (is_ISA_range(phys_addr, last_addr))
97 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
113 prot_val, &new_prot_val);
119 if (prot_val != new_prot_val) {
120 if (!is_new_memtype_allowed(phys_addr, size,
121 prot_val, new_prot_val)) {
123 "ioremap error for 0x%llx-0x%llx, requested 0x%lx, got 0x%lx\n",
124 (
unsigned long long)phys_addr,
125 (
unsigned long long)(phys_addr + size),
126 prot_val, new_prot_val);
127 goto err_free_memtype;
129 prot_val = new_prot_val;
153 goto err_free_memtype;
163 ret_addr = (
void __iomem *) (vaddr + offset);
171 KERN_INFO "Info: mapping multiple BARs. Your kernel is fine.");
214 __builtin_return_address(0));
232 __builtin_return_address(0));
241 __builtin_return_address(0));
246 unsigned long prot_val)
249 __builtin_return_address(0));
275 addr = (
volatile void __iomem *)
287 if (p->
addr == (
void __force *)addr)
322 addr = (
void *)((
unsigned long)addr | (phys & ~PAGE_MASK));
338 static int __init early_ioremap_debug_setup(
char *
str)
340 early_ioremap_debug = 1;
344 early_param(
"early_ioremap_debug", early_ioremap_debug_setup);
360 static inline pte_t *
__init early_ioremap_pte(
unsigned long addr)
367 return ptep >= &bm_pte[0] && ptep < &bm_pte[
PAGE_SIZE/
sizeof(
pte_t)];
377 if (early_ioremap_debug)
384 memset(bm_pte, 0,
sizeof(bm_pte));
391 #define __FIXADDR_TOP (-PAGE_SIZE)
412 after_paging_init = 1;
425 pte = early_ioremap_pte(addr);
437 if (after_paging_init)
440 __early_set_fixmap(idx, phys, prot);
445 if (after_paging_init)
448 __early_set_fixmap(idx, 0,
__pgprot(0));
468 static int __init check_early_ioremap_leak(
void)
480 "Debug warning: early ioremap leak of %d areas detected.\n",
483 "please boot with early_ioremap_debug and report the dmesg.\n");
510 (
u64)phys_addr, size);
515 if (early_ioremap_debug) {
517 (
u64)phys_addr, size, slot);
522 last_addr = phys_addr + size - 1;
523 if (!size || last_addr < phys_addr) {
550 while (nrpages > 0) {
551 early_set_fixmap(idx, phys_addr, prot);
556 if (early_ioremap_debug)
559 prev_map[
slot] = (
void __iomem *)(offset + slot_virt[slot]);
560 return prev_map[
slot];
574 return __early_ioremap(phys_addr, size,
PAGE_KERNEL);
579 unsigned long virt_addr;
587 if (prev_map[i] == addr) {
600 if (prev_size[slot] != size) {
601 printk(
KERN_INFO "early_iounmap(%p, %08lx) [%d] size not consistent %08lx\n",
602 addr, size, slot, prev_size[slot]);
607 if (early_ioremap_debug) {
613 virt_addr = (
unsigned long)addr;
622 while (nrpages > 0) {
623 early_clear_fixmap(idx);