1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1999-2000 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <sys/mdb_modapi.h> 30*7c478bd9Sstevel@tonic-gate #include <sys/dditypes.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/sysinfo.h> 32*7c478bd9Sstevel@tonic-gate #include <sys/1394/s1394.h> 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate static int print_node_info(s1394_hal_t *hal); 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate /* 37*7c478bd9Sstevel@tonic-gate * speedmap() 38*7c478bd9Sstevel@tonic-gate * is used to print node information (speed map, node number, GUID, etc.) 39*7c478bd9Sstevel@tonic-gate * about the 1394 devices currently attached to the 1394 bus. 40*7c478bd9Sstevel@tonic-gate */ 41*7c478bd9Sstevel@tonic-gate static int 42*7c478bd9Sstevel@tonic-gate speedmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 43*7c478bd9Sstevel@tonic-gate { 44*7c478bd9Sstevel@tonic-gate s1394_hal_t hal; 45*7c478bd9Sstevel@tonic-gate int ret; 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) { 48*7c478bd9Sstevel@tonic-gate if (mdb_vread(&hal, sizeof (s1394_hal_t), addr) == -1) { 49*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read the HAL structure"); 50*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 51*7c478bd9Sstevel@tonic-gate } 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate ret = print_node_info(&hal); 54*7c478bd9Sstevel@tonic-gate if (ret == DCMD_ERR) 55*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 56*7c478bd9Sstevel@tonic-gate } else { 57*7c478bd9Sstevel@tonic-gate (void) mdb_walk_dcmd("speedmap", "speedmap", argc, argv); 58*7c478bd9Sstevel@tonic-gate } 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 61*7c478bd9Sstevel@tonic-gate } 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate static int 64*7c478bd9Sstevel@tonic-gate speedmap_walk_init(mdb_walk_state_t *wsp) 65*7c478bd9Sstevel@tonic-gate { 66*7c478bd9Sstevel@tonic-gate s1394_state_t *statep; 67*7c478bd9Sstevel@tonic-gate s1394_state_t state; 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 70*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&statep, "s1394_statep") == -1) { 71*7c478bd9Sstevel@tonic-gate mdb_warn("failed to find the s1394_statep pointer"); 72*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 73*7c478bd9Sstevel@tonic-gate } 74*7c478bd9Sstevel@tonic-gate if (mdb_vread(&state, sizeof (s1394_state_t), 75*7c478bd9Sstevel@tonic-gate (uintptr_t)statep) == -1) { 76*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read the s1394_statep structure"); 77*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 78*7c478bd9Sstevel@tonic-gate } 79*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)state.hal_head; 80*7c478bd9Sstevel@tonic-gate } 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 83*7c478bd9Sstevel@tonic-gate } 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate static int 86*7c478bd9Sstevel@tonic-gate speedmap_walk_step(mdb_walk_state_t *wsp) 87*7c478bd9Sstevel@tonic-gate { 88*7c478bd9Sstevel@tonic-gate s1394_hal_t hal; 89*7c478bd9Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate if (addr == NULL) 92*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate if (mdb_vread(&hal, sizeof (s1394_hal_t), addr) == -1) { 95*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read the HAL structure"); 96*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 97*7c478bd9Sstevel@tonic-gate } 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)hal.hal_next; 100*7c478bd9Sstevel@tonic-gate return (wsp->walk_callback(addr, &hal, wsp->walk_cbdata)); 101*7c478bd9Sstevel@tonic-gate } 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 104*7c478bd9Sstevel@tonic-gate static void 105*7c478bd9Sstevel@tonic-gate speedmap_walk_fini(mdb_walk_state_t *wsp) 106*7c478bd9Sstevel@tonic-gate { 107*7c478bd9Sstevel@tonic-gate /* Nothing to do here */ 108*7c478bd9Sstevel@tonic-gate } 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = { 111*7c478bd9Sstevel@tonic-gate { "speedmap", NULL, "print 1394 bus information", speedmap }, 112*7c478bd9Sstevel@tonic-gate { NULL } 113*7c478bd9Sstevel@tonic-gate }; 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate static const mdb_walker_t walkers[] = { 116*7c478bd9Sstevel@tonic-gate { "speedmap", "iterate over HAL structures", speedmap_walk_init, 117*7c478bd9Sstevel@tonic-gate speedmap_walk_step, speedmap_walk_fini }, 118*7c478bd9Sstevel@tonic-gate { NULL } 119*7c478bd9Sstevel@tonic-gate }; 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { 122*7c478bd9Sstevel@tonic-gate MDB_API_VERSION, dcmds, walkers 123*7c478bd9Sstevel@tonic-gate }; 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate const mdb_modinfo_t * 126*7c478bd9Sstevel@tonic-gate _mdb_init(void) 127*7c478bd9Sstevel@tonic-gate { 128*7c478bd9Sstevel@tonic-gate return (&modinfo); 129*7c478bd9Sstevel@tonic-gate } 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate /* 132*7c478bd9Sstevel@tonic-gate * print_node_info() 133*7c478bd9Sstevel@tonic-gate * is used to do the actual printing, given a HAL pointer. 134*7c478bd9Sstevel@tonic-gate */ 135*7c478bd9Sstevel@tonic-gate static int 136*7c478bd9Sstevel@tonic-gate print_node_info(s1394_hal_t *hal) 137*7c478bd9Sstevel@tonic-gate { 138*7c478bd9Sstevel@tonic-gate s1394_node_t node[IEEE1394_MAX_NODES]; 139*7c478bd9Sstevel@tonic-gate uint32_t cfgrom[IEEE1394_CONFIG_ROM_QUAD_SZ]; 140*7c478bd9Sstevel@tonic-gate char str[512], tmp[512]; 141*7c478bd9Sstevel@tonic-gate uint_t hal_node_num, num_nodes; 142*7c478bd9Sstevel@tonic-gate int i, j; 143*7c478bd9Sstevel@tonic-gate 144*7c478bd9Sstevel@tonic-gate num_nodes = hal->number_of_nodes; 145*7c478bd9Sstevel@tonic-gate if (mdb_vread(node, (num_nodes * sizeof (s1394_node_t)), 146*7c478bd9Sstevel@tonic-gate (uintptr_t)hal->topology_tree) == -1) { 147*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read the node structures"); 148*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 149*7c478bd9Sstevel@tonic-gate } 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate hal_node_num = IEEE1394_NODE_NUM(hal->node_id); 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate mdb_printf("Speed Map:\n"); 154*7c478bd9Sstevel@tonic-gate 155*7c478bd9Sstevel@tonic-gate (void) strcpy(str, " |"); 156*7c478bd9Sstevel@tonic-gate for (i = 0; i < num_nodes; i++) { 157*7c478bd9Sstevel@tonic-gate (void) mdb_snprintf(tmp, sizeof (tmp), " %2d ", i); 158*7c478bd9Sstevel@tonic-gate (void) strcat(str, tmp); 159*7c478bd9Sstevel@tonic-gate } 160*7c478bd9Sstevel@tonic-gate (void) strcat(str, " | GUID\n"); 161*7c478bd9Sstevel@tonic-gate mdb_printf("%s", str); 162*7c478bd9Sstevel@tonic-gate 163*7c478bd9Sstevel@tonic-gate (void) strcpy(str, "----|"); 164*7c478bd9Sstevel@tonic-gate for (i = 0; i < hal->number_of_nodes; i++) { 165*7c478bd9Sstevel@tonic-gate (void) mdb_snprintf(tmp, sizeof (tmp), "----"); 166*7c478bd9Sstevel@tonic-gate (void) strcat(str, tmp); 167*7c478bd9Sstevel@tonic-gate } 168*7c478bd9Sstevel@tonic-gate (void) strcat(str, "--|------------------\n"); 169*7c478bd9Sstevel@tonic-gate mdb_printf("%s", str); 170*7c478bd9Sstevel@tonic-gate 171*7c478bd9Sstevel@tonic-gate for (i = 0; i < num_nodes; i++) { 172*7c478bd9Sstevel@tonic-gate if (node[i].cfgrom != NULL) { 173*7c478bd9Sstevel@tonic-gate if (mdb_vread(&cfgrom, IEEE1394_CONFIG_ROM_SZ, 174*7c478bd9Sstevel@tonic-gate (uintptr_t)node[i].cfgrom) == -1) { 175*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read Config ROM"); 176*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 177*7c478bd9Sstevel@tonic-gate } 178*7c478bd9Sstevel@tonic-gate } 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate (void) mdb_snprintf(str, sizeof (str), " %2d |", i); 181*7c478bd9Sstevel@tonic-gate 182*7c478bd9Sstevel@tonic-gate for (j = 0; j < num_nodes; j++) { 183*7c478bd9Sstevel@tonic-gate (void) mdb_snprintf(tmp, sizeof (tmp), " %3d", 184*7c478bd9Sstevel@tonic-gate hal->speed_map[i][j]); 185*7c478bd9Sstevel@tonic-gate (void) strcat(str, tmp); 186*7c478bd9Sstevel@tonic-gate } 187*7c478bd9Sstevel@tonic-gate 188*7c478bd9Sstevel@tonic-gate if (i == hal_node_num) { 189*7c478bd9Sstevel@tonic-gate (void) strcat(str, " | Local OHCI Card\n"); 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate } else if (node[i].link_active == 0) { 192*7c478bd9Sstevel@tonic-gate (void) strcat(str, " | Link off\n"); 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate } else if (CFGROM_BIB_READ(&node[i])) { 195*7c478bd9Sstevel@tonic-gate (void) mdb_snprintf(tmp, sizeof (tmp), 196*7c478bd9Sstevel@tonic-gate " | %08x%08x\n", cfgrom[3], cfgrom[4]); 197*7c478bd9Sstevel@tonic-gate (void) strcat(str, tmp); 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate } else { 200*7c478bd9Sstevel@tonic-gate (void) strcat(str, " | ????????????????\n"); 201*7c478bd9Sstevel@tonic-gate } 202*7c478bd9Sstevel@tonic-gate mdb_printf("%s", str); 203*7c478bd9Sstevel@tonic-gate } 204*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 205*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 206*7c478bd9Sstevel@tonic-gate } 207