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
51991Sheppo * Common Development and Distribution License (the "License").
61991Sheppo * 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 /*
2212301Ssree.lakshmi.vemuri@oracle.com * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate #include <sys/types.h>
260Sstevel@tonic-gate #include <sys/systm.h>
270Sstevel@tonic-gate #include <sys/archsystm.h>
280Sstevel@tonic-gate #include <sys/t_lock.h>
290Sstevel@tonic-gate #include <sys/uadmin.h>
300Sstevel@tonic-gate #include <sys/panic.h>
310Sstevel@tonic-gate #include <sys/reboot.h>
320Sstevel@tonic-gate #include <sys/autoconf.h>
330Sstevel@tonic-gate #include <sys/machsystm.h>
340Sstevel@tonic-gate #include <sys/promif.h>
350Sstevel@tonic-gate #include <sys/membar.h>
360Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
370Sstevel@tonic-gate #include <sys/cpu_module.h>
380Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h>
390Sstevel@tonic-gate #include <sys/intreg.h>
400Sstevel@tonic-gate #include <sys/consdev.h>
410Sstevel@tonic-gate #include <sys/kdi_impl.h>
421077Ssvemuri #include <sys/traptrace.h>
430Sstevel@tonic-gate #include <sys/hypervisor_api.h>
440Sstevel@tonic-gate #include <sys/vmsystm.h>
450Sstevel@tonic-gate #include <sys/dtrace.h>
460Sstevel@tonic-gate #include <sys/xc_impl.h>
47136Sachartre #include <sys/callb.h>
481991Sheppo #include <sys/mdesc.h>
491991Sheppo #include <sys/mach_descrip.h>
502036Swentaoy #include <sys/wdt.h>
513266Sjb145095 #include <sys/soft_state.h>
523266Sjb145095 #include <sys/promimpl.h>
533266Sjb145095 #include <sys/hsvc.h>
544776Sjm22469 #include <sys/ldoms.h>
558542SHaik.Aftandilian@Sun.COM #include <sys/kldc.h>
5611066Srafael.vanoni@sun.com #include <sys/clock_impl.h>
5711172SHaik.Aftandilian@Sun.COM #include <sys/suspend.h>
5810843SDave.Plauger@Sun.COM #include <sys/dumphdr.h>
590Sstevel@tonic-gate
600Sstevel@tonic-gate /*
610Sstevel@tonic-gate * hvdump_buf_va is a pointer to the currently-configured hvdump_buf.
620Sstevel@tonic-gate * A value of NULL indicates that this area is not configured.
630Sstevel@tonic-gate * hvdump_buf_sz is tunable but will be clamped to HVDUMP_SIZE_MAX.
640Sstevel@tonic-gate */
650Sstevel@tonic-gate
660Sstevel@tonic-gate caddr_t hvdump_buf_va;
670Sstevel@tonic-gate uint64_t hvdump_buf_sz = HVDUMP_SIZE_DEFAULT;
680Sstevel@tonic-gate static uint64_t hvdump_buf_pa;
690Sstevel@tonic-gate
701077Ssvemuri u_longlong_t panic_tick;
710Sstevel@tonic-gate
721077Ssvemuri extern u_longlong_t gettick();
730Sstevel@tonic-gate static void reboot_machine(char *);
740Sstevel@tonic-gate static void update_hvdump_buffer(void);
750Sstevel@tonic-gate
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate * For xt_sync synchronization.
780Sstevel@tonic-gate */
790Sstevel@tonic-gate extern uint64_t xc_tick_limit;
800Sstevel@tonic-gate extern uint64_t xc_tick_jump_limit;
816138Ssvemuri extern uint64_t xc_sync_tick_limit;
820Sstevel@tonic-gate
830Sstevel@tonic-gate /*
84*12524SChris.Baumbauer@Oracle.COM * Bring in the cpc PIL_15 handler for panic_enter_hw.
85*12524SChris.Baumbauer@Oracle.COM */
86*12524SChris.Baumbauer@Oracle.COM extern uint64_t cpc_level15_inum;
87*12524SChris.Baumbauer@Oracle.COM
88*12524SChris.Baumbauer@Oracle.COM /*
890Sstevel@tonic-gate * We keep our own copies, used for cache flushing, because we can be called
900Sstevel@tonic-gate * before cpu_fiximpl().
910Sstevel@tonic-gate */
920Sstevel@tonic-gate static int kdi_dcache_size;
930Sstevel@tonic-gate static int kdi_dcache_linesize;
940Sstevel@tonic-gate static int kdi_icache_size;
950Sstevel@tonic-gate static int kdi_icache_linesize;
960Sstevel@tonic-gate
970Sstevel@tonic-gate /*
980Sstevel@tonic-gate * Assembly support for generic modules in sun4v/ml/mach_xc.s
990Sstevel@tonic-gate */
1000Sstevel@tonic-gate extern void init_mondo_nocheck(xcfunc_t *func, uint64_t arg1, uint64_t arg2);
1010Sstevel@tonic-gate extern void kdi_flush_idcache(int, int, int, int);
1020Sstevel@tonic-gate extern uint64_t get_cpuaddr(uint64_t, uint64_t);
1030Sstevel@tonic-gate
1044776Sjm22469
10512301Ssree.lakshmi.vemuri@oracle.com #define BOOT_CMD_MAX_LEN 256 /* power of 2 & 16-byte aligned */
1064776Sjm22469 #define BOOT_CMD_BASE "boot "
1074776Sjm22469
1084776Sjm22469 /*
1094776Sjm22469 * In an LDoms system we do not save the user's boot args in NVRAM
1104776Sjm22469 * as is done on legacy systems. Instead, we format and send a
1114776Sjm22469 * 'reboot-command' variable to the variable service. The contents
1124776Sjm22469 * of the variable are retrieved by OBP and used verbatim for
1134776Sjm22469 * the next boot.
1144776Sjm22469 */
1154776Sjm22469 static void
store_boot_cmd(char * args,boolean_t add_boot_str,boolean_t invoke_cb)11611304SJanie.Lu@Sun.COM store_boot_cmd(char *args, boolean_t add_boot_str, boolean_t invoke_cb)
1174776Sjm22469 {
11812301Ssree.lakshmi.vemuri@oracle.com static char *cmd_buf;
1195974Sjm22469 size_t len = 1;
1204776Sjm22469 pnode_t node;
1215974Sjm22469 size_t base_len = 0;
1224776Sjm22469 size_t args_len;
1234776Sjm22469 size_t args_max;
12411304SJanie.Lu@Sun.COM uint64_t majornum;
12511304SJanie.Lu@Sun.COM uint64_t minornum;
12611304SJanie.Lu@Sun.COM uint64_t buf_pa;
12711304SJanie.Lu@Sun.COM uint64_t status;
12811304SJanie.Lu@Sun.COM
12911304SJanie.Lu@Sun.COM status = hsvc_version(HSVC_GROUP_REBOOT_DATA, &majornum, &minornum);
13011304SJanie.Lu@Sun.COM
13111304SJanie.Lu@Sun.COM /*
13211304SJanie.Lu@Sun.COM * invoke_cb is set to true when we are in a normal shutdown sequence
13311304SJanie.Lu@Sun.COM * (interrupts are not blocked, the system is not panicking or being
13411304SJanie.Lu@Sun.COM * suspended). In that case, we can use any method to store the boot
13511304SJanie.Lu@Sun.COM * command. Otherwise storing the boot command can not be done using
13611304SJanie.Lu@Sun.COM * a domain service because it can not be safely used in that context.
13711304SJanie.Lu@Sun.COM */
13811304SJanie.Lu@Sun.COM if ((status != H_EOK) && (invoke_cb == B_FALSE))
13911304SJanie.Lu@Sun.COM return;
1404776Sjm22469
14112301Ssree.lakshmi.vemuri@oracle.com cmd_buf = contig_mem_alloc(BOOT_CMD_MAX_LEN);
14212301Ssree.lakshmi.vemuri@oracle.com if (cmd_buf == NULL)
14312301Ssree.lakshmi.vemuri@oracle.com return;
14412301Ssree.lakshmi.vemuri@oracle.com
1455974Sjm22469 if (add_boot_str) {
1465974Sjm22469 (void) strcpy(cmd_buf, BOOT_CMD_BASE);
1474776Sjm22469
1485974Sjm22469 base_len = strlen(BOOT_CMD_BASE);
1495974Sjm22469 len = base_len + 1;
1505974Sjm22469 }
1514776Sjm22469
1524776Sjm22469 if (args != NULL) {
1534776Sjm22469 args_len = strlen(args);
1544776Sjm22469 args_max = BOOT_CMD_MAX_LEN - len;
1554776Sjm22469
1564776Sjm22469 if (args_len > args_max) {
1574776Sjm22469 cmn_err(CE_WARN, "Reboot command too long (%ld), "
1584776Sjm22469 "truncating command arguments", len + args_len);
1594776Sjm22469
1604776Sjm22469 args_len = args_max;
1614776Sjm22469 }
1624776Sjm22469
1634776Sjm22469 len += args_len;
1644776Sjm22469 (void) strncpy(&cmd_buf[base_len], args, args_len);
1654776Sjm22469 }
1664776Sjm22469
16711304SJanie.Lu@Sun.COM /*
16811304SJanie.Lu@Sun.COM * Save the reboot-command with HV, if reboot data group is
16911304SJanie.Lu@Sun.COM * negotiated. Else save the reboot-command via vars-config domain
17011304SJanie.Lu@Sun.COM * services on the SP.
17111304SJanie.Lu@Sun.COM */
17211304SJanie.Lu@Sun.COM if (status == H_EOK) {
17311304SJanie.Lu@Sun.COM buf_pa = va_to_pa(cmd_buf);
17411304SJanie.Lu@Sun.COM status = hv_reboot_data_set(buf_pa, len);
17511304SJanie.Lu@Sun.COM if (status != H_EOK) {
17611304SJanie.Lu@Sun.COM cmn_err(CE_WARN, "Unable to store boot command for "
17711304SJanie.Lu@Sun.COM "use on reboot with HV: error = 0x%lx", status);
17811304SJanie.Lu@Sun.COM }
17911304SJanie.Lu@Sun.COM } else {
18011304SJanie.Lu@Sun.COM node = prom_optionsnode();
18111304SJanie.Lu@Sun.COM if ((node == OBP_NONODE) || (node == OBP_BADNODE) ||
18211304SJanie.Lu@Sun.COM prom_setprop(node, "reboot-command", cmd_buf, len) == -1)
18311304SJanie.Lu@Sun.COM cmn_err(CE_WARN, "Unable to store boot command for "
18411304SJanie.Lu@Sun.COM "use on reboot");
18511304SJanie.Lu@Sun.COM }
1864776Sjm22469 }
1874776Sjm22469
1884776Sjm22469
1890Sstevel@tonic-gate /*
1900Sstevel@tonic-gate * Machine dependent code to reboot.
1914776Sjm22469 *
1924776Sjm22469 * "bootstr", when non-null, points to a string to be used as the
1934776Sjm22469 * argument string when rebooting.
194136Sachartre *
195136Sachartre * "invoke_cb" is a boolean. It is set to true when mdboot() can safely
196136Sachartre * invoke CB_CL_MDBOOT callbacks before shutting the system down, i.e. when
197136Sachartre * we are in a normal shutdown sequence (interrupts are not blocked, the
198136Sachartre * system is not panic'ing or being suspended).
1990Sstevel@tonic-gate */
2000Sstevel@tonic-gate /*ARGSUSED*/
2010Sstevel@tonic-gate void
mdboot(int cmd,int fcn,char * bootstr,boolean_t invoke_cb)202136Sachartre mdboot(int cmd, int fcn, char *bootstr, boolean_t invoke_cb)
2030Sstevel@tonic-gate {
2040Sstevel@tonic-gate extern void pm_cfb_check_and_powerup(void);
2050Sstevel@tonic-gate
2065630Sjbeck /*
2075630Sjbeck * XXX - rconsvp is set to NULL to ensure that output messages
2085630Sjbeck * are sent to the underlying "hardware" device using the
2095630Sjbeck * monitor's printf routine since we are in the process of
2105630Sjbeck * either rebooting or halting the machine.
2115630Sjbeck */
2125630Sjbeck rconsvp = NULL;
2135630Sjbeck
2144776Sjm22469 switch (fcn) {
2154776Sjm22469 case AD_HALT:
2165974Sjm22469 /*
2175974Sjm22469 * LDoms: By storing a no-op command
2185974Sjm22469 * in the 'reboot-command' variable we cause OBP
2195974Sjm22469 * to ignore the setting of 'auto-boot?' after
2205974Sjm22469 * it completes the reset. This causes the system
2215974Sjm22469 * to stop at the ok prompt.
2225974Sjm22469 */
22311304SJanie.Lu@Sun.COM if (domaining_enabled())
22411304SJanie.Lu@Sun.COM store_boot_cmd("noop", B_FALSE, invoke_cb);
2255974Sjm22469 break;
2265974Sjm22469
2274776Sjm22469 case AD_POWEROFF:
2284776Sjm22469 break;
2295974Sjm22469
2304776Sjm22469 default:
2314776Sjm22469 if (bootstr == NULL) {
2324776Sjm22469 switch (fcn) {
2334776Sjm22469
23411897SChris.Kiick@Sun.COM case AD_FASTREBOOT:
2354776Sjm22469 case AD_BOOT:
2364776Sjm22469 bootstr = "";
2374776Sjm22469 break;
2384776Sjm22469
2394776Sjm22469 case AD_IBOOT:
2404776Sjm22469 bootstr = "-a";
2414776Sjm22469 break;
2424776Sjm22469
2434776Sjm22469 case AD_SBOOT:
2444776Sjm22469 bootstr = "-s";
2454776Sjm22469 break;
2464776Sjm22469
2474776Sjm22469 case AD_SIBOOT:
2484776Sjm22469 bootstr = "-sa";
2494776Sjm22469 break;
2504776Sjm22469 default:
2514776Sjm22469 cmn_err(CE_WARN,
2524776Sjm22469 "mdboot: invalid function %d", fcn);
2534776Sjm22469 bootstr = "";
2544776Sjm22469 break;
2554776Sjm22469 }
2564776Sjm22469 }
2574776Sjm22469
2585177Sjm22469 /*
2595177Sjm22469 * If LDoms is running, we must save the boot string
2605177Sjm22469 * before we enter restricted mode. This is possible
2615177Sjm22469 * only if we are not being called from panic.
2625177Sjm22469 */
26311304SJanie.Lu@Sun.COM if (domaining_enabled())
26411304SJanie.Lu@Sun.COM store_boot_cmd(bootstr, B_TRUE, invoke_cb);
2655177Sjm22469 }
2664776Sjm22469
2670Sstevel@tonic-gate /*
2680Sstevel@tonic-gate * At a high interrupt level we can't:
2690Sstevel@tonic-gate * 1) bring up the console
2700Sstevel@tonic-gate * or
2710Sstevel@tonic-gate * 2) wait for pending interrupts prior to redistribution
2720Sstevel@tonic-gate * to the current CPU
2730Sstevel@tonic-gate *
2740Sstevel@tonic-gate * so we do them now.
2750Sstevel@tonic-gate */
2760Sstevel@tonic-gate pm_cfb_check_and_powerup();
2770Sstevel@tonic-gate
2780Sstevel@tonic-gate /* make sure there are no more changes to the device tree */
2790Sstevel@tonic-gate devtree_freeze();
2800Sstevel@tonic-gate
281136Sachartre if (invoke_cb)
282136Sachartre (void) callb_execute_class(CB_CL_MDBOOT, NULL);
283136Sachartre
2840Sstevel@tonic-gate /*
285917Selowe * Clear any unresolved UEs from memory.
286917Selowe */
2873253Smec page_retire_mdboot();
288917Selowe
289917Selowe /*
2900Sstevel@tonic-gate * stop other cpus which also raise our priority. since there is only
2910Sstevel@tonic-gate * one active cpu after this, and our priority will be too high
2920Sstevel@tonic-gate * for us to be preempted, we're essentially single threaded
2930Sstevel@tonic-gate * from here on out.
2940Sstevel@tonic-gate */
2950Sstevel@tonic-gate stop_other_cpus();
2960Sstevel@tonic-gate
2970Sstevel@tonic-gate /*
2980Sstevel@tonic-gate * try and reset leaf devices. reset_leaves() should only
2990Sstevel@tonic-gate * be called when there are no other threads that could be
3000Sstevel@tonic-gate * accessing devices
3010Sstevel@tonic-gate */
3020Sstevel@tonic-gate reset_leaves();
3030Sstevel@tonic-gate
3042036Swentaoy watchdog_clear();
3052036Swentaoy
3060Sstevel@tonic-gate if (fcn == AD_HALT) {
3073266Sjb145095 mach_set_soft_state(SIS_TRANSITION,
3084776Sjm22469 &SOLARIS_SOFT_STATE_HALT_MSG);
3090Sstevel@tonic-gate halt((char *)NULL);
3100Sstevel@tonic-gate } else if (fcn == AD_POWEROFF) {
3113266Sjb145095 mach_set_soft_state(SIS_TRANSITION,
3124776Sjm22469 &SOLARIS_SOFT_STATE_POWER_MSG);
3130Sstevel@tonic-gate power_down(NULL);
3140Sstevel@tonic-gate } else {
3154776Sjm22469 mach_set_soft_state(SIS_TRANSITION,
3164776Sjm22469 &SOLARIS_SOFT_STATE_REBOOT_MSG);
3170Sstevel@tonic-gate reboot_machine(bootstr);
3180Sstevel@tonic-gate }
3190Sstevel@tonic-gate /* MAYBE REACHED */
3200Sstevel@tonic-gate }
3210Sstevel@tonic-gate
3220Sstevel@tonic-gate /* mdpreboot - may be called prior to mdboot while root fs still mounted */
3230Sstevel@tonic-gate /*ARGSUSED*/
3240Sstevel@tonic-gate void
mdpreboot(int cmd,int fcn,char * bootstr)3250Sstevel@tonic-gate mdpreboot(int cmd, int fcn, char *bootstr)
3260Sstevel@tonic-gate {
3270Sstevel@tonic-gate }
3280Sstevel@tonic-gate
3290Sstevel@tonic-gate /*
3300Sstevel@tonic-gate * Halt the machine and then reboot with the device
3310Sstevel@tonic-gate * and arguments specified in bootstr.
3320Sstevel@tonic-gate */
3330Sstevel@tonic-gate static void
reboot_machine(char * bootstr)3340Sstevel@tonic-gate reboot_machine(char *bootstr)
3350Sstevel@tonic-gate {
3360Sstevel@tonic-gate flush_windows();
3370Sstevel@tonic-gate stop_other_cpus(); /* send stop signal to other CPUs */
3380Sstevel@tonic-gate prom_printf("rebooting...\n");
3390Sstevel@tonic-gate /*
3400Sstevel@tonic-gate * For platforms that use CPU signatures, we
3410Sstevel@tonic-gate * need to set the signature block to OS and
3420Sstevel@tonic-gate * the state to exiting for all the processors.
3430Sstevel@tonic-gate */
3440Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_EXIT, SIGSUBST_REBOOT, -1);
3450Sstevel@tonic-gate prom_reboot(bootstr);
3460Sstevel@tonic-gate /*NOTREACHED*/
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate
3490Sstevel@tonic-gate /*
3500Sstevel@tonic-gate * We use the x-trap mechanism and idle_stop_xcall() to stop the other CPUs.
3510Sstevel@tonic-gate * Once in panic_idle() they raise spl, record their location, and spin.
3520Sstevel@tonic-gate */
3530Sstevel@tonic-gate static void
panic_idle(void)3540Sstevel@tonic-gate panic_idle(void)
3550Sstevel@tonic-gate {
3560Sstevel@tonic-gate (void) spl7();
3570Sstevel@tonic-gate
3580Sstevel@tonic-gate debug_flush_windows();
3590Sstevel@tonic-gate (void) setjmp(&curthread->t_pcb);
3600Sstevel@tonic-gate
3610Sstevel@tonic-gate CPU->cpu_m.in_prom = 1;
3620Sstevel@tonic-gate membar_stld();
3630Sstevel@tonic-gate
36410843SDave.Plauger@Sun.COM dumpsys_helper();
36510843SDave.Plauger@Sun.COM
3664776Sjm22469 for (;;)
3675974Sjm22469 ;
3680Sstevel@tonic-gate }
3690Sstevel@tonic-gate
3700Sstevel@tonic-gate /*
3710Sstevel@tonic-gate * Force the other CPUs to trap into panic_idle(), and then remove them
3720Sstevel@tonic-gate * from the cpu_ready_set so they will no longer receive cross-calls.
3730Sstevel@tonic-gate */
3740Sstevel@tonic-gate /*ARGSUSED*/
3750Sstevel@tonic-gate void
panic_stopcpus(cpu_t * cp,kthread_t * t,int spl)3760Sstevel@tonic-gate panic_stopcpus(cpu_t *cp, kthread_t *t, int spl)
3770Sstevel@tonic-gate {
3780Sstevel@tonic-gate cpuset_t cps;
3790Sstevel@tonic-gate int i;
3800Sstevel@tonic-gate
3810Sstevel@tonic-gate (void) splzs();
3820Sstevel@tonic-gate CPUSET_ALL_BUT(cps, cp->cpu_id);
3830Sstevel@tonic-gate xt_some(cps, (xcfunc_t *)idle_stop_xcall, (uint64_t)&panic_idle, NULL);
3840Sstevel@tonic-gate
3850Sstevel@tonic-gate for (i = 0; i < NCPU; i++) {
3860Sstevel@tonic-gate if (i != cp->cpu_id && CPU_XCALL_READY(i)) {
3870Sstevel@tonic-gate int ntries = 0x10000;
3880Sstevel@tonic-gate
3890Sstevel@tonic-gate while (!cpu[i]->cpu_m.in_prom && ntries) {
3900Sstevel@tonic-gate DELAY(50);
3910Sstevel@tonic-gate ntries--;
3920Sstevel@tonic-gate }
3930Sstevel@tonic-gate
3940Sstevel@tonic-gate if (!cpu[i]->cpu_m.in_prom)
3950Sstevel@tonic-gate printf("panic: failed to stop cpu%d\n", i);
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate cpu[i]->cpu_flags &= ~CPU_READY;
3980Sstevel@tonic-gate cpu[i]->cpu_flags |= CPU_QUIESCED;
3990Sstevel@tonic-gate CPUSET_DEL(cpu_ready_set, cpu[i]->cpu_id);
4000Sstevel@tonic-gate }
4010Sstevel@tonic-gate }
4020Sstevel@tonic-gate }
4030Sstevel@tonic-gate
4040Sstevel@tonic-gate /*
4050Sstevel@tonic-gate * Platform callback following each entry to panicsys(). If we've panicked at
4060Sstevel@tonic-gate * level 14, we examine t_panic_trap to see if a fatal trap occurred. If so,
4070Sstevel@tonic-gate * we disable further %tick_cmpr interrupts. If not, an explicit call to panic
4080Sstevel@tonic-gate * was made and so we re-enqueue an interrupt request structure to allow
4090Sstevel@tonic-gate * further level 14 interrupts to be processed once we lower PIL. This allows
4100Sstevel@tonic-gate * us to handle panics from the deadman() CY_HIGH_LEVEL cyclic.
411*12524SChris.Baumbauer@Oracle.COM *
412*12524SChris.Baumbauer@Oracle.COM * In case we panic at level 15, ensure that the cpc handler has been
413*12524SChris.Baumbauer@Oracle.COM * reinstalled otherwise we could run the risk of hitting a missing interrupt
414*12524SChris.Baumbauer@Oracle.COM * handler when this thread drops PIL and the cpc counter overflows.
4150Sstevel@tonic-gate */
4160Sstevel@tonic-gate void
panic_enter_hw(int spl)4170Sstevel@tonic-gate panic_enter_hw(int spl)
4180Sstevel@tonic-gate {
419*12524SChris.Baumbauer@Oracle.COM uint_t opstate;
420*12524SChris.Baumbauer@Oracle.COM
421526Sarao if (!panic_tick) {
422526Sarao panic_tick = gettick();
4231077Ssvemuri if (mach_htraptrace_enable) {
4241077Ssvemuri uint64_t prev_freeze;
4251077Ssvemuri
4261077Ssvemuri /* there are no possible error codes for this hcall */
4271077Ssvemuri (void) hv_ttrace_freeze((uint64_t)TRAP_TFREEZE_ALL,
4281077Ssvemuri &prev_freeze);
4291077Ssvemuri }
4301077Ssvemuri #ifdef TRAPTRACE
431526Sarao TRAPTRACE_FREEZE;
4321077Ssvemuri #endif
433526Sarao }
4343266Sjb145095
4353266Sjb145095 mach_set_soft_state(SIS_TRANSITION, &SOLARIS_SOFT_STATE_PANIC_MSG);
4363266Sjb145095
4370Sstevel@tonic-gate if (spl == ipltospl(PIL_14)) {
438*12524SChris.Baumbauer@Oracle.COM opstate = disable_vec_intr();
4390Sstevel@tonic-gate
4400Sstevel@tonic-gate if (curthread->t_panic_trap != NULL) {
4410Sstevel@tonic-gate tickcmpr_disable();
4420Sstevel@tonic-gate intr_dequeue_req(PIL_14, cbe_level14_inum);
4430Sstevel@tonic-gate } else {
4440Sstevel@tonic-gate if (!tickcmpr_disabled())
4450Sstevel@tonic-gate intr_enqueue_req(PIL_14, cbe_level14_inum);
4460Sstevel@tonic-gate /*
4470Sstevel@tonic-gate * Clear SOFTINT<14>, SOFTINT<0> (TICK_INT)
4480Sstevel@tonic-gate * and SOFTINT<16> (STICK_INT) to indicate
4490Sstevel@tonic-gate * that the current level 14 has been serviced.
4500Sstevel@tonic-gate */
4510Sstevel@tonic-gate wr_clr_softint((1 << PIL_14) |
4524776Sjm22469 TICK_INT_MASK | STICK_INT_MASK);
4530Sstevel@tonic-gate }
4540Sstevel@tonic-gate
4550Sstevel@tonic-gate enable_vec_intr(opstate);
456*12524SChris.Baumbauer@Oracle.COM } else if (spl == ipltospl(PIL_15)) {
457*12524SChris.Baumbauer@Oracle.COM opstate = disable_vec_intr();
458*12524SChris.Baumbauer@Oracle.COM intr_enqueue_req(PIL_15, cpc_level15_inum);
459*12524SChris.Baumbauer@Oracle.COM wr_clr_softint(1 << PIL_15);
460*12524SChris.Baumbauer@Oracle.COM enable_vec_intr(opstate);
4610Sstevel@tonic-gate }
4620Sstevel@tonic-gate }
4630Sstevel@tonic-gate
4640Sstevel@tonic-gate /*
4650Sstevel@tonic-gate * Miscellaneous hardware-specific code to execute after panicstr is set
4660Sstevel@tonic-gate * by the panic code: we also print and record PTL1 panic information here.
4670Sstevel@tonic-gate */
4680Sstevel@tonic-gate /*ARGSUSED*/
4690Sstevel@tonic-gate void
panic_quiesce_hw(panic_data_t * pdp)4700Sstevel@tonic-gate panic_quiesce_hw(panic_data_t *pdp)
4710Sstevel@tonic-gate {
4720Sstevel@tonic-gate extern uint_t getpstate(void);
4730Sstevel@tonic-gate extern void setpstate(uint_t);
4740Sstevel@tonic-gate
4750Sstevel@tonic-gate /*
4760Sstevel@tonic-gate * Turn off TRAPTRACE and save the current %tick value in panic_tick.
4770Sstevel@tonic-gate */
4781077Ssvemuri if (!panic_tick) {
4790Sstevel@tonic-gate panic_tick = gettick();
4801077Ssvemuri if (mach_htraptrace_enable) {
4811077Ssvemuri uint64_t prev_freeze;
4821077Ssvemuri
4831077Ssvemuri /* there are no possible error codes for this hcall */
4841077Ssvemuri (void) hv_ttrace_freeze((uint64_t)TRAP_TFREEZE_ALL,
4851077Ssvemuri &prev_freeze);
4861077Ssvemuri }
4871077Ssvemuri #ifdef TRAPTRACE
4881077Ssvemuri TRAPTRACE_FREEZE;
4890Sstevel@tonic-gate #endif
4901077Ssvemuri }
4910Sstevel@tonic-gate /*
4920Sstevel@tonic-gate * For Platforms that use CPU signatures, we
4930Sstevel@tonic-gate * need to set the signature block to OS, the state to
4940Sstevel@tonic-gate * exiting, and the substate to panic for all the processors.
4950Sstevel@tonic-gate */
4960Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_EXIT, SIGSUBST_PANIC, -1);
4970Sstevel@tonic-gate
4980Sstevel@tonic-gate update_hvdump_buffer();
4990Sstevel@tonic-gate
5000Sstevel@tonic-gate /*
5010Sstevel@tonic-gate * Disable further ECC errors from the bus nexus.
5020Sstevel@tonic-gate */
5030Sstevel@tonic-gate (void) bus_func_invoke(BF_TYPE_ERRDIS);
5040Sstevel@tonic-gate
5050Sstevel@tonic-gate /*
5060Sstevel@tonic-gate * Redirect all interrupts to the current CPU.
5070Sstevel@tonic-gate */
5080Sstevel@tonic-gate intr_redist_all_cpus_shutdown();
5090Sstevel@tonic-gate
5100Sstevel@tonic-gate /*
5110Sstevel@tonic-gate * This call exists solely to support dumps to network
5120Sstevel@tonic-gate * devices after sync from OBP.
5130Sstevel@tonic-gate *
5140Sstevel@tonic-gate * If we came here via the sync callback, then on some
5150Sstevel@tonic-gate * platforms, interrupts may have arrived while we were
5160Sstevel@tonic-gate * stopped in OBP. OBP will arrange for those interrupts to
5170Sstevel@tonic-gate * be redelivered if you say "go", but not if you invoke a
5180Sstevel@tonic-gate * client callback like 'sync'. For some dump devices
5190Sstevel@tonic-gate * (network swap devices), we need interrupts to be
5200Sstevel@tonic-gate * delivered in order to dump, so we have to call the bus
5210Sstevel@tonic-gate * nexus driver to reset the interrupt state machines.
5220Sstevel@tonic-gate */
5230Sstevel@tonic-gate (void) bus_func_invoke(BF_TYPE_RESINTR);
5240Sstevel@tonic-gate
5250Sstevel@tonic-gate setpstate(getpstate() | PSTATE_IE);
5260Sstevel@tonic-gate }
5270Sstevel@tonic-gate
5280Sstevel@tonic-gate /*
5290Sstevel@tonic-gate * Platforms that use CPU signatures need to set the signature block to OS and
5300Sstevel@tonic-gate * the state to exiting for all CPUs. PANIC_CONT indicates that we're about to
5310Sstevel@tonic-gate * write the crash dump, which tells the SSP/SMS to begin a timeout routine to
5320Sstevel@tonic-gate * reboot the machine if the dump never completes.
5330Sstevel@tonic-gate */
5340Sstevel@tonic-gate /*ARGSUSED*/
5350Sstevel@tonic-gate void
panic_dump_hw(int spl)5360Sstevel@tonic-gate panic_dump_hw(int spl)
5370Sstevel@tonic-gate {
5380Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_EXIT, SIGSUBST_DUMP, -1);
5390Sstevel@tonic-gate }
5400Sstevel@tonic-gate
5410Sstevel@tonic-gate /*
5420Sstevel@tonic-gate * for ptl1_panic
5430Sstevel@tonic-gate */
5440Sstevel@tonic-gate void
ptl1_init_cpu(struct cpu * cpu)5450Sstevel@tonic-gate ptl1_init_cpu(struct cpu *cpu)
5460Sstevel@tonic-gate {
5470Sstevel@tonic-gate ptl1_state_t *pstate = &cpu->cpu_m.ptl1_state;
5480Sstevel@tonic-gate
5490Sstevel@tonic-gate /*CONSTCOND*/
5500Sstevel@tonic-gate if (sizeof (struct cpu) + PTL1_SSIZE > CPU_ALLOC_SIZE) {
5510Sstevel@tonic-gate panic("ptl1_init_cpu: not enough space left for ptl1_panic "
552911Siskreen "stack, sizeof (struct cpu) = %lu",
553911Siskreen (unsigned long)sizeof (struct cpu));
5540Sstevel@tonic-gate }
5550Sstevel@tonic-gate
5560Sstevel@tonic-gate pstate->ptl1_stktop = (uintptr_t)cpu + CPU_ALLOC_SIZE;
5570Sstevel@tonic-gate cpu_pa[cpu->cpu_id] = va_to_pa(cpu);
5580Sstevel@tonic-gate }
5590Sstevel@tonic-gate
5600Sstevel@tonic-gate void
ptl1_panic_handler(ptl1_state_t * pstate)5610Sstevel@tonic-gate ptl1_panic_handler(ptl1_state_t *pstate)
5620Sstevel@tonic-gate {
5630Sstevel@tonic-gate static const char *ptl1_reasons[] = {
5640Sstevel@tonic-gate #ifdef PTL1_PANIC_DEBUG
5650Sstevel@tonic-gate "trap for debug purpose", /* PTL1_BAD_DEBUG */
5660Sstevel@tonic-gate #else
5670Sstevel@tonic-gate "unknown trap", /* PTL1_BAD_DEBUG */
5680Sstevel@tonic-gate #endif
5690Sstevel@tonic-gate "register window trap", /* PTL1_BAD_WTRAP */
5700Sstevel@tonic-gate "kernel MMU miss", /* PTL1_BAD_KMISS */
5710Sstevel@tonic-gate "kernel protection fault", /* PTL1_BAD_KPROT_FAULT */
5720Sstevel@tonic-gate "ISM MMU miss", /* PTL1_BAD_ISM */
5730Sstevel@tonic-gate "kernel MMU trap", /* PTL1_BAD_MMUTRAP */
5740Sstevel@tonic-gate "kernel trap handler state", /* PTL1_BAD_TRAP */
5750Sstevel@tonic-gate "floating point trap", /* PTL1_BAD_FPTRAP */
5760Sstevel@tonic-gate #ifdef DEBUG
5772973Sgovinda "pointer to intr_vec", /* PTL1_BAD_INTR_VEC */
5780Sstevel@tonic-gate #else
5792973Sgovinda "unknown trap", /* PTL1_BAD_INTR_VEC */
5800Sstevel@tonic-gate #endif
5810Sstevel@tonic-gate #ifdef TRAPTRACE
5820Sstevel@tonic-gate "TRACE_PTR state", /* PTL1_BAD_TRACE_PTR */
5830Sstevel@tonic-gate #else
5840Sstevel@tonic-gate "unknown trap", /* PTL1_BAD_TRACE_PTR */
5850Sstevel@tonic-gate #endif
5860Sstevel@tonic-gate "stack overflow", /* PTL1_BAD_STACK */
5870Sstevel@tonic-gate "DTrace flags", /* PTL1_BAD_DTRACE_FLAGS */
5880Sstevel@tonic-gate "attempt to steal locked ctx", /* PTL1_BAD_CTX_STEAL */
5890Sstevel@tonic-gate "CPU ECC error loop", /* PTL1_BAD_ECC */
5900Sstevel@tonic-gate "unexpected error from hypervisor call", /* PTL1_BAD_HCALL */
591526Sarao "unexpected global level(%gl)", /* PTL1_BAD_GL */
5921991Sheppo "Watchdog Reset", /* PTL1_BAD_WATCHDOG */
5931991Sheppo "unexpected RED mode trap", /* PTL1_BAD_RED */
5941991Sheppo "return value EINVAL from hcall: "\
5951991Sheppo "UNMAP_PERM_ADDR", /* PTL1_BAD_HCALL_UNMAP_PERM_EINVAL */
5961991Sheppo "return value ENOMAP from hcall: "\
5971991Sheppo "UNMAP_PERM_ADDR", /* PTL1_BAD_HCALL_UNMAP_PERM_ENOMAP */
5986044Spaulsan "error raising a TSB exception", /* PTL1_BAD_RAISE_TSBEXCP */
5996044Spaulsan "missing shared TSB" /* PTL1_NO_SCDTSB8K */
6000Sstevel@tonic-gate };
6010Sstevel@tonic-gate
602357Ssvemuri uint_t reason = pstate->ptl1_regs.ptl1_gregs[0].ptl1_g1;
6030Sstevel@tonic-gate uint_t tl = pstate->ptl1_regs.ptl1_trap_regs[0].ptl1_tl;
6045084Sjohnlev struct panic_trap_info ti = { 0 };
6050Sstevel@tonic-gate
6060Sstevel@tonic-gate /*
6070Sstevel@tonic-gate * Use trap_info for a place holder to call panic_savetrap() and
6080Sstevel@tonic-gate * panic_showtrap() to save and print out ptl1_panic information.
6090Sstevel@tonic-gate */
6100Sstevel@tonic-gate if (curthread->t_panic_trap == NULL)
6110Sstevel@tonic-gate curthread->t_panic_trap = &ti;
6120Sstevel@tonic-gate
6130Sstevel@tonic-gate if (reason < sizeof (ptl1_reasons) / sizeof (ptl1_reasons[0]))
6140Sstevel@tonic-gate panic("bad %s at TL %u", ptl1_reasons[reason], tl);
6150Sstevel@tonic-gate else
6160Sstevel@tonic-gate panic("ptl1_panic reason 0x%x at TL %u", reason, tl);
6170Sstevel@tonic-gate }
6180Sstevel@tonic-gate
6190Sstevel@tonic-gate void
clear_watchdog_on_exit(void)6200Sstevel@tonic-gate clear_watchdog_on_exit(void)
6210Sstevel@tonic-gate {
6223349Swentaoy if (watchdog_enabled && watchdog_activated) {
6233349Swentaoy prom_printf("Debugging requested; hardware watchdog "
6244776Sjm22469 "suspended.\n");
6253349Swentaoy (void) watchdog_suspend();
6263349Swentaoy }
6270Sstevel@tonic-gate }
6280Sstevel@tonic-gate
6292036Swentaoy /*
6302036Swentaoy * Restore the watchdog timer when returning from a debugger
6312036Swentaoy * after a panic or L1-A and resume watchdog pat.
6322036Swentaoy */
6330Sstevel@tonic-gate void
restore_watchdog_on_entry()6342036Swentaoy restore_watchdog_on_entry()
6350Sstevel@tonic-gate {
6362036Swentaoy watchdog_resume();
6370Sstevel@tonic-gate }
6380Sstevel@tonic-gate
6390Sstevel@tonic-gate int
kdi_watchdog_disable(void)6400Sstevel@tonic-gate kdi_watchdog_disable(void)
6410Sstevel@tonic-gate {
6422036Swentaoy watchdog_suspend();
6432036Swentaoy
6442036Swentaoy return (0);
6450Sstevel@tonic-gate }
6460Sstevel@tonic-gate
6470Sstevel@tonic-gate void
kdi_watchdog_restore(void)6480Sstevel@tonic-gate kdi_watchdog_restore(void)
6490Sstevel@tonic-gate {
6502036Swentaoy watchdog_resume();
6510Sstevel@tonic-gate }
6520Sstevel@tonic-gate
6530Sstevel@tonic-gate void
mach_dump_buffer_init(void)6540Sstevel@tonic-gate mach_dump_buffer_init(void)
6550Sstevel@tonic-gate {
6560Sstevel@tonic-gate uint64_t ret, minsize = 0;
6570Sstevel@tonic-gate
6580Sstevel@tonic-gate if (hvdump_buf_sz > HVDUMP_SIZE_MAX)
6590Sstevel@tonic-gate hvdump_buf_sz = HVDUMP_SIZE_MAX;
6600Sstevel@tonic-gate
661288Sarao hvdump_buf_va = contig_mem_alloc_align(hvdump_buf_sz, PAGESIZE);
6620Sstevel@tonic-gate if (hvdump_buf_va == NULL)
6630Sstevel@tonic-gate return;
6640Sstevel@tonic-gate
6650Sstevel@tonic-gate hvdump_buf_pa = va_to_pa(hvdump_buf_va);
6660Sstevel@tonic-gate
6670Sstevel@tonic-gate ret = hv_dump_buf_update(hvdump_buf_pa, hvdump_buf_sz,
6680Sstevel@tonic-gate &minsize);
6690Sstevel@tonic-gate
6700Sstevel@tonic-gate if (ret != H_EOK) {
6710Sstevel@tonic-gate contig_mem_free(hvdump_buf_va, hvdump_buf_sz);
6720Sstevel@tonic-gate hvdump_buf_va = NULL;
6730Sstevel@tonic-gate cmn_err(CE_NOTE, "!Error in setting up hvstate"
6740Sstevel@tonic-gate "dump buffer. Error = 0x%lx, size = 0x%lx,"
6750Sstevel@tonic-gate "buf_pa = 0x%lx", ret, hvdump_buf_sz,
6760Sstevel@tonic-gate hvdump_buf_pa);
6770Sstevel@tonic-gate
6780Sstevel@tonic-gate if (ret == H_EINVAL) {
6790Sstevel@tonic-gate cmn_err(CE_NOTE, "!Buffer size too small."
6800Sstevel@tonic-gate "Available buffer size = 0x%lx,"
6810Sstevel@tonic-gate "Minimum buffer size required = 0x%lx",
6820Sstevel@tonic-gate hvdump_buf_sz, minsize);
6830Sstevel@tonic-gate }
6840Sstevel@tonic-gate }
6850Sstevel@tonic-gate }
6860Sstevel@tonic-gate
6870Sstevel@tonic-gate
6880Sstevel@tonic-gate static void
update_hvdump_buffer(void)6890Sstevel@tonic-gate update_hvdump_buffer(void)
6900Sstevel@tonic-gate {
6910Sstevel@tonic-gate uint64_t ret, dummy_val;
6920Sstevel@tonic-gate
6930Sstevel@tonic-gate if (hvdump_buf_va == NULL)
6940Sstevel@tonic-gate return;
6950Sstevel@tonic-gate
6960Sstevel@tonic-gate ret = hv_dump_buf_update(hvdump_buf_pa, hvdump_buf_sz,
6970Sstevel@tonic-gate &dummy_val);
6980Sstevel@tonic-gate if (ret != H_EOK) {
6990Sstevel@tonic-gate cmn_err(CE_NOTE, "!Cannot update hvstate dump"
7000Sstevel@tonic-gate "buffer. Error = 0x%lx", ret);
7010Sstevel@tonic-gate }
7020Sstevel@tonic-gate }
7030Sstevel@tonic-gate
7040Sstevel@tonic-gate
7050Sstevel@tonic-gate static int
getintprop(pnode_t node,char * name,int deflt)706789Sahrens getintprop(pnode_t node, char *name, int deflt)
7070Sstevel@tonic-gate {
7080Sstevel@tonic-gate int value;
7090Sstevel@tonic-gate
7100Sstevel@tonic-gate switch (prom_getproplen(node, name)) {
7110Sstevel@tonic-gate case 0:
7120Sstevel@tonic-gate value = 1; /* boolean properties */
7130Sstevel@tonic-gate break;
7140Sstevel@tonic-gate
7150Sstevel@tonic-gate case sizeof (int):
7160Sstevel@tonic-gate (void) prom_getprop(node, name, (caddr_t)&value);
7170Sstevel@tonic-gate break;
7180Sstevel@tonic-gate
7190Sstevel@tonic-gate default:
7200Sstevel@tonic-gate value = deflt;
7210Sstevel@tonic-gate break;
7220Sstevel@tonic-gate }
7230Sstevel@tonic-gate
7240Sstevel@tonic-gate return (value);
7250Sstevel@tonic-gate }
7260Sstevel@tonic-gate
7270Sstevel@tonic-gate /*
7280Sstevel@tonic-gate * Called by setcpudelay
7290Sstevel@tonic-gate */
7300Sstevel@tonic-gate void
cpu_init_tick_freq(void)7310Sstevel@tonic-gate cpu_init_tick_freq(void)
7320Sstevel@tonic-gate {
7331991Sheppo md_t *mdp;
7341991Sheppo mde_cookie_t rootnode;
7351991Sheppo int listsz;
7361991Sheppo mde_cookie_t *listp = NULL;
7371991Sheppo int num_nodes;
7381991Sheppo uint64_t stick_prop;
7391991Sheppo
7401991Sheppo if (broken_md_flag) {
7411991Sheppo sys_tick_freq = cpunodes[CPU->cpu_id].clock_freq;
7421991Sheppo return;
7431991Sheppo }
7441991Sheppo
7451991Sheppo if ((mdp = md_get_handle()) == NULL)
7461991Sheppo panic("stick_frequency property not found in MD");
7471991Sheppo
7481991Sheppo rootnode = md_root_node(mdp);
7491991Sheppo ASSERT(rootnode != MDE_INVAL_ELEM_COOKIE);
7501991Sheppo
7511991Sheppo num_nodes = md_node_count(mdp);
7521991Sheppo
7531991Sheppo ASSERT(num_nodes > 0);
7541991Sheppo listsz = num_nodes * sizeof (mde_cookie_t);
7551991Sheppo listp = (mde_cookie_t *)prom_alloc((caddr_t)0, listsz, 0);
7561991Sheppo
7571991Sheppo if (listp == NULL)
7581991Sheppo panic("cannot allocate list for MD properties");
7591991Sheppo
7601991Sheppo num_nodes = md_scan_dag(mdp, rootnode, md_find_name(mdp, "platform"),
7611991Sheppo md_find_name(mdp, "fwd"), listp);
7621991Sheppo
7631991Sheppo ASSERT(num_nodes == 1);
7641991Sheppo
7651991Sheppo if (md_get_prop_val(mdp, *listp, "stick-frequency", &stick_prop) != 0)
7661991Sheppo panic("stick_frequency property not found in MD");
7671991Sheppo
7681991Sheppo sys_tick_freq = stick_prop;
7691991Sheppo
7701991Sheppo prom_free((caddr_t)listp, listsz);
7711991Sheppo (void) md_fini_handle(mdp);
7720Sstevel@tonic-gate }
7730Sstevel@tonic-gate
7740Sstevel@tonic-gate int shipit(int n, uint64_t cpu_list_ra);
7750Sstevel@tonic-gate
7760Sstevel@tonic-gate #ifdef DEBUG
7770Sstevel@tonic-gate #define SEND_MONDO_STATS 1
7780Sstevel@tonic-gate #endif
7790Sstevel@tonic-gate
7800Sstevel@tonic-gate #ifdef SEND_MONDO_STATS
7810Sstevel@tonic-gate uint32_t x_one_stimes[64];
7820Sstevel@tonic-gate uint32_t x_one_ltimes[16];
7830Sstevel@tonic-gate uint32_t x_set_stimes[64];
7840Sstevel@tonic-gate uint32_t x_set_ltimes[16];
7850Sstevel@tonic-gate uint32_t x_set_cpus[NCPU];
7860Sstevel@tonic-gate #endif
7870Sstevel@tonic-gate
7880Sstevel@tonic-gate void
send_one_mondo(int cpuid)7890Sstevel@tonic-gate send_one_mondo(int cpuid)
7900Sstevel@tonic-gate {
7910Sstevel@tonic-gate int retries, stat;
7920Sstevel@tonic-gate uint64_t starttick, endtick, tick, lasttick;
7930Sstevel@tonic-gate struct machcpu *mcpup = &(CPU->cpu_m);
7940Sstevel@tonic-gate
7950Sstevel@tonic-gate CPU_STATS_ADDQ(CPU, sys, xcalls, 1);
7960Sstevel@tonic-gate starttick = lasttick = gettick();
7970Sstevel@tonic-gate mcpup->cpu_list[0] = (uint16_t)cpuid;
7980Sstevel@tonic-gate stat = shipit(1, mcpup->cpu_list_ra);
7990Sstevel@tonic-gate endtick = starttick + xc_tick_limit;
8000Sstevel@tonic-gate retries = 0;
8011310Sha137994 while (stat != H_EOK) {
8021310Sha137994 if (stat != H_EWOULDBLOCK) {
8031310Sha137994 if (panic_quiesce)
8041310Sha137994 return;
8051310Sha137994 if (stat == H_ECPUERROR)
8061310Sha137994 cmn_err(CE_PANIC, "send_one_mondo: "
8071310Sha137994 "cpuid: 0x%x has been marked in "
8081310Sha137994 "error", cpuid);
8091310Sha137994 else
8101310Sha137994 cmn_err(CE_PANIC, "send_one_mondo: "
8111310Sha137994 "unexpected hypervisor error 0x%x "
8121310Sha137994 "while sending a mondo to cpuid: "
8131310Sha137994 "0x%x", stat, cpuid);
8141310Sha137994 }
8150Sstevel@tonic-gate tick = gettick();
8160Sstevel@tonic-gate /*
8170Sstevel@tonic-gate * If there is a big jump between the current tick
8180Sstevel@tonic-gate * count and lasttick, we have probably hit a break
8190Sstevel@tonic-gate * point. Adjust endtick accordingly to avoid panic.
8200Sstevel@tonic-gate */
8210Sstevel@tonic-gate if (tick > (lasttick + xc_tick_jump_limit))
8220Sstevel@tonic-gate endtick += (tick - lasttick);
8230Sstevel@tonic-gate lasttick = tick;
8240Sstevel@tonic-gate if (tick > endtick) {
8250Sstevel@tonic-gate if (panic_quiesce)
8260Sstevel@tonic-gate return;
8270Sstevel@tonic-gate cmn_err(CE_PANIC, "send mondo timeout "
8280Sstevel@tonic-gate "(target 0x%x) [retries: 0x%x hvstat: 0x%x]",
8290Sstevel@tonic-gate cpuid, retries, stat);
8300Sstevel@tonic-gate }
8310Sstevel@tonic-gate drv_usecwait(1);
8320Sstevel@tonic-gate stat = shipit(1, mcpup->cpu_list_ra);
8330Sstevel@tonic-gate retries++;
8340Sstevel@tonic-gate }
8350Sstevel@tonic-gate #ifdef SEND_MONDO_STATS
8360Sstevel@tonic-gate {
8371310Sha137994 uint64_t n = gettick() - starttick;
8380Sstevel@tonic-gate if (n < 8192)
8390Sstevel@tonic-gate x_one_stimes[n >> 7]++;
8401310Sha137994 else if (n < 15*8192)
8411310Sha137994 x_one_ltimes[n >> 13]++;
8420Sstevel@tonic-gate else
8430Sstevel@tonic-gate x_one_ltimes[0xf]++;
8440Sstevel@tonic-gate }
8450Sstevel@tonic-gate #endif
8460Sstevel@tonic-gate }
8470Sstevel@tonic-gate
8480Sstevel@tonic-gate void
send_mondo_set(cpuset_t set)8490Sstevel@tonic-gate send_mondo_set(cpuset_t set)
8500Sstevel@tonic-gate {
8510Sstevel@tonic-gate uint64_t starttick, endtick, tick, lasttick;
8522492Sha137994 uint_t largestid, smallestid;
8532492Sha137994 int i, j;
8542492Sha137994 int ncpuids = 0;
8550Sstevel@tonic-gate int shipped = 0;
8561310Sha137994 int retries = 0;
8570Sstevel@tonic-gate struct machcpu *mcpup = &(CPU->cpu_m);
8580Sstevel@tonic-gate
8590Sstevel@tonic-gate ASSERT(!CPUSET_ISNULL(set));
8602492Sha137994 CPUSET_BOUNDS(set, smallestid, largestid);
8612492Sha137994 if (smallestid == CPUSET_NOTINSET) {
8622492Sha137994 return;
8632492Sha137994 }
8642492Sha137994
8650Sstevel@tonic-gate starttick = lasttick = gettick();
8660Sstevel@tonic-gate endtick = starttick + xc_tick_limit;
8670Sstevel@tonic-gate
8682492Sha137994 /*
8692492Sha137994 * Assemble CPU list for HV argument. We already know
8702492Sha137994 * smallestid and largestid are members of set.
8712492Sha137994 */
8722492Sha137994 mcpup->cpu_list[ncpuids++] = (uint16_t)smallestid;
8732492Sha137994 if (largestid != smallestid) {
8742492Sha137994 for (i = smallestid+1; i <= largestid-1; i++) {
8751310Sha137994 if (CPU_IN_SET(set, i)) {
8762492Sha137994 mcpup->cpu_list[ncpuids++] = (uint16_t)i;
8771310Sha137994 }
8781310Sha137994 }
8792492Sha137994 mcpup->cpu_list[ncpuids++] = (uint16_t)largestid;
8802492Sha137994 }
8812492Sha137994
8822492Sha137994 do {
8832492Sha137994 int stat;
8841310Sha137994
8851310Sha137994 stat = shipit(ncpuids, mcpup->cpu_list_ra);
8861310Sha137994 if (stat == H_EOK) {
8871310Sha137994 shipped += ncpuids;
8881310Sha137994 break;
8891310Sha137994 }
8901310Sha137994
8911310Sha137994 /*
8921310Sha137994 * Either not all CPU mondos were sent, or an
8931310Sha137994 * error occurred. CPUs that were sent mondos
8941310Sha137994 * have their CPU IDs overwritten in cpu_list.
8952492Sha137994 * Reset cpu_list so that it only holds those
8962492Sha137994 * CPU IDs that still need to be sent.
8971310Sha137994 */
8982492Sha137994 for (i = 0, j = 0; i < ncpuids; i++) {
8991310Sha137994 if (mcpup->cpu_list[i] == HV_SEND_MONDO_ENTRYDONE) {
9001310Sha137994 shipped++;
9011310Sha137994 } else {
9022492Sha137994 mcpup->cpu_list[j++] = mcpup->cpu_list[i];
9030Sstevel@tonic-gate }
9040Sstevel@tonic-gate }
9052492Sha137994 ncpuids = j;
9061310Sha137994
9071310Sha137994 /*
9081310Sha137994 * Now handle possible errors returned
9091310Sha137994 * from hypervisor.
9101310Sha137994 */
9111310Sha137994 if (stat == H_ECPUERROR) {
9122492Sha137994 int errorcpus;
9132492Sha137994
9142492Sha137994 if (!panic_quiesce)
9152492Sha137994 cmn_err(CE_CONT, "send_mondo_set: cpuid(s) ");
9161310Sha137994
9171310Sha137994 /*
9182492Sha137994 * Remove any CPUs in the error state from
9192492Sha137994 * cpu_list. At this point cpu_list only
9202492Sha137994 * contains the CPU IDs for mondos not
9212492Sha137994 * succesfully sent.
9221310Sha137994 */
9232492Sha137994 for (i = 0, errorcpus = 0; i < ncpuids; i++) {
9242492Sha137994 uint64_t state = CPU_STATE_INVALID;
9252492Sha137994 uint16_t id = mcpup->cpu_list[i];
9262492Sha137994
9272492Sha137994 (void) hv_cpu_state(id, &state);
9282492Sha137994 if (state == CPU_STATE_ERROR) {
9292492Sha137994 if (!panic_quiesce)
9302492Sha137994 cmn_err(CE_CONT, "0x%x ", id);
9312492Sha137994 errorcpus++;
9322492Sha137994 } else if (errorcpus > 0) {
9332492Sha137994 mcpup->cpu_list[i - errorcpus] =
9342492Sha137994 mcpup->cpu_list[i];
9351310Sha137994 }
9361310Sha137994 }
9372492Sha137994 ncpuids -= errorcpus;
9380Sstevel@tonic-gate
9391310Sha137994 if (!panic_quiesce) {
9402492Sha137994 if (errorcpus == 0) {
9412492Sha137994 cmn_err(CE_CONT, "<none> have been "
9422492Sha137994 "marked in error\n");
9431310Sha137994 cmn_err(CE_PANIC, "send_mondo_set: "
9441310Sha137994 "hypervisor returned "
9451310Sha137994 "H_ECPUERROR but no CPU in "
9461310Sha137994 "cpu_list in error state");
9472492Sha137994 } else {
9482492Sha137994 cmn_err(CE_CONT, "have been marked in "
9492492Sha137994 "error\n");
9502492Sha137994 cmn_err(CE_PANIC, "send_mondo_set: "
9512492Sha137994 "CPU(s) in error state");
9521310Sha137994 }
9531310Sha137994 }
9541310Sha137994 } else if (stat != H_EWOULDBLOCK) {
9551310Sha137994 if (panic_quiesce)
9561310Sha137994 return;
9571310Sha137994 /*
9581310Sha137994 * For all other errors, panic.
9591310Sha137994 */
9601310Sha137994 cmn_err(CE_CONT, "send_mondo_set: unexpected "
9611310Sha137994 "hypervisor error 0x%x while sending a "
9621310Sha137994 "mondo to cpuid(s):", stat);
9632492Sha137994 for (i = 0; i < ncpuids; i++) {
9642492Sha137994 cmn_err(CE_CONT, " 0x%x", mcpup->cpu_list[i]);
9651310Sha137994 }
9661310Sha137994 cmn_err(CE_CONT, "\n");
9671310Sha137994 cmn_err(CE_PANIC, "send_mondo_set: unexpected "
9681310Sha137994 "hypervisor error");
9691310Sha137994 }
9701310Sha137994
9710Sstevel@tonic-gate tick = gettick();
9720Sstevel@tonic-gate /*
9730Sstevel@tonic-gate * If there is a big jump between the current tick
9740Sstevel@tonic-gate * count and lasttick, we have probably hit a break
9750Sstevel@tonic-gate * point. Adjust endtick accordingly to avoid panic.
9760Sstevel@tonic-gate */
9770Sstevel@tonic-gate if (tick > (lasttick + xc_tick_jump_limit))
9780Sstevel@tonic-gate endtick += (tick - lasttick);
9790Sstevel@tonic-gate lasttick = tick;
9800Sstevel@tonic-gate if (tick > endtick) {
9810Sstevel@tonic-gate if (panic_quiesce)
9820Sstevel@tonic-gate return;
9830Sstevel@tonic-gate cmn_err(CE_CONT, "send mondo timeout "
9840Sstevel@tonic-gate "[retries: 0x%x] cpuids: ", retries);
9852492Sha137994 for (i = 0; i < ncpuids; i++)
9862492Sha137994 cmn_err(CE_CONT, " 0x%x", mcpup->cpu_list[i]);
9870Sstevel@tonic-gate cmn_err(CE_CONT, "\n");
9880Sstevel@tonic-gate cmn_err(CE_PANIC, "send_mondo_set: timeout");
9890Sstevel@tonic-gate }
9900Sstevel@tonic-gate
9910Sstevel@tonic-gate while (gettick() < (tick + sys_clock_mhz))
9920Sstevel@tonic-gate ;
9930Sstevel@tonic-gate retries++;
9942492Sha137994 } while (ncpuids > 0);
9951310Sha137994
9961310Sha137994 CPU_STATS_ADDQ(CPU, sys, xcalls, shipped);
9970Sstevel@tonic-gate
9980Sstevel@tonic-gate #ifdef SEND_MONDO_STATS
9990Sstevel@tonic-gate {
10001310Sha137994 uint64_t n = gettick() - starttick;
10010Sstevel@tonic-gate if (n < 8192)
10020Sstevel@tonic-gate x_set_stimes[n >> 7]++;
10031310Sha137994 else if (n < 15*8192)
10041310Sha137994 x_set_ltimes[n >> 13]++;
10050Sstevel@tonic-gate else
10060Sstevel@tonic-gate x_set_ltimes[0xf]++;
10070Sstevel@tonic-gate }
10080Sstevel@tonic-gate x_set_cpus[shipped]++;
10090Sstevel@tonic-gate #endif
10100Sstevel@tonic-gate }
10110Sstevel@tonic-gate
10120Sstevel@tonic-gate void
syncfpu(void)10130Sstevel@tonic-gate syncfpu(void)
10140Sstevel@tonic-gate {
10150Sstevel@tonic-gate }
10160Sstevel@tonic-gate
10170Sstevel@tonic-gate void
sticksync_slave(void)10180Sstevel@tonic-gate sticksync_slave(void)
101911172SHaik.Aftandilian@Sun.COM {
102011172SHaik.Aftandilian@Sun.COM suspend_sync_tick_stick_npt();
102111172SHaik.Aftandilian@Sun.COM }
10220Sstevel@tonic-gate
10230Sstevel@tonic-gate void
sticksync_master(void)10240Sstevel@tonic-gate sticksync_master(void)
10250Sstevel@tonic-gate {}
10260Sstevel@tonic-gate
10270Sstevel@tonic-gate void
cpu_init_cache_scrub(void)10280Sstevel@tonic-gate cpu_init_cache_scrub(void)
10293266Sjb145095 {
10303266Sjb145095 mach_set_soft_state(SIS_NORMAL, &SOLARIS_SOFT_STATE_RUN_MSG);
10313266Sjb145095 }
10320Sstevel@tonic-gate
10330Sstevel@tonic-gate int
dtrace_blksuword32_err(uintptr_t addr,uint32_t * data)10340Sstevel@tonic-gate dtrace_blksuword32_err(uintptr_t addr, uint32_t *data)
10350Sstevel@tonic-gate {
10360Sstevel@tonic-gate int ret, watched;
10370Sstevel@tonic-gate
10380Sstevel@tonic-gate watched = watch_disable_addr((void *)addr, 4, S_WRITE);
10390Sstevel@tonic-gate ret = dtrace_blksuword32(addr, data, 0);
10400Sstevel@tonic-gate if (watched)
10410Sstevel@tonic-gate watch_enable_addr((void *)addr, 4, S_WRITE);
10420Sstevel@tonic-gate
10430Sstevel@tonic-gate return (ret);
10440Sstevel@tonic-gate }
10450Sstevel@tonic-gate
10460Sstevel@tonic-gate int
dtrace_blksuword32(uintptr_t addr,uint32_t * data,int tryagain)10470Sstevel@tonic-gate dtrace_blksuword32(uintptr_t addr, uint32_t *data, int tryagain)
10480Sstevel@tonic-gate {
10490Sstevel@tonic-gate if (suword32((void *)addr, *data) == -1)
10500Sstevel@tonic-gate return (tryagain ? dtrace_blksuword32_err(addr, data) : -1);
10510Sstevel@tonic-gate dtrace_flush_sec(addr);
10520Sstevel@tonic-gate
10530Sstevel@tonic-gate return (0);
10540Sstevel@tonic-gate }
10550Sstevel@tonic-gate
10560Sstevel@tonic-gate /*ARGSUSED*/
10570Sstevel@tonic-gate void
cpu_faulted_enter(struct cpu * cp)10580Sstevel@tonic-gate cpu_faulted_enter(struct cpu *cp)
10590Sstevel@tonic-gate {
10600Sstevel@tonic-gate }
10610Sstevel@tonic-gate
10620Sstevel@tonic-gate /*ARGSUSED*/
10630Sstevel@tonic-gate void
cpu_faulted_exit(struct cpu * cp)10640Sstevel@tonic-gate cpu_faulted_exit(struct cpu *cp)
10650Sstevel@tonic-gate {
10660Sstevel@tonic-gate }
10670Sstevel@tonic-gate
10680Sstevel@tonic-gate static int
kdi_cpu_ready_iter(int (* cb)(int,void *),void * arg)10690Sstevel@tonic-gate kdi_cpu_ready_iter(int (*cb)(int, void *), void *arg)
10700Sstevel@tonic-gate {
10710Sstevel@tonic-gate int rc, i;
10720Sstevel@tonic-gate
10730Sstevel@tonic-gate for (rc = 0, i = 0; i < NCPU; i++) {
10740Sstevel@tonic-gate if (CPU_IN_SET(cpu_ready_set, i))
10750Sstevel@tonic-gate rc += cb(i, arg);
10760Sstevel@tonic-gate }
10770Sstevel@tonic-gate
10780Sstevel@tonic-gate return (rc);
10790Sstevel@tonic-gate }
10800Sstevel@tonic-gate
10810Sstevel@tonic-gate /*
10820Sstevel@tonic-gate * Sends a cross-call to a specified processor. The caller assumes
10830Sstevel@tonic-gate * responsibility for repetition of cross-calls, as appropriate (MARSA for
10840Sstevel@tonic-gate * debugging).
10850Sstevel@tonic-gate */
10860Sstevel@tonic-gate static int
kdi_xc_one(int cpuid,void (* func)(uintptr_t,uintptr_t),uintptr_t arg1,uintptr_t arg2)10870Sstevel@tonic-gate kdi_xc_one(int cpuid, void (*func)(uintptr_t, uintptr_t), uintptr_t arg1,
10880Sstevel@tonic-gate uintptr_t arg2)
10890Sstevel@tonic-gate {
10900Sstevel@tonic-gate int stat;
10910Sstevel@tonic-gate struct machcpu *mcpup;
10920Sstevel@tonic-gate uint64_t cpuaddr_reg = 0, cpuaddr_scr = 0;
10930Sstevel@tonic-gate
10940Sstevel@tonic-gate mcpup = &(((cpu_t *)get_cpuaddr(cpuaddr_reg, cpuaddr_scr))->cpu_m);
10950Sstevel@tonic-gate
10960Sstevel@tonic-gate /*
10970Sstevel@tonic-gate * if (idsr_busy())
10980Sstevel@tonic-gate * return (KDI_XC_RES_ERR);
10990Sstevel@tonic-gate */
11000Sstevel@tonic-gate
11010Sstevel@tonic-gate init_mondo_nocheck((xcfunc_t *)func, arg1, arg2);
11020Sstevel@tonic-gate
11030Sstevel@tonic-gate mcpup->cpu_list[0] = (uint16_t)cpuid;
11040Sstevel@tonic-gate stat = shipit(1, mcpup->cpu_list_ra);
11050Sstevel@tonic-gate
11060Sstevel@tonic-gate if (stat == 0)
11070Sstevel@tonic-gate return (KDI_XC_RES_OK);
11080Sstevel@tonic-gate else
11090Sstevel@tonic-gate return (KDI_XC_RES_NACK);
11100Sstevel@tonic-gate }
11110Sstevel@tonic-gate
11120Sstevel@tonic-gate static void
kdi_tickwait(clock_t nticks)11130Sstevel@tonic-gate kdi_tickwait(clock_t nticks)
11140Sstevel@tonic-gate {
11150Sstevel@tonic-gate clock_t endtick = gettick() + nticks;
11160Sstevel@tonic-gate
11174776Sjm22469 while (gettick() < endtick)
11185974Sjm22469 ;
11190Sstevel@tonic-gate }
11200Sstevel@tonic-gate
11210Sstevel@tonic-gate static void
kdi_cpu_init(int dcache_size,int dcache_linesize,int icache_size,int icache_linesize)11220Sstevel@tonic-gate kdi_cpu_init(int dcache_size, int dcache_linesize, int icache_size,
11230Sstevel@tonic-gate int icache_linesize)
11240Sstevel@tonic-gate {
11250Sstevel@tonic-gate kdi_dcache_size = dcache_size;
11260Sstevel@tonic-gate kdi_dcache_linesize = dcache_linesize;
11270Sstevel@tonic-gate kdi_icache_size = icache_size;
11280Sstevel@tonic-gate kdi_icache_linesize = icache_linesize;
11290Sstevel@tonic-gate }
11300Sstevel@tonic-gate
11310Sstevel@tonic-gate /* used directly by kdi_read/write_phys */
11320Sstevel@tonic-gate void
kdi_flush_caches(void)11330Sstevel@tonic-gate kdi_flush_caches(void)
11340Sstevel@tonic-gate {
113510271SJason.Beloro@Sun.COM /* Not required on sun4v architecture. */
11360Sstevel@tonic-gate }
11370Sstevel@tonic-gate
11380Sstevel@tonic-gate /*ARGSUSED*/
11390Sstevel@tonic-gate int
kdi_get_stick(uint64_t * stickp)11400Sstevel@tonic-gate kdi_get_stick(uint64_t *stickp)
11410Sstevel@tonic-gate {
11420Sstevel@tonic-gate return (-1);
11430Sstevel@tonic-gate }
11440Sstevel@tonic-gate
11450Sstevel@tonic-gate void
cpu_kdi_init(kdi_t * kdi)11460Sstevel@tonic-gate cpu_kdi_init(kdi_t *kdi)
11470Sstevel@tonic-gate {
11480Sstevel@tonic-gate kdi->kdi_flush_caches = kdi_flush_caches;
11490Sstevel@tonic-gate kdi->mkdi_cpu_init = kdi_cpu_init;
11500Sstevel@tonic-gate kdi->mkdi_cpu_ready_iter = kdi_cpu_ready_iter;
11510Sstevel@tonic-gate kdi->mkdi_xc_one = kdi_xc_one;
11520Sstevel@tonic-gate kdi->mkdi_tickwait = kdi_tickwait;
11530Sstevel@tonic-gate kdi->mkdi_get_stick = kdi_get_stick;
11540Sstevel@tonic-gate }
11550Sstevel@tonic-gate
11563266Sjb145095 uint64_t soft_state_message_ra[SOLARIS_SOFT_STATE_MSG_CNT];
11573266Sjb145095 static uint64_t soft_state_saved_state = (uint64_t)-1;
11583266Sjb145095 static int soft_state_initialized = 0;
11593266Sjb145095 static uint64_t soft_state_sup_minor; /* Supported minor number */
11603266Sjb145095 static hsvc_info_t soft_state_hsvc = {
11613266Sjb145095 HSVC_REV_1, NULL, HSVC_GROUP_SOFT_STATE, 1, 0, NULL };
11623266Sjb145095
11633266Sjb145095
11642036Swentaoy static void
sun4v_system_claim(void)11652036Swentaoy sun4v_system_claim(void)
11662036Swentaoy {
116711066Srafael.vanoni@sun.com lbolt_debug_entry();
116811066Srafael.vanoni@sun.com
11692036Swentaoy watchdog_suspend();
11708542SHaik.Aftandilian@Sun.COM kldc_debug_enter();
11713266Sjb145095 /*
11723266Sjb145095 * For "mdb -K", set soft state to debugging
11733266Sjb145095 */
11743266Sjb145095 if (soft_state_saved_state == -1) {
11753266Sjb145095 mach_get_soft_state(&soft_state_saved_state,
11764776Sjm22469 &SOLARIS_SOFT_STATE_SAVED_MSG);
11773266Sjb145095 }
11783266Sjb145095 /*
11793266Sjb145095 * check again as the read above may or may not have worked and if
11803266Sjb145095 * it didn't then soft state will still be -1
11813266Sjb145095 */
11823266Sjb145095 if (soft_state_saved_state != -1) {
11833266Sjb145095 mach_set_soft_state(SIS_TRANSITION,
11844776Sjm22469 &SOLARIS_SOFT_STATE_DEBUG_MSG);
11853266Sjb145095 }
11862036Swentaoy }
11872036Swentaoy
11882036Swentaoy static void
sun4v_system_release(void)11892036Swentaoy sun4v_system_release(void)
11902036Swentaoy {
11912036Swentaoy watchdog_resume();
11923266Sjb145095 /*
11933266Sjb145095 * For "mdb -K", set soft_state state back to original state on exit
11943266Sjb145095 */
11953266Sjb145095 if (soft_state_saved_state != -1) {
11963266Sjb145095 mach_set_soft_state(soft_state_saved_state,
11974776Sjm22469 &SOLARIS_SOFT_STATE_SAVED_MSG);
11983266Sjb145095 soft_state_saved_state = -1;
11993266Sjb145095 }
120011066Srafael.vanoni@sun.com
120111066Srafael.vanoni@sun.com lbolt_debug_return();
12022036Swentaoy }
12032036Swentaoy
12042036Swentaoy void
plat_kdi_init(kdi_t * kdi)12052036Swentaoy plat_kdi_init(kdi_t *kdi)
12062036Swentaoy {
12072036Swentaoy kdi->pkdi_system_claim = sun4v_system_claim;
12082036Swentaoy kdi->pkdi_system_release = sun4v_system_release;
12092036Swentaoy }
12102036Swentaoy
12110Sstevel@tonic-gate /*
12120Sstevel@tonic-gate * Routine to return memory information associated
12130Sstevel@tonic-gate * with a physical address and syndrome.
12140Sstevel@tonic-gate */
12150Sstevel@tonic-gate /* ARGSUSED */
12160Sstevel@tonic-gate int
cpu_get_mem_info(uint64_t synd,uint64_t afar,uint64_t * mem_sizep,uint64_t * seg_sizep,uint64_t * bank_sizep,int * segsp,int * banksp,int * mcidp)12170Sstevel@tonic-gate cpu_get_mem_info(uint64_t synd, uint64_t afar,
12180Sstevel@tonic-gate uint64_t *mem_sizep, uint64_t *seg_sizep, uint64_t *bank_sizep,
12190Sstevel@tonic-gate int *segsp, int *banksp, int *mcidp)
12200Sstevel@tonic-gate {
12210Sstevel@tonic-gate return (ENOTSUP);
12220Sstevel@tonic-gate }
12230Sstevel@tonic-gate
12240Sstevel@tonic-gate /*
12250Sstevel@tonic-gate * This routine returns the size of the kernel's FRU name buffer.
12260Sstevel@tonic-gate */
12270Sstevel@tonic-gate size_t
cpu_get_name_bufsize()12280Sstevel@tonic-gate cpu_get_name_bufsize()
12290Sstevel@tonic-gate {
12300Sstevel@tonic-gate return (UNUM_NAMLEN);
12310Sstevel@tonic-gate }
12320Sstevel@tonic-gate
12330Sstevel@tonic-gate /*
12340Sstevel@tonic-gate * This routine is a more generic interface to cpu_get_mem_unum(),
12350Sstevel@tonic-gate * that may be used by other modules (e.g. mm).
12360Sstevel@tonic-gate */
12370Sstevel@tonic-gate /* ARGSUSED */
12380Sstevel@tonic-gate int
cpu_get_mem_name(uint64_t synd,uint64_t * afsr,uint64_t afar,char * buf,int buflen,int * lenp)12390Sstevel@tonic-gate cpu_get_mem_name(uint64_t synd, uint64_t *afsr, uint64_t afar,
12400Sstevel@tonic-gate char *buf, int buflen, int *lenp)
12410Sstevel@tonic-gate {
12420Sstevel@tonic-gate return (ENOTSUP);
12430Sstevel@tonic-gate }
12440Sstevel@tonic-gate
12451186Sayznaga /* ARGSUSED */
12461186Sayznaga int
cpu_get_mem_sid(char * unum,char * buf,int buflen,int * lenp)12471186Sayznaga cpu_get_mem_sid(char *unum, char *buf, int buflen, int *lenp)
12481186Sayznaga {
12491186Sayznaga return (ENOTSUP);
12501186Sayznaga }
12511186Sayznaga
12521186Sayznaga /* ARGSUSED */
12531186Sayznaga int
cpu_get_mem_addr(char * unum,char * sid,uint64_t offset,uint64_t * addrp)12541186Sayznaga cpu_get_mem_addr(char *unum, char *sid, uint64_t offset, uint64_t *addrp)
12551186Sayznaga {
12561186Sayznaga return (ENOTSUP);
12571186Sayznaga }
12581186Sayznaga
12590Sstevel@tonic-gate /*
12600Sstevel@tonic-gate * xt_sync - wait for previous x-traps to finish
12610Sstevel@tonic-gate */
12620Sstevel@tonic-gate void
xt_sync(cpuset_t cpuset)12630Sstevel@tonic-gate xt_sync(cpuset_t cpuset)
12640Sstevel@tonic-gate {
12650Sstevel@tonic-gate union {
12660Sstevel@tonic-gate uint8_t volatile byte[NCPU];
12670Sstevel@tonic-gate uint64_t volatile xword[NCPU / 8];
12680Sstevel@tonic-gate } cpu_sync;
12695146Ssvemuri uint64_t starttick, endtick, tick, lasttick, traptrace_id;
12702492Sha137994 uint_t largestid, smallestid;
12713316Srf157361 int i, j;
12720Sstevel@tonic-gate
12730Sstevel@tonic-gate kpreempt_disable();
12740Sstevel@tonic-gate CPUSET_DEL(cpuset, CPU->cpu_id);
12750Sstevel@tonic-gate CPUSET_AND(cpuset, cpu_ready_set);
12760Sstevel@tonic-gate
12772492Sha137994 CPUSET_BOUNDS(cpuset, smallestid, largestid);
12782492Sha137994 if (smallestid == CPUSET_NOTINSET)
12792492Sha137994 goto out;
12802492Sha137994
12810Sstevel@tonic-gate /*
12820Sstevel@tonic-gate * Sun4v uses a queue for receiving mondos. Successful
12830Sstevel@tonic-gate * transmission of a mondo only indicates that the mondo
12840Sstevel@tonic-gate * has been written into the queue.
12850Sstevel@tonic-gate *
12860Sstevel@tonic-gate * We use an array of bytes to let each cpu to signal back
12870Sstevel@tonic-gate * to the cross trap sender that the cross trap has been
12880Sstevel@tonic-gate * executed. Set the byte to 1 before sending the cross trap
12890Sstevel@tonic-gate * and wait until other cpus reset it to 0.
12900Sstevel@tonic-gate */
12910Sstevel@tonic-gate bzero((void *)&cpu_sync, NCPU);
12922492Sha137994 cpu_sync.byte[smallestid] = 1;
12932492Sha137994 if (largestid != smallestid) {
12942492Sha137994 for (i = (smallestid + 1); i <= (largestid - 1); i++)
12952492Sha137994 if (CPU_IN_SET(cpuset, i))
12962492Sha137994 cpu_sync.byte[i] = 1;
12972492Sha137994 cpu_sync.byte[largestid] = 1;
12982492Sha137994 }
12990Sstevel@tonic-gate
13005146Ssvemuri /*
13015146Ssvemuri * To help debug xt_sync panic, each mondo is uniquely identified
13025146Ssvemuri * by passing the tick value, traptrace_id as the second mondo
13035146Ssvemuri * argument to xt_some which is logged in CPU's mondo queue,
13045146Ssvemuri * traptrace buffer and the panic message.
13055146Ssvemuri */
13065146Ssvemuri traptrace_id = gettick();
13070Sstevel@tonic-gate xt_some(cpuset, (xcfunc_t *)xt_sync_tl1,
13085146Ssvemuri (uint64_t)cpu_sync.byte, traptrace_id);
13090Sstevel@tonic-gate
13100Sstevel@tonic-gate starttick = lasttick = gettick();
13116138Ssvemuri endtick = starttick + xc_sync_tick_limit;
13120Sstevel@tonic-gate
13132492Sha137994 for (i = (smallestid / 8); i <= (largestid / 8); i++) {
13140Sstevel@tonic-gate while (cpu_sync.xword[i] != 0) {
13150Sstevel@tonic-gate tick = gettick();
13160Sstevel@tonic-gate /*
13170Sstevel@tonic-gate * If there is a big jump between the current tick
13180Sstevel@tonic-gate * count and lasttick, we have probably hit a break
13190Sstevel@tonic-gate * point. Adjust endtick accordingly to avoid panic.
13200Sstevel@tonic-gate */
13210Sstevel@tonic-gate if (tick > (lasttick + xc_tick_jump_limit)) {
13220Sstevel@tonic-gate endtick += (tick - lasttick);
13230Sstevel@tonic-gate }
13240Sstevel@tonic-gate lasttick = tick;
13250Sstevel@tonic-gate if (tick > endtick) {
13260Sstevel@tonic-gate if (panic_quiesce)
13270Sstevel@tonic-gate goto out;
13283316Srf157361 cmn_err(CE_CONT, "Cross trap sync timeout: "
13295146Ssvemuri "at cpu_sync.xword[%d]: 0x%lx "
13305146Ssvemuri "cpu_sync.byte: 0x%lx "
13315146Ssvemuri "starttick: 0x%lx endtick: 0x%lx "
13325146Ssvemuri "traptrace_id = 0x%lx\n",
13335146Ssvemuri i, cpu_sync.xword[i],
13345146Ssvemuri (uint64_t)cpu_sync.byte,
13355146Ssvemuri starttick, endtick, traptrace_id);
13365146Ssvemuri cmn_err(CE_CONT, "CPUIDs:");
13373316Srf157361 for (j = (i * 8); j <= largestid; j++) {
13383316Srf157361 if (cpu_sync.byte[j] != 0)
13393316Srf157361 cmn_err(CE_CONT, " 0x%x", j);
13403316Srf157361 }
13410Sstevel@tonic-gate cmn_err(CE_PANIC, "xt_sync: timeout");
13420Sstevel@tonic-gate }
13430Sstevel@tonic-gate }
13440Sstevel@tonic-gate }
13450Sstevel@tonic-gate
13460Sstevel@tonic-gate out:
13470Sstevel@tonic-gate kpreempt_enable();
13480Sstevel@tonic-gate }
13492957Sjm22469
13506138Ssvemuri #define QFACTOR 200
13512957Sjm22469 /*
13522957Sjm22469 * Recalculate the values of the cross-call timeout variables based
13532957Sjm22469 * on the value of the 'inter-cpu-latency' property of the platform node.
13542957Sjm22469 * The property sets the number of nanosec to wait for a cross-call
13552957Sjm22469 * to be acknowledged. Other timeout variables are derived from it.
13562957Sjm22469 *
13572957Sjm22469 * N.B. This implementation is aware of the internals of xc_init()
13582957Sjm22469 * and updates many of the same variables.
13592957Sjm22469 */
13602957Sjm22469 void
recalc_xc_timeouts(void)13612957Sjm22469 recalc_xc_timeouts(void)
13622957Sjm22469 {
13632957Sjm22469 typedef union {
13642957Sjm22469 uint64_t whole;
13652957Sjm22469 struct {
13662957Sjm22469 uint_t high;
13672957Sjm22469 uint_t low;
13682957Sjm22469 } half;
13692957Sjm22469 } u_number;
13702957Sjm22469
13712957Sjm22469 /* See x_call.c for descriptions of these extern variables. */
13722957Sjm22469 extern uint64_t xc_tick_limit_scale;
13732957Sjm22469 extern uint64_t xc_mondo_time_limit;
13742957Sjm22469 extern uint64_t xc_func_time_limit;
13752957Sjm22469 extern uint64_t xc_scale;
13762957Sjm22469 extern uint64_t xc_mondo_multiplier;
13772957Sjm22469 extern uint_t nsec_shift;
13782957Sjm22469
13792957Sjm22469 /* Temp versions of the target variables */
13802957Sjm22469 uint64_t tick_limit;
13812957Sjm22469 uint64_t tick_jump_limit;
13822957Sjm22469 uint64_t mondo_time_limit;
13832957Sjm22469 uint64_t func_time_limit;
13842957Sjm22469 uint64_t scale;
13852957Sjm22469
13862957Sjm22469 uint64_t latency; /* nanoseconds */
13872957Sjm22469 uint64_t maxfreq;
13882957Sjm22469 uint64_t tick_limit_save = xc_tick_limit;
13896138Ssvemuri uint64_t sync_tick_limit_save = xc_sync_tick_limit;
13902957Sjm22469 uint_t tick_scale;
13912957Sjm22469 uint64_t top;
13922957Sjm22469 uint64_t bottom;
13932957Sjm22469 u_number tk;
13942957Sjm22469
13952957Sjm22469 md_t *mdp;
13962957Sjm22469 int nrnode;
13972957Sjm22469 mde_cookie_t *platlist;
13982957Sjm22469
13992957Sjm22469 /*
14002957Sjm22469 * Look up the 'inter-cpu-latency' (optional) property in the
14012957Sjm22469 * platform node of the MD. The units are nanoseconds.
14022957Sjm22469 */
14032957Sjm22469 if ((mdp = md_get_handle()) == NULL) {
14042957Sjm22469 cmn_err(CE_WARN, "recalc_xc_timeouts: "
14052957Sjm22469 "Unable to initialize machine description");
14062957Sjm22469 return;
14072957Sjm22469 }
14082957Sjm22469
14092957Sjm22469 nrnode = md_alloc_scan_dag(mdp,
14102957Sjm22469 md_root_node(mdp), "platform", "fwd", &platlist);
14112957Sjm22469
14122957Sjm22469 ASSERT(nrnode == 1);
14132957Sjm22469 if (nrnode < 1) {
14142957Sjm22469 cmn_err(CE_WARN, "recalc_xc_timeouts: platform node missing");
14153069Sjm22469 goto done;
14162957Sjm22469 }
14172957Sjm22469 if (md_get_prop_val(mdp, platlist[0],
14182957Sjm22469 "inter-cpu-latency", &latency) == -1)
14193069Sjm22469 goto done;
14202957Sjm22469
14212957Sjm22469 /*
14222957Sjm22469 * clock.h defines an assembly-language macro
14232957Sjm22469 * (NATIVE_TIME_TO_NSEC_SCALE) to convert from %stick
14242957Sjm22469 * units to nanoseconds. Since the inter-cpu-latency
14252957Sjm22469 * units are nanoseconds and the xc_* variables require
14262957Sjm22469 * %stick units, we need the inverse of that function.
14272957Sjm22469 * The trick is to perform the calculation without
14282957Sjm22469 * floating point, but also without integer truncation
14292957Sjm22469 * or overflow. To understand the calculation below,
14302957Sjm22469 * please read the discussion of the macro in clock.h.
14312957Sjm22469 * Since this new code will be invoked infrequently,
14322957Sjm22469 * we can afford to implement it in C.
14332957Sjm22469 *
14342957Sjm22469 * tick_scale is the reciprocal of nsec_scale which is
14352957Sjm22469 * calculated at startup in setcpudelay(). The calc
14362957Sjm22469 * of tick_limit parallels that of NATIVE_TIME_TO_NSEC_SCALE
14372957Sjm22469 * except we use tick_scale instead of nsec_scale and
14382957Sjm22469 * C instead of assembler.
14392957Sjm22469 */
14402957Sjm22469 tick_scale = (uint_t)(((u_longlong_t)sys_tick_freq
14412957Sjm22469 << (32 - nsec_shift)) / NANOSEC);
14422957Sjm22469
14432957Sjm22469 tk.whole = latency;
14442957Sjm22469 top = ((uint64_t)tk.half.high << 4) * tick_scale;
14452957Sjm22469 bottom = (((uint64_t)tk.half.low << 4) * (uint64_t)tick_scale) >> 32;
14462957Sjm22469 tick_limit = top + bottom;
14472957Sjm22469
14482957Sjm22469 /*
14492957Sjm22469 * xc_init() calculated 'maxfreq' by looking at all the cpus,
14502957Sjm22469 * and used it to derive some of the timeout variables that we
14512957Sjm22469 * recalculate below. We can back into the original value by
14522957Sjm22469 * using the inverse of one of those calculations.
14532957Sjm22469 */
14542957Sjm22469 maxfreq = xc_mondo_time_limit / xc_scale;
14552957Sjm22469
14562957Sjm22469 /*
14572957Sjm22469 * Don't allow the new timeout (xc_tick_limit) to fall below
14582957Sjm22469 * the system tick frequency (stick). Allowing the timeout
14592957Sjm22469 * to be set more tightly than this empirically determined
14602957Sjm22469 * value may cause panics.
14612957Sjm22469 */
14622957Sjm22469 tick_limit = tick_limit < sys_tick_freq ? sys_tick_freq : tick_limit;
14632957Sjm22469
14642957Sjm22469 tick_jump_limit = tick_limit / 32;
14652957Sjm22469 tick_limit *= xc_tick_limit_scale;
14662957Sjm22469
14672957Sjm22469 /*
14682957Sjm22469 * Recalculate xc_scale since it is used in a callback function
14692957Sjm22469 * (xc_func_timeout_adj) to adjust two of the timeouts dynamically.
14702957Sjm22469 * Make the change in xc_scale proportional to the change in
14712957Sjm22469 * xc_tick_limit.
14722957Sjm22469 */
14732957Sjm22469 scale = (xc_scale * tick_limit + sys_tick_freq / 2) / tick_limit_save;
14742957Sjm22469 if (scale == 0)
14752957Sjm22469 scale = 1;
14762957Sjm22469
14772957Sjm22469 mondo_time_limit = maxfreq * scale;
14782957Sjm22469 func_time_limit = mondo_time_limit * xc_mondo_multiplier;
14792957Sjm22469
14802957Sjm22469 /*
14812957Sjm22469 * Don't modify the timeouts if nothing has changed. Else,
14822957Sjm22469 * stuff the variables with the freshly calculated (temp)
14832957Sjm22469 * variables. This minimizes the window where the set of
14842957Sjm22469 * values could be inconsistent.
14852957Sjm22469 */
14862957Sjm22469 if (tick_limit != xc_tick_limit) {
14872957Sjm22469 xc_tick_limit = tick_limit;
14882957Sjm22469 xc_tick_jump_limit = tick_jump_limit;
14892957Sjm22469 xc_scale = scale;
14902957Sjm22469 xc_mondo_time_limit = mondo_time_limit;
14912957Sjm22469 xc_func_time_limit = func_time_limit;
14922957Sjm22469 }
14933069Sjm22469
14943069Sjm22469 done:
14956138Ssvemuri /*
14966138Ssvemuri * Increase the timeout limit for xt_sync() cross calls.
14976138Ssvemuri */
14986138Ssvemuri xc_sync_tick_limit = xc_tick_limit * (cpu_q_entries / QFACTOR);
14996138Ssvemuri xc_sync_tick_limit = xc_sync_tick_limit < xc_tick_limit ?
15006138Ssvemuri xc_tick_limit : xc_sync_tick_limit;
15016138Ssvemuri
15026138Ssvemuri /*
15036138Ssvemuri * Force the new values to be used for future cross calls.
15046138Ssvemuri * This is necessary only when we increase the timeouts.
15056138Ssvemuri */
15066138Ssvemuri if ((xc_tick_limit > tick_limit_save) || (xc_sync_tick_limit >
15076138Ssvemuri sync_tick_limit_save)) {
15086138Ssvemuri cpuset_t cpuset = cpu_ready_set;
15096138Ssvemuri xt_sync(cpuset);
15106138Ssvemuri }
15116138Ssvemuri
15123069Sjm22469 if (nrnode > 0)
15133069Sjm22469 md_free_scan_dag(mdp, &platlist);
15143069Sjm22469 (void) md_fini_handle(mdp);
15152957Sjm22469 }
15163266Sjb145095
15173266Sjb145095 void
mach_soft_state_init(void)15183266Sjb145095 mach_soft_state_init(void)
15193266Sjb145095 {
15203266Sjb145095 int i;
15213266Sjb145095 uint64_t ra;
15223266Sjb145095
15233266Sjb145095 /*
15243266Sjb145095 * Try to register soft_state api. If it fails, soft_state api has not
15253266Sjb145095 * been implemented in the firmware, so do not bother to setup
15263266Sjb145095 * soft_state in the kernel.
15273266Sjb145095 */
15283266Sjb145095 if ((i = hsvc_register(&soft_state_hsvc, &soft_state_sup_minor)) != 0) {
15293266Sjb145095 return;
15303266Sjb145095 }
15313266Sjb145095 for (i = 0; i < SOLARIS_SOFT_STATE_MSG_CNT; i++) {
15323266Sjb145095 ASSERT(strlen((const char *)(void *)
15334776Sjm22469 soft_state_message_strings + i) < SSM_SIZE);
15344776Sjm22469 if ((ra = va_to_pa(
15354776Sjm22469 (void *)(soft_state_message_strings + i))) == -1ll) {
15363266Sjb145095 return;
15373266Sjb145095 }
15383266Sjb145095 soft_state_message_ra[i] = ra;
15393266Sjb145095 }
15403266Sjb145095 /*
15413266Sjb145095 * Tell OBP that we are supporting Guest State
15423266Sjb145095 */
15433266Sjb145095 prom_sun4v_soft_state_supported();
15443266Sjb145095 soft_state_initialized = 1;
15453266Sjb145095 }
15463266Sjb145095
15473266Sjb145095 void
mach_set_soft_state(uint64_t state,uint64_t * string_ra)15483266Sjb145095 mach_set_soft_state(uint64_t state, uint64_t *string_ra)
15493266Sjb145095 {
15503266Sjb145095 uint64_t rc;
15513266Sjb145095
15523266Sjb145095 if (soft_state_initialized && *string_ra) {
15533266Sjb145095 rc = hv_soft_state_set(state, *string_ra);
15543266Sjb145095 if (rc != H_EOK) {
15555146Ssvemuri cmn_err(CE_WARN,
15565146Ssvemuri "hv_soft_state_set returned %ld\n", rc);
15573266Sjb145095 }
15583266Sjb145095 }
15593266Sjb145095 }
15603266Sjb145095
15613266Sjb145095 void
mach_get_soft_state(uint64_t * state,uint64_t * string_ra)15623266Sjb145095 mach_get_soft_state(uint64_t *state, uint64_t *string_ra)
15633266Sjb145095 {
15644776Sjm22469 uint64_t rc;
15653266Sjb145095
15663266Sjb145095 if (soft_state_initialized && *string_ra) {
15673266Sjb145095 rc = hv_soft_state_get(*string_ra, state);
15683266Sjb145095 if (rc != H_EOK) {
15695146Ssvemuri cmn_err(CE_WARN,
15705146Ssvemuri "hv_soft_state_get returned %ld\n", rc);
15713266Sjb145095 *state = -1;
15723266Sjb145095 }
15733266Sjb145095 }
15743266Sjb145095 }
1575