xref: /openbsd/sys/arch/powerpc/include/pmap.h (revision 551b33bf)
1 /*	$OpenBSD: pmap.h,v 1.65 2023/12/11 22:12:53 kettenis Exp $	*/
2 /*	$NetBSD: pmap.h,v 1.1 1996/09/30 16:34:29 ws Exp $	*/
3 
4 /*-
5  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
6  * Copyright (C) 1995, 1996 TooLs GmbH.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed by TooLs GmbH.
20  * 4. The name of TooLs GmbH may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef	_POWERPC_PMAP_H_
36 #define	_POWERPC_PMAP_H_
37 
38 #include <machine/pte.h>
39 
40 /*
41  * Segment registers
42  */
43 #ifndef	_LOCORE
44 typedef u_int sr_t;
45 #endif	/* _LOCORE */
46 #define	SR_TYPE		0x80000000
47 #define	SR_SUKEY	0x40000000
48 #define	SR_PRKEY	0x20000000
49 #define SR_NOEXEC	0x10000000
50 #define	SR_VSID		0x00ffffff
51 /*
52  * bit
53  *   3  2 2  2    2 1  1 1  1 1            0
54  *   1  8 7  4    0 9  6 5  2 1            0
55  *  |XXXX|XXXX XXXX|XXXX XXXX|XXXX XXXX XXXX
56  *
57  *  bits 28 - 31 contain SR
58  *  bits 20 - 27 contain L1 for VtoP translation
59  *  bits 12 - 19 contain L2 for VtoP translation
60  *  bits  0 - 11 contain page offset
61  */
62 #ifndef _LOCORE
63 /* V->P mapping data */
64 #define VP_SR_SIZE	16
65 #define VP_SR_MASK	(VP_SR_SIZE-1)
66 #define VP_SR_POS 	28
67 #define VP_IDX1_SIZE	256
68 #define VP_IDX1_MASK	(VP_IDX1_SIZE-1)
69 #define VP_IDX1_POS 	20
70 #define VP_IDX2_SIZE	256
71 #define VP_IDX2_MASK	(VP_IDX2_SIZE-1)
72 #define VP_IDX2_POS 	12
73 
74 /* cache flags */
75 #define PMAP_CACHE_DEFAULT	0 	/* WB cache managed mem, devices not */
76 #define PMAP_CACHE_CI		1 	/* cache inhibit */
77 #define PMAP_CACHE_WT		2 	/* writethru */
78 #define PMAP_CACHE_WB		3	/* writeback */
79 
80 #include <sys/mutex.h>
81 #include <sys/queue.h>
82 
83 #ifdef	_KERNEL
84 
85 /*
86  * Pmap stuff
87  */
88 struct pmap {
89 	sr_t pm_sr[16];		/* segments used in this pmap */
90 	struct pmapvp *pm_vp[VP_SR_SIZE];	/* virtual to physical table */
91 	u_int32_t pm_exec[16];	/* segments used in this pmap */
92 	int pm_refs;		/* ref count */
93 	struct pmap_statistics	pm_stats;	/* pmap statistics */
94 	struct mutex		pm_mtx;		/* protect VP table */
95 };
96 
97 /*
98  * Segment handling stuff
99  */
100 #define	PPC_SEGMENT_LENGTH	0x10000000
101 #define	PPC_SEGMENT_MASK	0xf0000000
102 
103 /*
104  * Some system constants
105  */
106 #ifndef	NPMAPS
107 #define	NPMAPS		32768	/* Number of pmaps in system */
108 #endif
109 
110 typedef	struct pmap *pmap_t;
111 
112 extern struct pmap kernel_pmap_;
113 #define	pmap_kernel()	(&kernel_pmap_)
114 
115 
116 #define pmap_clear_modify(pg)		pmap_clear_attrs((pg), PG_PMAP_MOD)
117 #define	pmap_clear_reference(pg)	pmap_clear_attrs((pg), PG_PMAP_REF)
118 #define	pmap_is_modified(pg)		pmap_test_attrs((pg), PG_PMAP_MOD)
119 #define	pmap_is_referenced(pg)		pmap_test_attrs((pg), PG_PMAP_REF)
120 
121 #define	pmap_unwire(pm, va)
122 #define pmap_update(pmap)	/* nothing (yet) */
123 
124 #define pmap_resident_count(pmap)       ((pmap)->pm_stats.resident_count)
125 
126 /*
127  * Alternate mapping methods for pool.
128  * Really simple. 0x0->0x80000000 contain 1->1 mappings of the physical
129  * memory. - XXX
130  */
131 #define pmap_map_direct(pg)		((vaddr_t)VM_PAGE_TO_PHYS(pg))
132 #define pmap_unmap_direct(va)		PHYS_TO_VM_PAGE((paddr_t)va)
133 #define	__HAVE_PMAP_DIRECT
134 
135 void pmap_bootstrap(u_int kernelstart, u_int kernelend);
136 void pmap_enable_mmu();
137 
138 int pmap_clear_attrs(struct vm_page *, unsigned int);
139 int pmap_test_attrs(struct vm_page *, unsigned int);
140 
141 void pmap_pinit(struct pmap *);
142 void pmap_release(struct pmap *);
143 
144 #ifdef ALTIVEC
145 int pmap_copyinsn(pmap_t, vaddr_t, uint32_t *);
146 #endif
147 
148 void pmap_real_memory(vaddr_t *start, vsize_t *size);
149 
150 int pte_spill_v(struct pmap *pm, u_int32_t va, u_int32_t dsisr, int exec_fault);
151 int reserve_dumppages(caddr_t p);
152 
153 #define pmap_init_percpu()		do { /* nothing */ } while (0)
154 #define pmap_unuse_final(p)		/* nothing */
155 #define	pmap_remove_holes(vm)		do { /* nothing */ } while (0)
156 
157 #define PMAP_CHECK_COPYIN	(ppc_proc_is_64b == 0)
158 
159 #define	PMAP_STEAL_MEMORY
160 
161 #define PG_PMAP_MOD	PG_PMAP0
162 #define PG_PMAP_REF	PG_PMAP1
163 #define PG_PMAP_EXE	PG_PMAP2
164 #define PG_PMAP_UC	PG_PMAP3
165 
166 /*
167  * MD flags that we use for pmap_enter (in the pa):
168  */
169 #define PMAP_PA_MASK	~((paddr_t)PAGE_MASK) /* to remove the flags */
170 #define PMAP_NOCACHE	0x1		/* map uncached */
171 #define PMAP_WT		0x2		/* map write-through */
172 
173 #endif	/* _KERNEL */
174 
175 struct vm_page_md {
176 	struct mutex pv_mtx;
177 	LIST_HEAD(,pte_desc) pv_list;
178 };
179 
180 #define VM_MDPAGE_INIT(pg) do {                 \
181 	mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \
182 	LIST_INIT(&((pg)->mdpage.pv_list)); 	\
183 } while (0)
184 
185 #endif	/* _LOCORE */
186 
187 #endif	/* _POWERPC_PMAP_H_ */
188