Skip to contentSkip to conversation

target-arm: Implement qmp query-cpu-definitions

PATCH Applied Cole Robinson 3 participants 3 messages Sep 4, 2013 – Sep 5, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-arm: Implement qmp query-cpu-definitions

Libvirt uses this to introspect available CPU models.

---
Maybe this will be centrally handled after the QOM CPU work is done?

 target-arm/helper.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
target-arm/helper.c +32 -0
index e51ef20..1874377 100644
@@ -2,6 +2,7 @@
 #include "exec/gdbstub.h"
 #include "helper.h"
 #include "qemu/host-utils.h"
+#include "sysemu/arch_init.h"
 #include "sysemu/sysemu.h"
 #include "qemu/bitops.h"
 
@@ -1829,6 +1830,37 @@ void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf)
     g_slist_free(list);
 }
 
+static void arm_cpu_add_definition(gpointer data, gpointer user_data)
+{
+    ObjectClass *oc = data;
+    CpuDefinitionInfoList **cpu_list = user_data;
+    CpuDefinitionInfoList *entry;
+    CpuDefinitionInfo *info;
+    const char *typename;
+
+    typename = object_class_get_name(oc);
+    info = g_malloc0(sizeof(*info));
+    info->name = g_strndup(typename,
+                           strlen(typename) - strlen("-" TYPE_ARM_CPU));
+
+    entry = g_malloc0(sizeof(*entry));
+    entry->value = info;
+    entry->next = *cpu_list;
+    *cpu_list = entry;
+}
+
+CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
+{
+    CpuDefinitionInfoList *cpu_list = NULL;
+    GSList *list;
+
+    list = object_class_get_list(TYPE_ARM_CPU, false);
+    g_slist_foreach(list, arm_cpu_add_definition, &cpu_list);
+    g_slist_free(list);
+
+    return cpu_list;
+}
+
 void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,
                                        const ARMCPRegInfo *r, void *opaque)
 {
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Am 04.09.2013 17:23, schrieb Cole Robinson:

Quoted 5 lines

Libvirt uses this to introspect available CPU models.

---
Maybe this will be centrally handled after the QOM CPU work is done?

No, this API is about a pre-QOM command line switch, whose implementation is target-specific. What got standardized for multiple targets was the CPUClass::class_by_name() hook for the opposite direction of -cpu to ObjectClass lookup (with the goal of obsoleting cpu_init()). It is not wrong to implement query-cpus for arm, but -cpu is considered deprecated.

And personally especially for arm I would rather welcome someone contributing a proper, e.g., Raspberry Pi board (with clean separation of what is on the SoC and what on the board to avoid duplication among boards) than tweaking some other unrelated board with -cpu and then complaining that it doesn't work as expected. ;) For machines that use soft-core CPUs (FPGAs) or for mach-virt as non-physical machine it does make sense, but query-cpus gives us a list irrespective of whether they are compatible with the board. Same for ppc btw - plugging, e.g., a 440 CPU into pseries or mac99 won't work.
Short-term my view is to use fixed CPU types, ignoring -cpu, where the CPU cannot be exchanged (e.g., DIGIC patch series) and a suitable link<> type otherwise.

The long-term goal is to have machines be config files (thereby user-creatable) assembling QOM objects by specifying memory mapping and IRQ routing. The latter two parts don't work with the old qdev and SysBusDevice APIs.

That said, patch itself looks correct,

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg