Home | History | Annotate | Line # | Download | only in usb
usbdi.h revision 1.33
      1 /*	$NetBSD: usbdi.h,v 1.33 1999/11/17 23:00:50 augustss Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Lennart Augustsson (augustss (at) carlstedt.se) at
      9  * Carlstedt Research & Technology.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *        This product includes software developed by the NetBSD
     22  *        Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 typedef struct usbd_bus		*usbd_bus_handle;
     41 typedef struct usbd_device	*usbd_device_handle;
     42 typedef struct usbd_interface	*usbd_interface_handle;
     43 typedef struct usbd_pipe	*usbd_pipe_handle;
     44 typedef struct usbd_xfer	*usbd_xfer_handle;
     45 typedef void			*usbd_private_handle;
     46 
     47 typedef enum {		/* keep in sync with usbd_status_msgs */
     48 	USBD_NORMAL_COMPLETION = 0, /* must be 0 */
     49 	USBD_IN_PROGRESS,
     50 	/* errors */
     51 	USBD_PENDING_REQUESTS,
     52 	USBD_NOT_STARTED,
     53 	USBD_INVAL,
     54 	USBD_NOMEM,
     55 	USBD_CANCELLED,
     56 	USBD_BAD_ADDRESS,
     57 	USBD_IN_USE,
     58 	USBD_NO_ADDR,
     59 	USBD_SET_ADDR_FAILED,
     60 	USBD_NO_POWER,
     61 	USBD_TOO_DEEP,
     62 	USBD_IOERROR,
     63 	USBD_NOT_CONFIGURED,
     64 	USBD_TIMEOUT,
     65 	USBD_SHORT_XFER,
     66 	USBD_STALLED,
     67 	USBD_INTERRUPTED,
     68 
     69 	USBD_ERROR_MAX,		/* must be last */
     70 } usbd_status;
     71 
     72 typedef int usbd_lock_token;
     73 
     74 typedef void (*usbd_callback) __P((usbd_xfer_handle, usbd_private_handle,
     75 				   usbd_status));
     76 
     77 /* Open flags */
     78 #define USBD_EXCLUSIVE_USE	0x01
     79 
     80 /* Request flags */
     81 #define USBD_NO_COPY		0x01	/* do not copy data to DMA buffer */
     82 #define USBD_SYNCHRONOUS	0x02	/* wait for completion */
     83 /* in usb.h #define USBD_SHORT_XFER_OK	0x04*/	/* allow short reads */
     84 
     85 #define USBD_NO_TIMEOUT 0
     86 #define USBD_DEFAULT_TIMEOUT 5000 /* ms = 5 s */
     87 
     88 #if defined(__FreeBSD__)
     89 #define USB_CDEV_MAJOR 108
     90 #endif
     91 
     92 usbd_status usbd_open_pipe
     93 	__P((usbd_interface_handle iface, u_int8_t address,
     94 	     u_int8_t flags, usbd_pipe_handle *pipe));
     95 usbd_status usbd_close_pipe	__P((usbd_pipe_handle pipe));
     96 usbd_status usbd_transfer	__P((usbd_xfer_handle req));
     97 usbd_xfer_handle usbd_alloc_xfer __P((usbd_device_handle));
     98 usbd_status usbd_free_xfer	__P((usbd_xfer_handle xfer));
     99 void usbd_setup_xfer
    100 	__P((usbd_xfer_handle xfer, usbd_pipe_handle pipe,
    101 	     usbd_private_handle priv, void *buffer,
    102 	     u_int32_t length, u_int16_t flags, u_int32_t timeout,
    103 	     usbd_callback));
    104 void usbd_setup_default_xfer
    105 	__P((usbd_xfer_handle xfer, usbd_device_handle dev,
    106 	     usbd_private_handle priv, u_int32_t timeout,
    107 	     usb_device_request_t *req,  void *buffer,
    108 	     u_int32_t length, u_int16_t flags, usbd_callback));
    109 void usbd_setup_isoc_xfer
    110 	__P((usbd_xfer_handle xfer, usbd_pipe_handle pipe,
    111 	     usbd_private_handle priv, u_int16_t *frlengths,
    112 	     u_int32_t nframes, u_int16_t flags, usbd_callback));
    113 void usbd_get_xfer_status
    114 	__P((usbd_xfer_handle xfer, usbd_private_handle *priv,
    115 	     void **buffer, u_int32_t *count, usbd_status *status));
    116 usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor
    117 	__P((usbd_interface_handle iface, u_int8_t address));
    118 usbd_status usbd_abort_pipe __P((usbd_pipe_handle pipe));
    119 usbd_status usbd_clear_endpoint_stall __P((usbd_pipe_handle pipe));
    120 usbd_status usbd_clear_endpoint_stall_async __P((usbd_pipe_handle pipe));
    121 usbd_status usbd_endpoint_count
    122 	__P((usbd_interface_handle dev, u_int8_t *count));
    123 usbd_status usbd_interface_count
    124 	__P((usbd_device_handle dev, u_int8_t *count));
    125 usbd_status usbd_interface2device_handle
    126 	__P((usbd_interface_handle iface, usbd_device_handle *dev));
    127 usbd_status usbd_device2interface_handle
    128 	__P((usbd_device_handle dev, u_int8_t ifaceno, usbd_interface_handle *iface));
    129 
    130 usbd_device_handle usbd_pipe2device_handle __P((usbd_pipe_handle));
    131 void *usbd_alloc_buffer __P((usbd_xfer_handle req, u_int32_t size));
    132 void usbd_free_buffer __P((usbd_xfer_handle req));
    133 void *usbd_get_buffer __P((usbd_xfer_handle xfer));
    134 usbd_status usbd_sync_transfer	__P((usbd_xfer_handle req));
    135 usbd_status usbd_open_pipe_intr
    136 	__P((usbd_interface_handle iface, u_int8_t address,
    137 	     u_int8_t flags, usbd_pipe_handle *pipe,
    138 	     usbd_private_handle priv, void *buffer,
    139 	     u_int32_t length, usbd_callback));
    140 usbd_status usbd_do_request
    141 	__P((usbd_device_handle pipe, usb_device_request_t *req, void *data));
    142 usbd_status usbd_do_request_async
    143 	__P((usbd_device_handle pipe, usb_device_request_t *req, void *data));
    144 usbd_status usbd_do_request_flags
    145 	__P((usbd_device_handle pipe, usb_device_request_t *req,
    146 	     void *data, u_int16_t flags, int *));
    147 usb_interface_descriptor_t *usbd_get_interface_descriptor
    148 	__P((usbd_interface_handle iface));
    149 usb_config_descriptor_t *usbd_get_config_descriptor
    150 	__P((usbd_device_handle dev));
    151 usb_device_descriptor_t *usbd_get_device_descriptor
    152 	__P((usbd_device_handle dev));
    153 usbd_status usbd_set_interface __P((usbd_interface_handle, int));
    154 int usbd_get_no_alts __P((usb_config_descriptor_t *, int));
    155 usbd_status	usbd_get_interface
    156 	__P((usbd_interface_handle iface, u_int8_t *aiface));
    157 void usbd_fill_deviceinfo
    158 	__P((usbd_device_handle dev, struct usb_device_info *di));
    159 int usbd_get_interface_altindex __P((usbd_interface_handle iface));
    160 
    161 usb_interface_descriptor_t *usbd_find_idesc
    162 	__P((usb_config_descriptor_t *cd, int iindex, int ano));
    163 usb_endpoint_descriptor_t *usbd_find_edesc
    164 	__P((usb_config_descriptor_t *cd, int ifaceidx, int altidx,
    165 	     int endptidx));
    166 
    167 void usbd_dopoll __P((usbd_interface_handle));
    168 void usbd_set_polling __P((usbd_interface_handle iface, int on));
    169 
    170 const char *usbd_errstr __P((usbd_status err));
    171 
    172 void usbd_add_event __P((int, usbd_device_handle));
    173 
    174 /* NetBSD attachment information */
    175 
    176 /* Attach data */
    177 struct usb_attach_arg {
    178 	int			port;
    179 	int			configno;
    180 	int			ifaceno;
    181 	int			vendor;
    182 	int			product;
    183 	int			release;
    184 	usbd_device_handle	device;	/* current device */
    185 	usbd_interface_handle	iface; /* current interface */
    186 	int			usegeneric;
    187 	usbd_interface_handle  *ifaces;	/* all interfaces */
    188 	int			nifaces; /* number of interfaces */
    189 };
    190 
    191 #if defined(__NetBSD__) || defined(__OpenBSD__)
    192 /* Match codes. */
    193 /* First five codes is for a whole device. */
    194 #define UMATCH_VENDOR_PRODUCT_REV			14
    195 #define UMATCH_VENDOR_PRODUCT				13
    196 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO			12
    197 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO		11
    198 #define UMATCH_DEVCLASS_DEVSUBCLASS			10
    199 /* Next six codes are for interfaces. */
    200 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE		 9
    201 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE		 8
    202 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO		 7
    203 #define UMATCH_VENDOR_IFACESUBCLASS			 6
    204 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO	 5
    205 #define UMATCH_IFACECLASS_IFACESUBCLASS			 4
    206 #define UMATCH_IFACECLASS				 3
    207 #define UMATCH_IFACECLASS_GENERIC			 2
    208 /* Generic driver */
    209 #define UMATCH_GENERIC					 1
    210 /* No match */
    211 #define UMATCH_NONE					 0
    212 
    213 #elif defined(__FreeBSD__)
    214 /* FreeBSD needs values less than zero */
    215 #define UMATCH_VENDOR_PRODUCT_REV			(-10)
    216 #define UMATCH_VENDOR_PRODUCT				(-20)
    217 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO			(-30)
    218 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO		(-40)
    219 #define UMATCH_DEVCLASS_DEVSUBCLASS			(-50)
    220 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE		(-60)
    221 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE		(-70)
    222 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO		(-80)
    223 #define UMATCH_VENDOR_IFACESUBCLASS			(-90)
    224 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO	(-100)
    225 #define UMATCH_IFACECLASS_IFACESUBCLASS			(-110)
    226 #define UMATCH_IFACECLASS				(-120)
    227 #define UMATCH_IFACECLASS_GENERIC			(-130)
    228 #define UMATCH_GENERIC					(-140)
    229 #define UMATCH_NONE					(ENXIO)
    230 
    231 #endif
    232 
    233 void usbd_devinfo __P((usbd_device_handle, int, char *));
    234 struct usbd_quirks *usbd_get_quirks __P((usbd_device_handle));
    235 usb_endpoint_descriptor_t *usbd_get_endpoint_descriptor
    236 	__P((usbd_interface_handle iface, u_int8_t address));
    237 
    238 #if defined(__FreeBSD__)
    239 int usbd_driver_load    __P((module_t mod, int what, void *arg));
    240 #endif
    241 
    242 /* XXX */
    243 #define splusb splbio
    244 #define IPL_USB IPL_BIO
    245 /* XXX */
    246 
    247