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