blob: a2ceb58018d198e57a39ad696ab0ef6d6fa03ed9 [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
Nico Huber308c1b72020-09-27 13:57:04 +020011#define FIRST_CONSOLE (ENV_BOOTBLOCK || (CONFIG(NO_BOOTBLOCK_CONSOLE) && ENV_ROMSTAGE))
Aaron Durbin40039502017-04-24 16:03:57 -050012
Arthur Heymans48ae50c2019-11-20 22:07:40 +010013static int console_inited;
Nico Huber308c1b72020-09-27 13:57:04 +020014static int console_loglevel;
Aaron Durbin40039502017-04-24 16:03:57 -050015
16static inline int get_log_level(void)
17{
Arthur Heymans48ae50c2019-11-20 22:07:40 +010018 if (console_inited == 0)
Aaron Durbin60320182018-02-28 12:38:05 -070019 return -1;
Aaron Durbin40039502017-04-24 16:03:57 -050020
21 return console_loglevel;
22}
23
Aaron Durbin40039502017-04-24 16:03:57 -050024static void init_log_level(void)
25{
Nico Huber308c1b72020-09-27 13:57:04 +020026 console_loglevel = get_console_loglevel();
Aaron Durbin40039502017-04-24 16:03:57 -050027
Nico Huber308c1b72020-09-27 13:57:04 +020028 if (!FIRST_CONSOLE)
Angel Pons88dcb312021-04-26 17:10:28 +020029 console_loglevel = get_uint_option("debug_level", console_loglevel);
Aaron Durbin40039502017-04-24 16:03:57 -050030}
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020031
32int console_log_level(int msg_level)
33{
Kyösti Mälkkie613d702019-02-12 14:16:21 +020034 int log_level = get_log_level();
35
36 if (log_level < 0)
37 return CONSOLE_LOG_NONE;
38
39 if (msg_level <= log_level)
40 return CONSOLE_LOG_ALL;
41
Julius Wernercd49cce2019-03-05 16:53:33 -080042 if (CONFIG(CONSOLE_CBMEM) && (msg_level <= BIOS_DEBUG))
Kyösti Mälkkie613d702019-02-12 14:16:21 +020043 return CONSOLE_LOG_FAST;
44
45 return 0;
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020046}
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020047
Lee Leahy049b4622016-07-31 11:53:28 -070048asmlinkage void console_init(void)
Kyösti Mälkki21333f92014-02-14 10:04:31 +020049{
Aaron Durbin40039502017-04-24 16:03:57 -050050 init_log_level();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020051
Julius Wernercd49cce2019-03-05 16:53:33 -080052 if (CONFIG(DEBUG_CONSOLE_INIT))
Arthur Heymans48ae50c2019-11-20 22:07:40 +010053 console_inited = 1;
Kyösti Mälkki66277952018-12-31 15:22:34 +020054
Kyösti Mälkki5d0893a2020-06-09 11:46:32 +030055 if (CONFIG(EARLY_PCI_BRIDGE) && (ENV_BOOTBLOCK || ENV_ROMSTAGE))
Kyösti Mälkki3521e262018-12-26 19:33:28 +020056 pci_early_bridge_init();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020057
58 console_hw_init();
59
Arthur Heymans48ae50c2019-11-20 22:07:40 +010060 console_inited = 1;
Aaron Durbin60320182018-02-28 12:38:05 -070061
Paul Menzel5e442522019-01-08 00:17:44 +010062 printk(BIOS_NOTICE, "\n\ncoreboot-%s%s %s " ENV_STRING " starting (log level: %i)...\n",
63 coreboot_version, coreboot_extra_version, coreboot_build,
64 get_log_level());
Kyösti Mälkki21333f92014-02-14 10:04:31 +020065}