param.h revision 4
1166124Srafan/*- 2166124Srafan * Copyright (c) 1990 The Regents of the University of California. 3262685Sdelphij * All rights reserved. 4166124Srafan * 5166124Srafan * This code is derived from software contributed to Berkeley by 6166124Srafan * William Jolitz. 7166124Srafan * 8166124Srafan * Redistribution and use in source and binary forms, with or without 9166124Srafan * modification, are permitted provided that the following conditions 10166124Srafan * are met: 11166124Srafan * 1. Redistributions of source code must retain the above copyright 12166124Srafan * notice, this list of conditions and the following disclaimer. 13166124Srafan * 2. Redistributions in binary form must reproduce the above copyright 14166124Srafan * notice, this list of conditions and the following disclaimer in the 15166124Srafan * documentation and/or other materials provided with the distribution. 16166124Srafan * 3. All advertising materials mentioning features or use of this software 17166124Srafan * must display the following acknowledgement: 18166124Srafan * This product includes software developed by the University of 19166124Srafan * California, Berkeley and its contributors. 20166124Srafan * 4. Neither the name of the University nor the names of its contributors 21166124Srafan * may be used to endorse or promote products derived from this software 22166124Srafan * without specific prior written permission. 23166124Srafan * 24166124Srafan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25166124Srafan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26166124Srafan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27166124Srafan * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28166124Srafan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29166124Srafan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30166124Srafan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31166124Srafan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32262685Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33166124Srafan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34166124Srafan * SUCH DAMAGE. 35166124Srafan * 36166124Srafan * @(#)param.h 5.8 (Berkeley) 6/28/91 37166124Srafan * 38166124Srafan * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE 39166124Srafan * -------------------- ----- ---------------------- 40262685Sdelphij * CURRENT PATCH LEVEL: 2 00166 41166124Srafan * -------------------- ----- ---------------------- 42262685Sdelphij * 43262685Sdelphij * 08 Apr 93 Andrew Herbert Fixes for kmem_alloc panics 44262685Sdelphij * Rodney W. Grimes Tuneable mbuf sizes 45262685Sdelphij * 04 Jun 93 Rodney W. Grimes Change default mbuf size to 2048 via 46262685Sdelphij * MCLSHIFT. 47166124Srafan */ 48166124Srafan 49262685Sdelphij/* 50166124Srafan * Machine dependent constants for Intel 386. 51166124Srafan */ 52166124Srafan 53166124Srafan#define MACHINE "i386" 54166124Srafan 55166124Srafan/* 56262685Sdelphij * Round p (pointer or byte index) up to a correctly-aligned value 57262685Sdelphij * for all data types (int, long, ...). The result is u_int and 58166124Srafan * must be cast to any desired pointer type. 59166124Srafan */ 60166124Srafan#define ALIGN(p) (((u_int)(p) + (sizeof(int) - 1)) &~ (sizeof(int) - 1)) 61166124Srafan 62166124Srafan#define NBPG 4096 /* bytes/page */ 63166124Srafan#define PGOFSET (NBPG-1) /* byte offset into page */ 64262685Sdelphij#define PGSHIFT 12 /* LOG2(NBPG) */ 65262685Sdelphij#define NPTEPG (NBPG/(sizeof (struct pte))) 66262685Sdelphij 67262685Sdelphij#define NBPDR (1024*NBPG) /* bytes/page dir */ 68262685Sdelphij#define PDROFSET (NBPDR-1) /* byte offset into page dir */ 69262685Sdelphij#define PDRSHIFT 22 /* LOG2(NBPDR) */ 70262685Sdelphij 71262685Sdelphij#define KERNBASE 0xFE000000 /* start of kernel virtual */ 72262685Sdelphij#define BTOPKERNBASE ((u_long)KERNBASE >> PGSHIFT) 73262685Sdelphij 74262685Sdelphij#define DEV_BSIZE 512 75262685Sdelphij#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ 76262685Sdelphij#define BLKDEV_IOSIZE 2048 77262685Sdelphij#define MAXPHYS (64 * 1024) /* max raw I/O transfer size */ 78262685Sdelphij 79262685Sdelphij#define CLSIZE 1 80262685Sdelphij#define CLSIZELOG2 0 81262685Sdelphij 82262685Sdelphij/* NOTE: SSIZE, SINCR and UPAGES must be multiples of CLSIZE */ 83262685Sdelphij#define SSIZE 1 /* initial stack size/NBPG */ 84262685Sdelphij#define SINCR 1 /* increment of stack/NBPG */ 85262685Sdelphij 86262685Sdelphij#define UPAGES 2 /* pages of u-area */ 87262685Sdelphij 88262685Sdelphij/* 89262685Sdelphij * Constants related to network buffer management. 90262685Sdelphij * MCLBYTES must be no larger than CLBYTES (the software page size), and, 91262685Sdelphij * on machines that exchange pages of input or output buffers with mbuf 92262685Sdelphij * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple 93262685Sdelphij * of the hardware page size. 94262685Sdelphij */ 95262685Sdelphij#ifndef MSIZE 96262685Sdelphij#define MSIZE 128 /* size of an mbuf */ 97262685Sdelphij#endif /* MSIZE */ 98262685Sdelphij 99262685Sdelphij#ifndef MCLSHIFT 100262685Sdelphij#define MCLSHIFT 11 /* convert bytes to m_buf clusters */ 101262685Sdelphij#endif /* MCLSHIFT */ 102262685Sdelphij#define MCLBYTES (1 << MCLSHIFT) /* size of an m_buf cluster */ 103262685Sdelphij#define MCLOFSET (MCLBYTES - 1) /* offset within an m_buf cluster */ 104262685Sdelphij 105262685Sdelphij#ifndef NMBCLUSTERS 106262685Sdelphij#ifdef GATEWAY 107262685Sdelphij#define NMBCLUSTERS 512 /* map size, max cluster allocation */ 108262685Sdelphij#else 109262685Sdelphij#define NMBCLUSTERS 256 /* map size, max cluster allocation */ 110262685Sdelphij#endif /* GATEWAY */ 111262685Sdelphij#endif /* NMBCLUSTERS */ 112262685Sdelphij 113262685Sdelphij/* 114262685Sdelphij * Size of kernel malloc arena in CLBYTES-sized logical pages 115262685Sdelphij */ 116262685Sdelphij#ifndef NKMEMCLUSTERS 117262685Sdelphij#define NKMEMCLUSTERS (3072*1024/CLBYTES) 118262685Sdelphij#endif 119/* 120 * Some macros for units conversion 121 */ 122/* Core clicks (4096 bytes) to segments and vice versa */ 123#define ctos(x) (x) 124#define stoc(x) (x) 125 126/* Core clicks (4096 bytes) to disk blocks */ 127#define ctod(x) ((x)<<(PGSHIFT-DEV_BSHIFT)) 128#define dtoc(x) ((x)>>(PGSHIFT-DEV_BSHIFT)) 129#define dtob(x) ((x)<<DEV_BSHIFT) 130 131/* clicks to bytes */ 132#define ctob(x) ((x)<<PGSHIFT) 133 134/* bytes to clicks */ 135#define btoc(x) (((unsigned)(x)+(NBPG-1))>>PGSHIFT) 136 137#define btodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \ 138 ((unsigned)(bytes) >> DEV_BSHIFT) 139#define dbtob(db) /* calculates (db * DEV_BSIZE) */ \ 140 ((unsigned)(db) << DEV_BSHIFT) 141 142/* 143 * Map a ``block device block'' to a file system block. 144 * This should be device dependent, and will be if we 145 * add an entry to cdevsw/bdevsw for that purpose. 146 * For now though just use DEV_BSIZE. 147 */ 148#define bdbtofsb(bn) ((bn) / (BLKDEV_IOSIZE/DEV_BSIZE)) 149 150/* 151 * Mach derived conversion macros 152 */ 153#define i386_round_pdr(x) ((((unsigned)(x)) + NBPDR - 1) & ~(NBPDR-1)) 154#define i386_trunc_pdr(x) ((unsigned)(x) & ~(NBPDR-1)) 155#define i386_round_page(x) ((((unsigned)(x)) + NBPG - 1) & ~(NBPG-1)) 156#define i386_trunc_page(x) ((unsigned)(x) & ~(NBPG-1)) 157#define i386_btod(x) ((unsigned)(x) >> PDRSHIFT) 158#define i386_dtob(x) ((unsigned)(x) << PDRSHIFT) 159#define i386_btop(x) ((unsigned)(x) >> PGSHIFT) 160#define i386_ptob(x) ((unsigned)(x) << PGSHIFT) 161 162#ifndef KERNEL 163#define DELAY(n) { volatile int N = (n); while (--N > 0); } 164#endif 165