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