xref: /original-bsd/sys/pmax/include/param.h (revision 0ac4996f)
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.3 (Berkeley) 05/14/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 #ifdef KERNEL
119 #ifndef LOCORE
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 #endif
131 
132 #else /* !KERNEL */
133 #define	DELAY(n)	{ register int N = (n); while (--N > 0); }
134 #endif /* !KERNEL */
135 
136 #ifndef _SIMPLELOCK_H_
137 #define _SIMPLELOCK_H_
138 /*
139  * A simple spin lock.
140  *
141  * This structure only sets one bit of data, but is sized based on the
142  * minimum word size that can be operated on by the hardware test-and-set
143  * instruction. It is only needed for multiprocessors, as uniprocessors
144  * will always run to completion or a sleep. It is an error to hold one
145  * of these locks while a process is sleeping.
146  */
147 struct simplelock {
148 	int	lock_data;
149 };
150 
151 #if !defined(DEBUG) && NCPUS > 1
152 /*
153  * The simple-lock routines are the primitives out of which the lock
154  * package is built. The machine-dependent code must implement an
155  * atomic test_and_set operation that indivisibly sets the simple lock
156  * to non-zero and returns its old value. It also assumes that the
157  * setting of the lock to zero below is indivisible. Simple locks may
158  * only be used for exclusive locks.
159  */
160 static __inline void
161 simple_lock_init(lkp)
162 	struct simplelock *lkp;
163 {
164 
165 	lkp->lock_data = 0;
166 }
167 
168 static __inline void
169 simple_lock(lkp)
170 	__volatile struct simplelock *lkp;
171 {
172 
173 	while (test_and_set(&lkp->lock_data))
174 		continue;
175 }
176 
177 static __inline int
178 simple_lock_try(lkp)
179 	__volatile struct simplelock *lkp;
180 {
181 
182 	return (!test_and_set(&lkp->lock_data))
183 }
184 
185 static __inline void
186 simple_unlock(lkp)
187 	__volatile struct simplelock *lkp;
188 {
189 
190 	lkp->lock_data = 0;
191 }
192 #endif /* NCPUS > 1 */
193 #endif /* !_SIMPLELOCK_H_ */
194