xref: /illumos-gate/usr/src/cmd/mdb/common/modules/s1394/s1394.c (revision 33c72b7598992897b94815b1f47b7b8077e53808)
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 #include <sys/mdb_modapi.h>
28 #include <sys/dditypes.h>
29 #include <sys/sysinfo.h>
30 #include <sys/1394/s1394.h>
31 
32 static int print_node_info(s1394_hal_t *hal);
33 
34 /*
35  * speedmap()
36  *    is used to print node information (speed map, node number, GUID, etc.)
37  *    about the 1394 devices currently attached to the 1394 bus.
38  */
39 static int
40 speedmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
41 {
42 	s1394_hal_t	hal;
43 	int		ret;
44 
45 	if (flags & DCMD_ADDRSPEC) {
46 		if (mdb_vread(&hal, sizeof (s1394_hal_t), addr) == -1) {
47 			mdb_warn("failed to read the HAL structure");
48 			return (DCMD_ERR);
49 		}
50 
51 		ret = print_node_info(&hal);
52 		if (ret == DCMD_ERR)
53 		    return (DCMD_ERR);
54 	} else {
55 		(void) mdb_walk_dcmd("speedmap", "speedmap", argc, argv);
56 	}
57 
58 	return (DCMD_OK);
59 }
60 
61 static int
62 speedmap_walk_init(mdb_walk_state_t *wsp)
63 {
64 	s1394_state_t	*statep;
65 	s1394_state_t	state;
66 
67 	if (wsp->walk_addr == 0) {
68 		if (mdb_readvar(&statep, "s1394_statep") == -1) {
69 			mdb_warn("failed to find the s1394_statep pointer");
70 			return (WALK_ERR);
71 		}
72 		if (mdb_vread(&state, sizeof (s1394_state_t),
73 		    (uintptr_t)statep) == -1) {
74 			mdb_warn("failed to read the s1394_statep structure");
75 			return (WALK_ERR);
76 		}
77 		wsp->walk_addr = (uintptr_t)state.hal_head;
78 	}
79 
80 	return (WALK_NEXT);
81 }
82 
83 static int
84 speedmap_walk_step(mdb_walk_state_t *wsp)
85 {
86 	s1394_hal_t	hal;
87 	uintptr_t	addr = wsp->walk_addr;
88 
89 	if (addr == 0)
90 		return (WALK_DONE);
91 
92 	if (mdb_vread(&hal, sizeof (s1394_hal_t), addr) == -1) {
93 		mdb_warn("failed to read the HAL structure");
94 		return (WALK_ERR);
95 	}
96 
97 	wsp->walk_addr = (uintptr_t)hal.hal_next;
98 	return (wsp->walk_callback(addr, &hal, wsp->walk_cbdata));
99 }
100 
101 /*ARGSUSED*/
102 static void
103 speedmap_walk_fini(mdb_walk_state_t *wsp)
104 {
105 	/* Nothing to do here */
106 }
107 
108 static const mdb_dcmd_t dcmds[] = {
109 	{ "speedmap", NULL, "print 1394 bus information", speedmap },
110 	{ NULL }
111 };
112 
113 static const mdb_walker_t walkers[] = {
114 	{ "speedmap", "iterate over HAL structures", speedmap_walk_init,
115 		speedmap_walk_step, speedmap_walk_fini },
116 	{ NULL }
117 };
118 
119 static const mdb_modinfo_t modinfo = {
120 	MDB_API_VERSION, dcmds, walkers
121 };
122 
123 const mdb_modinfo_t *
124 _mdb_init(void)
125 {
126 	return (&modinfo);
127 }
128 
129 /*
130  * print_node_info()
131  *    is used to do the actual printing, given a HAL pointer.
132  */
133 static int
134 print_node_info(s1394_hal_t *hal)
135 {
136 	s1394_node_t	node[IEEE1394_MAX_NODES];
137 	uint32_t	cfgrom[IEEE1394_CONFIG_ROM_QUAD_SZ];
138 	char		str[512], tmp[512];
139 	uint_t		hal_node_num, num_nodes;
140 	int		i, j;
141 
142 	num_nodes = hal->number_of_nodes;
143 	if (mdb_vread(node, (num_nodes * sizeof (s1394_node_t)),
144 	    (uintptr_t)hal->topology_tree) == -1) {
145 		mdb_warn("failed to read the node structures");
146 		return (DCMD_ERR);
147 	}
148 
149 	hal_node_num = IEEE1394_NODE_NUM(hal->node_id);
150 
151 	mdb_printf("Speed Map:\n");
152 
153 	(void) strcpy(str, "    |");
154 	for (i = 0; i < num_nodes; i++) {
155 		(void) mdb_snprintf(tmp, sizeof (tmp), " %2d ", i);
156 		(void) strcat(str, tmp);
157 	}
158 	(void) strcat(str, "  |       GUID\n");
159 	mdb_printf("%s", str);
160 
161 	(void) strcpy(str, "----|");
162 	for (i = 0; i < hal->number_of_nodes; i++) {
163 		(void) mdb_snprintf(tmp, sizeof (tmp), "----");
164 		(void) strcat(str, tmp);
165 	}
166 	(void) strcat(str, "--|------------------\n");
167 	mdb_printf("%s", str);
168 
169 	for (i = 0; i < num_nodes; i++) {
170 		if (node[i].cfgrom != NULL) {
171 			if (mdb_vread(&cfgrom, IEEE1394_CONFIG_ROM_SZ,
172 			    (uintptr_t)node[i].cfgrom) == -1) {
173 				mdb_warn("failed to read Config ROM");
174 				return (DCMD_ERR);
175 			}
176 		}
177 
178 		(void) mdb_snprintf(str, sizeof (str), " %2d |", i);
179 
180 		for (j = 0; j < num_nodes; j++) {
181 			(void) mdb_snprintf(tmp, sizeof (tmp), " %3d",
182 			    hal->speed_map[i][j]);
183 			(void) strcat(str, tmp);
184 		}
185 
186 		if (i == hal_node_num) {
187 			(void) strcat(str, "  | Local OHCI Card\n");
188 
189 		} else if (node[i].link_active == 0) {
190 			(void) strcat(str, "  | Link off\n");
191 
192 		} else if (CFGROM_BIB_READ(&node[i])) {
193 			(void) mdb_snprintf(tmp, sizeof (tmp),
194 			    "  | %08x%08x\n", cfgrom[3], cfgrom[4]);
195 			(void) strcat(str, tmp);
196 
197 		} else {
198 			(void) strcat(str, "  | ????????????????\n");
199 		}
200 		mdb_printf("%s", str);
201 	}
202 	mdb_printf("\n");
203 	return (DCMD_OK);
204 }
205