Home | History | Annotate | Line # | Download | only in usb
usbdivar.h revision 1.39.2.2
      1  1.39.2.2  mycroft /*	$NetBSD: usbdivar.h,v 1.39.2.2 1999/11/10 04:20:00 mycroft Exp $	*/
      2  1.39.2.2  mycroft 
      3  1.39.2.2  mycroft /*
      4  1.39.2.2  mycroft  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.39.2.2  mycroft  * All rights reserved.
      6  1.39.2.2  mycroft  *
      7  1.39.2.2  mycroft  * This code is derived from software contributed to The NetBSD Foundation
      8  1.39.2.2  mycroft  * by Lennart Augustsson (augustss (at) carlstedt.se) at
      9  1.39.2.2  mycroft  * Carlstedt Research & Technology.
     10  1.39.2.2  mycroft  *
     11  1.39.2.2  mycroft  * Redistribution and use in source and binary forms, with or without
     12  1.39.2.2  mycroft  * modification, are permitted provided that the following conditions
     13  1.39.2.2  mycroft  * are met:
     14  1.39.2.2  mycroft  * 1. Redistributions of source code must retain the above copyright
     15  1.39.2.2  mycroft  *    notice, this list of conditions and the following disclaimer.
     16  1.39.2.2  mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.39.2.2  mycroft  *    notice, this list of conditions and the following disclaimer in the
     18  1.39.2.2  mycroft  *    documentation and/or other materials provided with the distribution.
     19  1.39.2.2  mycroft  * 3. All advertising materials mentioning features or use of this software
     20  1.39.2.2  mycroft  *    must display the following acknowledgement:
     21  1.39.2.2  mycroft  *        This product includes software developed by the NetBSD
     22  1.39.2.2  mycroft  *        Foundation, Inc. and its contributors.
     23  1.39.2.2  mycroft  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.39.2.2  mycroft  *    contributors may be used to endorse or promote products derived
     25  1.39.2.2  mycroft  *    from this software without specific prior written permission.
     26  1.39.2.2  mycroft  *
     27  1.39.2.2  mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.39.2.2  mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.39.2.2  mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.39.2.2  mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.39.2.2  mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.39.2.2  mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.39.2.2  mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.39.2.2  mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.39.2.2  mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.39.2.2  mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.39.2.2  mycroft  * POSSIBILITY OF SUCH DAMAGE.
     38  1.39.2.2  mycroft  */
     39  1.39.2.2  mycroft 
     40  1.39.2.2  mycroft /* From usb_mem.h */
     41  1.39.2.2  mycroft DECLARE_USB_DMA_T;
     42  1.39.2.2  mycroft 
     43  1.39.2.2  mycroft struct usbd_request;
     44  1.39.2.2  mycroft struct usbd_pipe;
     45  1.39.2.2  mycroft 
     46  1.39.2.2  mycroft struct usbd_endpoint {
     47  1.39.2.2  mycroft 	usb_endpoint_descriptor_t *edesc;
     48  1.39.2.2  mycroft 	int			refcnt;
     49  1.39.2.2  mycroft };
     50  1.39.2.2  mycroft 
     51  1.39.2.2  mycroft struct usbd_bus_methods {
     52  1.39.2.2  mycroft 	usbd_status	      (*open_pipe)__P((struct usbd_pipe *pipe));
     53  1.39.2.2  mycroft 	void		      (*do_poll)__P((struct usbd_bus *));
     54  1.39.2.2  mycroft 	usbd_status	      (*allocm)__P((struct usbd_bus *, usb_dma_t *,
     55  1.39.2.2  mycroft 					    u_int32_t bufsize));
     56  1.39.2.2  mycroft 	void		      (*freem)__P((struct usbd_bus *, usb_dma_t *));
     57  1.39.2.2  mycroft };
     58  1.39.2.2  mycroft 
     59  1.39.2.2  mycroft struct usbd_pipe_methods {
     60  1.39.2.2  mycroft 	usbd_status	      (*transfer)__P((usbd_request_handle reqh));
     61  1.39.2.2  mycroft 	usbd_status	      (*start)__P((usbd_request_handle reqh));
     62  1.39.2.2  mycroft 	void		      (*abort)__P((usbd_request_handle reqh));
     63  1.39.2.2  mycroft 	void		      (*close)__P((usbd_pipe_handle pipe));
     64  1.39.2.2  mycroft 	void		      (*cleartoggle)__P((usbd_pipe_handle pipe));
     65  1.39.2.2  mycroft 	void		      (*done)__P((usbd_request_handle reqh));
     66  1.39.2.2  mycroft };
     67  1.39.2.2  mycroft 
     68  1.39.2.2  mycroft struct usbd_port {
     69  1.39.2.2  mycroft 	usb_port_status_t	status;
     70  1.39.2.2  mycroft 	u_int16_t		power;	/* mA of current on port */
     71  1.39.2.2  mycroft 	u_int8_t		portno;
     72  1.39.2.2  mycroft 	u_int8_t		restartcnt;
     73  1.39.2.2  mycroft #define USBD_RESTART_MAX 5
     74  1.39.2.2  mycroft 	struct usbd_device     *device;
     75  1.39.2.2  mycroft 	struct usbd_device     *parent;	/* The ports hub */
     76  1.39.2.2  mycroft };
     77  1.39.2.2  mycroft 
     78  1.39.2.2  mycroft struct usbd_hub {
     79  1.39.2.2  mycroft 	usbd_status	      (*explore)__P((usbd_device_handle hub));
     80  1.39.2.2  mycroft 	void		       *hubsoftc;
     81  1.39.2.2  mycroft 	usb_hub_descriptor_t	hubdesc;
     82  1.39.2.2  mycroft 	struct usbd_port        ports[1];
     83  1.39.2.2  mycroft };
     84  1.39.2.2  mycroft 
     85  1.39.2.2  mycroft struct usb_softc;
     86  1.39.2.2  mycroft 
     87  1.39.2.2  mycroft /*****/
     88  1.39.2.2  mycroft 
     89  1.39.2.2  mycroft struct usbd_bus {
     90  1.39.2.2  mycroft 	/* Filled by HC driver */
     91  1.39.2.2  mycroft 	USBBASEDEVICE		bdev; /* base device, host adapter */
     92  1.39.2.2  mycroft 	struct usbd_bus_methods	*methods;
     93  1.39.2.2  mycroft 	u_int32_t		pipe_size; /* size of a pipe struct */
     94  1.39.2.2  mycroft 	/* Filled by usb driver */
     95  1.39.2.2  mycroft 	struct usbd_device     *root_hub;
     96  1.39.2.2  mycroft 	usbd_device_handle	devices[USB_MAX_DEVICES];
     97  1.39.2.2  mycroft 	char			needs_explore;/* a hub a signalled a change */
     98  1.39.2.2  mycroft 	char			use_polling;
     99  1.39.2.2  mycroft 	struct usb_softc       *usbctl;
    100  1.39.2.2  mycroft 	struct usb_device_stats	stats;
    101  1.39.2.2  mycroft 	int 			intr_context;
    102  1.39.2.2  mycroft 	u_int			no_intrs;
    103  1.39.2.2  mycroft #if defined(__NetBSD__) || defined(__OpenBSD__)
    104  1.39.2.2  mycroft 	bus_dma_tag_t		dmatag;	/* DMA tag */
    105  1.39.2.2  mycroft #endif
    106  1.39.2.2  mycroft };
    107  1.39.2.2  mycroft 
    108  1.39.2.2  mycroft struct usbd_device {
    109  1.39.2.2  mycroft 	struct usbd_bus	       *bus;
    110  1.39.2.2  mycroft 	struct usbd_pipe       *default_pipe;
    111  1.39.2.2  mycroft 	u_int8_t		address;
    112  1.39.2.2  mycroft 	u_int8_t		depth;
    113  1.39.2.2  mycroft 	u_int8_t		lowspeed;
    114  1.39.2.2  mycroft 	u_int16_t		power;
    115  1.39.2.2  mycroft 	u_int8_t		self_powered;
    116  1.39.2.2  mycroft 	int			config;
    117  1.39.2.2  mycroft 	int			langid;	/* language to use for strings */
    118  1.39.2.2  mycroft #define USBD_NOLANG (-1)
    119  1.39.2.2  mycroft 	usb_event_cookie_t	cookie;	/* unique connection id */
    120  1.39.2.2  mycroft 	struct usbd_port       *powersrc;
    121  1.39.2.2  mycroft 	struct usbd_endpoint	def_ep;	/* for pipe 0 */
    122  1.39.2.2  mycroft 	usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
    123  1.39.2.2  mycroft 	struct usbd_interface  *ifaces;
    124  1.39.2.2  mycroft 	usb_device_descriptor_t ddesc;
    125  1.39.2.2  mycroft 	usb_config_descriptor_t *cdesc;	/* full config descr */
    126  1.39.2.2  mycroft 	struct usbd_quirks     *quirks;
    127  1.39.2.2  mycroft 	struct usbd_hub	       *hub; /* only if this is a hub */
    128  1.39.2.2  mycroft 	device_ptr_t	       *subdevs;	/* sub-devices, 0 terminated */
    129  1.39.2.2  mycroft };
    130  1.39.2.2  mycroft 
    131  1.39.2.2  mycroft struct usbd_interface {
    132  1.39.2.2  mycroft 	struct usbd_device     *device;
    133  1.39.2.2  mycroft 	usb_interface_descriptor_t *idesc;
    134  1.39.2.2  mycroft 	int			index;
    135  1.39.2.2  mycroft 	int			altindex;
    136  1.39.2.2  mycroft 	struct usbd_endpoint   *endpoints;
    137  1.39.2.2  mycroft 	void		       *priv;
    138  1.39.2.2  mycroft 	LIST_HEAD(, usbd_pipe)	pipes;
    139  1.39.2.2  mycroft };
    140  1.39.2.2  mycroft 
    141  1.39.2.2  mycroft struct usbd_pipe {
    142  1.39.2.2  mycroft 	struct usbd_interface  *iface;
    143  1.39.2.2  mycroft 	struct usbd_device     *device;
    144  1.39.2.2  mycroft 	struct usbd_endpoint   *endpoint;
    145  1.39.2.2  mycroft 	int			refcnt;
    146  1.39.2.2  mycroft 	char			running;
    147  1.39.2.2  mycroft 	SIMPLEQ_HEAD(, usbd_request) queue;
    148  1.39.2.2  mycroft 	LIST_ENTRY(usbd_pipe)	next;
    149  1.39.2.2  mycroft 
    150  1.39.2.2  mycroft 	usbd_request_handle     intrreqh; /* used for repeating requests */
    151  1.39.2.2  mycroft 	char			repeat;
    152  1.39.2.2  mycroft 
    153  1.39.2.2  mycroft 	/* Filled by HC driver. */
    154  1.39.2.2  mycroft 	struct usbd_pipe_methods *methods;
    155  1.39.2.2  mycroft };
    156  1.39.2.2  mycroft 
    157  1.39.2.2  mycroft struct usbd_request {
    158  1.39.2.2  mycroft 	struct usbd_pipe       *pipe;
    159  1.39.2.2  mycroft 	void		       *priv;
    160  1.39.2.2  mycroft 	void		       *buffer;
    161  1.39.2.2  mycroft 	u_int32_t		length;
    162  1.39.2.2  mycroft 	u_int32_t		actlen;
    163  1.39.2.2  mycroft 	u_int16_t		flags;
    164  1.39.2.2  mycroft 	u_int32_t		timeout;
    165  1.39.2.2  mycroft 	usbd_status		status;
    166  1.39.2.2  mycroft 	usbd_callback		callback;
    167  1.39.2.2  mycroft 	__volatile char		done;
    168  1.39.2.2  mycroft 
    169  1.39.2.2  mycroft 	/* For control pipe */
    170  1.39.2.2  mycroft 	usb_device_request_t	request;
    171  1.39.2.2  mycroft 
    172  1.39.2.2  mycroft 	/* For isoc */
    173  1.39.2.2  mycroft 	u_int16_t		*frlengths;
    174  1.39.2.2  mycroft 	int			nframes;
    175  1.39.2.2  mycroft 
    176  1.39.2.2  mycroft 	/* For memory allocation */
    177  1.39.2.2  mycroft 	struct usbd_device     *device;
    178  1.39.2.2  mycroft 	usb_dma_t		dmabuf;
    179  1.39.2.2  mycroft 
    180  1.39.2.2  mycroft 	int			rqflags;
    181  1.39.2.2  mycroft #define URQ_REQUEST	0x01
    182  1.39.2.2  mycroft #define URQ_AUTO_DMABUF	0x10
    183  1.39.2.2  mycroft #define URQ_DEV_DMABUF	0x20
    184  1.39.2.2  mycroft 
    185  1.39.2.2  mycroft 	SIMPLEQ_ENTRY(usbd_request) next;
    186  1.39.2.2  mycroft 
    187  1.39.2.2  mycroft 	void		       *hcpriv; /* private use by the HC driver */
    188  1.39.2.2  mycroft 	int			hcprivint; /* ditto */
    189  1.39.2.2  mycroft 
    190  1.39.2.2  mycroft #if defined(__FreeBSD__)
    191  1.39.2.2  mycroft 	struct callout_handle  timo_handle;
    192  1.39.2.2  mycroft #endif
    193  1.39.2.2  mycroft };
    194  1.39.2.2  mycroft 
    195  1.39.2.2  mycroft void usbd_init __P((void));
    196  1.39.2.2  mycroft void usbd_finish __P((void));
    197  1.39.2.2  mycroft 
    198  1.39.2.2  mycroft /* Routines from usb_subr.c */
    199  1.39.2.2  mycroft int		usbctlprint __P((void *, const char *));
    200  1.39.2.2  mycroft void		usb_delay_ms __P((usbd_bus_handle, u_int));
    201  1.39.2.2  mycroft void		usbd_devinfo_vp __P((usbd_device_handle, char *, char *));
    202  1.39.2.2  mycroft usbd_status	usbd_reset_port __P((usbd_device_handle dev,
    203  1.39.2.2  mycroft 				     int port, usb_port_status_t *ps));
    204  1.39.2.2  mycroft usbd_status	usbd_setup_pipe __P((usbd_device_handle dev,
    205  1.39.2.2  mycroft 				     usbd_interface_handle iface,
    206  1.39.2.2  mycroft 				     struct usbd_endpoint *,
    207  1.39.2.2  mycroft 				     usbd_pipe_handle *pipe));
    208  1.39.2.2  mycroft usbd_status	usbd_new_device __P((device_ptr_t parent,
    209  1.39.2.2  mycroft 				     usbd_bus_handle bus, int depth,
    210  1.39.2.2  mycroft 				     int lowspeed, int port,
    211  1.39.2.2  mycroft 				     struct usbd_port *));
    212  1.39.2.2  mycroft void		usbd_remove_device __P((usbd_device_handle,
    213  1.39.2.2  mycroft 					struct usbd_port *));
    214  1.39.2.2  mycroft int		usbd_printBCD __P((char *cp, int bcd));
    215  1.39.2.2  mycroft usbd_status	usbd_fill_iface_data __P((usbd_device_handle dev,
    216  1.39.2.2  mycroft 					  int i, int a));
    217  1.39.2.2  mycroft void		usb_free_device __P((usbd_device_handle));
    218  1.39.2.2  mycroft 
    219  1.39.2.2  mycroft usbd_status	usb_insert_transfer __P((usbd_request_handle reqh));
    220  1.39.2.2  mycroft void		usb_transfer_complete __P((usbd_request_handle reqh));
    221  1.39.2.2  mycroft void		usb_disconnect_port __P((struct usbd_port *up, device_ptr_t));
    222  1.39.2.2  mycroft 
    223  1.39.2.2  mycroft /* Routines from usb.c */
    224  1.39.2.2  mycroft int		usb_bus_count __P((void));
    225  1.39.2.2  mycroft void		usb_needs_explore __P((usbd_bus_handle));
    226  1.39.2.2  mycroft 
    227  1.39.2.2  mycroft #ifdef DIAGNOSTIC
    228  1.39.2.2  mycroft #define SPLUSBCHECK \
    229  1.39.2.2  mycroft 	do { int _s = splusb(), _su = splusb(); \
    230  1.39.2.2  mycroft 	     extern int cold; \
    231  1.39.2.2  mycroft              if (!cold && _s != _su) printf("SPLUSBCHECK failed 0x%x!=0x%x, %s:%d\n", \
    232  1.39.2.2  mycroft 				   _s, _su, __FILE__, __LINE__); \
    233  1.39.2.2  mycroft 	     splx(_s); \
    234  1.39.2.2  mycroft         } while (0)
    235  1.39.2.2  mycroft #else
    236  1.39.2.2  mycroft #define SPLUSBCHECK
    237  1.39.2.2  mycroft #endif
    238  1.39.2.2  mycroft 
    239  1.39.2.2  mycroft /* Locator stuff. */
    240  1.39.2.2  mycroft 
    241  1.39.2.2  mycroft #if defined(__NetBSD__)
    242  1.39.2.2  mycroft #include "locators.h"
    243  1.39.2.2  mycroft #elif defined(__FreeBSD__) || defined(__OpenBSD__)
    244  1.39.2.2  mycroft /* XXX these values are used to statically bind some elements in the USB tree
    245  1.39.2.2  mycroft  * to specific driver instances. This should be somehow emulated in FreeBSD
    246  1.39.2.2  mycroft  * but can be done later on.
    247  1.39.2.2  mycroft  * The values are copied from the files.usb file in the NetBSD sources.
    248  1.39.2.2  mycroft  */
    249  1.39.2.2  mycroft #define UHUBCF_PORT_DEFAULT -1
    250  1.39.2.2  mycroft #define UHUBCF_CONFIGURATION_DEFAULT -1
    251  1.39.2.2  mycroft #define UHUBCF_INTERFACE_DEFAULT -1
    252  1.39.2.2  mycroft #define UHUBCF_VENDOR_DEFAULT -1
    253  1.39.2.2  mycroft #define UHUBCF_PRODUCT_DEFAULT -1
    254  1.39.2.2  mycroft #define UHUBCF_RELEASE_DEFAULT -1
    255  1.39.2.2  mycroft #endif
    256  1.39.2.2  mycroft 
    257  1.39.2.2  mycroft #if defined (__OpenBSD__)
    258  1.39.2.2  mycroft #define	UHUBCF_PORT		0
    259  1.39.2.2  mycroft #define	UHUBCF_CONFIGURATION	1
    260  1.39.2.2  mycroft #define	UHUBCF_INTERFACE	2
    261  1.39.2.2  mycroft #define	UHUBCF_VENDOR		3
    262  1.39.2.2  mycroft #define	UHUBCF_PRODUCT		4
    263  1.39.2.2  mycroft #define	UHUBCF_RELEASE		5
    264  1.39.2.2  mycroft #endif
    265  1.39.2.2  mycroft 
    266  1.39.2.2  mycroft #define	uhubcf_port		cf_loc[UHUBCF_PORT]
    267  1.39.2.2  mycroft #define	uhubcf_configuration	cf_loc[UHUBCF_CONFIGURATION]
    268  1.39.2.2  mycroft #define	uhubcf_interface	cf_loc[UHUBCF_INTERFACE]
    269  1.39.2.2  mycroft #define	uhubcf_vendor		cf_loc[UHUBCF_VENDOR]
    270  1.39.2.2  mycroft #define	uhubcf_product		cf_loc[UHUBCF_PRODUCT]
    271  1.39.2.2  mycroft #define	uhubcf_release		cf_loc[UHUBCF_RELEASE]
    272  1.39.2.2  mycroft #define	UHUB_UNK_PORT		UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
    273  1.39.2.2  mycroft #define	UHUB_UNK_CONFIGURATION	UHUBCF_CONFIGURATION_DEFAULT /* wildcarded 'configuration' */
    274  1.39.2.2  mycroft #define	UHUB_UNK_INTERFACE	UHUBCF_INTERFACE_DEFAULT /* wildcarded 'interface' */
    275  1.39.2.2  mycroft #define	UHUB_UNK_VENDOR		UHUBCF_VENDOR_DEFAULT /* wildcarded 'vendor' */
    276  1.39.2.2  mycroft #define	UHUB_UNK_PRODUCT	UHUBCF_PRODUCT_DEFAULT /* wildcarded 'product' */
    277  1.39.2.2  mycroft #define	UHUB_UNK_RELEASE	UHUBCF_RELEASE_DEFAULT /* wildcarded 'release' */
    278  1.39.2.2  mycroft 
    279