Skip to content

Commit

Permalink
sensor: add a family field in the handler
Browse files Browse the repository at this point in the history
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@kaod.org>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
legoater authored and stewartsmith committed Dec 8, 2016
1 parent aed1fbe commit 33fada1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
4 changes: 3 additions & 1 deletion core/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions doc/device-tree/ibm,opal/sensors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ Each node has a minimum set of properties describing the sensor :
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
Expand Down
6 changes: 3 additions & 3 deletions hw/dts.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ int64_t dts_sensor_read(uint32_t sensor_hndl, uint32_t *sensor_data)

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;
Expand Down Expand Up @@ -326,11 +326,11 @@ int64_t dts_sensor_read(uint32_t sensor_hndl, uint32_t *sensor_data)
(((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)
Expand Down
2 changes: 1 addition & 1 deletion hw/fsp/fsp-sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ static struct dt_node *sensor_get_node(struct dt_node *sensors,
}

#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)
{
Expand Down
34 changes: 21 additions & 13 deletions include/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,39 @@
* 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)

/*
* 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
Expand Down

0 comments on commit 33fada1

Please sign in to comment.