|
Justin M. Forbes |
272dfe |
This adds "bit" property type, which is a boolean stored in a 32 bit
|
|
Justin M. Forbes |
272dfe |
integer field, with legal values on and off. Will be used by virtio for
|
|
Justin M. Forbes |
272dfe |
feature bits.
|
|
Justin M. Forbes |
272dfe |
|
|
Justin M. Forbes |
272dfe |
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
|
|
Justin M. Forbes |
272dfe |
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
|
|
Justin M. Forbes |
272dfe |
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
|
|
Justin M. Forbes |
272dfe |
(cherry picked from commit d2364ee424ebf9180afaf21128a71da55321ad00)
|
|
Justin M. Forbes |
272dfe |
---
|
|
Justin M. Forbes |
272dfe |
hw/qdev-properties.c | 62 ++++++++++++++++++++++++++++++++++++++++++++-----
|
|
Justin M. Forbes |
272dfe |
hw/qdev.h | 11 +++++++++
|
|
Justin M. Forbes |
272dfe |
2 files changed, 66 insertions(+), 7 deletions(-)
|
|
Justin M. Forbes |
272dfe |
|
|
Justin M. Forbes |
272dfe |
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
|
|
Justin M. Forbes |
272dfe |
index 217ddc0..9e123ae 100644
|
|
Justin M. Forbes |
272dfe |
--- a/hw/qdev-properties.c
|
|
Justin M. Forbes |
272dfe |
+++ b/hw/qdev-properties.c
|
|
Justin M. Forbes |
272dfe |
@@ -9,6 +9,59 @@ void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
|
|
Justin M. Forbes |
272dfe |
return ptr;
|
|
Justin M. Forbes |
272dfe |
}
|
|
Justin M. Forbes |
272dfe |
|
|
Justin M. Forbes |
272dfe |
+static uint32_t qdev_get_prop_mask(Property *prop)
|
|
Justin M. Forbes |
272dfe |
+{
|
|
Justin M. Forbes |
272dfe |
+ assert(prop->info->type == PROP_TYPE_BIT);
|
|
Justin M. Forbes |
272dfe |
+ return 0x1 << prop->bitnr;
|
|
Justin M. Forbes |
272dfe |
+}
|
|
Justin M. Forbes |
272dfe |
+
|
|
Justin M. Forbes |
272dfe |
+static void bit_prop_set(DeviceState *dev, Property *props, bool val)
|
|
Justin M. Forbes |
272dfe |
+{
|
|
Justin M. Forbes |
272dfe |
+ uint32_t *p = qdev_get_prop_ptr(dev, props);
|
|
Justin M. Forbes |
272dfe |
+ uint32_t mask = qdev_get_prop_mask(props);
|
|
Justin M. Forbes |
272dfe |
+ if (val)
|
|
Justin M. Forbes |
272dfe |
+ *p |= ~mask;
|
|
Justin M. Forbes |
272dfe |
+ else
|
|
Justin M. Forbes |
272dfe |
+ *p &= ~mask;
|
|
Justin M. Forbes |
272dfe |
+}
|
|
Justin M. Forbes |
272dfe |
+
|
|
Justin M. Forbes |
272dfe |
+static void qdev_prop_cpy(DeviceState *dev, Property *props, void *src)
|
|
Justin M. Forbes |
272dfe |
+{
|
|
Justin M. Forbes |
272dfe |
+ if (props->info->type == PROP_TYPE_BIT) {
|
|
Justin M. Forbes |
272dfe |
+ bool *defval = src;
|
|
Justin M. Forbes |
272dfe |
+ bit_prop_set(dev, props, *defval);
|
|
Justin M. Forbes |
272dfe |
+ } else {
|
|
Justin M. Forbes |
272dfe |
+ char *dst = qdev_get_prop_ptr(dev, props);
|
|
Justin M. Forbes |
272dfe |
+ memcpy(dst, src, props->info->size);
|
|
Justin M. Forbes |
272dfe |
+ }
|
|
Justin M. Forbes |
272dfe |
+}
|
|
Justin M. Forbes |
272dfe |
+
|
|
Justin M. Forbes |
272dfe |
+/* Bit */
|
|
Justin M. Forbes |
272dfe |
+static int parse_bit(DeviceState *dev, Property *prop, const char *str)
|
|
Justin M. Forbes |
272dfe |
+{
|
|
Justin M. Forbes |
272dfe |
+ if (!strncasecmp(str, "on", 2))
|
|
Justin M. Forbes |
272dfe |
+ bit_prop_set(dev, prop, true);
|
|
Justin M. Forbes |
272dfe |
+ else if (!strncasecmp(str, "off", 3))
|
|
Justin M. Forbes |
272dfe |
+ bit_prop_set(dev, prop, false);
|
|
Justin M. Forbes |
272dfe |
+ else
|
|
Justin M. Forbes |
272dfe |
+ return -1;
|
|
Justin M. Forbes |
272dfe |
+ return 0;
|
|
Justin M. Forbes |
272dfe |
+}
|
|
Justin M. Forbes |
272dfe |
+
|
|
Justin M. Forbes |
272dfe |
+static int print_bit(DeviceState *dev, Property *prop, char *dest, size_t len)
|
|
Justin M. Forbes |
272dfe |
+{
|
|
Justin M. Forbes |
272dfe |
+ uint8_t *p = qdev_get_prop_ptr(dev, prop);
|
|
Justin M. Forbes |
272dfe |
+ return snprintf(dest, len, (*p & qdev_get_prop_mask(prop)) ? "on" : "off");
|
|
Justin M. Forbes |
272dfe |
+}
|
|
Justin M. Forbes |
272dfe |
+
|
|
Justin M. Forbes |
272dfe |
+PropertyInfo qdev_prop_bit = {
|
|
Justin M. Forbes |
272dfe |
+ .name = "on/off",
|
|
Justin M. Forbes |
272dfe |
+ .type = PROP_TYPE_BIT,
|
|
Justin M. Forbes |
272dfe |
+ .size = sizeof(uint32_t),
|
|
Justin M. Forbes |
272dfe |
+ .parse = parse_bit,
|
|
Justin M. Forbes |
272dfe |
+ .print = print_bit,
|
|
Justin M. Forbes |
272dfe |
+};
|
|
Justin M. Forbes |
272dfe |
+
|
|
Justin M. Forbes |
272dfe |
/* --- 8bit integer --- */
|
|
Justin M. Forbes |
272dfe |
|
|
Justin M. Forbes |
272dfe |
static int parse_uint8(DeviceState *dev, Property *prop, const char *str)
|
|
Justin M. Forbes |
272dfe |
@@ -511,7 +564,6 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
|
|
Justin M. Forbes |
272dfe |
void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type)
|
|
Justin M. Forbes |
272dfe |
{
|
|
Justin M. Forbes |
272dfe |
Property *prop;
|
|
Justin M. Forbes |
272dfe |
- void *dst;
|
|
Justin M. Forbes |
272dfe |
|
|
Justin M. Forbes |
272dfe |
prop = qdev_prop_find(dev, name);
|
|
Justin M. Forbes |
272dfe |
if (!prop) {
|
|
Justin M. Forbes |
272dfe |
@@ -524,8 +576,7 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
|
|
Justin M. Forbes |
272dfe |
__FUNCTION__, dev->info->name, name);
|
|
Justin M. Forbes |
272dfe |
abort();
|
|
Justin M. Forbes |
272dfe |
}
|
|
Justin M. Forbes |
272dfe |
- dst = qdev_get_prop_ptr(dev, prop);
|
|
Justin M. Forbes |
272dfe |
- memcpy(dst, src, prop->info->size);
|
|
Justin M. Forbes |
272dfe |
+ qdev_prop_cpy(dev, prop, src);
|
|
Justin M. Forbes |
272dfe |
}
|
|
Justin M. Forbes |
272dfe |
|
|
Justin M. Forbes |
272dfe |
void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value)
|
|
Justin M. Forbes |
272dfe |
@@ -585,14 +636,11 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
|
|
Justin M. Forbes |
272dfe |
|
|
Justin M. Forbes |
272dfe |
void qdev_prop_set_defaults(DeviceState *dev, Property *props)
|
|
Justin M. Forbes |
272dfe |
{
|
|
Justin M. Forbes |
272dfe |
- char *dst;
|
|
Justin M. Forbes |
272dfe |
-
|
|
Justin M. Forbes |
272dfe |
if (!props)
|
|
Justin M. Forbes |
272dfe |
return;
|
|
Justin M. Forbes |
272dfe |
while (props->name) {
|
|
Justin M. Forbes |
272dfe |
if (props->defval) {
|
|
Justin M. Forbes |
272dfe |
- dst = qdev_get_prop_ptr(dev, props);
|
|
Justin M. Forbes |
272dfe |
- memcpy(dst, props->defval, props->info->size);
|
|
Justin M. Forbes |
272dfe |
+ qdev_prop_cpy(dev, props, props->defval);
|
|
Justin M. Forbes |
272dfe |
}
|
|
Justin M. Forbes |
272dfe |
props++;
|
|
Justin M. Forbes |
272dfe |
}
|
|
Justin M. Forbes |
272dfe |
diff --git a/hw/qdev.h b/hw/qdev.h
|
|
Justin M. Forbes |
272dfe |
index bbcdba1..07b9603 100644
|
|
Justin M. Forbes |
272dfe |
--- a/hw/qdev.h
|
|
Justin M. Forbes |
272dfe |
+++ b/hw/qdev.h
|
|
Justin M. Forbes |
272dfe |
@@ -64,6 +64,7 @@ struct Property {
|
|
Justin M. Forbes |
272dfe |
const char *name;
|
|
Justin M. Forbes |
272dfe |
PropertyInfo *info;
|
|
Justin M. Forbes |
272dfe |
int offset;
|
|
Justin M. Forbes |
272dfe |
+ int bitnr;
|
|
Justin M. Forbes |
272dfe |
void *defval;
|
|
Justin M. Forbes |
272dfe |
};
|
|
Justin M. Forbes |
272dfe |
|
|
Justin M. Forbes |
272dfe |
@@ -82,6 +83,7 @@ enum PropertyType {
|
|
Justin M. Forbes |
272dfe |
PROP_TYPE_NETDEV,
|
|
Justin M. Forbes |
272dfe |
PROP_TYPE_VLAN,
|
|
Justin M. Forbes |
272dfe |
PROP_TYPE_PTR,
|
|
Justin M. Forbes |
272dfe |
+ PROP_TYPE_BIT,
|
|
Justin M. Forbes |
272dfe |
};
|
|
Justin M. Forbes |
272dfe |
|
|
Justin M. Forbes |
272dfe |
struct PropertyInfo {
|
|
Justin M. Forbes |
272dfe |
@@ -173,6 +175,7 @@ void do_device_del(Monitor *mon, const QDict *qdict);
|
|
Justin M. Forbes |
272dfe |
|
|
Justin M. Forbes |
272dfe |
/*** qdev-properties.c ***/
|
|
Justin M. Forbes |
272dfe |
|
|
Justin M. Forbes |
272dfe |
+extern PropertyInfo qdev_prop_bit;
|
|
Justin M. Forbes |
272dfe |
extern PropertyInfo qdev_prop_uint8;
|
|
Justin M. Forbes |
272dfe |
extern PropertyInfo qdev_prop_uint16;
|
|
Justin M. Forbes |
272dfe |
extern PropertyInfo qdev_prop_uint32;
|
|
Justin M. Forbes |
272dfe |
@@ -202,6 +205,14 @@ extern PropertyInfo qdev_prop_pci_devfn;
|
|
Justin M. Forbes |
272dfe |
+ type_check(_type,typeof_field(_state, _field)), \
|
|
Justin M. Forbes |
272dfe |
.defval = (_type[]) { _defval }, \
|
|
Justin M. Forbes |
272dfe |
}
|
|
Justin M. Forbes |
272dfe |
+#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
|
|
Justin M. Forbes |
272dfe |
+ .name = (_name), \
|
|
Justin M. Forbes |
272dfe |
+ .info = &(qdev_prop_bit), \
|
|
Justin M. Forbes |
272dfe |
+ .bitnr = (_bit), \
|
|
Justin M. Forbes |
272dfe |
+ .offset = offsetof(_state, _field) \
|
|
Justin M. Forbes |
272dfe |
+ + type_check(uint32_t,typeof_field(_state, _field)), \
|
|
Justin M. Forbes |
272dfe |
+ .defval = (bool[]) { (_defval) }, \
|
|
Justin M. Forbes |
272dfe |
+ }
|
|
Justin M. Forbes |
272dfe |
|
|
Justin M. Forbes |
272dfe |
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
|
|
Justin M. Forbes |
272dfe |
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
|
|
Justin M. Forbes |
272dfe |
--
|
|
Justin M. Forbes |
272dfe |
1.6.6.144.g5c3af
|