blob: 7e9a439c0739e6bdce4852a53178e9aefbc145f4 [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer2a8ad412010-09-27 18:49:46 +00002
Eric Biederman8ca8d762003-04-22 19:02:15 +00003#ifndef CONSOLE_CONSOLE_H_
4#define CONSOLE_CONSOLE_H_
5
Ricardo Quesada470ca5712021-07-16 16:39:28 -07006#include <commonlib/console/post_codes.h>
Kyösti Mälkkice39ba92020-01-04 16:15:50 +02007#include <console/vtxprintf.h>
Ricardo Quesada470ca5712021-07-16 16:39:28 -07008#include <stdint.h>
Elyes HAOUASbe112362019-02-05 08:48:59 +01009
10/* console.h is supposed to provide the log levels defined in here: */
Elyes Haouas35c3ae3b2022-10-27 12:25:12 +020011#include <commonlib/loglevel.h> /* IWYU pragma: export */
Eric Biederman8ca8d762003-04-22 19:02:15 +000012
Julius Wernercd49cce2019-03-05 16:53:33 -080013#define RAM_DEBUG (CONFIG(DEBUG_RAM_SETUP) ? BIOS_DEBUG : BIOS_NEVER)
14#define RAM_SPEW (CONFIG(DEBUG_RAM_SETUP) ? BIOS_SPEW : BIOS_NEVER)
Nico Huber54235ca2017-04-17 00:53:10 +020015
Stefan Reinauer720297c2010-04-02 22:11:20 +000016void post_code(u8 value);
Alexandru Gagniucf88204e2012-08-03 13:20:57 -050017void mainboard_post(u8 value);
Kyösti Mälkkice39ba92020-01-04 16:15:50 +020018void arch_post_code(u8 value);
Martin Roth771806d2022-10-17 13:52:19 -060019void soc_post_code(uint8_t value);
Kyösti Mälkkice39ba92020-01-04 16:15:50 +020020
Nico Huber6a07db22023-05-12 15:46:24 +020021void __noreturn __printf(1, 2) die(const char *fmt, ...);
Jacob Garber913437e2019-05-31 12:53:54 -060022#define die_with_post_code(value, fmt, ...) \
23 do { post_code(value); die(fmt, ##__VA_ARGS__); } while (0)
Eric Biederman8ca8d762003-04-22 19:02:15 +000024
Patrick Rudolph4b7b18d2017-05-17 19:08:32 +020025/*
26 * This function is weak and can be overridden to provide additional
27 * feedback to the user. Possible use case: Play a beep.
28 */
29void die_notify(void);
30
Arthur Heymans3202c8a2021-01-28 18:35:12 +010031#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 */
36int get_console_loglevel(void);
37#else
38static inline int get_console_loglevel(void)
39{
40 return CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
41}
42#endif
43
Kyösti Mälkkif3390862014-02-26 15:19:04 +020044#define __CONSOLE_ENABLE__ \
Julius Wernercd49cce2019-03-05 16:53:33 -080045 ((ENV_BOOTBLOCK && CONFIG(BOOTBLOCK_CONSOLE)) || \
Julius Werner21a40532020-04-21 16:03:53 -070046 (ENV_POSTCAR && CONFIG(POSTCAR_CONSOLE)) || \
Arthur Heymansa2bc2542021-05-29 08:10:49 +020047 ENV_SEPARATE_VERSTAGE || ENV_SEPARATE_ROMSTAGE || ENV_RAMSTAGE || \
Julius Werner21a40532020-04-21 16:03:53 -070048 ENV_LIBAGESA || (ENV_SMM && CONFIG(DEBUG_SMI)))
Hung-Te Lin580fa2b2013-02-06 21:51:15 +080049
Kyösti Mälkkif3390862014-02-26 15:19:04 +020050#if __CONSOLE_ENABLE__
Subrata Banik62731302022-01-01 20:37:19 +000051int get_log_level(void);
Raul E Rangele74b0b62021-09-10 16:29:23 -060052void console_init(void);
Kyösti Mälkkif3390862014-02-26 15:19:04 +020053int console_log_level(int msg_level);
Nico Huber7cc14ac2021-03-27 20:03:02 +010054
55int printk(int msg_level, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
56int vprintk(int msg_level, const char *fmt, va_list args);
57
Kyösti Mälkki657e0be2014-02-04 19:03:57 +020058void do_putchar(unsigned char byte);
Hung-Te Lin580fa2b2013-02-06 21:51:15 +080059
Kyösti Mälkki45ddb432019-11-02 14:12:18 +020060/* Return number of microseconds elapsed from start of stage or the previous
61 get_and_reset() call. */
62long console_time_get_and_reset(void);
63void console_time_report(void);
64
Julius Werner266041f2022-02-03 17:25:44 -080065/*
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älkkie613d702019-02-12 14:16:21 +020071enum { CONSOLE_LOG_NONE = 0, CONSOLE_LOG_FAST, CONSOLE_LOG_ALL };
Julius Werner266041f2022-02-03 17:25:44 -080072#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 Reitbergera02176d2023-02-01 16:00:54 -050075 CONFIG(CONSOLE_SYSTEM76_EC) || CONFIG(CONSOLE_AMD_SIMNOW))
Julius Werner266041f2022-02-03 17:25:44 -080076
Kyösti Mälkkif3390862014-02-26 15:19:04 +020077#else
Subrata Banik62731302022-01-01 20:37:19 +000078static inline int get_log_level(void) { return -1; }
Kyösti Mälkkif3390862014-02-26 15:19:04 +020079static inline void console_init(void) {}
80static inline int console_log_level(int msg_level) { return 0; }
Nico Huber7cc14ac2021-03-27 20:03:02 +010081static inline int
Nico Huber879ccaa2021-04-10 19:23:57 +020082 __attribute__((format(printf, 2, 3)))
Nico Huber7cc14ac2021-03-27 20:03:02 +010083 printk(int LEVEL, const char *fmt, ...) { return 0; }
84static inline int vprintk(int LEVEL, const char *fmt, va_list args) { return 0; }
Kyösti Mälkkif3390862014-02-26 15:19:04 +020085static inline void do_putchar(unsigned char byte) {}
Kyösti Mälkki45ddb432019-11-02 14:12:18 +020086static inline long console_time_get_and_reset(void) { return 0; }
87static inline void console_time_report(void) {}
Kyösti Mälkki657e0be2014-02-04 19:03:57 +020088#endif
Hung-Te Lin580fa2b2013-02-06 21:51:15 +080089
Eric Biederman8ca8d762003-04-22 19:02:15 +000090#endif /* CONSOLE_CONSOLE_H_ */