xref: /titanic_51/usr/src/uts/i86pc/os/machdep.c (revision a31148363f598def767ac48c5d82e1572e44b935)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5fea9cb91Slq150181  * Common Development and Distribution License (the "License").
6fea9cb91Slq150181  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21fea9cb91Slq150181 
227c478bd9Sstevel@tonic-gate /*
2356f33205SJonathan Adams  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
26*a3114836SGerry Liu /*
27*a3114836SGerry Liu  * Copyright (c) 2010, Intel Corporation.
28*a3114836SGerry Liu  * All rights reserved.
29*a3114836SGerry Liu  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
337c478bd9Sstevel@tonic-gate #include <sys/param.h>
34ddece0baSsethg #include <sys/segments.h>
357c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
367c478bd9Sstevel@tonic-gate #include <sys/signal.h>
377c478bd9Sstevel@tonic-gate #include <sys/systm.h>
387c478bd9Sstevel@tonic-gate #include <sys/user.h>
397c478bd9Sstevel@tonic-gate #include <sys/mman.h>
407c478bd9Sstevel@tonic-gate #include <sys/vm.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include <sys/disp.h>
437c478bd9Sstevel@tonic-gate #include <sys/class.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #include <sys/proc.h>
467c478bd9Sstevel@tonic-gate #include <sys/buf.h>
477c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #include <sys/reboot.h>
507c478bd9Sstevel@tonic-gate #include <sys/uadmin.h>
517c478bd9Sstevel@tonic-gate #include <sys/callb.h>
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #include <sys/cred.h>
547c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
557c478bd9Sstevel@tonic-gate #include <sys/file.h>
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #include <sys/procfs.h>
587c478bd9Sstevel@tonic-gate #include <sys/acct.h>
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
617c478bd9Sstevel@tonic-gate #include <sys/dnlc.h>
627c478bd9Sstevel@tonic-gate #include <sys/var.h>
637c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
647c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
657c478bd9Sstevel@tonic-gate #include <sys/debug.h>
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #include <sys/dumphdr.h>
687c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
697c478bd9Sstevel@tonic-gate #include <sys/varargs.h>
707c478bd9Sstevel@tonic-gate #include <sys/promif.h>
717c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #include <sys/consdev.h>
747c478bd9Sstevel@tonic-gate #include <sys/frame.h>
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
777c478bd9Sstevel@tonic-gate #include <sys/ddidmareq.h>
787c478bd9Sstevel@tonic-gate #include <sys/psw.h>
797c478bd9Sstevel@tonic-gate #include <sys/regset.h>
807c478bd9Sstevel@tonic-gate #include <sys/privregs.h>
817c478bd9Sstevel@tonic-gate #include <sys/clock.h>
827c478bd9Sstevel@tonic-gate #include <sys/tss.h>
837c478bd9Sstevel@tonic-gate #include <sys/cpu.h>
847c478bd9Sstevel@tonic-gate #include <sys/stack.h>
857c478bd9Sstevel@tonic-gate #include <sys/trap.h>
867c478bd9Sstevel@tonic-gate #include <sys/pic.h>
877c478bd9Sstevel@tonic-gate #include <vm/hat.h>
887c478bd9Sstevel@tonic-gate #include <vm/anon.h>
897c478bd9Sstevel@tonic-gate #include <vm/as.h>
907c478bd9Sstevel@tonic-gate #include <vm/page.h>
917c478bd9Sstevel@tonic-gate #include <vm/seg.h>
927c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h>
937c478bd9Sstevel@tonic-gate #include <vm/seg_map.h>
947c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h>
957c478bd9Sstevel@tonic-gate #include <vm/seg_kp.h>
967c478bd9Sstevel@tonic-gate #include <vm/hat_i86.h>
977c478bd9Sstevel@tonic-gate #include <sys/swap.h>
987c478bd9Sstevel@tonic-gate #include <sys/thread.h>
997c478bd9Sstevel@tonic-gate #include <sys/sysconf.h>
1007c478bd9Sstevel@tonic-gate #include <sys/vm_machparam.h>
1017c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
1027c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
1037c478bd9Sstevel@tonic-gate #include <sys/machlock.h>
1047c478bd9Sstevel@tonic-gate #include <sys/x_call.h>
1057c478bd9Sstevel@tonic-gate #include <sys/instance.h>
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #include <sys/time.h>
1087c478bd9Sstevel@tonic-gate #include <sys/smp_impldefs.h>
1097c478bd9Sstevel@tonic-gate #include <sys/psm_types.h>
1107c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
1117c478bd9Sstevel@tonic-gate #include <sys/panic.h>
1127c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
1137c478bd9Sstevel@tonic-gate #include <sys/dtrace.h>
1147c478bd9Sstevel@tonic-gate #include <sys/bl.h>
1157c478bd9Sstevel@tonic-gate #include <sys/nvpair.h>
1167c478bd9Sstevel@tonic-gate #include <sys/x86_archext.h>
1177c478bd9Sstevel@tonic-gate #include <sys/pool_pset.h>
1187c478bd9Sstevel@tonic-gate #include <sys/autoconf.h>
119ae115bc7Smrj #include <sys/mem.h>
120ae115bc7Smrj #include <sys/dumphdr.h>
121ae115bc7Smrj #include <sys/compress.h>
122e4b86885SCheng Sean Ye #include <sys/cpu_module.h>
123843e1988Sjohnlev #if defined(__xpv)
124843e1988Sjohnlev #include <sys/hypervisor.h>
125843e1988Sjohnlev #include <sys/xpv_panic.h>
126843e1988Sjohnlev #endif
1277c478bd9Sstevel@tonic-gate 
12819397407SSherry Moore #include <sys/fastboot.h>
12919397407SSherry Moore #include <sys/machelf.h>
13019397407SSherry Moore #include <sys/kobj.h>
13119397407SSherry Moore #include <sys/multiboot.h>
13219397407SSherry Moore 
1337c478bd9Sstevel@tonic-gate #ifdef	TRAPTRACE
1347c478bd9Sstevel@tonic-gate #include <sys/traptrace.h>
1357c478bd9Sstevel@tonic-gate #endif	/* TRAPTRACE */
1367c478bd9Sstevel@tonic-gate 
137005d3febSMarek Pospisil #include <c2/audit.h>
138d3d50737SRafael Vanoni #include <sys/clock_impl.h>
139d3d50737SRafael Vanoni 
1407c478bd9Sstevel@tonic-gate extern void audit_enterprom(int);
1417c478bd9Sstevel@tonic-gate extern void audit_exitprom(int);
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate /*
144c48ac12eSjohnlev  * Occassionally the kernel knows better whether to power-off or reboot.
145c48ac12eSjohnlev  */
146c48ac12eSjohnlev int force_shutdown_method = AD_UNKNOWN;
147c48ac12eSjohnlev 
148c48ac12eSjohnlev /*
1497c478bd9Sstevel@tonic-gate  * The panicbuf array is used to record messages and state:
1507c478bd9Sstevel@tonic-gate  */
1517c478bd9Sstevel@tonic-gate char panicbuf[PANICBUFSIZE];
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*
154*a3114836SGerry Liu  * Flags to control Dynamic Reconfiguration features.
155*a3114836SGerry Liu  */
156*a3114836SGerry Liu uint64_t plat_dr_options;
157*a3114836SGerry Liu 
158*a3114836SGerry Liu /*
159*a3114836SGerry Liu  * Maximum physical address for memory DR operations.
160*a3114836SGerry Liu  */
161*a3114836SGerry Liu uint64_t plat_dr_physmax;
162*a3114836SGerry Liu 
163*a3114836SGerry Liu /*
1647c478bd9Sstevel@tonic-gate  * maxphys - used during physio
1657c478bd9Sstevel@tonic-gate  * klustsize - used for klustering by swapfs and specfs
1667c478bd9Sstevel@tonic-gate  */
1677c478bd9Sstevel@tonic-gate int maxphys = 56 * 1024;    /* XXX See vm_subr.c - max b_count in physio */
1687c478bd9Sstevel@tonic-gate int klustsize = 56 * 1024;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate caddr_t	p0_va;		/* Virtual address for accessing physical page 0 */
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate /*
1737c478bd9Sstevel@tonic-gate  * defined here, though unused on x86,
1747c478bd9Sstevel@tonic-gate  * to make kstat_fr.c happy.
1757c478bd9Sstevel@tonic-gate  */
1767c478bd9Sstevel@tonic-gate int vac;
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate void debug_enter(char *);
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate extern void pm_cfb_check_and_powerup(void);
1817c478bd9Sstevel@tonic-gate extern void pm_cfb_rele(void);
1827c478bd9Sstevel@tonic-gate 
18319397407SSherry Moore extern fastboot_info_t newkernel;
18419397407SSherry Moore 
1857c478bd9Sstevel@tonic-gate /*
1867c478bd9Sstevel@tonic-gate  * Machine dependent code to reboot.
1877c478bd9Sstevel@tonic-gate  * "mdep" is interpreted as a character pointer; if non-null, it is a pointer
1887c478bd9Sstevel@tonic-gate  * to a string to be used as the argument string when rebooting.
189edc40228Sachartre  *
190edc40228Sachartre  * "invoke_cb" is a boolean. It is set to true when mdboot() can safely
191edc40228Sachartre  * invoke CB_CL_MDBOOT callbacks before shutting the system down, i.e. when
192edc40228Sachartre  * we are in a normal shutdown sequence (interrupts are not blocked, the
193edc40228Sachartre  * system is not panic'ing or being suspended).
1947c478bd9Sstevel@tonic-gate  */
1957c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1967c478bd9Sstevel@tonic-gate void
197edc40228Sachartre mdboot(int cmd, int fcn, char *mdep, boolean_t invoke_cb)
1987c478bd9Sstevel@tonic-gate {
19919397407SSherry Moore 	processorid_t bootcpuid = 0;
2006e5965bbSSherry Moore 	static int is_first_quiesce = 1;
2016e5965bbSSherry Moore 	static int is_first_reset = 1;
2026e5965bbSSherry Moore 	int reset_status = 0;
203753a6d45SSherry Moore 	static char fallback_str[] = "Falling back to regular reboot.\n";
20419397407SSherry Moore 
20519397407SSherry Moore 	if (fcn == AD_FASTREBOOT && !newkernel.fi_valid)
20619397407SSherry Moore 		fcn = AD_BOOT;
20719397407SSherry Moore 
2087c478bd9Sstevel@tonic-gate 	if (!panicstr) {
2097c478bd9Sstevel@tonic-gate 		kpreempt_disable();
21019397407SSherry Moore 		if (fcn == AD_FASTREBOOT) {
21119397407SSherry Moore 			mutex_enter(&cpu_lock);
21219397407SSherry Moore 			if (CPU_ACTIVE(cpu_get(bootcpuid))) {
21319397407SSherry Moore 				affinity_set(bootcpuid);
21419397407SSherry Moore 			}
21519397407SSherry Moore 			mutex_exit(&cpu_lock);
21619397407SSherry Moore 		} else {
217d90554ebSdmick 			affinity_set(CPU_CURRENT);
2187c478bd9Sstevel@tonic-gate 		}
21919397407SSherry Moore 	}
2207c478bd9Sstevel@tonic-gate 
221c48ac12eSjohnlev 	if (force_shutdown_method != AD_UNKNOWN)
222c48ac12eSjohnlev 		fcn = force_shutdown_method;
223c48ac12eSjohnlev 
2247c478bd9Sstevel@tonic-gate 	/*
225281888b3Sjbeck 	 * XXX - rconsvp is set to NULL to ensure that output messages
226281888b3Sjbeck 	 * are sent to the underlying "hardware" device using the
227281888b3Sjbeck 	 * monitor's printf routine since we are in the process of
228281888b3Sjbeck 	 * either rebooting or halting the machine.
229281888b3Sjbeck 	 */
230281888b3Sjbeck 	rconsvp = NULL;
231281888b3Sjbeck 
232281888b3Sjbeck 	/*
2337c478bd9Sstevel@tonic-gate 	 * Print the reboot message now, before pausing other cpus.
2347c478bd9Sstevel@tonic-gate 	 * There is a race condition in the printing support that
2357c478bd9Sstevel@tonic-gate 	 * can deadlock multiprocessor machines.
2367c478bd9Sstevel@tonic-gate 	 */
2377c478bd9Sstevel@tonic-gate 	if (!(fcn == AD_HALT || fcn == AD_POWEROFF))
2387c478bd9Sstevel@tonic-gate 		prom_printf("rebooting...\n");
2397c478bd9Sstevel@tonic-gate 
240843e1988Sjohnlev 	if (IN_XPV_PANIC())
241843e1988Sjohnlev 		reset();
242843e1988Sjohnlev 
2437c478bd9Sstevel@tonic-gate 	/*
2447c478bd9Sstevel@tonic-gate 	 * We can't bring up the console from above lock level, so do it now
2457c478bd9Sstevel@tonic-gate 	 */
2467c478bd9Sstevel@tonic-gate 	pm_cfb_check_and_powerup();
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	/* make sure there are no more changes to the device tree */
2497c478bd9Sstevel@tonic-gate 	devtree_freeze();
2507c478bd9Sstevel@tonic-gate 
251edc40228Sachartre 	if (invoke_cb)
252edc40228Sachartre 		(void) callb_execute_class(CB_CL_MDBOOT, NULL);
253edc40228Sachartre 
2548b464eb8Smec 	/*
2558b464eb8Smec 	 * Clear any unresolved UEs from memory.
2568b464eb8Smec 	 */
2578b464eb8Smec 	page_retire_mdboot();
258db874c57Selowe 
259843e1988Sjohnlev #if defined(__xpv)
260843e1988Sjohnlev 	/*
261843e1988Sjohnlev 	 * XXPV	Should probably think some more about how we deal
262843e1988Sjohnlev 	 *	with panicing before it's really safe to panic.
263843e1988Sjohnlev 	 *	On hypervisors, we reboot very quickly..  Perhaps panic
264843e1988Sjohnlev 	 *	should only attempt to recover by rebooting if,
265843e1988Sjohnlev 	 *	say, we were able to mount the root filesystem,
266843e1988Sjohnlev 	 *	or if we successfully launched init(1m).
267843e1988Sjohnlev 	 */
268843e1988Sjohnlev 	if (panicstr && proc_init == NULL)
269843e1988Sjohnlev 		(void) HYPERVISOR_shutdown(SHUTDOWN_poweroff);
270843e1988Sjohnlev #endif
2717c478bd9Sstevel@tonic-gate 	/*
2727c478bd9Sstevel@tonic-gate 	 * stop other cpus and raise our priority.  since there is only
2737c478bd9Sstevel@tonic-gate 	 * one active cpu after this, and our priority will be too high
2747c478bd9Sstevel@tonic-gate 	 * for us to be preempted, we're essentially single threaded
2757c478bd9Sstevel@tonic-gate 	 * from here on out.
2767c478bd9Sstevel@tonic-gate 	 */
2777c478bd9Sstevel@tonic-gate 	(void) spl6();
2787c478bd9Sstevel@tonic-gate 	if (!panicstr) {
2797c478bd9Sstevel@tonic-gate 		mutex_enter(&cpu_lock);
2807c478bd9Sstevel@tonic-gate 		pause_cpus(NULL);
2817c478bd9Sstevel@tonic-gate 		mutex_exit(&cpu_lock);
2827c478bd9Sstevel@tonic-gate 	}
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	/*
285835b9930SSherry Moore 	 * If the system is panicking, the preloaded kernel is valid, and
286835b9930SSherry Moore 	 * fastreboot_onpanic has been set, and the system has been up for
287835b9930SSherry Moore 	 * longer than fastreboot_onpanic_uptime (default to 10 minutes),
288835b9930SSherry Moore 	 * choose Fast Reboot.
289753a6d45SSherry Moore 	 */
290753a6d45SSherry Moore 	if (fcn == AD_BOOT && panicstr && newkernel.fi_valid &&
291835b9930SSherry Moore 	    fastreboot_onpanic &&
292835b9930SSherry Moore 	    (panic_lbolt - lbolt_at_boot) > fastreboot_onpanic_uptime) {
293753a6d45SSherry Moore 		fcn = AD_FASTREBOOT;
294835b9930SSherry Moore 	}
295753a6d45SSherry Moore 
296753a6d45SSherry Moore 	/*
29719397407SSherry Moore 	 * Try to quiesce devices.
2987c478bd9Sstevel@tonic-gate 	 */
2996e5965bbSSherry Moore 	if (is_first_quiesce) {
3006e5965bbSSherry Moore 		/*
3016e5965bbSSherry Moore 		 * Clear is_first_quiesce before calling quiesce_devices()
3026e5965bbSSherry Moore 		 * so that if quiesce_devices() causes panics, it will not
3036e5965bbSSherry Moore 		 * be invoked again.
3046e5965bbSSherry Moore 		 */
3056e5965bbSSherry Moore 		is_first_quiesce = 0;
30619397407SSherry Moore 
30719397407SSherry Moore 		quiesce_active = 1;
30819397407SSherry Moore 		quiesce_devices(ddi_root_node(), &reset_status);
309abe65fd9SSherry Moore 		if (reset_status == -1) {
310abe65fd9SSherry Moore 			if (fcn == AD_FASTREBOOT && !force_fastreboot) {
311abe65fd9SSherry Moore 				prom_printf("Driver(s) not capable of fast "
312753a6d45SSherry Moore 				    "reboot.\n");
313753a6d45SSherry Moore 				prom_printf(fallback_str);
314abe65fd9SSherry Moore 				fastreboot_capable = 0;
315753a6d45SSherry Moore 				fcn = AD_BOOT;
316abe65fd9SSherry Moore 			} else if (fcn != AD_FASTREBOOT)
31719397407SSherry Moore 				fastreboot_capable = 0;
31819397407SSherry Moore 		}
31919397407SSherry Moore 		quiesce_active = 0;
32019397407SSherry Moore 	}
32119397407SSherry Moore 
32219397407SSherry Moore 	/*
3236e5965bbSSherry Moore 	 * Try to reset devices. reset_leaves() should only be called
3246e5965bbSSherry Moore 	 * a) when there are no other threads that could be accessing devices,
3256e5965bbSSherry Moore 	 *    and
3266e5965bbSSherry Moore 	 * b) on a system that's not capable of fast reboot (fastreboot_capable
3276e5965bbSSherry Moore 	 *    being 0), or on a system where quiesce_devices() failed to
3286e5965bbSSherry Moore 	 *    complete (quiesce_active being 1).
32919397407SSherry Moore 	 */
3306e5965bbSSherry Moore 	if (is_first_reset && (!fastreboot_capable || quiesce_active)) {
3316e5965bbSSherry Moore 		/*
3326e5965bbSSherry Moore 		 * Clear is_first_reset before calling reset_devices()
3336e5965bbSSherry Moore 		 * so that if reset_devices() causes panics, it will not
3346e5965bbSSherry Moore 		 * be invoked again.
3356e5965bbSSherry Moore 		 */
3366e5965bbSSherry Moore 		is_first_reset = 0;
3377c478bd9Sstevel@tonic-gate 		reset_leaves();
3386e5965bbSSherry Moore 	}
3397c478bd9Sstevel@tonic-gate 
340753a6d45SSherry Moore 	/* Verify newkernel checksum */
341753a6d45SSherry Moore 	if (fastreboot_capable && fcn == AD_FASTREBOOT &&
342753a6d45SSherry Moore 	    fastboot_cksum_verify(&newkernel) != 0) {
343753a6d45SSherry Moore 		fastreboot_capable = 0;
344753a6d45SSherry Moore 		prom_printf("Fast reboot: checksum failed for the new "
345753a6d45SSherry Moore 		    "kernel.\n");
346753a6d45SSherry Moore 		prom_printf(fallback_str);
347753a6d45SSherry Moore 	}
348753a6d45SSherry Moore 
3497c478bd9Sstevel@tonic-gate 	(void) spl8();
350753a6d45SSherry Moore 
351753a6d45SSherry Moore 	if (fastreboot_capable && fcn == AD_FASTREBOOT) {
352753a6d45SSherry Moore 		/*
353753a6d45SSherry Moore 		 * psm_shutdown is called within fast_reboot()
354753a6d45SSherry Moore 		 */
355753a6d45SSherry Moore 		fast_reboot();
356753a6d45SSherry Moore 	} else {
3577c478bd9Sstevel@tonic-gate 		(*psm_shutdownf)(cmd, fcn);
3587c478bd9Sstevel@tonic-gate 
359753a6d45SSherry Moore 		if (fcn == AD_HALT || fcn == AD_POWEROFF)
3607c478bd9Sstevel@tonic-gate 			halt((char *)NULL);
3617c478bd9Sstevel@tonic-gate 		else
3627c478bd9Sstevel@tonic-gate 			prom_reboot("");
363753a6d45SSherry Moore 	}
3647c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
3657c478bd9Sstevel@tonic-gate }
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate /* mdpreboot - may be called prior to mdboot while root fs still mounted */
3687c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3697c478bd9Sstevel@tonic-gate void
3707c478bd9Sstevel@tonic-gate mdpreboot(int cmd, int fcn, char *mdep)
3717c478bd9Sstevel@tonic-gate {
37219397407SSherry Moore 	if (fcn == AD_FASTREBOOT && !fastreboot_capable) {
37319397407SSherry Moore 		fcn = AD_BOOT;
37419397407SSherry Moore #ifdef	__xpv
375753a6d45SSherry Moore 		cmn_err(CE_WARN, "Fast reboot is not supported on xVM");
37619397407SSherry Moore #else
377753a6d45SSherry Moore 		cmn_err(CE_WARN,
3785ee8e422SKonstantin Ananyev 		    "Fast reboot is not supported on this platform%s",
3795ee8e422SKonstantin Ananyev 		    fastreboot_nosup_message());
38019397407SSherry Moore #endif
38119397407SSherry Moore 	}
38219397407SSherry Moore 
38319397407SSherry Moore 	if (fcn == AD_FASTREBOOT) {
384753a6d45SSherry Moore 		fastboot_load_kernel(mdep);
38519397407SSherry Moore 		if (!newkernel.fi_valid)
38619397407SSherry Moore 			fcn = AD_BOOT;
38719397407SSherry Moore 	}
38819397407SSherry Moore 
3897c478bd9Sstevel@tonic-gate 	(*psm_preshutdownf)(cmd, fcn);
3907c478bd9Sstevel@tonic-gate }
3917c478bd9Sstevel@tonic-gate 
392f34a7178SJoe Bonasera static void
393f34a7178SJoe Bonasera stop_other_cpus(void)
3947c478bd9Sstevel@tonic-gate {
395f34a7178SJoe Bonasera 	ulong_t s = clear_int_flag(); /* fast way to keep CPU from changing */
3967c478bd9Sstevel@tonic-gate 	cpuset_t xcset;
3977c478bd9Sstevel@tonic-gate 
398f34a7178SJoe Bonasera 	CPUSET_ALL_BUT(xcset, CPU->cpu_id);
399f34a7178SJoe Bonasera 	xc_priority(0, 0, 0, CPUSET2BV(xcset), (xc_func_t)mach_cpu_halt);
400f34a7178SJoe Bonasera 	restore_int_flag(s);
4017c478bd9Sstevel@tonic-gate }
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate /*
4047c478bd9Sstevel@tonic-gate  *	Machine dependent abort sequence handling
4057c478bd9Sstevel@tonic-gate  */
4067c478bd9Sstevel@tonic-gate void
4077c478bd9Sstevel@tonic-gate abort_sequence_enter(char *msg)
4087c478bd9Sstevel@tonic-gate {
4097c478bd9Sstevel@tonic-gate 	if (abort_enable == 0) {
410005d3febSMarek Pospisil 		if (AU_ZONE_AUDITING(GET_KCTX_GZ))
4117c478bd9Sstevel@tonic-gate 			audit_enterprom(0);
4127c478bd9Sstevel@tonic-gate 		return;
4137c478bd9Sstevel@tonic-gate 	}
414005d3febSMarek Pospisil 	if (AU_ZONE_AUDITING(GET_KCTX_GZ))
4157c478bd9Sstevel@tonic-gate 		audit_enterprom(1);
4167c478bd9Sstevel@tonic-gate 	debug_enter(msg);
417005d3febSMarek Pospisil 	if (AU_ZONE_AUDITING(GET_KCTX_GZ))
4187c478bd9Sstevel@tonic-gate 		audit_exitprom(1);
4197c478bd9Sstevel@tonic-gate }
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate /*
4227c478bd9Sstevel@tonic-gate  * Enter debugger.  Called when the user types ctrl-alt-d or whenever
4237c478bd9Sstevel@tonic-gate  * code wants to enter the debugger and possibly resume later.
4247c478bd9Sstevel@tonic-gate  */
4257c478bd9Sstevel@tonic-gate void
4267c478bd9Sstevel@tonic-gate debug_enter(
4277c478bd9Sstevel@tonic-gate 	char	*msg)		/* message to print, possibly NULL */
4287c478bd9Sstevel@tonic-gate {
4297c478bd9Sstevel@tonic-gate 	if (dtrace_debugger_init != NULL)
4307c478bd9Sstevel@tonic-gate 		(*dtrace_debugger_init)();
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate 	if (msg)
4337c478bd9Sstevel@tonic-gate 		prom_printf("%s\n", msg);
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate 	if (boothowto & RB_DEBUG)
436ae115bc7Smrj 		kmdb_enter();
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate 	if (dtrace_debugger_fini != NULL)
4397c478bd9Sstevel@tonic-gate 		(*dtrace_debugger_fini)();
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate void
4437c478bd9Sstevel@tonic-gate reset(void)
4447c478bd9Sstevel@tonic-gate {
4454cf02d40SSaurabh Misra 	extern	void acpi_reset_system();
446843e1988Sjohnlev #if !defined(__xpv)
4477c478bd9Sstevel@tonic-gate 	ushort_t *bios_memchk;
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate 	/*
4504cf02d40SSaurabh Misra 	 * Can't use psm_map_phys or acpi_reset_system before the hat is
4514cf02d40SSaurabh Misra 	 * initialized.
4527c478bd9Sstevel@tonic-gate 	 */
4537c478bd9Sstevel@tonic-gate 	if (khat_running) {
4547c478bd9Sstevel@tonic-gate 		bios_memchk = (ushort_t *)psm_map_phys(0x472,
4557c478bd9Sstevel@tonic-gate 		    sizeof (ushort_t), PROT_READ | PROT_WRITE);
4567c478bd9Sstevel@tonic-gate 		if (bios_memchk)
4577c478bd9Sstevel@tonic-gate 			*bios_memchk = 0x1234;	/* bios memory check disable */
4584cf02d40SSaurabh Misra 
4594cf02d40SSaurabh Misra 		if (options_dip != NULL &&
4604cf02d40SSaurabh Misra 		    ddi_prop_exists(DDI_DEV_T_ANY, ddi_root_node(), 0,
4614cf02d40SSaurabh Misra 		    "efi-systab")) {
4624cf02d40SSaurabh Misra 			efi_reset();
4637c478bd9Sstevel@tonic-gate 		}
4647c478bd9Sstevel@tonic-gate 
4654cf02d40SSaurabh Misra 		/*
4664cf02d40SSaurabh Misra 		 * The problem with using stubs is that we can call
4674cf02d40SSaurabh Misra 		 * acpi_reset_system only after the kernel is up and running.
4684cf02d40SSaurabh Misra 		 *
4694cf02d40SSaurabh Misra 		 * We should create a global state to keep track of how far
4704cf02d40SSaurabh Misra 		 * up the kernel is but for the time being we will depend on
4714cf02d40SSaurabh Misra 		 * bootops. bootops cleared in startup_end().
4724cf02d40SSaurabh Misra 		 */
4734cf02d40SSaurabh Misra 		if (bootops == NULL)
4744cf02d40SSaurabh Misra 			acpi_reset_system();
4754cf02d40SSaurabh Misra 	}
4764cf02d40SSaurabh Misra 
4777c478bd9Sstevel@tonic-gate 	pc_reset();
478843e1988Sjohnlev #else
4794cf02d40SSaurabh Misra 	if (IN_XPV_PANIC()) {
4804cf02d40SSaurabh Misra 		if (khat_running && bootops == NULL) {
4814cf02d40SSaurabh Misra 			acpi_reset_system();
4824cf02d40SSaurabh Misra 		}
4834cf02d40SSaurabh Misra 
484843e1988Sjohnlev 		pc_reset();
4854cf02d40SSaurabh Misra 	}
4864cf02d40SSaurabh Misra 
487843e1988Sjohnlev 	(void) HYPERVISOR_shutdown(SHUTDOWN_reboot);
488843e1988Sjohnlev 	panic("HYPERVISOR_shutdown() failed");
489843e1988Sjohnlev #endif
4907c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
4917c478bd9Sstevel@tonic-gate }
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate /*
4947c478bd9Sstevel@tonic-gate  * Halt the machine and return to the monitor
4957c478bd9Sstevel@tonic-gate  */
4967c478bd9Sstevel@tonic-gate void
4977c478bd9Sstevel@tonic-gate halt(char *s)
4987c478bd9Sstevel@tonic-gate {
4997c478bd9Sstevel@tonic-gate 	stop_other_cpus();	/* send stop signal to other CPUs */
5007c478bd9Sstevel@tonic-gate 	if (s)
5017c478bd9Sstevel@tonic-gate 		prom_printf("(%s) \n", s);
5027c478bd9Sstevel@tonic-gate 	prom_exit_to_mon();
5037c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
5047c478bd9Sstevel@tonic-gate }
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate /*
5077c478bd9Sstevel@tonic-gate  * Initiate interrupt redistribution.
5087c478bd9Sstevel@tonic-gate  */
5097c478bd9Sstevel@tonic-gate void
5107c478bd9Sstevel@tonic-gate i_ddi_intr_redist_all_cpus()
5117c478bd9Sstevel@tonic-gate {
5127c478bd9Sstevel@tonic-gate }
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate /*
5157c478bd9Sstevel@tonic-gate  * XXX These probably ought to live somewhere else
5167c478bd9Sstevel@tonic-gate  * XXX They are called from mem.c
5177c478bd9Sstevel@tonic-gate  */
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate /*
5207c478bd9Sstevel@tonic-gate  * Convert page frame number to an OBMEM page frame number
5217c478bd9Sstevel@tonic-gate  * (i.e. put in the type bits -- zero for this implementation)
5227c478bd9Sstevel@tonic-gate  */
5237c478bd9Sstevel@tonic-gate pfn_t
5247c478bd9Sstevel@tonic-gate impl_obmem_pfnum(pfn_t pf)
5257c478bd9Sstevel@tonic-gate {
5267c478bd9Sstevel@tonic-gate 	return (pf);
5277c478bd9Sstevel@tonic-gate }
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate #ifdef	NM_DEBUG
5307c478bd9Sstevel@tonic-gate int nmi_test = 0;	/* checked in intentry.s during clock int */
5317c478bd9Sstevel@tonic-gate int nmtest = -1;
5327c478bd9Sstevel@tonic-gate nmfunc1(arg, rp)
5337c478bd9Sstevel@tonic-gate int	arg;
5347c478bd9Sstevel@tonic-gate struct regs *rp;
5357c478bd9Sstevel@tonic-gate {
5367c478bd9Sstevel@tonic-gate 	printf("nmi called with arg = %x, regs = %x\n", arg, rp);
5377c478bd9Sstevel@tonic-gate 	nmtest += 50;
5387c478bd9Sstevel@tonic-gate 	if (arg == nmtest) {
5397c478bd9Sstevel@tonic-gate 		printf("ip = %x\n", rp->r_pc);
5407c478bd9Sstevel@tonic-gate 		return (1);
5417c478bd9Sstevel@tonic-gate 	}
5427c478bd9Sstevel@tonic-gate 	return (0);
5437c478bd9Sstevel@tonic-gate }
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate #endif
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate #include <sys/bootsvcs.h>
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate /* Hacked up initialization for initial kernel check out is HERE. */
5507c478bd9Sstevel@tonic-gate /* The basic steps are: */
5517c478bd9Sstevel@tonic-gate /*	kernel bootfuncs definition/initialization for KADB */
5527c478bd9Sstevel@tonic-gate /*	kadb bootfuncs pointer initialization */
5537c478bd9Sstevel@tonic-gate /*	putchar/getchar (interrupts disabled) */
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate /* kadb bootfuncs pointer initialization */
5567c478bd9Sstevel@tonic-gate 
5577c478bd9Sstevel@tonic-gate int
5587c478bd9Sstevel@tonic-gate sysp_getchar()
5597c478bd9Sstevel@tonic-gate {
5607c478bd9Sstevel@tonic-gate 	int i;
561ae115bc7Smrj 	ulong_t s;
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate 	if (cons_polledio == NULL) {
5647c478bd9Sstevel@tonic-gate 		/* Uh oh */
5657c478bd9Sstevel@tonic-gate 		prom_printf("getchar called with no console\n");
5667c478bd9Sstevel@tonic-gate 		for (;;)
5677c478bd9Sstevel@tonic-gate 			/* LOOP FOREVER */;
5687c478bd9Sstevel@tonic-gate 	}
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate 	s = clear_int_flag();
5717c478bd9Sstevel@tonic-gate 	i = cons_polledio->cons_polledio_getchar(
5727c478bd9Sstevel@tonic-gate 	    cons_polledio->cons_polledio_argument);
5737c478bd9Sstevel@tonic-gate 	restore_int_flag(s);
5747c478bd9Sstevel@tonic-gate 	return (i);
5757c478bd9Sstevel@tonic-gate }
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate void
5787c478bd9Sstevel@tonic-gate sysp_putchar(int c)
5797c478bd9Sstevel@tonic-gate {
580ae115bc7Smrj 	ulong_t s;
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate 	/*
5837c478bd9Sstevel@tonic-gate 	 * We have no alternative but to drop the output on the floor.
5847c478bd9Sstevel@tonic-gate 	 */
585fea9cb91Slq150181 	if (cons_polledio == NULL ||
586fea9cb91Slq150181 	    cons_polledio->cons_polledio_putchar == NULL)
5877c478bd9Sstevel@tonic-gate 		return;
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate 	s = clear_int_flag();
5907c478bd9Sstevel@tonic-gate 	cons_polledio->cons_polledio_putchar(
5917c478bd9Sstevel@tonic-gate 	    cons_polledio->cons_polledio_argument, c);
5927c478bd9Sstevel@tonic-gate 	restore_int_flag(s);
5937c478bd9Sstevel@tonic-gate }
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate int
5967c478bd9Sstevel@tonic-gate sysp_ischar()
5977c478bd9Sstevel@tonic-gate {
5987c478bd9Sstevel@tonic-gate 	int i;
599ae115bc7Smrj 	ulong_t s;
6007c478bd9Sstevel@tonic-gate 
601fea9cb91Slq150181 	if (cons_polledio == NULL ||
602fea9cb91Slq150181 	    cons_polledio->cons_polledio_ischar == NULL)
6037c478bd9Sstevel@tonic-gate 		return (0);
6047c478bd9Sstevel@tonic-gate 
6057c478bd9Sstevel@tonic-gate 	s = clear_int_flag();
6067c478bd9Sstevel@tonic-gate 	i = cons_polledio->cons_polledio_ischar(
6077c478bd9Sstevel@tonic-gate 	    cons_polledio->cons_polledio_argument);
6087c478bd9Sstevel@tonic-gate 	restore_int_flag(s);
6097c478bd9Sstevel@tonic-gate 	return (i);
6107c478bd9Sstevel@tonic-gate }
6117c478bd9Sstevel@tonic-gate 
6127c478bd9Sstevel@tonic-gate int
6137c478bd9Sstevel@tonic-gate goany(void)
6147c478bd9Sstevel@tonic-gate {
6157c478bd9Sstevel@tonic-gate 	prom_printf("Type any key to continue ");
6167c478bd9Sstevel@tonic-gate 	(void) prom_getchar();
6177c478bd9Sstevel@tonic-gate 	prom_printf("\n");
6187c478bd9Sstevel@tonic-gate 	return (1);
6197c478bd9Sstevel@tonic-gate }
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate static struct boot_syscalls kern_sysp = {
6227c478bd9Sstevel@tonic-gate 	sysp_getchar,	/*	unchar	(*getchar)();	7  */
6237c478bd9Sstevel@tonic-gate 	sysp_putchar,	/*	int	(*putchar)();	8  */
6247c478bd9Sstevel@tonic-gate 	sysp_ischar,	/*	int	(*ischar)();	9  */
6257c478bd9Sstevel@tonic-gate };
6267c478bd9Sstevel@tonic-gate 
627843e1988Sjohnlev #if defined(__xpv)
628843e1988Sjohnlev int using_kern_polledio;
629843e1988Sjohnlev #endif
630843e1988Sjohnlev 
6317c478bd9Sstevel@tonic-gate void
6327c478bd9Sstevel@tonic-gate kadb_uses_kernel()
6337c478bd9Sstevel@tonic-gate {
6347c478bd9Sstevel@tonic-gate 	/*
6357c478bd9Sstevel@tonic-gate 	 * This routine is now totally misnamed, since it does not in fact
6367c478bd9Sstevel@tonic-gate 	 * control kadb's I/O; it only controls the kernel's prom_* I/O.
6377c478bd9Sstevel@tonic-gate 	 */
6387c478bd9Sstevel@tonic-gate 	sysp = &kern_sysp;
639843e1988Sjohnlev #if defined(__xpv)
640843e1988Sjohnlev 	using_kern_polledio = 1;
641843e1988Sjohnlev #endif
6427c478bd9Sstevel@tonic-gate }
6437c478bd9Sstevel@tonic-gate 
6447c478bd9Sstevel@tonic-gate /*
6457c478bd9Sstevel@tonic-gate  *	the interface to the outside world
6467c478bd9Sstevel@tonic-gate  */
6477c478bd9Sstevel@tonic-gate 
6487c478bd9Sstevel@tonic-gate /*
6497c478bd9Sstevel@tonic-gate  * poll_port -- wait for a register to achieve a
6507c478bd9Sstevel@tonic-gate  *		specific state.  Arguments are a mask of bits we care about,
6517c478bd9Sstevel@tonic-gate  *		and two sub-masks.  To return normally, all the bits in the
6527c478bd9Sstevel@tonic-gate  *		first sub-mask must be ON, all the bits in the second sub-
6537c478bd9Sstevel@tonic-gate  *		mask must be OFF.  If about seconds pass without the register
6547c478bd9Sstevel@tonic-gate  *		achieving the desired bit configuration, we return 1, else
6557c478bd9Sstevel@tonic-gate  *		0.
6567c478bd9Sstevel@tonic-gate  */
6577c478bd9Sstevel@tonic-gate int
6587c478bd9Sstevel@tonic-gate poll_port(ushort_t port, ushort_t mask, ushort_t onbits, ushort_t offbits)
6597c478bd9Sstevel@tonic-gate {
6607c478bd9Sstevel@tonic-gate 	int i;
6617c478bd9Sstevel@tonic-gate 	ushort_t maskval;
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate 	for (i = 500000; i; i--) {
6647c478bd9Sstevel@tonic-gate 		maskval = inb(port) & mask;
6657c478bd9Sstevel@tonic-gate 		if (((maskval & onbits) == onbits) &&
6667c478bd9Sstevel@tonic-gate 		    ((maskval & offbits) == 0))
6677c478bd9Sstevel@tonic-gate 			return (0);
6687c478bd9Sstevel@tonic-gate 		drv_usecwait(10);
6697c478bd9Sstevel@tonic-gate 	}
6707c478bd9Sstevel@tonic-gate 	return (1);
6717c478bd9Sstevel@tonic-gate }
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate /*
6747c478bd9Sstevel@tonic-gate  * set_idle_cpu is called from idle() when a CPU becomes idle.
6757c478bd9Sstevel@tonic-gate  */
6767c478bd9Sstevel@tonic-gate /*LINTED: static unused */
6777c478bd9Sstevel@tonic-gate static uint_t last_idle_cpu;
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6807c478bd9Sstevel@tonic-gate void
6817c478bd9Sstevel@tonic-gate set_idle_cpu(int cpun)
6827c478bd9Sstevel@tonic-gate {
6837c478bd9Sstevel@tonic-gate 	last_idle_cpu = cpun;
6847c478bd9Sstevel@tonic-gate 	(*psm_set_idle_cpuf)(cpun);
6857c478bd9Sstevel@tonic-gate }
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate /*
6887c478bd9Sstevel@tonic-gate  * unset_idle_cpu is called from idle() when a CPU is no longer idle.
6897c478bd9Sstevel@tonic-gate  */
6907c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6917c478bd9Sstevel@tonic-gate void
6927c478bd9Sstevel@tonic-gate unset_idle_cpu(int cpun)
6937c478bd9Sstevel@tonic-gate {
6947c478bd9Sstevel@tonic-gate 	(*psm_unset_idle_cpuf)(cpun);
6957c478bd9Sstevel@tonic-gate }
6967c478bd9Sstevel@tonic-gate 
6977c478bd9Sstevel@tonic-gate /*
6987c478bd9Sstevel@tonic-gate  * This routine is almost correct now, but not quite.  It still needs the
6997c478bd9Sstevel@tonic-gate  * equivalent concept of "hres_last_tick", just like on the sparc side.
7007c478bd9Sstevel@tonic-gate  * The idea is to take a snapshot of the hi-res timer while doing the
7017c478bd9Sstevel@tonic-gate  * hrestime_adj updates under hres_lock in locore, so that the small
7027c478bd9Sstevel@tonic-gate  * interval between interrupt assertion and interrupt processing is
7037c478bd9Sstevel@tonic-gate  * accounted for correctly.  Once we have this, the code below should
7047c478bd9Sstevel@tonic-gate  * be modified to subtract off hres_last_tick rather than hrtime_base.
7057c478bd9Sstevel@tonic-gate  *
7067c478bd9Sstevel@tonic-gate  * I'd have done this myself, but I don't have source to all of the
7077c478bd9Sstevel@tonic-gate  * vendor-specific hi-res timer routines (grrr...).  The generic hook I
7087c478bd9Sstevel@tonic-gate  * need is something like "gethrtime_unlocked()", which would be just like
7097c478bd9Sstevel@tonic-gate  * gethrtime() but would assume that you're already holding CLOCK_LOCK().
7107c478bd9Sstevel@tonic-gate  * This is what the GET_HRTIME() macro is for on sparc (although it also
7117c478bd9Sstevel@tonic-gate  * serves the function of making time available without a function call
7127c478bd9Sstevel@tonic-gate  * so you don't take a register window overflow while traps are disabled).
7137c478bd9Sstevel@tonic-gate  */
7147c478bd9Sstevel@tonic-gate void
7157c478bd9Sstevel@tonic-gate pc_gethrestime(timestruc_t *tp)
7167c478bd9Sstevel@tonic-gate {
7177c478bd9Sstevel@tonic-gate 	int lock_prev;
7187c478bd9Sstevel@tonic-gate 	timestruc_t now;
7197c478bd9Sstevel@tonic-gate 	int nslt;		/* nsec since last tick */
7207c478bd9Sstevel@tonic-gate 	int adj;		/* amount of adjustment to apply */
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate loop:
7237c478bd9Sstevel@tonic-gate 	lock_prev = hres_lock;
7247c478bd9Sstevel@tonic-gate 	now = hrestime;
7257c478bd9Sstevel@tonic-gate 	nslt = (int)(gethrtime() - hres_last_tick);
7267c478bd9Sstevel@tonic-gate 	if (nslt < 0) {
7277c478bd9Sstevel@tonic-gate 		/*
7287c478bd9Sstevel@tonic-gate 		 * nslt < 0 means a tick came between sampling
7297c478bd9Sstevel@tonic-gate 		 * gethrtime() and hres_last_tick; restart the loop
7307c478bd9Sstevel@tonic-gate 		 */
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate 		goto loop;
7337c478bd9Sstevel@tonic-gate 	}
7347c478bd9Sstevel@tonic-gate 	now.tv_nsec += nslt;
7357c478bd9Sstevel@tonic-gate 	if (hrestime_adj != 0) {
7367c478bd9Sstevel@tonic-gate 		if (hrestime_adj > 0) {
7377c478bd9Sstevel@tonic-gate 			adj = (nslt >> ADJ_SHIFT);
7387c478bd9Sstevel@tonic-gate 			if (adj > hrestime_adj)
7397c478bd9Sstevel@tonic-gate 				adj = (int)hrestime_adj;
7407c478bd9Sstevel@tonic-gate 		} else {
7417c478bd9Sstevel@tonic-gate 			adj = -(nslt >> ADJ_SHIFT);
7427c478bd9Sstevel@tonic-gate 			if (adj < hrestime_adj)
7437c478bd9Sstevel@tonic-gate 				adj = (int)hrestime_adj;
7447c478bd9Sstevel@tonic-gate 		}
7457c478bd9Sstevel@tonic-gate 		now.tv_nsec += adj;
7467c478bd9Sstevel@tonic-gate 	}
7477c478bd9Sstevel@tonic-gate 	while ((unsigned long)now.tv_nsec >= NANOSEC) {
7487c478bd9Sstevel@tonic-gate 
7497c478bd9Sstevel@tonic-gate 		/*
7507c478bd9Sstevel@tonic-gate 		 * We might have a large adjustment or have been in the
7517c478bd9Sstevel@tonic-gate 		 * debugger for a long time; take care of (at most) four
7527c478bd9Sstevel@tonic-gate 		 * of those missed seconds (tv_nsec is 32 bits, so
7537c478bd9Sstevel@tonic-gate 		 * anything >4s will be wrapping around).  However,
7547c478bd9Sstevel@tonic-gate 		 * anything more than 2 seconds out of sync will trigger
7557c478bd9Sstevel@tonic-gate 		 * timedelta from clock() to go correct the time anyway,
7567c478bd9Sstevel@tonic-gate 		 * so do what we can, and let the big crowbar do the
7577c478bd9Sstevel@tonic-gate 		 * rest.  A similar correction while loop exists inside
7587c478bd9Sstevel@tonic-gate 		 * hres_tick(); in all cases we'd like tv_nsec to
7597c478bd9Sstevel@tonic-gate 		 * satisfy 0 <= tv_nsec < NANOSEC to avoid confusing
7607c478bd9Sstevel@tonic-gate 		 * user processes, but if tv_sec's a little behind for a
7617c478bd9Sstevel@tonic-gate 		 * little while, that's OK; time still monotonically
7627c478bd9Sstevel@tonic-gate 		 * increases.
7637c478bd9Sstevel@tonic-gate 		 */
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate 		now.tv_nsec -= NANOSEC;
7667c478bd9Sstevel@tonic-gate 		now.tv_sec++;
7677c478bd9Sstevel@tonic-gate 	}
7687c478bd9Sstevel@tonic-gate 	if ((hres_lock & ~1) != lock_prev)
7697c478bd9Sstevel@tonic-gate 		goto loop;
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate 	*tp = now;
7727c478bd9Sstevel@tonic-gate }
7737c478bd9Sstevel@tonic-gate 
7747c478bd9Sstevel@tonic-gate void
7757c478bd9Sstevel@tonic-gate gethrestime_lasttick(timespec_t *tp)
7767c478bd9Sstevel@tonic-gate {
7777c478bd9Sstevel@tonic-gate 	int s;
7787c478bd9Sstevel@tonic-gate 
7797c478bd9Sstevel@tonic-gate 	s = hr_clock_lock();
7807c478bd9Sstevel@tonic-gate 	*tp = hrestime;
7817c478bd9Sstevel@tonic-gate 	hr_clock_unlock(s);
7827c478bd9Sstevel@tonic-gate }
7837c478bd9Sstevel@tonic-gate 
7847c478bd9Sstevel@tonic-gate time_t
7857c478bd9Sstevel@tonic-gate gethrestime_sec(void)
7867c478bd9Sstevel@tonic-gate {
7877c478bd9Sstevel@tonic-gate 	timestruc_t now;
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate 	gethrestime(&now);
7907c478bd9Sstevel@tonic-gate 	return (now.tv_sec);
7917c478bd9Sstevel@tonic-gate }
7927c478bd9Sstevel@tonic-gate 
7937c478bd9Sstevel@tonic-gate /*
7947c478bd9Sstevel@tonic-gate  * Initialize a kernel thread's stack
7957c478bd9Sstevel@tonic-gate  */
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate caddr_t
7987c478bd9Sstevel@tonic-gate thread_stk_init(caddr_t stk)
7997c478bd9Sstevel@tonic-gate {
8007c478bd9Sstevel@tonic-gate 	ASSERT(((uintptr_t)stk & (STACK_ALIGN - 1)) == 0);
8017c478bd9Sstevel@tonic-gate 	return (stk - SA(MINFRAME));
8027c478bd9Sstevel@tonic-gate }
8037c478bd9Sstevel@tonic-gate 
8047c478bd9Sstevel@tonic-gate /*
8057c478bd9Sstevel@tonic-gate  * Initialize lwp's kernel stack.
8067c478bd9Sstevel@tonic-gate  */
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE
8097c478bd9Sstevel@tonic-gate /*
8107c478bd9Sstevel@tonic-gate  * There's a tricky interdependency here between use of sysenter and
8117c478bd9Sstevel@tonic-gate  * TRAPTRACE which needs recording to avoid future confusion (this is
8127c478bd9Sstevel@tonic-gate  * about the third time I've re-figured this out ..)
8137c478bd9Sstevel@tonic-gate  *
8147c478bd9Sstevel@tonic-gate  * Here's how debugging lcall works with TRAPTRACE.
8157c478bd9Sstevel@tonic-gate  *
8167c478bd9Sstevel@tonic-gate  * 1 We're in userland with a breakpoint on the lcall instruction.
8177c478bd9Sstevel@tonic-gate  * 2 We execute the instruction - the instruction pushes the userland
8187c478bd9Sstevel@tonic-gate  *   %ss, %esp, %efl, %cs, %eip on the stack and zips into the kernel
8197c478bd9Sstevel@tonic-gate  *   via the call gate.
8207c478bd9Sstevel@tonic-gate  * 3 The hardware raises a debug trap in kernel mode, the hardware
8217c478bd9Sstevel@tonic-gate  *   pushes %efl, %cs, %eip and gets to dbgtrap via the idt.
8227c478bd9Sstevel@tonic-gate  * 4 dbgtrap pushes the error code and trapno and calls cmntrap
8237c478bd9Sstevel@tonic-gate  * 5 cmntrap finishes building a trap frame
8247c478bd9Sstevel@tonic-gate  * 6 The TRACE_REGS macros in cmntrap copy a REGSIZE worth chunk
8257c478bd9Sstevel@tonic-gate  *   off the stack into the traptrace buffer.
8267c478bd9Sstevel@tonic-gate  *
8277c478bd9Sstevel@tonic-gate  * This means that the traptrace buffer contains the wrong values in
8287c478bd9Sstevel@tonic-gate  * %esp and %ss, but everything else in there is correct.
8297c478bd9Sstevel@tonic-gate  *
8307c478bd9Sstevel@tonic-gate  * Here's how debugging sysenter works with TRAPTRACE.
8317c478bd9Sstevel@tonic-gate  *
8327c478bd9Sstevel@tonic-gate  * a We're in userland with a breakpoint on the sysenter instruction.
8337c478bd9Sstevel@tonic-gate  * b We execute the instruction - the instruction pushes -nothing-
8347c478bd9Sstevel@tonic-gate  *   on the stack, but sets %cs, %eip, %ss, %esp to prearranged
8357c478bd9Sstevel@tonic-gate  *   values to take us to sys_sysenter, at the top of the lwp's
8367c478bd9Sstevel@tonic-gate  *   stack.
8377c478bd9Sstevel@tonic-gate  * c goto 3
8387c478bd9Sstevel@tonic-gate  *
8397c478bd9Sstevel@tonic-gate  * At this point, because we got into the kernel without the requisite
8407c478bd9Sstevel@tonic-gate  * five pushes on the stack, if we didn't make extra room, we'd
8417c478bd9Sstevel@tonic-gate  * end up with the TRACE_REGS macro fetching the saved %ss and %esp
8427c478bd9Sstevel@tonic-gate  * values from negative (unmapped) stack addresses -- which really bites.
8437c478bd9Sstevel@tonic-gate  * That's why we do the '-= 8' below.
8447c478bd9Sstevel@tonic-gate  *
8457c478bd9Sstevel@tonic-gate  * XXX	Note that reading "up" lwp0's stack works because t0 is declared
8467c478bd9Sstevel@tonic-gate  *	right next to t0stack in locore.s
8477c478bd9Sstevel@tonic-gate  */
8487c478bd9Sstevel@tonic-gate #endif
8497c478bd9Sstevel@tonic-gate 
8507c478bd9Sstevel@tonic-gate caddr_t
8517c478bd9Sstevel@tonic-gate lwp_stk_init(klwp_t *lwp, caddr_t stk)
8527c478bd9Sstevel@tonic-gate {
8537c478bd9Sstevel@tonic-gate 	caddr_t oldstk;
8547c478bd9Sstevel@tonic-gate 	struct pcb *pcb = &lwp->lwp_pcb;
8557c478bd9Sstevel@tonic-gate 
8567c478bd9Sstevel@tonic-gate 	oldstk = stk;
8577c478bd9Sstevel@tonic-gate 	stk -= SA(sizeof (struct regs) + SA(MINFRAME));
8587c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE
8597c478bd9Sstevel@tonic-gate 	stk -= 2 * sizeof (greg_t); /* space for phony %ss:%sp (see above) */
8607c478bd9Sstevel@tonic-gate #endif
8617c478bd9Sstevel@tonic-gate 	stk = (caddr_t)((uintptr_t)stk & ~(STACK_ALIGN - 1ul));
8627c478bd9Sstevel@tonic-gate 	bzero(stk, oldstk - stk);
8637c478bd9Sstevel@tonic-gate 	lwp->lwp_regs = (void *)(stk + SA(MINFRAME));
8647c478bd9Sstevel@tonic-gate 
8657c478bd9Sstevel@tonic-gate 	/*
8667c478bd9Sstevel@tonic-gate 	 * Arrange that the virtualized %fs and %gs GDT descriptors
8677c478bd9Sstevel@tonic-gate 	 * have a well-defined initial state (present, ring 3
8687c478bd9Sstevel@tonic-gate 	 * and of type data).
8697c478bd9Sstevel@tonic-gate 	 */
8707c478bd9Sstevel@tonic-gate #if defined(__amd64)
8717c478bd9Sstevel@tonic-gate 	if (lwp_getdatamodel(lwp) == DATAMODEL_NATIVE)
8727c478bd9Sstevel@tonic-gate 		pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_udesc;
8737c478bd9Sstevel@tonic-gate 	else
8747c478bd9Sstevel@tonic-gate 		pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_u32desc;
8757c478bd9Sstevel@tonic-gate #elif defined(__i386)
8767c478bd9Sstevel@tonic-gate 	pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_udesc;
8777c478bd9Sstevel@tonic-gate #endif	/* __i386 */
8787c478bd9Sstevel@tonic-gate 	lwp_installctx(lwp);
8797c478bd9Sstevel@tonic-gate 	return (stk);
8807c478bd9Sstevel@tonic-gate }
8817c478bd9Sstevel@tonic-gate 
8827c478bd9Sstevel@tonic-gate /*ARGSUSED*/
8837c478bd9Sstevel@tonic-gate void
8847c478bd9Sstevel@tonic-gate lwp_stk_fini(klwp_t *lwp)
8857c478bd9Sstevel@tonic-gate {}
8867c478bd9Sstevel@tonic-gate 
8877c478bd9Sstevel@tonic-gate /*
888d90554ebSdmick  * If we're not the panic CPU, we wait in panic_idle for reboot.
8897c478bd9Sstevel@tonic-gate  */
890f34a7178SJoe Bonasera void
8917c478bd9Sstevel@tonic-gate panic_idle(void)
8927c478bd9Sstevel@tonic-gate {
8937c478bd9Sstevel@tonic-gate 	splx(ipltospl(CLOCK_LEVEL));
8947c478bd9Sstevel@tonic-gate 	(void) setjmp(&curthread->t_pcb);
8957c478bd9Sstevel@tonic-gate 
896ca3e8d88SDave Plauger 	dumpsys_helper();
897ca3e8d88SDave Plauger 
898f34a7178SJoe Bonasera #ifndef __xpv
899f34a7178SJoe Bonasera 	for (;;)
900f34a7178SJoe Bonasera 		i86_halt();
901f34a7178SJoe Bonasera #else
902ae115bc7Smrj 	for (;;)
903ae115bc7Smrj 		;
904f34a7178SJoe Bonasera #endif
9057c478bd9Sstevel@tonic-gate }
9067c478bd9Sstevel@tonic-gate 
9077c478bd9Sstevel@tonic-gate /*
9087c478bd9Sstevel@tonic-gate  * Stop the other CPUs by cross-calling them and forcing them to enter
9097c478bd9Sstevel@tonic-gate  * the panic_idle() loop above.
9107c478bd9Sstevel@tonic-gate  */
9117c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9127c478bd9Sstevel@tonic-gate void
9137c478bd9Sstevel@tonic-gate panic_stopcpus(cpu_t *cp, kthread_t *t, int spl)
9147c478bd9Sstevel@tonic-gate {
9157c478bd9Sstevel@tonic-gate 	processorid_t i;
9167c478bd9Sstevel@tonic-gate 	cpuset_t xcset;
9177c478bd9Sstevel@tonic-gate 
918843e1988Sjohnlev 	/*
919843e1988Sjohnlev 	 * In the case of a Xen panic, the hypervisor has already stopped
920843e1988Sjohnlev 	 * all of the CPUs.
921843e1988Sjohnlev 	 */
922843e1988Sjohnlev 	if (!IN_XPV_PANIC()) {
9237c478bd9Sstevel@tonic-gate 		(void) splzs();
9247c478bd9Sstevel@tonic-gate 
9257c478bd9Sstevel@tonic-gate 		CPUSET_ALL_BUT(xcset, cp->cpu_id);
926f34a7178SJoe Bonasera 		xc_priority(0, 0, 0, CPUSET2BV(xcset), (xc_func_t)panic_idle);
927843e1988Sjohnlev 	}
9287c478bd9Sstevel@tonic-gate 
9297c478bd9Sstevel@tonic-gate 	for (i = 0; i < NCPU; i++) {
9307c478bd9Sstevel@tonic-gate 		if (i != cp->cpu_id && cpu[i] != NULL &&
9317c478bd9Sstevel@tonic-gate 		    (cpu[i]->cpu_flags & CPU_EXISTS))
9327c478bd9Sstevel@tonic-gate 			cpu[i]->cpu_flags |= CPU_QUIESCED;
9337c478bd9Sstevel@tonic-gate 	}
9347c478bd9Sstevel@tonic-gate }
9357c478bd9Sstevel@tonic-gate 
9367c478bd9Sstevel@tonic-gate /*
9377c478bd9Sstevel@tonic-gate  * Platform callback following each entry to panicsys().
9387c478bd9Sstevel@tonic-gate  */
9397c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9407c478bd9Sstevel@tonic-gate void
9417c478bd9Sstevel@tonic-gate panic_enter_hw(int spl)
9427c478bd9Sstevel@tonic-gate {
9437c478bd9Sstevel@tonic-gate 	/* Nothing to do here */
9447c478bd9Sstevel@tonic-gate }
9457c478bd9Sstevel@tonic-gate 
9467c478bd9Sstevel@tonic-gate /*
9477c478bd9Sstevel@tonic-gate  * Platform-specific code to execute after panicstr is set: we invoke
9487c478bd9Sstevel@tonic-gate  * the PSM entry point to indicate that a panic has occurred.
9497c478bd9Sstevel@tonic-gate  */
9507c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9517c478bd9Sstevel@tonic-gate void
9527c478bd9Sstevel@tonic-gate panic_quiesce_hw(panic_data_t *pdp)
9537c478bd9Sstevel@tonic-gate {
9547c478bd9Sstevel@tonic-gate 	psm_notifyf(PSM_PANIC_ENTER);
9557c478bd9Sstevel@tonic-gate 
956e4b86885SCheng Sean Ye 	cmi_panic_callback();
957e4b86885SCheng Sean Ye 
9587c478bd9Sstevel@tonic-gate #ifdef	TRAPTRACE
9597c478bd9Sstevel@tonic-gate 	/*
9607c478bd9Sstevel@tonic-gate 	 * Turn off TRAPTRACE
9617c478bd9Sstevel@tonic-gate 	 */
9627c478bd9Sstevel@tonic-gate 	TRAPTRACE_FREEZE;
9637c478bd9Sstevel@tonic-gate #endif	/* TRAPTRACE */
9647c478bd9Sstevel@tonic-gate }
9657c478bd9Sstevel@tonic-gate 
9667c478bd9Sstevel@tonic-gate /*
9677c478bd9Sstevel@tonic-gate  * Platform callback prior to writing crash dump.
9687c478bd9Sstevel@tonic-gate  */
9697c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9707c478bd9Sstevel@tonic-gate void
9717c478bd9Sstevel@tonic-gate panic_dump_hw(int spl)
9727c478bd9Sstevel@tonic-gate {
9737c478bd9Sstevel@tonic-gate 	/* Nothing to do here */
9747c478bd9Sstevel@tonic-gate }
9757c478bd9Sstevel@tonic-gate 
976843e1988Sjohnlev void *
977843e1988Sjohnlev plat_traceback(void *fpreg)
978843e1988Sjohnlev {
979843e1988Sjohnlev #ifdef __xpv
980843e1988Sjohnlev 	if (IN_XPV_PANIC())
981843e1988Sjohnlev 		return (xpv_traceback(fpreg));
982843e1988Sjohnlev #endif
983843e1988Sjohnlev 	return (fpreg);
984843e1988Sjohnlev }
985843e1988Sjohnlev 
9867c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9877c478bd9Sstevel@tonic-gate void
9887c478bd9Sstevel@tonic-gate plat_tod_fault(enum tod_fault_type tod_bad)
989ae115bc7Smrj {}
9907c478bd9Sstevel@tonic-gate 
9917c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9927c478bd9Sstevel@tonic-gate int
9937c478bd9Sstevel@tonic-gate blacklist(int cmd, const char *scheme, nvlist_t *fmri, const char *class)
9947c478bd9Sstevel@tonic-gate {
9957c478bd9Sstevel@tonic-gate 	return (ENOTSUP);
9967c478bd9Sstevel@tonic-gate }
9977c478bd9Sstevel@tonic-gate 
9987c478bd9Sstevel@tonic-gate /*
9997c478bd9Sstevel@tonic-gate  * The underlying console output routines are protected by raising IPL in case
10007c478bd9Sstevel@tonic-gate  * we are still calling into the early boot services.  Once we start calling
10017c478bd9Sstevel@tonic-gate  * the kernel console emulator, it will disable interrupts completely during
10027c478bd9Sstevel@tonic-gate  * character rendering (see sysp_putchar, for example).  Refer to the comments
10037c478bd9Sstevel@tonic-gate  * and code in common/os/console.c for more information on these callbacks.
10047c478bd9Sstevel@tonic-gate  */
10057c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10067c478bd9Sstevel@tonic-gate int
10077c478bd9Sstevel@tonic-gate console_enter(int busy)
10087c478bd9Sstevel@tonic-gate {
10097c478bd9Sstevel@tonic-gate 	return (splzs());
10107c478bd9Sstevel@tonic-gate }
10117c478bd9Sstevel@tonic-gate 
10127c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10137c478bd9Sstevel@tonic-gate void
10147c478bd9Sstevel@tonic-gate console_exit(int busy, int spl)
10157c478bd9Sstevel@tonic-gate {
10167c478bd9Sstevel@tonic-gate 	splx(spl);
10177c478bd9Sstevel@tonic-gate }
10187c478bd9Sstevel@tonic-gate 
10197c478bd9Sstevel@tonic-gate /*
10207c478bd9Sstevel@tonic-gate  * Allocate a region of virtual address space, unmapped.
10217c478bd9Sstevel@tonic-gate  * Stubbed out except on sparc, at least for now.
10227c478bd9Sstevel@tonic-gate  */
10237c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10247c478bd9Sstevel@tonic-gate void *
10257c478bd9Sstevel@tonic-gate boot_virt_alloc(void *addr, size_t size)
10267c478bd9Sstevel@tonic-gate {
10277c478bd9Sstevel@tonic-gate 	return (addr);
10287c478bd9Sstevel@tonic-gate }
10297c478bd9Sstevel@tonic-gate 
10307c478bd9Sstevel@tonic-gate volatile unsigned long	tenmicrodata;
10317c478bd9Sstevel@tonic-gate 
10327c478bd9Sstevel@tonic-gate void
10337c478bd9Sstevel@tonic-gate tenmicrosec(void)
10347c478bd9Sstevel@tonic-gate {
1035843e1988Sjohnlev 	extern int gethrtime_hires;
10367c478bd9Sstevel@tonic-gate 
1037843e1988Sjohnlev 	if (gethrtime_hires) {
10387c478bd9Sstevel@tonic-gate 		hrtime_t start, end;
10397c478bd9Sstevel@tonic-gate 		start = end =  gethrtime();
10407c478bd9Sstevel@tonic-gate 		while ((end - start) < (10 * (NANOSEC / MICROSEC))) {
10417c478bd9Sstevel@tonic-gate 			SMT_PAUSE();
10427c478bd9Sstevel@tonic-gate 			end = gethrtime();
10437c478bd9Sstevel@tonic-gate 		}
10447c478bd9Sstevel@tonic-gate 	} else {
1045843e1988Sjohnlev #if defined(__xpv)
1046843e1988Sjohnlev 		hrtime_t newtime;
1047843e1988Sjohnlev 
1048843e1988Sjohnlev 		newtime = xpv_gethrtime() + 10000; /* now + 10 us */
1049843e1988Sjohnlev 		while (xpv_gethrtime() < newtime)
1050843e1988Sjohnlev 			SMT_PAUSE();
1051843e1988Sjohnlev #else	/* __xpv */
1052ae115bc7Smrj 		int i;
1053ae115bc7Smrj 
10547c478bd9Sstevel@tonic-gate 		/*
10557c478bd9Sstevel@tonic-gate 		 * Artificial loop to induce delay.
10567c478bd9Sstevel@tonic-gate 		 */
10577c478bd9Sstevel@tonic-gate 		for (i = 0; i < microdata; i++)
10587c478bd9Sstevel@tonic-gate 			tenmicrodata = microdata;
1059843e1988Sjohnlev #endif	/* __xpv */
10607c478bd9Sstevel@tonic-gate 	}
10617c478bd9Sstevel@tonic-gate }
1062eda89462Sesolom 
1063eda89462Sesolom /*
1064eda89462Sesolom  * get_cpu_mstate() is passed an array of timestamps, NCMSTATES
1065eda89462Sesolom  * long, and it fills in the array with the time spent on cpu in
1066eda89462Sesolom  * each of the mstates, where time is returned in nsec.
1067eda89462Sesolom  *
1068eda89462Sesolom  * No guarantee is made that the returned values in times[] will
1069eda89462Sesolom  * monotonically increase on sequential calls, although this will
1070eda89462Sesolom  * be true in the long run. Any such guarantee must be handled by
1071eda89462Sesolom  * the caller, if needed. This can happen if we fail to account
1072eda89462Sesolom  * for elapsed time due to a generation counter conflict, yet we
1073eda89462Sesolom  * did account for it on a prior call (see below).
1074eda89462Sesolom  *
1075eda89462Sesolom  * The complication is that the cpu in question may be updating
1076eda89462Sesolom  * its microstate at the same time that we are reading it.
1077eda89462Sesolom  * Because the microstate is only updated when the CPU's state
1078eda89462Sesolom  * changes, the values in cpu_intracct[] can be indefinitely out
1079eda89462Sesolom  * of date. To determine true current values, it is necessary to
1080eda89462Sesolom  * compare the current time with cpu_mstate_start, and add the
1081eda89462Sesolom  * difference to times[cpu_mstate].
1082eda89462Sesolom  *
1083eda89462Sesolom  * This can be a problem if those values are changing out from
1084eda89462Sesolom  * under us. Because the code path in new_cpu_mstate() is
1085eda89462Sesolom  * performance critical, we have not added a lock to it. Instead,
1086eda89462Sesolom  * we have added a generation counter. Before beginning
1087eda89462Sesolom  * modifications, the counter is set to 0. After modifications,
1088eda89462Sesolom  * it is set to the old value plus one.
1089eda89462Sesolom  *
1090eda89462Sesolom  * get_cpu_mstate() will not consider the values of cpu_mstate
1091eda89462Sesolom  * and cpu_mstate_start to be usable unless the value of
1092eda89462Sesolom  * cpu_mstate_gen is both non-zero and unchanged, both before and
1093eda89462Sesolom  * after reading the mstate information. Note that we must
1094eda89462Sesolom  * protect against out-of-order loads around accesses to the
1095eda89462Sesolom  * generation counter. Also, this is a best effort approach in
1096eda89462Sesolom  * that we do not retry should the counter be found to have
1097eda89462Sesolom  * changed.
1098eda89462Sesolom  *
1099eda89462Sesolom  * cpu_intracct[] is used to identify time spent in each CPU
1100eda89462Sesolom  * mstate while handling interrupts. Such time should be reported
1101eda89462Sesolom  * against system time, and so is subtracted out from its
1102eda89462Sesolom  * corresponding cpu_acct[] time and added to
1103eda89462Sesolom  * cpu_acct[CMS_SYSTEM].
1104eda89462Sesolom  */
1105eda89462Sesolom 
1106eda89462Sesolom void
1107eda89462Sesolom get_cpu_mstate(cpu_t *cpu, hrtime_t *times)
1108eda89462Sesolom {
1109eda89462Sesolom 	int i;
1110eda89462Sesolom 	hrtime_t now, start;
1111eda89462Sesolom 	uint16_t gen;
1112eda89462Sesolom 	uint16_t state;
1113eda89462Sesolom 	hrtime_t intracct[NCMSTATES];
1114eda89462Sesolom 
1115eda89462Sesolom 	/*
1116eda89462Sesolom 	 * Load all volatile state under the protection of membar.
1117eda89462Sesolom 	 * cpu_acct[cpu_mstate] must be loaded to avoid double counting
1118eda89462Sesolom 	 * of (now - cpu_mstate_start) by a change in CPU mstate that
1119eda89462Sesolom 	 * arrives after we make our last check of cpu_mstate_gen.
1120eda89462Sesolom 	 */
1121eda89462Sesolom 
1122eda89462Sesolom 	now = gethrtime_unscaled();
1123eda89462Sesolom 	gen = cpu->cpu_mstate_gen;
1124eda89462Sesolom 
1125eda89462Sesolom 	membar_consumer();	/* guarantee load ordering */
1126eda89462Sesolom 	start = cpu->cpu_mstate_start;
1127eda89462Sesolom 	state = cpu->cpu_mstate;
1128eda89462Sesolom 	for (i = 0; i < NCMSTATES; i++) {
1129eda89462Sesolom 		intracct[i] = cpu->cpu_intracct[i];
1130eda89462Sesolom 		times[i] = cpu->cpu_acct[i];
1131eda89462Sesolom 	}
1132eda89462Sesolom 	membar_consumer();	/* guarantee load ordering */
1133eda89462Sesolom 
1134eda89462Sesolom 	if (gen != 0 && gen == cpu->cpu_mstate_gen && now > start)
1135eda89462Sesolom 		times[state] += now - start;
1136eda89462Sesolom 
1137eda89462Sesolom 	for (i = 0; i < NCMSTATES; i++) {
1138eda89462Sesolom 		if (i == CMS_SYSTEM)
1139eda89462Sesolom 			continue;
1140eda89462Sesolom 		times[i] -= intracct[i];
1141eda89462Sesolom 		if (times[i] < 0) {
1142eda89462Sesolom 			intracct[i] += times[i];
1143eda89462Sesolom 			times[i] = 0;
1144eda89462Sesolom 		}
1145eda89462Sesolom 		times[CMS_SYSTEM] += intracct[i];
1146eda89462Sesolom 		scalehrtime(&times[i]);
1147eda89462Sesolom 	}
1148eda89462Sesolom 	scalehrtime(&times[CMS_SYSTEM]);
1149eda89462Sesolom }
1150ae115bc7Smrj 
1151ae115bc7Smrj /*
1152ae115bc7Smrj  * This is a version of the rdmsr instruction that allows
1153ae115bc7Smrj  * an error code to be returned in the case of failure.
1154ae115bc7Smrj  */
1155ae115bc7Smrj int
1156ae115bc7Smrj checked_rdmsr(uint_t msr, uint64_t *value)
1157ae115bc7Smrj {
1158ae115bc7Smrj 	if ((x86_feature & X86_MSR) == 0)
1159ae115bc7Smrj 		return (ENOTSUP);
1160ae115bc7Smrj 	*value = rdmsr(msr);
1161ae115bc7Smrj 	return (0);
1162ae115bc7Smrj }
1163ae115bc7Smrj 
1164ae115bc7Smrj /*
1165ae115bc7Smrj  * This is a version of the wrmsr instruction that allows
1166ae115bc7Smrj  * an error code to be returned in the case of failure.
1167ae115bc7Smrj  */
1168ae115bc7Smrj int
1169ae115bc7Smrj checked_wrmsr(uint_t msr, uint64_t value)
1170ae115bc7Smrj {
1171ae115bc7Smrj 	if ((x86_feature & X86_MSR) == 0)
1172ae115bc7Smrj 		return (ENOTSUP);
1173ae115bc7Smrj 	wrmsr(msr, value);
1174ae115bc7Smrj 	return (0);
1175ae115bc7Smrj }
1176ae115bc7Smrj 
1177ae115bc7Smrj /*
1178843e1988Sjohnlev  * The mem driver's usual method of using hat_devload() to establish a
1179843e1988Sjohnlev  * temporary mapping will not work for foreign pages mapped into this
1180843e1988Sjohnlev  * domain or for the special hypervisor-provided pages.  For the foreign
1181843e1988Sjohnlev  * pages, we often don't know which domain owns them, so we can't ask the
1182843e1988Sjohnlev  * hypervisor to set up a new mapping.  For the other pages, we don't have
1183843e1988Sjohnlev  * a pfn, so we can't create a new PTE.  For these special cases, we do a
1184843e1988Sjohnlev  * direct uiomove() from the existing kernel virtual address.
1185ae115bc7Smrj  */
1186ae115bc7Smrj /*ARGSUSED*/
1187ae115bc7Smrj int
1188843e1988Sjohnlev plat_mem_do_mmio(struct uio *uio, enum uio_rw rw)
1189ae115bc7Smrj {
1190843e1988Sjohnlev #if defined(__xpv)
1191843e1988Sjohnlev 	void *va = (void *)(uintptr_t)uio->uio_loffset;
1192843e1988Sjohnlev 	off_t pageoff = uio->uio_loffset & PAGEOFFSET;
1193843e1988Sjohnlev 	size_t nbytes = MIN((size_t)(PAGESIZE - pageoff),
1194843e1988Sjohnlev 	    (size_t)uio->uio_iov->iov_len);
1195843e1988Sjohnlev 
1196843e1988Sjohnlev 	if ((rw == UIO_READ &&
1197843e1988Sjohnlev 	    (va == HYPERVISOR_shared_info || va == xen_info)) ||
1198843e1988Sjohnlev 	    (pfn_is_foreign(hat_getpfnum(kas.a_hat, va))))
1199843e1988Sjohnlev 		return (uiomove(va, nbytes, rw, uio));
1200843e1988Sjohnlev #endif
1201843e1988Sjohnlev 	return (ENOTSUP);
1202843e1988Sjohnlev }
1203843e1988Sjohnlev 
1204843e1988Sjohnlev pgcnt_t
1205843e1988Sjohnlev num_phys_pages()
1206843e1988Sjohnlev {
1207843e1988Sjohnlev 	pgcnt_t npages = 0;
1208843e1988Sjohnlev 	struct memlist *mp;
1209843e1988Sjohnlev 
1210843e1988Sjohnlev #if defined(__xpv)
1211349b53ddSStuart Maybee 	if (DOMAIN_IS_INITDOMAIN(xen_info))
1212349b53ddSStuart Maybee 		return (xpv_nr_phys_pages());
1213843e1988Sjohnlev #endif /* __xpv */
1214843e1988Sjohnlev 
121556f33205SJonathan Adams 	for (mp = phys_install; mp != NULL; mp = mp->ml_next)
121656f33205SJonathan Adams 		npages += mp->ml_size >> PAGESHIFT;
1217843e1988Sjohnlev 
1218843e1988Sjohnlev 	return (npages);
1219ae115bc7Smrj }
1220ae115bc7Smrj 
1221ca3e8d88SDave Plauger /* cpu threshold for compressed dumps */
1222ca3e8d88SDave Plauger #ifdef _LP64
1223ca3e8d88SDave Plauger uint_t dump_plat_mincpu = DUMP_PLAT_X86_64_MINCPU;
1224ca3e8d88SDave Plauger #else
1225ca3e8d88SDave Plauger uint_t dump_plat_mincpu = DUMP_PLAT_X86_32_MINCPU;
1226ca3e8d88SDave Plauger #endif
1227ca3e8d88SDave Plauger 
1228ae115bc7Smrj int
1229ae115bc7Smrj dump_plat_addr()
1230ae115bc7Smrj {
1231843e1988Sjohnlev #ifdef __xpv
1232843e1988Sjohnlev 	pfn_t pfn = mmu_btop(xen_info->shared_info) | PFN_IS_FOREIGN_MFN;
1233843e1988Sjohnlev 	mem_vtop_t mem_vtop;
1234843e1988Sjohnlev 	int cnt;
1235843e1988Sjohnlev 
1236843e1988Sjohnlev 	/*
1237843e1988Sjohnlev 	 * On the hypervisor, we want to dump the page with shared_info on it.
1238843e1988Sjohnlev 	 */
1239843e1988Sjohnlev 	if (!IN_XPV_PANIC()) {
1240843e1988Sjohnlev 		mem_vtop.m_as = &kas;
1241843e1988Sjohnlev 		mem_vtop.m_va = HYPERVISOR_shared_info;
1242843e1988Sjohnlev 		mem_vtop.m_pfn = pfn;
1243843e1988Sjohnlev 		dumpvp_write(&mem_vtop, sizeof (mem_vtop_t));
1244843e1988Sjohnlev 		cnt = 1;
1245843e1988Sjohnlev 	} else {
1246843e1988Sjohnlev 		cnt = dump_xpv_addr();
1247843e1988Sjohnlev 	}
1248843e1988Sjohnlev 	return (cnt);
1249843e1988Sjohnlev #else
1250ae115bc7Smrj 	return (0);
1251843e1988Sjohnlev #endif
1252ae115bc7Smrj }
1253ae115bc7Smrj 
1254ae115bc7Smrj void
1255ae115bc7Smrj dump_plat_pfn()
1256ae115bc7Smrj {
1257843e1988Sjohnlev #ifdef __xpv
1258843e1988Sjohnlev 	pfn_t pfn = mmu_btop(xen_info->shared_info) | PFN_IS_FOREIGN_MFN;
1259843e1988Sjohnlev 
1260843e1988Sjohnlev 	if (!IN_XPV_PANIC())
1261843e1988Sjohnlev 		dumpvp_write(&pfn, sizeof (pfn));
1262843e1988Sjohnlev 	else
1263843e1988Sjohnlev 		dump_xpv_pfn();
1264843e1988Sjohnlev #endif
1265ae115bc7Smrj }
1266ae115bc7Smrj 
1267ae115bc7Smrj /*ARGSUSED*/
1268ae115bc7Smrj int
1269ae115bc7Smrj dump_plat_data(void *dump_cbuf)
1270ae115bc7Smrj {
1271843e1988Sjohnlev #ifdef __xpv
1272843e1988Sjohnlev 	uint32_t csize;
1273843e1988Sjohnlev 	int cnt;
1274843e1988Sjohnlev 
1275843e1988Sjohnlev 	if (!IN_XPV_PANIC()) {
1276843e1988Sjohnlev 		csize = (uint32_t)compress(HYPERVISOR_shared_info, dump_cbuf,
1277843e1988Sjohnlev 		    PAGESIZE);
1278843e1988Sjohnlev 		dumpvp_write(&csize, sizeof (uint32_t));
1279843e1988Sjohnlev 		dumpvp_write(dump_cbuf, csize);
1280843e1988Sjohnlev 		cnt = 1;
1281843e1988Sjohnlev 	} else {
1282843e1988Sjohnlev 		cnt = dump_xpv_data(dump_cbuf);
1283843e1988Sjohnlev 	}
1284843e1988Sjohnlev 	return (cnt);
1285843e1988Sjohnlev #else
1286ae115bc7Smrj 	return (0);
1287843e1988Sjohnlev #endif
1288ae115bc7Smrj }
1289ddece0baSsethg 
1290ddece0baSsethg /*
1291ddece0baSsethg  * Calculates a linear address, given the CS selector and PC values
1292ddece0baSsethg  * by looking up the %cs selector process's LDT or the CPU's GDT.
1293ddece0baSsethg  * proc->p_ldtlock must be held across this call.
1294ddece0baSsethg  */
1295ddece0baSsethg int
1296ddece0baSsethg linear_pc(struct regs *rp, proc_t *p, caddr_t *linearp)
1297ddece0baSsethg {
1298ddece0baSsethg 	user_desc_t	*descrp;
1299ddece0baSsethg 	caddr_t		baseaddr;
1300ddece0baSsethg 	uint16_t	idx = SELTOIDX(rp->r_cs);
1301ddece0baSsethg 
1302ddece0baSsethg 	ASSERT(rp->r_cs <= 0xFFFF);
1303ddece0baSsethg 	ASSERT(MUTEX_HELD(&p->p_ldtlock));
1304ddece0baSsethg 
1305ddece0baSsethg 	if (SELISLDT(rp->r_cs)) {
1306ddece0baSsethg 		/*
1307ddece0baSsethg 		 * Currently 64 bit processes cannot have private LDTs.
1308ddece0baSsethg 		 */
1309ddece0baSsethg 		ASSERT(p->p_model != DATAMODEL_LP64);
1310ddece0baSsethg 
1311ddece0baSsethg 		if (p->p_ldt == NULL)
1312ddece0baSsethg 			return (-1);
1313ddece0baSsethg 
1314ddece0baSsethg 		descrp = &p->p_ldt[idx];
1315ddece0baSsethg 		baseaddr = (caddr_t)(uintptr_t)USEGD_GETBASE(descrp);
1316ddece0baSsethg 
1317ddece0baSsethg 		/*
1318ddece0baSsethg 		 * Calculate the linear address (wraparound is not only ok,
1319ddece0baSsethg 		 * it's expected behavior).  The cast to uint32_t is because
1320ddece0baSsethg 		 * LDT selectors are only allowed in 32-bit processes.
1321ddece0baSsethg 		 */
1322ddece0baSsethg 		*linearp = (caddr_t)(uintptr_t)(uint32_t)((uintptr_t)baseaddr +
1323ddece0baSsethg 		    rp->r_pc);
1324ddece0baSsethg 	} else {
1325ddece0baSsethg #ifdef DEBUG
1326ddece0baSsethg 		descrp = &CPU->cpu_gdt[idx];
1327ddece0baSsethg 		baseaddr = (caddr_t)(uintptr_t)USEGD_GETBASE(descrp);
1328ddece0baSsethg 		/* GDT-based descriptors' base addresses should always be 0 */
1329ddece0baSsethg 		ASSERT(baseaddr == 0);
1330ddece0baSsethg #endif
1331ddece0baSsethg 		*linearp = (caddr_t)(uintptr_t)rp->r_pc;
1332ddece0baSsethg 	}
1333ddece0baSsethg 
1334ddece0baSsethg 	return (0);
1335ddece0baSsethg }
1336ddece0baSsethg 
1337ddece0baSsethg /*
1338ddece0baSsethg  * The implementation of dtrace_linear_pc is similar to the that of
1339ddece0baSsethg  * linear_pc, above, but here we acquire p_ldtlock before accessing
1340ddece0baSsethg  * p_ldt.  This implementation is used by the pid provider; we prefix
1341ddece0baSsethg  * it with "dtrace_" to avoid inducing spurious tracing events.
1342ddece0baSsethg  */
1343ddece0baSsethg int
1344ddece0baSsethg dtrace_linear_pc(struct regs *rp, proc_t *p, caddr_t *linearp)
1345ddece0baSsethg {
1346ddece0baSsethg 	user_desc_t	*descrp;
1347ddece0baSsethg 	caddr_t		baseaddr;
1348ddece0baSsethg 	uint16_t	idx = SELTOIDX(rp->r_cs);
1349ddece0baSsethg 
1350ddece0baSsethg 	ASSERT(rp->r_cs <= 0xFFFF);
1351ddece0baSsethg 
1352ddece0baSsethg 	if (SELISLDT(rp->r_cs)) {
1353ddece0baSsethg 		/*
1354ddece0baSsethg 		 * Currently 64 bit processes cannot have private LDTs.
1355ddece0baSsethg 		 */
1356ddece0baSsethg 		ASSERT(p->p_model != DATAMODEL_LP64);
1357ddece0baSsethg 
1358ddece0baSsethg 		mutex_enter(&p->p_ldtlock);
1359ddece0baSsethg 		if (p->p_ldt == NULL) {
1360ddece0baSsethg 			mutex_exit(&p->p_ldtlock);
1361ddece0baSsethg 			return (-1);
1362ddece0baSsethg 		}
1363ddece0baSsethg 		descrp = &p->p_ldt[idx];
1364ddece0baSsethg 		baseaddr = (caddr_t)(uintptr_t)USEGD_GETBASE(descrp);
1365ddece0baSsethg 		mutex_exit(&p->p_ldtlock);
1366ddece0baSsethg 
1367ddece0baSsethg 		/*
1368ddece0baSsethg 		 * Calculate the linear address (wraparound is not only ok,
1369ddece0baSsethg 		 * it's expected behavior).  The cast to uint32_t is because
1370ddece0baSsethg 		 * LDT selectors are only allowed in 32-bit processes.
1371ddece0baSsethg 		 */
1372ddece0baSsethg 		*linearp = (caddr_t)(uintptr_t)(uint32_t)((uintptr_t)baseaddr +
1373ddece0baSsethg 		    rp->r_pc);
1374ddece0baSsethg 	} else {
1375ddece0baSsethg #ifdef DEBUG
1376ddece0baSsethg 		descrp = &CPU->cpu_gdt[idx];
1377ddece0baSsethg 		baseaddr = (caddr_t)(uintptr_t)USEGD_GETBASE(descrp);
1378ddece0baSsethg 		/* GDT-based descriptors' base addresses should always be 0 */
1379ddece0baSsethg 		ASSERT(baseaddr == 0);
1380ddece0baSsethg #endif
1381ddece0baSsethg 		*linearp = (caddr_t)(uintptr_t)rp->r_pc;
1382ddece0baSsethg 	}
1383ddece0baSsethg 
1384ddece0baSsethg 	return (0);
1385ddece0baSsethg }
1386d3d50737SRafael Vanoni 
1387d3d50737SRafael Vanoni /*
1388d3d50737SRafael Vanoni  * We need to post a soft interrupt to reprogram the lbolt cyclic when
1389d3d50737SRafael Vanoni  * switching from event to cyclic driven lbolt. The following code adds
1390d3d50737SRafael Vanoni  * and posts the softint for x86.
1391d3d50737SRafael Vanoni  */
1392d3d50737SRafael Vanoni static ddi_softint_hdl_impl_t lbolt_softint_hdl =
1393d3d50737SRafael Vanoni 	{0, NULL, NULL, NULL, 0, NULL, NULL, NULL};
1394d3d50737SRafael Vanoni 
1395d3d50737SRafael Vanoni void
1396d3d50737SRafael Vanoni lbolt_softint_add(void)
1397d3d50737SRafael Vanoni {
1398d3d50737SRafael Vanoni 	(void) add_avsoftintr((void *)&lbolt_softint_hdl, LOCK_LEVEL,
1399d3d50737SRafael Vanoni 	    (avfunc)lbolt_ev_to_cyclic, "lbolt_ev_to_cyclic", NULL, NULL);
1400d3d50737SRafael Vanoni }
1401d3d50737SRafael Vanoni 
1402d3d50737SRafael Vanoni void
1403d3d50737SRafael Vanoni lbolt_softint_post(void)
1404d3d50737SRafael Vanoni {
1405d3d50737SRafael Vanoni 	(*setsoftint)(CBE_LOCK_PIL, lbolt_softint_hdl.ih_pending);
1406d3d50737SRafael Vanoni }
1407*a3114836SGerry Liu 
1408*a3114836SGerry Liu boolean_t
1409*a3114836SGerry Liu plat_dr_check_capability(uint64_t features)
1410*a3114836SGerry Liu {
1411*a3114836SGerry Liu 	return ((plat_dr_options & features) == features);
1412*a3114836SGerry Liu }
1413*a3114836SGerry Liu 
1414*a3114836SGerry Liu boolean_t
1415*a3114836SGerry Liu plat_dr_support_cpu(void)
1416*a3114836SGerry Liu {
1417*a3114836SGerry Liu 	return (plat_dr_options & PLAT_DR_FEATURE_CPU);
1418*a3114836SGerry Liu }
1419*a3114836SGerry Liu 
1420*a3114836SGerry Liu boolean_t
1421*a3114836SGerry Liu plat_dr_support_memory(void)
1422*a3114836SGerry Liu {
1423*a3114836SGerry Liu 	return (plat_dr_options & PLAT_DR_FEATURE_MEMORY);
1424*a3114836SGerry Liu }
1425*a3114836SGerry Liu 
1426*a3114836SGerry Liu void
1427*a3114836SGerry Liu plat_dr_enable_capability(uint64_t features)
1428*a3114836SGerry Liu {
1429*a3114836SGerry Liu 	atomic_or_64(&plat_dr_options, features);
1430*a3114836SGerry Liu }
1431*a3114836SGerry Liu 
1432*a3114836SGerry Liu void
1433*a3114836SGerry Liu plat_dr_disable_capability(uint64_t features)
1434*a3114836SGerry Liu {
1435*a3114836SGerry Liu 	atomic_and_64(&plat_dr_options, ~features);
1436*a3114836SGerry Liu }
1437