diff options
Diffstat (limited to 'arch/parisc/mm/ioremap.c')
-rw-r--r-- | arch/parisc/mm/ioremap.c | 100 |
1 files changed, 63 insertions, 37 deletions
diff --git a/arch/parisc/mm/ioremap.c b/arch/parisc/mm/ioremap.c index 5c7a1b3b9326..edd9a9559cba 100644 --- a/arch/parisc/mm/ioremap.c +++ b/arch/parisc/mm/ioremap.c | |||
@@ -1,12 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * arch/parisc/mm/ioremap.c | 2 | * arch/parisc/mm/ioremap.c |
3 | * | 3 | * |
4 | * Re-map IO memory to kernel address space so that we can access it. | ||
5 | * This is needed for high PCI addresses that aren't mapped in the | ||
6 | * 640k-1MB IO memory area on PC's | ||
7 | * | ||
8 | * (C) Copyright 1995 1996 Linus Torvalds | 4 | * (C) Copyright 1995 1996 Linus Torvalds |
9 | * (C) Copyright 2001 Helge Deller <deller@gmx.de> | 5 | * (C) Copyright 2001 Helge Deller <deller@gmx.de> |
6 | * (C) Copyright 2005 Kyle McMartin <kyle@parisc-linux.org> | ||
10 | */ | 7 | */ |
11 | 8 | ||
12 | #include <linux/vmalloc.h> | 9 | #include <linux/vmalloc.h> |
@@ -14,81 +11,107 @@ | |||
14 | #include <linux/module.h> | 11 | #include <linux/module.h> |
15 | #include <asm/io.h> | 12 | #include <asm/io.h> |
16 | #include <asm/pgalloc.h> | 13 | #include <asm/pgalloc.h> |
14 | #include <asm/tlbflush.h> | ||
15 | #include <asm/cacheflush.h> | ||
17 | 16 | ||
18 | static inline void remap_area_pte(pte_t * pte, unsigned long address, unsigned long size, | 17 | static inline void |
19 | unsigned long phys_addr, unsigned long flags) | 18 | remap_area_pte(pte_t *pte, unsigned long address, unsigned long size, |
19 | unsigned long phys_addr, unsigned long flags) | ||
20 | { | 20 | { |
21 | unsigned long end; | 21 | unsigned long end, pfn; |
22 | pgprot_t pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | | ||
23 | _PAGE_ACCESSED | flags); | ||
22 | 24 | ||
23 | address &= ~PMD_MASK; | 25 | address &= ~PMD_MASK; |
26 | |||
24 | end = address + size; | 27 | end = address + size; |
25 | if (end > PMD_SIZE) | 28 | if (end > PMD_SIZE) |
26 | end = PMD_SIZE; | 29 | end = PMD_SIZE; |
27 | if (address >= end) | 30 | |
28 | BUG(); | 31 | BUG_ON(address >= end); |
32 | |||
33 | pfn = phys_addr >> PAGE_SHIFT; | ||
29 | do { | 34 | do { |
30 | if (!pte_none(*pte)) { | 35 | BUG_ON(!pte_none(*pte)); |
31 | printk(KERN_ERR "remap_area_pte: page already exists\n"); | 36 | |
32 | BUG(); | 37 | set_pte(pte, pfn_pte(pfn, pgprot)); |
33 | } | 38 | |
34 | set_pte(pte, mk_pte_phys(phys_addr, __pgprot(_PAGE_PRESENT | _PAGE_RW | | ||
35 | _PAGE_DIRTY | _PAGE_ACCESSED | flags))); | ||
36 | address += PAGE_SIZE; | 39 | address += PAGE_SIZE; |
37 | phys_addr += PAGE_SIZE; | 40 | pfn++; |
38 | pte++; | 41 | pte++; |
39 | } while (address && (address < end)); | 42 | } while (address && (address < end)); |
40 | } | 43 | } |
41 | 44 | ||
42 | static inline int remap_area_pmd(pmd_t * pmd, unsigned long address, unsigned long size, | 45 | static inline int |
43 | unsigned long phys_addr, unsigned long flags) | 46 | remap_area_pmd(pmd_t *pmd, unsigned long address, unsigned long size, |
47 | unsigned long phys_addr, unsigned long flags) | ||
44 | { | 48 | { |
45 | unsigned long end; | 49 | unsigned long end; |
46 | 50 | ||
47 | address &= ~PGDIR_MASK; | 51 | address &= ~PGDIR_MASK; |
52 | |||
48 | end = address + size; | 53 | end = address + size; |
49 | if (end > PGDIR_SIZE) | 54 | if (end > PGDIR_SIZE) |
50 | end = PGDIR_SIZE; | 55 | end = PGDIR_SIZE; |
56 | |||
57 | BUG_ON(address >= end); | ||
58 | |||
51 | phys_addr -= address; | 59 | phys_addr -= address; |
52 | if (address >= end) | ||
53 | BUG(); | ||
54 | do { | 60 | do { |
55 | pte_t * pte = pte_alloc_kernel(pmd, address); | 61 | pte_t *pte = pte_alloc_kernel(pmd, address); |
56 | if (!pte) | 62 | if (!pte) |
57 | return -ENOMEM; | 63 | return -ENOMEM; |
58 | remap_area_pte(pte, address, end - address, address + phys_addr, flags); | 64 | |
65 | remap_area_pte(pte, address, end - address, | ||
66 | address + phys_addr, flags); | ||
67 | |||
59 | address = (address + PMD_SIZE) & PMD_MASK; | 68 | address = (address + PMD_SIZE) & PMD_MASK; |
60 | pmd++; | 69 | pmd++; |
61 | } while (address && (address < end)); | 70 | } while (address && (address < end)); |
71 | |||
62 | return 0; | 72 | return 0; |
63 | } | 73 | } |
64 | 74 | ||
65 | #if (USE_HPPA_IOREMAP) | 75 | #if USE_HPPA_IOREMAP |
66 | static int remap_area_pages(unsigned long address, unsigned long phys_addr, | 76 | static int |
67 | unsigned long size, unsigned long flags) | 77 | remap_area_pages(unsigned long address, unsigned long phys_addr, |
78 | unsigned long size, unsigned long flags) | ||
68 | { | 79 | { |
69 | int error; | 80 | pgd_t *dir; |
70 | pgd_t * dir; | 81 | int error = 0; |
71 | unsigned long end = address + size; | 82 | unsigned long end = address + size; |
72 | 83 | ||
84 | BUG_ON(address >= end); | ||
85 | |||
73 | phys_addr -= address; | 86 | phys_addr -= address; |
74 | dir = pgd_offset(&init_mm, address); | 87 | dir = pgd_offset_k(address); |
88 | |||
75 | flush_cache_all(); | 89 | flush_cache_all(); |
76 | if (address >= end) | 90 | |
77 | BUG(); | ||
78 | do { | 91 | do { |
92 | pud_t *pud; | ||
79 | pmd_t *pmd; | 93 | pmd_t *pmd; |
80 | pmd = pmd_alloc(&init_mm, dir, address); | 94 | |
81 | error = -ENOMEM; | 95 | error = -ENOMEM; |
96 | pud = pud_alloc(&init_mm, dir, address); | ||
97 | if (!pud) | ||
98 | break; | ||
99 | |||
100 | pmd = pmd_alloc(&init_mm, pud, address); | ||
82 | if (!pmd) | 101 | if (!pmd) |
83 | break; | 102 | break; |
103 | |||
84 | if (remap_area_pmd(pmd, address, end - address, | 104 | if (remap_area_pmd(pmd, address, end - address, |
85 | phys_addr + address, flags)) | 105 | phys_addr + address, flags)) |
86 | break; | 106 | break; |
107 | |||
87 | error = 0; | 108 | error = 0; |
88 | address = (address + PGDIR_SIZE) & PGDIR_MASK; | 109 | address = (address + PGDIR_SIZE) & PGDIR_MASK; |
89 | dir++; | 110 | dir++; |
90 | } while (address && (address < end)); | 111 | } while (address && (address < end)); |
112 | |||
91 | flush_tlb_all(); | 113 | flush_tlb_all(); |
114 | |||
92 | return error; | 115 | return error; |
93 | } | 116 | } |
94 | #endif /* USE_HPPA_IOREMAP */ | 117 | #endif /* USE_HPPA_IOREMAP */ |
@@ -123,8 +146,7 @@ EXPORT_SYMBOL(__raw_bad_addr); | |||
123 | 146 | ||
124 | /* | 147 | /* |
125 | * Remap an arbitrary physical address space into the kernel virtual | 148 | * Remap an arbitrary physical address space into the kernel virtual |
126 | * address space. Needed when the kernel wants to access high addresses | 149 | * address space. |
127 | * directly. | ||
128 | * | 150 | * |
129 | * NOTE! We need to allow non-page-aligned mappings too: we will obviously | 151 | * NOTE! We need to allow non-page-aligned mappings too: we will obviously |
130 | * have to convert them into an offset in a page-aligned mapping, but the | 152 | * have to convert them into an offset in a page-aligned mapping, but the |
@@ -148,8 +170,8 @@ void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned l | |||
148 | #endif | 170 | #endif |
149 | 171 | ||
150 | #else | 172 | #else |
151 | void * addr; | 173 | void *addr; |
152 | struct vm_struct * area; | 174 | struct vm_struct *area; |
153 | unsigned long offset, last_addr; | 175 | unsigned long offset, last_addr; |
154 | 176 | ||
155 | /* Don't allow wraparound or zero size */ | 177 | /* Don't allow wraparound or zero size */ |
@@ -167,9 +189,11 @@ void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned l | |||
167 | t_addr = __va(phys_addr); | 189 | t_addr = __va(phys_addr); |
168 | t_end = t_addr + (size - 1); | 190 | t_end = t_addr + (size - 1); |
169 | 191 | ||
170 | for(page = virt_to_page(t_addr); page <= virt_to_page(t_end); page++) | 192 | for (page = virt_to_page(t_addr); |
193 | page <= virt_to_page(t_end); page++) { | ||
171 | if(!PageReserved(page)) | 194 | if(!PageReserved(page)) |
172 | return NULL; | 195 | return NULL; |
196 | } | ||
173 | } | 197 | } |
174 | 198 | ||
175 | /* | 199 | /* |
@@ -185,11 +209,13 @@ void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned l | |||
185 | area = get_vm_area(size, VM_IOREMAP); | 209 | area = get_vm_area(size, VM_IOREMAP); |
186 | if (!area) | 210 | if (!area) |
187 | return NULL; | 211 | return NULL; |
212 | |||
188 | addr = area->addr; | 213 | addr = area->addr; |
189 | if (remap_area_pages((unsigned long) addr, phys_addr, size, flags)) { | 214 | if (remap_area_pages((unsigned long) addr, phys_addr, size, flags)) { |
190 | vfree(addr); | 215 | vfree(addr); |
191 | return NULL; | 216 | return NULL; |
192 | } | 217 | } |
218 | |||
193 | return (void __iomem *) (offset + (char *)addr); | 219 | return (void __iomem *) (offset + (char *)addr); |
194 | #endif | 220 | #endif |
195 | } | 221 | } |