Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/pseries: Fix drc-info mappings of logical cpus to drc-index

There are a couple subtle errors in the mapping between cpu-ids and a
cpus associated drc-index when using the new ibm,drc-info property.

The first is that while drc-info may have been a supported firmware
feature at boot it is possible we have migrated to a CEC with older
firmware that doesn't support the ibm,drc-info property. In that case
the device tree would have been updated after migration to remove the
ibm,drc-info property and replace it with the older style ibm,drc-*
properties for types, indexes, names, and power-domains. PAPR even
goes as far as dictating that if we advertise support for drc-info
that we are capable of supporting either property type at runtime.

The second is that the first value of the ibm,drc-info property is
the int encoded count of drc-info entries. As such "value" returned
by of_prop_next_u32() is pointing at that count, and not the first
element of the first drc-info entry as is expected by the
of_read_drc_info_cell() helper.

Fix the first by ignoring DRC-INFO firmware feature and instead
testing directly for ibm,drc-info, and then falling back to the
old style ibm,drc-indexes in the case it doesn't exit.

Fix the second by incrementing value to the next element prior to
parsing drc-info entries.

Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/1573449697-5448-3-git-send-email-tyreld@linux.ibm.com

authored by

Tyrel Datwyler and committed by
Michael Ellerman
775fa495 57409d4f

+10 -13
+10 -13
arch/powerpc/platforms/pseries/pseries_energy.c
··· 36 36 static u32 cpu_to_drc_index(int cpu) 37 37 { 38 38 struct device_node *dn = NULL; 39 + struct property *info; 39 40 int thread_index; 40 41 int rc = 1; 41 42 u32 ret = 0; ··· 48 47 /* Convert logical cpu number to core number */ 49 48 thread_index = cpu_core_index_of_thread(cpu); 50 49 51 - if (firmware_has_feature(FW_FEATURE_DRC_INFO)) { 52 - struct property *info = NULL; 50 + info = of_find_property(dn, "ibm,drc-info", NULL); 51 + if (info) { 53 52 struct of_drc_info drc; 54 53 int j; 55 54 u32 num_set_entries; 56 55 const __be32 *value; 57 56 58 - info = of_find_property(dn, "ibm,drc-info", NULL); 59 - if (info == NULL) 60 - goto err_of_node_put; 61 - 62 57 value = of_prop_next_u32(info, NULL, &num_set_entries); 63 58 if (!value) 64 59 goto err_of_node_put; 60 + else 61 + value++; 65 62 66 63 for (j = 0; j < num_set_entries; j++) { 67 64 ··· 109 110 static int drc_index_to_cpu(u32 drc_index) 110 111 { 111 112 struct device_node *dn = NULL; 113 + struct property *info; 112 114 const int *indexes; 113 115 int thread_index = 0, cpu = 0; 114 116 int rc = 1; ··· 117 117 dn = of_find_node_by_path("/cpus"); 118 118 if (dn == NULL) 119 119 goto err; 120 - 121 - if (firmware_has_feature(FW_FEATURE_DRC_INFO)) { 122 - struct property *info = NULL; 120 + info = of_find_property(dn, "ibm,drc-info", NULL); 121 + if (info) { 123 122 struct of_drc_info drc; 124 123 int j; 125 124 u32 num_set_entries; 126 125 const __be32 *value; 127 126 128 - info = of_find_property(dn, "ibm,drc-info", NULL); 129 - if (info == NULL) 130 - goto err_of_node_put; 131 - 132 127 value = of_prop_next_u32(info, NULL, &num_set_entries); 133 128 if (!value) 134 129 goto err_of_node_put; 130 + else 131 + value++; 135 132 136 133 for (j = 0; j < num_set_entries; j++) { 137 134