diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2017-06-07 20:35:53 +0400 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2017-06-19 14:56:29 +0200 |
commit | a2740ad584839ac84f3cdb2d928de93a0d7f4e72 (patch) | |
tree | 8230dd4feda8eec4323bb09ca9b25baa3883d3b3 | |
parent | edf8bc98424d62035d5e4c0f39542722d72d7979 (diff) | |
download | qemu-a2740ad584839ac84f3cdb2d928de93a0d7f4e72.zip qemu-a2740ad584839ac84f3cdb2d928de93a0d7f4e72.tar.gz qemu-a2740ad584839ac84f3cdb2d928de93a0d7f4e72.tar.bz2 |
qdev: remove PropertyInfo.qtype field
Remove dependency on qapi qtype, replace a field by a few PropertyInfo
callbacks to set the default value type (introduced in commit 4f2d3d7).
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20170607163635.17635-2-marcandre.lureau@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
-rw-r--r-- | hw/core/qdev-properties.c | 35 | ||||
-rw-r--r-- | hw/core/qdev.c | 13 | ||||
-rw-r--r-- | include/hw/qdev-core.h | 2 | ||||
-rw-r--r-- | include/hw/qdev-properties.h | 5 |
4 files changed, 37 insertions, 18 deletions
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 9f1a497..c5e028a 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -69,6 +69,12 @@ static void set_enum(Object *obj, Visitor *v, const char *name, void *opaque, visit_type_enum(v, prop->name, ptr, prop->info->enum_table, errp); } +static void set_default_value_enum(Object *obj, const Property *prop) +{ + object_property_set_str(obj, prop->info->enum_table[prop->defval], + prop->name, &error_abort); +} + /* Bit */ static uint32_t qdev_get_prop_mask(Property *prop) @@ -120,11 +126,17 @@ static void prop_set_bit(Object *obj, Visitor *v, const char *name, bit_prop_set(dev, prop, value); } +static void set_default_value_bool(Object *obj, const Property *prop) +{ + object_property_set_bool(obj, prop->defval, prop->name, &error_abort); +} + PropertyInfo qdev_prop_bit = { .name = "bool", .description = "on/off", .get = prop_get_bit, .set = prop_set_bit, + .set_default_value = set_default_value_bool, }; /* Bit64 */ @@ -183,6 +195,7 @@ PropertyInfo qdev_prop_bit64 = { .description = "on/off", .get = prop_get_bit64, .set = prop_set_bit64, + .set_default_value = set_default_value_bool, }; /* --- bool --- */ @@ -216,6 +229,7 @@ PropertyInfo qdev_prop_bool = { .name = "bool", .get = get_bool, .set = set_bool, + .set_default_value = set_default_value_bool, }; /* --- 8bit integer --- */ @@ -245,10 +259,16 @@ static void set_uint8(Object *obj, Visitor *v, const char *name, void *opaque, visit_type_uint8(v, name, ptr, errp); } +static void set_default_value_int(Object *obj, const Property *prop) +{ + object_property_set_int(obj, prop->defval, prop->name, &error_abort); +} + PropertyInfo qdev_prop_uint8 = { .name = "uint8", .get = get_uint8, .set = set_uint8, + .set_default_value = set_default_value_int, }; /* --- 16bit integer --- */ @@ -282,6 +302,7 @@ PropertyInfo qdev_prop_uint16 = { .name = "uint16", .get = get_uint16, .set = set_uint16, + .set_default_value = set_default_value_int, }; /* --- 32bit integer --- */ @@ -340,12 +361,14 @@ PropertyInfo qdev_prop_uint32 = { .name = "uint32", .get = get_uint32, .set = set_uint32, + .set_default_value = set_default_value_int, }; PropertyInfo qdev_prop_int32 = { .name = "int32", .get = get_int32, .set = set_int32, + .set_default_value = set_default_value_int, }; /* --- 64bit integer --- */ @@ -379,6 +402,7 @@ PropertyInfo qdev_prop_uint64 = { .name = "uint64", .get = get_uint64, .set = set_uint64, + .set_default_value = set_default_value_int, }; /* --- string --- */ @@ -526,6 +550,7 @@ PropertyInfo qdev_prop_on_off_auto = { .enum_table = OnOffAuto_lookup, .get = get_enum, .set = set_enum, + .set_default_value = set_default_value_enum, }; /* --- lost tick policy --- */ @@ -537,6 +562,7 @@ PropertyInfo qdev_prop_losttickpolicy = { .enum_table = LostTickPolicy_lookup, .get = get_enum, .set = set_enum, + .set_default_value = set_default_value_enum, }; /* --- Block device error handling policy --- */ @@ -550,6 +576,7 @@ PropertyInfo qdev_prop_blockdev_on_error = { .enum_table = BlockdevOnError_lookup, .get = get_enum, .set = set_enum, + .set_default_value = set_default_value_enum, }; /* --- BIOS CHS translation */ @@ -563,6 +590,7 @@ PropertyInfo qdev_prop_bios_chs_trans = { .enum_table = BiosAtaTranslation_lookup, .get = get_enum, .set = set_enum, + .set_default_value = set_default_value_enum, }; /* --- FDC default drive types */ @@ -573,7 +601,8 @@ PropertyInfo qdev_prop_fdc_drive_type = { "144/288/120/none/auto", .enum_table = FloppyDriveType_lookup, .get = get_enum, - .set = set_enum + .set = set_enum, + .set_default_value = set_default_value_enum, }; /* --- pci address --- */ @@ -648,6 +677,7 @@ PropertyInfo qdev_prop_pci_devfn = { .print = print_pci_devfn, .get = get_int32, .set = set_pci_devfn, + .set_default_value = set_default_value_int, }; /* --- blocksize --- */ @@ -695,6 +725,7 @@ PropertyInfo qdev_prop_blocksize = { .description = "A power of two between 512 and 32768", .get = get_uint16, .set = set_blocksize, + .set_default_value = set_default_value_int, }; /* --- pci host address --- */ @@ -917,6 +948,7 @@ PropertyInfo qdev_prop_arraylen = { .name = "uint32", .get = get_uint32, .set = set_prop_arraylen, + .set_default_value = set_default_value_int, }; /* --- public helpers --- */ @@ -1153,4 +1185,5 @@ PropertyInfo qdev_prop_size = { .name = "size", .get = get_size, .set = set_size, + .set_default_value = set_default_value_int, }; diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 0ce45a2..849952a 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -793,17 +793,8 @@ void qdev_property_add_static(DeviceState *dev, Property *prop, prop->info->description, &error_abort); - if (prop->qtype == QTYPE_NONE) { - return; - } - - if (prop->qtype == QTYPE_QBOOL) { - object_property_set_bool(obj, prop->defval, prop->name, &error_abort); - } else if (prop->info->enum_table) { - object_property_set_str(obj, prop->info->enum_table[prop->defval], - prop->name, &error_abort); - } else if (prop->qtype == QTYPE_QINT) { - object_property_set_int(obj, prop->defval, prop->name, &error_abort); + if (prop->info->set_default_value) { + prop->info->set_default_value(obj, prop); } } diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index e69489e..9523339 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -226,7 +226,6 @@ struct Property { PropertyInfo *info; ptrdiff_t offset; uint8_t bitnr; - QType qtype; int64_t defval; int arrayoffset; PropertyInfo *arrayinfo; @@ -238,6 +237,7 @@ struct PropertyInfo { const char *description; const char * const *enum_table; int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); + void (*set_default_value)(Object *obj, const Property *prop); ObjectPropertyAccessor *get; ObjectPropertyAccessor *set; ObjectPropertyRelease *release; diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index d206fc9..85e6899 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -42,7 +42,6 @@ extern PropertyInfo qdev_prop_arraylen; .info = &(_prop), \ .offset = offsetof(_state, _field) \ + type_check(_type,typeof_field(_state, _field)), \ - .qtype = QTYPE_QINT, \ .defval = (_type)_defval, \ } #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \ @@ -51,7 +50,6 @@ extern PropertyInfo qdev_prop_arraylen; .bitnr = (_bit), \ .offset = offsetof(_state, _field) \ + type_check(uint32_t,typeof_field(_state, _field)), \ - .qtype = QTYPE_QBOOL, \ .defval = (bool)_defval, \ } #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) { \ @@ -60,7 +58,6 @@ extern PropertyInfo qdev_prop_arraylen; .bitnr = (_bit), \ .offset = offsetof(_state, _field) \ + type_check(uint64_t, typeof_field(_state, _field)), \ - .qtype = QTYPE_QBOOL, \ .defval = (bool)_defval, \ } @@ -69,7 +66,6 @@ extern PropertyInfo qdev_prop_arraylen; .info = &(qdev_prop_bool), \ .offset = offsetof(_state, _field) \ + type_check(bool, typeof_field(_state, _field)), \ - .qtype = QTYPE_QBOOL, \ .defval = (bool)_defval, \ } @@ -105,7 +101,6 @@ extern PropertyInfo qdev_prop_arraylen; .info = &(qdev_prop_arraylen), \ .offset = offsetof(_state, _field) \ + type_check(uint32_t, typeof_field(_state, _field)), \ - .qtype = QTYPE_QINT, \ .arrayinfo = &(_arrayprop), \ .arrayfieldsize = sizeof(_arraytype), \ .arrayoffset = offsetof(_state, _arrayfield), \ |