Home | History | Annotate | Line # | Download | only in dev
dev_verbose.h revision 1.1.2.1
      1  1.1.2.1     skrll /*	$NetBSD: dev_verbose.h,v 1.1.2.1 2015/12/27 12:09:48 skrll 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.1  christos const char *dev_findvendor(char *, size_t, const char *, size_t,
     29      1.1  christos 	const uint16_t *, size_t, uint16_t);
     30      1.1  christos const char *dev_findproduct(char *, size_t, const char *, size_t,
     31      1.1  christos 	const uint16_t *, size_t, uint16_t, uint16_t);
     32      1.1  christos 
     33      1.1  christos #define DEV_VERBOSE_COMMON_DEFINE(tag)					\
     34      1.1  christos static const char *							\
     35      1.1  christos tag ## _findvendor_real(char *buf, size_t len, uint16_t vendor)		\
     36      1.1  christos {									\
     37      1.1  christos 	return dev_findvendor(buf, len, tag ## _words,			\
     38      1.1  christos 	    __arraycount(tag ## _words), tag ## _vendors,		\
     39      1.1  christos 	    __arraycount(tag ## _vendors), vendor);			\
     40      1.1  christos }									\
     41      1.1  christos 									\
     42      1.1  christos static const char *							\
     43      1.1  christos tag ## _findproduct_real(char *buf, size_t len, uint16_t vendor,	\
     44      1.1  christos     uint16_t product)							\
     45      1.1  christos {									\
     46      1.1  christos 	return dev_findproduct(buf, len, tag ## _words,			\
     47      1.1  christos 	    __arraycount(tag ## _words), tag ## _products,		\
     48      1.1  christos 	    __arraycount(tag ## _products), vendor, product);		\
     49      1.1  christos }									\
     50      1.1  christos 
     51      1.1  christos #ifdef _KERNEL
     52      1.1  christos 
     53      1.1  christos #define DEV_VERBOSE_MODULE_DEFINE(tag, deps)				\
     54      1.1  christos DEV_VERBOSE_COMMON_DEFINE(tag)						\
     55      1.1  christos extern int tag ## verbose_loaded;					\
     56      1.1  christos 									\
     57      1.1  christos static int								\
     58      1.1  christos tag ## verbose_modcmd(modcmd_t cmd, void *arg)				\
     59      1.1  christos {									\
     60      1.1  christos 	static const char *(*saved_findvendor)(char *, size_t,		\
     61      1.1  christos 	    uint16_t);							\
     62      1.1  christos 	static const char *(*saved_findproduct)(char *, size_t,		\
     63      1.1  christos 	    uint16_t, uint16_t);					\
     64      1.1  christos 									\
     65      1.1  christos 	switch (cmd) {							\
     66      1.1  christos 	case MODULE_CMD_INIT:						\
     67      1.1  christos 		saved_findvendor = tag ## _findvendor;			\
     68      1.1  christos 		saved_findproduct = tag ## _findproduct;		\
     69      1.1  christos 		tag ## _findvendor = tag ## _findvendor_real;		\
     70      1.1  christos 		tag ## _findproduct = tag ## _findproduct_real;		\
     71      1.1  christos 		tag ## verbose_loaded = 1;				\
     72      1.1  christos 		return 0;						\
     73      1.1  christos 	case MODULE_CMD_FINI:						\
     74      1.1  christos 		tag ## _findvendor = saved_findvendor;			\
     75      1.1  christos 		tag ## _findproduct = saved_findproduct;		\
     76      1.1  christos 		tag ## verbose_loaded = 0;				\
     77      1.1  christos 		return 0;						\
     78      1.1  christos 	default:							\
     79      1.1  christos 		return ENOTTY;						\
     80      1.1  christos 	}								\
     81      1.1  christos }									\
     82      1.1  christos MODULE(MODULE_CLASS_MISC, tag ## verbose, deps)
     83      1.1  christos 
     84      1.1  christos #endif /* KERNEL */
     85      1.1  christos 
     86      1.1  christos #define DEV_VERBOSE_DECLARE(tag)					\
     87      1.1  christos extern const char * (*tag ## _findvendor)(char *, size_t, uint16_t);	\
     88      1.1  christos extern const char * (*tag ## _findproduct)(char *, size_t, uint16_t, uint16_t)
     89      1.1  christos 
     90      1.1  christos #if defined(_KERNEL)
     91      1.1  christos #define DEV_VERBOSE_DEFINE(tag)						\
     92      1.1  christos int tag ## verbose_loaded = 0;						\
     93      1.1  christos 									\
     94      1.1  christos static void								\
     95      1.1  christos tag ## _load_verbose(void)						\
     96      1.1  christos {									\
     97      1.1  christos 									\
     98      1.1  christos 	if (tag ## verbose_loaded == 0)					\
     99      1.1  christos 		module_autoload(# tag "verbose", MODULE_CLASS_MISC);	\
    100      1.1  christos }									\
    101      1.1  christos 									\
    102      1.1  christos static const char *							\
    103      1.1  christos tag ## _findvendor_stub(char *buf, size_t len, uint16_t vendor)		\
    104      1.1  christos {									\
    105      1.1  christos 									\
    106      1.1  christos 	tag ## _load_verbose();						\
    107      1.1  christos 	if (tag ## verbose_loaded)					\
    108      1.1  christos 		return tag ## _findvendor(buf, len, vendor);		\
    109      1.1  christos 	else {								\
    110      1.1  christos 		snprintf(buf, len, "vendor %4.4x", vendor);		\
    111      1.1  christos 		return NULL;						\
    112      1.1  christos 	}								\
    113      1.1  christos }									\
    114      1.1  christos 									\
    115      1.1  christos static const char *							\
    116      1.1  christos tag ## _findproduct_stub(char *buf, size_t len, uint16_t vendor,	\
    117      1.1  christos     uint16_t product)							\
    118      1.1  christos {									\
    119      1.1  christos 									\
    120      1.1  christos 	tag ## _load_verbose();						\
    121      1.1  christos 	if (tag ## verbose_loaded)					\
    122      1.1  christos 		return tag ## _findproduct(buf, len, vendor, product);	\
    123      1.1  christos 	else {								\
    124      1.1  christos 		snprintf(buf, len, "product %4.4x", product);		\
    125      1.1  christos 		return NULL;						\
    126      1.1  christos 	}								\
    127      1.1  christos }									\
    128      1.1  christos 									\
    129      1.1  christos const char *(*tag ## _findvendor)(char *, size_t, uint16_t) = 		\
    130      1.1  christos     tag ## _findvendor_stub;						\
    131      1.1  christos const char *(*tag ## _findproduct)(char *, size_t, uint16_t, uint16_t) =\
    132  1.1.2.1     skrll     tag ## _findproduct_stub						\
    133      1.1  christos 
    134      1.1  christos #else
    135      1.1  christos 
    136      1.1  christos #define DEV_VERBOSE_DEFINE(tag)						\
    137      1.1  christos DEV_VERBOSE_COMMON_DEFINE(tag)						\
    138      1.1  christos const char *(*tag ## _findvendor)(char *, size_t, uint16_t) = 		\
    139      1.1  christos     tag ## _findvendor_real;						\
    140      1.1  christos const char *(*tag ## _findproduct)(char *, size_t, uint16_t, uint16_t) =\
    141  1.1.2.1     skrll     tag ## _findproduct_real						\
    142      1.1  christos 
    143      1.1  christos #endif /* _KERNEL */
    144      1.1  christos 
    145      1.1  christos #endif /* _DEV_DEV_VERBOSE_H_ */
    146