powerpc/powernv: Add support to enable sensor groups
authorShilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com>
Tue, 24 Jul 2018 09:13:08 +0000 (14:43 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 31 Jul 2018 09:56:45 +0000 (19:56 +1000)
Adds support to enable/disable a sensor group at runtime. This
can be used to select the sensor groups that needs to be copied to
main memory by OCC. Sensor groups like power, temperature, current,
voltage, frequency, utilization can be enabled/disabled at runtime.

Signed-off-by: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/opal-api.h
arch/powerpc/include/asm/opal.h
arch/powerpc/platforms/powernv/opal-sensor-groups.c
arch/powerpc/platforms/powernv/opal-wrappers.S

index 3bab299..56a94a1 100644 (file)
 #define OPAL_NPU_SPA_CLEAR_CACHE               160
 #define OPAL_NPU_TL_SET                                161
 #define OPAL_SENSOR_READ_U64                   162
+#define OPAL_SENSOR_GROUP_ENABLE               163
 #define OPAL_PCI_GET_PBCQ_TUNNEL_BAR           164
 #define OPAL_PCI_SET_PBCQ_TUNNEL_BAR           165
 #define OPAL_LAST                              165
index cd1acc8..2e81555 100644 (file)
@@ -292,6 +292,7 @@ int opal_set_powercap(u32 handle, int token, u32 pcap);
 int opal_get_power_shift_ratio(u32 handle, int token, u32 *psr);
 int opal_set_power_shift_ratio(u32 handle, int token, u32 psr);
 int opal_sensor_group_clear(u32 group_hndl, int token);
+int opal_sensor_group_enable(u32 group_hndl, int token, bool enable);
 
 s64 opal_signal_system_reset(s32 cpu);
 s64 opal_quiesce(u64 shutdown_type, s32 cpu);
@@ -328,6 +329,7 @@ extern int opal_async_wait_response_interruptible(uint64_t token,
                struct opal_msg *msg);
 extern int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data);
 extern int opal_get_sensor_data_u64(u32 sensor_hndl, u64 *sensor_data);
+extern int sensor_group_enable(u32 grp_hndl, bool enable);
 
 struct rtc_time;
 extern time64_t opal_get_boot_time(void);
index 541c9ea..f7d04b6 100644 (file)
@@ -32,6 +32,34 @@ static struct sensor_group {
        struct sg_attr *sgattrs;
 } *sgs;
 
+int sensor_group_enable(u32 handle, bool enable)
+{
+       struct opal_msg msg;
+       int token, ret;
+
+       token = opal_async_get_token_interruptible();
+       if (token < 0)
+               return token;
+
+       ret = opal_sensor_group_enable(handle, token, enable);
+       if (ret == OPAL_ASYNC_COMPLETION) {
+               ret = opal_async_wait_response(token, &msg);
+               if (ret) {
+                       pr_devel("Failed to wait for the async response\n");
+                       ret = -EIO;
+                       goto out;
+               }
+               ret = opal_error_code(opal_get_async_rc(msg));
+       } else {
+               ret = opal_error_code(ret);
+       }
+
+out:
+       opal_async_release_token(token);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(sensor_group_enable);
+
 static ssize_t sg_store(struct kobject *kobj, struct kobj_attribute *attr,
                        const char *buf, size_t count)
 {
index 3508be7..029b37c 100644 (file)
@@ -329,3 +329,4 @@ OPAL_CALL(opal_npu_tl_set,                  OPAL_NPU_TL_SET);
 OPAL_CALL(opal_pci_get_pbcq_tunnel_bar,                OPAL_PCI_GET_PBCQ_TUNNEL_BAR);
 OPAL_CALL(opal_pci_set_pbcq_tunnel_bar,                OPAL_PCI_SET_PBCQ_TUNNEL_BAR);
 OPAL_CALL(opal_sensor_read_u64,                        OPAL_SENSOR_READ_U64);
+OPAL_CALL(opal_sensor_group_enable,            OPAL_SENSOR_GROUP_ENABLE);