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> |
Raul E Rangel | 80a7f4e | 2022-01-11 12:54:36 -0700 | [diff] [blame] | 4 | #include <console/cbmem_console.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 | |
Nico Huber | 308c1b7 | 2020-09-27 13:57:04 +0200 | [diff] [blame] | 12 | #define FIRST_CONSOLE (ENV_BOOTBLOCK || (CONFIG(NO_BOOTBLOCK_CONSOLE) && ENV_ROMSTAGE)) |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 13 | |
Arthur Heymans | 48ae50c | 2019-11-20 22:07:40 +0100 | [diff] [blame] | 14 | static int console_inited; |
Nico Huber | 308c1b7 | 2020-09-27 13:57:04 +0200 | [diff] [blame] | 15 | static int console_loglevel; |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 16 | |
Subrata Banik | 6273130 | 2022-01-01 20:37:19 +0000 | [diff] [blame] | 17 | int get_log_level(void) |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 18 | { |
Arthur Heymans | 48ae50c | 2019-11-20 22:07:40 +0100 | [diff] [blame] | 19 | if (console_inited == 0) |
Aaron Durbin | 6032018 | 2018-02-28 12:38:05 -0700 | [diff] [blame] | 20 | return -1; |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 21 | |
22 | return console_loglevel; | ||||
23 | } | ||||
24 | |||||
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 25 | static void init_log_level(void) |
26 | { | ||||
Nico Huber | 308c1b7 | 2020-09-27 13:57:04 +0200 | [diff] [blame] | 27 | console_loglevel = get_console_loglevel(); |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 28 | |
Nico Huber | 308c1b7 | 2020-09-27 13:57:04 +0200 | [diff] [blame] | 29 | if (!FIRST_CONSOLE) |
Angel Pons | 88dcb31 | 2021-04-26 17:10:28 +0200 | [diff] [blame] | 30 | console_loglevel = get_uint_option("debug_level", console_loglevel); |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 31 | } |
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 32 | |
33 | int console_log_level(int msg_level) | ||||
34 | { | ||||
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 35 | 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 Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 43 | if (CONFIG(CONSOLE_CBMEM) && (msg_level <= BIOS_DEBUG)) |
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 44 | return CONSOLE_LOG_FAST; |
45 | |||||
46 | return 0; | ||||
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 47 | } |
Kyösti Mälkki | b2d2596 | 2014-01-27 15:09:13 +0200 | [diff] [blame] | 48 | |
Raul E Rangel | e74b0b6 | 2021-09-10 16:29:23 -0600 | [diff] [blame] | 49 | void console_init(void) |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 50 | { |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 51 | init_log_level(); |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 52 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 53 | if (CONFIG(DEBUG_CONSOLE_INIT)) |
Arthur Heymans | 48ae50c | 2019-11-20 22:07:40 +0100 | [diff] [blame] | 54 | console_inited = 1; |
Kyösti Mälkki | 6627795 | 2018-12-31 15:22:34 +0200 | [diff] [blame] | 55 | |
Kyösti Mälkki | 5d0893a | 2020-06-09 11:46:32 +0300 | [diff] [blame] | 56 | if (CONFIG(EARLY_PCI_BRIDGE) && (ENV_BOOTBLOCK || ENV_ROMSTAGE)) |
Kyösti Mälkki | 3521e26 | 2018-12-26 19:33:28 +0200 | [diff] [blame] | 57 | pci_early_bridge_init(); |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 58 | |
59 | console_hw_init(); | ||||
60 | |||||
Arthur Heymans | 48ae50c | 2019-11-20 22:07:40 +0100 | [diff] [blame] | 61 | console_inited = 1; |
Aaron Durbin | 6032018 | 2018-02-28 12:38:05 -0700 | [diff] [blame] | 62 | |
Raul E Rangel | 80a7f4e | 2022-01-11 12:54:36 -0700 | [diff] [blame] | 63 | if (ENV_BOOTBLOCK && CONFIG(CONSOLE_CBMEM_PRINT_PRE_BOOTBLOCK_CONTENTS)) |
64 | cbmem_dump_console(); | ||||
65 | |||||
Paul Menzel | 5e44252 | 2019-01-08 00:17:44 +0100 | [diff] [blame] | 66 | printk(BIOS_NOTICE, "\n\ncoreboot-%s%s %s " ENV_STRING " starting (log level: %i)...\n", |
Elyes Haouas | d0033e3 | 2022-05-29 15:34:41 +0200 | [diff] [blame] | 67 | coreboot_version, coreboot_extra_version, coreboot_build, get_log_level()); |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 68 | } |