param.h revision 203
14Srgrimes/*-
24Srgrimes * Copyright (c) 1990 The Regents of the University of California.
34Srgrimes * All rights reserved.
44Srgrimes *
54Srgrimes * This code is derived from software contributed to Berkeley by
64Srgrimes * William Jolitz.
74Srgrimes *
84Srgrimes * Redistribution and use in source and binary forms, with or without
94Srgrimes * modification, are permitted provided that the following conditions
104Srgrimes * are met:
114Srgrimes * 1. Redistributions of source code must retain the above copyright
124Srgrimes *    notice, this list of conditions and the following disclaimer.
134Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
144Srgrimes *    notice, this list of conditions and the following disclaimer in the
154Srgrimes *    documentation and/or other materials provided with the distribution.
164Srgrimes * 3. All advertising materials mentioning features or use of this software
174Srgrimes *    must display the following acknowledgement:
184Srgrimes *	This product includes software developed by the University of
194Srgrimes *	California, Berkeley and its contributors.
204Srgrimes * 4. Neither the name of the University nor the names of its contributors
214Srgrimes *    may be used to endorse or promote products derived from this software
224Srgrimes *    without specific prior written permission.
234Srgrimes *
244Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
254Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
264Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
274Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
284Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
294Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
304Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
314Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
324Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
334Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
344Srgrimes * SUCH DAMAGE.
354Srgrimes *
364Srgrimes *	@(#)param.h	5.8 (Berkeley) 6/28/91
374Srgrimes *
384Srgrimes * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
394Srgrimes * --------------------         -----   ----------------------
404Srgrimes * CURRENT PATCH LEVEL:         2       00166
414Srgrimes * --------------------         -----   ----------------------
424Srgrimes *
434Srgrimes * 08 Apr 93	Andrew Herbert		Fixes for kmem_alloc panics
444Srgrimes *		Rodney W. Grimes	Tuneable mbuf sizes
454Srgrimes * 04 Jun 93	Rodney W. Grimes	Change default mbuf size to 2048 via
464Srgrimes *					MCLSHIFT.
474Srgrimes */
484Srgrimes
494Srgrimes/*
504Srgrimes * Machine dependent constants for Intel 386.
514Srgrimes */
524Srgrimes
534Srgrimes#define MACHINE "i386"
544Srgrimes
554Srgrimes/*
564Srgrimes * Round p (pointer or byte index) up to a correctly-aligned value
574Srgrimes * for all data types (int, long, ...).   The result is u_int and
584Srgrimes * must be cast to any desired pointer type.
594Srgrimes */
60203Snate#define ALIGNBYTES	(sizeof(int) - 1)
61203Snate#define ALIGN(p)	(((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES)
624Srgrimes
63203Snate
644Srgrimes#define	NBPG		4096		/* bytes/page */
654Srgrimes#define	PGOFSET		(NBPG-1)	/* byte offset into page */
664Srgrimes#define	PGSHIFT		12		/* LOG2(NBPG) */
674Srgrimes#define	NPTEPG		(NBPG/(sizeof (struct pte)))
684Srgrimes
694Srgrimes#define NBPDR		(1024*NBPG)	/* bytes/page dir */
704Srgrimes#define	PDROFSET	(NBPDR-1)	/* byte offset into page dir */
714Srgrimes#define	PDRSHIFT	22		/* LOG2(NBPDR) */
724Srgrimes
734Srgrimes#define	KERNBASE	0xFE000000	/* start of kernel virtual */
744Srgrimes#define	BTOPKERNBASE	((u_long)KERNBASE >> PGSHIFT)
754Srgrimes
764Srgrimes#define	DEV_BSIZE	512
774Srgrimes#define	DEV_BSHIFT	9		/* log2(DEV_BSIZE) */
784Srgrimes#define BLKDEV_IOSIZE	2048
794Srgrimes#define	MAXPHYS		(64 * 1024)	/* max raw I/O transfer size */
804Srgrimes
814Srgrimes#define	CLSIZE		1
824Srgrimes#define	CLSIZELOG2	0
834Srgrimes
844Srgrimes/* NOTE: SSIZE, SINCR and UPAGES must be multiples of CLSIZE */
854Srgrimes#define	SSIZE	1		/* initial stack size/NBPG */
864Srgrimes#define	SINCR	1		/* increment of stack/NBPG */
874Srgrimes
884Srgrimes#define	UPAGES	2		/* pages of u-area */
894Srgrimes
904Srgrimes/*
914Srgrimes * Constants related to network buffer management.
924Srgrimes * MCLBYTES must be no larger than CLBYTES (the software page size), and,
934Srgrimes * on machines that exchange pages of input or output buffers with mbuf
944Srgrimes * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
954Srgrimes * of the hardware page size.
964Srgrimes */
974Srgrimes#ifndef	MSIZE
984Srgrimes#define	MSIZE		128		/* size of an mbuf */
994Srgrimes#endif	/* MSIZE */
1004Srgrimes
1014Srgrimes#ifndef	MCLSHIFT
1024Srgrimes#define	MCLSHIFT	11		/* convert bytes to m_buf clusters */
1034Srgrimes#endif	/* MCLSHIFT */
1044Srgrimes#define	MCLBYTES	(1 << MCLSHIFT)	/* size of an m_buf cluster */
1054Srgrimes#define	MCLOFSET	(MCLBYTES - 1)	/* offset within an m_buf cluster */
1064Srgrimes
1074Srgrimes#ifndef NMBCLUSTERS
1084Srgrimes#ifdef GATEWAY
1094Srgrimes#define	NMBCLUSTERS	512		/* map size, max cluster allocation */
1104Srgrimes#else
1114Srgrimes#define	NMBCLUSTERS	256		/* map size, max cluster allocation */
1124Srgrimes#endif	/* GATEWAY */
1134Srgrimes#endif	/* NMBCLUSTERS */
1144Srgrimes
1154Srgrimes/*
1164Srgrimes * Size of kernel malloc arena in CLBYTES-sized logical pages
1174Srgrimes */
1184Srgrimes#ifndef NKMEMCLUSTERS
1194Srgrimes#define	NKMEMCLUSTERS	(3072*1024/CLBYTES)
1204Srgrimes#endif
1214Srgrimes/*
1224Srgrimes * Some macros for units conversion
1234Srgrimes */
1244Srgrimes/* Core clicks (4096 bytes) to segments and vice versa */
1254Srgrimes#define	ctos(x)	(x)
1264Srgrimes#define	stoc(x)	(x)
1274Srgrimes
1284Srgrimes/* Core clicks (4096 bytes) to disk blocks */
1294Srgrimes#define	ctod(x)	((x)<<(PGSHIFT-DEV_BSHIFT))
1304Srgrimes#define	dtoc(x)	((x)>>(PGSHIFT-DEV_BSHIFT))
1314Srgrimes#define	dtob(x)	((x)<<DEV_BSHIFT)
1324Srgrimes
1334Srgrimes/* clicks to bytes */
1344Srgrimes#define	ctob(x)	((x)<<PGSHIFT)
1354Srgrimes
1364Srgrimes/* bytes to clicks */
1374Srgrimes#define	btoc(x)	(((unsigned)(x)+(NBPG-1))>>PGSHIFT)
1384Srgrimes
1394Srgrimes#define	btodb(bytes)	 		/* calculates (bytes / DEV_BSIZE) */ \
1404Srgrimes	((unsigned)(bytes) >> DEV_BSHIFT)
1414Srgrimes#define	dbtob(db)			/* calculates (db * DEV_BSIZE) */ \
1424Srgrimes	((unsigned)(db) << DEV_BSHIFT)
1434Srgrimes
1444Srgrimes/*
1454Srgrimes * Map a ``block device block'' to a file system block.
1464Srgrimes * This should be device dependent, and will be if we
1474Srgrimes * add an entry to cdevsw/bdevsw for that purpose.
1484Srgrimes * For now though just use DEV_BSIZE.
1494Srgrimes */
1504Srgrimes#define	bdbtofsb(bn)	((bn) / (BLKDEV_IOSIZE/DEV_BSIZE))
1514Srgrimes
1524Srgrimes/*
1534Srgrimes * Mach derived conversion macros
1544Srgrimes */
1554Srgrimes#define i386_round_pdr(x)	((((unsigned)(x)) + NBPDR - 1) & ~(NBPDR-1))
1564Srgrimes#define i386_trunc_pdr(x)	((unsigned)(x) & ~(NBPDR-1))
1574Srgrimes#define i386_round_page(x)	((((unsigned)(x)) + NBPG - 1) & ~(NBPG-1))
1584Srgrimes#define i386_trunc_page(x)	((unsigned)(x) & ~(NBPG-1))
1594Srgrimes#define i386_btod(x)		((unsigned)(x) >> PDRSHIFT)
1604Srgrimes#define i386_dtob(x)		((unsigned)(x) << PDRSHIFT)
1614Srgrimes#define i386_btop(x)		((unsigned)(x) >> PGSHIFT)
1624Srgrimes#define i386_ptob(x)		((unsigned)(x) << PGSHIFT)
1634Srgrimes
1644Srgrimes#ifndef KERNEL
1654Srgrimes#define	DELAY(n)	{ volatile int N = (n); while (--N > 0); }
1664Srgrimes#endif
167