2 * arch/parisc/mm/ioremap.c
4 * Re-map IO memory to kernel address space so that we can access it.
5 * This is needed for high PCI addresses that aren't mapped in the
6 * 640k-1MB IO memory area on PC's
8 * (C) Copyright 1995 1996 Linus Torvalds
9 * (C) Copyright 2001 Helge Deller <deller@gmx.de>
12 #include <linux/vmalloc.h>
13 #include <linux/errno.h>
14 #include <linux/module.h>
16 #include <asm/pgalloc.h>
18 static inline void remap_area_pte(pte_t * pte, unsigned long address, unsigned long size,
19 unsigned long phys_addr, unsigned long flags)
30 if (!pte_none(*pte)) {
31 printk(KERN_ERR "remap_area_pte: page already exists\n");
34 set_pte(pte, mk_pte_phys(phys_addr, __pgprot(_PAGE_PRESENT | _PAGE_RW |
35 _PAGE_DIRTY | _PAGE_ACCESSED | flags)));
37 phys_addr += PAGE_SIZE;
39 } while (address && (address < end));
42 static inline int remap_area_pmd(pmd_t * pmd, unsigned long address, unsigned long size,
43 unsigned long phys_addr, unsigned long flags)
47 address &= ~PGDIR_MASK;
55 pte_t * pte = pte_alloc_kernel(pmd, address);
58 remap_area_pte(pte, address, end - address, address + phys_addr, flags);
59 address = (address + PMD_SIZE) & PMD_MASK;
61 } while (address && (address < end));
65 #if (USE_HPPA_IOREMAP)
66 static int remap_area_pages(unsigned long address, unsigned long phys_addr,
67 unsigned long size, unsigned long flags)
71 unsigned long end = address + size;
74 dir = pgd_offset(&init_mm, address);
80 pmd = pmd_alloc(&init_mm, dir, address);
84 if (remap_area_pmd(pmd, address, end - address,
85 phys_addr + address, flags))
88 address = (address + PGDIR_SIZE) & PGDIR_MASK;
90 } while (address && (address < end));
94 #endif /* USE_HPPA_IOREMAP */
96 #ifdef CONFIG_DEBUG_IOREMAP
97 static unsigned long last = 0;
99 void gsc_bad_addr(unsigned long addr)
101 if (time_after(jiffies, last + HZ*10)) {
102 printk("gsc_foo() called with bad address 0x%lx\n", addr);
107 EXPORT_SYMBOL(gsc_bad_addr);
109 void __raw_bad_addr(const volatile void __iomem *addr)
111 if (time_after(jiffies, last + HZ*10)) {
112 printk("__raw_foo() called with bad address 0x%p\n", addr);
117 EXPORT_SYMBOL(__raw_bad_addr);
121 * Generic mapping function (not visible outside):
125 * Remap an arbitrary physical address space into the kernel virtual
126 * address space. Needed when the kernel wants to access high addresses
129 * NOTE! We need to allow non-page-aligned mappings too: we will obviously
130 * have to convert them into an offset in a page-aligned mapping, but the
131 * caller shouldn't need to know that small detail.
133 void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned long flags)
135 #if !(USE_HPPA_IOREMAP)
137 unsigned long end = phys_addr + size - 1;
138 /* Support EISA addresses */
139 if ((phys_addr >= 0x00080000 && end < 0x000fffff)
140 || (phys_addr >= 0x00500000 && end < 0x03bfffff)) {
141 phys_addr |= 0xfc000000;
144 #ifdef CONFIG_DEBUG_IOREMAP
145 return (void __iomem *)(phys_addr - (0x1UL << NYBBLE_SHIFT));
147 return (void __iomem *)phys_addr;
152 struct vm_struct * area;
153 unsigned long offset, last_addr;
155 /* Don't allow wraparound or zero size */
156 last_addr = phys_addr + size - 1;
157 if (!size || last_addr < phys_addr)
161 * Don't allow anybody to remap normal RAM that we're using..
163 if (phys_addr < virt_to_phys(high_memory)) {
164 char *t_addr, *t_end;
167 t_addr = __va(phys_addr);
168 t_end = t_addr + (size - 1);
170 for(page = virt_to_page(t_addr); page <= virt_to_page(t_end); page++)
171 if(!PageReserved(page))
176 * Mappings have to be page-aligned
178 offset = phys_addr & ~PAGE_MASK;
179 phys_addr &= PAGE_MASK;
180 size = PAGE_ALIGN(last_addr) - phys_addr;
185 area = get_vm_area(size, VM_IOREMAP);
189 if (remap_area_pages((unsigned long) addr, phys_addr, size, flags)) {
193 return (void __iomem *) (offset + (char *)addr);
197 void iounmap(void __iomem *addr)
199 #if !(USE_HPPA_IOREMAP)
202 if (addr > high_memory)
203 return vfree((void *) (PAGE_MASK & (unsigned long __force) addr));