]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/usb/usb_lookup.h
Update ee(1) in the base system to version 1.5.0.
[FreeBSD/FreeBSD.git] / sys / dev / usb / usb_lookup.h
1 /* $FreeBSD$ */
2 /*-
3  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26
27 #ifndef _USB2_LOOKUP_H_
28 #define _USB2_LOOKUP_H_
29
30 struct usb2_attach_arg;
31
32 /*
33  * The following structure is used when looking up an USB driver for
34  * an USB device. It is inspired by the Linux structure called
35  * "usb2_device_id".
36  */
37 struct usb2_device_id {
38
39         /* Hook for driver specific information */
40         const void *driver_info;
41
42         /* Used for product specific matches; the BCD range is inclusive */
43         uint16_t idVendor;
44         uint16_t idProduct;
45         uint16_t bcdDevice_lo;
46         uint16_t bcdDevice_hi;
47
48         /* Used for device class matches */
49         uint8_t bDeviceClass;
50         uint8_t bDeviceSubClass;
51         uint8_t bDeviceProtocol;
52
53         /* Used for interface class matches */
54         uint8_t bInterfaceClass;
55         uint8_t bInterfaceSubClass;
56         uint8_t bInterfaceProtocol;
57
58         /* Select which fields to match against */
59         uint8_t match_flag_vendor:1;
60         uint8_t match_flag_product:1;
61         uint8_t match_flag_dev_lo:1;
62         uint8_t match_flag_dev_hi:1;
63         uint8_t match_flag_dev_class:1;
64         uint8_t match_flag_dev_subclass:1;
65         uint8_t match_flag_dev_protocol:1;
66         uint8_t match_flag_int_class:1;
67         uint8_t match_flag_int_subclass:1;
68         uint8_t match_flag_int_protocol:1;
69 };
70
71 #define USB_VENDOR(vend)                        \
72   .match_flag_vendor = 1, .idVendor = (vend)
73
74 #define USB_PRODUCT(prod)                       \
75   .match_flag_product = 1, .idProduct = (prod)
76
77 #define USB_VP(vend,prod)                       \
78   USB_VENDOR(vend), USB_PRODUCT(prod)
79
80 #define USB_VPI(vend,prod,info)                 \
81   USB_VENDOR(vend), USB_PRODUCT(prod), USB_DRIVER_INFO(info)
82
83 #define USB_DEV_BCD_GTEQ(lo)    /* greater than or equal */ \
84   .match_flag_dev_lo = 1, .bcdDevice_lo = (lo)
85
86 #define USB_DEV_BCD_LTEQ(hi)    /* less than or equal */ \
87   .match_flag_dev_hi = 1, .bcdDevice_hi = (hi)
88
89 #define USB_DEV_CLASS(dc)                       \
90   .match_flag_dev_class = 1, .bDeviceClass = (dc)
91
92 #define USB_DEV_SUBCLASS(dsc)                   \
93   .match_flag_dev_subclass = 1, .bDeviceSubClass = (dsc)
94
95 #define USB_DEV_PROTOCOL(dp)                    \
96   .match_flag_dev_protocol = 1, .bDeviceProtocol = (dp)
97
98 #define USB_IFACE_CLASS(ic)                     \
99   .match_flag_int_class = 1, .bInterfaceClass = (ic)
100
101 #define USB_IFACE_SUBCLASS(isc)                 \
102   .match_flag_int_subclass = 1, .bInterfaceSubClass = (isc)
103
104 #define USB_IFACE_PROTOCOL(ip)                  \
105   .match_flag_int_protocol = 1, .bInterfaceProtocol = (ip)
106
107 #define USB_IF_CSI(class,subclass,info)                 \
108   USB_IFACE_CLASS(class), USB_IFACE_SUBCLASS(subclass), USB_DRIVER_INFO(info)
109
110 #define USB_DRIVER_INFO(ptr)                    \
111   .driver_info = ((const void *)(ptr))
112
113 #define USB_GET_DRIVER_INFO(did)                \
114   (((const uint8_t *)((did)->driver_info)) - ((const uint8_t *)0))
115
116 const struct usb2_device_id *usb2_lookup_id_by_info(
117             const struct usb2_device_id *id, usb2_size_t sizeof_id,
118             const struct usb2_lookup_info *info);
119 int     usb2_lookup_id_by_uaa(const struct usb2_device_id *id,
120             usb2_size_t sizeof_id, struct usb2_attach_arg *uaa);
121
122 #endif                                  /* _USB2_LOOKUP_H_ */