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 uint64_t value; 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate kpreempt_disable(); 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate #if defined(__amd64) 1430Sstevel@tonic-gate if (x86_feature & X86_ASYSC) { 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate #if !defined(__lint) 1460Sstevel@tonic-gate /* 1470Sstevel@tonic-gate * The syscall instruction imposes a certain ordering on 1480Sstevel@tonic-gate * segment selectors, so we double-check that ordering 1490Sstevel@tonic-gate * here. 1500Sstevel@tonic-gate */ 1510Sstevel@tonic-gate ASSERT(KDS_SEL == KCS_SEL + 8); 1520Sstevel@tonic-gate ASSERT(UDS_SEL == U32CS_SEL + 8); 1530Sstevel@tonic-gate ASSERT(UCS_SEL == U32CS_SEL + 16); 1540Sstevel@tonic-gate #endif 1550Sstevel@tonic-gate /* 1560Sstevel@tonic-gate * Turn syscall/sysret extensions on. 1570Sstevel@tonic-gate */ 1580Sstevel@tonic-gate cpu_asysc_enable(); 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate /* 1610Sstevel@tonic-gate * Program the magic registers .. 1620Sstevel@tonic-gate */ 1630Sstevel@tonic-gate value = ((uint64_t)(U32CS_SEL << 16 | KCS_SEL)) << 32; 1640Sstevel@tonic-gate wrmsr(MSR_AMD_STAR, &value); 1650Sstevel@tonic-gate value = (uintptr_t)sys_syscall; 1660Sstevel@tonic-gate wrmsr(MSR_AMD_LSTAR, &value); 1670Sstevel@tonic-gate value = (uintptr_t)sys_syscall32; 1680Sstevel@tonic-gate wrmsr(MSR_AMD_CSTAR, &value); 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate /* 1710Sstevel@tonic-gate * This list of flags is masked off the incoming 1720Sstevel@tonic-gate * %rfl when we enter the kernel. 1730Sstevel@tonic-gate */ 1740Sstevel@tonic-gate value = PS_IE | PS_T; 1750Sstevel@tonic-gate wrmsr(MSR_AMD_SFMASK, &value); 1760Sstevel@tonic-gate } 1770Sstevel@tonic-gate #endif 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate /* 1800Sstevel@tonic-gate * On 32-bit kernels, we use sysenter/sysexit because it's too 1810Sstevel@tonic-gate * hard to use syscall/sysret, and it is more portable anyway. 1820Sstevel@tonic-gate * 1830Sstevel@tonic-gate * On 64-bit kernels on Nocona machines, the 32-bit syscall 1840Sstevel@tonic-gate * variant isn't available to 32-bit applications, but sysenter is. 1850Sstevel@tonic-gate */ 1860Sstevel@tonic-gate if (x86_feature & X86_SEP) { 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate #if !defined(__lint) 1890Sstevel@tonic-gate /* 1900Sstevel@tonic-gate * The sysenter instruction imposes a certain ordering on 1910Sstevel@tonic-gate * segment selectors, so we double-check that ordering 1920Sstevel@tonic-gate * here. See "sysenter" in Intel document 245471-012, "IA-32 1930Sstevel@tonic-gate * Intel Architecture Software Developer's Manual Volume 2: 1940Sstevel@tonic-gate * Instruction Set Reference" 1950Sstevel@tonic-gate */ 1960Sstevel@tonic-gate ASSERT(KDS_SEL == KCS_SEL + 8); 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate ASSERT32(UCS_SEL == ((KCS_SEL + 16) | 3)); 1990Sstevel@tonic-gate ASSERT32(UDS_SEL == UCS_SEL + 8); 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate ASSERT64(U32CS_SEL == ((KCS_SEL + 16) | 3)); 2020Sstevel@tonic-gate ASSERT64(UDS_SEL == U32CS_SEL + 8); 2030Sstevel@tonic-gate #endif 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate cpu_sep_enable(); 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate /* 2080Sstevel@tonic-gate * resume() sets this value to the base of the threads stack 2090Sstevel@tonic-gate * via a context handler. 2100Sstevel@tonic-gate */ 2110Sstevel@tonic-gate value = 0; 2120Sstevel@tonic-gate wrmsr(MSR_INTC_SEP_ESP, &value); 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate value = (uintptr_t)sys_sysenter; 2150Sstevel@tonic-gate wrmsr(MSR_INTC_SEP_EIP, &value); 2160Sstevel@tonic-gate } 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate kpreempt_enable(); 2190Sstevel@tonic-gate } 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate /* 2220Sstevel@tonic-gate * Multiprocessor initialization. 2230Sstevel@tonic-gate * 2240Sstevel@tonic-gate * Allocate and initialize the cpu structure, TRAPTRACE buffer, and the 2250Sstevel@tonic-gate * startup and idle threads for the specified CPU. 2260Sstevel@tonic-gate */ 2270Sstevel@tonic-gate static void 2280Sstevel@tonic-gate mp_startup_init(int cpun) 2290Sstevel@tonic-gate { 2300Sstevel@tonic-gate #if defined(__amd64) 2310Sstevel@tonic-gate extern void *long_mode_64(void); 2320Sstevel@tonic-gate #endif /* __amd64 */ 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate struct cpu *cp; 2350Sstevel@tonic-gate struct tss *ntss; 2360Sstevel@tonic-gate kthread_id_t tp; 2370Sstevel@tonic-gate caddr_t sp; 2380Sstevel@tonic-gate int size; 2390Sstevel@tonic-gate proc_t *procp; 2400Sstevel@tonic-gate extern void idle(); 2410Sstevel@tonic-gate extern void init_intr_threads(struct cpu *); 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate struct cpu_tables *tablesp; 2440Sstevel@tonic-gate rm_platter_t *real_mode_platter = (rm_platter_t *)rm_platter_va; 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate #ifdef TRAPTRACE 2470Sstevel@tonic-gate trap_trace_ctl_t *ttc = &trap_trace_ctl[cpun]; 2480Sstevel@tonic-gate #endif 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate ASSERT(cpun < NCPU && cpu[cpun] == NULL); 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate if ((cp = kmem_zalloc(sizeof (*cp), KM_NOSLEEP)) == NULL) { 2530Sstevel@tonic-gate panic("mp_startup_init: cpu%d: " 2540Sstevel@tonic-gate "no memory for cpu structure", cpun); 2550Sstevel@tonic-gate /*NOTREACHED*/ 2560Sstevel@tonic-gate } 2570Sstevel@tonic-gate procp = curthread->t_procp; 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate mutex_enter(&cpu_lock); 2600Sstevel@tonic-gate /* 2610Sstevel@tonic-gate * Initialize the dispatcher first. 2620Sstevel@tonic-gate */ 2630Sstevel@tonic-gate disp_cpu_init(cp); 2640Sstevel@tonic-gate mutex_exit(&cpu_lock); 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate /* 2670Sstevel@tonic-gate * Allocate and initialize the startup thread for this CPU. 2680Sstevel@tonic-gate * Interrupt and process switch stacks get allocated later 2690Sstevel@tonic-gate * when the CPU starts running. 2700Sstevel@tonic-gate */ 2710Sstevel@tonic-gate tp = thread_create(NULL, 0, NULL, NULL, 0, procp, 2720Sstevel@tonic-gate TS_STOPPED, maxclsyspri); 2730Sstevel@tonic-gate 2740Sstevel@tonic-gate /* 2750Sstevel@tonic-gate * Set state to TS_ONPROC since this thread will start running 2760Sstevel@tonic-gate * as soon as the CPU comes online. 2770Sstevel@tonic-gate * 2780Sstevel@tonic-gate * All the other fields of the thread structure are setup by 2790Sstevel@tonic-gate * thread_create(). 2800Sstevel@tonic-gate */ 2810Sstevel@tonic-gate THREAD_ONPROC(tp, cp); 2820Sstevel@tonic-gate tp->t_preempt = 1; 2830Sstevel@tonic-gate tp->t_bound_cpu = cp; 2840Sstevel@tonic-gate tp->t_affinitycnt = 1; 2850Sstevel@tonic-gate tp->t_cpu = cp; 2860Sstevel@tonic-gate tp->t_disp_queue = cp->cpu_disp; 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate /* 2890Sstevel@tonic-gate * Setup thread to start in mp_startup. 2900Sstevel@tonic-gate */ 2910Sstevel@tonic-gate sp = tp->t_stk; 2920Sstevel@tonic-gate tp->t_pc = (uintptr_t)mp_startup; 2930Sstevel@tonic-gate tp->t_sp = (uintptr_t)(sp - MINFRAME); 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate cp->cpu_id = cpun; 2960Sstevel@tonic-gate cp->cpu_self = cp; 2970Sstevel@tonic-gate cp->cpu_mask = 1 << cpun; 2980Sstevel@tonic-gate cp->cpu_thread = tp; 2990Sstevel@tonic-gate cp->cpu_lwp = NULL; 3000Sstevel@tonic-gate cp->cpu_dispthread = tp; 3010Sstevel@tonic-gate cp->cpu_dispatch_pri = DISP_PRIO(tp); 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate /* 3040Sstevel@tonic-gate * Now, initialize per-CPU idle thread for this CPU. 3050Sstevel@tonic-gate */ 3060Sstevel@tonic-gate tp = thread_create(NULL, PAGESIZE, idle, NULL, 0, procp, TS_ONPROC, -1); 3070Sstevel@tonic-gate 3080Sstevel@tonic-gate cp->cpu_idle_thread = tp; 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate tp->t_preempt = 1; 3110Sstevel@tonic-gate tp->t_bound_cpu = cp; 3120Sstevel@tonic-gate tp->t_affinitycnt = 1; 3130Sstevel@tonic-gate tp->t_cpu = cp; 3140Sstevel@tonic-gate tp->t_disp_queue = cp->cpu_disp; 3150Sstevel@tonic-gate 3160Sstevel@tonic-gate /* 31760Sesaxe * Bootstrap the CPU for CMT aware scheduling 31860Sesaxe * The rest of the initialization will happen from 31960Sesaxe * mp_startup() 32060Sesaxe */ 32160Sesaxe chip_bootstrap_cpu(cp); 32260Sesaxe 32360Sesaxe /* 3240Sstevel@tonic-gate * Perform CPC intialization on the new CPU. 3250Sstevel@tonic-gate */ 3260Sstevel@tonic-gate kcpc_hw_init(cp); 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate /* 3290Sstevel@tonic-gate * Allocate virtual addresses for cpu_caddr1 and cpu_caddr2 3300Sstevel@tonic-gate * for each CPU. 3310Sstevel@tonic-gate */ 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate setup_vaddr_for_ppcopy(cp); 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate /* 3360Sstevel@tonic-gate * Allocate space for page directory, stack, tss, gdt and idt. 3370Sstevel@tonic-gate * This assumes that kmem_alloc will return memory which is aligned 3380Sstevel@tonic-gate * to the next higher power of 2 or a page(if size > MAXABIG) 3390Sstevel@tonic-gate * If this assumption goes wrong at any time due to change in 3400Sstevel@tonic-gate * kmem alloc, things may not work as the page directory has to be 3410Sstevel@tonic-gate * page aligned 3420Sstevel@tonic-gate */ 3430Sstevel@tonic-gate if ((tablesp = kmem_zalloc(sizeof (*tablesp), KM_NOSLEEP)) == NULL) 3440Sstevel@tonic-gate panic("mp_startup_init: cpu%d cannot allocate tables", cpun); 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate if ((uintptr_t)tablesp & ~MMU_STD_PAGEMASK) { 3470Sstevel@tonic-gate kmem_free(tablesp, sizeof (struct cpu_tables)); 3480Sstevel@tonic-gate size = sizeof (struct cpu_tables) + MMU_STD_PAGESIZE; 3490Sstevel@tonic-gate tablesp = kmem_zalloc(size, KM_NOSLEEP); 3500Sstevel@tonic-gate tablesp = (struct cpu_tables *) 3510Sstevel@tonic-gate (((uintptr_t)tablesp + MMU_STD_PAGESIZE) & 3520Sstevel@tonic-gate MMU_STD_PAGEMASK); 3530Sstevel@tonic-gate } 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate ntss = cp->cpu_tss = &tablesp->ct_tss; 3560Sstevel@tonic-gate cp->cpu_gdt = tablesp->ct_gdt; 3570Sstevel@tonic-gate bcopy(CPU->cpu_gdt, cp->cpu_gdt, NGDT * (sizeof (user_desc_t))); 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate #if defined(__amd64) 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate /* 3620Sstevel@tonic-gate * #DF (double fault). 3630Sstevel@tonic-gate */ 3640Sstevel@tonic-gate ntss->tss_ist1 = 3650Sstevel@tonic-gate (uint64_t)&tablesp->ct_stack[sizeof (tablesp->ct_stack)]; 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate #elif defined(__i386) 3680Sstevel@tonic-gate 3690Sstevel@tonic-gate ntss->tss_esp0 = ntss->tss_esp1 = ntss->tss_esp2 = ntss->tss_esp = 3700Sstevel@tonic-gate (uint32_t)&tablesp->ct_stack[sizeof (tablesp->ct_stack)]; 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate ntss->tss_ss0 = ntss->tss_ss1 = ntss->tss_ss2 = ntss->tss_ss = KDS_SEL; 3730Sstevel@tonic-gate 3740Sstevel@tonic-gate ntss->tss_eip = (uint32_t)mp_startup; 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate ntss->tss_cs = KCS_SEL; 3770Sstevel@tonic-gate ntss->tss_fs = KFS_SEL; 3780Sstevel@tonic-gate ntss->tss_gs = KGS_SEL; 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate /* 3810Sstevel@tonic-gate * setup kernel %gs. 3820Sstevel@tonic-gate */ 3830Sstevel@tonic-gate set_usegd(&cp->cpu_gdt[GDT_GS], cp, sizeof (struct cpu) -1, SDT_MEMRWA, 3840Sstevel@tonic-gate SEL_KPL, 0, 1); 3850Sstevel@tonic-gate 3860Sstevel@tonic-gate #endif /* __i386 */ 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate /* 3890Sstevel@tonic-gate * Set I/O bit map offset equal to size of TSS segment limit 3900Sstevel@tonic-gate * for no I/O permission map. This will cause all user I/O 3910Sstevel@tonic-gate * instructions to generate #gp fault. 3920Sstevel@tonic-gate */ 3930Sstevel@tonic-gate ntss->tss_bitmapbase = sizeof (*ntss); 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate /* 3960Sstevel@tonic-gate * setup kernel tss. 3970Sstevel@tonic-gate */ 3980Sstevel@tonic-gate set_syssegd((system_desc_t *)&cp->cpu_gdt[GDT_KTSS], cp->cpu_tss, 3990Sstevel@tonic-gate sizeof (*cp->cpu_tss) -1, SDT_SYSTSS, SEL_KPL); 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate /* 4020Sstevel@tonic-gate * If we have more than one node, each cpu gets a copy of IDT 4030Sstevel@tonic-gate * local to its node. If this is a Pentium box, we use cpu 0's 4040Sstevel@tonic-gate * IDT. cpu 0's IDT has been made read-only to workaround the 4050Sstevel@tonic-gate * cmpxchgl register bug 4060Sstevel@tonic-gate */ 4070Sstevel@tonic-gate cp->cpu_idt = CPU->cpu_idt; 4080Sstevel@tonic-gate if (system_hardware.hd_nodes && x86_type != X86_TYPE_P5) { 4090Sstevel@tonic-gate cp->cpu_idt = kmem_alloc(sizeof (idt0), KM_SLEEP); 4100Sstevel@tonic-gate bcopy(idt0, cp->cpu_idt, sizeof (idt0)); 4110Sstevel@tonic-gate } 4120Sstevel@tonic-gate 4130Sstevel@tonic-gate /* 4140Sstevel@tonic-gate * Get interrupt priority data from cpu 0 4150Sstevel@tonic-gate */ 4160Sstevel@tonic-gate cp->cpu_pri_data = CPU->cpu_pri_data; 4170Sstevel@tonic-gate 4180Sstevel@tonic-gate hat_cpu_online(cp); 4190Sstevel@tonic-gate 4200Sstevel@tonic-gate /* Should remove all entries for the current process/thread here */ 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate /* 4230Sstevel@tonic-gate * Fill up the real mode platter to make it easy for real mode code to 4240Sstevel@tonic-gate * kick it off. This area should really be one passed by boot to kernel 4250Sstevel@tonic-gate * and guaranteed to be below 1MB and aligned to 16 bytes. Should also 4260Sstevel@tonic-gate * have identical physical and virtual address in paged mode. 4270Sstevel@tonic-gate */ 4280Sstevel@tonic-gate real_mode_platter->rm_idt_base = cp->cpu_idt; 4290Sstevel@tonic-gate real_mode_platter->rm_idt_lim = sizeof (idt0) - 1; 4300Sstevel@tonic-gate real_mode_platter->rm_gdt_base = cp->cpu_gdt; 4310Sstevel@tonic-gate real_mode_platter->rm_gdt_lim = sizeof (gdt0) -1; 4320Sstevel@tonic-gate real_mode_platter->rm_pdbr = getcr3(); 4330Sstevel@tonic-gate real_mode_platter->rm_cpu = cpun; 4340Sstevel@tonic-gate real_mode_platter->rm_x86feature = x86_feature; 4350Sstevel@tonic-gate real_mode_platter->rm_cr4 = cr4_value; 4360Sstevel@tonic-gate 4370Sstevel@tonic-gate #if defined(__amd64) 4380Sstevel@tonic-gate if (getcr3() > 0xffffffffUL) 4390Sstevel@tonic-gate panic("Cannot initialize CPUs; kernel's 64-bit page tables\n" 4400Sstevel@tonic-gate "located above 4G in physical memory (@ 0x%llx).", 4410Sstevel@tonic-gate (unsigned long long)getcr3()); 4420Sstevel@tonic-gate 4430Sstevel@tonic-gate /* 4440Sstevel@tonic-gate * Setup pseudo-descriptors for temporary GDT and IDT for use ONLY 4450Sstevel@tonic-gate * by code in real_mode_start(): 4460Sstevel@tonic-gate * 4470Sstevel@tonic-gate * GDT[0]: NULL selector 4480Sstevel@tonic-gate * GDT[1]: 64-bit CS: Long = 1, Present = 1, bits 12, 11 = 1 4490Sstevel@tonic-gate * 4500Sstevel@tonic-gate * Clear the IDT as interrupts will be off and a limit of 0 will cause 4510Sstevel@tonic-gate * the CPU to triple fault and reset on an NMI, seemingly as reasonable 4520Sstevel@tonic-gate * a course of action as any other, though it may cause the entire 4530Sstevel@tonic-gate * platform to reset in some cases... 4540Sstevel@tonic-gate */ 4550Sstevel@tonic-gate real_mode_platter->rm_temp_gdt[0] = 0ULL; 4560Sstevel@tonic-gate real_mode_platter->rm_temp_gdt[TEMPGDT_KCODE64] = 0x20980000000000ULL; 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate real_mode_platter->rm_temp_gdt_lim = (ushort_t) 4590Sstevel@tonic-gate (sizeof (real_mode_platter->rm_temp_gdt) - 1); 4600Sstevel@tonic-gate real_mode_platter->rm_temp_gdt_base = rm_platter_pa + 4610Sstevel@tonic-gate (uint32_t)(&((rm_platter_t *)0)->rm_temp_gdt); 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate real_mode_platter->rm_temp_idt_lim = 0; 4640Sstevel@tonic-gate real_mode_platter->rm_temp_idt_base = 0; 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate /* 4670Sstevel@tonic-gate * Since the CPU needs to jump to protected mode using an identity 4680Sstevel@tonic-gate * mapped address, we need to calculate it here. 4690Sstevel@tonic-gate */ 4700Sstevel@tonic-gate real_mode_platter->rm_longmode64_addr = rm_platter_pa + 4710Sstevel@tonic-gate ((uint32_t)long_mode_64 - (uint32_t)real_mode_start); 4720Sstevel@tonic-gate #endif /* __amd64 */ 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate #ifdef TRAPTRACE 4750Sstevel@tonic-gate /* 4760Sstevel@tonic-gate * If this is a TRAPTRACE kernel, allocate TRAPTRACE buffers for this 4770Sstevel@tonic-gate * CPU. 4780Sstevel@tonic-gate */ 4790Sstevel@tonic-gate ttc->ttc_first = (uintptr_t)kmem_zalloc(trap_trace_bufsize, KM_SLEEP); 4800Sstevel@tonic-gate ttc->ttc_next = ttc->ttc_first; 4810Sstevel@tonic-gate ttc->ttc_limit = ttc->ttc_first + trap_trace_bufsize; 4820Sstevel@tonic-gate #endif 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate /* 4850Sstevel@tonic-gate * Record that we have another CPU. 4860Sstevel@tonic-gate */ 4870Sstevel@tonic-gate mutex_enter(&cpu_lock); 4880Sstevel@tonic-gate /* 4890Sstevel@tonic-gate * Initialize the interrupt threads for this CPU 4900Sstevel@tonic-gate */ 4910Sstevel@tonic-gate init_intr_threads(cp); 4920Sstevel@tonic-gate /* 4930Sstevel@tonic-gate * Add CPU to list of available CPUs. It'll be on the active list 4940Sstevel@tonic-gate * after mp_startup(). 4950Sstevel@tonic-gate */ 4960Sstevel@tonic-gate cpu_add_unit(cp); 4970Sstevel@tonic-gate mutex_exit(&cpu_lock); 4980Sstevel@tonic-gate } 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate /* 5010Sstevel@tonic-gate * Apply workarounds for known errata, and warn about those that are absent. 5020Sstevel@tonic-gate * 5030Sstevel@tonic-gate * System vendors occasionally create configurations which contain different 5040Sstevel@tonic-gate * revisions of the CPUs that are almost but not exactly the same. At the 5050Sstevel@tonic-gate * time of writing, this meant that their clock rates were the same, their 5060Sstevel@tonic-gate * feature sets were the same, but the required workaround were -not- 5070Sstevel@tonic-gate * necessarily the same. So, this routine is invoked on -every- CPU soon 5080Sstevel@tonic-gate * after starting to make sure that the resulting system contains the most 5090Sstevel@tonic-gate * pessimal set of workarounds needed to cope with *any* of the CPUs in the 5100Sstevel@tonic-gate * system. 5110Sstevel@tonic-gate * 512*359Skucharsk * These workarounds are based on Rev 3.57 of the Revision Guide for 513*359Skucharsk * AMD Athlon(tm) 64 and AMD Opteron(tm) Processors, August 2005. 5140Sstevel@tonic-gate */ 5150Sstevel@tonic-gate 5160Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_91) 5170Sstevel@tonic-gate int opteron_erratum_91; /* if non-zero -> at least one cpu has it */ 5180Sstevel@tonic-gate #endif 5190Sstevel@tonic-gate 5200Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_93) 5210Sstevel@tonic-gate int opteron_erratum_93; /* if non-zero -> at least one cpu has it */ 5220Sstevel@tonic-gate #endif 5230Sstevel@tonic-gate 5240Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_100) 5250Sstevel@tonic-gate int opteron_erratum_100; /* if non-zero -> at least one cpu has it */ 5260Sstevel@tonic-gate #endif 5270Sstevel@tonic-gate 5280Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_109) 5290Sstevel@tonic-gate int opteron_erratum_109; /* if non-zero -> at least one cpu has it */ 5300Sstevel@tonic-gate #endif 5310Sstevel@tonic-gate 5320Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_121) 5330Sstevel@tonic-gate int opteron_erratum_121; /* if non-zero -> at least one cpu has it */ 5340Sstevel@tonic-gate #endif 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_122) 5370Sstevel@tonic-gate int opteron_erratum_122; /* if non-zero -> at least one cpu has it */ 5380Sstevel@tonic-gate #endif 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_123) 5410Sstevel@tonic-gate int opteron_erratum_123; /* if non-zero -> at least one cpu has it */ 5420Sstevel@tonic-gate #endif 5430Sstevel@tonic-gate 544*359Skucharsk #if defined(OPTERON_ERRATUM_131) 545*359Skucharsk int opteron_erratum_131; /* if non-zero -> at least one cpu has it */ 546*359Skucharsk #endif 5470Sstevel@tonic-gate 5480Sstevel@tonic-gate #define WARNING(cpu, n) \ 5490Sstevel@tonic-gate cmn_err(CE_WARN, "cpu%d: no workaround for erratum %d", \ 5500Sstevel@tonic-gate (cpu)->cpu_id, (n)) 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate uint_t 5530Sstevel@tonic-gate workaround_errata(struct cpu *cpu) 5540Sstevel@tonic-gate { 5550Sstevel@tonic-gate uint_t missing = 0; 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate ASSERT(cpu == CPU); 5580Sstevel@tonic-gate 5590Sstevel@tonic-gate /*LINTED*/ 5600Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 88) > 0) { 5610Sstevel@tonic-gate /* 5620Sstevel@tonic-gate * SWAPGS May Fail To Read Correct GS Base 5630Sstevel@tonic-gate */ 5640Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_88) 5650Sstevel@tonic-gate /* 5660Sstevel@tonic-gate * The workaround is an mfence in the relevant assembler code 5670Sstevel@tonic-gate */ 5680Sstevel@tonic-gate #else 5690Sstevel@tonic-gate WARNING(cpu, 88); 5700Sstevel@tonic-gate missing++; 5710Sstevel@tonic-gate #endif 5720Sstevel@tonic-gate } 5730Sstevel@tonic-gate 5740Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 91) > 0) { 5750Sstevel@tonic-gate /* 5760Sstevel@tonic-gate * Software Prefetches May Report A Page Fault 5770Sstevel@tonic-gate */ 5780Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_91) 5790Sstevel@tonic-gate /* 5800Sstevel@tonic-gate * fix is in trap.c 5810Sstevel@tonic-gate */ 5820Sstevel@tonic-gate opteron_erratum_91++; 5830Sstevel@tonic-gate #else 5840Sstevel@tonic-gate WARNING(cpu, 91); 5850Sstevel@tonic-gate missing++; 5860Sstevel@tonic-gate #endif 5870Sstevel@tonic-gate } 5880Sstevel@tonic-gate 5890Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 93) > 0) { 5900Sstevel@tonic-gate /* 5910Sstevel@tonic-gate * RSM Auto-Halt Restart Returns to Incorrect RIP 5920Sstevel@tonic-gate */ 5930Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_93) 5940Sstevel@tonic-gate /* 5950Sstevel@tonic-gate * fix is in trap.c 5960Sstevel@tonic-gate */ 5970Sstevel@tonic-gate opteron_erratum_93++; 5980Sstevel@tonic-gate #else 5990Sstevel@tonic-gate WARNING(cpu, 93); 6000Sstevel@tonic-gate missing++; 6010Sstevel@tonic-gate #endif 6020Sstevel@tonic-gate } 6030Sstevel@tonic-gate 6040Sstevel@tonic-gate /*LINTED*/ 6050Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 95) > 0) { 6060Sstevel@tonic-gate /* 6070Sstevel@tonic-gate * RET Instruction May Return to Incorrect EIP 6080Sstevel@tonic-gate */ 6090Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_95) 6100Sstevel@tonic-gate #if defined(_LP64) 6110Sstevel@tonic-gate /* 6120Sstevel@tonic-gate * Workaround this by ensuring that 32-bit user code and 6130Sstevel@tonic-gate * 64-bit kernel code never occupy the same address 6140Sstevel@tonic-gate * range mod 4G. 6150Sstevel@tonic-gate */ 6160Sstevel@tonic-gate if (_userlimit32 > 0xc0000000ul) 6170Sstevel@tonic-gate *(uintptr_t *)&_userlimit32 = 0xc0000000ul; 6180Sstevel@tonic-gate 6190Sstevel@tonic-gate /*LINTED*/ 6200Sstevel@tonic-gate ASSERT((uint32_t)COREHEAP_BASE == 0xc0000000u); 6210Sstevel@tonic-gate #endif /* _LP64 */ 6220Sstevel@tonic-gate #else 6230Sstevel@tonic-gate WARNING(cpu, 95); 6240Sstevel@tonic-gate missing++; 6250Sstevel@tonic-gate #endif /* OPTERON_ERRATUM_95 */ 6260Sstevel@tonic-gate } 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 100) > 0) { 6290Sstevel@tonic-gate /* 6300Sstevel@tonic-gate * Compatibility Mode Branches Transfer to Illegal Address 6310Sstevel@tonic-gate */ 6320Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_100) 6330Sstevel@tonic-gate /* 6340Sstevel@tonic-gate * fix is in trap.c 6350Sstevel@tonic-gate */ 6360Sstevel@tonic-gate opteron_erratum_100++; 6370Sstevel@tonic-gate #else 6380Sstevel@tonic-gate WARNING(cpu, 100); 6390Sstevel@tonic-gate missing++; 6400Sstevel@tonic-gate #endif 6410Sstevel@tonic-gate } 6420Sstevel@tonic-gate 6430Sstevel@tonic-gate /*LINTED*/ 6440Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 108) > 0) { 6450Sstevel@tonic-gate /* 6460Sstevel@tonic-gate * CPUID Instruction May Return Incorrect Model Number In 6470Sstevel@tonic-gate * Some Processors 6480Sstevel@tonic-gate */ 6490Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 6500Sstevel@tonic-gate /* 6510Sstevel@tonic-gate * (Our cpuid-handling code corrects the model number on 6520Sstevel@tonic-gate * those processors) 6530Sstevel@tonic-gate */ 6540Sstevel@tonic-gate #else 6550Sstevel@tonic-gate WARNING(cpu, 108); 6560Sstevel@tonic-gate missing++; 6570Sstevel@tonic-gate #endif 6580Sstevel@tonic-gate } 6590Sstevel@tonic-gate 6600Sstevel@tonic-gate /*LINTED*/ 6610Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 109) > 0) { 6620Sstevel@tonic-gate /* 6630Sstevel@tonic-gate * Certain Reverse REP MOVS May Produce Unpredictable Behaviour 6640Sstevel@tonic-gate */ 6650Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_109) 6660Sstevel@tonic-gate uint64_t patchlevel; 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate (void) rdmsr(MSR_AMD_PATCHLEVEL, &patchlevel); 6690Sstevel@tonic-gate /* workaround is to print a warning to upgrade BIOS */ 6700Sstevel@tonic-gate if (patchlevel == 0) 6710Sstevel@tonic-gate opteron_erratum_109++; 6720Sstevel@tonic-gate #else 6730Sstevel@tonic-gate WARNING(cpu, 109); 6740Sstevel@tonic-gate missing++; 6750Sstevel@tonic-gate #endif 6760Sstevel@tonic-gate } 6770Sstevel@tonic-gate /*LINTED*/ 6780Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 121) > 0) { 6790Sstevel@tonic-gate /* 6800Sstevel@tonic-gate * Sequential Execution Across Non_Canonical Boundary Caused 6810Sstevel@tonic-gate * Processor Hang 6820Sstevel@tonic-gate */ 6830Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_121) 6840Sstevel@tonic-gate static int lma; 6850Sstevel@tonic-gate 6860Sstevel@tonic-gate if (opteron_erratum_121) 6870Sstevel@tonic-gate opteron_erratum_121++; 6880Sstevel@tonic-gate 6890Sstevel@tonic-gate /* 6900Sstevel@tonic-gate * Erratum 121 is only present in long (64 bit) mode. 6910Sstevel@tonic-gate * Workaround is to include the page immediately before the 6920Sstevel@tonic-gate * va hole to eliminate the possibility of system hangs due to 6930Sstevel@tonic-gate * sequential execution across the va hole boundary. 6940Sstevel@tonic-gate */ 6950Sstevel@tonic-gate if (lma == 0) { 6960Sstevel@tonic-gate uint64_t efer; 6970Sstevel@tonic-gate 6980Sstevel@tonic-gate /* 6990Sstevel@tonic-gate * check LMA once: assume all cpus are in long mode 7000Sstevel@tonic-gate * or not. 7010Sstevel@tonic-gate */ 7020Sstevel@tonic-gate lma = 1; 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate (void) rdmsr(MSR_AMD_EFER, &efer); 7050Sstevel@tonic-gate if (efer & AMD_EFER_LMA) { 7060Sstevel@tonic-gate if (hole_start) { 7070Sstevel@tonic-gate hole_start -= PAGESIZE; 7080Sstevel@tonic-gate } else { 7090Sstevel@tonic-gate /* 7100Sstevel@tonic-gate * hole_start not yet initialized by 7110Sstevel@tonic-gate * mmu_init. Initialize hole_start 7120Sstevel@tonic-gate * with value to be subtracted. 7130Sstevel@tonic-gate */ 7140Sstevel@tonic-gate hole_start = PAGESIZE; 7150Sstevel@tonic-gate } 7160Sstevel@tonic-gate opteron_erratum_121++; 7170Sstevel@tonic-gate } 7180Sstevel@tonic-gate } 7190Sstevel@tonic-gate #else 7200Sstevel@tonic-gate WARNING(cpu, 121); 7210Sstevel@tonic-gate missing++; 7220Sstevel@tonic-gate #endif 7230Sstevel@tonic-gate } 7240Sstevel@tonic-gate 7250Sstevel@tonic-gate /*LINTED*/ 7260Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 122) > 0) { 7270Sstevel@tonic-gate /* 7280Sstevel@tonic-gate * TLB Flush Filter May Cause Cohenrency Problem in 7290Sstevel@tonic-gate * Multiprocessor Systems 7300Sstevel@tonic-gate */ 7310Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_122) 7320Sstevel@tonic-gate /* 7330Sstevel@tonic-gate * Erratum 122 is only present in MP configurations (multi-core 7340Sstevel@tonic-gate * or multi-processor). 7350Sstevel@tonic-gate */ 7360Sstevel@tonic-gate 7370Sstevel@tonic-gate if (opteron_erratum_122 || lgrp_plat_node_cnt > 1 || 7380Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu) > 1) { 7390Sstevel@tonic-gate uint64_t hwcrval; 7400Sstevel@tonic-gate 7410Sstevel@tonic-gate /* disable TLB Flush Filter */ 7420Sstevel@tonic-gate (void) rdmsr(MSR_AMD_HWCR, &hwcrval); 7430Sstevel@tonic-gate hwcrval |= AMD_HWCR_FFDIS; 7440Sstevel@tonic-gate wrmsr(MSR_AMD_HWCR, &hwcrval); 7450Sstevel@tonic-gate opteron_erratum_122++; 7460Sstevel@tonic-gate } 7470Sstevel@tonic-gate 7480Sstevel@tonic-gate #else 7490Sstevel@tonic-gate WARNING(cpu, 122); 7500Sstevel@tonic-gate missing++; 7510Sstevel@tonic-gate #endif 7520Sstevel@tonic-gate } 753302Skchow 754302Skchow #if defined(OPTERON_ERRATUM_123) 7550Sstevel@tonic-gate /*LINTED*/ 7560Sstevel@tonic-gate if (cpuid_opteron_erratum(cpu, 123) > 0) { 7570Sstevel@tonic-gate /* 7580Sstevel@tonic-gate * Bypassed Reads May Cause Data Corruption of System Hang in 7590Sstevel@tonic-gate * Dual Core Processors 7600Sstevel@tonic-gate */ 7610Sstevel@tonic-gate /* 7620Sstevel@tonic-gate * Erratum 123 applies only to multi-core cpus. 7630Sstevel@tonic-gate */ 7640Sstevel@tonic-gate 7650Sstevel@tonic-gate if (cpuid_get_ncpu_per_chip(cpu) > 1) { 7660Sstevel@tonic-gate uint64_t patchlevel; 7670Sstevel@tonic-gate 7680Sstevel@tonic-gate (void) rdmsr(MSR_AMD_PATCHLEVEL, &patchlevel); 7690Sstevel@tonic-gate /* workaround is to print a warning to upgrade BIOS */ 7700Sstevel@tonic-gate if (patchlevel == 0) 7710Sstevel@tonic-gate opteron_erratum_123++; 7720Sstevel@tonic-gate } 773302Skchow } 7740Sstevel@tonic-gate #endif 775*359Skucharsk 776*359Skucharsk #if defined(OPTERON_ERRATUM_131) 777*359Skucharsk /*LINTED*/ 778*359Skucharsk if (cpuid_opteron_erratum(cpu, 131) > 0) { 779*359Skucharsk /* 780*359Skucharsk * Multiprocessor Systems with Four or More Cores May Deadlock 781*359Skucharsk * Waiting for a Probe Response 782*359Skucharsk */ 783*359Skucharsk /* 784*359Skucharsk * Erratum 131 applies to any system with four or more cores. 785*359Skucharsk */ 786*359Skucharsk if ((opteron_erratum_131 == 0) && ((lgrp_plat_node_cnt * 787*359Skucharsk cpuid_get_ncpu_per_chip(cpu)) >= 4)) { 788*359Skucharsk uint64_t nbcfg; 789*359Skucharsk 790*359Skucharsk /* 791*359Skucharsk * Workaround is to print a warning to upgrade 792*359Skucharsk * the BIOS 793*359Skucharsk */ 794*359Skucharsk (void) rdmsr(MSR_AMD_NB_CFG, &nbcfg); 795*359Skucharsk if (!(nbcfg & AMD_NB_CFG_SRQ_HEARTBEAT)) 796*359Skucharsk opteron_erratum_131++; 797*359Skucharsk } 798*359Skucharsk #endif 799*359Skucharsk } 8000Sstevel@tonic-gate return (missing); 8010Sstevel@tonic-gate } 8020Sstevel@tonic-gate 8030Sstevel@tonic-gate void 8040Sstevel@tonic-gate workaround_errata_end() 8050Sstevel@tonic-gate { 8060Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_109) 8070Sstevel@tonic-gate if (opteron_erratum_109) { 808*359Skucharsk cmn_err(CE_WARN, 809*359Skucharsk "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)" 810*359Skucharsk " processor\nerratum 109 was not detected; updating your" 811*359Skucharsk " system's BIOS to a version\ncontaining this" 812*359Skucharsk " microcode patch is HIGHLY recommended or erroneous" 813*359Skucharsk " system\noperation may occur.\n"); 8140Sstevel@tonic-gate } 815*359Skucharsk #endif /* OPTERON_ERRATUM_109 */ 8160Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_123) 8170Sstevel@tonic-gate if (opteron_erratum_123) { 818*359Skucharsk cmn_err(CE_WARN, 819*359Skucharsk "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)" 820*359Skucharsk " processor\nerratum 123 was not detected; updating your" 821*359Skucharsk " system's BIOS to a version\ncontaining this" 822*359Skucharsk " microcode patch is HIGHLY recommended or erroneous" 823*359Skucharsk " system\noperation may occur.\n"); 8240Sstevel@tonic-gate } 825*359Skucharsk #endif /* OPTERON_ERRATUM_123 */ 826*359Skucharsk #if defined(OPTERON_ERRATUM_131) 827*359Skucharsk if (opteron_erratum_131) { 828*359Skucharsk cmn_err(CE_WARN, 829*359Skucharsk "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)" 830*359Skucharsk " processor\nerratum 131 was not detected; updating your" 831*359Skucharsk " system's BIOS to a version\ncontaining this" 832*359Skucharsk " microcode patch is HIGHLY recommended or erroneous" 833*359Skucharsk " system\noperation may occur.\n"); 834*359Skucharsk } 835*359Skucharsk #endif /* OPTERON_ERRATUM_131 */ 8360Sstevel@tonic-gate } 8370Sstevel@tonic-gate 8380Sstevel@tonic-gate static ushort_t *mp_map_warm_reset_vector(); 8390Sstevel@tonic-gate static void mp_unmap_warm_reset_vector(ushort_t *warm_reset_vector); 8400Sstevel@tonic-gate 8410Sstevel@tonic-gate /*ARGSUSED*/ 8420Sstevel@tonic-gate void 8430Sstevel@tonic-gate start_other_cpus(int cprboot) 8440Sstevel@tonic-gate { 8450Sstevel@tonic-gate unsigned who; 8460Sstevel@tonic-gate int cpuid = getbootcpuid(); 8470Sstevel@tonic-gate int delays = 0; 8480Sstevel@tonic-gate int started_cpu; 8490Sstevel@tonic-gate ushort_t *warm_reset_vector = NULL; 8500Sstevel@tonic-gate extern int procset; 8510Sstevel@tonic-gate 8520Sstevel@tonic-gate /* 8530Sstevel@tonic-gate * Initialize our own cpu_info. 8540Sstevel@tonic-gate */ 8550Sstevel@tonic-gate init_cpu_info(CPU); 8560Sstevel@tonic-gate 8570Sstevel@tonic-gate /* 8580Sstevel@tonic-gate * Initialize our syscall handlers 8590Sstevel@tonic-gate */ 8600Sstevel@tonic-gate init_cpu_syscall(CPU); 8610Sstevel@tonic-gate 8620Sstevel@tonic-gate /* 8630Sstevel@tonic-gate * if only 1 cpu or not using MP, skip the rest of this 8640Sstevel@tonic-gate */ 8650Sstevel@tonic-gate if (!(mp_cpus & ~(1 << cpuid)) || use_mp == 0) { 8660Sstevel@tonic-gate if (use_mp == 0) 8670Sstevel@tonic-gate cmn_err(CE_CONT, "?***** Not in MP mode\n"); 8680Sstevel@tonic-gate goto done; 8690Sstevel@tonic-gate } 8700Sstevel@tonic-gate 8710Sstevel@tonic-gate /* 8720Sstevel@tonic-gate * perform such initialization as is needed 8730Sstevel@tonic-gate * to be able to take CPUs on- and off-line. 8740Sstevel@tonic-gate */ 8750Sstevel@tonic-gate cpu_pause_init(); 8760Sstevel@tonic-gate 8770Sstevel@tonic-gate xc_init(); /* initialize processor crosscalls */ 8780Sstevel@tonic-gate 8790Sstevel@tonic-gate /* 8800Sstevel@tonic-gate * Copy the real mode code at "real_mode_start" to the 8810Sstevel@tonic-gate * page at rm_platter_va. 8820Sstevel@tonic-gate */ 8830Sstevel@tonic-gate warm_reset_vector = mp_map_warm_reset_vector(); 8840Sstevel@tonic-gate if (warm_reset_vector == NULL) 8850Sstevel@tonic-gate goto done; 8860Sstevel@tonic-gate 8870Sstevel@tonic-gate bcopy((caddr_t)real_mode_start, 8880Sstevel@tonic-gate (caddr_t)((rm_platter_t *)rm_platter_va)->rm_code, 8890Sstevel@tonic-gate (size_t)real_mode_end - (size_t)real_mode_start); 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate flushes_require_xcalls = 1; 8920Sstevel@tonic-gate 8930Sstevel@tonic-gate affinity_set(CPU_CURRENT); 8940Sstevel@tonic-gate 8950Sstevel@tonic-gate for (who = 0; who < NCPU; who++) { 8960Sstevel@tonic-gate if (who == cpuid) 8970Sstevel@tonic-gate continue; 8980Sstevel@tonic-gate 8990Sstevel@tonic-gate if ((mp_cpus & (1 << who)) == 0) 9000Sstevel@tonic-gate continue; 9010Sstevel@tonic-gate 9020Sstevel@tonic-gate mp_startup_init(who); 9030Sstevel@tonic-gate started_cpu = 1; 9040Sstevel@tonic-gate (*cpu_startf)(who, rm_platter_pa); 9050Sstevel@tonic-gate 9060Sstevel@tonic-gate while ((procset & (1 << who)) == 0) { 9070Sstevel@tonic-gate 9080Sstevel@tonic-gate delay(1); 9090Sstevel@tonic-gate if (++delays > (20 * hz)) { 9100Sstevel@tonic-gate 9110Sstevel@tonic-gate cmn_err(CE_WARN, 9120Sstevel@tonic-gate "cpu%d failed to start", who); 9130Sstevel@tonic-gate 9140Sstevel@tonic-gate mutex_enter(&cpu_lock); 9150Sstevel@tonic-gate cpu[who]->cpu_flags = 0; 9160Sstevel@tonic-gate cpu_del_unit(who); 9170Sstevel@tonic-gate mutex_exit(&cpu_lock); 9180Sstevel@tonic-gate 9190Sstevel@tonic-gate started_cpu = 0; 9200Sstevel@tonic-gate break; 9210Sstevel@tonic-gate } 9220Sstevel@tonic-gate } 9230Sstevel@tonic-gate if (!started_cpu) 9240Sstevel@tonic-gate continue; 9250Sstevel@tonic-gate if (tsc_gethrtime_enable) 9260Sstevel@tonic-gate tsc_sync_master(who); 9270Sstevel@tonic-gate 9280Sstevel@tonic-gate 9290Sstevel@tonic-gate if (dtrace_cpu_init != NULL) { 9300Sstevel@tonic-gate /* 9310Sstevel@tonic-gate * DTrace CPU initialization expects cpu_lock 9320Sstevel@tonic-gate * to be held. 9330Sstevel@tonic-gate */ 9340Sstevel@tonic-gate mutex_enter(&cpu_lock); 9350Sstevel@tonic-gate (*dtrace_cpu_init)(who); 9360Sstevel@tonic-gate mutex_exit(&cpu_lock); 9370Sstevel@tonic-gate } 9380Sstevel@tonic-gate } 9390Sstevel@tonic-gate 9400Sstevel@tonic-gate affinity_clear(); 9410Sstevel@tonic-gate 9420Sstevel@tonic-gate for (who = 0; who < NCPU; who++) { 9430Sstevel@tonic-gate if (who == cpuid) 9440Sstevel@tonic-gate continue; 9450Sstevel@tonic-gate 9460Sstevel@tonic-gate if (!(procset & (1 << who))) 9470Sstevel@tonic-gate continue; 9480Sstevel@tonic-gate 9490Sstevel@tonic-gate while (!(cpu_ready_set & (1 << who))) 9500Sstevel@tonic-gate delay(1); 9510Sstevel@tonic-gate } 9520Sstevel@tonic-gate 9530Sstevel@tonic-gate done: 9540Sstevel@tonic-gate workaround_errata_end(); 9550Sstevel@tonic-gate 9560Sstevel@tonic-gate if (warm_reset_vector != NULL) 9570Sstevel@tonic-gate mp_unmap_warm_reset_vector(warm_reset_vector); 9580Sstevel@tonic-gate hat_unload(kas.a_hat, (caddr_t)(uintptr_t)rm_platter_pa, MMU_PAGESIZE, 9590Sstevel@tonic-gate HAT_UNLOAD); 9600Sstevel@tonic-gate } 9610Sstevel@tonic-gate 9620Sstevel@tonic-gate /* 9630Sstevel@tonic-gate * Dummy functions - no i86pc platforms support dynamic cpu allocation. 9640Sstevel@tonic-gate */ 9650Sstevel@tonic-gate /*ARGSUSED*/ 9660Sstevel@tonic-gate int 9670Sstevel@tonic-gate mp_cpu_configure(int cpuid) 9680Sstevel@tonic-gate { 9690Sstevel@tonic-gate return (ENOTSUP); /* not supported */ 9700Sstevel@tonic-gate } 9710Sstevel@tonic-gate 9720Sstevel@tonic-gate /*ARGSUSED*/ 9730Sstevel@tonic-gate int 9740Sstevel@tonic-gate mp_cpu_unconfigure(int cpuid) 9750Sstevel@tonic-gate { 9760Sstevel@tonic-gate return (ENOTSUP); /* not supported */ 9770Sstevel@tonic-gate } 9780Sstevel@tonic-gate 9790Sstevel@tonic-gate /* 9800Sstevel@tonic-gate * Startup function for 'other' CPUs (besides boot cpu). 9810Sstevel@tonic-gate * Resumed from cpu_startup. 9820Sstevel@tonic-gate */ 9830Sstevel@tonic-gate void 9840Sstevel@tonic-gate mp_startup(void) 9850Sstevel@tonic-gate { 9860Sstevel@tonic-gate struct cpu *cp = CPU; 9870Sstevel@tonic-gate extern int procset; 9880Sstevel@tonic-gate uint_t new_x86_feature; 9890Sstevel@tonic-gate 9900Sstevel@tonic-gate new_x86_feature = cpuid_pass1(cp); 9910Sstevel@tonic-gate 9920Sstevel@tonic-gate /* 9930Sstevel@tonic-gate * We need to Sync MTRR with cpu0's MTRR. We have to do 9940Sstevel@tonic-gate * this with interrupts disabled. 9950Sstevel@tonic-gate */ 9960Sstevel@tonic-gate if (x86_feature & X86_MTRR) 9970Sstevel@tonic-gate mtrr_sync(); 9980Sstevel@tonic-gate /* 9990Sstevel@tonic-gate * Enable machine check architecture 10000Sstevel@tonic-gate */ 10010Sstevel@tonic-gate if (x86_feature & X86_MCA) 10020Sstevel@tonic-gate setup_mca(); 10030Sstevel@tonic-gate 10040Sstevel@tonic-gate /* 10050Sstevel@tonic-gate * Initialize this CPU's syscall handlers 10060Sstevel@tonic-gate */ 10070Sstevel@tonic-gate init_cpu_syscall(cp); 10080Sstevel@tonic-gate 10090Sstevel@tonic-gate /* 10100Sstevel@tonic-gate * Enable interrupts with spl set to LOCK_LEVEL. LOCK_LEVEL is the 10110Sstevel@tonic-gate * highest level at which a routine is permitted to block on 10120Sstevel@tonic-gate * an adaptive mutex (allows for cpu poke interrupt in case 10130Sstevel@tonic-gate * the cpu is blocked on a mutex and halts). Setting LOCK_LEVEL blocks 10140Sstevel@tonic-gate * device interrupts that may end up in the hat layer issuing cross 10150Sstevel@tonic-gate * calls before CPU_READY is set. 10160Sstevel@tonic-gate */ 10170Sstevel@tonic-gate (void) splx(ipltospl(LOCK_LEVEL)); 10180Sstevel@tonic-gate 10190Sstevel@tonic-gate /* 10200Sstevel@tonic-gate * Do a sanity check to make sure this new CPU is a sane thing 10210Sstevel@tonic-gate * to add to the collection of processors running this system. 10220Sstevel@tonic-gate * 10230Sstevel@tonic-gate * XXX Clearly this needs to get more sophisticated, if x86 10240Sstevel@tonic-gate * systems start to get built out of heterogenous CPUs; as is 10250Sstevel@tonic-gate * likely to happen once the number of processors in a configuration 10260Sstevel@tonic-gate * gets large enough. 10270Sstevel@tonic-gate */ 10280Sstevel@tonic-gate if ((x86_feature & new_x86_feature) != x86_feature) { 10290Sstevel@tonic-gate cmn_err(CE_CONT, "?cpu%d: %b\n", 10300Sstevel@tonic-gate cp->cpu_id, new_x86_feature, FMT_X86_FEATURE); 10310Sstevel@tonic-gate cmn_err(CE_WARN, "cpu%d feature mismatch", cp->cpu_id); 10320Sstevel@tonic-gate } 10330Sstevel@tonic-gate 10340Sstevel@tonic-gate /* 10350Sstevel@tonic-gate * We could be more sophisticated here, and just mark the CPU 10360Sstevel@tonic-gate * as "faulted" but at this point we'll opt for the easier 10370Sstevel@tonic-gate * answer of dieing horribly. Provided the boot cpu is ok, 10380Sstevel@tonic-gate * the system can be recovered by booting with use_mp set to zero. 10390Sstevel@tonic-gate */ 10400Sstevel@tonic-gate if (workaround_errata(cp) != 0) 10410Sstevel@tonic-gate panic("critical workaround(s) missing for cpu%d", cp->cpu_id); 10420Sstevel@tonic-gate 10430Sstevel@tonic-gate cpuid_pass2(cp); 10440Sstevel@tonic-gate cpuid_pass3(cp); 10450Sstevel@tonic-gate (void) cpuid_pass4(cp); 10460Sstevel@tonic-gate 10470Sstevel@tonic-gate init_cpu_info(cp); 10480Sstevel@tonic-gate 10490Sstevel@tonic-gate add_cpunode2devtree(cp->cpu_id, cp->cpu_m.mcpu_cpi); 10500Sstevel@tonic-gate 10510Sstevel@tonic-gate mutex_enter(&cpu_lock); 10520Sstevel@tonic-gate procset |= 1 << cp->cpu_id; 10530Sstevel@tonic-gate mutex_exit(&cpu_lock); 10540Sstevel@tonic-gate 10550Sstevel@tonic-gate if (tsc_gethrtime_enable) 10560Sstevel@tonic-gate tsc_sync_slave(); 10570Sstevel@tonic-gate 10580Sstevel@tonic-gate mutex_enter(&cpu_lock); 10590Sstevel@tonic-gate /* 10600Sstevel@tonic-gate * It's unfortunate that chip_cpu_init() has to be called here. 10610Sstevel@tonic-gate * It really belongs in cpu_add_unit(), but unfortunately it is 10620Sstevel@tonic-gate * dependent on the cpuid probing, which must be done in the 10630Sstevel@tonic-gate * context of the current CPU. Care must be taken on x86 to ensure 10640Sstevel@tonic-gate * that mp_startup can safely block even though chip_cpu_init() and 10650Sstevel@tonic-gate * cpu_add_active() have not yet been called. 10660Sstevel@tonic-gate */ 10670Sstevel@tonic-gate chip_cpu_init(cp); 10680Sstevel@tonic-gate chip_cpu_startup(cp); 10690Sstevel@tonic-gate 10700Sstevel@tonic-gate cp->cpu_flags |= CPU_RUNNING | CPU_READY | CPU_ENABLE | CPU_EXISTS; 10710Sstevel@tonic-gate cpu_add_active(cp); 10720Sstevel@tonic-gate mutex_exit(&cpu_lock); 10730Sstevel@tonic-gate 10740Sstevel@tonic-gate (void) spl0(); /* enable interrupts */ 10750Sstevel@tonic-gate 10760Sstevel@tonic-gate if (boothowto & RB_DEBUG) 10770Sstevel@tonic-gate kdi_dvec_cpu_init(cp); 10780Sstevel@tonic-gate 10790Sstevel@tonic-gate /* 10800Sstevel@tonic-gate * Setting the bit in cpu_ready_set must be the last operation in 10810Sstevel@tonic-gate * processor initialization; the boot CPU will continue to boot once 10820Sstevel@tonic-gate * it sees this bit set for all active CPUs. 10830Sstevel@tonic-gate */ 10840Sstevel@tonic-gate CPUSET_ATOMIC_ADD(cpu_ready_set, cp->cpu_id); 10850Sstevel@tonic-gate 10860Sstevel@tonic-gate /* 10870Sstevel@tonic-gate * Because mp_startup() gets fired off after init() starts, we 10880Sstevel@tonic-gate * can't use the '?' trick to do 'boot -v' printing - so we 10890Sstevel@tonic-gate * always direct the 'cpu .. online' messages to the log. 10900Sstevel@tonic-gate */ 10910Sstevel@tonic-gate cmn_err(CE_CONT, "!cpu%d initialization complete - online\n", 10920Sstevel@tonic-gate cp->cpu_id); 10930Sstevel@tonic-gate 10940Sstevel@tonic-gate /* 10950Sstevel@tonic-gate * Now we are done with the startup thread, so free it up. 10960Sstevel@tonic-gate */ 10970Sstevel@tonic-gate thread_exit(); 10980Sstevel@tonic-gate panic("mp_startup: cannot return"); 10990Sstevel@tonic-gate /*NOTREACHED*/ 11000Sstevel@tonic-gate } 11010Sstevel@tonic-gate 11020Sstevel@tonic-gate 11030Sstevel@tonic-gate /* 11040Sstevel@tonic-gate * Start CPU on user request. 11050Sstevel@tonic-gate */ 11060Sstevel@tonic-gate /* ARGSUSED */ 11070Sstevel@tonic-gate int 11080Sstevel@tonic-gate mp_cpu_start(struct cpu *cp) 11090Sstevel@tonic-gate { 11100Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 11110Sstevel@tonic-gate if (cp->cpu_id == getbootcpuid()) 11120Sstevel@tonic-gate return (EBUSY); /* Cannot start boot CPU */ 11130Sstevel@tonic-gate return (0); 11140Sstevel@tonic-gate } 11150Sstevel@tonic-gate 11160Sstevel@tonic-gate /* 11170Sstevel@tonic-gate * Stop CPU on user request. 11180Sstevel@tonic-gate */ 11190Sstevel@tonic-gate /* ARGSUSED */ 11200Sstevel@tonic-gate int 11210Sstevel@tonic-gate mp_cpu_stop(struct cpu *cp) 11220Sstevel@tonic-gate { 11230Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 11240Sstevel@tonic-gate if (cp->cpu_id == getbootcpuid()) 11250Sstevel@tonic-gate return (EBUSY); /* Cannot stop boot CPU */ 11260Sstevel@tonic-gate 11270Sstevel@tonic-gate return (0); 11280Sstevel@tonic-gate } 11290Sstevel@tonic-gate 11300Sstevel@tonic-gate /* 11310Sstevel@tonic-gate * Power on CPU. 11320Sstevel@tonic-gate */ 11330Sstevel@tonic-gate /* ARGSUSED */ 11340Sstevel@tonic-gate int 11350Sstevel@tonic-gate mp_cpu_poweron(struct cpu *cp) 11360Sstevel@tonic-gate { 11370Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 11380Sstevel@tonic-gate return (ENOTSUP); /* not supported */ 11390Sstevel@tonic-gate } 11400Sstevel@tonic-gate 11410Sstevel@tonic-gate /* 11420Sstevel@tonic-gate * Power off CPU. 11430Sstevel@tonic-gate */ 11440Sstevel@tonic-gate /* ARGSUSED */ 11450Sstevel@tonic-gate int 11460Sstevel@tonic-gate mp_cpu_poweroff(struct cpu *cp) 11470Sstevel@tonic-gate { 11480Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 11490Sstevel@tonic-gate return (ENOTSUP); /* not supported */ 11500Sstevel@tonic-gate } 11510Sstevel@tonic-gate 11520Sstevel@tonic-gate 11530Sstevel@tonic-gate /* 11540Sstevel@tonic-gate * Take the specified CPU out of participation in interrupts. 11550Sstevel@tonic-gate */ 11560Sstevel@tonic-gate int 11570Sstevel@tonic-gate cpu_disable_intr(struct cpu *cp) 11580Sstevel@tonic-gate { 11590Sstevel@tonic-gate /* 11600Sstevel@tonic-gate * cannot disable interrupts on boot cpu 11610Sstevel@tonic-gate */ 11620Sstevel@tonic-gate if (cp == cpu[getbootcpuid()]) 11630Sstevel@tonic-gate return (EBUSY); 11640Sstevel@tonic-gate 11650Sstevel@tonic-gate if (psm_disable_intr(cp->cpu_id) != DDI_SUCCESS) 11660Sstevel@tonic-gate return (EBUSY); 11670Sstevel@tonic-gate 11680Sstevel@tonic-gate cp->cpu_flags &= ~CPU_ENABLE; 11690Sstevel@tonic-gate return (0); 11700Sstevel@tonic-gate } 11710Sstevel@tonic-gate 11720Sstevel@tonic-gate /* 11730Sstevel@tonic-gate * Allow the specified CPU to participate in interrupts. 11740Sstevel@tonic-gate */ 11750Sstevel@tonic-gate void 11760Sstevel@tonic-gate cpu_enable_intr(struct cpu *cp) 11770Sstevel@tonic-gate { 11780Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 11790Sstevel@tonic-gate if (cp == cpu[getbootcpuid()]) 11800Sstevel@tonic-gate return; 11810Sstevel@tonic-gate 11820Sstevel@tonic-gate cp->cpu_flags |= CPU_ENABLE; 11830Sstevel@tonic-gate psm_enable_intr(cp->cpu_id); 11840Sstevel@tonic-gate } 11850Sstevel@tonic-gate 11860Sstevel@tonic-gate 11870Sstevel@tonic-gate /* 11880Sstevel@tonic-gate * return the cpu id of the initial startup cpu 11890Sstevel@tonic-gate */ 11900Sstevel@tonic-gate processorid_t 11910Sstevel@tonic-gate getbootcpuid(void) 11920Sstevel@tonic-gate { 11930Sstevel@tonic-gate return (0); 11940Sstevel@tonic-gate } 11950Sstevel@tonic-gate 11960Sstevel@tonic-gate static ushort_t * 11970Sstevel@tonic-gate mp_map_warm_reset_vector() 11980Sstevel@tonic-gate { 11990Sstevel@tonic-gate ushort_t *warm_reset_vector; 12000Sstevel@tonic-gate 12010Sstevel@tonic-gate if (!(warm_reset_vector = (ushort_t *)psm_map_phys(WARM_RESET_VECTOR, 12020Sstevel@tonic-gate sizeof (ushort_t *), PROT_READ|PROT_WRITE))) 12030Sstevel@tonic-gate return (NULL); 12040Sstevel@tonic-gate 12050Sstevel@tonic-gate /* 12060Sstevel@tonic-gate * setup secondary cpu bios boot up vector 12070Sstevel@tonic-gate */ 12080Sstevel@tonic-gate *warm_reset_vector = (ushort_t)((caddr_t) 12090Sstevel@tonic-gate ((struct rm_platter *)rm_platter_va)->rm_code - rm_platter_va 12100Sstevel@tonic-gate + ((ulong_t)rm_platter_va & 0xf)); 12110Sstevel@tonic-gate warm_reset_vector++; 12120Sstevel@tonic-gate *warm_reset_vector = (ushort_t)(rm_platter_pa >> 4); 12130Sstevel@tonic-gate 12140Sstevel@tonic-gate --warm_reset_vector; 12150Sstevel@tonic-gate return (warm_reset_vector); 12160Sstevel@tonic-gate } 12170Sstevel@tonic-gate 12180Sstevel@tonic-gate static void 12190Sstevel@tonic-gate mp_unmap_warm_reset_vector(ushort_t *warm_reset_vector) 12200Sstevel@tonic-gate { 12210Sstevel@tonic-gate psm_unmap_phys((caddr_t)warm_reset_vector, sizeof (ushort_t *)); 12220Sstevel@tonic-gate } 12230Sstevel@tonic-gate 12240Sstevel@tonic-gate /*ARGSUSED*/ 12250Sstevel@tonic-gate void 12260Sstevel@tonic-gate mp_cpu_faulted_enter(struct cpu *cp) 12270Sstevel@tonic-gate {} 12280Sstevel@tonic-gate 12290Sstevel@tonic-gate /*ARGSUSED*/ 12300Sstevel@tonic-gate void 12310Sstevel@tonic-gate mp_cpu_faulted_exit(struct cpu *cp) 12320Sstevel@tonic-gate {} 12330Sstevel@tonic-gate 12340Sstevel@tonic-gate /* 12350Sstevel@tonic-gate * The following two routines are used as context operators on threads belonging 12360Sstevel@tonic-gate * to processes with a private LDT (see sysi86). Due to the rarity of such 12370Sstevel@tonic-gate * processes, these routines are currently written for best code readability and 12380Sstevel@tonic-gate * organization rather than speed. We could avoid checking x86_feature at every 12390Sstevel@tonic-gate * context switch by installing different context ops, depending on the 12400Sstevel@tonic-gate * x86_feature flags, at LDT creation time -- one for each combination of fast 12410Sstevel@tonic-gate * syscall feature flags. 12420Sstevel@tonic-gate */ 12430Sstevel@tonic-gate 12440Sstevel@tonic-gate /*ARGSUSED*/ 12450Sstevel@tonic-gate void 12460Sstevel@tonic-gate cpu_fast_syscall_disable(void *arg) 12470Sstevel@tonic-gate { 12480Sstevel@tonic-gate if (x86_feature & X86_SEP) 12490Sstevel@tonic-gate cpu_sep_disable(); 12500Sstevel@tonic-gate if (x86_feature & X86_ASYSC) 12510Sstevel@tonic-gate cpu_asysc_disable(); 12520Sstevel@tonic-gate } 12530Sstevel@tonic-gate 12540Sstevel@tonic-gate /*ARGSUSED*/ 12550Sstevel@tonic-gate void 12560Sstevel@tonic-gate cpu_fast_syscall_enable(void *arg) 12570Sstevel@tonic-gate { 12580Sstevel@tonic-gate if (x86_feature & X86_SEP) 12590Sstevel@tonic-gate cpu_sep_enable(); 12600Sstevel@tonic-gate if (x86_feature & X86_ASYSC) 12610Sstevel@tonic-gate cpu_asysc_enable(); 12620Sstevel@tonic-gate } 12630Sstevel@tonic-gate 12640Sstevel@tonic-gate static void 12650Sstevel@tonic-gate cpu_sep_enable(void) 12660Sstevel@tonic-gate { 12670Sstevel@tonic-gate uint64_t value; 12680Sstevel@tonic-gate 12690Sstevel@tonic-gate ASSERT(x86_feature & X86_SEP); 12700Sstevel@tonic-gate ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 12710Sstevel@tonic-gate 12720Sstevel@tonic-gate value = KCS_SEL; 12730Sstevel@tonic-gate wrmsr(MSR_INTC_SEP_CS, &value); 12740Sstevel@tonic-gate } 12750Sstevel@tonic-gate 12760Sstevel@tonic-gate static void 12770Sstevel@tonic-gate cpu_sep_disable(void) 12780Sstevel@tonic-gate { 12790Sstevel@tonic-gate uint64_t value; 12800Sstevel@tonic-gate 12810Sstevel@tonic-gate ASSERT(x86_feature & X86_SEP); 12820Sstevel@tonic-gate ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 12830Sstevel@tonic-gate 12840Sstevel@tonic-gate /* 12850Sstevel@tonic-gate * Setting the SYSENTER_CS_MSR register to 0 causes software executing 12860Sstevel@tonic-gate * the sysenter or sysexit instruction to trigger a #gp fault. 12870Sstevel@tonic-gate */ 12880Sstevel@tonic-gate value = 0; 12890Sstevel@tonic-gate wrmsr(MSR_INTC_SEP_CS, &value); 12900Sstevel@tonic-gate } 12910Sstevel@tonic-gate 12920Sstevel@tonic-gate static void 12930Sstevel@tonic-gate cpu_asysc_enable(void) 12940Sstevel@tonic-gate { 12950Sstevel@tonic-gate uint64_t value; 12960Sstevel@tonic-gate 12970Sstevel@tonic-gate ASSERT(x86_feature & X86_ASYSC); 12980Sstevel@tonic-gate ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 12990Sstevel@tonic-gate 13000Sstevel@tonic-gate (void) rdmsr(MSR_AMD_EFER, &value); 13010Sstevel@tonic-gate value |= AMD_EFER_SCE; 13020Sstevel@tonic-gate wrmsr(MSR_AMD_EFER, &value); 13030Sstevel@tonic-gate } 13040Sstevel@tonic-gate 13050Sstevel@tonic-gate static void 13060Sstevel@tonic-gate cpu_asysc_disable(void) 13070Sstevel@tonic-gate { 13080Sstevel@tonic-gate uint64_t value; 13090Sstevel@tonic-gate 13100Sstevel@tonic-gate ASSERT(x86_feature & X86_ASYSC); 13110Sstevel@tonic-gate ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL); 13120Sstevel@tonic-gate 13130Sstevel@tonic-gate /* 13140Sstevel@tonic-gate * Turn off the SCE (syscall enable) bit in the EFER register. Software 13150Sstevel@tonic-gate * executing syscall or sysret with this bit off will incur a #ud trap. 13160Sstevel@tonic-gate */ 13170Sstevel@tonic-gate (void) rdmsr(MSR_AMD_EFER, &value); 13180Sstevel@tonic-gate value &= ~AMD_EFER_SCE; 13190Sstevel@tonic-gate wrmsr(MSR_AMD_EFER, &value); 13200Sstevel@tonic-gate } 1321