1184610Salfred/* $FreeBSD$ */
2184610Salfred/*-
3184610Salfred * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4184610Salfred *
5184610Salfred * Redistribution and use in source and binary forms, with or without
6184610Salfred * modification, are permitted provided that the following conditions
7184610Salfred * are met:
8184610Salfred * 1. Redistributions of source code must retain the above copyright
9184610Salfred *    notice, this list of conditions and the following disclaimer.
10184610Salfred * 2. Redistributions in binary form must reproduce the above copyright
11184610Salfred *    notice, this list of conditions and the following disclaimer in the
12184610Salfred *    documentation and/or other materials provided with the distribution.
13184610Salfred *
14184610Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17184610Salfred * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18184610Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19184610Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20184610Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21184610Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22184610Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23184610Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24184610Salfred * SUCH DAMAGE.
25184610Salfred */
26184610Salfred
27194677Sthompsa#include <sys/stdint.h>
28194677Sthompsa#include <sys/stddef.h>
29194677Sthompsa#include <sys/param.h>
30194677Sthompsa#include <sys/queue.h>
31194677Sthompsa#include <sys/types.h>
32194677Sthompsa#include <sys/systm.h>
33194677Sthompsa#include <sys/kernel.h>
34194677Sthompsa#include <sys/bus.h>
35194677Sthompsa#include <sys/module.h>
36194677Sthompsa#include <sys/lock.h>
37194677Sthompsa#include <sys/mutex.h>
38194677Sthompsa#include <sys/condvar.h>
39194677Sthompsa#include <sys/sysctl.h>
40194677Sthompsa#include <sys/sx.h>
41194677Sthompsa#include <sys/unistd.h>
42194677Sthompsa#include <sys/callout.h>
43194677Sthompsa#include <sys/malloc.h>
44194677Sthompsa#include <sys/priv.h>
45194677Sthompsa
46188942Sthompsa#include <dev/usb/usb.h>
47194677Sthompsa#include <dev/usb/usbdi.h>
48184610Salfred
49188942Sthompsa#include <dev/usb/usb_core.h>
50188942Sthompsa#include <dev/usb/usb_process.h>
51188942Sthompsa#include <dev/usb/usb_device.h>
52188942Sthompsa#include <dev/usb/usb_dynamic.h>
53184610Salfred
54184610Salfred/* function prototypes */
55194228Sthompsastatic usb_handle_req_t usb_temp_get_desc_w;
56194228Sthompsastatic usb_temp_setup_by_index_t usb_temp_setup_by_index_w;
57194228Sthompsastatic usb_temp_unsetup_t usb_temp_unsetup_w;
58225469Shselaskystatic usb_test_quirk_t usb_test_quirk_w;
59194228Sthompsastatic usb_quirk_ioctl_t usb_quirk_ioctl_w;
60184610Salfred
61184610Salfred/* global variables */
62194228Sthompsausb_handle_req_t *usb_temp_get_desc_p = &usb_temp_get_desc_w;
63194228Sthompsausb_temp_setup_by_index_t *usb_temp_setup_by_index_p = &usb_temp_setup_by_index_w;
64194228Sthompsausb_temp_unsetup_t *usb_temp_unsetup_p = &usb_temp_unsetup_w;
65194228Sthompsausb_test_quirk_t *usb_test_quirk_p = &usb_test_quirk_w;
66194228Sthompsausb_quirk_ioctl_t *usb_quirk_ioctl_p = &usb_quirk_ioctl_w;
67194228Sthompsadevclass_t usb_devclass_ptr = NULL;
68184610Salfred
69193045Sthompsastatic usb_error_t
70194228Sthompsausb_temp_setup_by_index_w(struct usb_device *udev, uint16_t index)
71184610Salfred{
72184610Salfred	return (USB_ERR_INVAL);
73184610Salfred}
74184610Salfred
75225469Shselaskystatic uint8_t
76194228Sthompsausb_test_quirk_w(const struct usbd_lookup_info *info, uint16_t quirk)
77184610Salfred{
78184610Salfred	return (0);			/* no match */
79184610Salfred}
80184610Salfred
81184610Salfredstatic int
82194228Sthompsausb_quirk_ioctl_w(unsigned long cmd, caddr_t data, int fflag, struct thread *td)
83184610Salfred{
84184610Salfred	return (ENOIOCTL);
85184610Salfred}
86184610Salfred
87193045Sthompsastatic usb_error_t
88194228Sthompsausb_temp_get_desc_w(struct usb_device *udev, struct usb_device_request *req, const void **pPtr, uint16_t *pLength)
89184610Salfred{
90184610Salfred	/* stall */
91191402Sthompsa	return (USB_ERR_STALLED);
92184610Salfred}
93184610Salfred
94184610Salfredstatic void
95194228Sthompsausb_temp_unsetup_w(struct usb_device *udev)
96184610Salfred{
97194228Sthompsa	if (udev->usb_template_ptr) {
98184610Salfred
99194228Sthompsa		free(udev->usb_template_ptr, M_USB);
100184610Salfred
101194228Sthompsa		udev->usb_template_ptr = NULL;
102184610Salfred	}
103184610Salfred}
104184610Salfred
105184610Salfredvoid
106194228Sthompsausb_quirk_unload(void *arg)
107184610Salfred{
108184610Salfred	/* reset function pointers */
109184610Salfred
110194228Sthompsa	usb_test_quirk_p = &usb_test_quirk_w;
111194228Sthompsa	usb_quirk_ioctl_p = &usb_quirk_ioctl_w;
112184610Salfred
113184610Salfred	/* wait for CPU to exit the loaded functions, if any */
114184610Salfred
115184610Salfred	/* XXX this is a tradeoff */
116184610Salfred
117184610Salfred	pause("WAIT", hz);
118184610Salfred}
119184610Salfred
120184610Salfredvoid
121194228Sthompsausb_temp_unload(void *arg)
122184610Salfred{
123184610Salfred	/* reset function pointers */
124184610Salfred
125194228Sthompsa	usb_temp_get_desc_p = &usb_temp_get_desc_w;
126194228Sthompsa	usb_temp_setup_by_index_p = &usb_temp_setup_by_index_w;
127194228Sthompsa	usb_temp_unsetup_p = &usb_temp_unsetup_w;
128184610Salfred
129184610Salfred	/* wait for CPU to exit the loaded functions, if any */
130184610Salfred
131184610Salfred	/* XXX this is a tradeoff */
132184610Salfred
133184610Salfred	pause("WAIT", hz);
134184610Salfred}
135184610Salfred
136184610Salfredvoid
137194228Sthompsausb_bus_unload(void *arg)
138184610Salfred{
139184610Salfred	/* reset function pointers */
140184610Salfred
141194228Sthompsa	usb_devclass_ptr = NULL;
142184610Salfred
143184610Salfred	/* wait for CPU to exit the loaded functions, if any */
144184610Salfred
145184610Salfred	/* XXX this is a tradeoff */
146184610Salfred
147184610Salfred	pause("WAIT", hz);
148184610Salfred}
149