1 From 58d058f1fe1cc5981c57be8b48d3b2f74f25c0d6 Mon Sep 17 00:00:00 2001
2 From: Jan Kiszka <jan.kiszka@siemens.com>
3 Date: Sun, 11 Sep 2016 23:30:04 +0200
4 Subject: [PATCH] jailhouse: Add simple debug console via the hypervisor
6 Jailhouse allows explicitly enabled cells to write character-wise
7 messages to the hypervisor debug console. Make use of this for a
8 platform-agnostic boot diagnosis channel, specifically for non-root
9 cells. This also comes with earlycon support.
11 Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
12 (cherry picked from commit 60685bd589aef4972d20724863079edf2039eaa2)
13 From http://git.kiszka.org/?p=linux.git;a=shortlog;h=refs/heads/queues/jailhouse
16 drivers/virt/Kconfig | 11 +++++
17 drivers/virt/Makefile | 1 +
18 drivers/virt/jailhouse_dbgcon.c | 103 ++++++++++++++++++++++++++++++++++++++++
19 4 files changed, 116 insertions(+)
20 create mode 100644 drivers/virt/jailhouse_dbgcon.c
24 @@ -8773,6 +8773,7 @@ L: jailhouse-dev@googlegroups.com
26 F: arch/x86/kernel/jailhouse.c
27 F: arch/x86/include/asm/jailhouse_para.h
28 +F: drivers/virt/jailhouse_dbgcon.c
30 JC42.4 TEMPERATURE SENSOR DRIVER
31 M: Guenter Roeck <linux@roeck-us.net>
32 --- a/drivers/virt/Kconfig
33 +++ b/drivers/virt/Kconfig
34 @@ -31,5 +31,16 @@ config FSL_HV_MANAGER
35 4) A kernel interface for receiving callbacks when a managed
38 +config JAILHOUSE_DBGCON
39 + tristate "Jailhouse console driver"
40 + depends on X86 || ARM || ARM64
42 + The Jailhouse hypervisor provides a simple write-only console for
43 + debugging the bootstrap process of its cells. This driver registers
44 + a console with the kernel to make use of it.
46 + Note that Jailhouse has to be configured to permit a cell the usage
47 + of the console interface.
49 source "drivers/virt/vboxguest/Kconfig"
51 --- a/drivers/virt/Makefile
52 +++ b/drivers/virt/Makefile
56 obj-$(CONFIG_FSL_HV_MANAGER) += fsl_hypervisor.o
57 +obj-$(CONFIG_JAILHOUSE_DBGCON) += jailhouse_dbgcon.o
60 +++ b/drivers/virt/jailhouse_dbgcon.c
62 +/* SPDX-License-Identifier: GPL-2.0 */
64 + * Console driver for running over the Jailhouse partitioning hypervisor
66 + * Copyright (c) Siemens AG, 2016-2018
69 + * Jan Kiszka <jan.kiszka@siemens.com>
72 +#include <linux/console.h>
73 +#include <linux/hypervisor.h>
74 +#include <linux/module.h>
75 +#include <linux/serial_core.h>
77 +#include <asm/alternative.h>
80 +#include <asm/opcodes-virt.h>
83 +#define JAILHOUSE_HC_DEBUG_CONSOLE_PUTC 8
85 +static void hypervisor_putc(char c)
87 +#if defined(CONFIG_X86)
91 + ALTERNATIVE(".byte 0x0f,0x01,0xc1", ".byte 0x0f,0x01,0xd9",
92 + X86_FEATURE_VMMCALL)
94 + : "a" (JAILHOUSE_HC_DEBUG_CONSOLE_PUTC), "D" (c)
96 +#elif defined(CONFIG_ARM)
97 + register u32 num_res asm("r0") = JAILHOUSE_HC_DEBUG_CONSOLE_PUTC;
98 + register u32 arg1 asm("r1") = c;
103 + : "r" (num_res), "r" (arg1)
105 +#elif defined(CONFIG_ARM64)
106 + register u64 num_res asm("x0") = JAILHOUSE_HC_DEBUG_CONSOLE_PUTC;
107 + register u64 arg1 asm("x1") = c;
112 + : "r" (num_res), "r" (arg1)
115 +#error Unsupported architecture.
119 +static void jailhouse_dbgcon_write(struct console *con, const char *s,
122 + while (count > 0) {
123 + hypervisor_putc(*s);
129 +static int __init early_jailhouse_dbgcon_setup(struct earlycon_device *device,
130 + const char *options)
132 + device->con->write = jailhouse_dbgcon_write;
136 +EARLYCON_DECLARE(jailhouse, early_jailhouse_dbgcon_setup);
138 +static struct console jailhouse_dbgcon = {
139 + .name = "jailhouse",
140 + .write = jailhouse_dbgcon_write,
141 + .flags = CON_PRINTBUFFER | CON_ANYTIME,
145 +static int __init jailhouse_dbgcon_init(void)
147 + if (!jailhouse_paravirt())
150 + register_console(&jailhouse_dbgcon);
154 +static void __exit jailhouse_dbgcon_exit(void)
156 + unregister_console(&jailhouse_dbgcon);
159 +module_init(jailhouse_dbgcon_init);
160 +module_exit(jailhouse_dbgcon_exit);
162 +MODULE_LICENSE("GPL v2");
163 +MODULE_DESCRIPTION("Jailhouse debug console driver");
164 +MODULE_AUTHOR("Jan Kiszka <jan.kiszka@siemens.com>");