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