xref: /third_party/FreeBSD/sys/dev/usb/usb_dynamic.c (revision f9f848fa)
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#include "implementation/global_implementation.h"
29
30/* function prototypes */
31static usb_handle_req_t usb_temp_get_desc_w;
32static usb_temp_setup_by_index_t usb_temp_setup_by_index_w;
33static usb_temp_unsetup_t usb_temp_unsetup_w;
34static usb_test_quirk_t usb_test_quirk_w;
35static usb_quirk_ioctl_t usb_quirk_ioctl_w;
36
37/* global variables */
38usb_handle_req_t *usb_temp_get_desc_p = &usb_temp_get_desc_w;
39usb_temp_setup_by_index_t *usb_temp_setup_by_index_p = &usb_temp_setup_by_index_w;
40usb_temp_unsetup_t *usb_temp_unsetup_p = &usb_temp_unsetup_w;
41usb_test_quirk_t *usb_test_quirk_p = &usb_test_quirk_w;
42usb_quirk_ioctl_t *usb_quirk_ioctl_p = &usb_quirk_ioctl_w;
43devclass_t usb_devclass_ptr;
44
45static usb_error_t
46usb_temp_setup_by_index_w(struct usb_device *udev, uint16_t index)
47{
48	return (USB_ERR_INVAL);
49}
50
51static uint8_t
52usb_test_quirk_w(const struct usbd_lookup_info *info, uint16_t quirk)
53{
54	return (0);			/* no match */
55}
56
57static int
58usb_quirk_ioctl_w(unsigned long cmd, caddr_t data, int fflag, struct thread *td)
59{
60	return (ENOIOCTL);
61}
62
63static usb_error_t
64usb_temp_get_desc_w(struct usb_device *udev, struct usb_device_request *req, const void **pPtr, uint16_t *pLength)
65{
66	/* stall */
67	return (USB_ERR_STALLED);
68}
69
70static void
71usb_temp_unsetup_w(struct usb_device *udev)
72{
73	usbd_free_config_desc(udev, udev->usb_template_ptr);
74	udev->usb_template_ptr = NULL;
75}
76
77void
78usb_quirk_unload(void *arg)
79{
80	/* reset function pointers */
81
82	usb_test_quirk_p = &usb_test_quirk_w;
83	usb_quirk_ioctl_p = &usb_quirk_ioctl_w;
84
85	/* wait for CPU to exit the loaded functions, if any */
86
87	/* XXX this is a tradeoff */
88
89	pause("WAIT", hz);
90}
91
92void
93usb_temp_unload(void *arg)
94{
95	/* reset function pointers */
96
97	usb_temp_get_desc_p = &usb_temp_get_desc_w;
98	usb_temp_setup_by_index_p = &usb_temp_setup_by_index_w;
99	usb_temp_unsetup_p = &usb_temp_unsetup_w;
100
101	/* wait for CPU to exit the loaded functions, if any */
102
103	/* XXX this is a tradeoff */
104
105	pause("WAIT", hz);
106}
107
108void
109usb_bus_unload(void *arg)
110{
111	/* reset function pointers */
112
113	usb_devclass_ptr = NULL;
114
115	/* wait for CPU to exit the loaded functions, if any */
116
117	/* XXX this is a tradeoff */
118
119	pause("WAIT", hz);
120}
121