]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
lguest: support emerg_wr in console device in example launcher.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 11 Feb 2015 04:53:01 +0000 (15:23 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 11 Feb 2015 06:17:43 +0000 (16:47 +1030)
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 <rusty@rustcorp.com.au>
tools/lguest/lguest.c

index b5ac73525f6dee1b864cee38396125ef7d1d0f78..8959ac246668b85593dacf471009daca86f642dc 100644 (file)
@@ -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 <linux/virtio_console.h>
+#include "../../include/uapi/linux/virtio_console.h"
 #include "../../include/uapi/linux/virtio_rng.h"
 #include <linux/virtio_ring.h>
 #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);
 }