10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51253Slq150181 * Common Development and Distribution License (the "License"). 61253Slq150181 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211253Slq150181 220Sstevel@tonic-gate /* 23*10064SJames.Anderson@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* 280Sstevel@tonic-gate * The intent of this file is to contain any data that must remain 290Sstevel@tonic-gate * resident in the kernel. 300Sstevel@tonic-gate * 310Sstevel@tonic-gate * space_store(), space_fetch(), and space_free() have been added to 320Sstevel@tonic-gate * easily store and retrieve kernel resident data. 330Sstevel@tonic-gate * These functions are recommended rather than adding new variables to 340Sstevel@tonic-gate * this file. 350Sstevel@tonic-gate * 360Sstevel@tonic-gate * Note that it's possible for name collisions to occur. In order to 370Sstevel@tonic-gate * prevent collisions, it's recommended that the convention in 380Sstevel@tonic-gate * PSARC/1997/389 be used. If a collision occurs, then space_store will 390Sstevel@tonic-gate * fail. 400Sstevel@tonic-gate */ 410Sstevel@tonic-gate 420Sstevel@tonic-gate #include <sys/types.h> 430Sstevel@tonic-gate #include <sys/param.h> 440Sstevel@tonic-gate #include <sys/var.h> 450Sstevel@tonic-gate #include <sys/proc.h> 460Sstevel@tonic-gate #include <sys/signal.h> 470Sstevel@tonic-gate #include <sys/utsname.h> 480Sstevel@tonic-gate #include <sys/buf.h> 490Sstevel@tonic-gate #include <sys/cred.h> 500Sstevel@tonic-gate #include <sys/vfs.h> 510Sstevel@tonic-gate #include <sys/vnode.h> 520Sstevel@tonic-gate #include <sys/sysinfo.h> 530Sstevel@tonic-gate #include <sys/t_lock.h> 540Sstevel@tonic-gate #include <sys/vmem.h> 550Sstevel@tonic-gate #include <sys/modhash.h> 560Sstevel@tonic-gate #include <sys/cmn_err.h> 570Sstevel@tonic-gate 580Sstevel@tonic-gate #include <sys/strredir.h> 590Sstevel@tonic-gate #include <sys/kbio.h> 601253Slq150181 #include <sys/consdev.h> 611253Slq150181 #include <sys/wscons.h> 628194SJack.Meng@Sun.COM #include <sys/bootprops.h> 630Sstevel@tonic-gate 640Sstevel@tonic-gate struct buf bfreelist; /* Head of the free list of buffers */ 650Sstevel@tonic-gate 660Sstevel@tonic-gate sysinfo_t sysinfo; 670Sstevel@tonic-gate vminfo_t vminfo; /* VM stats protected by sysinfolock mutex */ 680Sstevel@tonic-gate 690Sstevel@tonic-gate #ifdef lint 700Sstevel@tonic-gate int __lintzero; /* Alway zero for shutting up lint */ 710Sstevel@tonic-gate #endif 720Sstevel@tonic-gate 730Sstevel@tonic-gate /* 740Sstevel@tonic-gate * The following describe the physical memory configuration. 750Sstevel@tonic-gate * 760Sstevel@tonic-gate * physmem - The amount of physical memory configured 770Sstevel@tonic-gate * in pages. ptob(physmem) is the amount 780Sstevel@tonic-gate * of physical memory in bytes. Defined in 790Sstevel@tonic-gate * .../os/startup.c. 800Sstevel@tonic-gate * 810Sstevel@tonic-gate * physmax - The highest numbered physical page in memory. 820Sstevel@tonic-gate * 830Sstevel@tonic-gate * maxmem - Maximum available memory, in pages. Defined 840Sstevel@tonic-gate * in main.c. 850Sstevel@tonic-gate * 860Sstevel@tonic-gate * physinstalled 870Sstevel@tonic-gate * - Pages of physical memory installed; 880Sstevel@tonic-gate * includes use by PROM/boot not counted in 890Sstevel@tonic-gate * physmem. 900Sstevel@tonic-gate */ 910Sstevel@tonic-gate 920Sstevel@tonic-gate pfn_t physmax; 930Sstevel@tonic-gate pgcnt_t physinstalled; 940Sstevel@tonic-gate 950Sstevel@tonic-gate struct var v; 960Sstevel@tonic-gate 970Sstevel@tonic-gate #include <sys/systm.h> 980Sstevel@tonic-gate #include <sys/conf.h> 990Sstevel@tonic-gate #include <sys/kmem.h> 1000Sstevel@tonic-gate #include <sys/sysmacros.h> 1010Sstevel@tonic-gate #include <sys/bootconf.h> 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate /* 1040Sstevel@tonic-gate * Data from swapgeneric.c that must be resident. 1050Sstevel@tonic-gate */ 1060Sstevel@tonic-gate struct vnode *rootvp; /* vnode of the root device */ 1070Sstevel@tonic-gate dev_t rootdev; /* dev_t of the root device */ 1085648Ssetje boolean_t root_is_svm; /* root is a mirrored device flag */ 1095648Ssetje boolean_t root_is_ramdisk; /* root is ramdisk */ 1105648Ssetje uint32_t ramdisk_size; /* (KB) currently set only for sparc netboots */ 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate /* 1135648Ssetje * dhcp 1140Sstevel@tonic-gate */ 1150Sstevel@tonic-gate #include <sys/socket.h> 1160Sstevel@tonic-gate #include <sys/errno.h> 1170Sstevel@tonic-gate #include <sys/sockio.h> 1180Sstevel@tonic-gate #include <sys/stream.h> 1190Sstevel@tonic-gate #include <sys/stropts.h> 1200Sstevel@tonic-gate #include <sys/dlpi.h> 1210Sstevel@tonic-gate #include <net/if.h> 1225648Ssetje 1235648Ssetje int netboot; 1245648Ssetje int obpdebug; 1255648Ssetje char *dhcack; /* dhcp response packet */ 1265648Ssetje int dhcacklen; 1275648Ssetje char *netdev_path; /* Used to cache the netdev_path handed up by boot */ 1285648Ssetje char dhcifname[IFNAMSIZ]; 1295648Ssetje 1305648Ssetje /* 1315648Ssetje * Data from arp.c that must be resident. 1325648Ssetje */ 1330Sstevel@tonic-gate #include <net/if_arp.h> 1340Sstevel@tonic-gate #include <netinet/in.h> 1350Sstevel@tonic-gate #include <netinet/in_var.h> 1360Sstevel@tonic-gate #include <netinet/if_ether.h> 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate ether_addr_t etherbroadcastaddr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 1390Sstevel@tonic-gate 1405648Ssetje 1410Sstevel@tonic-gate /* 1420Sstevel@tonic-gate * Data from timod that must be resident 1430Sstevel@tonic-gate */ 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate /* 1460Sstevel@tonic-gate * state transition table for TI interface 1470Sstevel@tonic-gate */ 1480Sstevel@tonic-gate #include <sys/tihdr.h> 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate #define nr 127 /* not reachable */ 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate char ti_statetbl[TE_NOEVENTS][TS_NOSTATES] = { 1530Sstevel@tonic-gate /* STATES */ 1540Sstevel@tonic-gate /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 */ 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate { 1, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1570Sstevel@tonic-gate {nr, nr, nr, 2, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1580Sstevel@tonic-gate {nr, nr, nr, 4, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1590Sstevel@tonic-gate {nr, 3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1600Sstevel@tonic-gate {nr, nr, nr, nr, 3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1610Sstevel@tonic-gate {nr, 0, 3, nr, 3, 3, nr, nr, 7, nr, nr, nr, 6, 7, 9, 10, 11}, 1620Sstevel@tonic-gate {nr, nr, 0, nr, nr, 6, nr, nr, nr, nr, nr, nr, 3, nr, 3, 3, 3}, 1630Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, nr, nr, 9, nr, nr, nr, nr, 3, nr, nr, nr}, 1640Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, nr, nr, 3, nr, nr, nr, nr, 3, nr, nr, nr}, 1650Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, nr, nr, 7, nr, nr, nr, nr, 7, nr, nr, nr}, 1660Sstevel@tonic-gate {nr, nr, nr, 5, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1670Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, nr, 8, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1680Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, 12, 13, nr, 14, 15, 16, nr, nr, nr, nr, nr}, 1690Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, nr, nr, nr, 9, nr, 11, nr, nr, nr, nr, nr}, 1700Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, nr, nr, nr, 9, nr, 11, nr, nr, nr, nr, nr}, 1710Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, nr, nr, nr, 10, nr, 3, nr, nr, nr, nr, nr}, 1720Sstevel@tonic-gate {nr, nr, nr, 7, nr, nr, nr, 7, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1730Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, 9, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1740Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, nr, nr, nr, 9, 10, nr, nr, nr, nr, nr, nr}, 1750Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, nr, nr, nr, 9, 10, nr, nr, nr, nr, nr, nr}, 1760Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, nr, nr, nr, 11, 3, nr, nr, nr, nr, nr, nr}, 1770Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, 3, nr, nr, 3, 3, 3, nr, nr, nr, nr, nr}, 1780Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, nr, 3, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1790Sstevel@tonic-gate {nr, nr, nr, nr, nr, nr, nr, 7, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1800Sstevel@tonic-gate {nr, nr, nr, 9, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1810Sstevel@tonic-gate {nr, nr, nr, 3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1820Sstevel@tonic-gate {nr, nr, nr, 3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1830Sstevel@tonic-gate {nr, nr, nr, 3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr}, 1840Sstevel@tonic-gate }; 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate #include <sys/tty.h> 1880Sstevel@tonic-gate #include <sys/ptyvar.h> 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate static void store_fetch_initspace(); 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate /* 1930Sstevel@tonic-gate * Allocate tunable structures at runtime. 1940Sstevel@tonic-gate */ 1950Sstevel@tonic-gate void 1960Sstevel@tonic-gate space_init(void) 1970Sstevel@tonic-gate { 1980Sstevel@tonic-gate pty_initspace(); 1990Sstevel@tonic-gate store_fetch_initspace(); 2000Sstevel@tonic-gate } 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate int ts_dispatch_extended = -1; /* set in ts_getdptbl or set_platform_default */ 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate /* 2050Sstevel@tonic-gate * Previously defined in consmsconf.c ... 2060Sstevel@tonic-gate */ 2070Sstevel@tonic-gate dev_t kbddev = NODEV; 2080Sstevel@tonic-gate dev_t mousedev = NODEV; 2090Sstevel@tonic-gate dev_t stdindev = NODEV; 2100Sstevel@tonic-gate struct vnode *wsconsvp; 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate dev_t fbdev = NODEV; 2130Sstevel@tonic-gate struct vnode *fbvp; 2140Sstevel@tonic-gate dev_info_t *fbdip; 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate /* 2170Sstevel@tonic-gate * moved from cons.c because they must be resident in the kernel. 2180Sstevel@tonic-gate */ 2190Sstevel@tonic-gate vnode_t *rconsvp; 2200Sstevel@tonic-gate dev_t rconsdev; 2210Sstevel@tonic-gate dev_t uconsdev = NODEV; 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate /* 224*10064SJames.Anderson@Sun.COM * serial virtual console vnode pointer. 225*10064SJames.Anderson@Sun.COM */ 226*10064SJames.Anderson@Sun.COM vnode_t *vsconsvp = NULL; 227*10064SJames.Anderson@Sun.COM 228*10064SJames.Anderson@Sun.COM /* 2291253Slq150181 * Flag whether console fb output is using PROM/PROM emulation 2301253Slq150181 * terminal emulator, or is using the kernel terminal emulator. 2311253Slq150181 */ 2321253Slq150181 int consmode = CONS_FW; 2331253Slq150181 2341253Slq150181 /* 2351253Slq150181 * The following allows systems to disable use of the kernel 2361253Slq150181 * terminal emulator (retreat to PROM terminal emulator if there 2371253Slq150181 * is PROM). 2381253Slq150181 */ 2391253Slq150181 int cons_tem_disable; 2401253Slq150181 2411253Slq150181 /* 2420Sstevel@tonic-gate * consconfig() in autoconf.c sets this; it's the vnode of the distinguished 2430Sstevel@tonic-gate * keyboard/frame buffer combination, aka the workstation console. 2440Sstevel@tonic-gate */ 2450Sstevel@tonic-gate vnode_t *rwsconsvp; 2460Sstevel@tonic-gate dev_t rwsconsdev; 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate /* 2490Sstevel@tonic-gate * Platform console abort policy. 2500Sstevel@tonic-gate * Platforms may override the default software policy, if such hardware 2510Sstevel@tonic-gate * (e.g. keyswitches with a secure position) exists. 2520Sstevel@tonic-gate */ 2530Sstevel@tonic-gate int abort_enable = KIOCABORTENABLE; 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate /* from cpc.c */ 2560Sstevel@tonic-gate uint_t kcpc_key; /* TSD key for CPU performance counter context */ 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate /* 2590Sstevel@tonic-gate * storing and retrieving data by string key 2600Sstevel@tonic-gate * 2610Sstevel@tonic-gate * this mechanism allows a consumer to store and retrieve by name a pointer 2620Sstevel@tonic-gate * to some space maintained by the consumer. 2630Sstevel@tonic-gate * For example, a driver or module may want to have persistent data 2640Sstevel@tonic-gate * over unloading/loading cycles. The pointer is typically to some 2650Sstevel@tonic-gate * kmem_alloced space and it should not be pointing to data that will 2660Sstevel@tonic-gate * be destroyed when the module is unloaded. 2670Sstevel@tonic-gate */ 2680Sstevel@tonic-gate static mod_hash_t *space_hash; 2690Sstevel@tonic-gate static char *space_hash_name = "space_hash"; 2700Sstevel@tonic-gate static size_t space_hash_nchains = 8; 2710Sstevel@tonic-gate 2720Sstevel@tonic-gate static void 2730Sstevel@tonic-gate store_fetch_initspace() 2740Sstevel@tonic-gate { 2750Sstevel@tonic-gate space_hash = mod_hash_create_strhash(space_hash_name, 2765648Ssetje space_hash_nchains, mod_hash_null_valdtor); 2770Sstevel@tonic-gate ASSERT(space_hash); 2780Sstevel@tonic-gate } 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate int 2810Sstevel@tonic-gate space_store(char *key, uintptr_t ptr) 2820Sstevel@tonic-gate { 2830Sstevel@tonic-gate char *s; 2840Sstevel@tonic-gate int rval; 2850Sstevel@tonic-gate size_t l; 2860Sstevel@tonic-gate 2870Sstevel@tonic-gate /* some sanity checks first */ 2880Sstevel@tonic-gate if (key == NULL) { 2890Sstevel@tonic-gate return (-1); 2900Sstevel@tonic-gate } 2910Sstevel@tonic-gate l = (size_t)strlen(key); 2920Sstevel@tonic-gate if (l == 0) { 2930Sstevel@tonic-gate return (-1); 2940Sstevel@tonic-gate } 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate /* increment for null terminator */ 2970Sstevel@tonic-gate l++; 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate /* alloc space for the string, mod_hash_insert will deallocate */ 3000Sstevel@tonic-gate s = kmem_alloc(l, KM_SLEEP); 3010Sstevel@tonic-gate bcopy(key, s, l); 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate rval = mod_hash_insert(space_hash, 3045648Ssetje (mod_hash_key_t)s, (mod_hash_val_t)ptr); 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate switch (rval) { 3070Sstevel@tonic-gate case 0: 3080Sstevel@tonic-gate break; 3090Sstevel@tonic-gate #ifdef DEBUG 3100Sstevel@tonic-gate case MH_ERR_DUPLICATE: 3110Sstevel@tonic-gate cmn_err(CE_WARN, "space_store: duplicate key %s", key); 3120Sstevel@tonic-gate rval = -1; 3130Sstevel@tonic-gate break; 3140Sstevel@tonic-gate case MH_ERR_NOMEM: 3150Sstevel@tonic-gate cmn_err(CE_WARN, "space_store: no mem for key %s", key); 3160Sstevel@tonic-gate rval = -1; 3170Sstevel@tonic-gate break; 3180Sstevel@tonic-gate default: 3190Sstevel@tonic-gate cmn_err(CE_WARN, "space_store: unspecified error for key %s", 3200Sstevel@tonic-gate key); 3210Sstevel@tonic-gate rval = -1; 3220Sstevel@tonic-gate break; 3230Sstevel@tonic-gate #else 3240Sstevel@tonic-gate default: 3250Sstevel@tonic-gate rval = -1; 3260Sstevel@tonic-gate break; 3270Sstevel@tonic-gate #endif 3280Sstevel@tonic-gate } 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate return (rval); 3310Sstevel@tonic-gate } 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate uintptr_t 3340Sstevel@tonic-gate space_fetch(char *key) 3350Sstevel@tonic-gate { 3360Sstevel@tonic-gate uintptr_t ptr = 0; 3370Sstevel@tonic-gate mod_hash_val_t val; 3380Sstevel@tonic-gate int rval; 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate if (key) { 3410Sstevel@tonic-gate rval = mod_hash_find(space_hash, (mod_hash_key_t)key, &val); 3420Sstevel@tonic-gate if (rval == 0) { 3430Sstevel@tonic-gate ptr = (uintptr_t)val; 3440Sstevel@tonic-gate } 3450Sstevel@tonic-gate } 3460Sstevel@tonic-gate 3470Sstevel@tonic-gate return (ptr); 3480Sstevel@tonic-gate } 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate void 3510Sstevel@tonic-gate space_free(char *key) 3520Sstevel@tonic-gate { 3530Sstevel@tonic-gate if (key) { 3540Sstevel@tonic-gate (void) mod_hash_destroy(space_hash, (mod_hash_key_t)key); 3550Sstevel@tonic-gate } 3560Sstevel@tonic-gate } 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate /* 3590Sstevel@tonic-gate * Support for CRC32. At present all calculations are done in simple 3600Sstevel@tonic-gate * macros, so all we need is somewhere to declare the global lookup table. 3610Sstevel@tonic-gate */ 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate #include <sys/crc32.h> 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate const uint32_t crc32_table[256] = { CRC32_TABLE }; 3661184Skrgopi 3671184Skrgopi /* 3688275SEric Cheng * We need to fanout load from NIC which can overwhelm a single CPU. 3698275SEric Cheng * This becomes especially important on systems having slow CPUs 3708275SEric Cheng * (sun4v architecture). mac_soft_ring_enable is false on all 3718275SEric Cheng * systems except sun4v. On sun4v, they get enabled by default (see 3728275SEric Cheng * sun4v/os/mach_startup.c). 3731184Skrgopi */ 3748275SEric Cheng boolean_t mac_soft_ring_enable = B_FALSE; 3758194SJack.Meng@Sun.COM 3768194SJack.Meng@Sun.COM /* 3778194SJack.Meng@Sun.COM * Global iscsi boot prop 3788194SJack.Meng@Sun.COM */ 3798194SJack.Meng@Sun.COM ib_boot_prop_t *iscsiboot_prop = NULL; 380