From: Eduardo Habkost <ehabkost@redhat.com> To: qemu-devel@nongnu.org Cc: Peter Maydell <peter.maydell@linaro.org>, Richard Henderson <rth@twiddle.net>, Igor Mammedov <imammedo@redhat.com> Subject: [Qemu-devel] [PATCH 5/7] cpu: Let architectures set CPU class name format Date: Fri, 19 Apr 2019 03:14:27 -0300 [thread overview] Message-ID: <20190419061429.17695-6-ehabkost@redhat.com> (raw) In-Reply-To: <20190419061429.17695-1-ehabkost@redhat.com> Instead of requiring every architecture to implement a class_by_name function, let them set a format string at CPUClass::class_name_format. This will let us get rid of at least 16 class_by_name functions in the next commits. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- include/qom/cpu.h | 12 ++++++++++++ qom/cpu.c | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index fefd5c26b0..eda6a46b82 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -163,7 +163,19 @@ typedef struct CPUClass { DeviceClass parent_class; /*< public >*/ + /* The following fields configure CPU model name -> QOM type translation: */ + + /* + * arch-specific CPU model -> QOM type translation function. + * Optional if @class_name_format is set. + */ ObjectClass *(*class_by_name)(const char *cpu_model); + /* + * Format string for g_strdup_printf(), used to generate the CPU + * class name. + */ + const char *class_name_format; + void (*parse_features)(const char *typename, char *str, Error **errp); void (*reset)(CPUState *cpu); diff --git a/qom/cpu.c b/qom/cpu.c index b971a56242..1fa64941b6 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -286,9 +286,23 @@ static bool cpu_common_has_work(CPUState *cs) CPUClass *cpu_class_by_name(const char *typename, const char *cpu_model) { CPUClass *cc = CPU_CLASS(object_class_by_name(typename)); + ObjectClass *oc; + char *class_name; - assert(cpu_model && cc->class_by_name); - return CPU_CLASS(cc->class_by_name(cpu_model)); + assert(cpu_model); + if (cc->class_by_name) { + return CPU_CLASS(cc->class_by_name(cpu_model)); + } + + assert(cc->class_name_format); + class_name = g_strdup_printf(cc->class_name_format, cpu_model); + oc = object_class_by_name(class_name); + g_free(class_name); + if (!oc || !object_class_dynamic_cast(oc, typename) || + object_class_is_abstract(oc)) { + return NULL; + } + return CPU_CLASS(oc); } static void cpu_common_parse_features(const char *typename, char *features, -- 2.18.0.rc1.1.g3f1ff2140
WARNING: multiple messages have this Message-ID (diff)
From: Eduardo Habkost <ehabkost@redhat.com> To: qemu-devel@nongnu.org Cc: Peter Maydell <peter.maydell@linaro.org>, Igor Mammedov <imammedo@redhat.com>, Richard Henderson <rth@twiddle.net> Subject: [Qemu-devel] [PATCH 5/7] cpu: Let architectures set CPU class name format Date: Fri, 19 Apr 2019 03:14:27 -0300 [thread overview] Message-ID: <20190419061429.17695-6-ehabkost@redhat.com> (raw) Message-ID: <20190419061427.FzI5_bRTmKrswRoVZxuYSQwvRm9bIO4CfNCzGhQwN_k@z> (raw) In-Reply-To: <20190419061429.17695-1-ehabkost@redhat.com> Instead of requiring every architecture to implement a class_by_name function, let them set a format string at CPUClass::class_name_format. This will let us get rid of at least 16 class_by_name functions in the next commits. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- include/qom/cpu.h | 12 ++++++++++++ qom/cpu.c | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index fefd5c26b0..eda6a46b82 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -163,7 +163,19 @@ typedef struct CPUClass { DeviceClass parent_class; /*< public >*/ + /* The following fields configure CPU model name -> QOM type translation: */ + + /* + * arch-specific CPU model -> QOM type translation function. + * Optional if @class_name_format is set. + */ ObjectClass *(*class_by_name)(const char *cpu_model); + /* + * Format string for g_strdup_printf(), used to generate the CPU + * class name. + */ + const char *class_name_format; + void (*parse_features)(const char *typename, char *str, Error **errp); void (*reset)(CPUState *cpu); diff --git a/qom/cpu.c b/qom/cpu.c index b971a56242..1fa64941b6 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -286,9 +286,23 @@ static bool cpu_common_has_work(CPUState *cs) CPUClass *cpu_class_by_name(const char *typename, const char *cpu_model) { CPUClass *cc = CPU_CLASS(object_class_by_name(typename)); + ObjectClass *oc; + char *class_name; - assert(cpu_model && cc->class_by_name); - return CPU_CLASS(cc->class_by_name(cpu_model)); + assert(cpu_model); + if (cc->class_by_name) { + return CPU_CLASS(cc->class_by_name(cpu_model)); + } + + assert(cc->class_name_format); + class_name = g_strdup_printf(cc->class_name_format, cpu_model); + oc = object_class_by_name(class_name); + g_free(class_name); + if (!oc || !object_class_dynamic_cast(oc, typename) || + object_class_is_abstract(oc)) { + return NULL; + } + return CPU_CLASS(oc); } static void cpu_common_parse_features(const char *typename, char *features, -- 2.18.0.rc1.1.g3f1ff2140
next prev parent reply other threads:[~2019-04-19 6:14 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-04-19 6:14 [Qemu-devel] [PATCH 0/7] Delete 16 *_cpu_class_by_name() functions Eduardo Habkost 2019-04-19 6:14 ` Eduardo Habkost 2019-04-19 6:14 ` [Qemu-devel] [PATCH 1/7] cpu: Change return type of cpu_class_by_name() to CPUClass Eduardo Habkost 2019-04-19 6:14 ` Eduardo Habkost 2019-04-19 6:14 ` [Qemu-devel] [PATCH 2/7] riscv: Don't split CPU model string Eduardo Habkost 2019-04-19 6:14 ` Eduardo Habkost 2019-04-19 21:00 ` Alistair Francis 2019-04-19 21:00 ` Alistair Francis 2019-04-19 6:14 ` [Qemu-devel] [PATCH 3/7] arm: " Eduardo Habkost 2019-04-19 6:14 ` Eduardo Habkost 2019-04-19 6:14 ` [Qemu-devel] [PATCH 4/7] arm: Remove special case for "any" CPU model Eduardo Habkost 2019-04-19 6:14 ` Eduardo Habkost 2019-04-19 6:14 ` Eduardo Habkost [this message] 2019-04-19 6:14 ` [Qemu-devel] [PATCH 5/7] cpu: Let architectures set CPU class name format Eduardo Habkost 2019-05-06 11:42 ` Markus Armbruster 2019-05-08 5:52 ` Markus Armbruster 2019-04-19 6:14 ` [Qemu-devel] [PATCH 6/7] cpu: Set class name format for some architectures Eduardo Habkost 2019-04-19 6:14 ` Eduardo Habkost 2019-04-19 20:59 ` Alistair Francis 2019-04-19 20:59 ` Alistair Francis 2019-04-19 6:14 ` [Qemu-devel] [PATCH 7/7] cpu: Set fixed class name on " Eduardo Habkost 2019-04-19 6:14 ` Eduardo Habkost 2019-05-06 11:53 ` [Qemu-devel] [PATCH 0/7] Delete 16 *_cpu_class_by_name() functions Markus Armbruster 2019-05-06 19:53 ` Eduardo Habkost 2019-05-08 8:34 ` Markus Armbruster 2019-05-08 19:46 ` Eduardo Habkost 2019-05-09 5:55 ` Markus Armbruster 2019-05-09 15:46 ` Igor Mammedov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190419061429.17695-6-ehabkost@redhat.com \ --to=ehabkost@redhat.com \ --cc=imammedo@redhat.com \ --cc=peter.maydell@linaro.org \ --cc=qemu-devel@nongnu.org \ --cc=rth@twiddle.net \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).