Mon Feb 14 09:23:32 2022 UTC ()
usbdi(9): Add some missing header include guards.


(riastradh)
diff -r1.35 -r1.36 src/sys/dev/usb/usb_mem.h
diff -r1.130 -r1.131 src/sys/dev/usb/usbdivar.h

cvs diff -r1.35 -r1.36 src/sys/dev/usb/usb_mem.h (switch to unified diff)

--- src/sys/dev/usb/usb_mem.h 2021/12/21 09:51:22 1.35
+++ src/sys/dev/usb/usb_mem.h 2022/02/14 09:23:32 1.36
@@ -1,62 +1,67 @@ @@ -1,62 +1,67 @@
1/* $NetBSD: usb_mem.h,v 1.35 2021/12/21 09:51:22 skrll Exp $ */ 1/* $NetBSD: usb_mem.h,v 1.36 2022/02/14 09:23:32 riastradh Exp $ */
2/* $FreeBSD: src/sys/dev/usb/usb_mem.h,v 1.9 1999/11/17 22:33:47 n_hibma Exp $ */ 2/* $FreeBSD: src/sys/dev/usb/usb_mem.h,v 1.9 1999/11/17 22:33:47 n_hibma Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to The NetBSD Foundation 8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (lennart@augustsson.net) at 9 * by Lennart Augustsson (lennart@augustsson.net) at
10 * Carlstedt Research & Technology. 10 * Carlstedt Research & Technology.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
15 * 1. Redistributions of source code must retain the above copyright 15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer. 16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright 17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the 18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution. 19 * documentation and/or other materials provided with the distribution.
20 * 20 *
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE. 31 * POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
 34#ifndef _DEV_USB_USB_MEM_H_
 35#define _DEV_USB_USB_MEM_H_
 36
34typedef struct usb_dma_block { 37typedef struct usb_dma_block {
35 bus_dma_tag_t tag; 38 bus_dma_tag_t tag;
36 bus_dmamap_t map; 39 bus_dmamap_t map;
37 void *kaddr; 40 void *kaddr;
38 bus_dma_segment_t *segs; 41 bus_dma_segment_t *segs;
39 int nsegs; 42 int nsegs;
40 int nsegs_alloc; 43 int nsegs_alloc;
41 size_t size; 44 size_t size;
42 size_t align; 45 size_t align;
43 int flags; 46 int flags;
44#define USB_DMA_FULLBLOCK __BIT(0) 47#define USB_DMA_FULLBLOCK __BIT(0)
45#define USB_DMA_COHERENT __BIT(1) 48#define USB_DMA_COHERENT __BIT(1)
46 49
47 LIST_ENTRY(usb_dma_block) next; 50 LIST_ENTRY(usb_dma_block) next;
48} usb_dma_block_t; 51} usb_dma_block_t;
49 52
50#define USBMALLOC_MULTISEG __BIT(0) 53#define USBMALLOC_MULTISEG __BIT(0)
51#define USBMALLOC_COHERENT __BIT(1) 54#define USBMALLOC_COHERENT __BIT(1)
52#define USBMALLOC_ZERO __BIT(2) 55#define USBMALLOC_ZERO __BIT(2)
53 56
54int usb_allocmem(bus_dma_tag_t, size_t, size_t, u_int, usb_dma_t *); 57int usb_allocmem(bus_dma_tag_t, size_t, size_t, u_int, usb_dma_t *);
55void usb_freemem(usb_dma_t *); 58void usb_freemem(usb_dma_t *);
56void usb_syncmem(usb_dma_t *, bus_addr_t, bus_size_t, int); 59void usb_syncmem(usb_dma_t *, bus_addr_t, bus_size_t, int);
57 60
58bus_addr_t usb_dmaaddr(usb_dma_t *, unsigned int); 61bus_addr_t usb_dmaaddr(usb_dma_t *, unsigned int);
59 62
60#define DMAADDR(dma, o) usb_dmaaddr((dma), (o)) 63#define DMAADDR(dma, o) usb_dmaaddr((dma), (o))
61#define KERNADDR(dma, o) \ 64#define KERNADDR(dma, o) \
62 ((void *)((char *)(dma)->udma_block->kaddr + (dma)->udma_offs + (o))) 65 ((void *)((char *)(dma)->udma_block->kaddr + (dma)->udma_offs + (o)))
 66
 67#endif /* _DEV_USB_USB_MEM_H_ */

cvs diff -r1.130 -r1.131 src/sys/dev/usb/usbdivar.h (switch to unified diff)

--- src/sys/dev/usb/usbdivar.h 2021/09/07 10:44:18 1.130
+++ src/sys/dev/usb/usbdivar.h 2022/02/14 09:23:32 1.131
@@ -1,399 +1,404 @@ @@ -1,399 +1,404 @@
1/* $NetBSD: usbdivar.h,v 1.130 2021/09/07 10:44:18 riastradh Exp $ */ 1/* $NetBSD: usbdivar.h,v 1.131 2022/02/14 09:23:32 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2012 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2012 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net) at 8 * by Lennart Augustsson (lennart@augustsson.net) at
9 * Carlstedt Research & Technology and Matthew R. Green (mrg@eterna.com.au). 9 * Carlstedt Research & Technology and Matthew R. Green (mrg@eterna.com.au).
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer. 15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright 16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the 17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution. 18 * documentation and/or other materials provided with the distribution.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
 33#ifndef _DEV_USB_USBDIVAR_H_
 34#define _DEV_USB_USBDIVAR_H_
 35
33/* 36/*
34 * Discussion about locking in the USB code: 37 * Discussion about locking in the USB code:
35 * 38 *
36 * The host controller presents one lock at IPL_SOFTUSB (aka IPL_SOFTNET). 39 * The host controller presents one lock at IPL_SOFTUSB (aka IPL_SOFTNET).
37 * 40 *
38 * List of hardware interface methods, and whether the lock is held 41 * List of hardware interface methods, and whether the lock is held
39 * when each is called by this module: 42 * when each is called by this module:
40 * 43 *
41 * BUS METHOD LOCK NOTES 44 * BUS METHOD LOCK NOTES
42 * ----------------------- ------- ------------------------- 45 * ----------------------- ------- -------------------------
43 * ubm_open - might want to take lock? 46 * ubm_open - might want to take lock?
44 * ubm_softint x 47 * ubm_softint x
45 * ubm_dopoll - might want to take lock? 48 * ubm_dopoll - might want to take lock?
46 * ubm_allocx - 49 * ubm_allocx -
47 * ubm_freex - 50 * ubm_freex -
48 * ubm_getlock - Called at attach time 51 * ubm_getlock - Called at attach time
49 * ubm_newdev - Will take lock 52 * ubm_newdev - Will take lock
50 ubm_rhctrl 53 ubm_rhctrl
51 * 54 *
52 * PIPE METHOD LOCK NOTES 55 * PIPE METHOD LOCK NOTES
53 * ----------------------- ------- ------------------------- 56 * ----------------------- ------- -------------------------
54 * upm_transfer - 57 * upm_transfer -
55 * upm_start - might want to take lock? 58 * upm_start - might want to take lock?
56 * upm_abort x 59 * upm_abort x
57 * upm_close x 60 * upm_close x
58 * upm_cleartoggle - 61 * upm_cleartoggle -
59 * upm_done x 62 * upm_done x
60 * 63 *
61 * The above semantics are likely to change. Little performance 64 * The above semantics are likely to change. Little performance
62 * evaluation has been done on this code and the locking strategy. 65 * evaluation has been done on this code and the locking strategy.
63 * 66 *
64 * USB functions known to expect the lock taken include (this list is 67 * USB functions known to expect the lock taken include (this list is
65 * probably not exhaustive): 68 * probably not exhaustive):
66 * usb_transfer_complete() 69 * usb_transfer_complete()
67 * usb_insert_transfer() 70 * usb_insert_transfer()
68 * usb_start_next() 71 * usb_start_next()
69 * 72 *
70 */ 73 */
71 74
72#include <sys/callout.h> 75#include <sys/callout.h>
73#include <sys/mutex.h> 76#include <sys/mutex.h>
74#include <sys/bus.h> 77#include <sys/bus.h>
75 78
76/* From usb_mem.h */ 79/* From usb_mem.h */
77struct usb_dma_block; 80struct usb_dma_block;
78typedef struct { 81typedef struct {
79 struct usb_dma_block *udma_block; 82 struct usb_dma_block *udma_block;
80 u_int udma_offs; 83 u_int udma_offs;
81} usb_dma_t; 84} usb_dma_t;
82 85
83struct usbd_xfer; 86struct usbd_xfer;
84struct usbd_pipe; 87struct usbd_pipe;
85struct usbd_port; 88struct usbd_port;
86 89
87struct usbd_endpoint { 90struct usbd_endpoint {
88 usb_endpoint_descriptor_t *ue_edesc; 91 usb_endpoint_descriptor_t *ue_edesc;
89 int ue_refcnt; 92 int ue_refcnt;
90 int ue_toggle; 93 int ue_toggle;
91}; 94};
92 95
93struct usbd_bus_methods { 96struct usbd_bus_methods {
94 usbd_status (*ubm_open)(struct usbd_pipe *); 97 usbd_status (*ubm_open)(struct usbd_pipe *);
95 void (*ubm_softint)(void *); 98 void (*ubm_softint)(void *);
96 void (*ubm_dopoll)(struct usbd_bus *); 99 void (*ubm_dopoll)(struct usbd_bus *);
97 struct usbd_xfer *(*ubm_allocx)(struct usbd_bus *, unsigned int); 100 struct usbd_xfer *(*ubm_allocx)(struct usbd_bus *, unsigned int);
98 void (*ubm_freex)(struct usbd_bus *, struct usbd_xfer *); 101 void (*ubm_freex)(struct usbd_bus *, struct usbd_xfer *);
99 void (*ubm_abortx)(struct usbd_xfer *); 102 void (*ubm_abortx)(struct usbd_xfer *);
100 bool (*ubm_dying)(struct usbd_bus *); 103 bool (*ubm_dying)(struct usbd_bus *);
101 void (*ubm_getlock)(struct usbd_bus *, kmutex_t **); 104 void (*ubm_getlock)(struct usbd_bus *, kmutex_t **);
102 usbd_status (*ubm_newdev)(device_t, struct usbd_bus *, int, 105 usbd_status (*ubm_newdev)(device_t, struct usbd_bus *, int,
103 int, int, struct usbd_port *); 106 int, int, struct usbd_port *);
104 107
105 int (*ubm_rhctrl)(struct usbd_bus *, 108 int (*ubm_rhctrl)(struct usbd_bus *,
106 usb_device_request_t *, void *, int); 109 usb_device_request_t *, void *, int);
107}; 110};
108 111
109struct usbd_pipe_methods { 112struct usbd_pipe_methods {
110 int (*upm_init)(struct usbd_xfer *); 113 int (*upm_init)(struct usbd_xfer *);
111 void (*upm_fini)(struct usbd_xfer *); 114 void (*upm_fini)(struct usbd_xfer *);
112 usbd_status (*upm_transfer)(struct usbd_xfer *); 115 usbd_status (*upm_transfer)(struct usbd_xfer *);
113 usbd_status (*upm_start)(struct usbd_xfer *); 116 usbd_status (*upm_start)(struct usbd_xfer *);
114 void (*upm_abort)(struct usbd_xfer *); 117 void (*upm_abort)(struct usbd_xfer *);
115 void (*upm_close)(struct usbd_pipe *); 118 void (*upm_close)(struct usbd_pipe *);
116 void (*upm_cleartoggle)(struct usbd_pipe *); 119 void (*upm_cleartoggle)(struct usbd_pipe *);
117 void (*upm_done)(struct usbd_xfer *); 120 void (*upm_done)(struct usbd_xfer *);
118}; 121};
119 122
120struct usbd_tt { 123struct usbd_tt {
121 struct usbd_hub *utt_hub; 124 struct usbd_hub *utt_hub;
122}; 125};
123 126
124struct usbd_port { 127struct usbd_port {
125 usb_port_status_t up_status; 128 usb_port_status_t up_status;
126 uint16_t up_power; /* mA of current on port */ 129 uint16_t up_power; /* mA of current on port */
127 uint8_t up_portno; 130 uint8_t up_portno;
128 uint8_t up_restartcnt; 131 uint8_t up_restartcnt;
129#define USBD_RESTART_MAX 5 132#define USBD_RESTART_MAX 5
130 uint8_t up_reattach; 133 uint8_t up_reattach;
131 struct usbd_device *up_dev; /* Connected device */ 134 struct usbd_device *up_dev; /* Connected device */
132 struct usbd_device *up_parent; /* The ports hub */ 135 struct usbd_device *up_parent; /* The ports hub */
133 struct usbd_tt *up_tt; /* Transaction translator (if any) */ 136 struct usbd_tt *up_tt; /* Transaction translator (if any) */
134}; 137};
135 138
136struct usbd_hub { 139struct usbd_hub {
137 usbd_status (*uh_explore)(struct usbd_device *hub); 140 usbd_status (*uh_explore)(struct usbd_device *hub);
138 void *uh_hubsoftc; 141 void *uh_hubsoftc;
139 usb_hub_descriptor_t uh_hubdesc; 142 usb_hub_descriptor_t uh_hubdesc;
140 struct usbd_port uh_ports[1]; 143 struct usbd_port uh_ports[1];
141}; 144};
142 145
143/*****/ 146/*****/
144/* 0, root, and 1->127 */ 147/* 0, root, and 1->127 */
145#define USB_ROOTHUB_INDEX 1 148#define USB_ROOTHUB_INDEX 1
146#define USB_TOTAL_DEVICES (USB_MAX_DEVICES + 1) 149#define USB_TOTAL_DEVICES (USB_MAX_DEVICES + 1)
147 150
148struct usbd_bus { 151struct usbd_bus {
149 /* Filled by HC driver */ 152 /* Filled by HC driver */
150 void *ub_hcpriv; 153 void *ub_hcpriv;
151 int ub_revision; /* USB revision */ 154 int ub_revision; /* USB revision */
152#define USBREV_UNKNOWN 0 155#define USBREV_UNKNOWN 0
153#define USBREV_PRE_1_0 1 156#define USBREV_PRE_1_0 1
154#define USBREV_1_0 2 157#define USBREV_1_0 2
155#define USBREV_1_1 3 158#define USBREV_1_1 3
156#define USBREV_2_0 4 159#define USBREV_2_0 4
157#define USBREV_3_0 5 160#define USBREV_3_0 5
158#define USBREV_3_1 6 161#define USBREV_3_1 6
159#define USBREV_STR { "unknown", "pre 1.0", "1.0", "1.1", "2.0", "3.0", "3.1" } 162#define USBREV_STR { "unknown", "pre 1.0", "1.0", "1.1", "2.0", "3.0", "3.1" }
160 int ub_hctype; 163 int ub_hctype;
161#define USBHCTYPE_UNKNOWN 0 164#define USBHCTYPE_UNKNOWN 0
162#define USBHCTYPE_MOTG 1 165#define USBHCTYPE_MOTG 1
163#define USBHCTYPE_OHCI 2 166#define USBHCTYPE_OHCI 2
164#define USBHCTYPE_UHCI 3 167#define USBHCTYPE_UHCI 3
165#define USBHCTYPE_EHCI 4 168#define USBHCTYPE_EHCI 4
166#define USBHCTYPE_XHCI 5 169#define USBHCTYPE_XHCI 5
167#define USBHCTYPE_VHCI 6 170#define USBHCTYPE_VHCI 6
168 int ub_busnum; 171 int ub_busnum;
169 const struct usbd_bus_methods 172 const struct usbd_bus_methods
170 *ub_methods; 173 *ub_methods;
171 uint32_t ub_pipesize; /* size of a pipe struct */ 174 uint32_t ub_pipesize; /* size of a pipe struct */
172 bool ub_usedma; /* Does this HC support DMA */ 175 bool ub_usedma; /* Does this HC support DMA */
173 int ub_dmaflags; 176 int ub_dmaflags;
174 bus_dma_tag_t ub_dmatag; /* DMA tag */ 177 bus_dma_tag_t ub_dmatag; /* DMA tag */
175 178
176 /* Filled by usb driver */ 179 /* Filled by usb driver */
177 kmutex_t *ub_lock; 180 kmutex_t *ub_lock;
178 struct usbd_device *ub_roothub; 181 struct usbd_device *ub_roothub;
179 uint8_t ub_rhaddr; /* roothub address */ 182 uint8_t ub_rhaddr; /* roothub address */
180 uint8_t ub_rhconf; /* roothub configuration */ 183 uint8_t ub_rhconf; /* roothub configuration */
181 struct usbd_device *ub_devices[USB_TOTAL_DEVICES]; 184 struct usbd_device *ub_devices[USB_TOTAL_DEVICES];
182 kcondvar_t ub_needsexplore_cv; 185 kcondvar_t ub_needsexplore_cv;
183 char ub_needsexplore;/* a hub a signalled a change */ 186 char ub_needsexplore;/* a hub a signalled a change */
184 char ub_usepolling; 187 char ub_usepolling;
185 device_t ub_usbctl; 188 device_t ub_usbctl;
186 struct usb_device_stats ub_stats; 189 struct usb_device_stats ub_stats;
187 190
188 void *ub_soft; /* soft interrupt cookie */ 191 void *ub_soft; /* soft interrupt cookie */
189}; 192};
190 193
191struct usbd_device { 194struct usbd_device {
192 struct usbd_bus *ud_bus; /* our controller */ 195 struct usbd_bus *ud_bus; /* our controller */
193 struct usbd_pipe *ud_pipe0; /* pipe 0 */ 196 struct usbd_pipe *ud_pipe0; /* pipe 0 */
194 uint8_t ud_addr; /* device address */ 197 uint8_t ud_addr; /* device address */
195 uint8_t ud_config; /* current configuration # */ 198 uint8_t ud_config; /* current configuration # */
196 uint8_t ud_depth; /* distance from root hub */ 199 uint8_t ud_depth; /* distance from root hub */
197 uint8_t ud_speed; /* low/full/high speed */ 200 uint8_t ud_speed; /* low/full/high speed */
198 uint8_t ud_selfpowered; /* flag for self powered */ 201 uint8_t ud_selfpowered; /* flag for self powered */
199 uint16_t ud_power; /* mA the device uses */ 202 uint16_t ud_power; /* mA the device uses */
200 int16_t ud_langid; /* language for strings */ 203 int16_t ud_langid; /* language for strings */
201#define USBD_NOLANG (-1) 204#define USBD_NOLANG (-1)
202 usb_event_cookie_t ud_cookie; /* unique connection id */ 205 usb_event_cookie_t ud_cookie; /* unique connection id */
203 struct usbd_port *ud_powersrc; /* upstream hub port, or 0 */ 206 struct usbd_port *ud_powersrc; /* upstream hub port, or 0 */
204 struct usbd_device *ud_myhub; /* upstream hub */ 207 struct usbd_device *ud_myhub; /* upstream hub */
205 struct usbd_port *ud_myhsport; /* closest high speed port */ 208 struct usbd_port *ud_myhsport; /* closest high speed port */
206 struct usbd_endpoint ud_ep0; /* for pipe 0 */ 209 struct usbd_endpoint ud_ep0; /* for pipe 0 */
207 usb_endpoint_descriptor_t 210 usb_endpoint_descriptor_t
208 ud_ep0desc; /* for pipe 0 */ 211 ud_ep0desc; /* for pipe 0 */
209 struct usbd_interface *ud_ifaces; /* array of all interfaces */ 212 struct usbd_interface *ud_ifaces; /* array of all interfaces */
210 usb_device_descriptor_t ud_ddesc; /* device descriptor */ 213 usb_device_descriptor_t ud_ddesc; /* device descriptor */
211 usb_config_descriptor_t *ud_cdesc; /* full config descr */ 214 usb_config_descriptor_t *ud_cdesc; /* full config descr */
212 usb_bos_descriptor_t *ud_bdesc; /* full BOS descr */ 215 usb_bos_descriptor_t *ud_bdesc; /* full BOS descr */
213 const struct usbd_quirks 216 const struct usbd_quirks
214 *ud_quirks; /* device quirks, always set */ 217 *ud_quirks; /* device quirks, always set */
215 struct usbd_hub *ud_hub; /* only if this is a hub */ 218 struct usbd_hub *ud_hub; /* only if this is a hub */
216 u_int ud_subdevlen; /* array length of following */ 219 u_int ud_subdevlen; /* array length of following */
217 device_t *ud_subdevs; /* sub-devices */ 220 device_t *ud_subdevs; /* sub-devices */
218 int ud_nifaces_claimed; /* number of ifaces in use */ 221 int ud_nifaces_claimed; /* number of ifaces in use */
219 void *ud_hcpriv; 222 void *ud_hcpriv;
220 223
221 char *ud_serial; /* serial number, can be NULL */ 224 char *ud_serial; /* serial number, can be NULL */
222 char *ud_vendor; /* vendor string, can be NULL */ 225 char *ud_vendor; /* vendor string, can be NULL */
223 char *ud_product; /* product string can be NULL */ 226 char *ud_product; /* product string can be NULL */
224}; 227};
225 228
226struct usbd_interface { 229struct usbd_interface {
227 struct usbd_device *ui_dev; 230 struct usbd_device *ui_dev;
228 usb_interface_descriptor_t 231 usb_interface_descriptor_t
229 *ui_idesc; 232 *ui_idesc;
230 int ui_index; 233 int ui_index;
231 int ui_altindex; 234 int ui_altindex;
232 struct usbd_endpoint *ui_endpoints; 235 struct usbd_endpoint *ui_endpoints;
233 int64_t ui_busy; /* #pipes, or -1 if setting */ 236 int64_t ui_busy; /* #pipes, or -1 if setting */
234}; 237};
235 238
236struct usbd_pipe { 239struct usbd_pipe {
237 struct usbd_interface *up_iface; 240 struct usbd_interface *up_iface;
238 struct usbd_device *up_dev; 241 struct usbd_device *up_dev;
239 struct usbd_endpoint *up_endpoint; 242 struct usbd_endpoint *up_endpoint;
240 char up_running; 243 char up_running;
241 char up_aborting; 244 char up_aborting;
242 bool up_serialise; 245 bool up_serialise;
243 SIMPLEQ_HEAD(, usbd_xfer) 246 SIMPLEQ_HEAD(, usbd_xfer)
244 up_queue; 247 up_queue;
245 struct usb_task up_async_task; 248 struct usb_task up_async_task;
246 249
247 struct usbd_xfer *up_intrxfer; /* used for repeating requests */ 250 struct usbd_xfer *up_intrxfer; /* used for repeating requests */
248 char up_repeat; 251 char up_repeat;
249 int up_interval; 252 int up_interval;
250 uint8_t up_flags; 253 uint8_t up_flags;
251 254
252 struct usbd_xfer *up_callingxfer; /* currently in callback */ 255 struct usbd_xfer *up_callingxfer; /* currently in callback */
253 kcondvar_t up_callingcv; 256 kcondvar_t up_callingcv;
254 257
255 /* Filled by HC driver. */ 258 /* Filled by HC driver. */
256 const struct usbd_pipe_methods 259 const struct usbd_pipe_methods
257 *up_methods; 260 *up_methods;
258}; 261};
259 262
260struct usbd_xfer { 263struct usbd_xfer {
261 struct usbd_pipe *ux_pipe; 264 struct usbd_pipe *ux_pipe;
262 void *ux_priv; 265 void *ux_priv;
263 void *ux_buffer; 266 void *ux_buffer;
264 kcondvar_t ux_cv; 267 kcondvar_t ux_cv;
265 uint32_t ux_length; 268 uint32_t ux_length;
266 uint32_t ux_actlen; 269 uint32_t ux_actlen;
267 uint16_t ux_flags; 270 uint16_t ux_flags;
268 uint32_t ux_timeout; 271 uint32_t ux_timeout;
269 usbd_status ux_status; 272 usbd_status ux_status;
270 usbd_callback ux_callback; 273 usbd_callback ux_callback;
271 volatile uint8_t ux_done; 274 volatile uint8_t ux_done;
272 uint8_t ux_state; /* used for DIAGNOSTIC */ 275 uint8_t ux_state; /* used for DIAGNOSTIC */
273#define XFER_FREE 0x46 276#define XFER_FREE 0x46
274#define XFER_BUSY 0x55 277#define XFER_BUSY 0x55
275#define XFER_ONQU 0x9e 278#define XFER_ONQU 0x9e
276 279
277 /* For control pipe */ 280 /* For control pipe */
278 usb_device_request_t ux_request; 281 usb_device_request_t ux_request;
279 282
280 /* For isoc */ 283 /* For isoc */
281 uint16_t *ux_frlengths; 284 uint16_t *ux_frlengths;
282 int ux_nframes; 285 int ux_nframes;
283 286
284 const struct usbd_pipe_methods *ux_methods; 287 const struct usbd_pipe_methods *ux_methods;
285 288
286 /* For memory allocation and softc */ 289 /* For memory allocation and softc */
287 struct usbd_bus *ux_bus; 290 struct usbd_bus *ux_bus;
288 usb_dma_t ux_dmabuf; 291 usb_dma_t ux_dmabuf;
289 void *ux_buf; 292 void *ux_buf;
290 uint32_t ux_bufsize; 293 uint32_t ux_bufsize;
291 294
292 uint8_t ux_rqflags; 295 uint8_t ux_rqflags;
293#define URQ_REQUEST 0x01 296#define URQ_REQUEST 0x01
294 297
295 SIMPLEQ_ENTRY(usbd_xfer) 298 SIMPLEQ_ENTRY(usbd_xfer)
296 ux_next; 299 ux_next;
297 300
298 void *ux_hcpriv; /* private use by the HC driver */ 301 void *ux_hcpriv; /* private use by the HC driver */
299 302
300 struct usb_task ux_aborttask; 303 struct usb_task ux_aborttask;
301 struct callout ux_callout; 304 struct callout ux_callout;
302 305
303 /* 306 /*
304 * Protected by bus lock. 307 * Protected by bus lock.
305 * 308 *
306 * - ux_timeout_set: The timeout is scheduled as a callout or 309 * - ux_timeout_set: The timeout is scheduled as a callout or
307 * usb task, and has not yet acquired the bus lock. 310 * usb task, and has not yet acquired the bus lock.
308 * 311 *
309 * - ux_timeout_reset: The xfer completed, and was resubmitted 312 * - ux_timeout_reset: The xfer completed, and was resubmitted
310 * before the callout or task was able to acquire the bus 313 * before the callout or task was able to acquire the bus
311 * lock, so one or the other needs to schedule a new callout. 314 * lock, so one or the other needs to schedule a new callout.
312 */ 315 */
313 bool ux_timeout_set; 316 bool ux_timeout_set;
314 bool ux_timeout_reset; 317 bool ux_timeout_reset;
315}; 318};
316 319
317void usbd_init(void); 320void usbd_init(void);
318void usbd_finish(void); 321void usbd_finish(void);
319 322
320#if defined(USB_DEBUG) 323#if defined(USB_DEBUG)
321void usbd_dump_iface(struct usbd_interface *); 324void usbd_dump_iface(struct usbd_interface *);
322void usbd_dump_device(struct usbd_device *); 325void usbd_dump_device(struct usbd_device *);
323void usbd_dump_endpoint(struct usbd_endpoint *); 326void usbd_dump_endpoint(struct usbd_endpoint *);
324void usbd_dump_queue(struct usbd_pipe *); 327void usbd_dump_queue(struct usbd_pipe *);
325void usbd_dump_pipe(struct usbd_pipe *); 328void usbd_dump_pipe(struct usbd_pipe *);
326#endif 329#endif
327 330
328/* Routines from usb_subr.c */ 331/* Routines from usb_subr.c */
329int usbctlprint(void *, const char *); 332int usbctlprint(void *, const char *);
330void usbd_get_device_strings(struct usbd_device *); 333void usbd_get_device_strings(struct usbd_device *);
331void usb_delay_ms_locked(struct usbd_bus *, u_int, kmutex_t *); 334void usb_delay_ms_locked(struct usbd_bus *, u_int, kmutex_t *);
332void usb_delay_ms(struct usbd_bus *, u_int); 335void usb_delay_ms(struct usbd_bus *, u_int);
333void usbd_delay_ms_locked(struct usbd_device *, u_int, kmutex_t *); 336void usbd_delay_ms_locked(struct usbd_device *, u_int, kmutex_t *);
334void usbd_delay_ms(struct usbd_device *, u_int); 337void usbd_delay_ms(struct usbd_device *, u_int);
335usbd_status usbd_reset_port(struct usbd_device *, int, usb_port_status_t *); 338usbd_status usbd_reset_port(struct usbd_device *, int, usb_port_status_t *);
336usbd_status usbd_setup_pipe(struct usbd_device *, 339usbd_status usbd_setup_pipe(struct usbd_device *,
337 struct usbd_interface *, 340 struct usbd_interface *,
338 struct usbd_endpoint *, int, 341 struct usbd_endpoint *, int,
339 struct usbd_pipe **); 342 struct usbd_pipe **);
340usbd_status usbd_setup_pipe_flags(struct usbd_device *, 343usbd_status usbd_setup_pipe_flags(struct usbd_device *,
341 struct usbd_interface *, 344 struct usbd_interface *,
342 struct usbd_endpoint *, int, 345 struct usbd_endpoint *, int,
343 struct usbd_pipe **, 346 struct usbd_pipe **,
344 uint8_t); 347 uint8_t);
345usbd_status usbd_new_device(device_t, struct usbd_bus *, int, int, int, 348usbd_status usbd_new_device(device_t, struct usbd_bus *, int, int, int,
346 struct usbd_port *); 349 struct usbd_port *);
347usbd_status usbd_reattach_device(device_t, struct usbd_device *, 350usbd_status usbd_reattach_device(device_t, struct usbd_device *,
348 int, const int *); 351 int, const int *);
349 352
350void usbd_remove_device(struct usbd_device *, struct usbd_port *); 353void usbd_remove_device(struct usbd_device *, struct usbd_port *);
351bool usbd_iface_locked(struct usbd_interface *); 354bool usbd_iface_locked(struct usbd_interface *);
352usbd_status usbd_iface_lock(struct usbd_interface *); 355usbd_status usbd_iface_lock(struct usbd_interface *);
353void usbd_iface_unlock(struct usbd_interface *); 356void usbd_iface_unlock(struct usbd_interface *);
354usbd_status usbd_iface_piperef(struct usbd_interface *); 357usbd_status usbd_iface_piperef(struct usbd_interface *);
355void usbd_iface_pipeunref(struct usbd_interface *); 358void usbd_iface_pipeunref(struct usbd_interface *);
356usbd_status usbd_fill_iface_data(struct usbd_device *, int, int); 359usbd_status usbd_fill_iface_data(struct usbd_device *, int, int);
357void usb_free_device(struct usbd_device *); 360void usb_free_device(struct usbd_device *);
358 361
359usbd_status usb_insert_transfer(struct usbd_xfer *); 362usbd_status usb_insert_transfer(struct usbd_xfer *);
360void usb_transfer_complete(struct usbd_xfer *); 363void usb_transfer_complete(struct usbd_xfer *);
361int usb_disconnect_port(struct usbd_port *, device_t, int); 364int usb_disconnect_port(struct usbd_port *, device_t, int);
362 365
363usbd_status usbd_endpoint_acquire(struct usbd_device *, 366usbd_status usbd_endpoint_acquire(struct usbd_device *,
364 struct usbd_endpoint *, int); 367 struct usbd_endpoint *, int);
365void usbd_endpoint_release(struct usbd_device *, 368void usbd_endpoint_release(struct usbd_device *,
366 struct usbd_endpoint *); 369 struct usbd_endpoint *);
367 370
368void usbd_kill_pipe(struct usbd_pipe *); 371void usbd_kill_pipe(struct usbd_pipe *);
369usbd_status usbd_attach_roothub(device_t, struct usbd_device *); 372usbd_status usbd_attach_roothub(device_t, struct usbd_device *);
370usbd_status usbd_probe_and_attach(device_t, struct usbd_device *, int, int); 373usbd_status usbd_probe_and_attach(device_t, struct usbd_device *, int, int);
371 374
372/* Routines from usb.c */ 375/* Routines from usb.c */
373void usb_needs_explore(struct usbd_device *); 376void usb_needs_explore(struct usbd_device *);
374void usb_needs_reattach(struct usbd_device *); 377void usb_needs_reattach(struct usbd_device *);
375void usb_schedsoftintr(struct usbd_bus *); 378void usb_schedsoftintr(struct usbd_bus *);
376 379
377static __inline int 380static __inline int
378usbd_xfer_isread(struct usbd_xfer *xfer) 381usbd_xfer_isread(struct usbd_xfer *xfer)
379{ 382{
380 if (xfer->ux_rqflags & URQ_REQUEST) 383 if (xfer->ux_rqflags & URQ_REQUEST)
381 return xfer->ux_request.bmRequestType & UT_READ; 384 return xfer->ux_request.bmRequestType & UT_READ;
382 385
383 return xfer->ux_pipe->up_endpoint->ue_edesc->bEndpointAddress & 386 return xfer->ux_pipe->up_endpoint->ue_edesc->bEndpointAddress &
384 UE_DIR_IN; 387 UE_DIR_IN;
385} 388}
386 389
387static __inline size_t 390static __inline size_t
388usb_addr2dindex(int addr) 391usb_addr2dindex(int addr)
389{ 392{
390 393
391 return USB_ROOTHUB_INDEX + addr; 394 return USB_ROOTHUB_INDEX + addr;
392} 395}
393 396
394/* 397/*
395 * These macros reflect the current locking scheme. They might change. 398 * These macros reflect the current locking scheme. They might change.
396 */ 399 */
397 400
398#define usbd_lock_pipe(p) mutex_enter((p)->up_dev->ud_bus->ub_lock) 401#define usbd_lock_pipe(p) mutex_enter((p)->up_dev->ud_bus->ub_lock)
399#define usbd_unlock_pipe(p) mutex_exit((p)->up_dev->ud_bus->ub_lock) 402#define usbd_unlock_pipe(p) mutex_exit((p)->up_dev->ud_bus->ub_lock)
 403
 404#endif /* _DEV_USB_USBDIVAR_H_ */