[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 26/37] target-i386: convert "vendor" property to sta
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH 26/37] target-i386: convert "vendor" property to static property |
Date: |
Mon, 22 Oct 2012 17:03:12 +0200 |
Signed-off-by: Igor Mammedov <address@hidden>
---
* use error_setg() instead of error_set()
* checkpatch doesn't like 'foo[i ]' used in original setter/getter, make it
happy.
---
target-i386/cpu.c | 102 +++++++++++++++++++++++++++++++-----------------------
1 file changed, 59 insertions(+), 43 deletions(-)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 09c354c..a1790aa 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -293,6 +293,64 @@ PropertyInfo qdev_prop_enforce = {
#define DEFINE_PROP_ENFORCE(_n)
\
DEFINE_ABSTRACT_PROP(_n, qdev_prop_enforce)
+static void x86_cpuid_get_vendor(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ X86CPU *cpu = X86_CPU(obj);
+ CPUX86State *env = &cpu->env;
+ char *value;
+ int i;
+
+ value = (char *)g_malloc(CPUID_VENDOR_SZ + 1);
+ for (i = 0; i < 4; i++) {
+ value[i] = env->cpuid_vendor1 >> (8 * i);
+ value[i + 4] = env->cpuid_vendor2 >> (8 * i);
+ value[i + 8] = env->cpuid_vendor3 >> (8 * i);
+ }
+ value[CPUID_VENDOR_SZ] = '\0';
+ visit_type_str(v, &value, name, errp);
+ g_free(value);
+}
+
+static void x86_cpuid_set_vendor(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ X86CPU *cpu = X86_CPU(obj);
+ CPUX86State *env = &cpu->env;
+ char *value;
+ int i;
+
+ visit_type_str(v, &value, name, errp);
+ if (error_is_set(errp)) {
+ return;
+ }
+
+ if (strlen(value) != CPUID_VENDOR_SZ) {
+ error_setg(errp, "Property '%s.%s' doesn't take value '%s'",
+ object_get_typename(obj), name, value);
+ g_free(value);
+ return;
+ }
+
+ env->cpuid_vendor1 = 0;
+ env->cpuid_vendor2 = 0;
+ env->cpuid_vendor3 = 0;
+ for (i = 0; i < 4; i++) {
+ env->cpuid_vendor1 |= ((uint8_t)value[i]) << (8 * i);
+ env->cpuid_vendor2 |= ((uint8_t)value[i + 4]) << (8 * i);
+ env->cpuid_vendor3 |= ((uint8_t)value[i + 8]) << (8 * i);
+ }
+ g_free(value);
+}
+
+PropertyInfo qdev_prop_vendor = {
+ .name = "string",
+ .get = x86_cpuid_get_vendor,
+ .set = x86_cpuid_set_vendor,
+};
+#define DEFINE_PROP_VENDOR(_n, _s, _f)
\
+ DEFINE_PROP(_n, _s, _f, qdev_prop_vendor, uint32_t)
+
static Property cpu_x86_properties[] = {
DEFINE_PROP_BIT("f-fpu", X86CPU, env.cpuid_features, 0, false),
DEFINE_PROP_BIT("f-vme", X86CPU, env.cpuid_features, 1, false),
@@ -412,6 +470,7 @@ static Property cpu_x86_properties[] = {
DEFINE_PROP_HV_VAPIC("hv_vapic"),
DEFINE_PROP_CHECK("check"),
DEFINE_PROP_ENFORCE("enforce"),
+ DEFINE_PROP_VENDOR("vendor", X86CPU, env.cpuid_vendor1),
DEFINE_PROP_END_OF_LIST(),
};
@@ -1233,46 +1292,6 @@ static void x86_cpuid_version_set_stepping(Object *obj,
Visitor *v,
env->cpuid_version |= value & 0xf;
}
-static char *x86_cpuid_get_vendor(Object *obj, Error **errp)
-{
- X86CPU *cpu = X86_CPU(obj);
- CPUX86State *env = &cpu->env;
- char *value;
- int i;
-
- value = (char *)g_malloc(CPUID_VENDOR_SZ + 1);
- for (i = 0; i < 4; i++) {
- value[i ] = env->cpuid_vendor1 >> (8 * i);
- value[i + 4] = env->cpuid_vendor2 >> (8 * i);
- value[i + 8] = env->cpuid_vendor3 >> (8 * i);
- }
- value[CPUID_VENDOR_SZ] = '\0';
- return value;
-}
-
-static void x86_cpuid_set_vendor(Object *obj, const char *value,
- Error **errp)
-{
- X86CPU *cpu = X86_CPU(obj);
- CPUX86State *env = &cpu->env;
- int i;
-
- if (strlen(value) != CPUID_VENDOR_SZ) {
- error_set(errp, QERR_PROPERTY_VALUE_BAD, "",
- "vendor", value);
- return;
- }
-
- env->cpuid_vendor1 = 0;
- env->cpuid_vendor2 = 0;
- env->cpuid_vendor3 = 0;
- for (i = 0; i < 4; i++) {
- env->cpuid_vendor1 |= ((uint8_t)value[i ]) << (8 * i);
- env->cpuid_vendor2 |= ((uint8_t)value[i + 4]) << (8 * i);
- env->cpuid_vendor3 |= ((uint8_t)value[i + 8]) << (8 * i);
- }
-}
-
static char *x86_cpuid_get_model_id(Object *obj, Error **errp)
{
X86CPU *cpu = X86_CPU(obj);
@@ -2214,9 +2233,6 @@ static void x86_cpu_initfn(Object *obj)
object_property_add(obj, "stepping", "int",
x86_cpuid_version_get_stepping,
x86_cpuid_version_set_stepping, NULL, NULL, NULL);
- object_property_add_str(obj, "vendor",
- x86_cpuid_get_vendor,
- x86_cpuid_set_vendor, NULL);
object_property_add_str(obj, "model-id",
x86_cpuid_get_model_id,
x86_cpuid_set_model_id, NULL);
--
1.7.11.7
- [Qemu-devel] [PATCH 34/37] qdev: introduce QDEV_FIND_PROP_FROM_BIT and qdev_prop_find_bit(), (continued)
- [Qemu-devel] [PATCH 34/37] qdev: introduce QDEV_FIND_PROP_FROM_BIT and qdev_prop_find_bit(), Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 25/37] target-i386: replace uint32_t vendor fields by vendor string in x86_def_t, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 23/37] target-i386: convert 'check' and 'enforce' to static properties, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 36/37] target-i386: use static properties to list CPUID features, Igor Mammedov, 2012/10/22
- Re: [Qemu-devel] [PATCH 36/37] target-i386: use static properties to list CPUID features, Don Slutz, 2012/10/23
- [Qemu-devel] [PATCH 37/37] target-i386: cleanup cpu_x86_find_by_name(), only fill x86_def_t in it, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 26/37] target-i386: convert "vendor" property to static property,
Igor Mammedov <=
- [Qemu-devel] [PATCH 30/37] target-i386: convert "model" to static property, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 24/37] target-i386: use define for cpuid vendor string size, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 09/37] qdev: export qdev_prop_find() and allow it to be used with DeviceClass instead of Object, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 27/37] target-i386: convert "tsc-frequency" to static property, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 15/37] target-i386: set default value of "hypervisor" feature using static property, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 22/37] target-i386: convert 'hv_vapic' to static property, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 05/37] target-i386: move out CPU features initialization in separate func, Igor Mammedov, 2012/10/22