1 /* $NetBSD: param.h,v 1.25 2001/05/30 12:28:51 mrg 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-1999 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 71 72 #define _MACHINE sparc64 73 #define MACHINE "sparc64" 74 #ifdef __arch64__ 75 #define _MACHINE_ARCH sparc64 76 #define MACHINE_ARCH "sparc64" 77 #define MID_MACHINE MID_SPARC64 78 #else 79 #define _MACHINE_ARCH sparc 80 #define MACHINE_ARCH "sparc" 81 #define MID_MACHINE MID_SPARC 82 #endif 83 84 #ifdef _KERNEL /* XXX */ 85 #ifndef _LOCORE /* XXX */ 86 #include <machine/cpu.h> /* XXX */ 87 #endif /* XXX */ 88 #endif /* XXX */ 89 90 /* 91 * Round p (pointer or byte index) up to a correctly-aligned value for 92 * the machine's strictest data type. The result is u_int and must be 93 * cast to any desired pointer type. 94 * 95 * ALIGNED_POINTER is a boolean macro that checks whether an address 96 * is valid to fetch data elements of type t from on this architecture. 97 * This does not reflect the optimal alignment, just the possibility 98 * (within reasonable limits). 99 * 100 */ 101 #define ALIGNBYTES32 0x7 102 #define ALIGNBYTES64 0xf 103 #ifdef __arch64__ 104 #define ALIGNBYTES ALIGNBYTES64 105 #else 106 #define ALIGNBYTES ALIGNBYTES32 107 #endif 108 #define ALIGN(p) (((u_long)(p) + ALIGNBYTES) & ~ALIGNBYTES) 109 #define ALIGN32(p) (((u_long)(p) + ALIGNBYTES32) & ~ALIGNBYTES32) 110 #define ALIGNED_POINTER(p,t) ((((u_long)(p)) & (sizeof(t)-1)) == 0) 111 112 113 /* 114 * The following variables are always defined and initialized (in locore) 115 * so independently compiled modules (e.g. LKMs) can be used irrespective 116 * of the `options SUN4?' combination a particular kernel was configured with. 117 * See also the definitions of NBPG, PGOFSET and PGSHIFT below. 118 */ 119 #if (defined(_KERNEL) || defined(_STANDALONE)) && !defined(_LOCORE) 120 extern int nbpg, pgofset, pgshift; 121 #endif 122 123 #define DEV_BSIZE 512 124 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ 125 #define BLKDEV_IOSIZE 2048 126 #define MAXPHYS (64 * 1024) 127 128 #ifdef __arch64__ 129 /* We get stack overflows w/8K stacks in 64-bit mode */ 130 #define SSIZE 2 /* initial stack size in pages */ 131 #else 132 #define SSIZE 2 133 #endif 134 #define USPACE (SSIZE*8192) 135 136 137 /* 138 * Here are all the magic kernel virtual addresses and how they're allocated. 139 * 140 * First, the PROM is usually a fixed-sized block from 0x00000000f0000000 to 141 * 0x00000000f0100000. It also uses some space around 0x00000000fff00000 to 142 * map in device registers. The rest is pretty much ours to play with. 143 * 144 * The kernel starts at KERNBASE. Here's they layout. We use macros to set 145 * the addresses so we can relocate everything easily. We use 4MB locked TTEs 146 * to map in the kernel text and data segments. Any extra pages are recycled, 147 * so they can potentially be double-mapped. This shouldn't really be a 148 * problem since they're unused, but wild pointers can cause silent data 149 * corruption if they are in those segments. 150 * 151 * 0x0000000000000000: 64K NFO page zero 152 * 0x0000000000010000: Userland or PROM 153 * KERNBASE: 4MB kernel text and read only data 154 * This is mapped in the ITLB and 155 * Read-Only in the DTLB 156 * KERNBASE+0x400000: 4MB kernel data and BSS -- not in ITLB 157 * Contains context table, kernel pmap, 158 * and other important structures. 159 * KERNBASE+0x800000: Unmapped page -- redzone 160 * KERNBASE+0x802000: Process 0 stack and u-area 161 * KERNBASE+0x806000: 2 pages for pmap_copy_page and /dev/mem 162 * KERNBASE+0x80a000: Start of kernel VA segment 163 * KERNEND: End of kernel VA segment 164 * KERNEND+0x02000: Auxreg_va (unused?) 165 * KERNEND+0x04000: TMPMAP_VA (unused?) 166 * KERNEND+0x06000: message buffer. 167 * KERNEND+0x010000: 64K locked TTE -- different for each CPU 168 * Contains interrupt stack, cpu_info structure, 169 * and 32KB kernel TSB. 170 * KERNEND+0x020000: IODEV_BASE -- begin mapping IO devices here. 171 * 0x00000000fe000000: IODEV_END -- end of device mapping space. 172 * 173 */ 174 #define KERNBASE 0x001000000 /* start of kernel virtual space */ 175 #define KERNEND 0x0e0000000 /* end of kernel virtual space */ 176 #define VM_MAX_KERNEL_BUF ((KERNEND-KERNBASE)/4) 177 178 #define _MAXNBPG 8192 /* fixed VAs, independent of actual NBPG */ 179 180 #define AUXREG_VA ( KERNEND + _MAXNBPG) /* 1 page REDZONE */ 181 #define TMPMAP_VA ( AUXREG_VA + _MAXNBPG) 182 #define MSGBUF_VA ( TMPMAP_VA + _MAXNBPG) 183 /* 184 * Here's the location of the interrupt stack and CPU structure. 185 */ 186 #define INTSTACK ( KERNEND + 8*_MAXNBPG)/* 64K after kernel end */ 187 #define EINTSTACK ( INTSTACK + 2*USPACE) /* 32KB */ 188 #define CPUINFO_VA ( EINTSTACK) 189 #define IODEV_BASE ( CPUINFO_VA + 8*_MAXNBPG)/* 64K long */ 190 #define IODEV_END 0x0f0000000UL /* 16 MB of iospace */ 191 192 /* 193 * Constants related to network buffer management. 194 * MCLBYTES must be no larger than NBPG (the software page size), and, 195 * on machines that exchange pages of input or output buffers with mbuf 196 * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple 197 * of the hardware page size. 198 */ 199 #define MSIZE 256 /* size of an mbuf */ 200 #define MCLBYTES 2048 /* enough for whole Ethernet packet */ 201 #define MCLSHIFT 11 /* log2(MCLBYTES) */ 202 #define MCLOFSET (MCLBYTES - 1) 203 204 #if defined(_KERNEL_OPT) 205 #include "opt_gateway.h" 206 #endif 207 208 #ifndef NMBCLUSTERS 209 #ifdef GATEWAY 210 #define NMBCLUSTERS 512 /* map size, max cluster allocation */ 211 #else 212 #define NMBCLUSTERS 256 /* map size, max cluster allocation */ 213 #endif 214 #endif 215 216 #define MSGBUFSIZE NBPG 217 218 /* 219 * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized 220 * logical pages. 221 */ 222 #define NKMEMPAGES_MIN_DEFAULT ((6 * 1024 * 1024) >> PAGE_SHIFT) 223 #define NKMEMPAGES_MAX_DEFAULT ((128 * 1024 * 1024) >> PAGE_SHIFT) 224 225 /* pages ("clicks") to disk blocks */ 226 #define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT)) 227 #define dtoc(x) ((x) >> (PGSHIFT - DEV_BSHIFT)) 228 229 /* pages to bytes */ 230 #define ctob(x) ((x) << PGSHIFT) 231 #define btoc(x) (((vsize_t)(x) + PGOFSET) >> PGSHIFT) 232 233 /* bytes to disk blocks */ 234 #define btodb(x) ((x) >> DEV_BSHIFT) 235 #define dbtob(x) ((x) << DEV_BSHIFT) 236 237 /* 238 * Map a ``block device block'' to a file system block. 239 * This should be device dependent, and should use the bsize 240 * field from the disk label. 241 * For now though just use DEV_BSIZE. 242 */ 243 #define bdbtofsb(bn) ((bn) / (BLKDEV_IOSIZE / DEV_BSIZE)) 244 245 /* 246 * dvmamap manages a range of DVMA addresses intended to create double 247 * mappings of physical memory. In a way, `dvmamap' is a submap of the 248 * VM map `phys_map'. The difference is the use of the `resource map' 249 * routines to manage page allocation, allowing DVMA addresses to be 250 * allocated and freed from within interrupt routines. 251 * 252 * Note that `phys_map' can still be used to allocate memory-backed pages 253 * in DVMA space. 254 */ 255 #ifdef _KERNEL 256 #ifndef _LOCORE 257 #if 0 258 extern vaddr_t dvma_base; 259 extern vaddr_t dvma_end; 260 extern struct map *dvmamap; 261 /* 262 * The dvma resource map is defined in page units, which are numbered 1 to N. 263 * Use these macros to convert to/from virtual addresses. 264 */ 265 #define rctov(n) (ctob(((n)-1))+dvma_base) 266 #define vtorc(v) ((btoc((v)-dvma_base))+1) 267 268 extern caddr_t kdvma_mapin __P((caddr_t, int, int)); 269 extern caddr_t dvma_malloc __P((size_t, void *, int)); 270 extern void dvma_free __P((caddr_t, size_t, void *)); 271 #endif 272 273 extern void delay __P((unsigned int)); 274 #define DELAY(n) delay(n) 275 276 extern int cputyp; 277 extern int cpumod; 278 extern int mmumod; 279 280 #endif /* _LOCORE */ 281 #endif /* _KERNEL */ 282 283 /* 284 * Values for the cputyp variable. 285 */ 286 #define CPU_SUN4 0 287 #define CPU_SUN4C 1 288 #define CPU_SUN4M 2 289 #define CPU_SUN4U 3 290 291 /* 292 * Shorthand CPU-type macros. Enumerate all eight cases. 293 * Let compiler optimize away code conditional on constants. 294 * 295 * On a sun4 machine, the page size is 8192, while on a sun4c and sun4m 296 * it is 4096. Therefore, in the (SUN4 && (SUN4C || SUN4M)) cases below, 297 * NBPG, PGOFSET and PGSHIFT are defined as variables which are initialized 298 * early in locore.s after the machine type has been detected. 299 * 300 * Note that whenever the macros defined below evaluate to expressions 301 * involving variables, the kernel will perform slighly worse due to the 302 * extra memory references they'll generate. 303 */ 304 305 #define CPU_ISSUN4U (1) 306 #define CPU_ISSUN4MOR4U (1) 307 #define CPU_ISSUN4M (0) 308 #define CPU_ISSUN4C (0) 309 #define CPU_ISSUN4 (0) 310 #define CPU_ISSUN4OR4C (0) 311 #define CPU_ISSUN4COR4M (0) 312 #define NBPG 8192 /* bytes/page */ 313 #define PGOFSET (NBPG-1) /* byte offset into page */ 314 #define PGSHIFT 13 /* log2(NBPG) */ 315