kernel: scheduling fix for ARM
[minix.git] / drivers / mmc / mmclog.h
blob872823a3e40a5ad4538a45f9a4d4c73a96ba4dc8
1 #ifndef __MMCLOG_H__
2 #define __MMCLOG_H__
3 /*
4 * Simple logging functions for the MMC layer
5 */
7 /*
8 * LEVEL_NONE do not log anything.
9 * LEVEL_WARN Information that needs to be known.
10 * LEVEL_INFO Basic information like startup messages and occasional events.
11 * LEVEL_DEBUG debug statements about things happening that are less expected.
12 * LEVEL_TRACE Way to much information for anybody.
15 #define LEVEL_NONE 0
16 #define LEVEL_WARN 1
17 #define LEVEL_INFO 2
18 #define LEVEL_DEBUG 3
19 #define LEVEL_TRACE 4
21 static const char *level_string[5] = {
22 "none",
23 "warn",
24 "info",
25 "debug",
26 "trace"
30 * struct to be initialized by the user of the logging system.
32 * name: The name attribute is used in logging statements do differentiate
33 * drivers
35 * log_level The level attribute describes the requested logging level. a level
36 * of 1 will only print warnings while a level of 4 will print all the trace
37 * information.
39 * log_func The logging function to use to log, mmclog.h provides default_log
40 * to display information on the kernel output buffer. As a bonus if the
41 * requested log level is debug or trace the method , file and line number will
42 * be printed to the steam.
44 struct mmclog { const char *name; int log_level;
46 /* the logging function itself */
47 void (*log_func) (struct mmclog * driver,
48 int level,
49 const char *file,
50 const char *function, int line, const char *fmt, ...);
54 #define __mmc_log(driver,log_level, fmt, args...) \
55 ((driver)->log_func(driver,log_level, \
56 __FILE__, __FUNCTION__, __LINE__,\
57 fmt, ## args))
59 /* Log a warning */
60 #define mmc_log_warn(driver, fmt, args...) \
61 __mmc_log(driver, LEVEL_WARN, fmt, ## args)
63 /* Log an information message */
64 #define mmc_log_info(driver, fmt, args...) \
65 __mmc_log(driver, LEVEL_INFO, fmt, ## args)
67 /* log debugging output */
68 #define mmc_log_debug(driver, fmt, args...) \
69 __mmc_log(driver, LEVEL_DEBUG, fmt, ## args)
71 /* log trace output */
72 #define mmc_log_trace(driver, fmt, args...) \
73 __mmc_log(driver, LEVEL_TRACE, fmt, ## args)
75 #endif /* __MMCLOG_H__ */
77 static void
78 default_log(struct mmclog *driver,
79 int level,
80 const char *file, const char *function, int line, const char *fmt, ...)
82 va_list args;
84 if (level > driver->log_level) {
85 return;
87 /* If the wanted level is debug also display line/method information */
88 if (driver->log_level >= LEVEL_DEBUG) {
89 fprintf(stderr, "%s(%s):%s+%d(%s):", driver->name,
90 level_string[level], file, line, function);
91 } else {
92 fprintf(stderr, "%s(%s)", driver->name, level_string[level]);
95 va_start(args, fmt);
96 vfprintf(stderr, fmt, args);
97 va_end(args);
100 #ifdef hacks
101 static void
102 hexdump(unsigned char *d, unsigned int size)
104 int s;
105 for (s = 0; s < size; s += 4) {
106 fprintf(stdout, "0x%04x 0x%02X%02X%02X%02X %c%c%c%c\n", s,
107 (unsigned int) d[s], (unsigned int) d[s + 1],
108 (unsigned int) d[s + 2], (unsigned int) d[s + 3], d[s],
109 d[s + 1], d[s + 2], d[s + 3]);
112 #endif