blob: 6050620dcaaacda51cfb9be0de9b6dbc60adc982 [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 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>,
6 * Raptor Engineering
Eric Biederman8ca8d762003-04-22 19:02:15 +00007 *
Damien Roth4e7e9872016-01-16 18:59:51 -07008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * blatantly copied from linux/kernel/printk.c
Eric Biederman8ca8d762003-04-22 19:02:15 +000018 */
Eric Biederman8ca8d762003-04-22 19:02:15 +000019
Kyösti Mälkkie613d702019-02-12 14:16:21 +020020#include <console/cbmem_console.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000021#include <console/console.h>
Kyösti Mälkki40760722014-02-27 19:30:18 +020022#include <console/streams.h>
Edward O'Callaghan0ddb8262014-06-17 18:37:08 +100023#include <console/vtxprintf.h>
24#include <smp/spinlock.h>
25#include <smp/node.h>
26#include <stddef.h>
Rudolf Marek7f0e9302011-09-02 23:23:41 +020027#include <trace.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000028
Timothy Pearson44d53422015-05-18 16:04:10 -050029#if (!defined(__PRE_RAM__) && IS_ENABLED(CONFIG_HAVE_ROMSTAGE_CONSOLE_SPINLOCK)) || !IS_ENABLED(CONFIG_HAVE_ROMSTAGE_CONSOLE_SPINLOCK)
Myles Watson2e672732009-11-12 16:38:03 +000030DECLARE_SPIN_LOCK(console_lock)
Timothy Pearson44d53422015-05-18 16:04:10 -050031#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000032
Kyösti Mälkki657e0be2014-02-04 19:03:57 +020033void do_putchar(unsigned char byte)
34{
Kyösti Mälkki657e0be2014-02-04 19:03:57 +020035 console_tx_byte(byte);
36}
37
Kyösti Mälkki77f43e92014-02-04 19:50:07 +020038static void wrap_putchar(unsigned char byte, void *data)
Kyösti Mälkkib04e0ff2014-02-04 14:28:17 +020039{
Kyösti Mälkkie613d702019-02-12 14:16:21 +020040 console_tx_byte(byte);
41}
42
43static void wrap_putchar_cbmemc(unsigned char byte, void *data)
44{
45 __cbmemc_tx_byte(byte);
Kyösti Mälkkib04e0ff2014-02-04 14:28:17 +020046}
47
Kyösti Mälkki7132f252019-02-14 23:08:29 +020048int vprintk(int msg_level, const char *fmt, va_list args)
Eric Biederman8ca8d762003-04-22 19:02:15 +000049{
Kyösti Mälkkie613d702019-02-12 14:16:21 +020050 int i, log_this;
Eric Biederman8ca8d762003-04-22 19:02:15 +000051
Kyösti Mälkkicebb6842018-05-06 07:00:40 +030052 if (IS_ENABLED(CONFIG_SQUELCH_EARLY_SMP) && ENV_CACHE_AS_RAM &&
53 !boot_cpu())
Eric Biederman8ca8d762003-04-22 19:02:15 +000054 return 0;
Eric Biederman8ca8d762003-04-22 19:02:15 +000055
Kyösti Mälkkie613d702019-02-12 14:16:21 +020056 log_this = console_log_level(msg_level);
57 if (log_this < CONSOLE_LOG_FAST)
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020058 return 0;
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020059
Rudolf Marek7f0e9302011-09-02 23:23:41 +020060 DISABLE_TRACE;
Timothy Pearson44d53422015-05-18 16:04:10 -050061#ifdef __PRE_RAM__
62#if IS_ENABLED(CONFIG_HAVE_ROMSTAGE_CONSOLE_SPINLOCK)
63 spin_lock(romstage_console_lock());
64#endif
65#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000066 spin_lock(&console_lock);
Timothy Pearson44d53422015-05-18 16:04:10 -050067#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000068
Kyösti Mälkkie613d702019-02-12 14:16:21 +020069 if (log_this == CONSOLE_LOG_FAST) {
70 i = vtxprintf(wrap_putchar_cbmemc, fmt, args, NULL);
71 } else {
72 i = vtxprintf(wrap_putchar, fmt, args, NULL);
73 console_tx_flush();
74 }
Eric Biederman8ca8d762003-04-22 19:02:15 +000075
Timothy Pearson44d53422015-05-18 16:04:10 -050076#ifdef __PRE_RAM__
77#if IS_ENABLED(CONFIG_HAVE_ROMSTAGE_CONSOLE_SPINLOCK)
78 spin_unlock(romstage_console_lock());
79#endif
80#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000081 spin_unlock(&console_lock);
Timothy Pearson44d53422015-05-18 16:04:10 -050082#endif
Rudolf Marek7f0e9302011-09-02 23:23:41 +020083 ENABLE_TRACE;
Eric Biederman8ca8d762003-04-22 19:02:15 +000084
85 return i;
86}
Kyösti Mälkkib3356bb2014-03-06 16:55:05 +020087
Kyösti Mälkki7132f252019-02-14 23:08:29 +020088int do_printk(int msg_level, const char *fmt, ...)
Kyösti Mälkkib3356bb2014-03-06 16:55:05 +020089{
Kyösti Mälkki7132f252019-02-14 23:08:29 +020090 va_list args;
91 int i;
92
93 va_start(args, fmt);
94 i = vprintk(msg_level, fmt, args);
95 va_end(args);
96
97 return i;
Kyösti Mälkkib3356bb2014-03-06 16:55:05 +020098}