Sparc32: convert eccmemctl to qdev
authorBlue Swirl <blauwirbel@gmail.com>
Sun, 12 Jul 2009 08:16:55 +0000 (08:16 +0000)
committerBlue Swirl <blauwirbel@gmail.com>
Sun, 12 Jul 2009 08:16:55 +0000 (08:16 +0000)
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
hw/eccmemctl.c
hw/sun4m.h

index 3430481c004c304356745e3e592f3156f3b82cba..0c9708e3e92925c6d03e2db278ba4ca79c6a1785 100644 (file)
@@ -21,9 +21,9 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include "hw.h"
+
 #include "sun4m.h"
-#include "sysemu.h"
+#include "sysbus.h"
 
 //#define DEBUG_ECC
 
 #define ECC_DIAG_MASK  (ECC_DIAG_SIZE - 1)
 
 typedef struct ECCState {
+    SysBusDevice busdev;
     qemu_irq irq;
     uint32_t regs[ECC_NREGS];
     uint8_t diag[ECC_DIAG_SIZE];
@@ -314,27 +315,46 @@ static void ecc_reset(void *opaque)
     s->regs[ECC_ECR1] = 0;
 }
 
-void * ecc_init(target_phys_addr_t base, qemu_irq irq, uint32_t version)
+static void ecc_init1(SysBusDevice *dev)
 {
     int ecc_io_memory;
-    ECCState *s;
-
-    s = qemu_mallocz(sizeof(ECCState));
-
-    s->version = version;
-    s->regs[0] = version;
-    s->irq = irq;
+    ECCState *s = FROM_SYSBUS(ECCState, dev);
 
+    sysbus_init_irq(dev, &s->irq);
+    s->version = qdev_get_prop_int(&dev->qdev, "version", -1);
+    s->regs[0] = s->version;
     ecc_io_memory = cpu_register_io_memory(ecc_mem_read, ecc_mem_write, s);
-    cpu_register_physical_memory(base, ECC_SIZE, ecc_io_memory);
-    if (version == ECC_MCC) { // SS-600MP only
+    sysbus_init_mmio(dev, ECC_SIZE, ecc_io_memory);
+
+    if (s->version == ECC_MCC) { // SS-600MP only
         ecc_io_memory = cpu_register_io_memory(ecc_diag_mem_read,
                                                ecc_diag_mem_write, s);
-        cpu_register_physical_memory(base + 0x1000, ECC_DIAG_SIZE,
-                                     ecc_io_memory);
+        sysbus_init_mmio(dev, ECC_DIAG_SIZE, ecc_io_memory);
     }
-    register_savevm("ECC", base, 3, ecc_save, ecc_load, s);
+    register_savevm("ECC", -1, 3, ecc_save, ecc_load, s);
     qemu_register_reset(ecc_reset, s);
     ecc_reset(s);
-    return s;
 }
+
+void ecc_init(target_phys_addr_t base, qemu_irq irq, uint32_t version)
+{
+    DeviceState *dev;
+    SysBusDevice *s;
+
+    dev = qdev_create(NULL, "ecc");
+    qdev_set_prop_int(dev, "version", version);
+    qdev_init(dev);
+    s = sysbus_from_qdev(dev);
+    sysbus_connect_irq(s, 0, irq);
+    sysbus_mmio_map(s, 0, base);
+    if (version == ECC_MCC) { // SS-600MP only
+        sysbus_mmio_map(s, 1, base + 0x1000);
+    }
+}
+
+static void ecc_register_devices(void)
+{
+    sysbus_register_dev("ecc", sizeof(ECCState), ecc_init1);
+}
+
+device_init(ecc_register_devices)
index c5605f48d96b1600ba682221f12e59c95c41d7c4..1ac4e88da8d3a6db834803aeeae3d12e875ca1e7 100644 (file)
@@ -63,6 +63,6 @@ void cs_init(target_phys_addr_t base, int irq, void *intctl);
 #include "sparc32_dma.h"
 
 /* eccmemctl.c */
-void *ecc_init(target_phys_addr_t base, qemu_irq irq, uint32_t version);
+void ecc_init(target_phys_addr_t base, qemu_irq irq, uint32_t version);
 
 #endif