* [Qemu-devel] [RfC PATCH 0/2] qdev: property macros. @ 2009-07-28 16:21 Gerd Hoffmann 2009-07-28 16:21 ` [Qemu-devel] [RfC PATCH 1/2] qdev/pci: make PCIDevice->devfn uint32_t Gerd Hoffmann 2009-07-28 16:22 ` [Qemu-devel] [RfC PATCH 2/2] qdev/prop: macros for creating typechecked properties Gerd Hoffmann 0 siblings, 2 replies; 4+ messages in thread From: Gerd Hoffmann @ 2009-07-28 16:21 UTC (permalink / raw) To: qemu-devel; +Cc: Gerd Hoffmann Hi folks, Presenting a new version of my patch to continue the discussion how the macros should look like ;) There are DEFINE_PROP_$TYPE("name", struct, field, default) macros for each property type, thus no gcc-powered automagic selection. typeof(struct->field) is verifyed to be the correct one for the given property though (new in this version). This uses gcc extentions, but as it is a check only it could easily be turned off for non-gcc compilers if needed. Comments? cheers, Gerd ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] [RfC PATCH 1/2] qdev/pci: make PCIDevice->devfn uint32_t 2009-07-28 16:21 [Qemu-devel] [RfC PATCH 0/2] qdev: property macros Gerd Hoffmann @ 2009-07-28 16:21 ` Gerd Hoffmann 2009-07-28 16:22 ` [Qemu-devel] [RfC PATCH 2/2] qdev/prop: macros for creating typechecked properties Gerd Hoffmann 1 sibling, 0 replies; 4+ messages in thread From: Gerd Hoffmann @ 2009-07-28 16:21 UTC (permalink / raw) To: qemu-devel; +Cc: Gerd Hoffmann Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/pci.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/hw/pci.h b/hw/pci.h index cbfea6a..a2ec16a 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -177,7 +177,7 @@ struct PCIDevice { /* the following fields are read only */ PCIBus *bus; - int devfn; + uint32_t devfn; char name[64]; PCIIORegion io_regions[PCI_NUM_REGIONS]; -- 1.6.2.5 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [RfC PATCH 2/2] qdev/prop: macros for creating typechecked properties. 2009-07-28 16:21 [Qemu-devel] [RfC PATCH 0/2] qdev: property macros Gerd Hoffmann 2009-07-28 16:21 ` [Qemu-devel] [RfC PATCH 1/2] qdev/pci: make PCIDevice->devfn uint32_t Gerd Hoffmann @ 2009-07-28 16:22 ` Gerd Hoffmann 1 sibling, 0 replies; 4+ messages in thread From: Gerd Hoffmann @ 2009-07-28 16:22 UTC (permalink / raw) To: qemu-devel; +Cc: Gerd Hoffmann Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/pci.c | 5 +++++ hw/qdev-addr.h | 3 +++ hw/qdev.h | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 0 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 4d0cdc7..bac0f8b 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -60,6 +60,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, @@ -67,6 +68,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..9568c27 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, target_phys_addr_t) + 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 af2ee0f..3a02af9 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -155,6 +155,46 @@ extern PropertyInfo qdev_prop_ptr; extern PropertyInfo qdev_prop_macaddr; extern PropertyInfo qdev_prop_pci_devfn; +extern int type_check_failed; +#define typeof_field(type, field) typeof(((type *)0)->field) +#define type_check(t1,t2) __builtin_choose_expr( \ + __builtin_types_compatible_p(t1,t2),0,type_check_failed) + +#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \ + .name = (_name), \ + .info = &(_prop), \ + .offset = offsetof(_state, _field) \ + + type_check(_type,typeof_field(_state, _field)), \ + } +#define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \ + .name = (_name), \ + .info = &(_prop), \ + .offset = offsetof(_state, _field) \ + + type_check(_type,typeof_field(_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_UINT64(_n, _s, _f, _d) \ + DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t) +#define DEFINE_PROP_HEX32(_n, _s, _f, _d) \ + DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t) +#define DEFINE_PROP_HEX64(_n, _s, _f, _d) \ + DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_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, void*) +#define DEFINE_PROP_MACADDR(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, uint8_t[6]) + +#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 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [RfC PATCH 0/2] qdev: property macros. @ 2009-07-28 10:24 Gerd Hoffmann 2009-07-28 10:24 ` [Qemu-devel] [RfC PATCH 2/2] qdev/prop: macros for creating typechecked properties Gerd Hoffmann 0 siblings, 1 reply; 4+ messages in thread From: Gerd Hoffmann @ 2009-07-28 10:24 UTC (permalink / raw) To: qemu-devel; +Cc: Gerd Hoffmann Hi folks, Presenting a new version of my patch to continue the discussion how the macros should look like ;) There are DEFINE_PROP_$TYPE("name", struct, field, default) macros for each property type, thus no gcc-powered automagic selection. typeof(struct->field) is verifyed to be the correct one for the given property though (new in this version). This uses gcc extentions, but as it is a check only it could easily be turned off for non-gcc compilers if needed. Comments? cheers, Gerd ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] [RfC PATCH 2/2] qdev/prop: macros for creating typechecked properties. 2009-07-28 10:24 [Qemu-devel] [RfC PATCH 0/2] qdev: property macros Gerd Hoffmann @ 2009-07-28 10:24 ` Gerd Hoffmann 0 siblings, 0 replies; 4+ messages in thread From: Gerd Hoffmann @ 2009-07-28 10:24 UTC (permalink / raw) To: qemu-devel; +Cc: Gerd Hoffmann Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/pci.c | 5 +++++ hw/qdev-addr.h | 3 +++ hw/qdev.h | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 0 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 4d0cdc7..bac0f8b 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -60,6 +60,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, @@ -67,6 +68,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..9568c27 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, target_phys_addr_t) + 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 af2ee0f..3a02af9 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -155,6 +155,46 @@ extern PropertyInfo qdev_prop_ptr; extern PropertyInfo qdev_prop_macaddr; extern PropertyInfo qdev_prop_pci_devfn; +extern int type_check_failed; +#define typeof_field(type, field) typeof(((type *)0)->field) +#define type_check(t1,t2) __builtin_choose_expr( \ + __builtin_types_compatible_p(t1,t2),0,type_check_failed) + +#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \ + .name = (_name), \ + .info = &(_prop), \ + .offset = offsetof(_state, _field) \ + + type_check(_type,typeof_field(_state, _field)), \ + } +#define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \ + .name = (_name), \ + .info = &(_prop), \ + .offset = offsetof(_state, _field) \ + + type_check(_type,typeof_field(_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_UINT64(_n, _s, _f, _d) \ + DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t) +#define DEFINE_PROP_HEX32(_n, _s, _f, _d) \ + DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t) +#define DEFINE_PROP_HEX64(_n, _s, _f, _d) \ + DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_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, void*) +#define DEFINE_PROP_MACADDR(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, uint8_t[6]) + +#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 ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-07-28 16:22 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-07-28 16:21 [Qemu-devel] [RfC PATCH 0/2] qdev: property macros Gerd Hoffmann 2009-07-28 16:21 ` [Qemu-devel] [RfC PATCH 1/2] qdev/pci: make PCIDevice->devfn uint32_t Gerd Hoffmann 2009-07-28 16:22 ` [Qemu-devel] [RfC PATCH 2/2] qdev/prop: macros for creating typechecked properties Gerd Hoffmann -- strict thread matches above, loose matches on Subject: below -- 2009-07-28 10:24 [Qemu-devel] [RfC PATCH 0/2] qdev: property macros Gerd Hoffmann 2009-07-28 10:24 ` [Qemu-devel] [RfC PATCH 2/2] qdev/prop: macros for creating typechecked properties Gerd Hoffmann
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).