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 52006Sandrei * Common Development and Distribution License (the "License"). 62006Sandrei * 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 */ 210Sstevel@tonic-gate /* 22*12826Skuriakose.kuruvilla@oracle.com * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 2412004Sjiang.liu@intel.com /* 2512004Sjiang.liu@intel.com * Copyright (c) 2010, Intel Corporation. 2612004Sjiang.liu@intel.com * All rights reserved. 2712004Sjiang.liu@intel.com */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/types.h> 303446Smrj #include <sys/sysmacros.h> 310Sstevel@tonic-gate #include <sys/disp.h> 320Sstevel@tonic-gate #include <sys/promif.h> 330Sstevel@tonic-gate #include <sys/clock.h> 340Sstevel@tonic-gate #include <sys/cpuvar.h> 350Sstevel@tonic-gate #include <sys/stack.h> 360Sstevel@tonic-gate #include <vm/as.h> 370Sstevel@tonic-gate #include <vm/hat.h> 380Sstevel@tonic-gate #include <sys/reboot.h> 390Sstevel@tonic-gate #include <sys/avintr.h> 400Sstevel@tonic-gate #include <sys/vtrace.h> 410Sstevel@tonic-gate #include <sys/proc.h> 420Sstevel@tonic-gate #include <sys/thread.h> 430Sstevel@tonic-gate #include <sys/cpupart.h> 440Sstevel@tonic-gate #include <sys/pset.h> 450Sstevel@tonic-gate #include <sys/copyops.h> 463434Sesaxe #include <sys/pg.h> 470Sstevel@tonic-gate #include <sys/disp.h> 480Sstevel@tonic-gate #include <sys/debug.h> 490Sstevel@tonic-gate #include <sys/sunddi.h> 500Sstevel@tonic-gate #include <sys/x86_archext.h> 510Sstevel@tonic-gate #include <sys/privregs.h> 520Sstevel@tonic-gate #include <sys/machsystm.h> 530Sstevel@tonic-gate #include <sys/ontrap.h> 540Sstevel@tonic-gate #include <sys/bootconf.h> 5510574SSherry.Moore@Sun.COM #include <sys/boot_console.h> 563446Smrj #include <sys/kdi_machimpl.h> 570Sstevel@tonic-gate #include <sys/archsystm.h> 580Sstevel@tonic-gate #include <sys/promif.h> 59748Sdmick #include <sys/pci_cfgspace.h> 605084Sjohnlev #ifdef __xpv 615084Sjohnlev #include <sys/hypervisor.h> 6210175SStuart.Maybee@Sun.COM #else 6310175SStuart.Maybee@Sun.COM #include <sys/xpv_support.h> 645084Sjohnlev #endif 650Sstevel@tonic-gate 660Sstevel@tonic-gate /* 670Sstevel@tonic-gate * some globals for patching the result of cpuid 680Sstevel@tonic-gate * to solve problems w/ creative cpu vendors 690Sstevel@tonic-gate */ 700Sstevel@tonic-gate 710Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_include; 720Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_exclude; 730Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_include; 740Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_exclude; 750Sstevel@tonic-gate 760Sstevel@tonic-gate /* 77783Sdmick * Dummy spl priority masks 78783Sdmick */ 793446Smrj static unsigned char dummy_cpu_pri[MAXIPL + 1] = { 80783Sdmick 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 81783Sdmick 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf 82783Sdmick }; 83783Sdmick 8410574SSherry.Moore@Sun.COM /* 8510574SSherry.Moore@Sun.COM * Set console mode 8610574SSherry.Moore@Sun.COM */ 8710574SSherry.Moore@Sun.COM static void 8810574SSherry.Moore@Sun.COM set_console_mode(uint8_t val) 8910574SSherry.Moore@Sun.COM { 9010574SSherry.Moore@Sun.COM struct bop_regs rp = {0}; 9110574SSherry.Moore@Sun.COM 9210574SSherry.Moore@Sun.COM rp.eax.byte.ah = 0x0; 9310574SSherry.Moore@Sun.COM rp.eax.byte.al = val; 9410574SSherry.Moore@Sun.COM rp.ebx.word.bx = 0x0; 9510574SSherry.Moore@Sun.COM 9610574SSherry.Moore@Sun.COM BOP_DOINT(bootops, 0x10, &rp); 9710574SSherry.Moore@Sun.COM } 9810574SSherry.Moore@Sun.COM 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* 1010Sstevel@tonic-gate * Setup routine called right before main(). Interposing this function 1020Sstevel@tonic-gate * before main() allows us to call it in a machine-independent fashion. 1030Sstevel@tonic-gate */ 1040Sstevel@tonic-gate void 1050Sstevel@tonic-gate mlsetup(struct regs *rp) 1060Sstevel@tonic-gate { 1079053Sjonathan.chew@sun.com u_longlong_t prop_value; 1080Sstevel@tonic-gate extern struct classfuncs sys_classfuncs; 1090Sstevel@tonic-gate extern disp_t cpu0_disp; 1100Sstevel@tonic-gate extern char t0stack[]; 11110574SSherry.Moore@Sun.COM extern int post_fastreboot; 11210574SSherry.Moore@Sun.COM extern int console; 11312004Sjiang.liu@intel.com extern uint64_t plat_dr_options; 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* 1180Sstevel@tonic-gate * initialize cpu_self 1190Sstevel@tonic-gate */ 1200Sstevel@tonic-gate cpu[0]->cpu_self = cpu[0]; 1210Sstevel@tonic-gate 1225084Sjohnlev #if defined(__xpv) 1235084Sjohnlev /* 1245084Sjohnlev * Point at the hypervisor's virtual cpu structure 1255084Sjohnlev */ 1265084Sjohnlev cpu[0]->cpu_m.mcpu_vcpu_info = &HYPERVISOR_shared_info->vcpu_info[0]; 1275084Sjohnlev #endif 1285084Sjohnlev 1290Sstevel@tonic-gate /* 130783Sdmick * Set up dummy cpu_pri_data values till psm spl code is 131783Sdmick * installed. This allows splx() to work on amd64. 132783Sdmick */ 133783Sdmick 134783Sdmick cpu[0]->cpu_pri_data = dummy_cpu_pri; 135783Sdmick 136783Sdmick /* 1370Sstevel@tonic-gate * check if we've got special bits to clear or set 1380Sstevel@tonic-gate * when checking cpu features 1390Sstevel@tonic-gate */ 1400Sstevel@tonic-gate 1419053Sjonathan.chew@sun.com if (bootprop_getval("cpuid_feature_ecx_include", &prop_value) != 0) 1429053Sjonathan.chew@sun.com cpuid_feature_ecx_include = 0; 1439053Sjonathan.chew@sun.com else 1449053Sjonathan.chew@sun.com cpuid_feature_ecx_include = (uint32_t)prop_value; 1459053Sjonathan.chew@sun.com 1469053Sjonathan.chew@sun.com if (bootprop_getval("cpuid_feature_ecx_exclude", &prop_value) != 0) 1479053Sjonathan.chew@sun.com cpuid_feature_ecx_exclude = 0; 1489053Sjonathan.chew@sun.com else 1499053Sjonathan.chew@sun.com cpuid_feature_ecx_exclude = (uint32_t)prop_value; 1509053Sjonathan.chew@sun.com 1519053Sjonathan.chew@sun.com if (bootprop_getval("cpuid_feature_edx_include", &prop_value) != 0) 1529053Sjonathan.chew@sun.com cpuid_feature_edx_include = 0; 1539053Sjonathan.chew@sun.com else 1549053Sjonathan.chew@sun.com cpuid_feature_edx_include = (uint32_t)prop_value; 1559053Sjonathan.chew@sun.com 1569053Sjonathan.chew@sun.com if (bootprop_getval("cpuid_feature_edx_exclude", &prop_value) != 0) 1579053Sjonathan.chew@sun.com cpuid_feature_edx_exclude = 0; 1589053Sjonathan.chew@sun.com else 1599053Sjonathan.chew@sun.com cpuid_feature_edx_exclude = (uint32_t)prop_value; 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate /* 16210698SDan.Mick@Sun.COM * Initialize idt0, gdt0, ldt0_default, ktss0 and dftss. 16310698SDan.Mick@Sun.COM */ 16410698SDan.Mick@Sun.COM init_desctbls(); 16510698SDan.Mick@Sun.COM 16610698SDan.Mick@Sun.COM /* 16710698SDan.Mick@Sun.COM * lgrp_init() and possibly cpuid_pass1() need PCI config 16810698SDan.Mick@Sun.COM * space access 16910698SDan.Mick@Sun.COM */ 17010698SDan.Mick@Sun.COM #if defined(__xpv) 17110698SDan.Mick@Sun.COM if (DOMAIN_IS_INITDOMAIN(xen_info)) 17210698SDan.Mick@Sun.COM pci_cfgspace_init(); 17310698SDan.Mick@Sun.COM #else 17410698SDan.Mick@Sun.COM pci_cfgspace_init(); 17510698SDan.Mick@Sun.COM #endif 17610698SDan.Mick@Sun.COM 17710698SDan.Mick@Sun.COM /* 1780Sstevel@tonic-gate * The first lightweight pass (pass0) through the cpuid data 1790Sstevel@tonic-gate * was done in locore before mlsetup was called. Do the next 1800Sstevel@tonic-gate * pass in C code. 1810Sstevel@tonic-gate * 182*12826Skuriakose.kuruvilla@oracle.com * The x86_featureset is initialized here based on the capabilities 1830Sstevel@tonic-gate * of the boot CPU. Note that if we choose to support CPUs that have 1840Sstevel@tonic-gate * different feature sets (at which point we would almost certainly 1850Sstevel@tonic-gate * want to set the feature bits to correspond to the feature 1860Sstevel@tonic-gate * minimum) this value may be altered. 1870Sstevel@tonic-gate */ 188*12826Skuriakose.kuruvilla@oracle.com x86_featureset = cpuid_pass1(cpu[0]); 1890Sstevel@tonic-gate 1905322Ssudheer #if !defined(__xpv) 1915322Ssudheer 19210175SStuart.Maybee@Sun.COM if (get_hwenv() == HW_XEN_HVM) 19310175SStuart.Maybee@Sun.COM xen_hvm_init(); 19410175SStuart.Maybee@Sun.COM 1955322Ssudheer /* 1965322Ssudheer * Patch the tsc_read routine with appropriate set of instructions, 1975322Ssudheer * depending on the processor family and architecure, to read the 1985322Ssudheer * time-stamp counter while ensuring no out-of-order execution. 1995322Ssudheer * Patch it while the kernel text is still writable. 2005322Ssudheer * 2015322Ssudheer * Note: tsc_read is not patched for intel processors whose family 2025322Ssudheer * is >6 and for amd whose family >f (in case they don't support rdtscp 2035322Ssudheer * instruction, unlikely). By default tsc_read will use cpuid for 2045322Ssudheer * serialization in such cases. The following code needs to be 2055322Ssudheer * revisited if intel processors of family >= f retains the 2065322Ssudheer * instruction serialization nature of mfence instruction. 2075338Ssudheer * Note: tsc_read is not patched for x86 processors which do 2085338Ssudheer * not support "mfence". By default tsc_read will use cpuid for 2095338Ssudheer * serialization in such cases. 2105741Smrj * 2115741Smrj * The Xen hypervisor does not correctly report whether rdtscp is 2125741Smrj * supported or not, so we must assume that it is not. 2135322Ssudheer */ 214*12826Skuriakose.kuruvilla@oracle.com if (get_hwenv() != HW_XEN_HVM && 215*12826Skuriakose.kuruvilla@oracle.com is_x86_feature(x86_featureset, X86FSET_TSCP)) 2165322Ssudheer patch_tsc_read(X86_HAVE_TSCP); 2175322Ssudheer else if (cpuid_getvendor(CPU) == X86_VENDOR_AMD && 218*12826Skuriakose.kuruvilla@oracle.com cpuid_getfamily(CPU) <= 0xf && 219*12826Skuriakose.kuruvilla@oracle.com is_x86_feature(x86_featureset, X86FSET_SSE2)) 2205322Ssudheer patch_tsc_read(X86_TSC_MFENCE); 2215322Ssudheer else if (cpuid_getvendor(CPU) == X86_VENDOR_Intel && 222*12826Skuriakose.kuruvilla@oracle.com cpuid_getfamily(CPU) <= 6 && 223*12826Skuriakose.kuruvilla@oracle.com is_x86_feature(x86_featureset, X86FSET_SSE2)) 2246642Ssudheer patch_tsc_read(X86_TSC_LFENCE); 2255322Ssudheer 2265322Ssudheer #endif /* !__xpv */ 2270Sstevel@tonic-gate 2285084Sjohnlev #if defined(__i386) && !defined(__xpv) 2290Sstevel@tonic-gate /* 2300Sstevel@tonic-gate * Some i386 processors do not implement the rdtsc instruction, 2315322Ssudheer * or at least they do not implement it correctly. Patch them to 2325322Ssudheer * return 0. 2330Sstevel@tonic-gate */ 234*12826Skuriakose.kuruvilla@oracle.com if (!is_x86_feature(x86_featureset, X86FSET_TSC)) 2355322Ssudheer patch_tsc_read(X86_NO_TSC); 2365084Sjohnlev #endif /* __i386 && !__xpv */ 2375084Sjohnlev 2388377SBill.Holler@Sun.COM #if defined(__amd64) && !defined(__xpv) 2398377SBill.Holler@Sun.COM patch_memops(cpuid_getvendor(CPU)); 2408377SBill.Holler@Sun.COM #endif /* __amd64 && !__xpv */ 2418377SBill.Holler@Sun.COM 2425084Sjohnlev #if !defined(__xpv) 2435084Sjohnlev /* XXPV what, if anything, should be dorked with here under xen? */ 2443446Smrj 2453446Smrj /* 2463446Smrj * While we're thinking about the TSC, let's set up %cr4 so that 2473446Smrj * userland can issue rdtsc, and initialize the TSC_AUX value 2483446Smrj * (the cpuid) for the rdtscp instruction on appropriately 2493446Smrj * capable hardware. 2503446Smrj */ 251*12826Skuriakose.kuruvilla@oracle.com if (is_x86_feature(x86_featureset, X86FSET_TSC)) 2523446Smrj setcr4(getcr4() & ~CR4_TSD); 2533446Smrj 254*12826Skuriakose.kuruvilla@oracle.com if (is_x86_feature(x86_featureset, X86FSET_TSCP)) 2553446Smrj (void) wrmsr(MSR_AMD_TSCAUX, 0); 2563446Smrj 257*12826Skuriakose.kuruvilla@oracle.com if (is_x86_feature(x86_featureset, X86FSET_DE)) 2583446Smrj setcr4(getcr4() | CR4_DE); 2595084Sjohnlev #endif /* __xpv */ 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate /* 2620Sstevel@tonic-gate * initialize t0 2630Sstevel@tonic-gate */ 2640Sstevel@tonic-gate t0.t_stk = (caddr_t)rp - MINFRAME; 2650Sstevel@tonic-gate t0.t_stkbase = t0stack; 2660Sstevel@tonic-gate t0.t_pri = maxclsyspri - 3; 2670Sstevel@tonic-gate t0.t_schedflag = TS_LOAD | TS_DONT_SWAP; 2680Sstevel@tonic-gate t0.t_procp = &p0; 2690Sstevel@tonic-gate t0.t_plockp = &p0lock.pl_lock; 2700Sstevel@tonic-gate t0.t_lwp = &lwp0; 2710Sstevel@tonic-gate t0.t_forw = &t0; 2720Sstevel@tonic-gate t0.t_back = &t0; 2730Sstevel@tonic-gate t0.t_next = &t0; 2740Sstevel@tonic-gate t0.t_prev = &t0; 2750Sstevel@tonic-gate t0.t_cpu = cpu[0]; 2760Sstevel@tonic-gate t0.t_disp_queue = &cpu0_disp; 2770Sstevel@tonic-gate t0.t_bind_cpu = PBIND_NONE; 2780Sstevel@tonic-gate t0.t_bind_pset = PS_NONE; 2796298Sakolb t0.t_bindflag = (uchar_t)default_binding_mode; 2800Sstevel@tonic-gate t0.t_cpupart = &cp_default; 2810Sstevel@tonic-gate t0.t_clfuncs = &sys_classfuncs.thread; 2820Sstevel@tonic-gate t0.t_copyops = NULL; 2830Sstevel@tonic-gate THREAD_ONPROC(&t0, CPU); 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate lwp0.lwp_thread = &t0; 2863446Smrj lwp0.lwp_regs = (void *)rp; 2870Sstevel@tonic-gate lwp0.lwp_procp = &p0; 2880Sstevel@tonic-gate t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1; 2890Sstevel@tonic-gate 2900Sstevel@tonic-gate p0.p_exec = NULL; 2910Sstevel@tonic-gate p0.p_stat = SRUN; 2920Sstevel@tonic-gate p0.p_flag = SSYS; 2930Sstevel@tonic-gate p0.p_tlist = &t0; 2940Sstevel@tonic-gate p0.p_stksize = 2*PAGESIZE; 2950Sstevel@tonic-gate p0.p_stkpageszc = 0; 2960Sstevel@tonic-gate p0.p_as = &kas; 2970Sstevel@tonic-gate p0.p_lockp = &p0lock; 2980Sstevel@tonic-gate p0.p_brkpageszc = 0; 2994426Saguzovsk p0.p_t1_lgrpid = LGRP_NONE; 3004426Saguzovsk p0.p_tr_lgrpid = LGRP_NONE; 3010Sstevel@tonic-gate sigorset(&p0.p_ignore, &ignoredefault); 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate CPU->cpu_thread = &t0; 3040Sstevel@tonic-gate bzero(&cpu0_disp, sizeof (disp_t)); 3050Sstevel@tonic-gate CPU->cpu_disp = &cpu0_disp; 3060Sstevel@tonic-gate CPU->cpu_disp->disp_cpu = CPU; 3070Sstevel@tonic-gate CPU->cpu_dispthread = &t0; 3080Sstevel@tonic-gate CPU->cpu_idle_thread = &t0; 3090Sstevel@tonic-gate CPU->cpu_flags = CPU_READY | CPU_RUNNING | CPU_EXISTS | CPU_ENABLE; 3100Sstevel@tonic-gate CPU->cpu_dispatch_pri = t0.t_pri; 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate CPU->cpu_id = 0; 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate CPU->cpu_pri = 12; /* initial PIL for the boot CPU */ 3150Sstevel@tonic-gate 3160Sstevel@tonic-gate /* 3171217Srab * The kernel doesn't use LDTs unless a process explicitly requests one. 3180Sstevel@tonic-gate */ 3195084Sjohnlev p0.p_ldt_desc = null_sdesc; 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate /* 3223446Smrj * Initialize thread/cpu microstate accounting 3230Sstevel@tonic-gate */ 3240Sstevel@tonic-gate init_mstate(&t0, LMS_SYSTEM); 3250Sstevel@tonic-gate init_cpu_mstate(CPU, CMS_SYSTEM); 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate /* 3280Sstevel@tonic-gate * Initialize lists of available and active CPUs. 3290Sstevel@tonic-gate */ 3300Sstevel@tonic-gate cpu_list_init(CPU); 3310Sstevel@tonic-gate 3328906SEric.Saxe@Sun.COM pg_cpu_bootstrap(CPU); 3338906SEric.Saxe@Sun.COM 3343446Smrj /* 3353446Smrj * Now that we have taken over the GDT, IDT and have initialized 3363446Smrj * active CPU list it's time to inform kmdb if present. 3373446Smrj */ 3383446Smrj if (boothowto & RB_DEBUG) 3393446Smrj kdi_idt_sync(); 3403446Smrj 3413446Smrj /* 34210574SSherry.Moore@Sun.COM * Explicitly set console to text mode (0x3) if this is a boot 34310574SSherry.Moore@Sun.COM * post Fast Reboot, and the console is set to CONS_SCREEN_TEXT. 34410574SSherry.Moore@Sun.COM */ 34510574SSherry.Moore@Sun.COM if (post_fastreboot && console == CONS_SCREEN_TEXT) 34610574SSherry.Moore@Sun.COM set_console_mode(0x3); 34710574SSherry.Moore@Sun.COM 34810574SSherry.Moore@Sun.COM /* 3493446Smrj * If requested (boot -d) drop into kmdb. 3503446Smrj * 3513446Smrj * This must be done after cpu_list_init() on the 64-bit kernel 3523446Smrj * since taking a trap requires that we re-compute gsbase based 3533446Smrj * on the cpu list. 3543446Smrj */ 3553446Smrj if (boothowto & RB_DEBUGENTER) 3563446Smrj kmdb_enter(); 3573446Smrj 358414Skchow cpu_vm_data_init(CPU); 359414Skchow 3600Sstevel@tonic-gate rp->r_fp = 0; /* terminate kernel stack traces! */ 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate prom_init("kernel", (void *)NULL); 3630Sstevel@tonic-gate 36412004Sjiang.liu@intel.com /* User-set option overrides firmware value. */ 36512004Sjiang.liu@intel.com if (bootprop_getval(PLAT_DR_OPTIONS_NAME, &prop_value) == 0) { 36612004Sjiang.liu@intel.com plat_dr_options = (uint64_t)prop_value; 36712004Sjiang.liu@intel.com } 36812004Sjiang.liu@intel.com #if defined(__xpv) 36912004Sjiang.liu@intel.com /* No support of DR operations on xpv */ 37012004Sjiang.liu@intel.com plat_dr_options = 0; 37112004Sjiang.liu@intel.com #else /* __xpv */ 37212004Sjiang.liu@intel.com /* Flag PLAT_DR_FEATURE_ENABLED should only be set by DR driver. */ 37312004Sjiang.liu@intel.com plat_dr_options &= ~PLAT_DR_FEATURE_ENABLED; 37412004Sjiang.liu@intel.com #ifndef __amd64 37512004Sjiang.liu@intel.com /* Only enable CPU/memory DR on 64 bits kernel. */ 37612004Sjiang.liu@intel.com plat_dr_options &= ~PLAT_DR_FEATURE_MEMORY; 37712004Sjiang.liu@intel.com plat_dr_options &= ~PLAT_DR_FEATURE_CPU; 37812004Sjiang.liu@intel.com #endif /* __amd64 */ 37912004Sjiang.liu@intel.com #endif /* __xpv */ 38012004Sjiang.liu@intel.com 38112004Sjiang.liu@intel.com /* 38212004Sjiang.liu@intel.com * Get value of "plat_dr_physmax" boot option. 38312004Sjiang.liu@intel.com * It overrides values calculated from MSCT or SRAT table. 38412004Sjiang.liu@intel.com */ 38512004Sjiang.liu@intel.com if (bootprop_getval(PLAT_DR_PHYSMAX_NAME, &prop_value) == 0) { 38612004Sjiang.liu@intel.com plat_dr_physmax = ((uint64_t)prop_value) >> PAGESHIFT; 38712004Sjiang.liu@intel.com } 38812004Sjiang.liu@intel.com 38912004Sjiang.liu@intel.com /* Get value of boot_ncpus. */ 39012004Sjiang.liu@intel.com if (bootprop_getval(BOOT_NCPUS_NAME, &prop_value) != 0) { 3913446Smrj boot_ncpus = NCPU; 39212004Sjiang.liu@intel.com } else { 3939053Sjonathan.chew@sun.com boot_ncpus = (int)prop_value; 3949053Sjonathan.chew@sun.com if (boot_ncpus <= 0 || boot_ncpus > NCPU) 3959053Sjonathan.chew@sun.com boot_ncpus = NCPU; 3969053Sjonathan.chew@sun.com } 3972006Sandrei 39812004Sjiang.liu@intel.com /* 39912004Sjiang.liu@intel.com * Set max_ncpus and boot_max_ncpus to boot_ncpus if platform doesn't 40012004Sjiang.liu@intel.com * support CPU DR operations. 40112004Sjiang.liu@intel.com */ 40212004Sjiang.liu@intel.com if (plat_dr_support_cpu() == 0) { 40312004Sjiang.liu@intel.com max_ncpus = boot_max_ncpus = boot_ncpus; 40412004Sjiang.liu@intel.com } else { 40512004Sjiang.liu@intel.com if (bootprop_getval(PLAT_MAX_NCPUS_NAME, &prop_value) != 0) { 40612004Sjiang.liu@intel.com max_ncpus = NCPU; 40712004Sjiang.liu@intel.com } else { 40812004Sjiang.liu@intel.com max_ncpus = (int)prop_value; 40912004Sjiang.liu@intel.com if (max_ncpus <= 0 || max_ncpus > NCPU) { 41012004Sjiang.liu@intel.com max_ncpus = NCPU; 41112004Sjiang.liu@intel.com } 41212004Sjiang.liu@intel.com if (boot_ncpus > max_ncpus) { 41312004Sjiang.liu@intel.com boot_ncpus = max_ncpus; 41412004Sjiang.liu@intel.com } 41512004Sjiang.liu@intel.com } 41612004Sjiang.liu@intel.com 41712004Sjiang.liu@intel.com if (bootprop_getval(BOOT_MAX_NCPUS_NAME, &prop_value) != 0) { 41812004Sjiang.liu@intel.com boot_max_ncpus = boot_ncpus; 41912004Sjiang.liu@intel.com } else { 42012004Sjiang.liu@intel.com boot_max_ncpus = (int)prop_value; 42112004Sjiang.liu@intel.com if (boot_max_ncpus <= 0 || boot_max_ncpus > NCPU) { 42212004Sjiang.liu@intel.com boot_max_ncpus = boot_ncpus; 42312004Sjiang.liu@intel.com } else if (boot_max_ncpus > max_ncpus) { 42412004Sjiang.liu@intel.com boot_max_ncpus = max_ncpus; 42512004Sjiang.liu@intel.com } 42612004Sjiang.liu@intel.com } 42712004Sjiang.liu@intel.com } 4282006Sandrei 4296445Sjjc /* 4306445Sjjc * Initialize the lgrp framework 4316445Sjjc */ 43210710Sjonathan.chew@sun.com lgrp_init(LGRP_INIT_STAGE1); 4336445Sjjc 4340Sstevel@tonic-gate if (boothowto & RB_HALT) { 4350Sstevel@tonic-gate prom_printf("unix: kernel halted by -h flag\n"); 4360Sstevel@tonic-gate prom_enter_mon(); 4370Sstevel@tonic-gate } 4380Sstevel@tonic-gate 4390Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 4400Sstevel@tonic-gate 4414581Ssherrym /* 4424581Ssherrym * Fill out cpu_ucode_info. Update microcode if necessary. 4434581Ssherrym */ 4444581Ssherrym ucode_check(CPU); 4454581Ssherrym 4460Sstevel@tonic-gate if (workaround_errata(CPU) != 0) 4470Sstevel@tonic-gate panic("critical workaround(s) missing for boot cpu"); 4480Sstevel@tonic-gate } 4495648Ssetje 4505648Ssetje 4515648Ssetje void 4525648Ssetje mach_modpath(char *path, const char *filename) 4535648Ssetje { 4545648Ssetje /* 4555648Ssetje * Construct the directory path from the filename. 4565648Ssetje */ 4575648Ssetje 4585648Ssetje int len; 4595648Ssetje char *p; 4605648Ssetje const char isastr[] = "/amd64"; 4615648Ssetje size_t isalen = strlen(isastr); 4625648Ssetje 4635648Ssetje if ((p = strrchr(filename, '/')) == NULL) 4645648Ssetje return; 4655648Ssetje 4665648Ssetje while (p > filename && *(p - 1) == '/') 4675648Ssetje p--; /* remove trailing '/' characters */ 4685648Ssetje if (p == filename) 4695648Ssetje p++; /* so "/" -is- the modpath in this case */ 4705648Ssetje 4715648Ssetje /* 4725648Ssetje * Remove optional isa-dependent directory name - the module 4735648Ssetje * subsystem will put this back again (!) 4745648Ssetje */ 4755648Ssetje len = p - filename; 4765648Ssetje if (len > isalen && 4775648Ssetje strncmp(&filename[len - isalen], isastr, isalen) == 0) 4785648Ssetje p -= isalen; 4795648Ssetje 4805648Ssetje /* 4815648Ssetje * "/platform/mumblefrotz" + " " + MOD_DEFPATH 4825648Ssetje */ 4835648Ssetje len += (p - filename) + 1 + strlen(MOD_DEFPATH) + 1; 4845648Ssetje (void) strncpy(path, filename, p - filename); 4855648Ssetje } 486