/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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
*/
/*
*/
#include <sys/archsystm.h>
#include <sys/autoconf.h>
#include <sys/machsystm.h>
#include <vm/hat_sfmmu.h>
#include <sys/cpu_module.h>
#include <sys/cpu_sgnblk_defs.h>
#include <sys/kdi_impl.h>
#include <sys/traptrace.h>
#include <sys/hypervisor_api.h>
#include <sys/mach_descrip.h>
#include <sys/soft_state.h>
#include <sys/promimpl.h>
#include <sys/clock_impl.h>
/*
* hvdump_buf_va is a pointer to the currently-configured hvdump_buf.
* A value of NULL indicates that this area is not configured.
* hvdump_buf_sz is tunable but will be clamped to HVDUMP_SIZE_MAX.
*/
extern u_longlong_t gettick();
static void reboot_machine(char *);
static void update_hvdump_buffer(void);
/*
* For xt_sync synchronization.
*/
extern uint64_t xc_tick_limit;
extern uint64_t xc_tick_jump_limit;
extern uint64_t xc_sync_tick_limit;
/*
* Bring in the cpc PIL_15 handler for panic_enter_hw.
*/
extern uint64_t cpc_level15_inum;
/*
* We keep our own copies, used for cache flushing, because we can be called
* before cpu_fiximpl().
*/
static int kdi_dcache_size;
static int kdi_dcache_linesize;
static int kdi_icache_size;
static int kdi_icache_linesize;
/*
*/
extern void kdi_flush_idcache(int, int, int, int);
/*
* In an LDoms system we do not save the user's boot args in NVRAM
* as is done on legacy systems. Instead, we format and send a
* 'reboot-command' variable to the variable service. The contents
* of the variable are retrieved by OBP and used verbatim for
* the next boot.
*/
static void
{
static char *cmd_buf;
/*
* invoke_cb is set to true when we are in a normal shutdown sequence
* (interrupts are not blocked, the system is not panicking or being
* suspended). In that case, we can use any method to store the boot
* command. Otherwise storing the boot command can not be done using
* a domain service because it can not be safely used in that context.
*/
return;
return;
if (add_boot_str) {
}
}
}
/*
* Save the reboot-command with HV, if reboot data group is
* negotiated. Else save the reboot-command via vars-config domain
* services on the SP.
*/
"use on reboot with HV: error = 0x%lx", status);
}
} else {
node = prom_optionsnode();
"use on reboot");
}
}
/*
* Machine dependent code to reboot.
*
* "bootstr", when non-null, points to a string to be used as the
* argument string when rebooting.
*
* "invoke_cb" is a boolean. It is set to true when mdboot() can safely
* invoke CB_CL_MDBOOT callbacks before shutting the system down, i.e. when
* we are in a normal shutdown sequence (interrupts are not blocked, the
* system is not panic'ing or being suspended).
*/
/*ARGSUSED*/
void
{
extern void pm_cfb_check_and_powerup(void);
/*
* XXX - rconsvp is set to NULL to ensure that output messages
* are sent to the underlying "hardware" device using the
* monitor's printf routine since we are in the process of
* either rebooting or halting the machine.
*/
switch (fcn) {
case AD_HALT:
/*
* LDoms: By storing a no-op command
* in the 'reboot-command' variable we cause OBP
* to ignore the setting of 'auto-boot?' after
* it completes the reset. This causes the system
* to stop at the ok prompt.
*/
if (domaining_enabled())
break;
case AD_POWEROFF:
break;
default:
switch (fcn) {
case AD_FASTREBOOT:
case AD_BOOT:
bootstr = "";
break;
case AD_IBOOT:
bootstr = "-a";
break;
case AD_SBOOT:
bootstr = "-s";
break;
case AD_SIBOOT:
bootstr = "-sa";
break;
default:
"mdboot: invalid function %d", fcn);
bootstr = "";
break;
}
}
/*
* If LDoms is running, we must save the boot string
* before we enter restricted mode. This is possible
* only if we are not being called from panic.
*/
if (domaining_enabled())
}
/*
* At a high interrupt level we can't:
* 1) bring up the console
* or
* 2) wait for pending interrupts prior to redistribution
* to the current CPU
*
* so we do them now.
*/
/* make sure there are no more changes to the device tree */
if (invoke_cb)
/*
* Clear any unresolved UEs from memory.
*/
/*
* stop other cpus which also raise our priority. since there is only
* one active cpu after this, and our priority will be too high
* for us to be preempted, we're essentially single threaded
* from here on out.
*/
/*
* try and reset leaf devices. reset_leaves() should only
* be called when there are no other threads that could be
* accessing devices
*/
reset_leaves();
} else if (fcn == AD_POWEROFF) {
} else {
}
/* MAYBE REACHED */
}
/* mdpreboot - may be called prior to mdboot while root fs still mounted */
/*ARGSUSED*/
void
{
}
/*
* Halt the machine and then reboot with the device
* and arguments specified in bootstr.
*/
static void
{
stop_other_cpus(); /* send stop signal to other CPUs */
prom_printf("rebooting...\n");
/*
* For platforms that use CPU signatures, we
* need to set the signature block to OS and
* the state to exiting for all the processors.
*/
/*NOTREACHED*/
}
/*
* We use the x-trap mechanism and idle_stop_xcall() to stop the other CPUs.
* Once in panic_idle() they raise spl, record their location, and spin.
*/
static void
panic_idle(void)
{
(void) spl7();
membar_stld();
for (;;)
;
}
/*
* Force the other CPUs to trap into panic_idle(), and then remove them
* from the cpu_ready_set so they will no longer receive cross-calls.
*/
/*ARGSUSED*/
void
{
int i;
(void) splzs();
for (i = 0; i < NCPU; i++) {
DELAY(50);
ntries--;
}
printf("panic: failed to stop cpu%d\n", i);
}
}
}
/*
* Platform callback following each entry to panicsys(). If we've panicked at
* level 14, we examine t_panic_trap to see if a fatal trap occurred. If so,
* we disable further %tick_cmpr interrupts. If not, an explicit call to panic
* was made and so we re-enqueue an interrupt request structure to allow
* further level 14 interrupts to be processed once we lower PIL. This allows
* us to handle panics from the deadman() CY_HIGH_LEVEL cyclic.
*
* In case we panic at level 15, ensure that the cpc handler has been
* reinstalled otherwise we could run the risk of hitting a missing interrupt
* handler when this thread drops PIL and the cpc counter overflows.
*/
void
{
if (!panic_tick) {
panic_tick = gettick();
if (mach_htraptrace_enable) {
/* there are no possible error codes for this hcall */
&prev_freeze);
}
#ifdef TRAPTRACE
#endif
}
opstate = disable_vec_intr();
} else {
if (!tickcmpr_disabled())
/*
* Clear SOFTINT<14>, SOFTINT<0> (TICK_INT)
* and SOFTINT<16> (STICK_INT) to indicate
* that the current level 14 has been serviced.
*/
}
opstate = disable_vec_intr();
}
}
/*
* Miscellaneous hardware-specific code to execute after panicstr is set
* by the panic code: we also print and record PTL1 panic information here.
*/
/*ARGSUSED*/
void
{
/*
* Turn off TRAPTRACE and save the current %tick value in panic_tick.
*/
if (!panic_tick) {
panic_tick = gettick();
if (mach_htraptrace_enable) {
/* there are no possible error codes for this hcall */
&prev_freeze);
}
#ifdef TRAPTRACE
#endif
}
/*
* For Platforms that use CPU signatures, we
* need to set the signature block to OS, the state to
* exiting, and the substate to panic for all the processors.
*/
/*
* Disable further ECC errors from the bus nexus.
*/
(void) bus_func_invoke(BF_TYPE_ERRDIS);
/*
* Redirect all interrupts to the current CPU.
*/
/*
* This call exists solely to support dumps to network
* devices after sync from OBP.
*
* If we came here via the sync callback, then on some
* platforms, interrupts may have arrived while we were
* stopped in OBP. OBP will arrange for those interrupts to
* be redelivered if you say "go", but not if you invoke a
* client callback like 'sync'. For some dump devices
* (network swap devices), we need interrupts to be
* delivered in order to dump, so we have to call the bus
* nexus driver to reset the interrupt state machines.
*/
(void) bus_func_invoke(BF_TYPE_RESINTR);
}
/*
* Platforms that use CPU signatures need to set the signature block to OS and
* the state to exiting for all CPUs. PANIC_CONT indicates that we're about to
* reboot the machine if the dump never completes.
*/
/*ARGSUSED*/
void
{
}
/*
* for ptl1_panic
*/
void
{
/*CONSTCOND*/
panic("ptl1_init_cpu: not enough space left for ptl1_panic "
"stack, sizeof (struct cpu) = %lu",
(unsigned long)sizeof (struct cpu));
}
}
void
{
static const char *ptl1_reasons[] = {
#ifdef PTL1_PANIC_DEBUG
"trap for debug purpose", /* PTL1_BAD_DEBUG */
#else
"unknown trap", /* PTL1_BAD_DEBUG */
#endif
"register window trap", /* PTL1_BAD_WTRAP */
"kernel MMU miss", /* PTL1_BAD_KMISS */
"kernel protection fault", /* PTL1_BAD_KPROT_FAULT */
"ISM MMU miss", /* PTL1_BAD_ISM */
"kernel MMU trap", /* PTL1_BAD_MMUTRAP */
"kernel trap handler state", /* PTL1_BAD_TRAP */
"floating point trap", /* PTL1_BAD_FPTRAP */
#ifdef DEBUG
"pointer to intr_vec", /* PTL1_BAD_INTR_VEC */
#else
"unknown trap", /* PTL1_BAD_INTR_VEC */
#endif
#ifdef TRAPTRACE
"TRACE_PTR state", /* PTL1_BAD_TRACE_PTR */
#else
"unknown trap", /* PTL1_BAD_TRACE_PTR */
#endif
"stack overflow", /* PTL1_BAD_STACK */
"DTrace flags", /* PTL1_BAD_DTRACE_FLAGS */
"attempt to steal locked ctx", /* PTL1_BAD_CTX_STEAL */
"CPU ECC error loop", /* PTL1_BAD_ECC */
"unexpected error from hypervisor call", /* PTL1_BAD_HCALL */
"unexpected global level(%gl)", /* PTL1_BAD_GL */
"Watchdog Reset", /* PTL1_BAD_WATCHDOG */
"unexpected RED mode trap", /* PTL1_BAD_RED */
"return value EINVAL from hcall: "\
"UNMAP_PERM_ADDR", /* PTL1_BAD_HCALL_UNMAP_PERM_EINVAL */
"return value ENOMAP from hcall: "\
"UNMAP_PERM_ADDR", /* PTL1_BAD_HCALL_UNMAP_PERM_ENOMAP */
"error raising a TSB exception", /* PTL1_BAD_RAISE_TSBEXCP */
"missing shared TSB" /* PTL1_NO_SCDTSB8K */
};
/*
* Use trap_info for a place holder to call panic_savetrap() and
* panic_showtrap() to save and print out ptl1_panic information.
*/
else
}
void
clear_watchdog_on_exit(void)
{
if (watchdog_enabled && watchdog_activated) {
prom_printf("Debugging requested; hardware watchdog "
"suspended.\n");
(void) watchdog_suspend();
}
}
/*
* Restore the watchdog timer when returning from a debugger
* after a panic or L1-A and resume watchdog pat.
*/
void
{
}
int
kdi_watchdog_disable(void)
{
return (0);
}
void
kdi_watchdog_restore(void)
{
}
void
mach_dump_buffer_init(void)
{
if (hvdump_buf_sz > HVDUMP_SIZE_MAX)
if (hvdump_buf_va == NULL)
return;
&minsize);
"dump buffer. Error = 0x%lx, size = 0x%lx,"
"Available buffer size = 0x%lx,"
"Minimum buffer size required = 0x%lx",
}
}
}
static void
update_hvdump_buffer(void)
{
if (hvdump_buf_va == NULL)
return;
&dummy_val);
"buffer. Error = 0x%lx", ret);
}
}
static int
{
int value;
case 0:
break;
case sizeof (int):
break;
default:
break;
}
return (value);
}
/*
* Called by setcpudelay
*/
void
cpu_init_tick_freq(void)
{
int listsz;
int num_nodes;
if (broken_md_flag) {
return;
}
panic("stick_frequency property not found in MD");
panic("cannot allocate list for MD properties");
panic("stick_frequency property not found in MD");
(void) md_fini_handle(mdp);
}
#ifdef DEBUG
#endif
#ifdef SEND_MONDO_STATS
#endif
void
{
retries = 0;
if (stat != H_EWOULDBLOCK) {
if (panic_quiesce)
return;
if (stat == H_ECPUERROR)
"cpuid: 0x%x has been marked in "
"error", cpuid);
else
"unexpected hypervisor error 0x%x "
"while sending a mondo to cpuid: "
}
/*
* If there is a big jump between the current tick
* count and lasttick, we have probably hit a break
* point. Adjust endtick accordingly to avoid panic.
*/
if (panic_quiesce)
return;
"(target 0x%x) [retries: 0x%x hvstat: 0x%x]",
}
drv_usecwait(1);
retries++;
}
#ifdef SEND_MONDO_STATS
{
if (n < 8192)
x_one_stimes[n >> 7]++;
else if (n < 15*8192)
x_one_ltimes[n >> 13]++;
else
x_one_ltimes[0xf]++;
}
#endif
}
void
{
int i, j;
int ncpuids = 0;
int shipped = 0;
int retries = 0;
if (smallestid == CPUSET_NOTINSET) {
return;
}
/*
* Assemble CPU list for HV argument. We already know
* smallestid and largestid are members of set.
*/
if (largestid != smallestid) {
if (CPU_IN_SET(set, i)) {
}
}
}
do {
int stat;
break;
}
/*
* Either not all CPU mondos were sent, or an
* error occurred. CPUs that were sent mondos
* have their CPU IDs overwritten in cpu_list.
* Reset cpu_list so that it only holds those
* CPU IDs that still need to be sent.
*/
for (i = 0, j = 0; i < ncpuids; i++) {
shipped++;
} else {
}
}
ncpuids = j;
/*
* Now handle possible errors returned
* from hypervisor.
*/
if (stat == H_ECPUERROR) {
int errorcpus;
if (!panic_quiesce)
/*
* Remove any CPUs in the error state from
* cpu_list. At this point cpu_list only
* contains the CPU IDs for mondos not
* succesfully sent.
*/
if (state == CPU_STATE_ERROR) {
if (!panic_quiesce)
errorcpus++;
} else if (errorcpus > 0) {
}
}
if (!panic_quiesce) {
if (errorcpus == 0) {
"marked in error\n");
"hypervisor returned "
"H_ECPUERROR but no CPU in "
"cpu_list in error state");
} else {
"error\n");
"CPU(s) in error state");
}
}
} else if (stat != H_EWOULDBLOCK) {
if (panic_quiesce)
return;
/*
* For all other errors, panic.
*/
"hypervisor error 0x%x while sending a "
"mondo to cpuid(s):", stat);
for (i = 0; i < ncpuids; i++) {
}
"hypervisor error");
}
/*
* If there is a big jump between the current tick
* count and lasttick, we have probably hit a break
* point. Adjust endtick accordingly to avoid panic.
*/
if (panic_quiesce)
return;
"[retries: 0x%x] cpuids: ", retries);
for (i = 0; i < ncpuids; i++)
}
;
retries++;
} while (ncpuids > 0);
#ifdef SEND_MONDO_STATS
{
if (n < 8192)
x_set_stimes[n >> 7]++;
else if (n < 15*8192)
x_set_ltimes[n >> 13]++;
else
x_set_ltimes[0xf]++;
}
x_set_cpus[shipped]++;
#endif
}
void
syncfpu(void)
{
}
void
sticksync_slave(void)
{
}
void
sticksync_master(void)
{}
void
cpu_init_cache_scrub(void)
{
}
int
{
if (watched)
return (ret);
}
int
{
return (0);
}
/*ARGSUSED*/
void
{
}
/*ARGSUSED*/
void
{
}
static int
{
int rc, i;
if (CPU_IN_SET(cpu_ready_set, i))
}
return (rc);
}
/*
* Sends a cross-call to a specified processor. The caller assumes
* responsibility for repetition of cross-calls, as appropriate (MARSA for
* debugging).
*/
static int
{
int stat;
/*
* if (idsr_busy())
* return (KDI_XC_RES_ERR);
*/
if (stat == 0)
return (KDI_XC_RES_OK);
else
return (KDI_XC_RES_NACK);
}
static void
{
;
}
static void
int icache_linesize)
{
}
/* used directly by kdi_read/write_phys */
void
kdi_flush_caches(void)
{
/* Not required on sun4v architecture. */
}
/*ARGSUSED*/
int
{
return (-1);
}
void
{
}
static int soft_state_initialized = 0;
static void
sun4v_system_claim(void)
{
/*
* For "mdb -K", set soft state to debugging
*/
if (soft_state_saved_state == -1) {
}
/*
* check again as the read above may or may not have worked and if
* it didn't then soft state will still be -1
*/
if (soft_state_saved_state != -1) {
}
}
static void
sun4v_system_release(void)
{
/*
* For "mdb -K", set soft_state state back to original state on exit
*/
if (soft_state_saved_state != -1) {
soft_state_saved_state = -1;
}
}
void
{
}
/*
* Routine to return memory information associated
* with a physical address and syndrome.
*/
/* ARGSUSED */
int
{
return (ENOTSUP);
}
/*
* This routine returns the size of the kernel's FRU name buffer.
*/
{
return (UNUM_NAMLEN);
}
/*
* This routine is a more generic interface to cpu_get_mem_unum(),
* that may be used by other modules (e.g. mm).
*/
/* ARGSUSED */
int
{
return (ENOTSUP);
}
/* ARGSUSED */
int
{
return (ENOTSUP);
}
/* ARGSUSED */
int
{
return (ENOTSUP);
}
/*
* xt_sync - wait for previous x-traps to finish
*/
void
{
union {
} cpu_sync;
int i, j;
if (smallestid == CPUSET_NOTINSET)
goto out;
/*
* Sun4v uses a queue for receiving mondos. Successful
* transmission of a mondo only indicates that the mondo
* has been written into the queue.
*
* We use an array of bytes to let each cpu to signal back
* to the cross trap sender that the cross trap has been
* executed. Set the byte to 1 before sending the cross trap
* and wait until other cpus reset it to 0.
*/
if (largestid != smallestid) {
if (CPU_IN_SET(cpuset, i))
}
/*
* To help debug xt_sync panic, each mondo is uniquely identified
* by passing the tick value, traptrace_id as the second mondo
* argument to xt_some which is logged in CPU's mondo queue,
* traptrace buffer and the panic message.
*/
traptrace_id = gettick();
/*
* If there is a big jump between the current tick
* count and lasttick, we have probably hit a break
* point. Adjust endtick accordingly to avoid panic.
*/
}
if (panic_quiesce)
goto out;
"at cpu_sync.xword[%d]: 0x%lx "
"cpu_sync.byte: 0x%lx "
"starttick: 0x%lx endtick: 0x%lx "
"traptrace_id = 0x%lx\n",
for (j = (i * 8); j <= largestid; j++) {
}
}
}
}
out:
}
/*
* Recalculate the values of the cross-call timeout variables based
* on the value of the 'inter-cpu-latency' property of the platform node.
* The property sets the number of nanosec to wait for a cross-call
* to be acknowledged. Other timeout variables are derived from it.
*
* N.B. This implementation is aware of the internals of xc_init()
* and updates many of the same variables.
*/
void
recalc_xc_timeouts(void)
{
typedef union {
struct {
} half;
} u_number;
/* See x_call.c for descriptions of these extern variables. */
extern uint64_t xc_tick_limit_scale;
extern uint64_t xc_mondo_time_limit;
extern uint64_t xc_func_time_limit;
extern uint64_t xc_mondo_multiplier;
extern uint_t nsec_shift;
/* Temp versions of the target variables */
int nrnode;
/*
* Look up the 'inter-cpu-latency' (optional) property in the
* platform node of the MD. The units are nanoseconds.
*/
"Unable to initialize machine description");
return;
}
if (nrnode < 1) {
goto done;
}
goto done;
/*
* clock.h defines an assembly-language macro
* (NATIVE_TIME_TO_NSEC_SCALE) to convert from %stick
* units to nanoseconds. Since the inter-cpu-latency
* units are nanoseconds and the xc_* variables require
* %stick units, we need the inverse of that function.
* The trick is to perform the calculation without
* floating point, but also without integer truncation
* or overflow. To understand the calculation below,
* please read the discussion of the macro in clock.h.
* Since this new code will be invoked infrequently,
* we can afford to implement it in C.
*
* tick_scale is the reciprocal of nsec_scale which is
* calculated at startup in setcpudelay(). The calc
* of tick_limit parallels that of NATIVE_TIME_TO_NSEC_SCALE
* except we use tick_scale instead of nsec_scale and
* C instead of assembler.
*/
/*
* xc_init() calculated 'maxfreq' by looking at all the cpus,
* and used it to derive some of the timeout variables that we
* recalculate below. We can back into the original value by
* using the inverse of one of those calculations.
*/
/*
* Don't allow the new timeout (xc_tick_limit) to fall below
* the system tick frequency (stick). Allowing the timeout
* to be set more tightly than this empirically determined
* value may cause panics.
*/
/*
* Recalculate xc_scale since it is used in a callback function
* (xc_func_timeout_adj) to adjust two of the timeouts dynamically.
* Make the change in xc_scale proportional to the change in
* xc_tick_limit.
*/
if (scale == 0)
scale = 1;
/*
* Don't modify the timeouts if nothing has changed. Else,
* stuff the variables with the freshly calculated (temp)
* variables. This minimizes the window where the set of
* values could be inconsistent.
*/
if (tick_limit != xc_tick_limit) {
}
done:
/*
* Increase the timeout limit for xt_sync() cross calls.
*/
/*
* Force the new values to be used for future cross calls.
* This is necessary only when we increase the timeouts.
*/
}
if (nrnode > 0)
(void) md_fini_handle(mdp);
}
void
mach_soft_state_init(void)
{
int i;
/*
* Try to register soft_state api. If it fails, soft_state api has not
* been implemented in the firmware, so do not bother to setup
* soft_state in the kernel.
*/
return;
}
for (i = 0; i < SOLARIS_SOFT_STATE_MSG_CNT; i++) {
soft_state_message_strings + i) < SSM_SIZE);
(void *)(soft_state_message_strings + i))) == -1ll) {
return;
}
soft_state_message_ra[i] = ra;
}
/*
* Tell OBP that we are supporting Guest State
*/
}
void
{
if (soft_state_initialized && *string_ra) {
"hv_soft_state_set returned %ld\n", rc);
}
}
}
void
{
if (soft_state_initialized && *string_ra) {
"hv_soft_state_get returned %ld\n", rc);
*state = -1;
}
}
}