xref: /openbsd/sys/arch/mips64/include/param.h (revision 99ca9df2)
1 /*      $OpenBSD: param.h,v 1.6 2005/01/31 21:35:49 grange Exp $ */
2 
3 /*
4  * Copyright (c) 1988 University of Utah.
5  * Copyright (c) 1992, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * the Systems Programming Group of the University of Utah Computer
10  * Science Department and Ralph Campbell.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *	This product includes software developed by the University of
23  *	California, Berkeley and its contributors.
24  * 4. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  *	from: Utah Hdr: machparam.h 1.11 89/08/14
41  *	from: @(#)param.h	8.1 (Berkeley) 6/10/93
42  */
43 
44 #ifndef _MIPS_PARAM_H_
45 #define _MIPS_PARAM_H_
46 
47 #ifdef _KERNEL
48 #ifdef _LOCORE
49 #include <machine/psl.h>
50 #else
51 #include <machine/cpu.h>
52 #endif
53 #endif
54 
55 /*
56  * Round p (pointer or byte index) up to a correctly-aligned value for all
57  * data types (int, long, ...).   The result is u_int and must be cast to
58  * any desired pointer type.
59  */
60 #define	ALIGNBYTES	7
61 #define	ALIGN(p)	(((u_long)(p) + ALIGNBYTES) &~ ALIGNBYTES)
62 #define ALIGNED_POINTER(p, t)  ((((u_long)(p)) & (sizeof (t) - 1)) == 0)
63 
64 #define	NBPG		4096		/* bytes/page */
65 #define	PGOFSET		(NBPG-1)	/* byte offset into page */
66 #define	PGSHIFT		12		/* LOG2(NBPG) */
67 
68 #define PAGE_SHIFT	12
69 #define PAGE_SIZE	(1 << PAGE_SHIFT)
70 #define PAGE_MASK	(PAGE_SIZE - 1)
71 
72 #define	NPTEPG		(NBPG/4)
73 
74 #define NBSEG		0x400000	/* bytes/segment */
75 #define	SEGOFSET	(NBSEG-1)	/* byte offset into segment */
76 #define	SEGSHIFT	22		/* LOG2(NBSEG) */
77 
78 #ifdef __LP64__
79 #define	KERNBASE	0xffffffff80000000L	/* start of kernel virtual */
80 #else
81 #define	KERNBASE	0x80000000	/* start of kernel virtual */
82 #endif
83 #define	BTOPKERNBASE	((u_long)KERNBASE >> PGSHIFT)
84 
85 #define	DEV_BSHIFT	9		/* log2(DEV_BSIZE) */
86 #define	DEV_BSIZE	(1 << DEV_BSHIFT)
87 #define BLKDEV_IOSIZE	2048
88 /* XXX Maxphys temporary changed to 32K while SCSI driver is fixed. */
89 #define	MAXPHYS		(32 * 1024)	/* max raw I/O transfer size */
90 
91 #define	SSIZE		1		/* initial stack size/NBPG */
92 #define	SINCR		1		/* increment of stack/NBPG */
93 
94 #ifdef __LP64__
95 #define	UPAGES		4		/* pages of u-area */
96 #else
97 #define	UPAGES		2		/* pages of u-area */
98 #endif
99 
100 #define USPACE		(UPAGES*NBPG)	/* size of u-area in bytes */
101 #define	USPACE_ALIGN	(2*NBPG)	/* u-area alignment 0-none */
102 
103 /*
104  * Constants related to network buffer management.
105  * MCLBYTES must be no larger than PAGE_SIZE (the software page size), and,
106  * on machines that exchange pages of input or output buffers with mbuf
107  * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
108  * of the hardware page size.
109  */
110 #define	MSIZE		256		/* size of an mbuf */
111 #define	MCLSHIFT	11
112 #define	MCLBYTES	(1 << MCLSHIFT)	/* enough for whole Ethernet packet */
113 #define	MCLOFSET	(MCLBYTES - 1)
114 #ifndef NMBCLUSTERS
115 #define	NMBCLUSTERS	4096		/* map size, max cluster allocation */
116 #endif
117 
118 #define	MSGBUFSIZE	8192
119 
120 /* Default malloc arena size */
121 #define	NKMEMPAGES_MIN_DEFAULT  ((8 * 1024 * 1024) >> PAGE_SHIFT)
122 #define	NKMEMPAGES_MAX_DEFAULT  ((64 * 1024 * 1024) >> PAGE_SHIFT)
123 
124 /* pages ("clicks") (4096 bytes) to disk blocks */
125 #define	ctod(x)	((x) << (PGSHIFT - DEV_BSHIFT))
126 #define	dtoc(x)	((x) >> (PGSHIFT - DEV_BSHIFT))
127 
128 /* pages to bytes */
129 #define	ctob(x)	((x) << PGSHIFT)
130 #define btoc(x) (((x) + PGOFSET) >> PGSHIFT)
131 
132 /* bytes to disk blocks */
133 #define	btodb(x)	((x) >> DEV_BSHIFT)
134 #define dbtob(x)	((x) << DEV_BSHIFT)
135 
136 /*
137  * Map a ``block device block'' to a file system block.
138  * This should be device dependent, and should use the bsize
139  * field from the disk label.
140  * For now though just use DEV_BSIZE.
141  */
142 #define	bdbtofsb(bn)	((bn) / (BLKDEV_IOSIZE/DEV_BSIZE))
143 
144 /*
145  * Conversion macros
146  */
147 #define mips_round_page(x)	((((u_long)(x)) + NBPG - 1) & ~(NBPG-1))
148 #define mips_trunc_page(x)	((u_long)(x) & ~(NBPG-1))
149 #define mips_btop(x)		((u_long)(x) >> PGSHIFT)
150 #define mips_ptob(x)		((u_long)(x) << PGSHIFT)
151 
152 #ifdef _KERNEL
153 #ifndef _LOCORE
154 
155 #define	DELAY(n)	delay(n)
156 void delay(int);
157 void nanodelay(int);
158 #endif
159 
160 #else /* !_KERNEL */
161 #define	DELAY(n)	{ int N = (n); while (--N > 0); }
162 #endif /* !_KERNEL */
163 
164 #endif /* !_MIPS_PARAM_H_ */
165