2003-04-22 21:02:15 +02:00
|
|
|
/*
|
2016-01-17 02:59:51 +01:00
|
|
|
* This file is part of the coreboot project.
|
2003-04-22 21:02:15 +02:00
|
|
|
*
|
2016-01-17 02:59:51 +01:00
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
|
|
* Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>,
|
|
|
|
* Raptor Engineering
|
2003-04-22 21:02:15 +02:00
|
|
|
*
|
2016-01-17 02:59:51 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* blatantly copied from linux/kernel/printk.c
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
|
|
|
|
2019-02-12 13:16:21 +01:00
|
|
|
#include <console/cbmem_console.h>
|
2003-04-22 21:02:15 +02:00
|
|
|
#include <console/console.h>
|
2014-02-27 18:30:18 +01:00
|
|
|
#include <console/streams.h>
|
2014-06-17 10:37:08 +02:00
|
|
|
#include <console/vtxprintf.h>
|
|
|
|
#include <smp/spinlock.h>
|
|
|
|
#include <smp/node.h>
|
|
|
|
#include <stddef.h>
|
2011-09-02 23:23:41 +02:00
|
|
|
#include <trace.h>
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2015-05-18 23:04:10 +02:00
|
|
|
#if (!defined(__PRE_RAM__) && IS_ENABLED(CONFIG_HAVE_ROMSTAGE_CONSOLE_SPINLOCK)) || !IS_ENABLED(CONFIG_HAVE_ROMSTAGE_CONSOLE_SPINLOCK)
|
2009-11-12 17:38:03 +01:00
|
|
|
DECLARE_SPIN_LOCK(console_lock)
|
2015-05-18 23:04:10 +02:00
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2014-02-04 18:03:57 +01:00
|
|
|
void do_putchar(unsigned char byte)
|
|
|
|
{
|
|
|
|
console_tx_byte(byte);
|
|
|
|
}
|
|
|
|
|
2014-02-04 18:50:07 +01:00
|
|
|
static void wrap_putchar(unsigned char byte, void *data)
|
2014-02-04 13:28:17 +01:00
|
|
|
{
|
2019-02-12 13:16:21 +01:00
|
|
|
console_tx_byte(byte);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wrap_putchar_cbmemc(unsigned char byte, void *data)
|
|
|
|
{
|
|
|
|
__cbmemc_tx_byte(byte);
|
2014-02-04 13:28:17 +01:00
|
|
|
}
|
|
|
|
|
2019-02-14 22:08:29 +01:00
|
|
|
int vprintk(int msg_level, const char *fmt, va_list args)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
2019-02-12 13:16:21 +01:00
|
|
|
int i, log_this;
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2018-05-06 06:00:40 +02:00
|
|
|
if (IS_ENABLED(CONFIG_SQUELCH_EARLY_SMP) && ENV_CACHE_AS_RAM &&
|
|
|
|
!boot_cpu())
|
2003-04-22 21:02:15 +02:00
|
|
|
return 0;
|
|
|
|
|
2019-02-12 13:16:21 +01:00
|
|
|
log_this = console_log_level(msg_level);
|
|
|
|
if (log_this < CONSOLE_LOG_FAST)
|
2014-01-27 14:09:13 +01:00
|
|
|
return 0;
|
|
|
|
|
2011-09-02 23:23:41 +02:00
|
|
|
DISABLE_TRACE;
|
2015-05-18 23:04:10 +02:00
|
|
|
#ifdef __PRE_RAM__
|
|
|
|
#if IS_ENABLED(CONFIG_HAVE_ROMSTAGE_CONSOLE_SPINLOCK)
|
|
|
|
spin_lock(romstage_console_lock());
|
|
|
|
#endif
|
|
|
|
#else
|
2003-04-22 21:02:15 +02:00
|
|
|
spin_lock(&console_lock);
|
2015-05-18 23:04:10 +02:00
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2019-02-12 13:16:21 +01:00
|
|
|
if (log_this == CONSOLE_LOG_FAST) {
|
|
|
|
i = vtxprintf(wrap_putchar_cbmemc, fmt, args, NULL);
|
|
|
|
} else {
|
|
|
|
i = vtxprintf(wrap_putchar, fmt, args, NULL);
|
|
|
|
console_tx_flush();
|
|
|
|
}
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2015-05-18 23:04:10 +02:00
|
|
|
#ifdef __PRE_RAM__
|
|
|
|
#if IS_ENABLED(CONFIG_HAVE_ROMSTAGE_CONSOLE_SPINLOCK)
|
|
|
|
spin_unlock(romstage_console_lock());
|
|
|
|
#endif
|
|
|
|
#else
|
2003-04-22 21:02:15 +02:00
|
|
|
spin_unlock(&console_lock);
|
2015-05-18 23:04:10 +02:00
|
|
|
#endif
|
2011-09-02 23:23:41 +02:00
|
|
|
ENABLE_TRACE;
|
2003-04-22 21:02:15 +02:00
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
2014-03-06 15:55:05 +01:00
|
|
|
|
2019-02-14 22:08:29 +01:00
|
|
|
int do_printk(int msg_level, const char *fmt, ...)
|
2014-03-06 15:55:05 +01:00
|
|
|
{
|
2019-02-14 22:08:29 +01:00
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
i = vprintk(msg_level, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
return i;
|
2014-03-06 15:55:05 +01:00
|
|
|
}
|