886e2cfa727061733e4b5daf7a118a577cdf4f72
[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 <stdarg.h>
9 #include <smp/spinlock.h>
10 #include <console/vtxprintf.h>
11 #include <console/console.h>
12
13 /* printk's without a loglevel use this.. */
14 #define DEFAULT_MESSAGE_LOGLEVEL 4 /* BIOS_WARNING */
15
16 /* We show everything that is MORE important than this.. */
17 #define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */
18
19 /* Keep together for sysctl support */
20
21 int console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
22 int default_console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
23
24 DECLARE_SPIN_LOCK(console_lock)
25
26 int do_printk(int msg_level, const char *fmt, ...)
27 {
28         va_list args;
29         int i;
30
31         if (msg_level > console_loglevel) {
32                 return 0;
33         }
34
35         spin_lock(&console_lock);
36
37         va_start(args, fmt);
38         i = vtxprintf(console_tx_byte, fmt, args);
39         va_end(args);
40
41         console_tx_flush();
42
43         spin_unlock(&console_lock);
44
45         return i;
46 }