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 51455Sandrei * Common Development and Distribution License (the "License"). 61455Sandrei * 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 /* 221251Skchow * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/types.h> 290Sstevel@tonic-gate #include <sys/thread.h> 300Sstevel@tonic-gate #include <sys/cpuvar.h> 310Sstevel@tonic-gate #include <sys/t_lock.h> 320Sstevel@tonic-gate #include <sys/param.h> 330Sstevel@tonic-gate #include <sys/proc.h> 340Sstevel@tonic-gate #include <sys/disp.h> 350Sstevel@tonic-gate #include <sys/mmu.h> 360Sstevel@tonic-gate #include <sys/class.h> 370Sstevel@tonic-gate #include <sys/cmn_err.h> 380Sstevel@tonic-gate #include <sys/debug.h> 390Sstevel@tonic-gate #include <sys/asm_linkage.h> 400Sstevel@tonic-gate #include <sys/x_call.h> 410Sstevel@tonic-gate #include <sys/systm.h> 420Sstevel@tonic-gate #include <sys/var.h> 430Sstevel@tonic-gate #include <sys/vtrace.h> 440Sstevel@tonic-gate #include <vm/hat.h> 450Sstevel@tonic-gate #include <sys/mmu.h> 460Sstevel@tonic-gate #include <vm/as.h> 470Sstevel@tonic-gate #include <vm/seg_kmem.h> 480Sstevel@tonic-gate #include <sys/segments.h> 490Sstevel@tonic-gate #include <sys/kmem.h> 500Sstevel@tonic-gate #include <sys/stack.h> 510Sstevel@tonic-gate #include <sys/smp_impldefs.h> 520Sstevel@tonic-gate #include <sys/x86_archext.h> 530Sstevel@tonic-gate #include <sys/machsystm.h> 540Sstevel@tonic-gate #include <sys/traptrace.h> 550Sstevel@tonic-gate #include <sys/clock.h> 560Sstevel@tonic-gate #include <sys/cpc_impl.h> 570Sstevel@tonic-gate #include <sys/chip.h> 580Sstevel@tonic-gate #include <sys/dtrace.h> 590Sstevel@tonic-gate #include <sys/archsystm.h> 600Sstevel@tonic-gate #include <sys/fp.h> 610Sstevel@tonic-gate #include <sys/reboot.h> 620Sstevel@tonic-gate #include <sys/kdi.h> 630Sstevel@tonic-gate #include <vm/hat_i86.h> 640Sstevel@tonic-gate #include <sys/memnode.h> 65938Sesaxe #include <sys/pci_cfgspace.h> 661414Scindi #include <sys/cpu_module.h> 670Sstevel@tonic-gate 680Sstevel@tonic-gate struct cpu cpus[1]; /* CPU data */ 690Sstevel@tonic-gate struct cpu *cpu[NCPU] = {&cpus[0]}; /* pointers to all CPUs */ 700Sstevel@tonic-gate cpu_core_t cpu_core[NCPU]; /* cpu_core structures */ 710Sstevel@tonic-gate 720Sstevel@tonic-gate /* 730Sstevel@tonic-gate * Useful for disabling MP bring-up for an MP capable kernel 740Sstevel@tonic-gate * (a kernel that was built with MP defined) 750Sstevel@tonic-gate */ 760Sstevel@tonic-gate int use_mp = 1; 770Sstevel@tonic-gate 780Sstevel@tonic-gate int mp_cpus = 0x1; /* to be set by platform specific module */ 790Sstevel@tonic-gate 800Sstevel@tonic-gate /* 810Sstevel@tonic-gate * This variable is used by the hat layer to decide whether or not 820Sstevel@tonic-gate * critical sections are needed to prevent race conditions. For sun4m, 830Sstevel@tonic-gate * this variable is set once enough MP initialization has been done in 840Sstevel@tonic-gate * order to allow cross calls. 850Sstevel@tonic-gate */ 860Sstevel@tonic-gate int flushes_require_xcalls = 0; 870Sstevel@tonic-gate ulong_t cpu_ready_set = 1; 880Sstevel@tonic-gate 890Sstevel@tonic-gate extern void real_mode_start(void); 900Sstevel@tonic-gate extern void real_mode_end(void); 910Sstevel@tonic-gate static void mp_startup(void); 920Sstevel@tonic-gate 930Sstevel@tonic-gate static void cpu_sep_enable(void); 940Sstevel@tonic-gate static void cpu_sep_disable(void); 950Sstevel@tonic-gate static void cpu_asysc_enable(void); 960Sstevel@tonic-gate static void cpu_asysc_disable(void); 970Sstevel@tonic-gate 980Sstevel@tonic-gate extern int tsc_gethrtime_enable; 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* 1010Sstevel@tonic-gate * Init CPU info - get CPU type info for processor_info system call. 1020Sstevel@tonic-gate */ 1030Sstevel@tonic-gate void 1040Sstevel@tonic-gate init_cpu_info(struct cpu *cp) 1050Sstevel@tonic-gate { 1060Sstevel@tonic-gate processor_info_t *pi = &cp->cpu_type_info; 1070Sstevel@tonic-gate char buf[CPU_IDSTRLEN]; 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate /* 1100Sstevel@tonic-gate * Get clock-frequency property for the CPU. 1110Sstevel@tonic-gate */ 1120Sstevel@tonic-gate pi->pi_clock = cpu_freq; 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate (void) strcpy(pi->pi_processor_type, "i386"); 1150Sstevel@tonic-gate if (fpu_exists) 1160Sstevel@tonic-gate (void) strcpy(pi->pi_fputypes, "i387 compatible"); 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate (void) cpuid_getidstr(cp, buf, sizeof (buf)); 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP); 1210Sstevel@tonic-gate (void) strcpy(cp->cpu_idstr, buf); 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate cmn_err(CE_CONT, "?cpu%d: %s\n", cp->cpu_id, cp->cpu_idstr); 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate (void) cpuid_getbrandstr(cp, buf, sizeof (buf)); 1260Sstevel@tonic-gate cp->cpu_brandstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP); 1270Sstevel@tonic-gate (void) strcpy(cp->cpu_brandstr, buf); 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate cmn_err(CE_CONT, "?cpu%d: %s\n", cp->cpu_id, cp->cpu_brandstr); 1300Sstevel@tonic-gate } 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate /* 1330Sstevel@tonic-gate * Configure syscall support on this CPU. 1340Sstevel@tonic-gate */ 1350Sstevel@tonic-gate /*ARGSUSED*/ 1360Sstevel@tonic-gate static void 1370Sstevel@tonic-gate init_cpu_syscall(struct cpu *cp) 1380Sstevel@tonic-gate { 1390Sstevel@tonic-gate kpreempt_disable(); 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate #if defined(__amd64) 1420Sstevel@tonic-gate if (x86_feature & X86_ASYSC) { 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate #if !defined(__lint) 1450Sstevel@tonic-gate /* 1460Sstevel@tonic-gate * The syscall instruction imposes a certain ordering on 1470Sstevel@tonic-gate * segment selectors, so we double-check that ordering 1480Sstevel@tonic-gate * here. 1490Sstevel@tonic-gate */ 1500Sstevel@tonic-gate ASSERT(KDS_SEL == KCS_SEL + 8); 1510Sstevel@tonic-gate ASSERT(UDS_SEL == U32CS_SEL + 8); 1520Sstevel@tonic-gate ASSERT(UCS_SEL == U32CS_SEL + 16); 1530Sstevel@tonic-gate #endif 1540Sstevel@tonic-gate /* 1550Sstevel@tonic-gate * Turn syscall/sysret extensions on. 1560Sstevel@tonic-gate */ 1570Sstevel@tonic-gate cpu_asysc_enable(); 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate /* 1600Sstevel@tonic-gate * Program the magic registers .. 1610Sstevel@tonic-gate */ 162770Skucharsk wrmsr(MSR_AMD_STAR, ((uint64_t)(U32CS_SEL << 16 | KCS_SEL)) << 163770Skucharsk 32); 164770Skucharsk wrmsr(MSR_AMD_LSTAR, (uint64_t)(uintptr_t)sys_syscall); 165770Skucharsk wrmsr(MSR_AMD_CSTAR, (uint64_t)(uintptr_t)sys_syscall32); 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate /* 1680Sstevel@tonic-gate * This list of flags is masked off the incoming 1690Sstevel@tonic-gate * %rfl when we enter the kernel. 1700Sstevel@tonic-gate */ 171770Skucharsk wrmsr(MSR_AMD_SFMASK, (uint64_t)(uintptr_t)(PS_IE | PS_T)); 1720Sstevel@tonic-gate } 1730Sstevel@tonic-gate #endif 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate /* 1760Sstevel@tonic-gate * On 32-bit kernels, we use sysenter/sysexit because it's too 1770Sstevel@tonic-gate * hard to use syscall/sysret, and it is more portable anyway. 1780Sstevel@tonic-gate * 1790Sstevel@tonic-gate * On 64-bit kernels on Nocona machines, the 32-bit syscall 1800Sstevel@tonic-gate * variant isn't available to 32-bit applications, but sysenter is. 1810Sstevel@tonic-gate */ 1820Sstevel@tonic-gate if (x86_feature & X86_SEP) { 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate #if !defined(__lint) 1850Sstevel@tonic-gate /* 1860Sstevel@tonic-gate * The sysenter instruction imposes a certain ordering on 1870Sstevel@tonic-gate * segment selectors, so we double-check that ordering 1880Sstevel@tonic-gate * here. See "sysenter" in Intel document 245471-012, "IA-32 1890Sstevel@tonic-gate * Intel Architecture Software Developer's Manual Volume 2: 1900Sstevel@tonic-gate * Instruction Set Reference" 1910Sstevel@tonic-gate */ 1920Sstevel@tonic-gate ASSERT(KDS_SEL == KCS_SEL + 8); 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate ASSERT32(UCS_SEL == ((KCS_SEL + 16) | 3)); 1950Sstevel@tonic-gate ASSERT32(UDS_SEL == UCS_SEL + 8); 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate ASSERT64(U32CS_SEL == ((KCS_SEL + 16) | 3)); 1980Sstevel@tonic-gate ASSERT64(UDS_SEL == U32CS_SEL + 8); 1990Sstevel@tonic-gate #endif 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate cpu_sep_enable(); 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate /* 2040Sstevel@tonic-gate * resume() sets this value to the base of the threads stack 2050Sstevel@tonic-gate * via a context handler. 2060Sstevel@tonic-gate */ 207770Skucharsk wrmsr(MSR_INTC_SEP_ESP, 0ULL); 208770Skucharsk wrmsr(MSR_INTC_SEP_EIP, (uint64_t)(uintptr_t)sys_sysenter); 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate kpreempt_enable(); 2120Sstevel@tonic-gate } 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate /* 2150Sstevel@tonic-gate * Multiprocessor initialization. 2160Sstevel@tonic-gate * 2170Sstevel@tonic-gate * Allocate and initialize the cpu structure, TRAPTRACE buffer, and the 2180Sstevel@tonic-gate * startup and idle threads for the specified CPU. 2190Sstevel@tonic-gate */ 2200Sstevel@tonic-gate static void 2210Sstevel@tonic-gate mp_startup_init(int cpun) 2220Sstevel@tonic-gate { 2230Sstevel@tonic-gate #if defined(__amd64) 2240Sstevel@tonic-gate extern void *long_mode_64(void); 2250Sstevel@tonic-gate #endif /* __amd64 */ 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate struct cpu *cp; 2280Sstevel@tonic-gate struct tss *ntss; 2290Sstevel@tonic-gate kthread_id_t tp; 2300Sstevel@tonic-gate caddr_t sp; 2310Sstevel@tonic-gate int size; 2320Sstevel@tonic-gate proc_t *procp; 2330Sstevel@tonic-gate extern void idle(); 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 /* 2981482Ssethg * cpu_base_spl must be set explicitly here to prevent any blocking 2991482Ssethg * operations in mp_startup from causing the spl of the cpu to drop 3001482Ssethg * to 0 (allowing device interrupts before we're ready) in resume(). 3011482Ssethg * cpu_base_spl MUST remain at LOCK_LEVEL until the cpu is CPU_READY. 3021482Ssethg * As an extra bit of security on DEBUG kernels, this is enforced with 3031482Ssethg * an assertion in mp_startup() -- before cpu_base_spl is set to its 3041482Ssethg * proper value. 3051482Ssethg */ 3061482Ssethg cp->cpu_base_spl = ipltospl(LOCK_LEVEL); 3071482Ssethg 3081482Ssethg /* 3090Sstevel@tonic-gate * Now, initialize per-CPU idle thread for this CPU. 3100Sstevel@tonic-gate */ 3110Sstevel@tonic-gate tp = thread_create(NULL, PAGESIZE, idle, NULL, 0, procp, TS_ONPROC, -1); 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate cp->cpu_idle_thread = tp; 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate tp->t_preempt = 1; 3160Sstevel@tonic-gate tp->t_bound_cpu = cp; 3170Sstevel@tonic-gate tp->t_affinitycnt = 1; 3180Sstevel@tonic-gate tp->t_cpu = cp; 3190Sstevel@tonic-gate tp->t_disp_queue = cp->cpu_disp; 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate /* 32260Sesaxe * Bootstrap the CPU for CMT aware scheduling 32360Sesaxe * The rest of the initialization will happen from 32460Sesaxe * mp_startup() 32560Sesaxe */ 32660Sesaxe chip_bootstrap_cpu(cp); 32760Sesaxe 32860Sesaxe /* 3290Sstevel@tonic-gate * Perform CPC intialization on the new CPU. 3300Sstevel@tonic-gate */ 3310Sstevel@tonic-gate kcpc_hw_init(cp); 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate /* 3340Sstevel@tonic-gate * Allocate virtual addresses for cpu_caddr1 and cpu_caddr2 3350Sstevel@tonic-gate * for each CPU. 3360Sstevel@tonic-gate */ 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate setup_vaddr_for_ppcopy(cp); 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate /* 3410Sstevel@tonic-gate * Allocate space for page directory, stack, tss, gdt and idt. 3420Sstevel@tonic-gate * This assumes that kmem_alloc will return memory which is aligned 3430Sstevel@tonic-gate * to the next higher power of 2 or a page(if size > MAXABIG) 3440Sstevel@tonic-gate * If this assumption goes wrong at any time due to change in 3450Sstevel@tonic-gate * kmem alloc, things may not work as the page directory has to be 3460Sstevel@tonic-gate * page aligned 3470Sstevel@tonic-gate */ 3480Sstevel@tonic-gate if ((tablesp = kmem_zalloc(sizeof (*tablesp), KM_NOSLEEP)) == NULL) 3490Sstevel@tonic-gate panic("mp_startup_init: cpu%d cannot allocate tables", cpun); 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate if ((uintptr_t)tablesp & ~MMU_STD_PAGEMASK) { 3520Sstevel@tonic-gate kmem_free(tablesp, sizeof (struct cpu_tables)); 3530Sstevel@tonic-gate size = sizeof (struct cpu_tables) + MMU_STD_PAGESIZE; 3540Sstevel@tonic-gate tablesp = kmem_zalloc(size, KM_NOSLEEP); 3550Sstevel@tonic-gate tablesp = (struct cpu_tables *) 3560Sstevel@tonic-gate (((uintptr_t)tablesp + MMU_STD_PAGESIZE) & 3570Sstevel@tonic-gate MMU_STD_PAGEMASK); 3580Sstevel@tonic-gate } 3590Sstevel@tonic-gate 3600Sstevel@tonic-gate ntss = cp->cpu_tss = &tablesp->ct_tss; 3611626Srab 3621626Srab if ((tablesp->ct_gdt = kmem_zalloc(PAGESIZE, KM_NOSLEEP)) == NULL) 3631626Srab panic("mp_startup_init: cpu%d cannot allocate GDT", cpun); 3640Sstevel@tonic-gate cp->cpu_gdt = tablesp->ct_gdt; 3650Sstevel@tonic-gate bcopy(CPU->cpu_gdt, cp->cpu_gdt, NGDT * (sizeof (user_desc_t))); 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate #if defined(__amd64) 3680Sstevel@tonic-gate 3690Sstevel@tonic-gate /* 3700Sstevel@tonic-gate * #DF (double fault). 3710Sstevel@tonic-gate */ 3720Sstevel@tonic-gate ntss->tss_ist1 = 3730Sstevel@tonic-gate (uint64_t)&tablesp->ct_stack[sizeof (tablesp->ct_stack)]; 3740Sstevel@tonic-gate 3750Sstevel@tonic-gate #elif defined(__i386) 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate ntss->tss_esp0 = ntss->tss_esp1 = ntss->tss_esp2 = ntss->tss_esp = 3780Sstevel@tonic-gate (uint32_t)&tablesp->ct_stack[sizeof (tablesp->ct_stack)]; 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate ntss->tss_ss0 = ntss->tss_ss1 = ntss->tss_ss2 = ntss->tss_ss = KDS_SEL; 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate ntss->tss_eip = (uint32_t)mp_startup; 3830Sstevel@tonic-gate 3840Sstevel@tonic-gate ntss->tss_cs = KCS_SEL; 3850Sstevel@tonic-gate ntss->tss_fs = KFS_SEL; 3860Sstevel@tonic-gate ntss->tss_gs = KGS_SEL; 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate /* 3890Sstevel@tonic-gate * setup kernel %gs. 3900Sstevel@tonic-gate */ 3910Sstevel@tonic-gate set_usegd(&cp->cpu_gdt[GDT_GS], cp, sizeof (struct cpu) -1, SDT_MEMRWA, 3920Sstevel@tonic-gate SEL_KPL, 0, 1); 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate #endif /* __i386 */ 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate /* 3970Sstevel@tonic-gate * Set I/O bit map offset equal to size of TSS segment limit 3980Sstevel@tonic-gate * for no I/O permission map. This will cause all user I/O 3990Sstevel@tonic-gate * instructions to generate #gp fault. 4000Sstevel@tonic-gate */ 4010Sstevel@tonic-gate ntss->tss_bitmapbase = sizeof (*ntss); 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate /* 4040Sstevel@tonic-gate * setup kernel tss. 4050Sstevel@tonic-gate */ 4060Sstevel@tonic-gate set_syssegd((system_desc_t *)&cp->cpu_gdt[GDT_KTSS], cp->cpu_tss, 4070Sstevel@tonic-gate sizeof (*cp->cpu_tss) -1, SDT_SYSTSS, SEL_KPL); 4080Sstevel@tonic-gate 4090Sstevel@tonic-gate /* 4100Sstevel@tonic-gate * If we have more than one node, each cpu gets a copy of IDT 4110Sstevel@tonic-gate * local to its node. If this is a Pentium box, we use cpu 0's 4120Sstevel@tonic-gate * IDT. cpu 0's IDT has been made read-only to workaround the 4130Sstevel@tonic-gate * cmpxchgl register bug 4140Sstevel@tonic-gate */ 4150Sstevel@tonic-gate cp->cpu_idt = CPU->cpu_idt; 4160Sstevel@tonic-gate if (system_hardware.hd_nodes && x86_type != X86_TYPE_P5) { 4170Sstevel@tonic-gate cp->cpu_idt = kmem_alloc(sizeof (idt0), KM_SLEEP); 4180Sstevel@tonic-gate bcopy(idt0, cp->cpu_idt, sizeof (idt0)); 4190Sstevel@tonic-gate } 4200Sstevel@tonic-gate 4210Sstevel@tonic-gate /* 4220Sstevel@tonic-gate * Get interrupt priority data from cpu 0 4230Sstevel@tonic-gate */ 4240Sstevel@tonic-gate cp->cpu_pri_data = CPU->cpu_pri_data; 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate hat_cpu_online(cp); 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate /* Should remove all entries for the current process/thread here */ 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate /* 4310Sstevel@tonic-gate * Fill up the real mode platter to make it easy for real mode code to 4320Sstevel@tonic-gate * kick it off. This area should really be one passed by boot to kernel 4330Sstevel@tonic-gate * and guaranteed to be below 1MB and aligned to 16 bytes. Should also 4340Sstevel@tonic-gate * have identical physical and virtual address in paged mode. 4350Sstevel@tonic-gate */ 4360Sstevel@tonic-gate real_mode_platter->rm_idt_base = cp->cpu_idt; 4370Sstevel@tonic-gate real_mode_platter->rm_idt_lim = sizeof (idt0) - 1; 4380Sstevel@tonic-gate real_mode_platter->rm_gdt_base = cp->cpu_gdt; 4390Sstevel@tonic-gate real_mode_platter->rm_gdt_lim = sizeof (gdt0) -1; 4400Sstevel@tonic-gate real_mode_platter->rm_pdbr = getcr3(); 4410Sstevel@tonic-gate real_mode_platter->rm_cpu = cpun; 4420Sstevel@tonic-gate real_mode_platter->rm_x86feature = x86_feature; 4430Sstevel@tonic-gate real_mode_platter->rm_cr4 = cr4_value; 4440Sstevel@tonic-gate 4450Sstevel@tonic-gate #if defined(__amd64) 4460Sstevel@tonic-gate if (getcr3() > 0xffffffffUL) 4470Sstevel@tonic-gate panic("Cannot initialize CPUs; kernel's 64-bit page tables\n" 4480Sstevel@tonic-gate "located above 4G in physical memory (@ 0x%llx).", 4490Sstevel@tonic-gate (unsigned long long)getcr3()); 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate /* 4520Sstevel@tonic-gate * Setup pseudo-descriptors for temporary GDT and IDT for use ONLY 4530Sstevel@tonic-gate * by code in real_mode_start(): 4540Sstevel@tonic-gate * 4550Sstevel@tonic-gate * GDT[0]: NULL selector 4560Sstevel@tonic-gate * GDT[1]: 64-bit CS: Long = 1, Present = 1, bits 12, 11 = 1 4570Sstevel@tonic-gate * 4580Sstevel@tonic-gate * Clear the IDT as interrupts will be off and a limit of 0 will cause 4590Sstevel@tonic-gate * the CPU to triple fault and reset on an NMI, seemingly as reasonable 4600Sstevel@tonic-gate * a course of action as any other, though it may cause the entire 4610Sstevel@tonic-gate * platform to reset in some cases... 4620Sstevel@tonic-gate */ 4630Sstevel@tonic-gate real_mode_platter->rm_temp_gdt[0] = 0ULL; 4640Sstevel@tonic-gate real_mode_platter->rm_temp_gdt[TEMPGDT_KCODE64] = 0x20980000000000ULL; 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate real_mode_platter->rm_temp_gdt_lim = (ushort_t) 4670Sstevel@tonic-gate (sizeof (real_mode_platter->rm_temp_gdt) - 1); 4680Sstevel@tonic-gate real_mode_platter->rm_temp_gdt_base = rm_platter_pa + 4690Sstevel@tonic-gate (uint32_t)(&((rm_platter_t *)0)->rm_temp_gdt); 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate real_mode_platter->rm_temp_idt_lim = 0; 4720Sstevel@tonic-gate real_mode_platter->rm_temp_idt_base = 0; 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate /* 4750Sstevel@tonic-gate * Since the CPU needs to jump to protected mode using an identity 4760Sstevel@tonic-gate * mapped address, we need to calculate it here. 4770Sstevel@tonic-gate */ 4780Sstevel@tonic-gate real_mode_platter->rm_longmode64_addr = rm_platter_pa + 4790Sstevel@tonic-gate ((uint32_t)long_mode_64 - (uint32_t)real_mode_start); 4800Sstevel@tonic-gate #endif /* __amd64 */ 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate #ifdef TRAPTRACE 4830Sstevel@tonic-gate /* 4840Sstevel@tonic-gate * If this is a TRAPTRACE kernel, allocate TRAPTRACE buffers for this 4850Sstevel@tonic-gate * CPU. 4860Sstevel@tonic-gate */ 4870Sstevel@tonic-gate ttc->ttc_first = (uintptr_t)kmem_zalloc(trap_trace_bufsize, KM_SLEEP); 4880Sstevel@tonic-gate ttc->ttc_next = ttc->ttc_first; 4890Sstevel@tonic-gate ttc->ttc_limit = ttc->ttc_first + trap_trace_bufsize; 4900Sstevel@tonic-gate #endif 4910Sstevel@tonic-gate 4920Sstevel@tonic-gate /* 4930Sstevel@tonic-gate * Record that we have another CPU. 4940Sstevel@tonic-gate */ 4950Sstevel@tonic-gate mutex_enter(&cpu_lock); 4960Sstevel@tonic-gate /* 4970Sstevel@tonic-gate * Initialize the interrupt threads for this CPU 4980Sstevel@tonic-gate */ 4991455Sandrei cpu_intr_alloc(cp, NINTR_THREADS); 5000Sstevel@tonic-gate /* 5010Sstevel@tonic-gate * Add CPU to list of available CPUs. It'll be on the active list 5020Sstevel@tonic-gate * after mp_startup(). 5030Sstevel@tonic-gate */ 5040Sstevel@tonic-gate cpu_add_unit(cp); 5050Sstevel@tonic-gate mutex_exit(&cpu_lock); 5060Sstevel@tonic-gate } 5070Sstevel@tonic-gate 5080Sstevel@tonic-gate /* 5090Sstevel@tonic-gate * Apply workarounds for known errata, and warn about those that are absent. 5100Sstevel@tonic-gate * 5110Sstevel@tonic-gate * System vendors occasionally create configurations which contain different 5120Sstevel@tonic-gate * revisions of the CPUs that are almost but not exactly the same. At the 5130Sstevel@tonic-gate * time of writing, this meant that their clock rates were the same, their 5140Sstevel@tonic-gate * feature sets were the same, but the required workaround were -not- 5150Sstevel@tonic-gate * necessarily the same. So, this routine is invoked on -every- CPU soon 5160Sstevel@tonic-gate * after starting to make sure that the resulting system contains the most 5170Sstevel@tonic-gate * pessimal set of workarounds needed to cope with *any* of the CPUs in the 5180Sstevel@tonic-gate * system. 5190Sstevel@tonic-gate * 520938Sesaxe * workaround_errata is invoked early in mlsetup() for CPU 0, and in 521938Sesaxe * mp_startup() for all slave CPUs. Slaves process workaround_errata prior 522938Sesaxe * to acknowledging their readiness to the master, so this routine will 523938Sesaxe * never be executed by multiple CPUs in parallel, thus making updates to 524938Sesaxe * global data safe. 525938Sesaxe * 526359Skucharsk * These workarounds are based on Rev 3.57 of the Revision Guide for 527359Skucharsk * AMD Athlon(tm) 64 and AMD Opteron(tm) Processors, August 2005. 5280Sstevel@tonic-gate */ 5290Sstevel@tonic-gate 5300Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_91) 5310Sstevel@tonic-gate int opteron_erratum_91; /* if non-zero -> at least one cpu has it */ 5320Sstevel@tonic-gate #endif 5330Sstevel@tonic-gate 5340Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_93) 5350Sstevel@tonic-gate int opteron_erratum_93; /* if non-zero -> at least one cpu has it */ 5360Sstevel@tonic-gate #endif 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_100) 5390Sstevel@tonic-gate int opteron_erratum_100; /* if non-zero -> at least one cpu has it */ 5400Sstevel@tonic-gate #endif 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_109) 5430Sstevel@tonic-gate int opteron_erratum_109; /* if non-zero -> at least one cpu has it */ 5440Sstevel@tonic-gate #endif 5450Sstevel@tonic-gate 5460Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_121) 5470Sstevel@tonic-gate int opteron_erratum_121; /* if non-zero -> at least one cpu has it */ 5480Sstevel@tonic-gate #endif 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_122) 5510Sstevel@tonic-gate int opteron_erratum_122; /* if non-zero -> at least one cpu has it */ 5520Sstevel@tonic-gate #endif 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_123) 5550Sstevel@tonic-gate int opteron_erratum_123; /* if non-zero -> at least one cpu has it */ 5560Sstevel@tonic-gate #endif 5570Sstevel@tonic-gate 558359Skucharsk #if defined(OPTERON_ERRATUM_131) 559359Skucharsk int opteron_erratum_131; /* if non-zero -> at least one cpu has it */ 560359Skucharsk #endif 5610Sstevel@tonic-gate 562938Sesaxe #if defined(OPTERON_WORKAROUND_6336786) 563938Sesaxe int opteron_workaround_6336786; /* non-zero -> WA relevant and applied */ 564938Sesaxe int opteron_workaround_6336786_UP = 0; /* Not needed for UP */ 565938Sesaxe #endif 566938Sesaxe 5671582Skchow #if defined(OPTERON_WORKAROUND_6323525) 5681582Skchow int opteron_workaround_6323525; /* if non-zero -> at least one cpu has it */ 5691582Skchow #endif 5701582Skchow 5710Sstevel@tonic-gate #define WARNING(cpu, n) \ 5720Sstevel@tonic-gate cmn_err(CE_WARN, "cpu%d: no workaround for erratum %d", \ 5730Sstevel@tonic-gate (cpu)->cpu_id, (n)) 5740Sstevel@tonic-gate 5750Sstevel@tonic-gate uint_t 5760Sstevel@tonic-gate workaround_errata(struct cpu *cpu) 5770Sstevel@tonic-gate { 5780Sstevel@tonic-gate uint_t missing = 0; 5790Sstevel@tonic-gate 5800Sstevel@tonic-gate ASSERT(cpu == CPU); 5810Sstevel@tonic-gate 5820Sstevel@tonic-gate /*LINTED*/ 5830Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 88) > 0) { 5840Sstevel@tonic-gate /* 5850Sstevel@tonic-gate * SWAPGS May Fail To Read Correct GS Base 5860Sstevel@tonic-gate */ 5870Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_88) 5880Sstevel@tonic-gate /* 5890Sstevel@tonic-gate * The workaround is an mfence in the relevant assembler code 5900Sstevel@tonic-gate */ 5910Sstevel@tonic-gate #else 5920Sstevel@tonic-gate WARNING(cpu, 88); 5930Sstevel@tonic-gate missing++; 5940Sstevel@tonic-gate #endif 5950Sstevel@tonic-gate } 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 91) > 0) { 5980Sstevel@tonic-gate /* 5990Sstevel@tonic-gate * Software Prefetches May Report A Page Fault 6000Sstevel@tonic-gate */ 6010Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_91) 6020Sstevel@tonic-gate /* 6030Sstevel@tonic-gate * fix is in trap.c 6040Sstevel@tonic-gate */ 6050Sstevel@tonic-gate opteron_erratum_91++; 6060Sstevel@tonic-gate #else 6070Sstevel@tonic-gate WARNING(cpu, 91); 6080Sstevel@tonic-gate missing++; 6090Sstevel@tonic-gate #endif 6100Sstevel@tonic-gate } 6110Sstevel@tonic-gate 6120Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 93) > 0) { 6130Sstevel@tonic-gate /* 6140Sstevel@tonic-gate * RSM Auto-Halt Restart Returns to Incorrect RIP 6150Sstevel@tonic-gate */ 6160Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_93) 6170Sstevel@tonic-gate /* 6180Sstevel@tonic-gate * fix is in trap.c 6190Sstevel@tonic-gate */ 6200Sstevel@tonic-gate opteron_erratum_93++; 6210Sstevel@tonic-gate #else 6220Sstevel@tonic-gate WARNING(cpu, 93); 6230Sstevel@tonic-gate missing++; 6240Sstevel@tonic-gate #endif 6250Sstevel@tonic-gate } 6260Sstevel@tonic-gate 6270Sstevel@tonic-gate /*LINTED*/ 6280Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 95) > 0) { 6290Sstevel@tonic-gate /* 6300Sstevel@tonic-gate * RET Instruction May Return to Incorrect EIP 6310Sstevel@tonic-gate */ 6320Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_95) 6330Sstevel@tonic-gate #if defined(_LP64) 6340Sstevel@tonic-gate /* 6350Sstevel@tonic-gate * Workaround this by ensuring that 32-bit user code and 6360Sstevel@tonic-gate * 64-bit kernel code never occupy the same address 6370Sstevel@tonic-gate * range mod 4G. 6380Sstevel@tonic-gate */ 6390Sstevel@tonic-gate if (_userlimit32 > 0xc0000000ul) 6400Sstevel@tonic-gate *(uintptr_t *)&_userlimit32 = 0xc0000000ul; 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate /*LINTED*/ 6430Sstevel@tonic-gate ASSERT((uint32_t)COREHEAP_BASE == 0xc0000000u); 6440Sstevel@tonic-gate #endif /* _LP64 */ 6450Sstevel@tonic-gate #else 6460Sstevel@tonic-gate WARNING(cpu, 95); 6470Sstevel@tonic-gate missing++; 6480Sstevel@tonic-gate #endif /* OPTERON_ERRATUM_95 */ 6490Sstevel@tonic-gate } 6500Sstevel@tonic-gate 6510Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 100) > 0) { 6520Sstevel@tonic-gate /* 6530Sstevel@tonic-gate * Compatibility Mode Branches Transfer to Illegal Address 6540Sstevel@tonic-gate */ 6550Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_100) 6560Sstevel@tonic-gate /* 6570Sstevel@tonic-gate * fix is in trap.c 6580Sstevel@tonic-gate */ 6590Sstevel@tonic-gate opteron_erratum_100++; 6600Sstevel@tonic-gate #else 6610Sstevel@tonic-gate WARNING(cpu, 100); 6620Sstevel@tonic-gate missing++; 6630Sstevel@tonic-gate #endif 6640Sstevel@tonic-gate } 6650Sstevel@tonic-gate 6660Sstevel@tonic-gate /*LINTED*/ 6670Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 108) > 0) { 6680Sstevel@tonic-gate /* 6690Sstevel@tonic-gate * CPUID Instruction May Return Incorrect Model Number In 6700Sstevel@tonic-gate * Some Processors 6710Sstevel@tonic-gate */ 6720Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 6730Sstevel@tonic-gate /* 6740Sstevel@tonic-gate * (Our cpuid-handling code corrects the model number on 6750Sstevel@tonic-gate * those processors) 6760Sstevel@tonic-gate */ 6770Sstevel@tonic-gate #else 6780Sstevel@tonic-gate WARNING(cpu, 108); 6790Sstevel@tonic-gate missing++; 6800Sstevel@tonic-gate #endif 6810Sstevel@tonic-gate } 6820Sstevel@tonic-gate 6830Sstevel@tonic-gate /*LINTED*/ 6840Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 109) > 0) { 6850Sstevel@tonic-gate /* 6860Sstevel@tonic-gate * Certain Reverse REP MOVS May Produce Unpredictable Behaviour 6870Sstevel@tonic-gate */ 6880Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_109) 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate /* workaround is to print a warning to upgrade BIOS */ 691770Skucharsk if (rdmsr(MSR_AMD_PATCHLEVEL) == 0) 6920Sstevel@tonic-gate opteron_erratum_109++; 6930Sstevel@tonic-gate #else 6940Sstevel@tonic-gate WARNING(cpu, 109); 6950Sstevel@tonic-gate missing++; 6960Sstevel@tonic-gate #endif 6970Sstevel@tonic-gate } 6980Sstevel@tonic-gate /*LINTED*/ 6990Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 121) > 0) { 7000Sstevel@tonic-gate /* 7010Sstevel@tonic-gate * Sequential Execution Across Non_Canonical Boundary Caused 7020Sstevel@tonic-gate * Processor Hang 7030Sstevel@tonic-gate */ 7040Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_121) 7050Sstevel@tonic-gate static int lma; 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate if (opteron_erratum_121) 7080Sstevel@tonic-gate opteron_erratum_121++; 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate /* 7110Sstevel@tonic-gate * Erratum 121 is only present in long (64 bit) mode. 7120Sstevel@tonic-gate * Workaround is to include the page immediately before the 7130Sstevel@tonic-gate * va hole to eliminate the possibility of system hangs due to 7140Sstevel@tonic-gate * sequential execution across the va hole boundary. 7150Sstevel@tonic-gate */ 7160Sstevel@tonic-gate if (lma == 0) { 7170Sstevel@tonic-gate /* 7180Sstevel@tonic-gate * check LMA once: assume all cpus are in long mode 7190Sstevel@tonic-gate * or not. 7200Sstevel@tonic-gate */ 7210Sstevel@tonic-gate lma = 1; 7220Sstevel@tonic-gate 723770Skucharsk if (rdmsr(MSR_AMD_EFER) & AMD_EFER_LMA) { 7240Sstevel@tonic-gate if (hole_start) { 7250Sstevel@tonic-gate hole_start -= PAGESIZE; 7260Sstevel@tonic-gate } else { 7270Sstevel@tonic-gate /* 7280Sstevel@tonic-gate * hole_start not yet initialized by 7290Sstevel@tonic-gate * mmu_init. Initialize hole_start 7300Sstevel@tonic-gate * with value to be subtracted. 7310Sstevel@tonic-gate */ 7320Sstevel@tonic-gate hole_start = PAGESIZE; 7330Sstevel@tonic-gate } 7340Sstevel@tonic-gate opteron_erratum_121++; 7350Sstevel@tonic-gate } 7360Sstevel@tonic-gate } 7370Sstevel@tonic-gate #else 7380Sstevel@tonic-gate WARNING(cpu, 121); 7390Sstevel@tonic-gate missing++; 7400Sstevel@tonic-gate #endif 7410Sstevel@tonic-gate } 7420Sstevel@tonic-gate 7430Sstevel@tonic-gate /*LINTED*/ 7440Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 122) > 0) { 7450Sstevel@tonic-gate /* 7460Sstevel@tonic-gate * TLB Flush Filter May Cause Cohenrency Problem in 7470Sstevel@tonic-gate * Multiprocessor Systems 7480Sstevel@tonic-gate */ 7490Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_122) 7500Sstevel@tonic-gate /* 7510Sstevel@tonic-gate * Erratum 122 is only present in MP configurations (multi-core 7520Sstevel@tonic-gate * or multi-processor). 7530Sstevel@tonic-gate */ 7540Sstevel@tonic-gate 7550Sstevel@tonic-gate if (opteron_erratum_122 || lgrp_plat_node_cnt > 1 || 7560Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu) > 1) { 7570Sstevel@tonic-gate /* disable TLB Flush Filter */ 758770Skucharsk wrmsr(MSR_AMD_HWCR, rdmsr(MSR_AMD_HWCR) | 759770Skucharsk (uint64_t)(uintptr_t)AMD_HWCR_FFDIS); 7600Sstevel@tonic-gate opteron_erratum_122++; 7610Sstevel@tonic-gate } 7620Sstevel@tonic-gate 7630Sstevel@tonic-gate #else 7640Sstevel@tonic-gate WARNING(cpu, 122); 7650Sstevel@tonic-gate missing++; 7660Sstevel@tonic-gate #endif 7670Sstevel@tonic-gate } 768302Skchow 769302Skchow #if defined(OPTERON_ERRATUM_123) 7700Sstevel@tonic-gate /*LINTED*/ 7710Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 123) > 0) { 7720Sstevel@tonic-gate /* 7730Sstevel@tonic-gate * Bypassed Reads May Cause Data Corruption of System Hang in 7740Sstevel@tonic-gate * Dual Core Processors 7750Sstevel@tonic-gate */ 7760Sstevel@tonic-gate /* 7770Sstevel@tonic-gate * Erratum 123 applies only to multi-core cpus. 7780Sstevel@tonic-gate */ 7790Sstevel@tonic-gate 7800Sstevel@tonic-gate if (cpuid_get_ncpu_per_chip(cpu) > 1) { 7810Sstevel@tonic-gate /* workaround is to print a warning to upgrade BIOS */ 782770Skucharsk if (rdmsr(MSR_AMD_PATCHLEVEL) == 0) 7830Sstevel@tonic-gate opteron_erratum_123++; 7840Sstevel@tonic-gate } 785302Skchow } 7860Sstevel@tonic-gate #endif 787359Skucharsk 788359Skucharsk #if defined(OPTERON_ERRATUM_131) 789359Skucharsk /*LINTED*/ 790359Skucharsk if (cpuid_opteron_erratum(cpu, 131) > 0) { 791359Skucharsk /* 792359Skucharsk * Multiprocessor Systems with Four or More Cores May Deadlock 793359Skucharsk * Waiting for a Probe Response 794359Skucharsk */ 795359Skucharsk /* 796359Skucharsk * Erratum 131 applies to any system with four or more cores. 797359Skucharsk */ 798359Skucharsk if ((opteron_erratum_131 == 0) && ((lgrp_plat_node_cnt * 799359Skucharsk cpuid_get_ncpu_per_chip(cpu)) >= 4)) { 800359Skucharsk /* 801359Skucharsk * Workaround is to print a warning to upgrade 802359Skucharsk * the BIOS 803359Skucharsk */ 804770Skucharsk if (!(rdmsr(MSR_AMD_NB_CFG) & AMD_NB_CFG_SRQ_HEARTBEAT)) 805359Skucharsk opteron_erratum_131++; 806359Skucharsk } 807938Sesaxe } 808359Skucharsk #endif 809938Sesaxe 810938Sesaxe #if defined(OPTERON_WORKAROUND_6336786) 811938Sesaxe /* 812938Sesaxe * This isn't really erratum, but for convenience the 813938Sesaxe * detection/workaround code lives here and in cpuid_opteron_erratum. 814938Sesaxe */ 815938Sesaxe if (cpuid_opteron_erratum(cpu, 6336786) > 0) { 816938Sesaxe int node; 817938Sesaxe uint8_t data; 818938Sesaxe 819938Sesaxe /* 820938Sesaxe * Disable C1-Clock ramping on multi-core/multi-processor 821938Sesaxe * K8 platforms to guard against TSC drift. 822938Sesaxe */ 823938Sesaxe if (opteron_workaround_6336786) { 824938Sesaxe opteron_workaround_6336786++; 825938Sesaxe } else if ((lgrp_plat_node_cnt * 826938Sesaxe cpuid_get_ncpu_per_chip(cpu) >= 2) || 827938Sesaxe opteron_workaround_6336786_UP) { 828938Sesaxe for (node = 0; node < lgrp_plat_node_cnt; node++) { 829938Sesaxe /* 830938Sesaxe * Clear PMM7[1:0] (function 3, offset 0x87) 831938Sesaxe * Northbridge device is the node id + 24. 832938Sesaxe */ 833938Sesaxe data = pci_getb_func(0, node + 24, 3, 0x87); 834938Sesaxe data &= 0xFC; 835938Sesaxe pci_putb_func(0, node + 24, 3, 0x87, data); 836938Sesaxe } 837938Sesaxe opteron_workaround_6336786++; 838938Sesaxe } 839359Skucharsk } 840938Sesaxe #endif 8411582Skchow 8421582Skchow #if defined(OPTERON_WORKAROUND_6323525) 8431582Skchow /*LINTED*/ 8441582Skchow /* 8451582Skchow * Mutex primitives don't work as expected. 8461582Skchow */ 8471582Skchow if (cpuid_opteron_erratum(cpu, 6323525) > 0) { 8481582Skchow 8491582Skchow /* 8501582Skchow * problem only occurs with 2 or more cores. If bit in 8511582Skchow * MSR_BU_CFG set, then not applicable. The workaround 8521582Skchow * is to patch the semaphone routines with the lfence 8531582Skchow * instruction to provide necessary load memory barrier with 8541582Skchow * possible subsequent read-modify-write ops. 8551582Skchow * 8561582Skchow * It is too early in boot to call the patch routine so 8571582Skchow * set erratum variable to be done in startup_end(). 8581582Skchow */ 8591582Skchow if (opteron_workaround_6323525) { 8601582Skchow opteron_workaround_6323525++; 8611582Skchow } else if ((x86_feature & X86_SSE2) && ((lgrp_plat_node_cnt * 8621582Skchow cpuid_get_ncpu_per_chip(cpu)) >= 2)) { 8631582Skchow if ((xrdmsr(MSR_BU_CFG) & 0x02) == 0) 8641582Skchow opteron_workaround_6323525++; 8651582Skchow } 8661582Skchow } 8671582Skchow #endif 8680Sstevel@tonic-gate return (missing); 8690Sstevel@tonic-gate } 8700Sstevel@tonic-gate 8710Sstevel@tonic-gate void 8720Sstevel@tonic-gate workaround_errata_end() 8730Sstevel@tonic-gate { 8740Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_109) 8750Sstevel@tonic-gate if (opteron_erratum_109) { 876359Skucharsk cmn_err(CE_WARN, 877359Skucharsk "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)" 878359Skucharsk " processor\nerratum 109 was not detected; updating your" 879359Skucharsk " system's BIOS to a version\ncontaining this" 880359Skucharsk " microcode patch is HIGHLY recommended or erroneous" 881359Skucharsk " system\noperation may occur.\n"); 8820Sstevel@tonic-gate } 883359Skucharsk #endif /* OPTERON_ERRATUM_109 */ 8840Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_123) 8850Sstevel@tonic-gate if (opteron_erratum_123) { 886359Skucharsk cmn_err(CE_WARN, 887359Skucharsk "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)" 888359Skucharsk " processor\nerratum 123 was not detected; updating your" 889359Skucharsk " system's BIOS to a version\ncontaining this" 890359Skucharsk " microcode patch is HIGHLY recommended or erroneous" 891359Skucharsk " system\noperation may occur.\n"); 8920Sstevel@tonic-gate } 893359Skucharsk #endif /* OPTERON_ERRATUM_123 */ 894359Skucharsk #if defined(OPTERON_ERRATUM_131) 895359Skucharsk if (opteron_erratum_131) { 896359Skucharsk cmn_err(CE_WARN, 897359Skucharsk "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)" 898359Skucharsk " processor\nerratum 131 was not detected; updating your" 899359Skucharsk " system's BIOS to a version\ncontaining this" 900359Skucharsk " microcode patch is HIGHLY recommended or erroneous" 901359Skucharsk " system\noperation may occur.\n"); 902359Skucharsk } 903359Skucharsk #endif /* OPTERON_ERRATUM_131 */ 9040Sstevel@tonic-gate } 9050Sstevel@tonic-gate 9060Sstevel@tonic-gate static ushort_t *mp_map_warm_reset_vector(); 9070Sstevel@tonic-gate static void mp_unmap_warm_reset_vector(ushort_t *warm_reset_vector); 9080Sstevel@tonic-gate 9090Sstevel@tonic-gate /*ARGSUSED*/ 9100Sstevel@tonic-gate void 9110Sstevel@tonic-gate start_other_cpus(int cprboot) 9120Sstevel@tonic-gate { 9130Sstevel@tonic-gate unsigned who; 9141389Sdmick int cpuid = 0; 9150Sstevel@tonic-gate int delays = 0; 9160Sstevel@tonic-gate int started_cpu; 9170Sstevel@tonic-gate ushort_t *warm_reset_vector = NULL; 9180Sstevel@tonic-gate extern int procset; 9190Sstevel@tonic-gate 9200Sstevel@tonic-gate /* 9210Sstevel@tonic-gate * Initialize our own cpu_info. 9220Sstevel@tonic-gate */ 9230Sstevel@tonic-gate init_cpu_info(CPU); 9240Sstevel@tonic-gate 9250Sstevel@tonic-gate /* 9260Sstevel@tonic-gate * Initialize our syscall handlers 9270Sstevel@tonic-gate */ 9280Sstevel@tonic-gate init_cpu_syscall(CPU); 9290Sstevel@tonic-gate 9300Sstevel@tonic-gate /* 9310Sstevel@tonic-gate * if only 1 cpu or not using MP, skip the rest of this 9320Sstevel@tonic-gate */ 9330Sstevel@tonic-gate if (!(mp_cpus & ~(1 << cpuid)) || use_mp == 0) { 9340Sstevel@tonic-gate if (use_mp == 0) 9350Sstevel@tonic-gate cmn_err(CE_CONT, "?***** Not in MP mode\n"); 9360Sstevel@tonic-gate goto done; 9370Sstevel@tonic-gate } 9380Sstevel@tonic-gate 9390Sstevel@tonic-gate /* 9400Sstevel@tonic-gate * perform such initialization as is needed 9410Sstevel@tonic-gate * to be able to take CPUs on- and off-line. 9420Sstevel@tonic-gate */ 9430Sstevel@tonic-gate cpu_pause_init(); 9440Sstevel@tonic-gate 9450Sstevel@tonic-gate xc_init(); /* initialize processor crosscalls */ 9460Sstevel@tonic-gate 9470Sstevel@tonic-gate /* 9480Sstevel@tonic-gate * Copy the real mode code at "real_mode_start" to the 9490Sstevel@tonic-gate * page at rm_platter_va. 9500Sstevel@tonic-gate */ 9510Sstevel@tonic-gate warm_reset_vector = mp_map_warm_reset_vector(); 9520Sstevel@tonic-gate if (warm_reset_vector == NULL) 9530Sstevel@tonic-gate goto done; 9540Sstevel@tonic-gate 9550Sstevel@tonic-gate bcopy((caddr_t)real_mode_start, 9560Sstevel@tonic-gate (caddr_t)((rm_platter_t *)rm_platter_va)->rm_code, 9570Sstevel@tonic-gate (size_t)real_mode_end - (size_t)real_mode_start); 9580Sstevel@tonic-gate 9590Sstevel@tonic-gate flushes_require_xcalls = 1; 9600Sstevel@tonic-gate 9610Sstevel@tonic-gate affinity_set(CPU_CURRENT); 9620Sstevel@tonic-gate 9630Sstevel@tonic-gate for (who = 0; who < NCPU; who++) { 9640Sstevel@tonic-gate if (who == cpuid) 9650Sstevel@tonic-gate continue; 9660Sstevel@tonic-gate 9670Sstevel@tonic-gate if ((mp_cpus & (1 << who)) == 0) 9680Sstevel@tonic-gate continue; 9690Sstevel@tonic-gate 9700Sstevel@tonic-gate mp_startup_init(who); 9710Sstevel@tonic-gate started_cpu = 1; 9720Sstevel@tonic-gate (*cpu_startf)(who, rm_platter_pa); 9730Sstevel@tonic-gate 9740Sstevel@tonic-gate while ((procset & (1 << who)) == 0) { 9750Sstevel@tonic-gate 9760Sstevel@tonic-gate delay(1); 9770Sstevel@tonic-gate if (++delays > (20 * hz)) { 9780Sstevel@tonic-gate 9790Sstevel@tonic-gate cmn_err(CE_WARN, 9800Sstevel@tonic-gate "cpu%d failed to start", who); 9810Sstevel@tonic-gate 9820Sstevel@tonic-gate mutex_enter(&cpu_lock); 9830Sstevel@tonic-gate cpu[who]->cpu_flags = 0; 984414Skchow cpu_vm_data_destroy(cpu[who]); 9850Sstevel@tonic-gate cpu_del_unit(who); 9860Sstevel@tonic-gate mutex_exit(&cpu_lock); 9870Sstevel@tonic-gate 9880Sstevel@tonic-gate started_cpu = 0; 9890Sstevel@tonic-gate break; 9900Sstevel@tonic-gate } 9910Sstevel@tonic-gate } 9920Sstevel@tonic-gate if (!started_cpu) 9930Sstevel@tonic-gate continue; 9940Sstevel@tonic-gate if (tsc_gethrtime_enable) 9950Sstevel@tonic-gate tsc_sync_master(who); 9960Sstevel@tonic-gate 9970Sstevel@tonic-gate 9980Sstevel@tonic-gate if (dtrace_cpu_init != NULL) { 9990Sstevel@tonic-gate /* 10000Sstevel@tonic-gate * DTrace CPU initialization expects cpu_lock 10010Sstevel@tonic-gate * to be held. 10020Sstevel@tonic-gate */ 10030Sstevel@tonic-gate mutex_enter(&cpu_lock); 10040Sstevel@tonic-gate (*dtrace_cpu_init)(who); 10050Sstevel@tonic-gate mutex_exit(&cpu_lock); 10060Sstevel@tonic-gate } 10070Sstevel@tonic-gate } 10080Sstevel@tonic-gate 10090Sstevel@tonic-gate affinity_clear(); 10100Sstevel@tonic-gate 10110Sstevel@tonic-gate for (who = 0; who < NCPU; who++) { 10120Sstevel@tonic-gate if (who == cpuid) 10130Sstevel@tonic-gate continue; 10140Sstevel@tonic-gate 10150Sstevel@tonic-gate if (!(procset & (1 << who))) 10160Sstevel@tonic-gate continue; 10170Sstevel@tonic-gate 10180Sstevel@tonic-gate while (!(cpu_ready_set & (1 << who))) 10190Sstevel@tonic-gate delay(1); 10200Sstevel@tonic-gate } 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate done: 10230Sstevel@tonic-gate workaround_errata_end(); 10240Sstevel@tonic-gate 10250Sstevel@tonic-gate if (warm_reset_vector != NULL) 10260Sstevel@tonic-gate mp_unmap_warm_reset_vector(warm_reset_vector); 10270Sstevel@tonic-gate hat_unload(kas.a_hat, (caddr_t)(uintptr_t)rm_platter_pa, MMU_PAGESIZE, 10280Sstevel@tonic-gate HAT_UNLOAD); 1029*1642Sgavinm 1030*1642Sgavinm cmi_post_mpstartup(); 10310Sstevel@tonic-gate } 10320Sstevel@tonic-gate 10330Sstevel@tonic-gate /* 10340Sstevel@tonic-gate * Dummy functions - no i86pc platforms support dynamic cpu allocation. 10350Sstevel@tonic-gate */ 10360Sstevel@tonic-gate /*ARGSUSED*/ 10370Sstevel@tonic-gate int 10380Sstevel@tonic-gate mp_cpu_configure(int cpuid) 10390Sstevel@tonic-gate { 10400Sstevel@tonic-gate return (ENOTSUP); /* not supported */ 10410Sstevel@tonic-gate } 10420Sstevel@tonic-gate 10430Sstevel@tonic-gate /*ARGSUSED*/ 10440Sstevel@tonic-gate int 10450Sstevel@tonic-gate mp_cpu_unconfigure(int cpuid) 10460Sstevel@tonic-gate { 10470Sstevel@tonic-gate return (ENOTSUP); /* not supported */ 10480Sstevel@tonic-gate } 10490Sstevel@tonic-gate 10500Sstevel@tonic-gate /* 10510Sstevel@tonic-gate * Startup function for 'other' CPUs (besides boot cpu). 10521482Ssethg * Called from real_mode_start (after *ap_mlsetup). 10531251Skchow * 10541251Skchow * WARNING: until CPU_READY is set, mp_startup and routines called by 10551251Skchow * mp_startup should not call routines (e.g. kmem_free) that could call 10561251Skchow * hat_unload which requires CPU_READY to be set. 10570Sstevel@tonic-gate */ 10580Sstevel@tonic-gate void 10590Sstevel@tonic-gate mp_startup(void) 10600Sstevel@tonic-gate { 10610Sstevel@tonic-gate struct cpu *cp = CPU; 10620Sstevel@tonic-gate extern int procset; 10630Sstevel@tonic-gate uint_t new_x86_feature; 10640Sstevel@tonic-gate 10650Sstevel@tonic-gate new_x86_feature = cpuid_pass1(cp); 10660Sstevel@tonic-gate 10670Sstevel@tonic-gate /* 10680Sstevel@tonic-gate * We need to Sync MTRR with cpu0's MTRR. We have to do 10690Sstevel@tonic-gate * this with interrupts disabled. 10700Sstevel@tonic-gate */ 10710Sstevel@tonic-gate if (x86_feature & X86_MTRR) 10720Sstevel@tonic-gate mtrr_sync(); 10730Sstevel@tonic-gate 10740Sstevel@tonic-gate /* 10750Sstevel@tonic-gate * Initialize this CPU's syscall handlers 10760Sstevel@tonic-gate */ 10770Sstevel@tonic-gate init_cpu_syscall(cp); 10780Sstevel@tonic-gate 10790Sstevel@tonic-gate /* 10800Sstevel@tonic-gate * Enable interrupts with spl set to LOCK_LEVEL. LOCK_LEVEL is the 10810Sstevel@tonic-gate * highest level at which a routine is permitted to block on 10820Sstevel@tonic-gate * an adaptive mutex (allows for cpu poke interrupt in case 10830Sstevel@tonic-gate * the cpu is blocked on a mutex and halts). Setting LOCK_LEVEL blocks 10840Sstevel@tonic-gate * device interrupts that may end up in the hat layer issuing cross 10850Sstevel@tonic-gate * calls before CPU_READY is set. 10860Sstevel@tonic-gate */ 10870Sstevel@tonic-gate (void) splx(ipltospl(LOCK_LEVEL)); 10880Sstevel@tonic-gate 10890Sstevel@tonic-gate /* 10900Sstevel@tonic-gate * Do a sanity check to make sure this new CPU is a sane thing 10910Sstevel@tonic-gate * to add to the collection of processors running this system. 10920Sstevel@tonic-gate * 10930Sstevel@tonic-gate * XXX Clearly this needs to get more sophisticated, if x86 10940Sstevel@tonic-gate * systems start to get built out of heterogenous CPUs; as is 10950Sstevel@tonic-gate * likely to happen once the number of processors in a configuration 10960Sstevel@tonic-gate * gets large enough. 10970Sstevel@tonic-gate */ 10980Sstevel@tonic-gate if ((x86_feature & new_x86_feature) != x86_feature) { 10990Sstevel@tonic-gate cmn_err(CE_CONT, "?cpu%d: %b\n", 11000Sstevel@tonic-gate cp->cpu_id, new_x86_feature, FMT_X86_FEATURE); 11010Sstevel@tonic-gate cmn_err(CE_WARN, "cpu%d feature mismatch", cp->cpu_id); 11020Sstevel@tonic-gate } 11030Sstevel@tonic-gate 11040Sstevel@tonic-gate /* 11050Sstevel@tonic-gate * We could be more sophisticated here, and just mark the CPU 11060Sstevel@tonic-gate * as "faulted" but at this point we'll opt for the easier 11070Sstevel@tonic-gate * answer of dieing horribly. Provided the boot cpu is ok, 11080Sstevel@tonic-gate * the system can be recovered by booting with use_mp set to zero. 11090Sstevel@tonic-gate */ 11100Sstevel@tonic-gate if (workaround_errata(cp) != 0) 11110Sstevel@tonic-gate panic("critical workaround(s) missing for cpu%d", cp->cpu_id); 11120Sstevel@tonic-gate 11130Sstevel@tonic-gate cpuid_pass2(cp); 11140Sstevel@tonic-gate cpuid_pass3(cp); 11150Sstevel@tonic-gate (void) cpuid_pass4(cp); 11160Sstevel@tonic-gate 11170Sstevel@tonic-gate init_cpu_info(cp); 11180Sstevel@tonic-gate 11190Sstevel@tonic-gate mutex_enter(&cpu_lock); 11200Sstevel@tonic-gate procset |= 1 << cp->cpu_id; 11210Sstevel@tonic-gate mutex_exit(&cpu_lock); 11220Sstevel@tonic-gate 11230Sstevel@tonic-gate if (tsc_gethrtime_enable) 11240Sstevel@tonic-gate tsc_sync_slave(); 11250Sstevel@tonic-gate 11260Sstevel@tonic-gate mutex_enter(&cpu_lock); 11270Sstevel@tonic-gate /* 11280Sstevel@tonic-gate * It's unfortunate that chip_cpu_init() has to be called here. 11290Sstevel@tonic-gate * It really belongs in cpu_add_unit(), but unfortunately it is 11300Sstevel@tonic-gate * dependent on the cpuid probing, which must be done in the 11310Sstevel@tonic-gate * context of the current CPU. Care must be taken on x86 to ensure 11320Sstevel@tonic-gate * that mp_startup can safely block even though chip_cpu_init() and 11330Sstevel@tonic-gate * cpu_add_active() have not yet been called. 11340Sstevel@tonic-gate */ 11350Sstevel@tonic-gate chip_cpu_init(cp); 11360Sstevel@tonic-gate chip_cpu_startup(cp); 11370Sstevel@tonic-gate 11380Sstevel@tonic-gate cp->cpu_flags |= CPU_RUNNING | CPU_READY | CPU_ENABLE | CPU_EXISTS; 11390Sstevel@tonic-gate cpu_add_active(cp); 11400Sstevel@tonic-gate mutex_exit(&cpu_lock); 11410Sstevel@tonic-gate 11421251Skchow add_cpunode2devtree(cp->cpu_id, cp->cpu_m.mcpu_cpi); 11431251Skchow 11441482Ssethg /* The base spl should still be at LOCK LEVEL here */ 11451482Ssethg ASSERT(cp->cpu_base_spl == ipltospl(LOCK_LEVEL)); 11461482Ssethg set_base_spl(); /* Restore the spl to its proper value */ 11471482Ssethg 11480Sstevel@tonic-gate (void) spl0(); /* enable interrupts */ 11490Sstevel@tonic-gate 11501414Scindi /* 11511414Scindi * Set up the CPU module for this CPU. This can't be done before 11521414Scindi * this CPU is made CPU_READY, because we may (in heterogeneous systems) 11531414Scindi * need to go load another CPU module. The act of attempting to load 11541414Scindi * a module may trigger a cross-call, which will ASSERT unless this 11551414Scindi * cpu is CPU_READY. 11561414Scindi */ 11571414Scindi cmi_init(); 11581414Scindi 11591414Scindi if (x86_feature & X86_MCA) 11601414Scindi cmi_mca_init(); 11611414Scindi 11620Sstevel@tonic-gate if (boothowto & RB_DEBUG) 11630Sstevel@tonic-gate kdi_dvec_cpu_init(cp); 11640Sstevel@tonic-gate 11650Sstevel@tonic-gate /* 11660Sstevel@tonic-gate * Setting the bit in cpu_ready_set must be the last operation in 11670Sstevel@tonic-gate * processor initialization; the boot CPU will continue to boot once 11680Sstevel@tonic-gate * it sees this bit set for all active CPUs. 11690Sstevel@tonic-gate */ 11700Sstevel@tonic-gate CPUSET_ATOMIC_ADD(cpu_ready_set, cp->cpu_id); 11710Sstevel@tonic-gate 11720Sstevel@tonic-gate /* 11730Sstevel@tonic-gate * Because mp_startup() gets fired off after init() starts, we 11740Sstevel@tonic-gate * can't use the '?' trick to do 'boot -v' printing - so we 11750Sstevel@tonic-gate * always direct the 'cpu .. online' messages to the log. 11760Sstevel@tonic-gate */ 11770Sstevel@tonic-gate cmn_err(CE_CONT, "!cpu%d initialization complete - online\n", 11780Sstevel@tonic-gate cp->cpu_id); 11790Sstevel@tonic-gate 11800Sstevel@tonic-gate /* 11810Sstevel@tonic-gate * Now we are done with the startup thread, so free it up. 11820Sstevel@tonic-gate */ 11830Sstevel@tonic-gate thread_exit(); 11840Sstevel@tonic-gate panic("mp_startup: cannot return"); 11850Sstevel@tonic-gate /*NOTREACHED*/ 11860Sstevel@tonic-gate } 11870Sstevel@tonic-gate 11880Sstevel@tonic-gate 11890Sstevel@tonic-gate /* 11900Sstevel@tonic-gate * Start CPU on user request. 11910Sstevel@tonic-gate */ 11920Sstevel@tonic-gate /* ARGSUSED */ 11930Sstevel@tonic-gate int 11940Sstevel@tonic-gate mp_cpu_start(struct cpu *cp) 11950Sstevel@tonic-gate { 11960Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 11970Sstevel@tonic-gate return (0); 11980Sstevel@tonic-gate } 11990Sstevel@tonic-gate 12000Sstevel@tonic-gate /* 12010Sstevel@tonic-gate * Stop CPU on user request. 12020Sstevel@tonic-gate */ 12030Sstevel@tonic-gate /* ARGSUSED */ 12040Sstevel@tonic-gate int 12050Sstevel@tonic-gate mp_cpu_stop(struct cpu *cp) 12060Sstevel@tonic-gate { 12071389Sdmick extern int cbe_psm_timer_mode; 12080Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 12091389Sdmick 12101389Sdmick /* 12111389Sdmick * If TIMER_PERIODIC mode is used, CPU0 is the one running it; 12121389Sdmick * can't stop it. (This is true only for machines with no TSC.) 12131389Sdmick */ 12141389Sdmick 12151389Sdmick if ((cbe_psm_timer_mode == TIMER_PERIODIC) && (cp->cpu_id == 0)) 12161389Sdmick return (1); 12170Sstevel@tonic-gate 12180Sstevel@tonic-gate return (0); 12190Sstevel@tonic-gate } 12200Sstevel@tonic-gate 12210Sstevel@tonic-gate /* 12220Sstevel@tonic-gate * Power on CPU. 12230Sstevel@tonic-gate */ 12240Sstevel@tonic-gate /* ARGSUSED */ 12250Sstevel@tonic-gate int 12260Sstevel@tonic-gate mp_cpu_poweron(struct cpu *cp) 12270Sstevel@tonic-gate { 12280Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 12290Sstevel@tonic-gate return (ENOTSUP); /* not supported */ 12300Sstevel@tonic-gate } 12310Sstevel@tonic-gate 12320Sstevel@tonic-gate /* 12330Sstevel@tonic-gate * Power off CPU. 12340Sstevel@tonic-gate */ 12350Sstevel@tonic-gate /* ARGSUSED */ 12360Sstevel@tonic-gate int 12370Sstevel@tonic-gate mp_cpu_poweroff(struct cpu *cp) 12380Sstevel@tonic-gate { 12390Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 12400Sstevel@tonic-gate return (ENOTSUP); /* not supported */ 12410Sstevel@tonic-gate } 12420Sstevel@tonic-gate 12430Sstevel@tonic-gate 12440Sstevel@tonic-gate /* 12450Sstevel@tonic-gate * Take the specified CPU out of participation in interrupts. 12460Sstevel@tonic-gate */ 12470Sstevel@tonic-gate int 12480Sstevel@tonic-gate cpu_disable_intr(struct cpu *cp) 12490Sstevel@tonic-gate { 12500Sstevel@tonic-gate if (psm_disable_intr(cp->cpu_id) != DDI_SUCCESS) 12510Sstevel@tonic-gate return (EBUSY); 12520Sstevel@tonic-gate 12530Sstevel@tonic-gate cp->cpu_flags &= ~CPU_ENABLE; 12540Sstevel@tonic-gate return (0); 12550Sstevel@tonic-gate } 12560Sstevel@tonic-gate 12570Sstevel@tonic-gate /* 12580Sstevel@tonic-gate * Allow the specified CPU to participate in interrupts. 12590Sstevel@tonic-gate */ 12600Sstevel@tonic-gate void 12610Sstevel@tonic-gate cpu_enable_intr(struct cpu *cp) 12620Sstevel@tonic-gate { 12630Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 12640Sstevel@tonic-gate cp->cpu_flags |= CPU_ENABLE; 12650Sstevel@tonic-gate psm_enable_intr(cp->cpu_id); 12660Sstevel@tonic-gate } 12670Sstevel@tonic-gate 12680Sstevel@tonic-gate 12690Sstevel@tonic-gate 12700Sstevel@tonic-gate static ushort_t * 12710Sstevel@tonic-gate mp_map_warm_reset_vector() 12720Sstevel@tonic-gate { 12730Sstevel@tonic-gate ushort_t *warm_reset_vector; 12740Sstevel@tonic-gate 12750Sstevel@tonic-gate if (!(warm_reset_vector = (ushort_t *)psm_map_phys(WARM_RESET_VECTOR, 12760Sstevel@tonic-gate sizeof (ushort_t *), PROT_READ|PROT_WRITE))) 12770Sstevel@tonic-gate return (NULL); 12780Sstevel@tonic-gate 12790Sstevel@tonic-gate /* 12800Sstevel@tonic-gate * setup secondary cpu bios boot up vector 12810Sstevel@tonic-gate */ 12820Sstevel@tonic-gate *warm_reset_vector = (ushort_t)((caddr_t) 12830Sstevel@tonic-gate ((struct rm_platter *)rm_platter_va)->rm_code - rm_platter_va 12840Sstevel@tonic-gate + ((ulong_t)rm_platter_va & 0xf)); 12850Sstevel@tonic-gate warm_reset_vector++; 12860Sstevel@tonic-gate *warm_reset_vector = (ushort_t)(rm_platter_pa >> 4); 12870Sstevel@tonic-gate 12880Sstevel@tonic-gate --warm_reset_vector; 12890Sstevel@tonic-gate return (warm_reset_vector); 12900Sstevel@tonic-gate } 12910Sstevel@tonic-gate 12920Sstevel@tonic-gate static void 12930Sstevel@tonic-gate mp_unmap_warm_reset_vector(ushort_t *warm_reset_vector) 12940Sstevel@tonic-gate { 12950Sstevel@tonic-gate psm_unmap_phys((caddr_t)warm_reset_vector, sizeof (ushort_t *)); 12960Sstevel@tonic-gate } 12970Sstevel@tonic-gate 12980Sstevel@tonic-gate void 12990Sstevel@tonic-gate mp_cpu_faulted_enter(struct cpu *cp) 13001414Scindi { 13011414Scindi cmi_faulted_enter(cp); 13021414Scindi } 13030Sstevel@tonic-gate 13040Sstevel@tonic-gate void 13050Sstevel@tonic-gate mp_cpu_faulted_exit(struct cpu *cp) 13061414Scindi { 13071414Scindi cmi_faulted_exit(cp); 13081414Scindi } 13090Sstevel@tonic-gate 13100Sstevel@tonic-gate /* 13110Sstevel@tonic-gate * The following two routines are used as context operators on threads belonging 13120Sstevel@tonic-gate * to processes with a private LDT (see sysi86). Due to the rarity of such 13130Sstevel@tonic-gate * processes, these routines are currently written for best code readability and 13140Sstevel@tonic-gate * organization rather than speed. We could avoid checking x86_feature at every 13150Sstevel@tonic-gate * context switch by installing different context ops, depending on the 13160Sstevel@tonic-gate * x86_feature flags, at LDT creation time -- one for each combination of fast 13170Sstevel@tonic-gate * syscall feature flags. 13180Sstevel@tonic-gate */ 13190Sstevel@tonic-gate 13200Sstevel@tonic-gate /*ARGSUSED*/ 13210Sstevel@tonic-gate void 13220Sstevel@tonic-gate cpu_fast_syscall_disable(void *arg) 13230Sstevel@tonic-gate { 13240Sstevel@tonic-gate if (x86_feature & X86_SEP) 13250Sstevel@tonic-gate cpu_sep_disable(); 13260Sstevel@tonic-gate if (x86_feature & X86_ASYSC) 13270Sstevel@tonic-gate cpu_asysc_disable(); 13280Sstevel@tonic-gate } 13290Sstevel@tonic-gate 13300Sstevel@tonic-gate /*ARGSUSED*/ 13310Sstevel@tonic-gate void 13320Sstevel@tonic-gate cpu_fast_syscall_enable(void *arg) 13330Sstevel@tonic-gate { 13340Sstevel@tonic-gate if (x86_feature & X86_SEP) 13350Sstevel@tonic-gate cpu_sep_enable(); 13360Sstevel@tonic-gate if (x86_feature & X86_ASYSC) 13370Sstevel@tonic-gate cpu_asysc_enable(); 13380Sstevel@tonic-gate } 13390Sstevel@tonic-gate 13400Sstevel@tonic-gate static void 13410Sstevel@tonic-gate cpu_sep_enable(void) 13420Sstevel@tonic-gate { 13430Sstevel@tonic-gate ASSERT(x86_feature & X86_SEP); 13440Sstevel@tonic-gate ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 13450Sstevel@tonic-gate 1346770Skucharsk wrmsr(MSR_INTC_SEP_CS, (uint64_t)(uintptr_t)KCS_SEL); 13470Sstevel@tonic-gate } 13480Sstevel@tonic-gate 13490Sstevel@tonic-gate static void 13500Sstevel@tonic-gate cpu_sep_disable(void) 13510Sstevel@tonic-gate { 13520Sstevel@tonic-gate ASSERT(x86_feature & X86_SEP); 13530Sstevel@tonic-gate ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 13540Sstevel@tonic-gate 13550Sstevel@tonic-gate /* 13560Sstevel@tonic-gate * Setting the SYSENTER_CS_MSR register to 0 causes software executing 13570Sstevel@tonic-gate * the sysenter or sysexit instruction to trigger a #gp fault. 13580Sstevel@tonic-gate */ 1359770Skucharsk wrmsr(MSR_INTC_SEP_CS, 0ULL); 13600Sstevel@tonic-gate } 13610Sstevel@tonic-gate 13620Sstevel@tonic-gate static void 13630Sstevel@tonic-gate cpu_asysc_enable(void) 13640Sstevel@tonic-gate { 13650Sstevel@tonic-gate ASSERT(x86_feature & X86_ASYSC); 13660Sstevel@tonic-gate ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 13670Sstevel@tonic-gate 1368770Skucharsk wrmsr(MSR_AMD_EFER, rdmsr(MSR_AMD_EFER) | 1369770Skucharsk (uint64_t)(uintptr_t)AMD_EFER_SCE); 13700Sstevel@tonic-gate } 13710Sstevel@tonic-gate 13720Sstevel@tonic-gate static void 13730Sstevel@tonic-gate cpu_asysc_disable(void) 13740Sstevel@tonic-gate { 13750Sstevel@tonic-gate ASSERT(x86_feature & X86_ASYSC); 13760Sstevel@tonic-gate ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 13770Sstevel@tonic-gate 13780Sstevel@tonic-gate /* 13790Sstevel@tonic-gate * Turn off the SCE (syscall enable) bit in the EFER register. Software 13800Sstevel@tonic-gate * executing syscall or sysret with this bit off will incur a #ud trap. 13810Sstevel@tonic-gate */ 1382770Skucharsk wrmsr(MSR_AMD_EFER, rdmsr(MSR_AMD_EFER) & 1383770Skucharsk ~((uint64_t)(uintptr_t)AMD_EFER_SCE)); 13840Sstevel@tonic-gate } 1385