xref: /titanic_44/usr/src/uts/common/os/kdi.c (revision 6dfee4834394825da35b977ca71cdc965bc7b6a4)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/cpuvar.h>
30 #include <sys/kdi_impl.h>
31 #include <sys/reboot.h>
32 #include <sys/errno.h>
33 #include <sys/atomic.h>
34 #include <sys/kmem.h>
35 
36 kdi_debugvec_t *kdi_dvec;
37 
38 static kdi_dtrace_state_t kdi_dtrace_state = KDI_DTSTATE_IDLE;
39 
40 void
41 kdi_dvec_enter(void)
42 {
43 	kdi_dvec->dv_enter();
44 }
45 
46 /*
47  * Called on the CPU being initialized
48  */
49 void
50 kdi_dvec_cpu_init(struct cpu *cp)
51 {
52 	kdi_dvec->dv_kctl_cpu_init();
53 	kdi_dvec->dv_cpu_init(cp);
54 }
55 
56 #if defined(__i386) || defined(__amd64)
57 void
58 kdi_dvec_idt_sync(gate_desc_t *idt)
59 {
60 	kdi_dvec->dv_idt_sync(idt);
61 }
62 #endif	/* __i386 || __amd64 */
63 
64 void
65 kdi_dvec_vmready(void)
66 {
67 	kdi_dvec->dv_kctl_vmready();
68 	kdi_dvec->dv_vmready();
69 }
70 
71 void
72 kdi_dvec_memavail(void)
73 {
74 	/*
75 	 * The driver will allocate more memory (if requested), and will call
76 	 * dv_memavail itself.
77 	 */
78 	kdi_dvec->dv_kctl_memavail();
79 }
80 
81 #if defined(__sparc)
82 void
83 kdi_dvec_cpr_restart(void)
84 {
85 	kdi_dvec->dv_kctl_cpu_init();
86 	kdi_dvec->dv_cpr_restart();
87 }
88 #endif	/* __sparc */
89 
90 void
91 kdi_dvec_modavail(void)
92 {
93 	kdi_dvec->dv_kctl_modavail();
94 }
95 
96 void
97 kdi_dvec_thravail(void)
98 {
99 	kdi_dvec->dv_kctl_thravail();
100 }
101 
102 void
103 kdi_dvec_mod_loaded(struct modctl *modp)
104 {
105 	kdi_dvec->dv_mod_loaded(modp);
106 }
107 
108 void
109 kdi_dvec_mod_unloading(struct modctl *modp)
110 {
111 	kdi_dvec->dv_mod_unloading(modp);
112 }
113 
114 kdi_dtrace_state_t
115 kdi_dtrace_get_state(void)
116 {
117 	return (kdi_dtrace_state);
118 }
119 
120 int
121 kdi_dtrace_set(kdi_dtrace_set_t transition)
122 {
123 	kdi_dtrace_state_t new, cur;
124 
125 	do {
126 		cur = kdi_dtrace_state;
127 
128 		switch (transition) {
129 		case KDI_DTSET_DTRACE_ACTIVATE:
130 			if (cur == KDI_DTSTATE_KMDB_BPT_ACTIVE)
131 				return (EBUSY);
132 			if (cur == KDI_DTSTATE_DTRACE_ACTIVE)
133 				return (0);
134 			new = KDI_DTSTATE_DTRACE_ACTIVE;
135 			break;
136 		case KDI_DTSET_DTRACE_DEACTIVATE:
137 			if (cur == KDI_DTSTATE_KMDB_BPT_ACTIVE)
138 				return (EBUSY);
139 			if (cur == KDI_DTSTATE_IDLE)
140 				return (0);
141 			new = KDI_DTSTATE_IDLE;
142 			break;
143 		case KDI_DTSET_KMDB_BPT_ACTIVATE:
144 			if (cur == KDI_DTSTATE_DTRACE_ACTIVE)
145 				return (EBUSY);
146 			if (cur == KDI_DTSTATE_KMDB_BPT_ACTIVE)
147 				return (0);
148 			new = KDI_DTSTATE_KMDB_BPT_ACTIVE;
149 			break;
150 		case KDI_DTSET_KMDB_BPT_DEACTIVATE:
151 			if (cur == KDI_DTSTATE_DTRACE_ACTIVE)
152 				return (EBUSY);
153 			if (cur == KDI_DTSTATE_IDLE)
154 				return (0);
155 			new = KDI_DTSTATE_IDLE;
156 			break;
157 		default:
158 			return (EINVAL);
159 		}
160 	} while (cas32((uint_t *)&kdi_dtrace_state, cur, new) != cur);
161 
162 	return (0);
163 }
164