xref: /csrg-svn/sys/pmax/include/param.h (revision 69466)
152131Smckusick /*
252131Smckusick  * Copyright (c) 1988 University of Utah.
363217Sbostic  * Copyright (c) 1992, 1993
463217Sbostic  *	The Regents of the University of California.  All rights reserved.
552131Smckusick  *
652131Smckusick  * This code is derived from software contributed to Berkeley by
752131Smckusick  * the Systems Programming Group of the University of Utah Computer
852131Smckusick  * Science Department and Ralph Campbell.
952131Smckusick  *
1052131Smckusick  * %sccs.include.redist.c%
1152131Smckusick  *
1252131Smckusick  * from: Utah $Hdr: machparam.h 1.11 89/08/14$
1352131Smckusick  *
14*69466Smckusick  *	@(#)param.h	8.3 (Berkeley) 05/14/95
1552131Smckusick  */
1652131Smckusick 
1752131Smckusick /*
1852131Smckusick  * Machine dependent constants for DEC Station 3100.
1952131Smckusick  */
2052131Smckusick #define	MACHINE	"mips"
21*69466Smckusick #define NCPUS 1
2252131Smckusick 
2352941Sralph /*
2452941Sralph  * Round p (pointer or byte index) up to a correctly-aligned value for all
2552941Sralph  * data types (int, long, ...).   The result is u_int and must be cast to
2652941Sralph  * any desired pointer type.
2752941Sralph  */
2856673Sbostic #define	ALIGNBYTES	7
2953674Sbostic #define	ALIGN(p)	(((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES)
3052941Sralph 
3152131Smckusick #define	NBPG		4096		/* bytes/page */
3252131Smckusick #define	PGOFSET		(NBPG-1)	/* byte offset into page */
3352131Smckusick #define	PGSHIFT		12		/* LOG2(NBPG) */
3452131Smckusick #define	NPTEPG		(NBPG/4)
3552131Smckusick 
3659845Sralph #define NBSEG		0x400000	/* bytes/segment */
3759845Sralph #define	SEGOFSET	(NBSEG-1)	/* byte offset into segment */
3859845Sralph #define	SEGSHIFT	22		/* LOG2(NBSEG) */
3959845Sralph 
4052131Smckusick #define	KERNBASE	0x80000000	/* start of kernel virtual */
4152131Smckusick #define	BTOPKERNBASE	((u_long)KERNBASE >> PGSHIFT)
4252131Smckusick 
4352131Smckusick #define	DEV_BSIZE	512
4452131Smckusick #define	DEV_BSHIFT	9		/* log2(DEV_BSIZE) */
4552131Smckusick #define BLKDEV_IOSIZE	2048
4659845Sralph #define	MAXPHYS		(64 * 1024)	/* max raw I/O transfer size */
4752131Smckusick 
4852131Smckusick #define	CLSIZE		1
4952131Smckusick #define	CLSIZELOG2	0
5052131Smckusick 
5152131Smckusick /* NOTE: SSIZE, SINCR and UPAGES must be multiples of CLSIZE */
5252131Smckusick #define	SSIZE		1		/* initial stack size/NBPG */
5352131Smckusick #define	SINCR		1		/* increment of stack/NBPG */
5452131Smckusick 
5552131Smckusick #define	UPAGES		2		/* pages of u-area */
5653716Smckusick #define	UADDR		0xffffd000	/* address of u */
5752131Smckusick #define	UVPN		(UADDR>>PGSHIFT)/* virtual page number of u */
5852131Smckusick #define	KERNELSTACK	(UADDR+UPAGES*NBPG)	/* top of kernel stack */
5952131Smckusick 
6052131Smckusick /*
6152131Smckusick  * Constants related to network buffer management.
6252131Smckusick  * MCLBYTES must be no larger than CLBYTES (the software page size), and,
6352131Smckusick  * on machines that exchange pages of input or output buffers with mbuf
6452131Smckusick  * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
6552131Smckusick  * of the hardware page size.
6652131Smckusick  */
6752131Smckusick #define	MSIZE		128		/* size of an mbuf */
6852131Smckusick #define	MCLBYTES	1024
6952131Smckusick #define	MCLSHIFT	10
7052131Smckusick #define	MCLOFSET	(MCLBYTES - 1)
7152131Smckusick #ifndef NMBCLUSTERS
7252131Smckusick #ifdef GATEWAY
7352131Smckusick #define	NMBCLUSTERS	512		/* map size, max cluster allocation */
7452131Smckusick #else
7552131Smckusick #define	NMBCLUSTERS	256		/* map size, max cluster allocation */
7652131Smckusick #endif
7752131Smckusick #endif
7852131Smckusick 
7952131Smckusick /*
8052131Smckusick  * Size of kernel malloc arena in CLBYTES-sized logical pages
8152131Smckusick  */
8252131Smckusick #ifndef NKMEMCLUSTERS
8352131Smckusick #define	NKMEMCLUSTERS	(512*1024/CLBYTES)
8452131Smckusick #endif
8552131Smckusick 
8652131Smckusick /* pages ("clicks") (4096 bytes) to disk blocks */
8752131Smckusick #define	ctod(x)	((x)<<(PGSHIFT-DEV_BSHIFT))
8852131Smckusick #define	dtoc(x)	((x)>>(PGSHIFT-DEV_BSHIFT))
8952131Smckusick #define	dtob(x)	((x)<<DEV_BSHIFT)
9052131Smckusick 
9152131Smckusick /* pages to bytes */
9252131Smckusick #define	ctob(x)	((x)<<PGSHIFT)
9352131Smckusick 
9452131Smckusick /* bytes to pages */
9552131Smckusick #define	btoc(x)	(((unsigned)(x)+(NBPG-1))>>PGSHIFT)
9652131Smckusick 
9752131Smckusick #define	btodb(bytes)	 		/* calculates (bytes / DEV_BSIZE) */ \
9868634Smckusick 	((bytes) >> DEV_BSHIFT)
9952131Smckusick #define	dbtob(db)			/* calculates (db * DEV_BSIZE) */ \
10068634Smckusick 	((db) << DEV_BSHIFT)
10152131Smckusick 
10252131Smckusick /*
10352131Smckusick  * Map a ``block device block'' to a file system block.
10452131Smckusick  * This should be device dependent, and should use the bsize
10552131Smckusick  * field from the disk label.
10652131Smckusick  * For now though just use DEV_BSIZE.
10752131Smckusick  */
10852131Smckusick #define	bdbtofsb(bn)	((bn) / (BLKDEV_IOSIZE/DEV_BSIZE))
10952131Smckusick 
11052131Smckusick /*
11152131Smckusick  * Mach derived conversion macros
11252131Smckusick  */
11352131Smckusick #define pmax_round_page(x)	((((unsigned)(x)) + NBPG - 1) & ~(NBPG-1))
11452131Smckusick #define pmax_trunc_page(x)	((unsigned)(x) & ~(NBPG-1))
11552131Smckusick #define pmax_btop(x)		((unsigned)(x) >> PGSHIFT)
11652131Smckusick #define pmax_ptob(x)		((unsigned)(x) << PGSHIFT)
11752131Smckusick 
11852131Smckusick #ifdef KERNEL
11952131Smckusick #ifndef LOCORE
12056821Sralph extern int (*Mach_splnet)(), (*Mach_splbio)(), (*Mach_splimp)(),
12156821Sralph 	   (*Mach_spltty)(), (*Mach_splclock)(), (*Mach_splstatclock)();
12256821Sralph #define	splnet()	((*Mach_splnet)())
12356821Sralph #define	splbio()	((*Mach_splbio)())
12456821Sralph #define	splimp()	((*Mach_splimp)())
12556821Sralph #define	spltty()	((*Mach_spltty)())
12656821Sralph #define	splclock()	((*Mach_splclock)())
12756821Sralph #define	splstatclock()	((*Mach_splstatclock)())
12852131Smckusick extern	int cpuspeed;
12952131Smckusick #define	DELAY(n)	{ register int N = cpuspeed * (n); while (--N > 0); }
13052131Smckusick #endif
13152131Smckusick 
13252131Smckusick #else /* !KERNEL */
13352131Smckusick #define	DELAY(n)	{ register int N = (n); while (--N > 0); }
13452131Smckusick #endif /* !KERNEL */
135*69466Smckusick 
136*69466Smckusick #ifndef _SIMPLELOCK_H_
137*69466Smckusick #define _SIMPLELOCK_H_
138*69466Smckusick /*
139*69466Smckusick  * A simple spin lock.
140*69466Smckusick  *
141*69466Smckusick  * This structure only sets one bit of data, but is sized based on the
142*69466Smckusick  * minimum word size that can be operated on by the hardware test-and-set
143*69466Smckusick  * instruction. It is only needed for multiprocessors, as uniprocessors
144*69466Smckusick  * will always run to completion or a sleep. It is an error to hold one
145*69466Smckusick  * of these locks while a process is sleeping.
146*69466Smckusick  */
147*69466Smckusick struct simplelock {
148*69466Smckusick 	int	lock_data;
149*69466Smckusick };
150*69466Smckusick 
151*69466Smckusick #if !defined(DEBUG) && NCPUS > 1
152*69466Smckusick /*
153*69466Smckusick  * The simple-lock routines are the primitives out of which the lock
154*69466Smckusick  * package is built. The machine-dependent code must implement an
155*69466Smckusick  * atomic test_and_set operation that indivisibly sets the simple lock
156*69466Smckusick  * to non-zero and returns its old value. It also assumes that the
157*69466Smckusick  * setting of the lock to zero below is indivisible. Simple locks may
158*69466Smckusick  * only be used for exclusive locks.
159*69466Smckusick  */
160*69466Smckusick static __inline void
161*69466Smckusick simple_lock_init(lkp)
162*69466Smckusick 	struct simplelock *lkp;
163*69466Smckusick {
164*69466Smckusick 
165*69466Smckusick 	lkp->lock_data = 0;
166*69466Smckusick }
167*69466Smckusick 
168*69466Smckusick static __inline void
169*69466Smckusick simple_lock(lkp)
170*69466Smckusick 	__volatile struct simplelock *lkp;
171*69466Smckusick {
172*69466Smckusick 
173*69466Smckusick 	while (test_and_set(&lkp->lock_data))
174*69466Smckusick 		continue;
175*69466Smckusick }
176*69466Smckusick 
177*69466Smckusick static __inline int
178*69466Smckusick simple_lock_try(lkp)
179*69466Smckusick 	__volatile struct simplelock *lkp;
180*69466Smckusick {
181*69466Smckusick 
182*69466Smckusick 	return (!test_and_set(&lkp->lock_data))
183*69466Smckusick }
184*69466Smckusick 
185*69466Smckusick static __inline void
186*69466Smckusick simple_unlock(lkp)
187*69466Smckusick 	__volatile struct simplelock *lkp;
188*69466Smckusick {
189*69466Smckusick 
190*69466Smckusick 	lkp->lock_data = 0;
191*69466Smckusick }
192*69466Smckusick #endif /* NCPUS > 1 */
193*69466Smckusick #endif /* !_SIMPLELOCK_H_ */
194