xref: /titanic_52/usr/src/cmd/mdb/common/modules/usba/usba.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2000-2002 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * Routines extracted from usr/src/uts/common/io/usb/usba/usba.c.
31*7c478bd9Sstevel@tonic-gate  */
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include <sys/mdb_modapi.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/usb/usba.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usba_types.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usba_impl.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/usb/usba/hcdi_impl.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/file.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate  * check whether this dip is the root hub.
44*7c478bd9Sstevel@tonic-gate  * dip_addr is address of the devinfo struct in the core image (not local space)
45*7c478bd9Sstevel@tonic-gate  */
46*7c478bd9Sstevel@tonic-gate static int
47*7c478bd9Sstevel@tonic-gate mdb_usba_is_root_hub(struct dev_info *dip)
48*7c478bd9Sstevel@tonic-gate {
49*7c478bd9Sstevel@tonic-gate 	uintptr_t	p = (uintptr_t)dip->devi_hw_prop_ptr;
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate 	while (p != NULL) {
52*7c478bd9Sstevel@tonic-gate 		ddi_prop_t prop;
53*7c478bd9Sstevel@tonic-gate 		char prop_name[128];
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate 		if (mdb_vread(&prop, sizeof (prop), p) == -1) {
56*7c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read property");
57*7c478bd9Sstevel@tonic-gate 			break;
58*7c478bd9Sstevel@tonic-gate 		}
59*7c478bd9Sstevel@tonic-gate 		if (mdb_readstr(prop_name, sizeof (prop_name),
60*7c478bd9Sstevel@tonic-gate 		    (uintptr_t)prop.prop_name) == -1) {
61*7c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read property name");
62*7c478bd9Sstevel@tonic-gate 		}
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate 		if (strcmp(prop_name, "root-hub") == 0) {
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate 			return (1);
67*7c478bd9Sstevel@tonic-gate 		}
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate 		p = (uintptr_t)prop.prop_next;
70*7c478bd9Sstevel@tonic-gate 	}
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	return (0);
73*7c478bd9Sstevel@tonic-gate }
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate /*
77*7c478bd9Sstevel@tonic-gate  * retrieve hcdi structure from the dip
78*7c478bd9Sstevel@tonic-gate  *
79*7c478bd9Sstevel@tonic-gate  * dip_addr is address of the devinfo struct in the core image (not local space)
80*7c478bd9Sstevel@tonic-gate  */
81*7c478bd9Sstevel@tonic-gate uintptr_t
82*7c478bd9Sstevel@tonic-gate mdb_usba_hcdi_get_hcdi(struct dev_info *dip)
83*7c478bd9Sstevel@tonic-gate {
84*7c478bd9Sstevel@tonic-gate 	return ((uintptr_t)dip->devi_driver_data);
85*7c478bd9Sstevel@tonic-gate }
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate /*
89*7c478bd9Sstevel@tonic-gate  * get usba_device pointer in the devi
90*7c478bd9Sstevel@tonic-gate  *
91*7c478bd9Sstevel@tonic-gate  * dip_addr is address of the devinfo struct in the core image (not local space)
92*7c478bd9Sstevel@tonic-gate  */
93*7c478bd9Sstevel@tonic-gate uintptr_t
94*7c478bd9Sstevel@tonic-gate mdb_usba_get_usba_device(uintptr_t dip_addr)
95*7c478bd9Sstevel@tonic-gate {
96*7c478bd9Sstevel@tonic-gate 	struct dev_info	devinfo;
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate 	if (mdb_vread(&devinfo, sizeof (struct dev_info), dip_addr) == -1) {
99*7c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read dev_info at %p", dip_addr);
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate 		return (NULL);
102*7c478bd9Sstevel@tonic-gate 	}
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	/*
105*7c478bd9Sstevel@tonic-gate 	 * we cannot use parent_data in the usb node because its
106*7c478bd9Sstevel@tonic-gate 	 * bus parent (eg. PCI nexus driver) uses this data
107*7c478bd9Sstevel@tonic-gate 	 *
108*7c478bd9Sstevel@tonic-gate 	 * we cannot use driver data in the other usb nodes since
109*7c478bd9Sstevel@tonic-gate 	 * usb drivers may need to use this
110*7c478bd9Sstevel@tonic-gate 	 */
111*7c478bd9Sstevel@tonic-gate 	if (mdb_usba_is_root_hub(&devinfo)) {
112*7c478bd9Sstevel@tonic-gate 		usba_hcdi_t hcdi_struct;
113*7c478bd9Sstevel@tonic-gate 		uintptr_t hcdi_addr = mdb_usba_hcdi_get_hcdi(&devinfo);
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 		if (!hcdi_addr) {
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate 			return (NULL);
118*7c478bd9Sstevel@tonic-gate 		}
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate 		/* Read hcdi struct into local address space. */
121*7c478bd9Sstevel@tonic-gate 		if (mdb_vread(&hcdi_struct, sizeof (usba_hcdi_t),
122*7c478bd9Sstevel@tonic-gate 		    hcdi_addr) == -1) {
123*7c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read hcdi struct");
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 			return (NULL);
126*7c478bd9Sstevel@tonic-gate 		}
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 		return ((uintptr_t)hcdi_struct.hcdi_usba_device);
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 	} else {
131*7c478bd9Sstevel@tonic-gate 		struct dev_info	devinfo;
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate 		if (mdb_vread(&devinfo, sizeof (struct dev_info),
134*7c478bd9Sstevel@tonic-gate 		    dip_addr) == -1) {
135*7c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read dev_info at %p", dip_addr);
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 			return (NULL);
138*7c478bd9Sstevel@tonic-gate 		}
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate 		/* casts needed to keep lint happy */
141*7c478bd9Sstevel@tonic-gate 		return ((uintptr_t)devinfo.devi_parent_data);
142*7c478bd9Sstevel@tonic-gate 	}
143*7c478bd9Sstevel@tonic-gate }
144