2000-02-22 14:30:54 +03:00
|
|
|
/* $NetBSD: usbdivar.h,v 1.47 2000/02/22 11:30:56 augustss Exp $ */
|
1999-11-19 02:32:25 +03:00
|
|
|
/* $FreeBSD: src/sys/dev/usb/usbdivar.h,v 1.11 1999/11/17 22:33:51 n_hibma Exp $ */
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
1998-11-26 01:32:04 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Lennart Augustsson (augustss@carlstedt.se) at
|
|
|
|
* Carlstedt Research & Technology.
|
1998-07-12 23:51:55 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1999-09-09 16:26:43 +04:00
|
|
|
/* From usb_mem.h */
|
1999-09-11 12:19:26 +04:00
|
|
|
DECLARE_USB_DMA_T;
|
1999-09-09 16:26:43 +04:00
|
|
|
|
1999-11-12 03:34:57 +03:00
|
|
|
struct usbd_xfer;
|
1998-07-12 23:51:55 +04:00
|
|
|
struct usbd_pipe;
|
|
|
|
|
|
|
|
struct usbd_endpoint {
|
|
|
|
usb_endpoint_descriptor_t *edesc;
|
|
|
|
int refcnt;
|
|
|
|
};
|
|
|
|
|
1999-09-09 16:26:43 +04:00
|
|
|
struct usbd_bus_methods {
|
|
|
|
usbd_status (*open_pipe)__P((struct usbd_pipe *pipe));
|
2000-02-22 14:30:54 +03:00
|
|
|
void (*soft_intr)__P((struct usbd_bus *));
|
1999-09-09 16:26:43 +04:00
|
|
|
void (*do_poll)__P((struct usbd_bus *));
|
|
|
|
usbd_status (*allocm)__P((struct usbd_bus *, usb_dma_t *,
|
|
|
|
u_int32_t bufsize));
|
|
|
|
void (*freem)__P((struct usbd_bus *, usb_dma_t *));
|
2000-01-18 23:11:00 +03:00
|
|
|
struct usbd_xfer * (*allocx)__P((struct usbd_bus *));
|
|
|
|
void (*freex)__P((struct usbd_bus *,
|
|
|
|
struct usbd_xfer *));
|
1999-09-09 16:26:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct usbd_pipe_methods {
|
1999-11-12 03:34:57 +03:00
|
|
|
usbd_status (*transfer)__P((usbd_xfer_handle xfer));
|
|
|
|
usbd_status (*start)__P((usbd_xfer_handle xfer));
|
|
|
|
void (*abort)__P((usbd_xfer_handle xfer));
|
1999-08-18 00:59:04 +04:00
|
|
|
void (*close)__P((usbd_pipe_handle pipe));
|
|
|
|
void (*cleartoggle)__P((usbd_pipe_handle pipe));
|
1999-11-12 03:34:57 +03:00
|
|
|
void (*done)__P((usbd_xfer_handle xfer));
|
1998-07-12 23:51:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct usbd_port {
|
|
|
|
usb_port_status_t status;
|
1998-12-26 15:53:00 +03:00
|
|
|
u_int16_t power; /* mA of current on port */
|
|
|
|
u_int8_t portno;
|
|
|
|
u_int8_t restartcnt;
|
|
|
|
#define USBD_RESTART_MAX 5
|
1998-07-12 23:51:55 +04:00
|
|
|
struct usbd_device *device;
|
|
|
|
struct usbd_device *parent; /* The ports hub */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct usbd_hub {
|
1998-12-26 15:53:00 +03:00
|
|
|
usbd_status (*explore)__P((usbd_device_handle hub));
|
|
|
|
void *hubsoftc;
|
1998-07-12 23:51:55 +04:00
|
|
|
usb_hub_descriptor_t hubdesc;
|
|
|
|
struct usbd_port ports[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct usb_softc;
|
|
|
|
|
|
|
|
/*****/
|
|
|
|
|
|
|
|
struct usbd_bus {
|
|
|
|
/* Filled by HC driver */
|
1999-09-05 23:32:18 +04:00
|
|
|
USBBASEDEVICE bdev; /* base device, host adapter */
|
1999-09-09 16:26:43 +04:00
|
|
|
struct usbd_bus_methods *methods;
|
1998-07-12 23:51:55 +04:00
|
|
|
u_int32_t pipe_size; /* size of a pipe struct */
|
|
|
|
/* Filled by usb driver */
|
|
|
|
struct usbd_device *root_hub;
|
|
|
|
usbd_device_handle devices[USB_MAX_DEVICES];
|
|
|
|
char needs_explore;/* a hub a signalled a change */
|
1998-08-01 22:16:19 +04:00
|
|
|
char use_polling;
|
1998-07-12 23:51:55 +04:00
|
|
|
struct usb_softc *usbctl;
|
1998-07-25 19:22:11 +04:00
|
|
|
struct usb_device_stats stats;
|
1999-09-13 23:49:41 +04:00
|
|
|
int intr_context;
|
|
|
|
u_int no_intrs;
|
1999-11-20 03:57:08 +03:00
|
|
|
int usbrev; /* USB revision */
|
|
|
|
#define USBREV_UNKNOWN 0
|
|
|
|
#define USBREV_PRE_1_0 1
|
|
|
|
#define USBREV_1_0 2
|
|
|
|
#define USBREV_1_1 3
|
|
|
|
#define USBREV_STR { "unknown", "pre 1.0", "1.0", "1.1" }
|
|
|
|
|
1999-09-13 23:18:17 +04:00
|
|
|
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
|
|
|
bus_dma_tag_t dmatag; /* DMA tag */
|
|
|
|
#endif
|
1998-07-12 23:51:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct usbd_device {
|
2000-01-16 12:43:43 +03:00
|
|
|
struct usbd_bus *bus; /* our controller */
|
|
|
|
struct usbd_pipe *default_pipe; /* pipe 0 */
|
|
|
|
u_int8_t address; /* device addess */
|
|
|
|
u_int8_t config; /* current configuration # */
|
|
|
|
u_int8_t depth; /* distance from root hub */
|
|
|
|
u_int8_t lowspeed; /* lowspeed flag */
|
|
|
|
u_int8_t self_powered; /* flag for self powered */
|
|
|
|
u_int16_t power; /* mA the device uses */
|
|
|
|
int16_t langid; /* language for strings */
|
1998-12-29 19:02:55 +03:00
|
|
|
#define USBD_NOLANG (-1)
|
2000-01-16 12:43:43 +03:00
|
|
|
usb_event_cookie_t cookie; /* unique connection id */
|
|
|
|
struct usbd_port *powersrc; /* upstream hub port, or 0 */
|
|
|
|
struct usbd_endpoint def_ep; /* for pipe 0 */
|
1998-07-12 23:51:55 +04:00
|
|
|
usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
|
2000-01-16 12:43:43 +03:00
|
|
|
struct usbd_interface *ifaces; /* array of all interfaces */
|
|
|
|
usb_device_descriptor_t ddesc; /* device descriptor */
|
|
|
|
usb_config_descriptor_t *cdesc; /* full config descr */
|
|
|
|
struct usbd_quirks *quirks; /* device quirks, always set */
|
|
|
|
struct usbd_hub *hub; /* only if this is a hub */
|
|
|
|
device_ptr_t *subdevs; /* sub-devices, 0 terminated */
|
1998-07-12 23:51:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct usbd_interface {
|
|
|
|
struct usbd_device *device;
|
|
|
|
usb_interface_descriptor_t *idesc;
|
1998-12-09 03:18:10 +03:00
|
|
|
int index;
|
|
|
|
int altindex;
|
1998-07-12 23:51:55 +04:00
|
|
|
struct usbd_endpoint *endpoints;
|
|
|
|
void *priv;
|
|
|
|
LIST_HEAD(, usbd_pipe) pipes;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct usbd_pipe {
|
|
|
|
struct usbd_interface *iface;
|
|
|
|
struct usbd_device *device;
|
|
|
|
struct usbd_endpoint *endpoint;
|
1999-06-14 21:09:57 +04:00
|
|
|
int refcnt;
|
1998-07-12 23:51:55 +04:00
|
|
|
char running;
|
1999-11-12 03:34:57 +03:00
|
|
|
SIMPLEQ_HEAD(, usbd_xfer) queue;
|
1998-07-12 23:51:55 +04:00
|
|
|
LIST_ENTRY(usbd_pipe) next;
|
|
|
|
|
2000-01-19 03:23:58 +03:00
|
|
|
usbd_xfer_handle intrxfer; /* used for repeating requests */
|
1999-06-30 10:44:22 +04:00
|
|
|
char repeat;
|
2000-01-19 03:23:58 +03:00
|
|
|
int interval;
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
/* Filled by HC driver. */
|
1999-09-09 16:26:43 +04:00
|
|
|
struct usbd_pipe_methods *methods;
|
1998-07-12 23:51:55 +04:00
|
|
|
};
|
|
|
|
|
1999-11-12 03:34:57 +03:00
|
|
|
struct usbd_xfer {
|
1998-07-12 23:51:55 +04:00
|
|
|
struct usbd_pipe *pipe;
|
|
|
|
void *priv;
|
|
|
|
void *buffer;
|
|
|
|
u_int32_t length;
|
|
|
|
u_int32_t actlen;
|
|
|
|
u_int16_t flags;
|
|
|
|
u_int32_t timeout;
|
|
|
|
usbd_status status;
|
|
|
|
usbd_callback callback;
|
1999-08-29 21:57:25 +04:00
|
|
|
__volatile char done;
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1999-09-09 16:26:43 +04:00
|
|
|
/* For control pipe */
|
1998-07-12 23:51:55 +04:00
|
|
|
usb_device_request_t request;
|
1999-09-09 16:26:43 +04:00
|
|
|
|
|
|
|
/* For isoc */
|
|
|
|
u_int16_t *frlengths;
|
|
|
|
int nframes;
|
|
|
|
|
|
|
|
/* For memory allocation */
|
1999-09-11 12:19:26 +04:00
|
|
|
struct usbd_device *device;
|
1999-09-09 16:26:43 +04:00
|
|
|
usb_dma_t dmabuf;
|
|
|
|
|
|
|
|
int rqflags;
|
|
|
|
#define URQ_REQUEST 0x01
|
1999-09-11 12:19:26 +04:00
|
|
|
#define URQ_AUTO_DMABUF 0x10
|
|
|
|
#define URQ_DEV_DMABUF 0x20
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1999-11-12 03:34:57 +03:00
|
|
|
SIMPLEQ_ENTRY(usbd_xfer) next;
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1999-09-09 16:26:43 +04:00
|
|
|
void *hcpriv; /* private use by the HC driver */
|
2000-01-19 04:16:38 +03:00
|
|
|
int hcprivint;
|
1998-12-26 15:53:00 +03:00
|
|
|
|
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
struct callout_handle timo_handle;
|
|
|
|
#endif
|
1998-07-12 23:51:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void usbd_init __P((void));
|
1999-10-12 15:54:56 +04:00
|
|
|
void usbd_finish __P((void));
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
/* Routines from usb_subr.c */
|
|
|
|
int usbctlprint __P((void *, const char *));
|
1998-12-30 21:06:25 +03:00
|
|
|
void usb_delay_ms __P((usbd_bus_handle, u_int));
|
1998-07-12 23:51:55 +04:00
|
|
|
void usbd_devinfo_vp __P((usbd_device_handle, char *, char *));
|
|
|
|
usbd_status usbd_reset_port __P((usbd_device_handle dev,
|
|
|
|
int port, usb_port_status_t *ps));
|
|
|
|
usbd_status usbd_setup_pipe __P((usbd_device_handle dev,
|
|
|
|
usbd_interface_handle iface,
|
2000-01-19 03:23:58 +03:00
|
|
|
struct usbd_endpoint *, int,
|
1998-07-12 23:51:55 +04:00
|
|
|
usbd_pipe_handle *pipe));
|
1999-09-05 23:32:18 +04:00
|
|
|
usbd_status usbd_new_device __P((device_ptr_t parent,
|
1998-07-12 23:51:55 +04:00
|
|
|
usbd_bus_handle bus, int depth,
|
|
|
|
int lowspeed, int port,
|
|
|
|
struct usbd_port *));
|
1998-12-26 15:53:00 +03:00
|
|
|
void usbd_remove_device __P((usbd_device_handle,
|
|
|
|
struct usbd_port *));
|
1998-07-12 23:51:55 +04:00
|
|
|
int usbd_printBCD __P((char *cp, int bcd));
|
1998-12-09 03:18:10 +03:00
|
|
|
usbd_status usbd_fill_iface_data __P((usbd_device_handle dev,
|
|
|
|
int i, int a));
|
1999-06-30 10:44:22 +04:00
|
|
|
void usb_free_device __P((usbd_device_handle));
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1999-11-12 03:34:57 +03:00
|
|
|
usbd_status usb_insert_transfer __P((usbd_xfer_handle xfer));
|
|
|
|
void usb_transfer_complete __P((usbd_xfer_handle xfer));
|
1999-10-13 00:02:47 +04:00
|
|
|
void usb_disconnect_port __P((struct usbd_port *up, device_ptr_t));
|
1999-08-23 00:12:39 +04:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
/* Routines from usb.c */
|
|
|
|
void usb_needs_explore __P((usbd_bus_handle));
|
2000-02-22 14:30:54 +03:00
|
|
|
void usb_schedsoftintr __P((struct usbd_bus *));
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1999-09-14 01:33:25 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
#define SPLUSBCHECK \
|
|
|
|
do { int _s = splusb(), _su = splusb(); \
|
1999-10-25 14:51:46 +04:00
|
|
|
extern int cold; \
|
|
|
|
if (!cold && _s != _su) printf("SPLUSBCHECK failed 0x%x!=0x%x, %s:%d\n", \
|
1999-09-14 01:33:25 +04:00
|
|
|
_s, _su, __FILE__, __LINE__); \
|
1999-11-10 07:19:59 +03:00
|
|
|
splx(_s); \
|
1999-09-14 01:33:25 +04:00
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define SPLUSBCHECK
|
|
|
|
#endif
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
/* Locator stuff. */
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
#if defined(__NetBSD__)
|
1998-07-12 23:51:55 +04:00
|
|
|
#include "locators.h"
|
1999-08-17 20:06:20 +04:00
|
|
|
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
|
1999-01-08 14:58:25 +03:00
|
|
|
/* XXX these values are used to statically bind some elements in the USB tree
|
|
|
|
* to specific driver instances. This should be somehow emulated in FreeBSD
|
|
|
|
* but can be done later on.
|
|
|
|
* The values are copied from the files.usb file in the NetBSD sources.
|
|
|
|
*/
|
|
|
|
#define UHUBCF_PORT_DEFAULT -1
|
|
|
|
#define UHUBCF_CONFIGURATION_DEFAULT -1
|
|
|
|
#define UHUBCF_INTERFACE_DEFAULT -1
|
1999-05-16 17:51:05 +04:00
|
|
|
#define UHUBCF_VENDOR_DEFAULT -1
|
|
|
|
#define UHUBCF_PRODUCT_DEFAULT -1
|
|
|
|
#define UHUBCF_RELEASE_DEFAULT -1
|
1998-12-26 15:53:00 +03:00
|
|
|
#endif
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1999-08-17 20:06:20 +04:00
|
|
|
#if defined (__OpenBSD__)
|
|
|
|
#define UHUBCF_PORT 0
|
|
|
|
#define UHUBCF_CONFIGURATION 1
|
|
|
|
#define UHUBCF_INTERFACE 2
|
|
|
|
#define UHUBCF_VENDOR 3
|
|
|
|
#define UHUBCF_PRODUCT 4
|
|
|
|
#define UHUBCF_RELEASE 5
|
|
|
|
#endif
|
|
|
|
|
1998-12-03 01:57:08 +03:00
|
|
|
#define uhubcf_port cf_loc[UHUBCF_PORT]
|
|
|
|
#define uhubcf_configuration cf_loc[UHUBCF_CONFIGURATION]
|
|
|
|
#define uhubcf_interface cf_loc[UHUBCF_INTERFACE]
|
1999-05-16 17:51:05 +04:00
|
|
|
#define uhubcf_vendor cf_loc[UHUBCF_VENDOR]
|
|
|
|
#define uhubcf_product cf_loc[UHUBCF_PRODUCT]
|
|
|
|
#define uhubcf_release cf_loc[UHUBCF_RELEASE]
|
1998-12-03 01:57:08 +03:00
|
|
|
#define UHUB_UNK_PORT UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
|
|
|
|
#define UHUB_UNK_CONFIGURATION UHUBCF_CONFIGURATION_DEFAULT /* wildcarded 'configuration' */
|
|
|
|
#define UHUB_UNK_INTERFACE UHUBCF_INTERFACE_DEFAULT /* wildcarded 'interface' */
|
1999-05-16 17:51:05 +04:00
|
|
|
#define UHUB_UNK_VENDOR UHUBCF_VENDOR_DEFAULT /* wildcarded 'vendor' */
|
|
|
|
#define UHUB_UNK_PRODUCT UHUBCF_PRODUCT_DEFAULT /* wildcarded 'product' */
|
|
|
|
#define UHUB_UNK_RELEASE UHUBCF_RELEASE_DEFAULT /* wildcarded 'release' */
|
1998-07-12 23:51:55 +04:00
|
|
|
|