fix newly introduced printk_foo warnings..
[coreboot.git] / src / include / console / console.h
1 #ifndef CONSOLE_CONSOLE_H_
2 #define CONSOLE_CONSOLE_H_
3
4 #include <stdint.h>
5 #include <console/loglevel.h>
6
7 void console_init(void);
8 void console_tx_byte(unsigned char byte);
9 void console_tx_flush(void);
10 unsigned char console_rx_byte(void);
11 int console_tst_byte(void);
12 void post_code(uint8_t value);
13 void __attribute__ ((noreturn)) die(const char *msg);
14
15 struct console_driver {
16         void (*init)(void);
17         void (*tx_byte)(unsigned char byte);
18         void (*tx_flush)(void);
19         unsigned char (*rx_byte)(void);
20         int (*tst_byte)(void);
21 };
22
23 #define __console       __attribute__((used, __section__ (".rodata.console_drivers")))
24
25 /* Defined by the linker... */
26 extern struct console_driver console_drivers[];
27 extern struct console_driver econsole_drivers[];
28
29 extern int console_loglevel;
30 int do_printk(int msg_level, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
31
32 #undef WE_CLEANED_UP_ALL_SIDE_EFFECTS
33 /* We saw some strange effects in the past like coreboot crashing while
34  * disabling cache as ram for a maximum console log level of 6 and above while
35  * it worked fine without. In order to catch such issues reliably we are
36  * always doing a function call to do_printk with the full number of arguments.
37  * This slightly increases the code size and some unprinted strings will end
38  * up in the final coreboot binary (most of them compressed). If you want to
39  * avoid this, do a
40  * #define WE_CLEANED_UP_ALL_SIDE_EFFECTS
41  */
42 #ifdef WE_CLEANED_UP_ALL_SIDE_EFFECTS
43
44 #define printk(LEVEL, fmt, args...)                             \
45         do {                                                    \
46                 if (CONFIG_MAXIMUM_CONSOLE_LOGLEVEL >= LEVEL) { \
47                         do_printk(LEVEL, fmt, ##args);          \
48                 }                                               \
49         } while(0)
50
51 #else
52
53 #define printk(LEVEL, fmt, args...)                             \
54         do {                                                    \
55                 if (CONFIG_MAXIMUM_CONSOLE_LOGLEVEL >= LEVEL) { \
56                         do_printk(LEVEL, fmt, ##args);          \
57                 } else {                                        \
58                         do_printk(BIOS_NEVER, fmt, ##args);     \
59                 }                                               \
60         } while(0)
61 #endif
62
63 #define print_emerg(STR)   printk(BIOS_EMERG,  "%s", (STR))
64 #define print_alert(STR)   printk(BIOS_ALERT,  "%s", (STR))
65 #define print_crit(STR)    printk(BIOS_CRIT,   "%s", (STR))
66 #define print_err(STR)     printk(BIOS_ERR,    "%s", (STR))
67 #define print_warning(STR) printk(BIOS_WARNING,"%s", (STR))
68 #define print_notice(STR)  printk(BIOS_NOTICE, "%s", (STR))
69 #define print_info(STR)    printk(BIOS_INFO,   "%s", (STR))
70 #define print_debug(STR)   printk(BIOS_DEBUG,  "%s", (STR))
71 #define print_spew(STR)    printk(BIOS_SPEW,   "%s", (STR))
72
73 #define print_emerg_char(CH)   printk(BIOS_EMERG,  "%c", (CH))
74 #define print_alert_char(CH)   printk(BIOS_ALERT,  "%c", (CH))
75 #define print_crit_char(CH)    printk(BIOS_CRIT,   "%c", (CH))
76 #define print_err_char(CH)     printk(BIOS_ERR,    "%c", (CH))
77 #define print_warning_char(CH) printk(BIOS_WARNING,"%c", (CH))
78 #define print_notice_char(CH)  printk(BIOS_NOTICE, "%c", (CH))
79 #define print_info_char(CH)    printk(BIOS_INFO,   "%c", (CH))
80 #define print_debug_char(CH)   printk(BIOS_DEBUG,  "%c", (CH))
81 #define print_spew_char(CH)    printk(BIOS_SPEW,   "%c", (CH))
82
83 #define print_emerg_hex8(HEX)   printk(BIOS_EMERG,  "%02x",  (HEX))
84 #define print_alert_hex8(HEX)   printk(BIOS_ALERT,  "%02x",  (HEX))
85 #define print_crit_hex8(HEX)    printk(BIOS_CRIT,   "%02x",  (HEX))
86 #define print_err_hex8(HEX)     printk(BIOS_ERR,    "%02x",  (HEX))
87 #define print_warning_hex8(HEX) printk(BIOS_WARNING,"%02x",  (HEX))
88 #define print_notice_hex8(HEX)  printk(BIOS_NOTICE, "%02x",  (HEX))
89 #define print_info_hex8(HEX)    printk(BIOS_INFO,   "%02x",  (HEX))
90 #define print_debug_hex8(HEX)   printk(BIOS_DEBUG,  "%02x",  (HEX))
91 #define print_spew_hex8(HEX)    printk(BIOS_SPEW,   "%02x",  (HEX))
92
93 #define print_emerg_hex16(HEX)   printk(BIOS_EMERG,  "%04x", (HEX))
94 #define print_alert_hex16(HEX)   printk(BIOS_ALERT,  "%04x", (HEX))
95 #define print_crit_hex16(HEX)    printk(BIOS_CRIT,   "%04x", (HEX))
96 #define print_err_hex16(HEX)     printk(BIOS_ERR,    "%04x", (HEX))
97 #define print_warning_hex16(HEX) printk(BIOS_WARNING,"%04x", (HEX))
98 #define print_notice_hex16(HEX)  printk(BIOS_NOTICE, "%04x", (HEX))
99 #define print_info_hex16(HEX)    printk(BIOS_INFO,   "%04x", (HEX))
100 #define print_debug_hex16(HEX)   printk(BIOS_DEBUG,  "%04x", (HEX))
101 #define print_spew_hex16(HEX)    printk(BIOS_SPEW,   "%04x", (HEX))
102
103 #define print_emerg_hex32(HEX)   printk(BIOS_EMERG,  "%08x", (HEX))
104 #define print_alert_hex32(HEX)   printk(BIOS_ALERT,  "%08x", (HEX))
105 #define print_crit_hex32(HEX)    printk(BIOS_CRIT,   "%08x", (HEX))
106 #define print_err_hex32(HEX)     printk(BIOS_ERR,    "%08x", (HEX))
107 #define print_warning_hex32(HEX) printk(BIOS_WARNING,"%08x", (HEX))
108 #define print_notice_hex32(HEX)  printk(BIOS_NOTICE, "%08x", (HEX))
109 #define print_info_hex32(HEX)    printk(BIOS_INFO,   "%08x", (HEX))
110 #define print_debug_hex32(HEX)   printk(BIOS_DEBUG,  "%08x", (HEX))
111 #define print_spew_hex32(HEX)    printk(BIOS_SPEW,   "%08x", (HEX))
112
113 #if CONFIG_CONSOLE_VGA == 1
114 void vga_console_init(void);
115 #endif
116
117 #endif /* CONSOLE_CONSOLE_H_ */