1 /* $NetBSD: dev_verbose.h,v 1.1 2014/09/21 14:30:22 christos Exp $ */
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #ifndef _DEV_DEV_VERBOSE_H_
26 #define _DEV_DEV_VERBOSE_H_
28 const char *dev_findvendor(char *, size_t, const char *, size_t,
29 const uint16_t *, size_t, uint16_t);
30 const char *dev_findproduct(char *, size_t, const char *, size_t,
31 const uint16_t *, size_t, uint16_t, uint16_t);
33 #define DEV_VERBOSE_COMMON_DEFINE(tag) \
35 tag ## _findvendor_real(char *buf, size_t len, uint16_t vendor) \
37 return dev_findvendor(buf, len, tag ## _words, \
38 __arraycount(tag ## _words), tag ## _vendors, \
39 __arraycount(tag ## _vendors), vendor); \
43 tag ## _findproduct_real(char *buf, size_t len, uint16_t vendor, \
46 return dev_findproduct(buf, len, tag ## _words, \
47 __arraycount(tag ## _words), tag ## _products, \
48 __arraycount(tag ## _products), vendor, product); \
53 #define DEV_VERBOSE_MODULE_DEFINE(tag, deps) \
54 DEV_VERBOSE_COMMON_DEFINE(tag) \
55 extern int tag ## verbose_loaded; \
58 tag ## verbose_modcmd(modcmd_t cmd, void *arg) \
60 static const char *(*saved_findvendor)(char *, size_t, \
62 static const char *(*saved_findproduct)(char *, size_t, \
63 uint16_t, uint16_t); \
66 case MODULE_CMD_INIT: \
67 saved_findvendor = tag ## _findvendor; \
68 saved_findproduct = tag ## _findproduct; \
69 tag ## _findvendor = tag ## _findvendor_real; \
70 tag ## _findproduct = tag ## _findproduct_real; \
71 tag ## verbose_loaded = 1; \
73 case MODULE_CMD_FINI: \
74 tag ## _findvendor = saved_findvendor; \
75 tag ## _findproduct = saved_findproduct; \
76 tag ## verbose_loaded = 0; \
82 MODULE(MODULE_CLASS_MISC, tag ## verbose, deps)
86 #define DEV_VERBOSE_DECLARE(tag) \
87 extern const char * (*tag ## _findvendor)(char *, size_t, uint16_t); \
88 extern const char * (*tag ## _findproduct)(char *, size_t, uint16_t, uint16_t)
91 #define DEV_VERBOSE_DEFINE(tag) \
92 int tag ## verbose_loaded = 0; \
95 tag ## _load_verbose(void) \
98 if (tag ## verbose_loaded == 0) \
99 module_autoload(# tag "verbose", MODULE_CLASS_MISC); \
102 static const char * \
103 tag ## _findvendor_stub(char *buf, size_t len, uint16_t vendor) \
106 tag ## _load_verbose(); \
107 if (tag ## verbose_loaded) \
108 return tag ## _findvendor(buf, len, vendor); \
110 snprintf(buf, len, "vendor %4.4x", vendor); \
115 static const char * \
116 tag ## _findproduct_stub(char *buf, size_t len, uint16_t vendor, \
120 tag ## _load_verbose(); \
121 if (tag ## verbose_loaded) \
122 return tag ## _findproduct(buf, len, vendor, product); \
124 snprintf(buf, len, "product %4.4x", product); \
129 const char *(*tag ## _findvendor)(char *, size_t, uint16_t) = \
130 tag ## _findvendor_stub; \
131 const char *(*tag ## _findproduct)(char *, size_t, uint16_t, uint16_t) =\
132 tag ## _findproduct_stub; \
136 #define DEV_VERBOSE_DEFINE(tag) \
137 DEV_VERBOSE_COMMON_DEFINE(tag) \
138 const char *(*tag ## _findvendor)(char *, size_t, uint16_t) = \
139 tag ## _findvendor_real; \
140 const char *(*tag ## _findproduct)(char *, size_t, uint16_t, uint16_t) =\
141 tag ## _findproduct_real; \
145 #endif /* _DEV_DEV_VERBOSE_H_ */