[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL for-2.0-rc0 20/58] cpu: Introduce CPUClass::parse_fea
From: |
Andreas Färber |
Subject: |
[Qemu-devel] [PULL for-2.0-rc0 20/58] cpu: Introduce CPUClass::parse_features() hook |
Date: |
Thu, 13 Mar 2014 15:54:23 +0100 |
Adapt the X86CPU implementation to suit the generic hook.
This involves a cleanup of error handling to cope with NULL errp.
Reviewed-by: Igor Mammedov <address@hidden>
Signed-off-by: Andreas Färber <address@hidden>
---
include/qom/cpu.h | 2 ++
target-i386/cpu.c | 36 +++++++++++++++++++++---------------
2 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 89d5dd1..3703b68 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -68,6 +68,7 @@ struct TranslationBlock;
* CPUClass:
* @class_by_name: Callback to map -cpu command line model name to an
* instantiatable CPU type.
+ * @parse_features: Callback to parse command line arguments.
* @reset: Callback to reset the #CPUState to its initial state.
* @reset_dump_flags: #CPUDumpFlags to use for reset logging.
* @has_work: Callback for checking if there is work to do.
@@ -97,6 +98,7 @@ typedef struct CPUClass {
/*< public >*/
ObjectClass *(*class_by_name)(const char *cpu_model);
+ void (*parse_features)(CPUState *cpu, char *str, Error **errp);
void (*reset)(CPUState *cpu);
int reset_dump_flags;
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 8070c97..d9a8f47 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1648,8 +1648,10 @@ static inline void feat2prop(char *s)
/* Parse "+feature,-feature,feature=foo" CPU feature string
*/
-static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
+static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
+ Error **errp)
{
+ X86CPU *cpu = X86_CPU(cs);
char *featurestr; /* Single 'key=value" string being parsed */
/* Features to be added */
FeatureWordArray plus_features = { 0 };
@@ -1657,6 +1659,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char
*features, Error **errp)
FeatureWordArray minus_features = { 0 };
uint32_t numvalue;
CPUX86State *env = &cpu->env;
+ Error *local_err = NULL;
featurestr = features ? strtok(features, ",") : NULL;
@@ -1675,16 +1678,16 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char
*features, Error **errp)
numvalue = strtoul(val, &err, 0);
if (!*val || *err) {
- error_setg(errp, "bad numerical value %s", val);
+ error_setg(&local_err, "bad numerical value %s", val);
goto out;
}
if (numvalue < 0x80000000) {
- fprintf(stderr, "xlevel value shall always be >=
0x80000000"
- ", fixup will be removed in future versions\n");
+ error_report("xlevel value shall always be >= 0x80000000"
+ ", fixup will be removed in future versions");
numvalue += 0x80000000;
}
snprintf(num, sizeof(num), "%" PRIu32, numvalue);
- object_property_parse(OBJECT(cpu), num, featurestr, errp);
+ object_property_parse(OBJECT(cpu), num, featurestr,
&local_err);
} else if (!strcmp(featurestr, "tsc-freq")) {
int64_t tsc_freq;
char *err;
@@ -1693,36 +1696,38 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char
*features, Error **errp)
tsc_freq = strtosz_suffix_unit(val, &err,
STRTOSZ_DEFSUFFIX_B, 1000);
if (tsc_freq < 0 || *err) {
- error_setg(errp, "bad numerical value %s", val);
+ error_setg(&local_err, "bad numerical value %s", val);
goto out;
}
snprintf(num, sizeof(num), "%" PRId64, tsc_freq);
- object_property_parse(OBJECT(cpu), num, "tsc-frequency", errp);
+ object_property_parse(OBJECT(cpu), num, "tsc-frequency",
+ &local_err);
} else if (!strcmp(featurestr, "hv-spinlocks")) {
char *err;
const int min = 0xFFF;
char num[32];
numvalue = strtoul(val, &err, 0);
if (!*val || *err) {
- error_setg(errp, "bad numerical value %s", val);
+ error_setg(&local_err, "bad numerical value %s", val);
goto out;
}
if (numvalue < min) {
- fprintf(stderr, "hv-spinlocks value shall always be >=
0x%x"
- ", fixup will be removed in future versions\n",
+ error_report("hv-spinlocks value shall always be >= 0x%x"
+ ", fixup will be removed in future versions",
min);
numvalue = min;
}
snprintf(num, sizeof(num), "%" PRId32, numvalue);
- object_property_parse(OBJECT(cpu), num, featurestr, errp);
+ object_property_parse(OBJECT(cpu), num, featurestr,
&local_err);
} else {
- object_property_parse(OBJECT(cpu), val, featurestr, errp);
+ object_property_parse(OBJECT(cpu), val, featurestr,
&local_err);
}
} else {
feat2prop(featurestr);
- object_property_parse(OBJECT(cpu), "on", featurestr, errp);
+ object_property_parse(OBJECT(cpu), "on", featurestr, &local_err);
}
- if (error_is_set(errp)) {
+ if (local_err) {
+ error_propagate(errp, local_err);
goto out;
}
featurestr = strtok(NULL, ",");
@@ -1941,7 +1946,7 @@ X86CPU *cpu_x86_create(const char *cpu_model, DeviceState
*icc_bridge,
object_unref(OBJECT(cpu));
#endif
- cpu_x86_parse_featurestr(cpu, features, &error);
+ x86_cpu_parse_featurestr(CPU(cpu), features, &error);
if (error) {
goto out;
}
@@ -2791,6 +2796,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc,
void *data)
cc->reset_dump_flags = CPU_DUMP_FPU | CPU_DUMP_CCOP;
cc->class_by_name = x86_cpu_class_by_name;
+ cc->parse_features = x86_cpu_parse_featurestr;
cc->has_work = x86_cpu_has_work;
cc->do_interrupt = x86_cpu_do_interrupt;
cc->dump_state = x86_cpu_dump_state;
--
1.8.4.5
- [Qemu-devel] [PULL for-2.0-rc0 09/58] target-xtensa: Clean up ENV_GET_CPU() usage, (continued)
- [Qemu-devel] [PULL for-2.0-rc0 09/58] target-xtensa: Clean up ENV_GET_CPU() usage, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 12/58] target-i386: Call x86_cpu_load_def() earlier, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 10/58] cpu: Turn cpu_has_work() into a CPUClass hook, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 13/58] target-i386: Rename x86_def_t to X86CPUDefinition, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 11/58] target-i386: Rename cpu_x86_register() to x86_cpu_load_def(), Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 15/58] target-i386: Make kvm_default_features an array, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 14/58] target-i386: Don't declare variables in the middle of blocks, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 18/58] target-i386: Prepare CPUClass::class_by_name for X86CPU, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 16/58] target-i386: Introduce x86_cpu_compat_disable_kvm_features(), Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 17/58] target-i386: Enable x2apic by default on KVM, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 20/58] cpu: Introduce CPUClass::parse_features() hook,
Andreas Färber <=
- [Qemu-devel] [PULL for-2.0-rc0 21/58] target-sparc: Use error_report() for CPU error reporting, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 23/58] target-sparc: Defer SPARCCPU feature inference to QOM realize, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 19/58] target-i386: X86CPU model subclasses, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 24/58] cpu: Implement CPUClass::parse_features() for the rest of CPUs, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 26/58] target-m68k: Remove custom qemu_assert() function, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 22/58] target-sparc: Implement CPUClass::parse_features() for SPARCCPU, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 25/58] cpu: Factor out cpu_generic_init(), Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 28/58] cpu: Move mem_io_{pc, vaddr} fields from CPU_COMMON to CPUState, Andreas Färber, 2014/03/13
- [Qemu-devel] [PULL for-2.0-rc0 27/58] cpu: Turn cpu_handle_mmu_fault() into a CPUClass hook, Andreas Färber, 2014/03/13