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