17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
247c478bd9Sstevel@tonic-gate  * All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <sys/mdb_modapi.h>
287c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
297c478bd9Sstevel@tonic-gate #include <sys/sysinfo.h>
307c478bd9Sstevel@tonic-gate #include <sys/1394/s1394.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate static int print_node_info(s1394_hal_t *hal);
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * speedmap()
367c478bd9Sstevel@tonic-gate  *    is used to print node information (speed map, node number, GUID, etc.)
377c478bd9Sstevel@tonic-gate  *    about the 1394 devices currently attached to the 1394 bus.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate static int
speedmap(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)407c478bd9Sstevel@tonic-gate speedmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
417c478bd9Sstevel@tonic-gate {
427c478bd9Sstevel@tonic-gate 	s1394_hal_t	hal;
437c478bd9Sstevel@tonic-gate 	int		ret;
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC) {
467c478bd9Sstevel@tonic-gate 		if (mdb_vread(&hal, sizeof (s1394_hal_t), addr) == -1) {
477c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read the HAL structure");
487c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
497c478bd9Sstevel@tonic-gate 		}
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate 		ret = print_node_info(&hal);
527c478bd9Sstevel@tonic-gate 		if (ret == DCMD_ERR)
537c478bd9Sstevel@tonic-gate 		    return (DCMD_ERR);
547c478bd9Sstevel@tonic-gate 	} else {
557c478bd9Sstevel@tonic-gate 		(void) mdb_walk_dcmd("speedmap", "speedmap", argc, argv);
567c478bd9Sstevel@tonic-gate 	}
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
597c478bd9Sstevel@tonic-gate }
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate static int
speedmap_walk_init(mdb_walk_state_t * wsp)627c478bd9Sstevel@tonic-gate speedmap_walk_init(mdb_walk_state_t *wsp)
637c478bd9Sstevel@tonic-gate {
647c478bd9Sstevel@tonic-gate 	s1394_state_t	*statep;
657c478bd9Sstevel@tonic-gate 	s1394_state_t	state;
667c478bd9Sstevel@tonic-gate 
67*892ad162SToomas Soome 	if (wsp->walk_addr == 0) {
687c478bd9Sstevel@tonic-gate 		if (mdb_readvar(&statep, "s1394_statep") == -1) {
697c478bd9Sstevel@tonic-gate 			mdb_warn("failed to find the s1394_statep pointer");
707c478bd9Sstevel@tonic-gate 			return (WALK_ERR);
717c478bd9Sstevel@tonic-gate 		}
727c478bd9Sstevel@tonic-gate 		if (mdb_vread(&state, sizeof (s1394_state_t),
737c478bd9Sstevel@tonic-gate 		    (uintptr_t)statep) == -1) {
747c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read the s1394_statep structure");
757c478bd9Sstevel@tonic-gate 			return (WALK_ERR);
767c478bd9Sstevel@tonic-gate 		}
777c478bd9Sstevel@tonic-gate 		wsp->walk_addr = (uintptr_t)state.hal_head;
787c478bd9Sstevel@tonic-gate 	}
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate static int
speedmap_walk_step(mdb_walk_state_t * wsp)847c478bd9Sstevel@tonic-gate speedmap_walk_step(mdb_walk_state_t *wsp)
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate 	s1394_hal_t	hal;
877c478bd9Sstevel@tonic-gate 	uintptr_t	addr = wsp->walk_addr;
887c478bd9Sstevel@tonic-gate 
89*892ad162SToomas Soome 	if (addr == 0)
907c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	if (mdb_vread(&hal, sizeof (s1394_hal_t), addr) == -1) {
937c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read the HAL structure");
947c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
957c478bd9Sstevel@tonic-gate 	}
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)hal.hal_next;
987c478bd9Sstevel@tonic-gate 	return (wsp->walk_callback(addr, &hal, wsp->walk_cbdata));
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1027c478bd9Sstevel@tonic-gate static void
speedmap_walk_fini(mdb_walk_state_t * wsp)1037c478bd9Sstevel@tonic-gate speedmap_walk_fini(mdb_walk_state_t *wsp)
1047c478bd9Sstevel@tonic-gate {
1057c478bd9Sstevel@tonic-gate 	/* Nothing to do here */
1067c478bd9Sstevel@tonic-gate }
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
1097c478bd9Sstevel@tonic-gate 	{ "speedmap", NULL, "print 1394 bus information", speedmap },
1107c478bd9Sstevel@tonic-gate 	{ NULL }
1117c478bd9Sstevel@tonic-gate };
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
1147c478bd9Sstevel@tonic-gate 	{ "speedmap", "iterate over HAL structures", speedmap_walk_init,
1157c478bd9Sstevel@tonic-gate 		speedmap_walk_step, speedmap_walk_fini },
1167c478bd9Sstevel@tonic-gate 	{ NULL }
1177c478bd9Sstevel@tonic-gate };
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate static const mdb_modinfo_t modinfo = {
1207c478bd9Sstevel@tonic-gate 	MDB_API_VERSION, dcmds, walkers
1217c478bd9Sstevel@tonic-gate };
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate const mdb_modinfo_t *
_mdb_init(void)1247c478bd9Sstevel@tonic-gate _mdb_init(void)
1257c478bd9Sstevel@tonic-gate {
1267c478bd9Sstevel@tonic-gate 	return (&modinfo);
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate  * print_node_info()
1317c478bd9Sstevel@tonic-gate  *    is used to do the actual printing, given a HAL pointer.
1327c478bd9Sstevel@tonic-gate  */
1337c478bd9Sstevel@tonic-gate static int
print_node_info(s1394_hal_t * hal)1347c478bd9Sstevel@tonic-gate print_node_info(s1394_hal_t *hal)
1357c478bd9Sstevel@tonic-gate {
1367c478bd9Sstevel@tonic-gate 	s1394_node_t	node[IEEE1394_MAX_NODES];
1377c478bd9Sstevel@tonic-gate 	uint32_t	cfgrom[IEEE1394_CONFIG_ROM_QUAD_SZ];
1387c478bd9Sstevel@tonic-gate 	char		str[512], tmp[512];
1397c478bd9Sstevel@tonic-gate 	uint_t		hal_node_num, num_nodes;
1407c478bd9Sstevel@tonic-gate 	int		i, j;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	num_nodes = hal->number_of_nodes;
1437c478bd9Sstevel@tonic-gate 	if (mdb_vread(node, (num_nodes * sizeof (s1394_node_t)),
1447c478bd9Sstevel@tonic-gate 	    (uintptr_t)hal->topology_tree) == -1) {
1457c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read the node structures");
1467c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
1477c478bd9Sstevel@tonic-gate 	}
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	hal_node_num = IEEE1394_NODE_NUM(hal->node_id);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	mdb_printf("Speed Map:\n");
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 	(void) strcpy(str, "    |");
1547c478bd9Sstevel@tonic-gate 	for (i = 0; i < num_nodes; i++) {
1557c478bd9Sstevel@tonic-gate 		(void) mdb_snprintf(tmp, sizeof (tmp), " %2d ", i);
1567c478bd9Sstevel@tonic-gate 		(void) strcat(str, tmp);
1577c478bd9Sstevel@tonic-gate 	}
1587c478bd9Sstevel@tonic-gate 	(void) strcat(str, "  |       GUID\n");
1597c478bd9Sstevel@tonic-gate 	mdb_printf("%s", str);
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 	(void) strcpy(str, "----|");
1627c478bd9Sstevel@tonic-gate 	for (i = 0; i < hal->number_of_nodes; i++) {
1637c478bd9Sstevel@tonic-gate 		(void) mdb_snprintf(tmp, sizeof (tmp), "----");
1647c478bd9Sstevel@tonic-gate 		(void) strcat(str, tmp);
1657c478bd9Sstevel@tonic-gate 	}
1667c478bd9Sstevel@tonic-gate 	(void) strcat(str, "--|------------------\n");
1677c478bd9Sstevel@tonic-gate 	mdb_printf("%s", str);
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate 	for (i = 0; i < num_nodes; i++) {
1707c478bd9Sstevel@tonic-gate 		if (node[i].cfgrom != NULL) {
1717c478bd9Sstevel@tonic-gate 			if (mdb_vread(&cfgrom, IEEE1394_CONFIG_ROM_SZ,
1727c478bd9Sstevel@tonic-gate 			    (uintptr_t)node[i].cfgrom) == -1) {
1737c478bd9Sstevel@tonic-gate 				mdb_warn("failed to read Config ROM");
1747c478bd9Sstevel@tonic-gate 				return (DCMD_ERR);
1757c478bd9Sstevel@tonic-gate 			}
1767c478bd9Sstevel@tonic-gate 		}
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 		(void) mdb_snprintf(str, sizeof (str), " %2d |", i);
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 		for (j = 0; j < num_nodes; j++) {
1817c478bd9Sstevel@tonic-gate 			(void) mdb_snprintf(tmp, sizeof (tmp), " %3d",
1827c478bd9Sstevel@tonic-gate 			    hal->speed_map[i][j]);
1837c478bd9Sstevel@tonic-gate 			(void) strcat(str, tmp);
1847c478bd9Sstevel@tonic-gate 		}
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 		if (i == hal_node_num) {
1877c478bd9Sstevel@tonic-gate 			(void) strcat(str, "  | Local OHCI Card\n");
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 		} else if (node[i].link_active == 0) {
1907c478bd9Sstevel@tonic-gate 			(void) strcat(str, "  | Link off\n");
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 		} else if (CFGROM_BIB_READ(&node[i])) {
1937c478bd9Sstevel@tonic-gate 			(void) mdb_snprintf(tmp, sizeof (tmp),
1947c478bd9Sstevel@tonic-gate 			    "  | %08x%08x\n", cfgrom[3], cfgrom[4]);
1957c478bd9Sstevel@tonic-gate 			(void) strcat(str, tmp);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 		} else {
1987c478bd9Sstevel@tonic-gate 			(void) strcat(str, "  | ????????????????\n");
1997c478bd9Sstevel@tonic-gate 		}
2007c478bd9Sstevel@tonic-gate 		mdb_printf("%s", str);
2017c478bd9Sstevel@tonic-gate 	}
2027c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
2037c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
2047c478bd9Sstevel@tonic-gate }
205