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*69797Sralph * @(#)param.h 8.5 (Berkeley) 06/02/95
1552131Smckusick */
1652131Smckusick
1752131Smckusick /*
1852131Smckusick * Machine dependent constants for DEC Station 3100.
1952131Smckusick */
2052131Smckusick #define MACHINE "mips"
2169466Smckusick #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
118*69797Sralph #ifndef LOCORE
11952131Smckusick #ifdef KERNEL
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 #else /* !KERNEL */
13152131Smckusick #define DELAY(n) { register int N = (n); while (--N > 0); }
13252131Smckusick #endif /* !KERNEL */
13369466Smckusick
13469466Smckusick #ifndef _SIMPLELOCK_H_
13569466Smckusick #define _SIMPLELOCK_H_
13669466Smckusick /*
13769466Smckusick * A simple spin lock.
13869466Smckusick *
13969466Smckusick * This structure only sets one bit of data, but is sized based on the
14069466Smckusick * minimum word size that can be operated on by the hardware test-and-set
14169466Smckusick * instruction. It is only needed for multiprocessors, as uniprocessors
14269466Smckusick * will always run to completion or a sleep. It is an error to hold one
14369466Smckusick * of these locks while a process is sleeping.
14469466Smckusick */
14569466Smckusick struct simplelock {
14669466Smckusick int lock_data;
14769466Smckusick };
14869466Smckusick
14969466Smckusick #if !defined(DEBUG) && NCPUS > 1
15069466Smckusick /*
15169466Smckusick * The simple-lock routines are the primitives out of which the lock
15269466Smckusick * package is built. The machine-dependent code must implement an
15369466Smckusick * atomic test_and_set operation that indivisibly sets the simple lock
15469466Smckusick * to non-zero and returns its old value. It also assumes that the
15569466Smckusick * setting of the lock to zero below is indivisible. Simple locks may
15669466Smckusick * only be used for exclusive locks.
15769466Smckusick */
15869466Smckusick static __inline void
simple_lock_init(lkp)15969466Smckusick simple_lock_init(lkp)
16069466Smckusick struct simplelock *lkp;
16169466Smckusick {
16269466Smckusick
16369466Smckusick lkp->lock_data = 0;
16469466Smckusick }
16569466Smckusick
16669466Smckusick static __inline void
simple_lock(lkp)16769466Smckusick simple_lock(lkp)
16869466Smckusick __volatile struct simplelock *lkp;
16969466Smckusick {
17069466Smckusick
17169466Smckusick while (test_and_set(&lkp->lock_data))
17269466Smckusick continue;
17369466Smckusick }
17469466Smckusick
17569466Smckusick static __inline int
simple_lock_try(lkp)17669466Smckusick simple_lock_try(lkp)
17769466Smckusick __volatile struct simplelock *lkp;
17869466Smckusick {
17969466Smckusick
18069466Smckusick return (!test_and_set(&lkp->lock_data))
18169466Smckusick }
18269466Smckusick
18369466Smckusick static __inline void
18469466Smckusick simple_unlock(lkp)
18569466Smckusick __volatile struct simplelock *lkp;
18669466Smckusick {
18769466Smckusick
18869466Smckusick lkp->lock_data = 0;
18969466Smckusick }
19069466Smckusick #endif /* NCPUS > 1 */
19169466Smckusick #endif /* !_SIMPLELOCK_H_ */
192*69797Sralph #endif /* LOCORE */
193