xref: /titanic_51/usr/src/uts/common/os/kdi.c (revision f808c858fa61e7769218966759510a8b1190dfcf)
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 2006 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 struct modctl	*kdi_dmods;
38 
39 static kdi_dtrace_state_t kdi_dtrace_state = KDI_DTSTATE_IDLE;
40 
41 void
42 kdi_dvec_enter(void)
43 {
44 	kdi_dvec->dv_enter();
45 }
46 
47 /*
48  * Called on the CPU being initialized
49  */
50 void
51 kdi_dvec_cpu_init(struct cpu *cp)
52 {
53 	kdi_dvec->dv_kctl_cpu_init();
54 	kdi_dvec->dv_cpu_init(cp);
55 }
56 
57 #if defined(__i386) || defined(__amd64)
58 void
59 kdi_dvec_idt_sync(gate_desc_t *idt)
60 {
61 	kdi_dvec->dv_idt_sync(idt);
62 }
63 #endif	/* __i386 || __amd64 */
64 
65 void
66 kdi_dvec_vmready(void)
67 {
68 	kdi_dvec->dv_kctl_vmready();
69 	kdi_dvec->dv_vmready();
70 }
71 
72 void
73 kdi_dvec_memavail(void)
74 {
75 	/*
76 	 * The driver will allocate more memory (if requested), and will call
77 	 * dv_memavail itself.
78 	 */
79 	kdi_dvec->dv_kctl_memavail();
80 }
81 
82 #if defined(__sparc)
83 void
84 kdi_dvec_cpr_restart(void)
85 {
86 	kdi_dvec->dv_kctl_cpu_init();
87 	kdi_dvec->dv_cpr_restart();
88 }
89 #endif	/* __sparc */
90 
91 void
92 kdi_dvec_modavail(void)
93 {
94 	kdi_dvec->dv_kctl_modavail();
95 }
96 
97 void
98 kdi_dvec_thravail(void)
99 {
100 	kdi_dvec->dv_kctl_thravail();
101 }
102 
103 void
104 kdi_dvec_mod_loaded(struct modctl *modp)
105 {
106 	kdi_dvec->dv_mod_loaded(modp);
107 }
108 
109 void
110 kdi_dvec_mod_unloading(struct modctl *modp)
111 {
112 	kdi_dvec->dv_mod_unloading(modp);
113 }
114 
115 kdi_dtrace_state_t
116 kdi_dtrace_get_state(void)
117 {
118 	return (kdi_dtrace_state);
119 }
120 
121 int
122 kdi_dtrace_set(kdi_dtrace_set_t transition)
123 {
124 	kdi_dtrace_state_t new, cur;
125 
126 	do {
127 		cur = kdi_dtrace_state;
128 
129 		switch (transition) {
130 		case KDI_DTSET_DTRACE_ACTIVATE:
131 			if (cur == KDI_DTSTATE_KMDB_BPT_ACTIVE)
132 				return (EBUSY);
133 			if (cur == KDI_DTSTATE_DTRACE_ACTIVE)
134 				return (0);
135 			new = KDI_DTSTATE_DTRACE_ACTIVE;
136 			break;
137 		case KDI_DTSET_DTRACE_DEACTIVATE:
138 			if (cur == KDI_DTSTATE_KMDB_BPT_ACTIVE)
139 				return (EBUSY);
140 			if (cur == KDI_DTSTATE_IDLE)
141 				return (0);
142 			new = KDI_DTSTATE_IDLE;
143 			break;
144 		case KDI_DTSET_KMDB_BPT_ACTIVATE:
145 			if (cur == KDI_DTSTATE_DTRACE_ACTIVE)
146 				return (EBUSY);
147 			if (cur == KDI_DTSTATE_KMDB_BPT_ACTIVE)
148 				return (0);
149 			new = KDI_DTSTATE_KMDB_BPT_ACTIVE;
150 			break;
151 		case KDI_DTSET_KMDB_BPT_DEACTIVATE:
152 			if (cur == KDI_DTSTATE_DTRACE_ACTIVE)
153 				return (EBUSY);
154 			if (cur == KDI_DTSTATE_IDLE)
155 				return (0);
156 			new = KDI_DTSTATE_IDLE;
157 			break;
158 		default:
159 			return (EINVAL);
160 		}
161 	} while (cas32((uint_t *)&kdi_dtrace_state, cur, new) != cur);
162 
163 	return (0);
164 }
165