2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * (C) Copyright 1995 1996 Linus Torvalds
7 * (C) Copyright 2001, 2002 Ralf Baechle
10 #include <linux/module.h>
11 #include <asm/addrspace.h>
12 #include <asm/byteorder.h>
14 #include <linux/vmalloc.h>
18 * Generic mapping function (not visible outside):
22 * Remap an arbitrary physical address space into the kernel virtual
23 * address space. Needed when the kernel wants to access high addresses
26 * NOTE! We need to allow non-page-aligned mappings too: we will obviously
27 * have to convert them into an offset in a page-aligned mapping, but the
28 * caller shouldn't need to know that small detail.
31 #define IS_LOW512(addr) (!((phys_t)(addr) & (phys_t) ~0x1fffffffULL))
33 void __iomem
* __ioremap(phys_t phys_addr
, phys_t size
, unsigned long flags
)
35 struct vm_struct
* area
;
41 phys_addr
= fixup_bigphys_addr(phys_addr
, size
);
43 /* Don't allow wraparound or zero size */
44 last_addr
= phys_addr
+ size
- 1;
45 if (!size
|| last_addr
< phys_addr
)
49 * Map uncached objects in the low 512mb of address space using KSEG1,
50 * otherwise map using page tables.
52 if (IS_LOW512(phys_addr
) && IS_LOW512(last_addr
) &&
53 flags
== _CACHE_UNCACHED
)
54 return (void __iomem
*) CKSEG1ADDR(phys_addr
);
57 * Don't allow anybody to remap normal RAM that we're using..
59 if (phys_addr
< virt_to_phys(high_memory
)) {
63 t_addr
= __va(phys_addr
);
64 t_end
= t_addr
+ (size
- 1);
66 for(page
= virt_to_page(t_addr
); page
<= virt_to_page(t_end
); page
++)
67 if(!PageReserved(page
))
71 pgprot
= __pgprot(_PAGE_GLOBAL
| _PAGE_PRESENT
| __READABLE
72 | __WRITEABLE
| flags
);
75 * Mappings have to be page-aligned
77 offset
= phys_addr
& ~PAGE_MASK
;
78 phys_addr
&= PAGE_MASK
;
79 size
= PAGE_ALIGN(last_addr
+ 1) - phys_addr
;
84 area
= get_vm_area(size
, VM_IOREMAP
);
88 if (ioremap_page_range((unsigned long)addr
, (unsigned long)addr
+ size
,
94 return (void __iomem
*) (offset
+ (char *)addr
);
97 #define IS_KSEG1(addr) (((unsigned long)(addr) & ~0x1fffffffUL) == CKSEG1)
99 void __iounmap(const volatile void __iomem
*addr
)
106 p
= remove_vm_area((void *) (PAGE_MASK
& (unsigned long __force
) addr
));
108 printk(KERN_ERR
"iounmap: bad address %p\n", addr
);
113 EXPORT_SYMBOL(__ioremap
);
114 EXPORT_SYMBOL(__iounmap
);