2 * arch/arm/mm/ioremap.c
4 * Re-map IO memory to kernel address space so that we can access it.
6 * (C) Copyright 1995 1996 Linus Torvalds
8 * Hacked for ARM by Phil Blundell <philb@gnu.org>
9 * Hacked to allow all architectures to build, and various cleanups
14 * This allows a driver to remap an arbitrary region of bus memory into
15 * virtual space. One should *only* use readl, writel, memcpy_toio and
16 * so on with such remapped areas.
18 * Because the ARM only has a 32-bit address space we can't address the
19 * whole of the (physical) PCI space at once. PCI huge-mode addressing
20 * allows us to circumvent this restriction by splitting PCI space into
21 * two 2GB chunks and mapping only one at a time into processor memory.
22 * We use MMU protection domains to trap any attempt to access the bank
23 * that is not currently mapped. (This isn't fully implemented yet.)
25 * DC21285 currently has a bug in that the PCI address extension
26 * register affects the address of any writes waiting in the outbound
27 * FIFO. Unfortunately, it is not possible to tell the DC21285 to
28 * flush this - flushing the area causes the bus to lock.
31 #include <linux/vmalloc.h>
34 static inline void remap_area_pte(pte_t
* pte
, unsigned long address
, unsigned long size
,
35 unsigned long phys_addr
, pgprot_t pgprot
)
45 printk("remap_area_pte: page already exists\n");
46 set_pte(pte
, mk_pte_phys(phys_addr
, pgprot
));
48 phys_addr
+= PAGE_SIZE
;
50 } while (address
< end
);
53 static inline int remap_area_pmd(pmd_t
* pmd
, unsigned long address
, unsigned long size
,
54 unsigned long phys_addr
, unsigned long flags
)
59 address
&= ~PGDIR_MASK
;
66 pgprot
= __pgprot(L_PTE_PRESENT
| L_PTE_YOUNG
| L_PTE_DIRTY
| L_PTE_WRITE
| flags
);
68 pte_t
* pte
= pte_alloc_kernel(pmd
, address
);
71 remap_area_pte(pte
, address
, end
- address
, address
+ phys_addr
, pgprot
);
72 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
74 } while (address
< end
);
78 static int remap_area_pages(unsigned long address
, unsigned long phys_addr
,
79 unsigned long size
, unsigned long flags
)
82 unsigned long end
= address
+ size
;
85 dir
= pgd_offset(&init_mm
, address
);
87 while (address
< end
) {
88 pmd_t
*pmd
= pmd_alloc_kernel(dir
, address
);
91 if (remap_area_pmd(pmd
, address
, end
- address
,
92 phys_addr
+ address
, flags
))
94 set_pgdir(address
, *dir
);
95 address
= (address
+ PGDIR_SIZE
) & PGDIR_MASK
;
103 * Remap an arbitrary physical address space into the kernel virtual
104 * address space. Needed when the kernel wants to access high addresses
107 * NOTE! We need to allow non-page-aligned mappings too: we will obviously
108 * have to convert them into an offset in a page-aligned mapping, but the
109 * caller shouldn't need to know that small detail.
111 * 'flags' are the extra L_PTE_ flags that you want to specify for this
112 * mapping. See include/asm-arm/proc-armv/pgtable.h for more information.
114 void * __ioremap(unsigned long phys_addr
, unsigned long size
, unsigned long flags
)
117 struct vm_struct
* area
;
118 unsigned long offset
, last_addr
;
120 /* Don't allow wraparound or zero size */
121 last_addr
= phys_addr
+ size
- 1;
122 if (!size
|| last_addr
< phys_addr
)
126 * Mappings have to be page-aligned
128 offset
= phys_addr
& ~PAGE_MASK
;
129 phys_addr
&= PAGE_MASK
;
130 size
= PAGE_ALIGN(last_addr
) - phys_addr
;
135 area
= get_vm_area(size
);
139 if (remap_area_pages(VMALLOC_VMADDR(addr
), phys_addr
, size
, flags
)) {
143 return (void *) (offset
+ (char *)addr
);
146 void __iounmap(void *addr
)
148 return vfree((void *) (PAGE_MASK
& (unsigned long) addr
));