#include <sys/types.h>
#include <sys/t_lock.h>
#include <sys/uadmin.h>
#include <sys/panic.h>
#include <sys/reboot.h>
#include <sys/autoconf.h>
#include <sys/machsystm.h>
#include <sys/promif.h>
#include <sys/membar.h>
#include <vm/hat_sfmmu.h>
#include <sys/cpu_module.h>
#include <sys/cpu_sgnblk_defs.h>
#include <sys/intreg.h>
#include <sys/consdev.h>
#include <sys/kdi_impl.h>
#include <sys/callb.h>
#include <sys/dumphdr.h>
#ifdef TRAPTRACE
#include <sys/traptrace.h>
u_longlong_t panic_tick;
#endif
extern u_longlong_t gettick();
static void reboot_machine(char *);
int disable_watchdog_on_exit = 0;
extern uint64_t cpc_level15_inum;
void
mdboot(int cmd, int fcn, char *bootstr, boolean_t invoke_cb)
{
extern void pm_cfb_check_and_powerup(void);
if (disable_watchdog_on_exit && watchdog_activated) {
mutex_enter(&tod_lock);
(void) tod_ops.tod_clear_watchdog_timer();
mutex_exit(&tod_lock);
}
rconsvp = NULL;
pm_cfb_check_and_powerup();
devtree_freeze();
if (invoke_cb)
(void) callb_execute_class(CB_CL_MDBOOT, 0);
page_retire_mdboot();
stop_other_cpus();
reset_leaves();
if (fcn == AD_HALT) {
halt((char *)NULL);
} else if (fcn == AD_POWEROFF) {
power_down(NULL);
} else {
if (bootstr == NULL) {
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:
cmn_err(CE_WARN,
"mdboot: invalid function %d", fcn);
bootstr = "";
break;
}
}
if (fcn == AD_FASTREBOOT) {
pnode_t onode;
int dllen;
onode = prom_optionsnode();
if ((onode == OBP_NONODE) || (onode == OBP_BADNODE)) {
cmn_err(CE_WARN, "Unable to set diag level for"
" quick reboot");
} else {
dllen = prom_getproplen(onode, "diag-level");
if (dllen != -1) {
char *newstr = kmem_alloc(strlen(
bootstr) + dllen + 5, KM_NOSLEEP);
if (newstr != NULL) {
int newstrlen;
(void) strcpy(newstr, bootstr);
(void) strcat(newstr, " -f ");
newstrlen = strlen(bootstr) + 4;
(void) prom_getprop(onode,
"diag-level",
(caddr_t)
&(newstr[newstrlen]));
newstr[newstrlen + dllen] =
'\0';
bootstr = newstr;
(void) prom_setprop(onode,
"diag-level",
"off", 4);
}
}
}
}
reboot_machine(bootstr);
}
}
void
mdpreboot(int cmd, int fcn, char *bootstr)
{
}
static void
reboot_machine(char *bootstr)
{
flush_windows();
stop_other_cpus();
prom_printf("rebooting...\n");
CPU_SIGNATURE(OS_SIG, SIGST_EXIT, SIGSUBST_REBOOT, -1);
prom_reboot(bootstr);
}
static void
panic_idle(void)
{
cpu_async_panic_callb();
(void) spl7();
debug_flush_windows();
(void) setjmp(&curthread->t_pcb);
CPU->cpu_m.in_prom = 1;
membar_stld();
dumpsys_helper();
for (;;)
continue;
}
void
panic_stopcpus(cpu_t *cp, kthread_t *t, int spl)
{
cpuset_t cps;
int i;
(void) splzs();
CPUSET_ALL_BUT(cps, cp->cpu_id);
xt_some(cps, (xcfunc_t *)idle_stop_xcall, (uint64_t)&panic_idle, 0);
for (i = 0; i < NCPU; i++) {
if (i != cp->cpu_id && CPU_XCALL_READY(i)) {
int ntries = 0x10000;
while (!cpu[i]->cpu_m.in_prom && ntries) {
DELAY(50);
ntries--;
}
if (!cpu[i]->cpu_m.in_prom)
printf("panic: failed to stop cpu%d\n", i);
cpu[i]->cpu_flags &= ~CPU_READY;
cpu[i]->cpu_flags |= CPU_QUIESCED;
CPUSET_DEL(cpu_ready_set, cpu[i]->cpu_id);
}
}
}
void
panic_enter_hw(int spl)
{
uint_t opstate;
if (spl == ipltospl(PIL_14)) {
opstate = disable_vec_intr();
if (curthread->t_panic_trap != NULL) {
tickcmpr_disable();
intr_dequeue_req(PIL_14, cbe_level14_inum);
} else {
if (!tickcmpr_disabled())
intr_enqueue_req(PIL_14, cbe_level14_inum);
wr_clr_softint((1 << PIL_14) |
TICK_INT_MASK | STICK_INT_MASK);
}
enable_vec_intr(opstate);
} else if (spl == ipltospl(PIL_15)) {
opstate = disable_vec_intr();
intr_enqueue_req(PIL_15, cpc_level15_inum);
wr_clr_softint(1 << PIL_15);
enable_vec_intr(opstate);
}
}
void
panic_quiesce_hw(panic_data_t *pdp)
{
extern uint_t getpstate(void);
extern void setpstate(uint_t);
#ifdef TRAPTRACE
if (!panic_tick)
panic_tick = gettick();
TRAPTRACE_FREEZE;
#endif
CPU_SIGNATURE(OS_SIG, SIGST_EXIT, SIGSUBST_PANIC, -1);
if (watchdog_enable)
(void) tod_ops.tod_clear_watchdog_timer();
cpu_disable_errors();
(void) bus_func_invoke(BF_TYPE_ERRDIS);
intr_redist_all_cpus_shutdown();
(void) bus_func_invoke(BF_TYPE_RESINTR);
setpstate(getpstate() | PSTATE_IE);
}
void
panic_dump_hw(int spl)
{
CPU_SIGNATURE(OS_SIG, SIGST_EXIT, SIGSUBST_DUMP, -1);
}
void
ptl1_init_cpu(struct cpu *cpu)
{
ptl1_state_t *pstate = &cpu->cpu_m.ptl1_state;
if (sizeof (struct cpu) + PTL1_SSIZE > CPU_ALLOC_SIZE) {
panic("ptl1_init_cpu: not enough space left for ptl1_panic "
"stack, sizeof (struct cpu) = %lu", sizeof (struct cpu));
}
pstate->ptl1_stktop = (uintptr_t)cpu + CPU_ALLOC_SIZE;
cpu_pa[cpu->cpu_id] = va_to_pa(cpu);
}
void
ptl1_panic_handler(ptl1_state_t *pstate)
{
static const char *ptl1_reasons[] = {
#ifdef PTL1_PANIC_DEBUG
"trap for debug purpose",
#else
"unknown trap",
#endif
"register window trap",
"kernel MMU miss",
"kernel protection fault",
"ISM MMU miss",
"kernel MMU trap",
"kernel trap handler state",
"floating point trap",
#ifdef DEBUG
"pointer to intr_vec",
#else
"unknown trap",
#endif
#ifdef TRAPTRACE
"TRACE_PTR state",
#else
"unknown trap",
#endif
"stack overflow",
"DTrace flags",
"attempt to steal locked ctx",
"CPU ECC error loop",
"non-kernel context in sys/priv_trap() below or",
"error raising a TSB exception",
"missing shared TSB"
};
uint_t reason = pstate->ptl1_regs.ptl1_g1;
uint_t tl = pstate->ptl1_regs.ptl1_trap_regs[0].ptl1_tl;
struct panic_trap_info ti = { 0 };
if (curthread->t_panic_trap == NULL)
curthread->t_panic_trap = &ti;
if (reason < sizeof (ptl1_reasons) / sizeof (ptl1_reasons[0]))
panic("bad %s at TL %u", ptl1_reasons[reason], tl);
else
panic("ptl1_panic reason 0x%x at TL %u", reason, tl);
}
void
clear_watchdog_on_exit()
{
if (disable_watchdog_on_exit && watchdog_activated) {
prom_printf("Debugging requested; hardware watchdog "
"disabled; reboot to re-enable.\n");
cmn_err(CE_WARN, "!Debugging requested; hardware watchdog "
"disabled; reboot to re-enable.");
mutex_enter(&tod_lock);
(void) tod_ops.tod_clear_watchdog_timer();
mutex_exit(&tod_lock);
}
}
void
restore_watchdog_on_entry(void)
{
}
int
kdi_watchdog_disable(void)
{
if (watchdog_activated) {
mutex_enter(&tod_lock);
(void) tod_ops.tod_clear_watchdog_timer();
mutex_exit(&tod_lock);
}
return (watchdog_activated);
}
void
kdi_watchdog_restore(void)
{
if (watchdog_enable) {
mutex_enter(&tod_lock);
(void) tod_ops.tod_set_watchdog_timer(watchdog_timeout_seconds);
mutex_exit(&tod_lock);
}
}
void
mach_dump_buffer_init(void)
{
}
void
xt_sync(cpuset_t cpuset)
{
kpreempt_disable();
CPUSET_DEL(cpuset, CPU->cpu_id);
CPUSET_AND(cpuset, cpu_ready_set);
xt_some(cpuset, (xcfunc_t *)xt_sync_tl1, 0, 0);
kpreempt_enable();
}
void
mach_soft_state_init(void)
{}