2 * arch/cris/mm/ioremap.c
4 * Re-map IO memory to kernel address space so that we can access it.
5 * Needed for memory-mapped I/O devices mapped outside our normal DRAM
6 * window (that is, all memory-mapped I/O devices).
8 * (C) Copyright 1995 1996 Linus Torvalds
9 * CRIS-port by Axis Communications AB
12 #include <linux/vmalloc.h>
14 #include <asm/pgalloc.h>
15 #include <asm/cacheflush.h>
16 #include <asm/tlbflush.h>
18 extern 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("remap_area_pte: page already exists\n");
34 set_pte(pte
, mk_pte_phys(phys_addr
, __pgprot(_PAGE_PRESENT
| __READABLE
|
35 __WRITEABLE
| _PAGE_GLOBAL
|
36 _PAGE_KERNEL
| flags
)));
38 phys_addr
+= PAGE_SIZE
;
40 } while (address
&& (address
< end
));
43 static inline int remap_area_pmd(pmd_t
* pmd
, unsigned long address
, unsigned long size
,
44 unsigned long phys_addr
, unsigned long flags
)
48 address
&= ~PGDIR_MASK
;
56 pte_t
* pte
= pte_alloc_kernel(&init_mm
, pmd
, address
);
59 remap_area_pte(pte
, address
, end
- address
, address
+ phys_addr
, flags
);
60 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
62 } while (address
&& (address
< end
));
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
);
78 spin_lock(&init_mm
.page_table_lock
);
81 pmd
= pmd_alloc(&init_mm
, dir
, address
);
85 if (remap_area_pmd(pmd
, address
, end
- address
,
86 phys_addr
+ address
, flags
))
89 address
= (address
+ PGDIR_SIZE
) & PGDIR_MASK
;
91 } while (address
&& (address
< end
));
92 spin_unlock(&init_mm
.page_table_lock
);
98 * Generic mapping function (not visible outside):
102 * Remap an arbitrary physical address space into the kernel virtual
103 * address space. Needed when the kernel wants to access high addresses
106 * NOTE! We need to allow non-page-aligned mappings too: we will obviously
107 * have to convert them into an offset in a page-aligned mapping, but the
108 * caller shouldn't need to know that small detail.
110 void * __ioremap(unsigned long phys_addr
, unsigned long size
, unsigned long flags
)
113 struct vm_struct
* area
;
114 unsigned long offset
, last_addr
;
116 /* Don't allow wraparound or zero size */
117 last_addr
= phys_addr
+ size
- 1;
118 if (!size
|| last_addr
< phys_addr
)
122 * Mappings have to be page-aligned
124 offset
= phys_addr
& ~PAGE_MASK
;
125 phys_addr
&= PAGE_MASK
;
126 size
= PAGE_ALIGN(last_addr
+1) - phys_addr
;
131 area
= get_vm_area(size
, VM_IOREMAP
);
135 if (remap_area_pages((unsigned long) addr
, phys_addr
, size
, flags
)) {
139 return (void *) (offset
+ (char *)addr
);
142 void iounmap(void *addr
)
144 if (addr
> high_memory
)
145 return vfree((void *) (PAGE_MASK
& (unsigned long) addr
));