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