Patchwork [13/20,MIPS] qdev: add a rtc forwarder device

login
register
mail settings
Submitter Hervé Poussineau
Date Aug. 1, 2010, 5:37 p.m.
Message ID <1280684242-19611-13-git-send-email-hpoussin@reactos.org>
Download mbox | patch
Permalink /patch/60485/
State New
Headers show

Comments

Hervé Poussineau - Aug. 1, 2010, 5:37 p.m.
Use it in Jazz emulation

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 hw/mc146818rtc.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/mips_jazz.c   |   28 +++-------------------------
 2 files changed, 56 insertions(+), 26 deletions(-)

Patch

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 2b91fa8..674d24f 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -28,6 +28,8 @@ 
 #include "apic.h"
 #include "isa.h"
 #include "mc146818rtc.h"
+#include "sysbus.h"
+#include "qdev-addr.h"
 
 //#define DEBUG_CMOS
 //#define DEBUG_COALESCED
@@ -631,7 +633,6 @@  ISADevice *rtc_init(int base_year, qemu_irq intercept_irq)
 static ISADeviceInfo mc146818rtc_info = {
     .qdev.name     = "mc146818rtc",
     .qdev.size     = sizeof(RTCState),
-    .qdev.no_user  = 1,
     .qdev.vmsd     = &vmstate_rtc,
     .init          = rtc_initfn,
     .qdev.props    = (Property[]) {
@@ -640,8 +641,59 @@  static ISADeviceInfo mc146818rtc_info = {
     }
 };
 
+static uint32_t rtc_forward_readb(void *opaque, target_phys_addr_t addr)
+{
+    return cpu_inw(0x71);
+}
+
+static void rtc_forward_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
+{
+    cpu_outw(0x71, val & 0xff);
+}
+
+static CPUReadMemoryFunc * const rtc_forward_read[3] = {
+    rtc_forward_readb,
+    rtc_forward_readb,
+    rtc_forward_readb,
+};
+
+static CPUWriteMemoryFunc * const rtc_forward_write[3] = {
+    rtc_forward_writeb,
+    rtc_forward_writeb,
+    rtc_forward_writeb,
+};
+
+typedef struct RtcForwardState {
+    SysBusDevice busdev;
+    target_phys_addr_t iobase;
+    uint32_t size;
+} RtcForwardState;
+
+static int rtc_forward_init(SysBusDevice *dev)
+{
+    RtcForwardState *s = FROM_SYSBUS(RtcForwardState, dev);
+    int io;
+
+    io = cpu_register_io_memory(rtc_forward_read, rtc_forward_write, s);
+    cpu_register_physical_memory(s->iobase, s->size, io);
+
+    return 0;
+}
+
+static SysBusDeviceInfo rtc_forward_info = {
+    .qdev.name  = "rtc-forward",
+    .qdev.size  = sizeof(RtcForwardState),
+    .init       = rtc_forward_init,
+    .qdev.props = (Property[]) {
+        DEFINE_PROP_TADDR("iobase", RtcForwardState, iobase, 0x80004000),
+        DEFINE_PROP_HEX32("size", RtcForwardState, size, 0x1000),
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
 static void mc146818rtc_register(void)
 {
     isa_qdev_register(&mc146818rtc_info);
+    sysbus_register_withprop(&rtc_forward_info);
 }
 device_init(mc146818rtc_register)
diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index c4f3721..b9c6b62 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -44,28 +44,6 @@  enum jazz_model_e
     JAZZ_PICA61,
 };
 
-static uint32_t rtc_readb(void *opaque, target_phys_addr_t addr)
-{
-    return cpu_inw(0x71);
-}
-
-static void rtc_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
-{
-    cpu_outw(0x71, val & 0xff);
-}
-
-static CPUReadMemoryFunc * const rtc_read[3] = {
-    rtc_readb,
-    rtc_readb,
-    rtc_readb,
-};
-
-static CPUWriteMemoryFunc * const rtc_write[3] = {
-    rtc_writeb,
-    rtc_writeb,
-    rtc_writeb,
-};
-
 static void dma_dummy_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     /* Nothing to do. That is only to ensure that
@@ -128,7 +106,7 @@  void mips_jazz_init (ram_addr_t ram_size,
     qemu_irq *rc4030, *i8259;
     rc4030_dma *dmas;
     void* rc4030_opaque;
-    int s_rtc, s_dma_dummy;
+    int s_dma_dummy;
     NICInfo *nd;
     PITState *pit;
     DriveInfo *fds[MAX_FD];
@@ -251,8 +229,8 @@  void mips_jazz_init (ram_addr_t ram_size,
 
     /* Real time clock */
     rtc_init(1980, NULL);
-    s_rtc = cpu_register_io_memory(rtc_read, rtc_write, NULL);
-    cpu_register_physical_memory(0x80004000, 0x00001000, s_rtc);
+    dev = qdev_create(NULL, "rtc-forward");
+    qdev_init_nofail(dev);
 
     /* Keyboard (i8042) */
     rc4030_create_simple("rc4030-i8042");