blob: 80bdb24c4b1b15bdbce3da6decab8b3b30746dde [file] [log] [blame]
Angel Ponsb706ab32020-04-02 23:48:09 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Kyösti Mälkki21333f92014-02-14 10:04:31 +02003
Kyösti Mälkkie613d702019-02-12 14:16:21 +02004#include <commonlib/helpers.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +02005#include <console/console.h>
6#include <console/uart.h>
Kyösti Mälkki40760722014-02-27 19:30:18 +02007#include <console/streams.h>
Kyösti Mälkkif9cdb482014-11-18 13:21:50 +02008#include <device/pci.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +02009#include <option.h>
Kyösti Mälkkic36af7b2014-11-18 12:41:16 +020010#include <version.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +020011
Aaron Durbin40039502017-04-24 16:03:57 -050012/* Mutable console log level only allowed when RAM comes online. */
Kyösti Mälkkie3acc8f2019-09-13 10:49:20 +030013#define CONSOLE_LEVEL_CONST !ENV_STAGE_HAS_DATA_SECTION
Aaron Durbin40039502017-04-24 16:03:57 -050014
Arthur Heymans48ae50c2019-11-20 22:07:40 +010015static int console_inited;
Aaron Durbin40039502017-04-24 16:03:57 -050016static int console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
17
18static inline int get_log_level(void)
19{
Arthur Heymans48ae50c2019-11-20 22:07:40 +010020 if (console_inited == 0)
Aaron Durbin60320182018-02-28 12:38:05 -070021 return -1;
Kyösti Mälkkic8bc9832017-09-24 12:32:24 +030022 if (CONSOLE_LEVEL_CONST)
Julien Viard de Galbert4ecd42f2018-02-20 15:01:27 +010023 return get_console_loglevel();
Aaron Durbin40039502017-04-24 16:03:57 -050024
25 return console_loglevel;
26}
27
28static inline void set_log_level(int new_level)
29{
30 if (CONSOLE_LEVEL_CONST)
31 return;
32
33 console_loglevel = new_level;
34}
35
36static void init_log_level(void)
37{
Julien Viard de Galbert4ecd42f2018-02-20 15:01:27 +010038 int debug_level = get_console_loglevel();
Aaron Durbin40039502017-04-24 16:03:57 -050039
Kyösti Mälkkic8bc9832017-09-24 12:32:24 +030040 if (CONSOLE_LEVEL_CONST)
41 return;
42
Aaron Durbin40039502017-04-24 16:03:57 -050043 get_option(&debug_level, "debug_level");
44
45 set_log_level(debug_level);
46}
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020047
48int console_log_level(int msg_level)
49{
Kyösti Mälkkie613d702019-02-12 14:16:21 +020050 int log_level = get_log_level();
51
52 if (log_level < 0)
53 return CONSOLE_LOG_NONE;
54
55 if (msg_level <= log_level)
56 return CONSOLE_LOG_ALL;
57
Julius Wernercd49cce2019-03-05 16:53:33 -080058 if (CONFIG(CONSOLE_CBMEM) && (msg_level <= BIOS_DEBUG))
Kyösti Mälkkie613d702019-02-12 14:16:21 +020059 return CONSOLE_LOG_FAST;
60
61 return 0;
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020062}
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020063
Lee Leahy049b4622016-07-31 11:53:28 -070064asmlinkage void console_init(void)
Kyösti Mälkki21333f92014-02-14 10:04:31 +020065{
Aaron Durbin40039502017-04-24 16:03:57 -050066 init_log_level();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020067
Julius Wernercd49cce2019-03-05 16:53:33 -080068 if (CONFIG(DEBUG_CONSOLE_INIT))
Arthur Heymans48ae50c2019-11-20 22:07:40 +010069 console_inited = 1;
Kyösti Mälkki66277952018-12-31 15:22:34 +020070
Julius Wernercd49cce2019-03-05 16:53:33 -080071 if (CONFIG(EARLY_PCI_BRIDGE) && !ENV_SMM && !ENV_RAMSTAGE)
Kyösti Mälkki3521e262018-12-26 19:33:28 +020072 pci_early_bridge_init();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020073
74 console_hw_init();
75
Arthur Heymans48ae50c2019-11-20 22:07:40 +010076 console_inited = 1;
Aaron Durbin60320182018-02-28 12:38:05 -070077
Paul Menzel5e442522019-01-08 00:17:44 +010078 printk(BIOS_NOTICE, "\n\ncoreboot-%s%s %s " ENV_STRING " starting (log level: %i)...\n",
79 coreboot_version, coreboot_extra_version, coreboot_build,
80 get_log_level());
Kyösti Mälkki21333f92014-02-14 10:04:31 +020081}