File S390-qemu-early-printk.patch of Package kvm

From 23b25f548a3640099a8524798cc6379180262c50 Mon Sep 17 00:00:00 2001
From: Alexander Graf <agraf@suse.de>
Date: Mon, 19 Oct 2009 12:21:55 +0200
Subject: [PATCH 2/4] 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 <agraf@suse.de>
---
 hw/s390-virtio.c    |    3 +++
 hw/virtio-console.c |    7 +++++++
 hw/virtio-console.h |    2 ++
 3 files changed, 12 insertions(+), 0 deletions(-)

Index: qemu-kvm-0.14.50/hw/s390-virtio.c
===================================================================
--- qemu-kvm-0.14.50.orig/hw/s390-virtio.c
+++ qemu-kvm-0.14.50/hw/s390-virtio.c
@@ -99,6 +99,9 @@ int s390_virtio_hypercall(CPUState *env,
             }
         } 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);
         }
         break;
     case KVM_S390_VIRTIO_RESET:
Index: qemu-kvm-0.14.50/hw/virtio-console.c
===================================================================
--- qemu-kvm-0.14.50.orig/hw/virtio-console.c
+++ qemu-kvm-0.14.50/hw/virtio-console.c
@@ -19,6 +19,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_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)
Index: qemu-kvm-0.14.50/hw/virtio-serial.h
===================================================================
--- qemu-kvm-0.14.50.orig/hw/virtio-serial.h
+++ qemu-kvm-0.14.50/hw/virtio-serial.h
@@ -204,4 +204,7 @@ size_t virtio_serial_guest_ready(VirtIOS
  */
 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
Index: qemu-kvm-0.14.50/hw/virtio-serial-bus.c
===================================================================
--- qemu-kvm-0.14.50.orig/hw/virtio-serial-bus.c
+++ qemu-kvm-0.14.50/hw/virtio-serial-bus.c
@@ -51,7 +51,7 @@ struct VirtIOSerial {
     struct virtio_console_config config;
 };
 
-static VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id)
+VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id)
 {
     VirtIOSerialPort *port;