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

hwmon: (ibmpowernv) pretty print labels

The new OPAL device tree adds a few properties which can be used to add
extra information on the sensor label.

In the case of a cpu core sensor, the firmware exposes the physical
identifier of the core in the "ibm,pir" property. The driver
translates this identifier in a linux cpu number and prints out a
range corresponding to the hardware threads of the core (as they
share the same sensor).

The numbering gives a hint on the localization of the core in the
system (which socket, which chip).

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Cédric Le Goater and committed by
Guenter Roeck
3df2f59f 2bcd3787

+41
+41
drivers/hwmon/ibmpowernv.c
··· 30 30 #include <linux/platform_device.h> 31 31 #include <asm/opal.h> 32 32 #include <linux/err.h> 33 + #include <asm/cputhreads.h> 33 34 34 35 #define MAX_ATTR_LEN 32 35 36 #define MAX_LABEL_LEN 64 ··· 113 112 return sprintf(buf, "%s\n", sdata->label); 114 113 } 115 114 115 + static int __init get_logical_cpu(int hwcpu) 116 + { 117 + int cpu; 118 + 119 + for_each_possible_cpu(cpu) 120 + if (get_hard_smp_processor_id(cpu) == hwcpu) 121 + return cpu; 122 + 123 + return -ENOENT; 124 + } 125 + 116 126 static void __init make_sensor_label(struct device_node *np, 117 127 struct sensor_data *sdata, 118 128 const char *label) 119 129 { 130 + u32 id; 120 131 size_t n; 121 132 122 133 n = snprintf(sdata->label, sizeof(sdata->label), "%s", label); 134 + 135 + /* 136 + * Core temp pretty print 137 + */ 138 + if (!of_property_read_u32(np, "ibm,pir", &id)) { 139 + int cpuid = get_logical_cpu(id); 140 + 141 + if (cpuid >= 0) 142 + /* 143 + * The digital thermal sensors are associated 144 + * with a core. Let's print out the range of 145 + * cpu ids corresponding to the hardware 146 + * threads of the core. 147 + */ 148 + n += snprintf(sdata->label + n, 149 + sizeof(sdata->label) - n, " %d-%d", 150 + cpuid, cpuid + threads_per_core - 1); 151 + else 152 + n += snprintf(sdata->label + n, 153 + sizeof(sdata->label) - n, " phy%d", id); 154 + } 155 + 156 + /* 157 + * Membuffer pretty print 158 + */ 159 + if (!of_property_read_u32(np, "ibm,chip-id", &id)) 160 + n += snprintf(sdata->label + n, sizeof(sdata->label) - n, 161 + " %d", id & 0xffff); 123 162 } 124 163 125 164 static int get_sensor_index_attr(const char *name, u32 *index, char *attr)