1 /* 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This software was developed by the Computer Systems Engineering group 6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7 * contributed to Berkeley. 8 * 9 * All advertising materials mentioning features or use of this software 10 * must display the following acknowledgement: 11 * This product includes software developed by the University of 12 * California, Lawrence Berkeley Laboratory. 13 * 14 * %sccs.include.redist.c% 15 * 16 * @(#)param.h 8.3 (Berkeley) 05/14/95 17 * 18 * from: $Header: param.h,v 1.13 92/11/26 02:04:38 torek Exp $ (LBL) 19 */ 20 21 /* 22 * Machine dependent constants for Sun-4c (SPARCstation) 23 */ 24 #define MACHINE "sparc" 25 #define NCPUS 1 26 27 #ifdef KERNEL /* XXX */ 28 #include <machine/cpu.h> /* XXX */ 29 #endif /* XXX */ 30 31 /* 32 * Round p (pointer or byte index) up to a correctly-aligned value for 33 * the machine's strictest data type. The result is u_int and must be 34 * cast to any desired pointer type. 35 */ 36 #define ALIGNBYTES 7 37 #define ALIGN(p) (((u_int)(p) + ALIGNBYTES) & ~ALIGNBYTES) 38 39 #define NBPG 4096 /* bytes/page */ 40 #define PGOFSET (NBPG-1) /* byte offset into page */ 41 #define PGSHIFT 12 /* log2(NBPG) */ 42 43 #define KERNBASE 0xf8000000 /* start of kernel virtual space */ 44 #define KERNTEXTOFF 0xf8004000 /* start of kernel text */ 45 #define BTOPKERNBASE ((u_long)KERNBASE >> PG_SHIFT) 46 47 #define DEV_BSIZE 512 48 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ 49 #define BLKDEV_IOSIZE 2048 50 #define MAXPHYS (64 * 1024) 51 52 #define CLSIZE 1 53 #define CLSIZELOG2 0 54 55 /* NOTE: SSIZE and UPAGES must be multiples of CLSIZE */ 56 #define SSIZE 1 /* initial stack size/NBPG */ 57 #define UPAGES 2 /* pages of u-area */ 58 59 /* 60 * Constants related to network buffer management. 61 * MCLBYTES must be no larger than CLBYTES (the software page size), and, 62 * on machines that exchange pages of input or output buffers with mbuf 63 * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple 64 * of the hardware page size. 65 */ 66 #define MSIZE 128 /* size of an mbuf */ 67 #define MCLBYTES 2048 /* enough for whole Ethernet packet */ 68 #define MCLSHIFT 11 /* log2(MCLBYTES) */ 69 #define MCLOFSET (MCLBYTES - 1) 70 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 (6 * 1024 * 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) + PGOFSET) >> 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 #ifdef KERNEL 111 #ifndef LOCORE 112 #define DELAY(n) delay(n) 113 #endif 114 #else 115 #define DELAY(n) { register volatile int N = (n); while (--N > 0); } 116 #endif 117 118 #ifndef _SIMPLELOCK_H_ 119 #define _SIMPLELOCK_H_ 120 /* 121 * A simple spin lock. 122 * 123 * This structure only sets one bit of data, but is sized based on the 124 * minimum word size that can be operated on by the hardware test-and-set 125 * instruction. It is only needed for multiprocessors, as uniprocessors 126 * will always run to completion or a sleep. It is an error to hold one 127 * of these locks while a process is sleeping. 128 */ 129 struct simplelock { 130 int lock_data; 131 }; 132 133 #if !defined(DEBUG) && NCPUS > 1 134 /* 135 * The simple-lock routines are the primitives out of which the lock 136 * package is built. The machine-dependent code must implement an 137 * atomic test_and_set operation that indivisibly sets the simple lock 138 * to non-zero and returns its old value. It also assumes that the 139 * setting of the lock to zero below is indivisible. Simple locks may 140 * only be used for exclusive locks. 141 */ 142 static __inline void 143 simple_lock_init(lkp) 144 struct simplelock *lkp; 145 { 146 147 lkp->lock_data = 0; 148 } 149 150 static __inline void 151 simple_lock(lkp) 152 __volatile struct simplelock *lkp; 153 { 154 155 while (test_and_set(&lkp->lock_data)) 156 continue; 157 } 158 159 static __inline int 160 simple_lock_try(lkp) 161 __volatile struct simplelock *lkp; 162 { 163 164 return (!test_and_set(&lkp->lock_data)) 165 } 166 167 static __inline void 168 simple_unlock(lkp) 169 __volatile struct simplelock *lkp; 170 { 171 172 lkp->lock_data = 0; 173 } 174 #endif /* NCPUS > 1 */ 175 #endif /* !_SIMPLELOCK_H_ */ 176