Angel Pons | b706ab3 | 2020-04-02 23:48:09 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 2 | |
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 3 | #include <commonlib/helpers.h> |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 4 | #include <console/console.h> |
5 | #include <console/uart.h> | ||||
Kyösti Mälkki | 4076072 | 2014-02-27 19:30:18 +0200 | [diff] [blame] | 6 | #include <console/streams.h> |
Kyösti Mälkki | f9cdb48 | 2014-11-18 13:21:50 +0200 | [diff] [blame] | 7 | #include <device/pci.h> |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 8 | #include <option.h> |
Kyösti Mälkki | c36af7b | 2014-11-18 12:41:16 +0200 | [diff] [blame] | 9 | #include <version.h> |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 10 | |
Nico Huber | 308c1b7 | 2020-09-27 13:57:04 +0200 | [diff] [blame] | 11 | #define FIRST_CONSOLE (ENV_BOOTBLOCK || (CONFIG(NO_BOOTBLOCK_CONSOLE) && ENV_ROMSTAGE)) |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 12 | |
Arthur Heymans | 48ae50c | 2019-11-20 22:07:40 +0100 | [diff] [blame] | 13 | static int console_inited; |
Nico Huber | 308c1b7 | 2020-09-27 13:57:04 +0200 | [diff] [blame] | 14 | static int console_loglevel; |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 15 | |
16 | static inline int get_log_level(void) | ||||
17 | { | ||||
Arthur Heymans | 48ae50c | 2019-11-20 22:07:40 +0100 | [diff] [blame] | 18 | if (console_inited == 0) |
Aaron Durbin | 6032018 | 2018-02-28 12:38:05 -0700 | [diff] [blame] | 19 | return -1; |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 20 | |
21 | return console_loglevel; | ||||
22 | } | ||||
23 | |||||
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 24 | static void init_log_level(void) |
25 | { | ||||
Nico Huber | 308c1b7 | 2020-09-27 13:57:04 +0200 | [diff] [blame] | 26 | console_loglevel = get_console_loglevel(); |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 27 | |
Nico Huber | 308c1b7 | 2020-09-27 13:57:04 +0200 | [diff] [blame] | 28 | if (!FIRST_CONSOLE) |
29 | get_option(&console_loglevel, "debug_level"); | ||||
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 30 | } |
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 31 | |
32 | int console_log_level(int msg_level) | ||||
33 | { | ||||
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 34 | 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 Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 42 | if (CONFIG(CONSOLE_CBMEM) && (msg_level <= BIOS_DEBUG)) |
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 43 | return CONSOLE_LOG_FAST; |
44 | |||||
45 | return 0; | ||||
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 46 | } |
Kyösti Mälkki | b2d2596 | 2014-01-27 15:09:13 +0200 | [diff] [blame] | 47 | |
Lee Leahy | 049b462 | 2016-07-31 11:53:28 -0700 | [diff] [blame] | 48 | asmlinkage void console_init(void) |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 49 | { |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 50 | init_log_level(); |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 51 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 52 | if (CONFIG(DEBUG_CONSOLE_INIT)) |
Arthur Heymans | 48ae50c | 2019-11-20 22:07:40 +0100 | [diff] [blame] | 53 | console_inited = 1; |
Kyösti Mälkki | 6627795 | 2018-12-31 15:22:34 +0200 | [diff] [blame] | 54 | |
Kyösti Mälkki | 5d0893a | 2020-06-09 11:46:32 +0300 | [diff] [blame] | 55 | if (CONFIG(EARLY_PCI_BRIDGE) && (ENV_BOOTBLOCK || ENV_ROMSTAGE)) |
Kyösti Mälkki | 3521e26 | 2018-12-26 19:33:28 +0200 | [diff] [blame] | 56 | pci_early_bridge_init(); |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 57 | |
58 | console_hw_init(); | ||||
59 | |||||
Arthur Heymans | 48ae50c | 2019-11-20 22:07:40 +0100 | [diff] [blame] | 60 | console_inited = 1; |
Aaron Durbin | 6032018 | 2018-02-28 12:38:05 -0700 | [diff] [blame] | 61 | |
Paul Menzel | 5e44252 | 2019-01-08 00:17:44 +0100 | [diff] [blame] | 62 | 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älkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 65 | } |