From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Alberto Garcia" <agarcia@igalia.com>,
"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [PATCH qom-next for-next 1/6] ipack: Convert to QOM realize
Date: Fri, 2 Aug 2013 23:16:56 +0200 [thread overview]
Message-ID: <1375478221-22722-2-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1375478221-22722-1-git-send-email-afaerber@suse.de>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/char/ipack.c | 40 ++++++++++++++++------------------------
hw/char/ipack.h | 5 ++---
hw/char/ipoctal232.c | 18 +++++++++++++-----
3 files changed, 31 insertions(+), 32 deletions(-)
diff --git a/hw/char/ipack.c b/hw/char/ipack.c
index f890471..a902fe4 100644
--- a/hw/char/ipack.c
+++ b/hw/char/ipack.c
@@ -33,37 +33,28 @@ void ipack_bus_new_inplace(IPackBus *bus, DeviceState *parent,
bus->set_irq = handler;
}
-static int ipack_device_dev_init(DeviceState *qdev)
+static void ipack_device_realize(DeviceState *dev, Error **errp)
{
- IPackBus *bus = IPACK_BUS(qdev_get_parent_bus(qdev));
- IPackDevice *dev = IPACK_DEVICE(qdev);
- IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(dev);
+ IPackDevice *idev = IPACK_DEVICE(dev);
+ IPackBus *bus = IPACK_BUS(qdev_get_parent_bus(dev));
- if (dev->slot < 0) {
- dev->slot = bus->free_slot;
+ if (idev->slot < 0) {
+ idev->slot = bus->free_slot;
}
- if (dev->slot >= bus->n_slots) {
- return -1;
+ if (idev->slot >= bus->n_slots) {
+ error_setg(errp, "Only %" PRIu8 " slots available.", bus->n_slots);
+ return;
}
- bus->free_slot = dev->slot + 1;
+ bus->free_slot = idev->slot + 1;
- dev->irq = qemu_allocate_irqs(bus->set_irq, dev, 2);
-
- return k->init(dev);
+ idev->irq = qemu_allocate_irqs(bus->set_irq, idev, 2);
}
-static int ipack_device_dev_exit(DeviceState *qdev)
+static void ipack_device_unrealize(DeviceState *dev, Error **errp)
{
- IPackDevice *dev = IPACK_DEVICE(qdev);
- IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(dev);
-
- if (k->exit) {
- k->exit(dev);
- }
+ IPackDevice *idev = IPACK_DEVICE(dev);
- qemu_free_irqs(dev->irq);
-
- return 0;
+ qemu_free_irqs(idev->irq);
}
static Property ipack_device_props[] = {
@@ -74,10 +65,11 @@ static Property ipack_device_props[] = {
static void ipack_device_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
+
set_bit(DEVICE_CATEGORY_INPUT, k->categories);
k->bus_type = TYPE_IPACK_BUS;
- k->init = ipack_device_dev_init;
- k->exit = ipack_device_dev_exit;
+ k->realize = ipack_device_realize;
+ k->unrealize = ipack_device_unrealize;
k->props = ipack_device_props;
}
diff --git a/hw/char/ipack.h b/hw/char/ipack.h
index f2b7a12..4286fc0 100644
--- a/hw/char/ipack.h
+++ b/hw/char/ipack.h
@@ -38,10 +38,9 @@ typedef struct IPackDeviceClass IPackDeviceClass;
OBJECT_GET_CLASS(IPackDeviceClass, (obj), TYPE_IPACK_DEVICE)
struct IPackDeviceClass {
+ /*< private >*/
DeviceClass parent_class;
-
- int (*init)(IPackDevice *dev);
- int (*exit)(IPackDevice *dev);
+ /*< public >*/
uint16_t (*io_read)(IPackDevice *dev, uint8_t addr);
void (*io_write)(IPackDevice *dev, uint8_t addr, uint16_t val);
diff --git a/hw/char/ipoctal232.c b/hw/char/ipoctal232.c
index 88e2cca..80ebe7b 100644
--- a/hw/char/ipoctal232.c
+++ b/hw/char/ipoctal232.c
@@ -118,6 +118,8 @@ struct IPOctalState {
#define IPOCTAL(obj) \
OBJECT_CHECK(IPOctalState, (obj), TYPE_IPOCTAL)
+#define IPOCTAL_GET_PARENT_CLASS(obj) \
+ OBJECT_GET_PARENT_CLASS(obj, TYPE_IPOCTAL)
static const VMStateDescription vmstate_scc2698_channel = {
.name = "scc2698_channel",
@@ -534,11 +536,19 @@ static void hostdev_event(void *opaque, int event)
}
}
-static int ipoctal_init(IPackDevice *ip)
+static void ipoctal_realize(DeviceState *dev, Error **errp)
{
- IPOctalState *s = IPOCTAL(ip);
+ IPOctalState *s = IPOCTAL(dev);
+ DeviceClass *parent_dc = DEVICE_CLASS(IPOCTAL_GET_PARENT_CLASS(dev));
+ Error *err = NULL;
unsigned i;
+ parent_dc->realize(dev, &err);
+ if (err != NULL) {
+ error_propagate(errp, err);
+ return;
+ }
+
for (i = 0; i < N_CHANNELS; i++) {
SCC2698Channel *ch = &s->ch[i];
ch->ipoctal = s;
@@ -552,8 +562,6 @@ static int ipoctal_init(IPackDevice *ip)
DPRINTF("Could not redirect channel %u, no chardev set\n", i);
}
}
-
- return 0;
}
static Property ipoctal_properties[] = {
@@ -573,7 +581,6 @@ static void ipoctal_class_init(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
IPackDeviceClass *ic = IPACK_DEVICE_CLASS(klass);
- ic->init = ipoctal_init;
ic->io_read = io_read;
ic->io_write = io_write;
ic->id_read = id_read;
@@ -585,6 +592,7 @@ static void ipoctal_class_init(ObjectClass *klass, void *data)
ic->mem_read8 = mem_read8;
ic->mem_write8 = mem_write8;
+ dc->realize = ipoctal_realize;
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
dc->desc = "GE IP-Octal 232 8-channel RS-232 IndustryPack";
dc->props = ipoctal_properties;
--
1.8.1.4
next prev parent reply other threads:[~2013-08-02 21:17 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-02 21:16 [Qemu-devel] [PATCH qom-next for-next 0/6] QOM realize for IndustryPack Andreas Färber
2013-08-02 21:16 ` Andreas Färber [this message]
2013-08-05 15:16 ` [Qemu-devel] [PATCH qom-next for-next 1/6] ipack: Convert to QOM realize Alberto Garcia
2013-08-05 17:46 ` Andreas Färber
2013-08-02 21:16 ` [Qemu-devel] [PATCH qom-next for-next 2/6] ipack: QOM parent field cleanup for IPackBus Andreas Färber
2013-08-02 21:16 ` [Qemu-devel] [PATCH qom-next for-next 3/6] ipack: QOM parent field cleanup for IPackDevice Andreas Färber
2013-08-02 21:16 ` [Qemu-devel] [PATCH qom-next for-next 4/6] ipack: Simplify VMSTATE_IPACK_DEVICE() macro Andreas Färber
2013-08-02 21:17 ` [Qemu-devel] [PATCH qom-next for-next 5/6] ipoctal232: QOM parent field cleanup Andreas Färber
2013-08-02 21:17 ` [Qemu-devel] [PATCH qom-next for-next 6/6] ipack: Move IndustryPack out of hw/char/ Andreas Färber
2013-08-06 8:48 ` [Qemu-devel] [PATCH qom-next for-next 0/6] QOM realize for IndustryPack Alberto Garcia
2014-02-08 19:58 ` Andreas Färber
2014-02-08 23:31 ` Paolo Bonzini
2014-02-09 21:31 ` Paolo Bonzini
2014-02-09 21:46 ` Alberto Garcia
2014-02-09 22:12 ` Andreas Färber
2014-02-09 18:17 ` Alberto Garcia
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=1375478221-22722-2-git-send-email-afaerber@suse.de \
--to=afaerber@suse.de \
--cc=agarcia@igalia.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).