xref: /freebsd/sys/powerpc/include/mmuvar.h (revision ddfc6f84f24215b418af19260e9156219f6df03e)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
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 
29 #ifndef _MACHINE_MMUVAR_H_
30 #define _MACHINE_MMUVAR_H_
31 
32 typedef	void	(*pmap_bootstrap_t)(vm_offset_t, vm_offset_t);
33 typedef	void	(*pmap_cpu_bootstrap_t)(int);
34 typedef	void	(*pmap_kenter_t)(vm_offset_t, vm_paddr_t pa);
35 typedef	void	(*pmap_kenter_attr_t)(vm_offset_t, vm_paddr_t, vm_memattr_t);
36 typedef	void	(*pmap_kremove_t)(vm_offset_t);
37 typedef	void	*(*pmap_mapdev_t)(vm_paddr_t, vm_size_t);
38 typedef	void	*(*pmap_mapdev_attr_t)(vm_paddr_t, vm_size_t, vm_memattr_t);
39 typedef	void	(*pmap_unmapdev_t)(void *, vm_size_t);
40 typedef	void	(*pmap_page_set_memattr_t)(vm_page_t, vm_memattr_t);
41 typedef	int	(*pmap_change_attr_t)(vm_offset_t, vm_size_t, vm_memattr_t);
42 typedef	int	(*pmap_map_user_ptr_t)(pmap_t, volatile const void *,
43  		    void **, size_t, size_t *);
44 typedef	int	(*pmap_decode_kernel_ptr_t)(vm_offset_t, int *, vm_offset_t *);
45 typedef	vm_paddr_t	(*pmap_kextract_t)(vm_offset_t);
46 typedef	int	(*pmap_dev_direct_mapped_t)(vm_paddr_t, vm_size_t);
47 
48 typedef	void	(*pmap_page_array_startup_t)(long);
49 typedef	void	(*pmap_advise_t)(pmap_t, vm_offset_t, vm_offset_t, int);
50 typedef	void	(*pmap_clear_modify_t)(vm_page_t);
51 typedef	void	(*pmap_remove_write_t)(vm_page_t);
52 typedef	void	(*pmap_copy_t)(pmap_t, pmap_t, vm_offset_t, vm_size_t, vm_offset_t);
53 typedef	void	(*pmap_copy_page_t)(vm_page_t, vm_page_t);
54 typedef	void	(*pmap_copy_pages_t)(vm_page_t *, vm_offset_t,
55 		    vm_page_t *, vm_offset_t, int);
56 typedef	int	(*pmap_enter_t)(pmap_t, vm_offset_t, vm_page_t, vm_prot_t,
57 		    u_int, int8_t);
58 typedef	void	(*pmap_enter_object_t)(pmap_t, vm_offset_t, vm_offset_t,
59 		    vm_page_t, vm_prot_t);
60 typedef	void	(*pmap_enter_quick_t)(pmap_t, vm_offset_t, vm_page_t, vm_prot_t);
61 typedef	vm_paddr_t	(*pmap_extract_t)(pmap_t, vm_offset_t);
62 typedef	vm_page_t	(*pmap_extract_and_hold_t)(pmap_t, vm_offset_t, vm_prot_t);
63 typedef	void	(*pmap_growkernel_t)(vm_offset_t);
64 typedef	void	(*pmap_init_t)(void);
65 typedef	bool	(*pmap_is_modified_t)(vm_page_t);
66 typedef	bool	(*pmap_is_prefaultable_t)(pmap_t, vm_offset_t);
67 typedef	bool	(*pmap_is_referenced_t)(vm_page_t);
68 typedef	int	(*pmap_ts_referenced_t)(vm_page_t);
69 typedef	vm_offset_t	(*pmap_map_t)(vm_offset_t *, vm_paddr_t, vm_paddr_t, int);
70 typedef	void	(*pmap_object_init_pt_t)(pmap_t, vm_offset_t, vm_object_t,
71 		    vm_pindex_t, vm_size_t);
72 typedef	bool	(*pmap_page_exists_quick_t)(pmap_t, vm_page_t);
73 typedef	bool	(*pmap_page_is_mapped_t)(vm_page_t);
74 typedef	void	(*pmap_page_init_t)(vm_page_t);
75 typedef	int	(*pmap_page_wired_mappings_t)(vm_page_t);
76 typedef	void	(*pmap_pinit0_t)(pmap_t);
77 typedef	void	(*pmap_protect_t)(pmap_t, vm_offset_t, vm_offset_t, vm_prot_t);
78 typedef	void	(*pmap_qenter_t)(vm_offset_t, vm_page_t *, int);
79 typedef	void	(*pmap_qremove_t)(vm_offset_t, int);
80 typedef	void	(*pmap_release_t)(pmap_t);
81 typedef	void	(*pmap_remove_t)(pmap_t, vm_offset_t, vm_offset_t);
82 typedef	void	(*pmap_remove_all_t)(vm_page_t);
83 typedef	void	(*pmap_remove_pages_t)(pmap_t);
84 typedef	void	(*pmap_unwire_t)(pmap_t, vm_offset_t, vm_offset_t);
85 typedef	void	(*pmap_zero_page_t)(vm_page_t);
86 typedef	void	(*pmap_zero_page_area_t)(vm_page_t, int, int);
87 typedef	int	(*pmap_mincore_t)(pmap_t, vm_offset_t, vm_paddr_t *);
88 typedef	void	(*pmap_activate_t)(struct thread	*);
89 typedef void	(*pmap_deactivate_t)(struct thread	*);
90 typedef	void	(*pmap_align_superpage_t)(vm_object_t, vm_ooffset_t,
91 		    vm_offset_t *, vm_size_t);
92 
93 typedef	void	(*pmap_sync_icache_t)(pmap_t, vm_offset_t, vm_size_t);
94 typedef	void	(*pmap_dumpsys_map_chunk_t)(vm_paddr_t, size_t, void **);
95 typedef	void	(*pmap_dumpsys_unmap_chunk_t)(vm_paddr_t, size_t, void *);
96 typedef	void	(*pmap_dumpsys_pa_init_t)(void);
97 typedef	size_t	(*pmap_dumpsys_scan_pmap_t)(struct bitset *dump_bitset);
98 typedef	void	*(*pmap_dumpsys_dump_pmap_init_t)(unsigned);
99 typedef	void	*(*pmap_dumpsys_dump_pmap_t)(void *, void *, u_long *);
100 typedef	vm_offset_t	(*pmap_quick_enter_page_t)(vm_page_t);
101 typedef	void	(*pmap_quick_remove_page_t)(vm_offset_t);
102 typedef	bool	(*pmap_ps_enabled_t)(pmap_t);
103 typedef	void	(*pmap_tlbie_all_t)(void);
104 typedef void	(*pmap_installer_t)(void);
105 
106 struct pmap_funcs {
107 	pmap_installer_t	install;
108 	pmap_bootstrap_t	bootstrap;
109 	pmap_cpu_bootstrap_t	cpu_bootstrap;
110 	pmap_kenter_t		kenter;
111 	pmap_kenter_attr_t	kenter_attr;
112 	pmap_kremove_t		kremove;
113 	pmap_mapdev_t		mapdev;
114 	pmap_mapdev_attr_t	mapdev_attr;
115 	pmap_unmapdev_t		unmapdev;
116 	pmap_page_set_memattr_t	page_set_memattr;
117 	pmap_change_attr_t	change_attr;
118 	pmap_map_user_ptr_t	map_user_ptr;
119 	pmap_decode_kernel_ptr_t	decode_kernel_ptr;
120 	pmap_kextract_t		kextract;
121 	pmap_dev_direct_mapped_t	dev_direct_mapped;
122 	pmap_advise_t		advise;
123 	pmap_clear_modify_t	clear_modify;
124 	pmap_remove_write_t	remove_write;
125 	pmap_copy_t	copy;
126 	pmap_copy_page_t	copy_page;
127 	pmap_copy_pages_t	copy_pages;
128 	pmap_enter_t	enter;
129 	pmap_enter_object_t	enter_object;
130 	pmap_enter_quick_t	enter_quick;
131 	pmap_extract_t	extract;
132 	pmap_extract_and_hold_t	extract_and_hold;
133 	pmap_growkernel_t	growkernel;
134 	pmap_init_t	init;
135 	pmap_is_modified_t	is_modified;
136 	pmap_is_prefaultable_t	is_prefaultable;
137 	pmap_is_referenced_t	is_referenced;
138 	pmap_ts_referenced_t	ts_referenced;
139 	pmap_page_is_mapped_t	page_is_mapped;
140 	pmap_ps_enabled_t	ps_enabled;
141 	pmap_map_t	map;
142 	pmap_object_init_pt_t	object_init_pt;
143 	pmap_page_exists_quick_t	page_exists_quick;
144 	pmap_page_init_t	page_init;
145 	pmap_page_wired_mappings_t	page_wired_mappings;
146 	pmap_pinit_t	pinit;
147 	pmap_pinit0_t	pinit0;
148 	pmap_protect_t	protect;
149 	pmap_qenter_t	qenter;
150 	pmap_qremove_t	qremove;
151 	pmap_release_t	release;
152 	pmap_remove_t	remove;
153 	pmap_remove_all_t	remove_all;
154 	pmap_remove_pages_t	remove_pages;
155 	pmap_unwire_t	unwire;
156 	pmap_zero_page_t	zero_page;
157 	pmap_zero_page_area_t	zero_page_area;
158 	pmap_mincore_t	mincore;
159 	pmap_activate_t	activate;
160 	pmap_deactivate_t	deactivate;
161 	pmap_align_superpage_t	align_superpage;
162 	pmap_sync_icache_t	sync_icache;
163 	pmap_quick_enter_page_t	quick_enter_page;
164 	pmap_quick_remove_page_t	quick_remove_page;
165 	pmap_page_array_startup_t	page_array_startup;
166 	pmap_dumpsys_map_chunk_t	dumpsys_map_chunk;
167 	pmap_dumpsys_unmap_chunk_t	dumpsys_unmap_chunk;
168 	pmap_dumpsys_pa_init_t	dumpsys_pa_init;
169 	pmap_dumpsys_scan_pmap_t	dumpsys_scan_pmap;
170 	pmap_dumpsys_dump_pmap_init_t	dumpsys_dump_pmap_init;
171 	pmap_dumpsys_dump_pmap_t	dumpsys_dump_pmap;
172 	pmap_tlbie_all_t	tlbie_all;
173 
174 };
175 struct mmu_kobj {
176 	const char *name;
177 	const struct mmu_kobj *base;
178 	const struct pmap_funcs *funcs;
179 };
180 
181 typedef struct mmu_kobj		*mmu_t;
182 
183 /* The currently installed pmap object. */
184 extern mmu_t	mmu_obj;
185 
186 /*
187  * Resolve a given pmap function.
188  * 'func' is the function name less the 'pmap_' * prefix.
189  */
190 #define PMAP_RESOLVE_FUNC(func) 		\
191 	({					\
192 	 pmap_##func##_t f;			\
193 	 const struct mmu_kobj	*mmu = mmu_obj;	\
194 	 do {					\
195 	    f = mmu->funcs->func;		\
196 	    if (f != NULL) break;		\
197 	    mmu = mmu->base;			\
198 	} while (mmu != NULL);			\
199 	f;})
200 
201 #define MMU_DEF(name, ident, methods)		\
202 						\
203 const struct mmu_kobj name = {		\
204 	ident, NULL, &methods			\
205 };						\
206 DATA_SET(mmu_set, name)
207 
208 #define MMU_DEF_INHERIT(name, ident, methods, base1)	\
209 						\
210 const struct mmu_kobj name = {			\
211 	ident, &base1, &methods,		\
212 };						\
213 DATA_SET(mmu_set, name)
214 
215 /*
216  * Known MMU names
217  */
218 #define MMU_TYPE_BOOKE	"mmu_booke"	/* Book-E MMU specification */
219 #define MMU_TYPE_OEA	"mmu_oea"	/* 32-bit OEA */
220 #define MMU_TYPE_G5	"mmu_g5"	/* 64-bit bridge (ibm 970) */
221 #define MMU_TYPE_RADIX	"mmu_radix"	/* 64-bit native ISA 3.0 (POWER9) radix */
222 #define MMU_TYPE_8xx	"mmu_8xx"	/* 8xx quicc TLB */
223 
224 #endif /* _MACHINE_MMUVAR_H_ */
225