| 1 | /*	$OpenBSD: pmap.h,v 1.66 2024/06/18 12:37:29 jsg 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_release(struct pmap *); |
| 142 | |
| 143 | #ifdef ALTIVEC |
| 144 | int pmap_copyinsn(pmap_t, vaddr_t, uint32_t *); |
| 145 | #endif |
| 146 | |
| 147 | void pmap_real_memory(vaddr_t *start, vsize_t *size); |
| 148 | |
| 149 | int pte_spill_v(struct pmap *pm, u_int32_t va, u_int32_t dsisr, int exec_fault); |
| 150 | int reserve_dumppages(caddr_t p); |
| 151 | |
| 152 | #define pmap_init_percpu()		do { /* nothing */ } while (0) |
| 153 | #define pmap_unuse_final(p)		/* nothing */ |
| 154 | #define	pmap_remove_holes(vm)		do { /* nothing */ } while (0) |
| 155 | |
| 156 | #define PMAP_CHECK_COPYIN	(ppc_proc_is_64b == 0) |
| 157 | |
| 158 | #define	PMAP_STEAL_MEMORY |
| 159 | |
| 160 | #define PG_PMAP_MOD	PG_PMAP0 |
| 161 | #define PG_PMAP_REF	PG_PMAP1 |
| 162 | #define PG_PMAP_EXE	PG_PMAP2 |
| 163 | #define PG_PMAP_UC	PG_PMAP3 |
| 164 | |
| 165 | /* |
| 166 | * MD flags that we use for pmap_enter (in the pa): |
| 167 | */ |
| 168 | #define PMAP_PA_MASK	~((paddr_t)PAGE_MASK) /* to remove the flags */ |
| 169 | #define PMAP_NOCACHE	0x1		/* map uncached */ |
| 170 | #define PMAP_WT		0x2		/* map write-through */ |
| 171 | |
| 172 | #endif	/* _KERNEL */ |
| 173 | |
| 174 | struct vm_page_md { |
| 175 | 	struct mutex pv_mtx; |
| 176 | 	LIST_HEAD(,pte_desc) pv_list; |
| 177 | }; |
| 178 | |
| 179 | #define VM_MDPAGE_INIT(pg) do { \ |
| 180 | 	mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \ |
| 181 | 	LIST_INIT(&((pg)->mdpage.pv_list)); 	\ |
| 182 | } while (0) |
| 183 | |
| 184 | #endif	/* _LOCORE */ |
| 185 | |
| 186 | #endif	/* _POWERPC_PMAP_H_ */ |