blob: 2f7e27719b8828e1a51fdaf8b87b1ecff7832a2f [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
Eric Biederman8ca8d762003-04-22 19:02:15 +000020#include <console/console.h>
Kyösti Mälkki40760722014-02-27 19:30:18 +020021#include <console/streams.h>
Edward O'Callaghan0ddb8262014-06-17 18:37:08 +100022#include <console/vtxprintf.h>
23#include <smp/spinlock.h>
24#include <smp/node.h>
25#include <stddef.h>
Rudolf Marek7f0e9302011-09-02 23:23:41 +020026#include <trace.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000027
Timothy Pearson44d53422015-05-18 16:04:10 -050028#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 +000029DECLARE_SPIN_LOCK(console_lock)
Timothy Pearson44d53422015-05-18 16:04:10 -050030#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000031
Kyösti Mälkki657e0be2014-02-04 19:03:57 +020032void do_putchar(unsigned char byte)
33{
Kyösti Mälkki657e0be2014-02-04 19:03:57 +020034 console_tx_byte(byte);
35}
36
Kyösti Mälkki77f43e92014-02-04 19:50:07 +020037static void wrap_putchar(unsigned char byte, void *data)
Kyösti Mälkkib04e0ff2014-02-04 14:28:17 +020038{
39 do_putchar(byte);
40}
41
Eric Biederman8ca8d762003-04-22 19:02:15 +000042int do_printk(int msg_level, const char *fmt, ...)
43{
44 va_list args;
45 int i;
46
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020047 if (!console_log_level(msg_level))
Eric Biederman8ca8d762003-04-22 19:02:15 +000048 return 0;
Eric Biederman8ca8d762003-04-22 19:02:15 +000049
Edward O'Callaghan0ddb8262014-06-17 18:37:08 +100050#if IS_ENABLED (CONFIG_SQUELCH_EARLY_SMP) && defined(__PRE_RAM__)
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020051 if (!boot_cpu())
52 return 0;
53#endif
54
Rudolf Marek7f0e9302011-09-02 23:23:41 +020055 DISABLE_TRACE;
Timothy Pearson44d53422015-05-18 16:04:10 -050056#ifdef __PRE_RAM__
57#if IS_ENABLED(CONFIG_HAVE_ROMSTAGE_CONSOLE_SPINLOCK)
58 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
64 va_start(args, fmt);
Kyösti Mälkkib04e0ff2014-02-04 14:28:17 +020065 i = vtxprintf(wrap_putchar, fmt, args, NULL);
Eric Biederman8ca8d762003-04-22 19:02:15 +000066 va_end(args);
67
68 console_tx_flush();
69
Timothy Pearson44d53422015-05-18 16:04:10 -050070#ifdef __PRE_RAM__
71#if IS_ENABLED(CONFIG_HAVE_ROMSTAGE_CONSOLE_SPINLOCK)
72 spin_unlock(romstage_console_lock());
73#endif
74#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000075 spin_unlock(&console_lock);
Timothy Pearson44d53422015-05-18 16:04:10 -050076#endif
Rudolf Marek7f0e9302011-09-02 23:23:41 +020077 ENABLE_TRACE;
Eric Biederman8ca8d762003-04-22 19:02:15 +000078
79 return i;
80}
Kyösti Mälkkib3356bb2014-03-06 16:55:05 +020081
Lee Leahyaa5c8f72016-12-26 10:58:16 -080082#if IS_ENABLED (CONFIG_VBOOT)
Aaron Durbin8fb36c02015-05-01 16:48:54 -050083void do_printk_va_list(int msg_level, const char *fmt, va_list args)
Kyösti Mälkkib3356bb2014-03-06 16:55:05 +020084{
Aaron Durbin8fb36c02015-05-01 16:48:54 -050085 if (!console_log_level(msg_level))
86 return;
Kyösti Mälkkib04e0ff2014-02-04 14:28:17 +020087 vtxprintf(wrap_putchar, fmt, args, NULL);
Kyösti Mälkkib3356bb2014-03-06 16:55:05 +020088 console_tx_flush();
89}
Lee Leahyaa5c8f72016-12-26 10:58:16 -080090#endif /* CONFIG_VBOOT */