xref: /titanic_50/usr/src/cmd/mdb/common/modules/usba/prtusb.c (revision ff0e937b36dcde1a47ff7b00aa76a491c0dc07a8)
14e968bc2Sgc161489 /*
24e968bc2Sgc161489  * CDDL HEADER START
34e968bc2Sgc161489  *
44e968bc2Sgc161489  * The contents of this file are subject to the terms of the
54e968bc2Sgc161489  * Common Development and Distribution License (the "License").
64e968bc2Sgc161489  * You may not use this file except in compliance with the License.
74e968bc2Sgc161489  *
84e968bc2Sgc161489  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
94e968bc2Sgc161489  * or http://www.opensolaris.org/os/licensing.
104e968bc2Sgc161489  * See the License for the specific language governing permissions
114e968bc2Sgc161489  * and limitations under the License.
124e968bc2Sgc161489  *
134e968bc2Sgc161489  * When distributing Covered Code, include this CDDL HEADER in each
144e968bc2Sgc161489  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
154e968bc2Sgc161489  * If applicable, add the following below this CDDL HEADER, with the
164e968bc2Sgc161489  * fields enclosed by brackets "[]" replaced with your own identifying
174e968bc2Sgc161489  * information: Portions Copyright [yyyy] [name of copyright owner]
184e968bc2Sgc161489  *
194e968bc2Sgc161489  * CDDL HEADER END
204e968bc2Sgc161489  */
214e968bc2Sgc161489 /*
22*ff0e937bSRaymond Chen  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
234e968bc2Sgc161489  * Use is subject to license terms.
244e968bc2Sgc161489  */
254e968bc2Sgc161489 
264e968bc2Sgc161489 
274e968bc2Sgc161489 #include <sys/mdb_modapi.h>
284e968bc2Sgc161489 
294e968bc2Sgc161489 
304e968bc2Sgc161489 #include <sys/usb/usba.h>
314e968bc2Sgc161489 #include <sys/usb/usba/usba_types.h>
324e968bc2Sgc161489 #include <sys/usb/clients/hid/hid.h>
334e968bc2Sgc161489 #include <sys/usb/clients/hidparser/hidparser.h>
344e968bc2Sgc161489 #include <sys/usb/clients/hidparser/hidparser_impl.h>
354e968bc2Sgc161489 #include <sys/usb/usba/genconsole.h>
364e968bc2Sgc161489 #include <sys/usb/clients/hid/hidvar.h>
374e968bc2Sgc161489 
384e968bc2Sgc161489 
394e968bc2Sgc161489 /* ****************************************************************** */
404e968bc2Sgc161489 
414e968bc2Sgc161489 /* extenal definition */
424e968bc2Sgc161489 
434e968bc2Sgc161489 typedef struct mdb_ctf_id {
444e968bc2Sgc161489 	void *_opaque[2];
454e968bc2Sgc161489 } mdb_ctf_id_t;
464e968bc2Sgc161489 
474e968bc2Sgc161489 extern int mdb_ctf_lookup_by_name(const char *, mdb_ctf_id_t *);
484e968bc2Sgc161489 
494e968bc2Sgc161489 extern int mdb_devinfo2driver(uintptr_t, char *, size_t);
504e968bc2Sgc161489 
514e968bc2Sgc161489 extern int mdb_devinfo2statep(uintptr_t, char *, uintptr_t *);
524e968bc2Sgc161489 
534e968bc2Sgc161489 extern char *mdb_ddi_pathname(uintptr_t, char *, size_t);
544e968bc2Sgc161489 
554e968bc2Sgc161489 
564e968bc2Sgc161489 /* ****************************************************************** */
574e968bc2Sgc161489 
584e968bc2Sgc161489 /* internal definition */
594e968bc2Sgc161489 
604e968bc2Sgc161489 #define	OPT_TREE	0x01
614e968bc2Sgc161489 #define	OPT_VERB	0x02
624e968bc2Sgc161489 
634e968bc2Sgc161489 #define	STRLEN		256
644e968bc2Sgc161489 #define	BYTE_OFFSET	8
654e968bc2Sgc161489 
664e968bc2Sgc161489 
674e968bc2Sgc161489 typedef	struct usb_descr_item {
684e968bc2Sgc161489 	uint_t	nlen;	/* if it's an byte array, nlen += BYTE_OFFSET */
694e968bc2Sgc161489 	char	*name;	/* descriptor item name */
704e968bc2Sgc161489 } usb_descr_item_t;
714e968bc2Sgc161489 
724e968bc2Sgc161489 /* define the known descriptor items */
734e968bc2Sgc161489 static usb_descr_item_t usb_cfg_descr[] = {
744e968bc2Sgc161489 	{1, "bLength"},
754e968bc2Sgc161489 	{1, "bDescriptorType"},
764e968bc2Sgc161489 	{2, "wTotalLength"},
774e968bc2Sgc161489 	{1, "bNumInterfaces"},
784e968bc2Sgc161489 	{1, "bConfigurationValue"},
794e968bc2Sgc161489 	{1, "iConfiguration"},
804e968bc2Sgc161489 	{1, "bmAttributes"},
814e968bc2Sgc161489 	{1, "bMaxPower"},
824e968bc2Sgc161489 };
834e968bc2Sgc161489 static uint_t usb_cfg_item = 8;
844e968bc2Sgc161489 
854e968bc2Sgc161489 static usb_descr_item_t usb_ia_descr[] = {
864e968bc2Sgc161489 	{1, "bLength"},
874e968bc2Sgc161489 	{1, "bDescriptorType"},
884e968bc2Sgc161489 	{1, "bFirstInterface"},
894e968bc2Sgc161489 	{1, "bInterfaceCount"},
904e968bc2Sgc161489 	{1, "bFunctionClass"},
914e968bc2Sgc161489 	{1, "bFunctionSubClass"},
924e968bc2Sgc161489 	{1, "bFunctionProtocol"},
934e968bc2Sgc161489 	{1, "iFunction"},
944e968bc2Sgc161489 };
954e968bc2Sgc161489 static uint_t usb_ia_item = 8;
964e968bc2Sgc161489 
974e968bc2Sgc161489 static usb_descr_item_t usb_if_descr[] = {
984e968bc2Sgc161489 	{1, "bLength"},
994e968bc2Sgc161489 	{1, "bDescriptorType"},
1004e968bc2Sgc161489 	{1, "bInterfaceNumber"},
1014e968bc2Sgc161489 	{1, "bAlternateSetting"},
1024e968bc2Sgc161489 	{1, "bNumEndpoints"},
1034e968bc2Sgc161489 	{1, "bInterfaceClass"},
1044e968bc2Sgc161489 	{1, "bInterfaceSubClass"},
1054e968bc2Sgc161489 	{1, "bInterfaceProtocol"},
1064e968bc2Sgc161489 	{1, "iInterface"},
1074e968bc2Sgc161489 };
1084e968bc2Sgc161489 static uint_t usb_if_item = 9;
1094e968bc2Sgc161489 
1104e968bc2Sgc161489 static usb_descr_item_t usb_ep_descr[] = {
1114e968bc2Sgc161489 	{1, "bLength"},
1124e968bc2Sgc161489 	{1, "bDescriptorType"},
1134e968bc2Sgc161489 	{1, "bEndpointAddress"},
1144e968bc2Sgc161489 	{1, "bmAttributes"},
1154e968bc2Sgc161489 	{2, "wMaxPacketSize"},
1164e968bc2Sgc161489 	{1, "bInterval"},
1174e968bc2Sgc161489 };
1184e968bc2Sgc161489 static uint_t usb_ep_item = 6;
1194e968bc2Sgc161489 
1204e968bc2Sgc161489 static usb_descr_item_t usb_qlf_descr[] = {
1214e968bc2Sgc161489 	{1, "bLength"},
1224e968bc2Sgc161489 	{1, "bDescriptorType"},
1234e968bc2Sgc161489 	{2, "bcdUSB"},
1244e968bc2Sgc161489 	{1, "bDeviceClass"},
1254e968bc2Sgc161489 	{1, "bDeviceSubClass"},
1264e968bc2Sgc161489 	{1, "bDeviceProtocol"},
1274e968bc2Sgc161489 	{1, "bMaxPacketSize0"},
1284e968bc2Sgc161489 	{1, "bNumConfigurations"},
1294e968bc2Sgc161489 	{1, "bReserved"},
1304e968bc2Sgc161489 };
1314e968bc2Sgc161489 static uint_t usb_qlf_item = 9;
1324e968bc2Sgc161489 
1334e968bc2Sgc161489 static usb_descr_item_t usb_str_descr[] = {
1344e968bc2Sgc161489 	{1, "bLength"},
1354e968bc2Sgc161489 	{1, "bDescriptorType"},
1364e968bc2Sgc161489 	{1, "bString"},
1374e968bc2Sgc161489 };
1384e968bc2Sgc161489 static uint_t usb_str_item = 3;
1394e968bc2Sgc161489 
140*ff0e937bSRaymond Chen static usb_descr_item_t usb_wa_descr[] = {
141*ff0e937bSRaymond Chen 	{1, "bLength"},
142*ff0e937bSRaymond Chen 	{1, "bDescriptorType"},
143*ff0e937bSRaymond Chen 	{2, "bcdWAVersion"},
144*ff0e937bSRaymond Chen 	{1, "bNumPorts"},
145*ff0e937bSRaymond Chen 	{1, "bmAttributes"},
146*ff0e937bSRaymond Chen 	{2, "wNumRPipes"},
147*ff0e937bSRaymond Chen 	{2, "wRPipeMaxBlock"},
148*ff0e937bSRaymond Chen 	{1, "bRPipeBlockSize"},
149*ff0e937bSRaymond Chen 	{1, "bPwrOn2PwrGood"},
150*ff0e937bSRaymond Chen 	{1, "bNumMMCIEs"},
151*ff0e937bSRaymond Chen 	{1, "DeviceRemovable"},
152*ff0e937bSRaymond Chen };
153*ff0e937bSRaymond Chen 
154*ff0e937bSRaymond Chen static uint_t usb_wa_item = 11;
155*ff0e937bSRaymond Chen 
1564e968bc2Sgc161489 static usb_descr_item_t usb_hid_descr[] = {
1574e968bc2Sgc161489 	{1, "bLength"},
1584e968bc2Sgc161489 	{1, "bDescriptorType"},
1594e968bc2Sgc161489 	{2, "bcdHID"},
1604e968bc2Sgc161489 	{1, "bCountryCode"},
1614e968bc2Sgc161489 	{1, "bNumDescriptors"},
1624e968bc2Sgc161489 	{1, "bReportDescriptorType"},
1634e968bc2Sgc161489 	{2, "wReportDescriptorLength"},
1644e968bc2Sgc161489 };
1654e968bc2Sgc161489 static uint_t usb_hid_item = 7;
1664e968bc2Sgc161489 
1674e968bc2Sgc161489 static usb_descr_item_t usb_ac_header_descr[] = {
1684e968bc2Sgc161489 	{1, "bLength"},
1694e968bc2Sgc161489 	{1, "bDescriptorType"},
1704e968bc2Sgc161489 	{1, "bDescriptorSubType"},
1714e968bc2Sgc161489 	{2, "bcdADC"},
1724e968bc2Sgc161489 	{2, "wTotalLength"},
1734e968bc2Sgc161489 	{1, "blnCollection"},
1744e968bc2Sgc161489 	{1, "baInterfaceNr"},
1754e968bc2Sgc161489 };
1764e968bc2Sgc161489 static uint_t usb_ac_header_item = 7;
1774e968bc2Sgc161489 
1784e968bc2Sgc161489 static usb_descr_item_t usb_ac_input_term_descr[] = {
1794e968bc2Sgc161489 	{1, "bLength"},
1804e968bc2Sgc161489 	{1, "bDescriptorType"},
1814e968bc2Sgc161489 	{1, "bDescriptorSubType"},
1824e968bc2Sgc161489 	{1, "bTerminalID"},
1834e968bc2Sgc161489 	{2, "wTerminalType"},
1844e968bc2Sgc161489 	{1, "bAssocTerminal"},
1854e968bc2Sgc161489 	{1, "bNrChannels"},
1864e968bc2Sgc161489 	{2, "wChannelConfig"},
1874e968bc2Sgc161489 	{1, "iChannelNames"},
1884e968bc2Sgc161489 	{1, "iTerminal"},
1894e968bc2Sgc161489 };
1904e968bc2Sgc161489 static uint_t usb_ac_input_term_item = 10;
1914e968bc2Sgc161489 
1924e968bc2Sgc161489 static usb_descr_item_t usb_ac_output_term_descr[] = {
1934e968bc2Sgc161489 	{1, "bLength"},
1944e968bc2Sgc161489 	{1, "bDescriptorType"},
1954e968bc2Sgc161489 	{1, "bDescriptorSubType"},
1964e968bc2Sgc161489 	{1, "bTerminalID"},
1974e968bc2Sgc161489 	{2, "wTerminalType"},
1984e968bc2Sgc161489 	{1, "bAssocTerminal"},
1994e968bc2Sgc161489 	{1, "bSourceID"},
2004e968bc2Sgc161489 	{1, "iTerminal"},
2014e968bc2Sgc161489 };
2024e968bc2Sgc161489 static uint_t usb_ac_output_term_item = 8;
2034e968bc2Sgc161489 
2044e968bc2Sgc161489 static usb_descr_item_t usb_ac_mixer_descr[] = {
2054e968bc2Sgc161489 	{1, "bLength"},
2064e968bc2Sgc161489 	{1, "bDescriptorType"},
2074e968bc2Sgc161489 	{1, "bDescriptorSubType"},
2084e968bc2Sgc161489 	{1, "bUnitID"},
2094e968bc2Sgc161489 	{1, "bNrInPins"},
2104e968bc2Sgc161489 	{1, "baSourceID"},
2114e968bc2Sgc161489 };
2124e968bc2Sgc161489 static uint_t usb_ac_mixer_item = 6;
2134e968bc2Sgc161489 
2144e968bc2Sgc161489 static usb_descr_item_t usb_ac_selector_descr[] = {
2154e968bc2Sgc161489 	{1, "bLength"},
2164e968bc2Sgc161489 	{1, "bDescriptorType"},
2174e968bc2Sgc161489 	{1, "bDescriptorSubType"},
2184e968bc2Sgc161489 	{1, "bUnitID"},
2194e968bc2Sgc161489 	{1, "bNrInPins"},
2204e968bc2Sgc161489 	{1, "baSourceID"},
2214e968bc2Sgc161489 };
2224e968bc2Sgc161489 static uint_t usb_ac_selector_item = 6;
2234e968bc2Sgc161489 
2244e968bc2Sgc161489 static usb_descr_item_t usb_ac_feature_descr[] = {
2254e968bc2Sgc161489 	{1, "bLength"},
2264e968bc2Sgc161489 	{1, "bDescriptorType"},
2274e968bc2Sgc161489 	{1, "bDescriptorSubType"},
2284e968bc2Sgc161489 	{1, "bUnitID"},
2294e968bc2Sgc161489 	{1, "bSourceID"},
2304e968bc2Sgc161489 	{1, "bControlSize"},
2314e968bc2Sgc161489 	{1, "bmaControls"},
2324e968bc2Sgc161489 };
2334e968bc2Sgc161489 static uint_t usb_ac_feature_item = 7;
2344e968bc2Sgc161489 
2354e968bc2Sgc161489 static usb_descr_item_t usb_ac_processing_descr[] = {
2364e968bc2Sgc161489 	{1, "bLength"},
2374e968bc2Sgc161489 	{1, "bDescriptorType"},
2384e968bc2Sgc161489 	{1, "bDescriptorSubType"},
2394e968bc2Sgc161489 	{1, "bUnitID"},
2404e968bc2Sgc161489 	{1, "wProcessType"},
2414e968bc2Sgc161489 	{1, "bNrInPins"},
2424e968bc2Sgc161489 	{1, "baSourceID"},
2434e968bc2Sgc161489 };
2444e968bc2Sgc161489 static uint_t usb_ac_processing_item = 7;
2454e968bc2Sgc161489 
2464e968bc2Sgc161489 static usb_descr_item_t usb_ac_extension_descr[] = {
2474e968bc2Sgc161489 	{1, "bLength"},
2484e968bc2Sgc161489 	{1, "bDescriptorType"},
2494e968bc2Sgc161489 	{1, "bDescriptorSubType"},
2504e968bc2Sgc161489 	{1, "wExtensionCode"},
2514e968bc2Sgc161489 	{1, "bUnitID"},
2524e968bc2Sgc161489 	{1, "bNrInPins"},
2534e968bc2Sgc161489 	{1, "baSourceID"},
2544e968bc2Sgc161489 };
2554e968bc2Sgc161489 static uint_t usb_ac_extension_item = 7;
2564e968bc2Sgc161489 
2574e968bc2Sgc161489 static usb_descr_item_t usb_as_ep_descr[] = {
2584e968bc2Sgc161489 	{1, "blength"},
2594e968bc2Sgc161489 	{1, "bDescriptorType"},
2604e968bc2Sgc161489 	{1, "bDescriptorSubType"},
2614e968bc2Sgc161489 	{1, "bmAttributes"},
2624e968bc2Sgc161489 	{1, "bLockDelayUnits"},
2634e968bc2Sgc161489 	{2, "wLockDelay"},
2644e968bc2Sgc161489 };
2654e968bc2Sgc161489 static uint_t usb_as_ep_item = 6;
2664e968bc2Sgc161489 
2674e968bc2Sgc161489 static usb_descr_item_t usb_as_if_descr[] = {
2684e968bc2Sgc161489 	{1, "blength"},
2694e968bc2Sgc161489 	{1, "bDescriptorType"},
2704e968bc2Sgc161489 	{1, "bDescriptorSubType"},
2714e968bc2Sgc161489 	{1, "bTerminalLink"},
2724e968bc2Sgc161489 	{1, "bDelay"},
2734e968bc2Sgc161489 	{2, "wFormatTag"},
2744e968bc2Sgc161489 };
2754e968bc2Sgc161489 static uint_t usb_as_if_item = 6;
2764e968bc2Sgc161489 
2774e968bc2Sgc161489 static usb_descr_item_t usb_as_format_descr[] = {
2784e968bc2Sgc161489 	{1, "blength"},
2794e968bc2Sgc161489 	{1, "bDescriptorType"},
2804e968bc2Sgc161489 	{1, "bDescriptorSubType"},
2814e968bc2Sgc161489 	{1, "bFormatType"},
2824e968bc2Sgc161489 	{1, "bNrChannels"},
2834e968bc2Sgc161489 	{1, "bSubFrameSize"},
2844e968bc2Sgc161489 	{1, "bBitResolution"},
2854e968bc2Sgc161489 	{1, "bSamFreqType"},
2864e968bc2Sgc161489 	{1, "bSamFreqs"},
2874e968bc2Sgc161489 };
2884e968bc2Sgc161489 static uint_t usb_as_format_item = 9;
2894e968bc2Sgc161489 
2904e968bc2Sgc161489 static usb_descr_item_t usb_vc_header_descr[] = {
2914e968bc2Sgc161489 	{1, "bLength"},
2924e968bc2Sgc161489 	{1, "bDescriptorType"},
2934e968bc2Sgc161489 	{1, "bDescriptorSubtype"},
2944e968bc2Sgc161489 	{2, "bcdUVC"},
2954e968bc2Sgc161489 	{2, "wTotalLength"},
2964e968bc2Sgc161489 	{4, "dwClockFrequency"},
2974e968bc2Sgc161489 	{1, "bInCollection"},
2984e968bc2Sgc161489 };
2994e968bc2Sgc161489 static uint_t usb_vc_header_item = 7;
3004e968bc2Sgc161489 
3014e968bc2Sgc161489 static usb_descr_item_t usb_vc_input_term_descr[] = {
3024e968bc2Sgc161489 	{1, "bLength"},
3034e968bc2Sgc161489 	{1, "bDescriptorType"},
3044e968bc2Sgc161489 	{1, "bDescriptorSubType"},
3054e968bc2Sgc161489 	{1, "bTerminalID"},
3064e968bc2Sgc161489 	{2, "wTerminalType"},
3074e968bc2Sgc161489 	{1, "AssocTerminal"},
3084e968bc2Sgc161489 	{1, "iTerminal"},
3094e968bc2Sgc161489 };
3104e968bc2Sgc161489 static uint_t usb_vc_input_term_item = 7;
3114e968bc2Sgc161489 
3124e968bc2Sgc161489 static usb_descr_item_t usb_vc_output_term_descr[] = {
3134e968bc2Sgc161489 	{1, "bLength"},
3144e968bc2Sgc161489 	{1, "bDescriptorType"},
3154e968bc2Sgc161489 	{1, "bDescriptorSubType"},
3164e968bc2Sgc161489 	{1, "bTerminalID"},
3174e968bc2Sgc161489 	{2, "wTerminalType"},
3184e968bc2Sgc161489 	{1, "AssocTerminal"},
3194e968bc2Sgc161489 	{1, "bSourceID"},
3204e968bc2Sgc161489 	{1, "iTerminal"},
3214e968bc2Sgc161489 };
3224e968bc2Sgc161489 static uint_t usb_vc_output_term_item = 8;
3234e968bc2Sgc161489 
3244e968bc2Sgc161489 static usb_descr_item_t usb_vc_processing_descr[] = {
3254e968bc2Sgc161489 	{1, "bLength"},
3264e968bc2Sgc161489 	{1, "bDescriptorType"},
3274e968bc2Sgc161489 	{1, "bDescriptorSubType"},
3284e968bc2Sgc161489 	{1, "bUnitID"},
3294e968bc2Sgc161489 	{1, "bSourceID"},
3304e968bc2Sgc161489 	{2, "wMaxMultiplier"},
3314e968bc2Sgc161489 	{1, "bControlSize"},
3324e968bc2Sgc161489 	{1, "bmControls"},
3334e968bc2Sgc161489 };
3344e968bc2Sgc161489 static uint_t usb_vc_processing_item = 8;
3354e968bc2Sgc161489 
3364e968bc2Sgc161489 static usb_descr_item_t usb_vc_selector_descr[] = {
3374e968bc2Sgc161489 	{1, "bLength"},
3384e968bc2Sgc161489 	{1, "bDescriptorType"},
3394e968bc2Sgc161489 	{1, "bDescriptorSubType"},
3404e968bc2Sgc161489 	{1, "bUnitID"},
3414e968bc2Sgc161489 	{1, "bNrInPins"},
3424e968bc2Sgc161489 };
3434e968bc2Sgc161489 static uint_t usb_vc_selector_item = 5;
3444e968bc2Sgc161489 
3454e968bc2Sgc161489 static usb_descr_item_t usb_vc_extension_descr[] = {
3464e968bc2Sgc161489 	{1, "bLength"},
3474e968bc2Sgc161489 	{1, "bDescriptorType"},
3484e968bc2Sgc161489 	{1, "bDescriptorSubType"},
3494e968bc2Sgc161489 	{1, "bUnitID"},
3504e968bc2Sgc161489 	{16 + BYTE_OFFSET, "guidExtensionCode[16]"},
3514e968bc2Sgc161489 	{1, "bNumControls"},
3524e968bc2Sgc161489 	{1, "bNrInPins"},
3534e968bc2Sgc161489 };
3544e968bc2Sgc161489 static uint_t usb_vc_extension_item = 7;
3554e968bc2Sgc161489 
3564e968bc2Sgc161489 static usb_descr_item_t usb_vs_input_header_descr[] = {
3574e968bc2Sgc161489 	{1, "bLength"},
3584e968bc2Sgc161489 	{1, "bDescriptorType"},
3594e968bc2Sgc161489 	{1, "bDescriptorSubType"},
3604e968bc2Sgc161489 	{1, "bNumFormats"},
3614e968bc2Sgc161489 	{2, "wTotalLength"},
3624e968bc2Sgc161489 	{1, "bEndpointAddress"},
3634e968bc2Sgc161489 	{1, "bmInfo"},
3644e968bc2Sgc161489 	{1, "bTerminalLink"},
3654e968bc2Sgc161489 	{1, "bStillCaptureMethod"},
3664e968bc2Sgc161489 	{1, "bTriggerSupport"},
3674e968bc2Sgc161489 	{1, "bTriggerUsage"},
3684e968bc2Sgc161489 	{1, "bControlSize"},
3694e968bc2Sgc161489 	{1, "bmaControls"},
3704e968bc2Sgc161489 };
3714e968bc2Sgc161489 static uint_t usb_vs_input_header_item = 13;
3724e968bc2Sgc161489 
3734e968bc2Sgc161489 static usb_descr_item_t usb_vs_output_header_descr[] = {
3744e968bc2Sgc161489 	{1, "bLength"},
3754e968bc2Sgc161489 	{1, "bDescriptorType"},
3764e968bc2Sgc161489 	{1, "bDescriptorSubType"},
3774e968bc2Sgc161489 	{1, "bNumFormats"},
3784e968bc2Sgc161489 	{2, "wTotalLength"},
3794e968bc2Sgc161489 	{1, "bEndpointAddress"},
3804e968bc2Sgc161489 	{1, "bTerminalLink"},
3814e968bc2Sgc161489 	{1, "bControlSize"},
3824e968bc2Sgc161489 	{1, "bmaControls"},
3834e968bc2Sgc161489 };
3844e968bc2Sgc161489 static uint_t usb_vs_output_header_item = 9;
3854e968bc2Sgc161489 
3864e968bc2Sgc161489 static usb_descr_item_t usb_vs_still_image_descr[] = {
3874e968bc2Sgc161489 	{1, "bLength"},
3884e968bc2Sgc161489 	{1, "bDescriptorType"},
3894e968bc2Sgc161489 	{1, "bDescriptorSubType"},
3904e968bc2Sgc161489 	{1, "bEndpointAddress"},
3914e968bc2Sgc161489 	{1, "bNumImageSizePatterns"},
3924e968bc2Sgc161489 	{2, "wWidth"},
3934e968bc2Sgc161489 	{2, "wHeight"},
3944e968bc2Sgc161489 };
3954e968bc2Sgc161489 static uint_t usb_vs_still_image_item = 7;
3964e968bc2Sgc161489 
3974e968bc2Sgc161489 static usb_descr_item_t usb_vs_color_matching_descr[] = {
3984e968bc2Sgc161489 	{1, "bLength"},
3994e968bc2Sgc161489 	{1, "bDescriptorType"},
4004e968bc2Sgc161489 	{1, "bDescriptorSubtype"},
4014e968bc2Sgc161489 	{1, "bColorPrimaries"},
4024e968bc2Sgc161489 	{1, "bTransferCharacteristics"},
4034e968bc2Sgc161489 	{1, "bMatrixCoefficients"},
4044e968bc2Sgc161489 };
4054e968bc2Sgc161489 static uint_t usb_vs_color_matching_item = 6;
4064e968bc2Sgc161489 
4074e968bc2Sgc161489 static usb_descr_item_t usb_vs_2frame_descr[] = {
4084e968bc2Sgc161489 	{1, "bLength"},
4094e968bc2Sgc161489 	{1, "bDescriptorType"},
4104e968bc2Sgc161489 	{1, "bDescriptorSubType"},
4114e968bc2Sgc161489 	{1, "bFrameIndex"},
4124e968bc2Sgc161489 	{1, "bmCapabilities"},
4134e968bc2Sgc161489 	{2, "wWidth"},
4144e968bc2Sgc161489 	{2, "wHeight"},
4154e968bc2Sgc161489 	{4, "dwMinBitRate"},
4164e968bc2Sgc161489 	{4, "dwMaxBitRate"},
4174e968bc2Sgc161489 	{4, "dwMaxVideoFrameBufferSize"},
4184e968bc2Sgc161489 	{4, "dwDefaultFrameInterval"},
4194e968bc2Sgc161489 	{1, "bFrameIntervalType"},
4204e968bc2Sgc161489 };
4214e968bc2Sgc161489 static uint_t usb_vs_2frame_item = 12;
4224e968bc2Sgc161489 
4234e968bc2Sgc161489 static usb_descr_item_t usb_vs_format_mjpeg_descr[] = {
4244e968bc2Sgc161489 	{1, "bLength"},
4254e968bc2Sgc161489 	{1, "bDescriptorType"},
4264e968bc2Sgc161489 	{1, "bDescriptorSubType"},
4274e968bc2Sgc161489 	{1, "bFormatIndex"},
4284e968bc2Sgc161489 	{1, "bNumFrameDescriptors"},
4294e968bc2Sgc161489 	{1, "bmFlags"},
4304e968bc2Sgc161489 	{1, "bDefaultFrameIndex"},
4314e968bc2Sgc161489 	{1, "bAspectRatioX"},
4324e968bc2Sgc161489 	{1, "bAspectRatioY"},
4334e968bc2Sgc161489 	{1, "bmInterlaceFlags"},
4344e968bc2Sgc161489 	{1, "bCopyProtect"},
4354e968bc2Sgc161489 };
4364e968bc2Sgc161489 static uint_t usb_vs_format_mjpeg_item = 11;
4374e968bc2Sgc161489 
4384e968bc2Sgc161489 static usb_descr_item_t usb_vs_format_uncps_descr[] = {
4394e968bc2Sgc161489 	{1, "bLength"},
4404e968bc2Sgc161489 	{1, "bDescriptorType"},
4414e968bc2Sgc161489 	{1, "bDescriptorSubType"},
4424e968bc2Sgc161489 	{1, "bFormatIndex"},
4434e968bc2Sgc161489 	{1, "bNumFrameDescriptors"},
4444e968bc2Sgc161489 	{16 + BYTE_OFFSET, "guidFormat[16]"},
4454e968bc2Sgc161489 	{1, "bBitsPerPixel"},
4464e968bc2Sgc161489 	{1, "bDefaultFrameIndex"},
4474e968bc2Sgc161489 	{1, "bAspectRatioX"},
4484e968bc2Sgc161489 	{1, "bAspectRatioY"},
4494e968bc2Sgc161489 	{1, "bmInterlaceFlags"},
4504e968bc2Sgc161489 	{1, "bCopyProtect"},
4514e968bc2Sgc161489 };
4524e968bc2Sgc161489 static uint_t usb_vs_format_uncps_item = 12;
4534e968bc2Sgc161489 
4544e968bc2Sgc161489 static usb_descr_item_t usb_vs_format_mp2ts_descr[] = {
4554e968bc2Sgc161489 	{1, "bLength"},
4564e968bc2Sgc161489 	{1, "bDescriptorType"},
4574e968bc2Sgc161489 	{1, "bDescriptorSubType"},
4584e968bc2Sgc161489 	{1, "bFormatIndex"},
4594e968bc2Sgc161489 	{1, "bDataOffset"},
4604e968bc2Sgc161489 	{1, "bPacketLength"},
4614e968bc2Sgc161489 	{1, "bStrideLength"},
4624e968bc2Sgc161489 	{16 + BYTE_OFFSET, "guidStrideFormat[16]"},
4634e968bc2Sgc161489 };
4644e968bc2Sgc161489 static uint_t usb_vs_format_mp2ts_item = 8;
4654e968bc2Sgc161489 
4664e968bc2Sgc161489 static usb_descr_item_t usb_vs_format_dv_descr[] = {
4674e968bc2Sgc161489 	{1, "bLength"},
4684e968bc2Sgc161489 	{1, "bDescriptorType"},
4694e968bc2Sgc161489 	{1, "bDescriptorSubType"},
4704e968bc2Sgc161489 	{1, "bFormatIndex"},
4714e968bc2Sgc161489 	{4, "dwMaxVideoFrameBufferSize"},
4724e968bc2Sgc161489 	{1, "bFormatType"},
4734e968bc2Sgc161489 };
4744e968bc2Sgc161489 static uint_t usb_vs_format_dv_item = 6;
4754e968bc2Sgc161489 
4764e968bc2Sgc161489 
4774e968bc2Sgc161489 /* ****************************************************************** */
4784e968bc2Sgc161489 
4794e968bc2Sgc161489 typedef struct hci_state {
4804e968bc2Sgc161489 	void			*hci_dip;
4814e968bc2Sgc161489 	uint_t			hci_instance;
4824e968bc2Sgc161489 	void			*hci_hcdi_ops;
4834e968bc2Sgc161489 	uint_t			hci_flags;
4844e968bc2Sgc161489 	uint16_t		vendor_id;
4854e968bc2Sgc161489 	uint16_t		device_id;
4864e968bc2Sgc161489 } hci_state_t;
4874e968bc2Sgc161489 
4884e968bc2Sgc161489 static int prt_usb_tree(uintptr_t paddr, uint_t flag);
4894e968bc2Sgc161489 
4904e968bc2Sgc161489 static int prt_usb_tree_node(uintptr_t paddr);
4914e968bc2Sgc161489 
4924e968bc2Sgc161489 static void prt_usb_hid_item(uintptr_t paddr);
4934e968bc2Sgc161489 
4944e968bc2Sgc161489 static void prt_usb_hid_item_params(entity_item_t *item);
4954e968bc2Sgc161489 
4964e968bc2Sgc161489 static void prt_usb_hid_item_attrs(uintptr_t paddr);
4974e968bc2Sgc161489 
4984e968bc2Sgc161489 static void prt_usb_hid_item_tags(uint_t tag);
4994e968bc2Sgc161489 
5004e968bc2Sgc161489 static void prt_usb_hid_item_data(uintptr_t paddr, uint_t len);
5014e968bc2Sgc161489 
5024e968bc2Sgc161489 static int prt_usb_desc(uintptr_t usb_cfg, uint_t cfg_len);
5034e968bc2Sgc161489 
5044e968bc2Sgc161489 static int prt_usb_ac_desc(uintptr_t paddr, uint_t nlen);
5054e968bc2Sgc161489 
5064e968bc2Sgc161489 static int prt_usb_as_desc(uintptr_t paddr, uint_t nlen);
5074e968bc2Sgc161489 
5084e968bc2Sgc161489 static int prt_usb_vc_desc(uintptr_t paddr, uint_t nlen);
5094e968bc2Sgc161489 
5104e968bc2Sgc161489 static int prt_usb_vs_desc(uintptr_t paddr, uint_t nlen);
5114e968bc2Sgc161489 
5124e968bc2Sgc161489 static int print_descr(uintptr_t, uint_t, usb_descr_item_t *, uint_t);
5134e968bc2Sgc161489 
5144e968bc2Sgc161489 static int print_struct(uintptr_t, uint_t, mdb_arg_t *);
5154e968bc2Sgc161489 
5164e968bc2Sgc161489 static int prt_usb_buf(uintptr_t, uint_t);
5174e968bc2Sgc161489 
5184e968bc2Sgc161489 
5194e968bc2Sgc161489 /* ****************************************************************** */
5204e968bc2Sgc161489 
5214e968bc2Sgc161489 /* exported functions */
5224e968bc2Sgc161489 
5234e968bc2Sgc161489 void prt_usb_usage(void);
5244e968bc2Sgc161489 
5254e968bc2Sgc161489 int prtusb(uintptr_t, uint_t, int, const mdb_arg_t *);
5264e968bc2Sgc161489 
5274e968bc2Sgc161489 /* ****************************************************************** */
5284e968bc2Sgc161489 
5294e968bc2Sgc161489 /* help of prtusb */
5304e968bc2Sgc161489 void
prt_usb_usage(void)5314e968bc2Sgc161489 prt_usb_usage(void)
5324e968bc2Sgc161489 {
5334e968bc2Sgc161489 	mdb_printf("%-8s : %s\n", "-v", "print all descriptors");
5344e968bc2Sgc161489 	mdb_printf("%-8s : %s\n", "-t", "print device trees");
535eae66f16Sgc161489 	mdb_printf("%-8s : %s\n", "-i index", "print the device by index");
5364e968bc2Sgc161489 }
5374e968bc2Sgc161489 
5384e968bc2Sgc161489 /* the entry of ::prtusb */
5394e968bc2Sgc161489 int
prtusb(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)5404e968bc2Sgc161489 prtusb(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
5414e968bc2Sgc161489 {
5424e968bc2Sgc161489 	static int count = 1;
5434e968bc2Sgc161489 	uint64_t sel_num = 0;
5444e968bc2Sgc161489 	uint_t usb_flag = 0;
5454e968bc2Sgc161489 	usba_device_t usb_dev;
5464e968bc2Sgc161489 	usb_dev_descr_t dev_desc;
5474e968bc2Sgc161489 	struct dev_info usb_dip;
5484e968bc2Sgc161489 	char strbuf[STRLEN];
5494e968bc2Sgc161489 
5504e968bc2Sgc161489 	/* print all usba devices if no address assigned */
5514e968bc2Sgc161489 	if (!(flags & DCMD_ADDRSPEC)) {
5524e968bc2Sgc161489 		if (mdb_walk_dcmd("usba_device", "prtusb", argc, argv) == -1) {
5534e968bc2Sgc161489 			mdb_warn("failed to walk usba_device");
5544e968bc2Sgc161489 
5554e968bc2Sgc161489 			return (DCMD_ERR);
5564e968bc2Sgc161489 		}
5574e968bc2Sgc161489 
5584e968bc2Sgc161489 		return (DCMD_OK);
5594e968bc2Sgc161489 	}
5604e968bc2Sgc161489 
5614e968bc2Sgc161489 	/* for the first device, print head */
5624e968bc2Sgc161489 	if (DCMD_HDRSPEC(flags)) {
5634e968bc2Sgc161489 		count = 1;
564eae66f16Sgc161489 		mdb_printf("%<u>%-8s%-12s%-6s%-16s%-12s%-20s%</u>\n",
565eae66f16Sgc161489 		    "INDEX", "DRIVER", "INST", "NODE", "VID.PID", "PRODUCT");
5664e968bc2Sgc161489 	}
5674e968bc2Sgc161489 
5684e968bc2Sgc161489 	if (mdb_getopts(argc, argv,
5694e968bc2Sgc161489 	    'i', MDB_OPT_UINT64, &sel_num,
5704e968bc2Sgc161489 	    't', MDB_OPT_SETBITS, OPT_TREE, &usb_flag,
5714e968bc2Sgc161489 	    'v', MDB_OPT_SETBITS, OPT_VERB, &usb_flag, NULL) != argc) {
5724e968bc2Sgc161489 
5734e968bc2Sgc161489 		return (DCMD_USAGE);
5744e968bc2Sgc161489 	}
5754e968bc2Sgc161489 
5764e968bc2Sgc161489 	if (mdb_vread(&usb_dev, sizeof (usba_device_t), addr) == -1) {
5774e968bc2Sgc161489 		mdb_warn("Failed to read usba_device!\n");
5784e968bc2Sgc161489 
5794e968bc2Sgc161489 		return (DCMD_ERR);
5804e968bc2Sgc161489 	}
5814e968bc2Sgc161489 
5824e968bc2Sgc161489 	if (mdb_vread(&usb_dip, sizeof (struct dev_info),
5834e968bc2Sgc161489 	    (uintptr_t)usb_dev.usb_dip) == -1) {
5844e968bc2Sgc161489 		mdb_warn("Failed to read dev_info!\n");
5854e968bc2Sgc161489 
5864e968bc2Sgc161489 		return (DCMD_ERR);
5874e968bc2Sgc161489 	}
5884e968bc2Sgc161489 
5894e968bc2Sgc161489 	/* process the "-i" */
5904e968bc2Sgc161489 	if (sel_num && sel_num != count) {
5914e968bc2Sgc161489 		count++;
5924e968bc2Sgc161489 
5934e968bc2Sgc161489 		return (DCMD_OK);
5944e968bc2Sgc161489 	}
5954e968bc2Sgc161489 
596eae66f16Sgc161489 	/* index number of device node  */
597eae66f16Sgc161489 	mdb_printf("%-8x", count++);
5984e968bc2Sgc161489 
5994e968bc2Sgc161489 	/* driver and instance */
6004e968bc2Sgc161489 	mdb_devinfo2driver((uintptr_t)usb_dev.usb_dip, strbuf, STRLEN);
6014e968bc2Sgc161489 	mdb_printf("%-12s%-6d", strbuf, usb_dip.devi_instance);
6024e968bc2Sgc161489 
6034e968bc2Sgc161489 	/* node name */
6044e968bc2Sgc161489 	if (mdb_readstr(strbuf, STRLEN,
6054e968bc2Sgc161489 	    (uintptr_t)usb_dip.devi_node_name) != -1) {
6064e968bc2Sgc161489 
6074e968bc2Sgc161489 		mdb_printf("%-16s", strbuf);
6084e968bc2Sgc161489 	} else {
6094e968bc2Sgc161489 
6104e968bc2Sgc161489 		mdb_printf("%-16s", "No Node Name");
6114e968bc2Sgc161489 	}
6124e968bc2Sgc161489 
6134e968bc2Sgc161489 	/* vid.pid */
6144e968bc2Sgc161489 	if (mdb_vread(&dev_desc, sizeof (usb_dev_descr_t),
6154e968bc2Sgc161489 	    (uintptr_t)usb_dev.usb_dev_descr) != -1) {
6164e968bc2Sgc161489 
6174e968bc2Sgc161489 		mdb_printf("%04x.%04x   ",
6184e968bc2Sgc161489 		    dev_desc.idVendor, dev_desc.idProduct);
6194e968bc2Sgc161489 	}
6204e968bc2Sgc161489 
6214e968bc2Sgc161489 	/* product string */
6224e968bc2Sgc161489 	if (mdb_readstr(strbuf, STRLEN,
6234e968bc2Sgc161489 	    (uintptr_t)usb_dev.usb_product_str) != -1) {
6244e968bc2Sgc161489 
6254e968bc2Sgc161489 		mdb_printf("%s\n", strbuf);
6264e968bc2Sgc161489 	} else {
6274e968bc2Sgc161489 
6284e968bc2Sgc161489 		mdb_printf("%s\n", "No Product String");
6294e968bc2Sgc161489 	}
6304e968bc2Sgc161489 
6314e968bc2Sgc161489 	/* tree, print usb device tree info */
6324e968bc2Sgc161489 	if (usb_flag & OPT_TREE) {
6334e968bc2Sgc161489 
6344e968bc2Sgc161489 		mdb_printf("\nusba_device: 0x%x\n", addr);
6354e968bc2Sgc161489 
6364e968bc2Sgc161489 		mdb_printf("mfg_prod_sn: ");
6374e968bc2Sgc161489 		if (mdb_readstr(strbuf, STRLEN,
6384e968bc2Sgc161489 		    (uintptr_t)usb_dev.usb_mfg_str) != -1) {
6394e968bc2Sgc161489 			mdb_printf("%s - ", strbuf);
6404e968bc2Sgc161489 		} else {
6414e968bc2Sgc161489 			mdb_printf("NULL - ");
6424e968bc2Sgc161489 		}
6434e968bc2Sgc161489 		if (mdb_readstr(strbuf, STRLEN,
6444e968bc2Sgc161489 		    (uintptr_t)usb_dev.usb_product_str) != -1) {
6454e968bc2Sgc161489 			mdb_printf("%s - ", strbuf);
6464e968bc2Sgc161489 		} else {
6474e968bc2Sgc161489 			mdb_printf("NULL -");
6484e968bc2Sgc161489 		}
6494e968bc2Sgc161489 		if (mdb_readstr(strbuf, STRLEN,
6504e968bc2Sgc161489 		    (uintptr_t)usb_dev.usb_serialno_str) != -1) {
6514e968bc2Sgc161489 			mdb_printf("%s", strbuf);
6524e968bc2Sgc161489 		} else {
6534e968bc2Sgc161489 			mdb_printf("NULL");
6544e968bc2Sgc161489 		}
6554e968bc2Sgc161489 
6564e968bc2Sgc161489 		mdb_printf("\n\n");
6574e968bc2Sgc161489 		prt_usb_tree((uintptr_t)usb_dev.usb_dip, 0);
6584e968bc2Sgc161489 	}
6594e968bc2Sgc161489 
6604e968bc2Sgc161489 	/* verbose, print all descriptors */
6614e968bc2Sgc161489 	if (usb_flag & OPT_VERB) {
6624e968bc2Sgc161489 		int i;
6634e968bc2Sgc161489 		uintptr_t cfg_buf;
6644e968bc2Sgc161489 		uint16_t cfg_len;
6654e968bc2Sgc161489 
6664e968bc2Sgc161489 		mdb_printf("\n");
6674e968bc2Sgc161489 
6684e968bc2Sgc161489 		/* device descriptor */
6694e968bc2Sgc161489 		prt_usb_desc((uintptr_t)usb_dev.usb_dev_descr, 18);
6704e968bc2Sgc161489 
6714e968bc2Sgc161489 		/* config cloud descriptors */
6724e968bc2Sgc161489 		if (usb_dev.usb_n_cfgs == 1) {
6734e968bc2Sgc161489 			mdb_inc_indent(4);
6744e968bc2Sgc161489 			mdb_printf("-- Active Config Index 0\n");
6754e968bc2Sgc161489 			mdb_dec_indent(4);
6764e968bc2Sgc161489 			prt_usb_desc((uintptr_t)usb_dev.usb_cfg,
6774e968bc2Sgc161489 			    usb_dev.usb_cfg_length);
6784e968bc2Sgc161489 		} else {
6794e968bc2Sgc161489 			/* multiple configs */
6804e968bc2Sgc161489 			for (i = 0; i < usb_dev.usb_n_cfgs; i++) {
6814e968bc2Sgc161489 
6824e968bc2Sgc161489 				if ((mdb_vread(&cfg_len, sizeof (uint16_t),
6834e968bc2Sgc161489 				    (uintptr_t)(usb_dev.usb_cfg_array_len + i))
6844e968bc2Sgc161489 				    != -1) &&
6854e968bc2Sgc161489 				    (mdb_vread(&cfg_buf, sizeof (uintptr_t),
6864e968bc2Sgc161489 				    (uintptr_t)(usb_dev.usb_cfg_array + i))
6874e968bc2Sgc161489 				    != -1)) {
6884e968bc2Sgc161489 					mdb_inc_indent(4);
6894e968bc2Sgc161489 					if (cfg_buf ==
6904e968bc2Sgc161489 					    (uintptr_t)usb_dev.usb_cfg) {
6914e968bc2Sgc161489 						mdb_printf("-- Active Config"
6924e968bc2Sgc161489 						    " Index %x\n", i);
6934e968bc2Sgc161489 					} else {
6944e968bc2Sgc161489 						mdb_printf("-- Inactive Config"
6954e968bc2Sgc161489 						    " Index %x\n", i);
6964e968bc2Sgc161489 					}
6974e968bc2Sgc161489 					mdb_dec_indent(4);
6984e968bc2Sgc161489 
6994e968bc2Sgc161489 					prt_usb_desc(cfg_buf, cfg_len);
7004e968bc2Sgc161489 				}
7014e968bc2Sgc161489 			}
7024e968bc2Sgc161489 		}
7034e968bc2Sgc161489 	}
7044e968bc2Sgc161489 
7054e968bc2Sgc161489 	if (usb_flag) {
7064e968bc2Sgc161489 
7074e968bc2Sgc161489 		mdb_printf("%<u>%-72s%</u>\n", " ");
7084e968bc2Sgc161489 	}
7094e968bc2Sgc161489 
7104e968bc2Sgc161489 	return (DCMD_OK);
7114e968bc2Sgc161489 }
7124e968bc2Sgc161489 
7134e968bc2Sgc161489 /* print the info required by "-t" */
7144e968bc2Sgc161489 static int
prt_usb_tree(uintptr_t paddr,uint_t flag)7154e968bc2Sgc161489 prt_usb_tree(uintptr_t paddr, uint_t flag)
7164e968bc2Sgc161489 {
7174e968bc2Sgc161489 	struct dev_info usb_dip;
7184e968bc2Sgc161489 
7194e968bc2Sgc161489 	if (mdb_vread(&usb_dip, sizeof (struct dev_info), paddr) == -1) {
7204e968bc2Sgc161489 		mdb_warn("prt_usb_tree: Failed to read dev_info!\n");
7214e968bc2Sgc161489 
7224e968bc2Sgc161489 		return (DCMD_ERR);
7234e968bc2Sgc161489 	}
7244e968bc2Sgc161489 
7254e968bc2Sgc161489 	prt_usb_tree_node(paddr);
7264e968bc2Sgc161489 
7274e968bc2Sgc161489 	if (usb_dip.devi_child) {
7284e968bc2Sgc161489 
7294e968bc2Sgc161489 		mdb_printf("{\n");
7304e968bc2Sgc161489 		mdb_inc_indent(4);
7314e968bc2Sgc161489 		prt_usb_tree((uintptr_t)usb_dip.devi_child, 1);
7324e968bc2Sgc161489 		mdb_dec_indent(4);
7334e968bc2Sgc161489 		mdb_printf("}\n\n");
7344e968bc2Sgc161489 	}
7354e968bc2Sgc161489 
7364e968bc2Sgc161489 	if (usb_dip.devi_sibling && flag == 1) {
7374e968bc2Sgc161489 		/* print the sibling if flag == 1 */
7384e968bc2Sgc161489 
7394e968bc2Sgc161489 		prt_usb_tree((uintptr_t)usb_dip.devi_sibling, 1);
7404e968bc2Sgc161489 	}
7414e968bc2Sgc161489 
7424e968bc2Sgc161489 	return (DCMD_OK);
7434e968bc2Sgc161489 }
7444e968bc2Sgc161489 
7454e968bc2Sgc161489 static int
prt_usb_tree_node(uintptr_t paddr)7464e968bc2Sgc161489 prt_usb_tree_node(uintptr_t paddr)
7474e968bc2Sgc161489 {
7484e968bc2Sgc161489 	struct dev_info usb_dip;
7494e968bc2Sgc161489 	uintptr_t statep;
7504e968bc2Sgc161489 	uint_t errlevel;
7514e968bc2Sgc161489 	char driver_name[STRLEN] = "";
7524e968bc2Sgc161489 	char strbuf[STRLEN] = "";
7534e968bc2Sgc161489 
7544e968bc2Sgc161489 	if (mdb_vread(&usb_dip, sizeof (struct dev_info), paddr) == -1) {
7554e968bc2Sgc161489 		mdb_warn("prt_usb_tree_node: Failed to read dev_info!\n");
7564e968bc2Sgc161489 
7574e968bc2Sgc161489 		return (DCMD_ERR);
7584e968bc2Sgc161489 	}
7594e968bc2Sgc161489 
7604e968bc2Sgc161489 	/* node name */
7614e968bc2Sgc161489 	if (mdb_readstr(strbuf, STRLEN,
7624e968bc2Sgc161489 	    (uintptr_t)usb_dip.devi_node_name) != -1) {
7634e968bc2Sgc161489 		mdb_printf("%s, ", strbuf);
7644e968bc2Sgc161489 	} else {
7654e968bc2Sgc161489 		mdb_printf("%s, ", "node_name");
7664e968bc2Sgc161489 	}
7674e968bc2Sgc161489 
7684e968bc2Sgc161489 	/* instance */
7694e968bc2Sgc161489 	mdb_printf("instance #%d ", usb_dip.devi_instance);
7704e968bc2Sgc161489 
7714e968bc2Sgc161489 	/* driver name */
7724e968bc2Sgc161489 	if (DDI_CF2(&usb_dip)) {
7734e968bc2Sgc161489 
7744e968bc2Sgc161489 		mdb_devinfo2driver(paddr, driver_name, STRLEN);
7754e968bc2Sgc161489 		mdb_printf("(driver name: %s)\n", driver_name);
7764e968bc2Sgc161489 	} else {
7774e968bc2Sgc161489 
7784e968bc2Sgc161489 		mdb_printf("(driver not attached)\n");
7794e968bc2Sgc161489 	}
7804e968bc2Sgc161489 
7814e968bc2Sgc161489 	/* device path */
7824e968bc2Sgc161489 	mdb_ddi_pathname(paddr, strbuf, STRLEN);
7834e968bc2Sgc161489 	mdb_printf("  %s\n", strbuf);
7844e968bc2Sgc161489 
7854e968bc2Sgc161489 	/* dip addr */
7864e968bc2Sgc161489 	mdb_printf("  dip: 0x%x\n", paddr);
7874e968bc2Sgc161489 
7884e968bc2Sgc161489 	/* softe_sate */
7894e968bc2Sgc161489 	mdb_snprintf(strbuf, STRLEN, "%s_statep", driver_name);
7904e968bc2Sgc161489 	if (mdb_devinfo2statep(paddr, strbuf, &statep) != -1) {
7914e968bc2Sgc161489 		mdb_printf("  %s: 0x%x\n", strbuf, statep);
7924e968bc2Sgc161489 	}
7934e968bc2Sgc161489 
7944e968bc2Sgc161489 	/* error level */
7954e968bc2Sgc161489 	mdb_snprintf(strbuf, STRLEN, "%s_errlevel", driver_name);
7964e968bc2Sgc161489 	if (mdb_readvar(&errlevel, strbuf) != -1) {
7974e968bc2Sgc161489 		mdb_printf("  %s: 0x%x\n", strbuf, errlevel);
7984e968bc2Sgc161489 	}
7994e968bc2Sgc161489 
8004e968bc2Sgc161489 	if (strcmp(driver_name, "ehci") == 0) {
8014e968bc2Sgc161489 		mdb_arg_t argv[] = {
8024e968bc2Sgc161489 		    {MDB_TYPE_STRING, {"ehci_state_t"}},
8034e968bc2Sgc161489 		    {MDB_TYPE_STRING, {"ehci_root_hub.rh_descr"}}
8044e968bc2Sgc161489 		};
8054e968bc2Sgc161489 		mdb_call_dcmd("print", statep, DCMD_ADDRSPEC, 2, argv);
8064e968bc2Sgc161489 	}
8074e968bc2Sgc161489 
8084e968bc2Sgc161489 	if (strcmp(driver_name, "ohci") == 0) {
8094e968bc2Sgc161489 		mdb_arg_t argv[] = {
8104e968bc2Sgc161489 		    {MDB_TYPE_STRING, {"ohci_state_t"}},
8114e968bc2Sgc161489 		    {MDB_TYPE_STRING, {"ohci_root_hub.rh_descr"}}
8124e968bc2Sgc161489 		};
8134e968bc2Sgc161489 		mdb_call_dcmd("print", statep, DCMD_ADDRSPEC, 2, argv);
8144e968bc2Sgc161489 	}
8154e968bc2Sgc161489 
8164e968bc2Sgc161489 	if (strcmp(driver_name, "uhci") == 0) {
8174e968bc2Sgc161489 		mdb_arg_t argv[] = {
8184e968bc2Sgc161489 		    {MDB_TYPE_STRING, {"uhci_state_t"}},
8194e968bc2Sgc161489 		    {MDB_TYPE_STRING, {"uhci_root_hub.rh_descr"}}
8204e968bc2Sgc161489 		};
8214e968bc2Sgc161489 		mdb_call_dcmd("print", statep, DCMD_ADDRSPEC, 2, argv);
8224e968bc2Sgc161489 	}
8234e968bc2Sgc161489 
8244e968bc2Sgc161489 	if (strcmp(driver_name, "hubd") == 0) {
8254e968bc2Sgc161489 		mdb_arg_t argv[] = {
8264e968bc2Sgc161489 		    {MDB_TYPE_STRING, {"hubd_t"}},
8274e968bc2Sgc161489 		    {MDB_TYPE_STRING, {"h_hub_descr"}}
8284e968bc2Sgc161489 		};
8294e968bc2Sgc161489 		mdb_call_dcmd("print", statep, DCMD_ADDRSPEC, 2, argv);
8304e968bc2Sgc161489 	}
8314e968bc2Sgc161489 
8324e968bc2Sgc161489 	if (strcmp(driver_name, "hid") == 0) {
8334e968bc2Sgc161489 		hid_state_t hidp;
8344e968bc2Sgc161489 
8354e968bc2Sgc161489 		if (mdb_vread(&hidp, sizeof (hid_state_t), statep) != -1) {
8364e968bc2Sgc161489 			hidparser_handle hid_report;
8374e968bc2Sgc161489 
8384e968bc2Sgc161489 			if (mdb_vread(&hid_report, sizeof (hidparser_handle),
8394e968bc2Sgc161489 			    (uintptr_t)hidp.hid_report_descr) != -1) {
8404e968bc2Sgc161489 
8414e968bc2Sgc161489 				mdb_inc_indent(2);
8424e968bc2Sgc161489 
8434e968bc2Sgc161489 				mdb_printf("\n");
8444e968bc2Sgc161489 				prt_usb_hid_item((uintptr_t)
8454e968bc2Sgc161489 				    hid_report.hidparser_handle_parse_tree);
8464e968bc2Sgc161489 
8474e968bc2Sgc161489 				mdb_dec_indent(2);
8484e968bc2Sgc161489 			}
8494e968bc2Sgc161489 		}
8504e968bc2Sgc161489 	}
8514e968bc2Sgc161489 
8524e968bc2Sgc161489 	mdb_printf("\n");
8534e968bc2Sgc161489 
8544e968bc2Sgc161489 	return (DCMD_OK);
8554e968bc2Sgc161489 }
8564e968bc2Sgc161489 
8574e968bc2Sgc161489 /* print hid report descriptor */
8584e968bc2Sgc161489 static void
prt_usb_hid_item(uintptr_t paddr)8594e968bc2Sgc161489 prt_usb_hid_item(uintptr_t paddr)
8604e968bc2Sgc161489 {
8614e968bc2Sgc161489 	entity_item_t item;
8624e968bc2Sgc161489 	if (mdb_vread(&item, sizeof (entity_item_t), paddr) != -1) {
8634e968bc2Sgc161489 
8644e968bc2Sgc161489 		prt_usb_hid_item_attrs((uintptr_t)item.entity_item_attributes);
8654e968bc2Sgc161489 		prt_usb_hid_item_params(&item);
8664e968bc2Sgc161489 
8674e968bc2Sgc161489 		if (item.info.child) {
8684e968bc2Sgc161489 			mdb_inc_indent(4);
8694e968bc2Sgc161489 			prt_usb_hid_item((uintptr_t)item.info.child);
8704e968bc2Sgc161489 			mdb_dec_indent(4);
8714e968bc2Sgc161489 		}
8724e968bc2Sgc161489 
8734e968bc2Sgc161489 		if (item.entity_item_right_sibling) {
8744e968bc2Sgc161489 			prt_usb_hid_item((uintptr_t)
8754e968bc2Sgc161489 			    item.entity_item_right_sibling);
8764e968bc2Sgc161489 		}
8774e968bc2Sgc161489 	}
8784e968bc2Sgc161489 }
8794e968bc2Sgc161489 
8804e968bc2Sgc161489 static void
prt_usb_hid_item_params(entity_item_t * item)8814e968bc2Sgc161489 prt_usb_hid_item_params(entity_item_t *item)
8824e968bc2Sgc161489 {
8834e968bc2Sgc161489 	switch (item->entity_item_type) {
8844e968bc2Sgc161489 	case 0x80:
8854e968bc2Sgc161489 		mdb_printf("INPUT ");
8864e968bc2Sgc161489 
8874e968bc2Sgc161489 		break;
8884e968bc2Sgc161489 	case 0x90:
8894e968bc2Sgc161489 		mdb_printf("OUTPUT ");
8904e968bc2Sgc161489 
8914e968bc2Sgc161489 		break;
8924e968bc2Sgc161489 	case 0xA0:
8934e968bc2Sgc161489 		mdb_printf("COLLECTION ");
8944e968bc2Sgc161489 
8954e968bc2Sgc161489 		break;
8964e968bc2Sgc161489 	case 0xB0:
8974e968bc2Sgc161489 		mdb_printf("FEATURE ");
8984e968bc2Sgc161489 
8994e968bc2Sgc161489 		break;
9004e968bc2Sgc161489 	case 0xC0:
9014e968bc2Sgc161489 		mdb_printf("END_COLLECTION ");
9024e968bc2Sgc161489 
9034e968bc2Sgc161489 		break;
9044e968bc2Sgc161489 	default:
9054e968bc2Sgc161489 		mdb_printf("MAIN_ITEM ");
9064e968bc2Sgc161489 
9074e968bc2Sgc161489 		break;
9084e968bc2Sgc161489 	}
9094e968bc2Sgc161489 
9104e968bc2Sgc161489 	prt_usb_hid_item_data((uintptr_t)item->entity_item_params,
9114e968bc2Sgc161489 	    item->entity_item_params_leng);
9124e968bc2Sgc161489 
9134e968bc2Sgc161489 	mdb_printf("\n");
9144e968bc2Sgc161489 }
9154e968bc2Sgc161489 
9164e968bc2Sgc161489 static void
prt_usb_hid_item_attrs(uintptr_t paddr)9174e968bc2Sgc161489 prt_usb_hid_item_attrs(uintptr_t paddr)
9184e968bc2Sgc161489 {
9194e968bc2Sgc161489 	entity_attribute_t attr;
9204e968bc2Sgc161489 
9214e968bc2Sgc161489 	if (mdb_vread(&attr, sizeof (entity_attribute_t), paddr) != -1) {
9224e968bc2Sgc161489 
9234e968bc2Sgc161489 		prt_usb_hid_item_tags(attr.entity_attribute_tag);
9244e968bc2Sgc161489 		prt_usb_hid_item_data((uintptr_t)attr.entity_attribute_value,
9254e968bc2Sgc161489 		    attr.entity_attribute_length);
9264e968bc2Sgc161489 
9274e968bc2Sgc161489 		mdb_printf("\n");
9284e968bc2Sgc161489 
9294e968bc2Sgc161489 		if (attr.entity_attribute_next) {
9304e968bc2Sgc161489 			prt_usb_hid_item_attrs((uintptr_t)
9314e968bc2Sgc161489 			    attr.entity_attribute_next);
9324e968bc2Sgc161489 		}
9334e968bc2Sgc161489 	}
9344e968bc2Sgc161489 }
9354e968bc2Sgc161489 
9364e968bc2Sgc161489 static void
prt_usb_hid_item_data(uintptr_t paddr,uint_t len)9374e968bc2Sgc161489 prt_usb_hid_item_data(uintptr_t paddr, uint_t len)
9384e968bc2Sgc161489 {
9394e968bc2Sgc161489 	char data[4];
9404e968bc2Sgc161489 	int i;
9414e968bc2Sgc161489 
9424e968bc2Sgc161489 	if (len > 4) {
9434e968bc2Sgc161489 		mdb_warn("Incorrect entity_item_length: 0x%x\n", len);
9444e968bc2Sgc161489 
9454e968bc2Sgc161489 		return;
9464e968bc2Sgc161489 	}
9474e968bc2Sgc161489 
9484e968bc2Sgc161489 	if (mdb_vread(data, len, paddr) != -1) {
9494e968bc2Sgc161489 
9504e968bc2Sgc161489 		mdb_printf("( ");
9514e968bc2Sgc161489 		for (i = 0; i < len; i++) {
9524e968bc2Sgc161489 			mdb_printf("0x%02x ", data[i] & 0xff);
9534e968bc2Sgc161489 		}
9544e968bc2Sgc161489 		mdb_printf(")");
9554e968bc2Sgc161489 	}
9564e968bc2Sgc161489 }
9574e968bc2Sgc161489 
9584e968bc2Sgc161489 static void
prt_usb_hid_item_tags(uint_t tag)9594e968bc2Sgc161489 prt_usb_hid_item_tags(uint_t tag)
9604e968bc2Sgc161489 {
9614e968bc2Sgc161489 	switch (tag) {
9624e968bc2Sgc161489 	case 0x04:
9634e968bc2Sgc161489 		mdb_printf("usage page ");
9644e968bc2Sgc161489 
9654e968bc2Sgc161489 		break;
9664e968bc2Sgc161489 	case 0x14:
9674e968bc2Sgc161489 		mdb_printf("logical minimum ");
9684e968bc2Sgc161489 
9694e968bc2Sgc161489 		break;
9704e968bc2Sgc161489 	case 0x24:
9714e968bc2Sgc161489 		mdb_printf("logical maximum ");
9724e968bc2Sgc161489 
9734e968bc2Sgc161489 		break;
9744e968bc2Sgc161489 	case 0x34:
9754e968bc2Sgc161489 		mdb_printf("physical minimum ");
9764e968bc2Sgc161489 
9774e968bc2Sgc161489 		break;
9784e968bc2Sgc161489 	case 0x44:
9794e968bc2Sgc161489 		mdb_printf("physical maximum ");
9804e968bc2Sgc161489 
9814e968bc2Sgc161489 		break;
9824e968bc2Sgc161489 	case 0x54:
9834e968bc2Sgc161489 		mdb_printf("exponent ");
9844e968bc2Sgc161489 
9854e968bc2Sgc161489 		break;
9864e968bc2Sgc161489 	case 0x64:
9874e968bc2Sgc161489 		mdb_printf("unit ");
9884e968bc2Sgc161489 
9894e968bc2Sgc161489 		break;
9904e968bc2Sgc161489 	case 0x74:
9914e968bc2Sgc161489 		mdb_printf("report size ");
9924e968bc2Sgc161489 
9934e968bc2Sgc161489 		break;
9944e968bc2Sgc161489 	case 0x84:
9954e968bc2Sgc161489 		mdb_printf("report id ");
9964e968bc2Sgc161489 
9974e968bc2Sgc161489 		break;
9984e968bc2Sgc161489 	case 0x94:
9994e968bc2Sgc161489 		mdb_printf("report count ");
10004e968bc2Sgc161489 
10014e968bc2Sgc161489 		break;
10024e968bc2Sgc161489 	case 0x08:
10034e968bc2Sgc161489 		mdb_printf("usage ");
10044e968bc2Sgc161489 
10054e968bc2Sgc161489 		break;
10064e968bc2Sgc161489 	case 0x18:
10074e968bc2Sgc161489 		mdb_printf("usage min ");
10084e968bc2Sgc161489 
10094e968bc2Sgc161489 		break;
10104e968bc2Sgc161489 	case 0x28:
10114e968bc2Sgc161489 		mdb_printf("usage max ");
10124e968bc2Sgc161489 
10134e968bc2Sgc161489 		break;
10144e968bc2Sgc161489 
10154e968bc2Sgc161489 	default:
10164e968bc2Sgc161489 		mdb_printf("tag ");
10174e968bc2Sgc161489 	}
10184e968bc2Sgc161489 }
10194e968bc2Sgc161489 
10204e968bc2Sgc161489 /* print the info required by "-v" */
10214e968bc2Sgc161489 static int
prt_usb_desc(uintptr_t usb_cfg,uint_t cfg_len)10224e968bc2Sgc161489 prt_usb_desc(uintptr_t usb_cfg, uint_t cfg_len)
10234e968bc2Sgc161489 {
10244e968bc2Sgc161489 	uintptr_t paddr = usb_cfg;
10254e968bc2Sgc161489 	uintptr_t pend = usb_cfg + cfg_len;
10264e968bc2Sgc161489 	uchar_t desc_type, nlen;
10274e968bc2Sgc161489 	usb_if_descr_t usb_if;
10284e968bc2Sgc161489 	ulong_t indent = 0;
10294e968bc2Sgc161489 
10304e968bc2Sgc161489 	mdb_arg_t argv = {MDB_TYPE_STRING, {"usb_dev_descr_t"}};
10314e968bc2Sgc161489 
10324e968bc2Sgc161489 	if (mdb_vread(&nlen, 1, paddr) == -1) {
10334e968bc2Sgc161489 
10344e968bc2Sgc161489 		return (DCMD_ERR);
10354e968bc2Sgc161489 	}
10364e968bc2Sgc161489 	while ((paddr + nlen <= pend) && (nlen > 0)) {
10374e968bc2Sgc161489 		if (mdb_vread(&desc_type, 1, paddr + 1) == -1) {
10384e968bc2Sgc161489 
10394e968bc2Sgc161489 			return (DCMD_ERR);
10404e968bc2Sgc161489 		}
10414e968bc2Sgc161489 
10424e968bc2Sgc161489 		switch (desc_type) {
10434e968bc2Sgc161489 		case USB_DESCR_TYPE_DEV:
10444e968bc2Sgc161489 			mdb_printf("Device Descriptor\n");
10454e968bc2Sgc161489 			print_struct(paddr, nlen, &argv);
10464e968bc2Sgc161489 
10474e968bc2Sgc161489 			break;
10484e968bc2Sgc161489 		case USB_DESCR_TYPE_CFG:
10494e968bc2Sgc161489 			indent = 4;
10504e968bc2Sgc161489 			mdb_inc_indent(indent);
10514e968bc2Sgc161489 			mdb_printf("Configuration Descriptor\n");
10524e968bc2Sgc161489 			print_descr(paddr, nlen, usb_cfg_descr, usb_cfg_item);
10534e968bc2Sgc161489 			mdb_dec_indent(indent);
10544e968bc2Sgc161489 
10554e968bc2Sgc161489 			break;
10564e968bc2Sgc161489 		case USB_DESCR_TYPE_STRING:
10574e968bc2Sgc161489 			mdb_printf("String Descriptor\n");
10584e968bc2Sgc161489 			print_descr(paddr, nlen, usb_str_descr, usb_str_item);
10594e968bc2Sgc161489 
10604e968bc2Sgc161489 			break;
10614e968bc2Sgc161489 		case USB_DESCR_TYPE_IF:
10624e968bc2Sgc161489 			indent = 8;
10634e968bc2Sgc161489 			mdb_inc_indent(indent);
10644e968bc2Sgc161489 			mdb_printf("Interface Descriptor\n");
10654e968bc2Sgc161489 			print_descr(paddr, nlen, usb_if_descr, usb_if_item);
10664e968bc2Sgc161489 			mdb_dec_indent(indent);
10674e968bc2Sgc161489 			mdb_vread(&usb_if, sizeof (usb_if_descr_t), paddr);
10684e968bc2Sgc161489 
10694e968bc2Sgc161489 			break;
10704e968bc2Sgc161489 		case USB_DESCR_TYPE_EP:
10714e968bc2Sgc161489 			indent = 8;
10724e968bc2Sgc161489 			mdb_inc_indent(indent);
10734e968bc2Sgc161489 			mdb_printf("Endpoint Descriptor\n");
10744e968bc2Sgc161489 			print_descr(paddr, nlen, usb_ep_descr, usb_ep_item);
10754e968bc2Sgc161489 			mdb_dec_indent(indent);
10764e968bc2Sgc161489 
10774e968bc2Sgc161489 			break;
10784e968bc2Sgc161489 		case USB_DESCR_TYPE_DEV_QLF:
10794e968bc2Sgc161489 			mdb_printf("Device_Qualifier Descriptor\n");
10804e968bc2Sgc161489 			print_descr(paddr, nlen, usb_qlf_descr, usb_qlf_item);
10814e968bc2Sgc161489 
10824e968bc2Sgc161489 			break;
10834e968bc2Sgc161489 		case USB_DESCR_TYPE_OTHER_SPEED_CFG:
10844e968bc2Sgc161489 			indent = 4;
10854e968bc2Sgc161489 			mdb_inc_indent(indent);
10864e968bc2Sgc161489 			mdb_printf("Other_Speed_Configuration Descriptor\n");
10874e968bc2Sgc161489 			print_descr(paddr, nlen, usb_cfg_descr, usb_cfg_item);
10884e968bc2Sgc161489 			mdb_dec_indent(indent);
10894e968bc2Sgc161489 
10904e968bc2Sgc161489 			break;
10914e968bc2Sgc161489 		case USB_DESCR_TYPE_IA:
10924e968bc2Sgc161489 			indent = 6;
10934e968bc2Sgc161489 			mdb_inc_indent(indent);
10944e968bc2Sgc161489 			mdb_printf("Interface_Association Descriptor\n");
10954e968bc2Sgc161489 			print_descr(paddr, nlen, usb_ia_descr, usb_ia_item);
10964e968bc2Sgc161489 			mdb_dec_indent(indent);
10974e968bc2Sgc161489 
10984e968bc2Sgc161489 			break;
10994e968bc2Sgc161489 		case 0x21:	/* hid descriptor */
11004e968bc2Sgc161489 			indent = 12;
11014e968bc2Sgc161489 			mdb_inc_indent(indent);
1102*ff0e937bSRaymond Chen 			if (usb_if.bInterfaceClass == 0xe0 &&
1103*ff0e937bSRaymond Chen 			    usb_if.bInterfaceSubClass == 0x02) {
1104*ff0e937bSRaymond Chen 				mdb_printf("WA Descriptor\n");
1105*ff0e937bSRaymond Chen 				print_descr(paddr, nlen, usb_wa_descr,
1106*ff0e937bSRaymond Chen 				    usb_wa_item);
1107*ff0e937bSRaymond Chen 			} else {
11084e968bc2Sgc161489 				mdb_printf("HID Descriptor\n");
1109*ff0e937bSRaymond Chen 				print_descr(paddr, nlen, usb_hid_descr,
1110*ff0e937bSRaymond Chen 				    usb_hid_item);
1111*ff0e937bSRaymond Chen 			}
11124e968bc2Sgc161489 			mdb_dec_indent(indent);
11134e968bc2Sgc161489 
11144e968bc2Sgc161489 			break;
11154e968bc2Sgc161489 		case 0x24:	/* class specific interfce descriptor */
11164e968bc2Sgc161489 			indent = 12;
11174e968bc2Sgc161489 			mdb_inc_indent(indent);
11184e968bc2Sgc161489 			if (usb_if.bInterfaceClass == 1 &&
11194e968bc2Sgc161489 			    usb_if.bInterfaceSubClass == 1) {
11204e968bc2Sgc161489 				mdb_printf("AudioControl_Interface: ");
11214e968bc2Sgc161489 				prt_usb_ac_desc(paddr, nlen);
11224e968bc2Sgc161489 
11234e968bc2Sgc161489 			} else if (usb_if.bInterfaceClass == 1 &&
11244e968bc2Sgc161489 			    usb_if.bInterfaceSubClass == 2) {
11254e968bc2Sgc161489 				mdb_printf("AudioStream_Interface: ");
11264e968bc2Sgc161489 				prt_usb_as_desc(paddr, nlen);
11274e968bc2Sgc161489 
11284e968bc2Sgc161489 			} else if (usb_if.bInterfaceClass == 0x0E &&
11294e968bc2Sgc161489 			    usb_if.bInterfaceSubClass == 1) {
11304e968bc2Sgc161489 				mdb_printf("VideoControl_Interface: ");
11314e968bc2Sgc161489 				prt_usb_vc_desc(paddr, nlen);
11324e968bc2Sgc161489 
11334e968bc2Sgc161489 
11344e968bc2Sgc161489 			} else if (usb_if.bInterfaceClass == 0x0E &&
11354e968bc2Sgc161489 			    usb_if.bInterfaceSubClass == 2) {
11364e968bc2Sgc161489 				mdb_printf("VideoStream_Interface: ");
11374e968bc2Sgc161489 				prt_usb_vs_desc(paddr, nlen);
11384e968bc2Sgc161489 
11394e968bc2Sgc161489 			} else {
11404e968bc2Sgc161489 				mdb_printf("Unknown_Interface:"
11414e968bc2Sgc161489 				    "0x%x\n", desc_type);
11424e968bc2Sgc161489 				prt_usb_buf(paddr, nlen);
11434e968bc2Sgc161489 			}
11444e968bc2Sgc161489 			mdb_dec_indent(indent);
11454e968bc2Sgc161489 
11464e968bc2Sgc161489 			break;
11474e968bc2Sgc161489 		case 0x25:	/* class specific endpoint descriptor */
11484e968bc2Sgc161489 			indent = 12;
11494e968bc2Sgc161489 			mdb_inc_indent(indent);
11504e968bc2Sgc161489 			if (usb_if.bInterfaceClass == 0x01) {
11514e968bc2Sgc161489 				mdb_printf("AudioEndpoint:\n");
11524e968bc2Sgc161489 				print_descr(paddr, nlen,
11534e968bc2Sgc161489 				    usb_as_ep_descr, usb_as_ep_item);
11544e968bc2Sgc161489 
11554e968bc2Sgc161489 			} else if (usb_if.bInterfaceClass == 0x0E) {
11564e968bc2Sgc161489 				mdb_printf("VideoEndpoint:\n");
11574e968bc2Sgc161489 				print_descr(paddr, nlen,
11584e968bc2Sgc161489 				    usb_ep_descr, usb_ep_item);
11594e968bc2Sgc161489 
11604e968bc2Sgc161489 			} else {
11614e968bc2Sgc161489 				mdb_printf("Unknown_Endpoint:"
11624e968bc2Sgc161489 				    "0x%x\n", desc_type);
11634e968bc2Sgc161489 				prt_usb_buf(paddr, nlen);
11644e968bc2Sgc161489 			}
11654e968bc2Sgc161489 			mdb_dec_indent(indent);
11664e968bc2Sgc161489 
11674e968bc2Sgc161489 			break;
11684e968bc2Sgc161489 		default:
11694e968bc2Sgc161489 			mdb_inc_indent(indent);
11704e968bc2Sgc161489 			mdb_printf("Unknown Descriptor: 0x%x\n", desc_type);
11714e968bc2Sgc161489 			prt_usb_buf(paddr, nlen);
11724e968bc2Sgc161489 			mdb_dec_indent(indent);
11734e968bc2Sgc161489 
11744e968bc2Sgc161489 			break;
11754e968bc2Sgc161489 		}
11764e968bc2Sgc161489 
11774e968bc2Sgc161489 		paddr += nlen;
11784e968bc2Sgc161489 		if (mdb_vread(&nlen, 1, paddr) == -1) {
11794e968bc2Sgc161489 
11804e968bc2Sgc161489 			return (DCMD_ERR);
11814e968bc2Sgc161489 		}
11824e968bc2Sgc161489 	};
11834e968bc2Sgc161489 
11844e968bc2Sgc161489 	return (DCMD_OK);
11854e968bc2Sgc161489 }
11864e968bc2Sgc161489 
11874e968bc2Sgc161489 
11884e968bc2Sgc161489 /* print audio class specific control descriptor */
11894e968bc2Sgc161489 static int
prt_usb_ac_desc(uintptr_t addr,uint_t nlen)11904e968bc2Sgc161489 prt_usb_ac_desc(uintptr_t addr, uint_t nlen)
11914e968bc2Sgc161489 {
11924e968bc2Sgc161489 	uchar_t sub_type;
11934e968bc2Sgc161489 
11944e968bc2Sgc161489 	if (mdb_vread(&sub_type, 1, addr + 2) == -1) {
11954e968bc2Sgc161489 
11964e968bc2Sgc161489 		return (DCMD_ERR);
11974e968bc2Sgc161489 	}
11984e968bc2Sgc161489 	switch (sub_type) {
11994e968bc2Sgc161489 	case 0x01:
12004e968bc2Sgc161489 		mdb_printf("header Descriptor\n");
12014e968bc2Sgc161489 		print_descr(addr, nlen,
12024e968bc2Sgc161489 		    usb_ac_header_descr, usb_ac_header_item);
12034e968bc2Sgc161489 
12044e968bc2Sgc161489 		break;
12054e968bc2Sgc161489 	case 0x02:
12064e968bc2Sgc161489 		mdb_printf("input_terminal Descriptor\n");
12074e968bc2Sgc161489 		print_descr(addr, nlen,
12084e968bc2Sgc161489 		    usb_ac_input_term_descr, usb_ac_input_term_item);
12094e968bc2Sgc161489 
12104e968bc2Sgc161489 		break;
12114e968bc2Sgc161489 	case 0x03:
12124e968bc2Sgc161489 		mdb_printf("output_terminal Descriptor\n");
12134e968bc2Sgc161489 		print_descr(addr, nlen,
12144e968bc2Sgc161489 		    usb_ac_output_term_descr, usb_ac_output_term_item);
12154e968bc2Sgc161489 
12164e968bc2Sgc161489 		break;
12174e968bc2Sgc161489 	case 0x04:
12184e968bc2Sgc161489 		mdb_printf("mixer_unit Descriptor\n");
12194e968bc2Sgc161489 		print_descr(addr, nlen,
12204e968bc2Sgc161489 		    usb_ac_mixer_descr, usb_ac_mixer_item);
12214e968bc2Sgc161489 
12224e968bc2Sgc161489 		break;
12234e968bc2Sgc161489 	case 0x05:
12244e968bc2Sgc161489 		mdb_printf("selector_unit Descriptor\n");
12254e968bc2Sgc161489 		print_descr(addr, nlen,
12264e968bc2Sgc161489 		    usb_ac_selector_descr, usb_ac_selector_item);
12274e968bc2Sgc161489 
12284e968bc2Sgc161489 		break;
12294e968bc2Sgc161489 	case 0x06:
12304e968bc2Sgc161489 		mdb_printf("feature_unit Descriptor\n");
12314e968bc2Sgc161489 		print_descr(addr, nlen,
12324e968bc2Sgc161489 		    usb_ac_feature_descr, usb_ac_feature_item);
12334e968bc2Sgc161489 
12344e968bc2Sgc161489 		break;
12354e968bc2Sgc161489 	case 0x07:
12364e968bc2Sgc161489 		mdb_printf("processing_unit Descriptor\n");
12374e968bc2Sgc161489 		print_descr(addr, nlen,
12384e968bc2Sgc161489 		    usb_ac_processing_descr, usb_ac_processing_item);
12394e968bc2Sgc161489 
12404e968bc2Sgc161489 		break;
12414e968bc2Sgc161489 	case 0x08:
12424e968bc2Sgc161489 		mdb_printf("extension_unit Descriptor\n");
12434e968bc2Sgc161489 		print_descr(addr, nlen,
12444e968bc2Sgc161489 		    usb_ac_extension_descr, usb_ac_extension_item);
12454e968bc2Sgc161489 
12464e968bc2Sgc161489 		break;
12474e968bc2Sgc161489 	default:
12484e968bc2Sgc161489 		mdb_printf("Unknown AC sub-descriptor 0x%x\n", sub_type);
12494e968bc2Sgc161489 		prt_usb_buf(addr, nlen);
12504e968bc2Sgc161489 
12514e968bc2Sgc161489 		break;
12524e968bc2Sgc161489 	}
12534e968bc2Sgc161489 
12544e968bc2Sgc161489 	return (DCMD_OK);
12554e968bc2Sgc161489 }
12564e968bc2Sgc161489 
12574e968bc2Sgc161489 /* print audio class specific stream descriptor */
12584e968bc2Sgc161489 static int
prt_usb_as_desc(uintptr_t addr,uint_t nlen)12594e968bc2Sgc161489 prt_usb_as_desc(uintptr_t addr, uint_t nlen)
12604e968bc2Sgc161489 {
12614e968bc2Sgc161489 	uchar_t sub_type;
12624e968bc2Sgc161489 
12634e968bc2Sgc161489 	if (mdb_vread(&sub_type, 1, addr + 2) == -1) {
12644e968bc2Sgc161489 
12654e968bc2Sgc161489 		return (DCMD_ERR);
12664e968bc2Sgc161489 	}
12674e968bc2Sgc161489 	switch (sub_type) {
12684e968bc2Sgc161489 	case 0x01:
12694e968bc2Sgc161489 		mdb_printf("general_interface Descriptor\n");
12704e968bc2Sgc161489 		print_descr(addr, nlen,
12714e968bc2Sgc161489 		    usb_as_if_descr, usb_as_if_item);
12724e968bc2Sgc161489 
12734e968bc2Sgc161489 		break;
12744e968bc2Sgc161489 	case 0x02:
12754e968bc2Sgc161489 		mdb_printf("format_type Descriptor\n");
12764e968bc2Sgc161489 		print_descr(addr, nlen,
12774e968bc2Sgc161489 		    usb_as_format_descr, usb_as_format_item);
12784e968bc2Sgc161489 
12794e968bc2Sgc161489 		break;
12804e968bc2Sgc161489 	default:
12814e968bc2Sgc161489 		mdb_printf("Unknown AS sub-descriptor 0x%x\n", sub_type);
12824e968bc2Sgc161489 		prt_usb_buf(addr, nlen);
12834e968bc2Sgc161489 
12844e968bc2Sgc161489 		break;
12854e968bc2Sgc161489 	}
12864e968bc2Sgc161489 
12874e968bc2Sgc161489 	return (DCMD_OK);
12884e968bc2Sgc161489 }
12894e968bc2Sgc161489 
12904e968bc2Sgc161489 /* print video class specific control descriptor */
12914e968bc2Sgc161489 static int
prt_usb_vc_desc(uintptr_t addr,uint_t nlen)12924e968bc2Sgc161489 prt_usb_vc_desc(uintptr_t addr, uint_t nlen)
12934e968bc2Sgc161489 {
12944e968bc2Sgc161489 	uchar_t sub_type;
12954e968bc2Sgc161489 
12964e968bc2Sgc161489 	if (mdb_vread(&sub_type, 1, addr + 2) == -1) {
12974e968bc2Sgc161489 
12984e968bc2Sgc161489 		return (DCMD_ERR);
12994e968bc2Sgc161489 	}
13004e968bc2Sgc161489 	switch (sub_type) {
13014e968bc2Sgc161489 	case 0x01:
13024e968bc2Sgc161489 		mdb_printf("header Descriptor\n");
13034e968bc2Sgc161489 		print_descr(addr, nlen,
13044e968bc2Sgc161489 		    usb_vc_header_descr, usb_vc_header_item);
13054e968bc2Sgc161489 
13064e968bc2Sgc161489 		break;
13074e968bc2Sgc161489 	case 0x02:
13084e968bc2Sgc161489 		mdb_printf("input_terminal Descriptor\n");
13094e968bc2Sgc161489 		print_descr(addr, nlen,
13104e968bc2Sgc161489 		    usb_vc_input_term_descr, usb_vc_input_term_item);
13114e968bc2Sgc161489 
13124e968bc2Sgc161489 		break;
13134e968bc2Sgc161489 	case 0x03:
13144e968bc2Sgc161489 		mdb_printf("output_terminal Descriptor\n");
13154e968bc2Sgc161489 		print_descr(addr, nlen,
13164e968bc2Sgc161489 		    usb_vc_output_term_descr, usb_vc_output_term_item);
13174e968bc2Sgc161489 
13184e968bc2Sgc161489 		break;
13194e968bc2Sgc161489 	case 0x04:
13204e968bc2Sgc161489 		mdb_printf("selector_unit Descriptor\n");
13214e968bc2Sgc161489 		print_descr(addr, nlen,
13224e968bc2Sgc161489 		    usb_vc_selector_descr, usb_vc_selector_item);
13234e968bc2Sgc161489 
13244e968bc2Sgc161489 		break;
13254e968bc2Sgc161489 	case 0x05:
13264e968bc2Sgc161489 		mdb_printf("processing_unit Descriptor\n");
13274e968bc2Sgc161489 		print_descr(addr, nlen,
13284e968bc2Sgc161489 		    usb_vc_processing_descr, usb_vc_processing_item);
13294e968bc2Sgc161489 
13304e968bc2Sgc161489 		break;
13314e968bc2Sgc161489 	case 0x06:
13324e968bc2Sgc161489 		mdb_printf("extension_unit Descriptor\n");
13334e968bc2Sgc161489 		print_descr(addr, nlen,
13344e968bc2Sgc161489 		    usb_vc_extension_descr, usb_vc_extension_item);
13354e968bc2Sgc161489 
13364e968bc2Sgc161489 		break;
13374e968bc2Sgc161489 	default:
13384e968bc2Sgc161489 		mdb_printf("Unknown VC sub-descriptor 0x%x\n", sub_type);
13394e968bc2Sgc161489 		prt_usb_buf(addr, nlen);
13404e968bc2Sgc161489 
13414e968bc2Sgc161489 		break;
13424e968bc2Sgc161489 	}
13434e968bc2Sgc161489 
13444e968bc2Sgc161489 	return (DCMD_OK);
13454e968bc2Sgc161489 }
13464e968bc2Sgc161489 
13474e968bc2Sgc161489 /* print video class specific stream descriptor */
13484e968bc2Sgc161489 static int
prt_usb_vs_desc(uintptr_t addr,uint_t nlen)13494e968bc2Sgc161489 prt_usb_vs_desc(uintptr_t addr, uint_t nlen)
13504e968bc2Sgc161489 {
13514e968bc2Sgc161489 	uchar_t sub_type;
13524e968bc2Sgc161489 
13534e968bc2Sgc161489 	if (mdb_vread(&sub_type, 1, addr + 2) == -1) {
13544e968bc2Sgc161489 
13554e968bc2Sgc161489 		return (DCMD_ERR);
13564e968bc2Sgc161489 	}
13574e968bc2Sgc161489 	switch (sub_type) {
13584e968bc2Sgc161489 	case 0x01:
13594e968bc2Sgc161489 		mdb_printf("input_header Descriptor\n");
13604e968bc2Sgc161489 		print_descr(addr, nlen,
13614e968bc2Sgc161489 		    usb_vs_input_header_descr, usb_vs_input_header_item);
13624e968bc2Sgc161489 
13634e968bc2Sgc161489 		break;
13644e968bc2Sgc161489 	case 0x02:
13654e968bc2Sgc161489 		mdb_printf("output_header Descriptor\n");
13664e968bc2Sgc161489 		print_descr(addr, nlen,
13674e968bc2Sgc161489 		    usb_vs_output_header_descr, usb_vs_output_header_item);
13684e968bc2Sgc161489 
13694e968bc2Sgc161489 		break;
13704e968bc2Sgc161489 	case 0x03:
13714e968bc2Sgc161489 		mdb_printf("still_image_frame Descriptor\n");
13724e968bc2Sgc161489 		print_descr(addr, nlen,
13734e968bc2Sgc161489 		    usb_vs_still_image_descr, usb_vs_still_image_item);
13744e968bc2Sgc161489 
13754e968bc2Sgc161489 		break;
13764e968bc2Sgc161489 	case 0x04:
13774e968bc2Sgc161489 		mdb_printf("format_uncompressed Descriptor\n");
13784e968bc2Sgc161489 		print_descr(addr, nlen,
13794e968bc2Sgc161489 		    usb_vs_format_uncps_descr, usb_vs_format_uncps_item);
13804e968bc2Sgc161489 
13814e968bc2Sgc161489 		break;
13824e968bc2Sgc161489 	case 0x05:
13834e968bc2Sgc161489 		mdb_printf("frame_uncompressed Descriptor\n");
13844e968bc2Sgc161489 		print_descr(addr, nlen,
13854e968bc2Sgc161489 		    usb_vs_2frame_descr, usb_vs_2frame_item);
13864e968bc2Sgc161489 
13874e968bc2Sgc161489 		break;
13884e968bc2Sgc161489 	case 0x06:
13894e968bc2Sgc161489 		mdb_printf("format_mjpeg Descriptor\n");
13904e968bc2Sgc161489 		print_descr(addr, nlen,
13914e968bc2Sgc161489 		    usb_vs_format_mjpeg_descr, usb_vs_format_mjpeg_item);
13924e968bc2Sgc161489 
13934e968bc2Sgc161489 		break;
13944e968bc2Sgc161489 	case 0x07:
13954e968bc2Sgc161489 		mdb_printf("frame_mjpeg Descriptor\n");
13964e968bc2Sgc161489 		print_descr(addr, nlen,
13974e968bc2Sgc161489 		    usb_vs_2frame_descr, usb_vs_2frame_item);
13984e968bc2Sgc161489 
13994e968bc2Sgc161489 		break;
14004e968bc2Sgc161489 	case 0x0A:
14014e968bc2Sgc161489 		mdb_printf("format_mpeg2ts Descriptor\n");
14024e968bc2Sgc161489 		print_descr(addr, nlen,
14034e968bc2Sgc161489 		    usb_vs_format_mp2ts_descr, usb_vs_format_mp2ts_item);
14044e968bc2Sgc161489 
14054e968bc2Sgc161489 		break;
14064e968bc2Sgc161489 	case 0x0C:
14074e968bc2Sgc161489 		mdb_printf("format_dv Descriptor\n");
14084e968bc2Sgc161489 		print_descr(addr, nlen,
14094e968bc2Sgc161489 		    usb_vs_format_dv_descr, usb_vs_format_dv_item);
14104e968bc2Sgc161489 
14114e968bc2Sgc161489 		break;
14124e968bc2Sgc161489 	case 0x0D:
14134e968bc2Sgc161489 		mdb_printf("color_matching Descriptor\n");
14144e968bc2Sgc161489 		print_descr(addr, nlen,
14154e968bc2Sgc161489 		    usb_vs_color_matching_descr, usb_vs_color_matching_item);
14164e968bc2Sgc161489 
14174e968bc2Sgc161489 		break;
14184e968bc2Sgc161489 	default:
14194e968bc2Sgc161489 		mdb_printf("Unknown VS sub-descriptor 0x%x\n", sub_type);
14204e968bc2Sgc161489 		prt_usb_buf(addr, nlen);
14214e968bc2Sgc161489 
14224e968bc2Sgc161489 		break;
14234e968bc2Sgc161489 	}
14244e968bc2Sgc161489 
14254e968bc2Sgc161489 	return (DCMD_OK);
14264e968bc2Sgc161489 }
14274e968bc2Sgc161489 
14284e968bc2Sgc161489 /* parse and print the descriptor items */
14294e968bc2Sgc161489 static int
print_descr(uintptr_t addr,uint_t nlen,usb_descr_item_t * item,uint_t nitem)14304e968bc2Sgc161489 print_descr(uintptr_t addr, uint_t nlen, usb_descr_item_t *item, uint_t nitem)
14314e968bc2Sgc161489 {
14324e968bc2Sgc161489 	int i, j;
14334e968bc2Sgc161489 	uint8_t buf[8];
14344e968bc2Sgc161489 	uint64_t value;
14354e968bc2Sgc161489 	uintptr_t paddr = addr;
14364e968bc2Sgc161489 	usb_descr_item_t *p = item;
14374e968bc2Sgc161489 
14384e968bc2Sgc161489 	mdb_printf("{");
14394e968bc2Sgc161489 	for (i = 0; (i < nitem) && (paddr < addr + nlen); i++) {
14404e968bc2Sgc161489 		mdb_printf("\n    %s =", p->name);
14414e968bc2Sgc161489 		switch (p->nlen) {
14424e968bc2Sgc161489 		case 1:		/* uint8_t */
14434e968bc2Sgc161489 			if (mdb_vread(buf, 1, paddr) == -1) {
14444e968bc2Sgc161489 
14454e968bc2Sgc161489 				return (DCMD_ERR);
14464e968bc2Sgc161489 			}
14474e968bc2Sgc161489 			value =  buf[0];
14484e968bc2Sgc161489 
14494e968bc2Sgc161489 			break;
14504e968bc2Sgc161489 		case 2:		/* uint16_t */
14514e968bc2Sgc161489 			if (mdb_vread(buf, 2, paddr) == -1) {
14524e968bc2Sgc161489 
14534e968bc2Sgc161489 				return (DCMD_ERR);
14544e968bc2Sgc161489 			}
14554e968bc2Sgc161489 			value = buf[0] | (buf[1] << 8);
14564e968bc2Sgc161489 
14574e968bc2Sgc161489 			break;
14584e968bc2Sgc161489 		case 4:		/* uint32_t */
14594e968bc2Sgc161489 			if (mdb_vread(buf, 4, paddr) == -1) {
14604e968bc2Sgc161489 
14614e968bc2Sgc161489 				return (DCMD_ERR);
14624e968bc2Sgc161489 			}
14634e968bc2Sgc161489 			value = buf[0] | (buf[1] << 8) |
14644e968bc2Sgc161489 			    (buf[2] << 16) | (buf[3] << 24);
14654e968bc2Sgc161489 
14664e968bc2Sgc161489 			break;
14674e968bc2Sgc161489 		case 8:		/* uint64_t */
14684e968bc2Sgc161489 			if (mdb_vread(buf, 8, paddr) == -1) {
14694e968bc2Sgc161489 
14704e968bc2Sgc161489 				return (DCMD_ERR);
14714e968bc2Sgc161489 			}
14724e968bc2Sgc161489 			value =	buf[4] | (buf[5] << 8) |
14734e968bc2Sgc161489 			    (buf[6] << 16) | (buf[7] << 24);
14744e968bc2Sgc161489 			value = buf[0] | (buf[1] << 8) |
14754e968bc2Sgc161489 			    (buf[2] << 16) | (buf[3] << 24) |
14764e968bc2Sgc161489 			    (value << 32);
14774e968bc2Sgc161489 
14784e968bc2Sgc161489 			break;
14794e968bc2Sgc161489 		default:	/* byte array */
14804e968bc2Sgc161489 			value = 0;
14814e968bc2Sgc161489 			/* print an array instead of a value */
14824e968bc2Sgc161489 			for (j = 0; j < p->nlen - BYTE_OFFSET; j++) {
14834e968bc2Sgc161489 				if (mdb_vread(buf, 1, paddr + j) == -1) {
14844e968bc2Sgc161489 
14854e968bc2Sgc161489 					break;
14864e968bc2Sgc161489 				}
14874e968bc2Sgc161489 				mdb_printf(" 0x%x", buf[0]);
14884e968bc2Sgc161489 			}
14894e968bc2Sgc161489 
14904e968bc2Sgc161489 			break;
14914e968bc2Sgc161489 		}
14924e968bc2Sgc161489 
14934e968bc2Sgc161489 		if (p->nlen > BYTE_OFFSET) {
14944e968bc2Sgc161489 			paddr += p->nlen - BYTE_OFFSET;
14954e968bc2Sgc161489 		} else {
14964e968bc2Sgc161489 			mdb_printf(" 0x%x", value);
14974e968bc2Sgc161489 			paddr += p->nlen;
14984e968bc2Sgc161489 		}
14994e968bc2Sgc161489 
15004e968bc2Sgc161489 		p++;
15014e968bc2Sgc161489 	}
15024e968bc2Sgc161489 
15034e968bc2Sgc161489 	/* print the unresolved bytes */
15044e968bc2Sgc161489 	if (paddr < addr + nlen) {
15054e968bc2Sgc161489 		mdb_printf("\n    ... =");
15064e968bc2Sgc161489 	}
15074e968bc2Sgc161489 	while (paddr < addr + nlen) {
15084e968bc2Sgc161489 		if (mdb_vread(buf, 1, paddr++) == -1) {
15094e968bc2Sgc161489 
15104e968bc2Sgc161489 			break;
15114e968bc2Sgc161489 		}
15124e968bc2Sgc161489 		mdb_printf(" 0x%x", buf[0]);
15134e968bc2Sgc161489 	}
15144e968bc2Sgc161489 	mdb_printf("\n}\n");
15154e968bc2Sgc161489 
15164e968bc2Sgc161489 	return (DCMD_OK);
15174e968bc2Sgc161489 }
15184e968bc2Sgc161489 
15194e968bc2Sgc161489 /* print the buffer as a struct */
15204e968bc2Sgc161489 static int
print_struct(uintptr_t addr,uint_t nlen,mdb_arg_t * arg)15214e968bc2Sgc161489 print_struct(uintptr_t addr, uint_t nlen, mdb_arg_t *arg)
15224e968bc2Sgc161489 {
15234e968bc2Sgc161489 	mdb_ctf_id_t id;
15244e968bc2Sgc161489 	if (mdb_ctf_lookup_by_name(arg->a_un.a_str, &id) == 0) {
15254e968bc2Sgc161489 
15264e968bc2Sgc161489 		mdb_call_dcmd("print", addr, DCMD_ADDRSPEC, 1, arg);
15274e968bc2Sgc161489 	} else {
15284e968bc2Sgc161489 
15294e968bc2Sgc161489 		prt_usb_buf(addr, nlen);
15304e968bc2Sgc161489 	}
15314e968bc2Sgc161489 
15324e968bc2Sgc161489 	return (DCMD_OK);
15334e968bc2Sgc161489 }
15344e968bc2Sgc161489 
15354e968bc2Sgc161489 /* print the buffer as a byte array */
15364e968bc2Sgc161489 static int
prt_usb_buf(uintptr_t addr,uint_t nlen)15374e968bc2Sgc161489 prt_usb_buf(uintptr_t addr, uint_t nlen)
15384e968bc2Sgc161489 {
15394e968bc2Sgc161489 	int i;
15404e968bc2Sgc161489 	uchar_t val;
15414e968bc2Sgc161489 
15424e968bc2Sgc161489 	mdb_printf("{\n");
15434e968bc2Sgc161489 	for (i = 0; i < nlen; i++) {
15444e968bc2Sgc161489 		if (mdb_vread(&val, 1, addr + i) == -1) {
15454e968bc2Sgc161489 
15464e968bc2Sgc161489 			break;
15474e968bc2Sgc161489 		}
15484e968bc2Sgc161489 		mdb_printf("%02x ", val);
15494e968bc2Sgc161489 	}
15504e968bc2Sgc161489 	if (nlen) {
15514e968bc2Sgc161489 		mdb_printf("\n");
15524e968bc2Sgc161489 	}
15534e968bc2Sgc161489 	mdb_printf("}\n");
15544e968bc2Sgc161489 
15554e968bc2Sgc161489 	return (DCMD_OK);
15564e968bc2Sgc161489 }
1557