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 52036Swentaoy * Common Development and Distribution License (the "License"). 62036Swentaoy * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 222036Swentaoy * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/reboot.h> 290Sstevel@tonic-gate #include <sys/systm.h> 300Sstevel@tonic-gate #include <sys/archsystm.h> 310Sstevel@tonic-gate #include <sys/machsystm.h> 320Sstevel@tonic-gate #include <sys/promif.h> 330Sstevel@tonic-gate #include <sys/promimpl.h> 340Sstevel@tonic-gate #include <sys/prom_plat.h> 350Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h> 360Sstevel@tonic-gate #include <sys/ivintr.h> 370Sstevel@tonic-gate #include <sys/kdi.h> 380Sstevel@tonic-gate #include <sys/callb.h> 392036Swentaoy #include <sys/wdt.h> 400Sstevel@tonic-gate 410Sstevel@tonic-gate #ifdef TRAPTRACE 420Sstevel@tonic-gate #include <sys/traptrace.h> 430Sstevel@tonic-gate #endif /* TRAPTRACE */ 440Sstevel@tonic-gate 450Sstevel@tonic-gate #ifdef C2_AUDIT 460Sstevel@tonic-gate extern void audit_enterprom(); 470Sstevel@tonic-gate extern void audit_exitprom(); 480Sstevel@tonic-gate #endif /* C2_AUDIT */ 490Sstevel@tonic-gate 500Sstevel@tonic-gate /* 510Sstevel@tonic-gate * Platforms that use CPU signatures need to set cpu_sgn_func 520Sstevel@tonic-gate * to point to a platform specific function. This needs to 530Sstevel@tonic-gate * be done in set_platform_defaults() within the platmod. 540Sstevel@tonic-gate */ 550Sstevel@tonic-gate void (*cpu_sgn_func)(ushort_t, uchar_t, uchar_t, int) = NULL; 560Sstevel@tonic-gate 570Sstevel@tonic-gate /* 580Sstevel@tonic-gate * abort_seq_handler required by sysctrl. 590Sstevel@tonic-gate */ 600Sstevel@tonic-gate void debug_enter(char *); 610Sstevel@tonic-gate void (*abort_seq_handler)(char *) = debug_enter; 620Sstevel@tonic-gate 630Sstevel@tonic-gate /* 640Sstevel@tonic-gate * Platform tunable to disable the h/w watchdog timer. 650Sstevel@tonic-gate */ 660Sstevel@tonic-gate extern void clear_watchdog_on_exit(void); 670Sstevel@tonic-gate 680Sstevel@tonic-gate /* 690Sstevel@tonic-gate * On sun4u platform, abort_sequence_enter() can be called at high PIL 700Sstevel@tonic-gate * and we can't afford to acquire any adaptive mutex or use any 710Sstevel@tonic-gate * condition variables as we are not allowed to sleep while running 720Sstevel@tonic-gate * on interrupt stack. We work around this problem by posting a level 730Sstevel@tonic-gate * 10 soft interrupt and then invoking the "abort_seq_handler" within 740Sstevel@tonic-gate * that soft interrupt context. 750Sstevel@tonic-gate * 760Sstevel@tonic-gate * This has the side effect of not allowing us to drop into debugger 770Sstevel@tonic-gate * when the kernel is stuck at high PIL (PIL > 10). It's better to 780Sstevel@tonic-gate * be able to break into a hung system even if it means crashing the 790Sstevel@tonic-gate * system. If a user presses L1-A more than once within a 15 seconds 800Sstevel@tonic-gate * window, and the previous L1-A soft interrupt is still pending, then 810Sstevel@tonic-gate * we directly invoke the abort_sequence_enter. 820Sstevel@tonic-gate * 830Sstevel@tonic-gate * Since the "msg" argument passed to abort_sequence_enter can refer 840Sstevel@tonic-gate * to a message anywhere in memory, including stack, it's copied into 850Sstevel@tonic-gate * abort_seq_msgbuf buffer for processing by the soft interrupt. 860Sstevel@tonic-gate */ 870Sstevel@tonic-gate 880Sstevel@tonic-gate #define ABORT_SEQ_MSGBUFSZ 256 890Sstevel@tonic-gate #define FORCE_ABORT_SEQ_INTERVAL ((hrtime_t)15 * NANOSEC) 900Sstevel@tonic-gate 910Sstevel@tonic-gate static kmutex_t abort_seq_lock; 92*2973Sgovinda static uint64_t abort_seq_inum; /* abort seq softintr # */ 930Sstevel@tonic-gate static hrtime_t abort_seq_tstamp; /* hrtime of last abort seq */ 940Sstevel@tonic-gate static size_t abort_seq_msglen; /* abort seq message length */ 950Sstevel@tonic-gate static char abort_seq_msgbuf[ABORT_SEQ_MSGBUFSZ]; 960Sstevel@tonic-gate 970Sstevel@tonic-gate /*ARGSUSED0*/ 980Sstevel@tonic-gate static uint_t 990Sstevel@tonic-gate abort_seq_softintr(caddr_t arg) 1000Sstevel@tonic-gate { 1010Sstevel@tonic-gate char *msg; 1020Sstevel@tonic-gate char msgbuf[ABORT_SEQ_MSGBUFSZ]; 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate mutex_enter(&abort_seq_lock); 1050Sstevel@tonic-gate if (abort_enable != 0 && abort_seq_tstamp != 0LL) { 1060Sstevel@tonic-gate if (abort_seq_msglen > 0) { 1070Sstevel@tonic-gate bcopy(abort_seq_msgbuf, msgbuf, abort_seq_msglen); 1080Sstevel@tonic-gate msg = msgbuf; 1090Sstevel@tonic-gate } else 1100Sstevel@tonic-gate msg = NULL; 1110Sstevel@tonic-gate abort_seq_tstamp = 0LL; 1120Sstevel@tonic-gate mutex_exit(&abort_seq_lock); 1130Sstevel@tonic-gate #ifdef C2_AUDIT 1140Sstevel@tonic-gate if (audit_active) 1150Sstevel@tonic-gate audit_enterprom(1); 1160Sstevel@tonic-gate #endif /* C2_AUDIT */ 1170Sstevel@tonic-gate (*abort_seq_handler)(msg); 1180Sstevel@tonic-gate #ifdef C2_AUDIT 1190Sstevel@tonic-gate if (audit_active) 1200Sstevel@tonic-gate audit_exitprom(1); 1210Sstevel@tonic-gate #endif /* C2_AUDIT */ 1220Sstevel@tonic-gate } else { 1230Sstevel@tonic-gate mutex_exit(&abort_seq_lock); 1240Sstevel@tonic-gate #ifdef C2_AUDIT 1250Sstevel@tonic-gate if (audit_active) 1260Sstevel@tonic-gate audit_enterprom(0); 1270Sstevel@tonic-gate #endif /* C2_AUDIT */ 1280Sstevel@tonic-gate } 1290Sstevel@tonic-gate return (1); 1300Sstevel@tonic-gate } 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate void 1330Sstevel@tonic-gate abort_sequence_init(void) 1340Sstevel@tonic-gate { 1350Sstevel@tonic-gate mutex_init(&abort_seq_lock, NULL, MUTEX_SPIN, (void *)PIL_12); 1360Sstevel@tonic-gate abort_seq_tstamp = 0LL; 1370Sstevel@tonic-gate if (abort_seq_inum == 0) 1380Sstevel@tonic-gate abort_seq_inum = add_softintr(LOCK_LEVEL, 139*2973Sgovinda (softintrfunc)abort_seq_softintr, NULL, SOFTINT_ST); 1400Sstevel@tonic-gate } 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate /* 1430Sstevel@tonic-gate * Machine dependent abort sequence handling 1440Sstevel@tonic-gate */ 1450Sstevel@tonic-gate void 1460Sstevel@tonic-gate abort_sequence_enter(char *msg) 1470Sstevel@tonic-gate { 1480Sstevel@tonic-gate int s, on_intr; 1490Sstevel@tonic-gate size_t msglen; 1500Sstevel@tonic-gate hrtime_t tstamp; 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate if (abort_enable != 0) { 1530Sstevel@tonic-gate s = splhi(); 1540Sstevel@tonic-gate on_intr = CPU_ON_INTR(CPU) || (spltoipl(s) > LOCK_LEVEL); 1550Sstevel@tonic-gate splx(s); 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate tstamp = gethrtime(); 1580Sstevel@tonic-gate mutex_enter(&abort_seq_lock); 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate /* 1610Sstevel@tonic-gate * If we are on an interrupt stack and/or running at 1620Sstevel@tonic-gate * PIL > LOCK_LEVEL, then we post a softint and invoke 1630Sstevel@tonic-gate * abort_seq_handler from there as we can't afford to 1640Sstevel@tonic-gate * acquire any adaptive mutex here. However, if we 1650Sstevel@tonic-gate * already have a pending softint, which was posted 1660Sstevel@tonic-gate * within FORCE_ABORT_SEQ_INTERVAL duration, then we 1670Sstevel@tonic-gate * bypass softint approach as our softint may be blocked 1680Sstevel@tonic-gate * and the user really wants to drop into the debugger. 1690Sstevel@tonic-gate */ 1700Sstevel@tonic-gate if (on_intr && abort_seq_inum != 0 && 1710Sstevel@tonic-gate (abort_seq_tstamp == 0LL || tstamp > 1720Sstevel@tonic-gate (abort_seq_tstamp + FORCE_ABORT_SEQ_INTERVAL))) { 1730Sstevel@tonic-gate abort_seq_tstamp = tstamp; 1740Sstevel@tonic-gate if (msg != NULL) { 1750Sstevel@tonic-gate msglen = strlen(msg); 1760Sstevel@tonic-gate if (msglen >= ABORT_SEQ_MSGBUFSZ) 1770Sstevel@tonic-gate msglen = ABORT_SEQ_MSGBUFSZ - 1; 1780Sstevel@tonic-gate bcopy(msg, abort_seq_msgbuf, msglen); 1790Sstevel@tonic-gate abort_seq_msgbuf[msglen] = '\0'; 1800Sstevel@tonic-gate abort_seq_msglen = msglen + 1; 1810Sstevel@tonic-gate } else 1820Sstevel@tonic-gate abort_seq_msglen = 0; 1830Sstevel@tonic-gate mutex_exit(&abort_seq_lock); 1840Sstevel@tonic-gate setsoftint(abort_seq_inum); 1850Sstevel@tonic-gate } else { 1860Sstevel@tonic-gate /* 1870Sstevel@tonic-gate * Ignore any pending abort sequence softint 1880Sstevel@tonic-gate * as we are invoking the abort_seq_handler 1890Sstevel@tonic-gate * here. 1900Sstevel@tonic-gate */ 1910Sstevel@tonic-gate abort_seq_tstamp = 0LL; 1920Sstevel@tonic-gate mutex_exit(&abort_seq_lock); 1930Sstevel@tonic-gate #ifdef C2_AUDIT 1940Sstevel@tonic-gate if (!on_intr && audit_active) 1950Sstevel@tonic-gate audit_enterprom(1); 1960Sstevel@tonic-gate #endif /* C2_AUDIT */ 1970Sstevel@tonic-gate (*abort_seq_handler)(msg); 1980Sstevel@tonic-gate #ifdef C2_AUDIT 1990Sstevel@tonic-gate if (!on_intr && audit_active) 2000Sstevel@tonic-gate audit_exitprom(1); 2010Sstevel@tonic-gate #endif /* C2_AUDIT */ 2020Sstevel@tonic-gate } 2030Sstevel@tonic-gate } else { 2040Sstevel@tonic-gate #ifdef C2_AUDIT 2050Sstevel@tonic-gate if (audit_active) 2060Sstevel@tonic-gate audit_enterprom(0); 2070Sstevel@tonic-gate #endif /* C2_AUDIT */ 2080Sstevel@tonic-gate } 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate /* 2120Sstevel@tonic-gate * Enter debugger. Called when the user types L1-A or break or whenever 2130Sstevel@tonic-gate * code wants to enter the debugger and possibly resume later. 2140Sstevel@tonic-gate * If the debugger isn't present, enter the PROM monitor. 2150Sstevel@tonic-gate * 2160Sstevel@tonic-gate * If console is a framebuffer which is powered off, it will be powered up 2170Sstevel@tonic-gate * before jumping to the debugger. If we are called above lock level, a 2180Sstevel@tonic-gate * softint is triggered to reenter this code and allow the fb to be powered 2190Sstevel@tonic-gate * up as in the less than lock level case. If this code is entered at greater 2200Sstevel@tonic-gate * than lock level and the fb is not already powered up, the msg argument 2210Sstevel@tonic-gate * will not be displayed. 2220Sstevel@tonic-gate */ 2230Sstevel@tonic-gate void 2240Sstevel@tonic-gate debug_enter(char *msg) 2250Sstevel@tonic-gate { 2260Sstevel@tonic-gate label_t old_pcb; 2270Sstevel@tonic-gate int s; 2280Sstevel@tonic-gate extern void pm_cfb_powerup(void); 2290Sstevel@tonic-gate extern void pm_cfb_rele(void); 2300Sstevel@tonic-gate extern void pm_cfb_trigger(void); 2310Sstevel@tonic-gate extern int pm_cfb_check_and_hold(void); 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate /* 2340Sstevel@tonic-gate * For platforms that use CPU signatures, update the signature 2350Sstevel@tonic-gate * to indicate that we are entering the debugger if we are in 2360Sstevel@tonic-gate * the middle of a panic flow. 2370Sstevel@tonic-gate */ 2380Sstevel@tonic-gate if (panicstr) 2390Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_EXIT, SIGSUBST_DEBUG, -1); 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate if (!panicstr) 2420Sstevel@tonic-gate (void) callb_execute_class(CB_CL_ENTER_DEBUGGER, 0); 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate if (pm_cfb_check_and_hold()) 2450Sstevel@tonic-gate if (getpil() > LOCK_LEVEL) { 2460Sstevel@tonic-gate pm_cfb_trigger(); 2470Sstevel@tonic-gate return; 2480Sstevel@tonic-gate } else 2490Sstevel@tonic-gate pm_cfb_powerup(); 2500Sstevel@tonic-gate if (msg) 2510Sstevel@tonic-gate prom_printf("%s\n", msg); 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate clear_watchdog_on_exit(); 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate if ((s = getpil()) < ipltospl(12)) 2560Sstevel@tonic-gate s = splzs(); 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate old_pcb = curthread->t_pcb; 2590Sstevel@tonic-gate (void) setjmp(&curthread->t_pcb); 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate if (boothowto & RB_DEBUG) 2620Sstevel@tonic-gate kdi_dvec_enter(); 2630Sstevel@tonic-gate else 2640Sstevel@tonic-gate prom_enter_mon(); 2650Sstevel@tonic-gate 2662036Swentaoy restore_watchdog_on_entry(); 2672036Swentaoy 2680Sstevel@tonic-gate curthread->t_pcb = old_pcb; 2690Sstevel@tonic-gate splx(s); 2700Sstevel@tonic-gate pm_cfb_rele(); 2710Sstevel@tonic-gate 2720Sstevel@tonic-gate if (!panicstr) 2730Sstevel@tonic-gate (void) callb_execute_class(CB_CL_ENTER_DEBUGGER, 1); 2740Sstevel@tonic-gate 2750Sstevel@tonic-gate if (panicstr) 2760Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_EXIT, SIGSUBST_PANIC_CONT, -1); 2770Sstevel@tonic-gate } 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate /* 2800Sstevel@tonic-gate * Halt the machine and return to the monitor 2810Sstevel@tonic-gate */ 2820Sstevel@tonic-gate void 2830Sstevel@tonic-gate halt(char *s) 2840Sstevel@tonic-gate { 2850Sstevel@tonic-gate flush_windows(); 2860Sstevel@tonic-gate stop_other_cpus(); /* send stop signal to other CPUs */ 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate if (s) 2890Sstevel@tonic-gate prom_printf("(%s) ", s); 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate /* 2920Sstevel@tonic-gate * For Platforms that use CPU signatures, we 2930Sstevel@tonic-gate * need to set the signature block to OS and 2940Sstevel@tonic-gate * the state to exiting for all the processors. 2950Sstevel@tonic-gate */ 2960Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_EXIT, SIGSUBST_HALT, -1); 2970Sstevel@tonic-gate prom_exit_to_mon(); 2980Sstevel@tonic-gate /*NOTREACHED*/ 2990Sstevel@tonic-gate } 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate /* 3020Sstevel@tonic-gate * Halt the machine and power off the system. 3030Sstevel@tonic-gate */ 3040Sstevel@tonic-gate void 3050Sstevel@tonic-gate power_down(const char *s) 3060Sstevel@tonic-gate { 3070Sstevel@tonic-gate flush_windows(); 3080Sstevel@tonic-gate stop_other_cpus(); /* send stop signal to other CPUs */ 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate if (s != NULL) 3110Sstevel@tonic-gate prom_printf("(%s) ", s); 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate /* 3140Sstevel@tonic-gate * For platforms that use CPU signatures, we need to set up the 3150Sstevel@tonic-gate * signature blocks to indicate that we have an environmental 3160Sstevel@tonic-gate * interrupt request to power down, and then exit to the prom monitor. 3170Sstevel@tonic-gate */ 3180Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_EXIT, SIGSUBST_ENVIRON, -1); 3190Sstevel@tonic-gate prom_power_off(); 3200Sstevel@tonic-gate /* 3210Sstevel@tonic-gate * If here is reached, for some reason prom's power-off command failed. 3220Sstevel@tonic-gate * Prom should have already printed out error messages. Exit to 3230Sstevel@tonic-gate * firmware. 3240Sstevel@tonic-gate */ 3250Sstevel@tonic-gate prom_exit_to_mon(); 3260Sstevel@tonic-gate /*NOTREACHED*/ 3270Sstevel@tonic-gate } 3280Sstevel@tonic-gate 3290Sstevel@tonic-gate void 3300Sstevel@tonic-gate do_shutdown(void) 3310Sstevel@tonic-gate { 3320Sstevel@tonic-gate proc_t *initpp; 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate /* 3350Sstevel@tonic-gate * If we're still booting and init(1) isn't set up yet, simply halt. 3360Sstevel@tonic-gate */ 3370Sstevel@tonic-gate mutex_enter(&pidlock); 3380Sstevel@tonic-gate initpp = prfind(P_INITPID); 3390Sstevel@tonic-gate mutex_exit(&pidlock); 3400Sstevel@tonic-gate if (initpp == NULL) { 3410Sstevel@tonic-gate extern void halt(char *); 3420Sstevel@tonic-gate prom_power_off(); 3430Sstevel@tonic-gate halt("Power off the System"); /* just in case */ 3440Sstevel@tonic-gate } 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate /* 3470Sstevel@tonic-gate * else, graceful shutdown with inittab and all getting involved 3480Sstevel@tonic-gate */ 3490Sstevel@tonic-gate psignal(initpp, SIGPWR); 3500Sstevel@tonic-gate } 351