Home | History | Annotate | Line # | Download | only in usb
usbdivar.h revision 1.32
      1 /*	$NetBSD: usbdivar.h,v 1.32 1999/09/13 19:49:41 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 /* From usb_mem.h */
     41 DECLARE_USB_DMA_T;
     42 
     43 struct usbd_request;
     44 struct usbd_pipe;
     45 
     46 struct usbd_endpoint {
     47 	usb_endpoint_descriptor_t *edesc;
     48 	int			refcnt;
     49 };
     50 
     51 struct usbd_bus_methods {
     52 	usbd_status	      (*open_pipe)__P((struct usbd_pipe *pipe));
     53 	void		      (*do_poll)__P((struct usbd_bus *));
     54 	usbd_status	      (*allocm)__P((struct usbd_bus *, usb_dma_t *,
     55 					    u_int32_t bufsize));
     56 	void		      (*freem)__P((struct usbd_bus *, usb_dma_t *));
     57 };
     58 
     59 struct usbd_pipe_methods {
     60 	usbd_status	      (*transfer)__P((usbd_request_handle reqh));
     61 	usbd_status	      (*start)__P((usbd_request_handle reqh));
     62 	void		      (*abort)__P((usbd_request_handle reqh));
     63 	void		      (*close)__P((usbd_pipe_handle pipe));
     64 	void		      (*cleartoggle)__P((usbd_pipe_handle pipe));
     65 	void		      (*done)__P((usbd_request_handle reqh));
     66 };
     67 
     68 struct usbd_port {
     69 	usb_port_status_t	status;
     70 	u_int16_t		power;	/* mA of current on port */
     71 	u_int8_t		portno;
     72 	u_int8_t		restartcnt;
     73 #define USBD_RESTART_MAX 5
     74 	struct usbd_device     *device;
     75 	struct usbd_device     *parent;	/* The ports hub */
     76 };
     77 
     78 struct usbd_hub {
     79 	usbd_status	      (*explore)__P((usbd_device_handle hub));
     80 	void		       *hubsoftc;
     81 	usb_hub_descriptor_t	hubdesc;
     82 	struct usbd_port        ports[1];
     83 };
     84 
     85 struct usb_softc;
     86 
     87 /*****/
     88 
     89 struct usbd_bus {
     90 	/* Filled by HC driver */
     91 	USBBASEDEVICE		bdev; /* base device, host adapter */
     92 	struct usbd_bus_methods	*methods;
     93 	u_int32_t		pipe_size; /* size of a pipe struct */
     94 	/* Filled by usb driver */
     95 	struct usbd_device     *root_hub;
     96 	usbd_device_handle	devices[USB_MAX_DEVICES];
     97 	char			needs_explore;/* a hub a signalled a change */
     98 	char			use_polling;
     99 	struct usb_softc       *usbctl;
    100 	struct usb_device_stats	stats;
    101 	int 			intr_context;
    102 	u_int			no_intrs;
    103 #if defined(__NetBSD__) || defined(__OpenBSD__)
    104 	bus_dma_tag_t		dmatag;	/* DMA tag */
    105 #endif
    106 };
    107 
    108 struct usbd_device {
    109 	struct usbd_bus	       *bus;
    110 	struct usbd_pipe       *default_pipe;
    111 	u_int8_t		address;
    112 	u_int8_t		depth;
    113 	u_int8_t		lowspeed;
    114 	u_int16_t		power;
    115 	u_int8_t		self_powered;
    116 	int			config;
    117 	int			langid;	/* language to use for strings */
    118 #define USBD_NOLANG (-1)
    119 	struct usbd_port       *powersrc;
    120 	struct usbd_endpoint	def_ep;	/* for pipe 0 */
    121 	usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
    122 	struct usbd_interface  *ifaces;
    123 	usb_device_descriptor_t ddesc;
    124 	usb_config_descriptor_t *cdesc;	/* full config descr */
    125 	struct usbd_quirks     *quirks;
    126 	struct usbd_hub	       *hub; /* only if this is a hub */
    127 	device_ptr_t	       *subdevs;	/* sub-devices, 0 terminated */
    128 };
    129 
    130 struct usbd_interface {
    131 	struct usbd_device     *device;
    132 	usb_interface_descriptor_t *idesc;
    133 	int			index;
    134 	int			altindex;
    135 	struct usbd_endpoint   *endpoints;
    136 	void		       *priv;
    137 	LIST_HEAD(, usbd_pipe)	pipes;
    138 };
    139 
    140 struct usbd_pipe {
    141 	struct usbd_interface  *iface;
    142 	struct usbd_device     *device;
    143 	struct usbd_endpoint   *endpoint;
    144 	int			refcnt;
    145 	char			running;
    146 	SIMPLEQ_HEAD(, usbd_request) queue;
    147 	LIST_ENTRY(usbd_pipe)	next;
    148 
    149 	usbd_request_handle     intrreqh; /* used for repeating requests */
    150 	char			repeat;
    151 
    152 	/* Filled by HC driver. */
    153 	struct usbd_pipe_methods *methods;
    154 };
    155 
    156 struct usbd_request {
    157 	struct usbd_pipe       *pipe;
    158 	void		       *priv;
    159 	void		       *buffer;
    160 	u_int32_t		length;
    161 	u_int32_t		actlen;
    162 	u_int16_t		flags;
    163 	u_int32_t		timeout;
    164 	usbd_status		status;
    165 	usbd_callback		callback;
    166 	__volatile char		done;
    167 
    168 	/* For control pipe */
    169 	usb_device_request_t	request;
    170 
    171 	/* For isoc */
    172 	u_int16_t		*frlengths;
    173 	int			nframes;
    174 
    175 	/* For memory allocation */
    176 	struct usbd_device     *device;
    177 	usb_dma_t		dmabuf;
    178 
    179 	int			rqflags;
    180 #define URQ_REQUEST	0x01
    181 #define URQ_AUTO_DMABUF	0x10
    182 #define URQ_DEV_DMABUF	0x20
    183 
    184 	SIMPLEQ_ENTRY(usbd_request) next;
    185 
    186 	void		       *hcpriv; /* private use by the HC driver */
    187 	int			hcprivint; /* ditto */
    188 
    189 #if defined(__FreeBSD__)
    190 	struct callout_handle  timo_handle;
    191 #endif
    192 };
    193 
    194 void usbd_init __P((void));
    195 
    196 /* Routines from usb_subr.c */
    197 int		usbctlprint __P((void *, const char *));
    198 void		usb_delay_ms __P((usbd_bus_handle, u_int));
    199 void		usbd_devinfo_vp __P((usbd_device_handle, char *, char *));
    200 usbd_status	usbd_reset_port __P((usbd_device_handle dev,
    201 				     int port, usb_port_status_t *ps));
    202 usbd_status	usbd_setup_pipe __P((usbd_device_handle dev,
    203 				     usbd_interface_handle iface,
    204 				     struct usbd_endpoint *,
    205 				     usbd_pipe_handle *pipe));
    206 usbd_status	usbd_new_device __P((device_ptr_t parent,
    207 				     usbd_bus_handle bus, int depth,
    208 				     int lowspeed, int port,
    209 				     struct usbd_port *));
    210 void		usbd_remove_device __P((usbd_device_handle,
    211 					struct usbd_port *));
    212 int		usbd_printBCD __P((char *cp, int bcd));
    213 usbd_status	usbd_fill_iface_data __P((usbd_device_handle dev,
    214 					  int i, int a));
    215 void		usb_free_device __P((usbd_device_handle));
    216 
    217 usbd_status	usb_insert_transfer __P((usbd_request_handle reqh));
    218 void		usb_transfer_complete __P((usbd_request_handle reqh));
    219 
    220 /* Routines from usb.c */
    221 int		usb_bus_count __P((void));
    222 void		usb_needs_explore __P((usbd_bus_handle));
    223 
    224 /* Locator stuff. */
    225 
    226 #if defined(__NetBSD__)
    227 #include "locators.h"
    228 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
    229 /* XXX these values are used to statically bind some elements in the USB tree
    230  * to specific driver instances. This should be somehow emulated in FreeBSD
    231  * but can be done later on.
    232  * The values are copied from the files.usb file in the NetBSD sources.
    233  */
    234 #define UHUBCF_PORT_DEFAULT -1
    235 #define UHUBCF_CONFIGURATION_DEFAULT -1
    236 #define UHUBCF_INTERFACE_DEFAULT -1
    237 #define UHUBCF_VENDOR_DEFAULT -1
    238 #define UHUBCF_PRODUCT_DEFAULT -1
    239 #define UHUBCF_RELEASE_DEFAULT -1
    240 #endif
    241 
    242 #if defined (__OpenBSD__)
    243 #define	UHUBCF_PORT		0
    244 #define	UHUBCF_CONFIGURATION	1
    245 #define	UHUBCF_INTERFACE	2
    246 #define	UHUBCF_VENDOR		3
    247 #define	UHUBCF_PRODUCT		4
    248 #define	UHUBCF_RELEASE		5
    249 #endif
    250 
    251 #define	uhubcf_port		cf_loc[UHUBCF_PORT]
    252 #define	uhubcf_configuration	cf_loc[UHUBCF_CONFIGURATION]
    253 #define	uhubcf_interface	cf_loc[UHUBCF_INTERFACE]
    254 #define	uhubcf_vendor		cf_loc[UHUBCF_VENDOR]
    255 #define	uhubcf_product		cf_loc[UHUBCF_PRODUCT]
    256 #define	uhubcf_release		cf_loc[UHUBCF_RELEASE]
    257 #define	UHUB_UNK_PORT		UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
    258 #define	UHUB_UNK_CONFIGURATION	UHUBCF_CONFIGURATION_DEFAULT /* wildcarded 'configuration' */
    259 #define	UHUB_UNK_INTERFACE	UHUBCF_INTERFACE_DEFAULT /* wildcarded 'interface' */
    260 #define	UHUB_UNK_VENDOR		UHUBCF_VENDOR_DEFAULT /* wildcarded 'vendor' */
    261 #define	UHUB_UNK_PRODUCT	UHUBCF_PRODUCT_DEFAULT /* wildcarded 'product' */
    262 #define	UHUB_UNK_RELEASE	UHUBCF_RELEASE_DEFAULT /* wildcarded 'release' */
    263 
    264