param.h revision 28885
1/*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * William Jolitz. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * from: @(#)param.h 5.8 (Berkeley) 6/28/91 37 * $Id: param.h,v 1.37 1997/08/24 00:04:59 fsmp Exp $ 38 */ 39 40#ifndef _MACHINE_PARAM_H_ 41#define _MACHINE_PARAM_H_ 42 43/* 44 * Machine dependent constants for Intel 386. 45 */ 46 47#define MACHINE "i386" 48#ifdef SMP 49#define NCPUS 2 50#else 51#define NCPUS 1 52#endif 53#define MID_MACHINE MID_I386 54 55/* 56 * Architecture dependent constants for i386 based machines. 57 */ 58#ifdef PC98 59/* NEC PC-9801/9821 series and compatibles. */ 60#define MACHINE_ARCH "pc-98" 61#else 62/* IBM-PC compatibles. */ 63#define MACHINE_ARCH "ibm-pc" 64#endif 65 66#ifndef LOCORE 67 68/* 69 * Round p (pointer or byte index) up to a correctly-aligned value 70 * for all data types (int, long, ...). The result is unsigned int 71 * and must be cast to any desired pointer type. 72 */ 73#define ALIGNBYTES (sizeof(int) - 1) 74#define ALIGN(p) (((unsigned)(p) + ALIGNBYTES) & ~ALIGNBYTES) 75 76#define PAGE_SHIFT 12 /* LOG2(PAGE_SIZE) */ 77#define PAGE_SIZE (1<<PAGE_SHIFT) /* bytes/page */ 78#define PAGE_MASK (PAGE_SIZE-1) 79#define NPTEPG (PAGE_SIZE/(sizeof (pt_entry_t))) 80 81#define NPDEPG (PAGE_SIZE/(sizeof (pd_entry_t))) 82#define PDRSHIFT 22 /* LOG2(NBPDR) */ 83#define NBPDR (1<<PDRSHIFT) /* bytes/page dir */ 84#define PDRMASK (NBPDR-1) 85 86#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ 87#define DEV_BSIZE (1<<DEV_BSHIFT) 88 89#define BLKDEV_IOSIZE 2048 90#define MAXPHYS (64 * 1024) /* max raw I/O transfer size */ 91 92#define IOPAGES 2 /* pages of i/o permission bitmap */ 93#define UPAGES 2 /* pages of u-area */ 94#define UPAGES_HOLE 2 /* pages of "hole" at top of user space where */ 95 /* the upages used to be. DO NOT CHANGE! */ 96 97/* 98 * Constants related to network buffer management. 99 * MCLBYTES must be no larger than CLBYTES (the software page size), and, 100 * on machines that exchange pages of input or output buffers with mbuf 101 * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple 102 * of the hardware page size. 103 */ 104#ifndef MSIZE 105#define MSIZE 128 /* size of an mbuf */ 106#endif /* MSIZE */ 107 108#ifndef MCLSHIFT 109#define MCLSHIFT 11 /* convert bytes to m_buf clusters */ 110#endif /* MCLSHIFT */ 111#define MCLBYTES (1 << MCLSHIFT) /* size of an m_buf cluster */ 112#define MCLOFSET (MCLBYTES - 1) /* offset within an m_buf cluster */ 113 114/* 115 * Some macros for units conversion 116 */ 117 118/* clicks to bytes */ 119#define ctob(x) ((x)<<PAGE_SHIFT) 120 121/* bytes to clicks */ 122#define btoc(x) (((unsigned)(x)+PAGE_MASK)>>PAGE_SHIFT) 123 124/* 125 * btodb() is messy and perhaps slow because `bytes' may be an off_t. We 126 * want to shift an unsigned type to avoid sign extension and we don't 127 * want to widen `bytes' unnecessarily. Assume that the result fits in 128 * a daddr_t. 129 */ 130#define btodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \ 131 (sizeof (bytes) > sizeof(long) \ 132 ? (daddr_t)((unsigned long long)(bytes) >> DEV_BSHIFT) \ 133 : (daddr_t)((unsigned long)(bytes) >> DEV_BSHIFT)) 134 135#define dbtob(db) /* calculates (db * DEV_BSIZE) */ \ 136 ((off_t)(db) << DEV_BSHIFT) 137 138/* 139 * Mach derived conversion macros 140 */ 141#define trunc_page(x) ((unsigned)(x) & ~PAGE_MASK) 142#define round_page(x) ((((unsigned)(x)) + PAGE_MASK) & ~PAGE_MASK) 143#define trunc_4mpage(x) ((unsigned)(x) & ~PDRMASK) 144#define round_4mpage(x) ((((unsigned)(x)) + PDRMASK) & ~PDRMASK) 145 146#define atop(x) ((unsigned)(x) >> PAGE_SHIFT) 147#define ptoa(x) ((unsigned)(x) << PAGE_SHIFT) 148 149#define i386_btop(x) ((unsigned)(x) >> PAGE_SHIFT) 150#define i386_ptob(x) ((unsigned)(x) << PAGE_SHIFT) 151 152#endif /* !LOCORE */ 153 154 155#ifndef _SIMPLELOCK_H_ 156#define _SIMPLELOCK_H_ 157 158/* 159 * XXX some temp debug control of cpl locks 160 */ 161#define REAL_ECPL /* exception.s: SCPL_LOCK/SCPL_UNLOCK */ 162#define REAL_ICPL /* ipl.s: CPL_LOCK/CPL_UNLOCK/FAST */ 163#define REAL_AICPL /* apic_ipl.s: SCPL_LOCK/SCPL_UNLOCK */ 164#define REAL_AVCPL /* apic_vector.s: CPL_LOCK/CPL_UNLOCK */ 165 166#define REAL_IFCPL /* ipl_funcs.c: SCPL_LOCK/SCPL_UNLOCK */ 167 168#define REAL_MCPL_NOT /* microtime.s: CPL_LOCK/movl $0,_cpl_lock */ 169 170 171#ifdef LOCORE 172 173#ifdef SMP 174 175#define MPLOCKED lock ; 176 177/* 178 * Some handy macros to allow logical organization and 179 * convenient reassignment of various locks. 180 */ 181 182#define FPU_LOCK call _get_fpu_lock 183#define ALIGN_LOCK call _get_align_lock 184#define SYSCALL_LOCK call _get_syscall_lock 185#define ALTSYSCALL_LOCK call _get_altsyscall_lock 186 187/* 188 * Protects INTR() ISRs. 189 */ 190#define ISR_TRYLOCK \ 191 pushl $_mp_lock ; /* GIANT_LOCK */ \ 192 call _MPtrylock ; /* try to get lock */ \ 193 add $4, %esp 194 195#define ISR_RELLOCK \ 196 pushl $_mp_lock ; /* GIANT_LOCK */ \ 197 call _MPrellock ; \ 198 add $4, %esp 199 200/* 201 * Protects the IO APIC and apic_imen as a critical region. 202 */ 203#define IMASK_LOCK \ 204 pushl $_imen_lock ; /* address of lock */ \ 205 call _s_lock ; /* MP-safe */ \ 206 addl $4, %esp 207 208#define IMASK_UNLOCK \ 209 pushl $_imen_lock ; /* address of lock */ \ 210 call _s_unlock ; /* MP-safe */ \ 211 addl $4, %esp 212 213/* 214 * Variations of CPL_LOCK protect spl updates as a critical region. 215 * Items within this 'region' include: 216 * cpl 217 * cil 218 * ipending 219 * ??? 220 */ 221 222/* 223 * Botom half routines, ie. those already protected from INTs. 224 * 225 * Used in: 226 * sys/i386/i386/microtime.s (XXX currently NOT used, possible race?) 227 * sys/i386/isa/ipl.s: _doreti 228 * sys/i386/isa/apic_vector.s: _Xintr0, ..., _Xintr23 229 */ 230#define CPL_LOCK \ 231 pushl $_cpl_lock ; /* address of lock */ \ 232 call _s_lock ; /* MP-safe */ \ 233 addl $4, %esp 234 235#define CPL_UNLOCK \ 236 pushl $_cpl_lock ; /* address of lock */ \ 237 call _s_unlock ; /* MP-safe */ \ 238 addl $4, %esp 239 240/* 241 * INT safe version for top half of kernel. 242 * 243 * Used in: 244 * sys/i386/i386/exception.s: _Xfpu, _Xalign, _Xsyscall, _Xint0x80_syscall 245 * sys/i386/isa/apic_ipl.s: splz() 246 */ 247#define SCPL_LOCK \ 248 pushl $_cpl_lock ; \ 249 call _ss_lock ; \ 250 addl $4, %esp 251 252#define SCPL_UNLOCK \ 253 pushl $_cpl_lock ; \ 254 call _ss_unlock ; \ 255 addl $4, %esp 256 257#else /* SMP */ 258 259#define MPLOCKED /* NOP */ 260 261#define FPU_LOCK /* NOP */ 262#define ALIGN_LOCK /* NOP */ 263#define SYSCALL_LOCK /* NOP */ 264#define ALTSYSCALL_LOCK /* NOP */ 265 266#endif /* SMP */ 267 268#else /* LOCORE */ 269 270#ifdef SMP 271 272/* 273 * Protects cpl/cil/ipending data as a critical region. 274 * 275 * Used in: 276 * sys/i386/isa/ipl_funcs.c: DO_SETBITS, softclockpending(), GENSPL, 277 * spl0(), splx(), splq() 278 */ 279 280/* Bottom half */ 281#define CPL_LOCK() s_lock(&cpl_lock) 282#define CPL_UNLOCK() s_unlock(&cpl_lock) 283 284/* INT safe version for top half of kernel */ 285#define SCPL_LOCK() ss_lock(&cpl_lock) 286#define SCPL_UNLOCK() ss_unlock(&cpl_lock) 287 288/* 289 * Protects com/tty data as a critical region. 290 */ 291#define COM_LOCK() s_lock(&com_lock) 292#define COM_UNLOCK() s_unlock(&com_lock) 293 294#else /* SMP */ 295 296#define CPL_LOCK() 297#define CPL_UNLOCK() 298#define SCPL_LOCK() 299#define SCPL_UNLOCK() 300 301#define COM_LOCK() 302#define COM_UNLOCK() 303 304#endif /* SMP */ 305 306/* 307 * A simple spin lock. 308 * 309 * This structure only sets one bit of data, but is sized based on the 310 * minimum word size that can be operated on by the hardware test-and-set 311 * instruction. It is only needed for multiprocessors, as uniprocessors 312 * will always run to completion or a sleep. It is an error to hold one 313 * of these locks while a process is sleeping. 314 */ 315struct simplelock { 316 volatile int lock_data; 317}; 318 319/* functions in simplelock.s */ 320void s_lock_init __P((struct simplelock *)); 321void s_lock __P((struct simplelock *)); 322int s_lock_try __P((struct simplelock *)); 323void s_unlock __P((struct simplelock *)); 324void ss_lock __P((struct simplelock *)); 325void ss_unlock __P((struct simplelock *)); 326 327/* global data in mp_machdep.c */ 328extern struct simplelock imen_lock; 329extern struct simplelock cpl_lock; 330extern struct simplelock fast_intr_lock; 331extern struct simplelock intr_lock; 332extern struct simplelock com_lock; 333 334#if !defined(SIMPLELOCK_DEBUG) && NCPUS > 1 335/* 336 * The simple-lock routines are the primitives out of which the lock 337 * package is built. The machine-dependent code must implement an 338 * atomic test_and_set operation that indivisibly sets the simple lock 339 * to non-zero and returns its old value. It also assumes that the 340 * setting of the lock to zero below is indivisible. Simple locks may 341 * only be used for exclusive locks. 342 */ 343 344#ifdef the_original_code 345 346static __inline void 347simple_lock_init(struct simplelock *lkp) 348{ 349 350 lkp->lock_data = 0; 351} 352 353static __inline void 354simple_lock(struct simplelock *lkp) 355{ 356 357 while (test_and_set(&lkp->lock_data)) 358 continue; 359} 360 361static __inline int 362simple_lock_try(struct simplelock *lkp) 363{ 364 365 return (!test_and_set(&lkp->lock_data)); 366} 367 368static __inline void 369simple_unlock(struct simplelock *lkp) 370{ 371 372 lkp->lock_data = 0; 373} 374 375#else /* the_original_code */ 376 377/* 378 * This set of defines turns on the real functions in i386/isa/apic_ipl.s. 379 * It has never actually been tested. 380 */ 381#define simple_lock_init(alp) s_lock_init(alp) 382#define simple_lock(alp) s_lock(alp) 383#define simple_lock_try(alp) s_lock_try(alp) 384#define simple_unlock(alp) s_unlock(alp) 385 386#endif /* the_original_code */ 387 388#endif /* NCPUS > 1 */ 389#endif /* LOCORE */ 390#endif /* !_SIMPLELOCK_H_ */ 391 392#endif /* !_MACHINE_PARAM_H_ */ 393