1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2005 Peter Grehan 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $FreeBSD$ 29 */ 30 31 #ifndef _MACHINE_MMUVAR_H_ 32 #define _MACHINE_MMUVAR_H_ 33 34 typedef void (*pmap_bootstrap_t)(vm_offset_t, vm_offset_t); 35 typedef void (*pmap_cpu_bootstrap_t)(int); 36 typedef void (*pmap_kenter_t)(vm_offset_t, vm_paddr_t pa); 37 typedef void (*pmap_kenter_attr_t)(vm_offset_t, vm_paddr_t, vm_memattr_t); 38 typedef void (*pmap_kremove_t)(vm_offset_t); 39 typedef void *(*pmap_mapdev_t)(vm_paddr_t, vm_size_t); 40 typedef void *(*pmap_mapdev_attr_t)(vm_paddr_t, vm_size_t, vm_memattr_t); 41 typedef void (*pmap_unmapdev_t)(vm_offset_t, vm_size_t); 42 typedef void (*pmap_page_set_memattr_t)(vm_page_t, vm_memattr_t); 43 typedef int (*pmap_change_attr_t)(vm_offset_t, vm_size_t, vm_memattr_t); 44 typedef int (*pmap_map_user_ptr_t)(pmap_t, volatile const void *, 45 void **, size_t, size_t *); 46 typedef int (*pmap_decode_kernel_ptr_t)(vm_offset_t, int *, vm_offset_t *); 47 typedef vm_paddr_t (*pmap_kextract_t)(vm_offset_t); 48 typedef int (*pmap_dev_direct_mapped_t)(vm_paddr_t, vm_size_t); 49 50 typedef void (*pmap_page_array_startup_t)(long); 51 typedef void (*pmap_advise_t)(pmap_t, vm_offset_t, vm_offset_t, int); 52 typedef void (*pmap_clear_modify_t)(vm_page_t); 53 typedef void (*pmap_remove_write_t)(vm_page_t); 54 typedef void (*pmap_copy_t)(pmap_t, pmap_t, vm_offset_t, vm_size_t, vm_offset_t); 55 typedef void (*pmap_copy_page_t)(vm_page_t, vm_page_t); 56 typedef void (*pmap_copy_pages_t)(vm_page_t *, vm_offset_t, 57 vm_page_t *, vm_offset_t, int); 58 typedef int (*pmap_enter_t)(pmap_t, vm_offset_t, vm_page_t, vm_prot_t, 59 u_int, int8_t); 60 typedef void (*pmap_enter_object_t)(pmap_t, vm_offset_t, vm_offset_t, 61 vm_page_t, vm_prot_t); 62 typedef void (*pmap_enter_quick_t)(pmap_t, vm_offset_t, vm_page_t, vm_prot_t); 63 typedef vm_paddr_t (*pmap_extract_t)(pmap_t, vm_offset_t); 64 typedef vm_page_t (*pmap_extract_and_hold_t)(pmap_t, vm_offset_t, vm_prot_t); 65 typedef void (*pmap_growkernel_t)(vm_offset_t); 66 typedef void (*pmap_init_t)(void); 67 typedef boolean_t (*pmap_is_modified_t)(vm_page_t); 68 typedef boolean_t (*pmap_is_prefaultable_t)(pmap_t, vm_offset_t); 69 typedef boolean_t (*pmap_is_referenced_t)(vm_page_t); 70 typedef int (*pmap_ts_referenced_t)(vm_page_t); 71 typedef vm_offset_t (*pmap_map_t)(vm_offset_t *, vm_paddr_t, vm_paddr_t, int); 72 typedef void (*pmap_object_init_pt_t)(pmap_t, vm_offset_t, vm_object_t, 73 vm_pindex_t, vm_size_t); 74 typedef boolean_t (*pmap_page_exists_quick_t)(pmap_t, vm_page_t); 75 typedef boolean_t (*pmap_page_is_mapped_t)(vm_page_t); 76 typedef void (*pmap_page_init_t)(vm_page_t); 77 typedef int (*pmap_page_wired_mappings_t)(vm_page_t); 78 typedef void (*pmap_pinit0_t)(pmap_t); 79 typedef void (*pmap_protect_t)(pmap_t, vm_offset_t, vm_offset_t, vm_prot_t); 80 typedef void (*pmap_qenter_t)(vm_offset_t, vm_page_t *, int); 81 typedef void (*pmap_qremove_t)(vm_offset_t, int); 82 typedef void (*pmap_release_t)(pmap_t); 83 typedef void (*pmap_remove_t)(pmap_t, vm_offset_t, vm_offset_t); 84 typedef void (*pmap_remove_all_t)(vm_page_t); 85 typedef void (*pmap_remove_pages_t)(pmap_t); 86 typedef void (*pmap_unwire_t)(pmap_t, vm_offset_t, vm_offset_t); 87 typedef void (*pmap_zero_page_t)(vm_page_t); 88 typedef void (*pmap_zero_page_area_t)(vm_page_t, int, int); 89 typedef int (*pmap_mincore_t)(pmap_t, vm_offset_t, vm_paddr_t *); 90 typedef void (*pmap_activate_t)(struct thread *); 91 typedef void (*pmap_deactivate_t)(struct thread *); 92 typedef void (*pmap_align_superpage_t)(vm_object_t, vm_ooffset_t, 93 vm_offset_t *, vm_size_t); 94 95 typedef void (*pmap_sync_icache_t)(pmap_t, vm_offset_t, vm_size_t); 96 typedef void (*pmap_dumpsys_map_chunk_t)(vm_paddr_t, size_t, void **); 97 typedef void (*pmap_dumpsys_unmap_chunk_t)(vm_paddr_t, size_t, void *); 98 typedef void (*pmap_dumpsys_pa_init_t)(void); 99 typedef size_t (*pmap_dumpsys_scan_pmap_t)(struct bitset *dump_bitset); 100 typedef void *(*pmap_dumpsys_dump_pmap_init_t)(unsigned); 101 typedef void *(*pmap_dumpsys_dump_pmap_t)(void *, void *, u_long *); 102 typedef vm_offset_t (*pmap_quick_enter_page_t)(vm_page_t); 103 typedef void (*pmap_quick_remove_page_t)(vm_offset_t); 104 typedef bool (*pmap_ps_enabled_t)(pmap_t); 105 typedef void (*pmap_tlbie_all_t)(void); 106 typedef void (*pmap_installer_t)(void); 107 108 struct pmap_funcs { 109 pmap_installer_t install; 110 pmap_bootstrap_t bootstrap; 111 pmap_cpu_bootstrap_t cpu_bootstrap; 112 pmap_kenter_t kenter; 113 pmap_kenter_attr_t kenter_attr; 114 pmap_kremove_t kremove; 115 pmap_mapdev_t mapdev; 116 pmap_mapdev_attr_t mapdev_attr; 117 pmap_unmapdev_t unmapdev; 118 pmap_page_set_memattr_t page_set_memattr; 119 pmap_change_attr_t change_attr; 120 pmap_map_user_ptr_t map_user_ptr; 121 pmap_decode_kernel_ptr_t decode_kernel_ptr; 122 pmap_kextract_t kextract; 123 pmap_dev_direct_mapped_t dev_direct_mapped; 124 pmap_advise_t advise; 125 pmap_clear_modify_t clear_modify; 126 pmap_remove_write_t remove_write; 127 pmap_copy_t copy; 128 pmap_copy_page_t copy_page; 129 pmap_copy_pages_t copy_pages; 130 pmap_enter_t enter; 131 pmap_enter_object_t enter_object; 132 pmap_enter_quick_t enter_quick; 133 pmap_extract_t extract; 134 pmap_extract_and_hold_t extract_and_hold; 135 pmap_growkernel_t growkernel; 136 pmap_init_t init; 137 pmap_is_modified_t is_modified; 138 pmap_is_prefaultable_t is_prefaultable; 139 pmap_is_referenced_t is_referenced; 140 pmap_ts_referenced_t ts_referenced; 141 pmap_page_is_mapped_t page_is_mapped; 142 pmap_ps_enabled_t ps_enabled; 143 pmap_map_t map; 144 pmap_object_init_pt_t object_init_pt; 145 pmap_page_exists_quick_t page_exists_quick; 146 pmap_page_init_t page_init; 147 pmap_page_wired_mappings_t page_wired_mappings; 148 pmap_pinit_t pinit; 149 pmap_pinit0_t pinit0; 150 pmap_protect_t protect; 151 pmap_qenter_t qenter; 152 pmap_qremove_t qremove; 153 pmap_release_t release; 154 pmap_remove_t remove; 155 pmap_remove_all_t remove_all; 156 pmap_remove_pages_t remove_pages; 157 pmap_unwire_t unwire; 158 pmap_zero_page_t zero_page; 159 pmap_zero_page_area_t zero_page_area; 160 pmap_mincore_t mincore; 161 pmap_activate_t activate; 162 pmap_deactivate_t deactivate; 163 pmap_align_superpage_t align_superpage; 164 pmap_sync_icache_t sync_icache; 165 pmap_quick_enter_page_t quick_enter_page; 166 pmap_quick_remove_page_t quick_remove_page; 167 pmap_page_array_startup_t page_array_startup; 168 pmap_dumpsys_map_chunk_t dumpsys_map_chunk; 169 pmap_dumpsys_unmap_chunk_t dumpsys_unmap_chunk; 170 pmap_dumpsys_pa_init_t dumpsys_pa_init; 171 pmap_dumpsys_scan_pmap_t dumpsys_scan_pmap; 172 pmap_dumpsys_dump_pmap_init_t dumpsys_dump_pmap_init; 173 pmap_dumpsys_dump_pmap_t dumpsys_dump_pmap; 174 pmap_tlbie_all_t tlbie_all; 175 176 }; 177 struct mmu_kobj { 178 const char *name; 179 const struct mmu_kobj *base; 180 const struct pmap_funcs *funcs; 181 }; 182 183 typedef struct mmu_kobj *mmu_t; 184 185 /* The currently installed pmap object. */ 186 extern mmu_t mmu_obj; 187 188 /* 189 * Resolve a given pmap function. 190 * 'func' is the function name less the 'pmap_' * prefix. 191 */ 192 #define PMAP_RESOLVE_FUNC(func) \ 193 ({ \ 194 pmap_##func##_t f; \ 195 const struct mmu_kobj *mmu = mmu_obj; \ 196 do { \ 197 f = mmu->funcs->func; \ 198 if (f != NULL) break; \ 199 mmu = mmu->base; \ 200 } while (mmu != NULL); \ 201 f;}) 202 203 #define MMU_DEF(name, ident, methods) \ 204 \ 205 const struct mmu_kobj name = { \ 206 ident, NULL, &methods \ 207 }; \ 208 DATA_SET(mmu_set, name) 209 210 #define MMU_DEF_INHERIT(name, ident, methods, base1) \ 211 \ 212 const struct mmu_kobj name = { \ 213 ident, &base1, &methods, \ 214 }; \ 215 DATA_SET(mmu_set, name) 216 217 /* 218 * Known MMU names 219 */ 220 #define MMU_TYPE_BOOKE "mmu_booke" /* Book-E MMU specification */ 221 #define MMU_TYPE_OEA "mmu_oea" /* 32-bit OEA */ 222 #define MMU_TYPE_G5 "mmu_g5" /* 64-bit bridge (ibm 970) */ 223 #define MMU_TYPE_RADIX "mmu_radix" /* 64-bit native ISA 3.0 (POWER9) radix */ 224 #define MMU_TYPE_8xx "mmu_8xx" /* 8xx quicc TLB */ 225 226 #endif /* _MACHINE_MMUVAR_H_ */ 227