diff mbox

[03/11] dts: add device tree nodes for the core temperatures

Message ID 1423117857-32759-4-git-send-email-clg@fr.ibm.com
State Changes Requested
Headers show

Commit Message

Cédric Le Goater Feb. 5, 2015, 6:30 a.m. UTC
This patch simply adds sensors nodes for the core temperatures. It
uses the core PIR as a resource identifier to fit in the sensor model.

The device tree nodes use the new layout.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---

Changes since RFC:

 - "/ibm,opal/sensors" needs to be created on open power platform

 core/sensor.c |    3 +++
 hw/dts.c      |   42 ++++++++++++++++++++++++++++++++++++++++++
 include/dts.h |    1 +
 3 files changed, 46 insertions(+)

Comments

Stewart Smith Feb. 13, 2015, 4:28 a.m. UTC | #1
Cédric Le Goater <clg@fr.ibm.com> writes:

> This patch simply adds sensors nodes for the core temperatures. It
> uses the core PIR as a resource identifier to fit in the sensor model.
>
> The device tree nodes use the new layout.
>
> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
> ---
>
> Changes since RFC:
>
>  - "/ibm,opal/sensors" needs to be created on open power platform
>
>  core/sensor.c |    3 +++
>  hw/dts.c      |   42 ++++++++++++++++++++++++++++++++++++++++++
>  include/dts.h |    1 +
>  3 files changed, 46 insertions(+)
>
> diff --git a/core/sensor.c b/core/sensor.c
> index 5db072e0e501..83ef2d98cd94 100644
> --- a/core/sensor.c
> +++ b/core/sensor.c
> @@ -18,6 +18,7 @@
>  #include <sensor.h>
>  #include <skiboot.h>
>  #include <opal.h>
> +#include <dts.h>
>
>  static int64_t opal_sensor_read(uint32_t sensor_hndl, int token,
>  		uint32_t *sensor_data)
> @@ -32,4 +33,6 @@ void sensor_init(void)
>  {
>  	/* Register OPAL interface */
>  	opal_register(OPAL_SENSOR_READ, opal_sensor_read, 3);
> +
> +	dts_sensor_create_nodes();
>  }
> diff --git a/hw/dts.c b/hw/dts.c
> index 288793a1c68d..356080e9e756 100644
> --- a/hw/dts.c
> +++ b/hw/dts.c
> @@ -162,3 +162,45 @@ int64_t dts_sensor_read(uint32_t sensor_hndl, uint32_t *sensor_data)
>
>  	return 0;
>  }
> +
> +bool dts_sensor_create_nodes(void)
> +{
> +	uint8_t sensor_class = SENSOR_DTS_CORE_TEMP|SENSOR_DTS;
> +
> +	struct proc_chip *chip;
> +	struct dt_node *sensors;
> +	char name[64];
> +
> +	sensors = dt_find_by_path(dt_root, "/ibm,opal/sensors");
> +	if (!sensors) {
> +		prlog(PR_WARNING, "DTS: creating node /ibm,opal/sensors\n");
> +		sensors = dt_new(opal_node, "sensors");
> +	}

We're expected to get these from HB? Is it really a warning that it
doesn't exist? Would we get anything on an openpower system?
Cédric Le Goater Feb. 16, 2015, 6:13 p.m. UTC | #2
On 02/13/2015 05:28 AM, Stewart Smith wrote:
> Cédric Le Goater <clg@fr.ibm.com> writes:
> 
>> This patch simply adds sensors nodes for the core temperatures. It
>> uses the core PIR as a resource identifier to fit in the sensor model.
>>
>> The device tree nodes use the new layout.
>>
>> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
>> ---
>>
>> Changes since RFC:
>>
>>  - "/ibm,opal/sensors" needs to be created on open power platform
>>
>>  core/sensor.c |    3 +++
>>  hw/dts.c      |   42 ++++++++++++++++++++++++++++++++++++++++++
>>  include/dts.h |    1 +
>>  3 files changed, 46 insertions(+)
>>
>> diff --git a/core/sensor.c b/core/sensor.c
>> index 5db072e0e501..83ef2d98cd94 100644
>> --- a/core/sensor.c
>> +++ b/core/sensor.c
>> @@ -18,6 +18,7 @@
>>  #include <sensor.h>
>>  #include <skiboot.h>
>>  #include <opal.h>
>> +#include <dts.h>
>>
>>  static int64_t opal_sensor_read(uint32_t sensor_hndl, int token,
>>  		uint32_t *sensor_data)
>> @@ -32,4 +33,6 @@ void sensor_init(void)
>>  {
>>  	/* Register OPAL interface */
>>  	opal_register(OPAL_SENSOR_READ, opal_sensor_read, 3);
>> +
>> +	dts_sensor_create_nodes();
>>  }
>> diff --git a/hw/dts.c b/hw/dts.c
>> index 288793a1c68d..356080e9e756 100644
>> --- a/hw/dts.c
>> +++ b/hw/dts.c
>> @@ -162,3 +162,45 @@ int64_t dts_sensor_read(uint32_t sensor_hndl, uint32_t *sensor_data)
>>
>>  	return 0;
>>  }
>> +
>> +bool dts_sensor_create_nodes(void)
>> +{
>> +	uint8_t sensor_class = SENSOR_DTS_CORE_TEMP|SENSOR_DTS;
>> +
>> +	struct proc_chip *chip;
>> +	struct dt_node *sensors;
>> +	char name[64];
>> +
>> +	sensors = dt_find_by_path(dt_root, "/ibm,opal/sensors");
>> +	if (!sensors) {
>> +		prlog(PR_WARNING, "DTS: creating node /ibm,opal/sensors\n");
>> +		sensors = dt_new(opal_node, "sensors");
>> +	}
> 
> We're expected to get these from HB? Is it really a warning that it
> doesn't exist? Would we get anything on an openpower system?

The warning is not appropriate, I will remove it. 

On an IBM power system, the root node for sensors is created with the 
FSP sensors. On an open power system, we need to create it as no one 
is doing it first. 

C.
Stewart Smith Feb. 16, 2015, 10:17 p.m. UTC | #3
Cedric Le Goater <clg@fr.ibm.com> writes:
> On 02/13/2015 05:28 AM, Stewart Smith wrote:
>> Cédric Le Goater <clg@fr.ibm.com> writes:
>> 
>>> This patch simply adds sensors nodes for the core temperatures. It
>>> uses the core PIR as a resource identifier to fit in the sensor model.
>>>
>>> The device tree nodes use the new layout.
>>>
>>> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
>>> ---
>>>
>>> Changes since RFC:
>>>
>>>  - "/ibm,opal/sensors" needs to be created on open power platform
>>>
>>>  core/sensor.c |    3 +++
>>>  hw/dts.c      |   42 ++++++++++++++++++++++++++++++++++++++++++
>>>  include/dts.h |    1 +
>>>  3 files changed, 46 insertions(+)
>>>
>>> diff --git a/core/sensor.c b/core/sensor.c
>>> index 5db072e0e501..83ef2d98cd94 100644
>>> --- a/core/sensor.c
>>> +++ b/core/sensor.c
>>> @@ -18,6 +18,7 @@
>>>  #include <sensor.h>
>>>  #include <skiboot.h>
>>>  #include <opal.h>
>>> +#include <dts.h>
>>>
>>>  static int64_t opal_sensor_read(uint32_t sensor_hndl, int token,
>>>  		uint32_t *sensor_data)
>>> @@ -32,4 +33,6 @@ void sensor_init(void)
>>>  {
>>>  	/* Register OPAL interface */
>>>  	opal_register(OPAL_SENSOR_READ, opal_sensor_read, 3);
>>> +
>>> +	dts_sensor_create_nodes();
>>>  }
>>> diff --git a/hw/dts.c b/hw/dts.c
>>> index 288793a1c68d..356080e9e756 100644
>>> --- a/hw/dts.c
>>> +++ b/hw/dts.c
>>> @@ -162,3 +162,45 @@ int64_t dts_sensor_read(uint32_t sensor_hndl, uint32_t *sensor_data)
>>>
>>>  	return 0;
>>>  }
>>> +
>>> +bool dts_sensor_create_nodes(void)
>>> +{
>>> +	uint8_t sensor_class = SENSOR_DTS_CORE_TEMP|SENSOR_DTS;
>>> +
>>> +	struct proc_chip *chip;
>>> +	struct dt_node *sensors;
>>> +	char name[64];
>>> +
>>> +	sensors = dt_find_by_path(dt_root, "/ibm,opal/sensors");
>>> +	if (!sensors) {
>>> +		prlog(PR_WARNING, "DTS: creating node /ibm,opal/sensors\n");
>>> +		sensors = dt_new(opal_node, "sensors");
>>> +	}
>> 
>> We're expected to get these from HB? Is it really a warning that it
>> doesn't exist? Would we get anything on an openpower system?
>
> The warning is not appropriate, I will remove it. 
>
> On an IBM power system, the root node for sensors is created with the 
> FSP sensors. On an open power system, we need to create it as no one 
> is doing it first. 

(without looking to check if this is a sensible suggestion) but feel
free to move creating the root node into common code if that makes sense.
diff mbox

Patch

diff --git a/core/sensor.c b/core/sensor.c
index 5db072e0e501..83ef2d98cd94 100644
--- a/core/sensor.c
+++ b/core/sensor.c
@@ -18,6 +18,7 @@ 
 #include <sensor.h>
 #include <skiboot.h>
 #include <opal.h>
+#include <dts.h>
 
 static int64_t opal_sensor_read(uint32_t sensor_hndl, int token,
 		uint32_t *sensor_data)
@@ -32,4 +33,6 @@  void sensor_init(void)
 {
 	/* Register OPAL interface */
 	opal_register(OPAL_SENSOR_READ, opal_sensor_read, 3);
+
+	dts_sensor_create_nodes();
 }
diff --git a/hw/dts.c b/hw/dts.c
index 288793a1c68d..356080e9e756 100644
--- a/hw/dts.c
+++ b/hw/dts.c
@@ -162,3 +162,45 @@  int64_t dts_sensor_read(uint32_t sensor_hndl, uint32_t *sensor_data)
 
 	return 0;
 }
+
+bool dts_sensor_create_nodes(void)
+{
+	uint8_t sensor_class = SENSOR_DTS_CORE_TEMP|SENSOR_DTS;
+
+	struct proc_chip *chip;
+	struct dt_node *sensors;
+	char name[64];
+
+	sensors = dt_find_by_path(dt_root, "/ibm,opal/sensors");
+	if (!sensors) {
+		prlog(PR_WARNING, "DTS: creating node /ibm,opal/sensors\n");
+		sensors = dt_new(opal_node, "sensors");
+	}
+
+	/* build the device tree nodes :
+	 *
+	 *     sensors/core-temp@pir
+	 *
+	 * The core is identified by its PIR, is stored in the resource
+	 * number of the sensor handler.
+	 */
+	for_each_chip(chip) {
+		struct cpu_thread *c;
+
+		for_each_available_core_in_chip(c, chip->id) {
+			struct dt_node *node;
+			uint32_t handler;
+
+			snprintf(name, sizeof(name), "core-temp@%x", c->pir);
+
+			handler = sensor_make_handler(sensor_class,
+					c->pir, SENSOR_DTS_ATTR_TEMP_MAX);
+			node = dt_new(sensors, name);
+			dt_add_property_string(node, "compatible",
+					       "ibm,opal-sensor");
+			dt_add_property_cells(node, "sensor-data", handler);
+		}
+	}
+
+	return true;
+}
diff --git a/include/dts.h b/include/dts.h
index 18933909ee08..f506c58efb6f 100644
--- a/include/dts.h
+++ b/include/dts.h
@@ -20,5 +20,6 @@ 
 #include <stdint.h>
 
 extern int64_t dts_sensor_read(uint32_t sensor_hndl, uint32_t *sensor_data);
+extern bool dts_sensor_create_nodes(void);
 
 #endif /* __DTS_H */