[PARISC] Fix and cleanup ioremap.c to work with 4level-fixup.h

Fixup ioremap a bit. It seems to work on 32-bit kernels, but fails
miserably on the first ioremapped access on 64-bit kernels. Also, having
STI enabled causes it to fail. Probably because we're passing an ioremapped
region to a real-mode STI call...

Signed-off-by: Kyle McMartin <kyle@parisc-linux.org>

authored by

Kyle McMartin and committed by
Kyle McMartin
e0565a1c 45dbe914

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