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

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(-)

diff --git a/hw/s390-virtio.c b/hw/s390-virtio.c
index 50ffc82..df19729 100644
--- a/hw/s390-virtio.c
+++ b/hw/s390-virtio.c
@@ -97,6 +97,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:
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index 57f8f89..cd6cf20 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -105,6 +105,13 @@ static void vcon_event(void *opaque, int event)
     /* we will ignore any event for the time being */
 }
 
+void virtio_console_print_early(VirtIODevice *vdev, uint8_t *buf)
+{
+    VirtIOConsole *s = to_virtio_console(vdev);
+
+    qemu_chr_write(s->chr, buf, strlen((char*)buf));
+}
+
 static void virtio_console_save(QEMUFile *f, void *opaque)
 {
     VirtIOConsole *s = opaque;
diff --git a/hw/virtio-console.h b/hw/virtio-console.h
index 84d0717..f3ccc3c 100644
--- a/hw/virtio-console.h
+++ b/hw/virtio-console.h
@@ -16,4 +16,6 @@
 /* The ID for virtio console */
 #define VIRTIO_ID_CONSOLE 3
 
+void virtio_console_print_early(VirtIODevice *vdev, uint8_t *buf);
+
 #endif
-- 
1.6.0.2