[Skiboot] [PATCH] sensor: add a family field in the handler
Cédric Le Goater
clg at kaod.org
Wed Sep 14 03:39:22 AEST 2016
Currently, we are hijacking the last bit of the resource field of the
sensor handler to differentiate the sensor families and route the
opal_sensor_read() call to the appropriate component.
Let's reserve the last 3bits and provide an API to set the sensor
family for current use and future use. This gives us a maximum of 8
families and 32 resource classes. The FSP uses 15, so we should be
fine for a while.
Signed-off-by: Cédric Le Goater <clg at kaod.org>
---
core/sensor.c | 4 +++-
doc/device-tree/ibm,opal/sensors.rst | 9 ++++++---
hw/dts.c | 6 +++---
hw/fsp/fsp-sensor.c | 2 +-
include/sensor.h | 34 +++++++++++++++++++++-------------
5 files changed, 34 insertions(+), 21 deletions(-)
Index: skiboot.git/include/sensor.h
===================================================================
--- skiboot.git.orig/include/sensor.h
+++ skiboot.git/include/sensor.h
@@ -22,18 +22,24 @@
* its resource class (temperature, fans ...), a resource identifier
* and an attribute number (data, status, ...) :
*
- * Res.
- * | Attr. | Class | Resource Id |
- * |--------|--------|----------------|
- *
+ * Res.
+ * | Attr. |Fam Class| Resource Id |
+ * |--------|---|-----|----------------|
*
+ * The last 3bits of the resource class are used to hold the family
+ * number. That leaves 32 differents resource classes. This is enough
+ * for the FSP as it uses 15.
+ */
+
+/*
* Helper routines to build or use the sensor handler.
*/
-#define sensor_make_handler(sensor_class, sensor_rid, sensor_attr) \
- (((sensor_attr) << 24) | ((sensor_class) & 0xff) << 16 | \
- ((sensor_rid) & 0xffff))
+#define sensor_make_handler(family, class, rid, attr) \
+ (((attr) << 24) | ((family) & 0x7) << 21 | ((class) & 0x1f) << 16 | \
+ ((rid) & 0xffff))
-#define sensor_get_frc(handler) (((handler) >> 16) & 0xff)
+#define sensor_get_family(handler) (((handler) >> 21) & 0x7)
+#define sensor_get_frc(handler) (((handler) >> 16) & 0x1f)
#define sensor_get_rid(handler) ((handler) & 0xffff)
#define sensor_get_attr(handler) ((handler) >> 24)
@@ -41,12 +47,14 @@
* Sensor families
*
* This identifier is used to dispatch calls to OPAL_SENSOR_READ to
- * the appropriate component. FSP is the initial family.
+ * the appropriate component. FSP is the initial family and you can
+ * have up to eight, as we are hijacking the last 3bits of the
+ * resource class.
*/
-#define SENSOR_FSP 0x0
-#define SENSOR_DTS 0x80
-
-#define sensor_is_dts(handler) (sensor_get_frc(handler) & SENSOR_DTS)
+enum {
+ SENSOR_FSP = 0,
+ SENSOR_DTS = 7,
+};
/*
* root node of all sensors : /ibm,opal/sensors
Index: skiboot.git/core/sensor.c
===================================================================
--- skiboot.git.orig/core/sensor.c
+++ skiboot.git/core/sensor.c
@@ -26,8 +26,10 @@ struct dt_node *sensor_node;
static int64_t opal_sensor_read(uint32_t sensor_hndl, int token,
uint32_t *sensor_data)
{
- if (sensor_is_dts(sensor_hndl))
+ switch (sensor_get_family(sensor_hndl)) {
+ case SENSOR_DTS:
return dts_sensor_read(sensor_hndl, sensor_data);
+ }
if (platform.sensor_read)
return platform.sensor_read(sensor_hndl, token, sensor_data);
Index: skiboot.git/hw/dts.c
===================================================================
--- skiboot.git.orig/hw/dts.c
+++ skiboot.git/hw/dts.c
@@ -290,7 +290,7 @@ int64_t dts_sensor_read(uint32_t sensor_
memset(&dts, 0, sizeof(struct dts));
- switch (sensor_get_frc(sensor_hndl) & ~SENSOR_DTS) {
+ switch (sensor_get_frc(sensor_hndl)) {
case SENSOR_DTS_CORE_TEMP:
rc = dts_read_core_temp(rid, &dts);
break;
@@ -326,11 +326,11 @@ int64_t dts_sensor_read(uint32_t sensor_
(((chip_id) & 0x3ff) | ((dimm_id) << 10))
#define core_handler(core_id, attr_id) \
- sensor_make_handler(SENSOR_DTS_CORE_TEMP | SENSOR_DTS, \
+ sensor_make_handler(SENSOR_DTS, SENSOR_DTS_CORE_TEMP, \
core_id, attr_id)
#define cen_handler(cen_id, attr_id) \
- sensor_make_handler(SENSOR_DTS_MEM_TEMP|SENSOR_DTS, \
+ sensor_make_handler(SENSOR_DTS, SENSOR_DTS_MEM_TEMP, \
centaur_make_id(chip_id, 0), attr_id)
bool dts_sensor_create_nodes(struct dt_node *sensors)
Index: skiboot.git/hw/fsp/fsp-sensor.c
===================================================================
--- skiboot.git.orig/hw/fsp/fsp-sensor.c
+++ skiboot.git/hw/fsp/fsp-sensor.c
@@ -617,7 +617,7 @@ static struct dt_node *sensor_get_node(s
}
#define sensor_handler(header, attr_num) \
- sensor_make_handler((header).frc, (header).rid, attr_num)
+ sensor_make_handler(SENSOR_FSP, (header).frc, (header).rid, attr_num)
static int add_sensor_prs(struct dt_node *sensors, struct sensor_prs *prs)
{
Index: skiboot.git/doc/device-tree/ibm,opal/sensors.rst
===================================================================
--- skiboot.git.orig/doc/device-tree/ibm,opal/sensors.rst
+++ skiboot.git/doc/device-tree/ibm,opal/sensors.rst
@@ -24,9 +24,12 @@ Each node has a minimum set of propertie
OPAL_SENSOR_READ call to be used by Linux to get the value of
a sensor attribute. A sensor handler has the following encoding : ::
- | Attr. | Res. | Resource |
- | Number | Class | Id |
- |--------|--------|----------------|
+ | Attr. |Fam|Res. | Resource |
+ | Number |ily|Class| Id |
+ |--------|---|-----|----------------|
+
+ The sensor family (FSP, DTS, etc) is used to dispatch the call to
+ the appriopriate skiboot component.
- a "sensor-status" property giving the state of the sensor. The
status bits have the slightly meanings depending on the resource
More information about the Skiboot
mailing list