Home | History | Annotate | Line # | Download | only in usb
usbdivar.h revision 1.17.2.1.2.1
      1  1.17.2.1.2.1   thorpej /*	$NetBSD: usbdivar.h,v 1.17.2.1.2.1 1999/06/21 01:19:31 thorpej 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.8  augustss  * This code is derived from software contributed to The NetBSD Foundation
      8           1.8  augustss  * by Lennart Augustsson (augustss (at) carlstedt.se) at
      9           1.8  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 struct usbd_request;
     41           1.1  augustss struct usbd_pipe;
     42           1.1  augustss 
     43           1.1  augustss struct usbd_endpoint {
     44           1.1  augustss 	usb_endpoint_descriptor_t *edesc;
     45           1.1  augustss 	int			refcnt;
     46           1.1  augustss 	int			toggle;	/* XXX */
     47           1.1  augustss };
     48           1.1  augustss 
     49           1.1  augustss typedef void (*usbd_xfercb)__P((usbd_request_handle req));
     50           1.1  augustss 
     51           1.1  augustss struct usbd_methods {
     52           1.1  augustss 	usbd_status	      (*transfer)__P((usbd_request_handle reqh));
     53          1.12  augustss 	usbd_status	      (*start)__P((usbd_request_handle reqh));
     54           1.1  augustss 	void		      (*abort)__P((usbd_request_handle reqh));
     55           1.7  augustss 	void		      (*close)__P((usbd_pipe_handle pipe));
     56           1.7  augustss 	usbd_status	      (*isobuf)__P((usbd_pipe_handle pipe,
     57           1.7  augustss 					    u_int32_t bufsize,u_int32_t nbuf));
     58           1.1  augustss };
     59           1.1  augustss 
     60           1.1  augustss struct usbd_port {
     61           1.1  augustss 	usb_port_status_t	status;
     62          1.11  augustss 	u_int16_t		power;	/* mA of current on port */
     63          1.11  augustss 	u_int8_t		portno;
     64          1.11  augustss 	u_int8_t		restartcnt;
     65          1.11  augustss #define USBD_RESTART_MAX 5
     66           1.1  augustss 	struct usbd_device     *device;
     67           1.1  augustss 	struct usbd_device     *parent;	/* The ports hub */
     68           1.1  augustss };
     69           1.1  augustss 
     70           1.1  augustss struct usbd_hub {
     71          1.11  augustss 	usbd_status	      (*explore)__P((usbd_device_handle hub));
     72          1.11  augustss 	void		       *hubsoftc;
     73           1.1  augustss 	usb_hub_descriptor_t	hubdesc;
     74           1.1  augustss 	struct usbd_port        ports[1];
     75           1.1  augustss };
     76           1.1  augustss 
     77           1.1  augustss struct usb_softc;
     78           1.1  augustss 
     79           1.1  augustss /*****/
     80           1.1  augustss 
     81           1.1  augustss struct usbd_bus {
     82           1.1  augustss 	/* Filled by HC driver */
     83          1.11  augustss 	bdevice			bdev; /* base device, host adapter */
     84           1.1  augustss 	usbd_status	      (*open_pipe)__P((struct usbd_pipe *pipe));
     85           1.1  augustss 	u_int32_t		pipe_size; /* size of a pipe struct */
     86           1.5  augustss 	void		      (*do_poll)__P((struct usbd_bus *));
     87           1.1  augustss 	/* Filled by usb driver */
     88           1.1  augustss 	struct usbd_device     *root_hub;
     89           1.1  augustss 	usbd_device_handle	devices[USB_MAX_DEVICES];
     90           1.1  augustss 	char			needs_explore;/* a hub a signalled a change */
     91           1.6  augustss 	char			use_polling;
     92           1.1  augustss 	struct usb_softc       *usbctl;
     93           1.4  augustss 	struct usb_device_stats	stats;
     94           1.1  augustss };
     95           1.1  augustss 
     96           1.1  augustss struct usbd_device {
     97           1.1  augustss 	struct usbd_bus	       *bus;
     98           1.1  augustss 	struct usbd_pipe       *default_pipe;
     99           1.1  augustss 	u_int8_t		address;
    100           1.1  augustss 	u_int8_t		depth;
    101           1.1  augustss 	u_int8_t		lowspeed;
    102           1.1  augustss 	u_int16_t		power;
    103           1.1  augustss 	u_int8_t		self_powered;
    104           1.1  augustss 	int			config;
    105          1.13  augustss 	int			langid;	/* language to use for strings */
    106          1.13  augustss #define USBD_NOLANG (-1)
    107           1.1  augustss 	struct usbd_port       *powersrc;
    108           1.1  augustss 	struct usbd_endpoint	def_ep;	/* for pipe 0 */
    109           1.1  augustss 	usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
    110           1.1  augustss 	struct usbd_interface  *ifaces;
    111           1.1  augustss 	usb_device_descriptor_t ddesc;
    112           1.1  augustss 	usb_config_descriptor_t *cdesc;	/* full config descr */
    113           1.1  augustss 	struct usbd_quirks     *quirks;
    114           1.1  augustss 	struct usbd_hub	       *hub; /* only if this is a hub */
    115          1.11  augustss 	void		       *softc;	/* device softc if attached */
    116           1.1  augustss };
    117           1.1  augustss 
    118           1.1  augustss struct usbd_interface {
    119           1.1  augustss 	struct usbd_device     *device;
    120           1.1  augustss 	usb_interface_descriptor_t *idesc;
    121          1.10  augustss 	int			index;
    122          1.10  augustss 	int			altindex;
    123           1.1  augustss 	struct usbd_endpoint   *endpoints;
    124           1.1  augustss 	void		       *priv;
    125           1.1  augustss 	LIST_HEAD(, usbd_pipe)	pipes;
    126           1.1  augustss };
    127           1.1  augustss 
    128           1.1  augustss struct usbd_pipe {
    129           1.1  augustss 	struct usbd_interface  *iface;
    130           1.1  augustss 	struct usbd_device     *device;
    131           1.1  augustss 	struct usbd_endpoint   *endpoint;
    132  1.17.2.1.2.1   thorpej 	int			refcnt;
    133           1.1  augustss 	char			running;
    134           1.1  augustss 	SIMPLEQ_HEAD(, usbd_request) queue;
    135           1.1  augustss 	LIST_ENTRY(usbd_pipe)	next;
    136           1.1  augustss 
    137           1.1  augustss 	void		      (*disco) __P((void *));
    138           1.1  augustss 	void		       *discoarg;
    139           1.1  augustss 
    140           1.1  augustss 	usbd_request_handle     intrreqh; /* used for repeating requests */
    141           1.1  augustss 
    142           1.1  augustss 	/* Filled by HC driver. */
    143           1.1  augustss 	struct usbd_methods    *methods;
    144           1.1  augustss };
    145           1.1  augustss 
    146           1.1  augustss struct usbd_request {
    147           1.1  augustss 	struct usbd_pipe       *pipe;
    148           1.1  augustss 	void		       *priv;
    149           1.1  augustss 	void		       *buffer;
    150           1.1  augustss 	u_int32_t		length;
    151           1.1  augustss 	u_int32_t		actlen;
    152           1.1  augustss 	u_int16_t		flags;
    153           1.1  augustss 	u_int32_t		timeout;
    154           1.1  augustss 	usbd_status		status;
    155           1.1  augustss 	usbd_callback		callback;
    156           1.1  augustss 	usbd_xfercb		xfercb;
    157           1.1  augustss 	u_int32_t		retries;
    158           1.1  augustss 	char			done;
    159           1.1  augustss 
    160           1.1  augustss 	usb_device_request_t	request;
    161           1.1  augustss 	u_int8_t		isreq;
    162           1.1  augustss 
    163           1.1  augustss 	SIMPLEQ_ENTRY(usbd_request) next;
    164           1.1  augustss 
    165           1.1  augustss 	void		       *hcpriv; /* XXX private use by the HC driver */
    166          1.11  augustss 
    167          1.11  augustss #if defined(__FreeBSD__)
    168          1.11  augustss 	struct callout_handle  timo_handle;
    169          1.11  augustss #endif
    170           1.1  augustss };
    171           1.1  augustss 
    172           1.1  augustss void usbd_init __P((void));
    173           1.1  augustss 
    174           1.1  augustss /* Routines from usb_subr.c */
    175           1.1  augustss int		usbctlprint __P((void *, const char *));
    176          1.14  augustss void		usb_delay_ms __P((usbd_bus_handle, u_int));
    177           1.1  augustss void		usbd_devinfo_vp __P((usbd_device_handle, char *, char *));
    178           1.1  augustss usbd_status	usbd_reset_port __P((usbd_device_handle dev,
    179           1.1  augustss 				     int port, usb_port_status_t *ps));
    180           1.1  augustss usbd_status	usbd_setup_pipe __P((usbd_device_handle dev,
    181           1.1  augustss 				     usbd_interface_handle iface,
    182           1.1  augustss 				     struct usbd_endpoint *,
    183           1.1  augustss 				     usbd_pipe_handle *pipe));
    184          1.11  augustss usbd_status	usbd_new_device __P((bdevice *parent,
    185           1.1  augustss 				     usbd_bus_handle bus, int depth,
    186           1.1  augustss 				     int lowspeed, int port,
    187           1.1  augustss 				     struct usbd_port *));
    188          1.11  augustss void		usbd_remove_device __P((usbd_device_handle,
    189          1.11  augustss 					struct usbd_port *));
    190           1.1  augustss int		usbd_printBCD __P((char *cp, int bcd));
    191          1.12  augustss usbd_status	usb_insert_transfer __P((usbd_request_handle reqh));
    192          1.12  augustss void		usb_start_next __P((usbd_pipe_handle pipe));
    193          1.10  augustss usbd_status	usbd_fill_iface_data __P((usbd_device_handle dev,
    194          1.10  augustss 					  int i, int a));
    195           1.1  augustss 
    196           1.1  augustss /* Routines from usb.c */
    197           1.1  augustss int		usb_bus_count __P((void));
    198          1.17  augustss void		usb_needs_explore __P((usbd_bus_handle));
    199          1.17  augustss #if 0
    200           1.1  augustss usbd_status	usb_get_bus_handle __P((int, usbd_bus_handle *));
    201          1.17  augustss #endif
    202           1.1  augustss 
    203           1.1  augustss /* Locator stuff. */
    204           1.1  augustss 
    205          1.11  augustss #if defined(__NetBSD__)
    206           1.1  augustss #include "locators.h"
    207          1.16  augustss #elif defined(__FreeBSD__)
    208          1.16  augustss /* XXX these values are used to statically bind some elements in the USB tree
    209          1.16  augustss  * to specific driver instances. This should be somehow emulated in FreeBSD
    210          1.16  augustss  * but can be done later on.
    211          1.16  augustss  * The values are copied from the files.usb file in the NetBSD sources.
    212          1.16  augustss  */
    213          1.16  augustss #define UHUBCF_PORT_DEFAULT -1
    214          1.16  augustss #define UHUBCF_CONFIGURATION_DEFAULT -1
    215          1.16  augustss #define UHUBCF_INTERFACE_DEFAULT -1
    216  1.17.2.1.2.1   thorpej #define UHUBCF_VENDOR_DEFAULT -1
    217  1.17.2.1.2.1   thorpej #define UHUBCF_PRODUCT_DEFAULT -1
    218  1.17.2.1.2.1   thorpej #define UHUBCF_RELEASE_DEFAULT -1
    219          1.11  augustss #endif
    220           1.1  augustss 
    221           1.9  augustss #define	uhubcf_port		cf_loc[UHUBCF_PORT]
    222           1.9  augustss #define	uhubcf_configuration	cf_loc[UHUBCF_CONFIGURATION]
    223           1.9  augustss #define	uhubcf_interface	cf_loc[UHUBCF_INTERFACE]
    224  1.17.2.1.2.1   thorpej #define	uhubcf_vendor		cf_loc[UHUBCF_VENDOR]
    225  1.17.2.1.2.1   thorpej #define	uhubcf_product		cf_loc[UHUBCF_PRODUCT]
    226  1.17.2.1.2.1   thorpej #define	uhubcf_release		cf_loc[UHUBCF_RELEASE]
    227           1.9  augustss #define	UHUB_UNK_PORT		UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
    228           1.9  augustss #define	UHUB_UNK_CONFIGURATION	UHUBCF_CONFIGURATION_DEFAULT /* wildcarded 'configuration' */
    229           1.9  augustss #define	UHUB_UNK_INTERFACE	UHUBCF_INTERFACE_DEFAULT /* wildcarded 'interface' */
    230  1.17.2.1.2.1   thorpej #define	UHUB_UNK_VENDOR		UHUBCF_VENDOR_DEFAULT /* wildcarded 'vendor' */
    231  1.17.2.1.2.1   thorpej #define	UHUB_UNK_PRODUCT	UHUBCF_PRODUCT_DEFAULT /* wildcarded 'product' */
    232  1.17.2.1.2.1   thorpej #define	UHUB_UNK_RELEASE	UHUBCF_RELEASE_DEFAULT /* wildcarded 'release' */
    233           1.1  augustss 
    234