102ac6454SAndrew Thompson /* $FreeBSD$ */ 202ac6454SAndrew Thompson /*- 302ac6454SAndrew Thompson * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 402ac6454SAndrew Thompson * 502ac6454SAndrew Thompson * Redistribution and use in source and binary forms, with or without 602ac6454SAndrew Thompson * modification, are permitted provided that the following conditions 702ac6454SAndrew Thompson * are met: 802ac6454SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 902ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer. 1002ac6454SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1102ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1202ac6454SAndrew Thompson * documentation and/or other materials provided with the distribution. 1302ac6454SAndrew Thompson * 1402ac6454SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1502ac6454SAndrew Thompson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1602ac6454SAndrew Thompson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1702ac6454SAndrew Thompson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1802ac6454SAndrew Thompson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1902ac6454SAndrew Thompson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2002ac6454SAndrew Thompson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2102ac6454SAndrew Thompson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2202ac6454SAndrew Thompson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2302ac6454SAndrew Thompson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2402ac6454SAndrew Thompson * SUCH DAMAGE. 2502ac6454SAndrew Thompson */ 2602ac6454SAndrew Thompson 27ed6d949aSAndrew Thompson #include <sys/stdint.h> 28ed6d949aSAndrew Thompson #include <sys/stddef.h> 29ed6d949aSAndrew Thompson #include <sys/param.h> 30ed6d949aSAndrew Thompson #include <sys/queue.h> 31ed6d949aSAndrew Thompson #include <sys/types.h> 32ed6d949aSAndrew Thompson #include <sys/systm.h> 33ed6d949aSAndrew Thompson #include <sys/kernel.h> 34ed6d949aSAndrew Thompson #include <sys/bus.h> 35ed6d949aSAndrew Thompson #include <sys/module.h> 36ed6d949aSAndrew Thompson #include <sys/lock.h> 37ed6d949aSAndrew Thompson #include <sys/mutex.h> 38ed6d949aSAndrew Thompson #include <sys/condvar.h> 39ed6d949aSAndrew Thompson #include <sys/sysctl.h> 40ed6d949aSAndrew Thompson #include <sys/sx.h> 41ed6d949aSAndrew Thompson #include <sys/unistd.h> 42ed6d949aSAndrew Thompson #include <sys/callout.h> 43ed6d949aSAndrew Thompson #include <sys/malloc.h> 44ed6d949aSAndrew Thompson #include <sys/priv.h> 45ed6d949aSAndrew Thompson 4602ac6454SAndrew Thompson #include <dev/usb/usb.h> 47ed6d949aSAndrew Thompson #include <dev/usb/usbdi.h> 4802ac6454SAndrew Thompson 4902ac6454SAndrew Thompson #include <dev/usb/usb_core.h> 5002ac6454SAndrew Thompson #include <dev/usb/usb_process.h> 5102ac6454SAndrew Thompson #include <dev/usb/usb_device.h> 5202ac6454SAndrew Thompson #include <dev/usb/usb_dynamic.h> 5302ac6454SAndrew Thompson 5402ac6454SAndrew Thompson /* function prototypes */ 55a593f6b8SAndrew Thompson static usb_handle_req_t usb_temp_get_desc_w; 56a593f6b8SAndrew Thompson static usb_temp_setup_by_index_t usb_temp_setup_by_index_w; 57a593f6b8SAndrew Thompson static usb_temp_unsetup_t usb_temp_unsetup_w; 58*3f37fb62SHans Petter Selasky static usb_test_quirk_t usb_test_quirk_w; 59a593f6b8SAndrew Thompson static usb_quirk_ioctl_t usb_quirk_ioctl_w; 6002ac6454SAndrew Thompson 6102ac6454SAndrew Thompson /* global variables */ 62a593f6b8SAndrew Thompson usb_handle_req_t *usb_temp_get_desc_p = &usb_temp_get_desc_w; 63a593f6b8SAndrew Thompson usb_temp_setup_by_index_t *usb_temp_setup_by_index_p = &usb_temp_setup_by_index_w; 64a593f6b8SAndrew Thompson usb_temp_unsetup_t *usb_temp_unsetup_p = &usb_temp_unsetup_w; 65a593f6b8SAndrew Thompson usb_test_quirk_t *usb_test_quirk_p = &usb_test_quirk_w; 66a593f6b8SAndrew Thompson usb_quirk_ioctl_t *usb_quirk_ioctl_p = &usb_quirk_ioctl_w; 67a593f6b8SAndrew Thompson devclass_t usb_devclass_ptr = NULL; 6802ac6454SAndrew Thompson 69e0a69b51SAndrew Thompson static usb_error_t 70a593f6b8SAndrew Thompson usb_temp_setup_by_index_w(struct usb_device *udev, uint16_t index) 7102ac6454SAndrew Thompson { 7202ac6454SAndrew Thompson return (USB_ERR_INVAL); 7302ac6454SAndrew Thompson } 7402ac6454SAndrew Thompson 75*3f37fb62SHans Petter Selasky static uint8_t 76a593f6b8SAndrew Thompson usb_test_quirk_w(const struct usbd_lookup_info *info, uint16_t quirk) 7702ac6454SAndrew Thompson { 7802ac6454SAndrew Thompson return (0); /* no match */ 7902ac6454SAndrew Thompson } 8002ac6454SAndrew Thompson 8102ac6454SAndrew Thompson static int 82a593f6b8SAndrew Thompson usb_quirk_ioctl_w(unsigned long cmd, caddr_t data, int fflag, struct thread *td) 8302ac6454SAndrew Thompson { 8402ac6454SAndrew Thompson return (ENOIOCTL); 8502ac6454SAndrew Thompson } 8602ac6454SAndrew Thompson 87e0a69b51SAndrew Thompson static usb_error_t 88a593f6b8SAndrew Thompson usb_temp_get_desc_w(struct usb_device *udev, struct usb_device_request *req, const void **pPtr, uint16_t *pLength) 8902ac6454SAndrew Thompson { 9002ac6454SAndrew Thompson /* stall */ 91459d369eSAndrew Thompson return (USB_ERR_STALLED); 9202ac6454SAndrew Thompson } 9302ac6454SAndrew Thompson 9402ac6454SAndrew Thompson static void 95a593f6b8SAndrew Thompson usb_temp_unsetup_w(struct usb_device *udev) 9602ac6454SAndrew Thompson { 97a593f6b8SAndrew Thompson if (udev->usb_template_ptr) { 9802ac6454SAndrew Thompson 99a593f6b8SAndrew Thompson free(udev->usb_template_ptr, M_USB); 10002ac6454SAndrew Thompson 101a593f6b8SAndrew Thompson udev->usb_template_ptr = NULL; 10202ac6454SAndrew Thompson } 10302ac6454SAndrew Thompson } 10402ac6454SAndrew Thompson 10502ac6454SAndrew Thompson void 106a593f6b8SAndrew Thompson usb_quirk_unload(void *arg) 10702ac6454SAndrew Thompson { 10802ac6454SAndrew Thompson /* reset function pointers */ 10902ac6454SAndrew Thompson 110a593f6b8SAndrew Thompson usb_test_quirk_p = &usb_test_quirk_w; 111a593f6b8SAndrew Thompson usb_quirk_ioctl_p = &usb_quirk_ioctl_w; 11202ac6454SAndrew Thompson 11302ac6454SAndrew Thompson /* wait for CPU to exit the loaded functions, if any */ 11402ac6454SAndrew Thompson 11502ac6454SAndrew Thompson /* XXX this is a tradeoff */ 11602ac6454SAndrew Thompson 11702ac6454SAndrew Thompson pause("WAIT", hz); 11802ac6454SAndrew Thompson } 11902ac6454SAndrew Thompson 12002ac6454SAndrew Thompson void 121a593f6b8SAndrew Thompson usb_temp_unload(void *arg) 12202ac6454SAndrew Thompson { 12302ac6454SAndrew Thompson /* reset function pointers */ 12402ac6454SAndrew Thompson 125a593f6b8SAndrew Thompson usb_temp_get_desc_p = &usb_temp_get_desc_w; 126a593f6b8SAndrew Thompson usb_temp_setup_by_index_p = &usb_temp_setup_by_index_w; 127a593f6b8SAndrew Thompson usb_temp_unsetup_p = &usb_temp_unsetup_w; 12802ac6454SAndrew Thompson 12902ac6454SAndrew Thompson /* wait for CPU to exit the loaded functions, if any */ 13002ac6454SAndrew Thompson 13102ac6454SAndrew Thompson /* XXX this is a tradeoff */ 13202ac6454SAndrew Thompson 13302ac6454SAndrew Thompson pause("WAIT", hz); 13402ac6454SAndrew Thompson } 13502ac6454SAndrew Thompson 13602ac6454SAndrew Thompson void 137a593f6b8SAndrew Thompson usb_bus_unload(void *arg) 13802ac6454SAndrew Thompson { 13902ac6454SAndrew Thompson /* reset function pointers */ 14002ac6454SAndrew Thompson 141a593f6b8SAndrew Thompson usb_devclass_ptr = NULL; 14202ac6454SAndrew Thompson 14302ac6454SAndrew Thompson /* wait for CPU to exit the loaded functions, if any */ 14402ac6454SAndrew Thompson 14502ac6454SAndrew Thompson /* XXX this is a tradeoff */ 14602ac6454SAndrew Thompson 14702ac6454SAndrew Thompson pause("WAIT", hz); 14802ac6454SAndrew Thompson } 149