blob: 3b89326c7fb6084639e1c4b68034b5490e75cca9 [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>
Raul E Rangel80a7f4e2022-01-11 12:54:36 -07004#include <console/cbmem_console.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
Arthur Heymansa2bc2542021-05-29 08:10:49 +020012#define FIRST_CONSOLE (ENV_BOOTBLOCK || (CONFIG(NO_BOOTBLOCK_CONSOLE) && ENV_SEPARATE_ROMSTAGE))
Aaron Durbin40039502017-04-24 16:03:57 -050013
Arthur Heymans48ae50c2019-11-20 22:07:40 +010014static int console_inited;
Nico Huber308c1b72020-09-27 13:57:04 +020015static int console_loglevel;
Aaron Durbin40039502017-04-24 16:03:57 -050016
Subrata Banik62731302022-01-01 20:37:19 +000017int get_log_level(void)
Aaron Durbin40039502017-04-24 16:03:57 -050018{
Arthur Heymans48ae50c2019-11-20 22:07:40 +010019 if (console_inited == 0)
Aaron Durbin60320182018-02-28 12:38:05 -070020 return -1;
Aaron Durbin40039502017-04-24 16:03:57 -050021
22 return console_loglevel;
23}
24
Aaron Durbin40039502017-04-24 16:03:57 -050025static void init_log_level(void)
26{
Nico Huber308c1b72020-09-27 13:57:04 +020027 console_loglevel = get_console_loglevel();
Aaron Durbin40039502017-04-24 16:03:57 -050028
Nico Huber308c1b72020-09-27 13:57:04 +020029 if (!FIRST_CONSOLE)
Angel Pons88dcb312021-04-26 17:10:28 +020030 console_loglevel = get_uint_option("debug_level", console_loglevel);
Aaron Durbin40039502017-04-24 16:03:57 -050031}
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020032
33int console_log_level(int msg_level)
34{
Kyösti Mälkkie613d702019-02-12 14:16:21 +020035 int log_level = get_log_level();
36
37 if (log_level < 0)
38 return CONSOLE_LOG_NONE;
39
40 if (msg_level <= log_level)
41 return CONSOLE_LOG_ALL;
42
Julius Wernercd49cce2019-03-05 16:53:33 -080043 if (CONFIG(CONSOLE_CBMEM) && (msg_level <= BIOS_DEBUG))
Kyösti Mälkkie613d702019-02-12 14:16:21 +020044 return CONSOLE_LOG_FAST;
45
46 return 0;
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020047}
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020048
Raul E Rangele74b0b62021-09-10 16:29:23 -060049void console_init(void)
Kyösti Mälkki21333f92014-02-14 10:04:31 +020050{
Aaron Durbin40039502017-04-24 16:03:57 -050051 init_log_level();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020052
Julius Wernercd49cce2019-03-05 16:53:33 -080053 if (CONFIG(DEBUG_CONSOLE_INIT))
Arthur Heymans48ae50c2019-11-20 22:07:40 +010054 console_inited = 1;
Kyösti Mälkki66277952018-12-31 15:22:34 +020055
Arthur Heymansa2bc2542021-05-29 08:10:49 +020056 if (CONFIG(EARLY_PCI_BRIDGE) && (ENV_BOOTBLOCK || ENV_SEPARATE_ROMSTAGE))
Kyösti Mälkki3521e262018-12-26 19:33:28 +020057 pci_early_bridge_init();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020058
59 console_hw_init();
60
Arthur Heymans48ae50c2019-11-20 22:07:40 +010061 console_inited = 1;
Aaron Durbin60320182018-02-28 12:38:05 -070062
Raul E Rangel80a7f4e2022-01-11 12:54:36 -070063 if (ENV_BOOTBLOCK && CONFIG(CONSOLE_CBMEM_PRINT_PRE_BOOTBLOCK_CONTENTS))
64 cbmem_dump_console();
65
Patrick Rudolph5e5c1da2021-11-30 13:56:07 +010066 printk(BIOS_NOTICE, "\n\ncoreboot-%s%s %s " ENV_ARCH " " ENV_STRING " starting (log level: %i)...\n",
Elyes Haouasd0033e32022-05-29 15:34:41 +020067 coreboot_version, coreboot_extra_version, coreboot_build, get_log_level());
Kyösti Mälkki21333f92014-02-14 10:04:31 +020068}