Home | History | Annotate | Line # | Download | only in usb
usbdivar.h revision 1.7
      1 /*	$NetBSD: usbdivar.h,v 1.7 1998/08/02 22:30:53 augustss Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Author: Lennart Augustsson <augustss (at) carlstedt.se>
      8  *         Carlstedt Research & Technology
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 struct usbd_request;
     40 struct usbd_pipe;
     41 
     42 struct usbd_endpoint {
     43 	usb_endpoint_descriptor_t *edesc;
     44 	usbd_endpoint_state	state;
     45 	int			refcnt;
     46 	int			toggle;	/* XXX */
     47 };
     48 
     49 typedef void (*usbd_xfercb)__P((usbd_request_handle req));
     50 
     51 struct usbd_methods {
     52 	usbd_status	      (*transfer)__P((usbd_request_handle reqh));
     53 	void		      (*abort)__P((usbd_request_handle reqh));
     54 	void		      (*close)__P((usbd_pipe_handle pipe));
     55 	usbd_status	      (*isobuf)__P((usbd_pipe_handle pipe,
     56 					    u_int32_t bufsize,u_int32_t nbuf));
     57 };
     58 
     59 struct usbd_port {
     60 	usb_port_status_t	status;
     61 	int 			power;	/* mA of current on port */
     62 	struct usbd_device     *device;
     63 	struct usbd_device     *parent;	/* The ports hub */
     64 };
     65 
     66 struct usbd_hub {
     67 	usbd_status	      (*explore)__P((struct device *parent,
     68 					     usbd_device_handle hub));
     69 	void		       *hubdata;
     70 	usb_hub_descriptor_t	hubdesc;
     71 	struct usbd_port        ports[1];
     72 };
     73 
     74 struct usb_softc;
     75 
     76 /*****/
     77 
     78 struct usbd_bus {
     79 	/* Filled by HC driver */
     80 	struct device		bdev; /* base device */
     81 	usbd_status	      (*open_pipe)__P((struct usbd_pipe *pipe));
     82 	u_int32_t		pipe_size; /* size of a pipe struct */
     83 	void		      (*do_poll)__P((struct usbd_bus *));
     84 	/* Filled by usb driver */
     85 	struct usbd_device     *root_hub;
     86 	usbd_device_handle	devices[USB_MAX_DEVICES];
     87 	char			needs_explore;/* a hub a signalled a change */
     88 	char			use_polling;
     89 	struct usb_softc       *usbctl;
     90 	struct usb_device_stats	stats;
     91 };
     92 
     93 struct usbd_device {
     94 	struct usbd_bus	       *bus;
     95 	usbd_device_state	state;
     96 	struct usbd_pipe       *default_pipe;
     97 	u_int8_t		address;
     98 	u_int8_t		depth;
     99 	u_int8_t		lowspeed;
    100 	u_int16_t		power;
    101 	u_int8_t		self_powered;
    102 	int			config;
    103 	struct usbd_port       *powersrc;
    104 	struct usbd_endpoint	def_ep;	/* for pipe 0 */
    105 	usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
    106 	struct usbd_interface  *ifaces;
    107 	usb_device_descriptor_t ddesc;
    108 	usb_config_descriptor_t *cdesc;	/* full config descr */
    109 	struct usbd_quirks     *quirks;
    110 	struct usbd_hub	       *hub; /* only if this is a hub */
    111 };
    112 
    113 struct usbd_interface {
    114 	struct usbd_device     *device;
    115 	usbd_interface_state	state;
    116 	usb_interface_descriptor_t *idesc;
    117 	struct usbd_endpoint   *endpoints;
    118 	void		       *priv;
    119 	LIST_HEAD(, usbd_pipe)	pipes;
    120 };
    121 
    122 struct usbd_pipe {
    123 	struct usbd_interface  *iface;
    124 	struct usbd_device     *device;
    125 	struct usbd_endpoint   *endpoint;
    126 	usbd_pipe_state		state;
    127 	int32_t			refcnt;
    128 	char			running;
    129 	SIMPLEQ_HEAD(, usbd_request) queue;
    130 	LIST_ENTRY(usbd_pipe)	next;
    131 
    132 	void		      (*disco) __P((void *));
    133 	void		       *discoarg;
    134 
    135 	usbd_request_handle     intrreqh; /* used for repeating requests */
    136 	usbd_request_handle     curreqh; /* currently running request */
    137 
    138 	/* Filled by HC driver. */
    139 	struct usbd_methods    *methods;
    140 };
    141 
    142 struct usbd_request {
    143 	struct usbd_pipe       *pipe;
    144 	void		       *priv;
    145 	void		       *buffer;
    146 	u_int32_t		length;
    147 	u_int32_t		actlen;
    148 	u_int16_t		flags;
    149 	u_int32_t		timeout;
    150 	usbd_status		status;
    151 	usbd_callback		callback;
    152 	usbd_xfercb		xfercb;
    153 	u_int32_t		retries;
    154 	char			done;
    155 
    156 	usb_device_request_t	request;
    157 	u_int8_t		isreq;
    158 
    159 	SIMPLEQ_ENTRY(usbd_request) next;
    160 
    161 	void		       *hcpriv; /* XXX private use by the HC driver */
    162 };
    163 
    164 void usbd_init __P((void));
    165 
    166 /* Routines from usb_subr.c */
    167 int		usbctlprint __P((void *, const char *));
    168 void		usbd_delay_ms __P((usbd_bus_handle, int));
    169 void		usbd_devinfo_vp __P((usbd_device_handle, char *, char *));
    170 usbd_status	usbd_set_config_no __P((usbd_device_handle, int, int));
    171 usbd_status	usbd_reset_port __P((usbd_device_handle dev,
    172 				     int port, usb_port_status_t *ps));
    173 usbd_status	usbd_setup_pipe __P((usbd_device_handle dev,
    174 				     usbd_interface_handle iface,
    175 				     struct usbd_endpoint *,
    176 				     usbd_pipe_handle *pipe));
    177 usbd_status	usbd_new_device __P((struct device *parent,
    178 				     usbd_bus_handle bus, int depth,
    179 				     int lowspeed, int port,
    180 				     struct usbd_port *));
    181 int		usbd_printBCD __P((char *cp, int bcd));
    182 
    183 /* Routines from usb.c */
    184 int		usb_bus_count __P((void));
    185 usbd_status	usb_get_bus_handle __P((int, usbd_bus_handle *));
    186 void		usb_needs_explore __P((usbd_bus_handle));
    187 
    188 extern	int usbd_use_polling;
    189 
    190 /* Locator stuff. */
    191 
    192 #include "locators.h"
    193 
    194 #define	uhubcf_port	cf_loc[UHUBCF_PORT]
    195 #define	UHUB_UNK_PORT	UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
    196 
    197 /* Junk. */
    198 
    199 /* XXX */
    200 #define splusb splbio
    201 #define IPL_USB IPL_BIO
    202 /* XXX */
    203 
    204