param.h revision 27950
1128723Sru/*- 2128723Sru * Copyright (c) 1990 The Regents of the University of California. 3128723Sru * All rights reserved. 4128723Sru * 5128723Sru * This code is derived from software contributed to Berkeley by 6128723Sru * William Jolitz. 7128723Sru * 8128723Sru * Redistribution and use in source and binary forms, with or without 9128723Sru * modification, are permitted provided that the following conditions 10128723Sru * are met: 11128723Sru * 1. Redistributions of source code must retain the above copyright 12128723Sru * notice, this list of conditions and the following disclaimer. 13128723Sru * 2. Redistributions in binary form must reproduce the above copyright 14128723Sru * notice, this list of conditions and the following disclaimer in the 15128723Sru * documentation and/or other materials provided with the distribution. 16128723Sru * 3. All advertising materials mentioning features or use of this software 17128723Sru * must display the following acknowledgement: 18128722Sru * This product includes software developed by the University of 19128723Sru * California, Berkeley and its contributors. 20128722Sru * 4. Neither the name of the University nor the names of its contributors 21128723Sru * may be used to endorse or promote products derived from this software 22128722Sru * without specific prior written permission. 23128722Sru * 24128723Sru * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25128723Sru * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26128723Sru * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27128723Sru * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28128722Sru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29128723Sru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30128722Sru * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31128723Sru * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32128723Sru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33128722Sru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34128723Sru * SUCH DAMAGE. 35128723Sru * 36128722Sru * from: @(#)param.h 5.8 (Berkeley) 6/28/91 37128723Sru * $Id: param.h,v 1.31 1997/08/04 19:14:47 fsmp Exp $ 38128723Sru */ 39128723Sru 40128722Sru#ifndef _MACHINE_PARAM_H_ 41128723Sru#define _MACHINE_PARAM_H_ 42128723Sru 43128722Sru/* 44128723Sru * Machine dependent constants for Intel 386. 45128723Sru */ 46128723Sru 47128723Sru#define MACHINE "i386" 48128723Sru#define NCPUS 1 49128723Sru#define MID_MACHINE MID_I386 50128723Sru 51128723Sru/* 52128723Sru * Round p (pointer or byte index) up to a correctly-aligned value 53128723Sru * for all data types (int, long, ...). The result is unsigned int 54128723Sru * and must be cast to any desired pointer type. 55128722Sru */ 56128723Sru#define ALIGNBYTES (sizeof(int) - 1) 57128723Sru#define ALIGN(p) (((unsigned)(p) + ALIGNBYTES) & ~ALIGNBYTES) 58128722Sru 59128723Sru#define PAGE_SHIFT 12 /* LOG2(PAGE_SIZE) */ 60128723Sru#define PAGE_SIZE (1<<PAGE_SHIFT) /* bytes/page */ 61128723Sru#define PAGE_MASK (PAGE_SIZE-1) 62128723Sru#define NPTEPG (PAGE_SIZE/(sizeof (pt_entry_t))) 63128723Sru 64128723Sru#define NPDEPG (PAGE_SIZE/(sizeof (pd_entry_t))) 65128723Sru#define PDRSHIFT 22 /* LOG2(NBPDR) */ 66128723Sru#define NBPDR (1<<PDRSHIFT) /* bytes/page dir */ 67128723Sru#define PDRMASK (NBPDR-1) 68128723Sru 69128723Sru#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ 70128722Sru#define DEV_BSIZE (1<<DEV_BSHIFT) 71128723Sru 72128723Sru#define BLKDEV_IOSIZE 2048 73128723Sru#define MAXPHYS (64 * 1024) /* max raw I/O transfer size */ 74128723Sru 75128723Sru#define UPAGES 2 /* pages of u-area */ 76128723Sru#define UPAGES_HOLE 2 /* pages of "hole" at top of user space where */ 77128723Sru /* the upages used to be. DO NOT CHANGE! */ 78128723Sru 79128723Sru/* 80128723Sru * Constants related to network buffer management. 81128723Sru * MCLBYTES must be no larger than CLBYTES (the software page size), and, 82128723Sru * on machines that exchange pages of input or output buffers with mbuf 83128723Sru * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple 84128723Sru * of the hardware page size. 85128723Sru */ 86128723Sru#ifndef MSIZE 87128723Sru#define MSIZE 128 /* size of an mbuf */ 88128723Sru#endif /* MSIZE */ 89128723Sru 90128723Sru#ifndef MCLSHIFT 91128723Sru#define MCLSHIFT 11 /* convert bytes to m_buf clusters */ 92128723Sru#endif /* MCLSHIFT */ 93128722Sru#define MCLBYTES (1 << MCLSHIFT) /* size of an m_buf cluster */ 94128722Sru#define MCLOFSET (MCLBYTES - 1) /* offset within an m_buf cluster */ 95128722Sru 96128723Sru/* 97128723Sru * Some macros for units conversion 98128723Sru */ 99128723Sru 100128723Sru/* clicks to bytes */ 101128723Sru#define ctob(x) ((x)<<PAGE_SHIFT) 102128723Sru 103128723Sru/* bytes to clicks */ 104128723Sru#define btoc(x) (((unsigned)(x)+PAGE_MASK)>>PAGE_SHIFT) 105128723Sru 106128722Sru/* 107128723Sru * btodb() is messy and perhaps slow because `bytes' may be an off_t. We 108128723Sru * want to shift an unsigned type to avoid sign extension and we don't 109128723Sru * want to widen `bytes' unnecessarily. Assume that the result fits in 110128723Sru * a daddr_t. 111128723Sru */ 112128723Sru#define btodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \ 113128723Sru (sizeof (bytes) > sizeof(long) \ 114128723Sru ? (daddr_t)((unsigned long long)(bytes) >> DEV_BSHIFT) \ 115128723Sru : (daddr_t)((unsigned long)(bytes) >> DEV_BSHIFT)) 116128723Sru 117128723Sru#define dbtob(db) /* calculates (db * DEV_BSIZE) */ \ 118128723Sru ((off_t)(db) << DEV_BSHIFT) 119128723Sru 120128723Sru/* 121128723Sru * Mach derived conversion macros 122128723Sru */ 123128723Sru#define trunc_page(x) ((unsigned)(x) & ~PAGE_MASK) 124128723Sru#define round_page(x) ((((unsigned)(x)) + PAGE_MASK) & ~PAGE_MASK) 125128723Sru#define trunc_4mpage(x) ((unsigned)(x) & ~PDRMASK) 126128723Sru#define round_4mpage(x) ((((unsigned)(x)) + PDRMASK) & ~PDRMASK) 127128723Sru 128128723Sru#define atop(x) ((unsigned)(x) >> PAGE_SHIFT) 129128723Sru#define ptoa(x) ((unsigned)(x) << PAGE_SHIFT) 130128723Sru 131128723Sru#define i386_btop(x) ((unsigned)(x) >> PAGE_SHIFT) 132128723Sru#define i386_ptob(x) ((unsigned)(x) << PAGE_SHIFT) 133128723Sru 134128723Sru#ifndef _SIMPLELOCK_H_ 135128723Sru#define _SIMPLELOCK_H_ 136128723Sru/* 137128723Sru * A simple spin lock. 138128723Sru * 139128723Sru * This structure only sets one bit of data, but is sized based on the 140128723Sru * minimum word size that can be operated on by the hardware test-and-set 141128723Sru * instruction. It is only needed for multiprocessors, as uniprocessors 142128723Sru * will always run to completion or a sleep. It is an error to hold one 143128723Sru * of these locks while a process is sleeping. 144128723Sru */ 145128723Srustruct simplelock { 146128723Sru volatile int lock_data; 147128723Sru}; 148128723Sru 149128723Sru#if !defined(SIMPLELOCK_DEBUG) && NCPUS > 1 150128723Sru/* 151128723Sru * The simple-lock routines are the primitives out of which the lock 152128723Sru * package is built. The machine-dependent code must implement an 153128723Sru * atomic test_and_set operation that indivisibly sets the simple lock 154128723Sru * to non-zero and returns its old value. It also assumes that the 155128723Sru * setting of the lock to zero below is indivisible. Simple locks may 156128723Sru * only be used for exclusive locks. 157128723Sru */ 158128723Sru 159128723Sru#ifdef the_original_code 160128723Sru 161128723Srustatic __inline void 162128723Srusimple_lock_init(struct simplelock *lkp) 163128723Sru{ 164128723Sru 165128723Sru lkp->lock_data = 0; 166128723Sru} 167128723Sru 168128723Srustatic __inline void 169128723Srusimple_lock(struct simplelock *lkp) 170128723Sru{ 171128723Sru 172128723Sru while (test_and_set(&lkp->lock_data)) 173128723Sru continue; 174128723Sru} 175128723Sru 176128723Srustatic __inline int 177128723Srusimple_lock_try(struct simplelock *lkp) 178128723Sru{ 179128723Sru 180128723Sru return (!test_and_set(&lkp->lock_data)); 181128723Sru} 182128723Sru 183128723Srustatic __inline void 184128723Srusimple_unlock(struct simplelock *lkp) 185128723Sru{ 186128723Sru 187128723Sru lkp->lock_data = 0; 188128723Sru} 189128723Sru 190128723Sru#else /* the_original_code */ 191128723Sru 192128723Sru/* 193128723Sru * This set of defines turns on the real functions in i386/isa/apic_ipl.s. 194128723Sru * It has never actually been tested. 195128723Sru */ 196128723Sru#define simple_lock_init(alp) s_lock_init(alp) 197128723Sru#define simple_lock(alp) s_lock(alp) 198128723Sru#define simple_lock_try(alp) s_lock_try(alp) 199128723Sru#define simple_unlock(alp) s_unlock(alp) 200128723Sru 201128723Sru#endif /* the_original_code */ 202128723Sru 203128723Sru#endif /* NCPUS > 1 */ 204128723Sru#endif /* !_SIMPLELOCK_H_ */ 205128723Sru 206128723Sru#endif /* !_MACHINE_PARAM_H_ */ 207128723Sru