diff options
Diffstat (limited to 'arch/sh/mm/ioremap.c')
-rw-r--r-- | arch/sh/mm/ioremap.c | 92 |
1 files changed, 4 insertions, 88 deletions
diff --git a/arch/sh/mm/ioremap.c b/arch/sh/mm/ioremap.c index a9fe80cfc233..90b494a0cf45 100644 --- a/arch/sh/mm/ioremap.c +++ b/arch/sh/mm/ioremap.c | |||
@@ -16,99 +16,13 @@ | |||
16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
17 | #include <linux/mm.h> | 17 | #include <linux/mm.h> |
18 | #include <linux/pci.h> | 18 | #include <linux/pci.h> |
19 | #include <asm/io.h> | 19 | #include <linux/io.h> |
20 | #include <asm/page.h> | 20 | #include <asm/page.h> |
21 | #include <asm/pgalloc.h> | 21 | #include <asm/pgalloc.h> |
22 | #include <asm/addrspace.h> | 22 | #include <asm/addrspace.h> |
23 | #include <asm/cacheflush.h> | 23 | #include <asm/cacheflush.h> |
24 | #include <asm/tlbflush.h> | 24 | #include <asm/tlbflush.h> |
25 | 25 | ||
26 | static inline void remap_area_pte(pte_t * pte, unsigned long address, | ||
27 | unsigned long size, unsigned long phys_addr, unsigned long flags) | ||
28 | { | ||
29 | unsigned long end; | ||
30 | unsigned long pfn; | ||
31 | pgprot_t pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW | | ||
32 | _PAGE_DIRTY | _PAGE_ACCESSED | | ||
33 | _PAGE_HW_SHARED | _PAGE_FLAGS_HARD | flags); | ||
34 | |||
35 | address &= ~PMD_MASK; | ||
36 | end = address + size; | ||
37 | if (end > PMD_SIZE) | ||
38 | end = PMD_SIZE; | ||
39 | if (address >= end) | ||
40 | BUG(); | ||
41 | pfn = phys_addr >> PAGE_SHIFT; | ||
42 | do { | ||
43 | if (!pte_none(*pte)) { | ||
44 | printk("remap_area_pte: page already exists\n"); | ||
45 | BUG(); | ||
46 | } | ||
47 | set_pte(pte, pfn_pte(pfn, pgprot)); | ||
48 | address += PAGE_SIZE; | ||
49 | pfn++; | ||
50 | pte++; | ||
51 | } while (address && (address < end)); | ||
52 | } | ||
53 | |||
54 | static inline int remap_area_pmd(pmd_t * pmd, unsigned long address, | ||
55 | unsigned long size, unsigned long phys_addr, unsigned long flags) | ||
56 | { | ||
57 | unsigned long end; | ||
58 | |||
59 | address &= ~PGDIR_MASK; | ||
60 | end = address + size; | ||
61 | if (end > PGDIR_SIZE) | ||
62 | end = PGDIR_SIZE; | ||
63 | phys_addr -= address; | ||
64 | if (address >= end) | ||
65 | BUG(); | ||
66 | do { | ||
67 | pte_t * pte = pte_alloc_kernel(pmd, address); | ||
68 | if (!pte) | ||
69 | return -ENOMEM; | ||
70 | remap_area_pte(pte, address, end - address, address + phys_addr, flags); | ||
71 | address = (address + PMD_SIZE) & PMD_MASK; | ||
72 | pmd++; | ||
73 | } while (address && (address < end)); | ||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | int remap_area_pages(unsigned long address, unsigned long phys_addr, | ||
78 | unsigned long size, unsigned long flags) | ||
79 | { | ||
80 | int error; | ||
81 | pgd_t * dir; | ||
82 | unsigned long end = address + size; | ||
83 | |||
84 | phys_addr -= address; | ||
85 | dir = pgd_offset_k(address); | ||
86 | flush_cache_all(); | ||
87 | if (address >= end) | ||
88 | BUG(); | ||
89 | do { | ||
90 | pud_t *pud; | ||
91 | pmd_t *pmd; | ||
92 | |||
93 | error = -ENOMEM; | ||
94 | |||
95 | pud = pud_alloc(&init_mm, dir, address); | ||
96 | if (!pud) | ||
97 | break; | ||
98 | pmd = pmd_alloc(&init_mm, pud, address); | ||
99 | if (!pmd) | ||
100 | break; | ||
101 | if (remap_area_pmd(pmd, address, end - address, | ||
102 | phys_addr + address, flags)) | ||
103 | break; | ||
104 | error = 0; | ||
105 | address = (address + PGDIR_SIZE) & PGDIR_MASK; | ||
106 | dir++; | ||
107 | } while (address && (address < end)); | ||
108 | flush_tlb_all(); | ||
109 | return error; | ||
110 | } | ||
111 | |||
112 | /* | 26 | /* |
113 | * Remap an arbitrary physical address space into the kernel virtual | 27 | * Remap an arbitrary physical address space into the kernel virtual |
114 | * address space. Needed when the kernel wants to access high addresses | 28 | * address space. Needed when the kernel wants to access high addresses |
@@ -123,6 +37,7 @@ void __iomem *__ioremap(unsigned long phys_addr, unsigned long size, | |||
123 | { | 37 | { |
124 | struct vm_struct * area; | 38 | struct vm_struct * area; |
125 | unsigned long offset, last_addr, addr, orig_addr; | 39 | unsigned long offset, last_addr, addr, orig_addr; |
40 | pgprot_t pgprot; | ||
126 | 41 | ||
127 | /* Don't allow wraparound or zero size */ | 42 | /* Don't allow wraparound or zero size */ |
128 | last_addr = phys_addr + size - 1; | 43 | last_addr = phys_addr + size - 1; |
@@ -192,8 +107,9 @@ void __iomem *__ioremap(unsigned long phys_addr, unsigned long size, | |||
192 | } | 107 | } |
193 | #endif | 108 | #endif |
194 | 109 | ||
110 | pgprot = __pgprot(pgprot_val(PAGE_KERNEL_NOCACHE) | flags); | ||
195 | if (likely(size)) | 111 | if (likely(size)) |
196 | if (remap_area_pages(addr, phys_addr, size, flags)) { | 112 | if (ioremap_page_range(addr, addr + size, phys_addr, pgprot)) { |
197 | vunmap((void *)orig_addr); | 113 | vunmap((void *)orig_addr); |
198 | return NULL; | 114 | return NULL; |
199 | } | 115 | } |