xref: /aosp_15_r20/external/coreboot/src/include/console/console.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef CONSOLE_CONSOLE_H_
4 #define CONSOLE_CONSOLE_H_
5 
6 #include <commonlib/console/post_codes.h>
7 #include <console/vtxprintf.h>
8 #include <stdint.h>
9 
10 /* console.h is supposed to provide the log levels defined in here: */
11 #include <commonlib/loglevel.h> /* IWYU pragma: export */
12 
13 #define RAM_DEBUG (CONFIG(DEBUG_RAM_SETUP) ? BIOS_DEBUG : BIOS_NEVER)
14 #define RAM_SPEW  (CONFIG(DEBUG_RAM_SETUP) ? BIOS_SPEW  : BIOS_NEVER)
15 
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);
20 
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)
24 
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 
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
get_console_loglevel(void)38 static inline int get_console_loglevel(void)
39 {
40 	return CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
41 }
42 #endif
43 
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)))
49 
50 #if __CONSOLE_ENABLE__
51 int get_log_level(void);
52 void console_init(void);
53 int console_log_level(int msg_level);
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 
58 void do_putchar(unsigned char byte);
59 
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 
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  */
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))
77 
78 #else
get_log_level(void)79 static inline int get_log_level(void) { return -1; }
console_init(void)80 static inline void console_init(void) {}
console_log_level(int msg_level)81 static inline int console_log_level(int msg_level) { return 0; }
82 static inline int
83 	__attribute__((format(printf, 2, 3)))
printk(int LEVEL,const char * fmt,...)84 	printk(int LEVEL, const char *fmt, ...) { return 0; }
vprintk(int LEVEL,const char * fmt,va_list args)85 static inline int vprintk(int LEVEL, const char *fmt, va_list args) { return 0; }
do_putchar(unsigned char byte)86 static inline void do_putchar(unsigned char byte) {}
console_time_get_and_reset(void)87 static inline long console_time_get_and_reset(void) { return 0; }
console_time_report(void)88 static inline void console_time_report(void) {}
89 #endif
90 
91 #endif /* CONSOLE_CONSOLE_H_ */
92