From: "Michael S. Tsirkin" <mst@redhat.com>
To: Paul Brook <paul@codesourcery.com>, Avi Kivity <avi@redhat.com>,
qemu-devel@nongnu.org, Carsten Otte <cotte@de.ibm.com>,
Christian Borntraeger <borntraeger@de.ibm.com>,
kraxel@redhat.com, markmc@redhat.com
Subject: [Qemu-devel] [PATCH 1/2] qemu/qdev: type safety in reset handler
Date: Tue, 15 Sep 2009 17:33:19 +0300 [thread overview]
Message-ID: <20090915143319.GB24708@redhat.com> (raw)
In-Reply-To: <cover.1253025151.git.mst@redhat.com>
Add type safety to qdev reset handlers, by declaring them as
DeviceState * rather than void *.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/qdev.c | 10 ++++++++--
hw/qdev.h | 3 ++-
hw/rtl8139.c | 10 +++++++---
hw/tcx.c | 11 +++++++----
4 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 43b1beb..4913f88 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -209,6 +209,12 @@ DeviceState *qdev_device_add(QemuOpts *opts)
return qdev;
}
+static void qdev_reset(void *opaque)
+{
+ DeviceState *dev = opaque;
+ dev->info->reset(dev);
+}
+
/* Initialize a device. Device properties should be set before calling
this function. IRQs and MMIO regions should be connected/mapped after
calling this function. */
@@ -220,7 +226,7 @@ int qdev_init(DeviceState *dev)
if (rc < 0)
return rc;
if (dev->info->reset)
- qemu_register_reset(dev->info->reset, dev);
+ qemu_register_reset(qdev_reset, dev);
if (dev->info->vmsd)
vmstate_register(-1, dev->info->vmsd, dev);
return 0;
@@ -234,7 +240,7 @@ void qdev_free(DeviceState *dev)
vmstate_unregister(dev->info->vmsd, dev);
#endif
if (dev->info->reset)
- qemu_unregister_reset(dev->info->reset, dev);
+ qemu_unregister_reset(qdev_reset, dev);
QLIST_REMOVE(dev, sibling);
qemu_free(dev);
}
diff --git a/hw/qdev.h b/hw/qdev.h
index 623ded5..61a252c 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -100,6 +100,7 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
/*** Device API. ***/
typedef int (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
+typedef void (*qdev_resetfn)(DeviceState *dev);
struct DeviceInfo {
const char *name;
@@ -110,7 +111,7 @@ struct DeviceInfo {
int no_user;
/* callbacks */
- QEMUResetHandler *reset;
+ qdev_resetfn reset;
/* device state */
const VMStateDescription *vmsd;
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 83cb1ff..fade985 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -1173,9 +1173,8 @@ static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize)
s->RxBufAddr = 0;
}
-static void rtl8139_reset(void *opaque)
+static void rtl8139_reset(RTL8139State *s)
{
- RTL8139State *s = opaque;
int i;
/* restore MAC address */
@@ -3488,10 +3487,15 @@ static int pci_rtl8139_init(PCIDevice *dev)
return 0;
}
+static void pci_rtl8139_reset(struct DeviceState *d)
+{
+ rtl8139_reset(container_of(d, RTL8139State, dev.qdev));
+}
+
static PCIDeviceInfo rtl8139_info = {
.qdev.name = "rtl8139",
.qdev.size = sizeof(RTL8139State),
- .qdev.reset = rtl8139_reset,
+ .qdev.reset = pci_rtl8139_reset,
.init = pci_rtl8139_init,
};
diff --git a/hw/tcx.c b/hw/tcx.c
index 012d01b..20fc2c7 100644
--- a/hw/tcx.c
+++ b/hw/tcx.c
@@ -411,10 +411,8 @@ static const VMStateDescription vmstate_tcx = {
}
};
-static void tcx_reset(void *opaque)
+static void tcx_reset(TCXState *s)
{
- TCXState *s = opaque;
-
/* Initialize palette */
memset(s->r, 0, 256);
memset(s->g, 0, 256);
@@ -628,11 +626,16 @@ static void tcx24_screen_dump(void *opaque, const char *filename)
return;
}
+static void reset_tcx(struct DeviceState *d)
+{
+ tcx_reset(container_of(d, TCXState, busdev.qdev));
+}
+
static SysBusDeviceInfo tcx_info = {
.init = tcx_init1,
.qdev.name = "SUNW,tcx",
.qdev.size = sizeof(TCXState),
- .qdev.reset = tcx_reset,
+ .qdev.reset = reset_tcx,
.qdev.vmsd = &vmstate_tcx,
.qdev.props = (Property[]) {
DEFINE_PROP_TADDR("addr", TCXState, addr, -1),
--
1.6.2.5
next parent reply other threads:[~2009-09-15 14:36 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1253025151.git.mst@redhat.com>
2009-09-15 14:33 ` Michael S. Tsirkin [this message]
2009-09-15 14:55 ` [Qemu-devel] Re: [PATCH 1/2] qemu/qdev: type safety in reset handler Gerd Hoffmann
2009-09-15 20:20 ` [Qemu-devel] " Blue Swirl
2009-09-15 20:42 ` Michael S. Tsirkin
2009-09-15 21:16 ` [Qemu-devel] " Paolo Bonzini
2009-09-15 21:37 ` Michael S. Tsirkin
2009-09-16 10:13 ` Gerd Hoffmann
2009-09-16 10:14 ` Michael S. Tsirkin
[not found] ` <m3vdjjutwa.fsf@neno.mitica>
2009-09-16 9:34 ` Michael S. Tsirkin
2009-09-16 10:05 ` Gerd Hoffmann
2009-09-16 10:06 ` Michael S. Tsirkin
2009-09-16 10:22 ` Gerd Hoffmann
2009-09-16 10:30 ` Michael S. Tsirkin
2009-09-16 10:47 ` Michael S. Tsirkin
2009-09-16 12:08 ` Michael S. Tsirkin
2009-09-15 14:33 ` [Qemu-devel] [PATCH 2/2] qemu/virtio: fix reset with device removal Michael S. Tsirkin
2009-09-15 15:30 ` [Qemu-devel] " Gerd Hoffmann
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=20090915143319.GB24708@redhat.com \
--to=mst@redhat.com \
--cc=avi@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cotte@de.ibm.com \
--cc=kraxel@redhat.com \
--cc=markmc@redhat.com \
--cc=paul@codesourcery.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).