Angel Pons | b706ab3 | 2020-04-02 23:48:09 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 3 | |
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 4 | #include <commonlib/helpers.h> |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <console/uart.h> |
Kyösti Mälkki | 4076072 | 2014-02-27 19:30:18 +0200 | [diff] [blame] | 7 | #include <console/streams.h> |
Kyösti Mälkki | f9cdb48 | 2014-11-18 13:21:50 +0200 | [diff] [blame] | 8 | #include <device/pci.h> |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 9 | #include <option.h> |
Kyösti Mälkki | c36af7b | 2014-11-18 12:41:16 +0200 | [diff] [blame] | 10 | #include <version.h> |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 11 | |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 12 | /* Mutable console log level only allowed when RAM comes online. */ |
Kyösti Mälkki | e3acc8f | 2019-09-13 10:49:20 +0300 | [diff] [blame] | 13 | #define CONSOLE_LEVEL_CONST !ENV_STAGE_HAS_DATA_SECTION |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 14 | |
Arthur Heymans | 48ae50c | 2019-11-20 22:07:40 +0100 | [diff] [blame] | 15 | static int console_inited; |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 16 | static int console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL; |
| 17 | |
| 18 | static inline int get_log_level(void) |
| 19 | { |
Arthur Heymans | 48ae50c | 2019-11-20 22:07:40 +0100 | [diff] [blame] | 20 | if (console_inited == 0) |
Aaron Durbin | 6032018 | 2018-02-28 12:38:05 -0700 | [diff] [blame] | 21 | return -1; |
Kyösti Mälkki | c8bc983 | 2017-09-24 12:32:24 +0300 | [diff] [blame] | 22 | if (CONSOLE_LEVEL_CONST) |
Julien Viard de Galbert | 4ecd42f | 2018-02-20 15:01:27 +0100 | [diff] [blame] | 23 | return get_console_loglevel(); |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 24 | |
| 25 | return console_loglevel; |
| 26 | } |
| 27 | |
| 28 | static inline void set_log_level(int new_level) |
| 29 | { |
| 30 | if (CONSOLE_LEVEL_CONST) |
| 31 | return; |
| 32 | |
| 33 | console_loglevel = new_level; |
| 34 | } |
| 35 | |
| 36 | static void init_log_level(void) |
| 37 | { |
Julien Viard de Galbert | 4ecd42f | 2018-02-20 15:01:27 +0100 | [diff] [blame] | 38 | int debug_level = get_console_loglevel(); |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 39 | |
Kyösti Mälkki | c8bc983 | 2017-09-24 12:32:24 +0300 | [diff] [blame] | 40 | if (CONSOLE_LEVEL_CONST) |
| 41 | return; |
| 42 | |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 43 | get_option(&debug_level, "debug_level"); |
| 44 | |
| 45 | set_log_level(debug_level); |
| 46 | } |
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 47 | |
| 48 | int console_log_level(int msg_level) |
| 49 | { |
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 50 | 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 Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 58 | if (CONFIG(CONSOLE_CBMEM) && (msg_level <= BIOS_DEBUG)) |
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 59 | return CONSOLE_LOG_FAST; |
| 60 | |
| 61 | return 0; |
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 62 | } |
Kyösti Mälkki | b2d2596 | 2014-01-27 15:09:13 +0200 | [diff] [blame] | 63 | |
Lee Leahy | 049b462 | 2016-07-31 11:53:28 -0700 | [diff] [blame] | 64 | asmlinkage void console_init(void) |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 65 | { |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 66 | init_log_level(); |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 67 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 68 | if (CONFIG(DEBUG_CONSOLE_INIT)) |
Arthur Heymans | 48ae50c | 2019-11-20 22:07:40 +0100 | [diff] [blame] | 69 | console_inited = 1; |
Kyösti Mälkki | 6627795 | 2018-12-31 15:22:34 +0200 | [diff] [blame] | 70 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 71 | if (CONFIG(EARLY_PCI_BRIDGE) && !ENV_SMM && !ENV_RAMSTAGE) |
Kyösti Mälkki | 3521e26 | 2018-12-26 19:33:28 +0200 | [diff] [blame] | 72 | pci_early_bridge_init(); |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 73 | |
| 74 | console_hw_init(); |
| 75 | |
Arthur Heymans | 48ae50c | 2019-11-20 22:07:40 +0100 | [diff] [blame] | 76 | console_inited = 1; |
Aaron Durbin | 6032018 | 2018-02-28 12:38:05 -0700 | [diff] [blame] | 77 | |
Paul Menzel | 5e44252 | 2019-01-08 00:17:44 +0100 | [diff] [blame] | 78 | 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älkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 81 | } |