diff options
author | Michal Simek <monstr@monstr.eu> | 2009-05-26 10:30:17 -0400 |
---|---|---|
committer | Michal Simek <monstr@monstr.eu> | 2009-05-26 10:45:18 -0400 |
commit | 1f84e1ea0e87ad659cd6f6a6285d50c73a8d1a24 (patch) | |
tree | 989477a96a5b0fb71d93d669484de4039467ccc0 /arch/microblaze/include/asm/page.h | |
parent | dc95be1f7188f0718ac922b6b6b72406c294d250 (diff) |
microblaze_mmu_v2: pgalloc.h and page.h
Signed-off-by: Michal Simek <monstr@monstr.eu>
Diffstat (limited to 'arch/microblaze/include/asm/page.h')
-rw-r--r-- | arch/microblaze/include/asm/page.h | 166 |
1 files changed, 123 insertions, 43 deletions
diff --git a/arch/microblaze/include/asm/page.h b/arch/microblaze/include/asm/page.h index 7238dcfcc517..210e584974f7 100644 --- a/arch/microblaze/include/asm/page.h +++ b/arch/microblaze/include/asm/page.h | |||
@@ -1,6 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2008 Michal Simek | 2 | * VM ops |
3 | * Copyright (C) 2008 PetaLogix | 3 | * |
4 | * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> | ||
5 | * Copyright (C) 2008-2009 PetaLogix | ||
4 | * Copyright (C) 2006 Atmark Techno, Inc. | 6 | * Copyright (C) 2006 Atmark Techno, Inc. |
5 | * Changes for MMU support: | 7 | * Changes for MMU support: |
6 | * Copyright (C) 2007 Xilinx, Inc. All rights reserved. | 8 | * Copyright (C) 2007 Xilinx, Inc. All rights reserved. |
@@ -15,14 +17,15 @@ | |||
15 | 17 | ||
16 | #include <linux/pfn.h> | 18 | #include <linux/pfn.h> |
17 | #include <asm/setup.h> | 19 | #include <asm/setup.h> |
20 | #include <linux/const.h> | ||
21 | |||
22 | #ifdef __KERNEL__ | ||
18 | 23 | ||
19 | /* PAGE_SHIFT determines the page size */ | 24 | /* PAGE_SHIFT determines the page size */ |
20 | #define PAGE_SHIFT (12) | 25 | #define PAGE_SHIFT (12) |
21 | #define PAGE_SIZE (1UL << PAGE_SHIFT) | 26 | #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT) |
22 | #define PAGE_MASK (~(PAGE_SIZE-1)) | 27 | #define PAGE_MASK (~(PAGE_SIZE-1)) |
23 | 28 | ||
24 | #ifdef __KERNEL__ | ||
25 | |||
26 | #ifndef __ASSEMBLY__ | 29 | #ifndef __ASSEMBLY__ |
27 | 30 | ||
28 | #define PAGE_UP(addr) (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1))) | 31 | #define PAGE_UP(addr) (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1))) |
@@ -35,6 +38,7 @@ | |||
35 | /* align addr on a size boundary - adjust address up if needed */ | 38 | /* align addr on a size boundary - adjust address up if needed */ |
36 | #define _ALIGN(addr, size) _ALIGN_UP(addr, size) | 39 | #define _ALIGN(addr, size) _ALIGN_UP(addr, size) |
37 | 40 | ||
41 | #ifndef CONFIG_MMU | ||
38 | /* | 42 | /* |
39 | * PAGE_OFFSET -- the first address of the first page of memory. When not | 43 | * PAGE_OFFSET -- the first address of the first page of memory. When not |
40 | * using MMU this corresponds to the first free page in physical memory (aligned | 44 | * using MMU this corresponds to the first free page in physical memory (aligned |
@@ -43,15 +47,44 @@ | |||
43 | extern unsigned int __page_offset; | 47 | extern unsigned int __page_offset; |
44 | #define PAGE_OFFSET __page_offset | 48 | #define PAGE_OFFSET __page_offset |
45 | 49 | ||
46 | #define copy_page(to, from) memcpy((to), (from), PAGE_SIZE) | 50 | #else /* CONFIG_MMU */ |
47 | #define get_user_page(vaddr) __get_free_page(GFP_KERNEL) | ||
48 | #define free_user_page(page, addr) free_page(addr) | ||
49 | 51 | ||
50 | #define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE) | 52 | /* |
53 | * PAGE_OFFSET -- the first address of the first page of memory. With MMU | ||
54 | * it is set to the kernel start address (aligned on a page boundary). | ||
55 | * | ||
56 | * CONFIG_KERNEL_START is defined in arch/microblaze/config.in and used | ||
57 | * in arch/microblaze/Makefile. | ||
58 | */ | ||
59 | #define PAGE_OFFSET CONFIG_KERNEL_START | ||
51 | 60 | ||
61 | /* | ||
62 | * MAP_NR -- given an address, calculate the index of the page struct which | ||
63 | * points to the address's page. | ||
64 | */ | ||
65 | #define MAP_NR(addr) (((unsigned long)(addr) - PAGE_OFFSET) >> PAGE_SHIFT) | ||
52 | 66 | ||
53 | #define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE) | 67 | /* |
54 | #define copy_user_page(vto, vfrom, vaddr, topg) \ | 68 | * The basic type of a PTE - 32 bit physical addressing. |
69 | */ | ||
70 | typedef unsigned long pte_basic_t; | ||
71 | #define PTE_SHIFT (PAGE_SHIFT - 2) /* 1024 ptes per page */ | ||
72 | #define PTE_FMT "%.8lx" | ||
73 | |||
74 | #endif /* CONFIG_MMU */ | ||
75 | |||
76 | # ifndef CONFIG_MMU | ||
77 | # define copy_page(to, from) memcpy((to), (from), PAGE_SIZE) | ||
78 | # define get_user_page(vaddr) __get_free_page(GFP_KERNEL) | ||
79 | # define free_user_page(page, addr) free_page(addr) | ||
80 | # else /* CONFIG_MMU */ | ||
81 | extern void copy_page(void *to, void *from); | ||
82 | # endif /* CONFIG_MMU */ | ||
83 | |||
84 | # define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE) | ||
85 | |||
86 | # define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE) | ||
87 | # define copy_user_page(vto, vfrom, vaddr, topg) \ | ||
55 | memcpy((vto), (vfrom), PAGE_SIZE) | 88 | memcpy((vto), (vfrom), PAGE_SIZE) |
56 | 89 | ||
57 | /* | 90 | /* |
@@ -60,21 +93,32 @@ extern unsigned int __page_offset; | |||
60 | typedef struct page *pgtable_t; | 93 | typedef struct page *pgtable_t; |
61 | typedef struct { unsigned long pte; } pte_t; | 94 | typedef struct { unsigned long pte; } pte_t; |
62 | typedef struct { unsigned long pgprot; } pgprot_t; | 95 | typedef struct { unsigned long pgprot; } pgprot_t; |
96 | /* FIXME this can depend on linux kernel version */ | ||
97 | # ifdef CONFIG_MMU | ||
98 | typedef struct { unsigned long pmd; } pmd_t; | ||
99 | typedef struct { unsigned long pgd; } pgd_t; | ||
100 | # else /* CONFIG_MMU */ | ||
63 | typedef struct { unsigned long ste[64]; } pmd_t; | 101 | typedef struct { unsigned long ste[64]; } pmd_t; |
64 | typedef struct { pmd_t pue[1]; } pud_t; | 102 | typedef struct { pmd_t pue[1]; } pud_t; |
65 | typedef struct { pud_t pge[1]; } pgd_t; | 103 | typedef struct { pud_t pge[1]; } pgd_t; |
104 | # endif /* CONFIG_MMU */ | ||
66 | 105 | ||
106 | # define pte_val(x) ((x).pte) | ||
107 | # define pgprot_val(x) ((x).pgprot) | ||
67 | 108 | ||
68 | #define pte_val(x) ((x).pte) | 109 | # ifdef CONFIG_MMU |
69 | #define pgprot_val(x) ((x).pgprot) | 110 | # define pmd_val(x) ((x).pmd) |
70 | #define pmd_val(x) ((x).ste[0]) | 111 | # define pgd_val(x) ((x).pgd) |
71 | #define pud_val(x) ((x).pue[0]) | 112 | # else /* CONFIG_MMU */ |
72 | #define pgd_val(x) ((x).pge[0]) | 113 | # define pmd_val(x) ((x).ste[0]) |
114 | # define pud_val(x) ((x).pue[0]) | ||
115 | # define pgd_val(x) ((x).pge[0]) | ||
116 | # endif /* CONFIG_MMU */ | ||
73 | 117 | ||
74 | #define __pte(x) ((pte_t) { (x) }) | 118 | # define __pte(x) ((pte_t) { (x) }) |
75 | #define __pmd(x) ((pmd_t) { (x) }) | 119 | # define __pmd(x) ((pmd_t) { (x) }) |
76 | #define __pgd(x) ((pgd_t) { (x) }) | 120 | # define __pgd(x) ((pgd_t) { (x) }) |
77 | #define __pgprot(x) ((pgprot_t) { (x) }) | 121 | # define __pgprot(x) ((pgprot_t) { (x) }) |
78 | 122 | ||
79 | /** | 123 | /** |
80 | * Conversions for virtual address, physical address, pfn, and struct | 124 | * Conversions for virtual address, physical address, pfn, and struct |
@@ -94,44 +138,80 @@ extern unsigned long max_low_pfn; | |||
94 | extern unsigned long min_low_pfn; | 138 | extern unsigned long min_low_pfn; |
95 | extern unsigned long max_pfn; | 139 | extern unsigned long max_pfn; |
96 | 140 | ||
97 | #define __pa(vaddr) ((unsigned long) (vaddr)) | 141 | extern unsigned long memory_start; |
98 | #define __va(paddr) ((void *) (paddr)) | 142 | extern unsigned long memory_end; |
143 | extern unsigned long memory_size; | ||
99 | 144 | ||
100 | #define phys_to_pfn(phys) (PFN_DOWN(phys)) | 145 | extern int page_is_ram(unsigned long pfn); |
101 | #define pfn_to_phys(pfn) (PFN_PHYS(pfn)) | ||
102 | 146 | ||
103 | #define virt_to_pfn(vaddr) (phys_to_pfn((__pa(vaddr)))) | 147 | # define phys_to_pfn(phys) (PFN_DOWN(phys)) |
104 | #define pfn_to_virt(pfn) __va(pfn_to_phys((pfn))) | 148 | # define pfn_to_phys(pfn) (PFN_PHYS(pfn)) |
105 | 149 | ||
106 | #define virt_to_page(vaddr) (pfn_to_page(virt_to_pfn(vaddr))) | 150 | # define virt_to_pfn(vaddr) (phys_to_pfn((__pa(vaddr)))) |
107 | #define page_to_virt(page) (pfn_to_virt(page_to_pfn(page))) | 151 | # define pfn_to_virt(pfn) __va(pfn_to_phys((pfn))) |
108 | 152 | ||
109 | #define page_to_phys(page) (pfn_to_phys(page_to_pfn(page))) | 153 | # ifdef CONFIG_MMU |
110 | #define page_to_bus(page) (page_to_phys(page)) | 154 | # define virt_to_page(kaddr) (mem_map + MAP_NR(kaddr)) |
111 | #define phys_to_page(paddr) (pfn_to_page(phys_to_pfn(paddr))) | 155 | # else /* CONFIG_MMU */ |
156 | # define virt_to_page(vaddr) (pfn_to_page(virt_to_pfn(vaddr))) | ||
157 | # define page_to_virt(page) (pfn_to_virt(page_to_pfn(page))) | ||
158 | # define page_to_phys(page) (pfn_to_phys(page_to_pfn(page))) | ||
159 | # define page_to_bus(page) (page_to_phys(page)) | ||
160 | # define phys_to_page(paddr) (pfn_to_page(phys_to_pfn(paddr))) | ||
161 | # endif /* CONFIG_MMU */ | ||
112 | 162 | ||
113 | extern unsigned int memory_start; | 163 | # ifndef CONFIG_MMU |
114 | extern unsigned int memory_end; | 164 | # define pfn_valid(pfn) ((pfn) >= min_low_pfn && (pfn) <= max_mapnr) |
115 | extern unsigned int memory_size; | 165 | # define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) |
166 | # else /* CONFIG_MMU */ | ||
167 | # define ARCH_PFN_OFFSET (memory_start >> PAGE_SHIFT) | ||
168 | # define pfn_valid(pfn) ((pfn) < (max_mapnr + ARCH_PFN_OFFSET)) | ||
169 | # define VALID_PAGE(page) ((page - mem_map) < max_mapnr) | ||
170 | # endif /* CONFIG_MMU */ | ||
116 | 171 | ||
117 | #define pfn_valid(pfn) ((pfn) >= min_low_pfn && (pfn) < max_mapnr) | 172 | # endif /* __ASSEMBLY__ */ |
118 | 173 | ||
119 | #define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) | 174 | #define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr))) |
120 | 175 | ||
121 | #else | ||
122 | #define tophys(rd, rs) (addik rd, rs, 0) | ||
123 | #define tovirt(rd, rs) (addik rd, rs, 0) | ||
124 | #endif /* __ASSEMBLY__ */ | ||
125 | 176 | ||
126 | #define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr))) | 177 | # ifndef CONFIG_MMU |
178 | # define __pa(vaddr) ((unsigned long) (vaddr)) | ||
179 | # define __va(paddr) ((void *) (paddr)) | ||
180 | # else /* CONFIG_MMU */ | ||
181 | # define __pa(x) __virt_to_phys((unsigned long)(x)) | ||
182 | # define __va(x) ((void *)__phys_to_virt((unsigned long)(x))) | ||
183 | # endif /* CONFIG_MMU */ | ||
184 | |||
127 | 185 | ||
128 | /* Convert between virtual and physical address for MMU. */ | 186 | /* Convert between virtual and physical address for MMU. */ |
129 | /* Handle MicroBlaze processor with virtual memory. */ | 187 | /* Handle MicroBlaze processor with virtual memory. */ |
188 | #ifndef CONFIG_MMU | ||
130 | #define __virt_to_phys(addr) addr | 189 | #define __virt_to_phys(addr) addr |
131 | #define __phys_to_virt(addr) addr | 190 | #define __phys_to_virt(addr) addr |
191 | #define tophys(rd, rs) addik rd, rs, 0 | ||
192 | #define tovirt(rd, rs) addik rd, rs, 0 | ||
193 | #else | ||
194 | #define __virt_to_phys(addr) \ | ||
195 | ((addr) + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START) | ||
196 | #define __phys_to_virt(addr) \ | ||
197 | ((addr) + CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR) | ||
198 | #define tophys(rd, rs) \ | ||
199 | addik rd, rs, (CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START) | ||
200 | #define tovirt(rd, rs) \ | ||
201 | addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR) | ||
202 | #endif /* CONFIG_MMU */ | ||
132 | 203 | ||
133 | #define TOPHYS(addr) __virt_to_phys(addr) | 204 | #define TOPHYS(addr) __virt_to_phys(addr) |
134 | 205 | ||
206 | #ifdef CONFIG_MMU | ||
207 | #ifdef CONFIG_CONTIGUOUS_PAGE_ALLOC | ||
208 | #define WANT_PAGE_VIRTUAL 1 /* page alloc 2 relies on this */ | ||
209 | #endif | ||
210 | |||
211 | #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \ | ||
212 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) | ||
213 | #endif /* CONFIG_MMU */ | ||
214 | |||
135 | #endif /* __KERNEL__ */ | 215 | #endif /* __KERNEL__ */ |
136 | 216 | ||
137 | #include <asm-generic/memory_model.h> | 217 | #include <asm-generic/memory_model.h> |