From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [RfC PATCH] qdev: helper macros for properties
Date: Wed, 15 Jul 2009 14:35:58 +0200 [thread overview]
Message-ID: <1247661358-5411-1-git-send-email-kraxel@redhat.com> (raw)
Hi,
New revision of the helper macros for defining properties, going on top
of all other qdev patches posted today.
Some minor updates. Now there are versions with and without defaults.
Problem of verifying the type of _state->_field still unsolved. Dropped
the union idea because it doesn't help much here.
cheers,
Gerd
---
hw/pci.c | 5 +++++
hw/qdev-addr.h | 3 +++
hw/qdev.h | 29 +++++++++++++++++++++++++++++
3 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/hw/pci.c b/hw/pci.c
index 03c7840..6ce3f8f 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -55,6 +55,7 @@ static struct BusInfo pci_bus_info = {
.size = sizeof(PCIBus),
.print_dev = pcibus_dev_print,
.props = (Property[]) {
+#if 0
{
.name = "addr",
.info = &qdev_prop_pci_devfn,
@@ -62,6 +63,10 @@ static struct BusInfo pci_bus_info = {
.defval = (uint32_t[]) { -1 },
},
{/* end of list */}
+#else
+ DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1),
+ DEFINE_PROP_END_OF_LIST()
+#endif
}
};
diff --git a/hw/qdev-addr.h b/hw/qdev-addr.h
index f02bd7a..e135a96 100644
--- a/hw/qdev-addr.h
+++ b/hw/qdev-addr.h
@@ -1,2 +1,5 @@
+#define DEFINE_PROP_TADDR(_n, _s, _f) \
+ DEFINE_PROP(_n, _s, _f, qdev_prop_taddr)
+
extern PropertyInfo qdev_prop_taddr;
void qdev_prop_set_taddr(DeviceState *dev, const char *name, target_phys_addr_t value);
diff --git a/hw/qdev.h b/hw/qdev.h
index f2b8b2e..7b2c062 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -152,6 +152,35 @@ extern PropertyInfo qdev_prop_ptr;
extern PropertyInfo qdev_prop_macaddr;
extern PropertyInfo qdev_prop_pci_devfn;
+#define DEFINE_PROP(_name, _state, _field, _prop) { \
+ .name = (_name), \
+ .info = &(_prop), \
+ .offset = offsetof(_state, _field), \
+ }
+#define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
+ .name = (_name), \
+ .info = &(_prop), \
+ .offset = offsetof(_state, _field), \
+ .defval = (_type[]) { _defval }, \
+ }
+
+#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
+ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
+#define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
+ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
+#define DEFINE_PROP_HEX32(_n, _s, _f, _d) \
+ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t)
+#define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
+ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, uint32_t)
+
+#define DEFINE_PROP_PTR(_n, _s, _f) \
+ DEFINE_PROP(_n, _s, _f, qdev_prop_ptr)
+#define DEFINE_PROP_MACADDR(_n, _s, _f) \
+ DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr)
+
+#define DEFINE_PROP_END_OF_LIST() \
+ {}
+
/* Set properties between creation and init. */
void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
--
1.6.2.5
next reply other threads:[~2009-07-15 12:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-15 12:35 Gerd Hoffmann [this message]
2009-07-17 0:23 ` [Qemu-devel] [RfC PATCH] qdev: helper macros for properties Paul Brook
2009-07-17 3:17 ` Anthony Liguori
2009-07-17 3:28 ` Anthony Liguori
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=1247661358-5411-1-git-send-email-kraxel@redhat.com \
--to=kraxel@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).