Patchwork [07/20,MIPS] qdev: convert parallel port to rc4030 device

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

Comments

Hervé Poussineau - Aug. 1, 2010, 5:37 p.m.
Use it in Jazz emulation
Remove parallel_mm_init() function, which is not used anymore

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 hw/mips_jazz.c |    5 ++-
 hw/parallel.c  |   58 +++++++++++++++++++++++++++++++++++++++++++++----------
 hw/pc.h        |    2 +-
 3 files changed, 51 insertions(+), 14 deletions(-)

Patch

diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index 9663a3c..a027559 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -271,8 +271,9 @@  void mips_jazz_init (ram_addr_t ram_size,
     }
 
     /* Parallel port */
-    if (parallel_hds[0])
-        parallel_mm_init(0x80008000, 0, rc4030[0], parallel_hds[0]);
+    if (parallel_hds[0]) {
+        parallel_rc4030_init(parallel_hds[0]);
+    }
 
     /* Sound card */
     /* FIXME: missing Jazz sound at 0x8000c000, rc4030[2] */
diff --git a/hw/parallel.c b/hw/parallel.c
index 6b11672..cb36fba 100644
--- a/hw/parallel.c
+++ b/hw/parallel.c
@@ -27,6 +27,8 @@ 
 #include "isa.h"
 #include "pc.h"
 #include "sysemu.h"
+#include "rc4030.h"
+#include "qdev-addr.h"
 
 //#define DEBUG_PARALLEL
 
@@ -87,6 +89,13 @@  typedef struct ISAParallelState {
     ParallelState state;
 } ISAParallelState;
 
+typedef struct RC4030ParallelState {
+    RC4030Device dev;
+    target_phys_addr_t iobase;
+    uint32_t irq;
+    ParallelState state;
+} RC4030ParallelState;
+
 static void parallel_update_irq(ParallelState *s)
 {
     if (s->irq_pending)
@@ -446,6 +455,12 @@  static void parallel_reset(void *opaque)
     s->last_read_offset = ~0U;
 }
 
+static void parallel_rc4030_reset(DeviceState *d)
+{
+    RC4030ParallelState *rc4030 = container_of(d, RC4030ParallelState, dev.qdev);
+    parallel_reset(&rc4030->state);
+}
+
 static const int isa_parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc };
 
 static int parallel_isa_initfn(ISADevice *dev)
@@ -565,21 +580,28 @@  static CPUWriteMemoryFunc * const parallel_mm_write_sw[] = {
     &parallel_mm_writel,
 };
 
-/* If fd is zero, it means that the parallel device uses the console */
-ParallelState *parallel_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq, CharDriverState *chr)
+static int parallel_rc4030_initfn(RC4030Device *dev)
 {
-    ParallelState *s;
+    RC4030ParallelState *s = container_of(dev, RC4030ParallelState, dev);
     int io_sw;
 
-    s = qemu_mallocz(sizeof(ParallelState));
-    s->irq = irq;
-    s->chr = chr;
-    s->it_shift = it_shift;
-    qemu_register_reset(parallel_reset, s);
+    rc4030_init_irq(dev, &s->state.irq, s->irq);
+
+    io_sw = cpu_register_io_memory(parallel_mm_read_sw, parallel_mm_write_sw, &s->state);
+    cpu_register_physical_memory(s->iobase, 8, io_sw);
+
+    return 0;
+}
 
-    io_sw = cpu_register_io_memory(parallel_mm_read_sw, parallel_mm_write_sw, s);
-    cpu_register_physical_memory(base, 8 << it_shift, io_sw);
-    return s;
+ParallelState *parallel_rc4030_init(CharDriverState *chr)
+{
+    RC4030Device *dev;
+
+    dev = rc4030_create("rc4030-parallel");
+    qdev_prop_set_chr(&dev->qdev, "chardev", chr);
+    if (qdev_init(&dev->qdev) < 0)
+        return NULL;
+    return &DO_UPCAST(RC4030ParallelState, dev, dev)->state;
 }
 
 static ISADeviceInfo parallel_isa_info = {
@@ -595,9 +617,23 @@  static ISADeviceInfo parallel_isa_info = {
     },
 };
 
+static RC4030DeviceInfo parallel_rc4030_info = {
+    .qdev.name  = "rc4030-parallel",
+    .qdev.size  = sizeof(RC4030ParallelState),
+    .qdev.reset = parallel_rc4030_reset,
+    .init       = parallel_rc4030_initfn,
+    .qdev.props = (Property[]) {
+        DEFINE_PROP_TADDR("iobase", RC4030ParallelState, iobase, 0x80008000),
+        DEFINE_PROP_UINT32("irq", RC4030ParallelState, irq, 0),
+        DEFINE_PROP_CHR("chardev", RC4030ParallelState, state.chr),
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
 static void parallel_register_devices(void)
 {
     isa_qdev_register(&parallel_isa_info);
+    rc4030_qdev_register(&parallel_rc4030_info);
 }
 
 device_init(parallel_register_devices)
diff --git a/hw/pc.h b/hw/pc.h
index e078fd9..61b5fbb 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -23,7 +23,7 @@  void serial_set_frequency(SerialState *s, uint32_t frequency);
 
 typedef struct ParallelState ParallelState;
 ParallelState *parallel_init(int index, CharDriverState *chr);
-ParallelState *parallel_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq, CharDriverState *chr);
+ParallelState *parallel_rc4030_init(CharDriverState *chr);
 
 /* i8259.c */