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 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/types.h> 300Sstevel@tonic-gate #include <sys/thread.h> 310Sstevel@tonic-gate #include <sys/cpuvar.h> 320Sstevel@tonic-gate #include <sys/t_lock.h> 330Sstevel@tonic-gate #include <sys/param.h> 340Sstevel@tonic-gate #include <sys/proc.h> 350Sstevel@tonic-gate #include <sys/disp.h> 360Sstevel@tonic-gate #include <sys/mmu.h> 370Sstevel@tonic-gate #include <sys/class.h> 380Sstevel@tonic-gate #include <sys/cmn_err.h> 390Sstevel@tonic-gate #include <sys/debug.h> 400Sstevel@tonic-gate #include <sys/asm_linkage.h> 410Sstevel@tonic-gate #include <sys/x_call.h> 420Sstevel@tonic-gate #include <sys/systm.h> 430Sstevel@tonic-gate #include <sys/var.h> 440Sstevel@tonic-gate #include <sys/vtrace.h> 450Sstevel@tonic-gate #include <vm/hat.h> 460Sstevel@tonic-gate #include <sys/mmu.h> 470Sstevel@tonic-gate #include <vm/as.h> 480Sstevel@tonic-gate #include <vm/seg_kmem.h> 490Sstevel@tonic-gate #include <sys/segments.h> 500Sstevel@tonic-gate #include <sys/kmem.h> 510Sstevel@tonic-gate #include <sys/stack.h> 520Sstevel@tonic-gate #include <sys/smp_impldefs.h> 530Sstevel@tonic-gate #include <sys/x86_archext.h> 540Sstevel@tonic-gate #include <sys/machsystm.h> 550Sstevel@tonic-gate #include <sys/traptrace.h> 560Sstevel@tonic-gate #include <sys/clock.h> 570Sstevel@tonic-gate #include <sys/cpc_impl.h> 580Sstevel@tonic-gate #include <sys/chip.h> 590Sstevel@tonic-gate #include <sys/dtrace.h> 600Sstevel@tonic-gate #include <sys/archsystm.h> 610Sstevel@tonic-gate #include <sys/fp.h> 620Sstevel@tonic-gate #include <sys/reboot.h> 630Sstevel@tonic-gate #include <sys/kdi.h> 640Sstevel@tonic-gate #include <vm/hat_i86.h> 650Sstevel@tonic-gate #include <sys/memnode.h> 660Sstevel@tonic-gate 670Sstevel@tonic-gate struct cpu cpus[1]; /* CPU data */ 680Sstevel@tonic-gate struct cpu *cpu[NCPU] = {&cpus[0]}; /* pointers to all CPUs */ 690Sstevel@tonic-gate cpu_core_t cpu_core[NCPU]; /* cpu_core structures */ 700Sstevel@tonic-gate 710Sstevel@tonic-gate /* 720Sstevel@tonic-gate * Useful for disabling MP bring-up for an MP capable kernel 730Sstevel@tonic-gate * (a kernel that was built with MP defined) 740Sstevel@tonic-gate */ 750Sstevel@tonic-gate int use_mp = 1; 760Sstevel@tonic-gate 770Sstevel@tonic-gate int mp_cpus = 0x1; /* to be set by platform specific module */ 780Sstevel@tonic-gate 790Sstevel@tonic-gate /* 800Sstevel@tonic-gate * This variable is used by the hat layer to decide whether or not 810Sstevel@tonic-gate * critical sections are needed to prevent race conditions. For sun4m, 820Sstevel@tonic-gate * this variable is set once enough MP initialization has been done in 830Sstevel@tonic-gate * order to allow cross calls. 840Sstevel@tonic-gate */ 850Sstevel@tonic-gate int flushes_require_xcalls = 0; 860Sstevel@tonic-gate ulong_t cpu_ready_set = 1; 870Sstevel@tonic-gate 880Sstevel@tonic-gate extern void real_mode_start(void); 890Sstevel@tonic-gate extern void real_mode_end(void); 900Sstevel@tonic-gate static void mp_startup(void); 910Sstevel@tonic-gate 920Sstevel@tonic-gate static void cpu_sep_enable(void); 930Sstevel@tonic-gate static void cpu_sep_disable(void); 940Sstevel@tonic-gate static void cpu_asysc_enable(void); 950Sstevel@tonic-gate static void cpu_asysc_disable(void); 960Sstevel@tonic-gate 970Sstevel@tonic-gate extern int tsc_gethrtime_enable; 980Sstevel@tonic-gate 990Sstevel@tonic-gate /* 1000Sstevel@tonic-gate * Init CPU info - get CPU type info for processor_info system call. 1010Sstevel@tonic-gate */ 1020Sstevel@tonic-gate void 1030Sstevel@tonic-gate init_cpu_info(struct cpu *cp) 1040Sstevel@tonic-gate { 1050Sstevel@tonic-gate processor_info_t *pi = &cp->cpu_type_info; 1060Sstevel@tonic-gate char buf[CPU_IDSTRLEN]; 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate /* 1090Sstevel@tonic-gate * Get clock-frequency property for the CPU. 1100Sstevel@tonic-gate */ 1110Sstevel@tonic-gate pi->pi_clock = cpu_freq; 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate (void) strcpy(pi->pi_processor_type, "i386"); 1140Sstevel@tonic-gate if (fpu_exists) 1150Sstevel@tonic-gate (void) strcpy(pi->pi_fputypes, "i387 compatible"); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate (void) cpuid_getidstr(cp, buf, sizeof (buf)); 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP); 1200Sstevel@tonic-gate (void) strcpy(cp->cpu_idstr, buf); 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate cmn_err(CE_CONT, "?cpu%d: %s\n", cp->cpu_id, cp->cpu_idstr); 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate (void) cpuid_getbrandstr(cp, buf, sizeof (buf)); 1250Sstevel@tonic-gate cp->cpu_brandstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP); 1260Sstevel@tonic-gate (void) strcpy(cp->cpu_brandstr, buf); 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate cmn_err(CE_CONT, "?cpu%d: %s\n", cp->cpu_id, cp->cpu_brandstr); 1290Sstevel@tonic-gate } 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate /* 1320Sstevel@tonic-gate * Configure syscall support on this CPU. 1330Sstevel@tonic-gate */ 1340Sstevel@tonic-gate /*ARGSUSED*/ 1350Sstevel@tonic-gate static void 1360Sstevel@tonic-gate init_cpu_syscall(struct cpu *cp) 1370Sstevel@tonic-gate { 1380Sstevel@tonic-gate kpreempt_disable(); 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate #if defined(__amd64) 1410Sstevel@tonic-gate if (x86_feature & X86_ASYSC) { 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate #if !defined(__lint) 1440Sstevel@tonic-gate /* 1450Sstevel@tonic-gate * The syscall instruction imposes a certain ordering on 1460Sstevel@tonic-gate * segment selectors, so we double-check that ordering 1470Sstevel@tonic-gate * here. 1480Sstevel@tonic-gate */ 1490Sstevel@tonic-gate ASSERT(KDS_SEL == KCS_SEL + 8); 1500Sstevel@tonic-gate ASSERT(UDS_SEL == U32CS_SEL + 8); 1510Sstevel@tonic-gate ASSERT(UCS_SEL == U32CS_SEL + 16); 1520Sstevel@tonic-gate #endif 1530Sstevel@tonic-gate /* 1540Sstevel@tonic-gate * Turn syscall/sysret extensions on. 1550Sstevel@tonic-gate */ 1560Sstevel@tonic-gate cpu_asysc_enable(); 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate /* 1590Sstevel@tonic-gate * Program the magic registers .. 1600Sstevel@tonic-gate */ 161*770Skucharsk wrmsr(MSR_AMD_STAR, ((uint64_t)(U32CS_SEL << 16 | KCS_SEL)) << 162*770Skucharsk 32); 163*770Skucharsk wrmsr(MSR_AMD_LSTAR, (uint64_t)(uintptr_t)sys_syscall); 164*770Skucharsk wrmsr(MSR_AMD_CSTAR, (uint64_t)(uintptr_t)sys_syscall32); 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate /* 1670Sstevel@tonic-gate * This list of flags is masked off the incoming 1680Sstevel@tonic-gate * %rfl when we enter the kernel. 1690Sstevel@tonic-gate */ 170*770Skucharsk wrmsr(MSR_AMD_SFMASK, (uint64_t)(uintptr_t)(PS_IE | PS_T)); 1710Sstevel@tonic-gate } 1720Sstevel@tonic-gate #endif 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate /* 1750Sstevel@tonic-gate * On 32-bit kernels, we use sysenter/sysexit because it's too 1760Sstevel@tonic-gate * hard to use syscall/sysret, and it is more portable anyway. 1770Sstevel@tonic-gate * 1780Sstevel@tonic-gate * On 64-bit kernels on Nocona machines, the 32-bit syscall 1790Sstevel@tonic-gate * variant isn't available to 32-bit applications, but sysenter is. 1800Sstevel@tonic-gate */ 1810Sstevel@tonic-gate if (x86_feature & X86_SEP) { 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate #if !defined(__lint) 1840Sstevel@tonic-gate /* 1850Sstevel@tonic-gate * The sysenter instruction imposes a certain ordering on 1860Sstevel@tonic-gate * segment selectors, so we double-check that ordering 1870Sstevel@tonic-gate * here. See "sysenter" in Intel document 245471-012, "IA-32 1880Sstevel@tonic-gate * Intel Architecture Software Developer's Manual Volume 2: 1890Sstevel@tonic-gate * Instruction Set Reference" 1900Sstevel@tonic-gate */ 1910Sstevel@tonic-gate ASSERT(KDS_SEL == KCS_SEL + 8); 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate ASSERT32(UCS_SEL == ((KCS_SEL + 16) | 3)); 1940Sstevel@tonic-gate ASSERT32(UDS_SEL == UCS_SEL + 8); 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate ASSERT64(U32CS_SEL == ((KCS_SEL + 16) | 3)); 1970Sstevel@tonic-gate ASSERT64(UDS_SEL == U32CS_SEL + 8); 1980Sstevel@tonic-gate #endif 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate cpu_sep_enable(); 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate /* 2030Sstevel@tonic-gate * resume() sets this value to the base of the threads stack 2040Sstevel@tonic-gate * via a context handler. 2050Sstevel@tonic-gate */ 206*770Skucharsk wrmsr(MSR_INTC_SEP_ESP, 0ULL); 207*770Skucharsk wrmsr(MSR_INTC_SEP_EIP, (uint64_t)(uintptr_t)sys_sysenter); 2080Sstevel@tonic-gate } 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate kpreempt_enable(); 2110Sstevel@tonic-gate } 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate /* 2140Sstevel@tonic-gate * Multiprocessor initialization. 2150Sstevel@tonic-gate * 2160Sstevel@tonic-gate * Allocate and initialize the cpu structure, TRAPTRACE buffer, and the 2170Sstevel@tonic-gate * startup and idle threads for the specified CPU. 2180Sstevel@tonic-gate */ 2190Sstevel@tonic-gate static void 2200Sstevel@tonic-gate mp_startup_init(int cpun) 2210Sstevel@tonic-gate { 2220Sstevel@tonic-gate #if defined(__amd64) 2230Sstevel@tonic-gate extern void *long_mode_64(void); 2240Sstevel@tonic-gate #endif /* __amd64 */ 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate struct cpu *cp; 2270Sstevel@tonic-gate struct tss *ntss; 2280Sstevel@tonic-gate kthread_id_t tp; 2290Sstevel@tonic-gate caddr_t sp; 2300Sstevel@tonic-gate int size; 2310Sstevel@tonic-gate proc_t *procp; 2320Sstevel@tonic-gate extern void idle(); 2330Sstevel@tonic-gate extern void init_intr_threads(struct cpu *); 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate struct cpu_tables *tablesp; 2360Sstevel@tonic-gate rm_platter_t *real_mode_platter = (rm_platter_t *)rm_platter_va; 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate #ifdef TRAPTRACE 2390Sstevel@tonic-gate trap_trace_ctl_t *ttc = &trap_trace_ctl[cpun]; 2400Sstevel@tonic-gate #endif 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate ASSERT(cpun < NCPU && cpu[cpun] == NULL); 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate if ((cp = kmem_zalloc(sizeof (*cp), KM_NOSLEEP)) == NULL) { 2450Sstevel@tonic-gate panic("mp_startup_init: cpu%d: " 2460Sstevel@tonic-gate "no memory for cpu structure", cpun); 2470Sstevel@tonic-gate /*NOTREACHED*/ 2480Sstevel@tonic-gate } 2490Sstevel@tonic-gate procp = curthread->t_procp; 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate mutex_enter(&cpu_lock); 2520Sstevel@tonic-gate /* 2530Sstevel@tonic-gate * Initialize the dispatcher first. 2540Sstevel@tonic-gate */ 2550Sstevel@tonic-gate disp_cpu_init(cp); 2560Sstevel@tonic-gate mutex_exit(&cpu_lock); 2570Sstevel@tonic-gate 258414Skchow cpu_vm_data_init(cp); 259414Skchow 2600Sstevel@tonic-gate /* 2610Sstevel@tonic-gate * Allocate and initialize the startup thread for this CPU. 2620Sstevel@tonic-gate * Interrupt and process switch stacks get allocated later 2630Sstevel@tonic-gate * when the CPU starts running. 2640Sstevel@tonic-gate */ 2650Sstevel@tonic-gate tp = thread_create(NULL, 0, NULL, NULL, 0, procp, 2660Sstevel@tonic-gate TS_STOPPED, maxclsyspri); 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate /* 2690Sstevel@tonic-gate * Set state to TS_ONPROC since this thread will start running 2700Sstevel@tonic-gate * as soon as the CPU comes online. 2710Sstevel@tonic-gate * 2720Sstevel@tonic-gate * All the other fields of the thread structure are setup by 2730Sstevel@tonic-gate * thread_create(). 2740Sstevel@tonic-gate */ 2750Sstevel@tonic-gate THREAD_ONPROC(tp, cp); 2760Sstevel@tonic-gate tp->t_preempt = 1; 2770Sstevel@tonic-gate tp->t_bound_cpu = cp; 2780Sstevel@tonic-gate tp->t_affinitycnt = 1; 2790Sstevel@tonic-gate tp->t_cpu = cp; 2800Sstevel@tonic-gate tp->t_disp_queue = cp->cpu_disp; 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate /* 2830Sstevel@tonic-gate * Setup thread to start in mp_startup. 2840Sstevel@tonic-gate */ 2850Sstevel@tonic-gate sp = tp->t_stk; 2860Sstevel@tonic-gate tp->t_pc = (uintptr_t)mp_startup; 2870Sstevel@tonic-gate tp->t_sp = (uintptr_t)(sp - MINFRAME); 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate cp->cpu_id = cpun; 2900Sstevel@tonic-gate cp->cpu_self = cp; 2910Sstevel@tonic-gate cp->cpu_mask = 1 << cpun; 2920Sstevel@tonic-gate cp->cpu_thread = tp; 2930Sstevel@tonic-gate cp->cpu_lwp = NULL; 2940Sstevel@tonic-gate cp->cpu_dispthread = tp; 2950Sstevel@tonic-gate cp->cpu_dispatch_pri = DISP_PRIO(tp); 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate /* 2980Sstevel@tonic-gate * Now, initialize per-CPU idle thread for this CPU. 2990Sstevel@tonic-gate */ 3000Sstevel@tonic-gate tp = thread_create(NULL, PAGESIZE, idle, NULL, 0, procp, TS_ONPROC, -1); 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate cp->cpu_idle_thread = tp; 3030Sstevel@tonic-gate 3040Sstevel@tonic-gate tp->t_preempt = 1; 3050Sstevel@tonic-gate tp->t_bound_cpu = cp; 3060Sstevel@tonic-gate tp->t_affinitycnt = 1; 3070Sstevel@tonic-gate tp->t_cpu = cp; 3080Sstevel@tonic-gate tp->t_disp_queue = cp->cpu_disp; 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate /* 31160Sesaxe * Bootstrap the CPU for CMT aware scheduling 31260Sesaxe * The rest of the initialization will happen from 31360Sesaxe * mp_startup() 31460Sesaxe */ 31560Sesaxe chip_bootstrap_cpu(cp); 31660Sesaxe 31760Sesaxe /* 3180Sstevel@tonic-gate * Perform CPC intialization on the new CPU. 3190Sstevel@tonic-gate */ 3200Sstevel@tonic-gate kcpc_hw_init(cp); 3210Sstevel@tonic-gate 3220Sstevel@tonic-gate /* 3230Sstevel@tonic-gate * Allocate virtual addresses for cpu_caddr1 and cpu_caddr2 3240Sstevel@tonic-gate * for each CPU. 3250Sstevel@tonic-gate */ 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate setup_vaddr_for_ppcopy(cp); 3280Sstevel@tonic-gate 3290Sstevel@tonic-gate /* 3300Sstevel@tonic-gate * Allocate space for page directory, stack, tss, gdt and idt. 3310Sstevel@tonic-gate * This assumes that kmem_alloc will return memory which is aligned 3320Sstevel@tonic-gate * to the next higher power of 2 or a page(if size > MAXABIG) 3330Sstevel@tonic-gate * If this assumption goes wrong at any time due to change in 3340Sstevel@tonic-gate * kmem alloc, things may not work as the page directory has to be 3350Sstevel@tonic-gate * page aligned 3360Sstevel@tonic-gate */ 3370Sstevel@tonic-gate if ((tablesp = kmem_zalloc(sizeof (*tablesp), KM_NOSLEEP)) == NULL) 3380Sstevel@tonic-gate panic("mp_startup_init: cpu%d cannot allocate tables", cpun); 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate if ((uintptr_t)tablesp & ~MMU_STD_PAGEMASK) { 3410Sstevel@tonic-gate kmem_free(tablesp, sizeof (struct cpu_tables)); 3420Sstevel@tonic-gate size = sizeof (struct cpu_tables) + MMU_STD_PAGESIZE; 3430Sstevel@tonic-gate tablesp = kmem_zalloc(size, KM_NOSLEEP); 3440Sstevel@tonic-gate tablesp = (struct cpu_tables *) 3450Sstevel@tonic-gate (((uintptr_t)tablesp + MMU_STD_PAGESIZE) & 3460Sstevel@tonic-gate MMU_STD_PAGEMASK); 3470Sstevel@tonic-gate } 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate ntss = cp->cpu_tss = &tablesp->ct_tss; 3500Sstevel@tonic-gate cp->cpu_gdt = tablesp->ct_gdt; 3510Sstevel@tonic-gate bcopy(CPU->cpu_gdt, cp->cpu_gdt, NGDT * (sizeof (user_desc_t))); 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate #if defined(__amd64) 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate /* 3560Sstevel@tonic-gate * #DF (double fault). 3570Sstevel@tonic-gate */ 3580Sstevel@tonic-gate ntss->tss_ist1 = 3590Sstevel@tonic-gate (uint64_t)&tablesp->ct_stack[sizeof (tablesp->ct_stack)]; 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate #elif defined(__i386) 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate ntss->tss_esp0 = ntss->tss_esp1 = ntss->tss_esp2 = ntss->tss_esp = 3640Sstevel@tonic-gate (uint32_t)&tablesp->ct_stack[sizeof (tablesp->ct_stack)]; 3650Sstevel@tonic-gate 3660Sstevel@tonic-gate ntss->tss_ss0 = ntss->tss_ss1 = ntss->tss_ss2 = ntss->tss_ss = KDS_SEL; 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate ntss->tss_eip = (uint32_t)mp_startup; 3690Sstevel@tonic-gate 3700Sstevel@tonic-gate ntss->tss_cs = KCS_SEL; 3710Sstevel@tonic-gate ntss->tss_fs = KFS_SEL; 3720Sstevel@tonic-gate ntss->tss_gs = KGS_SEL; 3730Sstevel@tonic-gate 3740Sstevel@tonic-gate /* 3750Sstevel@tonic-gate * setup kernel %gs. 3760Sstevel@tonic-gate */ 3770Sstevel@tonic-gate set_usegd(&cp->cpu_gdt[GDT_GS], cp, sizeof (struct cpu) -1, SDT_MEMRWA, 3780Sstevel@tonic-gate SEL_KPL, 0, 1); 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate #endif /* __i386 */ 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate /* 3830Sstevel@tonic-gate * Set I/O bit map offset equal to size of TSS segment limit 3840Sstevel@tonic-gate * for no I/O permission map. This will cause all user I/O 3850Sstevel@tonic-gate * instructions to generate #gp fault. 3860Sstevel@tonic-gate */ 3870Sstevel@tonic-gate ntss->tss_bitmapbase = sizeof (*ntss); 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate /* 3900Sstevel@tonic-gate * setup kernel tss. 3910Sstevel@tonic-gate */ 3920Sstevel@tonic-gate set_syssegd((system_desc_t *)&cp->cpu_gdt[GDT_KTSS], cp->cpu_tss, 3930Sstevel@tonic-gate sizeof (*cp->cpu_tss) -1, SDT_SYSTSS, SEL_KPL); 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate /* 3960Sstevel@tonic-gate * If we have more than one node, each cpu gets a copy of IDT 3970Sstevel@tonic-gate * local to its node. If this is a Pentium box, we use cpu 0's 3980Sstevel@tonic-gate * IDT. cpu 0's IDT has been made read-only to workaround the 3990Sstevel@tonic-gate * cmpxchgl register bug 4000Sstevel@tonic-gate */ 4010Sstevel@tonic-gate cp->cpu_idt = CPU->cpu_idt; 4020Sstevel@tonic-gate if (system_hardware.hd_nodes && x86_type != X86_TYPE_P5) { 4030Sstevel@tonic-gate cp->cpu_idt = kmem_alloc(sizeof (idt0), KM_SLEEP); 4040Sstevel@tonic-gate bcopy(idt0, cp->cpu_idt, sizeof (idt0)); 4050Sstevel@tonic-gate } 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate /* 4080Sstevel@tonic-gate * Get interrupt priority data from cpu 0 4090Sstevel@tonic-gate */ 4100Sstevel@tonic-gate cp->cpu_pri_data = CPU->cpu_pri_data; 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate hat_cpu_online(cp); 4130Sstevel@tonic-gate 4140Sstevel@tonic-gate /* Should remove all entries for the current process/thread here */ 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate /* 4170Sstevel@tonic-gate * Fill up the real mode platter to make it easy for real mode code to 4180Sstevel@tonic-gate * kick it off. This area should really be one passed by boot to kernel 4190Sstevel@tonic-gate * and guaranteed to be below 1MB and aligned to 16 bytes. Should also 4200Sstevel@tonic-gate * have identical physical and virtual address in paged mode. 4210Sstevel@tonic-gate */ 4220Sstevel@tonic-gate real_mode_platter->rm_idt_base = cp->cpu_idt; 4230Sstevel@tonic-gate real_mode_platter->rm_idt_lim = sizeof (idt0) - 1; 4240Sstevel@tonic-gate real_mode_platter->rm_gdt_base = cp->cpu_gdt; 4250Sstevel@tonic-gate real_mode_platter->rm_gdt_lim = sizeof (gdt0) -1; 4260Sstevel@tonic-gate real_mode_platter->rm_pdbr = getcr3(); 4270Sstevel@tonic-gate real_mode_platter->rm_cpu = cpun; 4280Sstevel@tonic-gate real_mode_platter->rm_x86feature = x86_feature; 4290Sstevel@tonic-gate real_mode_platter->rm_cr4 = cr4_value; 4300Sstevel@tonic-gate 4310Sstevel@tonic-gate #if defined(__amd64) 4320Sstevel@tonic-gate if (getcr3() > 0xffffffffUL) 4330Sstevel@tonic-gate panic("Cannot initialize CPUs; kernel's 64-bit page tables\n" 4340Sstevel@tonic-gate "located above 4G in physical memory (@ 0x%llx).", 4350Sstevel@tonic-gate (unsigned long long)getcr3()); 4360Sstevel@tonic-gate 4370Sstevel@tonic-gate /* 4380Sstevel@tonic-gate * Setup pseudo-descriptors for temporary GDT and IDT for use ONLY 4390Sstevel@tonic-gate * by code in real_mode_start(): 4400Sstevel@tonic-gate * 4410Sstevel@tonic-gate * GDT[0]: NULL selector 4420Sstevel@tonic-gate * GDT[1]: 64-bit CS: Long = 1, Present = 1, bits 12, 11 = 1 4430Sstevel@tonic-gate * 4440Sstevel@tonic-gate * Clear the IDT as interrupts will be off and a limit of 0 will cause 4450Sstevel@tonic-gate * the CPU to triple fault and reset on an NMI, seemingly as reasonable 4460Sstevel@tonic-gate * a course of action as any other, though it may cause the entire 4470Sstevel@tonic-gate * platform to reset in some cases... 4480Sstevel@tonic-gate */ 4490Sstevel@tonic-gate real_mode_platter->rm_temp_gdt[0] = 0ULL; 4500Sstevel@tonic-gate real_mode_platter->rm_temp_gdt[TEMPGDT_KCODE64] = 0x20980000000000ULL; 4510Sstevel@tonic-gate 4520Sstevel@tonic-gate real_mode_platter->rm_temp_gdt_lim = (ushort_t) 4530Sstevel@tonic-gate (sizeof (real_mode_platter->rm_temp_gdt) - 1); 4540Sstevel@tonic-gate real_mode_platter->rm_temp_gdt_base = rm_platter_pa + 4550Sstevel@tonic-gate (uint32_t)(&((rm_platter_t *)0)->rm_temp_gdt); 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate real_mode_platter->rm_temp_idt_lim = 0; 4580Sstevel@tonic-gate real_mode_platter->rm_temp_idt_base = 0; 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate /* 4610Sstevel@tonic-gate * Since the CPU needs to jump to protected mode using an identity 4620Sstevel@tonic-gate * mapped address, we need to calculate it here. 4630Sstevel@tonic-gate */ 4640Sstevel@tonic-gate real_mode_platter->rm_longmode64_addr = rm_platter_pa + 4650Sstevel@tonic-gate ((uint32_t)long_mode_64 - (uint32_t)real_mode_start); 4660Sstevel@tonic-gate #endif /* __amd64 */ 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate #ifdef TRAPTRACE 4690Sstevel@tonic-gate /* 4700Sstevel@tonic-gate * If this is a TRAPTRACE kernel, allocate TRAPTRACE buffers for this 4710Sstevel@tonic-gate * CPU. 4720Sstevel@tonic-gate */ 4730Sstevel@tonic-gate ttc->ttc_first = (uintptr_t)kmem_zalloc(trap_trace_bufsize, KM_SLEEP); 4740Sstevel@tonic-gate ttc->ttc_next = ttc->ttc_first; 4750Sstevel@tonic-gate ttc->ttc_limit = ttc->ttc_first + trap_trace_bufsize; 4760Sstevel@tonic-gate #endif 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate /* 4790Sstevel@tonic-gate * Record that we have another CPU. 4800Sstevel@tonic-gate */ 4810Sstevel@tonic-gate mutex_enter(&cpu_lock); 4820Sstevel@tonic-gate /* 4830Sstevel@tonic-gate * Initialize the interrupt threads for this CPU 4840Sstevel@tonic-gate */ 4850Sstevel@tonic-gate init_intr_threads(cp); 4860Sstevel@tonic-gate /* 4870Sstevel@tonic-gate * Add CPU to list of available CPUs. It'll be on the active list 4880Sstevel@tonic-gate * after mp_startup(). 4890Sstevel@tonic-gate */ 4900Sstevel@tonic-gate cpu_add_unit(cp); 4910Sstevel@tonic-gate mutex_exit(&cpu_lock); 4920Sstevel@tonic-gate } 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate /* 4950Sstevel@tonic-gate * Apply workarounds for known errata, and warn about those that are absent. 4960Sstevel@tonic-gate * 4970Sstevel@tonic-gate * System vendors occasionally create configurations which contain different 4980Sstevel@tonic-gate * revisions of the CPUs that are almost but not exactly the same. At the 4990Sstevel@tonic-gate * time of writing, this meant that their clock rates were the same, their 5000Sstevel@tonic-gate * feature sets were the same, but the required workaround were -not- 5010Sstevel@tonic-gate * necessarily the same. So, this routine is invoked on -every- CPU soon 5020Sstevel@tonic-gate * after starting to make sure that the resulting system contains the most 5030Sstevel@tonic-gate * pessimal set of workarounds needed to cope with *any* of the CPUs in the 5040Sstevel@tonic-gate * system. 5050Sstevel@tonic-gate * 506359Skucharsk * These workarounds are based on Rev 3.57 of the Revision Guide for 507359Skucharsk * AMD Athlon(tm) 64 and AMD Opteron(tm) Processors, August 2005. 5080Sstevel@tonic-gate */ 5090Sstevel@tonic-gate 5100Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_91) 5110Sstevel@tonic-gate int opteron_erratum_91; /* if non-zero -> at least one cpu has it */ 5120Sstevel@tonic-gate #endif 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_93) 5150Sstevel@tonic-gate int opteron_erratum_93; /* if non-zero -> at least one cpu has it */ 5160Sstevel@tonic-gate #endif 5170Sstevel@tonic-gate 5180Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_100) 5190Sstevel@tonic-gate int opteron_erratum_100; /* if non-zero -> at least one cpu has it */ 5200Sstevel@tonic-gate #endif 5210Sstevel@tonic-gate 5220Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_109) 5230Sstevel@tonic-gate int opteron_erratum_109; /* if non-zero -> at least one cpu has it */ 5240Sstevel@tonic-gate #endif 5250Sstevel@tonic-gate 5260Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_121) 5270Sstevel@tonic-gate int opteron_erratum_121; /* if non-zero -> at least one cpu has it */ 5280Sstevel@tonic-gate #endif 5290Sstevel@tonic-gate 5300Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_122) 5310Sstevel@tonic-gate int opteron_erratum_122; /* if non-zero -> at least one cpu has it */ 5320Sstevel@tonic-gate #endif 5330Sstevel@tonic-gate 5340Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_123) 5350Sstevel@tonic-gate int opteron_erratum_123; /* if non-zero -> at least one cpu has it */ 5360Sstevel@tonic-gate #endif 5370Sstevel@tonic-gate 538359Skucharsk #if defined(OPTERON_ERRATUM_131) 539359Skucharsk int opteron_erratum_131; /* if non-zero -> at least one cpu has it */ 540359Skucharsk #endif 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate #define WARNING(cpu, n) \ 5430Sstevel@tonic-gate cmn_err(CE_WARN, "cpu%d: no workaround for erratum %d", \ 5440Sstevel@tonic-gate (cpu)->cpu_id, (n)) 5450Sstevel@tonic-gate 5460Sstevel@tonic-gate uint_t 5470Sstevel@tonic-gate workaround_errata(struct cpu *cpu) 5480Sstevel@tonic-gate { 5490Sstevel@tonic-gate uint_t missing = 0; 5500Sstevel@tonic-gate 5510Sstevel@tonic-gate ASSERT(cpu == CPU); 5520Sstevel@tonic-gate 5530Sstevel@tonic-gate /*LINTED*/ 5540Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 88) > 0) { 5550Sstevel@tonic-gate /* 5560Sstevel@tonic-gate * SWAPGS May Fail To Read Correct GS Base 5570Sstevel@tonic-gate */ 5580Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_88) 5590Sstevel@tonic-gate /* 5600Sstevel@tonic-gate * The workaround is an mfence in the relevant assembler code 5610Sstevel@tonic-gate */ 5620Sstevel@tonic-gate #else 5630Sstevel@tonic-gate WARNING(cpu, 88); 5640Sstevel@tonic-gate missing++; 5650Sstevel@tonic-gate #endif 5660Sstevel@tonic-gate } 5670Sstevel@tonic-gate 5680Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 91) > 0) { 5690Sstevel@tonic-gate /* 5700Sstevel@tonic-gate * Software Prefetches May Report A Page Fault 5710Sstevel@tonic-gate */ 5720Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_91) 5730Sstevel@tonic-gate /* 5740Sstevel@tonic-gate * fix is in trap.c 5750Sstevel@tonic-gate */ 5760Sstevel@tonic-gate opteron_erratum_91++; 5770Sstevel@tonic-gate #else 5780Sstevel@tonic-gate WARNING(cpu, 91); 5790Sstevel@tonic-gate missing++; 5800Sstevel@tonic-gate #endif 5810Sstevel@tonic-gate } 5820Sstevel@tonic-gate 5830Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 93) > 0) { 5840Sstevel@tonic-gate /* 5850Sstevel@tonic-gate * RSM Auto-Halt Restart Returns to Incorrect RIP 5860Sstevel@tonic-gate */ 5870Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_93) 5880Sstevel@tonic-gate /* 5890Sstevel@tonic-gate * fix is in trap.c 5900Sstevel@tonic-gate */ 5910Sstevel@tonic-gate opteron_erratum_93++; 5920Sstevel@tonic-gate #else 5930Sstevel@tonic-gate WARNING(cpu, 93); 5940Sstevel@tonic-gate missing++; 5950Sstevel@tonic-gate #endif 5960Sstevel@tonic-gate } 5970Sstevel@tonic-gate 5980Sstevel@tonic-gate /*LINTED*/ 5990Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 95) > 0) { 6000Sstevel@tonic-gate /* 6010Sstevel@tonic-gate * RET Instruction May Return to Incorrect EIP 6020Sstevel@tonic-gate */ 6030Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_95) 6040Sstevel@tonic-gate #if defined(_LP64) 6050Sstevel@tonic-gate /* 6060Sstevel@tonic-gate * Workaround this by ensuring that 32-bit user code and 6070Sstevel@tonic-gate * 64-bit kernel code never occupy the same address 6080Sstevel@tonic-gate * range mod 4G. 6090Sstevel@tonic-gate */ 6100Sstevel@tonic-gate if (_userlimit32 > 0xc0000000ul) 6110Sstevel@tonic-gate *(uintptr_t *)&_userlimit32 = 0xc0000000ul; 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate /*LINTED*/ 6140Sstevel@tonic-gate ASSERT((uint32_t)COREHEAP_BASE == 0xc0000000u); 6150Sstevel@tonic-gate #endif /* _LP64 */ 6160Sstevel@tonic-gate #else 6170Sstevel@tonic-gate WARNING(cpu, 95); 6180Sstevel@tonic-gate missing++; 6190Sstevel@tonic-gate #endif /* OPTERON_ERRATUM_95 */ 6200Sstevel@tonic-gate } 6210Sstevel@tonic-gate 6220Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 100) > 0) { 6230Sstevel@tonic-gate /* 6240Sstevel@tonic-gate * Compatibility Mode Branches Transfer to Illegal Address 6250Sstevel@tonic-gate */ 6260Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_100) 6270Sstevel@tonic-gate /* 6280Sstevel@tonic-gate * fix is in trap.c 6290Sstevel@tonic-gate */ 6300Sstevel@tonic-gate opteron_erratum_100++; 6310Sstevel@tonic-gate #else 6320Sstevel@tonic-gate WARNING(cpu, 100); 6330Sstevel@tonic-gate missing++; 6340Sstevel@tonic-gate #endif 6350Sstevel@tonic-gate } 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate /*LINTED*/ 6380Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 108) > 0) { 6390Sstevel@tonic-gate /* 6400Sstevel@tonic-gate * CPUID Instruction May Return Incorrect Model Number In 6410Sstevel@tonic-gate * Some Processors 6420Sstevel@tonic-gate */ 6430Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 6440Sstevel@tonic-gate /* 6450Sstevel@tonic-gate * (Our cpuid-handling code corrects the model number on 6460Sstevel@tonic-gate * those processors) 6470Sstevel@tonic-gate */ 6480Sstevel@tonic-gate #else 6490Sstevel@tonic-gate WARNING(cpu, 108); 6500Sstevel@tonic-gate missing++; 6510Sstevel@tonic-gate #endif 6520Sstevel@tonic-gate } 6530Sstevel@tonic-gate 6540Sstevel@tonic-gate /*LINTED*/ 6550Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 109) > 0) { 6560Sstevel@tonic-gate /* 6570Sstevel@tonic-gate * Certain Reverse REP MOVS May Produce Unpredictable Behaviour 6580Sstevel@tonic-gate */ 6590Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_109) 6600Sstevel@tonic-gate 6610Sstevel@tonic-gate /* workaround is to print a warning to upgrade BIOS */ 662*770Skucharsk if (rdmsr(MSR_AMD_PATCHLEVEL) == 0) 6630Sstevel@tonic-gate opteron_erratum_109++; 6640Sstevel@tonic-gate #else 6650Sstevel@tonic-gate WARNING(cpu, 109); 6660Sstevel@tonic-gate missing++; 6670Sstevel@tonic-gate #endif 6680Sstevel@tonic-gate } 6690Sstevel@tonic-gate /*LINTED*/ 6700Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 121) > 0) { 6710Sstevel@tonic-gate /* 6720Sstevel@tonic-gate * Sequential Execution Across Non_Canonical Boundary Caused 6730Sstevel@tonic-gate * Processor Hang 6740Sstevel@tonic-gate */ 6750Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_121) 6760Sstevel@tonic-gate static int lma; 6770Sstevel@tonic-gate 6780Sstevel@tonic-gate if (opteron_erratum_121) 6790Sstevel@tonic-gate opteron_erratum_121++; 6800Sstevel@tonic-gate 6810Sstevel@tonic-gate /* 6820Sstevel@tonic-gate * Erratum 121 is only present in long (64 bit) mode. 6830Sstevel@tonic-gate * Workaround is to include the page immediately before the 6840Sstevel@tonic-gate * va hole to eliminate the possibility of system hangs due to 6850Sstevel@tonic-gate * sequential execution across the va hole boundary. 6860Sstevel@tonic-gate */ 6870Sstevel@tonic-gate if (lma == 0) { 6880Sstevel@tonic-gate /* 6890Sstevel@tonic-gate * check LMA once: assume all cpus are in long mode 6900Sstevel@tonic-gate * or not. 6910Sstevel@tonic-gate */ 6920Sstevel@tonic-gate lma = 1; 6930Sstevel@tonic-gate 694*770Skucharsk if (rdmsr(MSR_AMD_EFER) & AMD_EFER_LMA) { 6950Sstevel@tonic-gate if (hole_start) { 6960Sstevel@tonic-gate hole_start -= PAGESIZE; 6970Sstevel@tonic-gate } else { 6980Sstevel@tonic-gate /* 6990Sstevel@tonic-gate * hole_start not yet initialized by 7000Sstevel@tonic-gate * mmu_init. Initialize hole_start 7010Sstevel@tonic-gate * with value to be subtracted. 7020Sstevel@tonic-gate */ 7030Sstevel@tonic-gate hole_start = PAGESIZE; 7040Sstevel@tonic-gate } 7050Sstevel@tonic-gate opteron_erratum_121++; 7060Sstevel@tonic-gate } 7070Sstevel@tonic-gate } 7080Sstevel@tonic-gate #else 7090Sstevel@tonic-gate WARNING(cpu, 121); 7100Sstevel@tonic-gate missing++; 7110Sstevel@tonic-gate #endif 7120Sstevel@tonic-gate } 7130Sstevel@tonic-gate 7140Sstevel@tonic-gate /*LINTED*/ 7150Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 122) > 0) { 7160Sstevel@tonic-gate /* 7170Sstevel@tonic-gate * TLB Flush Filter May Cause Cohenrency Problem in 7180Sstevel@tonic-gate * Multiprocessor Systems 7190Sstevel@tonic-gate */ 7200Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_122) 7210Sstevel@tonic-gate /* 7220Sstevel@tonic-gate * Erratum 122 is only present in MP configurations (multi-core 7230Sstevel@tonic-gate * or multi-processor). 7240Sstevel@tonic-gate */ 7250Sstevel@tonic-gate 7260Sstevel@tonic-gate if (opteron_erratum_122 || lgrp_plat_node_cnt > 1 || 7270Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu) > 1) { 7280Sstevel@tonic-gate /* disable TLB Flush Filter */ 729*770Skucharsk wrmsr(MSR_AMD_HWCR, rdmsr(MSR_AMD_HWCR) | 730*770Skucharsk (uint64_t)(uintptr_t)AMD_HWCR_FFDIS); 7310Sstevel@tonic-gate opteron_erratum_122++; 7320Sstevel@tonic-gate } 7330Sstevel@tonic-gate 7340Sstevel@tonic-gate #else 7350Sstevel@tonic-gate WARNING(cpu, 122); 7360Sstevel@tonic-gate missing++; 7370Sstevel@tonic-gate #endif 7380Sstevel@tonic-gate } 739302Skchow 740302Skchow #if defined(OPTERON_ERRATUM_123) 7410Sstevel@tonic-gate /*LINTED*/ 7420Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 123) > 0) { 7430Sstevel@tonic-gate /* 7440Sstevel@tonic-gate * Bypassed Reads May Cause Data Corruption of System Hang in 7450Sstevel@tonic-gate * Dual Core Processors 7460Sstevel@tonic-gate */ 7470Sstevel@tonic-gate /* 7480Sstevel@tonic-gate * Erratum 123 applies only to multi-core cpus. 7490Sstevel@tonic-gate */ 7500Sstevel@tonic-gate 7510Sstevel@tonic-gate if (cpuid_get_ncpu_per_chip(cpu) > 1) { 7520Sstevel@tonic-gate /* workaround is to print a warning to upgrade BIOS */ 753*770Skucharsk if (rdmsr(MSR_AMD_PATCHLEVEL) == 0) 7540Sstevel@tonic-gate opteron_erratum_123++; 7550Sstevel@tonic-gate } 756302Skchow } 7570Sstevel@tonic-gate #endif 758359Skucharsk 759359Skucharsk #if defined(OPTERON_ERRATUM_131) 760359Skucharsk /*LINTED*/ 761359Skucharsk if (cpuid_opteron_erratum(cpu, 131) > 0) { 762359Skucharsk /* 763359Skucharsk * Multiprocessor Systems with Four or More Cores May Deadlock 764359Skucharsk * Waiting for a Probe Response 765359Skucharsk */ 766359Skucharsk /* 767359Skucharsk * Erratum 131 applies to any system with four or more cores. 768359Skucharsk */ 769359Skucharsk if ((opteron_erratum_131 == 0) && ((lgrp_plat_node_cnt * 770359Skucharsk cpuid_get_ncpu_per_chip(cpu)) >= 4)) { 771359Skucharsk /* 772359Skucharsk * Workaround is to print a warning to upgrade 773359Skucharsk * the BIOS 774359Skucharsk */ 775*770Skucharsk if (!(rdmsr(MSR_AMD_NB_CFG) & AMD_NB_CFG_SRQ_HEARTBEAT)) 776359Skucharsk opteron_erratum_131++; 777359Skucharsk } 778359Skucharsk #endif 779359Skucharsk } 7800Sstevel@tonic-gate return (missing); 7810Sstevel@tonic-gate } 7820Sstevel@tonic-gate 7830Sstevel@tonic-gate void 7840Sstevel@tonic-gate workaround_errata_end() 7850Sstevel@tonic-gate { 7860Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_109) 7870Sstevel@tonic-gate if (opteron_erratum_109) { 788359Skucharsk cmn_err(CE_WARN, 789359Skucharsk "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)" 790359Skucharsk " processor\nerratum 109 was not detected; updating your" 791359Skucharsk " system's BIOS to a version\ncontaining this" 792359Skucharsk " microcode patch is HIGHLY recommended or erroneous" 793359Skucharsk " system\noperation may occur.\n"); 7940Sstevel@tonic-gate } 795359Skucharsk #endif /* OPTERON_ERRATUM_109 */ 7960Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_123) 7970Sstevel@tonic-gate if (opteron_erratum_123) { 798359Skucharsk cmn_err(CE_WARN, 799359Skucharsk "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)" 800359Skucharsk " processor\nerratum 123 was not detected; updating your" 801359Skucharsk " system's BIOS to a version\ncontaining this" 802359Skucharsk " microcode patch is HIGHLY recommended or erroneous" 803359Skucharsk " system\noperation may occur.\n"); 8040Sstevel@tonic-gate } 805359Skucharsk #endif /* OPTERON_ERRATUM_123 */ 806359Skucharsk #if defined(OPTERON_ERRATUM_131) 807359Skucharsk if (opteron_erratum_131) { 808359Skucharsk cmn_err(CE_WARN, 809359Skucharsk "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)" 810359Skucharsk " processor\nerratum 131 was not detected; updating your" 811359Skucharsk " system's BIOS to a version\ncontaining this" 812359Skucharsk " microcode patch is HIGHLY recommended or erroneous" 813359Skucharsk " system\noperation may occur.\n"); 814359Skucharsk } 815359Skucharsk #endif /* OPTERON_ERRATUM_131 */ 8160Sstevel@tonic-gate } 8170Sstevel@tonic-gate 8180Sstevel@tonic-gate static ushort_t *mp_map_warm_reset_vector(); 8190Sstevel@tonic-gate static void mp_unmap_warm_reset_vector(ushort_t *warm_reset_vector); 8200Sstevel@tonic-gate 8210Sstevel@tonic-gate /*ARGSUSED*/ 8220Sstevel@tonic-gate void 8230Sstevel@tonic-gate start_other_cpus(int cprboot) 8240Sstevel@tonic-gate { 8250Sstevel@tonic-gate unsigned who; 8260Sstevel@tonic-gate int cpuid = getbootcpuid(); 8270Sstevel@tonic-gate int delays = 0; 8280Sstevel@tonic-gate int started_cpu; 8290Sstevel@tonic-gate ushort_t *warm_reset_vector = NULL; 8300Sstevel@tonic-gate extern int procset; 8310Sstevel@tonic-gate 8320Sstevel@tonic-gate /* 8330Sstevel@tonic-gate * Initialize our own cpu_info. 8340Sstevel@tonic-gate */ 8350Sstevel@tonic-gate init_cpu_info(CPU); 8360Sstevel@tonic-gate 8370Sstevel@tonic-gate /* 8380Sstevel@tonic-gate * Initialize our syscall handlers 8390Sstevel@tonic-gate */ 8400Sstevel@tonic-gate init_cpu_syscall(CPU); 8410Sstevel@tonic-gate 8420Sstevel@tonic-gate /* 8430Sstevel@tonic-gate * if only 1 cpu or not using MP, skip the rest of this 8440Sstevel@tonic-gate */ 8450Sstevel@tonic-gate if (!(mp_cpus & ~(1 << cpuid)) || use_mp == 0) { 8460Sstevel@tonic-gate if (use_mp == 0) 8470Sstevel@tonic-gate cmn_err(CE_CONT, "?***** Not in MP mode\n"); 8480Sstevel@tonic-gate goto done; 8490Sstevel@tonic-gate } 8500Sstevel@tonic-gate 8510Sstevel@tonic-gate /* 8520Sstevel@tonic-gate * perform such initialization as is needed 8530Sstevel@tonic-gate * to be able to take CPUs on- and off-line. 8540Sstevel@tonic-gate */ 8550Sstevel@tonic-gate cpu_pause_init(); 8560Sstevel@tonic-gate 8570Sstevel@tonic-gate xc_init(); /* initialize processor crosscalls */ 8580Sstevel@tonic-gate 8590Sstevel@tonic-gate /* 8600Sstevel@tonic-gate * Copy the real mode code at "real_mode_start" to the 8610Sstevel@tonic-gate * page at rm_platter_va. 8620Sstevel@tonic-gate */ 8630Sstevel@tonic-gate warm_reset_vector = mp_map_warm_reset_vector(); 8640Sstevel@tonic-gate if (warm_reset_vector == NULL) 8650Sstevel@tonic-gate goto done; 8660Sstevel@tonic-gate 8670Sstevel@tonic-gate bcopy((caddr_t)real_mode_start, 8680Sstevel@tonic-gate (caddr_t)((rm_platter_t *)rm_platter_va)->rm_code, 8690Sstevel@tonic-gate (size_t)real_mode_end - (size_t)real_mode_start); 8700Sstevel@tonic-gate 8710Sstevel@tonic-gate flushes_require_xcalls = 1; 8720Sstevel@tonic-gate 8730Sstevel@tonic-gate affinity_set(CPU_CURRENT); 8740Sstevel@tonic-gate 8750Sstevel@tonic-gate for (who = 0; who < NCPU; who++) { 8760Sstevel@tonic-gate if (who == cpuid) 8770Sstevel@tonic-gate continue; 8780Sstevel@tonic-gate 8790Sstevel@tonic-gate if ((mp_cpus & (1 << who)) == 0) 8800Sstevel@tonic-gate continue; 8810Sstevel@tonic-gate 8820Sstevel@tonic-gate mp_startup_init(who); 8830Sstevel@tonic-gate started_cpu = 1; 8840Sstevel@tonic-gate (*cpu_startf)(who, rm_platter_pa); 8850Sstevel@tonic-gate 8860Sstevel@tonic-gate while ((procset & (1 << who)) == 0) { 8870Sstevel@tonic-gate 8880Sstevel@tonic-gate delay(1); 8890Sstevel@tonic-gate if (++delays > (20 * hz)) { 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate cmn_err(CE_WARN, 8920Sstevel@tonic-gate "cpu%d failed to start", who); 8930Sstevel@tonic-gate 8940Sstevel@tonic-gate mutex_enter(&cpu_lock); 8950Sstevel@tonic-gate cpu[who]->cpu_flags = 0; 896414Skchow cpu_vm_data_destroy(cpu[who]); 8970Sstevel@tonic-gate cpu_del_unit(who); 8980Sstevel@tonic-gate mutex_exit(&cpu_lock); 8990Sstevel@tonic-gate 9000Sstevel@tonic-gate started_cpu = 0; 9010Sstevel@tonic-gate break; 9020Sstevel@tonic-gate } 9030Sstevel@tonic-gate } 9040Sstevel@tonic-gate if (!started_cpu) 9050Sstevel@tonic-gate continue; 9060Sstevel@tonic-gate if (tsc_gethrtime_enable) 9070Sstevel@tonic-gate tsc_sync_master(who); 9080Sstevel@tonic-gate 9090Sstevel@tonic-gate 9100Sstevel@tonic-gate if (dtrace_cpu_init != NULL) { 9110Sstevel@tonic-gate /* 9120Sstevel@tonic-gate * DTrace CPU initialization expects cpu_lock 9130Sstevel@tonic-gate * to be held. 9140Sstevel@tonic-gate */ 9150Sstevel@tonic-gate mutex_enter(&cpu_lock); 9160Sstevel@tonic-gate (*dtrace_cpu_init)(who); 9170Sstevel@tonic-gate mutex_exit(&cpu_lock); 9180Sstevel@tonic-gate } 9190Sstevel@tonic-gate } 9200Sstevel@tonic-gate 9210Sstevel@tonic-gate affinity_clear(); 9220Sstevel@tonic-gate 9230Sstevel@tonic-gate for (who = 0; who < NCPU; who++) { 9240Sstevel@tonic-gate if (who == cpuid) 9250Sstevel@tonic-gate continue; 9260Sstevel@tonic-gate 9270Sstevel@tonic-gate if (!(procset & (1 << who))) 9280Sstevel@tonic-gate continue; 9290Sstevel@tonic-gate 9300Sstevel@tonic-gate while (!(cpu_ready_set & (1 << who))) 9310Sstevel@tonic-gate delay(1); 9320Sstevel@tonic-gate } 9330Sstevel@tonic-gate 9340Sstevel@tonic-gate done: 9350Sstevel@tonic-gate workaround_errata_end(); 9360Sstevel@tonic-gate 9370Sstevel@tonic-gate if (warm_reset_vector != NULL) 9380Sstevel@tonic-gate mp_unmap_warm_reset_vector(warm_reset_vector); 9390Sstevel@tonic-gate hat_unload(kas.a_hat, (caddr_t)(uintptr_t)rm_platter_pa, MMU_PAGESIZE, 9400Sstevel@tonic-gate HAT_UNLOAD); 9410Sstevel@tonic-gate } 9420Sstevel@tonic-gate 9430Sstevel@tonic-gate /* 9440Sstevel@tonic-gate * Dummy functions - no i86pc platforms support dynamic cpu allocation. 9450Sstevel@tonic-gate */ 9460Sstevel@tonic-gate /*ARGSUSED*/ 9470Sstevel@tonic-gate int 9480Sstevel@tonic-gate mp_cpu_configure(int cpuid) 9490Sstevel@tonic-gate { 9500Sstevel@tonic-gate return (ENOTSUP); /* not supported */ 9510Sstevel@tonic-gate } 9520Sstevel@tonic-gate 9530Sstevel@tonic-gate /*ARGSUSED*/ 9540Sstevel@tonic-gate int 9550Sstevel@tonic-gate mp_cpu_unconfigure(int cpuid) 9560Sstevel@tonic-gate { 9570Sstevel@tonic-gate return (ENOTSUP); /* not supported */ 9580Sstevel@tonic-gate } 9590Sstevel@tonic-gate 9600Sstevel@tonic-gate /* 9610Sstevel@tonic-gate * Startup function for 'other' CPUs (besides boot cpu). 9620Sstevel@tonic-gate * Resumed from cpu_startup. 9630Sstevel@tonic-gate */ 9640Sstevel@tonic-gate void 9650Sstevel@tonic-gate mp_startup(void) 9660Sstevel@tonic-gate { 9670Sstevel@tonic-gate struct cpu *cp = CPU; 9680Sstevel@tonic-gate extern int procset; 9690Sstevel@tonic-gate uint_t new_x86_feature; 9700Sstevel@tonic-gate 9710Sstevel@tonic-gate new_x86_feature = cpuid_pass1(cp); 9720Sstevel@tonic-gate 9730Sstevel@tonic-gate /* 9740Sstevel@tonic-gate * We need to Sync MTRR with cpu0's MTRR. We have to do 9750Sstevel@tonic-gate * this with interrupts disabled. 9760Sstevel@tonic-gate */ 9770Sstevel@tonic-gate if (x86_feature & X86_MTRR) 9780Sstevel@tonic-gate mtrr_sync(); 9790Sstevel@tonic-gate /* 9800Sstevel@tonic-gate * Enable machine check architecture 9810Sstevel@tonic-gate */ 9820Sstevel@tonic-gate if (x86_feature & X86_MCA) 9830Sstevel@tonic-gate setup_mca(); 9840Sstevel@tonic-gate 9850Sstevel@tonic-gate /* 9860Sstevel@tonic-gate * Initialize this CPU's syscall handlers 9870Sstevel@tonic-gate */ 9880Sstevel@tonic-gate init_cpu_syscall(cp); 9890Sstevel@tonic-gate 9900Sstevel@tonic-gate /* 9910Sstevel@tonic-gate * Enable interrupts with spl set to LOCK_LEVEL. LOCK_LEVEL is the 9920Sstevel@tonic-gate * highest level at which a routine is permitted to block on 9930Sstevel@tonic-gate * an adaptive mutex (allows for cpu poke interrupt in case 9940Sstevel@tonic-gate * the cpu is blocked on a mutex and halts). Setting LOCK_LEVEL blocks 9950Sstevel@tonic-gate * device interrupts that may end up in the hat layer issuing cross 9960Sstevel@tonic-gate * calls before CPU_READY is set. 9970Sstevel@tonic-gate */ 9980Sstevel@tonic-gate (void) splx(ipltospl(LOCK_LEVEL)); 9990Sstevel@tonic-gate 10000Sstevel@tonic-gate /* 10010Sstevel@tonic-gate * Do a sanity check to make sure this new CPU is a sane thing 10020Sstevel@tonic-gate * to add to the collection of processors running this system. 10030Sstevel@tonic-gate * 10040Sstevel@tonic-gate * XXX Clearly this needs to get more sophisticated, if x86 10050Sstevel@tonic-gate * systems start to get built out of heterogenous CPUs; as is 10060Sstevel@tonic-gate * likely to happen once the number of processors in a configuration 10070Sstevel@tonic-gate * gets large enough. 10080Sstevel@tonic-gate */ 10090Sstevel@tonic-gate if ((x86_feature & new_x86_feature) != x86_feature) { 10100Sstevel@tonic-gate cmn_err(CE_CONT, "?cpu%d: %b\n", 10110Sstevel@tonic-gate cp->cpu_id, new_x86_feature, FMT_X86_FEATURE); 10120Sstevel@tonic-gate cmn_err(CE_WARN, "cpu%d feature mismatch", cp->cpu_id); 10130Sstevel@tonic-gate } 10140Sstevel@tonic-gate 10150Sstevel@tonic-gate /* 10160Sstevel@tonic-gate * We could be more sophisticated here, and just mark the CPU 10170Sstevel@tonic-gate * as "faulted" but at this point we'll opt for the easier 10180Sstevel@tonic-gate * answer of dieing horribly. Provided the boot cpu is ok, 10190Sstevel@tonic-gate * the system can be recovered by booting with use_mp set to zero. 10200Sstevel@tonic-gate */ 10210Sstevel@tonic-gate if (workaround_errata(cp) != 0) 10220Sstevel@tonic-gate panic("critical workaround(s) missing for cpu%d", cp->cpu_id); 10230Sstevel@tonic-gate 10240Sstevel@tonic-gate cpuid_pass2(cp); 10250Sstevel@tonic-gate cpuid_pass3(cp); 10260Sstevel@tonic-gate (void) cpuid_pass4(cp); 10270Sstevel@tonic-gate 10280Sstevel@tonic-gate init_cpu_info(cp); 10290Sstevel@tonic-gate 10300Sstevel@tonic-gate add_cpunode2devtree(cp->cpu_id, cp->cpu_m.mcpu_cpi); 10310Sstevel@tonic-gate 10320Sstevel@tonic-gate mutex_enter(&cpu_lock); 10330Sstevel@tonic-gate procset |= 1 << cp->cpu_id; 10340Sstevel@tonic-gate mutex_exit(&cpu_lock); 10350Sstevel@tonic-gate 10360Sstevel@tonic-gate if (tsc_gethrtime_enable) 10370Sstevel@tonic-gate tsc_sync_slave(); 10380Sstevel@tonic-gate 10390Sstevel@tonic-gate mutex_enter(&cpu_lock); 10400Sstevel@tonic-gate /* 10410Sstevel@tonic-gate * It's unfortunate that chip_cpu_init() has to be called here. 10420Sstevel@tonic-gate * It really belongs in cpu_add_unit(), but unfortunately it is 10430Sstevel@tonic-gate * dependent on the cpuid probing, which must be done in the 10440Sstevel@tonic-gate * context of the current CPU. Care must be taken on x86 to ensure 10450Sstevel@tonic-gate * that mp_startup can safely block even though chip_cpu_init() and 10460Sstevel@tonic-gate * cpu_add_active() have not yet been called. 10470Sstevel@tonic-gate */ 10480Sstevel@tonic-gate chip_cpu_init(cp); 10490Sstevel@tonic-gate chip_cpu_startup(cp); 10500Sstevel@tonic-gate 10510Sstevel@tonic-gate cp->cpu_flags |= CPU_RUNNING | CPU_READY | CPU_ENABLE | CPU_EXISTS; 10520Sstevel@tonic-gate cpu_add_active(cp); 10530Sstevel@tonic-gate mutex_exit(&cpu_lock); 10540Sstevel@tonic-gate 10550Sstevel@tonic-gate (void) spl0(); /* enable interrupts */ 10560Sstevel@tonic-gate 10570Sstevel@tonic-gate if (boothowto & RB_DEBUG) 10580Sstevel@tonic-gate kdi_dvec_cpu_init(cp); 10590Sstevel@tonic-gate 10600Sstevel@tonic-gate /* 10610Sstevel@tonic-gate * Setting the bit in cpu_ready_set must be the last operation in 10620Sstevel@tonic-gate * processor initialization; the boot CPU will continue to boot once 10630Sstevel@tonic-gate * it sees this bit set for all active CPUs. 10640Sstevel@tonic-gate */ 10650Sstevel@tonic-gate CPUSET_ATOMIC_ADD(cpu_ready_set, cp->cpu_id); 10660Sstevel@tonic-gate 10670Sstevel@tonic-gate /* 10680Sstevel@tonic-gate * Because mp_startup() gets fired off after init() starts, we 10690Sstevel@tonic-gate * can't use the '?' trick to do 'boot -v' printing - so we 10700Sstevel@tonic-gate * always direct the 'cpu .. online' messages to the log. 10710Sstevel@tonic-gate */ 10720Sstevel@tonic-gate cmn_err(CE_CONT, "!cpu%d initialization complete - online\n", 10730Sstevel@tonic-gate cp->cpu_id); 10740Sstevel@tonic-gate 10750Sstevel@tonic-gate /* 10760Sstevel@tonic-gate * Now we are done with the startup thread, so free it up. 10770Sstevel@tonic-gate */ 10780Sstevel@tonic-gate thread_exit(); 10790Sstevel@tonic-gate panic("mp_startup: cannot return"); 10800Sstevel@tonic-gate /*NOTREACHED*/ 10810Sstevel@tonic-gate } 10820Sstevel@tonic-gate 10830Sstevel@tonic-gate 10840Sstevel@tonic-gate /* 10850Sstevel@tonic-gate * Start CPU on user request. 10860Sstevel@tonic-gate */ 10870Sstevel@tonic-gate /* ARGSUSED */ 10880Sstevel@tonic-gate int 10890Sstevel@tonic-gate mp_cpu_start(struct cpu *cp) 10900Sstevel@tonic-gate { 10910Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 10920Sstevel@tonic-gate if (cp->cpu_id == getbootcpuid()) 10930Sstevel@tonic-gate return (EBUSY); /* Cannot start boot CPU */ 10940Sstevel@tonic-gate return (0); 10950Sstevel@tonic-gate } 10960Sstevel@tonic-gate 10970Sstevel@tonic-gate /* 10980Sstevel@tonic-gate * Stop CPU on user request. 10990Sstevel@tonic-gate */ 11000Sstevel@tonic-gate /* ARGSUSED */ 11010Sstevel@tonic-gate int 11020Sstevel@tonic-gate mp_cpu_stop(struct cpu *cp) 11030Sstevel@tonic-gate { 11040Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 11050Sstevel@tonic-gate if (cp->cpu_id == getbootcpuid()) 11060Sstevel@tonic-gate return (EBUSY); /* Cannot stop boot CPU */ 11070Sstevel@tonic-gate 11080Sstevel@tonic-gate return (0); 11090Sstevel@tonic-gate } 11100Sstevel@tonic-gate 11110Sstevel@tonic-gate /* 11120Sstevel@tonic-gate * Power on CPU. 11130Sstevel@tonic-gate */ 11140Sstevel@tonic-gate /* ARGSUSED */ 11150Sstevel@tonic-gate int 11160Sstevel@tonic-gate mp_cpu_poweron(struct cpu *cp) 11170Sstevel@tonic-gate { 11180Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 11190Sstevel@tonic-gate return (ENOTSUP); /* not supported */ 11200Sstevel@tonic-gate } 11210Sstevel@tonic-gate 11220Sstevel@tonic-gate /* 11230Sstevel@tonic-gate * Power off CPU. 11240Sstevel@tonic-gate */ 11250Sstevel@tonic-gate /* ARGSUSED */ 11260Sstevel@tonic-gate int 11270Sstevel@tonic-gate mp_cpu_poweroff(struct cpu *cp) 11280Sstevel@tonic-gate { 11290Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 11300Sstevel@tonic-gate return (ENOTSUP); /* not supported */ 11310Sstevel@tonic-gate } 11320Sstevel@tonic-gate 11330Sstevel@tonic-gate 11340Sstevel@tonic-gate /* 11350Sstevel@tonic-gate * Take the specified CPU out of participation in interrupts. 11360Sstevel@tonic-gate */ 11370Sstevel@tonic-gate int 11380Sstevel@tonic-gate cpu_disable_intr(struct cpu *cp) 11390Sstevel@tonic-gate { 11400Sstevel@tonic-gate /* 11410Sstevel@tonic-gate * cannot disable interrupts on boot cpu 11420Sstevel@tonic-gate */ 11430Sstevel@tonic-gate if (cp == cpu[getbootcpuid()]) 11440Sstevel@tonic-gate return (EBUSY); 11450Sstevel@tonic-gate 11460Sstevel@tonic-gate if (psm_disable_intr(cp->cpu_id) != DDI_SUCCESS) 11470Sstevel@tonic-gate return (EBUSY); 11480Sstevel@tonic-gate 11490Sstevel@tonic-gate cp->cpu_flags &= ~CPU_ENABLE; 11500Sstevel@tonic-gate return (0); 11510Sstevel@tonic-gate } 11520Sstevel@tonic-gate 11530Sstevel@tonic-gate /* 11540Sstevel@tonic-gate * Allow the specified CPU to participate in interrupts. 11550Sstevel@tonic-gate */ 11560Sstevel@tonic-gate void 11570Sstevel@tonic-gate cpu_enable_intr(struct cpu *cp) 11580Sstevel@tonic-gate { 11590Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 11600Sstevel@tonic-gate if (cp == cpu[getbootcpuid()]) 11610Sstevel@tonic-gate return; 11620Sstevel@tonic-gate 11630Sstevel@tonic-gate cp->cpu_flags |= CPU_ENABLE; 11640Sstevel@tonic-gate psm_enable_intr(cp->cpu_id); 11650Sstevel@tonic-gate } 11660Sstevel@tonic-gate 11670Sstevel@tonic-gate 11680Sstevel@tonic-gate /* 11690Sstevel@tonic-gate * return the cpu id of the initial startup cpu 11700Sstevel@tonic-gate */ 11710Sstevel@tonic-gate processorid_t 11720Sstevel@tonic-gate getbootcpuid(void) 11730Sstevel@tonic-gate { 11740Sstevel@tonic-gate return (0); 11750Sstevel@tonic-gate } 11760Sstevel@tonic-gate 11770Sstevel@tonic-gate static ushort_t * 11780Sstevel@tonic-gate mp_map_warm_reset_vector() 11790Sstevel@tonic-gate { 11800Sstevel@tonic-gate ushort_t *warm_reset_vector; 11810Sstevel@tonic-gate 11820Sstevel@tonic-gate if (!(warm_reset_vector = (ushort_t *)psm_map_phys(WARM_RESET_VECTOR, 11830Sstevel@tonic-gate sizeof (ushort_t *), PROT_READ|PROT_WRITE))) 11840Sstevel@tonic-gate return (NULL); 11850Sstevel@tonic-gate 11860Sstevel@tonic-gate /* 11870Sstevel@tonic-gate * setup secondary cpu bios boot up vector 11880Sstevel@tonic-gate */ 11890Sstevel@tonic-gate *warm_reset_vector = (ushort_t)((caddr_t) 11900Sstevel@tonic-gate ((struct rm_platter *)rm_platter_va)->rm_code - rm_platter_va 11910Sstevel@tonic-gate + ((ulong_t)rm_platter_va & 0xf)); 11920Sstevel@tonic-gate warm_reset_vector++; 11930Sstevel@tonic-gate *warm_reset_vector = (ushort_t)(rm_platter_pa >> 4); 11940Sstevel@tonic-gate 11950Sstevel@tonic-gate --warm_reset_vector; 11960Sstevel@tonic-gate return (warm_reset_vector); 11970Sstevel@tonic-gate } 11980Sstevel@tonic-gate 11990Sstevel@tonic-gate static void 12000Sstevel@tonic-gate mp_unmap_warm_reset_vector(ushort_t *warm_reset_vector) 12010Sstevel@tonic-gate { 12020Sstevel@tonic-gate psm_unmap_phys((caddr_t)warm_reset_vector, sizeof (ushort_t *)); 12030Sstevel@tonic-gate } 12040Sstevel@tonic-gate 12050Sstevel@tonic-gate /*ARGSUSED*/ 12060Sstevel@tonic-gate void 12070Sstevel@tonic-gate mp_cpu_faulted_enter(struct cpu *cp) 12080Sstevel@tonic-gate {} 12090Sstevel@tonic-gate 12100Sstevel@tonic-gate /*ARGSUSED*/ 12110Sstevel@tonic-gate void 12120Sstevel@tonic-gate mp_cpu_faulted_exit(struct cpu *cp) 12130Sstevel@tonic-gate {} 12140Sstevel@tonic-gate 12150Sstevel@tonic-gate /* 12160Sstevel@tonic-gate * The following two routines are used as context operators on threads belonging 12170Sstevel@tonic-gate * to processes with a private LDT (see sysi86). Due to the rarity of such 12180Sstevel@tonic-gate * processes, these routines are currently written for best code readability and 12190Sstevel@tonic-gate * organization rather than speed. We could avoid checking x86_feature at every 12200Sstevel@tonic-gate * context switch by installing different context ops, depending on the 12210Sstevel@tonic-gate * x86_feature flags, at LDT creation time -- one for each combination of fast 12220Sstevel@tonic-gate * syscall feature flags. 12230Sstevel@tonic-gate */ 12240Sstevel@tonic-gate 12250Sstevel@tonic-gate /*ARGSUSED*/ 12260Sstevel@tonic-gate void 12270Sstevel@tonic-gate cpu_fast_syscall_disable(void *arg) 12280Sstevel@tonic-gate { 12290Sstevel@tonic-gate if (x86_feature & X86_SEP) 12300Sstevel@tonic-gate cpu_sep_disable(); 12310Sstevel@tonic-gate if (x86_feature & X86_ASYSC) 12320Sstevel@tonic-gate cpu_asysc_disable(); 12330Sstevel@tonic-gate } 12340Sstevel@tonic-gate 12350Sstevel@tonic-gate /*ARGSUSED*/ 12360Sstevel@tonic-gate void 12370Sstevel@tonic-gate cpu_fast_syscall_enable(void *arg) 12380Sstevel@tonic-gate { 12390Sstevel@tonic-gate if (x86_feature & X86_SEP) 12400Sstevel@tonic-gate cpu_sep_enable(); 12410Sstevel@tonic-gate if (x86_feature & X86_ASYSC) 12420Sstevel@tonic-gate cpu_asysc_enable(); 12430Sstevel@tonic-gate } 12440Sstevel@tonic-gate 12450Sstevel@tonic-gate static void 12460Sstevel@tonic-gate cpu_sep_enable(void) 12470Sstevel@tonic-gate { 12480Sstevel@tonic-gate ASSERT(x86_feature & X86_SEP); 12490Sstevel@tonic-gate ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 12500Sstevel@tonic-gate 1251*770Skucharsk wrmsr(MSR_INTC_SEP_CS, (uint64_t)(uintptr_t)KCS_SEL); 12520Sstevel@tonic-gate } 12530Sstevel@tonic-gate 12540Sstevel@tonic-gate static void 12550Sstevel@tonic-gate cpu_sep_disable(void) 12560Sstevel@tonic-gate { 12570Sstevel@tonic-gate ASSERT(x86_feature & X86_SEP); 12580Sstevel@tonic-gate ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 12590Sstevel@tonic-gate 12600Sstevel@tonic-gate /* 12610Sstevel@tonic-gate * Setting the SYSENTER_CS_MSR register to 0 causes software executing 12620Sstevel@tonic-gate * the sysenter or sysexit instruction to trigger a #gp fault. 12630Sstevel@tonic-gate */ 1264*770Skucharsk wrmsr(MSR_INTC_SEP_CS, 0ULL); 12650Sstevel@tonic-gate } 12660Sstevel@tonic-gate 12670Sstevel@tonic-gate static void 12680Sstevel@tonic-gate cpu_asysc_enable(void) 12690Sstevel@tonic-gate { 12700Sstevel@tonic-gate ASSERT(x86_feature & X86_ASYSC); 12710Sstevel@tonic-gate ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 12720Sstevel@tonic-gate 1273*770Skucharsk wrmsr(MSR_AMD_EFER, rdmsr(MSR_AMD_EFER) | 1274*770Skucharsk (uint64_t)(uintptr_t)AMD_EFER_SCE); 12750Sstevel@tonic-gate } 12760Sstevel@tonic-gate 12770Sstevel@tonic-gate static void 12780Sstevel@tonic-gate cpu_asysc_disable(void) 12790Sstevel@tonic-gate { 12800Sstevel@tonic-gate ASSERT(x86_feature & X86_ASYSC); 12810Sstevel@tonic-gate ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 12820Sstevel@tonic-gate 12830Sstevel@tonic-gate /* 12840Sstevel@tonic-gate * Turn off the SCE (syscall enable) bit in the EFER register. Software 12850Sstevel@tonic-gate * executing syscall or sysret with this bit off will incur a #ud trap. 12860Sstevel@tonic-gate */ 1287*770Skucharsk wrmsr(MSR_AMD_EFER, rdmsr(MSR_AMD_EFER) & 1288*770Skucharsk ~((uint64_t)(uintptr_t)AMD_EFER_SCE)); 12890Sstevel@tonic-gate } 1290