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> |
John Williams | a125397 | 2009-06-22 01:38:13 +0200 | [diff] [blame] | 20 | #include <asm/asm-compat.h> |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 21 | #include <linux/const.h> |
| 22 | |
| 23 | #ifdef __KERNEL__ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 24 | |
| 25 | /* PAGE_SHIFT determines the page size */ |
Steven J. Magnani | ba9c4f8 | 2010-05-13 10:48:27 -0500 | [diff] [blame] | 26 | #if defined(CONFIG_MICROBLAZE_32K_PAGES) |
| 27 | #define PAGE_SHIFT 15 |
| 28 | #elif defined(CONFIG_MICROBLAZE_16K_PAGES) |
| 29 | #define PAGE_SHIFT 14 |
| 30 | #elif defined(CONFIG_MICROBLAZE_8K_PAGES) |
| 31 | #define PAGE_SHIFT 13 |
| 32 | #else |
| 33 | #define PAGE_SHIFT 12 |
| 34 | #endif |
| 35 | #define PAGE_SIZE (ASM_CONST(1) << PAGE_SHIFT) |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 36 | #define PAGE_MASK (~(PAGE_SIZE-1)) |
| 37 | |
John Williams | a125397 | 2009-06-22 01:38:13 +0200 | [diff] [blame] | 38 | #define LOAD_OFFSET ASM_CONST((CONFIG_KERNEL_START-CONFIG_KERNEL_BASE_ADDR)) |
| 39 | |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 40 | #ifndef __ASSEMBLY__ |
| 41 | |
Michal Simek | de925d9 | 2010-04-26 13:49:01 +0200 | [diff] [blame] | 42 | /* MS be sure that SLAB allocates aligned objects */ |
FUJITA Tomonori | a6eb9fe | 2010-08-10 18:03:22 -0700 | [diff] [blame] | 43 | #define ARCH_DMA_MINALIGN L1_CACHE_BYTES |
Michal Simek | de925d9 | 2010-04-26 13:49:01 +0200 | [diff] [blame] | 44 | |
Michal Simek | ffe57d0 | 2010-06-07 15:17:55 +0200 | [diff] [blame] | 45 | #define ARCH_SLAB_MINALIGN L1_CACHE_BYTES |
| 46 | |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 47 | #define PAGE_UP(addr) (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1))) |
| 48 | #define PAGE_DOWN(addr) ((addr)&(~((PAGE_SIZE)-1))) |
| 49 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 50 | #ifndef CONFIG_MMU |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 51 | /* |
| 52 | * PAGE_OFFSET -- the first address of the first page of memory. When not |
| 53 | * using MMU this corresponds to the first free page in physical memory (aligned |
| 54 | * on a page boundary). |
| 55 | */ |
| 56 | extern unsigned int __page_offset; |
| 57 | #define PAGE_OFFSET __page_offset |
| 58 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 59 | #else /* CONFIG_MMU */ |
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 | * PAGE_OFFSET -- the first address of the first page of memory. With MMU |
| 63 | * it is set to the kernel start address (aligned on a page boundary). |
| 64 | * |
| 65 | * CONFIG_KERNEL_START is defined in arch/microblaze/config.in and used |
| 66 | * in arch/microblaze/Makefile. |
| 67 | */ |
| 68 | #define PAGE_OFFSET CONFIG_KERNEL_START |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 69 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 70 | /* |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 71 | * The basic type of a PTE - 32 bit physical addressing. |
| 72 | */ |
| 73 | typedef unsigned long pte_basic_t; |
| 74 | #define PTE_SHIFT (PAGE_SHIFT - 2) /* 1024 ptes per page */ |
| 75 | #define PTE_FMT "%.8lx" |
| 76 | |
| 77 | #endif /* CONFIG_MMU */ |
| 78 | |
Michal Simek | 43f2a6e | 2010-04-22 07:28:48 +0200 | [diff] [blame] | 79 | # define copy_page(to, from) memcpy((to), (from), PAGE_SIZE) |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 80 | # define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE) |
| 81 | |
| 82 | # define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE) |
| 83 | # define copy_user_page(vto, vfrom, vaddr, topg) \ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 84 | memcpy((vto), (vfrom), PAGE_SIZE) |
| 85 | |
| 86 | /* |
| 87 | * These are used to make use of C type-checking.. |
| 88 | */ |
| 89 | typedef struct page *pgtable_t; |
| 90 | typedef struct { unsigned long pte; } pte_t; |
| 91 | typedef struct { unsigned long pgprot; } pgprot_t; |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 92 | /* FIXME this can depend on linux kernel version */ |
| 93 | # ifdef CONFIG_MMU |
| 94 | typedef struct { unsigned long pmd; } pmd_t; |
| 95 | typedef struct { unsigned long pgd; } pgd_t; |
| 96 | # else /* CONFIG_MMU */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 97 | typedef struct { unsigned long ste[64]; } pmd_t; |
| 98 | typedef struct { pmd_t pue[1]; } pud_t; |
| 99 | typedef struct { pud_t pge[1]; } pgd_t; |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 100 | # endif /* CONFIG_MMU */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 101 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 102 | # define pte_val(x) ((x).pte) |
| 103 | # define pgprot_val(x) ((x).pgprot) |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 104 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 105 | # ifdef CONFIG_MMU |
| 106 | # define pmd_val(x) ((x).pmd) |
| 107 | # define pgd_val(x) ((x).pgd) |
| 108 | # else /* CONFIG_MMU */ |
| 109 | # define pmd_val(x) ((x).ste[0]) |
| 110 | # define pud_val(x) ((x).pue[0]) |
| 111 | # define pgd_val(x) ((x).pge[0]) |
| 112 | # endif /* CONFIG_MMU */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 113 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 114 | # define __pte(x) ((pte_t) { (x) }) |
| 115 | # define __pmd(x) ((pmd_t) { (x) }) |
| 116 | # define __pgd(x) ((pgd_t) { (x) }) |
| 117 | # define __pgprot(x) ((pgprot_t) { (x) }) |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 118 | |
| 119 | /** |
| 120 | * Conversions for virtual address, physical address, pfn, and struct |
| 121 | * page are defined in the following files. |
| 122 | * |
| 123 | * virt -+ |
| 124 | * | asm-microblaze/page.h |
| 125 | * phys -+ |
| 126 | * | linux/pfn.h |
| 127 | * pfn -+ |
| 128 | * | asm-generic/memory_model.h |
| 129 | * page -+ |
| 130 | * |
| 131 | */ |
| 132 | |
| 133 | extern unsigned long max_low_pfn; |
| 134 | extern unsigned long min_low_pfn; |
| 135 | extern unsigned long max_pfn; |
| 136 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 137 | extern unsigned long memory_start; |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 138 | extern unsigned long memory_size; |
Michal Simek | 7c0d261 | 2011-12-22 12:33:24 +0100 | [diff] [blame] | 139 | extern unsigned long lowmem_size; |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 140 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 141 | extern int page_is_ram(unsigned long pfn); |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 142 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 143 | # define phys_to_pfn(phys) (PFN_DOWN(phys)) |
| 144 | # define pfn_to_phys(pfn) (PFN_PHYS(pfn)) |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 145 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 146 | # define virt_to_pfn(vaddr) (phys_to_pfn((__pa(vaddr)))) |
| 147 | # define pfn_to_virt(pfn) __va(pfn_to_phys((pfn))) |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 148 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 149 | # ifdef CONFIG_MMU |
Michal Simek | d79f3b0 | 2010-02-08 12:13:10 +0100 | [diff] [blame] | 150 | |
| 151 | # define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)) |
| 152 | # define page_to_virt(page) __va(page_to_pfn(page) << PAGE_SHIFT) |
| 153 | # define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) |
| 154 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 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 |
steve@digidescorp.com | 5dd48a2 | 2009-11-13 16:08:29 -0600 | [diff] [blame] | 164 | # define pfn_valid(pfn) (((pfn) >= min_low_pfn) && \ |
| 165 | ((pfn) <= (min_low_pfn + max_mapnr))) |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 166 | # define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) |
| 167 | # else /* CONFIG_MMU */ |
| 168 | # define ARCH_PFN_OFFSET (memory_start >> PAGE_SHIFT) |
| 169 | # define pfn_valid(pfn) ((pfn) < (max_mapnr + ARCH_PFN_OFFSET)) |
| 170 | # define VALID_PAGE(page) ((page - mem_map) < max_mapnr) |
| 171 | # endif /* CONFIG_MMU */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 172 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 173 | # endif /* __ASSEMBLY__ */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 174 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 175 | #define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr))) |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 176 | |
Michal Simek | ed70563 | 2011-12-19 11:10:10 +0100 | [diff] [blame] | 177 | # define __pa(x) __virt_to_phys((unsigned long)(x)) |
| 178 | # define __va(x) ((void *)__phys_to_virt((unsigned long)(x))) |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 179 | |
| 180 | /* Convert between virtual and physical address for MMU. */ |
| 181 | /* Handle MicroBlaze processor with virtual memory. */ |
| 182 | #ifndef CONFIG_MMU |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 183 | #define __virt_to_phys(addr) addr |
| 184 | #define __phys_to_virt(addr) addr |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 185 | #define tophys(rd, rs) addik rd, rs, 0 |
| 186 | #define tovirt(rd, rs) addik rd, rs, 0 |
| 187 | #else |
| 188 | #define __virt_to_phys(addr) \ |
| 189 | ((addr) + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START) |
| 190 | #define __phys_to_virt(addr) \ |
| 191 | ((addr) + CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR) |
| 192 | #define tophys(rd, rs) \ |
| 193 | addik rd, rs, (CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START) |
| 194 | #define tovirt(rd, rs) \ |
| 195 | addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR) |
| 196 | #endif /* CONFIG_MMU */ |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 197 | |
| 198 | #define TOPHYS(addr) __virt_to_phys(addr) |
| 199 | |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 200 | #ifdef CONFIG_MMU |
Michal Simek | 1f84e1e | 2009-05-26 16:30:17 +0200 | [diff] [blame] | 201 | |
| 202 | #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \ |
| 203 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) |
| 204 | #endif /* CONFIG_MMU */ |
| 205 | |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 206 | #endif /* __KERNEL__ */ |
| 207 | |
| 208 | #include <asm-generic/memory_model.h> |
Arnd Bergmann | 5b17e1c | 2009-05-13 22:56:30 +0000 | [diff] [blame] | 209 | #include <asm-generic/getorder.h> |
Michal Simek | 4b87d7a | 2009-03-27 14:25:30 +0100 | [diff] [blame] | 210 | |
| 211 | #endif /* _ASM_MICROBLAZE_PAGE_H */ |