blob: d4818580e4086ca2c7e26511165398aeb775f9d2 [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
Aaron Durbin60320182018-02-28 12:38:05 -070015#include <arch/early_variables.h>
Kyösti Mälkkie613d702019-02-12 14:16:21 +020016#include <commonlib/helpers.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +020017#include <console/console.h>
18#include <console/uart.h>
Kyösti Mälkki40760722014-02-27 19:30:18 +020019#include <console/streams.h>
Kyösti Mälkkif9cdb482014-11-18 13:21:50 +020020#include <device/pci.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +020021#include <option.h>
Kyösti Mälkkic36af7b2014-11-18 12:41:16 +020022#include <version.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +020023
Aaron Durbin40039502017-04-24 16:03:57 -050024/* Mutable console log level only allowed when RAM comes online. */
Kyösti Mälkkie3acc8f2019-09-13 10:49:20 +030025#define CONSOLE_LEVEL_CONST !ENV_STAGE_HAS_DATA_SECTION
Aaron Durbin40039502017-04-24 16:03:57 -050026
Aaron Durbin60320182018-02-28 12:38:05 -070027static int console_inited CAR_GLOBAL;
Aaron Durbin40039502017-04-24 16:03:57 -050028static int console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
29
30static inline int get_log_level(void)
31{
Kyösti Mälkki513a1a82018-06-03 12:29:50 +030032 if (car_get_var(console_inited) == 0)
Aaron Durbin60320182018-02-28 12:38:05 -070033 return -1;
Kyösti Mälkkic8bc9832017-09-24 12:32:24 +030034 if (CONSOLE_LEVEL_CONST)
Julien Viard de Galbert4ecd42f2018-02-20 15:01:27 +010035 return get_console_loglevel();
Aaron Durbin40039502017-04-24 16:03:57 -050036
37 return console_loglevel;
38}
39
40static inline void set_log_level(int new_level)
41{
42 if (CONSOLE_LEVEL_CONST)
43 return;
44
45 console_loglevel = new_level;
46}
47
48static void init_log_level(void)
49{
Julien Viard de Galbert4ecd42f2018-02-20 15:01:27 +010050 int debug_level = get_console_loglevel();
Aaron Durbin40039502017-04-24 16:03:57 -050051
Kyösti Mälkkic8bc9832017-09-24 12:32:24 +030052 if (CONSOLE_LEVEL_CONST)
53 return;
54
Aaron Durbin40039502017-04-24 16:03:57 -050055 get_option(&debug_level, "debug_level");
56
57 set_log_level(debug_level);
58}
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020059
60int console_log_level(int msg_level)
61{
Kyösti Mälkkie613d702019-02-12 14:16:21 +020062 int log_level = get_log_level();
63
64 if (log_level < 0)
65 return CONSOLE_LOG_NONE;
66
67 if (msg_level <= log_level)
68 return CONSOLE_LOG_ALL;
69
Julius Wernercd49cce2019-03-05 16:53:33 -080070 if (CONFIG(CONSOLE_CBMEM) && (msg_level <= BIOS_DEBUG))
Kyösti Mälkkie613d702019-02-12 14:16:21 +020071 return CONSOLE_LOG_FAST;
72
73 return 0;
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020074}
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020075
Lee Leahy049b4622016-07-31 11:53:28 -070076asmlinkage void console_init(void)
Kyösti Mälkki21333f92014-02-14 10:04:31 +020077{
Aaron Durbin40039502017-04-24 16:03:57 -050078 init_log_level();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020079
Julius Wernercd49cce2019-03-05 16:53:33 -080080 if (CONFIG(DEBUG_CONSOLE_INIT))
Kyösti Mälkki66277952018-12-31 15:22:34 +020081 car_set_var(console_inited, 1);
82
Julius Wernercd49cce2019-03-05 16:53:33 -080083 if (CONFIG(EARLY_PCI_BRIDGE) && !ENV_SMM && !ENV_RAMSTAGE)
Kyösti Mälkki3521e262018-12-26 19:33:28 +020084 pci_early_bridge_init();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020085
86 console_hw_init();
87
Kyösti Mälkki513a1a82018-06-03 12:29:50 +030088 car_set_var(console_inited, 1);
Aaron Durbin60320182018-02-28 12:38:05 -070089
Paul Menzel5e442522019-01-08 00:17:44 +010090 printk(BIOS_NOTICE, "\n\ncoreboot-%s%s %s " ENV_STRING " starting (log level: %i)...\n",
91 coreboot_version, coreboot_extra_version, coreboot_build,
92 get_log_level());
Kyösti Mälkki21333f92014-02-14 10:04:31 +020093}