diff mbox

[2/5] target-arm: Add feature parsing to virt

Message ID 1421706621-23731-3-git-send-email-greg.bellows@linaro.org
State New
Headers show

Commit Message

Greg Bellows Jan. 19, 2015, 10:30 p.m. UTC
Added machvirt parsing of feature keywords added to the -cpu command line
option.  Parsing occurs during machine initialization.

Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
 hw/arm/virt.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

Comments

Alex Bennée Jan. 20, 2015, 4:58 p.m. UTC | #1
Greg Bellows <greg.bellows@linaro.org> writes:

> Added machvirt parsing of feature keywords added to the -cpu command line
> option.  Parsing occurs during machine initialization.
>
> Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
> ---
>  hw/arm/virt.c | 21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 2353440..cd192ae 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -573,12 +573,19 @@ static void machvirt_init(MachineState *machine)
>      MemoryRegion *ram = g_new(MemoryRegion, 1);
>      const char *cpu_model = machine->cpu_model;
>      VirtBoardInfo *vbi;
> +    char *cpuname, *features;
>  
>      if (!cpu_model) {
>          cpu_model = "cortex-a15";
>      }
>  
> -    vbi = find_machine_info(cpu_model);
> +    /* Separate the actual CPU model name from any appended features */
> +    cpuname = g_strdup(cpu_model);
> +    cpuname = strtok(cpuname, ",");
> +    /* Keep track of the features for later parsing */
> +    features = strtok(NULL, ",");
<snip>

OK having read the strtok man page a bit more closely the second time
I'm happy this doesn't leak. My more-gliby request is a matter of
personal taste.
diff mbox

Patch

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 2353440..cd192ae 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -573,12 +573,19 @@  static void machvirt_init(MachineState *machine)
     MemoryRegion *ram = g_new(MemoryRegion, 1);
     const char *cpu_model = machine->cpu_model;
     VirtBoardInfo *vbi;
+    char *cpuname, *features;
 
     if (!cpu_model) {
         cpu_model = "cortex-a15";
     }
 
-    vbi = find_machine_info(cpu_model);
+    /* Separate the actual CPU model name from any appended features */
+    cpuname = g_strdup(cpu_model);
+    cpuname = strtok(cpuname, ",");
+    /* Keep track of the features for later parsing */
+    features = strtok(NULL, ",");
+
+    vbi = find_machine_info(cpuname);
 
     if (!vbi) {
         error_report("mach-virt: CPU %s not supported", cpu_model);
@@ -595,8 +602,10 @@  static void machvirt_init(MachineState *machine)
     create_fdt(vbi);
 
     for (n = 0; n < smp_cpus; n++) {
-        ObjectClass *oc = cpu_class_by_name(TYPE_ARM_CPU, cpu_model);
+        ObjectClass *oc = cpu_class_by_name(TYPE_ARM_CPU, cpuname);
+        CPUClass *cc = CPU_CLASS(oc);
         Object *cpuobj;
+        Error *err = NULL;
 
         if (!oc) {
             fprintf(stderr, "Unable to find CPU definition\n");
@@ -604,6 +613,13 @@  static void machvirt_init(MachineState *machine)
         }
         cpuobj = object_new(object_class_get_name(oc));
 
+        /* Handle any CPU options specfied by the user */
+        cc->parse_features(CPU(cpuobj), features, &err);
+        if (err) {
+            error_report("%s", error_get_pretty(err));
+            exit(1);
+        }
+
         if (!vms->secure) {
             object_property_set_bool(cpuobj, false, "has_el3", NULL);
         }
@@ -623,6 +639,7 @@  static void machvirt_init(MachineState *machine)
 
         object_property_set_bool(cpuobj, true, "realized", NULL);
     }
+    g_free(cpuname);
     fdt_add_timer_nodes(vbi);
     fdt_add_cpu_nodes(vbi);
     fdt_add_psci_node(vbi);