blob: 1dba9ad6642e901f00199c9a3001e72aa2aecadd [file] [log] [blame]
Angel Ponsb706ab32020-04-02 23:48:09 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Kyösti Mälkki21333f92014-02-14 10:04:31 +02002
Kyösti Mälkkie613d702019-02-12 14:16:21 +02003#include <commonlib/helpers.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +02004#include <console/console.h>
5#include <console/uart.h>
Kyösti Mälkki40760722014-02-27 19:30:18 +02006#include <console/streams.h>
Kyösti Mälkkif9cdb482014-11-18 13:21:50 +02007#include <device/pci.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +02008#include <option.h>
Kyösti Mälkkic36af7b2014-11-18 12:41:16 +02009#include <version.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +020010
Aaron Durbin40039502017-04-24 16:03:57 -050011/* Mutable console log level only allowed when RAM comes online. */
Kyösti Mälkkie3acc8f2019-09-13 10:49:20 +030012#define CONSOLE_LEVEL_CONST !ENV_STAGE_HAS_DATA_SECTION
Aaron Durbin40039502017-04-24 16:03:57 -050013
Arthur Heymans48ae50c2019-11-20 22:07:40 +010014static int console_inited;
Aaron Durbin40039502017-04-24 16:03:57 -050015static int console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
16
17static inline int get_log_level(void)
18{
Arthur Heymans48ae50c2019-11-20 22:07:40 +010019 if (console_inited == 0)
Aaron Durbin60320182018-02-28 12:38:05 -070020 return -1;
Kyösti Mälkkic8bc9832017-09-24 12:32:24 +030021 if (CONSOLE_LEVEL_CONST)
Julien Viard de Galbert4ecd42f2018-02-20 15:01:27 +010022 return get_console_loglevel();
Aaron Durbin40039502017-04-24 16:03:57 -050023
24 return console_loglevel;
25}
26
27static inline void set_log_level(int new_level)
28{
29 if (CONSOLE_LEVEL_CONST)
30 return;
31
32 console_loglevel = new_level;
33}
34
35static void init_log_level(void)
36{
Julien Viard de Galbert4ecd42f2018-02-20 15:01:27 +010037 int debug_level = get_console_loglevel();
Aaron Durbin40039502017-04-24 16:03:57 -050038
Kyösti Mälkkic8bc9832017-09-24 12:32:24 +030039 if (CONSOLE_LEVEL_CONST)
40 return;
41
Aaron Durbin40039502017-04-24 16:03:57 -050042 get_option(&debug_level, "debug_level");
43
44 set_log_level(debug_level);
45}
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020046
47int console_log_level(int msg_level)
48{
Kyösti Mälkkie613d702019-02-12 14:16:21 +020049 int log_level = get_log_level();
50
51 if (log_level < 0)
52 return CONSOLE_LOG_NONE;
53
54 if (msg_level <= log_level)
55 return CONSOLE_LOG_ALL;
56
Julius Wernercd49cce2019-03-05 16:53:33 -080057 if (CONFIG(CONSOLE_CBMEM) && (msg_level <= BIOS_DEBUG))
Kyösti Mälkkie613d702019-02-12 14:16:21 +020058 return CONSOLE_LOG_FAST;
59
60 return 0;
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020061}
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020062
Lee Leahy049b4622016-07-31 11:53:28 -070063asmlinkage void console_init(void)
Kyösti Mälkki21333f92014-02-14 10:04:31 +020064{
Aaron Durbin40039502017-04-24 16:03:57 -050065 init_log_level();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020066
Julius Wernercd49cce2019-03-05 16:53:33 -080067 if (CONFIG(DEBUG_CONSOLE_INIT))
Arthur Heymans48ae50c2019-11-20 22:07:40 +010068 console_inited = 1;
Kyösti Mälkki66277952018-12-31 15:22:34 +020069
Kyösti Mälkki5d0893a2020-06-09 11:46:32 +030070 if (CONFIG(EARLY_PCI_BRIDGE) && (ENV_BOOTBLOCK || ENV_ROMSTAGE))
Kyösti Mälkki3521e262018-12-26 19:33:28 +020071 pci_early_bridge_init();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020072
73 console_hw_init();
74
Arthur Heymans48ae50c2019-11-20 22:07:40 +010075 console_inited = 1;
Aaron Durbin60320182018-02-28 12:38:05 -070076
Paul Menzel5e442522019-01-08 00:17:44 +010077 printk(BIOS_NOTICE, "\n\ncoreboot-%s%s %s " ENV_STRING " starting (log level: %i)...\n",
78 coreboot_version, coreboot_extra_version, coreboot_build,
79 get_log_level());
Kyösti Mälkki21333f92014-02-14 10:04:31 +020080}