mp_machdep.c revision e23a7e348c32cb3a1a7072dcac6905a150a028d7
/*
* 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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#define PSMI_1_5
#include <sys/smp_impldefs.h>
#include <sys/psm_modctl.h>
#include <sys/x86_archext.h>
#include <sys/archsystm.h>
#include <sys/mach_intr.h>
/*
* Local function prototypes
*/
static void mach_init();
static void mach_picinit();
static uint64_t mach_getcpufreq(void);
static void mach_fixcpufreq(void);
static int mach_clkinit(int, int *);
static void mach_smpinit(void);
static void mach_cpu_start(int cpun);
static int mach_softlvl_to_vect(int ipl);
static void mach_get_platform(int owner);
static void mach_construct_info();
psm_intr_op_t, int *);
static timestruc_t mach_tod_get(void);
static hrtime_t dummy_hrtime(void);
static void dummy_scalehrtime(hrtime_t *);
static void cpu_halt(void);
static void cpu_wakeup(cpu_t *, int);
/*
* External reference functions
*/
extern void return_instr();
extern timestruc_t (*todgetf)(void);
extern void (*todsetf)(timestruc_t);
extern long gmt_lag;
#if defined(__i386)
#endif
extern void pc_gethrestime(timestruc_t *);
/*
* PSM functions initialization
*/
void (*psm_shutdownf)(int, int) = return_instr;
void (*psm_preshutdownf)(int, int) = return_instr;
void (*psm_notifyf)(int) = return_instr;
void (*psm_set_idle_cpuf)(int) = return_instr;
void (*psm_unset_idle_cpuf)(int) = return_instr;
void (*picinitf)() = return_instr;
int (*clkinitf)(int, int *) = (int (*)(int, int *))return_instr;
void (*cpu_startf)() = return_instr;
int (*ap_mlsetup)() = (int (*)(void))return_instr;
void (*send_dirintf)() = return_instr;
void (*setspl)(int) = return_instr;
int (*addspl)(int, int, int, int) = (int (*)(int, int, int, int))return_instr;
int (*delspl)(int, int, int, int) = (int (*)(int, int, int, int))return_instr;
void (*setsoftint)(int, struct av_softinfo *)=
(void (*)(int, struct av_softinfo *))return_instr;
int (*slvltovect)(int) = (int (*)(int))return_instr;
int (*setlvl)(int, int *) = (int (*)(int, int *))return_instr;
void (*setlvlx)(int, int) = (void (*)(int, int))return_instr;
int (*psm_disable_intr)(int) = mp_disable_intr;
void (*psm_enable_intr)(int) = mp_enable_intr;
void (*psm_notify_error)(int, char *) = (void (*)(int, char *))NULL;
int (*psm_get_clockirq)(int) = NULL;
int (*psm_get_ipivect)(int, int) = NULL;
int (*psm_clkinit)(int) = NULL;
void (*psm_timer_enable)(void) = NULL;
void (*psm_timer_disable)(void) = NULL;
int *) = mach_intr_ops;
void (*notify_error)(int, char *) = (void (*)(int, char *))return_instr;
void (*hrtime_tick)(void) = return_instr;
int tsc_gethrtime_enable = 1;
int tsc_gethrtime_initted = 0;
/*
* Local Static Data
*/
/*
* If non-zero, idle cpus will "halted" when there's
* no work to do.
*/
int halt_idle_cpus = 1;
#if defined(__amd64)
/*
* If non-zero, will use cr8 for interrupt priority masking
* We declare this here since install_spl is called from here
* (where this is checked).
*/
int intpri_use_cr8 = 0;
#endif /* __amd64 */
#ifdef _SIMULATOR_SUPPORT
int simulator_run = 0; /* patch to non-zero if running under simics */
#endif /* _SIMULATOR_SUPPORT */
/* ARGSUSED */
void
{
/*
* Hyperthreading is SMT
*/
else
cd->chipd_rechoose_adj = 0;
}
/*
* Routine to ensure initial callers to hrtime gets 0 as return
*/
static hrtime_t
dummy_hrtime(void)
{
return (0);
}
/* ARGSUSED */
static void
{}
/*
* Halt the present CPU until awoken via an interrupt
*/
static void
cpu_halt(void)
{
int hset_update = 1;
/*
* If this CPU is online, and there's multiple CPUs
* in the system, then we should notate our halting
* by adding ourselves to the partition's halted CPU
* work becomes available.
*/
hset_update = 0;
/*
* Add ourselves to the partition's halted CPUs bitmask
* and set our HALTED flag, if necessary.
*
* When a thread becomes runnable, it is placed on the queue
* and then the halted cpuset is checked to determine who
* (if anyone) should be awoken. We therefore need to first
* add ourselves to the halted cpuset, and and then check if there
* is any work available.
*
* Note that memory barriers after updating the HALTED flag
* are not necessary since an atomic operation (updating the bitmap)
* immediately follows. On x86 the atomic operation acts as a
* memory barrier for the update of cpu_disp_flags.
*/
if (hset_update) {
}
/*
* Check to make sure there's really nothing to do.
* Work destined for this CPU may become available after
* this check. We'll be notified through the clearing of our
* bit in the halted CPU bitmask, and a poke.
*/
if (disp_anywork()) {
if (hset_update) {
}
return;
}
/*
* We're on our way to being halted.
*
* Disable interrupts now, so that we'll awaken immediately
* after halting if someone tries to poke us between now and
* the time we actually halt.
*
* We check for the presence of our bit after disabling interrupts.
* If it's cleared, we'll return. If the bit is cleared after
* we check then the poke will pop us out of the halted state.
*
* This means that the ordering of the poke and the clearing
* of the bit by cpu_wakeup is important.
* cpu_wakeup() must clear, then poke.
* cpu_halt() must disable interrupts, then check for the bit.
*/
cli();
sti();
return;
}
/*
* The check for anything locally runnable is here for performance
* and isn't needed for correctness. disp_nrunnable ought to be
* in our cache still, so it's inexpensive to check, and if there
* is anything runnable we won't have to wait for the poke.
*/
if (hset_update) {
}
sti();
return;
}
/*
* Call the halt sequence:
* sti
* hlt
*/
i86_halt();
/*
* We're no longer halted
*/
if (hset_update) {
}
}
/*
* If "cpu" is halted, then wake it up clearing its halted bit in advance.
* Otherwise, see if other CPUs in the cpu partition are halted and need to
* be woken up so that they can steal the thread we placed on this CPU.
* This function is only used on MP systems.
*/
static void
{
int result;
/*
* Clear the halted bit for that CPU since it will be
* poked in a moment.
*/
/*
* We may find the current CPU present in the halted cpuset
* if we're in the context of an interrupt that occurred
* before we had a chance to clear our bit in cpu_halt().
* Poking ourself is obviously unnecessary, since if
* we're here, we're not halted.
*/
return;
} else {
/*
* This cpu isn't halted, but it's idle or undergoing a
* context switch. No need to awaken anyone else.
*/
return;
}
/*
* No need to wake up other CPUs if the thread we just enqueued
* is bound.
*/
if (bound)
return;
/*
* See if there's any other halted CPUs. If there are, then
* select one, and awaken it.
* It's possible that after we find a CPU, somebody else
* will awaken it before we get the chance.
* In that case, look again.
*/
do {
if (cpu_found == CPUSET_NOTINSET)
return;
} while (result < 0);
}
static int
mp_disable_intr(int cpun)
{
/*
* switch to the offline cpu
*/
/*
* raise ipl to just below cross call
*/
/*
* set base spl to prevent the next swtch to idle from
* lowering back to ipl 0
*/
set_base_spl();
return (DDI_SUCCESS);
}
static void
mp_enable_intr(int cpun)
{
/*
* switch to the online cpu
*/
/*
* clear the interrupt active mask
*/
set_base_spl();
(void) spl0();
}
static void
mach_get_platform(int owner)
{
void **srv_opsp;
void **clt_opsp;
int i;
int total_ops;
/* fix up psm ops */
total_ops = sizeof (struct psm_ops_ver01) /
sizeof (void (*)(void));
/* no psm_notify_func */
sizeof (void (*)(void));
/* no psm_timer funcs */
sizeof (void (*)(void));
/* no psm_preshutdown function */
sizeof (void (*)(void));
/* no psm_preshutdown function */
sizeof (void (*)(void));
else
/*
* Save the version of the PSM module, in case we need to
* bahave differently based on version.
*/
for (i = 0; i < total_ops; i++)
}
static void
{
int conflict_owner = 0;
panic("No valid PSM modules found");
continue;
}
/* check to see are there any conflicts */
if (conflict_owner) {
/* remove all psm modules except uppc */
"Conflicts detected on the following PSM modules:");
}
"Setting the system back to SINGLE processor mode!");
return;
}
if (mach_set[PSM_OWN_EXCLUSIVE])
if (mach_set[PSM_OWN_OVERRIDE])
}
static void
{
/* register the interrupt and clock initialization rotuines */
/* register the interrupt setup code */
if (pops->psm_translate_irq)
if (pops->psm_intr_ops)
if (pops->psm_tod_get) {
}
if (pops->psm_tod_set) {
}
if (pops->psm_notify_error) {
}
(*pops->psm_softinit)();
/*
* Initialize the dispatcher's function hooks
* to enable CPU halting when idle
*/
#if defined(_SIMULATOR_SUPPORT)
if (halt_idle_cpus && !simulator_run)
#else
if (halt_idle_cpus)
#endif /* _SIMULATOR_SUPPORT */
mach_smpinit();
}
static void
mach_smpinit(void)
{
register processorid_t cpu_id;
int cnt;
int cpumask;
cpu_id = -1;
}
/* MP related routines */
/* optional MP related routines */
if (pops->psm_shutdown)
if (pops->psm_preshutdown)
if (pops->psm_notify_func)
if (pops->psm_set_idlecpu)
if (pops->psm_unset_idlecpu)
if (pops->psm_timer_reprogram)
if (pops->psm_timer_enable)
if (pops->psm_timer_disable)
if (pops->psm_post_cyclic_setup)
/* check for multiple cpu's */
if (cnt < 2)
return;
/* check for MP platforms */
return;
/*
* Set the dispatcher hook to enable cpu "wake up"
* when a thread becomes runnable.
*/
#if defined(_SIMULATOR_SUPPORT)
if (halt_idle_cpus && !simulator_run) {
}
#else
if (halt_idle_cpus) {
}
#endif /* _SIMULATOR_SUPPORT */
if (pops->psm_disable_intr)
if (pops->psm_enable_intr)
}
static void
{
extern void install_spl(void); /* XXX: belongs in a header file */
#endif
/* register the interrupt handlers */
/* initialize the interrupt hardware */
(*pops->psm_picinit)();
/* set interrupt mask for current ipl */
/* Install proper spl routine now that we can Program the PIC */
#if defined(__amd64)
/*
* It would be better if we could check this at compile time
*/
#endif
install_spl();
}
#define MEGA_HZ 1000000
static uint64_t
{
if ((pit_counter == 0) || (*processor_clks == 0) ||
return (0);
return (cpu_hz);
}
static uint64_t
mach_getcpufreq(void)
{
if (x86_feature & X86_TSC) {
/*
* We have a TSC. freq_tsc() knows how to measure the number
* of clock cycles sampled against the PIT.
*/
#if defined(__amd64)
panic("mach_getcpufreq: no TSC!");
/*
* We are a Cyrix based on a 6x86 core or an Intel Pentium
* for which freq_notsc() knows how to measure the number of
* elapsed clock cycles sampled against the PIT
*/
#endif /* __i386 */
}
/* We do not know how to calculate cpu frequency for this cpu. */
return (0);
}
/*
* If the clock speed of a cpu is found to be reported incorrectly, do not add
* to this array, instead improve the accuracy of the algorithm that determines
* the clock speed of the processor or extend the implementation to support the
* vendor as appropriate. This is here only to support adjusting the speed on
* older slower processors that mach_fixcpufreq() would not be able to account
* for otherwise.
*/
/*
* On fast processors the clock frequency that is measured may be off by
* a few MHz from the value printed on the part. This is a combination of
* the factors that for such fast parts being off by this much is within
* the tolerances for manufacture and because of the difficulties in the
* measurement that can lead to small error. This function uses some
* heuristics in order to tweak the value that was measured to match what
* is most likely printed on the part.
*
* Some examples:
* AMD Athlon 1000 mhz measured as 998 mhz
* Intel Pentium III Xeon 733 mhz measured as 731 mhz
* Intel Pentium IV 1500 mhz measured as 1495mhz
*
* If in the future this function is no longer sufficient to correct
* for the error in the measurement, then the algorithm used to perform
* the measurement will have to be improved in order to increase accuracy
* rather than adding horrible and questionable kludges here.
*
* This is called after the cyclics subsystem because of the potential
* that the heuristics within may give a worse estimate of the clock
* frequency than the value that was measured.
*/
static void
mach_fixcpufreq(void)
{
/*
* Find the nearest integer multiple of 200/3 (about 66) MHz to the
* measured speed taking into account that the 667 MHz parts were
* the first to round-up.
*/
/* Find the nearest integer multiple of 50 MHz to the measured speed */
/* Find the closer of the two */
} else {
}
return;
/*
* Some older parts have a core clock frequency that is not an
* integral multiple of 50 or 66 MHz. Check if one of the old
* clock frequencies is closer to the measured value than any
* of the integral multiples of 50 an 66, and if so set fixed
* and delta appropriately to represent the closest value.
*/
i = sizeof (x86_cpu_freq) / sizeof (int);
while (i > 0) {
i--;
if (x86_cpu_freq[i] <= freq) {
fixed = x86_cpu_freq[i];
}
break;
}
fixed = x86_cpu_freq[i];
}
}
/*
* Set a reasonable maximum for how much to correct the measured
* result by. This check is here to prevent the adjustment made
* by this function from being more harm than good. It is entirely
* possible that in the future parts will be made that are not
* integral multiples of 66 or 50 in clock frequency or that
* someone may overclock a part to some odd frequency. If the
* measured value is farther from the corrected value than
* allowed, then assume the corrected value is in error and use
* the measured value.
*/
if (6 < delta)
return;
}
static int
{
/* Round to nearest MHZ */
return (0);
return ((int)cpu_mhz);
}
static int
{
int resolution;
#ifdef _SIMULATOR_SUPPORT
if (!simulator_run)
else
#else
#endif /* _SIMULATOR_SUPPORT */
tsc_gethrtime_enable = 0;
if (tsc_gethrtime_enable) {
} else {
if (pops->psm_hrtimeinit)
(*pops->psm_hrtimeinit)();
/* scalehrtimef will remain dummy */
}
if (mach_ver[0] >= PSM_INFO_VER01_3) {
if ((preferred_mode == TIMER_ONESHOT) &&
(tsc_gethrtime_enable)) {
if (resolution != 0) {
return (resolution);
}
}
/*
* either periodic mode was requested or could not set to
* one-shot mode
*/
/*
* psm should be able to do periodic, so we do not check
* for return value of psm_clkinit here.
*/
return (resolution);
} else {
/*
* PSMI interface prior to PSMI_3 does not define a return
* value for psm_clkinit, so the return value is ignored.
*/
return (nsec_per_tick);
}
}
/*ARGSUSED*/
static void
{
/* invoke hardware interrupt */
}
static int
mach_softlvl_to_vect(register int ipl)
{
register int softvect;
/* check for null handler for set soft interrupt call */
return (PSM_SV_SOFTWARE);
}
/* check for hardware scheme */
if (softvect > PSM_SV_SOFTWARE) {
return (softvect);
}
if (softvect == PSM_SV_SOFTWARE)
else /* hardware and software mixed scheme */
return (PSM_SV_SOFTWARE);
}
static void
{
/* set software pending bits */
/* check if dosoftint will be called at the end of intr */
return;
/* invoke hardware interrupt */
}
static void
mach_cpu_start(register int cpun)
{
int i;
/* wait for the auxillary cpu to be ready */
for (i = 20000; i; i--) {
return;
drv_usecwait(100);
}
}
/*ARGSUSED*/
static int
{
return (irqno); /* default to NO translation */
}
static timestruc_t
mach_tod_get(void)
{
/* The year returned from is the last 2 digit only */
if ((*psm_todgetf)(&tod)) {
return (ts);
}
/* assume that we wrap the rtc year back to zero at 2000 */
"of range -- time needs to be reset");
mach_range_warn = 0;
}
}
/* tod_to_utc uses 1900 as base for the year */
return (ts);
}
static void
{
(*psm_todsetf)(&tod);
}
static void
{
/*
* SL_FATAL is pass in once panicstr is set, deliver it
* as CE_PANIC. Also, translate SL_ codes back to CE_
* codes for the psmi handler
*/
else if (level & SL_CONSOLE)
}
/*
* It provides the default basic intr_ops interface for the new DDI
* interrupt framework if the PSM doesn't have one.
*
* Input:
* dip - pointer to the dev_info structure of the requested device
* hdlp - pointer to the internal interrupt handle structure for the
* requested interrupt
* intr_op - opcode for this call
* result - pointer to the integer that will hold the result to be
* passed back if return value is PSM_SUCCESS
*
* Output:
* return value is either PSM_SUCCESS or PSM_FAILURE
*/
static int
{
switch (intr_op) {
case PSM_INTR_OP_CHECK_MSI:
break;
*result = 1;
else
*result = 0;
break;
case PSM_INTR_OP_FREE_VECTORS:
break;
*result = 1;
else
*result = 0;
break;
case PSM_INTR_OP_XLATE_VECTOR:
break;
case PSM_INTR_OP_GET_CAP:
*result = 0;
break;
case PSM_INTR_OP_GET_PENDING:
case PSM_INTR_OP_CLEAR_MASK:
case PSM_INTR_OP_SET_MASK:
case PSM_INTR_OP_GET_SHARED:
case PSM_INTR_OP_SET_PRI:
case PSM_INTR_OP_SET_CAP:
case PSM_INTR_OP_SET_CPU:
case PSM_INTR_OP_GET_INTR:
default:
return (PSM_FAILURE);
}
return (PSM_SUCCESS);
}