Blame view

arch/parisc/mm/ioremap.c 2.36 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
  /*
   * arch/parisc/mm/ioremap.c
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
   * (C) Copyright 1995 1996 Linus Torvalds
b2d6b9fb3   Helge Deller   [PARISC] EISA reg...
5
   * (C) Copyright 2001-2006 Helge Deller <deller@gmx.de>
e0565a1c8   Kyle McMartin   [PARISC] Fix and ...
6
   * (C) Copyright 2005 Kyle McMartin <kyle@parisc-linux.org>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
9
10
11
   */
  
  #include <linux/vmalloc.h>
  #include <linux/errno.h>
  #include <linux/module.h>
e34067fdd   Haavard Skinnemoen   [PATCH] Generic i...
12
  #include <linux/io.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
  #include <asm/pgalloc.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15
16
17
18
19
20
  /*
   * Generic mapping function (not visible outside):
   */
  
  /*
   * Remap an arbitrary physical address space into the kernel virtual
e0565a1c8   Kyle McMartin   [PARISC] Fix and ...
21
   * address space.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
23
24
25
26
27
28
   *
   * NOTE! We need to allow non-page-aligned mappings too: we will obviously
   * have to convert them into an offset in a page-aligned mapping, but the
   * caller shouldn't need to know that small detail.
   */
  void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned long flags)
  {
e51ec2417   Matthew Wilcox   [PARISC] more spa...
29
  	void __iomem *addr;
cb4ab59cd   Helge Deller   [PARISC] Temporar...
30
31
  	struct vm_struct *area;
  	unsigned long offset, last_addr;
e34067fdd   Haavard Skinnemoen   [PATCH] Generic i...
32
  	pgprot_t pgprot;
cb4ab59cd   Helge Deller   [PARISC] Temporar...
33

29ef82953   Helge Deller   [PARISC] Enable i...
34
  #ifdef CONFIG_EISA
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
36
  	unsigned long end = phys_addr + size - 1;
  	/* Support EISA addresses */
10267cdd0   Helge Deller   [PARISC] Fixup CO...
37
38
39
  	if ((phys_addr >= 0x00080000 && end < 0x000fffff) ||
  	    (phys_addr >= 0x00500000 && end < 0x03bfffff)) {
  		phys_addr |= F_EXTEND(0xfc000000);
b2d6b9fb3   Helge Deller   [PARISC] EISA reg...
40
  		flags |= _PAGE_NO_CACHE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  	/* Don't allow wraparound or zero size */
  	last_addr = phys_addr + size - 1;
  	if (!size || last_addr < phys_addr)
  		return NULL;
  
  	/*
  	 * Don't allow anybody to remap normal RAM that we're using..
  	 */
  	if (phys_addr < virt_to_phys(high_memory)) {
  		char *t_addr, *t_end;
  		struct page *page;
  
  		t_addr = __va(phys_addr);
  		t_end = t_addr + (size - 1);
  	   
e0565a1c8   Kyle McMartin   [PARISC] Fix and ...
58
59
  		for (page = virt_to_page(t_addr); 
  		     page <= virt_to_page(t_end); page++) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60
61
  			if(!PageReserved(page))
  				return NULL;
e0565a1c8   Kyle McMartin   [PARISC] Fix and ...
62
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63
  	}
e34067fdd   Haavard Skinnemoen   [PATCH] Generic i...
64
65
  	pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY |
  			  _PAGE_ACCESSED | flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
67
68
69
70
  	/*
  	 * Mappings have to be page-aligned
  	 */
  	offset = phys_addr & ~PAGE_MASK;
  	phys_addr &= PAGE_MASK;
a292dfa01   Florian Zumbiehl   parisc: fix wrong...
71
  	size = PAGE_ALIGN(last_addr + 1) - phys_addr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
73
74
75
76
77
78
  
  	/*
  	 * Ok, go for it..
  	 */
  	area = get_vm_area(size, VM_IOREMAP);
  	if (!area)
  		return NULL;
e0565a1c8   Kyle McMartin   [PARISC] Fix and ...
79

e51ec2417   Matthew Wilcox   [PARISC] more spa...
80
  	addr = (void __iomem *) area->addr;
e34067fdd   Haavard Skinnemoen   [PATCH] Generic i...
81
82
  	if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
  			       phys_addr, pgprot)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
84
85
  		vfree(addr);
  		return NULL;
  	}
e0565a1c8   Kyle McMartin   [PARISC] Fix and ...
86

e51ec2417   Matthew Wilcox   [PARISC] more spa...
87
  	return (void __iomem *) (offset + (char __iomem *)addr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88
  }
d345fd362   Kyle McMartin   [PARISC] Move ior...
89
  EXPORT_SYMBOL(__ioremap);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90

01232e932   Matthew Wilcox   [PARISC] Fix ioun...
91
  void iounmap(const volatile void __iomem *addr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
93
94
  	if (addr > high_memory)
  		return vfree((void *) (PAGE_MASK & (unsigned long __force) addr));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95
  }
d345fd362   Kyle McMartin   [PARISC] Move ior...
96
  EXPORT_SYMBOL(iounmap);