blob: 2fa160b4f37acb077e7c784d963f9b9203885b8e [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001/*
Martin Roth50d887d2013-07-08 16:22:54 -06002 * blatantly copied from linux/kernel/printk.c
Eric Biederman8ca8d762003-04-22 19:02:15 +00003 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 *
6 */
Eric Biederman8ca8d762003-04-22 19:02:15 +00007
Kyösti Mälkkib04e0ff2014-02-04 14:28:17 +02008#include <stddef.h>
Kyösti Mälkkib2d25962014-01-27 15:09:13 +02009#include <smp/node.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000010#include <smp/spinlock.h>
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000011#include <console/vtxprintf.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000012#include <console/console.h>
Rudolf Marek7f0e9302011-09-02 23:23:41 +020013#include <trace.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000014
Myles Watson2e672732009-11-12 16:38:03 +000015DECLARE_SPIN_LOCK(console_lock)
Eric Biederman8ca8d762003-04-22 19:02:15 +000016
Kyösti Mälkki657e0be2014-02-04 19:03:57 +020017void do_putchar(unsigned char byte)
18{
19 if (byte == '\n')
20 console_tx_byte('\r');
21 console_tx_byte(byte);
22}
23
Kyösti Mälkki77f43e92014-02-04 19:50:07 +020024static void wrap_putchar(unsigned char byte, void *data)
Kyösti Mälkkib04e0ff2014-02-04 14:28:17 +020025{
26 do_putchar(byte);
27}
28
Eric Biederman8ca8d762003-04-22 19:02:15 +000029int do_printk(int msg_level, const char *fmt, ...)
30{
31 va_list args;
32 int i;
33
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020034 if (!console_log_level(msg_level))
Eric Biederman8ca8d762003-04-22 19:02:15 +000035 return 0;
Eric Biederman8ca8d762003-04-22 19:02:15 +000036
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020037#if CONFIG_SQUELCH_EARLY_SMP && defined(__PRE_RAM__)
38 if (!boot_cpu())
39 return 0;
40#endif
41
Rudolf Marek7f0e9302011-09-02 23:23:41 +020042 DISABLE_TRACE;
Eric Biederman8ca8d762003-04-22 19:02:15 +000043 spin_lock(&console_lock);
44
45 va_start(args, fmt);
Kyösti Mälkkib04e0ff2014-02-04 14:28:17 +020046 i = vtxprintf(wrap_putchar, fmt, args, NULL);
Eric Biederman8ca8d762003-04-22 19:02:15 +000047 va_end(args);
48
49 console_tx_flush();
50
51 spin_unlock(&console_lock);
Rudolf Marek7f0e9302011-09-02 23:23:41 +020052 ENABLE_TRACE;
Eric Biederman8ca8d762003-04-22 19:02:15 +000053
54 return i;
55}
Kyösti Mälkkib3356bb2014-03-06 16:55:05 +020056
57#if CONFIG_CHROMEOS
58void do_vtxprintf(const char *fmt, va_list args)
59{
Kyösti Mälkkib04e0ff2014-02-04 14:28:17 +020060 vtxprintf(wrap_putchar, fmt, args, NULL);
Kyösti Mälkkib3356bb2014-03-06 16:55:05 +020061 console_tx_flush();
62}
63#endif