xref: /netbsd-src/sys/arch/mips/include/mips_param.h (revision 4d12bfcd155352508213ace5ccc59ce930ea2974)
1 /*	$NetBSD: mips_param.h,v 1.34 2013/05/23 21:39:49 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 2013 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 #ifdef _KERNEL
29 #include <machine/cpu.h>
30 #endif
31 
32 /*
33  * No reason this can't be common
34  */
35 #if defined(__MIPSEB__)
36 # if defined(__mips_n32) || defined(__mips_n64)
37 #  define	_MACHINE_ARCH	mips64eb
38 #  define	MACHINE_ARCH	"mips64eb"
39 #  define	_MACHINE32_ARCH	mipseb
40 #  define	MACHINE32_ARCH	"mipseb"
41 # else
42 #  define	_MACHINE_ARCH	mipseb
43 #  define	MACHINE_ARCH	"mipseb"
44 # endif
45 #elif defined(__MIPSEL__)
46 # if defined(__mips_n32) || defined(__mips_n64)
47 #  define	_MACHINE_ARCH	mips64el
48 #  define	MACHINE_ARCH	"mips64el"
49 #  define	_MACHINE32_ARCH	mipsel
50 #  define	MACHINE32_ARCH	"mipsel"
51 # else
52 #  define	_MACHINE_ARCH	mipsel
53 #  define	MACHINE_ARCH	"mipsel"
54 #endif
55 #else
56 #error neither __MIPSEL__ nor __MIPSEB__ are defined.
57 #endif
58 
59 /*
60  * Userland code should be using uname/sysctl to get MACHINE so simply
61  * export a generic MACHINE of "mips"
62  */
63 #ifndef _KERNEL
64 #undef MACHINE
65 #define MACHINE "mips"
66 #endif
67 
68 #define ALIGNBYTES32		(sizeof(double) - 1)
69 #define ALIGN32(p)		(((uintptr_t)(p) + ALIGNBYTES32) &~ALIGNBYTES32)
70 
71 /*
72  * On mips, UPAGES is fixed by sys/arch/mips/mips/locore code
73  * to be the number of per-process-wired kernel-stack pages/PTES.
74  */
75 
76 #define	SSIZE		1		/* initial stack size/NBPG */
77 #define	SINCR		1		/* increment of stack/NBPG */
78 
79 #ifdef ENABLE_MIPS_16KB_PAGE
80 #define	UPAGES		1		/* pages of u-area */
81 #define	USPACE		(UPAGES*NBPG)	/* size of u-area in bytes */
82 #elif defined(ENABLE_MIPS_4KB_PAGE) || 1
83 #define	UPAGES		2		/* pages of u-area */
84 #define	USPACE		(UPAGES*NBPG)	/* size of u-area in bytes */
85 #else
86 #error ENABLE_MIPS_xKB_PAGE not defined
87 #endif
88 #define	USPACE_ALIGN	USPACE		/* make sure it starts on a even VA */
89 
90 #ifndef MSGBUFSIZE
91 #define MSGBUFSIZE	NBPG		/* default message buffer size */
92 #endif
93 
94 #ifndef COHERENCY_UNIT
95 #define COHERENCY_UNIT	32	/* MIPS cachelines are usually 32 bytes */
96 #endif
97 
98 #ifdef ENABLE_MIPS_16KB_PAGE
99 #define	NBPG		16384		/* bytes/page */
100 #define	PGSHIFT		14		/* LOG2(NBPG) */
101 #else
102 #define	NBPG		4096		/* bytes/page */
103 #define	PGSHIFT		12		/* LOG2(NBPG) */
104 #endif
105 #define	PGOFSET		(NBPG-1)	/* byte offset into page */
106 #define	NPTEPG		(NBPG/4)
107 
108 #define NBSEG		(NBPG*NPTEPG)	/* bytes/segment */
109 #define	SEGOFSET	(NBSEG-1)	/* byte offset into segment */
110 #define	SEGSHIFT	(PGSHIFT+(PGSHIFT-2))	/* LOG2(NBSEG) */
111 
112 #ifdef _LP64
113 #define	NSEGPG		(NBPG/8)
114 #define NBXSEG		(NSEGPG*NBSEG)	/* bytes/xsegment */
115 #define	XSEGOFSET	(NBSEG-1)	/* byte offset into segment */
116 #define	XSEGSHIFT	(SEGSHIFT+(PGSHIFT-3))	/* LOG2(NBXSEG) */
117 #endif
118 
119 /*
120  * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized
121  * logical pages.
122  */
123 #define	NKMEMPAGES_MIN_DEFAULT	((8 * 1024 * 1024) >> PAGE_SHIFT)
124 #define	NKMEMPAGES_MAX_DEFAULT	((128 * 1024 * 1024) >> PAGE_SHIFT)
125 
126 /*
127  * Mach derived conversion macros
128  */
129 #define mips_round_page(x)	((((uintptr_t)(x)) + NBPG - 1) & ~(NBPG-1))
130 #define mips_trunc_page(x)	((uintptr_t)(x) & ~(NBPG-1))
131 #define mips_btop(x)		((paddr_t)(x) >> PGSHIFT)
132 #define mips_ptob(x)		((paddr_t)(x) << PGSHIFT)
133 
134 #ifdef __MIPSEL__
135 #define	MID_MACHINE	MID_PMAX	/* MID_PMAX (little-endian) */
136 #endif
137 #ifdef __MIPSEB__
138 #define	MID_MACHINE	MID_MIPS	/* MID_MIPS (big-endian) */
139 #endif
140 
141 /*
142  * Constants related to network buffer management.
143  * MCLBYTES must be no larger than NBPG (the software page size), and,
144  * on machines that exchange pages of input or output buffers with mbuf
145  * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
146  * of the hardware page size.
147  */
148 #ifndef MSIZE
149 #ifdef _LP64
150 #define	MSIZE		512		/* size of an mbuf */
151 #else
152 #define	MSIZE		256		/* size of an mbuf */
153 #endif
154 
155 #ifndef MCLSHIFT
156 # define MCLSHIFT	11		/* convert bytes to m_buf clusters */
157 #endif	/* MCLSHIFT */
158 
159 #define	MCLBYTES	(1 << MCLSHIFT)	/* size of a m_buf cluster */
160 
161 #endif
162