1 /* $FreeBSD: releng/12.2/sys/dev/usb/usb_dynamic.c 326255 2017-11-27 14:52:40Z pfg $ */ 2 /*- 3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 4 * 5 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include "implementation/global_implementation.h" 30 31 /* function prototypes */ 32 static usb_handle_req_t usb_temp_get_desc_w; 33 static usb_temp_setup_by_index_t usb_temp_setup_by_index_w; 34 static usb_temp_unsetup_t usb_temp_unsetup_w; 35 static usb_test_quirk_t usb_test_quirk_w; 36 static usb_quirk_ioctl_t usb_quirk_ioctl_w; 37 38 /* global variables */ 39 usb_handle_req_t *usb_temp_get_desc_p = &usb_temp_get_desc_w; 40 usb_temp_setup_by_index_t *usb_temp_setup_by_index_p = &usb_temp_setup_by_index_w; 41 usb_temp_unsetup_t *usb_temp_unsetup_p = &usb_temp_unsetup_w; 42 usb_test_quirk_t *usb_test_quirk_p = &usb_test_quirk_w; 43 usb_quirk_ioctl_t *usb_quirk_ioctl_p = &usb_quirk_ioctl_w; 44 devclass_t usb_devclass_ptr; 45 46 static usb_error_t 47 usb_temp_setup_by_index_w(struct usb_device *udev, uint16_t index) 48 { 49 return (USB_ERR_INVAL); 50 } 51 52 static uint8_t 53 usb_test_quirk_w(const struct usbd_lookup_info *info, uint16_t quirk) 54 { 55 return (0); /* no match */ 56 } 57 58 static int 59 usb_quirk_ioctl_w(unsigned long cmd, caddr_t data, int fflag, struct thread *td) 60 { 61 return (ENOIOCTL); 62 } 63 64 static usb_error_t 65 usb_temp_get_desc_w(struct usb_device *udev, struct usb_device_request *req, const void **pPtr, uint16_t *pLength) 66 { 67 /* stall */ 68 return (USB_ERR_STALLED); 69 } 70 71 static void 72 usb_temp_unsetup_w(struct usb_device *udev) 73 { 74 usbd_free_config_desc(udev, udev->usb_template_ptr); 75 udev->usb_template_ptr = NULL; 76 } 77 78 void 79 usb_quirk_unload(void *arg) 80 { 81 /* reset function pointers */ 82 83 usb_test_quirk_p = &usb_test_quirk_w; 84 usb_quirk_ioctl_p = &usb_quirk_ioctl_w; 85 86 /* wait for CPU to exit the loaded functions, if any */ 87 88 /* XXX this is a tradeoff */ 89 90 pause("WAIT", hz); 91 } 92 93 void 94 usb_temp_unload(void *arg) 95 { 96 /* reset function pointers */ 97 98 usb_temp_get_desc_p = &usb_temp_get_desc_w; 99 usb_temp_setup_by_index_p = &usb_temp_setup_by_index_w; 100 usb_temp_unsetup_p = &usb_temp_unsetup_w; 101 102 /* wait for CPU to exit the loaded functions, if any */ 103 104 /* XXX this is a tradeoff */ 105 106 pause("WAIT", hz); 107 } 108 109 void 110 usb_bus_unload(void *arg) 111 { 112 /* reset function pointers */ 113 114 usb_devclass_ptr = NULL; 115 116 /* wait for CPU to exit the loaded functions, if any */ 117 118 /* XXX this is a tradeoff */ 119 120 pause("WAIT", hz); 121 } 122