mp_startup.c revision d90554eb1da54eb443177f39ed0e119805d34a46
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/asm_linkage.h>
#include <vm/seg_kmem.h>
#include <sys/segments.h>
#include <sys/smp_impldefs.h>
#include <sys/x86_archext.h>
#include <sys/machsystm.h>
#include <sys/traptrace.h>
#include <sys/cpc_impl.h>
#include <sys/archsystm.h>
#include <sys/pci_cfgspace.h>
/*
* Useful for disabling MP bring-up for an MP capable kernel
* (a kernel that was built with MP defined)
*/
int use_mp = 1;
/*
* This variable is used by the hat layer to decide whether or not
* critical sections are needed to prevent race conditions. For sun4m,
* this variable is set once enough MP initialization has been done in
* order to allow cross calls.
*/
int flushes_require_xcalls = 0;
extern void real_mode_start(void);
extern void real_mode_end(void);
static void mp_startup(void);
static void cpu_sep_enable(void);
static void cpu_sep_disable(void);
static void cpu_asysc_enable(void);
static void cpu_asysc_disable(void);
extern int tsc_gethrtime_enable;
/*
* Init CPU info - get CPU type info for processor_info system call.
*/
void
{
char buf[CPU_IDSTRLEN];
/*
* Get clock-frequency property for the CPU.
*/
if (fpu_exists)
}
/*
* Configure syscall support on this CPU.
*/
/*ARGSUSED*/
static void
{
#if defined(__amd64)
if (x86_feature & X86_ASYSC) {
#if !defined(__lint)
/*
* The syscall instruction imposes a certain ordering on
* segment selectors, so we double-check that ordering
* here.
*/
#endif
/*
*/
/*
* Program the magic registers ..
*/
32);
/*
* This list of flags is masked off the incoming
* %rfl when we enter the kernel.
*/
}
#endif
/*
*
* On 64-bit kernels on Nocona machines, the 32-bit syscall
* variant isn't available to 32-bit applications, but sysenter is.
*/
if (x86_feature & X86_SEP) {
#if !defined(__lint)
/*
* The sysenter instruction imposes a certain ordering on
* segment selectors, so we double-check that ordering
* here. See "sysenter" in Intel document 245471-012, "IA-32
* Intel Architecture Software Developer's Manual Volume 2:
* Instruction Set Reference"
*/
#endif
/*
* resume() sets this value to the base of the threads stack
* via a context handler.
*/
}
}
/*
* Multiprocessor initialization.
*
* Allocate and initialize the cpu structure, TRAPTRACE buffer, and the
* startup and idle threads for the specified CPU.
*/
static void
mp_startup_init(int cpun)
{
#if defined(__amd64)
extern void *long_mode_64(void);
#endif /* __amd64 */
int size;
extern void idle();
extern void init_intr_threads(struct cpu *);
struct cpu_tables *tablesp;
#ifdef TRAPTRACE
#endif
panic("mp_startup_init: cpu%d: "
"no memory for cpu structure", cpun);
/*NOTREACHED*/
}
/*
* Initialize the dispatcher first.
*/
/*
* Allocate and initialize the startup thread for this CPU.
* Interrupt and process switch stacks get allocated later
* when the CPU starts running.
*/
/*
* Set state to TS_ONPROC since this thread will start running
* as soon as the CPU comes online.
*
* All the other fields of the thread structure are setup by
* thread_create().
*/
/*
* Setup thread to start in mp_startup.
*/
/*
* Now, initialize per-CPU idle thread for this CPU.
*/
/*
* Bootstrap the CPU for CMT aware scheduling
* The rest of the initialization will happen from
* mp_startup()
*/
/*
* Perform CPC intialization on the new CPU.
*/
/*
* Allocate virtual addresses for cpu_caddr1 and cpu_caddr2
* for each CPU.
*/
/*
* Allocate space for page directory, stack, tss, gdt and idt.
* This assumes that kmem_alloc will return memory which is aligned
* to the next higher power of 2 or a page(if size > MAXABIG)
* If this assumption goes wrong at any time due to change in
* kmem alloc, things may not work as the page directory has to be
* page aligned
*/
tablesp = (struct cpu_tables *)
}
#if defined(__amd64)
/*
* #DF (double fault).
*/
/*
* setup kernel %gs.
*/
SEL_KPL, 0, 1);
#endif /* __i386 */
/*
* Set I/O bit map offset equal to size of TSS segment limit
* for no I/O permission map. This will cause all user I/O
* instructions to generate #gp fault.
*/
/*
* setup kernel tss.
*/
/*
* If we have more than one node, each cpu gets a copy of IDT
* local to its node. If this is a Pentium box, we use cpu 0's
* IDT. cpu 0's IDT has been made read-only to workaround the
* cmpxchgl register bug
*/
}
/*
* Get interrupt priority data from cpu 0
*/
/*
* Fill up the real mode platter to make it easy for real mode code to
* kick it off. This area should really be one passed by boot to kernel
* and guaranteed to be below 1MB and aligned to 16 bytes. Should also
* have identical physical and virtual address in paged mode.
*/
#if defined(__amd64)
if (getcr3() > 0xffffffffUL)
panic("Cannot initialize CPUs; kernel's 64-bit page tables\n"
"located above 4G in physical memory (@ 0x%llx).",
(unsigned long long)getcr3());
/*
* Setup pseudo-descriptors for temporary GDT and IDT for use ONLY
* by code in real_mode_start():
*
* GDT[0]: NULL selector
* GDT[1]: 64-bit CS: Long = 1, Present = 1, bits 12, 11 = 1
*
* Clear the IDT as interrupts will be off and a limit of 0 will cause
* the CPU to triple fault and reset on an NMI, seemingly as reasonable
* a course of action as any other, though it may cause the entire
* platform to reset in some cases...
*/
/*
* Since the CPU needs to jump to protected mode using an identity
* mapped address, we need to calculate it here.
*/
#endif /* __amd64 */
#ifdef TRAPTRACE
/*
* If this is a TRAPTRACE kernel, allocate TRAPTRACE buffers for this
* CPU.
*/
#endif
/*
* Record that we have another CPU.
*/
/*
* Initialize the interrupt threads for this CPU
*/
/*
* Add CPU to list of available CPUs. It'll be on the active list
* after mp_startup().
*/
}
/*
* Apply workarounds for known errata, and warn about those that are absent.
*
* System vendors occasionally create configurations which contain different
* revisions of the CPUs that are almost but not exactly the same. At the
* time of writing, this meant that their clock rates were the same, their
* feature sets were the same, but the required workaround were -not-
* necessarily the same. So, this routine is invoked on -every- CPU soon
* after starting to make sure that the resulting system contains the most
* pessimal set of workarounds needed to cope with *any* of the CPUs in the
* system.
*
* workaround_errata is invoked early in mlsetup() for CPU 0, and in
* mp_startup() for all slave CPUs. Slaves process workaround_errata prior
* to acknowledging their readiness to the master, so this routine will
* never be executed by multiple CPUs in parallel, thus making updates to
* global data safe.
*
* These workarounds are based on Rev 3.57 of the Revision Guide for
* AMD Athlon(tm) 64 and AMD Opteron(tm) Processors, August 2005.
*/
#if defined(OPTERON_ERRATUM_91)
int opteron_erratum_91; /* if non-zero -> at least one cpu has it */
#endif
#if defined(OPTERON_ERRATUM_93)
int opteron_erratum_93; /* if non-zero -> at least one cpu has it */
#endif
#if defined(OPTERON_ERRATUM_100)
int opteron_erratum_100; /* if non-zero -> at least one cpu has it */
#endif
#if defined(OPTERON_ERRATUM_109)
int opteron_erratum_109; /* if non-zero -> at least one cpu has it */
#endif
#if defined(OPTERON_ERRATUM_121)
int opteron_erratum_121; /* if non-zero -> at least one cpu has it */
#endif
#if defined(OPTERON_ERRATUM_122)
int opteron_erratum_122; /* if non-zero -> at least one cpu has it */
#endif
#if defined(OPTERON_ERRATUM_123)
int opteron_erratum_123; /* if non-zero -> at least one cpu has it */
#endif
#if defined(OPTERON_ERRATUM_131)
int opteron_erratum_131; /* if non-zero -> at least one cpu has it */
#endif
#if defined(OPTERON_WORKAROUND_6336786)
int opteron_workaround_6336786; /* non-zero -> WA relevant and applied */
int opteron_workaround_6336786_UP = 0; /* Not needed for UP */
#endif
{
/*LINTED*/
/*
* SWAPGS May Fail To Read Correct GS Base
*/
#if defined(OPTERON_ERRATUM_88)
/*
* The workaround is an mfence in the relevant assembler code
*/
#else
missing++;
#endif
}
/*
* Software Prefetches May Report A Page Fault
*/
#if defined(OPTERON_ERRATUM_91)
/*
* fix is in trap.c
*/
#else
missing++;
#endif
}
/*
* RSM Auto-Halt Restart Returns to Incorrect RIP
*/
#if defined(OPTERON_ERRATUM_93)
/*
* fix is in trap.c
*/
#else
missing++;
#endif
}
/*LINTED*/
/*
* RET Instruction May Return to Incorrect EIP
*/
#if defined(OPTERON_ERRATUM_95)
#if defined(_LP64)
/*
* Workaround this by ensuring that 32-bit user code and
* 64-bit kernel code never occupy the same address
* range mod 4G.
*/
if (_userlimit32 > 0xc0000000ul)
/*LINTED*/
#endif /* _LP64 */
#else
missing++;
#endif /* OPTERON_ERRATUM_95 */
}
/*
* Compatibility Mode Branches Transfer to Illegal Address
*/
#if defined(OPTERON_ERRATUM_100)
/*
* fix is in trap.c
*/
#else
missing++;
#endif
}
/*LINTED*/
/*
* CPUID Instruction May Return Incorrect Model Number In
* Some Processors
*/
#if defined(OPTERON_ERRATUM_108)
/*
* (Our cpuid-handling code corrects the model number on
* those processors)
*/
#else
missing++;
#endif
}
/*LINTED*/
/*
* Certain Reverse REP MOVS May Produce Unpredictable Behaviour
*/
#if defined(OPTERON_ERRATUM_109)
/* workaround is to print a warning to upgrade BIOS */
if (rdmsr(MSR_AMD_PATCHLEVEL) == 0)
#else
missing++;
#endif
}
/*LINTED*/
/*
* Sequential Execution Across Non_Canonical Boundary Caused
* Processor Hang
*/
#if defined(OPTERON_ERRATUM_121)
static int lma;
if (opteron_erratum_121)
/*
* Erratum 121 is only present in long (64 bit) mode.
* Workaround is to include the page immediately before the
* va hole to eliminate the possibility of system hangs due to
* sequential execution across the va hole boundary.
*/
if (lma == 0) {
/*
* check LMA once: assume all cpus are in long mode
* or not.
*/
lma = 1;
if (hole_start) {
hole_start -= PAGESIZE;
} else {
/*
* hole_start not yet initialized by
* mmu_init. Initialize hole_start
* with value to be subtracted.
*/
}
}
}
#else
missing++;
#endif
}
/*LINTED*/
/*
* TLB Flush Filter May Cause Cohenrency Problem in
* Multiprocessor Systems
*/
#if defined(OPTERON_ERRATUM_122)
/*
* Erratum 122 is only present in MP configurations (multi-core
* or multi-processor).
*/
/* disable TLB Flush Filter */
}
#else
missing++;
#endif
}
#if defined(OPTERON_ERRATUM_123)
/*LINTED*/
/*
* Bypassed Reads May Cause Data Corruption of System Hang in
* Dual Core Processors
*/
/*
* Erratum 123 applies only to multi-core cpus.
*/
/* workaround is to print a warning to upgrade BIOS */
if (rdmsr(MSR_AMD_PATCHLEVEL) == 0)
}
}
#endif
#if defined(OPTERON_ERRATUM_131)
/*LINTED*/
/*
* Multiprocessor Systems with Four or More Cores May Deadlock
* Waiting for a Probe Response
*/
/*
* Erratum 131 applies to any system with four or more cores.
*/
if ((opteron_erratum_131 == 0) && ((lgrp_plat_node_cnt *
/*
* Workaround is to print a warning to upgrade
* the BIOS
*/
}
}
#endif
#if defined(OPTERON_WORKAROUND_6336786)
/*
* This isn't really erratum, but for convenience the
* detection/workaround code lives here and in cpuid_opteron_erratum.
*/
int node;
/*
* Disable C1-Clock ramping on multi-core/multi-processor
* K8 platforms to guard against TSC drift.
*/
if (opteron_workaround_6336786) {
} else if ((lgrp_plat_node_cnt *
/*
* Clear PMM7[1:0] (function 3, offset 0x87)
* Northbridge device is the node id + 24.
*/
data &= 0xFC;
}
}
}
#endif
return (missing);
}
void
{
#if defined(OPTERON_ERRATUM_109)
if (opteron_erratum_109) {
"BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)"
" processor\nerratum 109 was not detected; updating your"
" system's BIOS to a version\ncontaining this"
" microcode patch is HIGHLY recommended or erroneous"
" system\noperation may occur.\n");
}
#endif /* OPTERON_ERRATUM_109 */
#if defined(OPTERON_ERRATUM_123)
if (opteron_erratum_123) {
"BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)"
" processor\nerratum 123 was not detected; updating your"
" system's BIOS to a version\ncontaining this"
" microcode patch is HIGHLY recommended or erroneous"
" system\noperation may occur.\n");
}
#endif /* OPTERON_ERRATUM_123 */
#if defined(OPTERON_ERRATUM_131)
if (opteron_erratum_131) {
"BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)"
" processor\nerratum 131 was not detected; updating your"
" system's BIOS to a version\ncontaining this"
" microcode patch is HIGHLY recommended or erroneous"
" system\noperation may occur.\n");
}
#endif /* OPTERON_ERRATUM_131 */
}
static ushort_t *mp_map_warm_reset_vector();
/*ARGSUSED*/
void
start_other_cpus(int cprboot)
{
unsigned who;
int cpuid = 0;
int delays = 0;
int started_cpu;
extern int procset;
/*
* Initialize our own cpu_info.
*/
/*
* Initialize our syscall handlers
*/
/*
* if only 1 cpu or not using MP, skip the rest of this
*/
if (use_mp == 0)
goto done;
}
/*
* perform such initialization as is needed
* to be able to take CPUs on- and off-line.
*/
xc_init(); /* initialize processor crosscalls */
/*
* Copy the real mode code at "real_mode_start" to the
* page at rm_platter_va.
*/
if (warm_reset_vector == NULL)
goto done;
continue;
continue;
started_cpu = 1;
delay(1);
"cpu%d failed to start", who);
started_cpu = 0;
break;
}
}
if (!started_cpu)
continue;
if (tsc_gethrtime_enable)
if (dtrace_cpu_init != NULL) {
/*
* DTrace CPU initialization expects cpu_lock
* to be held.
*/
(*dtrace_cpu_init)(who);
}
}
continue;
continue;
delay(1);
}
done:
if (warm_reset_vector != NULL)
}
/*
* Dummy functions - no i86pc platforms support dynamic cpu allocation.
*/
/*ARGSUSED*/
int
mp_cpu_configure(int cpuid)
{
return (ENOTSUP); /* not supported */
}
/*ARGSUSED*/
int
mp_cpu_unconfigure(int cpuid)
{
return (ENOTSUP); /* not supported */
}
/*
* Startup function for 'other' CPUs (besides boot cpu).
* Resumed from cpu_startup.
*
* WARNING: until CPU_READY is set, mp_startup and routines called by
* mp_startup should not call routines (e.g. kmem_free) that could call
* hat_unload which requires CPU_READY to be set.
*/
void
mp_startup(void)
{
extern int procset;
/*
* We need to Sync MTRR with cpu0's MTRR. We have to do
* this with interrupts disabled.
*/
if (x86_feature & X86_MTRR)
mtrr_sync();
/*
* Enable machine check architecture
*/
if (x86_feature & X86_MCA)
setup_mca();
/*
* Initialize this CPU's syscall handlers
*/
/*
* Enable interrupts with spl set to LOCK_LEVEL. LOCK_LEVEL is the
* highest level at which a routine is permitted to block on
* an adaptive mutex (allows for cpu poke interrupt in case
* the cpu is blocked on a mutex and halts). Setting LOCK_LEVEL blocks
* device interrupts that may end up in the hat layer issuing cross
* calls before CPU_READY is set.
*/
/*
* Do a sanity check to make sure this new CPU is a sane thing
* to add to the collection of processors running this system.
*
* XXX Clearly this needs to get more sophisticated, if x86
* systems start to get built out of heterogenous CPUs; as is
* likely to happen once the number of processors in a configuration
* gets large enough.
*/
}
/*
* We could be more sophisticated here, and just mark the CPU
* as "faulted" but at this point we'll opt for the easier
* answer of dieing horribly. Provided the boot cpu is ok,
* the system can be recovered by booting with use_mp set to zero.
*/
if (workaround_errata(cp) != 0)
(void) cpuid_pass4(cp);
if (tsc_gethrtime_enable)
/*
* It's unfortunate that chip_cpu_init() has to be called here.
* It really belongs in cpu_add_unit(), but unfortunately it is
* dependent on the cpuid probing, which must be done in the
* context of the current CPU. Care must be taken on x86 to ensure
* that mp_startup can safely block even though chip_cpu_init() and
* cpu_add_active() have not yet been called.
*/
(void) spl0(); /* enable interrupts */
/*
* Setting the bit in cpu_ready_set must be the last operation in
* processor initialization; the boot CPU will continue to boot once
* it sees this bit set for all active CPUs.
*/
/*
* Because mp_startup() gets fired off after init() starts, we
* can't use the '?' trick to do 'boot -v' printing - so we
* always direct the 'cpu .. online' messages to the log.
*/
/*
* Now we are done with the startup thread, so free it up.
*/
thread_exit();
panic("mp_startup: cannot return");
/*NOTREACHED*/
}
/*
* Start CPU on user request.
*/
/* ARGSUSED */
int
{
return (0);
}
/*
* Stop CPU on user request.
*/
/* ARGSUSED */
int
{
extern int cbe_psm_timer_mode;
/*
* If TIMER_PERIODIC mode is used, CPU0 is the one running it;
* can't stop it. (This is true only for machines with no TSC.)
*/
return (1);
return (0);
}
/*
* Power on CPU.
*/
/* ARGSUSED */
int
{
return (ENOTSUP); /* not supported */
}
/*
* Power off CPU.
*/
/* ARGSUSED */
int
{
return (ENOTSUP); /* not supported */
}
/*
* Take the specified CPU out of participation in interrupts.
*/
int
{
return (EBUSY);
return (0);
}
/*
* Allow the specified CPU to participate in interrupts.
*/
void
{
}
static ushort_t *
{
return (NULL);
/*
* setup secondary cpu bios boot up vector
*/
return (warm_reset_vector);
}
static void
{
}
/*ARGSUSED*/
void
{}
/*ARGSUSED*/
void
{}
/*
* The following two routines are used as context operators on threads belonging
* to processes with a private LDT (see sysi86). Due to the rarity of such
* processes, these routines are currently written for best code readability and
* organization rather than speed. We could avoid checking x86_feature at every
* context switch by installing different context ops, depending on the
* x86_feature flags, at LDT creation time -- one for each combination of fast
* syscall feature flags.
*/
/*ARGSUSED*/
void
cpu_fast_syscall_disable(void *arg)
{
if (x86_feature & X86_SEP)
if (x86_feature & X86_ASYSC)
}
/*ARGSUSED*/
void
cpu_fast_syscall_enable(void *arg)
{
if (x86_feature & X86_SEP)
if (x86_feature & X86_ASYSC)
}
static void
cpu_sep_enable(void)
{
}
static void
cpu_sep_disable(void)
{
/*
* Setting the SYSENTER_CS_MSR register to 0 causes software executing
* the sysenter or sysexit instruction to trigger a #gp fault.
*/
}
static void
cpu_asysc_enable(void)
{
}
static void
cpu_asysc_disable(void)
{
/*
* Turn off the SCE (syscall enable) bit in the EFER register. Software
* executing syscall or sysret with this bit off will incur a #ud trap.
*/
}