From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MnZ8T-0007lB-EL for qemu-devel@nongnu.org; Tue, 15 Sep 2009 10:36:01 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MnZ8O-0007fE-Fa for qemu-devel@nongnu.org; Tue, 15 Sep 2009 10:36:00 -0400 Received: from [199.232.76.173] (port=35724 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MnZ8O-0007f4-9q for qemu-devel@nongnu.org; Tue, 15 Sep 2009 10:35:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61381) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MnZ8N-0002sd-RG for qemu-devel@nongnu.org; Tue, 15 Sep 2009 10:35:56 -0400 Date: Tue, 15 Sep 2009 17:33:19 +0300 From: "Michael S. Tsirkin" Message-ID: <20090915143319.GB24708@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: [Qemu-devel] [PATCH 1/2] qemu/qdev: type safety in reset handler List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paul Brook , Avi Kivity , qemu-devel@nongnu.org, Carsten Otte , Christian Borntraeger , kraxel@redhat.com, markmc@redhat.com Add type safety to qdev reset handlers, by declaring them as DeviceState * rather than void *. Signed-off-by: Michael S. Tsirkin --- 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