1/*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#ifdef USB_GLOBAL_INCLUDE_FILE 29#include USB_GLOBAL_INCLUDE_FILE 30#else 31#include <sys/stdint.h> 32#include <sys/stddef.h> 33#include <sys/param.h> 34#include <sys/queue.h> 35#include <sys/types.h> 36#include <sys/systm.h> 37#include <sys/kernel.h> 38#include <sys/bus.h> 39#include <sys/module.h> 40#include <sys/lock.h> 41#include <sys/mutex.h> 42#include <sys/condvar.h> 43#include <sys/sysctl.h> 44#include <sys/sx.h> 45#include <sys/unistd.h> 46#include <sys/callout.h> 47#include <sys/malloc.h> 48#include <sys/priv.h> 49 50#include <dev/usb/usb.h> 51#include <dev/usb/usbdi.h> 52 53#include <dev/usb/usb_core.h> 54#include <dev/usb/usb_process.h> 55#include <dev/usb/usb_device.h> 56#include <dev/usb/usb_dynamic.h> 57#include <dev/usb/usb_request.h> 58#endif /* USB_GLOBAL_INCLUDE_FILE */ 59 60/* function prototypes */ 61static usb_handle_req_t usb_temp_get_desc_w; 62static usb_temp_setup_by_index_t usb_temp_setup_by_index_w; 63#if USB_HAVE_COMPAT_LINUX 64static usb_linux_free_device_t usb_linux_free_device_w; 65#endif 66static usb_temp_unsetup_t usb_temp_unsetup_w; 67static usb_test_quirk_t usb_test_quirk_w; 68static usb_quirk_ioctl_t usb_quirk_ioctl_w; 69 70/* global variables */ 71usb_handle_req_t *usb_temp_get_desc_p = &usb_temp_get_desc_w; 72usb_temp_setup_by_index_t *usb_temp_setup_by_index_p = &usb_temp_setup_by_index_w; 73#if USB_HAVE_COMPAT_LINUX 74usb_linux_free_device_t *usb_linux_free_device_p = &usb_linux_free_device_w; 75#endif 76usb_temp_unsetup_t *usb_temp_unsetup_p = &usb_temp_unsetup_w; 77usb_test_quirk_t *usb_test_quirk_p = &usb_test_quirk_w; 78usb_quirk_ioctl_t *usb_quirk_ioctl_p = &usb_quirk_ioctl_w; 79devclass_t usb_devclass_ptr; 80 81static usb_error_t 82usb_temp_setup_by_index_w(struct usb_device *udev, uint16_t index) 83{ 84 return (USB_ERR_INVAL); 85} 86 87static uint8_t 88usb_test_quirk_w(const struct usbd_lookup_info *info, uint16_t quirk) 89{ 90 return (0); /* no match */ 91} 92 93static int 94usb_quirk_ioctl_w(unsigned long cmd, caddr_t data, int fflag, struct thread *td) 95{ 96 return (ENOIOCTL); 97} 98 99static usb_error_t 100usb_temp_get_desc_w(struct usb_device *udev, struct usb_device_request *req, const void **pPtr, uint16_t *pLength) 101{ 102 /* stall */ 103 return (USB_ERR_STALLED); 104} 105 106static void 107usb_temp_unsetup_w(struct usb_device *udev) 108{ 109 usbd_free_config_desc(udev, udev->usb_template_ptr); 110 udev->usb_template_ptr = NULL; 111} 112 113#if USB_HAVE_COMPAT_LINUX 114static void 115usb_linux_free_device_w(struct usb_device *udev) 116{ 117 /* NOP */ 118} 119#endif 120 121void 122usb_quirk_unload(void *arg) 123{ 124 /* reset function pointers */ 125 126 usb_test_quirk_p = &usb_test_quirk_w; 127 usb_quirk_ioctl_p = &usb_quirk_ioctl_w; 128 129 /* wait for CPU to exit the loaded functions, if any */ 130 131 /* XXX this is a tradeoff */ 132 133 pause("WAIT", hz); 134} 135 136void 137usb_temp_unload(void *arg) 138{ 139 /* reset function pointers */ 140 141 usb_temp_get_desc_p = &usb_temp_get_desc_w; 142 usb_temp_setup_by_index_p = &usb_temp_setup_by_index_w; 143 usb_temp_unsetup_p = &usb_temp_unsetup_w; 144 145 /* wait for CPU to exit the loaded functions, if any */ 146 147 /* XXX this is a tradeoff */ 148 149 pause("WAIT", hz); 150} 151 152void 153usb_bus_unload(void *arg) 154{ 155 /* reset function pointers */ 156 157 usb_devclass_ptr = NULL; 158 159 /* wait for CPU to exit the loaded functions, if any */ 160 161 /* XXX this is a tradeoff */ 162 163 pause("WAIT", hz); 164} 165 166#if USB_HAVE_COMPAT_LINUX 167void 168usb_linux_unload(void *arg) 169{ 170 /* reset function pointers */ 171 172 usb_linux_free_device_p = &usb_linux_free_device_w; 173 174 /* wait for CPU to exit the loaded functions, if any */ 175 176 /* XXX this is a tradeoff */ 177 178 pause("WAIT", hz); 179} 180#endif 181