[PATCH] Generic ioremap_page_range: mips conversion
[linux-2.6/openmoko-kernel/knife-kernel.git] / arch / mips / mm / ioremap.c
blobfc2c96f0a1fd6bd532b233da431ca7dc4f6db5ff
1 /*
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
4 * for more details.
6 * (C) Copyright 1995 1996 Linus Torvalds
7 * (C) Copyright 2001, 2002 Ralf Baechle
8 */
9 #include <linux/mm.h>
10 #include <linux/module.h>
11 #include <asm/addrspace.h>
12 #include <asm/byteorder.h>
14 #include <linux/vmalloc.h>
15 #include <linux/io.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
24 * directly.
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;
36 unsigned long offset;
37 phys_t last_addr;
38 void * addr;
39 pgprot_t pgprot;
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)
46 return NULL;
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)) {
60 char *t_addr, *t_end;
61 struct page *page;
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))
68 return NULL;
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;
82 * Ok, go for it..
84 area = get_vm_area(size, VM_IOREMAP);
85 if (!area)
86 return NULL;
87 addr = area->addr;
88 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
89 phys_addr, pgprot)) {
90 vunmap(addr);
91 return NULL;
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)
101 struct vm_struct *p;
103 if (IS_KSEG1(addr))
104 return;
106 p = remove_vm_area((void *) (PAGE_MASK & (unsigned long __force) addr));
107 if (!p)
108 printk(KERN_ERR "iounmap: bad address %p\n", addr);
110 kfree(p);
113 EXPORT_SYMBOL(__ioremap);
114 EXPORT_SYMBOL(__iounmap);