Print this page
5218 posix definition of NULL
correct unistd.h and iso/stddef_iso.h
update gate source affected
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mdb/common/modules/usba/usb.c
+++ new/usr/src/cmd/mdb/common/modules/usba/usb.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 2007 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #pragma ident "%Z%%M% %I% %E% SMI"
27 27
28 28 #include <stddef.h>
29 29 #include <sys/mdb_modapi.h>
30 30 #include <mdb/mdb_ks.h>
31 31
32 32 #include <sys/usb/usba.h>
33 33 #include <sys/ddi_impldefs.h>
34 34 #include <sys/usb/usba/usba_types.h>
35 35 #include <sys/usb/usba/usba_impl.h>
36 36 #include <sys/usb/usba/hcdi_impl.h>
37 37 #include <sys/file.h>
38 38 #include <sys/sunndi.h>
39 39 #include <unistd.h>
40 40
41 41
42 42 /*
43 43 * Prototypes
44 44 */
45 45 /* usba.c */
46 46 extern uintptr_t mdb_usba_get_usba_device(uintptr_t);
47 47 extern uintptr_t mdb_usba_hcdi_get_hcdi(struct dev_info *);
48 48
49 49 /*
50 50 * Defines
51 51 */
52 52 /* dcmd options */
53 53 #define USB_DUMP_VERBOSE 0x01
54 54 #define USB_DUMP_ACTIVE_PIPES 0x02
55 55
56 56 /* Hardcoded slop factor designed into debug buf logic */
57 57 #define USB_DEBUG_SIZE_EXTRA_ALLOC 8
58 58
59 59
60 60 /*
61 61 * Callback arg struct for find_dip (callback func used in usba_device2devinfo).
62 62 */
63 63 typedef struct usba_device2devinfo_data {
64 64 uintptr_t u2d_target_usb_dev_p; /* one we're looking for */
65 65 uintptr_t *u2d_dip_addr; /* Where to store result */
66 66 boolean_t u2d_found; /* Match found */
67 67 } usba_device2devinfo_cbdata_t;
68 68
69 69
70 70 /*
71 71 * Callback for usba_device2dip.
72 72 * Callback called from the devinfo_children walk invoked in usba_device2dip.
73 73 *
74 74 * For the current dip, get the (potential) pointer to its usba_device_t
75 75 * struct.
76 76 * See if this pointer matches the address of the usba_device_t we're looking
77 77 * for (passed in as usb_dev_p). If so, stuff its value in u2d_dip_addr,
78 78 * and terminate the walk.
79 79 *
80 80 * - dip_addr is the address in core of the dip currently being processed by the
81 81 * walk
82 82 * - local_dip is a pointer to a copy of the struct dev_info in local memory
83 83 * - cb_data is the addr of the callback arg the walker was invoked with
84 84 * (passed through transparently from walk invoker).
85 85 *
86 86 * Returns:
87 87 * - WALK_NEXT on success (match not found yet)
88 88 * - WALK_ERR on errors.
89 89 * - WALK_DONE is returned, cb_data.found is set to TRUE, and
90 90 * *cb_data.u2d_dip_addr is set to the matched dip addr if a dip corresponding
↓ open down ↓ |
90 lines elided |
↑ open up ↑ |
91 91 * to the desired usba_device_t* is found.
92 92 */
93 93 /*ARGSUSED*/
94 94 static int
95 95 find_dip(uintptr_t dip_addr, const void *local_dip, void *cb_arg)
96 96 {
97 97 uintptr_t cur_usb_dev;
98 98 usba_device2devinfo_cbdata_t *cb_data =
99 99 (usba_device2devinfo_cbdata_t *)cb_arg;
100 100
101 - if ((cur_usb_dev = mdb_usba_get_usba_device(dip_addr)) == NULL) {
101 + if ((cur_usb_dev = mdb_usba_get_usba_device(dip_addr)) == (uintptr_t)NULL) {
102 102 /*
103 103 * If there's no corresponding usba_device_t, this dip isn't
104 104 * a usb node. Might be an sd node. Ignore it.
105 105 */
106 106
107 107 return (WALK_NEXT);
108 108 }
109 109
110 110 if (cur_usb_dev == cb_data->u2d_target_usb_dev_p) {
111 111 *cb_data->u2d_dip_addr = dip_addr;
112 112 cb_data->u2d_found = TRUE;
113 113
114 114 return (WALK_DONE);
115 115 }
116 116
117 117 return (WALK_NEXT);
118 118 }
119 119
120 120
121 121 /*
122 122 * Given a usba_device pointer, figure out which dip is associated with it.
123 123 * Relies on usba_device.usb_root_hub_dip being accurate.
124 124 *
125 125 * - usb_dev_addr is a pointer to a usba_device_t in core.
126 126 * - dip_addr is the address of a uintptr_t to receive the address in core
127 127 * of the found dip (if any).
128 128 *
129 129 * Returns:
130 130 * 0 on success (no match found)
131 131 * 1 on success (match found)
132 132 * -1 on errors.
133 133 */
134 134 static int
135 135 usba_device2dip(uintptr_t usb_dev_addr, uintptr_t *dip_addr)
136 136 {
137 137 usba_device_t usb_dev;
138 138 usba_device2devinfo_cbdata_t cb_data;
139 139
140 140 /*
141 141 * Walk all USB children of the root hub devinfo.
142 142 * The callback func looks for a match on the usba_device address.
143 143 */
144 144 cb_data.u2d_target_usb_dev_p = usb_dev_addr;
145 145 cb_data.u2d_dip_addr = dip_addr;
146 146 cb_data.u2d_found = FALSE;
147 147
148 148 if (mdb_vread(&usb_dev, sizeof (usba_device_t),
149 149 usb_dev_addr) == -1) {
150 150 mdb_warn("failed to read usba_device struct");
151 151
152 152 return (-1);
153 153 }
154 154
155 155 /*
156 156 * Walk devinfo children starting with the root hub node,
157 157 * looking for a match on the usba_device pointer (which is what
158 158 * find_dip does).
159 159 * Result is placed in cb_data.dip_addr.
160 160 */
161 161 if (mdb_pwalk("devinfo_children", find_dip, &cb_data,
162 162 (uintptr_t)usb_dev.usb_root_hub_dip) != 0) {
163 163 mdb_warn("failed to walk devinfo_children");
164 164
165 165 return (-1);
166 166 }
167 167
168 168 if (cb_data.u2d_found == TRUE) {
169 169
170 170 return (1);
171 171 }
172 172
173 173 return (0);
174 174 }
↓ open down ↓ |
63 lines elided |
↑ open up ↑ |
175 175
176 176
177 177 /*
178 178 * Generic walker usba_list_entry_t walker.
179 179 * Works for any usba_list_entry_t list.
180 180 */
181 181 int
182 182 usba_list_walk_init(mdb_walk_state_t *wsp)
183 183 {
184 184 /* Must have a start addr. */
185 - if (wsp->walk_addr == NULL) {
185 + if (wsp->walk_addr == (uintptr_t)NULL) {
186 186 mdb_warn("not a global walk. Starting address required\n");
187 187
188 188 return (WALK_ERR);
189 189 }
190 190
191 191 return (WALK_NEXT);
192 192 }
193 193
194 194
195 195 /*
196 196 * Generic list walker step routine.
197 197 * NOTE: multiple walkers share this routine.
198 198 */
199 199 int
200 200 usba_list_walk_step(mdb_walk_state_t *wsp)
201 201 {
202 202 int status;
203 203 usba_list_entry_t list_entry;
204 204
205 205 if (mdb_vread(&list_entry, sizeof (usba_list_entry_t),
206 206 (uintptr_t)wsp->walk_addr) == -1) {
207 207 mdb_warn("failed to read usba_list_entry_t at %p",
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
208 208 wsp->walk_addr);
209 209
210 210 return (WALK_ERR);
211 211 }
212 212
213 213 status = wsp->walk_callback(wsp->walk_addr, &list_entry,
214 214 wsp->walk_cbdata);
215 215 wsp->walk_addr = (uintptr_t)list_entry.next;
216 216
217 217 /* Check if we're at the last element */
218 - if (wsp->walk_addr == NULL) {
218 + if (wsp->walk_addr == (uintptr_t)NULL) {
219 219
220 220 return (WALK_DONE);
221 221 }
222 222
223 223 return (status);
224 224 }
225 225
226 226
227 227 /*
228 228 * usb_pipe_handle walker
229 229 * Given a pointer to a usba_device_t, walk the array of endpoint
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
230 230 * pipe_handle lists.
231 231 * For each list, traverse the list, invoking the callback on each element.
232 232 *
233 233 * Note this function takes the address of a usba_device struct (which is
234 234 * easily obtainable), but actually traverses a sub-portion of the struct
235 235 * (which address is not so easily obtainable).
236 236 */
237 237 int
238 238 usb_pipe_handle_walk_init(mdb_walk_state_t *wsp)
239 239 {
240 - if (wsp->walk_addr == NULL) {
240 + if (wsp->walk_addr == (uintptr_t)NULL) {
241 241 mdb_warn("not a global walk; usba_device_t required\n");
242 242
243 243 return (WALK_ERR);
244 244 }
245 245
246 246 wsp->walk_data = mdb_alloc((sizeof (usba_ph_impl_t)) * USBA_N_ENDPOINTS,
247 247 UM_SLEEP | UM_GC);
248 248
249 249 /*
250 250 * Read the usb_ph_list array into local memory.
251 251 * Set start address to first element/endpoint in usb_pipehandle_list
252 252 */
253 253 if (mdb_vread(wsp->walk_data,
254 254 (sizeof (usba_ph_impl_t)) * USBA_N_ENDPOINTS,
255 255 (uintptr_t)((size_t)(wsp->walk_addr) +
256 256 offsetof(usba_device_t, usb_ph_list))) == -1) {
257 257 mdb_warn("failed to read usb_pipehandle_list at %p",
258 258 wsp->walk_addr);
259 259
260 260 return (WALK_ERR);
261 261 }
262 262
263 263 wsp->walk_arg = 0;
264 264
265 265 return (WALK_NEXT);
266 266 }
267 267
268 268
269 269 int
270 270 usb_pipe_handle_walk_step(mdb_walk_state_t *wsp)
271 271 {
272 272 int status;
273 273 usba_ph_impl_t *impl_list = (usba_ph_impl_t *)(wsp->walk_data);
274 274 intptr_t index = (intptr_t)wsp->walk_arg;
275 275
276 276 /* Find the first valid endpoint, starting from where we left off. */
277 277 while ((index < USBA_N_ENDPOINTS) &&
278 278 (impl_list[index].usba_ph_data == NULL)) {
279 279 index++;
280 280 }
281 281
282 282 /* No more valid endpoints. */
283 283 if (index >= USBA_N_ENDPOINTS) {
284 284
285 285 return (WALK_DONE);
286 286 }
287 287
288 288 status = wsp->walk_callback((uintptr_t)impl_list[index].usba_ph_data,
289 289 wsp->walk_data, wsp->walk_cbdata);
290 290
291 291 /* Set up to start at next pipe handle next time. */
292 292 wsp->walk_arg = (void *)(index + 1);
293 293
294 294 return (status);
295 295 }
296 296
297 297
298 298 /*
299 299 * Given the address of a usba_pipe_handle_data_t, dump summary info.
300 300 */
301 301 /*ARGSUSED*/
302 302 int
303 303 usb_pipe_handle(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
304 304 {
305 305 char *dir, *type, *state;
306 306 usb_ep_descr_t ept_descr;
307 307 usba_pipe_handle_data_t pipe_handle;
308 308 usba_ph_impl_t ph_impl;
309 309
310 310 if (!(flags & DCMD_ADDRSPEC)) {
311 311
312 312 return (DCMD_USAGE);
313 313 }
314 314
315 315 if (mdb_vread(&pipe_handle,
316 316 sizeof (usba_pipe_handle_data_t), addr) == -1) {
317 317 mdb_warn("failed to read pipe handle at %p", addr);
318 318
319 319 return (DCMD_ERR);
320 320 }
321 321
322 322 if (mdb_vread(&ph_impl, sizeof (usba_ph_impl_t),
323 323 (uintptr_t)pipe_handle.p_ph_impl) == -1) {
324 324 state = "*******";
325 325 } else {
326 326 switch (ph_impl.usba_ph_state) {
327 327 case USB_PIPE_STATE_CLOSED:
328 328 state = "CLOSED ";
329 329 break;
330 330
331 331 case USB_PIPE_STATE_IDLE:
332 332 state = "IDLE ";
333 333 break;
334 334
335 335 case USB_PIPE_STATE_ACTIVE:
336 336 state = "ACTIVE ";
337 337 break;
338 338
339 339 case USB_PIPE_STATE_ERROR:
340 340 state = "ERROR ";
341 341 break;
342 342
343 343 case USB_PIPE_STATE_CLOSING:
344 344 state = "CLOSING";
345 345 break;
346 346
347 347 default:
348 348 state = "ILLEGAL";
349 349 break;
350 350 }
351 351 }
352 352
353 353 bcopy(&pipe_handle.p_ep, &ept_descr, sizeof (usb_ep_descr_t));
354 354
355 355 if (DCMD_HDRSPEC(flags)) {
356 356 mdb_printf("\n %<u>%-3s %5s %3s %7s %-?s %-?s %-?s%</u>\n",
357 357 "EP", "TYPE ", "DIR", "STATE ", "P_HANDLE", "P_POLICY",
358 358 "EP DESCR");
359 359 }
360 360
361 361 dir = ((ept_descr.bEndpointAddress & USB_EP_DIR_MASK) &
362 362 USB_EP_DIR_IN) ? "In " : "Out";
363 363 switch (ept_descr.bmAttributes & USB_EP_ATTR_MASK) {
364 364 case USB_EP_ATTR_CONTROL:
365 365 type = "Cntrl";
366 366 break;
367 367
368 368 case USB_EP_ATTR_ISOCH:
369 369 type = "Isoch";
370 370 break;
371 371
372 372 case USB_EP_ATTR_BULK:
373 373 type = "Bulk ";
374 374 break;
375 375
376 376 case USB_EP_ATTR_INTR:
377 377 type = "Intr ";
378 378 break;
379 379
380 380 default:
381 381 type = "*****";
382 382 break;
383 383 }
384 384
385 385 mdb_printf(" %3d %5s %3s %7s %-?p %-?p %-?p\n",
386 386 ept_descr.bEndpointAddress & USB_EP_NUM_MASK, type, dir, state,
387 387 addr, addr + offsetof(usba_pipe_handle_data_t, p_policy),
388 388 addr + offsetof(usba_pipe_handle_data_t, p_ep));
389 389
390 390 return (DCMD_OK);
391 391 }
392 392
393 393
394 394 /*
395 395 * usba_device walker:
↓ open down ↓ |
145 lines elided |
↑ open up ↑ |
396 396 *
397 397 * walks the chain of usba_device structs headed by usba_device_list in usba.c
398 398 * NOTE: It uses the generic list walk step routine usba_list_walk_step.
399 399 * No walk_fini routine is needed.
400 400 */
401 401 int
402 402 usba_device_walk_init(mdb_walk_state_t *wsp)
403 403 {
404 404 usba_list_entry_t list_entry;
405 405
406 - if (wsp->walk_addr != NULL) {
406 + if (wsp->walk_addr != (uintptr_t)NULL) {
407 407 mdb_warn(
408 408 "global walk only. Must be invoked without an address\n");
409 409
410 410 return (WALK_ERR);
411 411 }
412 412
413 413 if (mdb_readvar(&list_entry, "usba_device_list") == -1) {
414 414 mdb_warn("failed to read usba_device_list");
415 415
416 416 return (WALK_ERR);
417 417 }
418 418
419 419 /* List head is not part of usba_device_t, get first usba_device_t */
420 420 wsp->walk_addr = (uintptr_t)list_entry.next;
421 421
422 422 return (WALK_NEXT);
423 423 }
424 424
425 425
426 426 /*
427 427 * usba_device dcmd
428 428 * Given the address of a usba_device struct, dump summary info
429 429 * -v: Print more (verbose) info
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
430 430 * -p: Walk/dump all open pipes for this usba_device
431 431 */
432 432 /*ARGSUSED*/
433 433 int
434 434 usba_device(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
435 435 {
436 436 int status;
437 437 char pathname[MAXNAMELEN];
438 438 char dname[MODMAXNAMELEN + 1] = "<unatt>"; /* Driver name */
439 439 char drv_statep[MODMAXNAMELEN+ 10];
440 - uint_t usb_flag = NULL;
440 + uint_t usb_flag = 0;
441 441 boolean_t no_driver_attached = FALSE;
442 442 uintptr_t dip_addr;
443 443 struct dev_info devinfo;
444 444
445 445 if (!(flags & DCMD_ADDRSPEC)) {
446 446 /* Global walk */
447 447 if (mdb_walk_dcmd("usba_device", "usba_device", argc,
448 448 argv) == -1) {
449 449 mdb_warn("failed to walk usba_device");
450 450
451 451 return (DCMD_ERR);
452 452 }
453 453
454 454 return (DCMD_OK);
455 455 }
456 456
457 457 if (mdb_getopts(argc, argv,
458 458 'p', MDB_OPT_SETBITS, USB_DUMP_ACTIVE_PIPES, &usb_flag,
459 459 'v', MDB_OPT_SETBITS, USB_DUMP_VERBOSE, &usb_flag, NULL) != argc) {
460 460
461 461 return (DCMD_USAGE);
462 462 }
463 463
464 464 if (usb_flag && !(DCMD_HDRSPEC(flags))) {
465 465 mdb_printf("\n");
466 466 }
467 467
468 468 if (DCMD_HDRSPEC(flags)) {
469 469 mdb_printf("%<u>%-15s %4s %-?s %-42s%</u>\n",
470 470 "NAME", "INST", "DIP", "PATH ");
471 471 }
472 472
473 473 status = usba_device2dip(addr, &dip_addr);
474 474 /*
475 475 * -1 = error
476 476 * 0 = no error, no match
477 477 * 1 = no error, match
478 478 */
479 479 if (status != 1) {
480 480 if (status == -1) {
481 481 mdb_warn("error looking for dip for usba_device %p",
482 482 addr);
483 483 } else {
484 484 mdb_warn("failed to find dip for usba_device %p\n",
485 485 addr);
486 486 }
487 487 mdb_warn("dip and statep unobtainable\n");
488 488
489 489 return (DCMD_ERR);
490 490 }
491 491
492 492 /* Figure out what driver (name) is attached to this node. */
493 493 (void) mdb_devinfo2driver(dip_addr, (char *)dname, sizeof (dname));
494 494
495 495 if (mdb_vread(&devinfo, sizeof (struct dev_info),
496 496 dip_addr) == -1) {
497 497 mdb_warn("failed to read devinfo");
498 498
499 499 return (DCMD_ERR);
500 500 }
501 501
↓ open down ↓ |
51 lines elided |
↑ open up ↑ |
502 502 if (!(DDI_CF2(&devinfo))) {
503 503 no_driver_attached = TRUE;
504 504 }
505 505
506 506 (void) mdb_ddi_pathname(dip_addr, pathname, sizeof (pathname));
507 507 mdb_printf("%-15s %2d %-?p %s\n", dname, devinfo.devi_instance,
508 508 dip_addr, pathname);
509 509
510 510 if (usb_flag & USB_DUMP_VERBOSE) {
511 511 int i;
512 - uintptr_t statep = NULL;
512 + uintptr_t statep = (uintptr_t)NULL;
513 513 char *string_descr;
514 514 char **config_cloud, **conf_str_descr;
515 515 usb_dev_descr_t usb_dev_descr;
516 516 usba_device_t usba_device_struct;
517 517
518 518 if (mdb_vread(&usba_device_struct,
519 519 sizeof (usba_device_t), addr) == -1) {
520 520 mdb_warn("failed to read usba_device struct");
521 521
522 522 return (DCMD_ERR);
523 523 }
524 524
525 525 mdb_printf(" usba_device: %-16p\n\n", (usba_device_t *)addr);
526 526
527 527 if (mdb_vread(&usb_dev_descr, sizeof (usb_dev_descr),
528 528 (uintptr_t)usba_device_struct.usb_dev_descr) == -1) {
529 529 mdb_warn("failed to read usb_dev_descr_t struct");
530 530
531 531 return (DCMD_ERR);
532 532 }
533 533
534 534 mdb_printf("\n idVendor: 0x%04x idProduct: 0x%04x "
535 535 "usb_addr: 0x%02x\n", usb_dev_descr.idVendor,
536 536 usb_dev_descr.idProduct, usba_device_struct.usb_addr);
537 537
538 538 /* Get the string descriptor string into local space. */
539 539 string_descr = (char *)mdb_alloc(USB_MAXSTRINGLEN, UM_GC);
540 540
541 541 if (usba_device_struct.usb_mfg_str == NULL) {
542 542 (void) strcpy(string_descr, "<No Manufacturer String>");
543 543 } else {
544 544 if (mdb_readstr(string_descr, USB_MAXSTRINGLEN,
545 545 (uintptr_t)usba_device_struct.usb_mfg_str) == -1) {
546 546 mdb_warn("failed to read manufacturer "
547 547 "string descriptor");
548 548 (void) strcpy(string_descr, "???");
549 549 }
550 550 }
551 551 mdb_printf("\n Manufacturer String:\t%s\n", string_descr);
552 552
553 553 if (usba_device_struct.usb_product_str == NULL) {
554 554 (void) strcpy(string_descr, "<No Product String>");
555 555 } else {
556 556 if (mdb_readstr(string_descr, USB_MAXSTRINGLEN,
557 557 (uintptr_t)usba_device_struct.usb_product_str) ==
558 558 -1) {
559 559 mdb_warn("failed to read product string "
560 560 "descriptor");
561 561 (void) strcpy(string_descr, "???");
562 562 }
563 563 }
564 564 mdb_printf(" Product String:\t\t%s\n", string_descr);
565 565
566 566 if (usba_device_struct.usb_serialno_str == NULL) {
567 567 (void) strcpy(string_descr, "<No SerialNumber String>");
568 568 } else {
569 569 if (mdb_readstr(string_descr, USB_MAXSTRINGLEN,
570 570 (uintptr_t)usba_device_struct.usb_serialno_str) ==
571 571 -1) {
572 572 mdb_warn("failed to read serial number string "
573 573 "descriptor");
574 574 (void) strcpy(string_descr, "???");
575 575 }
576 576 }
577 577 mdb_printf(" SerialNumber String:\t%s\n", string_descr);
578 578
579 579 if (no_driver_attached) {
580 580 mdb_printf("\n");
581 581 } else {
582 582 mdb_printf(" state_p: ");
583 583
584 584 /*
585 585 * Given the dip, find the associated statep. The
586 586 * convention to generate this soft state anchor is:
587 587 * <driver_name>_statep
588 588 */
589 589 (void) mdb_snprintf(drv_statep, sizeof (drv_statep),
590 590 "%s_statep", dname);
591 591 if (mdb_devinfo2statep(dip_addr, drv_statep,
592 592 &statep) == -1) {
593 593 mdb_warn("failed to find %s state struct for "
594 594 "dip %p", drv_statep, dip_addr);
595 595
596 596 return (DCMD_ERR);
597 597 }
598 598 mdb_printf("%-?p\n", statep);
599 599 }
600 600
601 601 config_cloud = (char **)mdb_alloc(sizeof (void *) *
602 602 usba_device_struct.usb_n_cfgs, UM_GC);
603 603
604 604 conf_str_descr = (char **)mdb_alloc(sizeof (void *) *
605 605 usba_device_struct.usb_n_cfgs, UM_GC);
606 606
607 607 if ((usba_device_struct.usb_cfg_array) &&
608 608 (usba_device_struct.usb_cfg_str_descr)) {
609 609 if ((mdb_vread(config_cloud, sizeof (void *) *
610 610 usba_device_struct.usb_n_cfgs,
611 611 (uintptr_t)usba_device_struct.usb_cfg_array) ==
612 612 -1) || (mdb_vread(conf_str_descr, sizeof (void *)
613 613 * usba_device_struct.usb_n_cfgs, (uintptr_t)
614 614 usba_device_struct.usb_cfg_str_descr)) == -1) {
615 615
616 616 mdb_warn("failed to read config cloud pointers");
617 617
618 618 } else {
619 619
620 620 mdb_printf("\n Device Config Clouds:\n"
621 621 " Index\tConfig\t\tConfiguration "
622 622 "String\n"
623 623 " -----\t------\t\t"
624 624 "--------------------\n");
625 625
626 626 for (i = 0; i < usba_device_struct.usb_n_cfgs;
627 627 i++) {
628 628 if (mdb_readstr(string_descr,
629 629 USB_MAXSTRINGLEN,
630 630 (uintptr_t)conf_str_descr[i]) ==
631 631 -1) {
632 632 (void) strcpy(string_descr,
633 633 "<No Configuration "
634 634 "String>");
635 635 }
636 636 mdb_printf(" %4d\t0x%p\t%s\n", i,
637 637 config_cloud[i], string_descr);
638 638 }
639 639 }
640 640 }
641 641
642 642 mdb_printf("\n Active configuration index: %d\n",
643 643 usba_device_struct.usb_active_cfg_ndx);
644 644 }
645 645
646 646 if (usb_flag & USB_DUMP_ACTIVE_PIPES) {
647 647
648 648 if (mdb_pwalk_dcmd("usb_pipe_handle", "usb_pipe_handle",
649 649 0, NULL, addr) == -1) {
650 650 mdb_warn("failed to walk usb_pipe_handle");
651 651 return (DCMD_ERR);
652 652 }
653 653 }
654 654
655 655 return (DCMD_OK);
656 656 }
657 657
658 658
659 659 /*
660 660 * Dump the contents of the usba_debug_buf, from the oldest to newest,
661 661 * wrapping around if necessary.
662 662 */
663 663 /*ARGSUSED*/
664 664 int
665 665 usba_debug_buf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
666 666 {
667 667 char *debug_buf_addr; /* addr in core */
668 668 char *local_debug_buf; /* local copy of buf */
669 669 int debug_buf_size;
670 670 char *term_p;
671 671 int being_cleared;
672 672
673 673 if (flags & DCMD_ADDRSPEC) {
674 674
675 675 return (DCMD_USAGE);
676 676 }
677 677
678 678 if (mdb_readvar(&being_cleared, "usba_clear_debug_buf_flag") ==
679 679 -1) {
680 680 mdb_warn("failed to read usba_clear_debug_buf_flag");
681 681
682 682 return (DCMD_ERR);
683 683 }
684 684 if (being_cleared) {
685 685
686 686 return (DCMD_OK);
687 687 }
688 688
689 689 if (mdb_readvar(&debug_buf_addr, "usba_debug_buf") == -1) {
690 690 mdb_warn("failed to read usba_debug_buf");
691 691
692 692 return (DCMD_ERR);
693 693 }
694 694
695 695 if (debug_buf_addr == NULL) {
696 696 mdb_warn("usba_debug_buf not allocated\n");
697 697
698 698 return (DCMD_OK);
699 699 }
700 700
701 701
702 702 if (mdb_readvar(&debug_buf_size, "usba_debug_buf_size") == -1) {
703 703 mdb_warn("failed to read usba_debug_buf_size");
704 704
705 705 return (DCMD_ERR);
706 706 }
707 707
708 708 debug_buf_size += USB_DEBUG_SIZE_EXTRA_ALLOC;
709 709 local_debug_buf = (char *)mdb_alloc(debug_buf_size, UM_SLEEP | UM_GC);
↓ open down ↓ |
187 lines elided |
↑ open up ↑ |
710 710
711 711 if ((mdb_vread(local_debug_buf, debug_buf_size,
712 712 (uintptr_t)debug_buf_addr)) == -1) {
713 713 mdb_warn("failed to read usba_debug_buf at %p",
714 714 local_debug_buf);
715 715
716 716 return (DCMD_ERR);
717 717 }
718 718 local_debug_buf[debug_buf_size - 1] = '\0';
719 719
720 - if (strlen(local_debug_buf) == NULL) {
720 + if (strlen(local_debug_buf) == 0) {
721 721
722 722 return (DCMD_OK);
723 723 }
724 724
725 725 if ((term_p = strstr(local_debug_buf, ">>>>")) == NULL) {
726 726 mdb_warn("failed to find terminator \">>>>\"\n");
727 727
728 728 return (DCMD_ERR);
729 729 }
730 730
731 731 /*
732 732 * Print the chunk of buffer from the terminator to the end.
733 733 * This will print a null string if no wrap has occurred yet.
734 734 */
735 735 mdb_printf("%s", term_p+5); /* after >>>>\0 to end of buf */
736 736 mdb_printf("%s\n", local_debug_buf); /* beg of buf to >>>>\0 */
737 737
738 738 return (DCMD_OK);
739 739 }
740 740
741 741 /*ARGSUSED*/
742 742 int
743 743 usba_clear_debug_buf(
744 744 uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
745 745 {
746 746 int clear = 1;
747 747
748 748 /* stop the tracing */
749 749 if (mdb_writevar((void*)&clear, "usba_clear_debug_buf_flag") == -1) {
750 750 mdb_warn("failed to set usba_clear_debug_buf_flag");
751 751
752 752 return (DCMD_ERR);
753 753 }
754 754
755 755 return (DCMD_OK);
756 756 }
757 757
758 758 /* prtusb entries */
759 759 extern int prtusb(uintptr_t, uint_t, int, const mdb_arg_t *);
760 760
761 761 extern void prt_usb_usage(void);
762 762
763 763 /*
764 764 * MDB module linkage information:
765 765 *
766 766 * We declare a list of structures describing our dcmds, and a function
767 767 * named _mdb_init to return a pointer to our module information.
768 768 */
769 769 static const mdb_dcmd_t dcmds[] = {
770 770 { "usb_pipe_handle", ":",
771 771 "print a usb_pipe_handle struct", usb_pipe_handle, NULL},
772 772 { "usba_device", ": [-pv]",
773 773 "print summary info for a usba_device_t struct", usba_device, NULL},
774 774 { "usba_debug_buf", NULL,
775 775 "print usba_debug_buf", usba_debug_buf, NULL},
776 776 { "usba_clear_debug_buf", NULL,
777 777 "clear usba_debug_buf", usba_clear_debug_buf, NULL},
778 778 { "prtusb", "?[-t] [-v] [-i index]",
779 779 "print trees and descriptors for usba_device_t",
780 780 prtusb, prt_usb_usage},
781 781 { NULL }
782 782 };
783 783
784 784 static const mdb_walker_t walkers[] = {
785 785 /* Generic list walker. */
786 786 { "usba_list_entry", "walk list of usba_list_entry_t structures",
787 787 usba_list_walk_init, usba_list_walk_step, NULL, NULL },
788 788 { "usb_pipe_handle", "walk USB pipe handles, given a usba_device_t ptr",
789 789 usb_pipe_handle_walk_init, usb_pipe_handle_walk_step, NULL, NULL },
790 790 { "usba_device", "walk global list of usba_device_t structures",
791 791 usba_device_walk_init, usba_list_walk_step, NULL, NULL },
792 792 { NULL }
793 793 };
794 794
795 795 static const mdb_modinfo_t modinfo = {
796 796 MDB_API_VERSION, dcmds, walkers
797 797 };
798 798
799 799 const mdb_modinfo_t *
800 800 _mdb_init(void)
801 801 {
802 802 return (&modinfo);
803 803 }
↓ open down ↓ |
73 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX