488d4e5ca39b951a814d92489093d79ae13f8aa2
[coreboot.git] / src / console / printk.c
1 /*
2  *  blantantly copied from linux/kernel/printk.c
3  *
4  *  Copyright (C) 1991, 1992  Linus Torvalds
5  *
6  */
7
8 #include <smp/spinlock.h>
9 #include <console/vtxprintf.h>
10 #include <console/console.h>
11
12 int console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
13 int default_console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
14
15 DECLARE_SPIN_LOCK(console_lock)
16
17 int do_printk(int msg_level, const char *fmt, ...)
18 {
19         va_list args;
20         int i;
21
22         if (msg_level > console_loglevel) {
23                 return 0;
24         }
25
26         spin_lock(&console_lock);
27
28         va_start(args, fmt);
29         i = vtxprintf(console_tx_byte, fmt, args);
30         va_end(args);
31
32         console_tx_flush();
33
34         spin_unlock(&console_lock);
35
36         return i;
37 }