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