1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * VM ops 4 * 5 * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> 6 * Copyright (C) 2008-2009 PetaLogix 7 * Copyright (C) 2006 Atmark Techno, Inc. 8 * Changes for MMU support: 9 * Copyright (C) 2007 Xilinx, Inc. All rights reserved. 10 */ 11 12 #ifndef _ASM_MICROBLAZE_PAGE_H 13 #define _ASM_MICROBLAZE_PAGE_H 14 15 #include <linux/pfn.h> 16 #include <asm/setup.h> 17 #include <asm/asm-compat.h> 18 #include <linux/const.h> 19 20 #ifdef __KERNEL__ 21 22 /* PAGE_SHIFT determines the page size */ 23 #if defined(CONFIG_MICROBLAZE_64K_PAGES) 24 #define PAGE_SHIFT 16 25 #elif defined(CONFIG_MICROBLAZE_16K_PAGES) 26 #define PAGE_SHIFT 14 27 #else 28 #define PAGE_SHIFT 12 29 #endif 30 #define PAGE_SIZE (ASM_CONST(1) << PAGE_SHIFT) 31 #define PAGE_MASK (~(PAGE_SIZE-1)) 32 33 #define LOAD_OFFSET ASM_CONST((CONFIG_KERNEL_START-CONFIG_KERNEL_BASE_ADDR)) 34 35 #define PTE_SHIFT (PAGE_SHIFT - 2) /* 1024 ptes per page */ 36 37 #ifndef __ASSEMBLY__ 38 39 /* MS be sure that SLAB allocates aligned objects */ 40 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES 41 42 #define ARCH_SLAB_MINALIGN L1_CACHE_BYTES 43 44 #define PAGE_UP(addr) (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1))) 45 #define PAGE_DOWN(addr) ((addr)&(~((PAGE_SIZE)-1))) 46 47 #ifndef CONFIG_MMU 48 /* 49 * PAGE_OFFSET -- the first address of the first page of memory. When not 50 * using MMU this corresponds to the first free page in physical memory (aligned 51 * on a page boundary). 52 */ 53 extern unsigned int __page_offset; 54 #define PAGE_OFFSET __page_offset 55 56 #else /* CONFIG_MMU */ 57 58 /* 59 * PAGE_OFFSET -- the first address of the first page of memory. With MMU 60 * it is set to the kernel start address (aligned on a page boundary). 61 * 62 * CONFIG_KERNEL_START is defined in arch/microblaze/config.in and used 63 * in arch/microblaze/Makefile. 64 */ 65 #define PAGE_OFFSET CONFIG_KERNEL_START 66 67 /* 68 * The basic type of a PTE - 32 bit physical addressing. 69 */ 70 typedef unsigned long pte_basic_t; 71 #define PTE_FMT "%.8lx" 72 73 #endif /* CONFIG_MMU */ 74 75 # define copy_page(to, from) memcpy((to), (from), PAGE_SIZE) 76 # define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE) 77 78 # define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE) 79 # define copy_user_page(vto, vfrom, vaddr, topg) \ 80 memcpy((vto), (vfrom), PAGE_SIZE) 81 82 /* 83 * These are used to make use of C type-checking.. 84 */ 85 typedef struct page *pgtable_t; 86 typedef struct { unsigned long pte; } pte_t; 87 typedef struct { unsigned long pgprot; } pgprot_t; 88 /* FIXME this can depend on linux kernel version */ 89 # ifdef CONFIG_MMU 90 typedef struct { unsigned long pgd; } pgd_t; 91 # else /* CONFIG_MMU */ 92 typedef struct { unsigned long ste[64]; } pmd_t; 93 typedef struct { pmd_t pue[1]; } pud_t; 94 typedef struct { pud_t p4e[1]; } p4d_t; 95 typedef struct { p4d_t pge[1]; } pgd_t; 96 # endif /* CONFIG_MMU */ 97 98 # define pte_val(x) ((x).pte) 99 # define pgprot_val(x) ((x).pgprot) 100 101 # ifdef CONFIG_MMU 102 # define pgd_val(x) ((x).pgd) 103 # else /* CONFIG_MMU */ 104 # define pmd_val(x) ((x).ste[0]) 105 # define pud_val(x) ((x).pue[0]) 106 # define pgd_val(x) ((x).pge[0]) 107 # endif /* CONFIG_MMU */ 108 109 # define __pte(x) ((pte_t) { (x) }) 110 # define __pgd(x) ((pgd_t) { (x) }) 111 # define __pgprot(x) ((pgprot_t) { (x) }) 112 113 /** 114 * Conversions for virtual address, physical address, pfn, and struct 115 * page are defined in the following files. 116 * 117 * virt -+ 118 * | asm-microblaze/page.h 119 * phys -+ 120 * | linux/pfn.h 121 * pfn -+ 122 * | asm-generic/memory_model.h 123 * page -+ 124 * 125 */ 126 127 extern unsigned long max_low_pfn; 128 extern unsigned long min_low_pfn; 129 extern unsigned long max_pfn; 130 131 extern unsigned long memory_start; 132 extern unsigned long memory_size; 133 extern unsigned long lowmem_size; 134 135 extern unsigned long kernel_tlb; 136 137 extern int page_is_ram(unsigned long pfn); 138 139 # define phys_to_pfn(phys) (PFN_DOWN(phys)) 140 # define pfn_to_phys(pfn) (PFN_PHYS(pfn)) 141 142 # define virt_to_pfn(vaddr) (phys_to_pfn((__pa(vaddr)))) 143 # define pfn_to_virt(pfn) __va(pfn_to_phys((pfn))) 144 145 # ifdef CONFIG_MMU 146 147 # define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)) 148 # define page_to_virt(page) __va(page_to_pfn(page) << PAGE_SHIFT) 149 # define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) 150 151 # else /* CONFIG_MMU */ 152 # define virt_to_page(vaddr) (pfn_to_page(virt_to_pfn(vaddr))) 153 # define page_to_virt(page) (pfn_to_virt(page_to_pfn(page))) 154 # define page_to_phys(page) (pfn_to_phys(page_to_pfn(page))) 155 # define page_to_bus(page) (page_to_phys(page)) 156 # define phys_to_page(paddr) (pfn_to_page(phys_to_pfn(paddr))) 157 # endif /* CONFIG_MMU */ 158 159 # ifndef CONFIG_MMU 160 # define pfn_valid(pfn) (((pfn) >= min_low_pfn) && \ 161 ((pfn) <= (min_low_pfn + max_mapnr))) 162 # define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) 163 # else /* CONFIG_MMU */ 164 # define ARCH_PFN_OFFSET (memory_start >> PAGE_SHIFT) 165 # define pfn_valid(pfn) ((pfn) < (max_mapnr + ARCH_PFN_OFFSET)) 166 # endif /* CONFIG_MMU */ 167 168 # endif /* __ASSEMBLY__ */ 169 170 #define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr))) 171 172 # define __pa(x) __virt_to_phys((unsigned long)(x)) 173 # define __va(x) ((void *)__phys_to_virt((unsigned long)(x))) 174 175 /* Convert between virtual and physical address for MMU. */ 176 /* Handle MicroBlaze processor with virtual memory. */ 177 #ifndef CONFIG_MMU 178 #define __virt_to_phys(addr) addr 179 #define __phys_to_virt(addr) addr 180 #define tophys(rd, rs) addik rd, rs, 0 181 #define tovirt(rd, rs) addik rd, rs, 0 182 #else 183 #define __virt_to_phys(addr) \ 184 ((addr) + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START) 185 #define __phys_to_virt(addr) \ 186 ((addr) + CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR) 187 #define tophys(rd, rs) \ 188 addik rd, rs, (CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START) 189 #define tovirt(rd, rs) \ 190 addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR) 191 #endif /* CONFIG_MMU */ 192 193 #define TOPHYS(addr) __virt_to_phys(addr) 194 195 #ifdef CONFIG_MMU 196 197 #endif /* CONFIG_MMU */ 198 199 #endif /* __KERNEL__ */ 200 201 #include <asm-generic/memory_model.h> 202 #include <asm-generic/getorder.h> 203 204 #endif /* _ASM_MICROBLAZE_PAGE_H */ 205