blob: 838d0259cd2715e034ce7787eba12ac4cc7ae9c4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/parisc/mm/ioremap.c
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * (C) Copyright 1995 1996 Linus Torvalds
Helge Dellerb2d6b9f2006-03-27 19:52:14 +00005 * (C) Copyright 2001-2006 Helge Deller <deller@gmx.de>
Kyle McMartine0565a12006-01-10 20:47:52 -05006 * (C) Copyright 2005 Kyle McMartin <kyle@parisc-linux.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
9#include <linux/vmalloc.h>
10#include <linux/errno.h>
11#include <linux/module.h>
Haavard Skinnemoene34067f2006-12-08 02:38:05 -080012#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/pgalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015/*
16 * Generic mapping function (not visible outside):
17 */
18
19/*
20 * Remap an arbitrary physical address space into the kernel virtual
Kyle McMartine0565a12006-01-10 20:47:52 -050021 * address space.
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
23 * NOTE! We need to allow non-page-aligned mappings too: we will obviously
24 * have to convert them into an offset in a page-aligned mapping, but the
25 * caller shouldn't need to know that small detail.
26 */
27void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned long flags)
28{
Matthew Wilcoxe51ec242006-11-05 15:24:48 -070029 void __iomem *addr;
Helge Dellercb4ab592006-03-23 00:40:10 -070030 struct vm_struct *area;
31 unsigned long offset, last_addr;
Haavard Skinnemoene34067f2006-12-08 02:38:05 -080032 pgprot_t pgprot;
Helge Dellercb4ab592006-03-23 00:40:10 -070033
Helge Deller29ef82952006-03-23 00:32:46 -070034#ifdef CONFIG_EISA
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 unsigned long end = phys_addr + size - 1;
36 /* Support EISA addresses */
Helge Deller10267cd2006-03-26 01:54:16 -070037 if ((phys_addr >= 0x00080000 && end < 0x000fffff) ||
38 (phys_addr >= 0x00500000 && end < 0x03bfffff)) {
39 phys_addr |= F_EXTEND(0xfc000000);
Helge Dellerb2d6b9f2006-03-27 19:52:14 +000040 flags |= _PAGE_NO_CACHE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#endif
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 /* Don't allow wraparound or zero size */
45 last_addr = phys_addr + size - 1;
46 if (!size || last_addr < phys_addr)
47 return NULL;
48
49 /*
50 * Don't allow anybody to remap normal RAM that we're using..
51 */
52 if (phys_addr < virt_to_phys(high_memory)) {
53 char *t_addr, *t_end;
54 struct page *page;
55
56 t_addr = __va(phys_addr);
57 t_end = t_addr + (size - 1);
58
Kyle McMartine0565a12006-01-10 20:47:52 -050059 for (page = virt_to_page(t_addr);
60 page <= virt_to_page(t_end); page++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 if(!PageReserved(page))
62 return NULL;
Kyle McMartine0565a12006-01-10 20:47:52 -050063 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 }
65
Haavard Skinnemoene34067f2006-12-08 02:38:05 -080066 pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY |
67 _PAGE_ACCESSED | flags);
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 /*
70 * Mappings have to be page-aligned
71 */
72 offset = phys_addr & ~PAGE_MASK;
73 phys_addr &= PAGE_MASK;
Florian Zumbiehla292dfa2010-08-11 14:17:33 -070074 size = PAGE_ALIGN(last_addr + 1) - phys_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 /*
77 * Ok, go for it..
78 */
79 area = get_vm_area(size, VM_IOREMAP);
80 if (!area)
81 return NULL;
Kyle McMartine0565a12006-01-10 20:47:52 -050082
Matthew Wilcoxe51ec242006-11-05 15:24:48 -070083 addr = (void __iomem *) area->addr;
Haavard Skinnemoene34067f2006-12-08 02:38:05 -080084 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
85 phys_addr, pgprot)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 vfree(addr);
87 return NULL;
88 }
Kyle McMartine0565a12006-01-10 20:47:52 -050089
Matthew Wilcoxe51ec242006-11-05 15:24:48 -070090 return (void __iomem *) (offset + (char __iomem *)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
Kyle McMartind345fd32006-03-29 15:18:32 -070092EXPORT_SYMBOL(__ioremap);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Matthew Wilcox01232e92006-09-19 16:37:01 -060094void iounmap(const volatile void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 if (addr > high_memory)
97 return vfree((void *) (PAGE_MASK & (unsigned long __force) addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
Kyle McMartind345fd32006-03-29 15:18:32 -070099EXPORT_SYMBOL(iounmap);