From e8330d9bc1f7af7737500aebd3fc1f488e3dbb71 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 11 Feb 2015 15:23:01 +1030 Subject: lguest: support emerg_wr in console device in example launcher. This is a magic register which causes a character to be outputted: it can be used even before the device is configured. Signed-off-by: Rusty Russell --- tools/lguest/lguest.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/lguest/lguest.c b/tools/lguest/lguest.c index b5ac73525f6d..8959ac246668 100644 --- a/tools/lguest/lguest.c +++ b/tools/lguest/lguest.c @@ -71,7 +71,7 @@ typedef uint8_t u8; #include "../../include/uapi/linux/virtio_config.h" #include "../../include/uapi/linux/virtio_net.h" #include "../../include/uapi/linux/virtio_blk.h" -#include +#include "../../include/uapi/linux/virtio_console.h" #include "../../include/uapi/linux/virtio_rng.h" #include #include "../../include/uapi/linux/virtio_pci.h" @@ -1687,6 +1687,15 @@ static void emulate_mmio_write(struct device *d, u32 off, u32 val, u32 mask) goto write_through16; case offsetof(struct virtio_pci_mmio, isr): errx(1, "%s: Unexpected write to isr", d->name); + /* Weird corner case: write to emerg_wr of console */ + case sizeof(struct virtio_pci_mmio) + + offsetof(struct virtio_console_config, emerg_wr): + if (strcmp(d->name, "console") == 0) { + char c = val; + write(STDOUT_FILENO, &c, 1); + goto write_through32; + } + /* Fall through... */ default: errx(1, "%s: Unexpected write to offset %u", d->name, off); } @@ -2048,6 +2057,7 @@ static struct device *new_pci_device(const char *name, u16 type, static void setup_console(void) { struct device *dev; + struct virtio_console_config conf; /* If we can save the initial standard input settings... */ if (tcgetattr(STDIN_FILENO, &orig_term) == 0) { @@ -2075,8 +2085,9 @@ static void setup_console(void) add_pci_virtqueue(dev, console_input); add_pci_virtqueue(dev, console_output); - /* There's no configuration area for this device. */ - no_device_config(dev); + /* We need a configuration area for the emerg_wr early writes. */ + add_pci_feature(dev, VIRTIO_CONSOLE_F_EMERG_WRITE); + set_device_config(dev, &conf, sizeof(conf)); verbose("device %u: console\n", devices.device_num); } -- cgit v1.2.3-59-g8ed1b