qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Hervé Poussineau" <hpoussin@reactos.org>
To: qemu-devel@nongnu.org
Cc: "Hervé Poussineau" <hpoussin@reactos.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"John Snow" <jsnow@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [PATCH v3 08/19] i8257: QOM'ify
Date: Tue, 26 Jan 2016 22:32:13 +0100	[thread overview]
Message-ID: <1453843944-26833-9-git-send-email-hpoussin@reactos.org> (raw)
In-Reply-To: <1453843944-26833-1-git-send-email-hpoussin@reactos.org>

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 hw/dma/i8257.c | 160 ++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 107 insertions(+), 53 deletions(-)

diff --git a/hw/dma/i8257.c b/hw/dma/i8257.c
index 186a48a..2eb6d42 100644
--- a/hw/dma/i8257.c
+++ b/hw/dma/i8257.c
@@ -26,6 +26,10 @@
 #include "qemu/main-loop.h"
 #include "trace.h"
 
+#define TYPE_I8257 "i8257"
+#define I8257(obj) \
+    OBJECT_CHECK(I8257State, (obj), TYPE_I8257)
+
 /* #define DEBUG_DMA */
 
 #define dolog(...) fprintf (stderr, "dma: " __VA_ARGS__)
@@ -53,11 +57,17 @@ typedef struct I8257Regs {
 #define COUNT 1
 
 typedef struct I8257State {
+    ISADevice parent_obj;
+
+    int32_t base;
+    int32_t page_base;
+    int32_t pageh_base;
+    int32_t dshift;
+
     uint8_t status;
     uint8_t command;
     uint8_t mask;
     uint8_t flip_flop;
-    int dshift;
     I8257Regs regs[4];
     MemoryRegion channel_io;
     MemoryRegion cont_io;
@@ -67,7 +77,7 @@ typedef struct I8257State {
     int running;
 } I8257State;
 
-static I8257State dma_controllers[2];
+static I8257State *dma_controllers[2];
 
 enum {
     CMD_MEMORY_TO_MEMORY = 0x01,
@@ -313,7 +323,7 @@ static uint64_t i8257_read_cont(void *opaque, hwaddr nport, unsigned size)
 
 int DMA_get_channel_mode (int nchan)
 {
-    return dma_controllers[nchan > 3].regs[nchan & 3].mode;
+    return dma_controllers[nchan > 3]->regs[nchan & 3].mode;
 }
 
 void DMA_hold_DREQ (int nchan)
@@ -323,8 +333,8 @@ void DMA_hold_DREQ (int nchan)
     ncont = nchan > 3;
     ichan = nchan & 3;
     linfo ("held cont=%d chan=%d\n", ncont, ichan);
-    dma_controllers[ncont].status |= 1 << (ichan + 4);
-    i8257_dma_run(&dma_controllers[ncont]);
+    dma_controllers[ncont]->status |= 1 << (ichan + 4);
+    i8257_dma_run(dma_controllers[ncont]);
 }
 
 void DMA_release_DREQ (int nchan)
@@ -334,8 +344,8 @@ void DMA_release_DREQ (int nchan)
     ncont = nchan > 3;
     ichan = nchan & 3;
     linfo ("released cont=%d chan=%d\n", ncont, ichan);
-    dma_controllers[ncont].status &= ~(1 << (ichan + 4));
-    i8257_dma_run(&dma_controllers[ncont]);
+    dma_controllers[ncont]->status &= ~(1 << (ichan + 4));
+    i8257_dma_run(dma_controllers[ncont]);
 }
 
 static void i8257_channel_run(I8257State *d, int ichan)
@@ -405,14 +415,14 @@ void DMA_register_channel (int nchan,
     ncont = nchan > 3;
     ichan = nchan & 3;
 
-    r = dma_controllers[ncont].regs + ichan;
+    r = dma_controllers[ncont]->regs + ichan;
     r->transfer_handler = transfer_handler;
     r->opaque = opaque;
 }
 
 int DMA_read_memory (int nchan, void *buf, int pos, int len)
 {
-    I8257Regs *r = &dma_controllers[nchan > 3].regs[nchan & 3];
+    I8257Regs *r = &dma_controllers[nchan > 3]->regs[nchan & 3];
     hwaddr addr = ((r->pageh & 0x7f) << 24) | (r->page << 16) | r->now[ADDR];
 
     if (r->mode & 0x20) {
@@ -434,7 +444,7 @@ int DMA_read_memory (int nchan, void *buf, int pos, int len)
 
 int DMA_write_memory (int nchan, void *buf, int pos, int len)
 {
-    I8257Regs *r = &dma_controllers[nchan > 3].regs[nchan & 3];
+    I8257Regs *r = &dma_controllers[nchan > 3]->regs[nchan & 3];
     hwaddr addr = ((r->pageh & 0x7f) << 24) | (r->page << 16) | r->now[ADDR];
 
     if (r->mode & 0x20) {
@@ -459,15 +469,15 @@ int DMA_write_memory (int nchan, void *buf, int pos, int len)
  */
 void DMA_schedule(void)
 {
-    if (dma_controllers[0].dma_bh_scheduled ||
-        dma_controllers[1].dma_bh_scheduled) {
+    if (dma_controllers[0]->dma_bh_scheduled ||
+        dma_controllers[1]->dma_bh_scheduled) {
         qemu_notify_event();
     }
 }
 
-static void i8257_reset(void *opaque)
+static void i8257_reset(DeviceState *dev)
 {
-    I8257State *d = opaque;
+    I8257State *d = I8257(dev);
     i8257_write_cont(d, (0x05 << d->dshift), 0, 1);
 }
 
@@ -513,40 +523,6 @@ static const MemoryRegionOps cont_io_ops = {
     },
 };
 
-/* dshift = 0: 8 bit DMA, 1 = 16 bit DMA */
-static void dma_init2(I8257State *d, int base, int dshift,
-                      int page_base, int pageh_base)
-{
-    int i;
-
-    d->dshift = dshift;
-
-    memory_region_init_io(&d->channel_io, NULL, &channel_io_ops, d,
-                          "dma-chan", 8 << d->dshift);
-    memory_region_add_subregion(isa_address_space_io(NULL),
-                                base, &d->channel_io);
-
-    isa_register_portio_list(NULL, page_base, page_portio_list, d,
-                             "dma-page");
-    if (pageh_base >= 0) {
-        isa_register_portio_list(NULL, pageh_base, pageh_portio_list, d,
-                                 "dma-pageh");
-    }
-
-    memory_region_init_io(&d->cont_io, NULL, &cont_io_ops, d, "dma-cont",
-                          8 << d->dshift);
-    memory_region_add_subregion(isa_address_space_io(NULL),
-                                base + (8 << d->dshift), &d->cont_io);
-
-    qemu_register_reset(i8257_reset, d);
-    i8257_reset(d);
-    for (i = 0; i < ARRAY_SIZE (d->regs); ++i) {
-        d->regs[i].transfer_handler = i8257_phony_handler;
-    }
-
-    d->dma_bh = qemu_bh_new(i8257_dma_run, d);
-}
-
 static const VMStateDescription vmstate_i8257_regs = {
     .name = "dma_regs",
     .version_id = 1,
@@ -571,7 +547,7 @@ static int i8257_post_load(void *opaque, int version_id)
     return 0;
 }
 
-static const VMStateDescription vmstate_dma = {
+static const VMStateDescription vmstate_i8257 = {
     .name = "dma",
     .version_id = 1,
     .minimum_version_id = 1,
@@ -587,10 +563,88 @@ static const VMStateDescription vmstate_dma = {
     }
 };
 
+static void i8257_realize(DeviceState *dev, Error **errp)
+{
+    ISADevice *isa = ISA_DEVICE(dev);
+    I8257State *d = I8257(dev);
+    int i;
+
+    memory_region_init_io(&d->channel_io, NULL, &channel_io_ops, d,
+                          "dma-chan", 8 << d->dshift);
+    memory_region_add_subregion(isa_address_space_io(isa),
+                                d->base, &d->channel_io);
+
+    isa_register_portio_list(isa, d->page_base, page_portio_list, d,
+                             "dma-page");
+    if (d->pageh_base >= 0) {
+        isa_register_portio_list(isa, d->pageh_base, pageh_portio_list, d,
+                                 "dma-pageh");
+    }
+
+    memory_region_init_io(&d->cont_io, OBJECT(isa), &cont_io_ops, d,
+                          "dma-cont", 8 << d->dshift);
+    memory_region_add_subregion(isa_address_space_io(isa),
+                                d->base + (8 << d->dshift), &d->cont_io);
+
+    for (i = 0; i < ARRAY_SIZE(d->regs); ++i) {
+        d->regs[i].transfer_handler = i8257_phony_handler;
+    }
+
+    d->dma_bh = qemu_bh_new(i8257_dma_run, d);
+}
+
+static Property i8257_properties[] = {
+    DEFINE_PROP_INT32("base", I8257State, base, 0x00),
+    DEFINE_PROP_INT32("page-base", I8257State, page_base, 0x80),
+    DEFINE_PROP_INT32("pageh-base", I8257State, pageh_base, 0x480),
+    DEFINE_PROP_INT32("dshift", I8257State, dshift, 0),
+    DEFINE_PROP_END_OF_LIST()
+};
+
+static void i8257_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = i8257_realize;
+    dc->reset = i8257_reset;
+    dc->vmsd = &vmstate_i8257;
+    dc->props = i8257_properties;
+}
+
+static const TypeInfo i8257_info = {
+    .name = TYPE_I8257,
+    .parent = TYPE_ISA_DEVICE,
+    .instance_size = sizeof(I8257State),
+    .class_init = i8257_class_init,
+};
+
+static void i8257_register_types(void)
+{
+    type_register_static(&i8257_info);
+}
+
+type_init(i8257_register_types)
+
 void DMA_init(ISABus *bus, int high_page_enable)
 {
-    dma_init2(&dma_controllers[0], 0x00, 0, 0x80, high_page_enable ? 0x480 : -1);
-    dma_init2(&dma_controllers[1], 0xc0, 1, 0x88, high_page_enable ? 0x488 : -1);
-    vmstate_register (NULL, 0, &vmstate_dma, &dma_controllers[0]);
-    vmstate_register (NULL, 1, &vmstate_dma, &dma_controllers[1]);
+    ISADevice *isa1, *isa2;
+    DeviceState *d;
+
+    isa1 = isa_create(bus, TYPE_I8257);
+    d = DEVICE(isa1);
+    qdev_prop_set_int32(d, "base", 0x00);
+    qdev_prop_set_int32(d, "page-base", 0x80);
+    qdev_prop_set_int32(d, "pageh-base", high_page_enable ? 0x480 : -1);
+    qdev_prop_set_int32(d, "dshift", 0);
+    qdev_init_nofail(d);
+    dma_controllers[0] = I8257(d);
+
+    isa2 = isa_create(bus, TYPE_I8257);
+    d = DEVICE(isa2);
+    qdev_prop_set_int32(d, "base", 0xc0);
+    qdev_prop_set_int32(d, "page-base", 0x88);
+    qdev_prop_set_int32(d, "pageh-base", high_page_enable ? 0x488 : -1);
+    qdev_prop_set_int32(d, "dshift", 1);
+    qdev_init_nofail(d);
+    dma_controllers[1] = I8257(d);
 }
-- 
2.1.4

  parent reply	other threads:[~2016-01-26 21:32 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-26 21:32 [Qemu-devel] [PATCH v3 00/19] ISA DMA controllers cleanup (i8257, i82374) Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 01/19] i82374: device only existed as ISA device, so simplify device Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 02/19] i8257: pass ISA bus to DMA_init() function Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 03/19] i8257: rename struct dma_cont to I8257State Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 04/19] i8257: rename struct dma_regs to I8257Regs Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 05/19] i8257: rename functions to start with i8257_ prefix Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 06/19] i8257: make the DMA running method per controller Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 07/19] i8257: add missing const Hervé Poussineau
2016-01-26 21:32 ` Hervé Poussineau [this message]
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 09/19] i8257: move state definition to new independent header Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 10/19] isa: add an ISA DMA interface, and store it within the ISA bus Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 11/19] i8257: implement the IsaDma interface Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 12/19] magnum: disable floppy DMA for now Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 13/19] sparc: disable floppy DMA Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 14/19] sparc64: " Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 15/19] fdc: use IsaDma interface instead of global DMA_* functions Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 16/19] cs4231a: " Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 17/19] gus: " Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 18/19] sb16: " Hervé Poussineau
2016-01-26 21:32 ` [Qemu-devel] [PATCH v3 19/19] dma: remove now useless " Hervé Poussineau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453843944-26833-9-git-send-email-hpoussin@reactos.org \
    --to=hpoussin@reactos.org \
    --cc=jsnow@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).