45e84a0
From 0b23c5d40ea933cfece3b4f69427f79c8a23256d Mon Sep 17 00:00:00 2001
45e84a0
From: Stefan Weil <sw@weilnetz.de>
45e84a0
Date: Tue, 29 Nov 2011 06:34:48 +0100
45e84a0
Subject: [PATCH 01/25] malta: Fix regression (i8259 interrupts did not work)
45e84a0
45e84a0
Commit 5632ae46d5bda798e971dae48ebb318ac2c3686a passes the address
45e84a0
of i8259 to qemu_irq_proxy. i8259 is an auto variable with undefined
45e84a0
value outside of mips_malta_init.
45e84a0
45e84a0
This made the interrupt proxy unusable: either QEMU crashes, or
45e84a0
the interrupt handler was not called.
45e84a0
45e84a0
Ethernet for example no longer worked with MIPS Malta.
45e84a0
45e84a0
v2:
45e84a0
While v1 used a static variable for i8259, this patch introduces
45e84a0
a qdev for the malta machine. i8259 is now part of the device status.
45e84a0
This is a minimal qdev implementation to keep the patch small.
45e84a0
45e84a0
Signed-off-by: Stefan Weil <sw@weilnetz.de>
45e84a0
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
45e84a0
(cherry picked from commit e9b40fd34ceb23461083d505a444a389c094455b)
45e84a0
---
45e84a0
 hw/mips_malta.c |   39 +++++++++++++++++++++++++++++++++++----
45e84a0
 1 files changed, 35 insertions(+), 4 deletions(-)
45e84a0
45e84a0
diff --git a/hw/mips_malta.c b/hw/mips_malta.c
45e84a0
index bb49749..941b9bd 100644
45e84a0
--- a/hw/mips_malta.c
45e84a0
+++ b/hw/mips_malta.c
45e84a0
@@ -47,6 +47,7 @@
45e84a0
 #include "mc146818rtc.h"
45e84a0
 #include "blockdev.h"
45e84a0
 #include "exec-memory.h"
45e84a0
+#include "sysbus.h"             /* SysBusDevice */
45e84a0
45e84a0
 //#define DEBUG_BOARD_INIT
45e84a0
45e84a0
@@ -72,6 +73,11 @@ typedef struct {
45e84a0
     SerialState *uart;
45e84a0
 } MaltaFPGAState;
45e84a0
45e84a0
+typedef struct {
45e84a0
+    SysBusDevice busdev;
45e84a0
+    qemu_irq *i8259;
45e84a0
+} MaltaState;
45e84a0
+
45e84a0
 static ISADevice *pit;
45e84a0
45e84a0
 static struct _loaderparams {
45e84a0
@@ -775,7 +781,7 @@ void mips_malta_init (ram_addr_t ram_size,
45e84a0
     int64_t kernel_entry;
45e84a0
     PCIBus *pci_bus;
45e84a0
     CPUState *env;
45e84a0
-    qemu_irq *i8259 = NULL, *isa_irq;
45e84a0
+    qemu_irq *isa_irq;
45e84a0
     qemu_irq *cpu_exit_irq;
45e84a0
     int piix4_devfn;
45e84a0
     i2c_bus *smbus;
45e84a0
@@ -787,6 +793,11 @@ void mips_malta_init (ram_addr_t ram_size,
45e84a0
     int fl_sectors = 0;
45e84a0
     int be;
45e84a0
45e84a0
+    DeviceState *dev = qdev_create(NULL, "mips-malta");
45e84a0
+    MaltaState *s = DO_UPCAST(MaltaState, busdev.qdev, dev);
45e84a0
+
45e84a0
+    qdev_init_nofail(dev);
45e84a0
+
45e84a0
     /* Make sure the first 3 serial ports are associated with a device. */
45e84a0
     for(i = 0; i < 3; i++) {
45e84a0
         if (!serial_hds[i]) {
45e84a0
@@ -932,7 +943,7 @@ void mips_malta_init (ram_addr_t ram_size,
45e84a0
      * qemu_irq_proxy() adds an extra bit of indirection, allowing us
45e84a0
      * to resolve the isa_irq -> i8259 dependency after i8259 is initialized.
45e84a0
      */
45e84a0
-    isa_irq = qemu_irq_proxy(&i8259, 16);
45e84a0
+    isa_irq = qemu_irq_proxy(&s->i8259, 16);
45e84a0
45e84a0
     /* Northbridge */
45e84a0
     pci_bus = gt64120_register(isa_irq);
45e84a0
@@ -944,9 +955,9 @@ void mips_malta_init (ram_addr_t ram_size,
45e84a0
45e84a0
     /* Interrupt controller */
45e84a0
     /* The 8259 is attached to the MIPS CPU INT0 pin, ie interrupt 2 */
45e84a0
-    i8259 = i8259_init(env->irq[2]);
45e84a0
+    s->i8259 = i8259_init(env->irq[2]);
45e84a0
45e84a0
-    isa_bus_irqs(i8259);
45e84a0
+    isa_bus_irqs(s->i8259);
45e84a0
     pci_piix4_ide_init(pci_bus, hd, piix4_devfn + 1);
45e84a0
     usb_uhci_piix4_init(pci_bus, piix4_devfn + 2);
45e84a0
     smbus = piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100, isa_get_irq(9),
45e84a0
@@ -990,6 +1001,20 @@ void mips_malta_init (ram_addr_t ram_size,
45e84a0
     }
45e84a0
 }
45e84a0
45e84a0
+static int mips_malta_sysbus_device_init(SysBusDevice *sysbusdev)
45e84a0
+{
45e84a0
+    return 0;
45e84a0
+}
45e84a0
+
45e84a0
+static SysBusDeviceInfo mips_malta_device = {
45e84a0
+    .init = mips_malta_sysbus_device_init,
45e84a0
+    .qdev.name  = "mips-malta",
45e84a0
+    .qdev.size  = sizeof(MaltaState),
45e84a0
+    .qdev.props = (Property[]) {
45e84a0
+        DEFINE_PROP_END_OF_LIST(),
45e84a0
+    }
45e84a0
+};
45e84a0
+
45e84a0
 static QEMUMachine mips_malta_machine = {
45e84a0
     .name = "malta",
45e84a0
     .desc = "MIPS Malta Core LV",
45e84a0
@@ -998,9 +1023,15 @@ static QEMUMachine mips_malta_machine = {
45e84a0
     .is_default = 1,
45e84a0
 };
45e84a0
45e84a0
+static void mips_malta_device_init(void)
45e84a0
+{
45e84a0
+    sysbus_register_withprop(&mips_malta_device);
45e84a0
+}
45e84a0
+
45e84a0
 static void mips_malta_machine_init(void)
45e84a0
 {
45e84a0
     qemu_register_machine(&mips_malta_machine);
45e84a0
 }
45e84a0
45e84a0
+device_init(mips_malta_device_init);
45e84a0
 machine_init(mips_malta_machine_init);
45e84a0
-- 
45e84a0
1.7.7.5
45e84a0