xref: /onnv-gate/usr/src/uts/i86pc/os/mlsetup.c (revision 12004:93f274d4a367)
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 /*
228906SEric.Saxe@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
25*12004Sjiang.liu@intel.com /*
26*12004Sjiang.liu@intel.com  * Copyright (c) 2010, Intel Corporation.
27*12004Sjiang.liu@intel.com  * All rights reserved.
28*12004Sjiang.liu@intel.com  */
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <sys/types.h>
313446Smrj #include <sys/sysmacros.h>
320Sstevel@tonic-gate #include <sys/disp.h>
330Sstevel@tonic-gate #include <sys/promif.h>
340Sstevel@tonic-gate #include <sys/clock.h>
350Sstevel@tonic-gate #include <sys/cpuvar.h>
360Sstevel@tonic-gate #include <sys/stack.h>
370Sstevel@tonic-gate #include <vm/as.h>
380Sstevel@tonic-gate #include <vm/hat.h>
390Sstevel@tonic-gate #include <sys/reboot.h>
400Sstevel@tonic-gate #include <sys/avintr.h>
410Sstevel@tonic-gate #include <sys/vtrace.h>
420Sstevel@tonic-gate #include <sys/proc.h>
430Sstevel@tonic-gate #include <sys/thread.h>
440Sstevel@tonic-gate #include <sys/cpupart.h>
450Sstevel@tonic-gate #include <sys/pset.h>
460Sstevel@tonic-gate #include <sys/copyops.h>
473434Sesaxe #include <sys/pg.h>
480Sstevel@tonic-gate #include <sys/disp.h>
490Sstevel@tonic-gate #include <sys/debug.h>
500Sstevel@tonic-gate #include <sys/sunddi.h>
510Sstevel@tonic-gate #include <sys/x86_archext.h>
520Sstevel@tonic-gate #include <sys/privregs.h>
530Sstevel@tonic-gate #include <sys/machsystm.h>
540Sstevel@tonic-gate #include <sys/ontrap.h>
550Sstevel@tonic-gate #include <sys/bootconf.h>
5610574SSherry.Moore@Sun.COM #include <sys/boot_console.h>
573446Smrj #include <sys/kdi_machimpl.h>
580Sstevel@tonic-gate #include <sys/archsystm.h>
590Sstevel@tonic-gate #include <sys/promif.h>
60748Sdmick #include <sys/pci_cfgspace.h>
615084Sjohnlev #ifdef __xpv
625084Sjohnlev #include <sys/hypervisor.h>
6310175SStuart.Maybee@Sun.COM #else
6410175SStuart.Maybee@Sun.COM #include <sys/xpv_support.h>
655084Sjohnlev #endif
660Sstevel@tonic-gate 
670Sstevel@tonic-gate /*
680Sstevel@tonic-gate  * some globals for patching the result of cpuid
690Sstevel@tonic-gate  * to solve problems w/ creative cpu vendors
700Sstevel@tonic-gate  */
710Sstevel@tonic-gate 
720Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_include;
730Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_exclude;
740Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_include;
750Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_exclude;
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /*
78783Sdmick  * Dummy spl priority masks
79783Sdmick  */
803446Smrj static unsigned char dummy_cpu_pri[MAXIPL + 1] = {
81783Sdmick 	0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf,
82783Sdmick 	0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf
83783Sdmick };
84783Sdmick 
8510574SSherry.Moore@Sun.COM /*
8610574SSherry.Moore@Sun.COM  * Set console mode
8710574SSherry.Moore@Sun.COM  */
8810574SSherry.Moore@Sun.COM static void
8910574SSherry.Moore@Sun.COM set_console_mode(uint8_t val)
9010574SSherry.Moore@Sun.COM {
9110574SSherry.Moore@Sun.COM 	struct bop_regs rp = {0};
9210574SSherry.Moore@Sun.COM 
9310574SSherry.Moore@Sun.COM 	rp.eax.byte.ah = 0x0;
9410574SSherry.Moore@Sun.COM 	rp.eax.byte.al = val;
9510574SSherry.Moore@Sun.COM 	rp.ebx.word.bx = 0x0;
9610574SSherry.Moore@Sun.COM 
9710574SSherry.Moore@Sun.COM 	BOP_DOINT(bootops, 0x10, &rp);
9810574SSherry.Moore@Sun.COM }
9910574SSherry.Moore@Sun.COM 
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate /*
1020Sstevel@tonic-gate  * Setup routine called right before main(). Interposing this function
1030Sstevel@tonic-gate  * before main() allows us to call it in a machine-independent fashion.
1040Sstevel@tonic-gate  */
1050Sstevel@tonic-gate void
1060Sstevel@tonic-gate mlsetup(struct regs *rp)
1070Sstevel@tonic-gate {
1089053Sjonathan.chew@sun.com 	u_longlong_t prop_value;
1090Sstevel@tonic-gate 	extern struct classfuncs sys_classfuncs;
1100Sstevel@tonic-gate 	extern disp_t cpu0_disp;
1110Sstevel@tonic-gate 	extern char t0stack[];
11210574SSherry.Moore@Sun.COM 	extern int post_fastreboot;
11310574SSherry.Moore@Sun.COM 	extern int console;
114*12004Sjiang.liu@intel.com 	extern uint64_t plat_dr_options;
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 	/*
1190Sstevel@tonic-gate 	 * initialize cpu_self
1200Sstevel@tonic-gate 	 */
1210Sstevel@tonic-gate 	cpu[0]->cpu_self = cpu[0];
1220Sstevel@tonic-gate 
1235084Sjohnlev #if defined(__xpv)
1245084Sjohnlev 	/*
1255084Sjohnlev 	 * Point at the hypervisor's virtual cpu structure
1265084Sjohnlev 	 */
1275084Sjohnlev 	cpu[0]->cpu_m.mcpu_vcpu_info = &HYPERVISOR_shared_info->vcpu_info[0];
1285084Sjohnlev #endif
1295084Sjohnlev 
1300Sstevel@tonic-gate 	/*
131783Sdmick 	 * Set up dummy cpu_pri_data values till psm spl code is
132783Sdmick 	 * installed.  This allows splx() to work on amd64.
133783Sdmick 	 */
134783Sdmick 
135783Sdmick 	cpu[0]->cpu_pri_data = dummy_cpu_pri;
136783Sdmick 
137783Sdmick 	/*
1380Sstevel@tonic-gate 	 * check if we've got special bits to clear or set
1390Sstevel@tonic-gate 	 * when checking cpu features
1400Sstevel@tonic-gate 	 */
1410Sstevel@tonic-gate 
1429053Sjonathan.chew@sun.com 	if (bootprop_getval("cpuid_feature_ecx_include", &prop_value) != 0)
1439053Sjonathan.chew@sun.com 		cpuid_feature_ecx_include = 0;
1449053Sjonathan.chew@sun.com 	else
1459053Sjonathan.chew@sun.com 		cpuid_feature_ecx_include = (uint32_t)prop_value;
1469053Sjonathan.chew@sun.com 
1479053Sjonathan.chew@sun.com 	if (bootprop_getval("cpuid_feature_ecx_exclude", &prop_value) != 0)
1489053Sjonathan.chew@sun.com 		cpuid_feature_ecx_exclude = 0;
1499053Sjonathan.chew@sun.com 	else
1509053Sjonathan.chew@sun.com 		cpuid_feature_ecx_exclude = (uint32_t)prop_value;
1519053Sjonathan.chew@sun.com 
1529053Sjonathan.chew@sun.com 	if (bootprop_getval("cpuid_feature_edx_include", &prop_value) != 0)
1539053Sjonathan.chew@sun.com 		cpuid_feature_edx_include = 0;
1549053Sjonathan.chew@sun.com 	else
1559053Sjonathan.chew@sun.com 		cpuid_feature_edx_include = (uint32_t)prop_value;
1569053Sjonathan.chew@sun.com 
1579053Sjonathan.chew@sun.com 	if (bootprop_getval("cpuid_feature_edx_exclude", &prop_value) != 0)
1589053Sjonathan.chew@sun.com 		cpuid_feature_edx_exclude = 0;
1599053Sjonathan.chew@sun.com 	else
1609053Sjonathan.chew@sun.com 		cpuid_feature_edx_exclude = (uint32_t)prop_value;
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate 	/*
16310698SDan.Mick@Sun.COM 	 * Initialize idt0, gdt0, ldt0_default, ktss0 and dftss.
16410698SDan.Mick@Sun.COM 	 */
16510698SDan.Mick@Sun.COM 	init_desctbls();
16610698SDan.Mick@Sun.COM 
16710698SDan.Mick@Sun.COM 	/*
16810698SDan.Mick@Sun.COM 	 * lgrp_init() and possibly cpuid_pass1() need PCI config
16910698SDan.Mick@Sun.COM 	 * space access
17010698SDan.Mick@Sun.COM 	 */
17110698SDan.Mick@Sun.COM #if defined(__xpv)
17210698SDan.Mick@Sun.COM 	if (DOMAIN_IS_INITDOMAIN(xen_info))
17310698SDan.Mick@Sun.COM 		pci_cfgspace_init();
17410698SDan.Mick@Sun.COM #else
17510698SDan.Mick@Sun.COM 	pci_cfgspace_init();
17610698SDan.Mick@Sun.COM #endif
17710698SDan.Mick@Sun.COM 
17810698SDan.Mick@Sun.COM 	/*
1790Sstevel@tonic-gate 	 * The first lightweight pass (pass0) through the cpuid data
1800Sstevel@tonic-gate 	 * was done in locore before mlsetup was called.  Do the next
1810Sstevel@tonic-gate 	 * pass in C code.
1820Sstevel@tonic-gate 	 *
1830Sstevel@tonic-gate 	 * The x86_feature bits are set here on the basis of the capabilities
1840Sstevel@tonic-gate 	 * of the boot CPU.  Note that if we choose to support CPUs that have
1850Sstevel@tonic-gate 	 * different feature sets (at which point we would almost certainly
1860Sstevel@tonic-gate 	 * want to set the feature bits to correspond to the feature
1870Sstevel@tonic-gate 	 * minimum) this value may be altered.
1880Sstevel@tonic-gate 	 */
1890Sstevel@tonic-gate 	x86_feature = cpuid_pass1(cpu[0]);
1900Sstevel@tonic-gate 
1915322Ssudheer #if !defined(__xpv)
1925322Ssudheer 
19310175SStuart.Maybee@Sun.COM 	if (get_hwenv() == HW_XEN_HVM)
19410175SStuart.Maybee@Sun.COM 		xen_hvm_init();
19510175SStuart.Maybee@Sun.COM 
1965322Ssudheer 	/*
1975322Ssudheer 	 * Patch the tsc_read routine with appropriate set of instructions,
1985322Ssudheer 	 * depending on the processor family and architecure, to read the
1995322Ssudheer 	 * time-stamp counter while ensuring no out-of-order execution.
2005322Ssudheer 	 * Patch it while the kernel text is still writable.
2015322Ssudheer 	 *
2025322Ssudheer 	 * Note: tsc_read is not patched for intel processors whose family
2035322Ssudheer 	 * is >6 and for amd whose family >f (in case they don't support rdtscp
2045322Ssudheer 	 * instruction, unlikely). By default tsc_read will use cpuid for
2055322Ssudheer 	 * serialization in such cases. The following code needs to be
2065322Ssudheer 	 * revisited if intel processors of family >= f retains the
2075322Ssudheer 	 * instruction serialization nature of mfence instruction.
2085338Ssudheer 	 * Note: tsc_read is not patched for x86 processors which do
2095338Ssudheer 	 * not support "mfence". By default tsc_read will use cpuid for
2105338Ssudheer 	 * serialization in such cases.
2115741Smrj 	 *
2125741Smrj 	 * The Xen hypervisor does not correctly report whether rdtscp is
2135741Smrj 	 * supported or not, so we must assume that it is not.
2145322Ssudheer 	 */
2159000SStuart.Maybee@Sun.COM 	if (get_hwenv() != HW_XEN_HVM && (x86_feature & X86_TSCP))
2165322Ssudheer 		patch_tsc_read(X86_HAVE_TSCP);
2175322Ssudheer 	else if (cpuid_getvendor(CPU) == X86_VENDOR_AMD &&
2185338Ssudheer 	    cpuid_getfamily(CPU) <= 0xf && (x86_feature & X86_SSE2) != 0)
2195322Ssudheer 		patch_tsc_read(X86_TSC_MFENCE);
2205322Ssudheer 	else if (cpuid_getvendor(CPU) == X86_VENDOR_Intel &&
2215338Ssudheer 	    cpuid_getfamily(CPU) <= 6 && (x86_feature & X86_SSE2) != 0)
2226642Ssudheer 		patch_tsc_read(X86_TSC_LFENCE);
2235322Ssudheer 
2245322Ssudheer #endif	/* !__xpv */
2250Sstevel@tonic-gate 
2265084Sjohnlev #if defined(__i386) && !defined(__xpv)
2270Sstevel@tonic-gate 	/*
2280Sstevel@tonic-gate 	 * Some i386 processors do not implement the rdtsc instruction,
2295322Ssudheer 	 * or at least they do not implement it correctly. Patch them to
2305322Ssudheer 	 * return 0.
2310Sstevel@tonic-gate 	 */
2325322Ssudheer 	if ((x86_feature & X86_TSC) == 0)
2335322Ssudheer 		patch_tsc_read(X86_NO_TSC);
2345084Sjohnlev #endif	/* __i386 && !__xpv */
2355084Sjohnlev 
2368377SBill.Holler@Sun.COM #if defined(__amd64) && !defined(__xpv)
2378377SBill.Holler@Sun.COM 	patch_memops(cpuid_getvendor(CPU));
2388377SBill.Holler@Sun.COM #endif	/* __amd64 && !__xpv */
2398377SBill.Holler@Sun.COM 
2405084Sjohnlev #if !defined(__xpv)
2415084Sjohnlev 	/* XXPV	what, if anything, should be dorked with here under xen? */
2423446Smrj 
2433446Smrj 	/*
2443446Smrj 	 * While we're thinking about the TSC, let's set up %cr4 so that
2453446Smrj 	 * userland can issue rdtsc, and initialize the TSC_AUX value
2463446Smrj 	 * (the cpuid) for the rdtscp instruction on appropriately
2473446Smrj 	 * capable hardware.
2483446Smrj 	 */
2493446Smrj 	if (x86_feature & X86_TSC)
2503446Smrj 		setcr4(getcr4() & ~CR4_TSD);
2513446Smrj 
2523446Smrj 	if (x86_feature & X86_TSCP)
2533446Smrj 		(void) wrmsr(MSR_AMD_TSCAUX, 0);
2543446Smrj 
2553446Smrj 	if (x86_feature & X86_DE)
2563446Smrj 		setcr4(getcr4() | CR4_DE);
2575084Sjohnlev #endif /* __xpv */
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate 	/*
2600Sstevel@tonic-gate 	 * initialize t0
2610Sstevel@tonic-gate 	 */
2620Sstevel@tonic-gate 	t0.t_stk = (caddr_t)rp - MINFRAME;
2630Sstevel@tonic-gate 	t0.t_stkbase = t0stack;
2640Sstevel@tonic-gate 	t0.t_pri = maxclsyspri - 3;
2650Sstevel@tonic-gate 	t0.t_schedflag = TS_LOAD | TS_DONT_SWAP;
2660Sstevel@tonic-gate 	t0.t_procp = &p0;
2670Sstevel@tonic-gate 	t0.t_plockp = &p0lock.pl_lock;
2680Sstevel@tonic-gate 	t0.t_lwp = &lwp0;
2690Sstevel@tonic-gate 	t0.t_forw = &t0;
2700Sstevel@tonic-gate 	t0.t_back = &t0;
2710Sstevel@tonic-gate 	t0.t_next = &t0;
2720Sstevel@tonic-gate 	t0.t_prev = &t0;
2730Sstevel@tonic-gate 	t0.t_cpu = cpu[0];
2740Sstevel@tonic-gate 	t0.t_disp_queue = &cpu0_disp;
2750Sstevel@tonic-gate 	t0.t_bind_cpu = PBIND_NONE;
2760Sstevel@tonic-gate 	t0.t_bind_pset = PS_NONE;
2776298Sakolb 	t0.t_bindflag = (uchar_t)default_binding_mode;
2780Sstevel@tonic-gate 	t0.t_cpupart = &cp_default;
2790Sstevel@tonic-gate 	t0.t_clfuncs = &sys_classfuncs.thread;
2800Sstevel@tonic-gate 	t0.t_copyops = NULL;
2810Sstevel@tonic-gate 	THREAD_ONPROC(&t0, CPU);
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate 	lwp0.lwp_thread = &t0;
2843446Smrj 	lwp0.lwp_regs = (void *)rp;
2850Sstevel@tonic-gate 	lwp0.lwp_procp = &p0;
2860Sstevel@tonic-gate 	t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1;
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate 	p0.p_exec = NULL;
2890Sstevel@tonic-gate 	p0.p_stat = SRUN;
2900Sstevel@tonic-gate 	p0.p_flag = SSYS;
2910Sstevel@tonic-gate 	p0.p_tlist = &t0;
2920Sstevel@tonic-gate 	p0.p_stksize = 2*PAGESIZE;
2930Sstevel@tonic-gate 	p0.p_stkpageszc = 0;
2940Sstevel@tonic-gate 	p0.p_as = &kas;
2950Sstevel@tonic-gate 	p0.p_lockp = &p0lock;
2960Sstevel@tonic-gate 	p0.p_brkpageszc = 0;
2974426Saguzovsk 	p0.p_t1_lgrpid = LGRP_NONE;
2984426Saguzovsk 	p0.p_tr_lgrpid = LGRP_NONE;
2990Sstevel@tonic-gate 	sigorset(&p0.p_ignore, &ignoredefault);
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 	CPU->cpu_thread = &t0;
3020Sstevel@tonic-gate 	bzero(&cpu0_disp, sizeof (disp_t));
3030Sstevel@tonic-gate 	CPU->cpu_disp = &cpu0_disp;
3040Sstevel@tonic-gate 	CPU->cpu_disp->disp_cpu = CPU;
3050Sstevel@tonic-gate 	CPU->cpu_dispthread = &t0;
3060Sstevel@tonic-gate 	CPU->cpu_idle_thread = &t0;
3070Sstevel@tonic-gate 	CPU->cpu_flags = CPU_READY | CPU_RUNNING | CPU_EXISTS | CPU_ENABLE;
3080Sstevel@tonic-gate 	CPU->cpu_dispatch_pri = t0.t_pri;
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate 	CPU->cpu_id = 0;
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate 	CPU->cpu_pri = 12;		/* initial PIL for the boot CPU */
3130Sstevel@tonic-gate 
3140Sstevel@tonic-gate 	/*
3151217Srab 	 * The kernel doesn't use LDTs unless a process explicitly requests one.
3160Sstevel@tonic-gate 	 */
3175084Sjohnlev 	p0.p_ldt_desc = null_sdesc;
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate 	/*
3203446Smrj 	 * Initialize thread/cpu microstate accounting
3210Sstevel@tonic-gate 	 */
3220Sstevel@tonic-gate 	init_mstate(&t0, LMS_SYSTEM);
3230Sstevel@tonic-gate 	init_cpu_mstate(CPU, CMS_SYSTEM);
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate 	/*
3260Sstevel@tonic-gate 	 * Initialize lists of available and active CPUs.
3270Sstevel@tonic-gate 	 */
3280Sstevel@tonic-gate 	cpu_list_init(CPU);
3290Sstevel@tonic-gate 
3308906SEric.Saxe@Sun.COM 	pg_cpu_bootstrap(CPU);
3318906SEric.Saxe@Sun.COM 
3323446Smrj 	/*
3333446Smrj 	 * Now that we have taken over the GDT, IDT and have initialized
3343446Smrj 	 * active CPU list it's time to inform kmdb if present.
3353446Smrj 	 */
3363446Smrj 	if (boothowto & RB_DEBUG)
3373446Smrj 		kdi_idt_sync();
3383446Smrj 
3393446Smrj 	/*
34010574SSherry.Moore@Sun.COM 	 * Explicitly set console to text mode (0x3) if this is a boot
34110574SSherry.Moore@Sun.COM 	 * post Fast Reboot, and the console is set to CONS_SCREEN_TEXT.
34210574SSherry.Moore@Sun.COM 	 */
34310574SSherry.Moore@Sun.COM 	if (post_fastreboot && console == CONS_SCREEN_TEXT)
34410574SSherry.Moore@Sun.COM 		set_console_mode(0x3);
34510574SSherry.Moore@Sun.COM 
34610574SSherry.Moore@Sun.COM 	/*
3473446Smrj 	 * If requested (boot -d) drop into kmdb.
3483446Smrj 	 *
3493446Smrj 	 * This must be done after cpu_list_init() on the 64-bit kernel
3503446Smrj 	 * since taking a trap requires that we re-compute gsbase based
3513446Smrj 	 * on the cpu list.
3523446Smrj 	 */
3533446Smrj 	if (boothowto & RB_DEBUGENTER)
3543446Smrj 		kmdb_enter();
3553446Smrj 
356414Skchow 	cpu_vm_data_init(CPU);
357414Skchow 
3580Sstevel@tonic-gate 	rp->r_fp = 0;	/* terminate kernel stack traces! */
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 	prom_init("kernel", (void *)NULL);
3610Sstevel@tonic-gate 
362*12004Sjiang.liu@intel.com 	/* User-set option overrides firmware value. */
363*12004Sjiang.liu@intel.com 	if (bootprop_getval(PLAT_DR_OPTIONS_NAME, &prop_value) == 0) {
364*12004Sjiang.liu@intel.com 		plat_dr_options = (uint64_t)prop_value;
365*12004Sjiang.liu@intel.com 	}
366*12004Sjiang.liu@intel.com #if defined(__xpv)
367*12004Sjiang.liu@intel.com 	/* No support of DR operations on xpv */
368*12004Sjiang.liu@intel.com 	plat_dr_options = 0;
369*12004Sjiang.liu@intel.com #else	/* __xpv */
370*12004Sjiang.liu@intel.com 	/* Flag PLAT_DR_FEATURE_ENABLED should only be set by DR driver. */
371*12004Sjiang.liu@intel.com 	plat_dr_options &= ~PLAT_DR_FEATURE_ENABLED;
372*12004Sjiang.liu@intel.com #ifndef	__amd64
373*12004Sjiang.liu@intel.com 	/* Only enable CPU/memory DR on 64 bits kernel. */
374*12004Sjiang.liu@intel.com 	plat_dr_options &= ~PLAT_DR_FEATURE_MEMORY;
375*12004Sjiang.liu@intel.com 	plat_dr_options &= ~PLAT_DR_FEATURE_CPU;
376*12004Sjiang.liu@intel.com #endif	/* __amd64 */
377*12004Sjiang.liu@intel.com #endif	/* __xpv */
378*12004Sjiang.liu@intel.com 
379*12004Sjiang.liu@intel.com 	/*
380*12004Sjiang.liu@intel.com 	 * Get value of "plat_dr_physmax" boot option.
381*12004Sjiang.liu@intel.com 	 * It overrides values calculated from MSCT or SRAT table.
382*12004Sjiang.liu@intel.com 	 */
383*12004Sjiang.liu@intel.com 	if (bootprop_getval(PLAT_DR_PHYSMAX_NAME, &prop_value) == 0) {
384*12004Sjiang.liu@intel.com 		plat_dr_physmax = ((uint64_t)prop_value) >> PAGESHIFT;
385*12004Sjiang.liu@intel.com 	}
386*12004Sjiang.liu@intel.com 
387*12004Sjiang.liu@intel.com 	/* Get value of boot_ncpus. */
388*12004Sjiang.liu@intel.com 	if (bootprop_getval(BOOT_NCPUS_NAME, &prop_value) != 0) {
3893446Smrj 		boot_ncpus = NCPU;
390*12004Sjiang.liu@intel.com 	} else {
3919053Sjonathan.chew@sun.com 		boot_ncpus = (int)prop_value;
3929053Sjonathan.chew@sun.com 		if (boot_ncpus <= 0 || boot_ncpus > NCPU)
3939053Sjonathan.chew@sun.com 			boot_ncpus = NCPU;
3949053Sjonathan.chew@sun.com 	}
3952006Sandrei 
396*12004Sjiang.liu@intel.com 	/*
397*12004Sjiang.liu@intel.com 	 * Set max_ncpus and boot_max_ncpus to boot_ncpus if platform doesn't
398*12004Sjiang.liu@intel.com 	 * support CPU DR operations.
399*12004Sjiang.liu@intel.com 	 */
400*12004Sjiang.liu@intel.com 	if (plat_dr_support_cpu() == 0) {
401*12004Sjiang.liu@intel.com 		max_ncpus = boot_max_ncpus = boot_ncpus;
402*12004Sjiang.liu@intel.com 	} else {
403*12004Sjiang.liu@intel.com 		if (bootprop_getval(PLAT_MAX_NCPUS_NAME, &prop_value) != 0) {
404*12004Sjiang.liu@intel.com 			max_ncpus = NCPU;
405*12004Sjiang.liu@intel.com 		} else {
406*12004Sjiang.liu@intel.com 			max_ncpus = (int)prop_value;
407*12004Sjiang.liu@intel.com 			if (max_ncpus <= 0 || max_ncpus > NCPU) {
408*12004Sjiang.liu@intel.com 				max_ncpus = NCPU;
409*12004Sjiang.liu@intel.com 			}
410*12004Sjiang.liu@intel.com 			if (boot_ncpus > max_ncpus) {
411*12004Sjiang.liu@intel.com 				boot_ncpus = max_ncpus;
412*12004Sjiang.liu@intel.com 			}
413*12004Sjiang.liu@intel.com 		}
414*12004Sjiang.liu@intel.com 
415*12004Sjiang.liu@intel.com 		if (bootprop_getval(BOOT_MAX_NCPUS_NAME, &prop_value) != 0) {
416*12004Sjiang.liu@intel.com 			boot_max_ncpus = boot_ncpus;
417*12004Sjiang.liu@intel.com 		} else {
418*12004Sjiang.liu@intel.com 			boot_max_ncpus = (int)prop_value;
419*12004Sjiang.liu@intel.com 			if (boot_max_ncpus <= 0 || boot_max_ncpus > NCPU) {
420*12004Sjiang.liu@intel.com 				boot_max_ncpus = boot_ncpus;
421*12004Sjiang.liu@intel.com 			} else if (boot_max_ncpus > max_ncpus) {
422*12004Sjiang.liu@intel.com 				boot_max_ncpus = max_ncpus;
423*12004Sjiang.liu@intel.com 			}
424*12004Sjiang.liu@intel.com 		}
425*12004Sjiang.liu@intel.com 	}
4262006Sandrei 
4276445Sjjc 	/*
4286445Sjjc 	 * Initialize the lgrp framework
4296445Sjjc 	 */
43010710Sjonathan.chew@sun.com 	lgrp_init(LGRP_INIT_STAGE1);
4316445Sjjc 
4320Sstevel@tonic-gate 	if (boothowto & RB_HALT) {
4330Sstevel@tonic-gate 		prom_printf("unix: kernel halted by -h flag\n");
4340Sstevel@tonic-gate 		prom_enter_mon();
4350Sstevel@tonic-gate 	}
4360Sstevel@tonic-gate 
4370Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
4380Sstevel@tonic-gate 
4394581Ssherrym 	/*
4404581Ssherrym 	 * Fill out cpu_ucode_info.  Update microcode if necessary.
4414581Ssherrym 	 */
4424581Ssherrym 	ucode_check(CPU);
4434581Ssherrym 
4440Sstevel@tonic-gate 	if (workaround_errata(CPU) != 0)
4450Sstevel@tonic-gate 		panic("critical workaround(s) missing for boot cpu");
4460Sstevel@tonic-gate }
4475648Ssetje 
4485648Ssetje 
4495648Ssetje void
4505648Ssetje mach_modpath(char *path, const char *filename)
4515648Ssetje {
4525648Ssetje 	/*
4535648Ssetje 	 * Construct the directory path from the filename.
4545648Ssetje 	 */
4555648Ssetje 
4565648Ssetje 	int len;
4575648Ssetje 	char *p;
4585648Ssetje 	const char isastr[] = "/amd64";
4595648Ssetje 	size_t isalen = strlen(isastr);
4605648Ssetje 
4615648Ssetje 	if ((p = strrchr(filename, '/')) == NULL)
4625648Ssetje 		return;
4635648Ssetje 
4645648Ssetje 	while (p > filename && *(p - 1) == '/')
4655648Ssetje 		p--;	/* remove trailing '/' characters */
4665648Ssetje 	if (p == filename)
4675648Ssetje 		p++;	/* so "/" -is- the modpath in this case */
4685648Ssetje 
4695648Ssetje 	/*
4705648Ssetje 	 * Remove optional isa-dependent directory name - the module
4715648Ssetje 	 * subsystem will put this back again (!)
4725648Ssetje 	 */
4735648Ssetje 	len = p - filename;
4745648Ssetje 	if (len > isalen &&
4755648Ssetje 	    strncmp(&filename[len - isalen], isastr, isalen) == 0)
4765648Ssetje 		p -= isalen;
4775648Ssetje 
4785648Ssetje 	/*
4795648Ssetje 	 * "/platform/mumblefrotz" + " " + MOD_DEFPATH
4805648Ssetje 	 */
4815648Ssetje 	len += (p - filename) + 1 + strlen(MOD_DEFPATH) + 1;
4825648Ssetje 	(void) strncpy(path, filename, p - filename);
4835648Ssetje }
484