[Skiboot] [PATCH V7 8/8] sensor: occ: Add support to clear sensor groups
Shilpasri G Bhat
shilpa.bhat at linux.vnet.ibm.com
Thu Jul 20 04:22:41 AEST 2017
Adds a generic API to clear sensor groups. OCC inband sensor groups
such as CSM, Profiler and Job Scheduler can be cleared using this API.
It will clear the min/max of all sensors belonging to OCC sensor
groups.
Signed-off-by: Shilpasri G Bhat <shilpa.bhat at linux.vnet.ibm.com>
---
core/sensor.c | 13 +++++++++
hw/occ-sensor.c | 1 +
hw/occ.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
include/opal-api.h | 3 +-
include/skiboot.h | 2 ++
5 files changed, 99 insertions(+), 1 deletion(-)
diff --git a/core/sensor.c b/core/sensor.c
index b0d3c5e..dc54d50 100644
--- a/core/sensor.c
+++ b/core/sensor.c
@@ -41,6 +41,18 @@ static int64_t opal_sensor_read(uint32_t sensor_hndl, int token,
return OPAL_UNSUPPORTED;
}
+static int opal_clear_sensor_groups(u32 group_hndl, int token)
+{
+ switch (sensor_get_family(group_hndl)) {
+ case SENSOR_OCC:
+ return occ_clear_sensor_groups(group_hndl, token);
+ default:
+ break;
+ }
+
+ return OPAL_UNSUPPORTED;
+}
+
void sensor_init(void)
{
sensor_node = dt_new(opal_node, "sensors");
@@ -50,4 +62,5 @@ void sensor_init(void)
/* Register OPAL interface */
opal_register(OPAL_SENSOR_READ, opal_sensor_read, 3);
+ opal_register(OPAL_CLEAR_SENSOR_GROUPS, opal_clear_sensor_groups, 2);
}
diff --git a/hw/occ-sensor.c b/hw/occ-sensor.c
index 15b6031..bf9f3f4 100644
--- a/hw/occ-sensor.c
+++ b/hw/occ-sensor.c
@@ -610,4 +610,5 @@ void occ_sensors_init(void)
}
occ_num++;
}
+ occ_add_sensor_groups();
}
diff --git a/hw/occ.c b/hw/occ.c
index 907cf6e..ac84218 100644
--- a/hw/occ.c
+++ b/hw/occ.c
@@ -29,6 +29,7 @@
#include <timer.h>
#include <i2c.h>
#include <powercap.h>
+#include <sensor.h>
/* OCC Communication Area for PStates */
@@ -1458,6 +1459,86 @@ static void occ_add_psr_sensors(struct dt_node *power_mgt)
opal_register(OPAL_SET_PSR, opal_set_power_shifting_ratio, 3);
}
+/* OCC clear sensor limits CSM/Profiler/Job-scheduler */
+
+enum occ_sensor_limit_group {
+ OCC_SENSOR_LIMIT_GROUP_CSM = 0x10,
+ OCC_SENSOR_LIMIT_GROUP_PROFILER = 0x20,
+ OCC_SENSOR_LIMIT_GROUP_JOB_SCHED = 0x40,
+};
+
+static u32 sensor_limit;
+static struct opal_occ_cmd_data slimit_data = {
+ .data = (u8 *)&sensor_limit,
+ .cmd = OCC_CMD_CLEAR_SENSOR_DATA,
+};
+
+int occ_clear_sensor_groups(u32 group_hndl, int token)
+{
+ u32 limit = sensor_get_rid(group_hndl);
+ int i = sensor_get_attr(group_hndl);
+
+ if (i < 0 || i > nr_occs)
+ return OPAL_PARAMETER;
+
+ switch (limit) {
+ case OCC_SENSOR_LIMIT_GROUP_CSM:
+ case OCC_SENSOR_LIMIT_GROUP_PROFILER:
+ case OCC_SENSOR_LIMIT_GROUP_JOB_SCHED:
+ break;
+ default:
+ return OPAL_UNSUPPORTED;
+ }
+
+ if (!(*chips[i].valid))
+ return OPAL_WRONG_STATE;
+
+ sensor_limit = limit << 24;
+ return opal_occ_command(&chips[i], token, &slimit_data);
+}
+
+void occ_add_sensor_groups(void)
+{
+ struct dt_node *sg;
+ struct limit_group_info {
+ int limit;
+ const char *str;
+ } limits[] = {
+ { OCC_SENSOR_LIMIT_GROUP_CSM, "csm" },
+ { OCC_SENSOR_LIMIT_GROUP_PROFILER, "profiler" },
+ { OCC_SENSOR_LIMIT_GROUP_JOB_SCHED, "js" },
+ };
+ int i, j;
+
+ sg = dt_new(opal_node, "sensor-groups");
+ if (!sg) {
+ prerror("OCC: Failed to create sensor groups node\n");
+ return;
+ }
+ dt_add_property_string(sg, "compatible", "ibm,opal-occ-sensor-group");
+
+ for (i = 0; i < nr_occs; i++)
+ for (j = 0; j < ARRAY_SIZE(limits); j++) {
+ struct dt_node *node;
+ char name[20];
+ u32 handle;
+
+ snprintf(name, 20, "occ-%s", limits[j].str);
+ handle = sensor_make_handler(SENSOR_OCC, 0,
+ limits[i].limit, i);
+ node = dt_new_addr(sg, name, handle);
+ if (!node) {
+ prerror("Failed to create sensor group nodes\n");
+ return;
+ }
+
+ dt_add_property_cells(node, "sensor-group-id", handle);
+ dt_add_property_string(node, "type", limits[j].str);
+ dt_add_property_cells(node, "ibm,chip-id",
+ chips[i].chip_id);
+ }
+}
+
/* CPU-OCC PState init */
/* Called after OCC init on P8 and P9 */
void occ_pstates_init(void)
diff --git a/include/opal-api.h b/include/opal-api.h
index 2717a0d..c5f619e 100644
--- a/include/opal-api.h
+++ b/include/opal-api.h
@@ -212,7 +212,8 @@
#define OPAL_SET_POWERCAP 153
#define OPAL_GET_PSR 154
#define OPAL_SET_PSR 155
-#define OPAL_LAST 155
+#define OPAL_CLEAR_SENSOR_GROUPS 156
+#define OPAL_LAST 156
/* Device tree flags */
diff --git a/include/skiboot.h b/include/skiboot.h
index db4ca36..a4ade02 100644
--- a/include/skiboot.h
+++ b/include/skiboot.h
@@ -313,5 +313,7 @@ extern int fake_nvram_write(uint32_t offset, void *src, uint32_t size);
/* OCC Inband Sensors */
extern void occ_sensors_init(void);
extern int occ_sensor_read(u32 handle, u32 *data);
+extern int occ_clear_sensor_groups(u32 group_hndl, int token);
+extern void occ_add_sensor_groups(void);
#endif /* __SKIBOOT_H */
--
1.8.3.1
More information about the Skiboot
mailing list