Remove warnings from USB debug console code.
[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_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 #if CONFIG_CONSOLE_VGA == 1
13 void vga_console_init(void);
14 #endif
15 #if CONFIG_USBDEBUG
16 #include <usbdebug.h>
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 #else
35 /* __PRE_RAM__ */
36 /* Using a global varible can cause problems when we reset the stack
37  * from cache as ram to ram. If we make this a define USE_SHARED_STACK
38  * we could use the same code on all architectures.
39  */
40 #define console_loglevel CONFIG_DEFAULT_CONSOLE_LOGLEVEL
41 #endif
42
43 #ifndef __ROMCC__
44 void console_init(void);
45 void post_code(u8 value);
46 void __attribute__ ((noreturn)) die(const char *msg);
47 int do_printk(int msg_level, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
48
49 #undef WE_CLEANED_UP_ALL_SIDE_EFFECTS
50 /* We saw some strange effects in the past like coreboot crashing while
51  * disabling cache as ram for a maximum console log level of 6 and above while
52  * it worked fine without. In order to catch such issues reliably we are
53  * always doing a function call to do_printk with the full number of arguments.
54  * Our favorite reason to do it this way was:
55  *   disable_car();
56  *   printk(BIOS_DEBUG, "CAR disabled\n"); // oops, garbage stack pointer
57  *   move_stack();
58  * This slightly increases the code size and some unprinted strings will end
59  * up in the final coreboot binary (most of them compressed). If you want to
60  * avoid this, do a
61  * #define WE_CLEANED_UP_ALL_SIDE_EFFECTS
62  */
63 #ifdef WE_CLEANED_UP_ALL_SIDE_EFFECTS
64
65 #define printk(LEVEL, fmt, args...)                             \
66         do {                                                    \
67                 if (CONFIG_MAXIMUM_CONSOLE_LOGLEVEL >= LEVEL) { \
68                         do_printk(LEVEL, fmt, ##args);          \
69                 }                                               \
70         } while(0)
71
72 #else
73
74 #define printk(LEVEL, fmt, args...)                             \
75         do {                                                    \
76                 if (CONFIG_MAXIMUM_CONSOLE_LOGLEVEL >= LEVEL) { \
77                         do_printk(LEVEL, fmt, ##args);          \
78                 } else {                                        \
79                         do_printk(BIOS_NEVER, fmt, ##args);     \
80                 }                                               \
81         } while(0)
82 #endif
83
84 #define print_emerg(STR)         printk(BIOS_EMERG,  "%s", (STR))
85 #define print_alert(STR)         printk(BIOS_ALERT,  "%s", (STR))
86 #define print_crit(STR)          printk(BIOS_CRIT,   "%s", (STR))
87 #define print_err(STR)           printk(BIOS_ERR,    "%s", (STR))
88 #define print_warning(STR)       printk(BIOS_WARNING,"%s", (STR))
89 #define print_notice(STR)        printk(BIOS_NOTICE, "%s", (STR))
90 #define print_info(STR)          printk(BIOS_INFO,   "%s", (STR))
91 #define print_debug(STR)         printk(BIOS_DEBUG,  "%s", (STR))
92 #define print_spew(STR)          printk(BIOS_SPEW,   "%s", (STR))
93
94 #define print_emerg_char(CH)     printk(BIOS_EMERG,  "%c", (CH))
95 #define print_alert_char(CH)     printk(BIOS_ALERT,  "%c", (CH))
96 #define print_crit_char(CH)      printk(BIOS_CRIT,   "%c", (CH))
97 #define print_err_char(CH)       printk(BIOS_ERR,    "%c", (CH))
98 #define print_warning_char(CH)   printk(BIOS_WARNING,"%c", (CH))
99 #define print_notice_char(CH)    printk(BIOS_NOTICE, "%c", (CH))
100 #define print_info_char(CH)      printk(BIOS_INFO,   "%c", (CH))
101 #define print_debug_char(CH)     printk(BIOS_DEBUG,  "%c", (CH))
102 #define print_spew_char(CH)      printk(BIOS_SPEW,   "%c", (CH))
103
104 #define print_emerg_hex8(HEX)    printk(BIOS_EMERG,  "%02x",  (HEX))
105 #define print_alert_hex8(HEX)    printk(BIOS_ALERT,  "%02x",  (HEX))
106 #define print_crit_hex8(HEX)     printk(BIOS_CRIT,   "%02x",  (HEX))
107 #define print_err_hex8(HEX)      printk(BIOS_ERR,    "%02x",  (HEX))
108 #define print_warning_hex8(HEX)  printk(BIOS_WARNING,"%02x",  (HEX))
109 #define print_notice_hex8(HEX)   printk(BIOS_NOTICE, "%02x",  (HEX))
110 #define print_info_hex8(HEX)     printk(BIOS_INFO,   "%02x",  (HEX))
111 #define print_debug_hex8(HEX)    printk(BIOS_DEBUG,  "%02x",  (HEX))
112 #define print_spew_hex8(HEX)     printk(BIOS_SPEW,   "%02x",  (HEX))
113
114 #define print_emerg_hex16(HEX)   printk(BIOS_EMERG,  "%04x", (HEX))
115 #define print_alert_hex16(HEX)   printk(BIOS_ALERT,  "%04x", (HEX))
116 #define print_crit_hex16(HEX)    printk(BIOS_CRIT,   "%04x", (HEX))
117 #define print_err_hex16(HEX)     printk(BIOS_ERR,    "%04x", (HEX))
118 #define print_warning_hex16(HEX) printk(BIOS_WARNING,"%04x", (HEX))
119 #define print_notice_hex16(HEX)  printk(BIOS_NOTICE, "%04x", (HEX))
120 #define print_info_hex16(HEX)    printk(BIOS_INFO,   "%04x", (HEX))
121 #define print_debug_hex16(HEX)   printk(BIOS_DEBUG,  "%04x", (HEX))
122 #define print_spew_hex16(HEX)    printk(BIOS_SPEW,   "%04x", (HEX))
123
124 #define print_emerg_hex32(HEX)   printk(BIOS_EMERG,  "%08x", (HEX))
125 #define print_alert_hex32(HEX)   printk(BIOS_ALERT,  "%08x", (HEX))
126 #define print_crit_hex32(HEX)    printk(BIOS_CRIT,   "%08x", (HEX))
127 #define print_err_hex32(HEX)     printk(BIOS_ERR,    "%08x", (HEX))
128 #define print_warning_hex32(HEX) printk(BIOS_WARNING,"%08x", (HEX))
129 #define print_notice_hex32(HEX)  printk(BIOS_NOTICE, "%08x", (HEX))
130 #define print_info_hex32(HEX)    printk(BIOS_INFO,   "%08x", (HEX))
131 #define print_debug_hex32(HEX)   printk(BIOS_DEBUG,  "%08x", (HEX))
132 #define print_spew_hex32(HEX)    printk(BIOS_SPEW,   "%08x", (HEX))
133 #else
134
135 #include <pc80/serial.c>
136
137 #if CONFIG_CONSOLE_NE2K
138 #include "lib/ne2k.c"
139 #endif
140
141 /* __ROMCC__ */
142 static void __console_tx_byte(unsigned char byte)
143 {
144         uart_tx_byte(byte);
145 #if CONFIG_CONSOLE_NE2K
146         ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT);
147 #endif
148 }
149
150 static void __console_tx_nibble(unsigned nibble)
151 {
152         unsigned char digit;
153         digit = nibble + '0';
154         if (digit > '9') {
155                 digit += 39;
156         }
157         __console_tx_byte(digit);
158 }
159
160 static void __console_tx_char(int loglevel, unsigned char byte)
161 {
162         if (console_loglevel >= loglevel) {
163                 uart_tx_byte(byte);
164 #if CONFIG_CONSOLE_NE2K
165         ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT);
166         ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
167 #endif
168         }
169 }
170
171 static void __console_tx_hex8(int loglevel, unsigned char value)
172 {
173         if (console_loglevel >= loglevel) {
174                 __console_tx_nibble((value >>  4U) & 0x0fU);
175                 __console_tx_nibble(value & 0x0fU);
176         }
177 #if CONFIG_CONSOLE_NE2K
178                 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
179 #endif
180 }
181
182 static void __console_tx_hex16(int loglevel, unsigned short value)
183 {
184         if (console_loglevel >= loglevel) {
185                 __console_tx_nibble((value >> 12U) & 0x0fU);
186                 __console_tx_nibble((value >>  8U) & 0x0fU);
187                 __console_tx_nibble((value >>  4U) & 0x0fU);
188                 __console_tx_nibble(value & 0x0fU);
189         }
190 #if CONFIG_CONSOLE_NE2K
191                 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
192 #endif
193 }
194
195 static void __console_tx_hex32(int loglevel, unsigned int value)
196 {
197         if (console_loglevel >= loglevel) {
198                 __console_tx_nibble((value >> 28U) & 0x0fU);
199                 __console_tx_nibble((value >> 24U) & 0x0fU);
200                 __console_tx_nibble((value >> 20U) & 0x0fU);
201                 __console_tx_nibble((value >> 16U) & 0x0fU);
202                 __console_tx_nibble((value >> 12U) & 0x0fU);
203                 __console_tx_nibble((value >>  8U) & 0x0fU);
204                 __console_tx_nibble((value >>  4U) & 0x0fU);
205                 __console_tx_nibble(value & 0x0fU);
206         }
207 #if CONFIG_CONSOLE_NE2K
208                 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
209 #endif
210 }
211
212 static void __console_tx_string(int loglevel, const char *str)
213 {
214         if (console_loglevel >= loglevel) {
215                 unsigned char ch;
216                 while((ch = *str++) != '\0') {
217                         if (ch == '\n')
218                                 __console_tx_byte('\r');
219                         __console_tx_byte(ch);
220                 }
221 #if CONFIG_CONSOLE_NE2K
222                 ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
223 #endif
224         }
225 }
226
227 #define FUNCTIONS_FOR_PRINT
228 #ifdef  FUNCTIONS_FOR_PRINT
229 static void print_emerg_char(unsigned char byte) { __console_tx_char(BIOS_EMERG, byte); }
230 static void print_emerg_hex8(unsigned char value){ __console_tx_hex8(BIOS_EMERG, value); }
231 static void print_emerg_hex16(unsigned short value){ __console_tx_hex16(BIOS_EMERG, value); }
232 static void print_emerg_hex32(unsigned int value) { __console_tx_hex32(BIOS_EMERG, value); }
233 static void print_emerg(const char *str) { __console_tx_string(BIOS_EMERG, str); }
234
235 static void print_alert_char(unsigned char byte) { __console_tx_char(BIOS_ALERT, byte); }
236 static void print_alert_hex8(unsigned char value) { __console_tx_hex8(BIOS_ALERT, value); }
237 static void print_alert_hex16(unsigned short value){ __console_tx_hex16(BIOS_ALERT, value); }
238 static void print_alert_hex32(unsigned int value) { __console_tx_hex32(BIOS_ALERT, value); }
239 static void print_alert(const char *str) { __console_tx_string(BIOS_ALERT, str); }
240
241 static void print_crit_char(unsigned char byte) { __console_tx_char(BIOS_CRIT, byte); }
242 static void print_crit_hex8(unsigned char value) { __console_tx_hex8(BIOS_CRIT, value); }
243 static void print_crit_hex16(unsigned short value){ __console_tx_hex16(BIOS_CRIT, value); }
244 static void print_crit_hex32(unsigned int value) { __console_tx_hex32(BIOS_CRIT, value); }
245 static void print_crit(const char *str) { __console_tx_string(BIOS_CRIT, str); }
246
247 static void print_err_char(unsigned char byte) { __console_tx_char(BIOS_ERR, byte); }
248 static void print_err_hex8(unsigned char value) { __console_tx_hex8(BIOS_ERR, value); }
249 static void print_err_hex16(unsigned short value){ __console_tx_hex16(BIOS_ERR, value); }
250 static void print_err_hex32(unsigned int value) { __console_tx_hex32(BIOS_ERR, value); }
251 static void print_err(const char *str) { __console_tx_string(BIOS_ERR, str); }
252
253 static void print_warning_char(unsigned char byte) { __console_tx_char(BIOS_WARNING, byte); }
254 static void print_warning_hex8(unsigned char value) { __console_tx_hex8(BIOS_WARNING, value); }
255 static void print_warning_hex16(unsigned short value){ __console_tx_hex16(BIOS_WARNING, value); }
256 static void print_warning_hex32(unsigned int value) { __console_tx_hex32(BIOS_WARNING, value); }
257 static void print_warning(const char *str) { __console_tx_string(BIOS_WARNING, str); }
258
259 static void print_notice_char(unsigned char byte) { __console_tx_char(BIOS_NOTICE, byte); }
260 static void print_notice_hex8(unsigned char value) { __console_tx_hex8(BIOS_NOTICE, value); }
261 static void print_notice_hex16(unsigned short value){ __console_tx_hex16(BIOS_NOTICE, value); }
262 static void print_notice_hex32(unsigned int value) { __console_tx_hex32(BIOS_NOTICE, value); }
263 static void print_notice(const char *str) { __console_tx_string(BIOS_NOTICE, str); }
264
265 static void print_info_char(unsigned char byte) { __console_tx_char(BIOS_INFO, byte); }
266 static void print_info_hex8(unsigned char value) { __console_tx_hex8(BIOS_INFO, value); }
267 static void print_info_hex16(unsigned short value){ __console_tx_hex16(BIOS_INFO, value); }
268 static void print_info_hex32(unsigned int value) { __console_tx_hex32(BIOS_INFO, value); }
269 static void print_info(const char *str) { __console_tx_string(BIOS_INFO, str); }
270
271 static void print_debug_char(unsigned char byte) { __console_tx_char(BIOS_DEBUG, byte); }
272 static void print_debug_hex8(unsigned char value) { __console_tx_hex8(BIOS_DEBUG, value); }
273 static void print_debug_hex16(unsigned short value){ __console_tx_hex16(BIOS_DEBUG, value); }
274 static void print_debug_hex32(unsigned int value) { __console_tx_hex32(BIOS_DEBUG, value); }
275 static void print_debug(const char *str) { __console_tx_string(BIOS_DEBUG, str); }
276
277 static void print_spew_char(unsigned char byte) { __console_tx_char(BIOS_SPEW, byte); }
278 static void print_spew_hex8(unsigned char value) { __console_tx_hex8(BIOS_SPEW, value); }
279 static void print_spew_hex16(unsigned short value){ __console_tx_hex16(BIOS_SPEW, value); }
280 static void print_spew_hex32(unsigned int value) { __console_tx_hex32(BIOS_SPEW, value); }
281 static void print_spew(const char *str) { __console_tx_string(BIOS_SPEW, str); }
282
283 #else
284 #define print_emerg(STR)         __console_tx_string(BIOS_EMERG, STR)
285 #define print_alert(STR)         __console_tx_string(BIOS_ALERT, STR)
286 #define print_crit(STR)          __console_tx_string(BIOS_CRIT, STR)
287 #define print_err(STR)           __console_tx_string(BIOS_ERR, STR)
288 #define print_warning(STR)       __console_tx_string(BIOS_WARNING, STR)
289 #define print_notice(STR)        __console_tx_string(BIOS_NOTICE, STR)
290 #define print_info(STR)          __console_tx_string(BIOS_INFO, STR)
291 #define print_debug(STR)         __console_tx_string(BIOS_DEBUG, STR)
292 #define print_spew(STR)          __console_tx_string(BIOS_SPEW, STR)
293
294 #define print_emerg_char(CH)     __console_tx_char(BIOS_EMERG, CH)
295 #define print_alert_char(CH)     __console_tx_char(BIOS_ALERT, CH)
296 #define print_crit_char(CH)      __console_tx_char(BIOS_CRIT, CH)
297 #define print_err_char(CH)       __console_tx_char(BIOS_ERR, CH)
298 #define print_warning_char(CH)   __console_tx_char(BIOS_WARNING, CH)
299 #define print_notice_char(CH)    __console_tx_char(BIOS_NOTICE, CH)
300 #define print_info_char(CH)      __console_tx_char(BIOS_INFO, CH)
301 #define print_debug_char(CH)     __console_tx_char(BIOS_DEBUG, CH)
302 #define print_spew_char(CH)      __console_tx_char(BIOS_SPEW, CH)
303
304 #define print_emerg_hex8(HEX)    __console_tx_hex8(BIOS_EMERG, HEX)
305 #define print_alert_hex8(HEX)    __console_tx_hex8(BIOS_ALERT, HEX)
306 #define print_crit_hex8(HEX)     __console_tx_hex8(BIOS_CRIT, HEX)
307 #define print_err_hex8(HEX)      __console_tx_hex8(BIOS_ERR, HEX)
308 #define print_warning_hex8(HEX)  __console_tx_hex8(BIOS_WARNING, HEX)
309 #define print_notice_hex8(HEX)   __console_tx_hex8(BIOS_NOTICE, HEX)
310 #define print_info_hex8(HEX)     __console_tx_hex8(BIOS_INFO, HEX)
311 #define print_debug_hex8(HEX)    __console_tx_hex8(BIOS_DEBUG, HEX)
312 #define print_spew_hex8(HEX)     __console_tx_hex8(BIOS_SPEW, HEX)
313
314 #define print_emerg_hex16(HEX)   __console_tx_hex16(BIOS_EMERG, HEX)
315 #define print_alert_hex16(HEX)   __console_tx_hex16(BIOS_ALERT, HEX)
316 #define print_crit_hex16(HEX)    __console_tx_hex16(BIOS_CRIT, HEX)
317 #define print_err_hex16(HEX)     __console_tx_hex16(BIOS_ERR, HEX)
318 #define print_warning_hex16(HEX) __console_tx_hex16(BIOS_WARNING, HEX)
319 #define print_notice_hex16(HEX)  __console_tx_hex16(BIOS_NOTICE, HEX)
320 #define print_info_hex16(HEX)    __console_tx_hex16(BIOS_INFO, HEX)
321 #define print_debug_hex16(HEX)   __console_tx_hex16(BIOS_DEBUG, HEX)
322 #define print_spew_hex16(HEX)    __console_tx_hex16(BIOS_SPEW, HEX)
323
324 #define print_emerg_hex32(HEX)   __console_tx_hex32(BIOS_EMERG, HEX)
325 #define print_alert_hex32(HEX)   __console_tx_hex32(BIOS_ALERT, HEX)
326 #define print_crit_hex32(HEX)    __console_tx_hex32(BIOS_CRIT, HEX)
327 #define print_err_hex32(HEX)     __console_tx_hex32(BIOS_ERR, HEX)
328 #define print_warning_hex32(HEX) __console_tx_hex32(BIOS_WARNING, HEX)
329 #define print_notice_hex32(HEX)  __console_tx_hex32(BIOS_NOTICE, HEX)
330 #define print_info_hex32(HEX)    __console_tx_hex32(BIOS_INFO, HEX)
331 #define print_debug_hex32(HEX)   __console_tx_hex32(BIOS_DEBUG, HEX)
332 #define print_spew_hex32(HEX)    __console_tx_hex32(BIOS_SPEW, HEX)
333 #endif
334
335 #endif
336
337 #ifdef __ROMCC__
338 /* if included by romcc, include the sources, too. romcc can't use prototypes */
339 #include <console/console.c>
340 #endif
341
342 #endif /* CONSOLE_CONSOLE_H_ */