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> |
Rudolf Marek | 7f0e930 | 2011-09-02 23:23:41 +0200 | [diff] [blame] | 13 | #include <trace.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 14 | |
Myles Watson | 2e67273 | 2009-11-12 16:38:03 +0000 | [diff] [blame] | 15 | DECLARE_SPIN_LOCK(console_lock) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 16 | |
Kyösti Mälkki | 657e0be | 2014-02-04 19:03:57 +0200 | [diff] [blame] | 17 | void 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älkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame^] | 24 | void wrap_putchar(unsigned char byte, void *data) |
| 25 | { |
| 26 | do_putchar(byte); |
| 27 | } |
| 28 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 29 | int do_printk(int msg_level, const char *fmt, ...) |
| 30 | { |
| 31 | va_list args; |
| 32 | int i; |
| 33 | |
Kyösti Mälkki | 56ae139 | 2014-02-28 14:37:27 +0200 | [diff] [blame] | 34 | if (!console_log_level(msg_level)) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 35 | return 0; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 36 | |
Kyösti Mälkki | b2d2596 | 2014-01-27 15:09:13 +0200 | [diff] [blame] | 37 | #if CONFIG_SQUELCH_EARLY_SMP && defined(__PRE_RAM__) |
| 38 | if (!boot_cpu()) |
| 39 | return 0; |
| 40 | #endif |
| 41 | |
Rudolf Marek | 7f0e930 | 2011-09-02 23:23:41 +0200 | [diff] [blame] | 42 | DISABLE_TRACE; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 43 | spin_lock(&console_lock); |
| 44 | |
| 45 | va_start(args, fmt); |
Kyösti Mälkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame^] | 46 | i = vtxprintf(wrap_putchar, fmt, args, NULL); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 47 | va_end(args); |
| 48 | |
| 49 | console_tx_flush(); |
| 50 | |
| 51 | spin_unlock(&console_lock); |
Rudolf Marek | 7f0e930 | 2011-09-02 23:23:41 +0200 | [diff] [blame] | 52 | ENABLE_TRACE; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 53 | |
| 54 | return i; |
| 55 | } |
Kyösti Mälkki | b3356bb | 2014-03-06 16:55:05 +0200 | [diff] [blame] | 56 | |
| 57 | #if CONFIG_CHROMEOS |
| 58 | void do_vtxprintf(const char *fmt, va_list args) |
| 59 | { |
Kyösti Mälkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame^] | 60 | vtxprintf(wrap_putchar, fmt, args, NULL); |
Kyösti Mälkki | b3356bb | 2014-03-06 16:55:05 +0200 | [diff] [blame] | 61 | console_tx_flush(); |
| 62 | } |
| 63 | #endif |
Kyösti Mälkki | 657e0be | 2014-02-04 19:03:57 +0200 | [diff] [blame] | 64 | |