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