Stefan Reinauer | 2a8ad41 | 2010-09-27 18:49:46 +0000 | [diff] [blame] | 1 | /* |
| 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 Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 20 | #ifndef CONSOLE_CONSOLE_H_ |
| 21 | #define CONSOLE_CONSOLE_H_ |
| 22 | |
Stefan Reinauer | 4f7a5c4 | 2010-09-27 20:51:33 +0000 | [diff] [blame] | 23 | #include <stdint.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 24 | #include <console/loglevel.h> |
Alexandru Gagniuc | 5005bb06 | 2011-04-11 20:17:22 +0000 | [diff] [blame] | 25 | #include <console/post_codes.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 26 | |
Hung-Te Lin | ad173ea | 2013-02-06 21:24:12 +0800 | [diff] [blame] | 27 | #if CONFIG_CONSOLE_SERIAL |
| 28 | #include <uart.h> |
Stefan Reinauer | 8907e81 | 2011-05-10 10:46:41 -0700 | [diff] [blame] | 29 | #endif |
Kyösti Mälkki | b0aec8f | 2013-10-30 15:03:25 +0200 | [diff] [blame] | 30 | #if CONFIG_USBDEBUG && !defined(__ROMCC__) |
Stefan Reinauer | 8907e81 | 2011-05-10 10:46:41 -0700 | [diff] [blame] | 31 | #include <usbdebug.h> |
| 32 | #endif |
| 33 | #if CONFIG_CONSOLE_NE2K |
| 34 | #include <console/ne2k.h> |
| 35 | #endif |
Vadim Bendebury | 32da8be | 2011-09-29 17:27:15 -0700 | [diff] [blame] | 36 | #if CONFIG_CONSOLE_CBMEM |
| 37 | #include <console/cbmem_console.h> |
| 38 | #endif |
Vladimir Serbinenko | 45988da | 2013-03-30 02:02:13 +0100 | [diff] [blame] | 39 | #if CONFIG_SPKMODEM |
| 40 | #include <console/spkmodem.h> |
| 41 | #endif |
Stefan Reinauer | 8907e81 | 2011-05-10 10:46:41 -0700 | [diff] [blame] | 42 | |
Myles Watson | b54deb7 | 2010-04-02 21:39:12 +0000 | [diff] [blame] | 43 | #ifndef __PRE_RAM__ |
Greg Watson | e54d55b | 2004-03-13 03:40:51 +0000 | [diff] [blame] | 44 | unsigned char console_rx_byte(void); |
| 45 | int console_tst_byte(void); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 46 | struct console_driver { |
| 47 | void (*init)(void); |
| 48 | void (*tx_byte)(unsigned char byte); |
| 49 | void (*tx_flush)(void); |
Greg Watson | e54d55b | 2004-03-13 03:40:51 +0000 | [diff] [blame] | 50 | unsigned char (*rx_byte)(void); |
| 51 | int (*tst_byte)(void); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 54 | #define __console __attribute__((used, __section__ (".rodata.console_drivers"))) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 55 | |
| 56 | /* Defined by the linker... */ |
| 57 | extern struct console_driver console_drivers[]; |
| 58 | extern struct console_driver econsole_drivers[]; |
| 59 | |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 60 | extern int console_loglevel; |
Stefan Reinauer | 0c781b2 | 2010-04-01 09:50:32 +0000 | [diff] [blame] | 61 | #else |
| 62 | /* __PRE_RAM__ */ |
Martin Roth | 0cb07e3 | 2013-07-09 21:46:01 -0600 | [diff] [blame] | 63 | /* Using a global variable can cause problems when we reset the stack |
Stefan Reinauer | 0c781b2 | 2010-04-01 09:50:32 +0000 | [diff] [blame] | 64 | * 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 Reinauer | b8ac05d | 2010-03-31 00:06:12 +0000 | [diff] [blame] | 69 | |
Stefan Reinauer | 5a1f597 | 2010-03-31 14:34:40 +0000 | [diff] [blame] | 70 | #ifndef __ROMCC__ |
Stefan Reinauer | 720297c | 2010-04-02 22:11:20 +0000 | [diff] [blame] | 71 | void console_init(void); |
Vadim Bendebury | 48a4a7f | 2012-06-07 18:47:13 -0700 | [diff] [blame] | 72 | void console_tx_byte(unsigned char byte); |
Aaron Durbin | 1989b4b | 2013-03-22 19:52:42 -0500 | [diff] [blame] | 73 | void console_tx_flush(void); |
Stefan Reinauer | 720297c | 2010-04-02 22:11:20 +0000 | [diff] [blame] | 74 | void post_code(u8 value); |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame^] | 75 | #if CONFIG_CMOS_POST_EXTRA |
| 76 | void post_log_extra(u32 value); |
| 77 | #else |
| 78 | #define post_log_extra(x) do {} while (0) |
| 79 | #endif |
Alexandru Gagniuc | f88204e | 2012-08-03 13:20:57 -0500 | [diff] [blame] | 80 | /* this function is weak and can be overridden by a mainboard function. */ |
| 81 | void mainboard_post(u8 value); |
Stefan Reinauer | 720297c | 2010-04-02 22:11:20 +0000 | [diff] [blame] | 82 | void __attribute__ ((noreturn)) die(const char *msg); |
Carl-Daniel Hailfinger | 90308bb | 2009-01-20 18:37:26 +0000 | [diff] [blame] | 83 | int do_printk(int msg_level, const char *fmt, ...) __attribute__((format(printf, 2, 3))); |
Marc Jones | af0cd09 | 2013-10-30 16:25:23 -0600 | [diff] [blame] | 84 | void hexdump32(char LEVEL, const void *d, int len); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 85 | |
Gabe Black | fbb11cf | 2013-06-06 00:21:20 -0700 | [diff] [blame] | 86 | #if defined(__BOOT_BLOCK__) && !CONFIG_BOOTBLOCK_CONSOLE || \ |
| 87 | (defined(__PRE_RAM__) && !defined(__BOOT_BLOCK__)) && !CONFIG_EARLY_CONSOLE |
Hung-Te Lin | 580fa2b | 2013-02-06 21:51:15 +0800 | [diff] [blame] | 88 | |
| 89 | static inline void printk(int LEVEL, const char *fmt, ...); |
| 90 | static inline void printk(int LEVEL, const char *fmt, ...) { |
| 91 | /* Do nothing. */ |
| 92 | } |
| 93 | |
| 94 | #else /* defined(__PRE_RAM__) && !CONFIG_EARLY_CONSOLE */ |
| 95 | |
Stefan Reinauer | f0aa09b | 2010-03-23 13:23:40 +0000 | [diff] [blame] | 96 | #define printk(LEVEL, fmt, args...) \ |
| 97 | do { \ |
Ronald G. Minnich | 711a6fd | 2013-05-03 18:25:27 +0200 | [diff] [blame] | 98 | do_printk(LEVEL, fmt, ##args); \ |
Stefan Reinauer | f0aa09b | 2010-03-23 13:23:40 +0000 | [diff] [blame] | 99 | } while(0) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 100 | |
Hung-Te Lin | 580fa2b | 2013-02-06 21:51:15 +0800 | [diff] [blame] | 101 | #endif /* defined(__PRE_RAM__) && !CONFIG_EARLY_CONSOLE */ |
| 102 | |
Stefan Reinauer | 5a1f597 | 2010-03-31 14:34:40 +0000 | [diff] [blame] | 103 | #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 Biederman | 9b4336c | 2003-07-19 04:28:22 +0000 | [diff] [blame] | 112 | |
Stefan Reinauer | 5a1f597 | 2010-03-31 14:34:40 +0000 | [diff] [blame] | 113 | #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 Biederman | 9b4336c | 2003-07-19 04:28:22 +0000 | [diff] [blame] | 122 | |
Stefan Reinauer | 5a1f597 | 2010-03-31 14:34:40 +0000 | [diff] [blame] | 123 | #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 Biederman | 9b4336c | 2003-07-19 04:28:22 +0000 | [diff] [blame] | 132 | |
Stefan Reinauer | f0aa09b | 2010-03-23 13:23:40 +0000 | [diff] [blame] | 133 | #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 Biederman | 9b4336c | 2003-07-19 04:28:22 +0000 | [diff] [blame] | 142 | |
Stefan Reinauer | f0aa09b | 2010-03-23 13:23:40 +0000 | [diff] [blame] | 143 | #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 Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 152 | |
Stefan Reinauer | 5a1f597 | 2010-03-31 14:34:40 +0000 | [diff] [blame] | 153 | #else |
Stefan Reinauer | 0c781b2 | 2010-04-01 09:50:32 +0000 | [diff] [blame] | 154 | |
Stefan Reinauer | 3817494 | 2010-12-17 01:51:34 +0000 | [diff] [blame] | 155 | /* __ROMCC__ */ |
| 156 | |
Stefan Reinauer | 5a1f597 | 2010-03-31 14:34:40 +0000 | [diff] [blame] | 157 | #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 Reinauer | 5a1f597 | 2010-03-31 14:34:40 +0000 | [diff] [blame] | 206 | |
Stefan Reinauer | bbd2f21 | 2011-04-20 21:11:22 +0000 | [diff] [blame] | 207 | #include "arch/x86/lib/romcc_console.c" |
| 208 | |
| 209 | #endif /* __ROMCC__ */ |
Patrick Georgi | 12584e2 | 2010-05-08 09:14:51 +0000 | [diff] [blame] | 210 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 211 | #endif /* CONSOLE_CONSOLE_H_ */ |