Full support for Ginger Console
[linux-ginger.git] / arch / m32r / mm / ioremap.c
blob5152c4e6ac80dfec69bde07efe6754edf657df37
1 /*
2 * linux/arch/m32r/mm/ioremap.c
4 * Copyright (c) 2001, 2002 Hiroyuki Kondo
6 * Taken from mips version.
7 * (C) Copyright 1995 1996 Linus Torvalds
8 * (C) Copyright 2001 Ralf Baechle
9 */
12 * This file is subject to the terms and conditions of the GNU General Public
13 * License. See the file "COPYING" in the main directory of this archive
14 * for more details.
18 #include <linux/module.h>
19 #include <asm/addrspace.h>
20 #include <asm/byteorder.h>
22 #include <linux/vmalloc.h>
23 #include <linux/io.h>
24 #include <asm/pgalloc.h>
27 * Generic mapping function (not visible outside):
31 * Remap an arbitrary physical address space into the kernel virtual
32 * address space. Needed when the kernel wants to access high addresses
33 * directly.
35 * NOTE! We need to allow non-page-aligned mappings too: we will obviously
36 * have to convert them into an offset in a page-aligned mapping, but the
37 * caller shouldn't need to know that small detail.
40 #define IS_LOW512(addr) (!((unsigned long)(addr) & ~0x1fffffffUL))
42 void __iomem *
43 __ioremap(unsigned long phys_addr, unsigned long size, unsigned long flags)
45 void __iomem * addr;
46 struct vm_struct * area;
47 unsigned long offset, last_addr;
48 pgprot_t pgprot;
50 /* Don't allow wraparound or zero size */
51 last_addr = phys_addr + size - 1;
52 if (!size || last_addr < phys_addr)
53 return NULL;
56 * Map objects in the low 512mb of address space using KSEG1, otherwise
57 * map using page tables.
59 if (IS_LOW512(phys_addr) && IS_LOW512(phys_addr + size - 1))
60 return (void *) KSEG1ADDR(phys_addr);
63 * Don't allow anybody to remap normal RAM that we're using..
65 if (phys_addr < virt_to_phys(high_memory)) {
66 char *t_addr, *t_end;
67 struct page *page;
69 t_addr = __va(phys_addr);
70 t_end = t_addr + (size - 1);
72 for(page = virt_to_page(t_addr); page <= virt_to_page(t_end); page++)
73 if(!PageReserved(page))
74 return NULL;
77 pgprot = __pgprot(_PAGE_GLOBAL | _PAGE_PRESENT | _PAGE_READ
78 | _PAGE_WRITE | flags);
81 * Mappings have to be page-aligned
83 offset = phys_addr & ~PAGE_MASK;
84 phys_addr &= PAGE_MASK;
85 size = PAGE_ALIGN(last_addr + 1) - phys_addr;
88 * Ok, go for it..
90 area = get_vm_area(size, VM_IOREMAP);
91 if (!area)
92 return NULL;
93 area->phys_addr = phys_addr;
94 addr = (void __iomem *) area->addr;
95 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
96 phys_addr, pgprot)) {
97 vunmap((void __force *) addr);
98 return NULL;
101 return (void __iomem *) (offset + (char __iomem *)addr);
104 #define IS_KSEG1(addr) (((unsigned long)(addr) & ~0x1fffffffUL) == KSEG1)
106 void iounmap(volatile void __iomem *addr)
108 if (!IS_KSEG1(addr))
109 vfree((void *) (PAGE_MASK & (unsigned long) addr));