blob: b6777e14752a1b7e8bebe70c8036cc635a2cf6e3 [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
Eric Biederman8ca8d762003-04-22 19:02:15 +00008#include <console/console.h>
Kyösti Mälkki40760722014-02-27 19:30:18 +02009#include <console/streams.h>
Edward O'Callaghan0ddb8262014-06-17 18:37:08 +100010#include <console/vtxprintf.h>
11#include <smp/spinlock.h>
12#include <smp/node.h>
13#include <stddef.h>
Rudolf Marek7f0e9302011-09-02 23:23:41 +020014#include <trace.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000015
Myles Watson2e672732009-11-12 16:38:03 +000016DECLARE_SPIN_LOCK(console_lock)
Eric Biederman8ca8d762003-04-22 19:02:15 +000017
Kyösti Mälkki657e0be2014-02-04 19:03:57 +020018void do_putchar(unsigned char byte)
19{
20 if (byte == '\n')
21 console_tx_byte('\r');
22 console_tx_byte(byte);
23}
24
Kyösti Mälkki77f43e92014-02-04 19:50:07 +020025static void wrap_putchar(unsigned char byte, void *data)
Kyösti Mälkkib04e0ff2014-02-04 14:28:17 +020026{
27 do_putchar(byte);
28}
29
Eric Biederman8ca8d762003-04-22 19:02:15 +000030int do_printk(int msg_level, const char *fmt, ...)
31{
32 va_list args;
33 int i;
34
Kyösti Mälkki56ae1392014-02-28 14:37:27 +020035 if (!console_log_level(msg_level))
Eric Biederman8ca8d762003-04-22 19:02:15 +000036 return 0;
Eric Biederman8ca8d762003-04-22 19:02:15 +000037
Edward O'Callaghan0ddb8262014-06-17 18:37:08 +100038#if IS_ENABLED (CONFIG_SQUELCH_EARLY_SMP) && defined(__PRE_RAM__)
Kyösti Mälkkib2d25962014-01-27 15:09:13 +020039 if (!boot_cpu())
40 return 0;
41#endif
42
Rudolf Marek7f0e9302011-09-02 23:23:41 +020043 DISABLE_TRACE;
Eric Biederman8ca8d762003-04-22 19:02:15 +000044 spin_lock(&console_lock);
45
46 va_start(args, fmt);
Kyösti Mälkkib04e0ff2014-02-04 14:28:17 +020047 i = vtxprintf(wrap_putchar, fmt, args, NULL);
Eric Biederman8ca8d762003-04-22 19:02:15 +000048 va_end(args);
49
50 console_tx_flush();
51
52 spin_unlock(&console_lock);
Rudolf Marek7f0e9302011-09-02 23:23:41 +020053 ENABLE_TRACE;
Eric Biederman8ca8d762003-04-22 19:02:15 +000054
55 return i;
56}
Kyösti Mälkkib3356bb2014-03-06 16:55:05 +020057
Edward O'Callaghan0ddb8262014-06-17 18:37:08 +100058#if IS_ENABLED (CONFIG_CHROMEOS)
Kyösti Mälkkib3356bb2014-03-06 16:55:05 +020059void do_vtxprintf(const char *fmt, va_list args)
60{
Kyösti Mälkkib04e0ff2014-02-04 14:28:17 +020061 vtxprintf(wrap_putchar, fmt, args, NULL);
Kyösti Mälkkib3356bb2014-03-06 16:55:05 +020062 console_tx_flush();
63}
Edward O'Callaghan0ddb8262014-06-17 18:37:08 +100064#endif /* CONFIG_CHROMEOS */