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 #include <vdso/page.h> 23 24 #define LOAD_OFFSET ASM_CONST((CONFIG_KERNEL_START-CONFIG_KERNEL_BASE_ADDR)) 25 26 #define PTE_SHIFT (PAGE_SHIFT - 2) /* 1024 ptes per page */ 27 28 #ifndef __ASSEMBLY__ 29 30 /* 31 * PAGE_OFFSET -- the first address of the first page of memory. With MMU 32 * it is set to the kernel start address (aligned on a page boundary). 33 * 34 * CONFIG_KERNEL_START is defined in arch/microblaze/config.in and used 35 * in arch/microblaze/Makefile. 36 */ 37 #define PAGE_OFFSET CONFIG_KERNEL_START 38 39 /* 40 * The basic type of a PTE - 32 bit physical addressing. 41 */ 42 typedef unsigned long pte_basic_t; 43 #define PTE_FMT "%.8lx" 44 45 # define copy_page(to, from) memcpy((to), (from), PAGE_SIZE) 46 # define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE) 47 48 # define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE) 49 # define copy_user_page(vto, vfrom, vaddr, topg) \ 50 memcpy((vto), (vfrom), PAGE_SIZE) 51 52 /* 53 * These are used to make use of C type-checking.. 54 */ 55 typedef struct page *pgtable_t; 56 typedef struct { unsigned long pte; } pte_t; 57 typedef struct { unsigned long pgprot; } pgprot_t; 58 /* FIXME this can depend on linux kernel version */ 59 typedef struct { unsigned long pgd; } pgd_t; 60 61 # define pte_val(x) ((x).pte) 62 # define pgprot_val(x) ((x).pgprot) 63 64 # define pgd_val(x) ((x).pgd) 65 66 # define __pte(x) ((pte_t) { (x) }) 67 # define __pgd(x) ((pgd_t) { (x) }) 68 # define __pgprot(x) ((pgprot_t) { (x) }) 69 70 /** 71 * Conversions for virtual address, physical address, pfn, and struct 72 * page are defined in the following files. 73 * 74 * virt -+ 75 * | asm-microblaze/page.h 76 * phys -+ 77 * | linux/pfn.h 78 * pfn -+ 79 * | asm-generic/memory_model.h 80 * page -+ 81 * 82 */ 83 84 extern unsigned long max_low_pfn; 85 extern unsigned long min_low_pfn; 86 extern unsigned long max_pfn; 87 88 extern unsigned long memory_start; 89 extern unsigned long memory_size; 90 extern unsigned long lowmem_size; 91 92 extern unsigned long kernel_tlb; 93 94 extern int page_is_ram(unsigned long pfn); 95 96 # define phys_to_pfn(phys) (PFN_DOWN(phys)) 97 # define pfn_to_phys(pfn) (PFN_PHYS(pfn)) 98 99 # define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)) 100 # define page_to_virt(page) __va(page_to_pfn(page) << PAGE_SHIFT) 101 102 # define ARCH_PFN_OFFSET (memory_start >> PAGE_SHIFT) 103 # endif /* __ASSEMBLY__ */ 104 105 /* Convert between virtual and physical address for MMU. */ 106 /* Handle MicroBlaze processor with virtual memory. */ 107 #define __virt_to_phys(addr) \ 108 ((addr) + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START) 109 #define __phys_to_virt(addr) \ 110 ((addr) + CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR) 111 #define tophys(rd, rs) \ 112 addik rd, rs, (CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START) 113 #define tovirt(rd, rs) \ 114 addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR) 115 116 #ifndef __ASSEMBLY__ 117 118 # define __pa(x) __virt_to_phys((unsigned long)(x)) 119 # define __va(x) ((void *)__phys_to_virt((unsigned long)(x))) 120 121 static inline unsigned long virt_to_pfn(const void *vaddr) 122 { 123 return phys_to_pfn(__pa(vaddr)); 124 } 125 126 static inline const void *pfn_to_virt(unsigned long pfn) 127 { 128 return __va(pfn_to_phys((pfn))); 129 } 130 131 #define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr))) 132 133 #endif /* __ASSEMBLY__ */ 134 135 #define TOPHYS(addr) __virt_to_phys(addr) 136 137 #endif /* __KERNEL__ */ 138 139 #include <asm-generic/memory_model.h> 140 #include <asm-generic/getorder.h> 141 142 #endif /* _ASM_MICROBLAZE_PAGE_H */ 143