dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / mdb / common / modules / s1394 / s1394.c
bloba6b4957697f045d12fdac79e67f64194cf5896a1
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #include <sys/mdb_modapi.h>
28 #include <sys/dditypes.h>
29 #include <sys/sysinfo.h>
30 #include <sys/1394/s1394.h>
32 static int print_node_info(s1394_hal_t *hal);
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.
39 static int
40 speedmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
42 s1394_hal_t hal;
43 int ret;
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);
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);
58 return (DCMD_OK);
61 static int
62 speedmap_walk_init(mdb_walk_state_t *wsp)
64 s1394_state_t *statep;
65 s1394_state_t state;
67 if (wsp->walk_addr == (uintptr_t)NULL) {
68 if (mdb_readvar(&statep, "s1394_statep") == -1) {
69 mdb_warn("failed to find the s1394_statep pointer");
70 return (WALK_ERR);
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);
77 wsp->walk_addr = (uintptr_t)state.hal_head;
80 return (WALK_NEXT);
83 static int
84 speedmap_walk_step(mdb_walk_state_t *wsp)
86 s1394_hal_t hal;
87 uintptr_t addr = wsp->walk_addr;
89 if (addr == (uintptr_t)NULL)
90 return (WALK_DONE);
92 if (mdb_vread(&hal, sizeof (s1394_hal_t), addr) == -1) {
93 mdb_warn("failed to read the HAL structure");
94 return (WALK_ERR);
97 wsp->walk_addr = (uintptr_t)hal.hal_next;
98 return (wsp->walk_callback(addr, &hal, wsp->walk_cbdata));
101 /*ARGSUSED*/
102 static void
103 speedmap_walk_fini(mdb_walk_state_t *wsp)
105 /* Nothing to do here */
108 static const mdb_dcmd_t dcmds[] = {
109 { "speedmap", NULL, "print 1394 bus information", speedmap },
110 { NULL }
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 }
119 static const mdb_modinfo_t modinfo = {
120 MDB_API_VERSION, dcmds, walkers
123 const mdb_modinfo_t *
124 _mdb_init(void)
126 return (&modinfo);
130 * print_node_info()
131 * is used to do the actual printing, given a HAL pointer.
133 static int
134 print_node_info(s1394_hal_t *hal)
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;
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);
149 hal_node_num = IEEE1394_NODE_NUM(hal->node_id);
151 mdb_printf("Speed Map:\n");
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);
158 (void) strcat(str, " | GUID\n");
159 mdb_printf("%s", str);
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);
166 (void) strcat(str, "--|------------------\n");
167 mdb_printf("%s", str);
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);
178 (void) mdb_snprintf(str, sizeof (str), " %2d |", i);
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);
186 if (i == hal_node_num) {
187 (void) strcat(str, " | Local OHCI Card\n");
189 } else if (node[i].link_active == 0) {
190 (void) strcat(str, " | Link off\n");
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);
197 } else {
198 (void) strcat(str, " | ????????????????\n");
200 mdb_printf("%s", str);
202 mdb_printf("\n");
203 return (DCMD_OK);