1 /* $NetBSD: mips_param.h,v 1.37 2015/06/11 15:43:36 matt 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 /* 29 * No reason this can't be common 30 */ 31 #if defined(__MIPSEB__) 32 # if defined(__mips_n32) || defined(__mips_n64) 33 # define _MACHINE_ARCH mips64eb 34 # define MACHINE_ARCH "mips64eb" 35 # define _MACHINE32_ARCH mipseb 36 # define MACHINE32_ARCH "mipseb" 37 # else 38 # define _MACHINE_ARCH mipseb 39 # define MACHINE_ARCH "mipseb" 40 # endif 41 #elif defined(__MIPSEL__) 42 # if defined(__mips_n32) || defined(__mips_n64) 43 # define _MACHINE_ARCH mips64el 44 # define MACHINE_ARCH "mips64el" 45 # define _MACHINE32_ARCH mipsel 46 # define MACHINE32_ARCH "mipsel" 47 # else 48 # define _MACHINE_ARCH mipsel 49 # define MACHINE_ARCH "mipsel" 50 #endif 51 #else 52 #error neither __MIPSEL__ nor __MIPSEB__ are defined. 53 #endif 54 55 /* 56 * Userland code should be using uname/sysctl to get MACHINE so simply 57 * export a generic MACHINE of "mips" 58 */ 59 #ifndef _KERNEL 60 #undef MACHINE 61 #define MACHINE "mips" 62 #endif 63 64 #define ALIGNBYTES32 (sizeof(double) - 1) 65 #define ALIGN32(p) (((uintptr_t)(p) + ALIGNBYTES32) &~ALIGNBYTES32) 66 67 /* 68 * On mips, UPAGES is fixed by sys/arch/mips/mips/locore code 69 * to be the number of per-process-wired kernel-stack pages/PTES. 70 */ 71 72 #define SSIZE 1 /* initial stack size/NBPG */ 73 #define SINCR 1 /* increment of stack/NBPG */ 74 75 #ifdef ENABLE_MIPS_16KB_PAGE 76 #define UPAGES 1 /* pages of u-area */ 77 #define USPACE (UPAGES*NBPG) /* size of u-area in bytes */ 78 #elif defined(ENABLE_MIPS_4KB_PAGE) || 1 79 #define UPAGES 2 /* pages of u-area */ 80 #define USPACE (UPAGES*NBPG) /* size of u-area in bytes */ 81 #else 82 #error ENABLE_MIPS_xKB_PAGE not defined 83 #endif 84 #define USPACE_ALIGN USPACE /* make sure it starts on a even VA */ 85 86 #ifndef MSGBUFSIZE 87 #define MSGBUFSIZE NBPG /* default message buffer size */ 88 #endif 89 90 #ifndef COHERENCY_UNIT 91 #define COHERENCY_UNIT 32 /* MIPS cachelines are usually 32 bytes */ 92 #endif 93 94 #ifdef ENABLE_MIPS_16KB_PAGE 95 #define NBPG 16384 /* bytes/page */ 96 #define PGSHIFT 14 /* LOG2(NBPG) */ 97 #else 98 #define NBPG 4096 /* bytes/page */ 99 #define PGSHIFT 12 /* LOG2(NBPG) */ 100 #endif 101 #define PGOFSET (NBPG-1) /* byte offset into page */ 102 #define NPTEPG (NBPG/4) 103 104 #define NBSEG (NBPG*NPTEPG) /* bytes/segment */ 105 #define SEGOFSET (NBSEG-1) /* byte offset into segment */ 106 #define SEGSHIFT (PGSHIFT+(PGSHIFT-2)) /* LOG2(NBSEG) */ 107 108 #ifdef _LP64 109 #define NSEGPG (NBPG/8) 110 #define NBXSEG ((uint64_t)NSEGPG*NBSEG) /* bytes/xsegment */ 111 #define XSEGOFSET (NBSEG-1) /* byte offset into segment */ 112 #define XSEGSHIFT (SEGSHIFT+(PGSHIFT-3)) /* LOG2(NBXSEG) */ 113 #endif 114 115 /* 116 * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized 117 * logical pages. 118 */ 119 #define NKMEMPAGES_MIN_DEFAULT ((8 * 1024 * 1024) >> PAGE_SHIFT) 120 #define NKMEMPAGES_MAX_DEFAULT ((128 * 1024 * 1024) >> PAGE_SHIFT) 121 122 /* 123 * Mach derived conversion macros 124 */ 125 #define mips_round_page(x) ((((uintptr_t)(x)) + NBPG - 1) & ~(NBPG-1)) 126 #define mips_trunc_page(x) ((uintptr_t)(x) & ~(NBPG-1)) 127 #define mips_btop(x) ((paddr_t)(x) >> PGSHIFT) 128 #define mips_ptob(x) ((paddr_t)(x) << PGSHIFT) 129 130 #ifdef __MIPSEL__ 131 #define MID_MACHINE MID_PMAX /* MID_PMAX (little-endian) */ 132 #endif 133 #ifdef __MIPSEB__ 134 #define MID_MACHINE MID_MIPS /* MID_MIPS (big-endian) */ 135 #endif 136 137 /* 138 * Constants related to network buffer management. 139 * MCLBYTES must be no larger than NBPG (the software page size), and, 140 * on machines that exchange pages of input or output buffers with mbuf 141 * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple 142 * of the hardware page size. 143 */ 144 #ifndef MSIZE 145 #ifdef _LP64 146 #define MSIZE 512 /* size of an mbuf */ 147 #else 148 #define MSIZE 256 /* size of an mbuf */ 149 #endif 150 151 #ifndef MCLSHIFT 152 # define MCLSHIFT 11 /* convert bytes to m_buf clusters */ 153 #endif /* MCLSHIFT */ 154 155 #define MCLBYTES (1 << MCLSHIFT) /* size of a m_buf cluster */ 156 157 #endif 158