1 /* 2 * Copyright (c) 1988 University of Utah. 3 * Copyright (c) 1992 OMRON Corporation. 4 * Copyright (c) 1982, 1986, 1990, 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * the Systems Programming Group of the University of Utah Computer 9 * Science Department. 10 * 11 * %sccs.include.redist.c% 12 * 13 * from: Utah $Hdr: machparam.h 1.11 89/08/14$ 14 * from: hp300/include/param.h 7.13 (Berkeley) 12/27/92 15 * 16 * @(#)param.h 8.3 (Berkeley) 05/14/95 17 */ 18 19 /* 20 * Machine dependent constants for LUNA taken from: 21 * Param.h for HP9000 series 300. 22 */ 23 #define MACHINE "luna68k" 24 #define NCPUS 1 25 26 /* 27 * Round p (pointer or byte index) up to a correctly-aligned value 28 * for all data types (int, long, ...). The result is u_int and 29 * must be cast to any desired pointer type. 30 */ 31 #define ALIGNBYTES 3 32 #define ALIGN(p) (((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES) 33 34 #define NBPG 4096 /* bytes/page */ 35 #define PGOFSET (NBPG-1) /* byte offset into page */ 36 #define PGSHIFT 12 /* LOG2(NBPG) */ 37 #define NPTEPG (NBPG/(sizeof (struct pte))) 38 39 #define NBSEG 0x400000 /* bytes/segment */ 40 #define SEGOFSET (NBSEG-1) /* byte offset into segment */ 41 #define SEGSHIFT 22 /* LOG2(NBSEG) */ 42 43 #define KERNBASE 0x00000000 /* start of kernel virtual */ 44 #define BTOPKERNBASE ((u_long)KERNBASE >> PGSHIFT) 45 46 #define DEV_BSIZE 512 47 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ 48 #define BLKDEV_IOSIZE 2048 49 #define MAXPHYS (64 * 1024) /* max raw I/O transfer size */ 50 51 #define CLSIZE 1 52 #define CLSIZELOG2 0 53 54 /* NOTE: SSIZE, SINCR and UPAGES must be multiples of CLSIZE */ 55 #define SSIZE 1 /* initial stack size/NBPG */ 56 #define SINCR 1 /* increment of stack/NBPG */ 57 58 #define UPAGES 2 /* pages of u-area */ 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 2048 /* large enough for ether MTU */ 69 #define MCLSHIFT 11 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 (2048*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 luna_round_page(x) ((((unsigned)(x)) + NBPG - 1) & ~(NBPG-1)) 114 #define luna_trunc_page(x) ((unsigned)(x) & ~(NBPG-1)) 115 #define luna_btop(x) ((unsigned)(x) >> PGSHIFT) 116 #define luna_ptob(x) ((unsigned)(x) << PGSHIFT) 117 118 /* 119 * spl functions; all but spl0 are done in-line 120 */ 121 #include <machine/psl.h> 122 123 #define _spl(s) \ 124 ({ \ 125 register int _spl_r; \ 126 \ 127 asm __volatile ("clrl %0; movew sr,%0; movew %1,sr" : \ 128 "&=d" (_spl_r) : "di" (s)); \ 129 _spl_r; \ 130 }) 131 132 /* spl0 requires checking for software interrupts */ 133 #define spl1() _spl(PSL_S|PSL_IPL1) 134 #define spl2() _spl(PSL_S|PSL_IPL2) 135 #define spl3() _spl(PSL_S|PSL_IPL3) 136 #define spl4() _spl(PSL_S|PSL_IPL4) 137 #define spl5() _spl(PSL_S|PSL_IPL5) 138 #define spl6() _spl(PSL_S|PSL_IPL6) 139 #define spl7() _spl(PSL_S|PSL_IPL7) 140 141 #define splsoftclock() spl1() 142 #define splnet() spl1() 143 #define splbio() spl5() 144 #define splimp() spl5() 145 #define spltty() spl6() 146 #define splclock() spl5() 147 #define splstatclock() spl5() 148 #define splvm() spl6() 149 #define splhigh() spl7() 150 #define splsched() spl7() 151 152 /* watch out for side effects */ 153 #define splx(s) (s & PSL_IPL ? _spl(s) : spl0()) 154 155 #ifdef KERNEL 156 #ifndef LOCORE 157 int cpuspeed; 158 #define DELAY(n) { register int N = cpuspeed * (n); while (--N > 0); } 159 #endif 160 161 #else 162 #define DELAY(n) { register int N = (n); while (--N > 0); } 163 #endif 164 165 #ifndef _SIMPLELOCK_H_ 166 #define _SIMPLELOCK_H_ 167 /* 168 * A simple spin lock. 169 * 170 * This structure only sets one bit of data, but is sized based on the 171 * minimum word size that can be operated on by the hardware test-and-set 172 * instruction. It is only needed for multiprocessors, as uniprocessors 173 * will always run to completion or a sleep. It is an error to hold one 174 * of these locks while a process is sleeping. 175 */ 176 struct simplelock { 177 int lock_data; 178 }; 179 180 #if !defined(DEBUG) && NCPUS > 1 181 /* 182 * The simple-lock routines are the primitives out of which the lock 183 * package is built. The machine-dependent code must implement an 184 * atomic test_and_set operation that indivisibly sets the simple lock 185 * to non-zero and returns its old value. It also assumes that the 186 * setting of the lock to zero below is indivisible. Simple locks may 187 * only be used for exclusive locks. 188 */ 189 static __inline void 190 simple_lock_init(lkp) 191 struct simplelock *lkp; 192 { 193 194 lkp->lock_data = 0; 195 } 196 197 static __inline void 198 simple_lock(lkp) 199 __volatile struct simplelock *lkp; 200 { 201 202 while (test_and_set(&lkp->lock_data)) 203 continue; 204 } 205 206 static __inline int 207 simple_lock_try(lkp) 208 __volatile struct simplelock *lkp; 209 { 210 211 return (!test_and_set(&lkp->lock_data)) 212 } 213 214 static __inline void 215 simple_unlock(lkp) 216 __volatile struct simplelock *lkp; 217 { 218 219 lkp->lock_data = 0; 220 } 221 #endif /* NCPUS > 1 */ 222 #endif /* !_SIMPLELOCK_H_ */ 223