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