2 * arch/parisc/mm/ioremap.c
4 * (C) Copyright 1995 1996 Linus Torvalds
5 * (C) Copyright 2001 Helge Deller <deller@gmx.de>
6 * (C) Copyright 2005 Kyle McMartin <kyle@parisc-linux.org>
9 #include <linux/vmalloc.h>
10 #include <linux/errno.h>
11 #include <linux/module.h>
13 #include <asm/pgalloc.h>
14 #include <asm/tlbflush.h>
15 #include <asm/cacheflush.h>
18 remap_area_pte(pte_t
*pte
, unsigned long address
, unsigned long size
,
19 unsigned long phys_addr
, unsigned long flags
)
21 unsigned long end
, pfn
;
22 pgprot_t pgprot
= __pgprot(_PAGE_PRESENT
| _PAGE_RW
| _PAGE_DIRTY
|
23 _PAGE_ACCESSED
| flags
);
31 BUG_ON(address
>= end
);
33 pfn
= phys_addr
>> PAGE_SHIFT
;
35 BUG_ON(!pte_none(*pte
));
37 set_pte(pte
, pfn_pte(pfn
, pgprot
));
42 } while (address
&& (address
< end
));
46 remap_area_pmd(pmd_t
*pmd
, unsigned long address
, unsigned long size
,
47 unsigned long phys_addr
, unsigned long flags
)
51 address
&= ~PGDIR_MASK
;
57 BUG_ON(address
>= end
);
61 pte_t
*pte
= pte_alloc_kernel(pmd
, address
);
65 remap_area_pte(pte
, address
, end
- address
,
66 address
+ phys_addr
, flags
);
68 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
70 } while (address
&& (address
< end
));
77 remap_area_pages(unsigned long address
, unsigned long phys_addr
,
78 unsigned long size
, unsigned long flags
)
82 unsigned long end
= address
+ size
;
84 BUG_ON(address
>= end
);
87 dir
= pgd_offset_k(address
);
96 pud
= pud_alloc(&init_mm
, dir
, address
);
100 pmd
= pmd_alloc(&init_mm
, pud
, address
);
104 if (remap_area_pmd(pmd
, address
, end
- address
,
105 phys_addr
+ address
, flags
))
109 address
= (address
+ PGDIR_SIZE
) & PGDIR_MASK
;
111 } while (address
&& (address
< end
));
117 #endif /* USE_HPPA_IOREMAP */
119 #ifdef CONFIG_DEBUG_IOREMAP
120 static unsigned long last
= 0;
122 void gsc_bad_addr(unsigned long addr
)
124 if (time_after(jiffies
, last
+ HZ
*10)) {
125 printk("gsc_foo() called with bad address 0x%lx\n", addr
);
130 EXPORT_SYMBOL(gsc_bad_addr
);
132 void __raw_bad_addr(const volatile void __iomem
*addr
)
134 if (time_after(jiffies
, last
+ HZ
*10)) {
135 printk("__raw_foo() called with bad address 0x%p\n", addr
);
140 EXPORT_SYMBOL(__raw_bad_addr
);
144 * Generic mapping function (not visible outside):
148 * Remap an arbitrary physical address space into the kernel virtual
151 * NOTE! We need to allow non-page-aligned mappings too: we will obviously
152 * have to convert them into an offset in a page-aligned mapping, but the
153 * caller shouldn't need to know that small detail.
155 void __iomem
* __ioremap(unsigned long phys_addr
, unsigned long size
, unsigned long flags
)
157 #if !(USE_HPPA_IOREMAP)
159 unsigned long end
= phys_addr
+ size
- 1;
160 /* Support EISA addresses */
161 if ((phys_addr
>= 0x00080000 && end
< 0x000fffff)
162 || (phys_addr
>= 0x00500000 && end
< 0x03bfffff)) {
163 phys_addr
|= 0xfc000000;
166 #ifdef CONFIG_DEBUG_IOREMAP
167 return (void __iomem
*)(phys_addr
- (0x1UL
<< NYBBLE_SHIFT
));
169 return (void __iomem
*)phys_addr
;
174 struct vm_struct
*area
;
175 unsigned long offset
, last_addr
;
177 /* Don't allow wraparound or zero size */
178 last_addr
= phys_addr
+ size
- 1;
179 if (!size
|| last_addr
< phys_addr
)
183 * Don't allow anybody to remap normal RAM that we're using..
185 if (phys_addr
< virt_to_phys(high_memory
)) {
186 char *t_addr
, *t_end
;
189 t_addr
= __va(phys_addr
);
190 t_end
= t_addr
+ (size
- 1);
192 for (page
= virt_to_page(t_addr
);
193 page
<= virt_to_page(t_end
); page
++) {
194 if(!PageReserved(page
))
200 * Mappings have to be page-aligned
202 offset
= phys_addr
& ~PAGE_MASK
;
203 phys_addr
&= PAGE_MASK
;
204 size
= PAGE_ALIGN(last_addr
) - phys_addr
;
209 area
= get_vm_area(size
, VM_IOREMAP
);
214 if (remap_area_pages((unsigned long) addr
, phys_addr
, size
, flags
)) {
219 return (void __iomem
*) (offset
+ (char *)addr
);
223 void iounmap(void __iomem
*addr
)
225 #if !(USE_HPPA_IOREMAP)
228 if (addr
> high_memory
)
229 return vfree((void *) (PAGE_MASK
& (unsigned long __force
) addr
));