diff mbox

[04/15] target-i386: Add "family" property to X86CPU

Message ID 1334704279-11708-5-git-send-email-afaerber@suse.de
State New
Headers show

Commit Message

Andreas Färber April 17, 2012, 11:11 p.m. UTC
Add the property early in the initfn so that it can be used in helpers
such as mce_init().

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 target-i386/cpu.c |   38 +++++++++++++++++++++++++++++++++-----
 1 files changed, 33 insertions(+), 5 deletions(-)

Comments

Michael Roth April 19, 2012, 10:34 p.m. UTC | #1
On Wed, Apr 18, 2012 at 01:11:08AM +0200, Andreas Färber wrote:
> Add the property early in the initfn so that it can be used in helpers
> such as mce_init().
> 
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> ---
>  target-i386/cpu.c |   38 +++++++++++++++++++++++++++++++++-----
>  1 files changed, 33 insertions(+), 5 deletions(-)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index d30185b..aa0d328 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -27,6 +27,8 @@
>  #include "qemu-option.h"
>  #include "qemu-config.h"
>  
> +#include "qapi/qapi-visit-core.h"
> +
>  #include "hyperv.h"
>  
>  /* feature flags taken from "Intel Processor Identification and the CPUID
> @@ -597,13 +599,30 @@ static int check_features_against_host(x86_def_t *guest_def)
>      return rv;
>  }
>  
> -static void x86_cpuid_version_set_family(CPUX86State *env, int family)
> +static void x86_cpuid_version_set_family(Object *obj, Visitor *v, void *opaque,
> +                                         const char *name, Error **errp)
>  {
> +    X86CPU *cpu = X86_CPU(obj);
> +    CPUX86State *env = &cpu->env;
> +    const int64_t min = 0;
> +    const int64_t max = 0xff + 0xf;
> +    int64_t value;
> +
> +    visit_type_int(v, &value, name, errp);
> +    if (error_is_set(errp)) {
> +        return;
> +    }
> +    if (value < min || value > max) {
> +        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
> +                  name ? name : "null", value, min, max);
> +        return;
> +    }
> +
>      env->cpuid_version &= ~0xff00f00;
> -    if (family > 0x0f) {
> -        env->cpuid_version |= 0xf00 | ((family - 0x0f) << 20);
> +    if (value > 0x0f) {
> +        env->cpuid_version |= 0xf00 | ((value - 0x0f) << 20);
>      } else {
> -        env->cpuid_version |= family << 8;
> +        env->cpuid_version |= value << 8;
>      }
>  }
>  
> @@ -911,6 +930,7 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
>  {
>      CPUX86State *env = &cpu->env;
>      x86_def_t def1, *def = &def1;
> +    Error *error = NULL;
>  
>      memset(def, 0, sizeof(*def));
>  
> @@ -927,7 +947,7 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
>      }
>      env->cpuid_vendor_override = def->vendor_override;
>      env->cpuid_level = def->level;
> -    x86_cpuid_version_set_family(env, def->family);
> +    object_property_set_int(OBJECT(cpu), def->family, "family", &error);
>      x86_cpuid_version_set_model(env, def->model);
>      x86_cpuid_version_set_stepping(env, def->stepping);
>      env->cpuid_features = def->features;
> @@ -952,6 +972,9 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
>          env->cpuid_svm_features &= TCG_SVM_FEATURES;
>      }
>      x86_cpuid_set_model_id(env, def->model_id);
> +    if (error_is_set(&error)) {

Missing an error_free(error) here

> +        return -1;
> +    }
>      return 0;
>  }
>  
> @@ -1476,6 +1499,11 @@ static void x86_cpu_initfn(Object *obj)
>      CPUX86State *env = &cpu->env;
>  
>      cpu_exec_init(env);
> +
> +    object_property_add(obj, "family", "int",
> +                        NULL,
> +                        x86_cpuid_version_set_family, NULL, NULL, NULL);
> +
>      env->cpuid_apic_id = env->cpu_index;
>      mce_init(cpu);
>  }
> -- 
> 1.7.7
> 
>
Andreas Färber April 20, 2012, 11:16 a.m. UTC | #2
Am 20.04.2012 00:34, schrieb Michael Roth:
> On Wed, Apr 18, 2012 at 01:11:08AM +0200, Andreas Färber wrote:
>> Add the property early in the initfn so that it can be used in helpers
>> such as mce_init().
>>
>> Signed-off-by: Andreas Färber <afaerber@suse.de>
>> ---
>>  target-i386/cpu.c |   38 +++++++++++++++++++++++++++++++++-----
>>  1 files changed, 33 insertions(+), 5 deletions(-)
>>
>> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
>> index d30185b..aa0d328 100644
>> --- a/target-i386/cpu.c
>> +++ b/target-i386/cpu.c
[...]
>> @@ -952,6 +972,9 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
>>          env->cpuid_svm_features &= TCG_SVM_FEATURES;
>>      }
>>      x86_cpuid_set_model_id(env, def->model_id);
>> +    if (error_is_set(&error)) {
> 
> Missing an error_free(error) here

Thanks, fixed on qom-cpu-x86 branch.

Andreas
diff mbox

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index d30185b..aa0d328 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -27,6 +27,8 @@ 
 #include "qemu-option.h"
 #include "qemu-config.h"
 
+#include "qapi/qapi-visit-core.h"
+
 #include "hyperv.h"
 
 /* feature flags taken from "Intel Processor Identification and the CPUID
@@ -597,13 +599,30 @@  static int check_features_against_host(x86_def_t *guest_def)
     return rv;
 }
 
-static void x86_cpuid_version_set_family(CPUX86State *env, int family)
+static void x86_cpuid_version_set_family(Object *obj, Visitor *v, void *opaque,
+                                         const char *name, Error **errp)
 {
+    X86CPU *cpu = X86_CPU(obj);
+    CPUX86State *env = &cpu->env;
+    const int64_t min = 0;
+    const int64_t max = 0xff + 0xf;
+    int64_t value;
+
+    visit_type_int(v, &value, name, errp);
+    if (error_is_set(errp)) {
+        return;
+    }
+    if (value < min || value > max) {
+        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
+                  name ? name : "null", value, min, max);
+        return;
+    }
+
     env->cpuid_version &= ~0xff00f00;
-    if (family > 0x0f) {
-        env->cpuid_version |= 0xf00 | ((family - 0x0f) << 20);
+    if (value > 0x0f) {
+        env->cpuid_version |= 0xf00 | ((value - 0x0f) << 20);
     } else {
-        env->cpuid_version |= family << 8;
+        env->cpuid_version |= value << 8;
     }
 }
 
@@ -911,6 +930,7 @@  int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
 {
     CPUX86State *env = &cpu->env;
     x86_def_t def1, *def = &def1;
+    Error *error = NULL;
 
     memset(def, 0, sizeof(*def));
 
@@ -927,7 +947,7 @@  int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
     }
     env->cpuid_vendor_override = def->vendor_override;
     env->cpuid_level = def->level;
-    x86_cpuid_version_set_family(env, def->family);
+    object_property_set_int(OBJECT(cpu), def->family, "family", &error);
     x86_cpuid_version_set_model(env, def->model);
     x86_cpuid_version_set_stepping(env, def->stepping);
     env->cpuid_features = def->features;
@@ -952,6 +972,9 @@  int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
         env->cpuid_svm_features &= TCG_SVM_FEATURES;
     }
     x86_cpuid_set_model_id(env, def->model_id);
+    if (error_is_set(&error)) {
+        return -1;
+    }
     return 0;
 }
 
@@ -1476,6 +1499,11 @@  static void x86_cpu_initfn(Object *obj)
     CPUX86State *env = &cpu->env;
 
     cpu_exec_init(env);
+
+    object_property_add(obj, "family", "int",
+                        NULL,
+                        x86_cpuid_version_set_family, NULL, NULL, NULL);
+
     env->cpuid_apic_id = env->cpu_index;
     mce_init(cpu);
 }