1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #ifndef CONSOLE_CONSOLE_H_
4 #define CONSOLE_CONSOLE_H_
6 #include <commonlib/console/post_codes.h>
7 #include <console/vtxprintf.h>
10 /* console.h is supposed to provide the log levels defined in here: */
11 #include <commonlib/loglevel.h> /* IWYU pragma: export */
13 #define RAM_DEBUG (CONFIG(DEBUG_RAM_SETUP) ? BIOS_DEBUG : BIOS_NEVER)
14 #define RAM_SPEW (CONFIG(DEBUG_RAM_SETUP) ? BIOS_SPEW : BIOS_NEVER)
16 void post_code(u8 value
);
17 void mainboard_post(u8 value
);
18 void arch_post_code(u8 value
);
19 void soc_post_code(uint8_t value
);
21 void __noreturn
__printf(1, 2) die(const char *fmt
, ...);
22 #define die_with_post_code(value, fmt, ...) \
23 do { post_code(value); die(fmt, ##__VA_ARGS__); } while (0)
26 * This function is weak and can be overridden to provide additional
27 * feedback to the user. Possible use case: Play a beep.
29 void die_notify(void);
31 #if CONFIG(CONSOLE_OVERRIDE_LOGLEVEL)
33 * This function should be implemented at mainboard level.
34 * The returned value will _replace_ the loglevel value;
36 int get_console_loglevel(void);
38 static inline int get_console_loglevel(void)
40 return CONFIG_DEFAULT_CONSOLE_LOGLEVEL
;
44 #define __CONSOLE_ENABLE__ \
45 ((ENV_BOOTBLOCK && CONFIG(BOOTBLOCK_CONSOLE)) || \
46 (ENV_POSTCAR && CONFIG(POSTCAR_CONSOLE)) || \
47 ENV_SEPARATE_VERSTAGE || ENV_SEPARATE_ROMSTAGE || ENV_RAMSTAGE || \
48 ENV_LIBAGESA || (ENV_SMM && CONFIG(DEBUG_SMI)))
50 #if __CONSOLE_ENABLE__
51 int get_log_level(void);
52 void console_init(void);
53 int console_log_level(int msg_level
);
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
);
58 void do_putchar(unsigned char byte
);
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);
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.
71 enum { CONSOLE_LOG_NONE
= 0, CONSOLE_LOG_FAST
, CONSOLE_LOG_ALL
};
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) || \
75 CONFIG(CONSOLE_SYSTEM76_EC) || CONFIG(CONSOLE_AMD_SIMNOW) || \
76 CONFIG(CONSOLE_I2C_SMBUS))
79 static inline int get_log_level(void) { return -1; }
80 static inline void console_init(void) {}
81 static inline int console_log_level(int msg_level
) { return 0; }
83 __attribute__((format(printf
, 2, 3)))
84 printk(int LEVEL
, const char *fmt
, ...) { return 0; }
85 static inline int vprintk(int LEVEL
, const char *fmt
, va_list args
) { return 0; }
86 static inline void do_putchar(unsigned char byte
) {}
87 static inline long console_time_get_and_reset(void) { return 0; }
88 static inline void console_time_report(void) {}
91 #endif /* CONSOLE_CONSOLE_H_ */