1 /* $FreeBSD: releng/12.2/stand/kshim/bsd_kernel.c 314068 2017-02-22 02:35:59Z pfg $ */
2 /*-
3 * Copyright (c) 2013 Hans Petter Selasky. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27 #include "implementation/global_implementation.h"
28
29 #ifdef LOSCFG_DRIVERS_USB_HOST_DRIVER
30 extern volatile uint8_t g_device_is_ready;
31 #endif
32
33 #undef USB_DEBUG_VAR
34 #define USB_DEBUG_VAR usb_debug
35
36 /*------------------------------------------------------------------------*
37 * Implementation of mutex API
38 *------------------------------------------------------------------------*/
39
40 struct mtx Giant = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
41 struct mtx Gcall = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
42
43 /*------------------------------------------------------------------------*
44 * Implementation of device API
45 *------------------------------------------------------------------------*/
46
47 #ifdef LOSCFG_USB_DEBUG
48 static uint8_t
devclass_equal(const char * a,const char * b)49 devclass_equal(const char *a, const char *b)
50 {
51 char ta, tb;
52
53 if (a == b)
54 return (1);
55 if(!a || !b)
56 return (0);
57 while (1) {
58 ta = *a;
59 tb = *b;
60 if (ta != tb)
61 return (0);
62 if (ta == 0)
63 break;
64 a++;
65 b++;
66 }
67 return (1);
68 }
69
70 static TAILQ_HEAD(, debug_module_data) debug_module_head =
71 TAILQ_HEAD_INITIALIZER(debug_module_head);
72
73 void
debug_module_register(void * data)74 debug_module_register(void *data)
75 {
76 struct debug_module_data *mdata = data;
77 TAILQ_INSERT_TAIL(&debug_module_head, mdata, entry);
78 }
79
80 void
debug_module_unregister(void * data)81 debug_module_unregister(void *data)
82 {
83 struct debug_module_data *mdata = data;
84 TAILQ_REMOVE(&debug_module_head, mdata, entry);
85 }
86
87 struct debug_module_data *
get_debug_module(const char * modname)88 get_debug_module(const char *modname)
89 {
90 static struct debug_module_data *mod;
91
92 TAILQ_FOREACH(mod, &debug_module_head, entry) {
93 if (devclass_equal(mod->mod_name, modname)) {
94 return (mod);
95 }
96 }
97 return (NULL);
98 }
99
100 void
debug_module_dump(void)101 debug_module_dump(void)
102 {
103 const struct debug_module_data *mod;
104
105 TAILQ_FOREACH(mod, &debug_module_head, entry) {
106 PRINTK("%s\n", mod->mod_name);
107 }
108 }
109 #endif
110 #undef USB_DEBUG_VAR
111