Home | History | Annotate | Line # | Download | only in usb
usbdivar.h revision 1.37
      1 /*	$NetBSD: usbdivar.h,v 1.37 1999/10/12 20:02:48 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 	usb_event_cookie_t	cookie;	/* unique connection id */
    120 	struct usbd_port       *powersrc;
    121 	struct usbd_endpoint	def_ep;	/* for pipe 0 */
    122 	usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
    123 	struct usbd_interface  *ifaces;
    124 	usb_device_descriptor_t ddesc;
    125 	usb_config_descriptor_t *cdesc;	/* full config descr */
    126 	struct usbd_quirks     *quirks;
    127 	struct usbd_hub	       *hub; /* only if this is a hub */
    128 	device_ptr_t	       *subdevs;	/* sub-devices, 0 terminated */
    129 };
    130 
    131 struct usbd_interface {
    132 	struct usbd_device     *device;
    133 	usb_interface_descriptor_t *idesc;
    134 	int			index;
    135 	int			altindex;
    136 	struct usbd_endpoint   *endpoints;
    137 	void		       *priv;
    138 	LIST_HEAD(, usbd_pipe)	pipes;
    139 };
    140 
    141 struct usbd_pipe {
    142 	struct usbd_interface  *iface;
    143 	struct usbd_device     *device;
    144 	struct usbd_endpoint   *endpoint;
    145 	int			refcnt;
    146 	char			running;
    147 	SIMPLEQ_HEAD(, usbd_request) queue;
    148 	LIST_ENTRY(usbd_pipe)	next;
    149 
    150 	usbd_request_handle     intrreqh; /* used for repeating requests */
    151 	char			repeat;
    152 
    153 	/* Filled by HC driver. */
    154 	struct usbd_pipe_methods *methods;
    155 };
    156 
    157 struct usbd_request {
    158 	struct usbd_pipe       *pipe;
    159 	void		       *priv;
    160 	void		       *buffer;
    161 	u_int32_t		length;
    162 	u_int32_t		actlen;
    163 	u_int16_t		flags;
    164 	u_int32_t		timeout;
    165 	usbd_status		status;
    166 	usbd_callback		callback;
    167 	__volatile char		done;
    168 
    169 	/* For control pipe */
    170 	usb_device_request_t	request;
    171 
    172 	/* For isoc */
    173 	u_int16_t		*frlengths;
    174 	int			nframes;
    175 
    176 	/* For memory allocation */
    177 	struct usbd_device     *device;
    178 	usb_dma_t		dmabuf;
    179 
    180 	int			rqflags;
    181 #define URQ_REQUEST	0x01
    182 #define URQ_AUTO_DMABUF	0x10
    183 #define URQ_DEV_DMABUF	0x20
    184 
    185 	SIMPLEQ_ENTRY(usbd_request) next;
    186 
    187 	void		       *hcpriv; /* private use by the HC driver */
    188 	int			hcprivint; /* ditto */
    189 
    190 #if defined(__FreeBSD__)
    191 	struct callout_handle  timo_handle;
    192 #endif
    193 };
    194 
    195 void usbd_init __P((void));
    196 void usbd_finish __P((void));
    197 
    198 /* Routines from usb_subr.c */
    199 int		usbctlprint __P((void *, const char *));
    200 void		usb_delay_ms __P((usbd_bus_handle, u_int));
    201 void		usbd_devinfo_vp __P((usbd_device_handle, char *, char *));
    202 usbd_status	usbd_reset_port __P((usbd_device_handle dev,
    203 				     int port, usb_port_status_t *ps));
    204 usbd_status	usbd_setup_pipe __P((usbd_device_handle dev,
    205 				     usbd_interface_handle iface,
    206 				     struct usbd_endpoint *,
    207 				     usbd_pipe_handle *pipe));
    208 usbd_status	usbd_new_device __P((device_ptr_t parent,
    209 				     usbd_bus_handle bus, int depth,
    210 				     int lowspeed, int port,
    211 				     struct usbd_port *));
    212 void		usbd_remove_device __P((usbd_device_handle,
    213 					struct usbd_port *));
    214 int		usbd_printBCD __P((char *cp, int bcd));
    215 usbd_status	usbd_fill_iface_data __P((usbd_device_handle dev,
    216 					  int i, int a));
    217 void		usb_free_device __P((usbd_device_handle));
    218 
    219 usbd_status	usb_insert_transfer __P((usbd_request_handle reqh));
    220 void		usb_transfer_complete __P((usbd_request_handle reqh));
    221 void		usb_disconnect_port __P((struct usbd_port *up, device_ptr_t));
    222 
    223 /* Routines from usb.c */
    224 int		usb_bus_count __P((void));
    225 void		usb_needs_explore __P((usbd_bus_handle));
    226 
    227 #ifdef DIAGNOSTIC
    228 #define SPLUSBCHECK \
    229 	do { int _s = splusb(), _su = splusb(); \
    230              if (_s != _su) printf("SPLUSBCHECK failed 0x%x!=0x%x, %s:%d\n", \
    231 				   _s, _su, __FILE__, __LINE__); \
    232         } while (0)
    233 #else
    234 #define SPLUSBCHECK
    235 #endif
    236 
    237 /* Locator stuff. */
    238 
    239 #if defined(__NetBSD__)
    240 #include "locators.h"
    241 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
    242 /* XXX these values are used to statically bind some elements in the USB tree
    243  * to specific driver instances. This should be somehow emulated in FreeBSD
    244  * but can be done later on.
    245  * The values are copied from the files.usb file in the NetBSD sources.
    246  */
    247 #define UHUBCF_PORT_DEFAULT -1
    248 #define UHUBCF_CONFIGURATION_DEFAULT -1
    249 #define UHUBCF_INTERFACE_DEFAULT -1
    250 #define UHUBCF_VENDOR_DEFAULT -1
    251 #define UHUBCF_PRODUCT_DEFAULT -1
    252 #define UHUBCF_RELEASE_DEFAULT -1
    253 #endif
    254 
    255 #if defined (__OpenBSD__)
    256 #define	UHUBCF_PORT		0
    257 #define	UHUBCF_CONFIGURATION	1
    258 #define	UHUBCF_INTERFACE	2
    259 #define	UHUBCF_VENDOR		3
    260 #define	UHUBCF_PRODUCT		4
    261 #define	UHUBCF_RELEASE		5
    262 #endif
    263 
    264 #define	uhubcf_port		cf_loc[UHUBCF_PORT]
    265 #define	uhubcf_configuration	cf_loc[UHUBCF_CONFIGURATION]
    266 #define	uhubcf_interface	cf_loc[UHUBCF_INTERFACE]
    267 #define	uhubcf_vendor		cf_loc[UHUBCF_VENDOR]
    268 #define	uhubcf_product		cf_loc[UHUBCF_PRODUCT]
    269 #define	uhubcf_release		cf_loc[UHUBCF_RELEASE]
    270 #define	UHUB_UNK_PORT		UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
    271 #define	UHUB_UNK_CONFIGURATION	UHUBCF_CONFIGURATION_DEFAULT /* wildcarded 'configuration' */
    272 #define	UHUB_UNK_INTERFACE	UHUBCF_INTERFACE_DEFAULT /* wildcarded 'interface' */
    273 #define	UHUB_UNK_VENDOR		UHUBCF_VENDOR_DEFAULT /* wildcarded 'vendor' */
    274 #define	UHUB_UNK_PRODUCT	UHUBCF_PRODUCT_DEFAULT /* wildcarded 'product' */
    275 #define	UHUB_UNK_RELEASE	UHUBCF_RELEASE_DEFAULT /* wildcarded 'release' */
    276 
    277