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 | * |
| 4 | * Copyright (C) 2003 Eric Biederman |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
Aaron Durbin | 6032018 | 2018-02-28 12:38:05 -0700 | [diff] [blame] | 17 | #include <arch/early_variables.h> |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 18 | #include <console/console.h> |
| 19 | #include <console/uart.h> |
Kyösti Mälkki | 4076072 | 2014-02-27 19:30:18 +0200 | [diff] [blame] | 20 | #include <console/streams.h> |
Kyösti Mälkki | f9cdb48 | 2014-11-18 13:21:50 +0200 | [diff] [blame] | 21 | #include <device/pci.h> |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 22 | #include <option.h> |
Aaron Durbin | aab1326 | 2015-05-13 13:32:11 -0500 | [diff] [blame] | 23 | #include <rules.h> |
Kyösti Mälkki | c36af7b | 2014-11-18 12:41:16 +0200 | [diff] [blame] | 24 | #include <version.h> |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 25 | |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 26 | /* Mutable console log level only allowed when RAM comes online. */ |
| 27 | #if defined(__PRE_RAM__) |
| 28 | #define CONSOLE_LEVEL_CONST 1 |
| 29 | #else |
| 30 | #define CONSOLE_LEVEL_CONST 0 |
| 31 | #endif |
| 32 | |
Aaron Durbin | 6032018 | 2018-02-28 12:38:05 -0700 | [diff] [blame] | 33 | static int console_inited CAR_GLOBAL; |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 34 | static int console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL; |
| 35 | |
| 36 | static inline int get_log_level(void) |
| 37 | { |
Kyösti Mälkki | 64b2999 | 2018-05-31 07:03:29 +0300 | [diff] [blame] | 38 | if (!IS_ENABLED(CONFIG_LATE_CBMEM_INIT) && |
| 39 | car_get_var(console_inited) == 0) |
Aaron Durbin | 6032018 | 2018-02-28 12:38:05 -0700 | [diff] [blame] | 40 | return -1; |
Kyösti Mälkki | c8bc983 | 2017-09-24 12:32:24 +0300 | [diff] [blame] | 41 | if (CONSOLE_LEVEL_CONST) |
Julien Viard de Galbert | 4ecd42f | 2018-02-20 15:01:27 +0100 | [diff] [blame] | 42 | return get_console_loglevel(); |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 43 | |
| 44 | return console_loglevel; |
| 45 | } |
| 46 | |
| 47 | static inline void set_log_level(int new_level) |
| 48 | { |
| 49 | if (CONSOLE_LEVEL_CONST) |
| 50 | return; |
| 51 | |
| 52 | console_loglevel = new_level; |
| 53 | } |
| 54 | |
| 55 | static void init_log_level(void) |
| 56 | { |
Julien Viard de Galbert | 4ecd42f | 2018-02-20 15:01:27 +0100 | [diff] [blame] | 57 | int debug_level = get_console_loglevel(); |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 58 | |
Kyösti Mälkki | c8bc983 | 2017-09-24 12:32:24 +0300 | [diff] [blame] | 59 | if (CONSOLE_LEVEL_CONST) |
| 60 | return; |
| 61 | |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 62 | get_option(&debug_level, "debug_level"); |
| 63 | |
| 64 | set_log_level(debug_level); |
| 65 | } |
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 66 | |
| 67 | int console_log_level(int msg_level) |
| 68 | { |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 69 | return (get_log_level() >= msg_level); |
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 70 | } |
Kyösti Mälkki | b2d2596 | 2014-01-27 15:09:13 +0200 | [diff] [blame] | 71 | |
Lee Leahy | 049b462 | 2016-07-31 11:53:28 -0700 | [diff] [blame] | 72 | asmlinkage void console_init(void) |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 73 | { |
Aaron Durbin | 4003950 | 2017-04-24 16:03:57 -0500 | [diff] [blame] | 74 | init_log_level(); |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 75 | |
Martin Roth | 53de6cd | 2017-06-09 09:27:08 -0600 | [diff] [blame] | 76 | #if IS_ENABLED(CONFIG_EARLY_PCI_BRIDGE) && !defined(__SMM__) |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 77 | pci_early_bridge_init(); |
| 78 | #endif |
| 79 | |
| 80 | console_hw_init(); |
| 81 | |
Kyösti Mälkki | 64b2999 | 2018-05-31 07:03:29 +0300 | [diff] [blame] | 82 | if (!IS_ENABLED(CONFIG_LATE_CBMEM_INIT)) |
| 83 | car_set_var(console_inited, 1); |
Aaron Durbin | 6032018 | 2018-02-28 12:38:05 -0700 | [diff] [blame] | 84 | |
Julius Werner | d906bb6 | 2017-05-16 13:54:18 -0700 | [diff] [blame] | 85 | printk(BIOS_NOTICE, "\n\ncoreboot-%s%s %s " ENV_STRING " starting...\n", |
Ben Gardner | aa5f5b1 | 2015-11-19 10:48:47 -0600 | [diff] [blame] | 86 | coreboot_version, coreboot_extra_version, coreboot_build); |
Kyösti Mälkki | 21333f9 | 2014-02-14 10:04:31 +0200 | [diff] [blame] | 87 | } |