xref: /netbsd-src/sys/arch/sparc64/include/param.h (revision 220b5c059a84c51ea44107ea8951a57ffaecdc8c)
1 /*	$NetBSD: param.h,v 1.26 2001/12/04 00:53:19 darrenr Exp $ */
2 
3 /*
4  * Copyright (c) 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This software was developed by the Computer Systems Engineering group
8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9  * contributed to Berkeley.
10  *
11  * All advertising materials mentioning features or use of this software
12  * must display the following acknowledgement:
13  *	This product includes software developed by the University of
14  *	California, Lawrence Berkeley Laboratory.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  * 3. All advertising materials mentioning features or use of this software
25  *    must display the following acknowledgement:
26  *	This product includes software developed by the University of
27  *	California, Berkeley and its contributors.
28  * 4. Neither the name of the University nor the names of its contributors
29  *    may be used to endorse or promote products derived from this software
30  *    without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42  * SUCH DAMAGE.
43  *
44  *	@(#)param.h	8.1 (Berkeley) 6/11/93
45  */
46 
47 /*
48  * Copyright (c) 1996-1999 Eduardo Horvath
49  *
50  * Redistribution and use in source and binary forms, with or without
51  * modification, are permitted provided that the following conditions
52  * are met:
53  * 1. Redistributions of source code must retain the above copyright
54  *    notice, this list of conditions and the following disclaimer.
55  *
56  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR  ``AS IS'' AND
57  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR  BE LIABLE
60  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66  * SUCH DAMAGE.
67  *
68  */
69 
70 #if defined(_KERNEL_OPT)
71 #include "opt_sparc_arch.h"
72 #endif
73 
74 #define	_MACHINE	sparc64
75 #define	MACHINE		"sparc64"
76 #ifdef __arch64__
77 #define	_MACHINE_ARCH	sparc64
78 #define	MACHINE_ARCH	"sparc64"
79 #define	MID_MACHINE	MID_SPARC64
80 #else
81 #define	_MACHINE_ARCH	sparc
82 #define	MACHINE_ARCH	"sparc"
83 #define	MID_MACHINE	MID_SPARC
84 #endif
85 
86 #ifdef _KERNEL_OPT
87 #include "opt_sparc_arch.h"
88 #endif
89 #ifdef _KERNEL				/* XXX */
90 #ifndef _LOCORE				/* XXX */
91 #include <machine/cpu.h>		/* XXX */
92 #endif					/* XXX */
93 #endif					/* XXX */
94 
95 /*
96  * Round p (pointer or byte index) up to a correctly-aligned value for
97  * the machine's strictest data type.  The result is u_int and must be
98  * cast to any desired pointer type.
99  *
100  * ALIGNED_POINTER is a boolean macro that checks whether an address
101  * is valid to fetch data elements of type t from on this architecture.
102  * This does not reflect the optimal alignment, just the possibility
103  * (within reasonable limits).
104  *
105  */
106 #define ALIGNBYTES32		0x7
107 #define ALIGNBYTES64		0xf
108 #ifdef __arch64__
109 #define	ALIGNBYTES		ALIGNBYTES64
110 #else
111 #define	ALIGNBYTES		ALIGNBYTES32
112 #endif
113 #define	ALIGN(p)		(((u_long)(p) + ALIGNBYTES) & ~ALIGNBYTES)
114 #define ALIGN32(p)		(((u_long)(p) + ALIGNBYTES32) & ~ALIGNBYTES32)
115 #define ALIGNED_POINTER(p,t)	((((u_long)(p)) & (sizeof(t)-1)) == 0)
116 
117 
118 /*
119  * The following variables are always defined and initialized (in locore)
120  * so independently compiled modules (e.g. LKMs) can be used irrespective
121  * of the `options SUN4?' combination a particular kernel was configured with.
122  * See also the definitions of NBPG, PGOFSET and PGSHIFT below.
123  */
124 #if (defined(_KERNEL) || defined(_STANDALONE)) && !defined(_LOCORE)
125 extern int nbpg, pgofset, pgshift;
126 #endif
127 
128 #define	DEV_BSIZE	512
129 #define	DEV_BSHIFT	9		/* log2(DEV_BSIZE) */
130 #define	BLKDEV_IOSIZE	2048
131 #define	MAXPHYS		(64 * 1024)
132 
133 #ifdef __arch64__
134 /* We get stack overflows w/8K stacks in 64-bit mode */
135 #define	SSIZE		2		/* initial stack size in pages */
136 #else
137 #define	SSIZE		2
138 #endif
139 #define	USPACE		(SSIZE*8192)
140 
141 
142 /*
143  * Here are all the magic kernel virtual addresses and how they're allocated.
144  *
145  * First, the PROM is usually a fixed-sized block from 0x00000000f0000000 to
146  * 0x00000000f0100000.  It also uses some space around 0x00000000fff00000 to
147  * map in device registers.  The rest is pretty much ours to play with.
148  *
149  * The kernel starts at KERNBASE.  Here's they layout.  We use macros to set
150  * the addresses so we can relocate everything easily.  We use 4MB locked TTEs
151  * to map in the kernel text and data segments.  Any extra pages are recycled,
152  * so they can potentially be double-mapped.  This shouldn't really be a
153  * problem since they're unused, but wild pointers can cause silent data
154  * corruption if they are in those segments.
155  *
156  * 0x0000000000000000:	64K NFO page zero
157  * 0x0000000000010000:	Userland or PROM
158  * KERNBASE:		4MB kernel text and read only data
159  *				This is mapped in the ITLB and
160  *				Read-Only in the DTLB
161  * KERNBASE+0x400000:	4MB kernel data and BSS -- not in ITLB
162  *				Contains context table, kernel pmap,
163  *				and other important structures.
164  * KERNBASE+0x800000:	Unmapped page -- redzone
165  * KERNBASE+0x802000:	Process 0 stack and u-area
166  * KERNBASE+0x806000:	2 pages for pmap_copy_page and /dev/mem
167  * KERNBASE+0x80a000:	Start of kernel VA segment
168  * KERNEND:		End of kernel VA segment
169  * KERNEND+0x02000:	Auxreg_va (unused?)
170  * KERNEND+0x04000:	TMPMAP_VA (unused?)
171  * KERNEND+0x06000:	message buffer.
172  * KERNEND+0x010000:	64K locked TTE -- different for each CPU
173  *			Contains interrupt stack, cpu_info structure,
174  *			and 32KB kernel TSB.
175  * KERNEND+0x020000:	IODEV_BASE -- begin mapping IO devices here.
176  * 0x00000000fe000000:	IODEV_END -- end of device mapping space.
177  *
178  */
179 #define	KERNBASE	0x001000000	/* start of kernel virtual space */
180 #define	KERNEND		0x0e0000000	/* end of kernel virtual space */
181 #define	VM_MAX_KERNEL_BUF	((KERNEND-KERNBASE)/4)
182 
183 #define _MAXNBPG	8192	/* fixed VAs, independent of actual NBPG */
184 
185 #define	AUXREG_VA	(      KERNEND + _MAXNBPG) /* 1 page REDZONE */
186 #define	TMPMAP_VA	(    AUXREG_VA + _MAXNBPG)
187 #define	MSGBUF_VA	(    TMPMAP_VA + _MAXNBPG)
188 /*
189  * Here's the location of the interrupt stack and CPU structure.
190  */
191 #define INTSTACK	(      KERNEND + 8*_MAXNBPG)/* 64K after kernel end */
192 #define	EINTSTACK	(     INTSTACK + 2*USPACE)	/* 32KB */
193 #define	CPUINFO_VA	(    EINTSTACK)
194 #define	IODEV_BASE	(   CPUINFO_VA + 8*_MAXNBPG)/* 64K long */
195 #define	IODEV_END	0x0f0000000UL		/* 16 MB of iospace */
196 
197 /*
198  * Constants related to network buffer management.
199  * MCLBYTES must be no larger than NBPG (the software page size), and,
200  * on machines that exchange pages of input or output buffers with mbuf
201  * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
202  * of the hardware page size.
203  */
204 #define	MSIZE		256		/* size of an mbuf */
205 #define	MCLBYTES	2048		/* enough for whole Ethernet packet */
206 #define	MCLSHIFT	11		/* log2(MCLBYTES) */
207 #define	MCLOFSET	(MCLBYTES - 1)
208 
209 #if defined(_KERNEL_OPT)
210 #include "opt_gateway.h"
211 #endif
212 
213 #ifndef NMBCLUSTERS
214 #ifdef GATEWAY
215 #define	NMBCLUSTERS	512		/* map size, max cluster allocation */
216 #else
217 #define	NMBCLUSTERS	256		/* map size, max cluster allocation */
218 #endif
219 #endif
220 
221 #define MSGBUFSIZE	NBPG
222 
223 /*
224  * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized
225  * logical pages.
226  */
227 #define	NKMEMPAGES_MIN_DEFAULT	((6 * 1024 * 1024) >> PAGE_SHIFT)
228 #define	NKMEMPAGES_MAX_DEFAULT	((128 * 1024 * 1024) >> PAGE_SHIFT)
229 
230 /* pages ("clicks") to disk blocks */
231 #define	ctod(x)		((x) << (PGSHIFT - DEV_BSHIFT))
232 #define	dtoc(x)		((x) >> (PGSHIFT - DEV_BSHIFT))
233 
234 /* pages to bytes */
235 #define	ctob(x)		((x) << PGSHIFT)
236 #define	btoc(x)		(((vsize_t)(x) + PGOFSET) >> PGSHIFT)
237 
238 /* bytes to disk blocks */
239 #define	btodb(x)	((x) >> DEV_BSHIFT)
240 #define	dbtob(x)	((x) << DEV_BSHIFT)
241 
242 /*
243  * Map a ``block device block'' to a file system block.
244  * This should be device dependent, and should use the bsize
245  * field from the disk label.
246  * For now though just use DEV_BSIZE.
247  */
248 #define	bdbtofsb(bn)	((bn) / (BLKDEV_IOSIZE / DEV_BSIZE))
249 
250 /*
251  * dvmamap manages a range of DVMA addresses intended to create double
252  * mappings of physical memory. In a way, `dvmamap' is a submap of the
253  * VM map `phys_map'. The difference is the use of the `resource map'
254  * routines to manage page allocation, allowing DVMA addresses to be
255  * allocated and freed from within interrupt routines.
256  *
257  * Note that `phys_map' can still be used to allocate memory-backed pages
258  * in DVMA space.
259  */
260 #ifdef _KERNEL
261 #ifndef _LOCORE
262 #if 0
263 extern vaddr_t	dvma_base;
264 extern vaddr_t	dvma_end;
265 extern struct map	*dvmamap;
266 /*
267  * The dvma resource map is defined in page units, which are numbered 1 to N.
268  * Use these macros to convert to/from virtual addresses.
269  */
270 #define rctov(n)		(ctob(((n)-1))+dvma_base)
271 #define vtorc(v)		((btoc((v)-dvma_base))+1)
272 
273 extern caddr_t	kdvma_mapin __P((caddr_t, int, int));
274 extern caddr_t	dvma_malloc __P((size_t, void *, int));
275 extern void	dvma_free __P((caddr_t, size_t, void *));
276 #endif
277 
278 extern void	delay __P((unsigned int));
279 #define	DELAY(n)	delay(n)
280 
281 extern int cputyp;
282 extern int cpumod;
283 extern int mmumod;
284 
285 #endif /* _LOCORE */
286 #endif /* _KERNEL */
287 
288 /*
289  * Values for the cputyp variable.
290  */
291 #define CPU_SUN4	0
292 #define CPU_SUN4C	1
293 #define CPU_SUN4M	2
294 #define CPU_SUN4U	3
295 
296 /*
297  * Shorthand CPU-type macros. Enumerate all eight cases.
298  * Let compiler optimize away code conditional on constants.
299  *
300  * On a sun4 machine, the page size is 8192, while on a sun4c and sun4m
301  * it is 4096. Therefore, in the (SUN4 && (SUN4C || SUN4M)) cases below,
302  * NBPG, PGOFSET and PGSHIFT are defined as variables which are initialized
303  * early in locore.s after the machine type has been detected.
304  *
305  * Note that whenever the macros defined below evaluate to expressions
306  * involving variables, the kernel will perform slighly worse due to the
307  * extra memory references they'll generate.
308  */
309 
310 #define CPU_ISSUN4U	(1)
311 #define CPU_ISSUN4MOR4U	(1)
312 #define CPU_ISSUN4M	(0)
313 #define CPU_ISSUN4C	(0)
314 #define CPU_ISSUN4	(0)
315 #define CPU_ISSUN4OR4C	(0)
316 #define CPU_ISSUN4COR4M	(0)
317 #define	NBPG		8192		/* bytes/page */
318 #define	PGOFSET		(NBPG-1)	/* byte offset into page */
319 #define	PGSHIFT		13		/* log2(NBPG) */
320