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