blob: c1565a420f9b60eae42c9ce742fc765daf924939 [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
Kyösti Mälkki21333f92014-02-14 10:04:31 +020017#include <console/console.h>
18#include <console/uart.h>
Kyösti Mälkki40760722014-02-27 19:30:18 +020019#include <console/streams.h>
Kyösti Mälkkif9cdb482014-11-18 13:21:50 +020020#include <device/pci.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +020021#include <option.h>
Aaron Durbinaab13262015-05-13 13:32:11 -050022#include <rules.h>
Kyösti Mälkkic36af7b2014-11-18 12:41:16 +020023#include <version.h>
Kyösti Mälkki21333f92014-02-14 10:04:31 +020024
Aaron Durbin40039502017-04-24 16:03:57 -050025/* Mutable console log level only allowed when RAM comes online. */
26#if defined(__PRE_RAM__)
27#define CONSOLE_LEVEL_CONST 1
28#else
29#define CONSOLE_LEVEL_CONST 0
30#endif
31
32static int console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
33
34static inline int get_log_level(void)
35{
Martin Roth53de6cd2017-06-09 09:27:08 -060036 if (IS_ENABLED(CONSOLE_LEVEL_CONST))
Aaron Durbin40039502017-04-24 16:03:57 -050037 return CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
38
39 return console_loglevel;
40}
41
42static inline void set_log_level(int new_level)
43{
44 if (CONSOLE_LEVEL_CONST)
45 return;
46
47 console_loglevel = new_level;
48}
49
50static void init_log_level(void)
51{
52 int debug_level = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
53
54 get_option(&debug_level, "debug_level");
55
56 set_log_level(debug_level);
57}
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020058
59int console_log_level(int msg_level)
60{
Aaron Durbin40039502017-04-24 16:03:57 -050061 return (get_log_level() >= msg_level);
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020062}
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020063
Lee Leahy049b4622016-07-31 11:53:28 -070064asmlinkage void console_init(void)
Kyösti Mälkki21333f92014-02-14 10:04:31 +020065{
Aaron Durbin40039502017-04-24 16:03:57 -050066 init_log_level();
Kyösti Mälkki21333f92014-02-14 10:04:31 +020067
Martin Roth53de6cd2017-06-09 09:27:08 -060068#if IS_ENABLED(CONFIG_EARLY_PCI_BRIDGE) && !defined(__SMM__)
Kyösti Mälkki21333f92014-02-14 10:04:31 +020069 pci_early_bridge_init();
70#endif
71
72 console_hw_init();
73
Julius Wernerd906bb62017-05-16 13:54:18 -070074 printk(BIOS_NOTICE, "\n\ncoreboot-%s%s %s " ENV_STRING " starting...\n",
Ben Gardneraa5f5b12015-11-19 10:48:47 -060075 coreboot_version, coreboot_extra_version, coreboot_build);
Kyösti Mälkki21333f92014-02-14 10:04:31 +020076}