mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-24 12:09:58 +00:00
qdev/prop: macros for creating typechecked properties.
There are DEFINE_PROP_$TYPE("name", struct, field, default) macros for each property type. These macros link the qdev_prop_$name struct to the type used by that property. typeof(struct->field) is verifyed to be the correct one for the given property. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Message-Id:
This commit is contained in:
parent
93c8cfd9e6
commit
cf12b95bf5
@ -1,2 +1,5 @@
|
||||
#define DEFINE_PROP_TADDR(_n, _s, _f, _d) \
|
||||
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, 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);
|
||||
|
38
hw/qdev.h
38
hw/qdev.h
@ -160,6 +160,44 @@ extern PropertyInfo qdev_prop_macaddr;
|
||||
extern PropertyInfo qdev_prop_drive;
|
||||
extern PropertyInfo qdev_prop_pci_devfn;
|
||||
|
||||
#define typeof_field(type, field) typeof(((type *)0)->field)
|
||||
#define type_check(t1,t2) ((t1*)0 - (t2*)0)
|
||||
|
||||
#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);
|
||||
|
Loading…
Reference in New Issue
Block a user