From bf5b9c24c54e39fb1a62a5d384fd9d26b156e11f Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Mon, 19 Oct 2009 12:21:55 +0200 Subject: [PATCH] Implement early printk in virtio-console On our S390x Virtio machine we don't have anywhere to display early printks on, because we don't know about VGA or serial ports. So instead we just forward everything to the virtio console that we created anyways. Signed-off-by: Alexander Graf Conflicts: hw/s390-virtio.c --- hw/s390x/s390-virtio.c | 3 +++ hw/virtio-console.c | 8 ++++++++ hw/virtio-serial-bus.c | 2 +- hw/virtio-serial.h | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c index e25c330320..0bde3b0ded 100644 --- a/hw/s390x/s390-virtio.c +++ b/hw/s390x/s390-virtio.c @@ -76,6 +76,9 @@ static int s390_virtio_hcall_notify(const uint64_t *args) } } else { /* Early printk */ + uint8_t *p = (uint8_t *)qemu_get_ram_ptr(mem); + VirtIOS390Device *dev = s390_virtio_bus_console(s390_bus); + virtio_console_print_early(dev->vdev, p); } return r; } diff --git a/hw/virtio-console.c b/hw/virtio-console.c index 46072a086f..eec0ef9888 100644 --- a/hw/virtio-console.c +++ b/hw/virtio-console.c @@ -20,6 +20,14 @@ typedef struct VirtConsole { CharDriverState *chr; } VirtConsole; +void virtio_console_print_early(VirtIODevice *vdev, uint8_t *buf) +{ + VirtIOSerial *vser = (void*)vdev; + VirtIOSerialPort *port = find_port_by_id(vser, 0); + VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port); + + qemu_chr_fe_write(vcon->chr, buf, strlen((char*)buf)); +} /* Callback function that's called when the guest sends us data */ static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len) diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index aa7d0d7fc7..9227e4fd6b 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -66,7 +66,7 @@ struct VirtIOSerial { struct VirtIOSerialPostLoad *post_load; }; -static VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id) +VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id) { VirtIOSerialPort *port; diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h index 16e39820a2..f250b758c3 100644 --- a/hw/virtio-serial.h +++ b/hw/virtio-serial.h @@ -205,4 +205,7 @@ size_t virtio_serial_guest_ready(VirtIOSerialPort *port); */ void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle); +void virtio_console_print_early(VirtIODevice *vdev, uint8_t *buf); +VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id); + #endif