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