1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * Copyright 2016 Nexenta Systems, Inc. 26 * Copyright 2020 Joyent, Inc. 27 */ 28 29 /* 30 * The intent of this file is to contain any data that must remain 31 * resident in the kernel. 32 * 33 * space_store(), space_fetch(), and space_free() have been added to 34 * easily store and retrieve kernel resident data. 35 * These functions are recommended rather than adding new variables to 36 * this file. 37 * 38 * Note that it's possible for name collisions to occur. In order to 39 * prevent collisions, it's recommended that the convention in 40 * PSARC/1997/389 be used. If a collision occurs, then space_store will 41 * fail. 42 */ 43 44 #include <sys/types.h> 45 #include <sys/param.h> 46 #include <sys/var.h> 47 #include <sys/proc.h> 48 #include <sys/signal.h> 49 #include <sys/utsname.h> 50 #include <sys/buf.h> 51 #include <sys/cred.h> 52 #include <sys/vfs.h> 53 #include <sys/vnode.h> 54 #include <sys/sysinfo.h> 55 #include <sys/t_lock.h> 56 #include <sys/vmem.h> 57 #include <sys/modhash.h> 58 #include <sys/cmn_err.h> 59 60 #include <sys/strredir.h> 61 #include <sys/kbio.h> 62 #include <sys/consdev.h> 63 #include <sys/wscons.h> 64 #include <sys/bootprops.h> 65 66 struct buf bfreelist; /* Head of the free list of buffers */ 67 68 sysinfo_t sysinfo; 69 vminfo_t vminfo; /* VM stats protected by sysinfolock mutex */ 70 71 #ifdef lint 72 int __lintzero; /* Alway zero for shutting up lint */ 73 #endif 74 75 /* 76 * The following describe the physical memory configuration. 77 * 78 * physmem - The amount of physical memory configured 79 * in pages. ptob(physmem) is the amount 80 * of physical memory in bytes. Defined in 81 * .../os/startup.c. 82 * 83 * physmax - The highest numbered physical page in memory. 84 * 85 * maxmem - Maximum available memory, in pages. Defined 86 * in main.c. 87 * 88 * physinstalled 89 * - Pages of physical memory installed; 90 * includes use by PROM/boot not counted in 91 * physmem. 92 */ 93 94 pfn_t physmax; 95 pgcnt_t physinstalled; 96 97 struct var v; 98 99 #include <sys/systm.h> 100 #include <sys/conf.h> 101 #include <sys/kmem.h> 102 #include <sys/sysmacros.h> 103 #include <sys/bootconf.h> 104 105 /* 106 * Data for segkmem pages that should be resident 107 */ 108 struct vnode kvps[KV_MAX]; 109 110 /* 111 * Data from swapgeneric.c that must be resident. 112 */ 113 struct vnode *rootvp; /* vnode of the root device */ 114 dev_t rootdev; /* dev_t of the root device */ 115 boolean_t root_is_ramdisk; /* root is ramdisk */ 116 uint32_t ramdisk_size; /* (KB) currently set only for sparc netboots */ 117 118 /* 119 * dhcp 120 */ 121 #include <sys/socket.h> 122 #include <sys/errno.h> 123 #include <sys/sockio.h> 124 #include <sys/stream.h> 125 #include <sys/stropts.h> 126 #include <sys/dlpi.h> 127 #include <net/if.h> 128 129 int netboot; 130 int obpdebug; 131 char *dhcack; /* dhcp response packet */ 132 int dhcacklen; 133 char *netdev_path; /* Used to cache the netdev_path handed up by boot */ 134 char dhcifname[IFNAMSIZ]; 135 136 /* 137 * Data from arp.c that must be resident. 138 */ 139 #include <net/if_arp.h> 140 #include <netinet/in.h> 141 #include <netinet/in_var.h> 142 #include <netinet/if_ether.h> 143 144 ether_addr_t etherbroadcastaddr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 145 146 #include <sys/tty.h> 147 #include <sys/ptyvar.h> 148 149 static void store_fetch_initspace(); 150 151 /* 152 * Allocate tunable structures at runtime. 153 */ 154 void 155 space_init(void) 156 { 157 pty_initspace(); 158 store_fetch_initspace(); 159 } 160 161 int ts_dispatch_extended = -1; /* set in ts_getdptbl or set_platform_default */ 162 163 /* 164 * Previously defined in consmsconf.c ... 165 */ 166 dev_t kbddev = NODEV; 167 dev_t mousedev = NODEV; 168 dev_t stdindev = NODEV; 169 dev_t diagdev = NODEV; 170 struct vnode *wsconsvp; 171 172 dev_t fbdev = NODEV; 173 struct vnode *fbvp; 174 dev_info_t *fbdip; 175 176 /* 177 * moved from cons.c because they must be resident in the kernel. 178 */ 179 vnode_t *rconsvp; 180 dev_t rconsdev; 181 dev_t uconsdev = NODEV; 182 183 /* 184 * serial virtual console vnode pointer. 185 */ 186 vnode_t *vsconsvp = NULL; 187 188 /* 189 * Flag whether console fb output is using PROM/PROM emulation 190 * terminal emulator, or is using the kernel terminal emulator. 191 */ 192 int consmode = CONS_FW; 193 194 /* 195 * The following allows systems to disable use of the kernel 196 * terminal emulator (retreat to PROM terminal emulator if there 197 * is PROM). 198 */ 199 int cons_tem_disable; 200 201 /* 202 * consconfig() in autoconf.c sets this; it's the vnode of the distinguished 203 * keyboard/frame buffer combination, aka the workstation console. 204 */ 205 vnode_t *rwsconsvp; 206 dev_t rwsconsdev; 207 208 /* 209 * Platform console abort policy. 210 * Platforms may override the default software policy, if such hardware 211 * (e.g. keyswitches with a secure position) exists. 212 */ 213 int abort_enable = KIOCABORTENABLE; 214 215 /* from cpc.c */ 216 uint_t kcpc_key; /* TSD key for CPU performance counter context */ 217 218 /* 219 * storing and retrieving data by string key 220 * 221 * this mechanism allows a consumer to store and retrieve by name a pointer 222 * to some space maintained by the consumer. 223 * For example, a driver or module may want to have persistent data 224 * over unloading/loading cycles. The pointer is typically to some 225 * kmem_alloced space and it should not be pointing to data that will 226 * be destroyed when the module is unloaded. 227 */ 228 static mod_hash_t *space_hash; 229 static char *space_hash_name = "space_hash"; 230 static size_t space_hash_nchains = 8; 231 232 static void 233 store_fetch_initspace() 234 { 235 space_hash = mod_hash_create_strhash(space_hash_name, 236 space_hash_nchains, mod_hash_null_valdtor); 237 ASSERT(space_hash); 238 } 239 240 int 241 space_store(char *key, uintptr_t ptr) 242 { 243 char *s; 244 int rval; 245 size_t l; 246 247 /* some sanity checks first */ 248 if (key == NULL) { 249 return (-1); 250 } 251 l = (size_t)strlen(key); 252 if (l == 0) { 253 return (-1); 254 } 255 256 /* increment for null terminator */ 257 l++; 258 259 /* alloc space for the string, mod_hash_insert will deallocate */ 260 s = kmem_alloc(l, KM_SLEEP); 261 bcopy(key, s, l); 262 263 rval = mod_hash_insert(space_hash, 264 (mod_hash_key_t)s, (mod_hash_val_t)ptr); 265 266 switch (rval) { 267 case 0: 268 break; 269 #ifdef DEBUG 270 case MH_ERR_DUPLICATE: 271 cmn_err(CE_WARN, "space_store: duplicate key %s", key); 272 rval = -1; 273 break; 274 case MH_ERR_NOMEM: 275 cmn_err(CE_WARN, "space_store: no mem for key %s", key); 276 rval = -1; 277 break; 278 default: 279 cmn_err(CE_WARN, "space_store: unspecified error for key %s", 280 key); 281 rval = -1; 282 break; 283 #else 284 default: 285 rval = -1; 286 break; 287 #endif 288 } 289 290 return (rval); 291 } 292 293 uintptr_t 294 space_fetch(char *key) 295 { 296 uintptr_t ptr = 0; 297 mod_hash_val_t val; 298 int rval; 299 300 if (key) { 301 rval = mod_hash_find(space_hash, (mod_hash_key_t)key, &val); 302 if (rval == 0) { 303 ptr = (uintptr_t)val; 304 } 305 } 306 307 return (ptr); 308 } 309 310 void 311 space_free(char *key) 312 { 313 if (key) { 314 (void) mod_hash_destroy(space_hash, (mod_hash_key_t)key); 315 } 316 } 317 318 /* 319 * Support for CRC32. At present all calculations are done in simple 320 * macros, so all we need is somewhere to declare the global lookup table. 321 */ 322 323 #include <sys/crc32.h> 324 325 const uint32_t crc32_table[256] = { CRC32_TABLE }; 326 327 /* 328 * We need to fanout load from NIC which can overwhelm a single CPU. 329 * This becomes especially important on systems having slow CPUs 330 * (sun4v architecture). mac_soft_ring_enable is false on all 331 * systems except sun4v. On sun4v, they get enabled by default (see 332 * sun4v/os/mach_startup.c). 333 */ 334 boolean_t mac_soft_ring_enable = B_FALSE; 335 336 /* 337 * Global iscsi boot prop 338 */ 339 ib_boot_prop_t *iscsiboot_prop = NULL;