1 /* $NetBSD: param.h,v 1.32 2003/08/07 16:29:49 agc Exp $ */ 2 3 /* 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This software was developed by the Computer Systems Engineering group 8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 9 * contributed to Berkeley. 10 * 11 * All advertising materials mentioning features or use of this software 12 * must display the following acknowledgement: 13 * This product includes software developed by the University of 14 * California, Lawrence Berkeley Laboratory. 15 * 16 * Redistribution and use in source and binary forms, with or without 17 * modification, are permitted provided that the following conditions 18 * are met: 19 * 1. Redistributions of source code must retain the above copyright 20 * notice, this list of conditions and the following disclaimer. 21 * 2. Redistributions in binary form must reproduce the above copyright 22 * notice, this list of conditions and the following disclaimer in the 23 * documentation and/or other materials provided with the distribution. 24 * 3. 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 * @(#)param.h 8.1 (Berkeley) 6/11/93 41 */ 42 43 /* 44 * Copyright (c) 1996-2002 Eduardo Horvath 45 * 46 * Redistribution and use in source and binary forms, with or without 47 * modification, are permitted provided that the following conditions 48 * are met: 49 * 1. Redistributions of source code must retain the above copyright 50 * notice, this list of conditions and the following disclaimer. 51 * 52 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND 53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 55 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE 56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 * SUCH DAMAGE. 63 * 64 */ 65 66 #if defined(_KERNEL_OPT) 67 #include "opt_sparc_arch.h" 68 #endif 69 70 #define _MACHINE sparc64 71 #define MACHINE "sparc64" 72 #ifdef __arch64__ 73 #define _MACHINE_ARCH sparc64 74 #define MACHINE_ARCH "sparc64" 75 #define MID_MACHINE MID_SPARC64 76 #else 77 #define _MACHINE_ARCH sparc 78 #define MACHINE_ARCH "sparc" 79 #define MID_MACHINE MID_SPARC 80 #endif 81 82 #ifdef _KERNEL_OPT 83 #include "opt_sparc_arch.h" 84 #endif 85 #ifdef _KERNEL /* XXX */ 86 #ifndef _LOCORE /* XXX */ 87 #include <machine/cpu.h> /* XXX */ 88 #endif /* XXX */ 89 #endif /* XXX */ 90 91 /* 92 * Round p (pointer or byte index) up to a correctly-aligned value for 93 * the machine's strictest data type. The result is u_int and must be 94 * cast to any desired pointer type. 95 * 96 * ALIGNED_POINTER is a boolean macro that checks whether an address 97 * is valid to fetch data elements of type t from on this architecture. 98 * This does not reflect the optimal alignment, just the possibility 99 * (within reasonable limits). 100 * 101 */ 102 #define ALIGNBYTES32 0x7 103 #define ALIGNBYTES64 0xf 104 #ifdef __arch64__ 105 #define ALIGNBYTES ALIGNBYTES64 106 #else 107 #define ALIGNBYTES ALIGNBYTES32 108 #endif 109 #define ALIGN(p) (((u_long)(p) + ALIGNBYTES) & ~ALIGNBYTES) 110 #define ALIGN32(p) (((u_long)(p) + ALIGNBYTES32) & ~ALIGNBYTES32) 111 #define ALIGNED_POINTER(p,t) ((((u_long)(p)) & (sizeof(t)-1)) == 0) 112 113 114 /* 115 * The following variables are always defined and initialized (in locore) 116 * so independently compiled modules (e.g. LKMs) can be used irrespective 117 * of the `options SUN4?' combination a particular kernel was configured with. 118 * See also the definitions of NBPG, PGOFSET and PGSHIFT below. 119 */ 120 #if (defined(_KERNEL) || defined(_STANDALONE)) && !defined(_LOCORE) 121 extern int nbpg, pgofset, pgshift; 122 #endif 123 124 #define DEV_BSIZE 512 125 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ 126 #define BLKDEV_IOSIZE 2048 127 #define MAXPHYS (64 * 1024) 128 129 #ifdef __arch64__ 130 /* We get stack overflows w/8K stacks in 64-bit mode */ 131 #define SSIZE 2 /* initial stack size in pages */ 132 #else 133 #define SSIZE 2 134 #endif 135 #define USPACE (SSIZE*8192) 136 137 138 /* 139 * Here are all the magic kernel virtual addresses and how they're allocated. 140 * 141 * First, the PROM is usually a fixed-sized block from 0x00000000f0000000 to 142 * 0x00000000f0100000. It also uses some space around 0x00000000fff00000 to 143 * map in device registers. The rest is pretty much ours to play with. 144 * 145 * The kernel starts at KERNBASE. Here's they layout. We use macros to set 146 * the addresses so we can relocate everything easily. We use 4MB locked TTEs 147 * to map in the kernel text and data segments. Any extra pages are recycled, 148 * so they can potentially be double-mapped. This shouldn't really be a 149 * problem since they're unused, but wild pointers can cause silent data 150 * corruption if they are in those segments. 151 * 152 * 0x0000000000000000: 64K NFO page zero 153 * 0x0000000000010000: Userland or PROM 154 * KERNBASE: 4MB kernel text and read only data 155 * This is mapped in the ITLB and 156 * Read-Only in the DTLB 157 * KERNBASE+0x400000: 4MB kernel data and BSS -- not in ITLB 158 * Contains context table, kernel pmap, 159 * and other important structures. 160 * KERNBASE+0x800000: Unmapped page -- redzone 161 * KERNBASE+0x802000: Process 0 stack and u-area 162 * KERNBASE+0x806000: 2 pages for pmap_copy_page and /dev/mem 163 * KERNBASE+0x80a000: Start of kernel VA segment 164 * KERNEND: End of kernel VA segment 165 * KERNEND+0x02000: Auxreg_va (unused?) 166 * KERNEND+0x04000: TMPMAP_VA (unused?) 167 * KERNEND+0x06000: message buffer. 168 * KERNEND+0x010000: 64K locked TTE -- different for each CPU 169 * Contains interrupt stack, cpu_info structure, 170 * and 32KB kernel TSB. 171 * KERNEND+0x020000: IODEV_BASE -- begin mapping IO devices here. 172 * 0x00000000fe000000: IODEV_END -- end of device mapping space. 173 * 174 */ 175 #define KERNBASE 0x001000000 /* start of kernel virtual space */ 176 #define KERNEND 0x0e0000000 /* end of kernel virtual space */ 177 #define VM_MAX_KERNEL_BUF ((KERNEND-KERNBASE)/4) 178 179 #define _MAXNBPG 8192 /* fixed VAs, independent of actual NBPG */ 180 181 #define AUXREG_VA ( KERNEND + _MAXNBPG) /* 1 page REDZONE */ 182 #define TMPMAP_VA ( AUXREG_VA + _MAXNBPG) 183 #define MSGBUF_VA ( TMPMAP_VA + _MAXNBPG) 184 /* 185 * Here's the location of the interrupt stack and CPU structure. 186 */ 187 #define INTSTACK ( KERNEND + 8*_MAXNBPG)/* 64K after kernel end */ 188 #define EINTSTACK ( INTSTACK + 2*USPACE) /* 32KB */ 189 #define CPUINFO_VA ( EINTSTACK) 190 #define IODEV_BASE ( CPUINFO_VA + 8*_MAXNBPG)/* 64K long */ 191 #define IODEV_END 0x0f0000000UL /* 16 MB of iospace */ 192 193 /* 194 * Constants related to network buffer management. 195 * MCLBYTES must be no larger than NBPG (the software page size), and, 196 * on machines that exchange pages of input or output buffers with mbuf 197 * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple 198 * of the hardware page size. 199 */ 200 #define MSIZE 256 /* size of an mbuf */ 201 202 #ifndef MCLSHIFT 203 #define MCLSHIFT 11 /* convert bytes to m_buf clusters */ 204 /* 2K cluster can hold Ether frame */ 205 #endif /* MCLSHIFT */ 206 207 #define MCLBYTES (1 << MCLSHIFT) /* size of a m_buf cluster */ 208 209 #ifndef NMBCLUSTERS 210 #if defined(_KERNEL_OPT) 211 #include "opt_gateway.h" 212 #endif 213 214 #ifdef GATEWAY 215 #define NMBCLUSTERS 2048 /* map size, max cluster allocation */ 216 #else 217 #define NMBCLUSTERS 1024 /* map size, max cluster allocation */ 218 #endif 219 #endif 220 221 #define MSGBUFSIZE NBPG 222 223 /* 224 * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized 225 * logical pages. 226 */ 227 #define NKMEMPAGES_MIN_DEFAULT ((6 * 1024 * 1024) >> PAGE_SHIFT) 228 #define NKMEMPAGES_MAX_DEFAULT ((128 * 1024 * 1024) >> PAGE_SHIFT) 229 230 /* pages ("clicks") to disk blocks */ 231 #define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT)) 232 #define dtoc(x) ((x) >> (PGSHIFT - DEV_BSHIFT)) 233 234 /* pages to bytes */ 235 #define ctob(x) ((x) << PGSHIFT) 236 #define btoc(x) (((vsize_t)(x) + PGOFSET) >> PGSHIFT) 237 238 /* bytes to disk blocks */ 239 #define btodb(x) ((x) >> DEV_BSHIFT) 240 #define dbtob(x) ((x) << DEV_BSHIFT) 241 242 /* 243 * Map a ``block device block'' to a file system block. 244 * This should be device dependent, and should use the bsize 245 * field from the disk label. 246 * For now though just use DEV_BSIZE. 247 */ 248 #define bdbtofsb(bn) ((bn) / (BLKDEV_IOSIZE / DEV_BSIZE)) 249 250 #ifdef _KERNEL 251 #ifndef _LOCORE 252 253 extern void delay __P((unsigned int)); 254 #define DELAY(n) delay(n) 255 256 #ifdef __arch64__ 257 /* If we're using a 64-bit kernel use 64-bit math */ 258 #define mstohz(ms) ((ms + 0UL) * hz / 1000) 259 #endif 260 261 extern int cputyp; 262 263 #endif /* _LOCORE */ 264 #endif /* _KERNEL */ 265 266 /* 267 * Values for the cputyp variable. 268 */ 269 #define CPU_SUN4 0 270 #define CPU_SUN4C 1 271 #define CPU_SUN4M 2 272 #define CPU_SUN4U 3 273 274 /* 275 * Shorthand CPU-type macros. Enumerate all eight cases. 276 * Let compiler optimize away code conditional on constants. 277 * 278 * On a sun4 machine, the page size is 8192, while on a sun4c and sun4m 279 * it is 4096. Therefore, in the (SUN4 && (SUN4C || SUN4M)) cases below, 280 * NBPG, PGOFSET and PGSHIFT are defined as variables which are initialized 281 * early in locore.s after the machine type has been detected. 282 * 283 * Note that whenever the macros defined below evaluate to expressions 284 * involving variables, the kernel will perform slighly worse due to the 285 * extra memory references they'll generate. 286 */ 287 288 #define CPU_ISSUN4U (1) 289 #define CPU_ISSUN4M (0) 290 #define CPU_ISSUN4C (0) 291 #define CPU_ISSUN4 (0) 292 293 294 #define PGSHIFT 13 /* log2(NBPG) */ 295 #define NBPG (1<<PGSHIFT) /* bytes/page */ 296 #define PGOFSET (NBPG-1) /* byte offset into page */ 297