xref: /titanic_41/usr/src/lib/libbc/inc/include/sun4/mmu.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_SUN4_MMU_H
28*7c478bd9Sstevel@tonic-gate #define	_SUN4_MMU_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
33*7c478bd9Sstevel@tonic-gate extern "C" {
34*7c478bd9Sstevel@tonic-gate #endif
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate /*
37*7c478bd9Sstevel@tonic-gate  * Sun-4 memory management unit.
38*7c478bd9Sstevel@tonic-gate  * All sun-4 implementations use 32 bits of address.
39*7c478bd9Sstevel@tonic-gate  * A particular implementation may implement a smaller MMU.
40*7c478bd9Sstevel@tonic-gate  * If so, the missing addresses are in the "middle" of the
41*7c478bd9Sstevel@tonic-gate  * 32 bit address space. All accesses in this range behave
42*7c478bd9Sstevel@tonic-gate  * as if there was an invalid page map entry correspronding
43*7c478bd9Sstevel@tonic-gate  * to the address.
44*7c478bd9Sstevel@tonic-gate  *
45*7c478bd9Sstevel@tonic-gate  * There are two types of MMUs a 2 level MMU and a 3 level MMU.
46*7c478bd9Sstevel@tonic-gate  * Three level MMUs do not have holes.
47*7c478bd9Sstevel@tonic-gate  */
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate /*
50*7c478bd9Sstevel@tonic-gate  * Hardware context and segment information
51*7c478bd9Sstevel@tonic-gate  * Mnemonic decoding:
52*7c478bd9Sstevel@tonic-gate  *	PMENT - Page Map ENTry
53*7c478bd9Sstevel@tonic-gate  *	PMGRP - Group of PMENTs (aka "segment")
54*7c478bd9Sstevel@tonic-gate  *	SMENT - Segment Map ENTry - 3 level MMU only
55*7c478bd9Sstevel@tonic-gate  *	SMGRP - Group of SMENTs (aka "region") - 3 level MMU only
56*7c478bd9Sstevel@tonic-gate  */
57*7c478bd9Sstevel@tonic-gate /* fixed SUN4 constants */
58*7c478bd9Sstevel@tonic-gate #define	NPMENTPERPMGRP		32
59*7c478bd9Sstevel@tonic-gate #define	NPMENTPERPMGRPSHIFT	5	/* log2(NPMENTPERPMGRP) */
60*7c478bd9Sstevel@tonic-gate #define	PMGRPSIZE	(NPMENTPERPMGRP * PAGESIZE)
61*7c478bd9Sstevel@tonic-gate #define	PMGRPOFFSET	(PMGRPSIZE - 1)
62*7c478bd9Sstevel@tonic-gate #define	PMGRPSHIFT	(PAGESHIFT + NPMENTPERPMGRPSHIFT)
63*7c478bd9Sstevel@tonic-gate #define	PMGRPMASK	(~PMGRPOFFSET)
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate #define	NSMENTPERSMGRP		64
66*7c478bd9Sstevel@tonic-gate #define	NSMENTPERSMGRPSHIFT	6	/* log2(NSMENTPERSMGRP) */
67*7c478bd9Sstevel@tonic-gate #define	SMGRPSIZE	(NSMENTPERSMGRP * PMGRPSIZE)
68*7c478bd9Sstevel@tonic-gate #define	SMGRPOFFSET	(SMGRPSIZE - 1)
69*7c478bd9Sstevel@tonic-gate #define	SMGRPSHIFT	(PMGRPSHIFT + NSMENTPERSMGRPSHIFT)
70*7c478bd9Sstevel@tonic-gate #define	SMGRPMASK	(~SMGRPOFFSET)
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate #define	NSMGRPPERCTX		256
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate /*
75*7c478bd9Sstevel@tonic-gate  * Useful defines for hat constants,
76*7c478bd9Sstevel@tonic-gate  * Every implementation seems to have its own set
77*7c478bd9Sstevel@tonic-gate  * they are set at boot time by setcputype()
78*7c478bd9Sstevel@tonic-gate  */
79*7c478bd9Sstevel@tonic-gate #define	NCTXS		nctxs
80*7c478bd9Sstevel@tonic-gate #define	NPMGRPS		npmgrps
81*7c478bd9Sstevel@tonic-gate #define	NSMGRPS		nsmgrps
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate /*
84*7c478bd9Sstevel@tonic-gate  * Variables set at boot time to reflect cpu type.
85*7c478bd9Sstevel@tonic-gate  */
86*7c478bd9Sstevel@tonic-gate #ifndef LOCORE
87*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate extern uint_t nctxs;		/* number of implemented contexts */
90*7c478bd9Sstevel@tonic-gate extern uint_t npmgrps;		/* number of pmgrps in page map */
91*7c478bd9Sstevel@tonic-gate #ifdef	MMU_3LEVEL
92*7c478bd9Sstevel@tonic-gate extern uint_t nsmgrps;		/* number of smgrps in segment map (3 level) */
93*7c478bd9Sstevel@tonic-gate #endif	/* MMU_3LEVEL */
94*7c478bd9Sstevel@tonic-gate extern uint_t segmask;		/* mask for segment number */
95*7c478bd9Sstevel@tonic-gate extern addr_t hole_start;	/* addr of start of MMU "hole" */
96*7c478bd9Sstevel@tonic-gate extern addr_t hole_end;		/* addr of end of MMU "hole" */
97*7c478bd9Sstevel@tonic-gate extern uint_t shm_alignment;	/* VAC address consistency modulus */
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate #ifdef MMU_3LEVEL
100*7c478bd9Sstevel@tonic-gate extern int mmu_3level;		/* indicates 3 level MMU can exist */
101*7c478bd9Sstevel@tonic-gate #endif /* MMU_3LEVEL */
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate #define	PMGRP_INVALID (NPMGRPS - 1)
104*7c478bd9Sstevel@tonic-gate #define	SMGRP_INVALID (NSMGRPS - 1)
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate /*
107*7c478bd9Sstevel@tonic-gate  * Macro to determine whether an address is within the range of the MMU.
108*7c478bd9Sstevel@tonic-gate  */
109*7c478bd9Sstevel@tonic-gate #ifdef MMU_3LEVEL
110*7c478bd9Sstevel@tonic-gate #define	good_addr(a) \
111*7c478bd9Sstevel@tonic-gate 	(mmu_3level || (addr_t)(a) < hole_start || (addr_t)(a) >= hole_end)
112*7c478bd9Sstevel@tonic-gate #else
113*7c478bd9Sstevel@tonic-gate #define	good_addr(a) \
114*7c478bd9Sstevel@tonic-gate 	((addr_t)(a) < hole_start || (addr_t)(a) >= hole_end)
115*7c478bd9Sstevel@tonic-gate #endif /* MMU_3LEVEL */
116*7c478bd9Sstevel@tonic-gate #endif /* !LOCORE */
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate /*
119*7c478bd9Sstevel@tonic-gate  * Address space identifiers.
120*7c478bd9Sstevel@tonic-gate  */
121*7c478bd9Sstevel@tonic-gate #define	ASI_CTL	0x2		/* control space */
122*7c478bd9Sstevel@tonic-gate #define	ASI_SM	0x3		/* segment map */
123*7c478bd9Sstevel@tonic-gate #define	ASI_PM	0x4		/* page map */
124*7c478bd9Sstevel@tonic-gate #define	ASI_BC	0x5		/* block copy */
125*7c478bd9Sstevel@tonic-gate #define	ASI_RM	0x6		/* region map */
126*7c478bd9Sstevel@tonic-gate #define	ASI_FCR	0x7		/* flush cache region */
127*7c478bd9Sstevel@tonic-gate #define	ASI_UP	0x8		/* user program */
128*7c478bd9Sstevel@tonic-gate #define	ASI_SP	0x9		/* supervisor program */
129*7c478bd9Sstevel@tonic-gate #define	ASI_UD	0xA		/* user data */
130*7c478bd9Sstevel@tonic-gate #define	ASI_SD	0xB		/* supervisor data */
131*7c478bd9Sstevel@tonic-gate #define	ASI_FCS	0xC		/* flush cache segment */
132*7c478bd9Sstevel@tonic-gate #define	ASI_FCP	0xD		/* flush cache page */
133*7c478bd9Sstevel@tonic-gate #define	ASI_FCC	0xE		/* flush cache context */
134*7c478bd9Sstevel@tonic-gate #define	ASI_FCU 0xF		/* flush cache user, sunray */
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate #define	ASI_CD	0xF		/* cache data, sunrise */
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate /*
139*7c478bd9Sstevel@tonic-gate  * ASI_CTL addresses
140*7c478bd9Sstevel@tonic-gate  */
141*7c478bd9Sstevel@tonic-gate #define	ID_PROM		0x00000000
142*7c478bd9Sstevel@tonic-gate #define	CONTEXT_REG	0x30000000
143*7c478bd9Sstevel@tonic-gate #define	SYSTEM_ENABLE	0x40000000
144*7c478bd9Sstevel@tonic-gate #define	BUS_ERROR_REG	0x60000000
145*7c478bd9Sstevel@tonic-gate #define	DIAGNOSTIC_REG	0x70000000
146*7c478bd9Sstevel@tonic-gate #define	CACHE_TAGS	0x80000000
147*7c478bd9Sstevel@tonic-gate #define	CACHE_DATA	0x90000000	/* cache data, sunray */
148*7c478bd9Sstevel@tonic-gate #define	VME_INT_VEC	0xE0000000
149*7c478bd9Sstevel@tonic-gate #define	UART_BYPASS	0xF0000000
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate #define	IDPROMSIZE	0x20		/* size of id prom in bytes */
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate /*
154*7c478bd9Sstevel@tonic-gate  * Constants for cache operations.
155*7c478bd9Sstevel@tonic-gate  * XXX - should be deleted but the standalones (boot) use them.
156*7c478bd9Sstevel@tonic-gate  */
157*7c478bd9Sstevel@tonic-gate #define	VAC_SIZE		0x20000		/* 128K */
158*7c478bd9Sstevel@tonic-gate #define	VAC_LINESIZE_SUNRISE	16		/* 16 bytes per line */
159*7c478bd9Sstevel@tonic-gate #define	VAC_LINESIZE_SUNRAY	32		/* 32 bytes per line */
160*7c478bd9Sstevel@tonic-gate #define	NPMGRPPERCTX_110	4096
161*7c478bd9Sstevel@tonic-gate #define	NPMGRPPERCTX_260	4096
162*7c478bd9Sstevel@tonic-gate #define	NPMGRPPERCTX_330	4096
163*7c478bd9Sstevel@tonic-gate #define	NPMGRPS_110		256
164*7c478bd9Sstevel@tonic-gate #define	NPMGRPS_260		512
165*7c478bd9Sstevel@tonic-gate #define	NPMGRPS_330		256
166*7c478bd9Sstevel@tonic-gate #define	NPMGRPS_470		1024
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate /*
169*7c478bd9Sstevel@tonic-gate  * Various I/O space related constants
170*7c478bd9Sstevel@tonic-gate  */
171*7c478bd9Sstevel@tonic-gate #define	VME16_BASE	0xFFFF0000
172*7c478bd9Sstevel@tonic-gate #define	VME16_SIZE	(1<<16)
173*7c478bd9Sstevel@tonic-gate #define	VME16_MASK	(VME16_SIZE-1)
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate #define	VME24_BASE	0xFF000000
176*7c478bd9Sstevel@tonic-gate #define	VME24_SIZE	(1<<24)
177*7c478bd9Sstevel@tonic-gate #define	VME24_MASK	(VME24_SIZE-1)
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate /*
180*7c478bd9Sstevel@tonic-gate  * Virtual address where dvma starts.
181*7c478bd9Sstevel@tonic-gate  */
182*7c478bd9Sstevel@tonic-gate #define	DVMABASE	(0-(1024*1024))
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate /*
185*7c478bd9Sstevel@tonic-gate  * Context for kernel. On a Sun-4 the kernel is in every address space,
186*7c478bd9Sstevel@tonic-gate  * but KCONTEXT is magic in that there is never any user context there.
187*7c478bd9Sstevel@tonic-gate  */
188*7c478bd9Sstevel@tonic-gate #define	KCONTEXT	0
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate /*
191*7c478bd9Sstevel@tonic-gate  * MDEVBASE is a virtual segment reserved for mapping misc. obio devices.
192*7c478bd9Sstevel@tonic-gate  * The base address and the number of devices mapped should not cause the
193*7c478bd9Sstevel@tonic-gate  * device mappings to cross a segment boundary.  We use the segment
194*7c478bd9Sstevel@tonic-gate  * immediately before SYSBASE
195*7c478bd9Sstevel@tonic-gate  */
196*7c478bd9Sstevel@tonic-gate #define	MDEVBASE	(SYSBASE - PMGRPSIZE)
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate /*
199*7c478bd9Sstevel@tonic-gate  * SEGTEMP & SEGTEMP2 are virtual segments reserved for temporary operations.
200*7c478bd9Sstevel@tonic-gate  * We use the segments immediately before the start of debugger area.
201*7c478bd9Sstevel@tonic-gate  */
202*7c478bd9Sstevel@tonic-gate #define	SEGTEMP		((addr_t)(DEBUGSTART - (2 * PMGRPSIZE)))
203*7c478bd9Sstevel@tonic-gate #define	SEGTEMP2	((addr_t)(DEBUGSTART - PMGRPSIZE))
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate /*
206*7c478bd9Sstevel@tonic-gate  * REGTEMP is only during intialization, we use the
207*7c478bd9Sstevel@tonic-gate  * REGION immediately before KERNELBASE, it is invalidated
208*7c478bd9Sstevel@tonic-gate  * after use
209*7c478bd9Sstevel@tonic-gate  */
210*7c478bd9Sstevel@tonic-gate #define	REGTEMP		((KERNELBASE-SMGRPSIZE)&SMGRPMASK)
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate #if defined(KERNEL) && !defined(LOCORE)
213*7c478bd9Sstevel@tonic-gate 
214*7c478bd9Sstevel@tonic-gate #ifdef VAC
215*7c478bd9Sstevel@tonic-gate void vac_dontcache();
216*7c478bd9Sstevel@tonic-gate /*
217*7c478bd9Sstevel@tonic-gate  * cache related constants set at boot time
218*7c478bd9Sstevel@tonic-gate  */
219*7c478bd9Sstevel@tonic-gate extern int vac_size;			/* size of cache in bytes */
220*7c478bd9Sstevel@tonic-gate extern int vac_linesize;		/* cache linesize */
221*7c478bd9Sstevel@tonic-gate extern int vac_nlines;			/* number of lines in cache */
222*7c478bd9Sstevel@tonic-gate extern int vac_pglines;			/* number of cache lines in a page */
223*7c478bd9Sstevel@tonic-gate #endif /* VAC */
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate /*
226*7c478bd9Sstevel@tonic-gate  * Low level mmu-specific functions
227*7c478bd9Sstevel@tonic-gate  */
228*7c478bd9Sstevel@tonic-gate struct	ctx *mmu_getctx();
229*7c478bd9Sstevel@tonic-gate void	mmu_setctx(/* ctx */);
230*7c478bd9Sstevel@tonic-gate void	mmu_setpmg(/* base, pmg */);
231*7c478bd9Sstevel@tonic-gate void	mmu_settpmg(/* base, pmg */);
232*7c478bd9Sstevel@tonic-gate struct	pmgrp *mmu_getpmg(/* base */);
233*7c478bd9Sstevel@tonic-gate void	mmu_setpte(/* base, pte */);
234*7c478bd9Sstevel@tonic-gate void	mmu_getpte(/* base, ppte */);
235*7c478bd9Sstevel@tonic-gate void	mmu_getkpte(/* base, ppte */);
236*7c478bd9Sstevel@tonic-gate void	mmu_pmginval(/* pmg */);
237*7c478bd9Sstevel@tonic-gate #ifdef MMU_3LEVEL
238*7c478bd9Sstevel@tonic-gate struct	smgrp *mmu_getsmg(/* base */);
239*7c478bd9Sstevel@tonic-gate void	mmu_setsmg(/* base, smg */);
240*7c478bd9Sstevel@tonic-gate void	mmu_settsmg(/* base, smg */);
241*7c478bd9Sstevel@tonic-gate void	mmu_smginval(/* smg */);
242*7c478bd9Sstevel@tonic-gate #endif /* MMU_3LEVEL */
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate /*
245*7c478bd9Sstevel@tonic-gate  * Cache specific routines - ifdef'ed out if there is no chance
246*7c478bd9Sstevel@tonic-gate  * of running on a machine with a virtual address cache.
247*7c478bd9Sstevel@tonic-gate  */
248*7c478bd9Sstevel@tonic-gate #ifdef VAC
249*7c478bd9Sstevel@tonic-gate void	vac_init();
250*7c478bd9Sstevel@tonic-gate void	vac_tagsinit();
251*7c478bd9Sstevel@tonic-gate void	vac_flushall();
252*7c478bd9Sstevel@tonic-gate void	vac_ctxflush();
253*7c478bd9Sstevel@tonic-gate #ifdef MMU_3LEVEL
254*7c478bd9Sstevel@tonic-gate void	vac_usrflush();
255*7c478bd9Sstevel@tonic-gate void	vac_rgnflush(/* base */);
256*7c478bd9Sstevel@tonic-gate #endif /* MMU_3LEVEL */
257*7c478bd9Sstevel@tonic-gate void	vac_segflush(/* base */);
258*7c478bd9Sstevel@tonic-gate void	vac_pageflush(/* base */);
259*7c478bd9Sstevel@tonic-gate void	vac_flush(/* base, len */);
260*7c478bd9Sstevel@tonic-gate int	bp_alloc(/* map, bp, size */);
261*7c478bd9Sstevel@tonic-gate #else /* VAC */
262*7c478bd9Sstevel@tonic-gate #define	vac_init()
263*7c478bd9Sstevel@tonic-gate #define	vac_tagsinit()
264*7c478bd9Sstevel@tonic-gate #define	vac_flushall()
265*7c478bd9Sstevel@tonic-gate #define	vac_usrflush()
266*7c478bd9Sstevel@tonic-gate #define	vac_ctxflush()
267*7c478bd9Sstevel@tonic-gate #define	vac_rgnflush(base)
268*7c478bd9Sstevel@tonic-gate #define	vac_segflush(base)
269*7c478bd9Sstevel@tonic-gate #define	vac_pageflush(base)
270*7c478bd9Sstevel@tonic-gate #define	vac_flush(base, len)
271*7c478bd9Sstevel@tonic-gate #define	bp_alloc(map, bp, size)		(int)rmalloc((map), (long)(size))
272*7c478bd9Sstevel@tonic-gate #endif /* VAC */
273*7c478bd9Sstevel@tonic-gate 
274*7c478bd9Sstevel@tonic-gate int	valid_va_range(/* basep, lenp, minlen, dir */);
275*7c478bd9Sstevel@tonic-gate 
276*7c478bd9Sstevel@tonic-gate #endif /* defined(KERNEL) && !defined(LOCORE) */
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
279*7c478bd9Sstevel@tonic-gate }
280*7c478bd9Sstevel@tonic-gate #endif
281*7c478bd9Sstevel@tonic-gate 
282*7c478bd9Sstevel@tonic-gate #endif /* !_SUN4_MMU_H */
283