xref: /titanic_41/usr/src/cmd/mdb/common/kmdb/kctl/kctl.h (revision 2278144afd2005b3eabcfd9bc412fe5ceb78749d)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _KCTL_H
27 #define	_KCTL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <kmdb/kmdb_auxv.h>
32 #include <kmdb/kmdb_wr.h>
33 
34 #include <sys/ddi.h>
35 #include <sys/sunddi.h>
36 #include <sys/kdi.h>
37 #include <sys/modctl.h>
38 #include <sys/ksynch.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 typedef enum {
45 	KCTL_ST_INACTIVE = 0,		/* kmdb is inactive */
46 	KCTL_ST_DSEG_ALLOCED,		/* kmdb segment has been allocated */
47 	KCTL_ST_INITIALIZED,		/* kmdb_init has been called */
48 	KCTL_ST_KCTL_PREACTIVATED,	/* kctl preactivation completed */
49 	KCTL_ST_MOD_NOTIFIERS,		/* krtld module notifiers registered */
50 	KCTL_ST_THREAD_STARTED,		/* WR queue thread started */
51 	KCTL_ST_DBG_ACTIVATED,		/* kmdb activated */
52 	KCTL_ST_KCTL_ACTIVATED,		/* kctl activated */
53 	KCTL_ST_ACTIVE,			/* kernel is aware of kmdb activation */
54 	KCTL_ST_DEACTIVATING		/* debugger is being deactivated */
55 } kctl_state_t;
56 
57 typedef enum {
58 	KCTL_WR_ST_RUN,			/* WR queue thread is running */
59 	KCTL_WR_ST_STOP,		/* WR queue thread is stopping */
60 	KCTL_WR_ST_STOPPED		/* WR queue thread has stopped */
61 } kctl_wr_state_t;
62 
63 typedef struct kctl {
64 	dev_info_t *kctl_drv_dip;	/* Driver's device info structure */
65 	size_t kctl_memgoalsz;		/* Desired size of debugger memory */
66 	caddr_t	kctl_dseg;		/* Debugger segment (Oz) address */
67 	size_t kctl_dseg_size;		/* Debugger segment (Oz) size */
68 	caddr_t kctl_mrbase;		/* Add'l Oz memory range base address */
69 	size_t kctl_mrsize;		/* Add'l Oz memory range size */
70 	vnode_t kctl_vp;		/* vnode used to allocate dbgr seg */
71 	kctl_state_t kctl_state;	/* State of debugger */
72 	uint_t kctl_boot_loaded;	/* Set if debugger loaded at boot */
73 	struct bootops *kctl_boot_ops;	/* Boot operations (during init only) */
74 	const char *kctl_execname;	/* Path of this module */
75 	uint_t kctl_wr_avail;		/* Work available on the WR queue */
76 	ksema_t kctl_wr_avail_sem;	/* For WR thr: Work avail on WR queue */
77 	kthread_t *kctl_wr_thr;		/* Thread that processes WR queue */
78 	kctl_wr_state_t kctl_wr_state;	/* State of WR queue thread */
79 	kmutex_t kctl_lock;		/* serializes (de)activation */
80 	kcondvar_t kctl_wr_cv;		/* WR queue thread completion */
81 	kmutex_t kctl_wr_lock;		/* WR queue thread completion */
82 	uint_t kctl_flags;		/* KMDB_F_* from kmdb.h */
83 #ifdef __sparc
84 	caddr_t kctl_tba;		/* kmdb's native trap table */
85 #endif
86 } kctl_t;
87 
88 extern kctl_t kctl;
89 
90 struct bootops;
91 
92 extern void kctl_dprintf(const char *, ...);
93 extern void kctl_warn(const char *, ...);
94 
95 extern int kctl_preactivate_isadep(void);
96 extern int kctl_activate_isadep(kdi_debugvec_t *);
97 extern void kctl_depreactivate_isadep(void);
98 extern void kctl_deactivate_isadep(void);
99 extern void kctl_cleanup(void);
100 
101 extern void *kctl_boot_tmpinit(void);
102 extern void kctl_boot_tmpfini(void *);
103 
104 extern void kctl_auxv_init(kmdb_auxv_t *, const char *, const char **, void *);
105 extern void kctl_auxv_init_isadep(kmdb_auxv_t *, void *);
106 extern void kctl_auxv_fini(kmdb_auxv_t *);
107 extern void kctl_auxv_fini_isadep(kmdb_auxv_t *);
108 #ifdef sun4v
109 extern void kctl_auxv_set_promif(kmdb_auxv_t *);
110 extern void kctl_switch_promif(void);
111 #endif
112 
113 extern void kctl_wrintr(void);
114 extern void kctl_wrintr_fire(void);
115 extern void kctl_wr_thr_start(void);
116 extern void kctl_wr_thr_stop(void);
117 extern void kctl_wr_thr_join(void);
118 
119 extern int kctl_mod_decompress(struct modctl *);
120 extern void kctl_mod_loaded(struct modctl *);
121 extern void kctl_mod_changed(uint_t, struct modctl *);
122 extern void kctl_mod_notify_reg(void);
123 extern void kctl_mod_notify_unreg(void);
124 
125 extern void kctl_dmod_init(void);
126 extern void kctl_dmod_fini(void);
127 extern void kctl_dmod_sync(void);
128 extern void kctl_dmod_autoload(const char *);
129 extern void kctl_dmod_unload_all(void);
130 extern void kctl_dmod_path_reset(void);
131 
132 extern int kctl_wr_process(void);
133 extern void kctl_wr_unload(void);
134 
135 extern char *kctl_basename(char *);
136 extern char *kctl_strdup(const char *);
137 extern void kctl_strfree(char *);
138 
139 #if defined(__sparc)
140 extern kthread_t *kctl_curthread_set(kthread_t *);
141 #endif
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif /* _KCTL_H */
148