mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-12-17 21:26:13 -07:00
qdev: support properties which don't set a default value
In some situations it's useful to have a qdev property which doesn't automatically set its default value when qdev_property_add_static is called (for instance when the default value is not constant). Support this by adding a flag to the Property struct indicating whether to set the default value. This replaces the existing test for whether the PropertyInfo set_default_value function pointer is NULL, and we set the .set_default field to true for all those cases of struct Property which use a PropertyInfo with a non-NULL set_default_value, so behaviour remains the same as before. This gives us the semantics of: * if .set_default is true, then .info->set_default_value must be not NULL, and .defval is used as the the default value of the property * otherwise, the property system does not set any default, and the field will retain whatever initial value it was given by the device's .instance_init method We define two new macros DEFINE_PROP_SIGNED_NODEFAULT and DEFINE_PROP_UNSIGNED_NODEFAULT, to cover the most plausible use cases of wanting to set an integer property with no default value. Suggested-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Message-id: 1499788408-10096-3-git-send-email-peter.maydell@linaro.org
This commit is contained in:
parent
d9a7b125d6
commit
5cc56cc687
3 changed files with 31 additions and 1 deletions
|
|
@ -221,11 +221,21 @@ struct BusState {
|
|||
QLIST_ENTRY(BusState) sibling;
|
||||
};
|
||||
|
||||
/**
|
||||
* Property:
|
||||
* @set_default: true if the default value should be set from @defval,
|
||||
* in which case @info->set_default_value must not be NULL
|
||||
* (if false then no default value is set by the property system
|
||||
* and the field retains whatever value it was given by instance_init).
|
||||
* @defval: default value for the property. This is used only if @set_default
|
||||
* is true.
|
||||
*/
|
||||
struct Property {
|
||||
const char *name;
|
||||
const PropertyInfo *info;
|
||||
ptrdiff_t offset;
|
||||
uint8_t bitnr;
|
||||
bool set_default;
|
||||
union {
|
||||
int64_t i;
|
||||
uint64_t u;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue