Patchwork [08/20,MIPS] qdev: convert serial port to rc4030 device

login
register
mail settings
Submitter Hervé Poussineau
Date Aug. 1, 2010, 5:37 p.m.
Message ID <1280684242-19611-8-git-send-email-hpoussin@reactos.org>
Download mbox | patch
Permalink /patch/60478/
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/mips_jazz.c |   12 +-------
 hw/pc.h        |    1 +
 hw/serial.c    |   78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+), 10 deletions(-)

Patch

diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index a027559..1298bc1 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -256,18 +256,10 @@  void mips_jazz_init (ram_addr_t ram_size,
 
     /* Serial ports */
     if (serial_hds[0]) {
-#ifdef TARGET_WORDS_BIGENDIAN
-        serial_mm_init(0x80006000, 0, rc4030[8], 8000000/16, serial_hds[0], 1, 1);
-#else
-        serial_mm_init(0x80006000, 0, rc4030[8], 8000000/16, serial_hds[0], 1, 0);
-#endif
+        serial_rc4030_init(0, serial_hds[0]);
     }
     if (serial_hds[1]) {
-#ifdef TARGET_WORDS_BIGENDIAN
-        serial_mm_init(0x80007000, 0, rc4030[9], 8000000/16, serial_hds[1], 1, 1);
-#else
-        serial_mm_init(0x80007000, 0, rc4030[9], 8000000/16, serial_hds[1], 1, 0);
-#endif
+        serial_rc4030_init(1, serial_hds[1]);
     }
 
     /* Parallel port */
diff --git a/hw/pc.h b/hw/pc.h
index 61b5fbb..f5a479a 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -17,6 +17,7 @@  SerialState *serial_mm_init (target_phys_addr_t base, int it_shift,
                              CharDriverState *chr, int ioregister,
                              int be);
 SerialState *serial_isa_init(int index, CharDriverState *chr);
+SerialState *serial_rc4030_init(int index, CharDriverState *chr);
 void serial_set_frequency(SerialState *s, uint32_t frequency);
 
 /* parallel.c */
diff --git a/hw/serial.c b/hw/serial.c
index b66d13a..0c13cbb 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -28,6 +28,8 @@ 
 #include "pc.h"
 #include "qemu-timer.h"
 #include "sysemu.h"
+#include "rc4030.h"
+#include "qdev-addr.h"
 
 //#define DEBUG_SERIAL
 
@@ -155,6 +157,14 @@  typedef struct ISASerialState {
     SerialState state;
 } ISASerialState;
 
+typedef struct RC4030SerialState {
+    RC4030Device dev;
+    uint32_t index;
+    target_phys_addr_t iobase;
+    uint32_t irq;
+    SerialState state;
+} RC4030SerialState;
+
 static void serial_receive1(void *opaque, const uint8_t *buf, int size);
 
 static void fifo_clear(SerialState *s, int fifo)
@@ -964,6 +974,59 @@  SerialState *serial_mm_init (target_phys_addr_t base, int it_shift,
     return s;
 }
 
+static const target_phys_addr_t rc4030_serial_io[] = { 0x80006000, 0x80007000 };
+static const uint32_t rc4030_serial_irq[] = { 8, 9 };
+
+static int serial_rc4030_initfn(RC4030Device *dev)
+{
+    static int index;
+    RC4030SerialState *rc4030 = DO_UPCAST(RC4030SerialState, dev, dev);
+    SerialState *s = &rc4030->state;
+    int s_io;
+
+    if (rc4030->index == -1)
+        rc4030->index = index;
+    if (rc4030->index >= ARRAY_SIZE(rc4030_serial_io))
+        return -1;
+    if (rc4030->iobase == -1)
+        rc4030->iobase = rc4030_serial_io[rc4030->index];
+    if (rc4030->irq == -1)
+        rc4030->irq = rc4030_serial_irq[rc4030->index];
+    index++;
+
+    s->baudbase = 8000000 / 16;
+    rc4030_init_irq(dev, &s->irq, rc4030->irq);
+    serial_init_core(s);
+
+    s_io = cpu_register_io_memory(serial_mm_read_le,
+                                  serial_mm_write_le, s);
+    cpu_register_physical_memory(rc4030->iobase, 8, s_io);
+
+    return 0;
+}
+
+SerialState *serial_rc4030_init(int index, CharDriverState *chr)
+{
+    RC4030Device *dev;
+
+    dev = rc4030_create("rc4030-serial");
+    qdev_prop_set_uint32(&dev->qdev, "index", index);
+    qdev_prop_set_chr(&dev->qdev, "chardev", chr);
+    if (qdev_init(&dev->qdev) < 0)
+        return NULL;
+    return &DO_UPCAST(RC4030SerialState, dev, dev)->state;
+}
+
+static const VMStateDescription vmstate_rc4030_serial = {
+    .name = "serial",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields      = (VMStateField []) {
+        VMSTATE_STRUCT(state, RC4030SerialState, 0, vmstate_serial, SerialState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static ISADeviceInfo serial_isa_info = {
     .qdev.name  = "isa-serial",
     .qdev.size  = sizeof(ISASerialState),
@@ -978,9 +1041,24 @@  static ISADeviceInfo serial_isa_info = {
     },
 };
 
+static RC4030DeviceInfo serial_rc4030_info = {
+    .qdev.name  = "rc4030-serial",
+    .qdev.size  = sizeof(RC4030SerialState),
+    .qdev.vmsd  = &vmstate_rc4030_serial,
+    .init       = serial_rc4030_initfn,
+    .qdev.props = (Property[]) {
+        DEFINE_PROP_UINT32("index", RC4030SerialState, index,  -1),
+        DEFINE_PROP_TADDR("iobase", RC4030SerialState, iobase, -1),
+        DEFINE_PROP_UINT32("irq",   RC4030SerialState, irq,    -1),
+        DEFINE_PROP_CHR("chardev",  RC4030SerialState, state.chr),
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
 static void serial_register_devices(void)
 {
     isa_qdev_register(&serial_isa_info);
+    rc4030_qdev_register(&serial_rc4030_info);
 }
 
 device_init(serial_register_devices)