xref: /onnv-gate/usr/src/uts/common/os/kdi.c (revision 3446:5903aece022d)
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
5*3446Smrj  * Common Development and Distribution License (the "License").
6*3446Smrj  * 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 /*
22*3446Smrj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/cpuvar.h>
290Sstevel@tonic-gate #include <sys/kdi_impl.h>
300Sstevel@tonic-gate #include <sys/reboot.h>
310Sstevel@tonic-gate #include <sys/errno.h>
320Sstevel@tonic-gate #include <sys/atomic.h>
330Sstevel@tonic-gate #include <sys/kmem.h>
340Sstevel@tonic-gate 
351226Scth kdi_debugvec_t	*kdi_dvec;
361226Scth struct modctl	*kdi_dmods;
370Sstevel@tonic-gate 
380Sstevel@tonic-gate static kdi_dtrace_state_t kdi_dtrace_state = KDI_DTSTATE_IDLE;
390Sstevel@tonic-gate 
400Sstevel@tonic-gate void
kdi_dvec_vmready(void)410Sstevel@tonic-gate kdi_dvec_vmready(void)
420Sstevel@tonic-gate {
430Sstevel@tonic-gate 	kdi_dvec->dv_kctl_vmready();
440Sstevel@tonic-gate 	kdi_dvec->dv_vmready();
450Sstevel@tonic-gate }
460Sstevel@tonic-gate 
470Sstevel@tonic-gate void
kdi_dvec_memavail(void)480Sstevel@tonic-gate kdi_dvec_memavail(void)
490Sstevel@tonic-gate {
500Sstevel@tonic-gate 	/*
510Sstevel@tonic-gate 	 * The driver will allocate more memory (if requested), and will call
520Sstevel@tonic-gate 	 * dv_memavail itself.
530Sstevel@tonic-gate 	 */
540Sstevel@tonic-gate 	kdi_dvec->dv_kctl_memavail();
550Sstevel@tonic-gate }
560Sstevel@tonic-gate 
57*3446Smrj #if defined(__x86)
58*3446Smrj void
kdi_dvec_handle_fault(greg_t trapno,greg_t pc,greg_t sp,int cpuid)59*3446Smrj kdi_dvec_handle_fault(greg_t trapno, greg_t pc, greg_t sp, int cpuid)
60*3446Smrj {
61*3446Smrj 	kdi_dvec->dv_handle_fault(trapno, pc, sp, cpuid);
62*3446Smrj }
63*3446Smrj #endif
64*3446Smrj 
650Sstevel@tonic-gate #if defined(__sparc)
66*3446Smrj /*
67*3446Smrj  * Called on the CPU being initialized
68*3446Smrj  */
69*3446Smrj void
kdi_dvec_cpu_init(struct cpu * cp)70*3446Smrj kdi_dvec_cpu_init(struct cpu *cp)
71*3446Smrj {
72*3446Smrj 	kdi_dvec->dv_kctl_cpu_init();
73*3446Smrj 	kdi_dvec->dv_cpu_init(cp);
74*3446Smrj }
75*3446Smrj 
760Sstevel@tonic-gate void
kdi_dvec_cpr_restart(void)770Sstevel@tonic-gate kdi_dvec_cpr_restart(void)
780Sstevel@tonic-gate {
790Sstevel@tonic-gate 	kdi_dvec->dv_kctl_cpu_init();
800Sstevel@tonic-gate 	kdi_dvec->dv_cpr_restart();
810Sstevel@tonic-gate }
820Sstevel@tonic-gate #endif	/* __sparc */
830Sstevel@tonic-gate 
840Sstevel@tonic-gate void
kdi_dvec_modavail(void)850Sstevel@tonic-gate kdi_dvec_modavail(void)
860Sstevel@tonic-gate {
870Sstevel@tonic-gate 	kdi_dvec->dv_kctl_modavail();
880Sstevel@tonic-gate }
890Sstevel@tonic-gate 
900Sstevel@tonic-gate void
kdi_dvec_thravail(void)910Sstevel@tonic-gate kdi_dvec_thravail(void)
920Sstevel@tonic-gate {
930Sstevel@tonic-gate 	kdi_dvec->dv_kctl_thravail();
940Sstevel@tonic-gate }
950Sstevel@tonic-gate 
960Sstevel@tonic-gate void
kdi_dvec_mod_loaded(struct modctl * modp)970Sstevel@tonic-gate kdi_dvec_mod_loaded(struct modctl *modp)
980Sstevel@tonic-gate {
990Sstevel@tonic-gate 	kdi_dvec->dv_mod_loaded(modp);
1000Sstevel@tonic-gate }
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate void
kdi_dvec_mod_unloading(struct modctl * modp)1030Sstevel@tonic-gate kdi_dvec_mod_unloading(struct modctl *modp)
1040Sstevel@tonic-gate {
1050Sstevel@tonic-gate 	kdi_dvec->dv_mod_unloading(modp);
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate kdi_dtrace_state_t
kdi_dtrace_get_state(void)1090Sstevel@tonic-gate kdi_dtrace_get_state(void)
1100Sstevel@tonic-gate {
1110Sstevel@tonic-gate 	return (kdi_dtrace_state);
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate int
kdi_dtrace_set(kdi_dtrace_set_t transition)1150Sstevel@tonic-gate kdi_dtrace_set(kdi_dtrace_set_t transition)
1160Sstevel@tonic-gate {
1170Sstevel@tonic-gate 	kdi_dtrace_state_t new, cur;
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate 	do {
1200Sstevel@tonic-gate 		cur = kdi_dtrace_state;
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate 		switch (transition) {
1230Sstevel@tonic-gate 		case KDI_DTSET_DTRACE_ACTIVATE:
1240Sstevel@tonic-gate 			if (cur == KDI_DTSTATE_KMDB_BPT_ACTIVE)
1250Sstevel@tonic-gate 				return (EBUSY);
1260Sstevel@tonic-gate 			if (cur == KDI_DTSTATE_DTRACE_ACTIVE)
1270Sstevel@tonic-gate 				return (0);
1280Sstevel@tonic-gate 			new = KDI_DTSTATE_DTRACE_ACTIVE;
1290Sstevel@tonic-gate 			break;
1300Sstevel@tonic-gate 		case KDI_DTSET_DTRACE_DEACTIVATE:
1310Sstevel@tonic-gate 			if (cur == KDI_DTSTATE_KMDB_BPT_ACTIVE)
1320Sstevel@tonic-gate 				return (EBUSY);
1330Sstevel@tonic-gate 			if (cur == KDI_DTSTATE_IDLE)
1340Sstevel@tonic-gate 				return (0);
1350Sstevel@tonic-gate 			new = KDI_DTSTATE_IDLE;
1360Sstevel@tonic-gate 			break;
1370Sstevel@tonic-gate 		case KDI_DTSET_KMDB_BPT_ACTIVATE:
1380Sstevel@tonic-gate 			if (cur == KDI_DTSTATE_DTRACE_ACTIVE)
1390Sstevel@tonic-gate 				return (EBUSY);
1400Sstevel@tonic-gate 			if (cur == KDI_DTSTATE_KMDB_BPT_ACTIVE)
1410Sstevel@tonic-gate 				return (0);
1420Sstevel@tonic-gate 			new = KDI_DTSTATE_KMDB_BPT_ACTIVE;
1430Sstevel@tonic-gate 			break;
1440Sstevel@tonic-gate 		case KDI_DTSET_KMDB_BPT_DEACTIVATE:
1450Sstevel@tonic-gate 			if (cur == KDI_DTSTATE_DTRACE_ACTIVE)
1460Sstevel@tonic-gate 				return (EBUSY);
1470Sstevel@tonic-gate 			if (cur == KDI_DTSTATE_IDLE)
1480Sstevel@tonic-gate 				return (0);
1490Sstevel@tonic-gate 			new = KDI_DTSTATE_IDLE;
1500Sstevel@tonic-gate 			break;
1510Sstevel@tonic-gate 		default:
1520Sstevel@tonic-gate 			return (EINVAL);
1530Sstevel@tonic-gate 		}
1540Sstevel@tonic-gate 	} while (cas32((uint_t *)&kdi_dtrace_state, cur, new) != cur);
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 	return (0);
1570Sstevel@tonic-gate }
158