blob: 911dbd054686cfbfff62f919d211b769a6c51cb9 [file] [log] [blame]
Kyösti Mälkki21333f92014-02-14 10:04:31 +02001/*
2 * This file is part of the coreboot project.
3 *
Kyösti Mälkki21333f92014-02-14 10:04:31 +02004 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; version 2 of
7 * the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Kyösti Mälkki21333f92014-02-14 10:04:31 +020013 */
14
Kyösti Mälkkie613d702019-02-12 14:16:21 +020015#include <commonlib/helpers.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +020016#include <console/console.h>
17#include <console/uart.h>
Kyösti Mälkki40760722014-02-27 19:30:18 +020018#include <console/streams.h>
Kyösti Mälkkif9cdb482014-11-18 13:21:50 +020019#include <device/pci.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +020020#include <option.h>
Kyösti Mälkkic36af7b2014-11-18 12:41:16 +020021#include <version.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +020022
Aaron Durbin40039502017-04-24 16:03:57 -050023/* Mutable console log level only allowed when RAM comes online. */
Kyösti Mälkkie3acc8f2019-09-13 10:49:20 +030024#define CONSOLE_LEVEL_CONST !ENV_STAGE_HAS_DATA_SECTION
Aaron Durbin40039502017-04-24 16:03:57 -050025
Arthur Heymans48ae50c2019-11-20 22:07:40 +010026static int console_inited;
Aaron Durbin40039502017-04-24 16:03:57 -050027static int console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
28
29static inline int get_log_level(void)
30{
Arthur Heymans48ae50c2019-11-20 22:07:40 +010031 if (console_inited == 0)
Aaron Durbin60320182018-02-28 12:38:05 -070032 return -1;
Kyösti Mälkkic8bc9832017-09-24 12:32:24 +030033 if (CONSOLE_LEVEL_CONST)
Julien Viard de Galbert4ecd42f2018-02-20 15:01:27 +010034 return get_console_loglevel();
Aaron Durbin40039502017-04-24 16:03:57 -050035
36 return console_loglevel;
37}
38
39static inline void set_log_level(int new_level)
40{
41 if (CONSOLE_LEVEL_CONST)
42 return;
43
44 console_loglevel = new_level;
45}
46
47static void init_log_level(void)
48{
Julien Viard de Galbert4ecd42f2018-02-20 15:01:27 +010049 int debug_level = get_console_loglevel();
Aaron Durbin40039502017-04-24 16:03:57 -050050
Kyösti Mälkkic8bc9832017-09-24 12:32:24 +030051 if (CONSOLE_LEVEL_CONST)
52 return;
53
Aaron Durbin40039502017-04-24 16:03:57 -050054 get_option(&debug_level, "debug_level");
55
56 set_log_level(debug_level);
57}
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020058
59int console_log_level(int msg_level)
60{
Kyösti Mälkkie613d702019-02-12 14:16:21 +020061 int log_level = get_log_level();
62
63 if (log_level < 0)
64 return CONSOLE_LOG_NONE;
65
66 if (msg_level <= log_level)
67 return CONSOLE_LOG_ALL;
68
Julius Wernercd49cce2019-03-05 16:53:33 -080069 if (CONFIG(CONSOLE_CBMEM) && (msg_level <= BIOS_DEBUG))
Kyösti Mälkkie613d702019-02-12 14:16:21 +020070 return CONSOLE_LOG_FAST;
71
72 return 0;
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020073}
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020074
Lee Leahy049b4622016-07-31 11:53:28 -070075asmlinkage void console_init(void)
Kyösti Mälkki21333f92014-02-14 10:04:31 +020076{
Aaron Durbin40039502017-04-24 16:03:57 -050077 init_log_level();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020078
Julius Wernercd49cce2019-03-05 16:53:33 -080079 if (CONFIG(DEBUG_CONSOLE_INIT))
Arthur Heymans48ae50c2019-11-20 22:07:40 +010080 console_inited = 1;
Kyösti Mälkki66277952018-12-31 15:22:34 +020081
Julius Wernercd49cce2019-03-05 16:53:33 -080082 if (CONFIG(EARLY_PCI_BRIDGE) && !ENV_SMM && !ENV_RAMSTAGE)
Kyösti Mälkki3521e262018-12-26 19:33:28 +020083 pci_early_bridge_init();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020084
85 console_hw_init();
86
Arthur Heymans48ae50c2019-11-20 22:07:40 +010087 console_inited = 1;
Aaron Durbin60320182018-02-28 12:38:05 -070088
Paul Menzel5e442522019-01-08 00:17:44 +010089 printk(BIOS_NOTICE, "\n\ncoreboot-%s%s %s " ENV_STRING " starting (log level: %i)...\n",
90 coreboot_version, coreboot_extra_version, coreboot_build,
91 get_log_level());
Kyösti Mälkki21333f92014-02-14 10:04:31 +020092}