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
5*d73ae94eSgc  * Common Development and Distribution License (the "License").
6*d73ae94eSgc  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*d73ae94eSgc  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_USB_USBA_USBA_PRIVATE_H
277c478bd9Sstevel@tonic-gate #define	_SYS_USB_USBA_USBA_PRIVATE_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * Header file for items to be shared within usba but not to be used
357c478bd9Sstevel@tonic-gate  * by drivers
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
397c478bd9Sstevel@tonic-gate extern "C" {
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * **************************************************************************
447c478bd9Sstevel@tonic-gate  * DDK version 0.8 binaries are supported.
457c478bd9Sstevel@tonic-gate  * **************************************************************************
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /* USBA supports (obsolete) legacy version 0.8 of the S8/S9 DDK. */
497c478bd9Sstevel@tonic-gate #define	USBA_LEG_MAJOR_VER	0
507c478bd9Sstevel@tonic-gate #define	USBA_LEG_MINOR_VER	8
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * **************************************************************************
547c478bd9Sstevel@tonic-gate  * Descriptor definitions and parsing functions.
557c478bd9Sstevel@tonic-gate  * **************************************************************************
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  * functions to return a pre-processed device descriptor to the client driver.
607c478bd9Sstevel@tonic-gate  * These all extract data from the raw config cloud  returned by a
617c478bd9Sstevel@tonic-gate  * usb_get_raw_cfg_data()
627c478bd9Sstevel@tonic-gate  *
637c478bd9Sstevel@tonic-gate  * The pre-processed descriptor is returned into a buffer supplied by
647c478bd9Sstevel@tonic-gate  * the caller
657c478bd9Sstevel@tonic-gate  * The size of the buffer should allow for padding
667c478bd9Sstevel@tonic-gate  *
677c478bd9Sstevel@tonic-gate  * In the following:
687c478bd9Sstevel@tonic-gate  *	buf		buffer containing data returned by GET_DESCRIPTOR
697c478bd9Sstevel@tonic-gate  *	buflen		length of the data at buf
707c478bd9Sstevel@tonic-gate  *	ret_descr	buffer the data is to be returned in
717c478bd9Sstevel@tonic-gate  *	ret_buf_len	size of the buffer at ret_descr
727c478bd9Sstevel@tonic-gate  *
73*d73ae94eSgc  * 	first_if	the first interace associated with current iad
74*d73ae94eSgc  *	if_index	the index in the array of concurrent interfaces
757c478bd9Sstevel@tonic-gate  *			supported by this configuration
76*d73ae94eSgc  *	alt_if_setting	alternate setting for the interface identified
777c478bd9Sstevel@tonic-gate  *			by if_index
787c478bd9Sstevel@tonic-gate  *	ep_index	the index in the array of endpoints supported by
797c478bd9Sstevel@tonic-gate  *			this configuration
807c478bd9Sstevel@tonic-gate  *
817c478bd9Sstevel@tonic-gate  * These functions return the length of the returned descriptor structure,
827c478bd9Sstevel@tonic-gate  * or USB_PARSE_ERROR on error.
837c478bd9Sstevel@tonic-gate  *
847c478bd9Sstevel@tonic-gate  * No error is returned if ret_buf_len is too small but
857c478bd9Sstevel@tonic-gate  * the data is truncated
867c478bd9Sstevel@tonic-gate  * This allows successful parsing of descriptors that have been
877c478bd9Sstevel@tonic-gate  * extended in a later rev of the spec.
887c478bd9Sstevel@tonic-gate  */
897c478bd9Sstevel@tonic-gate size_t usb_parse_dev_descr(
907c478bd9Sstevel@tonic-gate 	uchar_t			*buf,	/* from GET_DESCRIPTOR(DEVICE) */
917c478bd9Sstevel@tonic-gate 	size_t			buflen,
927c478bd9Sstevel@tonic-gate 	usb_dev_descr_t		*ret_descr,
937c478bd9Sstevel@tonic-gate 	size_t			ret_buf_len);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate size_t usb_parse_cfg_descr(
977c478bd9Sstevel@tonic-gate 	uchar_t			*buf,	/* from GET_DESCRIPTOR(CONFIGURATION) */
987c478bd9Sstevel@tonic-gate 	size_t			buflen,
997c478bd9Sstevel@tonic-gate 	usb_cfg_descr_t		*ret_descr,
1007c478bd9Sstevel@tonic-gate 	size_t			ret_buf_len);
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 
103*d73ae94eSgc size_t usb_parse_ia_descr(
104*d73ae94eSgc 	uchar_t			*buf,	/* from GET_DESCRIPTOR(CONFIGURATION) */
105*d73ae94eSgc 	size_t			buflen,
106*d73ae94eSgc 	size_t			first_if,
107*d73ae94eSgc 	usb_ia_descr_t		*ret_descr,
108*d73ae94eSgc 	size_t			ret_buf_len);
109*d73ae94eSgc 
110*d73ae94eSgc 
1117c478bd9Sstevel@tonic-gate size_t usb_parse_if_descr(
1127c478bd9Sstevel@tonic-gate 	uchar_t			*buf,	/* from GET_DESCRIPTOR(CONFIGURATION) */
1137c478bd9Sstevel@tonic-gate 	size_t			buflen,
1147c478bd9Sstevel@tonic-gate 	uint_t			if_index,
1157c478bd9Sstevel@tonic-gate 	uint_t			alt_if_setting,
1167c478bd9Sstevel@tonic-gate 	usb_if_descr_t		*ret_descr,
1177c478bd9Sstevel@tonic-gate 	size_t			ret_buf_len);
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate  * the endpoint index is relative to the interface. index 0 is
1227c478bd9Sstevel@tonic-gate  * the first endpoint
1237c478bd9Sstevel@tonic-gate  */
1247c478bd9Sstevel@tonic-gate size_t usb_parse_ep_descr(
1257c478bd9Sstevel@tonic-gate 	uchar_t			*buf,	/* from GET_DESCRIPTOR(CONFIGURATION) */
1267c478bd9Sstevel@tonic-gate 	size_t			buflen,
1277c478bd9Sstevel@tonic-gate 	uint_t			if_index,
1287c478bd9Sstevel@tonic-gate 	uint_t			alt_if_setting,
1297c478bd9Sstevel@tonic-gate 	uint_t			ep_index,
1307c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		*ret_descr,
1317c478bd9Sstevel@tonic-gate 	size_t			ret_buf_len);
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * functions to handle arbitrary descriptors. USBA doesn't know the format
1357c478bd9Sstevel@tonic-gate  * and therefore cannot do any automatic pre-processing.
1367c478bd9Sstevel@tonic-gate  *
1377c478bd9Sstevel@tonic-gate  * In the following:
1387c478bd9Sstevel@tonic-gate  *	buf		buffer containing data returned by GET_DESCRIPTOR
1397c478bd9Sstevel@tonic-gate  *	buflen		length of the data at buf allowing for padding
1407c478bd9Sstevel@tonic-gate  *	fmt		a null terminated string describing the format of
1417c478bd9Sstevel@tonic-gate  *			the data structure for general-purpose byte swapping,
1427c478bd9Sstevel@tonic-gate  *			use NULL for raw access.
1437c478bd9Sstevel@tonic-gate  *			The letters "c", "s", "l", and "L"
1447c478bd9Sstevel@tonic-gate  *			represent 1, 2, 4, and 8 byte quantities,
1457c478bd9Sstevel@tonic-gate  *			respectively.  A descriptor that consists of a
1467c478bd9Sstevel@tonic-gate  *			short and two bytes would be described by "scc\0".
1477c478bd9Sstevel@tonic-gate  *	descr_type	type of the desired descriptor, USB_DESCR_TYPE_ANY
1487c478bd9Sstevel@tonic-gate  *			to get any type.
1497c478bd9Sstevel@tonic-gate  *	descr_index	index of the desired descriptor
1507c478bd9Sstevel@tonic-gate  *	ret_descr	buffer the data is to be returned in
1517c478bd9Sstevel@tonic-gate  *	ret_buf_len	size of the buffer at ret_descr
1527c478bd9Sstevel@tonic-gate  *
1537c478bd9Sstevel@tonic-gate  * Specifying descr_index=0 returns the first descriptor of the specified
1547c478bd9Sstevel@tonic-gate  * type, specifying descr_index=1 returns the second, and so on.
1557c478bd9Sstevel@tonic-gate  *
1567c478bd9Sstevel@tonic-gate  * No error is returned if ret_buf_len is too small. This allows successful
1577c478bd9Sstevel@tonic-gate  * parsing of descriptors that have been extended in a later rev of the spec.
1587c478bd9Sstevel@tonic-gate  */
1597c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_ANY			-1	/* Wild card */
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate size_t usb_parse_CV_cfg_descr(
1627c478bd9Sstevel@tonic-gate 	uchar_t			*buf,	/* from GET_DESCRIPTOR(CONFIGURATION) */
1637c478bd9Sstevel@tonic-gate 	size_t			buflen,
1647c478bd9Sstevel@tonic-gate 	char			*fmt,
1657c478bd9Sstevel@tonic-gate 	uint_t			descr_type,
1667c478bd9Sstevel@tonic-gate 	uint_t			descr_index,
1677c478bd9Sstevel@tonic-gate 	void			*ret_descr,
1687c478bd9Sstevel@tonic-gate 	size_t			ret_buf_len);
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate size_t usb_parse_CV_if_descr(
1727c478bd9Sstevel@tonic-gate 	uchar_t			*buf,	/* from GET_DESCRIPTOR(CONFIGURATION) */
1737c478bd9Sstevel@tonic-gate 	size_t			buflen,
1747c478bd9Sstevel@tonic-gate 	char			*fmt,
1757c478bd9Sstevel@tonic-gate 	uint_t			if_index,
1767c478bd9Sstevel@tonic-gate 	uint_t			alt_if_setting,
1777c478bd9Sstevel@tonic-gate 	uint_t			descr_type,
1787c478bd9Sstevel@tonic-gate 	uint_t			descr_index,
1797c478bd9Sstevel@tonic-gate 	void			*ret_descr,
1807c478bd9Sstevel@tonic-gate 	size_t			ret_buf_len);
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate size_t usb_parse_CV_ep_descr(
1847c478bd9Sstevel@tonic-gate 	uchar_t			*buf,	/* from GET_DESCRIPTOR(CONFIGURATION) */
1857c478bd9Sstevel@tonic-gate 	size_t			buflen,
1867c478bd9Sstevel@tonic-gate 	char			*fmt,
1877c478bd9Sstevel@tonic-gate 	uint_t			if_index,
1887c478bd9Sstevel@tonic-gate 	uint_t			alt_if_setting,
1897c478bd9Sstevel@tonic-gate 	uint_t			ep_index,
1907c478bd9Sstevel@tonic-gate 	uint_t			descr_type,
1917c478bd9Sstevel@tonic-gate 	uint_t			descr_index,
1927c478bd9Sstevel@tonic-gate 	void			*ret_descr,
1937c478bd9Sstevel@tonic-gate 	size_t			ret_buf_len);
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate /*
1977c478bd9Sstevel@tonic-gate  * for unpacking any kind of LE data
1987c478bd9Sstevel@tonic-gate  */
1997c478bd9Sstevel@tonic-gate size_t usb_parse_CV_descr(
2007c478bd9Sstevel@tonic-gate 	char			*format,
2017c478bd9Sstevel@tonic-gate 	uchar_t			*data,
2027c478bd9Sstevel@tonic-gate 	size_t			datalen,
2037c478bd9Sstevel@tonic-gate 	void			*structure,
2047c478bd9Sstevel@tonic-gate 	size_t			structlen);
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate /*
2077c478bd9Sstevel@tonic-gate  * Returns pointer to the raw config cloud. The client should
2087c478bd9Sstevel@tonic-gate  * not free this space.
2097c478bd9Sstevel@tonic-gate  */
2107c478bd9Sstevel@tonic-gate uchar_t *usb_get_raw_cfg_data(
2117c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
2127c478bd9Sstevel@tonic-gate 	size_t			*length);
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate /*
2157c478bd9Sstevel@tonic-gate  * Return pointer to device descriptor
2167c478bd9Sstevel@tonic-gate  */
2177c478bd9Sstevel@tonic-gate usb_dev_descr_t *usb_get_dev_descr(
2187c478bd9Sstevel@tonic-gate 	dev_info_t		*dip);
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate /*
2227c478bd9Sstevel@tonic-gate  * **************************************************************************
2237c478bd9Sstevel@tonic-gate  * List entry functions and definitions
2247c478bd9Sstevel@tonic-gate  * **************************************************************************
2257c478bd9Sstevel@tonic-gate  */
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate /*
2287c478bd9Sstevel@tonic-gate  * Data structure for maintaining lists
2297c478bd9Sstevel@tonic-gate  * This data structure private to USBA and not exposed to HCD or client
2307c478bd9Sstevel@tonic-gate  * driver or hub driver
2317c478bd9Sstevel@tonic-gate  */
2327c478bd9Sstevel@tonic-gate typedef struct usba_list_entry {
2337c478bd9Sstevel@tonic-gate 	struct usba_list_entry	*next;		/* ptr to next element */
2347c478bd9Sstevel@tonic-gate 	struct usba_list_entry	*prev;		/* ptr to previous element */
2357c478bd9Sstevel@tonic-gate 	kmutex_t		list_mutex;	/* mutex that protects queue */
2367c478bd9Sstevel@tonic-gate 	usb_opaque_t		private;	/* ptr to private data */
2377c478bd9Sstevel@tonic-gate 	int			count;		/* for head of the list */
2387c478bd9Sstevel@tonic-gate 						/* counts of entries */
2397c478bd9Sstevel@tonic-gate } usba_list_entry_t;
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(usba_list_entry::list_mutex, usba_list_entry))
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate /* list entry functions. */
2457c478bd9Sstevel@tonic-gate void	usba_init_list(usba_list_entry_t *, usb_opaque_t,
2467c478bd9Sstevel@tonic-gate 					ddi_iblock_cookie_t);
2477c478bd9Sstevel@tonic-gate void	usba_destroy_list(usba_list_entry_t *);
2487c478bd9Sstevel@tonic-gate void	usba_add_to_list(usba_list_entry_t *, usba_list_entry_t *);
2497c478bd9Sstevel@tonic-gate int	usba_rm_from_list(usba_list_entry_t *, usba_list_entry_t *);
2507c478bd9Sstevel@tonic-gate void	usba_move_list(usba_list_entry_t *, usba_list_entry_t *,
2517c478bd9Sstevel@tonic-gate 					ddi_iblock_cookie_t);
2527c478bd9Sstevel@tonic-gate int	usba_check_in_list(usba_list_entry_t *, usba_list_entry_t *);
2537c478bd9Sstevel@tonic-gate int	usba_list_entry_leaks(usba_list_entry_t *, char *);
2547c478bd9Sstevel@tonic-gate int	usba_list_entry_count(usba_list_entry_t *);
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate usb_opaque_t usba_rm_first_pvt_from_list(usba_list_entry_t *);
2577c478bd9Sstevel@tonic-gate usba_list_entry_t *usba_rm_first_from_list(usba_list_entry_t *);
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate /*
2607c478bd9Sstevel@tonic-gate  * **************************************************************************
2617c478bd9Sstevel@tonic-gate  * Kernel interface definitions and functionality
2627c478bd9Sstevel@tonic-gate  * **************************************************************************
2637c478bd9Sstevel@tonic-gate  */
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate /*
2667c478bd9Sstevel@tonic-gate  * USBA private event definitions
2677c478bd9Sstevel@tonic-gate  */
2687c478bd9Sstevel@tonic-gate typedef enum usba_event {
2697c478bd9Sstevel@tonic-gate 	USBA_EVENT_TAG_HOT_REMOVAL = 0,
2707c478bd9Sstevel@tonic-gate 	USBA_EVENT_TAG_HOT_INSERTION = 1,
2717c478bd9Sstevel@tonic-gate 	USBA_EVENT_TAG_PRE_SUSPEND = 2,
2727c478bd9Sstevel@tonic-gate 	USBA_EVENT_TAG_POST_RESUME = 3,
2737c478bd9Sstevel@tonic-gate 	USBA_EVENT_TAG_CPR = -1
2747c478bd9Sstevel@tonic-gate } usba_event_t;
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate #define	USBA_PRE_SUSPEND_EVENT	"SUNW,USBA:USBA_PRE_SUSPEND"
2777c478bd9Sstevel@tonic-gate #define	USBA_POST_RESUME_EVENT	"SUNW,USBA:USBA_POST_RESUME"
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate /*
2807c478bd9Sstevel@tonic-gate  * Get dma attributes from HC.
2817c478bd9Sstevel@tonic-gate  */
2827c478bd9Sstevel@tonic-gate ddi_dma_attr_t *usba_get_hc_dma_attr(dev_info_t *dip);
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate /*
2857c478bd9Sstevel@tonic-gate  * This function calls ndi_devi_bind_driver() to bind the
2867c478bd9Sstevel@tonic-gate  * driver to the device. If the call fails it reports an
2877c478bd9Sstevel@tonic-gate  * error on the console. Attaching of the driver is done
2887c478bd9Sstevel@tonic-gate  * later by devfs framework.
2897c478bd9Sstevel@tonic-gate  */
2907c478bd9Sstevel@tonic-gate int usba_bind_driver(dev_info_t *);
2917c478bd9Sstevel@tonic-gate 
292*d73ae94eSgc /* check whether the dip owns an interface-associaiton */
293*d73ae94eSgc boolean_t usba_owns_ia(dev_info_t *dip);
294*d73ae94eSgc 
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate  * Driver binding functions
2977c478bd9Sstevel@tonic-gate  */
2987c478bd9Sstevel@tonic-gate dev_info_t *usba_ready_device_node(dev_info_t *);
299*d73ae94eSgc dev_info_t *usba_ready_interface_association_node(dev_info_t *,
300*d73ae94eSgc 					uint_t, uint_t *);
3017c478bd9Sstevel@tonic-gate dev_info_t *usba_ready_interface_node(dev_info_t *, uint_t);
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate /* Some Nexus driver functions. */
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate /*
3067c478bd9Sstevel@tonic-gate  * Common bus ctl for hcd, usb_mid and hubd.
3077c478bd9Sstevel@tonic-gate  */
3087c478bd9Sstevel@tonic-gate int	usba_bus_ctl(dev_info_t *, dev_info_t *, ddi_ctl_enum_t,
3097c478bd9Sstevel@tonic-gate 					void *, void *);
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate void	usb_enable_parent_notification(dev_info_t *);
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate /*
3147c478bd9Sstevel@tonic-gate  * Some functions for setting/getting usba_device from dip.
3157c478bd9Sstevel@tonic-gate  */
3167c478bd9Sstevel@tonic-gate struct	usba_device	*usba_get_usba_device(dev_info_t *);
3177c478bd9Sstevel@tonic-gate struct	usba_device	*usba_polled_get_usba_device(dev_info_t *);
3187c478bd9Sstevel@tonic-gate void	usba_set_usba_device(dev_info_t *, struct usba_device *);
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate /* extract NDI event registration info */
3217c478bd9Sstevel@tonic-gate struct	usba_evdata	*usba_get_evdata(dev_info_t *);
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate /*
3247c478bd9Sstevel@tonic-gate  * **************************************************************************
3257c478bd9Sstevel@tonic-gate  * Misc private USBA functions
3267c478bd9Sstevel@tonic-gate  * **************************************************************************
3277c478bd9Sstevel@tonic-gate  */
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate /*
3307c478bd9Sstevel@tonic-gate  * Get policy of a pipe while holding only opaque pipe handle.
3317c478bd9Sstevel@tonic-gate  */
3327c478bd9Sstevel@tonic-gate usb_pipe_policy_t *usba_pipe_get_policy(usb_pipe_handle_t);
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate /*
3357c478bd9Sstevel@tonic-gate  * Check interrupt context and or in USB_CB_INTR_CONTEXT to cb_flags as needed.
3367c478bd9Sstevel@tonic-gate  */
3377c478bd9Sstevel@tonic-gate usb_cb_flags_t	usba_check_intr_context(usb_cb_flags_t);
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate /* returns interface number, zero if driver owns the device */
3407c478bd9Sstevel@tonic-gate uint8_t	usba_get_ifno(dev_info_t *);
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate /*
3437c478bd9Sstevel@tonic-gate  * **************************************************************************
3447c478bd9Sstevel@tonic-gate  * Misc private descriptor definitions and functionality
3457c478bd9Sstevel@tonic-gate  * **************************************************************************
3467c478bd9Sstevel@tonic-gate  */
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate /* default endpoint descriptor */
3497c478bd9Sstevel@tonic-gate extern usb_ep_descr_t   usba_default_ep_descr;
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate /*
3527c478bd9Sstevel@tonic-gate  * The compiler pads the above structures;  the following represent the
3537c478bd9Sstevel@tonic-gate  * unpadded, aggregate data sizes.
3547c478bd9Sstevel@tonic-gate  */
3557c478bd9Sstevel@tonic-gate #define	USB_DEV_DESCR_SIZE	18	/* device descr size */
3567c478bd9Sstevel@tonic-gate #define	USB_CFG_DESCR_SIZE	 9	/* configuration desc. size */
3577c478bd9Sstevel@tonic-gate #define	USBA_CFG_PWR_DESCR_SIZE	18	/* configuration pwr desc. size */
3587c478bd9Sstevel@tonic-gate #define	USB_IF_DESCR_SIZE	 9	/* interface descr size */
3597c478bd9Sstevel@tonic-gate #define	USBA_IF_PWR_DESCR_SIZE	15	/* interface pwr descr size */
3607c478bd9Sstevel@tonic-gate #define	USB_EP_DESCR_SIZE	 7	/* endpoint descr size */
361*d73ae94eSgc #define	USB_IA_DESCR_SIZE	 8	/* interface association descr size */
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate /*
3647c478bd9Sstevel@tonic-gate  * For compatibility with old code.
3657c478bd9Sstevel@tonic-gate  */
3667c478bd9Sstevel@tonic-gate #define	USBA_DESCR_TYPE_CFG_PWR_1_1	0xfe
3677c478bd9Sstevel@tonic-gate #define	USBA_DESCR_TYPE_IF_PWR_1_1	0xff
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate /*
3707c478bd9Sstevel@tonic-gate  * Configuration Power Descriptor
3717c478bd9Sstevel@tonic-gate  *	This reports the power consuption of the device core
3727c478bd9Sstevel@tonic-gate  *	for all types of USB devices.
3737c478bd9Sstevel@tonic-gate  */
3747c478bd9Sstevel@tonic-gate typedef struct usba_cfg_pwr_descr {
3757c478bd9Sstevel@tonic-gate 	uint8_t		bLength;	/* size of this descriptor 0x12 */
3767c478bd9Sstevel@tonic-gate 	uint8_t		bDescriptorType;	/* config pwr descr 0x07 */
3777c478bd9Sstevel@tonic-gate 	uint16_t	SelfPowerConsumedD0_l;	/* power consumed lower word */
3787c478bd9Sstevel@tonic-gate 	uint8_t		SelfPowerConsumedD0_h;	/* power consumed upper byte */
3797c478bd9Sstevel@tonic-gate 	uint8_t		bPowerSummaryId;	/* ID for own power devices */
3807c478bd9Sstevel@tonic-gate 	uint8_t		bBusPowerSavingD1;	/* power saving in D1 */
3817c478bd9Sstevel@tonic-gate 	uint8_t		bSelfPowerSavingD1;	/* power saving in D1 */
3827c478bd9Sstevel@tonic-gate 	uint8_t		bBusPowerSavingD2;	/* power saving in D2 */
3837c478bd9Sstevel@tonic-gate 	uint8_t		bSelfPowerSavingD2;	/* power saving in D2 */
3847c478bd9Sstevel@tonic-gate 	uint8_t		bBusPowerSavingD3;	/* power saving in D3 */
3857c478bd9Sstevel@tonic-gate 	uint8_t		bSelfPowerSavingD3;	/* power saving in D3 */
3867c478bd9Sstevel@tonic-gate 	uint16_t	TransitionTimeFromD1;	/* D1 -> D0 transition time */
3877c478bd9Sstevel@tonic-gate 	uint16_t	TransitionTimeFromD2;	/* D2 -> D0 transition time */
3887c478bd9Sstevel@tonic-gate 	uint16_t	TransitionTimeFromD3;	/* D3 -> D0 transition time */
3897c478bd9Sstevel@tonic-gate } usba_cfg_pwr_descr_t;
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate /*
3927c478bd9Sstevel@tonic-gate  * Interface Power Descriptor
3937c478bd9Sstevel@tonic-gate  *	This reports the power states implemented by the interface
3947c478bd9Sstevel@tonic-gate  *	and its wake-up capabilities.
3957c478bd9Sstevel@tonic-gate  */
3967c478bd9Sstevel@tonic-gate typedef struct usba_if_pwr_descr {
3977c478bd9Sstevel@tonic-gate 	uint8_t		bLength;	/* size of this descriptor 0x0F */
3987c478bd9Sstevel@tonic-gate 	uint8_t		bDescriptorType;	/* i/f pwr descr 0x08 */
3997c478bd9Sstevel@tonic-gate 	uint8_t		bmCapabilitiesFlags;	/* wakeup & pwr transition */
4007c478bd9Sstevel@tonic-gate 	uint8_t		bBusPowerSavingD1;	/* power saving in D1 */
4017c478bd9Sstevel@tonic-gate 	uint8_t		bSelfPowerSavingD1;	/* power saving in D1 */
4027c478bd9Sstevel@tonic-gate 	uint8_t		bBusPowerSavingD2;	/* power saving in D2 */
4037c478bd9Sstevel@tonic-gate 	uint8_t		bSelfPowerSavingD2;	/* power saving in D2 */
4047c478bd9Sstevel@tonic-gate 	uint8_t		bBusPowerSavingD3;	/* power saving in D3 */
4057c478bd9Sstevel@tonic-gate 	uint8_t		bSelfPowerSavingD3;	/* power saving in D3 */
4067c478bd9Sstevel@tonic-gate 	uint16_t	TransitionTimeFromD1;	/* D1 -> D0 transition time */
4077c478bd9Sstevel@tonic-gate 	uint16_t	TransitionTimeFromD2;	/* D2 -> D0 transition time */
4087c478bd9Sstevel@tonic-gate 	uint16_t	TransitionTimeFromD3;	/* D3 -> D0 transition time */
4097c478bd9Sstevel@tonic-gate } usba_if_pwr_descr_t;
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate size_t usba_parse_cfg_pwr_descr(uchar_t *, size_t, usba_cfg_pwr_descr_t *,
4127c478bd9Sstevel@tonic-gate 						size_t);
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate size_t usba_parse_if_pwr_descr(uchar_t *, size_t buflen, uint_t,
4157c478bd9Sstevel@tonic-gate 	uint_t, usba_if_pwr_descr_t *, size_t);
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate /*
4187c478bd9Sstevel@tonic-gate  * Returns (at ret_descr) a null-terminated string.  Null termination is
4197c478bd9Sstevel@tonic-gate  * guaranteed, even if the string is longer than the buffer.  Thus, a
4207c478bd9Sstevel@tonic-gate  * maximum of (ret_buf_len - 1) characters are returned.
4217c478bd9Sstevel@tonic-gate  *
4227c478bd9Sstevel@tonic-gate  * XXX is this needed when there is usb_get_string_descriptor
4237c478bd9Sstevel@tonic-gate  * If so, then more comments about how it differs?
4247c478bd9Sstevel@tonic-gate  */
4257c478bd9Sstevel@tonic-gate size_t usba_ascii_string_descr(uchar_t *, size_t, char *, size_t);
4267c478bd9Sstevel@tonic-gate 
427*d73ae94eSgc 
428*d73ae94eSgc /*
429*d73ae94eSgc  * usb common power management, for usb_mid, usb_ia and maybe other simple
430*d73ae94eSgc  * drivers.
431*d73ae94eSgc  */
432*d73ae94eSgc typedef struct usb_common_power_struct {
433*d73ae94eSgc 	void		*uc_usb_statep;	/* points back to state structure */
434*d73ae94eSgc 
435*d73ae94eSgc 	uint8_t		uc_wakeup_enabled;
436*d73ae94eSgc 
437*d73ae94eSgc 	/* this is the bit mask of the power states that device has */
438*d73ae94eSgc 	uint8_t		uc_pwr_states;
439*d73ae94eSgc 
440*d73ae94eSgc 	/* wakeup and power transition capabilites of an interface */
441*d73ae94eSgc 	uint8_t		uc_pm_capabilities;
442*d73ae94eSgc 
443*d73ae94eSgc 	uint8_t		uc_current_power;	/* current power level */
444*d73ae94eSgc } usb_common_power_t;
445*d73ae94eSgc 
446*d73ae94eSgc /* warlock directives, stable data */
447*d73ae94eSgc _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_common_power_t::uc_usb_statep))
448*d73ae94eSgc _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_common_power_t::uc_wakeup_enabled))
449*d73ae94eSgc _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_common_power_t::uc_pwr_states))
450*d73ae94eSgc _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_common_power_t::uc_pm_capabilities))
451*d73ae94eSgc 
452*d73ae94eSgc /* power management */
453*d73ae94eSgc int usba_common_power(dev_info_t *, usb_common_power_t *, int *, int);
454*d73ae94eSgc 
455*d73ae94eSgc /*
456*d73ae94eSgc  * usb common events handler for usb_mid, usb_ia and maybe other nexus
457*d73ae94eSgc  * drivers.
458*d73ae94eSgc  */
459*d73ae94eSgc 
460*d73ae94eSgc void usba_common_register_events(dev_info_t *, uint_t,
461*d73ae94eSgc 	void (*)(dev_info_t *, ddi_eventcookie_t, void *, void *));
462*d73ae94eSgc 
463*d73ae94eSgc void usba_common_unregister_events(dev_info_t *, uint_t);
464*d73ae94eSgc 
465*d73ae94eSgc 
4667c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4677c478bd9Sstevel@tonic-gate }
4687c478bd9Sstevel@tonic-gate #endif
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate #endif	/* _SYS_USB_USBA_USBA_PRIVATE_H */
471