[BACK]Return to usbdi.h CVS log [TXT][DIR] Up to [local] / sys / dev / usb

Annotation of sys/dev/usb/usbdi.h, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: usbdi.h,v 1.29 2007/06/18 11:37:04 mbalmer Exp $ */
                      2: /*     $NetBSD: usbdi.h,v 1.62 2002/07/11 21:14:35 augustss Exp $      */
                      3: /*     $FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $      */
                      4:
                      5: /*
                      6:  * Copyright (c) 1998 The NetBSD Foundation, Inc.
                      7:  * All rights reserved.
                      8:  *
                      9:  * This code is derived from software contributed to The NetBSD Foundation
                     10:  * by Lennart Augustsson (lennart@augustsson.net) at
                     11:  * Carlstedt Research & Technology.
                     12:  *
                     13:  * Redistribution and use in source and binary forms, with or without
                     14:  * modification, are permitted provided that the following conditions
                     15:  * are met:
                     16:  * 1. Redistributions of source code must retain the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer.
                     18:  * 2. Redistributions in binary form must reproduce the above copyright
                     19:  *    notice, this list of conditions and the following disclaimer in the
                     20:  *    documentation and/or other materials provided with the distribution.
                     21:  * 3. All advertising materials mentioning features or use of this software
                     22:  *    must display the following acknowledgement:
                     23:  *        This product includes software developed by the NetBSD
                     24:  *        Foundation, Inc. and its contributors.
                     25:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     26:  *    contributors may be used to endorse or promote products derived
                     27:  *    from this software without specific prior written permission.
                     28:  *
                     29:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     30:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     31:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     32:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     33:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     34:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     35:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     36:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     37:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     38:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     39:  * POSSIBILITY OF SUCH DAMAGE.
                     40:  */
                     41:
                     42: typedef struct usbd_bus                *usbd_bus_handle;
                     43: typedef struct usbd_device     *usbd_device_handle;
                     44: typedef struct usbd_interface  *usbd_interface_handle;
                     45: typedef struct usbd_pipe       *usbd_pipe_handle;
                     46: typedef struct usbd_xfer       *usbd_xfer_handle;
                     47: typedef void                   *usbd_private_handle;
                     48:
                     49: typedef enum {         /* keep in sync with usbd_status_msgs */
                     50:        USBD_NORMAL_COMPLETION = 0, /* must be 0 */
                     51:        USBD_IN_PROGRESS,       /* 1 */
                     52:        /* errors */
                     53:        USBD_PENDING_REQUESTS,  /* 2 */
                     54:        USBD_NOT_STARTED,       /* 3 */
                     55:        USBD_INVAL,             /* 4 */
                     56:        USBD_NOMEM,             /* 5 */
                     57:        USBD_CANCELLED,         /* 6 */
                     58:        USBD_BAD_ADDRESS,       /* 7 */
                     59:        USBD_IN_USE,            /* 8 */
                     60:        USBD_NO_ADDR,           /* 9 */
                     61:        USBD_SET_ADDR_FAILED,   /* 10 */
                     62:        USBD_NO_POWER,          /* 11 */
                     63:        USBD_TOO_DEEP,          /* 12 */
                     64:        USBD_IOERROR,           /* 13 */
                     65:        USBD_NOT_CONFIGURED,    /* 14 */
                     66:        USBD_TIMEOUT,           /* 15 */
                     67:        USBD_SHORT_XFER,        /* 16 */
                     68:        USBD_STALLED,           /* 17 */
                     69:        USBD_INTERRUPTED,       /* 18 */
                     70:
                     71:        USBD_ERROR_MAX          /* must be last */
                     72: } usbd_status;
                     73:
                     74: typedef void (*usbd_callback)(usbd_xfer_handle, usbd_private_handle,
                     75:                              usbd_status);
                     76:
                     77: /* Open flags */
                     78: #define USBD_EXCLUSIVE_USE     0x01
                     79:
                     80: /* Use default (specified by ep. desc.) interval on interrupt pipe */
                     81: #define USBD_DEFAULT_INTERVAL  (-1)
                     82:
                     83: /* Request flags */
                     84: #define USBD_NO_COPY           0x01    /* do not copy data to DMA buffer */
                     85: #define USBD_SYNCHRONOUS       0x02    /* wait for completion */
                     86: /* in usb.h #define USBD_SHORT_XFER_OK 0x04*/  /* allow short reads */
                     87: #define USBD_FORCE_SHORT_XFER  0x08    /* force last short packet on write */
                     88:
                     89: #define USBD_NO_TIMEOUT 0
                     90: #define USBD_DEFAULT_TIMEOUT 5000 /* ms = 5 s */
                     91:
                     92: #define DEVINFOSIZE 1024
                     93:
                     94: usbd_status usbd_open_pipe(usbd_interface_handle iface, u_int8_t address,
                     95:     u_int8_t flags, usbd_pipe_handle *pipe);
                     96: usbd_status usbd_close_pipe(usbd_pipe_handle pipe);
                     97: usbd_status usbd_transfer(usbd_xfer_handle req);
                     98: usbd_xfer_handle usbd_alloc_xfer(usbd_device_handle);
                     99: usbd_status usbd_free_xfer(usbd_xfer_handle xfer);
                    100: void usbd_setup_xfer(usbd_xfer_handle xfer, usbd_pipe_handle pipe,
                    101:     usbd_private_handle priv, void *buffer, u_int32_t length, u_int16_t flags,
                    102:     u_int32_t timeout, usbd_callback);
                    103: void usbd_setup_default_xfer(usbd_xfer_handle xfer, usbd_device_handle dev,
                    104:     usbd_private_handle priv, u_int32_t timeout, usb_device_request_t *req,
                    105:     void *buffer, u_int32_t length, u_int16_t flags, usbd_callback);
                    106: void usbd_setup_isoc_xfer(usbd_xfer_handle xfer, usbd_pipe_handle pipe,
                    107:     usbd_private_handle priv, u_int16_t *frlengths, u_int32_t nframes,
                    108:     u_int16_t flags, usbd_callback);
                    109: void usbd_get_xfer_status(usbd_xfer_handle xfer, usbd_private_handle *priv,
                    110:     void **buffer, u_int32_t *count, usbd_status *status);
                    111: usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor(
                    112:     usbd_interface_handle iface, u_int8_t address);
                    113: usbd_status usbd_abort_pipe(usbd_pipe_handle pipe);
                    114: usbd_status usbd_clear_endpoint_stall(usbd_pipe_handle pipe);
                    115: usbd_status usbd_clear_endpoint_stall_async(usbd_pipe_handle pipe);
                    116: void usbd_clear_endpoint_toggle(usbd_pipe_handle pipe);
                    117: usbd_status usbd_endpoint_count(usbd_interface_handle dev, u_int8_t *count);
                    118: usbd_status usbd_interface_count(usbd_device_handle dev, u_int8_t *count);
                    119: void usbd_interface2device_handle(usbd_interface_handle iface,
                    120:     usbd_device_handle *dev);
                    121: usbd_status usbd_device2interface_handle(usbd_device_handle dev,
                    122:     u_int8_t ifaceno, usbd_interface_handle *iface);
                    123:
                    124: usbd_device_handle usbd_pipe2device_handle(usbd_pipe_handle);
                    125: void *usbd_alloc_buffer(usbd_xfer_handle xfer, u_int32_t size);
                    126: void usbd_free_buffer(usbd_xfer_handle xfer);
                    127: void *usbd_get_buffer(usbd_xfer_handle xfer);
                    128: usbd_status usbd_sync_transfer(usbd_xfer_handle req);
                    129: usbd_status usbd_open_pipe_intr(usbd_interface_handle iface, u_int8_t address,
                    130:     u_int8_t flags, usbd_pipe_handle *pipe, usbd_private_handle priv,
                    131:     void *buffer, u_int32_t length, usbd_callback, int);
                    132: usbd_status usbd_do_request(usbd_device_handle pipe, usb_device_request_t *req,
                    133:     void *data);
                    134: usbd_status usbd_do_request_async(usbd_device_handle pipe,
                    135:     usb_device_request_t *req, void *data);
                    136: usbd_status usbd_do_request_flags(usbd_device_handle pipe,
                    137:     usb_device_request_t *req, void *data, u_int16_t flags, int*, u_int32_t);
                    138: usbd_status usbd_do_request_flags_pipe( usbd_device_handle dev,
                    139:     usbd_pipe_handle pipe, usb_device_request_t *req, void *data,
                    140:     u_int16_t flags, int *actlen, u_int32_t);
                    141: usb_interface_descriptor_t *usbd_get_interface_descriptor(
                    142:     usbd_interface_handle iface);
                    143: usb_config_descriptor_t *usbd_get_config_descriptor(usbd_device_handle dev);
                    144: usb_device_descriptor_t *usbd_get_device_descriptor(usbd_device_handle dev);
                    145: usbd_status usbd_set_interface(usbd_interface_handle, int);
                    146: int usbd_get_no_alts(usb_config_descriptor_t *, int);
                    147: usbd_status  usbd_get_interface(usbd_interface_handle iface, u_int8_t *aiface);
                    148: void usbd_fill_deviceinfo(usbd_device_handle, struct usb_device_info *, int);
                    149: int usbd_get_interface_altindex(usbd_interface_handle iface);
                    150:
                    151: usb_interface_descriptor_t *usbd_find_idesc(usb_config_descriptor_t *cd,
                    152:     int iindex, int ano);
                    153: usb_endpoint_descriptor_t *usbd_find_edesc(usb_config_descriptor_t *cd,
                    154:     int ifaceidx, int altidx, int endptidx);
                    155:
                    156: void usbd_dopoll(usbd_interface_handle);
                    157: void usbd_set_polling(usbd_device_handle iface, int on);
                    158:
                    159: const char *usbd_errstr(usbd_status err);
                    160:
                    161: void usbd_add_dev_event(int, usbd_device_handle);
                    162: void usbd_add_drv_event(int, usbd_device_handle, struct device *);
                    163:
                    164: char *usbd_devinfo_alloc(usbd_device_handle dev, int showclass);
                    165: void usbd_devinfo_free(char *devinfop);
                    166:
                    167: const struct usbd_quirks *usbd_get_quirks(usbd_device_handle);
                    168: usb_endpoint_descriptor_t *usbd_get_endpoint_descriptor(
                    169:     usbd_interface_handle iface, u_int8_t address);
                    170:
                    171: usbd_status usbd_reload_device_desc(usbd_device_handle);
                    172:
                    173: int usbd_ratecheck(struct timeval *last);
                    174:
                    175: /* An iterator for descriptors. */
                    176: typedef struct {
                    177:        const uByte *cur;
                    178:        const uByte *end;
                    179: } usbd_desc_iter_t;
                    180: void usb_desc_iter_init(usbd_device_handle, usbd_desc_iter_t *);
                    181: const usb_descriptor_t *usb_desc_iter_next(usbd_desc_iter_t *);
                    182:
                    183: /*
                    184:  * The usb_task structs form a queue of things to run in the USB event
                    185:  * thread.  Normally this is just device discovery when a connect/disconnect
                    186:  * has been detected.  But it may also be used by drivers that need to
                    187:  * perform (short) tasks that must have a process context.
                    188:  */
                    189: struct usb_task {
                    190:        TAILQ_ENTRY(usb_task) next;
                    191:        void (*fun)(void *);
                    192:        void *arg;
                    193:        char onqueue;
                    194: };
                    195:
                    196: void usb_add_task(usbd_device_handle dev, struct usb_task *task);
                    197: void usb_rem_task(usbd_device_handle dev, struct usb_task *task);
                    198: #define usb_init_task(t, f, a) ((t)->fun = (f), (t)->arg = (a), (t)->onqueue = 0)
                    199:
                    200: struct usb_devno {
                    201:        u_int16_t ud_vendor;
                    202:        u_int16_t ud_product;
                    203: };
                    204: const struct usb_devno *usb_match_device(const struct usb_devno *tbl,
                    205:     u_int nentries, u_int sz, u_int16_t vendor, u_int16_t product);
                    206: #define usb_lookup(tbl, vendor, product) \
                    207:        usb_match_device((const struct usb_devno *)(tbl), sizeof (tbl) / sizeof ((tbl)[0]), sizeof ((tbl)[0]), (vendor), (product))
                    208: #define        USB_PRODUCT_ANY         0xffff
                    209:
                    210: /* NetBSD attachment information */
                    211:
                    212: /* Attach data */
                    213: struct usb_attach_arg {
                    214:        int                     port;
                    215:        int                     configno;
                    216:        int                     ifaceno;
                    217:        int                     vendor;
                    218:        int                     product;
                    219:        int                     release;
                    220:        int                     matchlvl;
                    221:        usbd_device_handle      device; /* current device */
                    222:        usbd_interface_handle   iface; /* current interface */
                    223:        int                     usegeneric;
                    224:        usbd_interface_handle  *ifaces; /* all interfaces */
                    225:        int                     nifaces; /* number of interfaces */
                    226: };
                    227:
                    228: /* Match codes. */
                    229: /* First five codes is for a whole device. */
                    230: #define UMATCH_VENDOR_PRODUCT_REV                      14
                    231: #define UMATCH_VENDOR_PRODUCT                          13
                    232: #define UMATCH_VENDOR_DEVCLASS_DEVPROTO                        12
                    233: #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO           11
                    234: #define UMATCH_DEVCLASS_DEVSUBCLASS                    10
                    235: /* Next six codes are for interfaces. */
                    236: #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE            9
                    237: #define UMATCH_VENDOR_PRODUCT_CONF_IFACE                8
                    238: #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO          7
                    239: #define UMATCH_VENDOR_IFACESUBCLASS                     6
                    240: #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO      5
                    241: #define UMATCH_IFACECLASS_IFACESUBCLASS                         4
                    242: #define UMATCH_IFACECLASS                               3
                    243: #define UMATCH_IFACECLASS_GENERIC                       2
                    244: /* Generic driver */
                    245: #define UMATCH_GENERIC                                  1
                    246: /* No match */
                    247: #define UMATCH_NONE                                     0
                    248:
                    249: /* XXX Perhaps USB should have its own levels? */
                    250: #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
                    251: #define splusb splsoftnet
                    252: #else
                    253: #define splusb splbio
                    254: #endif /* __HAVE_GENERIC_SOFT_INTERRUPTS */
                    255: #define splhardusb splbio
                    256: #define IPL_USB IPL_BIO

CVSweb