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