10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51993Sramat * Common Development and Distribution License (the "License"). 61993Sramat * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*13015Sgavin.maltby@oracle.com * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate #include <sys/types.h> 260Sstevel@tonic-gate #include <sys/sysmacros.h> 270Sstevel@tonic-gate #include <sys/dditypes.h> 280Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 290Sstevel@tonic-gate #include <sys/ddifm.h> 300Sstevel@tonic-gate #include <sys/ddipropdefs.h> 310Sstevel@tonic-gate #include <sys/modctl.h> 320Sstevel@tonic-gate #include <sys/hwconf.h> 330Sstevel@tonic-gate #include <sys/stat.h> 340Sstevel@tonic-gate #include <errno.h> 350Sstevel@tonic-gate #include <sys/sunmdi.h> 360Sstevel@tonic-gate #include <sys/mdi_impldefs.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #include <ctype.h> 390Sstevel@tonic-gate #include <mdb/mdb_modapi.h> 400Sstevel@tonic-gate #include <mdb/mdb_ks.h> 410Sstevel@tonic-gate 420Sstevel@tonic-gate #include "nvpair.h" 4310923SEvan.Yan@Sun.COM #include "devinfo.h" 440Sstevel@tonic-gate 450Sstevel@tonic-gate #define DEVINFO_TREE_INDENT 4 /* Indent for devs one down in tree */ 460Sstevel@tonic-gate #define DEVINFO_PROP_INDENT 4 /* Indent for properties */ 470Sstevel@tonic-gate #define DEVINFO_PROPLIST_INDENT 8 /* Indent for properties lists */ 480Sstevel@tonic-gate 490Sstevel@tonic-gate /* 500Sstevel@tonic-gate * devinfo node state map. Used by devinfo() and devinfo_audit(). 510Sstevel@tonic-gate * Long words are deliberately truncated so that output 520Sstevel@tonic-gate * fits in 80 column with 64-bit addresses. 530Sstevel@tonic-gate */ 540Sstevel@tonic-gate static const char *const di_state[] = { 550Sstevel@tonic-gate "DS_INVAL", 560Sstevel@tonic-gate "DS_PROTO", 570Sstevel@tonic-gate "DS_LINKED", 580Sstevel@tonic-gate "DS_BOUND", 590Sstevel@tonic-gate "DS_INITIA", 600Sstevel@tonic-gate "DS_PROBED", 610Sstevel@tonic-gate "DS_ATTACH", 620Sstevel@tonic-gate "DS_READY", 630Sstevel@tonic-gate "?" 640Sstevel@tonic-gate }; 650Sstevel@tonic-gate 660Sstevel@tonic-gate #define DI_STATE_MAX ((sizeof (di_state) / sizeof (char *)) - 1) 670Sstevel@tonic-gate 680Sstevel@tonic-gate void 690Sstevel@tonic-gate prtconf_help(void) 700Sstevel@tonic-gate { 710Sstevel@tonic-gate mdb_printf("Prints the devinfo tree from a given node.\n" 720Sstevel@tonic-gate "Without the address of a \"struct devinfo\" given, " 730Sstevel@tonic-gate "prints from the root;\n" 740Sstevel@tonic-gate "with an address, prints the parents of, " 750Sstevel@tonic-gate "and all children of, that address.\n\n" 760Sstevel@tonic-gate "Switches:\n" 770Sstevel@tonic-gate " -v be verbose - print device property lists\n" 780Sstevel@tonic-gate " -p only print the ancestors of the given node\n" 790Sstevel@tonic-gate " -c only print the children of the given node\n"); 800Sstevel@tonic-gate } 810Sstevel@tonic-gate 820Sstevel@tonic-gate void 830Sstevel@tonic-gate devinfo_help(void) 840Sstevel@tonic-gate { 850Sstevel@tonic-gate mdb_printf("Switches:\n" 860Sstevel@tonic-gate " -q be quiet - don't print device property lists\n" 870Sstevel@tonic-gate " -s print summary of dev_info structures\n"); 880Sstevel@tonic-gate } 890Sstevel@tonic-gate 900Sstevel@tonic-gate 910Sstevel@tonic-gate /* 920Sstevel@tonic-gate * Devinfo walker. 930Sstevel@tonic-gate */ 940Sstevel@tonic-gate 950Sstevel@tonic-gate typedef struct { 960Sstevel@tonic-gate /* 970Sstevel@tonic-gate * The "struct dev_info" must be the first thing in this structure. 980Sstevel@tonic-gate */ 990Sstevel@tonic-gate struct dev_info din_dev; 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate /* 1020Sstevel@tonic-gate * This is for the benefit of prtconf(). 1030Sstevel@tonic-gate */ 1040Sstevel@tonic-gate int din_depth; 1050Sstevel@tonic-gate } devinfo_node_t; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate typedef struct devinfo_parents_walk_data { 1080Sstevel@tonic-gate devinfo_node_t dip_node; 1090Sstevel@tonic-gate #define dip_dev dip_node.din_dev 1100Sstevel@tonic-gate #define dip_depth dip_node.din_depth 1110Sstevel@tonic-gate struct dev_info *dip_end; 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate /* 1140Sstevel@tonic-gate * The following three elements are for walking the parents of a node: 1150Sstevel@tonic-gate * "dip_base_depth" is the depth of the given node from the root. 1160Sstevel@tonic-gate * This starts at 1 (if we're walking devinfo_root), because 1170Sstevel@tonic-gate * it's the size of the dip_parent_{nodes,addresses} arrays, 1180Sstevel@tonic-gate * and has to include the given node. 1190Sstevel@tonic-gate * "dip_parent_nodes" is a collection of the parent node structures, 1200Sstevel@tonic-gate * already read in via mdb_vread(). dip_parent_nodes[0] is the 1210Sstevel@tonic-gate * root, dip_parent_nodes[1] is a child of the root, etc. 1220Sstevel@tonic-gate * "dip_parent_addresses" holds the vaddrs of all the parent nodes. 1230Sstevel@tonic-gate */ 1240Sstevel@tonic-gate int dip_base_depth; 1250Sstevel@tonic-gate devinfo_node_t *dip_parent_nodes; 1260Sstevel@tonic-gate uintptr_t *dip_parent_addresses; 1270Sstevel@tonic-gate } devinfo_parents_walk_data_t; 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate int 1300Sstevel@tonic-gate devinfo_parents_walk_init(mdb_walk_state_t *wsp) 1310Sstevel@tonic-gate { 1320Sstevel@tonic-gate devinfo_parents_walk_data_t *dip; 1330Sstevel@tonic-gate uintptr_t addr; 1345839Sdmick uintptr_t devinfo_root; /* Address of root of devinfo tree */ 1350Sstevel@tonic-gate int i; 1360Sstevel@tonic-gate 1375839Sdmick if (mdb_readvar(&devinfo_root, "top_devinfo") == -1) { 1385839Sdmick mdb_warn("failed to read 'top_devinfo'"); 1395839Sdmick return (NULL); 1405839Sdmick } 1415839Sdmick 1420Sstevel@tonic-gate if (wsp->walk_addr == NULL) 1430Sstevel@tonic-gate wsp->walk_addr = devinfo_root; 1440Sstevel@tonic-gate addr = wsp->walk_addr; 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate dip = mdb_alloc(sizeof (devinfo_parents_walk_data_t), UM_SLEEP); 1470Sstevel@tonic-gate wsp->walk_data = dip; 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate dip->dip_end = (struct dev_info *)wsp->walk_addr; 1500Sstevel@tonic-gate dip->dip_depth = 0; 1510Sstevel@tonic-gate dip->dip_base_depth = 1; 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate do { 1540Sstevel@tonic-gate if (mdb_vread(&dip->dip_dev, sizeof (dip->dip_dev), 1550Sstevel@tonic-gate addr) == -1) { 1560Sstevel@tonic-gate mdb_warn("failed to read devinfo at %p", addr); 1570Sstevel@tonic-gate mdb_free(dip, sizeof (devinfo_parents_walk_data_t)); 1580Sstevel@tonic-gate wsp->walk_data = NULL; 1590Sstevel@tonic-gate return (WALK_ERR); 1600Sstevel@tonic-gate } 1610Sstevel@tonic-gate addr = (uintptr_t)dip->dip_dev.devi_parent; 1620Sstevel@tonic-gate if (addr != 0) 1630Sstevel@tonic-gate dip->dip_base_depth++; 1640Sstevel@tonic-gate } while (addr != 0); 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate addr = wsp->walk_addr; 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate dip->dip_parent_nodes = mdb_alloc( 1690Sstevel@tonic-gate dip->dip_base_depth * sizeof (devinfo_node_t), UM_SLEEP); 1700Sstevel@tonic-gate dip->dip_parent_addresses = mdb_alloc( 1710Sstevel@tonic-gate dip->dip_base_depth * sizeof (uintptr_t), UM_SLEEP); 1720Sstevel@tonic-gate for (i = dip->dip_base_depth - 1; i >= 0; i--) { 1730Sstevel@tonic-gate if (mdb_vread(&dip->dip_parent_nodes[i].din_dev, 1740Sstevel@tonic-gate sizeof (struct dev_info), addr) == -1) { 1750Sstevel@tonic-gate mdb_warn("failed to read devinfo at %p", addr); 1760Sstevel@tonic-gate return (WALK_ERR); 1770Sstevel@tonic-gate } 1780Sstevel@tonic-gate dip->dip_parent_nodes[i].din_depth = i; 1790Sstevel@tonic-gate dip->dip_parent_addresses[i] = addr; 1800Sstevel@tonic-gate addr = (uintptr_t) 1810Sstevel@tonic-gate dip->dip_parent_nodes[i].din_dev.devi_parent; 1820Sstevel@tonic-gate } 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate return (WALK_NEXT); 1850Sstevel@tonic-gate } 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate int 1880Sstevel@tonic-gate devinfo_parents_walk_step(mdb_walk_state_t *wsp) 1890Sstevel@tonic-gate { 1900Sstevel@tonic-gate devinfo_parents_walk_data_t *dip = wsp->walk_data; 1910Sstevel@tonic-gate int status; 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate if (dip->dip_depth == dip->dip_base_depth) 1940Sstevel@tonic-gate return (WALK_DONE); 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate status = wsp->walk_callback( 1970Sstevel@tonic-gate dip->dip_parent_addresses[dip->dip_depth], 1980Sstevel@tonic-gate &dip->dip_parent_nodes[dip->dip_depth], 1990Sstevel@tonic-gate wsp->walk_cbdata); 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate dip->dip_depth++; 2020Sstevel@tonic-gate return (status); 2030Sstevel@tonic-gate } 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate void 2060Sstevel@tonic-gate devinfo_parents_walk_fini(mdb_walk_state_t *wsp) 2070Sstevel@tonic-gate { 2080Sstevel@tonic-gate devinfo_parents_walk_data_t *dip = wsp->walk_data; 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate mdb_free(dip->dip_parent_nodes, 2110Sstevel@tonic-gate dip->dip_base_depth * sizeof (devinfo_node_t)); 2120Sstevel@tonic-gate mdb_free(dip->dip_parent_addresses, 2130Sstevel@tonic-gate dip->dip_base_depth * sizeof (uintptr_t)); 2140Sstevel@tonic-gate mdb_free(wsp->walk_data, sizeof (devinfo_parents_walk_data_t)); 2150Sstevel@tonic-gate } 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate typedef struct devinfo_children_walk_data { 2190Sstevel@tonic-gate devinfo_node_t dic_node; 2200Sstevel@tonic-gate #define dic_dev dic_node.din_dev 2210Sstevel@tonic-gate #define dic_depth dic_node.din_depth 2220Sstevel@tonic-gate struct dev_info *dic_end; 2230Sstevel@tonic-gate int dic_print_first_node; 2240Sstevel@tonic-gate } devinfo_children_walk_data_t; 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate int 2270Sstevel@tonic-gate devinfo_children_walk_init(mdb_walk_state_t *wsp) 2280Sstevel@tonic-gate { 2290Sstevel@tonic-gate devinfo_children_walk_data_t *dic; 2305839Sdmick uintptr_t devinfo_root; /* Address of root of devinfo tree */ 2315839Sdmick 2325839Sdmick if (mdb_readvar(&devinfo_root, "top_devinfo") == -1) { 2335839Sdmick mdb_warn("failed to read 'top_devinfo'"); 2345839Sdmick return (NULL); 2355839Sdmick } 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate if (wsp->walk_addr == NULL) 2380Sstevel@tonic-gate wsp->walk_addr = devinfo_root; 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate dic = mdb_alloc(sizeof (devinfo_children_walk_data_t), UM_SLEEP); 2410Sstevel@tonic-gate wsp->walk_data = dic; 2420Sstevel@tonic-gate dic->dic_end = (struct dev_info *)wsp->walk_addr; 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate /* 2450Sstevel@tonic-gate * This could be set by devinfo_walk_init(). 2460Sstevel@tonic-gate */ 2470Sstevel@tonic-gate if (wsp->walk_arg != NULL) { 2480Sstevel@tonic-gate dic->dic_depth = (*(int *)wsp->walk_arg - 1); 2490Sstevel@tonic-gate dic->dic_print_first_node = 0; 2500Sstevel@tonic-gate } else { 2510Sstevel@tonic-gate dic->dic_depth = 0; 2520Sstevel@tonic-gate dic->dic_print_first_node = 1; 2530Sstevel@tonic-gate } 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate return (WALK_NEXT); 2560Sstevel@tonic-gate } 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate int 2590Sstevel@tonic-gate devinfo_children_walk_step(mdb_walk_state_t *wsp) 2600Sstevel@tonic-gate { 2610Sstevel@tonic-gate devinfo_children_walk_data_t *dic = wsp->walk_data; 2620Sstevel@tonic-gate struct dev_info *v; 2630Sstevel@tonic-gate devinfo_node_t *cur; 2640Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 2650Sstevel@tonic-gate int status = WALK_NEXT; 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate if (wsp->walk_addr == NULL) 2680Sstevel@tonic-gate return (WALK_DONE); 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate if (mdb_vread(&dic->dic_dev, sizeof (dic->dic_dev), addr) == -1) { 2710Sstevel@tonic-gate mdb_warn("failed to read devinfo at %p", addr); 2720Sstevel@tonic-gate return (WALK_DONE); 2730Sstevel@tonic-gate } 2740Sstevel@tonic-gate cur = &dic->dic_node; 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate if (dic->dic_print_first_node == 0) 2770Sstevel@tonic-gate dic->dic_print_first_node = 1; 2780Sstevel@tonic-gate else 2790Sstevel@tonic-gate status = wsp->walk_callback(addr, cur, wsp->walk_cbdata); 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate /* 2820Sstevel@tonic-gate * "v" is always a virtual address pointer, 2830Sstevel@tonic-gate * i.e. can't be deref'ed. 2840Sstevel@tonic-gate */ 2850Sstevel@tonic-gate v = (struct dev_info *)addr; 2860Sstevel@tonic-gate 2870Sstevel@tonic-gate if (dic->dic_dev.devi_child != NULL) { 2880Sstevel@tonic-gate v = dic->dic_dev.devi_child; 2890Sstevel@tonic-gate dic->dic_depth++; 2900Sstevel@tonic-gate } else if (dic->dic_dev.devi_sibling != NULL && v != dic->dic_end) { 2910Sstevel@tonic-gate v = dic->dic_dev.devi_sibling; 2920Sstevel@tonic-gate } else { 2930Sstevel@tonic-gate while (v != NULL && v != dic->dic_end && 2940Sstevel@tonic-gate dic->dic_dev.devi_sibling == NULL) { 2950Sstevel@tonic-gate v = dic->dic_dev.devi_parent; 2960Sstevel@tonic-gate if (v == NULL) 2970Sstevel@tonic-gate break; 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate mdb_vread(&dic->dic_dev, 3000Sstevel@tonic-gate sizeof (struct dev_info), (uintptr_t)v); 3010Sstevel@tonic-gate dic->dic_depth--; 3020Sstevel@tonic-gate } 3030Sstevel@tonic-gate if (v != NULL && v != dic->dic_end) 3040Sstevel@tonic-gate v = dic->dic_dev.devi_sibling; 3050Sstevel@tonic-gate if (v == dic->dic_end) 3060Sstevel@tonic-gate v = NULL; /* Done */ 3070Sstevel@tonic-gate } 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)v; 3100Sstevel@tonic-gate return (status); 3110Sstevel@tonic-gate } 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate void 3140Sstevel@tonic-gate devinfo_children_walk_fini(mdb_walk_state_t *wsp) 3150Sstevel@tonic-gate { 3160Sstevel@tonic-gate mdb_free(wsp->walk_data, sizeof (devinfo_children_walk_data_t)); 3170Sstevel@tonic-gate } 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate typedef struct devinfo_walk_data { 3200Sstevel@tonic-gate mdb_walk_state_t diw_parent, diw_child; 3210Sstevel@tonic-gate enum { DIW_PARENT, DIW_CHILD, DIW_DONE } diw_mode; 3220Sstevel@tonic-gate } devinfo_walk_data_t; 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate int 3250Sstevel@tonic-gate devinfo_walk_init(mdb_walk_state_t *wsp) 3260Sstevel@tonic-gate { 3270Sstevel@tonic-gate devinfo_walk_data_t *diw; 3280Sstevel@tonic-gate devinfo_parents_walk_data_t *dip; 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate diw = mdb_alloc(sizeof (devinfo_walk_data_t), UM_SLEEP); 3310Sstevel@tonic-gate diw->diw_parent = *wsp; 3320Sstevel@tonic-gate diw->diw_child = *wsp; 3330Sstevel@tonic-gate wsp->walk_data = diw; 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate diw->diw_mode = DIW_PARENT; 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate if (devinfo_parents_walk_init(&diw->diw_parent) == -1) { 3380Sstevel@tonic-gate mdb_free(diw, sizeof (devinfo_walk_data_t)); 3390Sstevel@tonic-gate return (WALK_ERR); 3400Sstevel@tonic-gate } 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate /* 3430Sstevel@tonic-gate * This is why the "devinfo" walker needs to be marginally 3440Sstevel@tonic-gate * complicated - the child walker needs this initialization 3450Sstevel@tonic-gate * data, and the best way to get it is out of the parent walker. 3460Sstevel@tonic-gate */ 3470Sstevel@tonic-gate dip = diw->diw_parent.walk_data; 3480Sstevel@tonic-gate diw->diw_child.walk_arg = &dip->dip_base_depth; 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate if (devinfo_children_walk_init(&diw->diw_child) == -1) { 3510Sstevel@tonic-gate devinfo_parents_walk_fini(&diw->diw_parent); 3520Sstevel@tonic-gate mdb_free(diw, sizeof (devinfo_walk_data_t)); 3530Sstevel@tonic-gate return (WALK_ERR); 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate return (WALK_NEXT); 3570Sstevel@tonic-gate } 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate int 3600Sstevel@tonic-gate devinfo_walk_step(mdb_walk_state_t *wsp) 3610Sstevel@tonic-gate { 3620Sstevel@tonic-gate devinfo_walk_data_t *diw = wsp->walk_data; 3630Sstevel@tonic-gate int status = WALK_NEXT; 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate if (diw->diw_mode == DIW_PARENT) { 3660Sstevel@tonic-gate status = devinfo_parents_walk_step(&diw->diw_parent); 3670Sstevel@tonic-gate if (status != WALK_NEXT) { 3680Sstevel@tonic-gate /* 3690Sstevel@tonic-gate * Keep on going even if the parents walk hit an error. 3700Sstevel@tonic-gate */ 3710Sstevel@tonic-gate diw->diw_mode = DIW_CHILD; 3720Sstevel@tonic-gate status = WALK_NEXT; 3730Sstevel@tonic-gate } 3740Sstevel@tonic-gate } else if (diw->diw_mode == DIW_CHILD) { 3750Sstevel@tonic-gate status = devinfo_children_walk_step(&diw->diw_child); 3760Sstevel@tonic-gate if (status != WALK_NEXT) { 3770Sstevel@tonic-gate diw->diw_mode = DIW_DONE; 3780Sstevel@tonic-gate status = WALK_DONE; 3790Sstevel@tonic-gate } 3800Sstevel@tonic-gate } else 3810Sstevel@tonic-gate status = WALK_DONE; 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate return (status); 3840Sstevel@tonic-gate } 3850Sstevel@tonic-gate 3860Sstevel@tonic-gate void 3870Sstevel@tonic-gate devinfo_walk_fini(mdb_walk_state_t *wsp) 3880Sstevel@tonic-gate { 3890Sstevel@tonic-gate devinfo_walk_data_t *diw = wsp->walk_data; 3900Sstevel@tonic-gate 3910Sstevel@tonic-gate devinfo_children_walk_fini(&diw->diw_child); 3920Sstevel@tonic-gate devinfo_parents_walk_fini(&diw->diw_parent); 3930Sstevel@tonic-gate mdb_free(diw, sizeof (devinfo_walk_data_t)); 3940Sstevel@tonic-gate } 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate /* 3970Sstevel@tonic-gate * Given a devinfo pointer, figure out which driver is associated 3980Sstevel@tonic-gate * with the node (by driver name, from the devnames array). 3990Sstevel@tonic-gate */ 4000Sstevel@tonic-gate /*ARGSUSED*/ 4010Sstevel@tonic-gate int 4020Sstevel@tonic-gate devinfo2driver(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 4030Sstevel@tonic-gate { 4040Sstevel@tonic-gate char dname[MODMAXNAMELEN + 1]; 4050Sstevel@tonic-gate struct dev_info devi; 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 4090Sstevel@tonic-gate return (DCMD_USAGE); 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate if (mdb_vread(&devi, sizeof (devi), addr) == -1) { 4120Sstevel@tonic-gate mdb_warn("failed to read devinfo struct at %p", addr); 4130Sstevel@tonic-gate return (DCMD_ERR); 4140Sstevel@tonic-gate } 4150Sstevel@tonic-gate 4161125Seschrock if (devi.devi_node_state < DS_ATTACHED) { 4170Sstevel@tonic-gate /* No driver attached to this devinfo - nothing to do. */ 4180Sstevel@tonic-gate mdb_warn("%p: No driver attached to this devinfo node\n", addr); 4190Sstevel@tonic-gate return (DCMD_ERR); 4200Sstevel@tonic-gate } 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate if (mdb_devinfo2driver(addr, dname, sizeof (dname)) != 0) { 4230Sstevel@tonic-gate mdb_warn("failed to determine driver name"); 4240Sstevel@tonic-gate return (DCMD_ERR); 4250Sstevel@tonic-gate } 4260Sstevel@tonic-gate 4270Sstevel@tonic-gate mdb_printf("Driver '%s' is associated with devinfo %p.\n", dname, addr); 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate return (DCMD_OK); 4300Sstevel@tonic-gate } 4310Sstevel@tonic-gate 4320Sstevel@tonic-gate 4330Sstevel@tonic-gate typedef struct devnames_walk { 4340Sstevel@tonic-gate struct devnames *dnw_names; 4350Sstevel@tonic-gate int dnw_ndx; 4360Sstevel@tonic-gate int dnw_devcnt; 4370Sstevel@tonic-gate uintptr_t dnw_base; 4380Sstevel@tonic-gate uintptr_t dnw_size; 4390Sstevel@tonic-gate } devnames_walk_t; 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate int 4420Sstevel@tonic-gate devnames_walk_init(mdb_walk_state_t *wsp) 4430Sstevel@tonic-gate { 4440Sstevel@tonic-gate devnames_walk_t *dnw; 4450Sstevel@tonic-gate int devcnt; 4460Sstevel@tonic-gate uintptr_t devnamesp; 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate if (wsp->walk_addr != NULL) { 4490Sstevel@tonic-gate mdb_warn("devnames walker only supports global walks\n"); 4500Sstevel@tonic-gate return (WALK_ERR); 4510Sstevel@tonic-gate } 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate if (mdb_readvar(&devcnt, "devcnt") == -1) { 4540Sstevel@tonic-gate mdb_warn("failed to read 'devcnt'"); 4550Sstevel@tonic-gate return (WALK_ERR); 4560Sstevel@tonic-gate } 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate if (mdb_readvar(&devnamesp, "devnamesp") == -1) { 4590Sstevel@tonic-gate mdb_warn("failed to read 'devnamesp'"); 4600Sstevel@tonic-gate return (WALK_ERR); 4610Sstevel@tonic-gate } 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate dnw = mdb_zalloc(sizeof (devnames_walk_t), UM_SLEEP); 4640Sstevel@tonic-gate dnw->dnw_size = sizeof (struct devnames) * devcnt; 4650Sstevel@tonic-gate dnw->dnw_devcnt = devcnt; 4660Sstevel@tonic-gate dnw->dnw_base = devnamesp; 4670Sstevel@tonic-gate dnw->dnw_names = mdb_alloc(dnw->dnw_size, UM_SLEEP); 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate if (mdb_vread(dnw->dnw_names, dnw->dnw_size, dnw->dnw_base) == -1) { 4700Sstevel@tonic-gate mdb_warn("couldn't read devnames array at %p", devnamesp); 4710Sstevel@tonic-gate return (WALK_ERR); 4720Sstevel@tonic-gate } 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate wsp->walk_data = dnw; 4750Sstevel@tonic-gate return (WALK_NEXT); 4760Sstevel@tonic-gate } 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate int 4790Sstevel@tonic-gate devnames_walk_step(mdb_walk_state_t *wsp) 4800Sstevel@tonic-gate { 4810Sstevel@tonic-gate devnames_walk_t *dnw = wsp->walk_data; 4820Sstevel@tonic-gate int status; 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate if (dnw->dnw_ndx == dnw->dnw_devcnt) 4850Sstevel@tonic-gate return (WALK_DONE); 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate status = wsp->walk_callback(dnw->dnw_ndx * sizeof (struct devnames) + 4880Sstevel@tonic-gate dnw->dnw_base, &dnw->dnw_names[dnw->dnw_ndx], wsp->walk_cbdata); 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate dnw->dnw_ndx++; 4910Sstevel@tonic-gate return (status); 4920Sstevel@tonic-gate } 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate void 4950Sstevel@tonic-gate devnames_walk_fini(mdb_walk_state_t *wsp) 4960Sstevel@tonic-gate { 4970Sstevel@tonic-gate devnames_walk_t *dnw = wsp->walk_data; 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate mdb_free(dnw->dnw_names, dnw->dnw_size); 5000Sstevel@tonic-gate mdb_free(dnw, sizeof (devnames_walk_t)); 5010Sstevel@tonic-gate } 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate int 5040Sstevel@tonic-gate devinfo_siblings_walk_init(mdb_walk_state_t *wsp) 5050Sstevel@tonic-gate { 5060Sstevel@tonic-gate struct dev_info di; 5070Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 5080Sstevel@tonic-gate 5090Sstevel@tonic-gate if (addr == NULL) { 5100Sstevel@tonic-gate mdb_warn("a dev_info struct address must be provided\n"); 5110Sstevel@tonic-gate return (WALK_ERR); 5120Sstevel@tonic-gate } 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate if (mdb_vread(&di, sizeof (di), addr) == -1) { 5150Sstevel@tonic-gate mdb_warn("failed to read dev_info struct at %p", addr); 5160Sstevel@tonic-gate return (WALK_ERR); 5170Sstevel@tonic-gate } 5180Sstevel@tonic-gate 5190Sstevel@tonic-gate if (di.devi_parent == NULL) { 5200Sstevel@tonic-gate mdb_warn("no parent for devinfo at %p", addr); 5210Sstevel@tonic-gate return (WALK_DONE); 5220Sstevel@tonic-gate } 5230Sstevel@tonic-gate 5240Sstevel@tonic-gate if (mdb_vread(&di, sizeof (di), (uintptr_t)di.devi_parent) == -1) { 5250Sstevel@tonic-gate mdb_warn("failed to read parent dev_info struct at %p", 5260Sstevel@tonic-gate (uintptr_t)di.devi_parent); 5270Sstevel@tonic-gate return (WALK_ERR); 5280Sstevel@tonic-gate } 5290Sstevel@tonic-gate 5300Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)di.devi_child; 5310Sstevel@tonic-gate return (WALK_NEXT); 5320Sstevel@tonic-gate } 5330Sstevel@tonic-gate 5340Sstevel@tonic-gate int 5350Sstevel@tonic-gate devinfo_siblings_walk_step(mdb_walk_state_t *wsp) 5360Sstevel@tonic-gate { 5370Sstevel@tonic-gate struct dev_info di; 5380Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate if (addr == NULL) 5410Sstevel@tonic-gate return (WALK_DONE); 5420Sstevel@tonic-gate 5430Sstevel@tonic-gate if (mdb_vread(&di, sizeof (di), addr) == -1) { 5440Sstevel@tonic-gate mdb_warn("failed to read dev_info struct at %p", addr); 5450Sstevel@tonic-gate return (WALK_DONE); 5460Sstevel@tonic-gate } 5470Sstevel@tonic-gate 5480Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)di.devi_sibling; 5490Sstevel@tonic-gate return (wsp->walk_callback(addr, &di, wsp->walk_cbdata)); 5500Sstevel@tonic-gate } 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate int 5530Sstevel@tonic-gate devi_next_walk_step(mdb_walk_state_t *wsp) 5540Sstevel@tonic-gate { 5550Sstevel@tonic-gate struct dev_info di; 5560Sstevel@tonic-gate int status; 5570Sstevel@tonic-gate 5580Sstevel@tonic-gate if (wsp->walk_addr == NULL) 5590Sstevel@tonic-gate return (WALK_DONE); 5600Sstevel@tonic-gate 5610Sstevel@tonic-gate if (mdb_vread(&di, sizeof (di), wsp->walk_addr) == -1) 5620Sstevel@tonic-gate return (WALK_DONE); 5630Sstevel@tonic-gate 5640Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, &di, wsp->walk_cbdata); 5650Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)di.devi_next; 5660Sstevel@tonic-gate return (status); 5670Sstevel@tonic-gate } 5680Sstevel@tonic-gate 5690Sstevel@tonic-gate /* 5700Sstevel@tonic-gate * Helper functions. 5710Sstevel@tonic-gate */ 5720Sstevel@tonic-gate 5730Sstevel@tonic-gate static int 5740Sstevel@tonic-gate is_printable_string(unsigned char *prop_value) 5750Sstevel@tonic-gate { 5760Sstevel@tonic-gate while (*prop_value != 0) 5770Sstevel@tonic-gate if (!isprint(*prop_value++)) 5780Sstevel@tonic-gate return (0); 5790Sstevel@tonic-gate return (1); 5800Sstevel@tonic-gate } 5810Sstevel@tonic-gate 5820Sstevel@tonic-gate static void 5830Sstevel@tonic-gate devinfo_print_props_type(int type) { 5840Sstevel@tonic-gate char *type_str = NULL; 5850Sstevel@tonic-gate 5860Sstevel@tonic-gate switch (type) { 5870Sstevel@tonic-gate case DDI_PROP_TYPE_ANY: 5880Sstevel@tonic-gate type_str = "any"; 5890Sstevel@tonic-gate break; 5900Sstevel@tonic-gate case DDI_PROP_TYPE_COMPOSITE: 5910Sstevel@tonic-gate type_str = "composite"; 5920Sstevel@tonic-gate break; 5930Sstevel@tonic-gate case DDI_PROP_TYPE_INT64: 5940Sstevel@tonic-gate type_str = "int64"; 5950Sstevel@tonic-gate break; 5960Sstevel@tonic-gate case DDI_PROP_TYPE_INT: 5970Sstevel@tonic-gate type_str = "int"; 5980Sstevel@tonic-gate break; 5990Sstevel@tonic-gate case DDI_PROP_TYPE_BYTE: 6000Sstevel@tonic-gate type_str = "byte"; 6010Sstevel@tonic-gate break; 6020Sstevel@tonic-gate case DDI_PROP_TYPE_STRING: 6030Sstevel@tonic-gate type_str = "string"; 6040Sstevel@tonic-gate break; 6050Sstevel@tonic-gate } 6060Sstevel@tonic-gate 6070Sstevel@tonic-gate if (type_str != NULL) 6080Sstevel@tonic-gate mdb_printf("type=%s", type_str); 6090Sstevel@tonic-gate else 6100Sstevel@tonic-gate mdb_printf("type=0x%x", type); 6110Sstevel@tonic-gate } 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate static void 6140Sstevel@tonic-gate devinfo_print_props_value(int elem_size, int nelem, 6150Sstevel@tonic-gate unsigned char *prop_value, int prop_value_len) 6160Sstevel@tonic-gate { 6170Sstevel@tonic-gate int i; 6180Sstevel@tonic-gate 6190Sstevel@tonic-gate mdb_printf("value="); 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate if (elem_size == 0) { 6220Sstevel@tonic-gate /* if elem_size == 0, then we are printing out string(s) */ 6230Sstevel@tonic-gate char *p = (char *)prop_value; 6240Sstevel@tonic-gate 6250Sstevel@tonic-gate for (i = 0; i < nelem - 1; i++) { 6260Sstevel@tonic-gate mdb_printf("'%s' + ", p); 6270Sstevel@tonic-gate p += strlen(p) + 1; 6280Sstevel@tonic-gate } 6290Sstevel@tonic-gate mdb_printf("'%s'", p); 6300Sstevel@tonic-gate } else { 6310Sstevel@tonic-gate /* 6320Sstevel@tonic-gate * if elem_size != 0 then we are printing out an array 6330Sstevel@tonic-gate * where each element is of elem_size 6340Sstevel@tonic-gate */ 6350Sstevel@tonic-gate mdb_nhconvert(prop_value, prop_value, elem_size); 6360Sstevel@tonic-gate mdb_printf("%02x", *prop_value); 6370Sstevel@tonic-gate for (i = 1; i < prop_value_len; i++) { 6380Sstevel@tonic-gate if ((i % elem_size) == 0) { 6390Sstevel@tonic-gate mdb_nhconvert(&prop_value[i], 6400Sstevel@tonic-gate &prop_value[i], elem_size); 6410Sstevel@tonic-gate mdb_printf("."); 6420Sstevel@tonic-gate } 6430Sstevel@tonic-gate 6440Sstevel@tonic-gate mdb_printf("%02x", prop_value[i]); 6450Sstevel@tonic-gate } 6460Sstevel@tonic-gate } 6470Sstevel@tonic-gate } 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate /* 6500Sstevel@tonic-gate * devinfo_print_props_guess() 6510Sstevel@tonic-gate * Guesses how to interpret the value of the property 6520Sstevel@tonic-gate * 6530Sstevel@tonic-gate * Params: 6540Sstevel@tonic-gate * type - Should be the type value of the property 6550Sstevel@tonic-gate * prop_val - Pointer to the property value data buffer 6560Sstevel@tonic-gate * prop_len - Length of the property value data buffer 6570Sstevel@tonic-gate * 6580Sstevel@tonic-gate * Return values: 6590Sstevel@tonic-gate * nelem - The number of elements stored in the property value 6600Sstevel@tonic-gate * data buffer pointed to by prop_val. 6610Sstevel@tonic-gate * elem_size - The size (in bytes) of the elements stored in the property 6620Sstevel@tonic-gate * value data buffer pointed to by prop_val. 6630Sstevel@tonic-gate * Upon return if elem_size == 0 and nelem != 0 then 6640Sstevel@tonic-gate * the property value data buffer contains strings 6650Sstevel@tonic-gate * len_err - There was an error with the length of the data buffer. 6660Sstevel@tonic-gate * Its size is not a multiple of the array value type. 6670Sstevel@tonic-gate * It will be interpreted as an array of bytes. 6680Sstevel@tonic-gate */ 6690Sstevel@tonic-gate static void 6700Sstevel@tonic-gate devinfo_print_props_guess(int type, unsigned char *prop_val, int prop_len, 6710Sstevel@tonic-gate int *elem_size, int *nelem, int *len_err) 6720Sstevel@tonic-gate { 6730Sstevel@tonic-gate *len_err = 0; 6740Sstevel@tonic-gate if (prop_len == NULL) { 6750Sstevel@tonic-gate *elem_size = 0; 6760Sstevel@tonic-gate *nelem = 0; 6770Sstevel@tonic-gate return; 6780Sstevel@tonic-gate } 6790Sstevel@tonic-gate 6800Sstevel@tonic-gate /* by default, assume an array of bytes */ 6810Sstevel@tonic-gate *elem_size = 1; 6820Sstevel@tonic-gate *nelem = prop_len; 6830Sstevel@tonic-gate 6840Sstevel@tonic-gate switch (type) { 6850Sstevel@tonic-gate case DDI_PROP_TYPE_BYTE: 6860Sstevel@tonic-gate /* default case, that was easy */ 6870Sstevel@tonic-gate break; 6880Sstevel@tonic-gate case DDI_PROP_TYPE_INT64: 6890Sstevel@tonic-gate if ((prop_len % sizeof (int64_t)) == 0) { 6900Sstevel@tonic-gate *elem_size = sizeof (int64_t); 6910Sstevel@tonic-gate *nelem = prop_len / *elem_size; 6920Sstevel@tonic-gate } else { 6930Sstevel@tonic-gate /* array is not a multiple of type size, error */ 6940Sstevel@tonic-gate *len_err = 1; 6950Sstevel@tonic-gate } 6960Sstevel@tonic-gate break; 6970Sstevel@tonic-gate case DDI_PROP_TYPE_INT: 6980Sstevel@tonic-gate if ((prop_len % sizeof (int)) == 0) { 6990Sstevel@tonic-gate *elem_size = sizeof (int); 7000Sstevel@tonic-gate *nelem = prop_len / *elem_size; 7010Sstevel@tonic-gate } else { 7020Sstevel@tonic-gate /* array is not a multiple of type size, error */ 7030Sstevel@tonic-gate *len_err = 1; 7040Sstevel@tonic-gate } 7050Sstevel@tonic-gate break; 7060Sstevel@tonic-gate case DDI_PROP_TYPE_STRING: 7070Sstevel@tonic-gate case DDI_PROP_TYPE_COMPOSITE: 7080Sstevel@tonic-gate case DDI_PROP_TYPE_ANY: 7090Sstevel@tonic-gate default: 7100Sstevel@tonic-gate /* 7110Sstevel@tonic-gate * if we made it here the type is either unknown 7120Sstevel@tonic-gate * or a string. Try to interpret is as a string 7130Sstevel@tonic-gate * and if that fails assume an array of bytes. 7140Sstevel@tonic-gate */ 7150Sstevel@tonic-gate if (prop_val[prop_len - 1] == '\0') { 7160Sstevel@tonic-gate unsigned char *s = prop_val; 7170Sstevel@tonic-gate int i; 7180Sstevel@tonic-gate 7190Sstevel@tonic-gate /* assume an array of strings */ 7200Sstevel@tonic-gate *elem_size = 0; 7210Sstevel@tonic-gate *nelem = 0; 7220Sstevel@tonic-gate 7230Sstevel@tonic-gate for (i = 0; i < prop_len; i++) { 7240Sstevel@tonic-gate if (prop_val[i] != '\0') 7250Sstevel@tonic-gate continue; 7260Sstevel@tonic-gate 7270Sstevel@tonic-gate /* 7280Sstevel@tonic-gate * If the property is typed as a string 7290Sstevel@tonic-gate * property, then interpret empty strings 7300Sstevel@tonic-gate * as strings. Otherwise default to an 7310Sstevel@tonic-gate * array of bytes. If there are unprintable 7320Sstevel@tonic-gate * characters, always default to an array of 7330Sstevel@tonic-gate * bytes. 7340Sstevel@tonic-gate */ 7350Sstevel@tonic-gate if ((*s == '\0' && type != 7360Sstevel@tonic-gate DDI_PROP_TYPE_STRING) || 7370Sstevel@tonic-gate !is_printable_string(s)) { 7380Sstevel@tonic-gate *elem_size = 1; 7390Sstevel@tonic-gate *nelem = prop_len; 7400Sstevel@tonic-gate break; 7410Sstevel@tonic-gate } 7420Sstevel@tonic-gate 7430Sstevel@tonic-gate (*nelem)++; 7440Sstevel@tonic-gate s = &prop_val[i + 1]; 7450Sstevel@tonic-gate } 7460Sstevel@tonic-gate } 7470Sstevel@tonic-gate break; 7480Sstevel@tonic-gate } 7490Sstevel@tonic-gate } 7500Sstevel@tonic-gate 7510Sstevel@tonic-gate static void 7520Sstevel@tonic-gate devinfo_print_props(char *name, ddi_prop_t *p) 7530Sstevel@tonic-gate { 7540Sstevel@tonic-gate if (p == NULL) 7550Sstevel@tonic-gate return; 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate if (name != NULL) 7580Sstevel@tonic-gate mdb_printf("%s ", name); 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate mdb_printf("properties at %p:\n", p); 7610Sstevel@tonic-gate mdb_inc_indent(DEVINFO_PROP_INDENT); 7620Sstevel@tonic-gate 7630Sstevel@tonic-gate while (p != NULL) { 7640Sstevel@tonic-gate ddi_prop_t prop; 7650Sstevel@tonic-gate char prop_name[128]; 7660Sstevel@tonic-gate unsigned char *prop_value; 7670Sstevel@tonic-gate int type, elem_size, nelem, prop_len_error; 7680Sstevel@tonic-gate 7690Sstevel@tonic-gate /* read in the property struct */ 7700Sstevel@tonic-gate if (mdb_vread(&prop, sizeof (prop), (uintptr_t)p) == -1) { 7710Sstevel@tonic-gate mdb_warn("could not read property at 0x%p", p); 7720Sstevel@tonic-gate break; 7730Sstevel@tonic-gate } 7740Sstevel@tonic-gate 7750Sstevel@tonic-gate /* print the property name */ 7760Sstevel@tonic-gate if (mdb_readstr(prop_name, sizeof (prop_name), 7770Sstevel@tonic-gate (uintptr_t)prop.prop_name) == -1) { 7780Sstevel@tonic-gate mdb_warn("could not read property name at 0x%p", 7790Sstevel@tonic-gate prop.prop_name); 7800Sstevel@tonic-gate goto next; 7810Sstevel@tonic-gate } 7820Sstevel@tonic-gate mdb_printf("name='%s' ", prop_name); 7830Sstevel@tonic-gate 7840Sstevel@tonic-gate /* get the property type and print it out */ 7850Sstevel@tonic-gate type = (prop.prop_flags & DDI_PROP_TYPE_MASK); 7860Sstevel@tonic-gate devinfo_print_props_type(type); 7870Sstevel@tonic-gate 7880Sstevel@tonic-gate /* get the property value */ 7890Sstevel@tonic-gate if (prop.prop_len > 0) { 7900Sstevel@tonic-gate prop_value = mdb_alloc(prop.prop_len, UM_SLEEP|UM_GC); 7910Sstevel@tonic-gate if (mdb_vread(prop_value, prop.prop_len, 7925839Sdmick (uintptr_t)prop.prop_val) == -1) { 7930Sstevel@tonic-gate mdb_warn("could not read property value at " 7940Sstevel@tonic-gate "0x%p", prop.prop_val); 7950Sstevel@tonic-gate goto next; 7960Sstevel@tonic-gate } 7970Sstevel@tonic-gate } else { 7980Sstevel@tonic-gate prop_value = NULL; 7990Sstevel@tonic-gate } 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate /* take a guess at interpreting the property value */ 8020Sstevel@tonic-gate devinfo_print_props_guess(type, prop_value, prop.prop_len, 8030Sstevel@tonic-gate &elem_size, &nelem, &prop_len_error); 8040Sstevel@tonic-gate 8050Sstevel@tonic-gate /* print out the number ot items */ 8060Sstevel@tonic-gate mdb_printf(" items=%d", nelem); 8070Sstevel@tonic-gate 8080Sstevel@tonic-gate /* print out any associated device information */ 8090Sstevel@tonic-gate if (prop.prop_dev != DDI_DEV_T_NONE) { 8100Sstevel@tonic-gate mdb_printf(" dev="); 8110Sstevel@tonic-gate if (prop.prop_dev == DDI_DEV_T_ANY) 8120Sstevel@tonic-gate mdb_printf("any"); 8130Sstevel@tonic-gate else if (prop.prop_dev == DDI_MAJOR_T_UNKNOWN) 8140Sstevel@tonic-gate mdb_printf("unknown"); 8150Sstevel@tonic-gate else 8160Sstevel@tonic-gate mdb_printf("(%u,%u)", 8170Sstevel@tonic-gate getmajor(prop.prop_dev), 8180Sstevel@tonic-gate getminor(prop.prop_dev)); 8190Sstevel@tonic-gate } 8200Sstevel@tonic-gate 8210Sstevel@tonic-gate /* print out the property value */ 8220Sstevel@tonic-gate if (prop_value != NULL) { 8230Sstevel@tonic-gate mdb_printf("\n"); 8240Sstevel@tonic-gate mdb_inc_indent(DEVINFO_PROP_INDENT); 8250Sstevel@tonic-gate if (prop_len_error) 8260Sstevel@tonic-gate mdb_printf("NOTE: prop length is not a " 8270Sstevel@tonic-gate "multiple of element size\n"); 8280Sstevel@tonic-gate devinfo_print_props_value(elem_size, nelem, 8290Sstevel@tonic-gate prop_value, prop.prop_len); 8300Sstevel@tonic-gate mdb_dec_indent(DEVINFO_PROP_INDENT); 8310Sstevel@tonic-gate } 8320Sstevel@tonic-gate 8330Sstevel@tonic-gate next: 8340Sstevel@tonic-gate mdb_printf("\n"); 8350Sstevel@tonic-gate p = prop.prop_next; 8360Sstevel@tonic-gate } 8370Sstevel@tonic-gate 8380Sstevel@tonic-gate mdb_dec_indent(DEVINFO_PROP_INDENT); 8390Sstevel@tonic-gate } 8400Sstevel@tonic-gate 8410Sstevel@tonic-gate static void 8420Sstevel@tonic-gate devinfo_pathinfo_state(mdi_pathinfo_state_t state) { 8430Sstevel@tonic-gate char *type_str = NULL; 8440Sstevel@tonic-gate 8450Sstevel@tonic-gate switch (state) { 8460Sstevel@tonic-gate case MDI_PATHINFO_STATE_INIT: 8470Sstevel@tonic-gate type_str = "init"; 8480Sstevel@tonic-gate break; 8490Sstevel@tonic-gate case MDI_PATHINFO_STATE_ONLINE: 8500Sstevel@tonic-gate type_str = "online"; 8510Sstevel@tonic-gate break; 8520Sstevel@tonic-gate case MDI_PATHINFO_STATE_STANDBY: 8530Sstevel@tonic-gate type_str = "standby"; 8540Sstevel@tonic-gate break; 8550Sstevel@tonic-gate case MDI_PATHINFO_STATE_FAULT: 8560Sstevel@tonic-gate type_str = "fault"; 8570Sstevel@tonic-gate break; 8580Sstevel@tonic-gate case MDI_PATHINFO_STATE_OFFLINE: 8590Sstevel@tonic-gate type_str = "offline"; 8600Sstevel@tonic-gate break; 8610Sstevel@tonic-gate } 8620Sstevel@tonic-gate if (type_str != NULL) 8630Sstevel@tonic-gate mdb_printf("state=%s\n", type_str); 8640Sstevel@tonic-gate else 8650Sstevel@tonic-gate mdb_printf("state=0x%x\n", state); 8660Sstevel@tonic-gate } 8670Sstevel@tonic-gate 8680Sstevel@tonic-gate static void 8690Sstevel@tonic-gate devinfo_print_pathing(int mdi_component, void *mdi_client) { 8700Sstevel@tonic-gate mdi_client_t mdi_c; 8710Sstevel@tonic-gate struct mdi_pathinfo *pip; 8720Sstevel@tonic-gate 8730Sstevel@tonic-gate /* we only print out multipathing info for client nodes */ 8740Sstevel@tonic-gate if ((mdi_component & MDI_COMPONENT_CLIENT) == 0) 8750Sstevel@tonic-gate return; 8760Sstevel@tonic-gate 8770Sstevel@tonic-gate mdb_printf("Client multipath info at: 0x%p\n", mdi_client); 8780Sstevel@tonic-gate mdb_inc_indent(DEVINFO_PROP_INDENT); 8790Sstevel@tonic-gate 8800Sstevel@tonic-gate /* read in the client multipathing info */ 8810Sstevel@tonic-gate if (mdb_readstr((void*) &mdi_c, sizeof (mdi_c), 8820Sstevel@tonic-gate (uintptr_t)mdi_client) == -1) { 8830Sstevel@tonic-gate mdb_warn("failed to read mdi_client at %p", 8840Sstevel@tonic-gate (uintptr_t)mdi_client); 8850Sstevel@tonic-gate goto exit; 8860Sstevel@tonic-gate } 8870Sstevel@tonic-gate 8880Sstevel@tonic-gate /* 8890Sstevel@tonic-gate * walk through the clients list of pathinfo structures and print 8900Sstevel@tonic-gate * out the properties for each path 8910Sstevel@tonic-gate */ 8920Sstevel@tonic-gate pip = (struct mdi_pathinfo *)mdi_c.ct_path_head; 8930Sstevel@tonic-gate while (pip != NULL) { 8940Sstevel@tonic-gate char binding_name[128]; 8950Sstevel@tonic-gate struct mdi_pathinfo pi; 8960Sstevel@tonic-gate mdi_phci_t ph; 8970Sstevel@tonic-gate struct dev_info ph_di; 8980Sstevel@tonic-gate 8990Sstevel@tonic-gate /* read in the pathinfo structure */ 9000Sstevel@tonic-gate if (mdb_vread((void*)&pi, sizeof (pi), 9010Sstevel@tonic-gate (uintptr_t)pip) == -1) { 9020Sstevel@tonic-gate mdb_warn("failed to read mdi_pathinfo at %p", 9030Sstevel@tonic-gate (uintptr_t)pip); 9040Sstevel@tonic-gate goto exit; 9050Sstevel@tonic-gate } 9060Sstevel@tonic-gate 9070Sstevel@tonic-gate /* read in the pchi (path host adapter) info */ 9080Sstevel@tonic-gate if (mdb_vread((void*)&ph, sizeof (ph), 9090Sstevel@tonic-gate (uintptr_t)pi.pi_phci) == -1) { 9100Sstevel@tonic-gate mdb_warn("failed to read mdi_pchi at %p", 9110Sstevel@tonic-gate (uintptr_t)pi.pi_phci); 9120Sstevel@tonic-gate goto exit; 9130Sstevel@tonic-gate } 9140Sstevel@tonic-gate 9150Sstevel@tonic-gate /* read in the dip of the phci so we can get it's name */ 9160Sstevel@tonic-gate if (mdb_vread((void*)&ph_di, sizeof (ph_di), 9170Sstevel@tonic-gate (uintptr_t)ph.ph_dip) == -1) { 9180Sstevel@tonic-gate mdb_warn("failed to read mdi_pchi at %p", 9190Sstevel@tonic-gate (uintptr_t)ph.ph_dip); 9200Sstevel@tonic-gate goto exit; 9210Sstevel@tonic-gate } 9220Sstevel@tonic-gate if (mdb_vread(binding_name, sizeof (binding_name), 9230Sstevel@tonic-gate (uintptr_t)ph_di.devi_binding_name) == -1) { 9240Sstevel@tonic-gate mdb_warn("failed to read binding_name at %p", 9250Sstevel@tonic-gate (uintptr_t)ph_di.devi_binding_name); 9260Sstevel@tonic-gate goto exit; 9270Sstevel@tonic-gate } 9280Sstevel@tonic-gate 9290Sstevel@tonic-gate mdb_printf("%s#%d, ", binding_name, ph_di.devi_instance); 9300Sstevel@tonic-gate devinfo_pathinfo_state(pi.pi_state); 9310Sstevel@tonic-gate 9320Sstevel@tonic-gate /* print out the pathing info */ 9330Sstevel@tonic-gate mdb_inc_indent(DEVINFO_PROP_INDENT); 9340Sstevel@tonic-gate if (mdb_pwalk_dcmd(NVPAIR_WALKER_FQNAME, NVPAIR_DCMD_FQNAME, 9350Sstevel@tonic-gate 0, NULL, (uintptr_t)pi.pi_prop) != 0) { 9360Sstevel@tonic-gate mdb_dec_indent(DEVINFO_PROP_INDENT); 9370Sstevel@tonic-gate goto exit; 9380Sstevel@tonic-gate } 9390Sstevel@tonic-gate mdb_dec_indent(DEVINFO_PROP_INDENT); 9400Sstevel@tonic-gate pip = pi.pi_client_link; 9410Sstevel@tonic-gate } 9420Sstevel@tonic-gate 9430Sstevel@tonic-gate exit: 9440Sstevel@tonic-gate mdb_dec_indent(DEVINFO_PROP_INDENT); 9450Sstevel@tonic-gate } 9460Sstevel@tonic-gate 9470Sstevel@tonic-gate static int 9480Sstevel@tonic-gate devinfo_print(uintptr_t addr, struct dev_info *dev, devinfo_cb_data_t *data) 9490Sstevel@tonic-gate { 9500Sstevel@tonic-gate /* 9510Sstevel@tonic-gate * We know the walker passes us extra data after the dev_info. 9520Sstevel@tonic-gate */ 9530Sstevel@tonic-gate char binding_name[128]; 9541125Seschrock char dname[MODMAXNAMELEN + 1]; 9550Sstevel@tonic-gate devinfo_node_t *din = (devinfo_node_t *)dev; 9560Sstevel@tonic-gate ddi_prop_t *global_props = NULL; 9570Sstevel@tonic-gate 9580Sstevel@tonic-gate if (mdb_readstr(binding_name, sizeof (binding_name), 9590Sstevel@tonic-gate (uintptr_t)dev->devi_binding_name) == -1) { 9600Sstevel@tonic-gate mdb_warn("failed to read binding_name at %p", 9610Sstevel@tonic-gate (uintptr_t)dev->devi_binding_name); 9620Sstevel@tonic-gate return (WALK_ERR); 9630Sstevel@tonic-gate } 9640Sstevel@tonic-gate 9650Sstevel@tonic-gate /* if there are any global properties, get a pointer to them */ 9660Sstevel@tonic-gate if (dev->devi_global_prop_list != NULL) { 9670Sstevel@tonic-gate ddi_prop_list_t plist; 9680Sstevel@tonic-gate if (mdb_vread((void*)&plist, sizeof (plist), 9695839Sdmick (uintptr_t)dev->devi_global_prop_list) == -1) { 9700Sstevel@tonic-gate mdb_warn("failed to read global prop_list at %p", 9710Sstevel@tonic-gate (uintptr_t)dev->devi_global_prop_list); 9720Sstevel@tonic-gate return (WALK_ERR); 9730Sstevel@tonic-gate } 9740Sstevel@tonic-gate global_props = plist.prop_list; 9750Sstevel@tonic-gate } 9760Sstevel@tonic-gate 9770Sstevel@tonic-gate mdb_inc_indent(din->din_depth * DEVINFO_TREE_INDENT); 9780Sstevel@tonic-gate if ((addr == data->di_base) || (data->di_flags & DEVINFO_ALLBOLD)) 9790Sstevel@tonic-gate mdb_printf("%<b>"); 9800Sstevel@tonic-gate mdb_printf("%-0?p %s", addr, binding_name); 9810Sstevel@tonic-gate if ((addr == data->di_base) || (data->di_flags & DEVINFO_ALLBOLD)) 9820Sstevel@tonic-gate mdb_printf("%</b>"); 9830Sstevel@tonic-gate if (dev->devi_instance >= 0) 9840Sstevel@tonic-gate mdb_printf(", instance #%d", dev->devi_instance); 9851125Seschrock 9861125Seschrock if (dev->devi_node_state < DS_ATTACHED) 9870Sstevel@tonic-gate mdb_printf(" (driver not attached)"); 9881125Seschrock else if (mdb_devinfo2driver(addr, dname, sizeof (dname)) != 0) 9891125Seschrock mdb_printf(" (could not determine driver name)"); 9901125Seschrock else 9911125Seschrock mdb_printf(" (driver name: %s)", dname); 9921125Seschrock 9930Sstevel@tonic-gate mdb_printf("\n"); 9940Sstevel@tonic-gate if (data->di_flags & DEVINFO_VERBOSE) { 9950Sstevel@tonic-gate mdb_inc_indent(DEVINFO_PROPLIST_INDENT); 9960Sstevel@tonic-gate devinfo_print_props("System", dev->devi_sys_prop_ptr); 9970Sstevel@tonic-gate devinfo_print_props("Driver", dev->devi_drv_prop_ptr); 9980Sstevel@tonic-gate devinfo_print_props("Hardware", dev->devi_hw_prop_ptr); 9990Sstevel@tonic-gate devinfo_print_props("Global", global_props); 10000Sstevel@tonic-gate 10010Sstevel@tonic-gate devinfo_print_pathing(dev->devi_mdi_component, 10020Sstevel@tonic-gate dev->devi_mdi_client); 10030Sstevel@tonic-gate 10040Sstevel@tonic-gate mdb_dec_indent(DEVINFO_PROPLIST_INDENT); 10050Sstevel@tonic-gate } 10060Sstevel@tonic-gate 10070Sstevel@tonic-gate mdb_dec_indent(din->din_depth * DEVINFO_TREE_INDENT); 10080Sstevel@tonic-gate return (WALK_NEXT); 10090Sstevel@tonic-gate } 10100Sstevel@tonic-gate 10110Sstevel@tonic-gate /*ARGSUSED*/ 10120Sstevel@tonic-gate int 10130Sstevel@tonic-gate prtconf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 10140Sstevel@tonic-gate { 10150Sstevel@tonic-gate devinfo_cb_data_t data; 10165839Sdmick uintptr_t devinfo_root; /* Address of root of devinfo tree */ 10170Sstevel@tonic-gate int status; 10180Sstevel@tonic-gate 10190Sstevel@tonic-gate data.di_flags = DEVINFO_PARENT | DEVINFO_CHILD; 10200Sstevel@tonic-gate 10210Sstevel@tonic-gate if (mdb_getopts(argc, argv, 10220Sstevel@tonic-gate 'v', MDB_OPT_SETBITS, DEVINFO_VERBOSE, &data.di_flags, 10230Sstevel@tonic-gate 'p', MDB_OPT_CLRBITS, DEVINFO_CHILD, &data.di_flags, 10240Sstevel@tonic-gate 'c', MDB_OPT_CLRBITS, DEVINFO_PARENT, &data.di_flags, NULL) != argc) 10250Sstevel@tonic-gate return (DCMD_USAGE); 10260Sstevel@tonic-gate 10275839Sdmick if (mdb_readvar(&devinfo_root, "top_devinfo") == -1) { 10285839Sdmick mdb_warn("failed to read 'top_devinfo'"); 10295839Sdmick return (NULL); 10305839Sdmick } 10315839Sdmick 10320Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == 0) { 10330Sstevel@tonic-gate addr = devinfo_root; 10340Sstevel@tonic-gate if (data.di_flags & DEVINFO_VERBOSE) 10350Sstevel@tonic-gate data.di_flags |= DEVINFO_ALLBOLD; 10360Sstevel@tonic-gate } 10370Sstevel@tonic-gate 10380Sstevel@tonic-gate data.di_base = addr; 10390Sstevel@tonic-gate mdb_printf("%<u>%-?s %-50s%</u>\n", "DEVINFO", "NAME"); 10400Sstevel@tonic-gate 10410Sstevel@tonic-gate if ((data.di_flags & (DEVINFO_PARENT | DEVINFO_CHILD)) == 10420Sstevel@tonic-gate (DEVINFO_PARENT | DEVINFO_CHILD)) { 10430Sstevel@tonic-gate status = mdb_pwalk("devinfo", 10440Sstevel@tonic-gate (mdb_walk_cb_t)devinfo_print, &data, addr); 10450Sstevel@tonic-gate } else if (data.di_flags & DEVINFO_PARENT) { 10460Sstevel@tonic-gate status = mdb_pwalk("devinfo_parents", 10470Sstevel@tonic-gate (mdb_walk_cb_t)devinfo_print, &data, addr); 10480Sstevel@tonic-gate } else if (data.di_flags & DEVINFO_CHILD) { 10490Sstevel@tonic-gate status = mdb_pwalk("devinfo_children", 10500Sstevel@tonic-gate (mdb_walk_cb_t)devinfo_print, &data, addr); 10510Sstevel@tonic-gate } else { 10520Sstevel@tonic-gate devinfo_node_t din; 10530Sstevel@tonic-gate if (mdb_vread(&din.din_dev, sizeof (din.din_dev), addr) == -1) { 10540Sstevel@tonic-gate mdb_warn("failed to read device"); 10550Sstevel@tonic-gate return (DCMD_ERR); 10560Sstevel@tonic-gate } 10570Sstevel@tonic-gate din.din_depth = 0; 10580Sstevel@tonic-gate return (devinfo_print(addr, (struct dev_info *)&din, &data)); 10590Sstevel@tonic-gate } 10600Sstevel@tonic-gate 10610Sstevel@tonic-gate if (status == -1) { 10620Sstevel@tonic-gate mdb_warn("couldn't walk devinfo tree"); 10630Sstevel@tonic-gate return (DCMD_ERR); 10640Sstevel@tonic-gate } 10650Sstevel@tonic-gate 10660Sstevel@tonic-gate return (DCMD_OK); 10670Sstevel@tonic-gate } 10680Sstevel@tonic-gate 10690Sstevel@tonic-gate /*ARGSUSED*/ 10700Sstevel@tonic-gate int 10710Sstevel@tonic-gate devinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 10720Sstevel@tonic-gate { 10730Sstevel@tonic-gate char tmpstr[MODMAXNAMELEN]; 10740Sstevel@tonic-gate char nodename[MODMAXNAMELEN]; 10754145Scth char bindname[MAXPATHLEN]; 10760Sstevel@tonic-gate int size, length; 10770Sstevel@tonic-gate struct dev_info devi; 10780Sstevel@tonic-gate devinfo_node_t din; 10790Sstevel@tonic-gate devinfo_cb_data_t data; 10800Sstevel@tonic-gate 10810Sstevel@tonic-gate static const mdb_bitmask_t devi_state_masks[] = { 10820Sstevel@tonic-gate { "DEVICE_OFFLINE", DEVI_DEVICE_OFFLINE, DEVI_DEVICE_OFFLINE }, 10830Sstevel@tonic-gate { "DEVICE_DOWN", DEVI_DEVICE_DOWN, DEVI_DEVICE_DOWN }, 10840Sstevel@tonic-gate { "DEVICE_DEGRADED", DEVI_DEVICE_DEGRADED, DEVI_DEVICE_DEGRADED }, 10854145Scth { "DEVICE_REMOVED", DEVI_DEVICE_REMOVED, DEVI_DEVICE_REMOVED }, 10860Sstevel@tonic-gate { "BUS_QUIESCED", DEVI_BUS_QUIESCED, DEVI_BUS_QUIESCED }, 10870Sstevel@tonic-gate { "BUS_DOWN", DEVI_BUS_DOWN, DEVI_BUS_DOWN }, 10880Sstevel@tonic-gate { "NDI_CONFIG", DEVI_NDI_CONFIG, DEVI_NDI_CONFIG }, 10890Sstevel@tonic-gate 10900Sstevel@tonic-gate { "S_ATTACHING", DEVI_S_ATTACHING, DEVI_S_ATTACHING }, 10910Sstevel@tonic-gate { "S_DETACHING", DEVI_S_DETACHING, DEVI_S_DETACHING }, 10920Sstevel@tonic-gate { "S_ONLINING", DEVI_S_ONLINING, DEVI_S_ONLINING }, 10930Sstevel@tonic-gate { "S_OFFLINING", DEVI_S_OFFLINING, DEVI_S_OFFLINING }, 10940Sstevel@tonic-gate { "S_INVOKING_DACF", DEVI_S_INVOKING_DACF, DEVI_S_INVOKING_DACF }, 10950Sstevel@tonic-gate { "S_UNBOUND", DEVI_S_UNBOUND, DEVI_S_UNBOUND }, 10960Sstevel@tonic-gate { "S_REPORT", DEVI_S_REPORT, DEVI_S_REPORT }, 10970Sstevel@tonic-gate { "S_EVADD", DEVI_S_EVADD, DEVI_S_EVADD }, 10980Sstevel@tonic-gate { "S_EVREMOVE", DEVI_S_EVREMOVE, DEVI_S_EVREMOVE }, 10994145Scth { "S_NEED_RESET", DEVI_S_NEED_RESET, DEVI_S_NEED_RESET }, 11000Sstevel@tonic-gate { NULL, 0, 0 } 11010Sstevel@tonic-gate }; 11020Sstevel@tonic-gate 11030Sstevel@tonic-gate static const mdb_bitmask_t devi_flags_masks[] = { 11040Sstevel@tonic-gate { "BUSY", DEVI_BUSY, DEVI_BUSY }, 11050Sstevel@tonic-gate { "MADE_CHILDREN", DEVI_MADE_CHILDREN, DEVI_MADE_CHILDREN }, 11060Sstevel@tonic-gate { "ATTACHED_CHILDREN", 11070Sstevel@tonic-gate DEVI_ATTACHED_CHILDREN, DEVI_ATTACHED_CHILDREN}, 11080Sstevel@tonic-gate { "BRANCH_HELD", DEVI_BRANCH_HELD, DEVI_BRANCH_HELD }, 11094145Scth { "NO_BIND", DEVI_NO_BIND, DEVI_NO_BIND }, 1110*13015Sgavin.maltby@oracle.com { "DEVI_CACHED_DEVID", 1111*13015Sgavin.maltby@oracle.com DEVI_CACHED_DEVID, DEVI_CACHED_DEVID }, 11124145Scth { "PHCI_SIGNALS_VHCI", 11134145Scth DEVI_PHCI_SIGNALS_VHCI, 11144145Scth DEVI_PHCI_SIGNALS_VHCI }, 11154145Scth { "REBIND", DEVI_REBIND, DEVI_REBIND }, 11160Sstevel@tonic-gate { NULL, 0, 0 } 11170Sstevel@tonic-gate }; 11180Sstevel@tonic-gate 11190Sstevel@tonic-gate data.di_flags = DEVINFO_VERBOSE; 11200Sstevel@tonic-gate data.di_base = addr; 11210Sstevel@tonic-gate 11220Sstevel@tonic-gate if (mdb_getopts(argc, argv, 11230Sstevel@tonic-gate 'q', MDB_OPT_CLRBITS, DEVINFO_VERBOSE, &data.di_flags, 11240Sstevel@tonic-gate 's', MDB_OPT_SETBITS, DEVINFO_SUMMARY, &data.di_flags, NULL) 11250Sstevel@tonic-gate != argc) 11260Sstevel@tonic-gate return (DCMD_USAGE); 11270Sstevel@tonic-gate 11280Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == 0) { 11290Sstevel@tonic-gate mdb_warn( 11300Sstevel@tonic-gate "devinfo doesn't give global information (try prtconf)\n"); 11310Sstevel@tonic-gate return (DCMD_ERR); 11320Sstevel@tonic-gate } 11330Sstevel@tonic-gate 11340Sstevel@tonic-gate if (DCMD_HDRSPEC(flags) && data.di_flags & DEVINFO_SUMMARY) 11350Sstevel@tonic-gate mdb_printf( 11360Sstevel@tonic-gate "%-?s %5s %?s %-20s %-s\n" 11370Sstevel@tonic-gate "%-?s %5s %?s %-20s %-s\n" 11380Sstevel@tonic-gate "%<u>%-?s %5s %?s %-20s %-15s%</u>\n", 11390Sstevel@tonic-gate "DEVINFO", "MAJ", "REFCNT", "NODENAME", "NODESTATE", 11400Sstevel@tonic-gate "", "INST", "CIRCULAR", "BINDNAME", "STATE", 11410Sstevel@tonic-gate "", "", "THREAD", "", "FLAGS"); 11420Sstevel@tonic-gate 11430Sstevel@tonic-gate if (mdb_vread(&devi, sizeof (devi), addr) == -1) { 11440Sstevel@tonic-gate mdb_warn("failed to read device"); 11450Sstevel@tonic-gate return (DCMD_ERR); 11460Sstevel@tonic-gate } 11470Sstevel@tonic-gate 11480Sstevel@tonic-gate if (data.di_flags & DEVINFO_SUMMARY) { 11490Sstevel@tonic-gate *nodename = '\0'; 11500Sstevel@tonic-gate size = sizeof (nodename); 11510Sstevel@tonic-gate 11520Sstevel@tonic-gate if ((length = mdb_readstr(tmpstr, size, 11530Sstevel@tonic-gate (uintptr_t)devi.devi_node_name)) > 0) { 11540Sstevel@tonic-gate strcat(nodename, tmpstr); 11550Sstevel@tonic-gate size -= length; 11560Sstevel@tonic-gate } 11570Sstevel@tonic-gate 11580Sstevel@tonic-gate if (devi.devi_addr != NULL && mdb_readstr(tmpstr, size - 1, 11590Sstevel@tonic-gate (uintptr_t)devi.devi_addr) > 0) { 11600Sstevel@tonic-gate strcat(nodename, "@"); 11610Sstevel@tonic-gate strcat(nodename, tmpstr); 11620Sstevel@tonic-gate } 11630Sstevel@tonic-gate 11640Sstevel@tonic-gate if (mdb_readstr(bindname, sizeof (bindname), 11650Sstevel@tonic-gate (uintptr_t)devi.devi_binding_name) == -1) 11660Sstevel@tonic-gate *bindname = '\0'; 11670Sstevel@tonic-gate 11680Sstevel@tonic-gate mdb_printf("%0?p %5d %?d %-20s %s\n", 11690Sstevel@tonic-gate addr, devi.devi_major, devi.devi_ref, nodename, 11700Sstevel@tonic-gate di_state[MIN(devi.devi_node_state + 1, DI_STATE_MAX)]); 11710Sstevel@tonic-gate mdb_printf("%?s %5d %?d %-20s <%b>\n", 11720Sstevel@tonic-gate "", devi.devi_instance, devi.devi_circular, bindname, 11730Sstevel@tonic-gate devi.devi_state, devi_state_masks); 11740Sstevel@tonic-gate mdb_printf("%?s %5s %?p %-20s <%b>\n\n", 11750Sstevel@tonic-gate "", "", devi.devi_busy_thread, "", 11760Sstevel@tonic-gate devi.devi_flags, devi_flags_masks); 11770Sstevel@tonic-gate 11780Sstevel@tonic-gate return (DCMD_OK); 11790Sstevel@tonic-gate } else { 11800Sstevel@tonic-gate din.din_dev = devi; 11810Sstevel@tonic-gate din.din_depth = 0; 11820Sstevel@tonic-gate return (devinfo_print(addr, (struct dev_info *)&din, &data)); 11830Sstevel@tonic-gate } 11840Sstevel@tonic-gate } 11850Sstevel@tonic-gate 11860Sstevel@tonic-gate /*ARGSUSED*/ 11870Sstevel@tonic-gate int 11880Sstevel@tonic-gate m2d_walk_dinfo(uintptr_t addr, struct dev_info *di, char *mod_name) 11890Sstevel@tonic-gate { 11900Sstevel@tonic-gate char name[MODMAXNAMELEN]; 11910Sstevel@tonic-gate 11920Sstevel@tonic-gate if (mdb_readstr(name, MODMAXNAMELEN, 11930Sstevel@tonic-gate (uintptr_t)di->devi_binding_name) == -1) { 11940Sstevel@tonic-gate mdb_warn("couldn't read devi_binding_name at %p", 11950Sstevel@tonic-gate di->devi_binding_name); 11960Sstevel@tonic-gate return (WALK_ERR); 11970Sstevel@tonic-gate } 11980Sstevel@tonic-gate 11990Sstevel@tonic-gate if (strcmp(name, mod_name) == 0) 12000Sstevel@tonic-gate mdb_printf("%p\n", addr); 12010Sstevel@tonic-gate 12020Sstevel@tonic-gate return (WALK_NEXT); 12030Sstevel@tonic-gate } 12040Sstevel@tonic-gate 12050Sstevel@tonic-gate /*ARGSUSED*/ 12060Sstevel@tonic-gate int 12070Sstevel@tonic-gate modctl2devinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 12080Sstevel@tonic-gate { 12090Sstevel@tonic-gate struct modctl modctl; 12100Sstevel@tonic-gate char name[MODMAXNAMELEN]; 12110Sstevel@tonic-gate 12120Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 12130Sstevel@tonic-gate return (DCMD_USAGE); 12140Sstevel@tonic-gate 12150Sstevel@tonic-gate if (mdb_vread(&modctl, sizeof (modctl), addr) == -1) { 12160Sstevel@tonic-gate mdb_warn("couldn't read modctl at %p", addr); 12170Sstevel@tonic-gate return (DCMD_ERR); 12180Sstevel@tonic-gate } 12190Sstevel@tonic-gate 12200Sstevel@tonic-gate if (mdb_readstr(name, MODMAXNAMELEN, 12210Sstevel@tonic-gate (uintptr_t)modctl.mod_modname) == -1) { 12220Sstevel@tonic-gate mdb_warn("couldn't read modname at %p", modctl.mod_modname); 12230Sstevel@tonic-gate return (DCMD_ERR); 12240Sstevel@tonic-gate } 12250Sstevel@tonic-gate 12260Sstevel@tonic-gate if (mdb_walk("devinfo", (mdb_walk_cb_t)m2d_walk_dinfo, name) == -1) { 12270Sstevel@tonic-gate mdb_warn("couldn't walk devinfo"); 12280Sstevel@tonic-gate return (DCMD_ERR); 12290Sstevel@tonic-gate } 12300Sstevel@tonic-gate 12310Sstevel@tonic-gate return (DCMD_OK); 12320Sstevel@tonic-gate } 12330Sstevel@tonic-gate 12340Sstevel@tonic-gate static int 12350Sstevel@tonic-gate major_to_addr(major_t major, uintptr_t *vaddr) 12360Sstevel@tonic-gate { 12370Sstevel@tonic-gate uint_t devcnt; 12380Sstevel@tonic-gate uintptr_t devnamesp; 12390Sstevel@tonic-gate 12400Sstevel@tonic-gate if (mdb_readvar(&devcnt, "devcnt") == -1) { 12410Sstevel@tonic-gate mdb_warn("failed to read 'devcnt'"); 12420Sstevel@tonic-gate return (-1); 12430Sstevel@tonic-gate } 12440Sstevel@tonic-gate 12450Sstevel@tonic-gate if (mdb_readvar(&devnamesp, "devnamesp") == -1) { 12460Sstevel@tonic-gate mdb_warn("failed to read 'devnamesp'"); 12470Sstevel@tonic-gate return (-1); 12480Sstevel@tonic-gate } 12490Sstevel@tonic-gate 12500Sstevel@tonic-gate if (major >= devcnt) { 12510Sstevel@tonic-gate mdb_warn("%x is out of range [0x0-0x%x]\n", major, devcnt - 1); 12520Sstevel@tonic-gate return (-1); 12530Sstevel@tonic-gate } 12540Sstevel@tonic-gate 12550Sstevel@tonic-gate *vaddr = devnamesp + (major * sizeof (struct devnames)); 12560Sstevel@tonic-gate return (0); 12570Sstevel@tonic-gate } 12580Sstevel@tonic-gate 12590Sstevel@tonic-gate /*ARGSUSED*/ 12600Sstevel@tonic-gate int 12610Sstevel@tonic-gate devnames(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 12620Sstevel@tonic-gate { 12630Sstevel@tonic-gate static const mdb_bitmask_t dn_flag_bits[] = { 12640Sstevel@tonic-gate { "DN_CONF_PARSED", DN_CONF_PARSED, DN_CONF_PARSED }, 12650Sstevel@tonic-gate { "DN_DRIVER_BUSY", DN_DRIVER_BUSY, DN_DRIVER_BUSY }, 12660Sstevel@tonic-gate { "DN_DRIVER_HELD", DN_DRIVER_HELD, DN_DRIVER_HELD }, 12670Sstevel@tonic-gate { "DN_TAKEN_GETUDEV", DN_TAKEN_GETUDEV, DN_TAKEN_GETUDEV }, 12680Sstevel@tonic-gate { "DN_DRIVER_REMOVED", DN_DRIVER_REMOVED, DN_DRIVER_REMOVED}, 12690Sstevel@tonic-gate { "DN_FORCE_ATTACH", DN_FORCE_ATTACH, DN_FORCE_ATTACH}, 12700Sstevel@tonic-gate { "DN_LEAF_DRIVER", DN_LEAF_DRIVER, DN_LEAF_DRIVER}, 12710Sstevel@tonic-gate { "DN_NETWORK_DRIVER", DN_NETWORK_DRIVER, DN_NETWORK_DRIVER}, 12720Sstevel@tonic-gate { "DN_NO_AUTODETACH", DN_NO_AUTODETACH, DN_NO_AUTODETACH }, 1273385Scth { "DN_GLDV3_DRIVER", DN_GLDV3_DRIVER, DN_GLDV3_DRIVER}, 12741993Sramat { "DN_PHCI_DRIVER", DN_PHCI_DRIVER, DN_PHCI_DRIVER}, 12756640Scth { "DN_OPEN_RETURNS_EINTR", \ 12766640Scth DN_OPEN_RETURNS_EINTR, DN_OPEN_RETURNS_EINTR}, 12776640Scth { "DN_SCSI_SIZE_CLEAN", DN_SCSI_SIZE_CLEAN, DN_SCSI_SIZE_CLEAN}, 127810788SCathy.Zhou@Sun.COM { "DN_NETWORK_PHYSDRIVER", \ 127910788SCathy.Zhou@Sun.COM DN_NETWORK_PHYSDRIVER, DN_NETWORK_PHYSDRIVER}, 12800Sstevel@tonic-gate { NULL, 0, 0 } 12810Sstevel@tonic-gate }; 12820Sstevel@tonic-gate 12830Sstevel@tonic-gate const mdb_arg_t *argp = NULL; 12840Sstevel@tonic-gate uint_t opt_v = FALSE, opt_m = FALSE; 12850Sstevel@tonic-gate major_t major; 12860Sstevel@tonic-gate size_t i; 12870Sstevel@tonic-gate 12880Sstevel@tonic-gate char name[MODMAXNAMELEN + 1]; 12890Sstevel@tonic-gate struct devnames dn; 12900Sstevel@tonic-gate 12910Sstevel@tonic-gate if ((i = mdb_getopts(argc, argv, 12920Sstevel@tonic-gate 'm', MDB_OPT_SETBITS, TRUE, &opt_m, 12930Sstevel@tonic-gate 'v', MDB_OPT_SETBITS, TRUE, &opt_v, 12940Sstevel@tonic-gate NULL)) != argc) { 12950Sstevel@tonic-gate if (argc - i > 1) 12960Sstevel@tonic-gate return (DCMD_USAGE); 12970Sstevel@tonic-gate argp = &argv[i]; 12980Sstevel@tonic-gate } 12990Sstevel@tonic-gate 13000Sstevel@tonic-gate if (opt_m) { 13010Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 13020Sstevel@tonic-gate return (DCMD_USAGE); 13030Sstevel@tonic-gate 13040Sstevel@tonic-gate if (major_to_addr(addr, &addr) == -1) 13050Sstevel@tonic-gate return (DCMD_ERR); 13060Sstevel@tonic-gate 13070Sstevel@tonic-gate } else if (!(flags & DCMD_ADDRSPEC)) { 13080Sstevel@tonic-gate if (argp == NULL) { 13090Sstevel@tonic-gate if (mdb_walk_dcmd("devnames", "devnames", argc, argv)) { 13100Sstevel@tonic-gate mdb_warn("failed to walk devnames"); 13110Sstevel@tonic-gate return (DCMD_ERR); 13120Sstevel@tonic-gate } 13130Sstevel@tonic-gate return (DCMD_OK); 13140Sstevel@tonic-gate } 13150Sstevel@tonic-gate 13160Sstevel@tonic-gate if (argp->a_type == MDB_TYPE_IMMEDIATE) 13170Sstevel@tonic-gate major = (major_t)argp->a_un.a_val; 13180Sstevel@tonic-gate else 13190Sstevel@tonic-gate major = (major_t)mdb_strtoull(argp->a_un.a_str); 13200Sstevel@tonic-gate 13210Sstevel@tonic-gate if (major_to_addr(major, &addr) == -1) 13220Sstevel@tonic-gate return (DCMD_ERR); 13230Sstevel@tonic-gate } 13240Sstevel@tonic-gate 13250Sstevel@tonic-gate if (mdb_vread(&dn, sizeof (struct devnames), addr) == -1) { 13260Sstevel@tonic-gate mdb_warn("failed to read devnames struct at %p", addr); 13270Sstevel@tonic-gate return (DCMD_ERR); 13280Sstevel@tonic-gate } 13290Sstevel@tonic-gate 13300Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 13310Sstevel@tonic-gate if (opt_v) 13320Sstevel@tonic-gate mdb_printf("%<u>%-16s%</u>\n", "NAME"); 13330Sstevel@tonic-gate else 13340Sstevel@tonic-gate mdb_printf("%<u>%-16s %-?s%</u>\n", "NAME", "DN_HEAD"); 13350Sstevel@tonic-gate } 13360Sstevel@tonic-gate 13370Sstevel@tonic-gate if ((flags & DCMD_LOOP) && (dn.dn_name == NULL)) 13380Sstevel@tonic-gate return (DCMD_OK); /* Skip empty slots if we're printing table */ 13390Sstevel@tonic-gate 13400Sstevel@tonic-gate if (mdb_readstr(name, sizeof (name), (uintptr_t)dn.dn_name) == -1) 13410Sstevel@tonic-gate (void) mdb_snprintf(name, sizeof (name), "0x%p", dn.dn_name); 13420Sstevel@tonic-gate 13430Sstevel@tonic-gate if (opt_v) { 13440Sstevel@tonic-gate ddi_prop_list_t prop_list; 13450Sstevel@tonic-gate mdb_printf("%<b>%-16s%</b>\n", name); 13460Sstevel@tonic-gate mdb_inc_indent(2); 13470Sstevel@tonic-gate 13480Sstevel@tonic-gate mdb_printf(" flags %b\n", dn.dn_flags, dn_flag_bits); 13490Sstevel@tonic-gate mdb_printf(" pl %p\n", (void *)dn.dn_pl); 13500Sstevel@tonic-gate mdb_printf(" head %p\n", dn.dn_head); 13510Sstevel@tonic-gate mdb_printf(" instance %d\n", dn.dn_instance); 13520Sstevel@tonic-gate mdb_printf(" inlist %p\n", dn.dn_inlist); 13530Sstevel@tonic-gate mdb_printf("global_prop_ptr %p\n", dn.dn_global_prop_ptr); 13540Sstevel@tonic-gate if (mdb_vread(&prop_list, sizeof (ddi_prop_list_t), 13550Sstevel@tonic-gate (uintptr_t)dn.dn_global_prop_ptr) != -1) { 13560Sstevel@tonic-gate devinfo_print_props(NULL, prop_list.prop_list); 13570Sstevel@tonic-gate } 13580Sstevel@tonic-gate 13590Sstevel@tonic-gate mdb_dec_indent(2); 13600Sstevel@tonic-gate } else 13610Sstevel@tonic-gate mdb_printf("%-16s %-?p\n", name, dn.dn_head); 13620Sstevel@tonic-gate 13630Sstevel@tonic-gate return (DCMD_OK); 13640Sstevel@tonic-gate } 13650Sstevel@tonic-gate 13660Sstevel@tonic-gate /*ARGSUSED*/ 13670Sstevel@tonic-gate int 13680Sstevel@tonic-gate name2major(uintptr_t vaddr, uint_t flags, int argc, const mdb_arg_t *argv) 13690Sstevel@tonic-gate { 13700Sstevel@tonic-gate major_t major; 13710Sstevel@tonic-gate 13720Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) 13730Sstevel@tonic-gate return (DCMD_USAGE); 13740Sstevel@tonic-gate 13750Sstevel@tonic-gate if (argc != 1 || argv->a_type != MDB_TYPE_STRING) 13760Sstevel@tonic-gate return (DCMD_USAGE); 13770Sstevel@tonic-gate 13780Sstevel@tonic-gate if (mdb_name_to_major(argv->a_un.a_str, &major) != 0) { 13790Sstevel@tonic-gate mdb_warn("failed to convert name to major number\n"); 13800Sstevel@tonic-gate return (DCMD_ERR); 13810Sstevel@tonic-gate } 13820Sstevel@tonic-gate 13830Sstevel@tonic-gate mdb_printf("0x%x\n", major); 13840Sstevel@tonic-gate return (DCMD_OK); 13850Sstevel@tonic-gate } 13860Sstevel@tonic-gate 13870Sstevel@tonic-gate /* 13880Sstevel@tonic-gate * Get a numerical argument of a dcmd from addr if an address is specified 13890Sstevel@tonic-gate * or from argv if no address is specified. Return the argument in ret. 13900Sstevel@tonic-gate */ 13910Sstevel@tonic-gate static int 13920Sstevel@tonic-gate getarg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv, 13930Sstevel@tonic-gate uintptr_t *ret) 13940Sstevel@tonic-gate { 13950Sstevel@tonic-gate if (argc == 0 && (flags & DCMD_ADDRSPEC)) { 13960Sstevel@tonic-gate *ret = addr; 13970Sstevel@tonic-gate 13980Sstevel@tonic-gate } else if (argc == 1 && !(flags & DCMD_ADDRSPEC)) { 13990Sstevel@tonic-gate *ret = (argv[0].a_type == MDB_TYPE_IMMEDIATE) ? 14000Sstevel@tonic-gate (uintptr_t)argv[0].a_un.a_val : 14010Sstevel@tonic-gate (uintptr_t)mdb_strtoull(argv->a_un.a_str); 14020Sstevel@tonic-gate 14030Sstevel@tonic-gate } else { 14040Sstevel@tonic-gate return (-1); 14050Sstevel@tonic-gate } 14060Sstevel@tonic-gate 14070Sstevel@tonic-gate return (0); 14080Sstevel@tonic-gate } 14090Sstevel@tonic-gate 14100Sstevel@tonic-gate /*ARGSUSED*/ 14110Sstevel@tonic-gate int 14120Sstevel@tonic-gate major2name(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 14130Sstevel@tonic-gate { 14140Sstevel@tonic-gate uintptr_t major; 14150Sstevel@tonic-gate const char *name; 14160Sstevel@tonic-gate 14170Sstevel@tonic-gate if (getarg(addr, flags, argc, argv, &major) < 0) 14180Sstevel@tonic-gate return (DCMD_USAGE); 14190Sstevel@tonic-gate 14200Sstevel@tonic-gate if ((name = mdb_major_to_name((major_t)major)) == NULL) { 14210Sstevel@tonic-gate mdb_warn("failed to convert major number to name\n"); 14220Sstevel@tonic-gate return (DCMD_ERR); 14230Sstevel@tonic-gate } 14240Sstevel@tonic-gate 14250Sstevel@tonic-gate mdb_printf("%s\n", name); 14260Sstevel@tonic-gate return (DCMD_OK); 14270Sstevel@tonic-gate } 14280Sstevel@tonic-gate 14290Sstevel@tonic-gate /*ARGSUSED*/ 14300Sstevel@tonic-gate int 14310Sstevel@tonic-gate dev2major(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 14320Sstevel@tonic-gate { 14330Sstevel@tonic-gate uintptr_t dev; 14340Sstevel@tonic-gate 14350Sstevel@tonic-gate if (getarg(addr, flags, argc, argv, &dev) < 0) 14360Sstevel@tonic-gate return (DCMD_USAGE); 14370Sstevel@tonic-gate 14380Sstevel@tonic-gate if (flags & DCMD_PIPE_OUT) 14390Sstevel@tonic-gate mdb_printf("%x\n", getmajor(dev)); 14400Sstevel@tonic-gate else 14410Sstevel@tonic-gate mdb_printf("0x%x (0t%d)\n", getmajor(dev), getmajor(dev)); 14420Sstevel@tonic-gate 14430Sstevel@tonic-gate return (DCMD_OK); 14440Sstevel@tonic-gate } 14450Sstevel@tonic-gate 14460Sstevel@tonic-gate /*ARGSUSED*/ 14470Sstevel@tonic-gate int 14480Sstevel@tonic-gate dev2minor(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 14490Sstevel@tonic-gate { 14500Sstevel@tonic-gate uintptr_t dev; 14510Sstevel@tonic-gate 14520Sstevel@tonic-gate if (getarg(addr, flags, argc, argv, &dev) < 0) 14530Sstevel@tonic-gate return (DCMD_USAGE); 14540Sstevel@tonic-gate 14550Sstevel@tonic-gate if (flags & DCMD_PIPE_OUT) 14560Sstevel@tonic-gate mdb_printf("%x\n", getminor(dev)); 14570Sstevel@tonic-gate else 14580Sstevel@tonic-gate mdb_printf("0x%x (0t%d)\n", getminor(dev), getminor(dev)); 14590Sstevel@tonic-gate 14600Sstevel@tonic-gate return (DCMD_OK); 14610Sstevel@tonic-gate } 14620Sstevel@tonic-gate 14630Sstevel@tonic-gate /*ARGSUSED*/ 14640Sstevel@tonic-gate int 14650Sstevel@tonic-gate devt(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 14660Sstevel@tonic-gate { 14670Sstevel@tonic-gate uintptr_t dev; 14680Sstevel@tonic-gate 14690Sstevel@tonic-gate if (getarg(addr, flags, argc, argv, &dev) < 0) 14700Sstevel@tonic-gate return (DCMD_USAGE); 14710Sstevel@tonic-gate 14720Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 14730Sstevel@tonic-gate mdb_printf("%<u>%10s%</u> %<u>%10s%</u>\n", "MAJOR", 14740Sstevel@tonic-gate "MINOR"); 14750Sstevel@tonic-gate } 14760Sstevel@tonic-gate 14770Sstevel@tonic-gate mdb_printf("%10d %10d\n", getmajor(dev), getminor(dev)); 14780Sstevel@tonic-gate 14790Sstevel@tonic-gate return (DCMD_OK); 14800Sstevel@tonic-gate } 14810Sstevel@tonic-gate 14820Sstevel@tonic-gate /*ARGSUSED*/ 14830Sstevel@tonic-gate int 14840Sstevel@tonic-gate softstate(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 14850Sstevel@tonic-gate { 14860Sstevel@tonic-gate uintptr_t statep; 14870Sstevel@tonic-gate int instance; 14880Sstevel@tonic-gate 14890Sstevel@tonic-gate 14900Sstevel@tonic-gate if (argc != 1) { 14910Sstevel@tonic-gate return (DCMD_USAGE); 14920Sstevel@tonic-gate } 14930Sstevel@tonic-gate 14940Sstevel@tonic-gate if (argv[0].a_type == MDB_TYPE_IMMEDIATE) 14950Sstevel@tonic-gate instance = argv[0].a_un.a_val; 14960Sstevel@tonic-gate else 14970Sstevel@tonic-gate instance = mdb_strtoull(argv->a_un.a_str); 14980Sstevel@tonic-gate 14990Sstevel@tonic-gate if (mdb_get_soft_state_byaddr(addr, instance, &statep, NULL, 0) == -1) { 15000Sstevel@tonic-gate if (errno == ENOENT) { 15010Sstevel@tonic-gate mdb_warn("instance %d unused\n", instance); 15020Sstevel@tonic-gate } else { 15030Sstevel@tonic-gate mdb_warn("couldn't determine softstate for " 15040Sstevel@tonic-gate "instance %d", instance); 15050Sstevel@tonic-gate } 15060Sstevel@tonic-gate 15070Sstevel@tonic-gate return (DCMD_ERR); 15080Sstevel@tonic-gate } 15090Sstevel@tonic-gate 15100Sstevel@tonic-gate mdb_printf("%p\n", statep); 15110Sstevel@tonic-gate return (DCMD_OK); 15120Sstevel@tonic-gate } 15130Sstevel@tonic-gate 15140Sstevel@tonic-gate /* 15150Sstevel@tonic-gate * Walker for all possible pointers to a driver state struct in an 15160Sstevel@tonic-gate * i_ddi_soft_state instance chain. Returns all non-NULL pointers. 15170Sstevel@tonic-gate */ 15180Sstevel@tonic-gate typedef struct soft_state_walk { 15190Sstevel@tonic-gate struct i_ddi_soft_state ssw_ss; /* Local copy of i_ddi_soft_state */ 15200Sstevel@tonic-gate void **ssw_pointers; /* to driver state structs */ 15210Sstevel@tonic-gate uint_t ssw_index; /* array entry we're using */ 15220Sstevel@tonic-gate } soft_state_walk_t; 15230Sstevel@tonic-gate 15240Sstevel@tonic-gate int 15250Sstevel@tonic-gate soft_state_walk_init(mdb_walk_state_t *wsp) 15260Sstevel@tonic-gate { 15270Sstevel@tonic-gate soft_state_walk_t *sst; 15280Sstevel@tonic-gate 15290Sstevel@tonic-gate 15300Sstevel@tonic-gate if (wsp->walk_addr == NULL) 15310Sstevel@tonic-gate return (WALK_DONE); 15320Sstevel@tonic-gate 15330Sstevel@tonic-gate sst = mdb_zalloc(sizeof (soft_state_walk_t), UM_SLEEP|UM_GC); 15340Sstevel@tonic-gate wsp->walk_data = sst; 15350Sstevel@tonic-gate 15360Sstevel@tonic-gate 15370Sstevel@tonic-gate if (mdb_vread(&(sst->ssw_ss), sizeof (sst->ssw_ss), wsp->walk_addr) != 15380Sstevel@tonic-gate sizeof (sst->ssw_ss)) { 15390Sstevel@tonic-gate mdb_warn("failed to read i_ddi_soft_state at %p", 15400Sstevel@tonic-gate wsp->walk_addr); 15410Sstevel@tonic-gate return (WALK_ERR); 15420Sstevel@tonic-gate } 15430Sstevel@tonic-gate 15440Sstevel@tonic-gate 15450Sstevel@tonic-gate /* Read array of pointers to state structs into local storage. */ 15460Sstevel@tonic-gate sst->ssw_pointers = mdb_alloc((sst->ssw_ss.n_items * sizeof (void *)), 15470Sstevel@tonic-gate UM_SLEEP|UM_GC); 15480Sstevel@tonic-gate 15490Sstevel@tonic-gate if (mdb_vread(sst->ssw_pointers, (sst->ssw_ss.n_items * 15500Sstevel@tonic-gate sizeof (void *)), (uintptr_t)sst->ssw_ss.array) != 15510Sstevel@tonic-gate (sst->ssw_ss.n_items * sizeof (void *))) { 15520Sstevel@tonic-gate mdb_warn("failed to read i_ddi_soft_state at %p", 15530Sstevel@tonic-gate wsp->walk_addr); 15540Sstevel@tonic-gate return (WALK_ERR); 15550Sstevel@tonic-gate } 15560Sstevel@tonic-gate 15570Sstevel@tonic-gate sst->ssw_index = 0; 15580Sstevel@tonic-gate 15590Sstevel@tonic-gate return (WALK_NEXT); 15600Sstevel@tonic-gate } 15610Sstevel@tonic-gate 15620Sstevel@tonic-gate int 15630Sstevel@tonic-gate soft_state_walk_step(mdb_walk_state_t *wsp) 15640Sstevel@tonic-gate { 15650Sstevel@tonic-gate soft_state_walk_t *sst = (soft_state_walk_t *)wsp->walk_data; 15660Sstevel@tonic-gate int status = WALK_NEXT; 15670Sstevel@tonic-gate 15680Sstevel@tonic-gate 15690Sstevel@tonic-gate /* 15700Sstevel@tonic-gate * If the entry indexed has a valid pointer to a soft state struct, 15710Sstevel@tonic-gate * invoke caller's callback func. 15720Sstevel@tonic-gate */ 15730Sstevel@tonic-gate if (sst->ssw_pointers[sst->ssw_index] != NULL) { 15740Sstevel@tonic-gate status = wsp->walk_callback( 15750Sstevel@tonic-gate (uintptr_t)(sst->ssw_pointers[sst->ssw_index]), NULL, 15760Sstevel@tonic-gate wsp->walk_cbdata); 15770Sstevel@tonic-gate } 15780Sstevel@tonic-gate 15790Sstevel@tonic-gate sst->ssw_index += 1; 15800Sstevel@tonic-gate 15810Sstevel@tonic-gate if (sst->ssw_index == sst->ssw_ss.n_items) 15820Sstevel@tonic-gate return (WALK_DONE); 15830Sstevel@tonic-gate 15840Sstevel@tonic-gate return (status); 15850Sstevel@tonic-gate } 15860Sstevel@tonic-gate 15870Sstevel@tonic-gate int 15880Sstevel@tonic-gate soft_state_all_walk_step(mdb_walk_state_t *wsp) 15890Sstevel@tonic-gate { 15900Sstevel@tonic-gate soft_state_walk_t *sst = (soft_state_walk_t *)wsp->walk_data; 15910Sstevel@tonic-gate int status = WALK_NEXT; 15920Sstevel@tonic-gate 15930Sstevel@tonic-gate 15940Sstevel@tonic-gate status = wsp->walk_callback( 15950Sstevel@tonic-gate (uintptr_t)(sst->ssw_pointers[sst->ssw_index]), NULL, 15960Sstevel@tonic-gate wsp->walk_cbdata); 15970Sstevel@tonic-gate 15980Sstevel@tonic-gate sst->ssw_index += 1; 15990Sstevel@tonic-gate 16000Sstevel@tonic-gate if (sst->ssw_index == sst->ssw_ss.n_items) 16010Sstevel@tonic-gate return (WALK_DONE); 16020Sstevel@tonic-gate 16030Sstevel@tonic-gate return (status); 16040Sstevel@tonic-gate } 16050Sstevel@tonic-gate 16060Sstevel@tonic-gate /*ARGSUSED*/ 16070Sstevel@tonic-gate int 16080Sstevel@tonic-gate devbindings(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 16090Sstevel@tonic-gate { 16100Sstevel@tonic-gate const mdb_arg_t *arg; 16110Sstevel@tonic-gate struct devnames dn; 16120Sstevel@tonic-gate uintptr_t dn_addr; 16130Sstevel@tonic-gate major_t major; 16140Sstevel@tonic-gate 16150Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) && argc < 1) 16160Sstevel@tonic-gate return (DCMD_USAGE); 16170Sstevel@tonic-gate 16180Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) { 16190Sstevel@tonic-gate /* 16200Sstevel@tonic-gate * If there's an address, then it's a major number 16210Sstevel@tonic-gate */ 16220Sstevel@tonic-gate major = addr; 16230Sstevel@tonic-gate } else { 16240Sstevel@tonic-gate /* 16250Sstevel@tonic-gate * We interpret the last argument. Any other arguments are 16260Sstevel@tonic-gate * forwarded to "devinfo" 16270Sstevel@tonic-gate */ 16280Sstevel@tonic-gate arg = &argv[argc - 1]; 16290Sstevel@tonic-gate argc--; 16300Sstevel@tonic-gate 16310Sstevel@tonic-gate if (arg->a_type == MDB_TYPE_IMMEDIATE) { 16320Sstevel@tonic-gate major = (uintptr_t)arg->a_un.a_val; 16330Sstevel@tonic-gate 16340Sstevel@tonic-gate } else if (arg->a_un.a_str[0] == '-') { 16350Sstevel@tonic-gate /* the argument shouldn't be an option */ 16360Sstevel@tonic-gate return (DCMD_USAGE); 16370Sstevel@tonic-gate 16380Sstevel@tonic-gate } else if (isdigit(arg->a_un.a_str[0])) { 16390Sstevel@tonic-gate major = (uintptr_t)mdb_strtoull(arg->a_un.a_str); 16400Sstevel@tonic-gate 16410Sstevel@tonic-gate } else { 16420Sstevel@tonic-gate if (mdb_name_to_major(arg->a_un.a_str, &major) != 0) { 16430Sstevel@tonic-gate mdb_warn("failed to get major number for %s\n", 16440Sstevel@tonic-gate arg->a_un.a_str); 16450Sstevel@tonic-gate return (DCMD_ERR); 16460Sstevel@tonic-gate } 16470Sstevel@tonic-gate } 16480Sstevel@tonic-gate } 16490Sstevel@tonic-gate 16500Sstevel@tonic-gate if (major_to_addr(major, &dn_addr) != 0) 16510Sstevel@tonic-gate return (DCMD_ERR); 16520Sstevel@tonic-gate 16530Sstevel@tonic-gate if (mdb_vread(&dn, sizeof (struct devnames), dn_addr) == -1) { 16540Sstevel@tonic-gate mdb_warn("couldn't read devnames array at %p", dn_addr); 16550Sstevel@tonic-gate return (DCMD_ERR); 16560Sstevel@tonic-gate } 16570Sstevel@tonic-gate 16580Sstevel@tonic-gate if (mdb_pwalk_dcmd("devi_next", "devinfo", argc, argv, 16590Sstevel@tonic-gate (uintptr_t)dn.dn_head) != 0) { 16600Sstevel@tonic-gate mdb_warn("couldn't walk the devinfo chain at %p", dn.dn_head); 16610Sstevel@tonic-gate return (DCMD_ERR); 16620Sstevel@tonic-gate } 16630Sstevel@tonic-gate 16640Sstevel@tonic-gate return (DCMD_OK); 16650Sstevel@tonic-gate } 16660Sstevel@tonic-gate 16670Sstevel@tonic-gate /* 16680Sstevel@tonic-gate * walk binding hashtable (as of of driver names (e.g., mb_hashtab)) 16690Sstevel@tonic-gate */ 16700Sstevel@tonic-gate int 16710Sstevel@tonic-gate binding_hash_walk_init(mdb_walk_state_t *wsp) 16720Sstevel@tonic-gate { 16730Sstevel@tonic-gate if (wsp->walk_addr == NULL) 16740Sstevel@tonic-gate return (WALK_ERR); 16750Sstevel@tonic-gate 16760Sstevel@tonic-gate wsp->walk_data = mdb_alloc(sizeof (void *) * MOD_BIND_HASHSIZE, 16770Sstevel@tonic-gate UM_SLEEP|UM_GC); 16780Sstevel@tonic-gate if (mdb_vread(wsp->walk_data, sizeof (void *) * MOD_BIND_HASHSIZE, 16790Sstevel@tonic-gate wsp->walk_addr) == -1) { 16800Sstevel@tonic-gate mdb_warn("failed to read mb_hashtab"); 16810Sstevel@tonic-gate return (WALK_ERR); 16820Sstevel@tonic-gate } 16830Sstevel@tonic-gate 16840Sstevel@tonic-gate wsp->walk_arg = 0; /* index into mb_hashtab array to start */ 16850Sstevel@tonic-gate 16860Sstevel@tonic-gate return (WALK_NEXT); 16870Sstevel@tonic-gate } 16880Sstevel@tonic-gate 16890Sstevel@tonic-gate int 16900Sstevel@tonic-gate binding_hash_walk_step(mdb_walk_state_t *wsp) 16910Sstevel@tonic-gate { 16920Sstevel@tonic-gate int status; 16930Sstevel@tonic-gate uintptr_t bind_p; 16940Sstevel@tonic-gate struct bind bind; 16950Sstevel@tonic-gate 16960Sstevel@tonic-gate 16970Sstevel@tonic-gate /* 16980Sstevel@tonic-gate * Walk the singly-linked list of struct bind 16990Sstevel@tonic-gate */ 17000Sstevel@tonic-gate bind_p = ((uintptr_t *)wsp->walk_data)[(ulong_t)wsp->walk_arg]; 17010Sstevel@tonic-gate while (bind_p != NULL) { 17020Sstevel@tonic-gate 17030Sstevel@tonic-gate if (mdb_vread(&bind, sizeof (bind), bind_p) == -1) { 17040Sstevel@tonic-gate mdb_warn("failed to read bind struct at %p", 17050Sstevel@tonic-gate wsp->walk_addr); 17060Sstevel@tonic-gate return (WALK_ERR); 17070Sstevel@tonic-gate } 17080Sstevel@tonic-gate 17090Sstevel@tonic-gate if ((status = wsp->walk_callback(bind_p, &bind, 17100Sstevel@tonic-gate wsp->walk_cbdata)) != WALK_NEXT) { 17110Sstevel@tonic-gate return (status); 17120Sstevel@tonic-gate } 17130Sstevel@tonic-gate 17140Sstevel@tonic-gate bind_p = (uintptr_t)bind.b_next; 17150Sstevel@tonic-gate } 17160Sstevel@tonic-gate 17170Sstevel@tonic-gate wsp->walk_arg = (void *)((char *)wsp->walk_arg + 1); 17180Sstevel@tonic-gate 17190Sstevel@tonic-gate if (wsp->walk_arg == (void *)(MOD_BIND_HASHSIZE - 1)) 17200Sstevel@tonic-gate return (WALK_DONE); 17210Sstevel@tonic-gate 17220Sstevel@tonic-gate return (WALK_NEXT); 17230Sstevel@tonic-gate } 17240Sstevel@tonic-gate 17250Sstevel@tonic-gate /*ARGSUSED*/ 17260Sstevel@tonic-gate int 17270Sstevel@tonic-gate binding_hash_entry(uintptr_t addr, uint_t flags, int argc, 17280Sstevel@tonic-gate const mdb_arg_t *argv) 17290Sstevel@tonic-gate { 17300Sstevel@tonic-gate struct bind bind; 17310Sstevel@tonic-gate /* Arbitrary lengths based on output format below */ 17324145Scth char name[MAXPATHLEN] = "???"; 17334145Scth char bind_name[MAXPATHLEN] = "<null>"; 17340Sstevel@tonic-gate 17350Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == NULL) 17360Sstevel@tonic-gate return (DCMD_USAGE); 17370Sstevel@tonic-gate 17380Sstevel@tonic-gate /* Allow null addresses to be passed (as from a walker) */ 17390Sstevel@tonic-gate if (addr == NULL) 17400Sstevel@tonic-gate return (DCMD_OK); 17410Sstevel@tonic-gate 17420Sstevel@tonic-gate if (mdb_vread(&bind, sizeof (bind), addr) == -1) { 17430Sstevel@tonic-gate mdb_warn("failed to read struct bind at %p", addr); 17440Sstevel@tonic-gate return (DCMD_ERR); 17450Sstevel@tonic-gate } 17460Sstevel@tonic-gate 17470Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 17484145Scth mdb_printf("%<u>%?s% %-5s %s%</u>\n", 17494145Scth "NEXT", "MAJOR", "NAME(S)"); 17500Sstevel@tonic-gate } 17510Sstevel@tonic-gate 17520Sstevel@tonic-gate if (mdb_readstr(name, sizeof (name), (uintptr_t)bind.b_name) == -1) 17530Sstevel@tonic-gate mdb_warn("failed to read 'name'"); 17540Sstevel@tonic-gate 17554145Scth /* There may be bind_name, so this may fail */ 17564145Scth if (mdb_readstr(bind_name, sizeof (bind_name), 17574145Scth (uintptr_t)bind.b_bind_name) == -1) { 17584145Scth mdb_printf("%?p %5d %s\n", 17594145Scth bind.b_next, bind.b_num, name); 17604145Scth } else { 17614145Scth mdb_printf("%?p %5d %s %s\n", 17624145Scth bind.b_next, bind.b_num, name, bind_name); 17634145Scth } 17640Sstevel@tonic-gate 17650Sstevel@tonic-gate return (DCMD_OK); 17660Sstevel@tonic-gate } 17670Sstevel@tonic-gate 17680Sstevel@tonic-gate typedef struct devinfo_audit_log_walk_data { 17690Sstevel@tonic-gate devinfo_audit_t dil_buf; /* buffer of last entry */ 17700Sstevel@tonic-gate uintptr_t dil_base; /* starting address of log buffer */ 17710Sstevel@tonic-gate int dil_max; /* maximum index */ 17720Sstevel@tonic-gate int dil_start; /* starting index */ 17730Sstevel@tonic-gate int dil_index; /* current walking index */ 17740Sstevel@tonic-gate } devinfo_audit_log_walk_data_t; 17750Sstevel@tonic-gate 17760Sstevel@tonic-gate int 17770Sstevel@tonic-gate devinfo_audit_log_walk_init(mdb_walk_state_t *wsp) 17780Sstevel@tonic-gate { 17790Sstevel@tonic-gate devinfo_log_header_t header; 17800Sstevel@tonic-gate devinfo_audit_log_walk_data_t *dil; 17810Sstevel@tonic-gate uintptr_t devinfo_audit_log; 17820Sstevel@tonic-gate 17830Sstevel@tonic-gate /* read in devinfo_log_header structure */ 17840Sstevel@tonic-gate if (mdb_readvar(&devinfo_audit_log, "devinfo_audit_log") == -1) { 17850Sstevel@tonic-gate mdb_warn("failed to read 'devinfo_audit_log'"); 17860Sstevel@tonic-gate return (WALK_ERR); 17870Sstevel@tonic-gate } 17880Sstevel@tonic-gate 17890Sstevel@tonic-gate if (mdb_vread(&header, sizeof (devinfo_log_header_t), 17900Sstevel@tonic-gate devinfo_audit_log) == -1) { 17910Sstevel@tonic-gate mdb_warn("couldn't read devinfo_log_header at %p", 17920Sstevel@tonic-gate devinfo_audit_log); 17930Sstevel@tonic-gate return (WALK_ERR); 17940Sstevel@tonic-gate } 17950Sstevel@tonic-gate 17960Sstevel@tonic-gate dil = mdb_zalloc(sizeof (devinfo_audit_log_walk_data_t), UM_SLEEP); 17970Sstevel@tonic-gate wsp->walk_data = dil; 17980Sstevel@tonic-gate 17990Sstevel@tonic-gate dil->dil_start = dil->dil_index = header.dh_curr; 18000Sstevel@tonic-gate dil->dil_max = header.dh_max; 18010Sstevel@tonic-gate if (dil->dil_start < 0) /* no log entries */ 18020Sstevel@tonic-gate return (WALK_DONE); 18030Sstevel@tonic-gate 18040Sstevel@tonic-gate dil->dil_base = devinfo_audit_log + 18050Sstevel@tonic-gate offsetof(devinfo_log_header_t, dh_entry); 18060Sstevel@tonic-gate wsp->walk_addr = dil->dil_base + 18070Sstevel@tonic-gate dil->dil_index * sizeof (devinfo_audit_t); 18080Sstevel@tonic-gate 18090Sstevel@tonic-gate return (WALK_NEXT); 18100Sstevel@tonic-gate } 18110Sstevel@tonic-gate 18120Sstevel@tonic-gate int 18130Sstevel@tonic-gate devinfo_audit_log_walk_step(mdb_walk_state_t *wsp) 18140Sstevel@tonic-gate { 18150Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 18160Sstevel@tonic-gate devinfo_audit_log_walk_data_t *dil = wsp->walk_data; 18170Sstevel@tonic-gate devinfo_audit_t *da = &dil->dil_buf; 18180Sstevel@tonic-gate int status = WALK_NEXT; 18190Sstevel@tonic-gate 18200Sstevel@tonic-gate /* read in current entry and invoke callback */ 18210Sstevel@tonic-gate if (addr == NULL) 18220Sstevel@tonic-gate return (WALK_DONE); 18230Sstevel@tonic-gate 18240Sstevel@tonic-gate if (mdb_vread(&dil->dil_buf, sizeof (devinfo_audit_t), addr) == -1) { 18250Sstevel@tonic-gate mdb_warn("failed to read devinfo_audit at %p", addr); 18260Sstevel@tonic-gate status = WALK_DONE; 18270Sstevel@tonic-gate } 18280Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, da, wsp->walk_cbdata); 18290Sstevel@tonic-gate 18300Sstevel@tonic-gate /* step to the previous log entry in time */ 18310Sstevel@tonic-gate if (--dil->dil_index < 0) 18320Sstevel@tonic-gate dil->dil_index += dil->dil_max; 18330Sstevel@tonic-gate if (dil->dil_index == dil->dil_start) { 18340Sstevel@tonic-gate wsp->walk_addr = NULL; 18350Sstevel@tonic-gate return (WALK_DONE); 18360Sstevel@tonic-gate } 18370Sstevel@tonic-gate 18380Sstevel@tonic-gate wsp->walk_addr = dil->dil_base + 18390Sstevel@tonic-gate dil->dil_index * sizeof (devinfo_audit_t); 18400Sstevel@tonic-gate return (status); 18410Sstevel@tonic-gate } 18420Sstevel@tonic-gate 18430Sstevel@tonic-gate void 18440Sstevel@tonic-gate devinfo_audit_log_walk_fini(mdb_walk_state_t *wsp) 18450Sstevel@tonic-gate { 18460Sstevel@tonic-gate mdb_free(wsp->walk_data, sizeof (devinfo_audit_log_walk_data_t)); 18470Sstevel@tonic-gate } 18480Sstevel@tonic-gate 18490Sstevel@tonic-gate /* 18500Sstevel@tonic-gate * display devinfo_audit_t stack trace 18510Sstevel@tonic-gate */ 18520Sstevel@tonic-gate /*ARGSUSED*/ 18530Sstevel@tonic-gate int 18540Sstevel@tonic-gate devinfo_audit(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 18550Sstevel@tonic-gate { 18560Sstevel@tonic-gate uint_t verbose = FALSE; 18570Sstevel@tonic-gate devinfo_audit_t da; 18580Sstevel@tonic-gate int i, depth; 18590Sstevel@tonic-gate 18600Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == 0) 18610Sstevel@tonic-gate return (DCMD_USAGE); 18620Sstevel@tonic-gate 18630Sstevel@tonic-gate if (mdb_getopts(argc, argv, 18640Sstevel@tonic-gate 'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL) != argc) 18650Sstevel@tonic-gate return (DCMD_USAGE); 18660Sstevel@tonic-gate 18670Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 18680Sstevel@tonic-gate mdb_printf(" %-?s %16s %-?s %-?s %5s\n", 18690Sstevel@tonic-gate "AUDIT", "TIMESTAMP", "THREAD", "DEVINFO", "STATE"); 18700Sstevel@tonic-gate } 18710Sstevel@tonic-gate 18720Sstevel@tonic-gate if (mdb_vread(&da, sizeof (da), addr) == -1) { 18730Sstevel@tonic-gate mdb_warn("couldn't read devinfo_audit at %p", addr); 18740Sstevel@tonic-gate return (DCMD_ERR); 18750Sstevel@tonic-gate } 18760Sstevel@tonic-gate 18770Sstevel@tonic-gate mdb_printf(" %0?p %16llx %0?p %0?p %s\n", 18780Sstevel@tonic-gate addr, da.da_timestamp, da.da_thread, da.da_devinfo, 18790Sstevel@tonic-gate di_state[MIN(da.da_node_state + 1, DI_STATE_MAX)]); 18800Sstevel@tonic-gate 18810Sstevel@tonic-gate if (!verbose) 18820Sstevel@tonic-gate return (DCMD_OK); 18830Sstevel@tonic-gate 18840Sstevel@tonic-gate mdb_inc_indent(4); 18850Sstevel@tonic-gate 18860Sstevel@tonic-gate /* 18870Sstevel@tonic-gate * Guard against bogus da_depth in case the devinfo_audit_t 18880Sstevel@tonic-gate * is corrupt or the address does not really refer to a 18890Sstevel@tonic-gate * devinfo_audit_t. 18900Sstevel@tonic-gate */ 18910Sstevel@tonic-gate depth = MIN(da.da_depth, DDI_STACK_DEPTH); 18920Sstevel@tonic-gate 18930Sstevel@tonic-gate for (i = 0; i < depth; i++) 18940Sstevel@tonic-gate mdb_printf("%a\n", da.da_stack[i]); 18950Sstevel@tonic-gate 18960Sstevel@tonic-gate mdb_printf("\n"); 18970Sstevel@tonic-gate mdb_dec_indent(4); 18980Sstevel@tonic-gate 18990Sstevel@tonic-gate return (DCMD_OK); 19000Sstevel@tonic-gate } 19010Sstevel@tonic-gate 19020Sstevel@tonic-gate int 19030Sstevel@tonic-gate devinfo_audit_log(uintptr_t addr, uint_t flags, int argc, 19040Sstevel@tonic-gate const mdb_arg_t *argv) 19050Sstevel@tonic-gate { 19060Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) 19070Sstevel@tonic-gate return (devinfo_audit(addr, flags, argc, argv)); 19080Sstevel@tonic-gate 19090Sstevel@tonic-gate (void) mdb_walk_dcmd("devinfo_audit_log", "devinfo_audit", argc, argv); 19100Sstevel@tonic-gate return (DCMD_OK); 19110Sstevel@tonic-gate } 19120Sstevel@tonic-gate 19130Sstevel@tonic-gate typedef struct devinfo_audit_node_walk_data { 19140Sstevel@tonic-gate devinfo_audit_t dih_buf; /* buffer of last entry */ 19150Sstevel@tonic-gate uintptr_t dih_dip; /* address of dev_info */ 19160Sstevel@tonic-gate int dih_on_devinfo; /* devi_audit on dev_info struct */ 19170Sstevel@tonic-gate } devinfo_audit_node_walk_data_t; 19180Sstevel@tonic-gate 19190Sstevel@tonic-gate int 19200Sstevel@tonic-gate devinfo_audit_node_walk_init(mdb_walk_state_t *wsp) 19210Sstevel@tonic-gate { 19220Sstevel@tonic-gate devinfo_audit_node_walk_data_t *dih; 19230Sstevel@tonic-gate devinfo_audit_t *da; 19240Sstevel@tonic-gate struct dev_info devi; 19250Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 19260Sstevel@tonic-gate 19270Sstevel@tonic-gate /* read in devinfo structure */ 19280Sstevel@tonic-gate if (mdb_vread(&devi, sizeof (struct dev_info), addr) == -1) { 19290Sstevel@tonic-gate mdb_warn("couldn't read dev_info at %p", addr); 19300Sstevel@tonic-gate return (WALK_ERR); 19310Sstevel@tonic-gate } 19320Sstevel@tonic-gate 19330Sstevel@tonic-gate dih = mdb_zalloc(sizeof (devinfo_audit_node_walk_data_t), UM_SLEEP); 19340Sstevel@tonic-gate wsp->walk_data = dih; 19350Sstevel@tonic-gate da = &dih->dih_buf; 19360Sstevel@tonic-gate 19370Sstevel@tonic-gate /* read in devi_audit structure */ 19380Sstevel@tonic-gate if (mdb_vread(da, sizeof (devinfo_audit_t), (uintptr_t)devi.devi_audit) 19390Sstevel@tonic-gate == -1) { 19400Sstevel@tonic-gate mdb_warn("couldn't read devi_audit at %p", devi.devi_audit); 19410Sstevel@tonic-gate return (WALK_ERR); 19420Sstevel@tonic-gate } 19430Sstevel@tonic-gate dih->dih_dip = addr; 19440Sstevel@tonic-gate dih->dih_on_devinfo = 1; 19450Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)devi.devi_audit; 19460Sstevel@tonic-gate 19470Sstevel@tonic-gate return (WALK_NEXT); 19480Sstevel@tonic-gate } 19490Sstevel@tonic-gate 19500Sstevel@tonic-gate int 19510Sstevel@tonic-gate devinfo_audit_node_walk_step(mdb_walk_state_t *wsp) 19520Sstevel@tonic-gate { 19530Sstevel@tonic-gate uintptr_t addr; 19540Sstevel@tonic-gate devinfo_audit_node_walk_data_t *dih = wsp->walk_data; 19550Sstevel@tonic-gate devinfo_audit_t *da = &dih->dih_buf; 19560Sstevel@tonic-gate 19570Sstevel@tonic-gate if (wsp->walk_addr == NULL) 19580Sstevel@tonic-gate return (WALK_DONE); 19590Sstevel@tonic-gate (void) wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata); 19600Sstevel@tonic-gate 19610Sstevel@tonic-gate skip: 19620Sstevel@tonic-gate /* read in previous entry */ 19630Sstevel@tonic-gate if ((addr = (uintptr_t)da->da_lastlog) == 0) 19640Sstevel@tonic-gate return (WALK_DONE); 19650Sstevel@tonic-gate 19660Sstevel@tonic-gate if (mdb_vread(&dih->dih_buf, sizeof (devinfo_audit_t), addr) == -1) { 19670Sstevel@tonic-gate mdb_warn("failed to read devinfo_audit at %p", addr); 19680Sstevel@tonic-gate return (WALK_DONE); 19690Sstevel@tonic-gate } 19700Sstevel@tonic-gate 19710Sstevel@tonic-gate /* check if last log was over-written */ 19720Sstevel@tonic-gate if ((uintptr_t)da->da_devinfo != dih->dih_dip) 19730Sstevel@tonic-gate return (WALK_DONE); 19740Sstevel@tonic-gate 19750Sstevel@tonic-gate /* 19760Sstevel@tonic-gate * skip the first common log entry, which is a duplicate of 19770Sstevel@tonic-gate * the devi_audit buffer on the dev_info structure 19780Sstevel@tonic-gate */ 19790Sstevel@tonic-gate if (dih->dih_on_devinfo) { 19800Sstevel@tonic-gate dih->dih_on_devinfo = 0; 19810Sstevel@tonic-gate goto skip; 19820Sstevel@tonic-gate } 19830Sstevel@tonic-gate wsp->walk_addr = addr; 19840Sstevel@tonic-gate 19850Sstevel@tonic-gate return (WALK_NEXT); 19860Sstevel@tonic-gate } 19870Sstevel@tonic-gate 19880Sstevel@tonic-gate void 19890Sstevel@tonic-gate devinfo_audit_node_walk_fini(mdb_walk_state_t *wsp) 19900Sstevel@tonic-gate { 19910Sstevel@tonic-gate mdb_free(wsp->walk_data, sizeof (devinfo_audit_node_walk_data_t)); 19920Sstevel@tonic-gate } 19930Sstevel@tonic-gate 19940Sstevel@tonic-gate int 19950Sstevel@tonic-gate devinfo_audit_node(uintptr_t addr, uint_t flags, int argc, 19960Sstevel@tonic-gate const mdb_arg_t *argv) 19970Sstevel@tonic-gate { 19980Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 19990Sstevel@tonic-gate return (DCMD_USAGE); 20000Sstevel@tonic-gate 20010Sstevel@tonic-gate (void) mdb_pwalk_dcmd("devinfo_audit_node", "devinfo_audit", 20020Sstevel@tonic-gate argc, argv, addr); 20030Sstevel@tonic-gate return (DCMD_OK); 20040Sstevel@tonic-gate } 20050Sstevel@tonic-gate 20060Sstevel@tonic-gate /* 20070Sstevel@tonic-gate * mdb support for per-devinfo fault management data 20080Sstevel@tonic-gate */ 20090Sstevel@tonic-gate /*ARGSUSED*/ 20100Sstevel@tonic-gate int 20110Sstevel@tonic-gate devinfo_fm(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 20120Sstevel@tonic-gate { 20130Sstevel@tonic-gate struct dev_info devi; 20140Sstevel@tonic-gate struct i_ddi_fmhdl fhdl; 20150Sstevel@tonic-gate 20160Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == 0) 20170Sstevel@tonic-gate return (DCMD_USAGE); 20180Sstevel@tonic-gate 20190Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 20207931SSean.Ye@Sun.COM mdb_printf("%<u>%?s IPL CAPS DROP FMCFULL FMCMISS ACCERR " 20217931SSean.Ye@Sun.COM "DMAERR %?s %?s%</u>\n", "ADDR", "DMACACHE", "ACCCACHE"); 20220Sstevel@tonic-gate } 20230Sstevel@tonic-gate 20240Sstevel@tonic-gate if (mdb_vread(&devi, sizeof (devi), addr) == -1) { 20250Sstevel@tonic-gate mdb_warn("failed to read devinfo struct at %p", addr); 20260Sstevel@tonic-gate return (DCMD_ERR); 20270Sstevel@tonic-gate } 20280Sstevel@tonic-gate 20290Sstevel@tonic-gate if (mdb_vread(&fhdl, sizeof (fhdl), (uintptr_t)devi.devi_fmhdl) == -1) { 20300Sstevel@tonic-gate mdb_warn("failed to read devinfo fm struct at %p", 20310Sstevel@tonic-gate (uintptr_t)devi.devi_fmhdl); 20320Sstevel@tonic-gate return (DCMD_ERR); 20330Sstevel@tonic-gate } 20340Sstevel@tonic-gate 20357931SSean.Ye@Sun.COM mdb_printf("%?p %3u %c%c%c%c %4llu %7llu %7llu %6llu %6llu %?p %?p\n", 20360Sstevel@tonic-gate (uintptr_t)devi.devi_fmhdl, fhdl.fh_ibc, 20370Sstevel@tonic-gate (DDI_FM_EREPORT_CAP(fhdl.fh_cap) ? 'E' : '-'), 20380Sstevel@tonic-gate (DDI_FM_ERRCB_CAP(fhdl.fh_cap) ? 'C' : '-'), 20390Sstevel@tonic-gate (DDI_FM_ACC_ERR_CAP(fhdl.fh_cap) ? 'A' : '-'), 20400Sstevel@tonic-gate (DDI_FM_DMA_ERR_CAP(fhdl.fh_cap) ? 'D' : '-'), 20410Sstevel@tonic-gate fhdl.fh_kstat.fek_erpt_dropped.value.ui64, 20420Sstevel@tonic-gate fhdl.fh_kstat.fek_fmc_full.value.ui64, 20437931SSean.Ye@Sun.COM fhdl.fh_kstat.fek_fmc_miss.value.ui64, 20440Sstevel@tonic-gate fhdl.fh_kstat.fek_acc_err.value.ui64, 20450Sstevel@tonic-gate fhdl.fh_kstat.fek_dma_err.value.ui64, 20460Sstevel@tonic-gate fhdl.fh_dma_cache, fhdl.fh_acc_cache); 20470Sstevel@tonic-gate 20480Sstevel@tonic-gate 20490Sstevel@tonic-gate return (DCMD_OK); 20500Sstevel@tonic-gate } 20510Sstevel@tonic-gate 20520Sstevel@tonic-gate /*ARGSUSED*/ 20530Sstevel@tonic-gate int 20540Sstevel@tonic-gate devinfo_fmce(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 20550Sstevel@tonic-gate { 20560Sstevel@tonic-gate struct i_ddi_fmc_entry fce; 20570Sstevel@tonic-gate 20580Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == 0) 20590Sstevel@tonic-gate return (DCMD_USAGE); 20600Sstevel@tonic-gate 20610Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 20627931SSean.Ye@Sun.COM mdb_printf("%<u>%?s %?s %?s%</u>\n", "ADDR", 20630Sstevel@tonic-gate "RESOURCE", "BUS_SPECIFIC"); 20640Sstevel@tonic-gate } 20650Sstevel@tonic-gate 20660Sstevel@tonic-gate if (mdb_vread(&fce, sizeof (fce), addr) == -1) { 20670Sstevel@tonic-gate mdb_warn("failed to read fm cache struct at %p", addr); 20680Sstevel@tonic-gate return (DCMD_ERR); 20690Sstevel@tonic-gate } 20700Sstevel@tonic-gate 20717931SSean.Ye@Sun.COM mdb_printf("%?p %?p %?p\n", 20720Sstevel@tonic-gate (uintptr_t)addr, fce.fce_resource, fce.fce_bus_specific); 20730Sstevel@tonic-gate 20740Sstevel@tonic-gate 20750Sstevel@tonic-gate return (DCMD_OK); 20760Sstevel@tonic-gate } 20770Sstevel@tonic-gate 20780Sstevel@tonic-gate int 20790Sstevel@tonic-gate devinfo_fmc_walk_init(mdb_walk_state_t *wsp) 20800Sstevel@tonic-gate { 20810Sstevel@tonic-gate struct i_ddi_fmc fec; 20820Sstevel@tonic-gate 20830Sstevel@tonic-gate if (wsp->walk_addr == NULL) 20840Sstevel@tonic-gate return (WALK_ERR); 20850Sstevel@tonic-gate 20860Sstevel@tonic-gate if (mdb_vread(&fec, sizeof (fec), wsp->walk_addr) == -1) { 20870Sstevel@tonic-gate mdb_warn("failed to read fm cache at %p", wsp->walk_addr); 20880Sstevel@tonic-gate return (WALK_ERR); 20890Sstevel@tonic-gate } 20900Sstevel@tonic-gate 20917931SSean.Ye@Sun.COM if (fec.fc_head == NULL) 20920Sstevel@tonic-gate return (WALK_DONE); 20930Sstevel@tonic-gate 20947931SSean.Ye@Sun.COM wsp->walk_addr = (uintptr_t)fec.fc_head; 20950Sstevel@tonic-gate return (WALK_NEXT); 20960Sstevel@tonic-gate } 20970Sstevel@tonic-gate 20980Sstevel@tonic-gate int 20990Sstevel@tonic-gate devinfo_fmc_walk_step(mdb_walk_state_t *wsp) 21000Sstevel@tonic-gate { 21010Sstevel@tonic-gate int status; 21020Sstevel@tonic-gate struct i_ddi_fmc_entry fe; 21030Sstevel@tonic-gate 21040Sstevel@tonic-gate if (mdb_vread(&fe, sizeof (fe), wsp->walk_addr) == -1) { 21050Sstevel@tonic-gate mdb_warn("failed to read active fm cache entry at %p", 21060Sstevel@tonic-gate wsp->walk_addr); 21070Sstevel@tonic-gate return (WALK_DONE); 21080Sstevel@tonic-gate } 21090Sstevel@tonic-gate 21100Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, &fe, wsp->walk_cbdata); 21110Sstevel@tonic-gate 21120Sstevel@tonic-gate if (fe.fce_next == NULL) 21130Sstevel@tonic-gate return (WALK_DONE); 21140Sstevel@tonic-gate 21150Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)fe.fce_next; 21160Sstevel@tonic-gate return (status); 21170Sstevel@tonic-gate } 21180Sstevel@tonic-gate 21190Sstevel@tonic-gate int 21200Sstevel@tonic-gate minornode_walk_init(mdb_walk_state_t *wsp) 21210Sstevel@tonic-gate { 21220Sstevel@tonic-gate struct dev_info di; 21230Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 21240Sstevel@tonic-gate 21250Sstevel@tonic-gate if (addr == NULL) { 21260Sstevel@tonic-gate mdb_warn("a dev_info struct address must be provided\n"); 21270Sstevel@tonic-gate return (WALK_ERR); 21280Sstevel@tonic-gate } 21290Sstevel@tonic-gate 21300Sstevel@tonic-gate if (mdb_vread(&di, sizeof (di), wsp->walk_addr) == -1) { 21310Sstevel@tonic-gate mdb_warn("failed to read dev_info struct at %p", addr); 21320Sstevel@tonic-gate return (WALK_ERR); 21330Sstevel@tonic-gate } 21340Sstevel@tonic-gate 21350Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)di.devi_minor; 21360Sstevel@tonic-gate return (WALK_NEXT); 21370Sstevel@tonic-gate } 21380Sstevel@tonic-gate 21390Sstevel@tonic-gate int 21400Sstevel@tonic-gate minornode_walk_step(mdb_walk_state_t *wsp) 21410Sstevel@tonic-gate { 21420Sstevel@tonic-gate struct ddi_minor_data md; 21430Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 21440Sstevel@tonic-gate 21450Sstevel@tonic-gate if (addr == NULL) 21460Sstevel@tonic-gate return (WALK_DONE); 21470Sstevel@tonic-gate 21480Sstevel@tonic-gate if (mdb_vread(&md, sizeof (md), addr) == -1) { 21490Sstevel@tonic-gate mdb_warn("failed to read dev_info struct at %p", addr); 21500Sstevel@tonic-gate return (WALK_DONE); 21510Sstevel@tonic-gate } 21520Sstevel@tonic-gate 21530Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)md.next; 21540Sstevel@tonic-gate return (wsp->walk_callback(addr, &md, wsp->walk_cbdata)); 21550Sstevel@tonic-gate } 21560Sstevel@tonic-gate 21570Sstevel@tonic-gate static const char *const md_type[] = { 21580Sstevel@tonic-gate "DDI_MINOR", 21590Sstevel@tonic-gate "DDI_ALIAS", 21600Sstevel@tonic-gate "DDI_DEFAULT", 21610Sstevel@tonic-gate "DDI_I_PATH", 21620Sstevel@tonic-gate "?" 21630Sstevel@tonic-gate }; 21640Sstevel@tonic-gate 21650Sstevel@tonic-gate #define MD_TYPE_MAX ((sizeof (md_type) / sizeof (char *)) - 1) 21660Sstevel@tonic-gate 21670Sstevel@tonic-gate /*ARGSUSED*/ 21680Sstevel@tonic-gate static int 21690Sstevel@tonic-gate print_minornode(uintptr_t addr, const void *arg, void *data) 21700Sstevel@tonic-gate { 21710Sstevel@tonic-gate char name[128]; 21720Sstevel@tonic-gate char nodetype[128]; 21730Sstevel@tonic-gate char *spectype; 21740Sstevel@tonic-gate struct ddi_minor_data *mdp = (struct ddi_minor_data *)arg; 21750Sstevel@tonic-gate 21760Sstevel@tonic-gate if (mdb_readstr(name, sizeof (name), (uintptr_t)mdp->ddm_name) == -1) 21770Sstevel@tonic-gate *name = '\0'; 21780Sstevel@tonic-gate 21790Sstevel@tonic-gate if (mdb_readstr(nodetype, sizeof (nodetype), 21800Sstevel@tonic-gate (uintptr_t)mdp->ddm_node_type) == -1) 21810Sstevel@tonic-gate *nodetype = '\0'; 21820Sstevel@tonic-gate 21830Sstevel@tonic-gate switch (mdp->ddm_spec_type) { 21840Sstevel@tonic-gate case S_IFCHR: spectype = "c"; break; 21850Sstevel@tonic-gate case S_IFBLK: spectype = "b"; break; 21860Sstevel@tonic-gate default: spectype = "?"; break; 21870Sstevel@tonic-gate } 21880Sstevel@tonic-gate 21890Sstevel@tonic-gate mdb_printf("%?p %16lx %-4s %-11s %-10s %s\n", 21900Sstevel@tonic-gate addr, mdp->ddm_dev, spectype, md_type[MIN(mdp->type, MD_TYPE_MAX)], 21910Sstevel@tonic-gate name, nodetype); 21920Sstevel@tonic-gate 21930Sstevel@tonic-gate return (WALK_NEXT); 21940Sstevel@tonic-gate } 21950Sstevel@tonic-gate 21960Sstevel@tonic-gate /*ARGSUSED*/ 21970Sstevel@tonic-gate int 21980Sstevel@tonic-gate minornodes(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 21990Sstevel@tonic-gate { 22000Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) || argc != 0) 22010Sstevel@tonic-gate return (DCMD_USAGE); 22020Sstevel@tonic-gate 22030Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) 22040Sstevel@tonic-gate mdb_printf("%<u>%?s %16s %-4s %-11s %-10s %-16s%</u>\n", 22050Sstevel@tonic-gate "ADDR", "DEV", "SPEC", "TYPE", "NAME", "NODETYPE"); 22060Sstevel@tonic-gate 22070Sstevel@tonic-gate if (mdb_pwalk("minornode", print_minornode, NULL, addr) == -1) { 22080Sstevel@tonic-gate mdb_warn("can't walk minornode"); 22090Sstevel@tonic-gate return (DCMD_ERR); 22100Sstevel@tonic-gate } 22110Sstevel@tonic-gate 22120Sstevel@tonic-gate return (DCMD_OK); 22130Sstevel@tonic-gate } 2214