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