Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 2a8ad41 | 2010-09-27 18:49:46 +0000 | [diff] [blame] | 2 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 3 | #ifndef CONSOLE_CONSOLE_H_ |
| 4 | #define CONSOLE_CONSOLE_H_ |
| 5 | |
Ricardo Quesada | 470ca571 | 2021-07-16 16:39:28 -0700 | [diff] [blame] | 6 | #include <commonlib/console/post_codes.h> |
Kyösti Mälkki | ce39ba9 | 2020-01-04 16:15:50 +0200 | [diff] [blame] | 7 | #include <console/vtxprintf.h> |
Ricardo Quesada | 470ca571 | 2021-07-16 16:39:28 -0700 | [diff] [blame] | 8 | #include <stdint.h> |
Elyes HAOUAS | be11236 | 2019-02-05 08:48:59 +0100 | [diff] [blame] | 9 | |
| 10 | /* console.h is supposed to provide the log levels defined in here: */ |
Elyes Haouas | 35c3ae3b | 2022-10-27 12:25:12 +0200 | [diff] [blame] | 11 | #include <commonlib/loglevel.h> /* IWYU pragma: export */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 12 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 13 | #define RAM_DEBUG (CONFIG(DEBUG_RAM_SETUP) ? BIOS_DEBUG : BIOS_NEVER) |
| 14 | #define RAM_SPEW (CONFIG(DEBUG_RAM_SETUP) ? BIOS_SPEW : BIOS_NEVER) |
Nico Huber | 54235ca | 2017-04-17 00:53:10 +0200 | [diff] [blame] | 15 | |
Stefan Reinauer | 720297c | 2010-04-02 22:11:20 +0000 | [diff] [blame] | 16 | void post_code(u8 value); |
Alexandru Gagniuc | f88204e | 2012-08-03 13:20:57 -0500 | [diff] [blame] | 17 | void mainboard_post(u8 value); |
Kyösti Mälkki | ce39ba9 | 2020-01-04 16:15:50 +0200 | [diff] [blame] | 18 | void arch_post_code(u8 value); |
Martin Roth | 771806d | 2022-10-17 13:52:19 -0600 | [diff] [blame] | 19 | void soc_post_code(uint8_t value); |
Kyösti Mälkki | ce39ba9 | 2020-01-04 16:15:50 +0200 | [diff] [blame] | 20 | |
Nico Huber | 6a07db2 | 2023-05-12 15:46:24 +0200 | [diff] [blame^] | 21 | void __noreturn __printf(1, 2) die(const char *fmt, ...); |
Jacob Garber | 913437e | 2019-05-31 12:53:54 -0600 | [diff] [blame] | 22 | #define die_with_post_code(value, fmt, ...) \ |
| 23 | do { post_code(value); die(fmt, ##__VA_ARGS__); } while (0) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 24 | |
Patrick Rudolph | 4b7b18d | 2017-05-17 19:08:32 +0200 | [diff] [blame] | 25 | /* |
| 26 | * This function is weak and can be overridden to provide additional |
| 27 | * feedback to the user. Possible use case: Play a beep. |
| 28 | */ |
| 29 | void die_notify(void); |
| 30 | |
Arthur Heymans | 3202c8a | 2021-01-28 18:35:12 +0100 | [diff] [blame] | 31 | #if CONFIG(CONSOLE_OVERRIDE_LOGLEVEL) |
| 32 | /* |
| 33 | * This function should be implemented at mainboard level. |
| 34 | * The returned value will _replace_ the loglevel value; |
| 35 | */ |
| 36 | int get_console_loglevel(void); |
| 37 | #else |
| 38 | static inline int get_console_loglevel(void) |
| 39 | { |
| 40 | return CONFIG_DEFAULT_CONSOLE_LOGLEVEL; |
| 41 | } |
| 42 | #endif |
| 43 | |
Kyösti Mälkki | f339086 | 2014-02-26 15:19:04 +0200 | [diff] [blame] | 44 | #define __CONSOLE_ENABLE__ \ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 45 | ((ENV_BOOTBLOCK && CONFIG(BOOTBLOCK_CONSOLE)) || \ |
Julius Werner | 21a4053 | 2020-04-21 16:03:53 -0700 | [diff] [blame] | 46 | (ENV_POSTCAR && CONFIG(POSTCAR_CONSOLE)) || \ |
| 47 | ENV_SEPARATE_VERSTAGE || ENV_ROMSTAGE || ENV_RAMSTAGE || \ |
| 48 | ENV_LIBAGESA || (ENV_SMM && CONFIG(DEBUG_SMI))) |
Hung-Te Lin | 580fa2b | 2013-02-06 21:51:15 +0800 | [diff] [blame] | 49 | |
Kyösti Mälkki | f339086 | 2014-02-26 15:19:04 +0200 | [diff] [blame] | 50 | #if __CONSOLE_ENABLE__ |
Subrata Banik | 6273130 | 2022-01-01 20:37:19 +0000 | [diff] [blame] | 51 | int get_log_level(void); |
Raul E Rangel | e74b0b6 | 2021-09-10 16:29:23 -0600 | [diff] [blame] | 52 | void console_init(void); |
Kyösti Mälkki | f339086 | 2014-02-26 15:19:04 +0200 | [diff] [blame] | 53 | int console_log_level(int msg_level); |
Nico Huber | 7cc14ac | 2021-03-27 20:03:02 +0100 | [diff] [blame] | 54 | |
| 55 | int printk(int msg_level, const char *fmt, ...) __attribute__((format(printf, 2, 3))); |
| 56 | int vprintk(int msg_level, const char *fmt, va_list args); |
| 57 | |
Kyösti Mälkki | 657e0be | 2014-02-04 19:03:57 +0200 | [diff] [blame] | 58 | void do_putchar(unsigned char byte); |
Hung-Te Lin | 580fa2b | 2013-02-06 21:51:15 +0800 | [diff] [blame] | 59 | |
Kyösti Mälkki | 45ddb43 | 2019-11-02 14:12:18 +0200 | [diff] [blame] | 60 | /* Return number of microseconds elapsed from start of stage or the previous |
| 61 | get_and_reset() call. */ |
| 62 | long console_time_get_and_reset(void); |
| 63 | void console_time_report(void); |
| 64 | |
Julius Werner | 266041f | 2022-02-03 17:25:44 -0800 | [diff] [blame] | 65 | /* |
| 66 | * "Fast" basically means only the CBMEM console right now. This is used to still |
| 67 | * print debug messages there when loglevel disables the other consoles. It is also |
| 68 | * used to compile-time eliminate code paths that only affect "interactive" consoles |
| 69 | * (which are all "slow") when none of those are enabled. |
| 70 | */ |
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 71 | enum { CONSOLE_LOG_NONE = 0, CONSOLE_LOG_FAST, CONSOLE_LOG_ALL }; |
Julius Werner | 266041f | 2022-02-03 17:25:44 -0800 | [diff] [blame] | 72 | #define HAS_ONLY_FAST_CONSOLES !(CONFIG(SPKMODEM) || CONFIG(CONSOLE_QEMU_DEBUGCON) || \ |
| 73 | CONFIG(CONSOLE_SERIAL) || CONFIG(CONSOLE_NE2K) || CONFIG(CONSOLE_USB) || \ |
| 74 | CONFIG(EM100PRO_SPI_CONSOLE) || CONFIG(CONSOLE_SPI_FLASH) || \ |
Fred Reitberger | a02176d | 2023-02-01 16:00:54 -0500 | [diff] [blame] | 75 | CONFIG(CONSOLE_SYSTEM76_EC) || CONFIG(CONSOLE_AMD_SIMNOW)) |
Julius Werner | 266041f | 2022-02-03 17:25:44 -0800 | [diff] [blame] | 76 | |
Kyösti Mälkki | f339086 | 2014-02-26 15:19:04 +0200 | [diff] [blame] | 77 | #else |
Subrata Banik | 6273130 | 2022-01-01 20:37:19 +0000 | [diff] [blame] | 78 | static inline int get_log_level(void) { return -1; } |
Kyösti Mälkki | f339086 | 2014-02-26 15:19:04 +0200 | [diff] [blame] | 79 | static inline void console_init(void) {} |
| 80 | static inline int console_log_level(int msg_level) { return 0; } |
Nico Huber | 7cc14ac | 2021-03-27 20:03:02 +0100 | [diff] [blame] | 81 | static inline int |
Nico Huber | 879ccaa | 2021-04-10 19:23:57 +0200 | [diff] [blame] | 82 | __attribute__((format(printf, 2, 3))) |
Nico Huber | 7cc14ac | 2021-03-27 20:03:02 +0100 | [diff] [blame] | 83 | printk(int LEVEL, const char *fmt, ...) { return 0; } |
| 84 | static inline int vprintk(int LEVEL, const char *fmt, va_list args) { return 0; } |
Kyösti Mälkki | f339086 | 2014-02-26 15:19:04 +0200 | [diff] [blame] | 85 | static inline void do_putchar(unsigned char byte) {} |
Kyösti Mälkki | 45ddb43 | 2019-11-02 14:12:18 +0200 | [diff] [blame] | 86 | static inline long console_time_get_and_reset(void) { return 0; } |
| 87 | static inline void console_time_report(void) {} |
Kyösti Mälkki | 657e0be | 2014-02-04 19:03:57 +0200 | [diff] [blame] | 88 | #endif |
Hung-Te Lin | 580fa2b | 2013-02-06 21:51:15 +0800 | [diff] [blame] | 89 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 90 | #endif /* CONSOLE_CONSOLE_H_ */ |