| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: usbdi.c,v 1.173.2.5 2019/01/11 15:52:24 martin Exp $ */ | | 1 | /* $NetBSD: usbdi.c,v 1.173.2.6 2024/03/12 12:36:17 martin Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1998, 2012, 2015 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, Matthew R. Green (mrg@eterna.com.au), | | 9 | * Carlstedt Research & Technology, Matthew R. Green (mrg@eterna.com.au), |
10 | * and Nick Hudson. | | 10 | * and Nick Hudson. |
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: |
| @@ -22,27 +22,27 @@ | | | @@ -22,27 +22,27 @@ |
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 | #include <sys/cdefs.h> | | 34 | #include <sys/cdefs.h> |
35 | __KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.173.2.5 2019/01/11 15:52:24 martin Exp $"); | | 35 | __KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.173.2.6 2024/03/12 12:36:17 martin Exp $"); |
36 | | | 36 | |
37 | #ifdef _KERNEL_OPT | | 37 | #ifdef _KERNEL_OPT |
38 | #include "opt_usb.h" | | 38 | #include "opt_usb.h" |
39 | #include "opt_compat_netbsd.h" | | 39 | #include "opt_compat_netbsd.h" |
40 | #include "usb_dma.h" | | 40 | #include "usb_dma.h" |
41 | #endif | | 41 | #endif |
42 | | | 42 | |
43 | #include <sys/param.h> | | 43 | #include <sys/param.h> |
44 | #include <sys/systm.h> | | 44 | #include <sys/systm.h> |
45 | #include <sys/kernel.h> | | 45 | #include <sys/kernel.h> |
46 | #include <sys/device.h> | | 46 | #include <sys/device.h> |
47 | #include <sys/kmem.h> | | 47 | #include <sys/kmem.h> |
48 | #include <sys/proc.h> | | 48 | #include <sys/proc.h> |
| @@ -1159,34 +1159,54 @@ usbd_get_quirks(struct usbd_device *dev) | | | @@ -1159,34 +1159,54 @@ usbd_get_quirks(struct usbd_device *dev) |
1159 | void | | 1159 | void |
1160 | usbd_dopoll(struct usbd_interface *iface) | | 1160 | usbd_dopoll(struct usbd_interface *iface) |
1161 | { | | 1161 | { |
1162 | iface->ui_dev->ud_bus->ub_methods->ubm_dopoll(iface->ui_dev->ud_bus); | | 1162 | iface->ui_dev->ud_bus->ub_methods->ubm_dopoll(iface->ui_dev->ud_bus); |
1163 | } | | 1163 | } |
1164 | | | 1164 | |
1165 | /* | | 1165 | /* |
1166 | * This is for keyboard driver as well, which only operates in polling | | 1166 | * This is for keyboard driver as well, which only operates in polling |
1167 | * mode from the ask root, etc., prompt and from DDB. | | 1167 | * mode from the ask root, etc., prompt and from DDB. |
1168 | */ | | 1168 | */ |
1169 | void | | 1169 | void |
1170 | usbd_set_polling(struct usbd_device *dev, int on) | | 1170 | usbd_set_polling(struct usbd_device *dev, int on) |
1171 | { | | 1171 | { |
1172 | if (on) | | | |
1173 | dev->ud_bus->ub_usepolling++; | | | |
1174 | else | | | |
1175 | dev->ud_bus->ub_usepolling--; | | | |
1176 | | | 1172 | |
1177 | /* Kick the host controller when switching modes */ | | | |
1178 | mutex_enter(dev->ud_bus->ub_lock); | | 1173 | mutex_enter(dev->ud_bus->ub_lock); |
1179 | dev->ud_bus->ub_methods->ubm_softint(dev->ud_bus); | | 1174 | if (on) { |
| | | 1175 | /* |
| | | 1176 | * Enabling polling. If we're enabling for the first |
| | | 1177 | * time, call the softint routine on transition while |
| | | 1178 | * we hold the lock and polling is still disabled, and |
| | | 1179 | * then enable polling -- once polling is enabled, we |
| | | 1180 | * must not hold the lock when we call the softint |
| | | 1181 | * routine. |
| | | 1182 | */ |
| | | 1183 | KASSERT(dev->ud_bus->ub_usepolling < __type_max(char)); |
| | | 1184 | if (dev->ud_bus->ub_usepolling == 0) |
| | | 1185 | dev->ud_bus->ub_methods->ubm_softint(dev->ud_bus); |
| | | 1186 | dev->ud_bus->ub_usepolling++; |
| | | 1187 | } else { |
| | | 1188 | /* |
| | | 1189 | * Disabling polling. If we're disabling polling for |
| | | 1190 | * the last time, disable polling first and then call |
| | | 1191 | * the softint routine while we hold the lock -- until |
| | | 1192 | * polling is disabled, we must not hold the lock when |
| | | 1193 | * we call the softint routine. |
| | | 1194 | */ |
| | | 1195 | KASSERT(dev->ud_bus->ub_usepolling > 0); |
| | | 1196 | dev->ud_bus->ub_usepolling--; |
| | | 1197 | if (dev->ud_bus->ub_usepolling == 0) |
| | | 1198 | dev->ud_bus->ub_methods->ubm_softint(dev->ud_bus); |
| | | 1199 | } |
1180 | mutex_exit(dev->ud_bus->ub_lock); | | 1200 | mutex_exit(dev->ud_bus->ub_lock); |
1181 | } | | 1201 | } |
1182 | | | 1202 | |
1183 | | | 1203 | |
1184 | usb_endpoint_descriptor_t * | | 1204 | usb_endpoint_descriptor_t * |
1185 | usbd_get_endpoint_descriptor(struct usbd_interface *iface, uint8_t address) | | 1205 | usbd_get_endpoint_descriptor(struct usbd_interface *iface, uint8_t address) |
1186 | { | | 1206 | { |
1187 | struct usbd_endpoint *ep; | | 1207 | struct usbd_endpoint *ep; |
1188 | int i; | | 1208 | int i; |
1189 | | | 1209 | |
1190 | for (i = 0; i < iface->ui_idesc->bNumEndpoints; i++) { | | 1210 | for (i = 0; i < iface->ui_idesc->bNumEndpoints; i++) { |
1191 | ep = &iface->ui_endpoints[i]; | | 1211 | ep = &iface->ui_endpoints[i]; |
1192 | if (ep->ue_edesc->bEndpointAddress == address) | | 1212 | if (ep->ue_edesc->bEndpointAddress == address) |