aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2015-02-10 23:53:01 -0500
committerRusty Russell <rusty@rustcorp.com.au>2015-02-11 01:17:43 -0500
commite8330d9bc1f7af7737500aebd3fc1f488e3dbb71 (patch)
treecd969719b32d065937524a733eb06c90d5496419 /tools
parentb3e28b65de254570140832cf7c95255ab4d501bb (diff)
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 <rusty@rustcorp.com.au>
Diffstat (limited to 'tools')
-rw-r--r--tools/lguest/lguest.c17
1 files changed, 14 insertions, 3 deletions
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;
71#include "../../include/uapi/linux/virtio_config.h" 71#include "../../include/uapi/linux/virtio_config.h"
72#include "../../include/uapi/linux/virtio_net.h" 72#include "../../include/uapi/linux/virtio_net.h"
73#include "../../include/uapi/linux/virtio_blk.h" 73#include "../../include/uapi/linux/virtio_blk.h"
74#include <linux/virtio_console.h> 74#include "../../include/uapi/linux/virtio_console.h"
75#include "../../include/uapi/linux/virtio_rng.h" 75#include "../../include/uapi/linux/virtio_rng.h"
76#include <linux/virtio_ring.h> 76#include <linux/virtio_ring.h>
77#include "../../include/uapi/linux/virtio_pci.h" 77#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)
1687 goto write_through16; 1687 goto write_through16;
1688 case offsetof(struct virtio_pci_mmio, isr): 1688 case offsetof(struct virtio_pci_mmio, isr):
1689 errx(1, "%s: Unexpected write to isr", d->name); 1689 errx(1, "%s: Unexpected write to isr", d->name);
1690 /* Weird corner case: write to emerg_wr of console */
1691 case sizeof(struct virtio_pci_mmio)
1692 + offsetof(struct virtio_console_config, emerg_wr):
1693 if (strcmp(d->name, "console") == 0) {
1694 char c = val;
1695 write(STDOUT_FILENO, &c, 1);
1696 goto write_through32;
1697 }
1698 /* Fall through... */
1690 default: 1699 default:
1691 errx(1, "%s: Unexpected write to offset %u", d->name, off); 1700 errx(1, "%s: Unexpected write to offset %u", d->name, off);
1692 } 1701 }
@@ -2048,6 +2057,7 @@ static struct device *new_pci_device(const char *name, u16 type,
2048static void setup_console(void) 2057static void setup_console(void)
2049{ 2058{
2050 struct device *dev; 2059 struct device *dev;
2060 struct virtio_console_config conf;
2051 2061
2052 /* If we can save the initial standard input settings... */ 2062 /* If we can save the initial standard input settings... */
2053 if (tcgetattr(STDIN_FILENO, &orig_term) == 0) { 2063 if (tcgetattr(STDIN_FILENO, &orig_term) == 0) {
@@ -2075,8 +2085,9 @@ static void setup_console(void)
2075 add_pci_virtqueue(dev, console_input); 2085 add_pci_virtqueue(dev, console_input);
2076 add_pci_virtqueue(dev, console_output); 2086 add_pci_virtqueue(dev, console_output);
2077 2087
2078 /* There's no configuration area for this device. */ 2088 /* We need a configuration area for the emerg_wr early writes. */
2079 no_device_config(dev); 2089 add_pci_feature(dev, VIRTIO_CONSOLE_F_EMERG_WRITE);
2090 set_device_config(dev, &conf, sizeof(conf));
2080 2091
2081 verbose("device %u: console\n", devices.device_num); 2092 verbose("device %u: console\n", devices.device_num);
2082} 2093}