[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 28/37] target-i386: convert "model-id" to static pro
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH 28/37] target-i386: convert "model-id" to static property |
Date: |
Mon, 22 Oct 2012 17:03:14 +0200 |
check "if (model_id == NULL)" looks to 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).
- use g_malloc0() instead of g_malloc() in x86_cpuid_get_model_id()
Signed-off-by: Igor Mammedov <address@hidden>
---
target-i386/cpu.c | 91 +++++++++++++++++++++++++++++++------------------------
1 file changed, 51 insertions(+), 40 deletions(-)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 8d3f4cc..6cbdde1 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -391,6 +391,56 @@ PropertyInfo qdev_prop_tsc_freq = {
#define DEFINE_PROP_TSC_FREQ(_n, _s, _f)
\
DEFINE_PROP(_n, _s, _f, qdev_prop_tsc_freq, int32_t)
+static void x86_cpuid_get_model_id(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 = g_malloc0(48 + 1);
+ for (i = 0; i < 48; i++) {
+ value[i] = env->cpuid_model[i >> 2] >> (8 * (i & 3));
+ }
+ visit_type_str(v, &value, name, errp);
+ g_free(value);
+}
+
+static void x86_cpuid_set_model_id(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ X86CPU *cpu = X86_CPU(obj);
+ CPUX86State *env = &cpu->env;
+ int c, len, i;
+ char *value;
+
+ visit_type_str(v, &value, name, errp);
+ if (error_is_set(errp)) {
+ return;
+ }
+
+ len = strlen(value);
+ memset(env->cpuid_model, 0, 48);
+ for (i = 0; i < 48; i++) {
+ if (i >= len) {
+ c = '\0';
+ } else {
+ c = (uint8_t)value[i];
+ }
+ env->cpuid_model[i >> 2] |= c << (8 * (i & 3));
+ }
+ g_free(value);
+}
+
+PropertyInfo qdev_prop_model_id = {
+ .name = "string",
+ .get = x86_cpuid_get_model_id,
+ .set = x86_cpuid_set_model_id,
+};
+#define DEFINE_PROP_MODEL_ID(_n)
\
+ DEFINE_ABSTRACT_PROP(_n, qdev_prop_model_id)
+
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),
@@ -512,6 +562,7 @@ static Property cpu_x86_properties[] = {
DEFINE_PROP_ENFORCE("enforce"),
DEFINE_PROP_VENDOR("vendor", X86CPU, env.cpuid_vendor1),
DEFINE_PROP_TSC_FREQ("tsc-frequency", X86CPU, env.tsc_khz),
+ DEFINE_PROP_MODEL_ID("model-id"),
DEFINE_PROP_END_OF_LIST(),
};
@@ -1333,43 +1384,6 @@ static void x86_cpuid_version_set_stepping(Object *obj,
Visitor *v,
env->cpuid_version |= value & 0xf;
}
-static char *x86_cpuid_get_model_id(Object *obj, Error **errp)
-{
- X86CPU *cpu = X86_CPU(obj);
- CPUX86State *env = &cpu->env;
- char *value;
- int i;
-
- value = g_malloc(48 + 1);
- for (i = 0; i < 48; i++) {
- value[i] = env->cpuid_model[i >> 2] >> (8 * (i & 3));
- }
- value[48] = '\0';
- return value;
-}
-
-static void x86_cpuid_set_model_id(Object *obj, const char *model_id,
- Error **errp)
-{
- X86CPU *cpu = X86_CPU(obj);
- CPUX86State *env = &cpu->env;
- int c, len, i;
-
- if (model_id == NULL) {
- model_id = "";
- }
- len = strlen(model_id);
- memset(env->cpuid_model, 0, 48);
- for (i = 0; i < 48; i++) {
- if (i >= len) {
- c = '\0';
- } else {
- c = (uint8_t)model_id[i];
- }
- env->cpuid_model[i >> 2] |= c << (8 * (i & 3));
- }
-}
-
static void cpudef_2_x86_cpu(X86CPU *cpu, x86_def_t *def, Error **errp)
{
CPUX86State *env = &cpu->env;
@@ -2243,9 +2257,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, "model-id",
- x86_cpuid_get_model_id,
- x86_cpuid_set_model_id, NULL);
env->cpuid_apic_id = env->cpu_index;
--
1.7.11.7
- [Qemu-devel] [PATCH 10/37] target-i386: parse cpu_model string into set of stringified properties, (continued)
- [Qemu-devel] [PATCH 10/37] target-i386: parse cpu_model string into set of stringified properties, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 01/37] target-i386: return Error from cpu_x86_find_by_name(), Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 03/37] target-i386: if x86_cpu_realize() failed report error and do cleanup, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 13/37] target-i386: convert "level" to static property, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 06/37] add visitor for parsing hz[KMG] input string, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 14/37] target-i386: postpone cpuid_level update to realize time, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 08/37] target-i386: define static properties for cpuid features, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 21/37] target-i386: convert 'hv_relaxed' to static property, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 11/37] target-i386: introduce vendor-override static property, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 28/37] target-i386: convert "model-id" to static property,
Igor Mammedov <=
- [Qemu-devel] [PATCH 20/37] target-i386: convert 'hv_spinlocks' to static property, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 19/37] qdev: add DEFINE_ABSTRACT_PROP() helper, Igor Mammedov, 2012/10/22
- [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