cpu_generic_init() without realized=true. Gives board code an opportunity to change CPU properties. --- include/qom/cpu.h | 12 ++++++++++++ qom/cpu.c | 23 +++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 51a1323..9093500 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -489,6 +489,18 @@ ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model); CPUState *cpu_generic_init(const char *typename, const char *cpu_model); /** + * cpu_generic_init_unrealized: + * @typename: The CPU base type. + * @cpu_model: The model string including optional parameters. + * + * Instantiates a CPU, processes optional parameters but does not realize it. + * + * Returns: A #CPUState or %NULL if an error occurred. + */ +CPUState *cpu_generic_init_unrealized(const char *typename, + const char *cpu_model); + +/** * cpu_has_work: * @cpu: The vCPU to check. * diff --git a/qom/cpu.c b/qom/cpu.c index fb80d13..f622fc2 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -42,6 +42,23 @@ bool cpu_exists(int64_t id) CPUState *cpu_generic_init(const char *typename, const char *cpu_model) { + CPUState *cpu = cpu_generic_init_unrealized(typename, cpu_model); + if (cpu) { + Error *err = NULL; + object_property_set_bool(OBJECT(cpu), true, "realized", &err); + + if (err != NULL) { + error_report_err(err); + object_unref(OBJECT(cpu)); + return NULL; + } + } + return cpu; +} + +CPUState *cpu_generic_init_unrealized(const char *typename, + const char *cpu_model) +{ char *str, *name, *featurestr; CPUState *cpu; ObjectClass *oc; @@ -63,13 +80,7 @@ CPUState *cpu_generic_init(const char *typename, const char *cpu_model) featurestr = strtok(NULL, ","); cc->parse_features(cpu, featurestr, &err); g_free(str); - if (err != NULL) { - goto out; - } - - object_property_set_bool(OBJECT(cpu), true, "realized", &err); -out: if (err != NULL) { error_report_err(err); object_unref(OBJECT(cpu)); -- 2.1.4