Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/kmdb/kdrv.c
+++ new/usr/src/uts/common/kmdb/kdrv.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26
27 27 /*
28 28 * The driver portion of kmdb, which manages /dev/kmdb and passes requests along
29 29 * to the kmdb misc module (kmdbmod).
30 30 */
31 31
32 32 #include <sys/conf.h>
33 33 #include <sys/stat.h>
34 34 #include <sys/modctl.h>
35 35 #include <sys/ddi.h>
36 36 #include <sys/sunddi.h>
37 37 #include <sys/open.h>
38 38 #include <sys/kobj.h>
39 39 #include <sys/kdi.h>
40 40 #include <sys/policy.h>
41 41 #include <sys/kobj_impl.h>
42 42 #include <sys/kmdb.h>
43 43 #include <sys/sysmacros.h>
44 44 #include <sys/consdev.h>
45 45
46 46 #define KDRV_CFG_MAXLEN 2048
47 47
48 48 static dev_info_t *kdrv_dip;
49 49
50 50 /*ARGSUSED*/
51 51 static int
52 52 kdrv_open(dev_t *dev, int openflags, int otyp, cred_t *credp)
53 53 {
54 54 if (otyp != OTYP_CHR)
55 55 return (EINVAL);
56 56
57 57 if (secpolicy_kmdb(credp) != 0)
58 58 return (EPERM);
59 59
60 60 return (0);
61 61 }
62 62
63 63 /*ARGSUSED*/
64 64 static int
65 65 kdrv_close(dev_t dev, int openflags, int otyp, cred_t *credp)
66 66 {
67 67 return (0);
68 68 }
69 69
70 70 typedef struct kdrv_flags_map {
71 71 const char *fm_name;
72 72 int fm_defval;
73 73 uint_t fm_flag;
74 74 } kdrv_flags_map_t;
75 75
76 76 static const kdrv_flags_map_t kdrv_flags_map[] = {
77 77 { "kmdb-auto-entry", 1, KMDB_F_AUTO_ENTRY },
78 78 { "kmdb-trap-noswitch", 0, KMDB_F_TRAP_NOSWITCH },
79 79 { "kmdb-driver-debug", 0, KMDB_F_DRV_DEBUG },
80 80 { NULL }
81 81 };
82 82
83 83 static int
84 84 kdrv_activate(intptr_t arg)
85 85 {
86 86 uint_t flags;
87 87 size_t memsz;
88 88 char *cfg;
89 89 size_t got;
90 90 int i, rc;
91 91
92 92 #if defined(__x86)
93 93 if (cons_polledio == NULL) {
94 94 cmn_err(CE_NOTE, "kmdb not supported: no console polled I/O");
95 95 return (ENOTSUP);
96 96 }
97 97 #endif
98 98
99 99 memsz = ddi_prop_get_int(DDI_DEV_T_ANY, kdrv_dip,
100 100 DDI_PROP_DONTPASS, "kmdb-memseg-size", 0);
101 101
102 102 for (flags = 0, i = 0; kdrv_flags_map[i].fm_name != NULL; i++) {
103 103 const kdrv_flags_map_t *fm = &kdrv_flags_map[i];
104 104 if (ddi_prop_get_int(DDI_DEV_T_ANY, kdrv_dip, DDI_PROP_DONTPASS,
105 105 (char *)fm->fm_name, fm->fm_defval))
106 106 flags |= fm->fm_flag;
107 107 }
108 108
109 109 cfg = kmem_alloc(KDRV_CFG_MAXLEN, KM_SLEEP);
110 110
111 111 if ((rc = copyinstr((caddr_t)arg, cfg, KDRV_CFG_MAXLEN, &got)) != 0) {
112 112 kmem_free(cfg, KDRV_CFG_MAXLEN);
113 113 return (rc == ENAMETOOLONG ? E2BIG : EFAULT);
114 114 }
115 115
116 116 rc = kctl_modload_activate(memsz, cfg, flags);
117 117
118 118 kmem_free(cfg, KDRV_CFG_MAXLEN);
119 119
120 120 return (rc);
121 121 }
122 122
123 123 static int
124 124 kdrv_deactivate(void)
125 125 {
126 126 return (kctl_deactivate());
127 127 }
128 128
129 129 /*ARGSUSED*/
130 130 static int
131 131 kdrv_ioctl(dev_t dev, int cmd, intptr_t arg, int flags, cred_t *credp,
132 132 int *rvalp)
133 133 {
134 134 switch (cmd) {
135 135 case KMDB_IOC_START:
136 136 return (kdrv_activate(arg));
137 137
138 138 case KMDB_IOC_STOP:
139 139 return (kdrv_deactivate());
140 140
141 141 default:
142 142 return (EINVAL);
143 143 }
144 144 }
145 145
146 146 /*ARGSUSED*/
147 147 static int
148 148 kdrv_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
149 149 {
150 150 int error = DDI_SUCCESS;
151 151
152 152 switch (infocmd) {
153 153 case DDI_INFO_DEVT2DEVINFO:
154 154 *result = kdrv_dip;
155 155 break;
156 156 case DDI_INFO_DEVT2INSTANCE:
157 157 *result = (void *)(uintptr_t)getminor((dev_t)arg);
158 158 break;
159 159 default:
160 160 *result = NULL;
161 161 error = DDI_FAILURE;
162 162 }
163 163
164 164 return (error);
165 165 }
166 166
167 167 static int
168 168 kdrv_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
169 169 {
170 170 if (cmd != DDI_ATTACH)
171 171 return (DDI_FAILURE);
172 172
173 173 if (ddi_create_minor_node(dip, ddi_get_name(dip), S_IFCHR,
174 174 ddi_get_instance(dip), DDI_PSEUDO, 0) != DDI_SUCCESS)
175 175 return (DDI_FAILURE);
176 176
177 177 kdrv_dip = dip;
178 178
179 179 if (kctl_attach(dip) != 0)
180 180 return (DDI_FAILURE);
181 181
182 182 return (DDI_SUCCESS);
183 183 }
184 184
185 185 static int
186 186 kdrv_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
187 187 {
188 188 if (cmd != DDI_DETACH)
189 189 return (DDI_FAILURE);
190 190
191 191 if (kctl_detach() == EBUSY)
192 192 return (DDI_FAILURE);
193 193
194 194 ddi_remove_minor_node(dip, NULL);
195 195
196 196 return (DDI_SUCCESS);
197 197 }
198 198
199 199 static struct cb_ops kdrv_cb_ops = {
200 200 kdrv_open,
201 201 kdrv_close,
202 202 nodev, /* not a block driver */
203 203 nodev, /* no print routine */
204 204 nodev, /* no dump routine */
205 205 nodev, /* no read routine */
206 206 nodev, /* no write routine */
207 207 kdrv_ioctl,
208 208 nodev, /* no devmap routine */
209 209 nodev, /* no mmap routine */
210 210 nodev, /* no segmap routine */
211 211 nochpoll, /* no chpoll routine */
212 212 ddi_prop_op,
213 213 0, /* not a STREAMS driver */
214 214 D_NEW | D_MP, /* safe for multi-thread/multi-processor */
215 215 };
216 216
217 217 static struct dev_ops kdrv_ops = {
218 218 DEVO_REV, /* devo_rev */
219 219 0, /* devo_refcnt */
220 220 kdrv_getinfo, /* devo_getinfo */
221 221 nulldev, /* devo_identify */
222 222 nulldev, /* devo_probe */
223 223 kdrv_attach, /* devo_attach */
224 224 kdrv_detach, /* devo_detach */
225 225 nodev, /* devo_reset */
226 226 &kdrv_cb_ops, /* devo_cb_ops */
227 227 (struct bus_ops *)0, /* devo_bus_ops */
228 228 NULL, /* devo_power */
229 229 ddi_quiesce_not_needed, /* devo_quiesce */
↓ open down ↓ |
229 lines elided |
↑ open up ↑ |
230 230 };
231 231
232 232 static struct modldrv modldrv = {
233 233 &mod_driverops,
234 234 "kmdb driver",
235 235 &kdrv_ops
236 236 };
237 237
238 238 static struct modlinkage modlinkage = {
239 239 MODREV_1,
240 - (void *)&modldrv,
241 - NULL
240 + { (void *)&modldrv, NULL }
242 241 };
243 242
244 243 int
245 244 _init(void)
246 245 {
247 246 return (mod_install(&modlinkage));
248 247 }
249 248
250 249 int
251 250 _info(struct modinfo *modinfop)
252 251 {
253 252 return (mod_info(&modlinkage, modinfop));
254 253 }
255 254
256 255 int
257 256 _fini(void)
258 257 {
259 258 return (mod_remove(&modlinkage));
260 259 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX