/* * This file is part of the coreboot project. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * blatantly copied from linux/kernel/printk.c */ #include #include #include #include #include #include #include #include #include #if (!defined(__PRE_RAM__) && CONFIG(HAVE_ROMSTAGE_CONSOLE_SPINLOCK)) || !CONFIG(HAVE_ROMSTAGE_CONSOLE_SPINLOCK) DECLARE_SPIN_LOCK(console_lock) #endif #define TRACK_CONSOLE_TIME (CONFIG(HAVE_MONOTONIC_TIMER) && \ (ENV_RAMSTAGE || !CONFIG(CAR_GLOBAL_MIGRATION))) static struct mono_time mt_start, mt_stop; static long console_usecs; static void console_time_run(void) { if (TRACK_CONSOLE_TIME) timer_monotonic_get(&mt_start); } static void console_time_stop(void) { if (TRACK_CONSOLE_TIME) { timer_monotonic_get(&mt_stop); console_usecs += mono_time_diff_microseconds(&mt_start, &mt_stop); } } void console_time_report(void) { if (!TRACK_CONSOLE_TIME) return; printk(BIOS_DEBUG, "Accumulated console time in " ENV_STRING " %ld ms\n", DIV_ROUND_CLOSEST(console_usecs, USECS_PER_MSEC)); } long console_time_get_and_reset(void) { if (!TRACK_CONSOLE_TIME) return 0; long elapsed = console_usecs; console_usecs = 0; return elapsed; } void do_putchar(unsigned char byte) { console_time_run(); console_tx_byte(byte); console_time_stop(); } static void wrap_putchar(unsigned char byte, void *data) { console_tx_byte(byte); } static void wrap_putchar_cbmemc(unsigned char byte, void *data) { __cbmemc_tx_byte(byte); } int do_vprintk(int msg_level, const char *fmt, va_list args) { int i, log_this; if (CONFIG(SQUELCH_EARLY_SMP) && ENV_ROMSTAGE_OR_BEFORE && !boot_cpu()) return 0; log_this = console_log_level(msg_level); if (log_this < CONSOLE_LOG_FAST) return 0; DISABLE_TRACE; #ifdef __PRE_RAM__ #if CONFIG(HAVE_ROMSTAGE_CONSOLE_SPINLOCK) spin_lock(romstage_console_lock()); #endif #else spin_lock(&console_lock); #endif console_time_run(); if (log_this == CONSOLE_LOG_FAST) { i = vtxprintf(wrap_putchar_cbmemc, fmt, args, NULL); } else { i = vtxprintf(wrap_putchar, fmt, args, NULL); console_tx_flush(); } console_time_stop(); #ifdef __PRE_RAM__ #if CONFIG(HAVE_ROMSTAGE_CONSOLE_SPINLOCK) spin_unlock(romstage_console_lock()); #endif #else spin_unlock(&console_lock); #endif ENABLE_TRACE; return i; } int mrc_printk(const char *fmt, ...) { int i; va_list args; va_start(args, fmt); i = vtxprintf(wrap_putchar, fmt, args, NULL); va_end(args); console_tx_flush(); return i; } int do_printk(int msg_level, const char *fmt, ...) { va_list args; int i; va_start(args, fmt); i = do_vprintk(msg_level, fmt, args); va_end(args); return i; }