]> rtime.felk.cvut.cz Git - jailhouse.git/blob - hypervisor/printk.c
603bb8369e428ed0f48b8ed1250a96a816d81458
[jailhouse.git] / hypervisor / printk.c
1 /*
2  * Jailhouse, a Linux-based partitioning hypervisor
3  *
4  * Copyright (c) Siemens AG, 2013
5  *
6  * Authors:
7  *  Jan Kiszka <jan.kiszka@siemens.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  */
12
13 #include <stdarg.h>
14 #include <jailhouse/printk.h>
15 #include <jailhouse/processor.h>
16 #include <jailhouse/string.h>
17 #include <asm/spinlock.h>
18
19 volatile unsigned long panic_in_progress;
20 unsigned int panic_cpu = -1;
21
22 static DEFINE_SPINLOCK(printk_lock);
23
24 #define console_write(msg)      arch_dbg_write(msg)
25 #include "printk-core.c"
26
27 void printk(const char *fmt, ...)
28 {
29         va_list ap;
30
31         va_start(ap, fmt);
32
33         spin_lock(&printk_lock);
34         __vprintk(fmt, ap);
35         spin_unlock(&printk_lock);
36
37         va_end(ap);
38 }
39
40 void panic_printk(const char *fmt, ...)
41 {
42         unsigned int cpu_id = phys_processor_id();
43         va_list ap;
44
45         if (test_and_set_bit(0, &panic_in_progress) && panic_cpu != cpu_id)
46                 return;
47         panic_cpu = cpu_id;
48
49         va_start(ap, fmt);
50
51         __vprintk(fmt, ap);
52
53         va_end(ap);
54 }