Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 1 | /* |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 2 | * VM ops |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> |
| 5 | * Copyright (C) 2008-2009 PetaLogix |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 6 | * Copyright (C) 2006 Atmark Techno, Inc. |
| 7 | * Changes for MMU support: |
| 8 | * Copyright (C) 2007 Xilinx, Inc. All rights reserved. |
| 9 | * |
| 10 | * This file is subject to the terms and conditions of the GNU General Public |
| 11 | * License. See the file "COPYING" in the main directory of this archive |
| 12 | * for more details. |
| 13 | */ |
| 14 | |
| 15 | #ifndef _ASM_MICROBLAZE_PAGE_H |
| 16 | #define _ASM_MICROBLAZE_PAGE_H |
| 17 | |
| 18 | #include <linux/pfn.h> |
| 19 | #include <asm/setup.h> |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 20 | #include <linux/const.h> |
| 21 | |
| 22 | #ifdef __KERNEL__ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 23 | |
| 24 | /* PAGE_SHIFT determines the page size */ |
| 25 | #define PAGE_SHIFT (12) |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 26 | #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT) |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 27 | #define PAGE_MASK (~(PAGE_SIZE-1)) |
| 28 | |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 29 | #ifndef __ASSEMBLY__ |
| 30 | |
| 31 | #define PAGE_UP(addr) (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1))) |
| 32 | #define PAGE_DOWN(addr) ((addr)&(~((PAGE_SIZE)-1))) |
| 33 | |
| 34 | /* align addr on a size boundary - adjust address up/down if needed */ |
| 35 | #define _ALIGN_UP(addr, size) (((addr)+((size)-1))&(~((size)-1))) |
| 36 | #define _ALIGN_DOWN(addr, size) ((addr)&(~((size)-1))) |
| 37 | |
| 38 | /* align addr on a size boundary - adjust address up if needed */ |
| 39 | #define _ALIGN(addr, size) _ALIGN_UP(addr, size) |
| 40 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 41 | #ifndef CONFIG_MMU |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 42 | /* |
| 43 | * PAGE_OFFSET -- the first address of the first page of memory. When not |
| 44 | * using MMU this corresponds to the first free page in physical memory (aligned |
| 45 | * on a page boundary). |
| 46 | */ |
| 47 | extern unsigned int __page_offset; |
| 48 | #define PAGE_OFFSET __page_offset |
| 49 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 50 | #else /* CONFIG_MMU */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 51 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 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 |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 60 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 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) |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 66 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 67 | /* |
| 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) \ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 88 | memcpy((vto), (vfrom), PAGE_SIZE) |
| 89 | |
| 90 | /* |
| 91 | * These are used to make use of C type-checking.. |
| 92 | */ |
| 93 | typedef struct page *pgtable_t; |
| 94 | typedef struct { unsigned long pte; } pte_t; |
| 95 | typedef struct { unsigned long pgprot; } pgprot_t; |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 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 */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 101 | typedef struct { unsigned long ste[64]; } pmd_t; |
| 102 | typedef struct { pmd_t pue[1]; } pud_t; |
| 103 | typedef struct { pud_t pge[1]; } pgd_t; |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 104 | # endif /* CONFIG_MMU */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 105 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 106 | # define pte_val(x) ((x).pte) |
| 107 | # define pgprot_val(x) ((x).pgprot) |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 108 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 109 | # ifdef CONFIG_MMU |
| 110 | # define pmd_val(x) ((x).pmd) |
| 111 | # define pgd_val(x) ((x).pgd) |
| 112 | # else /* CONFIG_MMU */ |
| 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 */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 117 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 118 | # define __pte(x) ((pte_t) { (x) }) |
| 119 | # define __pmd(x) ((pmd_t) { (x) }) |
| 120 | # define __pgd(x) ((pgd_t) { (x) }) |
| 121 | # define __pgprot(x) ((pgprot_t) { (x) }) |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 122 | |
| 123 | /** |
| 124 | * Conversions for virtual address, physical address, pfn, and struct |
| 125 | * page are defined in the following files. |
| 126 | * |
| 127 | * virt -+ |
| 128 | * | asm-microblaze/page.h |
| 129 | * phys -+ |
| 130 | * | linux/pfn.h |
| 131 | * pfn -+ |
| 132 | * | asm-generic/memory_model.h |
| 133 | * page -+ |
| 134 | * |
| 135 | */ |
| 136 | |
| 137 | extern unsigned long max_low_pfn; |
| 138 | extern unsigned long min_low_pfn; |
| 139 | extern unsigned long max_pfn; |
| 140 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 141 | extern unsigned long memory_start; |
| 142 | extern unsigned long memory_end; |
| 143 | extern unsigned long memory_size; |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 144 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 145 | extern int page_is_ram(unsigned long pfn); |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 146 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 147 | # define phys_to_pfn(phys) (PFN_DOWN(phys)) |
| 148 | # define pfn_to_phys(pfn) (PFN_PHYS(pfn)) |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 149 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 150 | # define virt_to_pfn(vaddr) (phys_to_pfn((__pa(vaddr)))) |
| 151 | # define pfn_to_virt(pfn) __va(pfn_to_phys((pfn))) |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 152 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 153 | # ifdef CONFIG_MMU |
| 154 | # define virt_to_page(kaddr) (mem_map + MAP_NR(kaddr)) |
| 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 */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 162 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 163 | # ifndef CONFIG_MMU |
| 164 | # define pfn_valid(pfn) ((pfn) >= min_low_pfn && (pfn) <= max_mapnr) |
| 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 */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 171 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 172 | # endif /* __ASSEMBLY__ */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 173 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 174 | #define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr))) |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 175 | |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 176 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 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 */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 184 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 185 | |
| 186 | /* Convert between virtual and physical address for MMU. */ |
| 187 | /* Handle MicroBlaze processor with virtual memory. */ |
| 188 | #ifndef CONFIG_MMU |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 189 | #define __virt_to_phys(addr) addr |
| 190 | #define __phys_to_virt(addr) addr |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 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 */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 203 | |
| 204 | #define TOPHYS(addr) __virt_to_phys(addr) |
| 205 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 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 | |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 215 | #endif /* __KERNEL__ */ |
| 216 | |
| 217 | #include <asm-generic/memory_model.h> |
Arnd Bergmann | 5b17e1c | 2009-05-13 22:56:30 +0000 | [diff] [blame] | 218 | #include <asm-generic/getorder.h> |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 219 | |
| 220 | #endif /* _ASM_MICROBLAZE_PAGE_H */ |