Message ID | 20221220111122.8966-6-philmd@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | target: Restrict 'qapi-commands-machine.h' to system emulation | expand |
On 12/20/22 12:11, Philippe Mathieu-Daudé wrote: > Since commit a0e61807a3 ("qapi: Remove QMP events and commands from > user-mode builds") we don't generate the "qapi-commands-machine.h" > header in a user-emulation-only build. > > Move the QMP functions from cpu_init.c (which is always compiled) to > monitor.c (which is only compiled when system-emulation is selected). > Note ppc_cpu_class_by_name() is used by both file units, so we expose > its prototype in "cpu-qom.h". > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Cédric Le Goater <clg@kaod.org> Thanks, C. > --- > target/ppc/cpu-qom.h | 2 ++ > target/ppc/cpu_init.c | 48 +---------------------------------------- > target/ppc/monitor.c | 50 ++++++++++++++++++++++++++++++++++++++++++- > 3 files changed, 52 insertions(+), 48 deletions(-) > > diff --git a/target/ppc/cpu-qom.h b/target/ppc/cpu-qom.h > index 89ff88f28c..6431c520c8 100644 > --- a/target/ppc/cpu-qom.h > +++ b/target/ppc/cpu-qom.h > @@ -31,6 +31,8 @@ > > OBJECT_DECLARE_CPU_TYPE(PowerPCCPU, PowerPCCPUClass, POWERPC_CPU) > > +ObjectClass *ppc_cpu_class_by_name(const char *name); > + > typedef struct CPUArchState CPUPPCState; > typedef struct ppc_tb_t ppc_tb_t; > typedef struct ppc_dcr_t ppc_dcr_t; > diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c > index cbf0081374..7858cc4c6c 100644 > --- a/target/ppc/cpu_init.c > +++ b/target/ppc/cpu_init.c > @@ -40,7 +40,6 @@ > #include "qemu/cutils.h" > #include "disas/capstone.h" > #include "fpu/softfloat.h" > -#include "qapi/qapi-commands-machine-target.h" > > #include "helper_regs.h" > #include "internal.h" > @@ -6816,7 +6815,7 @@ static const char *ppc_cpu_lookup_alias(const char *alias) > return NULL; > } > > -static ObjectClass *ppc_cpu_class_by_name(const char *name) > +ObjectClass *ppc_cpu_class_by_name(const char *name) > { > char *cpu_model, *typename; > ObjectClass *oc; > @@ -6956,51 +6955,6 @@ void ppc_cpu_list(void) > #endif > } > > -static void ppc_cpu_defs_entry(gpointer data, gpointer user_data) > -{ > - ObjectClass *oc = data; > - CpuDefinitionInfoList **first = user_data; > - const char *typename; > - CpuDefinitionInfo *info; > - > - typename = object_class_get_name(oc); > - info = g_malloc0(sizeof(*info)); > - info->name = g_strndup(typename, > - strlen(typename) - strlen(POWERPC_CPU_TYPE_SUFFIX)); > - > - QAPI_LIST_PREPEND(*first, info); > -} > - > -CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) > -{ > - CpuDefinitionInfoList *cpu_list = NULL; > - GSList *list; > - int i; > - > - list = object_class_get_list(TYPE_POWERPC_CPU, false); > - g_slist_foreach(list, ppc_cpu_defs_entry, &cpu_list); > - g_slist_free(list); > - > - for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) { > - PowerPCCPUAlias *alias = &ppc_cpu_aliases[i]; > - ObjectClass *oc; > - CpuDefinitionInfo *info; > - > - oc = ppc_cpu_class_by_name(alias->model); > - if (oc == NULL) { > - continue; > - } > - > - info = g_malloc0(sizeof(*info)); > - info->name = g_strdup(alias->alias); > - info->q_typename = g_strdup(object_class_get_name(oc)); > - > - QAPI_LIST_PREPEND(cpu_list, info); > - } > - > - return cpu_list; > -} > - > static void ppc_cpu_set_pc(CPUState *cs, vaddr value) > { > PowerPCCPU *cpu = POWERPC_CPU(cs); > diff --git a/target/ppc/monitor.c b/target/ppc/monitor.c > index 8250b1304e..36e5b5eff8 100644 > --- a/target/ppc/monitor.c > +++ b/target/ppc/monitor.c > @@ -1,5 +1,5 @@ > /* > - * QEMU monitor > + * QEMU PPC (monitor definitions) > * > * Copyright (c) 2003-2004 Fabrice Bellard > * > @@ -28,6 +28,9 @@ > #include "qemu/ctype.h" > #include "monitor/hmp-target.h" > #include "monitor/hmp.h" > +#include "qapi/qapi-commands-machine-target.h" > +#include "cpu-models.h" > +#include "cpu-qom.h" > > static target_long monitor_get_ccr(Monitor *mon, const struct MonitorDef *md, > int val) > @@ -172,3 +175,48 @@ int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval) > > return -EINVAL; > } > + > +static void ppc_cpu_defs_entry(gpointer data, gpointer user_data) > +{ > + ObjectClass *oc = data; > + CpuDefinitionInfoList **first = user_data; > + const char *typename; > + CpuDefinitionInfo *info; > + > + typename = object_class_get_name(oc); > + info = g_malloc0(sizeof(*info)); > + info->name = g_strndup(typename, > + strlen(typename) - strlen(POWERPC_CPU_TYPE_SUFFIX)); > + > + QAPI_LIST_PREPEND(*first, info); > +} > + > +CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) > +{ > + CpuDefinitionInfoList *cpu_list = NULL; > + GSList *list; > + int i; > + > + list = object_class_get_list(TYPE_POWERPC_CPU, false); > + g_slist_foreach(list, ppc_cpu_defs_entry, &cpu_list); > + g_slist_free(list); > + > + for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) { > + PowerPCCPUAlias *alias = &ppc_cpu_aliases[i]; > + ObjectClass *oc; > + CpuDefinitionInfo *info; > + > + oc = ppc_cpu_class_by_name(alias->model); > + if (oc == NULL) { > + continue; > + } > + > + info = g_malloc0(sizeof(*info)); > + info->name = g_strdup(alias->alias); > + info->q_typename = g_strdup(object_class_get_name(oc)); > + > + QAPI_LIST_PREPEND(cpu_list, info); > + } > + > + return cpu_list; > +}
diff --git a/target/ppc/cpu-qom.h b/target/ppc/cpu-qom.h index 89ff88f28c..6431c520c8 100644 --- a/target/ppc/cpu-qom.h +++ b/target/ppc/cpu-qom.h @@ -31,6 +31,8 @@ OBJECT_DECLARE_CPU_TYPE(PowerPCCPU, PowerPCCPUClass, POWERPC_CPU) +ObjectClass *ppc_cpu_class_by_name(const char *name); + typedef struct CPUArchState CPUPPCState; typedef struct ppc_tb_t ppc_tb_t; typedef struct ppc_dcr_t ppc_dcr_t; diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index cbf0081374..7858cc4c6c 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -40,7 +40,6 @@ #include "qemu/cutils.h" #include "disas/capstone.h" #include "fpu/softfloat.h" -#include "qapi/qapi-commands-machine-target.h" #include "helper_regs.h" #include "internal.h" @@ -6816,7 +6815,7 @@ static const char *ppc_cpu_lookup_alias(const char *alias) return NULL; } -static ObjectClass *ppc_cpu_class_by_name(const char *name) +ObjectClass *ppc_cpu_class_by_name(const char *name) { char *cpu_model, *typename; ObjectClass *oc; @@ -6956,51 +6955,6 @@ void ppc_cpu_list(void) #endif } -static void ppc_cpu_defs_entry(gpointer data, gpointer user_data) -{ - ObjectClass *oc = data; - CpuDefinitionInfoList **first = user_data; - const char *typename; - CpuDefinitionInfo *info; - - typename = object_class_get_name(oc); - info = g_malloc0(sizeof(*info)); - info->name = g_strndup(typename, - strlen(typename) - strlen(POWERPC_CPU_TYPE_SUFFIX)); - - QAPI_LIST_PREPEND(*first, info); -} - -CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) -{ - CpuDefinitionInfoList *cpu_list = NULL; - GSList *list; - int i; - - list = object_class_get_list(TYPE_POWERPC_CPU, false); - g_slist_foreach(list, ppc_cpu_defs_entry, &cpu_list); - g_slist_free(list); - - for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) { - PowerPCCPUAlias *alias = &ppc_cpu_aliases[i]; - ObjectClass *oc; - CpuDefinitionInfo *info; - - oc = ppc_cpu_class_by_name(alias->model); - if (oc == NULL) { - continue; - } - - info = g_malloc0(sizeof(*info)); - info->name = g_strdup(alias->alias); - info->q_typename = g_strdup(object_class_get_name(oc)); - - QAPI_LIST_PREPEND(cpu_list, info); - } - - return cpu_list; -} - static void ppc_cpu_set_pc(CPUState *cs, vaddr value) { PowerPCCPU *cpu = POWERPC_CPU(cs); diff --git a/target/ppc/monitor.c b/target/ppc/monitor.c index 8250b1304e..36e5b5eff8 100644 --- a/target/ppc/monitor.c +++ b/target/ppc/monitor.c @@ -1,5 +1,5 @@ /* - * QEMU monitor + * QEMU PPC (monitor definitions) * * Copyright (c) 2003-2004 Fabrice Bellard * @@ -28,6 +28,9 @@ #include "qemu/ctype.h" #include "monitor/hmp-target.h" #include "monitor/hmp.h" +#include "qapi/qapi-commands-machine-target.h" +#include "cpu-models.h" +#include "cpu-qom.h" static target_long monitor_get_ccr(Monitor *mon, const struct MonitorDef *md, int val) @@ -172,3 +175,48 @@ int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval) return -EINVAL; } + +static void ppc_cpu_defs_entry(gpointer data, gpointer user_data) +{ + ObjectClass *oc = data; + CpuDefinitionInfoList **first = user_data; + const char *typename; + CpuDefinitionInfo *info; + + typename = object_class_get_name(oc); + info = g_malloc0(sizeof(*info)); + info->name = g_strndup(typename, + strlen(typename) - strlen(POWERPC_CPU_TYPE_SUFFIX)); + + QAPI_LIST_PREPEND(*first, info); +} + +CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) +{ + CpuDefinitionInfoList *cpu_list = NULL; + GSList *list; + int i; + + list = object_class_get_list(TYPE_POWERPC_CPU, false); + g_slist_foreach(list, ppc_cpu_defs_entry, &cpu_list); + g_slist_free(list); + + for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) { + PowerPCCPUAlias *alias = &ppc_cpu_aliases[i]; + ObjectClass *oc; + CpuDefinitionInfo *info; + + oc = ppc_cpu_class_by_name(alias->model); + if (oc == NULL) { + continue; + } + + info = g_malloc0(sizeof(*info)); + info->name = g_strdup(alias->alias); + info->q_typename = g_strdup(object_class_get_name(oc)); + + QAPI_LIST_PREPEND(cpu_list, info); + } + + return cpu_list; +}