blob: 89f908f0c6253c0536ffb04015e0ccb8d0953ca4 [file] [log] [blame]
Kyösti Mälkki21333f92014-02-14 10:04:31 +02001/*
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älkki21333f92014-02-14 10:04:31 +020015 */
16
Aaron Durbin60320182018-02-28 12:38:05 -070017#include <arch/early_variables.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +020018#include <console/console.h>
19#include <console/uart.h>
Kyösti Mälkki40760722014-02-27 19:30:18 +020020#include <console/streams.h>
Kyösti Mälkkif9cdb482014-11-18 13:21:50 +020021#include <device/pci.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +020022#include <option.h>
Aaron Durbinaab13262015-05-13 13:32:11 -050023#include <rules.h>
Kyösti Mälkkic36af7b2014-11-18 12:41:16 +020024#include <version.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +020025
Aaron Durbin40039502017-04-24 16:03:57 -050026/* 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 Durbin60320182018-02-28 12:38:05 -070033static int console_inited CAR_GLOBAL;
Aaron Durbin40039502017-04-24 16:03:57 -050034static int console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
35
36static inline int get_log_level(void)
37{
Kyösti Mälkki64b29992018-05-31 07:03:29 +030038 if (!IS_ENABLED(CONFIG_LATE_CBMEM_INIT) &&
39 car_get_var(console_inited) == 0)
Aaron Durbin60320182018-02-28 12:38:05 -070040 return -1;
Kyösti Mälkkic8bc9832017-09-24 12:32:24 +030041 if (CONSOLE_LEVEL_CONST)
Julien Viard de Galbert4ecd42f2018-02-20 15:01:27 +010042 return get_console_loglevel();
Aaron Durbin40039502017-04-24 16:03:57 -050043
44 return console_loglevel;
45}
46
47static inline void set_log_level(int new_level)
48{
49 if (CONSOLE_LEVEL_CONST)
50 return;
51
52 console_loglevel = new_level;
53}
54
55static void init_log_level(void)
56{
Julien Viard de Galbert4ecd42f2018-02-20 15:01:27 +010057 int debug_level = get_console_loglevel();
Aaron Durbin40039502017-04-24 16:03:57 -050058
Kyösti Mälkkic8bc9832017-09-24 12:32:24 +030059 if (CONSOLE_LEVEL_CONST)
60 return;
61
Aaron Durbin40039502017-04-24 16:03:57 -050062 get_option(&debug_level, "debug_level");
63
64 set_log_level(debug_level);
65}
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020066
67int console_log_level(int msg_level)
68{
Aaron Durbin40039502017-04-24 16:03:57 -050069 return (get_log_level() >= msg_level);
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020070}
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020071
Lee Leahy049b4622016-07-31 11:53:28 -070072asmlinkage void console_init(void)
Kyösti Mälkki21333f92014-02-14 10:04:31 +020073{
Aaron Durbin40039502017-04-24 16:03:57 -050074 init_log_level();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020075
Martin Roth53de6cd2017-06-09 09:27:08 -060076#if IS_ENABLED(CONFIG_EARLY_PCI_BRIDGE) && !defined(__SMM__)
Kyösti Mälkki21333f92014-02-14 10:04:31 +020077 pci_early_bridge_init();
78#endif
79
80 console_hw_init();
81
Kyösti Mälkki64b29992018-05-31 07:03:29 +030082 if (!IS_ENABLED(CONFIG_LATE_CBMEM_INIT))
83 car_set_var(console_inited, 1);
Aaron Durbin60320182018-02-28 12:38:05 -070084
Julius Wernerd906bb62017-05-16 13:54:18 -070085 printk(BIOS_NOTICE, "\n\ncoreboot-%s%s %s " ENV_STRING " starting...\n",
Ben Gardneraa5f5b12015-11-19 10:48:47 -060086 coreboot_version, coreboot_extra_version, coreboot_build);
Kyösti Mälkki21333f92014-02-14 10:04:31 +020087}