xref: /netbsd-src/sys/arch/powerpc/include/oea/pmap.h (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
1 /*	$NetBSD: pmap.h,v 1.35 2021/03/12 04:57:42 thorpej Exp $	*/
2 
3 /*-
4  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5  * Copyright (C) 1995, 1996 TooLs GmbH.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by TooLs GmbH.
19  * 4. The name of TooLs GmbH may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef	_POWERPC_OEA_PMAP_H_
35 #define	_POWERPC_OEA_PMAP_H_
36 
37 #ifdef _LOCORE
38 #error use assym.h instead
39 #endif
40 
41 #ifdef _MODULE
42 #error this file should not be included by loadable kernel modules
43 #endif
44 
45 #ifdef _KERNEL_OPT
46 #include "opt_ppcarch.h"
47 #include "opt_modular.h"
48 #endif
49 #include <powerpc/oea/pte.h>
50 
51 /*
52  * Pmap stuff
53  */
54 struct pmap {
55 #ifdef PPC_OEA64
56 	struct steg *pm_steg_table;		/* segment table pointer */
57 	/* XXX need way to track exec pages */
58 #endif
59 
60 #if defined(PPC_OEA) || defined (PPC_OEA64_BRIDGE)
61 	register_t pm_sr[16];			/* segments used in this pmap */
62 	int pm_exec[16];			/* counts of exec mappings */
63 #endif
64 	register_t pm_vsid;			/* VSID bits */
65 	int pm_refs;				/* ref count */
66 	struct pmap_statistics pm_stats;	/* pmap statistics */
67 	unsigned int pm_evictions;		/* pvo's not in page table */
68 
69 #ifdef PPC_OEA64
70 	unsigned int pm_ste_evictions;
71 #endif
72 };
73 
74 struct pmap_ops {
75 	int (*pmapop_pte_spill)(struct pmap *, vaddr_t, bool);
76 	void (*pmapop_real_memory)(paddr_t *, psize_t *);
77 	void (*pmapop_init)(void);
78 	void (*pmapop_virtual_space)(vaddr_t *, vaddr_t *);
79 	pmap_t (*pmapop_create)(void);
80 	void (*pmapop_reference)(pmap_t);
81 	void (*pmapop_destroy)(pmap_t);
82 	void (*pmapop_copy)(pmap_t, pmap_t, vaddr_t, vsize_t, vaddr_t);
83 	void (*pmapop_update)(pmap_t);
84 	int (*pmapop_enter)(pmap_t, vaddr_t, paddr_t, vm_prot_t, u_int);
85 	void (*pmapop_remove)(pmap_t, vaddr_t, vaddr_t);
86 	void (*pmapop_kenter_pa)(vaddr_t, paddr_t, vm_prot_t, u_int);
87 	void (*pmapop_kremove)(vaddr_t, vsize_t);
88 	bool (*pmapop_extract)(pmap_t, vaddr_t, paddr_t *);
89 
90 	void (*pmapop_protect)(pmap_t, vaddr_t, vaddr_t, vm_prot_t);
91 	void (*pmapop_unwire)(pmap_t, vaddr_t);
92 	void (*pmapop_page_protect)(struct vm_page *, vm_prot_t);
93 	bool (*pmapop_query_bit)(struct vm_page *, int);
94 	bool (*pmapop_clear_bit)(struct vm_page *, int);
95 
96 	void (*pmapop_activate)(struct lwp *);
97 	void (*pmapop_deactivate)(struct lwp *);
98 
99 	void (*pmapop_pinit)(pmap_t);
100 	void (*pmapop_procwr)(struct proc *, vaddr_t, size_t);
101 
102 	void (*pmapop_pte_print)(volatile struct pte *);
103 	void (*pmapop_pteg_check)(void);
104 	void (*pmapop_print_mmuregs)(void);
105 	void (*pmapop_print_pte)(pmap_t, vaddr_t);
106 	void (*pmapop_pteg_dist)(void);
107 	void (*pmapop_pvo_verify)(void);
108 	vaddr_t (*pmapop_steal_memory)(vsize_t, vaddr_t *, vaddr_t *);
109 	void (*pmapop_bootstrap)(paddr_t, paddr_t);
110 	void (*pmapop_bootstrap1)(paddr_t, paddr_t);
111 	void (*pmapop_bootstrap2)(void);
112 };
113 
114 #ifdef	_KERNEL
115 #include <sys/cdefs.h>
116 __BEGIN_DECLS
117 #include <sys/param.h>
118 #include <sys/systm.h>
119 
120 #if defined (PPC_OEA) || defined (PPC_OEA64_BRIDGE)
121 extern register_t iosrtable[];
122 #endif
123 extern int pmap_use_altivec;
124 
125 #define pmap_clear_modify(pg)		(pmap_clear_bit((pg), PTE_CHG))
126 #define	pmap_clear_reference(pg)	(pmap_clear_bit((pg), PTE_REF))
127 #define	pmap_is_modified(pg)		(pmap_query_bit((pg), PTE_CHG))
128 #define	pmap_is_referenced(pg)		(pmap_query_bit((pg), PTE_REF))
129 
130 #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
131 #define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
132 
133 /* ARGSUSED */
134 static __inline bool
135 pmap_remove_all(struct pmap *pmap)
136 {
137 	/* Nothing. */
138 	return false;
139 }
140 
141 #if (defined(PPC_OEA) + defined(PPC_OEA64) + defined(PPC_OEA64_BRIDGE)) != 1
142 #define	PMAP_NEEDS_FIXUP
143 #endif
144 
145 extern volatile struct pteg *pmap_pteg_table;
146 extern unsigned int pmap_pteg_cnt;
147 extern unsigned int pmap_pteg_mask;
148 
149 void pmap_bootstrap(vaddr_t, vaddr_t);
150 void pmap_bootstrap1(vaddr_t, vaddr_t);
151 void pmap_bootstrap2(void);
152 bool pmap_extract(pmap_t, vaddr_t, paddr_t *);
153 bool pmap_query_bit(struct vm_page *, int);
154 bool pmap_clear_bit(struct vm_page *, int);
155 void pmap_real_memory(paddr_t *, psize_t *);
156 void pmap_procwr(struct proc *, vaddr_t, size_t);
157 int pmap_pte_spill(pmap_t, vaddr_t, bool);
158 int pmap_ste_spill(pmap_t, vaddr_t, bool);
159 void pmap_pinit(pmap_t);
160 
161 #ifdef PPC_OEA601
162 bool	pmap_extract_ioseg601(vaddr_t, paddr_t *);
163 #endif /* PPC_OEA601 */
164 #ifdef PPC_OEA
165 bool	pmap_extract_battable(vaddr_t, paddr_t *);
166 #endif /* PPC_OEA */
167 
168 u_int powerpc_mmap_flags(paddr_t);
169 #define POWERPC_MMAP_FLAG_MASK	0xf
170 #define POWERPC_MMAP_FLAG_PREFETCHABLE	0x1
171 #define POWERPC_MMAP_FLAG_CACHEABLE	0x2
172 
173 #define pmap_phys_address(ppn)		(ppn & ~POWERPC_MMAP_FLAG_MASK)
174 #define pmap_mmap_flags(ppn)		powerpc_mmap_flags(ppn)
175 
176 static __inline paddr_t vtophys (vaddr_t);
177 
178 /*
179  * Alternate mapping hooks for pool pages.  Avoids thrashing the TLB.
180  *
181  * Note: This won't work if we have more memory than can be direct-mapped
182  * VA==PA all at once.  But pmap_copy_page() and pmap_zero_page() will have
183  * this problem, too.
184  */
185 #if !defined(PPC_OEA64) && !defined (PPC_OEA64_BRIDGE)
186 #define	PMAP_MAP_POOLPAGE(pa)	(pa)
187 #define	PMAP_UNMAP_POOLPAGE(pa)	(pa)
188 #define POOL_VTOPHYS(va)	vtophys((vaddr_t) va)
189 #endif
190 
191 static __inline paddr_t
192 vtophys(vaddr_t va)
193 {
194 	paddr_t pa;
195 
196 	if (pmap_extract(pmap_kernel(), va, &pa))
197 		return pa;
198 	KASSERTMSG(0, "vtophys: pmap_extract of %#"PRIxVADDR" failed", va);
199 	return (paddr_t) -1;
200 }
201 
202 
203 #ifdef PMAP_NEEDS_FIXUP
204 extern const struct pmap_ops *pmapops;
205 extern const struct pmap_ops pmap32_ops;
206 extern const struct pmap_ops pmap64_ops;
207 extern const struct pmap_ops pmap64bridge_ops;
208 
209 static __inline void
210 pmap_setup32(void)
211 {
212 	pmapops = &pmap32_ops;
213 }
214 
215 static __inline void
216 pmap_setup64(void)
217 {
218 	pmapops = &pmap64_ops;
219 }
220 
221 static __inline void
222 pmap_setup64bridge(void)
223 {
224 	pmapops = &pmap64bridge_ops;
225 }
226 #endif
227 
228 bool pmap_pageidlezero (paddr_t);
229 void pmap_syncicache (paddr_t, psize_t);
230 #ifdef PPC_OEA64
231 vaddr_t pmap_setusr (vaddr_t);
232 vaddr_t pmap_unsetusr (void);
233 #endif
234 
235 #ifdef PPC_OEA64_BRIDGE
236 int pmap_setup_segment0_map(int use_large_pages, ...);
237 #endif
238 
239 #define PMAP_MD_PREFETCHABLE		0x2000000
240 #define PMAP_STEAL_MEMORY
241 #define PMAP_NEED_PROCWR
242 
243 void pmap_zero_page(paddr_t);
244 void pmap_copy_page(paddr_t, paddr_t);
245 
246 LIST_HEAD(pvo_head, pvo_entry);
247 
248 #define	__HAVE_VM_PAGE_MD
249 
250 struct vm_page_md {
251 	unsigned int mdpg_attrs;
252 	struct pvo_head mdpg_pvoh;
253 #ifdef MODULAR
254 	uintptr_t mdpg_dummy[3];
255 #endif
256 };
257 
258 #define	VM_MDPAGE_INIT(pg) do {			\
259 	(pg)->mdpage.mdpg_attrs = 0;		\
260 	LIST_INIT(&(pg)->mdpage.mdpg_pvoh);	\
261 } while (/*CONSTCOND*/0)
262 
263 __END_DECLS
264 #endif	/* _KERNEL */
265 
266 #endif	/* _POWERPC_OEA_PMAP_H_ */
267