xref: /openbsd/sys/arch/powerpc/include/pmap.h (revision 09467b48)
1 /*	$OpenBSD: pmap.h,v 1.59 2015/10/08 10:20:14 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 #ifdef	_KERNEL
81 
82 /*
83  * Pmap stuff
84  */
85 struct pmap {
86 	sr_t pm_sr[16];		/* segments used in this pmap */
87 	struct pmapvp *pm_vp[VP_SR_SIZE];	/* virtual to physical table */
88 	u_int32_t pm_exec[16];	/* segments used in this pmap */
89 	int pm_refs;		/* ref count */
90 	struct pmap_statistics	pm_stats;	/* pmap statistics */
91 	struct mutex		pm_mtx;		/* protect VP table */
92 };
93 
94 /*
95  * Segment handling stuff
96  */
97 #define	PPC_SEGMENT_LENGTH	0x10000000
98 #define	PPC_SEGMENT_MASK	0xf0000000
99 
100 /*
101  * Some system constants
102  */
103 #ifndef	NPMAPS
104 #define	NPMAPS		32768	/* Number of pmaps in system */
105 #endif
106 
107 typedef	struct pmap *pmap_t;
108 
109 extern struct pmap kernel_pmap_;
110 #define	pmap_kernel()	(&kernel_pmap_)
111 
112 
113 #define pmap_clear_modify(pg)		pmap_clear_attrs((pg), PG_PMAP_MOD)
114 #define	pmap_clear_reference(pg)	pmap_clear_attrs((pg), PG_PMAP_REF)
115 #define	pmap_is_modified(pg)		pmap_test_attrs((pg), PG_PMAP_MOD)
116 #define	pmap_is_referenced(pg)		pmap_test_attrs((pg), PG_PMAP_REF)
117 
118 #define	pmap_unwire(pm, va)
119 #define pmap_update(pmap)	/* nothing (yet) */
120 
121 #define pmap_resident_count(pmap)       ((pmap)->pm_stats.resident_count)
122 
123 /*
124  * Alternate mapping methods for pool.
125  * Really simple. 0x0->0x80000000 contain 1->1 mappings of the physical
126  * memory. - XXX
127  */
128 #define pmap_map_direct(pg)		((vaddr_t)VM_PAGE_TO_PHYS(pg))
129 #define pmap_unmap_direct(va)		PHYS_TO_VM_PAGE((paddr_t)va)
130 #define	__HAVE_PMAP_DIRECT
131 
132 void pmap_bootstrap(u_int kernelstart, u_int kernelend);
133 void pmap_enable_mmu();
134 
135 int pmap_clear_attrs(struct vm_page *, unsigned int);
136 int pmap_test_attrs(struct vm_page *, unsigned int);
137 
138 void pmap_pinit(struct pmap *);
139 void pmap_release(struct pmap *);
140 
141 void pmap_real_memory(vaddr_t *start, vsize_t *size);
142 void switchexit(struct proc *);
143 
144 int pte_spill_v(struct pmap *pm, u_int32_t va, u_int32_t dsisr, int exec_fault);
145 #define pmap_copy(dst_pmap, src_pmap, dst_addr, len, src_addr) ;
146 int reserve_dumppages(caddr_t p);
147 
148 #define pmap_unuse_final(p)		/* nothing */
149 #define	pmap_remove_holes(vm)		do { /* nothing */ } while (0)
150 
151 #define	PMAP_STEAL_MEMORY
152 
153 #define PG_PMAP_MOD	PG_PMAP0
154 #define PG_PMAP_REF	PG_PMAP1
155 #define PG_PMAP_EXE	PG_PMAP2
156 #define PG_PMAP_UC	PG_PMAP3
157 
158 /*
159  * MD flags that we use for pmap_enter (in the pa):
160  */
161 #define PMAP_PA_MASK	~((paddr_t)PAGE_MASK) /* to remove the flags */
162 #define PMAP_NOCACHE	0x1		/* map uncached */
163 #define PMAP_WT		0x2		/* map write-through */
164 
165 #endif	/* _KERNEL */
166 
167 #include <sys/mutex.h>
168 
169 struct vm_page_md {
170 	struct mutex pv_mtx;
171 	LIST_HEAD(,pte_desc) pv_list;
172 };
173 
174 #define VM_MDPAGE_INIT(pg) do {                 \
175 	mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \
176 	LIST_INIT(&((pg)->mdpage.pv_list)); 	\
177 } while (0)
178 
179 #endif	/* _LOCORE */
180 
181 #endif	/* _POWERPC_PMAP_H_ */
182