Merge commit 'ea01a15a654b9e1c7b37d958f4d1911882ed7781'
[unleashed.git] / kernel / os / kdi.c
blob216dc16646798130d359509a58a29d6237ec19bd
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/cpuvar.h>
27 #include <sys/kdi_impl.h>
28 #include <sys/reboot.h>
29 #include <sys/errno.h>
30 #include <sys/atomic.h>
31 #include <sys/kmem.h>
33 kdi_debugvec_t *kdi_dvec;
34 struct modctl *kdi_dmods;
36 static kdi_dtrace_state_t kdi_dtrace_state = KDI_DTSTATE_IDLE;
38 void
39 kdi_dvec_vmready(void)
41 kdi_dvec->dv_kctl_vmready();
42 kdi_dvec->dv_vmready();
45 void
46 kdi_dvec_memavail(void)
49 * The driver will allocate more memory (if requested), and will call
50 * dv_memavail itself.
52 kdi_dvec->dv_kctl_memavail();
55 #if defined(__x86)
56 void
57 kdi_dvec_handle_fault(greg_t trapno, greg_t pc, greg_t sp, int cpuid)
59 kdi_dvec->dv_handle_fault(trapno, pc, sp, cpuid);
61 #endif
64 void
65 kdi_dvec_modavail(void)
67 kdi_dvec->dv_kctl_modavail();
70 void
71 kdi_dvec_thravail(void)
73 kdi_dvec->dv_kctl_thravail();
76 void
77 kdi_dvec_mod_loaded(struct modctl *modp)
79 kdi_dvec->dv_mod_loaded(modp);
82 void
83 kdi_dvec_mod_unloading(struct modctl *modp)
85 kdi_dvec->dv_mod_unloading(modp);
88 kdi_dtrace_state_t
89 kdi_dtrace_get_state(void)
91 return (kdi_dtrace_state);
94 int
95 kdi_dtrace_set(kdi_dtrace_set_t transition)
97 kdi_dtrace_state_t new, cur;
99 do {
100 cur = kdi_dtrace_state;
102 switch (transition) {
103 case KDI_DTSET_DTRACE_ACTIVATE:
104 if (cur == KDI_DTSTATE_KMDB_BPT_ACTIVE)
105 return (EBUSY);
106 if (cur == KDI_DTSTATE_DTRACE_ACTIVE)
107 return (0);
108 new = KDI_DTSTATE_DTRACE_ACTIVE;
109 break;
110 case KDI_DTSET_DTRACE_DEACTIVATE:
111 if (cur == KDI_DTSTATE_KMDB_BPT_ACTIVE)
112 return (EBUSY);
113 if (cur == KDI_DTSTATE_IDLE)
114 return (0);
115 new = KDI_DTSTATE_IDLE;
116 break;
117 case KDI_DTSET_KMDB_BPT_ACTIVATE:
118 if (cur == KDI_DTSTATE_DTRACE_ACTIVE)
119 return (EBUSY);
120 if (cur == KDI_DTSTATE_KMDB_BPT_ACTIVE)
121 return (0);
122 new = KDI_DTSTATE_KMDB_BPT_ACTIVE;
123 break;
124 case KDI_DTSET_KMDB_BPT_DEACTIVATE:
125 if (cur == KDI_DTSTATE_DTRACE_ACTIVE)
126 return (EBUSY);
127 if (cur == KDI_DTSTATE_IDLE)
128 return (0);
129 new = KDI_DTSTATE_IDLE;
130 break;
131 default:
132 return (EINVAL);
134 } while (atomic_cas_32((uint_t *)&kdi_dtrace_state, cur, new) != cur);
136 return (0);