Skip to contentSkip to conversation

qdev: add qdev property for bool type

PATCH In review Andreas Färber 2 participants 8 messages Mar 7, 2013 – Apr 26, 2013 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Am 25.02.2013 02:03, schrieb Igor Mammedov:

Quoted 1 line

I vaguely remember having written something like this long time ago for ISA and for Vasilis... looks good except for minor nits.

Quoted 17 lines
---
 hw/qdev-properties.c |   33 +++++++++++++++++++++++++++++++++
 hw/qdev-properties.h |   10 ++++++++++
 2 files changed, 43 insertions(+), 0 deletions(-)
hw/qdev-properties.c +4 -0
index a8a31f5..16ac814 100644
@@ -106,6 +106,39 @@ PropertyInfo qdev_prop_bit = {
     .set   = set_bit,
 };
 
+/* --- bool --- */
+
+static void get_bool(Object *obj, Visitor *v, void *opaque,
+                     const char *name, Error **errp)

hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 122

Quoted 10 lines
hw/qdev-properties.c +10 -0
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    bool *ptr = qdev_get_prop_ptr(dev, prop);
+
+    visit_type_bool(v, ptr, name, errp);
+}
+
+static void set_bool(Object *obj, Visitor *v, void *opaque,
+                       const char *name, Error **errp)

Indentation is off.

hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 129

Quoted 7 lines
hw/qdev-properties.c +7 -0
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    bool *ptr = qdev_get_prop_ptr(dev, prop);
+
+    if (dev->realized) {
+        error_setg(errp, "Insufficient permission to perform this operation");

Should we be more specific here?
E.g., "Property '%s' cannot be changed once realized."

Andreas

Quoted 44 lines
hw/qdev-properties.c +12 -0
+        return;
+    }
+
+    visit_type_bool(v, ptr, name, errp);
+}
+
+PropertyInfo qdev_prop_bool = {
+    .name  = "boolean",
+    .get   = get_bool,
+    .set   = set_bool,
+};
+
 /* --- 8bit integer --- */
 
 static void get_uint8(Object *obj, Visitor *v, void *opaque,
hw/qdev-properties.h +10 -0
index 20c67f3..3915f7c 100644
@@ -6,6 +6,7 @@
 /*** qdev-properties.c ***/
 
 extern PropertyInfo qdev_prop_bit;
+extern PropertyInfo qdev_prop_bool;
 extern PropertyInfo qdev_prop_uint8;
 extern PropertyInfo qdev_prop_uint16;
 extern PropertyInfo qdev_prop_uint32;
@@ -51,6 +52,15 @@ extern PropertyInfo qdev_prop_pci_host_devaddr;
         .defval    = (bool)_defval,                              \
         }
 
+#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) {       \
+        .name      = (_name),                                    \
+        .info      = &(qdev_prop_bool),                          \
+        .offset    = offsetof(_state, _field)                    \
+            + type_check(bool, typeof_field(_state, _field)),    \
+        .qtype     = QTYPE_QBOOL,                                \
+        .defval    = (bool)_defval,                              \
+        }
+
 #define DEFINE_PROP_UINT8(_n, _s, _f, _d)                       \
     DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
 #define DEFINE_PROP_UINT16(_n, _s, _f, _d)                      \
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw

PATCH v2 1/10 qdev: add qdev property for bool type

---
v2:
- fixed indentation
- replaced error message. Suggested-By: Andreas Färber <[email protected]>

---
 hw/qdev-properties.c |   33 +++++++++++++++++++++++++++++++++
 hw/qdev-properties.h |   10 ++++++++++
 2 files changed, 43 insertions(+), 0 deletions(-)
hw/qdev-properties.c +33 -0
index a8a31f5..b0f2333 100644
@@ -106,6 +106,39 @@ PropertyInfo qdev_prop_bit = {
     .set   = set_bit,
 };
 
+/* --- bool --- */
+
+static void get_bool(Object *obj, Visitor *v, void *opaque,
+                     const char *name, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    bool *ptr = qdev_get_prop_ptr(dev, prop);
+
+    visit_type_bool(v, ptr, name, errp);
+}
+
+static void set_bool(Object *obj, Visitor *v, void *opaque,
+                     const char *name, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    bool *ptr = qdev_get_prop_ptr(dev, prop);
+
+    if (dev->realized) {
+        error_setg(errp, "Property '%s' cannot be changed once realized", name);
+        return;
+    }
+
+    visit_type_bool(v, ptr, name, errp);
+}
+
+PropertyInfo qdev_prop_bool = {
+    .name  = "boolean",
+    .get   = get_bool,
+    .set   = set_bool,
+};
+
 /* --- 8bit integer --- */
 
 static void get_uint8(Object *obj, Visitor *v, void *opaque,
hw/qdev-properties.h +10 -0
index 20c67f3..3915f7c 100644
@@ -6,6 +6,7 @@
 /*** qdev-properties.c ***/
 
 extern PropertyInfo qdev_prop_bit;
+extern PropertyInfo qdev_prop_bool;
 extern PropertyInfo qdev_prop_uint8;
 extern PropertyInfo qdev_prop_uint16;
 extern PropertyInfo qdev_prop_uint32;
@@ -51,6 +52,15 @@ extern PropertyInfo qdev_prop_pci_host_devaddr;
         .defval    = (bool)_defval,                              \
         }
 
+#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) {       \
+        .name      = (_name),                                    \
+        .info      = &(qdev_prop_bool),                          \
+        .offset    = offsetof(_state, _field)                    \
+            + type_check(bool, typeof_field(_state, _field)),    \
+        .qtype     = QTYPE_QBOOL,                                \
+        .defval    = (bool)_defval,                              \
+        }
+
 #define DEFINE_PROP_UINT8(_n, _s, _f, _d)                       \
     DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
 #define DEFINE_PROP_UINT16(_n, _s, _f, _d)                      \
Signature · 1 line
1.7.1
#4 lore raw

Am 07.03.2013 17:16, schrieb Igor Mammedov:

Quoted 5 lines

---
v2:
- fixed indentation
- replaced error message. Suggested-By: Andreas Färber <[email protected]>

Thanks, rebased onto PMM's array properties and applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#5 lore raw
Quoted 8 lines · On Tue, 09 Apr 2013 15:56:57 +0200 Andreas Färber <[email protected]> wrote:

Am 07.03.2013 17:16, schrieb Igor Mammedov:

Quoted 6 lines

---
v2:
- fixed indentation
- replaced error message. Suggested-By: Andreas Färber
<[email protected]>

Quoted 5 lines

Thanks, rebased onto PMM's array properties and applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas

Thanks,

one more note could you fixup setter like Peter did in b000dfbd4, or would you like me send a patch?

#6 lore raw

Am 09.04.2013 16:13, schrieb Igor Mammedov:

Quoted 14 lines
Quoted 11 lines · On Tue, 09 Apr 2013 15:56:57 +0200 Andreas Färber <[email protected]> wrote:

Am 07.03.2013 17:16, schrieb Igor Mammedov:

Quoted 6 lines

---
v2:
- fixed indentation
- replaced error message. Suggested-By: Andreas Färber
<[email protected]>

Thanks, rebased onto PMM's array properties and applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Quoted 7 lines
Quoted 2 lines

Andreas

Thanks,

one more note could you fixup setter like Peter did in b000dfbd4, or would you like me send a patch?

Thanks for pointing that out! Updated to use
qdev_prop_set_after_realized() and pushed.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#8 lore raw

Re: [Qemu-devel] [PATCH qom-cpu-next 00/10 v7] target-i386: convert CPU features into properties

Am 18.03.2013 13:31, schrieb Igor Mammedov:

Quoted 1 line

ping

Thanks. First day back at work here. :)

Cheers,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw

Re: [Qemu-devel] [PATCH 02/10] target-i386: cpu: convert existing dynamic properties into static properties

Am 25.02.2013 02:03, schrieb Igor Mammedov:

Quoted 41 lines

Following properties are converted:
* vendor
* xlevel
* custom setter/getter replaced by qdev's DEFINE_PROP_UINT32
* level
* custom setter/getter replaced by qdev's DEFINE_PROP_UINT32
* tsc-frequency
* stepping
* model
* family
* model-id
* check "if (model_id == NULL)" looks unnecessary now, since all builtin model-ids are not NULL and user shouldn't be able to set it NULL (cpumodel string parsing code takes care of it, if feature is specified as "model-id=" on command line, its parsing will result in an empty string as value).

Common changes to all properties:
* string properties: changed function signature to conform to form used in qdev-properties.c

* extra change is addition of feat2prop() helper to deal with properties naming using '-' instead of '_'. Used in this patch for 'model_id' name conversion and converting along the way 'hv-spinlocks', but will be reused in following patches for "hv_*" and +-foo conversions as well.

v2:
- removed s/error_set/error_setg/;s/QERR*/with similar message/
- made PropertyInfo static
- Left setters/getters atwher they have been, only signature change
+ usin visitors where needed
- use g_malloc0() instead of g_malloc() in x86_cpuid_get_model_id()

---
 target-i386/cpu.c |  174 ++++++++++++++++++++++++++++++++---------------------
 1 files changed, 105 insertions(+), 69 deletions(-)
target-i386/cpu.c +0 -0
index dfcf86e..5626931 100644

[...]

Quoted 40 lines
target-i386/cpu.c +15 -3
@@ -1297,6 +1345,17 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name)
     return -1;
 }
 
+/* It converts all '_' in a feature string option name to '-', to make
+ * feature name to conform property naming rule which uses '-' instead of '_'
+ */
+static inline void feat2prop(char *s)
+{
+    char *delimiter = strchr(s, '=');
+    while ((s = strchr(s, '_')) && ((delimiter == NULL) || (s < delimiter))) {
+        *s = '-';
+    }
+}
+
 /* Parse "+feature,-feature,feature=foo" CPU feature string
  */
 static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
@@ -1318,6 +1377,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
         } else if (featurestr[0] == '-') {
             add_flagname_to_bitmaps(featurestr + 1, minus_features);
         } else if ((val = strchr(featurestr, '='))) {
+            feat2prop(featurestr);
             *val = 0; val++;
             if (!strcmp(featurestr, "family")) {
                 object_property_parse(OBJECT(cpu), val, featurestr, errp);
@@ -1345,9 +1405,9 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
                 object_property_parse(OBJECT(cpu), num, featurestr, errp);
             } else if (!strcmp(featurestr, "vendor")) {
                 object_property_parse(OBJECT(cpu), val, featurestr, errp);
-            } else if (!strcmp(featurestr, "model_id")) {
-                object_property_parse(OBJECT(cpu), val, "model-id", errp);
-            } else if (!strcmp(featurestr, "tsc_freq")) {
+            } else if (!strcmp(featurestr, "model-id")) {
+                object_property_parse(OBJECT(cpu), val, featurestr, errp);
+            } else if (!strcmp(featurestr, "tsc-freq")) {
                 int64_t tsc_freq;
                 char *err;
                 char num[32];

target-i386/cpu.c static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp) · line 1426

Quoted 8 lines
target-i386/cpu.c +1 -1
@@ -1360,7 +1420,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
                 }
                 snprintf(num, sizeof(num), "%" PRId64, tsc_freq);
                 object_property_parse(OBJECT(cpu), num, "tsc-frequency", errp);
-            } else if (!strcmp(featurestr, "hv_spinlocks")) {
+            } else if (!strcmp(featurestr, "hv-spinlocks")) {
                 char *err;
                 numvalue = strtoul(val, &err, 0);
                 if (!*val || *err) {

[snip]

Thanks, split this part off and applied to qom-cpu (modified as below):

https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas

target-i386/cpu.c +0 -0
index f34ba23..697848d 100644
@@ -1307,6 +1307,16 @@ static int cpu_x86_find_by_name(x86_def_t

*x86_cpu_def, c
onst char *name)

     return -1;

}

+/* Convert all '_' in a feature string option name to '-', to make feature
+ * name conform to QOM property naming rule, which uses '-' instead of '_'.
+ */
+static inline void feat2prop(char *s)
+{
+ while ((s = strchr(s, '_'))) {
+ *s = '-';
+ }
+}
+
/* Parse "+feature,-feature,feature=foo" CPU feature string
*/
static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error
**errp)
@@ -1329,6 +1339,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *fe
atures, Error **errp)

             add_flagname_to_bitmaps(featurestr + 1, minus_features);
         } else if ((val = strchr(featurestr, '='))) {
             *val = 0; val++;
+            feat2prop(featurestr);
             if (!strcmp(featurestr, "family")) {
                 object_property_parse(OBJECT(cpu), val, featurestr, errp);
             } else if (!strcmp(featurestr, "model")) {
@@ -1355,9 +1366,9 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu,
char *fe
atures, Error **errp)
                 object_property_parse(OBJECT(cpu), num, featurestr, errp);
             } else if (!strcmp(featurestr, "vendor")) {
                 object_property_parse(OBJECT(cpu), val, featurestr, errp);

- } else if (!strcmp(featurestr, "model_id")) {
- object_property_parse(OBJECT(cpu), val, "model-id", errp);
- } else if (!strcmp(featurestr, "tsc_freq")) {
+ } else if (!strcmp(featurestr, "model-id")) {
+ object_property_parse(OBJECT(cpu), val, featurestr, errp);

+            } else if (!strcmp(featurestr, "tsc-freq")) {
                 int64_t tsc_freq;
                 char *err;
                 char num[32];
@@ -1370,7 +1381,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu,
char *features, Error **errp)
                 }
                 snprintf(num, sizeof(num), "%" PRId64, tsc_freq);
                 object_property_parse(OBJECT(cpu), num,
"tsc-frequency", errp);
-            } else if (!strcmp(featurestr, "hv_spinlocks")) {
+            } else if (!strcmp(featurestr, "hv-spinlocks")) {
                 char *err;
                 numvalue = strtoul(val, &err, 0);
                 if (!*val || *err) {
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg