xref: /original-bsd/sys/pmax/include/param.h (revision 00a25f5a)
1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1992, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Systems Programming Group of the University of Utah Computer
8  * Science Department and Ralph Campbell.
9  *
10  * %sccs.include.redist.c%
11  *
12  * from: Utah $Hdr: machparam.h 1.11 89/08/14$
13  *
14  *	@(#)param.h	8.5 (Berkeley) 06/02/95
15  */
16 
17 /*
18  * Machine dependent constants for DEC Station 3100.
19  */
20 #define	MACHINE	"mips"
21 #define NCPUS 1
22 
23 /*
24  * Round p (pointer or byte index) up to a correctly-aligned value for all
25  * data types (int, long, ...).   The result is u_int and must be cast to
26  * any desired pointer type.
27  */
28 #define	ALIGNBYTES	7
29 #define	ALIGN(p)	(((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES)
30 
31 #define	NBPG		4096		/* bytes/page */
32 #define	PGOFSET		(NBPG-1)	/* byte offset into page */
33 #define	PGSHIFT		12		/* LOG2(NBPG) */
34 #define	NPTEPG		(NBPG/4)
35 
36 #define NBSEG		0x400000	/* bytes/segment */
37 #define	SEGOFSET	(NBSEG-1)	/* byte offset into segment */
38 #define	SEGSHIFT	22		/* LOG2(NBSEG) */
39 
40 #define	KERNBASE	0x80000000	/* start of kernel virtual */
41 #define	BTOPKERNBASE	((u_long)KERNBASE >> PGSHIFT)
42 
43 #define	DEV_BSIZE	512
44 #define	DEV_BSHIFT	9		/* log2(DEV_BSIZE) */
45 #define BLKDEV_IOSIZE	2048
46 #define	MAXPHYS		(64 * 1024)	/* max raw I/O transfer size */
47 
48 #define	CLSIZE		1
49 #define	CLSIZELOG2	0
50 
51 /* NOTE: SSIZE, SINCR and UPAGES must be multiples of CLSIZE */
52 #define	SSIZE		1		/* initial stack size/NBPG */
53 #define	SINCR		1		/* increment of stack/NBPG */
54 
55 #define	UPAGES		2		/* pages of u-area */
56 #define	UADDR		0xffffd000	/* address of u */
57 #define	UVPN		(UADDR>>PGSHIFT)/* virtual page number of u */
58 #define	KERNELSTACK	(UADDR+UPAGES*NBPG)	/* top of kernel stack */
59 
60 /*
61  * Constants related to network buffer management.
62  * MCLBYTES must be no larger than CLBYTES (the software page size), and,
63  * on machines that exchange pages of input or output buffers with mbuf
64  * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
65  * of the hardware page size.
66  */
67 #define	MSIZE		128		/* size of an mbuf */
68 #define	MCLBYTES	1024
69 #define	MCLSHIFT	10
70 #define	MCLOFSET	(MCLBYTES - 1)
71 #ifndef NMBCLUSTERS
72 #ifdef GATEWAY
73 #define	NMBCLUSTERS	512		/* map size, max cluster allocation */
74 #else
75 #define	NMBCLUSTERS	256		/* map size, max cluster allocation */
76 #endif
77 #endif
78 
79 /*
80  * Size of kernel malloc arena in CLBYTES-sized logical pages
81  */
82 #ifndef NKMEMCLUSTERS
83 #define	NKMEMCLUSTERS	(512*1024/CLBYTES)
84 #endif
85 
86 /* pages ("clicks") (4096 bytes) to disk blocks */
87 #define	ctod(x)	((x)<<(PGSHIFT-DEV_BSHIFT))
88 #define	dtoc(x)	((x)>>(PGSHIFT-DEV_BSHIFT))
89 #define	dtob(x)	((x)<<DEV_BSHIFT)
90 
91 /* pages to bytes */
92 #define	ctob(x)	((x)<<PGSHIFT)
93 
94 /* bytes to pages */
95 #define	btoc(x)	(((unsigned)(x)+(NBPG-1))>>PGSHIFT)
96 
97 #define	btodb(bytes)	 		/* calculates (bytes / DEV_BSIZE) */ \
98 	((bytes) >> DEV_BSHIFT)
99 #define	dbtob(db)			/* calculates (db * DEV_BSIZE) */ \
100 	((db) << DEV_BSHIFT)
101 
102 /*
103  * Map a ``block device block'' to a file system block.
104  * This should be device dependent, and should use the bsize
105  * field from the disk label.
106  * For now though just use DEV_BSIZE.
107  */
108 #define	bdbtofsb(bn)	((bn) / (BLKDEV_IOSIZE/DEV_BSIZE))
109 
110 /*
111  * Mach derived conversion macros
112  */
113 #define pmax_round_page(x)	((((unsigned)(x)) + NBPG - 1) & ~(NBPG-1))
114 #define pmax_trunc_page(x)	((unsigned)(x) & ~(NBPG-1))
115 #define pmax_btop(x)		((unsigned)(x) >> PGSHIFT)
116 #define pmax_ptob(x)		((unsigned)(x) << PGSHIFT)
117 
118 #ifndef LOCORE
119 #ifdef KERNEL
120 extern int (*Mach_splnet)(), (*Mach_splbio)(), (*Mach_splimp)(),
121 	   (*Mach_spltty)(), (*Mach_splclock)(), (*Mach_splstatclock)();
122 #define	splnet()	((*Mach_splnet)())
123 #define	splbio()	((*Mach_splbio)())
124 #define	splimp()	((*Mach_splimp)())
125 #define	spltty()	((*Mach_spltty)())
126 #define	splclock()	((*Mach_splclock)())
127 #define	splstatclock()	((*Mach_splstatclock)())
128 extern	int cpuspeed;
129 #define	DELAY(n)	{ register int N = cpuspeed * (n); while (--N > 0); }
130 #else /* !KERNEL */
131 #define	DELAY(n)	{ register int N = (n); while (--N > 0); }
132 #endif /* !KERNEL */
133 
134 #ifndef _SIMPLELOCK_H_
135 #define _SIMPLELOCK_H_
136 /*
137  * A simple spin lock.
138  *
139  * This structure only sets one bit of data, but is sized based on the
140  * minimum word size that can be operated on by the hardware test-and-set
141  * instruction. It is only needed for multiprocessors, as uniprocessors
142  * will always run to completion or a sleep. It is an error to hold one
143  * of these locks while a process is sleeping.
144  */
145 struct simplelock {
146 	int	lock_data;
147 };
148 
149 #if !defined(DEBUG) && NCPUS > 1
150 /*
151  * The simple-lock routines are the primitives out of which the lock
152  * package is built. The machine-dependent code must implement an
153  * atomic test_and_set operation that indivisibly sets the simple lock
154  * to non-zero and returns its old value. It also assumes that the
155  * setting of the lock to zero below is indivisible. Simple locks may
156  * only be used for exclusive locks.
157  */
158 static __inline void
159 simple_lock_init(lkp)
160 	struct simplelock *lkp;
161 {
162 
163 	lkp->lock_data = 0;
164 }
165 
166 static __inline void
167 simple_lock(lkp)
168 	__volatile struct simplelock *lkp;
169 {
170 
171 	while (test_and_set(&lkp->lock_data))
172 		continue;
173 }
174 
175 static __inline int
176 simple_lock_try(lkp)
177 	__volatile struct simplelock *lkp;
178 {
179 
180 	return (!test_and_set(&lkp->lock_data))
181 }
182 
183 static __inline void
184 simple_unlock(lkp)
185 	__volatile struct simplelock *lkp;
186 {
187 
188 	lkp->lock_data = 0;
189 }
190 #endif /* NCPUS > 1 */
191 #endif /* !_SIMPLELOCK_H_ */
192 #endif /* LOCORE */
193