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
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
{
|
|
|
|
do_putchar(byte);
|
|
|
|
}
|
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
int do_printk(int msg_level, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
|
2014-02-28 13:37:27 +01:00
|
|
|
if (!console_log_level(msg_level))
|
2003-04-22 21:02:15 +02:00
|
|
|
return 0;
|
|
|
|
|
2014-06-17 10:37:08 +02:00
|
|
|
#if IS_ENABLED (CONFIG_SQUELCH_EARLY_SMP) && defined(__PRE_RAM__)
|
2014-01-27 14:09:13 +01:00
|
|
|
if (!boot_cpu())
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
|
|
|
va_start(args, fmt);
|
2014-02-04 13:28:17 +01:00
|
|
|
i = vtxprintf(wrap_putchar, fmt, args, NULL);
|
2003-04-22 21:02:15 +02:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
console_tx_flush();
|
|
|
|
|
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
|
|
|
|
2014-06-17 10:37:08 +02:00
|
|
|
#if IS_ENABLED (CONFIG_CHROMEOS)
|
2015-05-01 23:48:54 +02:00
|
|
|
void do_printk_va_list(int msg_level, const char *fmt, va_list args)
|
2014-03-06 15:55:05 +01:00
|
|
|
{
|
2015-05-01 23:48:54 +02:00
|
|
|
if (!console_log_level(msg_level))
|
|
|
|
return;
|
2014-02-04 13:28:17 +01:00
|
|
|
vtxprintf(wrap_putchar, fmt, args, NULL);
|
2014-03-06 15:55:05 +01:00
|
|
|
console_tx_flush();
|
|
|
|
}
|
2014-06-17 10:37:08 +02:00
|
|
|
#endif /* CONFIG_CHROMEOS */
|