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