1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * blatantly copied from linux/kernel/printk.c
7 #include <console/cbmem_console.h>
8 #include <console/console.h>
9 #include <console/streams.h>
10 #include <console/vtxprintf.h>
11 #include <smp/spinlock.h>
17 DECLARE_SPIN_LOCK(console_lock
)
19 #define TRACK_CONSOLE_TIME (!ENV_SMM && CONFIG(HAVE_MONOTONIC_TIMER))
21 static struct mono_time mt_start
, mt_stop
;
22 static long console_usecs
;
24 static void console_time_run(void)
26 if (TRACK_CONSOLE_TIME
&& boot_cpu())
27 timer_monotonic_get(&mt_start
);
30 static void console_time_stop(void)
32 if (TRACK_CONSOLE_TIME
&& boot_cpu()) {
33 timer_monotonic_get(&mt_stop
);
34 console_usecs
+= mono_time_diff_microseconds(&mt_start
, &mt_stop
);
38 void console_time_report(void)
40 if (!TRACK_CONSOLE_TIME
)
43 printk(BIOS_DEBUG
, "BS: " ENV_STRING
" times (exec / console): total (unknown) / %ld ms\n",
44 DIV_ROUND_CLOSEST(console_usecs
, USECS_PER_MSEC
));
47 long console_time_get_and_reset(void)
49 if (!TRACK_CONSOLE_TIME
)
52 long elapsed
= console_usecs
;
57 void do_putchar(unsigned char byte
)
60 console_tx_byte(byte
);
64 static void wrap_putchar(unsigned char byte
, void *data
)
66 console_tx_byte(byte
);
69 static void wrap_putchar_cbmemc(unsigned char byte
, void *data
)
71 __cbmemc_tx_byte(byte
);
74 int do_vprintk(int msg_level
, const char *fmt
, va_list args
)
78 if (CONFIG(SQUELCH_EARLY_SMP
) && ENV_ROMSTAGE_OR_BEFORE
&& !boot_cpu())
81 log_this
= console_log_level(msg_level
);
82 if (log_this
< CONSOLE_LOG_FAST
)
86 spin_lock(&console_lock
);
90 if (log_this
== CONSOLE_LOG_FAST
) {
91 i
= vtxprintf(wrap_putchar_cbmemc
, fmt
, args
, NULL
);
93 i
= vtxprintf(wrap_putchar
, fmt
, args
, NULL
);
99 spin_unlock(&console_lock
);
105 int do_printk(int msg_level
, const char *fmt
, ...)
111 i
= do_vprintk(msg_level
, fmt
, args
);