Home | History | Annotate | Line # | Download | only in dev
dev_verbose.h revision 1.4.6.2
      1  1.4.6.2   thorpej /*	$NetBSD: dev_verbose.h,v 1.4.6.2 2021/08/01 22:42:20 thorpej Exp $ */
      2      1.1  christos 
      3      1.1  christos /*
      4      1.1  christos  * Redistribution and use in source and binary forms, with or without
      5      1.1  christos  * modification, are permitted provided that the following conditions
      6      1.1  christos  * are met:
      7      1.1  christos  * 1. Redistributions of source code must retain the above copyright
      8      1.1  christos  *    notice, this list of conditions and the following disclaimer.
      9      1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     10      1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     11      1.1  christos  *    documentation and/or other materials provided with the distribution.
     12      1.1  christos  *
     13      1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     14      1.1  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     15      1.1  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     16      1.1  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     17      1.1  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     18      1.1  christos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     19      1.1  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     20      1.1  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     21      1.1  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     22      1.1  christos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     23      1.1  christos  */
     24      1.1  christos 
     25      1.1  christos #ifndef _DEV_DEV_VERBOSE_H_
     26      1.1  christos #define	_DEV_DEV_VERBOSE_H_
     27      1.1  christos 
     28  1.4.6.1   thorpej #ifdef _KERNEL
     29  1.4.6.1   thorpej #include <sys/module_hook.h>
     30  1.4.6.1   thorpej #endif
     31  1.4.6.1   thorpej 
     32      1.1  christos const char *dev_findvendor(char *, size_t, const char *, size_t,
     33  1.4.6.2   thorpej 	const uint32_t *, size_t, uint32_t, const char *);
     34      1.1  christos const char *dev_findproduct(char *, size_t, const char *, size_t,
     35  1.4.6.2   thorpej 	const uint32_t *, size_t, uint32_t, uint32_t, const char *);
     36      1.1  christos 
     37      1.1  christos #define DEV_VERBOSE_COMMON_DEFINE(tag)					\
     38      1.1  christos static const char *							\
     39  1.4.6.2   thorpej tag ## _findvendor_real(char *buf, size_t len, uint32_t vendor)		\
     40      1.1  christos {									\
     41      1.1  christos 	return dev_findvendor(buf, len, tag ## _words,			\
     42      1.1  christos 	    __arraycount(tag ## _words), tag ## _vendors,		\
     43  1.4.6.2   thorpej 	    __arraycount(tag ## _vendors), vendor, tag ## _id1_format);	\
     44      1.1  christos }									\
     45      1.1  christos 									\
     46      1.1  christos static const char *							\
     47  1.4.6.2   thorpej tag ## _findproduct_real(char *buf, size_t len, uint32_t vendor,	\
     48  1.4.6.2   thorpej     uint32_t product)							\
     49      1.1  christos {									\
     50      1.1  christos 	return dev_findproduct(buf, len, tag ## _words,			\
     51      1.1  christos 	    __arraycount(tag ## _words), tag ## _products,		\
     52  1.4.6.2   thorpej 	    __arraycount(tag ## _products), vendor, product,		\
     53  1.4.6.2   thorpej 	    tag ## _id2_format);					\
     54      1.1  christos }									\
     55      1.1  christos 
     56      1.1  christos #ifdef _KERNEL
     57      1.1  christos 
     58  1.4.6.1   thorpej #define DEV_VERBOSE_KERNEL_DECLARE(tag)					\
     59  1.4.6.1   thorpej MODULE_HOOK(tag ## _findvendor_hook, const char *,			\
     60  1.4.6.2   thorpej 	(char *, size_t, uint32_t));					\
     61  1.4.6.1   thorpej MODULE_HOOK(tag ## _findproduct_hook, const char *,			\
     62  1.4.6.2   thorpej 	(char *, size_t, uint32_t, uint32_t));				\
     63  1.4.6.1   thorpej extern int tag ## verbose_loaded;
     64  1.4.6.1   thorpej 
     65      1.1  christos #define DEV_VERBOSE_MODULE_DEFINE(tag, deps)				\
     66      1.1  christos DEV_VERBOSE_COMMON_DEFINE(tag)						\
     67  1.4.6.1   thorpej DEV_VERBOSE_KERNEL_DECLARE(tag)						\
     68      1.1  christos 									\
     69      1.1  christos static int								\
     70      1.1  christos tag ## verbose_modcmd(modcmd_t cmd, void *arg)				\
     71      1.1  christos {									\
     72      1.1  christos 									\
     73      1.1  christos 	switch (cmd) {							\
     74      1.1  christos 	case MODULE_CMD_INIT:						\
     75  1.4.6.1   thorpej 		MODULE_HOOK_SET(tag ## _findvendor_hook,		\
     76  1.4.6.1   thorpej 			tag ## _findvendor_real);			\
     77  1.4.6.1   thorpej 		MODULE_HOOK_SET(tag ## _findproduct_hook,		\
     78  1.4.6.1   thorpej 			tag ## _findproduct_real);			\
     79      1.1  christos 		tag ## verbose_loaded = 1;				\
     80      1.1  christos 		return 0;						\
     81      1.1  christos 	case MODULE_CMD_FINI:						\
     82      1.1  christos 		tag ## verbose_loaded = 0;				\
     83  1.4.6.1   thorpej 		MODULE_HOOK_UNSET(tag ## _findproduct_hook);		\
     84  1.4.6.1   thorpej 		MODULE_HOOK_UNSET(tag ## _findvendor_hook);		\
     85      1.1  christos 		return 0;						\
     86      1.1  christos 	default:							\
     87      1.1  christos 		return ENOTTY;						\
     88      1.1  christos 	}								\
     89      1.1  christos }									\
     90      1.3       uwe MODULE(MODULE_CLASS_DRIVER, tag ## verbose, deps)
     91      1.1  christos 
     92      1.1  christos #endif /* KERNEL */
     93      1.1  christos 
     94      1.1  christos #define DEV_VERBOSE_DECLARE(tag)					\
     95  1.4.6.2   thorpej extern const char * tag ## _findvendor(char *, size_t, uint32_t);	\
     96  1.4.6.2   thorpej extern const char * tag ## _findproduct(char *, size_t, uint32_t, uint32_t)
     97      1.1  christos 
     98      1.1  christos #if defined(_KERNEL)
     99  1.4.6.1   thorpej 
    100      1.1  christos #define DEV_VERBOSE_DEFINE(tag)						\
    101  1.4.6.1   thorpej DEV_VERBOSE_KERNEL_DECLARE(tag)						\
    102  1.4.6.1   thorpej struct tag ## _findvendor_hook_t tag ## _findvendor_hook;		\
    103  1.4.6.1   thorpej struct tag ## _findproduct_hook_t tag ## _findproduct_hook;		\
    104      1.1  christos int tag ## verbose_loaded = 0;						\
    105      1.1  christos 									\
    106      1.1  christos static void								\
    107      1.1  christos tag ## _load_verbose(void)						\
    108      1.1  christos {									\
    109      1.1  christos 									\
    110      1.1  christos 	if (tag ## verbose_loaded == 0)					\
    111      1.4       uwe 		module_autoload(# tag "verbose", MODULE_CLASS_DRIVER);	\
    112      1.1  christos }									\
    113      1.1  christos 									\
    114  1.4.6.1   thorpej const char *								\
    115  1.4.6.2   thorpej tag ## _findvendor(char *buf, size_t len, uint32_t vendor)		\
    116      1.1  christos {									\
    117  1.4.6.1   thorpej 	const char *retval = NULL;					\
    118      1.1  christos 									\
    119      1.1  christos 	tag ## _load_verbose();						\
    120  1.4.6.1   thorpej 	MODULE_HOOK_CALL(tag ## _findvendor_hook, (buf, len, vendor),	\
    121  1.4.6.2   thorpej 		(snprintf(buf, len, tag ## _id1_format, vendor), NULL),	\
    122  1.4.6.1   thorpej 		retval);						\
    123  1.4.6.1   thorpej 	return retval;							\
    124      1.1  christos }									\
    125      1.1  christos 									\
    126  1.4.6.1   thorpej const char *								\
    127  1.4.6.2   thorpej tag ## _findproduct(char *buf, size_t len, uint32_t vendor,		\
    128  1.4.6.2   thorpej     uint32_t product)							\
    129      1.1  christos {									\
    130  1.4.6.1   thorpej 	const char *retval = NULL;					\
    131      1.1  christos 									\
    132      1.1  christos 	tag ## _load_verbose();						\
    133  1.4.6.1   thorpej 	MODULE_HOOK_CALL(tag ## _findproduct_hook,			\
    134  1.4.6.1   thorpej 		(buf, len, vendor, product),				\
    135  1.4.6.2   thorpej 		(snprintf(buf, len, tag ## _id2_format, product), NULL), \
    136  1.4.6.1   thorpej 		retval);						\
    137  1.4.6.1   thorpej 	return retval;							\
    138      1.1  christos }									\
    139      1.1  christos 
    140  1.4.6.1   thorpej #else	/* _KERNEL */
    141      1.1  christos 
    142      1.1  christos #define DEV_VERBOSE_DEFINE(tag)						\
    143      1.1  christos DEV_VERBOSE_COMMON_DEFINE(tag)						\
    144  1.4.6.2   thorpej const char *tag ## _findvendor(char *buf, size_t len, uint32_t vendor)	\
    145  1.4.6.1   thorpej {									\
    146  1.4.6.1   thorpej 									\
    147  1.4.6.1   thorpej 	return tag ## _findvendor_real(buf, len, vendor);		\
    148  1.4.6.1   thorpej }									\
    149  1.4.6.1   thorpej 									\
    150  1.4.6.2   thorpej const char *tag ## _findproduct(char *buf, size_t len, uint32_t vendor,	\
    151  1.4.6.2   thorpej 		uint32_t product)					\
    152  1.4.6.1   thorpej {									\
    153  1.4.6.1   thorpej 									\
    154  1.4.6.1   thorpej 	return tag ## _findproduct_real(buf, len, vendor, product);	\
    155  1.4.6.1   thorpej }
    156      1.1  christos 
    157      1.1  christos #endif /* _KERNEL */
    158      1.1  christos 
    159      1.1  christos #endif /* _DEV_DEV_VERBOSE_H_ */
    160