blob: e24c752492d58882a26d6b73c102edcfc46708e3 [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001/*
Martin Roth50d887d2013-07-08 16:22:54 -06002 * blatantly copied from linux/kernel/printk.c
Eric Biederman8ca8d762003-04-22 19:02:15 +00003 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 *
6 */
Eric Biederman8ca8d762003-04-22 19:02:15 +00007
Eric Biederman8ca8d762003-04-22 19:02:15 +00008#include <smp/spinlock.h>
Stefan Reinauer52fc6b122009-10-24 13:06:04 +00009#include <console/vtxprintf.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000010#include <console/console.h>
Rudolf Marek7f0e9302011-09-02 23:23:41 +020011#include <trace.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000012
Stefan Reinauer08670622009-06-30 15:17:49 +000013int console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
Stefan Reinauer08670622009-06-30 15:17:49 +000014int default_console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
Eric Biederman8ca8d762003-04-22 19:02:15 +000015
Myles Watson2e672732009-11-12 16:38:03 +000016DECLARE_SPIN_LOCK(console_lock)
Eric Biederman8ca8d762003-04-22 19:02:15 +000017
18int do_printk(int msg_level, const char *fmt, ...)
19{
20 va_list args;
21 int i;
22
Myles Watson03646182009-10-16 19:29:45 +000023 if (msg_level > console_loglevel) {
Eric Biederman8ca8d762003-04-22 19:02:15 +000024 return 0;
25 }
26
Rudolf Marek7f0e9302011-09-02 23:23:41 +020027 DISABLE_TRACE;
Eric Biederman8ca8d762003-04-22 19:02:15 +000028 spin_lock(&console_lock);
29
30 va_start(args, fmt);
31 i = vtxprintf(console_tx_byte, fmt, args);
32 va_end(args);
33
34 console_tx_flush();
35
36 spin_unlock(&console_lock);
Rudolf Marek7f0e9302011-09-02 23:23:41 +020037 ENABLE_TRACE;
Eric Biederman8ca8d762003-04-22 19:02:15 +000038
39 return i;
40}