Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | /* |
Damien Roth | 4e7e987 | 2016-01-16 18:59:51 -0700 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 3 | * |
Damien Roth | 4e7e987 | 2016-01-16 18:59:51 -0700 | [diff] [blame] | 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, |
| 6 | * Raptor Engineering |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 7 | * |
Damien Roth | 4e7e987 | 2016-01-16 18:59:51 -0700 | [diff] [blame] | 8 | * 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 Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 18 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 19 | |
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 20 | #include <console/cbmem_console.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 21 | #include <console/console.h> |
Kyösti Mälkki | 4076072 | 2014-02-27 19:30:18 +0200 | [diff] [blame] | 22 | #include <console/streams.h> |
Edward O'Callaghan | 0ddb826 | 2014-06-17 18:37:08 +1000 | [diff] [blame] | 23 | #include <console/vtxprintf.h> |
| 24 | #include <smp/spinlock.h> |
| 25 | #include <smp/node.h> |
| 26 | #include <stddef.h> |
Rudolf Marek | 7f0e930 | 2011-09-02 23:23:41 +0200 | [diff] [blame] | 27 | #include <trace.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 28 | |
Timothy Pearson | 44d5342 | 2015-05-18 16:04:10 -0500 | [diff] [blame] | 29 | #if (!defined(__PRE_RAM__) && IS_ENABLED(CONFIG_HAVE_ROMSTAGE_CONSOLE_SPINLOCK)) || !IS_ENABLED(CONFIG_HAVE_ROMSTAGE_CONSOLE_SPINLOCK) |
Myles Watson | 2e67273 | 2009-11-12 16:38:03 +0000 | [diff] [blame] | 30 | DECLARE_SPIN_LOCK(console_lock) |
Timothy Pearson | 44d5342 | 2015-05-18 16:04:10 -0500 | [diff] [blame] | 31 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 32 | |
Kyösti Mälkki | 657e0be | 2014-02-04 19:03:57 +0200 | [diff] [blame] | 33 | void do_putchar(unsigned char byte) |
| 34 | { |
Kyösti Mälkki | 657e0be | 2014-02-04 19:03:57 +0200 | [diff] [blame] | 35 | console_tx_byte(byte); |
| 36 | } |
| 37 | |
Kyösti Mälkki | 77f43e9 | 2014-02-04 19:50:07 +0200 | [diff] [blame] | 38 | static void wrap_putchar(unsigned char byte, void *data) |
Kyösti Mälkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame] | 39 | { |
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 40 | console_tx_byte(byte); |
| 41 | } |
| 42 | |
| 43 | static void wrap_putchar_cbmemc(unsigned char byte, void *data) |
| 44 | { |
| 45 | __cbmemc_tx_byte(byte); |
Kyösti Mälkki | b04e0ff | 2014-02-04 14:28:17 +0200 | [diff] [blame] | 46 | } |
| 47 | |
Kyösti Mälkki | 7132f25 | 2019-02-14 23:08:29 +0200 | [diff] [blame] | 48 | int vprintk(int msg_level, const char *fmt, va_list args) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 49 | { |
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 50 | int i, log_this; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 51 | |
Kyösti Mälkki | cebb684 | 2018-05-06 07:00:40 +0300 | [diff] [blame] | 52 | if (IS_ENABLED(CONFIG_SQUELCH_EARLY_SMP) && ENV_CACHE_AS_RAM && |
| 53 | !boot_cpu()) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 54 | return 0; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 55 | |
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 56 | log_this = console_log_level(msg_level); |
| 57 | if (log_this < CONSOLE_LOG_FAST) |
Kyösti Mälkki | b2d2596 | 2014-01-27 15:09:13 +0200 | [diff] [blame] | 58 | return 0; |
Kyösti Mälkki | b2d2596 | 2014-01-27 15:09:13 +0200 | [diff] [blame] | 59 | |
Rudolf Marek | 7f0e930 | 2011-09-02 23:23:41 +0200 | [diff] [blame] | 60 | DISABLE_TRACE; |
Timothy Pearson | 44d5342 | 2015-05-18 16:04:10 -0500 | [diff] [blame] | 61 | #ifdef __PRE_RAM__ |
| 62 | #if IS_ENABLED(CONFIG_HAVE_ROMSTAGE_CONSOLE_SPINLOCK) |
| 63 | spin_lock(romstage_console_lock()); |
| 64 | #endif |
| 65 | #else |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 66 | spin_lock(&console_lock); |
Timothy Pearson | 44d5342 | 2015-05-18 16:04:10 -0500 | [diff] [blame] | 67 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 68 | |
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 69 | if (log_this == CONSOLE_LOG_FAST) { |
| 70 | i = vtxprintf(wrap_putchar_cbmemc, fmt, args, NULL); |
| 71 | } else { |
| 72 | i = vtxprintf(wrap_putchar, fmt, args, NULL); |
| 73 | console_tx_flush(); |
| 74 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 75 | |
Timothy Pearson | 44d5342 | 2015-05-18 16:04:10 -0500 | [diff] [blame] | 76 | #ifdef __PRE_RAM__ |
| 77 | #if IS_ENABLED(CONFIG_HAVE_ROMSTAGE_CONSOLE_SPINLOCK) |
| 78 | spin_unlock(romstage_console_lock()); |
| 79 | #endif |
| 80 | #else |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 81 | spin_unlock(&console_lock); |
Timothy Pearson | 44d5342 | 2015-05-18 16:04:10 -0500 | [diff] [blame] | 82 | #endif |
Rudolf Marek | 7f0e930 | 2011-09-02 23:23:41 +0200 | [diff] [blame] | 83 | ENABLE_TRACE; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 84 | |
| 85 | return i; |
| 86 | } |
Kyösti Mälkki | b3356bb | 2014-03-06 16:55:05 +0200 | [diff] [blame] | 87 | |
Kyösti Mälkki | 7132f25 | 2019-02-14 23:08:29 +0200 | [diff] [blame] | 88 | int do_printk(int msg_level, const char *fmt, ...) |
Kyösti Mälkki | b3356bb | 2014-03-06 16:55:05 +0200 | [diff] [blame] | 89 | { |
Kyösti Mälkki | 7132f25 | 2019-02-14 23:08:29 +0200 | [diff] [blame] | 90 | va_list args; |
| 91 | int i; |
| 92 | |
| 93 | va_start(args, fmt); |
| 94 | i = vprintk(msg_level, fmt, args); |
| 95 | va_end(args); |
| 96 | |
| 97 | return i; |
Kyösti Mälkki | b3356bb | 2014-03-06 16:55:05 +0200 | [diff] [blame] | 98 | } |