155121Storek /*
263320Sbostic * Copyright (c) 1992, 1993
363320Sbostic * The Regents of the University of California. All rights reserved.
455121Storek *
555121Storek * This software was developed by the Computer Systems Engineering group
655121Storek * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
755121Storek * contributed to Berkeley.
855121Storek *
955501Sbostic * All advertising materials mentioning features or use of this software
1055501Sbostic * must display the following acknowledgement:
1155501Sbostic * This product includes software developed by the University of
1259208Storek * California, Lawrence Berkeley Laboratory.
1355501Sbostic *
1455121Storek * %sccs.include.redist.c%
1555121Storek *
16*69467Smckusick * @(#)param.h 8.3 (Berkeley) 05/14/95
1755121Storek *
1859662Storek * from: $Header: param.h,v 1.13 92/11/26 02:04:38 torek Exp $ (LBL)
1955121Storek */
2055121Storek
2155121Storek /*
2255121Storek * Machine dependent constants for Sun-4c (SPARCstation)
2355121Storek */
2455121Storek #define MACHINE "sparc"
25*69467Smckusick #define NCPUS 1
2655121Storek
2755121Storek #ifdef KERNEL /* XXX */
2856538Sbostic #include <machine/cpu.h> /* XXX */
2955121Storek #endif /* XXX */
3055121Storek
3155121Storek /*
3255121Storek * Round p (pointer or byte index) up to a correctly-aligned value for
3355121Storek * the machine's strictest data type. The result is u_int and must be
3455121Storek * cast to any desired pointer type.
3555121Storek */
3655121Storek #define ALIGNBYTES 7
3755121Storek #define ALIGN(p) (((u_int)(p) + ALIGNBYTES) & ~ALIGNBYTES)
3855121Storek
3955121Storek #define NBPG 4096 /* bytes/page */
4055121Storek #define PGOFSET (NBPG-1) /* byte offset into page */
4155121Storek #define PGSHIFT 12 /* log2(NBPG) */
4255121Storek
4355121Storek #define KERNBASE 0xf8000000 /* start of kernel virtual space */
4455121Storek #define KERNTEXTOFF 0xf8004000 /* start of kernel text */
4555121Storek #define BTOPKERNBASE ((u_long)KERNBASE >> PG_SHIFT)
4655121Storek
4755121Storek #define DEV_BSIZE 512
4855121Storek #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
4955121Storek #define BLKDEV_IOSIZE 2048
5055121Storek #define MAXPHYS (64 * 1024)
5155121Storek
5255121Storek #define CLSIZE 1
5355121Storek #define CLSIZELOG2 0
5455121Storek
5555121Storek /* NOTE: SSIZE and UPAGES must be multiples of CLSIZE */
5655121Storek #define SSIZE 1 /* initial stack size/NBPG */
5755121Storek #define UPAGES 2 /* pages of u-area */
5855121Storek
5955121Storek /*
6055121Storek * Constants related to network buffer management.
6155121Storek * MCLBYTES must be no larger than CLBYTES (the software page size), and,
6255121Storek * on machines that exchange pages of input or output buffers with mbuf
6355121Storek * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
6455121Storek * of the hardware page size.
6555121Storek */
6655121Storek #define MSIZE 128 /* size of an mbuf */
6755121Storek #define MCLBYTES 2048 /* enough for whole Ethernet packet */
6855121Storek #define MCLSHIFT 11 /* log2(MCLBYTES) */
6955121Storek #define MCLOFSET (MCLBYTES - 1)
7055121Storek
7155121Storek #ifndef NMBCLUSTERS
7255121Storek #ifdef GATEWAY
7355121Storek #define NMBCLUSTERS 512 /* map size, max cluster allocation */
7455121Storek #else
7555121Storek #define NMBCLUSTERS 256 /* map size, max cluster allocation */
7655121Storek #endif
7755121Storek #endif
7855121Storek
7955121Storek /*
8055121Storek * Size of kernel malloc arena in CLBYTES-sized logical pages.
8155121Storek */
8255121Storek #ifndef NKMEMCLUSTERS
8359208Storek #define NKMEMCLUSTERS (6 * 1024 * 1024 / CLBYTES)
8455121Storek #endif
8555121Storek
8655121Storek /* pages ("clicks") (4096 bytes) to disk blocks */
8755121Storek #define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT))
8855121Storek #define dtoc(x) ((x) >> (PGSHIFT - DEV_BSHIFT))
8955121Storek #define dtob(x) ((x) << DEV_BSHIFT)
9055121Storek
9155121Storek /* pages to bytes */
9255121Storek #define ctob(x) ((x) << PGSHIFT)
9355121Storek
9455121Storek /* bytes to pages */
9555121Storek #define btoc(x) (((unsigned)(x) + PGOFSET) >> PGSHIFT)
9655121Storek
9755121Storek #define btodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \
9868636Smckusick ((bytes) >> DEV_BSHIFT)
9955121Storek #define dbtob(db) /* calculates (db * DEV_BSIZE) */ \
10068636Smckusick ((db) << DEV_BSHIFT)
10155121Storek
10255121Storek /*
10355121Storek * Map a ``block device block'' to a file system block.
10455121Storek * This should be device dependent, and should use the bsize
10555121Storek * field from the disk label.
10655121Storek * For now though just use DEV_BSIZE.
10755121Storek */
10855121Storek #define bdbtofsb(bn) ((bn) / (BLKDEV_IOSIZE / DEV_BSIZE))
10955121Storek
11055121Storek #ifdef KERNEL
11155121Storek #ifndef LOCORE
11255121Storek #define DELAY(n) delay(n)
11355121Storek #endif
11455121Storek #else
11555121Storek #define DELAY(n) { register volatile int N = (n); while (--N > 0); }
11655121Storek #endif
117*69467Smckusick
118*69467Smckusick #ifndef _SIMPLELOCK_H_
119*69467Smckusick #define _SIMPLELOCK_H_
120*69467Smckusick /*
121*69467Smckusick * A simple spin lock.
122*69467Smckusick *
123*69467Smckusick * This structure only sets one bit of data, but is sized based on the
124*69467Smckusick * minimum word size that can be operated on by the hardware test-and-set
125*69467Smckusick * instruction. It is only needed for multiprocessors, as uniprocessors
126*69467Smckusick * will always run to completion or a sleep. It is an error to hold one
127*69467Smckusick * of these locks while a process is sleeping.
128*69467Smckusick */
129*69467Smckusick struct simplelock {
130*69467Smckusick int lock_data;
131*69467Smckusick };
132*69467Smckusick
133*69467Smckusick #if !defined(DEBUG) && NCPUS > 1
134*69467Smckusick /*
135*69467Smckusick * The simple-lock routines are the primitives out of which the lock
136*69467Smckusick * package is built. The machine-dependent code must implement an
137*69467Smckusick * atomic test_and_set operation that indivisibly sets the simple lock
138*69467Smckusick * to non-zero and returns its old value. It also assumes that the
139*69467Smckusick * setting of the lock to zero below is indivisible. Simple locks may
140*69467Smckusick * only be used for exclusive locks.
141*69467Smckusick */
142*69467Smckusick static __inline void
simple_lock_init(lkp)143*69467Smckusick simple_lock_init(lkp)
144*69467Smckusick struct simplelock *lkp;
145*69467Smckusick {
146*69467Smckusick
147*69467Smckusick lkp->lock_data = 0;
148*69467Smckusick }
149*69467Smckusick
150*69467Smckusick static __inline void
simple_lock(lkp)151*69467Smckusick simple_lock(lkp)
152*69467Smckusick __volatile struct simplelock *lkp;
153*69467Smckusick {
154*69467Smckusick
155*69467Smckusick while (test_and_set(&lkp->lock_data))
156*69467Smckusick continue;
157*69467Smckusick }
158*69467Smckusick
159*69467Smckusick static __inline int
simple_lock_try(lkp)160*69467Smckusick simple_lock_try(lkp)
161*69467Smckusick __volatile struct simplelock *lkp;
162*69467Smckusick {
163*69467Smckusick
164*69467Smckusick return (!test_and_set(&lkp->lock_data))
165*69467Smckusick }
166*69467Smckusick
167*69467Smckusick static __inline void
168*69467Smckusick simple_unlock(lkp)
169*69467Smckusick __volatile struct simplelock *lkp;
170*69467Smckusick {
171*69467Smckusick
172*69467Smckusick lkp->lock_data = 0;
173*69467Smckusick }
174*69467Smckusick #endif /* NCPUS > 1 */
175*69467Smckusick #endif /* !_SIMPLELOCK_H_ */
176