]> rtime.felk.cvut.cz Git - jailhouse.git/blob - inmates/lib/x86/printk.c
inmates: Refactor folder structure
[jailhouse.git] / inmates / lib / x86 / 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 <inmate.h>
15
16 #define UART_TX                 0x0
17 #define UART_DLL                0x0
18 #define UART_DLM                0x1
19 #define UART_LCR                0x3
20 #define UART_LCR_8N1            0x03
21 #define UART_LCR_DLAB           0x80
22 #define UART_LSR                0x5
23 #define UART_LSR_THRE           0x20
24
25 unsigned int printk_uart_base;
26
27 static void uart_write(const char *msg)
28 {
29         char c;
30
31         while (1) {
32                 c = *msg++;
33                 if (!c)
34                         break;
35                 while (!(inb(printk_uart_base + UART_LSR) & UART_LSR_THRE))
36                         cpu_relax();
37                 outb(c, printk_uart_base + UART_TX);
38         }
39 }
40
41 #define console_write(msg)      uart_write(msg)
42 #include "../../../hypervisor/printk-core.c"
43
44 void printk(const char *fmt, ...)
45 {
46         static bool inited;
47         va_list ap;
48
49         if (!inited) {
50                 inited = true;
51                 outb(UART_LCR_DLAB, printk_uart_base + UART_LCR);
52 #ifdef CONFIG_UART_OXPCIE952
53                 outb(0x22, printk_uart_base + UART_DLL);
54 #else
55                 outb(1, printk_uart_base + UART_DLL);  
56 #endif
57                 outb(0, printk_uart_base + UART_DLM);
58                 outb(UART_LCR_8N1, printk_uart_base + UART_LCR);
59         }
60
61         va_start(ap, fmt);
62
63         __vprintk(fmt, ap);
64
65         va_end(ap);
66 }