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 <c...@fr.ibm.com>
---

 Changes since v1:

 - check cpu validity before printing out the attribute label. 
   if invalid, use a "phy" prefix to distinguish a linux cpu 
   number from a physical cpu number. 

 drivers/hwmon/ibmpowernv.c |   34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

Index: linux.git/drivers/hwmon/ibmpowernv.c
===================================================================
--- linux.git.orig/drivers/hwmon/ibmpowernv.c
+++ linux.git/drivers/hwmon/ibmpowernv.c
@@ -113,9 +113,43 @@ static ssize_t show_label(struct device
 static void __init make_sensor_label(struct device_node *np,
                    struct sensor_data *sdata, const char *label)
 {
+       u32 id;
        size_t n;
 
        n = snprintf(sdata->label, sizeof(sdata->label), "%s", label);
+
+       /*
+        * Core temp pretty print
+        */
+       if (!of_property_read_u32(np, "ibm,pir", &id)) {
+               int i = -1;
+
+               for_each_possible_cpu(i)
+                       if (paca[i].hw_cpu_id == id)
+                               break;
+
+               if (i != -1)
+                       /*
+                        * The digital thermal sensors are associated
+                        * with a core. Let's print out the range of
+                        * cpu ids corresponding to the hardware
+                        * threads of the core.
+                        */
+                       n += snprintf(sdata->label + n,
+                                     sizeof(sdata->label) - n,
+                                     " %d-%d", i, i+7);
+               else
+                       n += snprintf(sdata->label + n,
+                                     sizeof(sdata->label) - n,
+                                     " phy%d", id);
+       }
+
+       /*
+        * Membuffer pretty print
+        */
+       if (!of_property_read_u32(np, "ibm,chip-id", &id))
+               n += snprintf(sdata->label + n, sizeof(sdata->label) - n,
+                             " %d", id & 0xffff);
 }
 
 static int get_sensor_index_attr(const char *name, u32 *index,

_______________________________________________
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Reply via email to