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