Skip to contentSkip to conversation

target-ppc: Tidy sPAPR device tree CPU nodes

PATCH Applied Andreas Färber 2 participants 4 messages Oct 15, 2013 – Oct 17, 2013

lore
Share & tools
lore
#0 lore raw

v3 cover target-ppc: Tidy sPAPR device tree CPU nodes

Hello Alexey and Alex,

This series cleans up the fdt CPU nodes for -M pseries as attempted by Prerna.

v3 uses DeviceClass::fw_name for name storage exclusively, with "PowerPC,UNKNOWN" as fallback.

Regards,
Andreas

v2 -> v3:
* Drop any type-based model name mangling and default to PowerPC,UNKNOWN (Alex).

preview -> v2:
* Set fw_name at family level rather than model level, saving macro extensions.
* Appended patch stripping underscores (Prerna).

v1 / Prerna's v3 -> preview:
* Instead of overwriting cpu_model with parent's type name for -cpu host, set fw_name for some models and read type / parent's types otherwise.
* Don't pass cpu_model to functions, determine name per CPU iterated.
* Avoid walking alias list by taking fw_name or model part of type name.

Cc Prerna Saxena <[email protected]>
Cc Alexander Graf <[email protected]>
Cc Alexey Kardashevskiy <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Thomas Huth <[email protected]>
Cc Anthony Liguori <[email protected]>

Andreas Färber (2):
target-ppc: Fill in OpenFirmware names for some PowerPCCPU families
spapr: Use DeviceClass::fw_name for device tree CPU node

 hw/ppc/spapr.c              | 26 ++++++--------------------
 include/hw/ppc/spapr.h      |  1 -
 target-ppc/translate_init.c |  5 +++++
 3 files changed, 11 insertions(+), 21 deletions(-)
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH v3 1/2 target-ppc: Fill in OpenFirmware names for some PowerPCCPU families

Set the expected values for POWER7, POWER7+, POWER8 and POWER5+. Note that POWER5+ and POWER7+ are intentionally lacking the '+', so the lack of a POWER7P family constitutes no problem.

---
 target-ppc/translate_init.c | 3 +++
 1 file changed, 3 insertions(+)
target-ppc/translate_init.c +3 -0
index 651da6b..5f6a836 100644
@@ -7103,6 +7103,7 @@ POWERPC_FAMILY(POWER5P)(ObjectClass *oc, void *data)
     DeviceClass *dc = DEVICE_CLASS(oc);
     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
 
+    dc->fw_name = "PowerPC,POWER5";
     dc->desc = "POWER5+";
     pcc->init_proc = init_proc_power5plus;
     pcc->check_pow = check_pow_970FX;
@@ -7213,6 +7214,7 @@ POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
     DeviceClass *dc = DEVICE_CLASS(oc);
     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
 
+    dc->fw_name = "PowerPC,POWER7";
     dc->desc = "POWER7";
     pcc->init_proc = init_proc_POWER7;
     pcc->check_pow = check_pow_nocheck;
@@ -7247,6 +7249,7 @@ POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data)
     DeviceClass *dc = DEVICE_CLASS(oc);
     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
 
+    dc->fw_name = "PowerPC,POWER8";
     dc->desc = "POWER8";
     pcc->init_proc = init_proc_POWER7;
     pcc->check_pow = check_pow_nocheck;
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH v3 2/2 spapr: Use DeviceClass::fw_name for device tree CPU node

In reply to Andreas Färber

Instead of relying on cpu_model, obtain the device tree node label per CPU. Use DeviceClass::fw_name as source.

Whenever DeviceClass::fw_name is unknown, default to "PowerPC,UNKNOWN".

As a consequence, spapr_fixup_cpu_dt() can operate on each CPU's fw_name, obsoleting sPAPREnvironment::cpu_model, and spapr_create_fdt_skel() can drop its cpu_model argument.

---
 hw/ppc/spapr.c              | 26 ++++++--------------------
 include/hw/ppc/spapr.h      |  1 -
 target-ppc/translate_init.c |  2 ++
 3 files changed, 8 insertions(+), 21 deletions(-)
hw/ppc/spapr.c +6 -20
index 004184d..6c00a8f 100644
@@ -185,9 +185,8 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
     int smt = kvmppc_smt_threads();
     uint32_t pft_size_prop[] = {0, cpu_to_be32(spapr->htab_shift)};
 
-    assert(spapr->cpu_model);
-
     CPU_FOREACH(cpu) {
+        DeviceClass *dc = DEVICE_GET_CLASS(cpu);
         uint32_t associativity[] = {cpu_to_be32(0x5),
                                     cpu_to_be32(0x0),
                                     cpu_to_be32(0x0),
@@ -199,7 +198,7 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
             continue;
         }
 
-        snprintf(cpu_model, 32, "/cpus/%s@%x", spapr->cpu_model,
+        snprintf(cpu_model, 32, "/cpus/%s@%x", dc->fw_name,
                  cpu->cpu_index);
 
         offset = fdt_path_offset(fdt, cpu_model);
@@ -269,8 +268,7 @@ static size_t create_page_sizes_prop(CPUPPCState *env, uint32_t *prop,
     } while (0)
 
 
-static void *spapr_create_fdt_skel(const char *cpu_model,
-                                   hwaddr initrd_base,
+static void *spapr_create_fdt_skel(hwaddr initrd_base,
                                    hwaddr initrd_size,
                                    hwaddr kernel_size,
                                    const char *boot_device,
@@ -286,7 +284,6 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
     char qemu_hypertas_prop[] = "hcall-memop1";
     uint32_t refpoints[] = {cpu_to_be32(0x4), cpu_to_be32(0x4)};
     uint32_t interrupt_server_ranges_prop[] = {0, cpu_to_be32(smp_cpus)};
-    char *modelname;
     int i, smt = kvmppc_smt_threads();
     unsigned char vec5[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x80};
 
@@ -342,18 +339,10 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
     _FDT((fdt_property_cell(fdt, "#address-cells", 0x1)));
     _FDT((fdt_property_cell(fdt, "#size-cells", 0x0)));
 
-    modelname = g_strdup(cpu_model);
-
-    for (i = 0; i < strlen(modelname); i++) {
-        modelname[i] = toupper(modelname[i]);
-    }
-
-    /* This is needed during FDT finalization */
-    spapr->cpu_model = g_strdup(modelname);
-
     CPU_FOREACH(cs) {
         PowerPCCPU *cpu = POWERPC_CPU(cs);
         CPUPPCState *env = &cpu->env;
+        DeviceClass *dc = DEVICE_GET_CLASS(cs);
         PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cs);
         int index = cs->cpu_index;
         uint32_t servers_prop[smp_threads];
@@ -370,7 +359,7 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
             continue;
         }
 
-        nodename = g_strdup_printf("%s@%x", modelname, index);
+        nodename = g_strdup_printf("%s@%x", dc->fw_name, index);
 
         _FDT((fdt_begin_node(fdt, nodename)));
 
@@ -450,8 +439,6 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
         _FDT((fdt_end_node(fdt)));
     }
 
-    g_free(modelname);
-
     _FDT((fdt_end_node(fdt)));
 
     /* RTAS */
@@ -1329,8 +1316,7 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
                          &savevm_htab_handlers, spapr);
 
     /* Prepare the device tree */
-    spapr->fdt_skel = spapr_create_fdt_skel(cpu_model,
-                                            initrd_base, initrd_size,
+    spapr->fdt_skel = spapr_create_fdt_skel(initrd_base, initrd_size,
                                             kernel_size,
                                             boot_device, kernel_cmdline,
                                             spapr->epow_irq);
include/hw/ppc/spapr.h +0 -1
index e37b419..74361f3 100644
@@ -29,7 +29,6 @@ typedef struct sPAPREnvironment {
     target_ulong entry_point;
     uint32_t next_irq;
     uint64_t rtc_offset;
-    char *cpu_model;
     bool has_graphics;
 
     uint32_t epow_irq;
target-ppc/translate_init.c +2 -0
index 5f6a836..32f6cdd 100644
@@ -8578,6 +8578,8 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)
 #else
     cc->gdb_core_xml_file = "power-core.xml";
 #endif
+
+    dc->fw_name = "PowerPC,UNKNOWN";
 }
 
 static const TypeInfo ppc_cpu_type_info = {
Signature · 1 line
1.8.1.4
#3 lore raw
In reply to Andreas Färber
Quoted 6 lines · Andreas Färber

Hello Alexey and Alex,

This series cleans up the fdt CPU nodes for -M pseries as attempted by Prerna.

v3 uses DeviceClass::fw_name for name storage exclusively, with "PowerPC,UNKNOWN" as fallback.

Thanks, applied all to ppc-next.

Alex