blob: 15c599dce01ee7165e2dcbc1520dd4f150b26a30 [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001/*
Damien Roth4e7e9872016-01-16 18:59:51 -07002 * This file is part of the coreboot project.
Eric Biederman8ca8d762003-04-22 19:02:15 +00003 *
Damien Roth4e7e9872016-01-16 18:59:51 -07004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * blatantly copied from linux/kernel/printk.c
Eric Biederman8ca8d762003-04-22 19:02:15 +000014 */
Eric Biederman8ca8d762003-04-22 19:02:15 +000015
Kyösti Mälkkie613d702019-02-12 14:16:21 +020016#include <console/cbmem_console.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000017#include <console/console.h>
Kyösti Mälkki40760722014-02-27 19:30:18 +020018#include <console/streams.h>
Edward O'Callaghan0ddb8262014-06-17 18:37:08 +100019#include <console/vtxprintf.h>
20#include <smp/spinlock.h>
21#include <smp/node.h>
22#include <stddef.h>
Rudolf Marek7f0e9302011-09-02 23:23:41 +020023#include <trace.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000024
Julius Wernercd49cce2019-03-05 16:53:33 -080025#if (!defined(__PRE_RAM__) && CONFIG(HAVE_ROMSTAGE_CONSOLE_SPINLOCK)) || !CONFIG(HAVE_ROMSTAGE_CONSOLE_SPINLOCK)
Myles Watson2e672732009-11-12 16:38:03 +000026DECLARE_SPIN_LOCK(console_lock)
Timothy Pearson44d53422015-05-18 16:04:10 -050027#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000028
Kyösti Mälkki657e0be2014-02-04 19:03:57 +020029void do_putchar(unsigned char byte)
30{
Kyösti Mälkki657e0be2014-02-04 19:03:57 +020031 console_tx_byte(byte);
32}
33
Kyösti Mälkki77f43e92014-02-04 19:50:07 +020034static void wrap_putchar(unsigned char byte, void *data)
Kyösti Mälkkib04e0ff2014-02-04 14:28:17 +020035{
Kyösti Mälkkie613d702019-02-12 14:16:21 +020036 console_tx_byte(byte);
37}
38
39static void wrap_putchar_cbmemc(unsigned char byte, void *data)
40{
41 __cbmemc_tx_byte(byte);
Kyösti Mälkkib04e0ff2014-02-04 14:28:17 +020042}
43
Jacob Garberdeb99af2019-06-03 15:19:47 -060044int do_vprintk(int msg_level, const char *fmt, va_list args)
Eric Biederman8ca8d762003-04-22 19:02:15 +000045{
Kyösti Mälkkie613d702019-02-12 14:16:21 +020046 int i, log_this;
Eric Biederman8ca8d762003-04-22 19:02:15 +000047
Kyösti Mälkki21160a72019-08-17 17:29:36 +030048 if (CONFIG(SQUELCH_EARLY_SMP) && ENV_ROMSTAGE_OR_BEFORE && !boot_cpu())
Eric Biederman8ca8d762003-04-22 19:02:15 +000049 return 0;
Eric Biederman8ca8d762003-04-22 19:02:15 +000050
Kyösti Mälkkie613d702019-02-12 14:16:21 +020051 log_this = console_log_level(msg_level);
52 if (log_this < CONSOLE_LOG_FAST)
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020053 return 0;
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020054
Rudolf Marek7f0e9302011-09-02 23:23:41 +020055 DISABLE_TRACE;
Timothy Pearson44d53422015-05-18 16:04:10 -050056#ifdef __PRE_RAM__
Julius Wernercd49cce2019-03-05 16:53:33 -080057#if CONFIG(HAVE_ROMSTAGE_CONSOLE_SPINLOCK)
Timothy Pearson44d53422015-05-18 16:04:10 -050058 spin_lock(romstage_console_lock());
59#endif
60#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000061 spin_lock(&console_lock);
Timothy Pearson44d53422015-05-18 16:04:10 -050062#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000063
Kyösti Mälkkie613d702019-02-12 14:16:21 +020064 if (log_this == CONSOLE_LOG_FAST) {
65 i = vtxprintf(wrap_putchar_cbmemc, fmt, args, NULL);
66 } else {
67 i = vtxprintf(wrap_putchar, fmt, args, NULL);
68 console_tx_flush();
69 }
Eric Biederman8ca8d762003-04-22 19:02:15 +000070
Timothy Pearson44d53422015-05-18 16:04:10 -050071#ifdef __PRE_RAM__
Julius Wernercd49cce2019-03-05 16:53:33 -080072#if CONFIG(HAVE_ROMSTAGE_CONSOLE_SPINLOCK)
Timothy Pearson44d53422015-05-18 16:04:10 -050073 spin_unlock(romstage_console_lock());
74#endif
75#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000076 spin_unlock(&console_lock);
Timothy Pearson44d53422015-05-18 16:04:10 -050077#endif
Rudolf Marek7f0e9302011-09-02 23:23:41 +020078 ENABLE_TRACE;
Eric Biederman8ca8d762003-04-22 19:02:15 +000079
80 return i;
81}
Kyösti Mälkkib3356bb2014-03-06 16:55:05 +020082
Kyösti Mälkki7132f252019-02-14 23:08:29 +020083int do_printk(int msg_level, const char *fmt, ...)
Kyösti Mälkkib3356bb2014-03-06 16:55:05 +020084{
Kyösti Mälkki7132f252019-02-14 23:08:29 +020085 va_list args;
86 int i;
87
88 va_start(args, fmt);
Jacob Garberdeb99af2019-06-03 15:19:47 -060089 i = do_vprintk(msg_level, fmt, args);
Kyösti Mälkki7132f252019-02-14 23:08:29 +020090 va_end(args);
91
92 return i;
Kyösti Mälkkib3356bb2014-03-06 16:55:05 +020093}