Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | /* |
Martin Roth | 50d887d | 2013-07-08 16:22:54 -0600 | [diff] [blame] | 2 | * blatantly copied from linux/kernel/printk.c |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | * |
| 6 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 7 | |
Kyösti Mälkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame] | 8 | #include <stddef.h> |
Kyösti Mälkki | b2d2596 | 2014-01-27 15:09:13 +0200 | [diff] [blame] | 9 | #include <smp/node.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 10 | #include <smp/spinlock.h> |
Stefan Reinauer | 52fc6b1 | 2009-10-24 13:06:04 +0000 | [diff] [blame] | 11 | #include <console/vtxprintf.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 12 | #include <console/console.h> |
Kyösti Mälkki | 4076072 | 2014-02-27 19:30:18 +0200 | [diff] [blame] | 13 | #include <console/streams.h> |
Rudolf Marek | 7f0e930 | 2011-09-02 23:23:41 +0200 | [diff] [blame] | 14 | #include <trace.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 15 | |
Myles Watson | 2e67273 | 2009-11-12 16:38:03 +0000 | [diff] [blame] | 16 | DECLARE_SPIN_LOCK(console_lock) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 17 | |
Kyösti Mälkki | 657e0be | 2014-02-04 19:03:57 +0200 | [diff] [blame] | 18 | void 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älkki | 77f43e9 | 2014-02-04 19:50:07 +0200 | [diff] [blame] | 25 | static void wrap_putchar(unsigned char byte, void *data) |
Kyösti Mälkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame] | 26 | { |
| 27 | do_putchar(byte); |
| 28 | } |
| 29 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 30 | int do_printk(int msg_level, const char *fmt, ...) |
| 31 | { |
| 32 | va_list args; |
| 33 | int i; |
| 34 | |
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 35 | if (!console_log_level(msg_level)) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 36 | return 0; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 37 | |
Kyösti Mälkki | b2d2596 | 2014-01-27 15:09:13 +0200 | [diff] [blame] | 38 | #if CONFIG_SQUELCH_EARLY_SMP && defined(__PRE_RAM__) |
| 39 | if (!boot_cpu()) |
| 40 | return 0; |
| 41 | #endif |
| 42 | |
Rudolf Marek | 7f0e930 | 2011-09-02 23:23:41 +0200 | [diff] [blame] | 43 | DISABLE_TRACE; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 44 | spin_lock(&console_lock); |
| 45 | |
| 46 | va_start(args, fmt); |
Kyösti Mälkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame] | 47 | i = vtxprintf(wrap_putchar, fmt, args, NULL); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 48 | va_end(args); |
| 49 | |
| 50 | console_tx_flush(); |
| 51 | |
| 52 | spin_unlock(&console_lock); |
Rudolf Marek | 7f0e930 | 2011-09-02 23:23:41 +0200 | [diff] [blame] | 53 | ENABLE_TRACE; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 54 | |
| 55 | return i; |
| 56 | } |
Kyösti Mälkki | b3356bb | 2014-03-06 16:55:05 +0200 | [diff] [blame] | 57 | |
| 58 | #if CONFIG_CHROMEOS |
| 59 | void do_vtxprintf(const char *fmt, va_list args) |
| 60 | { |
Kyösti Mälkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame] | 61 | vtxprintf(wrap_putchar, fmt, args, NULL); |
Kyösti Mälkki | b3356bb | 2014-03-06 16:55:05 +0200 | [diff] [blame] | 62 | console_tx_flush(); |
| 63 | } |
| 64 | #endif |