blob: 8f71b098817eac68aad383e874d973f868e93e1d [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{
Aaron Durbin60320182018-02-28 12:38:05 -070038 if (car_get_var(console_inited) == 0)
39 return -1;
Kyösti Mälkkic8bc9832017-09-24 12:32:24 +030040 if (CONSOLE_LEVEL_CONST)
Julien Viard de Galbert4ecd42f2018-02-20 15:01:27 +010041 return get_console_loglevel();
Aaron Durbin40039502017-04-24 16:03:57 -050042
43 return console_loglevel;
44}
45
46static inline void set_log_level(int new_level)
47{
48 if (CONSOLE_LEVEL_CONST)
49 return;
50
51 console_loglevel = new_level;
52}
53
54static void init_log_level(void)
55{
Julien Viard de Galbert4ecd42f2018-02-20 15:01:27 +010056 int debug_level = get_console_loglevel();
Aaron Durbin40039502017-04-24 16:03:57 -050057
Kyösti Mälkkic8bc9832017-09-24 12:32:24 +030058 if (CONSOLE_LEVEL_CONST)
59 return;
60
Aaron Durbin40039502017-04-24 16:03:57 -050061 get_option(&debug_level, "debug_level");
62
63 set_log_level(debug_level);
64}
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020065
66int console_log_level(int msg_level)
67{
Aaron Durbin40039502017-04-24 16:03:57 -050068 return (get_log_level() >= msg_level);
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020069}
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020070
Lee Leahy049b4622016-07-31 11:53:28 -070071asmlinkage void console_init(void)
Kyösti Mälkki21333f92014-02-14 10:04:31 +020072{
Aaron Durbin40039502017-04-24 16:03:57 -050073 init_log_level();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020074
Martin Roth53de6cd2017-06-09 09:27:08 -060075#if IS_ENABLED(CONFIG_EARLY_PCI_BRIDGE) && !defined(__SMM__)
Kyösti Mälkki21333f92014-02-14 10:04:31 +020076 pci_early_bridge_init();
77#endif
78
79 console_hw_init();
80
Aaron Durbin60320182018-02-28 12:38:05 -070081 car_set_var(console_inited, 1);
82
Julius Wernerd906bb62017-05-16 13:54:18 -070083 printk(BIOS_NOTICE, "\n\ncoreboot-%s%s %s " ENV_STRING " starting...\n",
Ben Gardneraa5f5b12015-11-19 10:48:47 -060084 coreboot_version, coreboot_extra_version, coreboot_build);
Kyösti Mälkki21333f92014-02-14 10:04:31 +020085}