blob: e6962cc69dd377fc278a902911cf14afe0a5f4e2 [file] [log] [blame]
Stefan Reinauer2a8ad412010-09-27 18:49:46 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2003 Eric Biederman
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
Eric Biederman8ca8d762003-04-22 19:02:15 +000020#ifndef CONSOLE_CONSOLE_H_
21#define CONSOLE_CONSOLE_H_
22
Stefan Reinauer4f7a5c42010-09-27 20:51:33 +000023#include <stdint.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000024#include <console/loglevel.h>
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +000025#include <console/post_codes.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000026
Hung-Te Linad173ea2013-02-06 21:24:12 +080027#if CONFIG_CONSOLE_SERIAL
28#include <uart.h>
Stefan Reinauer8907e812011-05-10 10:46:41 -070029#endif
Kyösti Mälkkib0aec8f2013-10-30 15:03:25 +020030#if CONFIG_USBDEBUG && !defined(__ROMCC__)
Stefan Reinauer8907e812011-05-10 10:46:41 -070031#include <usbdebug.h>
32#endif
33#if CONFIG_CONSOLE_NE2K
34#include <console/ne2k.h>
35#endif
Vadim Bendebury32da8be2011-09-29 17:27:15 -070036#if CONFIG_CONSOLE_CBMEM
37#include <console/cbmem_console.h>
38#endif
Vladimir Serbinenko45988da2013-03-30 02:02:13 +010039#if CONFIG_SPKMODEM
40#include <console/spkmodem.h>
41#endif
Stefan Reinauer8907e812011-05-10 10:46:41 -070042
Myles Watsonb54deb72010-04-02 21:39:12 +000043#ifndef __PRE_RAM__
Greg Watsone54d55b2004-03-13 03:40:51 +000044unsigned char console_rx_byte(void);
45int console_tst_byte(void);
Eric Biederman8ca8d762003-04-22 19:02:15 +000046struct console_driver {
47 void (*init)(void);
48 void (*tx_byte)(unsigned char byte);
49 void (*tx_flush)(void);
Greg Watsone54d55b2004-03-13 03:40:51 +000050 unsigned char (*rx_byte)(void);
51 int (*tst_byte)(void);
Eric Biederman8ca8d762003-04-22 19:02:15 +000052};
53
Eric Biedermanb78c1972004-10-14 20:54:17 +000054#define __console __attribute__((used, __section__ (".rodata.console_drivers")))
Eric Biederman8ca8d762003-04-22 19:02:15 +000055
56/* Defined by the linker... */
57extern struct console_driver console_drivers[];
58extern struct console_driver econsole_drivers[];
59
Luc Verhaegena9c5ea02009-06-03 14:19:33 +000060extern int console_loglevel;
Stefan Reinauer0c781b22010-04-01 09:50:32 +000061#else
62/* __PRE_RAM__ */
Martin Roth0cb07e32013-07-09 21:46:01 -060063/* Using a global variable can cause problems when we reset the stack
Stefan Reinauer0c781b22010-04-01 09:50:32 +000064 * from cache as ram to ram. If we make this a define USE_SHARED_STACK
65 * we could use the same code on all architectures.
66 */
67#define console_loglevel CONFIG_DEFAULT_CONSOLE_LOGLEVEL
68#endif
Stefan Reinauerb8ac05d2010-03-31 00:06:12 +000069
Stefan Reinauer5a1f5972010-03-31 14:34:40 +000070#ifndef __ROMCC__
Stefan Reinauer720297c2010-04-02 22:11:20 +000071void console_init(void);
Vadim Bendebury48a4a7f2012-06-07 18:47:13 -070072void console_tx_byte(unsigned char byte);
Aaron Durbin1989b4b2013-03-22 19:52:42 -050073void console_tx_flush(void);
Stefan Reinauer720297c2010-04-02 22:11:20 +000074void post_code(u8 value);
Duncan Lauried5686fe2013-06-10 10:21:41 -070075#if CONFIG_CMOS_POST_EXTRA
76void post_log_extra(u32 value);
77#else
78#define post_log_extra(x) do {} while (0)
79#endif
Alexandru Gagniucf88204e2012-08-03 13:20:57 -050080/* this function is weak and can be overridden by a mainboard function. */
81void mainboard_post(u8 value);
Stefan Reinauer720297c2010-04-02 22:11:20 +000082void __attribute__ ((noreturn)) die(const char *msg);
Carl-Daniel Hailfinger90308bb2009-01-20 18:37:26 +000083int do_printk(int msg_level, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
Marc Jonesaf0cd092013-10-30 16:25:23 -060084void hexdump32(char LEVEL, const void *d, int len);
Eric Biederman8ca8d762003-04-22 19:02:15 +000085
Gabe Blackfbb11cf2013-06-06 00:21:20 -070086#if defined(__BOOT_BLOCK__) && !CONFIG_BOOTBLOCK_CONSOLE || \
87 (defined(__PRE_RAM__) && !defined(__BOOT_BLOCK__)) && !CONFIG_EARLY_CONSOLE
Hung-Te Lin580fa2b2013-02-06 21:51:15 +080088
89static inline void printk(int LEVEL, const char *fmt, ...);
90static inline void printk(int LEVEL, const char *fmt, ...) {
91 /* Do nothing. */
92}
93
94#else /* defined(__PRE_RAM__) && !CONFIG_EARLY_CONSOLE */
95
Stefan Reinauerf0aa09b2010-03-23 13:23:40 +000096#define printk(LEVEL, fmt, args...) \
97 do { \
Ronald G. Minnich711a6fd2013-05-03 18:25:27 +020098 do_printk(LEVEL, fmt, ##args); \
Stefan Reinauerf0aa09b2010-03-23 13:23:40 +000099 } while(0)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000100
Hung-Te Lin580fa2b2013-02-06 21:51:15 +0800101#endif /* defined(__PRE_RAM__) && !CONFIG_EARLY_CONSOLE */
102
Stefan Reinauer5a1f5972010-03-31 14:34:40 +0000103#define print_emerg(STR) printk(BIOS_EMERG, "%s", (STR))
104#define print_alert(STR) printk(BIOS_ALERT, "%s", (STR))
105#define print_crit(STR) printk(BIOS_CRIT, "%s", (STR))
106#define print_err(STR) printk(BIOS_ERR, "%s", (STR))
107#define print_warning(STR) printk(BIOS_WARNING,"%s", (STR))
108#define print_notice(STR) printk(BIOS_NOTICE, "%s", (STR))
109#define print_info(STR) printk(BIOS_INFO, "%s", (STR))
110#define print_debug(STR) printk(BIOS_DEBUG, "%s", (STR))
111#define print_spew(STR) printk(BIOS_SPEW, "%s", (STR))
Eric Biederman9b4336c2003-07-19 04:28:22 +0000112
Stefan Reinauer5a1f5972010-03-31 14:34:40 +0000113#define print_emerg_char(CH) printk(BIOS_EMERG, "%c", (CH))
114#define print_alert_char(CH) printk(BIOS_ALERT, "%c", (CH))
115#define print_crit_char(CH) printk(BIOS_CRIT, "%c", (CH))
116#define print_err_char(CH) printk(BIOS_ERR, "%c", (CH))
117#define print_warning_char(CH) printk(BIOS_WARNING,"%c", (CH))
118#define print_notice_char(CH) printk(BIOS_NOTICE, "%c", (CH))
119#define print_info_char(CH) printk(BIOS_INFO, "%c", (CH))
120#define print_debug_char(CH) printk(BIOS_DEBUG, "%c", (CH))
121#define print_spew_char(CH) printk(BIOS_SPEW, "%c", (CH))
Eric Biederman9b4336c2003-07-19 04:28:22 +0000122
Stefan Reinauer5a1f5972010-03-31 14:34:40 +0000123#define print_emerg_hex8(HEX) printk(BIOS_EMERG, "%02x", (HEX))
124#define print_alert_hex8(HEX) printk(BIOS_ALERT, "%02x", (HEX))
125#define print_crit_hex8(HEX) printk(BIOS_CRIT, "%02x", (HEX))
126#define print_err_hex8(HEX) printk(BIOS_ERR, "%02x", (HEX))
127#define print_warning_hex8(HEX) printk(BIOS_WARNING,"%02x", (HEX))
128#define print_notice_hex8(HEX) printk(BIOS_NOTICE, "%02x", (HEX))
129#define print_info_hex8(HEX) printk(BIOS_INFO, "%02x", (HEX))
130#define print_debug_hex8(HEX) printk(BIOS_DEBUG, "%02x", (HEX))
131#define print_spew_hex8(HEX) printk(BIOS_SPEW, "%02x", (HEX))
Eric Biederman9b4336c2003-07-19 04:28:22 +0000132
Stefan Reinauerf0aa09b2010-03-23 13:23:40 +0000133#define print_emerg_hex16(HEX) printk(BIOS_EMERG, "%04x", (HEX))
134#define print_alert_hex16(HEX) printk(BIOS_ALERT, "%04x", (HEX))
135#define print_crit_hex16(HEX) printk(BIOS_CRIT, "%04x", (HEX))
136#define print_err_hex16(HEX) printk(BIOS_ERR, "%04x", (HEX))
137#define print_warning_hex16(HEX) printk(BIOS_WARNING,"%04x", (HEX))
138#define print_notice_hex16(HEX) printk(BIOS_NOTICE, "%04x", (HEX))
139#define print_info_hex16(HEX) printk(BIOS_INFO, "%04x", (HEX))
140#define print_debug_hex16(HEX) printk(BIOS_DEBUG, "%04x", (HEX))
141#define print_spew_hex16(HEX) printk(BIOS_SPEW, "%04x", (HEX))
Eric Biederman9b4336c2003-07-19 04:28:22 +0000142
Stefan Reinauerf0aa09b2010-03-23 13:23:40 +0000143#define print_emerg_hex32(HEX) printk(BIOS_EMERG, "%08x", (HEX))
144#define print_alert_hex32(HEX) printk(BIOS_ALERT, "%08x", (HEX))
145#define print_crit_hex32(HEX) printk(BIOS_CRIT, "%08x", (HEX))
146#define print_err_hex32(HEX) printk(BIOS_ERR, "%08x", (HEX))
147#define print_warning_hex32(HEX) printk(BIOS_WARNING,"%08x", (HEX))
148#define print_notice_hex32(HEX) printk(BIOS_NOTICE, "%08x", (HEX))
149#define print_info_hex32(HEX) printk(BIOS_INFO, "%08x", (HEX))
150#define print_debug_hex32(HEX) printk(BIOS_DEBUG, "%08x", (HEX))
151#define print_spew_hex32(HEX) printk(BIOS_SPEW, "%08x", (HEX))
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000152
Stefan Reinauer5a1f5972010-03-31 14:34:40 +0000153#else
Stefan Reinauer0c781b22010-04-01 09:50:32 +0000154
Stefan Reinauer38174942010-12-17 01:51:34 +0000155/* __ROMCC__ */
156
Stefan Reinauer5a1f5972010-03-31 14:34:40 +0000157#define print_emerg(STR) __console_tx_string(BIOS_EMERG, STR)
158#define print_alert(STR) __console_tx_string(BIOS_ALERT, STR)
159#define print_crit(STR) __console_tx_string(BIOS_CRIT, STR)
160#define print_err(STR) __console_tx_string(BIOS_ERR, STR)
161#define print_warning(STR) __console_tx_string(BIOS_WARNING, STR)
162#define print_notice(STR) __console_tx_string(BIOS_NOTICE, STR)
163#define print_info(STR) __console_tx_string(BIOS_INFO, STR)
164#define print_debug(STR) __console_tx_string(BIOS_DEBUG, STR)
165#define print_spew(STR) __console_tx_string(BIOS_SPEW, STR)
166
167#define print_emerg_char(CH) __console_tx_char(BIOS_EMERG, CH)
168#define print_alert_char(CH) __console_tx_char(BIOS_ALERT, CH)
169#define print_crit_char(CH) __console_tx_char(BIOS_CRIT, CH)
170#define print_err_char(CH) __console_tx_char(BIOS_ERR, CH)
171#define print_warning_char(CH) __console_tx_char(BIOS_WARNING, CH)
172#define print_notice_char(CH) __console_tx_char(BIOS_NOTICE, CH)
173#define print_info_char(CH) __console_tx_char(BIOS_INFO, CH)
174#define print_debug_char(CH) __console_tx_char(BIOS_DEBUG, CH)
175#define print_spew_char(CH) __console_tx_char(BIOS_SPEW, CH)
176
177#define print_emerg_hex8(HEX) __console_tx_hex8(BIOS_EMERG, HEX)
178#define print_alert_hex8(HEX) __console_tx_hex8(BIOS_ALERT, HEX)
179#define print_crit_hex8(HEX) __console_tx_hex8(BIOS_CRIT, HEX)
180#define print_err_hex8(HEX) __console_tx_hex8(BIOS_ERR, HEX)
181#define print_warning_hex8(HEX) __console_tx_hex8(BIOS_WARNING, HEX)
182#define print_notice_hex8(HEX) __console_tx_hex8(BIOS_NOTICE, HEX)
183#define print_info_hex8(HEX) __console_tx_hex8(BIOS_INFO, HEX)
184#define print_debug_hex8(HEX) __console_tx_hex8(BIOS_DEBUG, HEX)
185#define print_spew_hex8(HEX) __console_tx_hex8(BIOS_SPEW, HEX)
186
187#define print_emerg_hex16(HEX) __console_tx_hex16(BIOS_EMERG, HEX)
188#define print_alert_hex16(HEX) __console_tx_hex16(BIOS_ALERT, HEX)
189#define print_crit_hex16(HEX) __console_tx_hex16(BIOS_CRIT, HEX)
190#define print_err_hex16(HEX) __console_tx_hex16(BIOS_ERR, HEX)
191#define print_warning_hex16(HEX) __console_tx_hex16(BIOS_WARNING, HEX)
192#define print_notice_hex16(HEX) __console_tx_hex16(BIOS_NOTICE, HEX)
193#define print_info_hex16(HEX) __console_tx_hex16(BIOS_INFO, HEX)
194#define print_debug_hex16(HEX) __console_tx_hex16(BIOS_DEBUG, HEX)
195#define print_spew_hex16(HEX) __console_tx_hex16(BIOS_SPEW, HEX)
196
197#define print_emerg_hex32(HEX) __console_tx_hex32(BIOS_EMERG, HEX)
198#define print_alert_hex32(HEX) __console_tx_hex32(BIOS_ALERT, HEX)
199#define print_crit_hex32(HEX) __console_tx_hex32(BIOS_CRIT, HEX)
200#define print_err_hex32(HEX) __console_tx_hex32(BIOS_ERR, HEX)
201#define print_warning_hex32(HEX) __console_tx_hex32(BIOS_WARNING, HEX)
202#define print_notice_hex32(HEX) __console_tx_hex32(BIOS_NOTICE, HEX)
203#define print_info_hex32(HEX) __console_tx_hex32(BIOS_INFO, HEX)
204#define print_debug_hex32(HEX) __console_tx_hex32(BIOS_DEBUG, HEX)
205#define print_spew_hex32(HEX) __console_tx_hex32(BIOS_SPEW, HEX)
Stefan Reinauer5a1f5972010-03-31 14:34:40 +0000206
Stefan Reinauerbbd2f212011-04-20 21:11:22 +0000207#include "arch/x86/lib/romcc_console.c"
208
209#endif /* __ROMCC__ */
Patrick Georgi12584e22010-05-08 09:14:51 +0000210
Eric Biederman8ca8d762003-04-22 19:02:15 +0000211#endif /* CONSOLE_CONSOLE_H_ */