From patchwork Fri Dec 15 07:21:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shilpasri G Bhat X-Patchwork-Id: 849006 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yyhlv271Jz9ryQ for ; Fri, 15 Dec 2017 18:25:15 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yyhlv0Gr7zDrn8 for ; Fri, 15 Dec 2017 18:25:15 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=shilpa.bhat@linux.vnet.ibm.com; receiver=) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yyhlg528rzDrn7 for ; Fri, 15 Dec 2017 18:25:03 +1100 (AEDT) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBF7Ovl0069206 for ; Fri, 15 Dec 2017 02:25:01 -0500 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ev7wu4gwa-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 15 Dec 2017 02:24:58 -0500 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 15 Dec 2017 07:21:15 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 15 Dec 2017 07:21:13 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBF7LCbI41091320; Fri, 15 Dec 2017 07:21:12 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 155ECA4057; Fri, 15 Dec 2017 07:15:30 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 55F98A4051; Fri, 15 Dec 2017 07:15:29 +0000 (GMT) Received: from oc4502181600.ibm.com (unknown [9.79.203.247]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 15 Dec 2017 07:15:29 +0000 (GMT) From: Shilpasri G Bhat To: skiboot@lists.ozlabs.org Date: Fri, 15 Dec 2017 12:51:00 +0530 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1513322463-24801-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> References: <1513322463-24801-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17121507-0040-0000-0000-000003FA670C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17121507-0041-0000-0000-000025FD7D0B Message-Id: <1513322463-24801-2-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-15_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712150106 Subject: [Skiboot] [PATCH V2 1/4] sensors: Support reading u64 sensor values X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This patch adds support to read u64 sensor values. This also adds changes to the core and the backend implementation code to make this API as the base call. Host can use this new API to read sensors upto 64bits. This adds a list to store the pointer to the kernel u32 buffer, for older kernels making async sensor u32 reads. Signed-off-by: Shilpasri G Bhat --- core/sensor.c | 78 ++++++++++++++++++++++++++++++- doc/opal-api/opal-sensor-read-u64-158.rst | 16 +++++++ hw/dts.c | 9 ++-- hw/fsp/fsp-sensor.c | 7 +-- hw/occ-sensor.c | 2 +- include/cpu.h | 2 +- include/dts.h | 2 +- include/fsp.h | 2 +- include/opal-api.h | 3 +- include/platform.h | 2 +- include/sensor.h | 1 + include/skiboot.h | 2 +- platforms/ibm-fsp/common.c | 2 +- platforms/ibm-fsp/ibm-fsp.h | 2 +- 14 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 doc/opal-api/opal-sensor-read-u64-158.rst diff --git a/core/sensor.c b/core/sensor.c index ff72636..b128964 100644 --- a/core/sensor.c +++ b/core/sensor.c @@ -20,11 +20,63 @@ #include #include #include +#include struct dt_node *sensor_node; -static int64_t opal_sensor_read(uint32_t sensor_hndl, int token, - uint32_t *sensor_data) +static struct lock async_read_list_lock = LOCK_UNLOCKED; +static LIST_HEAD(async_read_list); + +struct sensor_async_read { + struct list_node link; + u64 *sensor_data64; + u32 *sensor_data32; + int token; +}; + +static int add_to_async_read_list(int token, u32 *data32, u64 *data64) +{ + struct sensor_async_read *req; + + req = zalloc(sizeof(*req)); + if (!req) + return OPAL_NO_MEM; + + req->token = token; + req->sensor_data64 = data64; + req->sensor_data32 = data32; + + lock(&async_read_list_lock); + list_add_tail(&async_read_list, &req->link); + unlock(&async_read_list_lock); + + return OPAL_ASYNC_COMPLETION; +} + +void check_sensor_read(int token) +{ + struct sensor_async_read *req = NULL; + + lock(&async_read_list_lock); + if (list_empty(&async_read_list)) + goto out; + + list_for_each(&async_read_list, req, link) { + if (req->token == token) + break; + } + if (!req) + goto out; + + *req->sensor_data32 = *req->sensor_data64; + free(req->sensor_data64); + list_del(&req->link); + free(req); +out: + unlock(&async_read_list_lock); +} + +static s64 opal_sensor_read_u64(u32 sensor_hndl, int token, u64 *sensor_data) { switch (sensor_get_family(sensor_hndl)) { case SENSOR_DTS: @@ -41,6 +93,27 @@ static int64_t opal_sensor_read(uint32_t sensor_hndl, int token, return OPAL_UNSUPPORTED; } +static int64_t opal_sensor_read(uint32_t sensor_hndl, int token, + uint32_t *sensor_data) +{ + u64 *val; + s64 ret; + + val = zalloc(sizeof(*val)); + if (!val) + return OPAL_NO_MEM; + + ret = opal_sensor_read_u64(sensor_hndl, token, val); + if (!ret) { + *sensor_data = *val; + free(val); + } else if (ret == OPAL_ASYNC_COMPLETION) { + ret = add_to_async_read_list(token, sensor_data, val); + } + + return ret; +} + static int opal_sensor_group_clear(u32 group_hndl, int token) { switch (sensor_get_family(group_hndl)) { @@ -65,4 +138,5 @@ void sensor_init(void) /* Register OPAL interface */ opal_register(OPAL_SENSOR_READ, opal_sensor_read, 3); opal_register(OPAL_SENSOR_GROUP_CLEAR, opal_sensor_group_clear, 2); + opal_register(OPAL_SENSOR_READ_U64, opal_sensor_read_u64, 3); } diff --git a/doc/opal-api/opal-sensor-read-u64-158.rst b/doc/opal-api/opal-sensor-read-u64-158.rst new file mode 100644 index 0000000..b75bcbc --- /dev/null +++ b/doc/opal-api/opal-sensor-read-u64-158.rst @@ -0,0 +1,16 @@ +OPAL_SENSOR_READ_U64 +==================== + +The OPAL sensor call to read sensor data of type u64. Unlike +opal_sensor_read which reads upto u32 this call can be used to +read values of sensors upto 64bits. The calling conventions and +return values are same as OPAL_SENSOR_READ. +(ref: doc/opal-api/opal-sensor-read-88.rst) + +Parameters +---------- +:: + + u32 sensor_handler + int token + u64 *sensor_data diff --git a/hw/dts.c b/hw/dts.c index 881d66e..ecfe847 100644 --- a/hw/dts.c +++ b/hw/dts.c @@ -276,14 +276,15 @@ static void dts_async_read_temp(struct timer *t __unused, void *data, rc = dts_read_core_temp_p9(cpu->pir, &dts); if (!rc) { if (cpu->sensor_attr == SENSOR_DTS_ATTR_TEMP_MAX) - *(u32 *)cpu->sensor_data = dts.temp; + *cpu->sensor_data = dts.temp; else if (cpu->sensor_attr == SENSOR_DTS_ATTR_TEMP_TRIP) - *(u32 *)cpu->sensor_data = dts.trip; + *cpu->sensor_data = dts.trip; } if (!swkup_rc) dctl_clear_special_wakeup(cpu); + check_sensor_read(cpu->token); rc = opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, cpu->token, rc); if (rc) prerror("Failed to queue async message\n"); @@ -292,7 +293,7 @@ static void dts_async_read_temp(struct timer *t __unused, void *data, } static int dts_read_core_temp(u32 pir, struct dts *dts, u8 attr, - int token, u32 *sensor_data) + int token, u64 *sensor_data) { struct cpu_thread *cpu; int rc; @@ -390,7 +391,7 @@ enum sensor_dts_class { */ #define centaur_get_id(rid) (0x80000000 | ((rid) & 0x3ff)) -int64_t dts_sensor_read(u32 sensor_hndl, int token, u32 *sensor_data) +int64_t dts_sensor_read(u32 sensor_hndl, int token, u64 *sensor_data) { uint8_t attr = sensor_get_attr(sensor_hndl); uint32_t rid = sensor_get_rid(sensor_hndl); diff --git a/hw/fsp/fsp-sensor.c b/hw/fsp/fsp-sensor.c index 6363530..eff5d21 100644 --- a/hw/fsp/fsp-sensor.c +++ b/hw/fsp/fsp-sensor.c @@ -87,7 +87,7 @@ enum spcn_attr { /* Parsed sensor attributes, passed through OPAL */ struct opal_sensor_data { uint64_t async_token; /* Asynchronous token */ - uint32_t *sensor_data; /* Kernel pointer to copy data */ + uint64_t *sensor_data; /* Kernel pointer to copy data */ enum spcn_attr spcn_attr; /* Modifier attribute */ uint16_t rid; /* Sensor RID */ uint8_t frc; /* Sensor resource class */ @@ -306,8 +306,9 @@ static int fsp_sensor_process_read(struct fsp_msg *resp_msg) static void queue_msg_for_delivery(int rc, struct opal_sensor_data *attr) { - prlog(PR_INSANE, "%s: rc:%d, data:%d\n", + prlog(PR_INSANE, "%s: rc:%d, data:%lld\n", __func__, rc, *(attr->sensor_data)); + check_sensor_read(attr->async_token); opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, attr->async_token, rc); spcn_mod_data[attr->mod_index].entry_count = 0; @@ -512,7 +513,7 @@ static int64_t parse_sensor_id(uint32_t handler, struct opal_sensor_data *attr) int64_t fsp_opal_read_sensor(uint32_t sensor_hndl, int token, - uint32_t *sensor_data) + uint64_t *sensor_data) { struct opal_sensor_data *attr; int64_t rc; diff --git a/hw/occ-sensor.c b/hw/occ-sensor.c index cb05f7c..11a45c9 100644 --- a/hw/occ-sensor.c +++ b/hw/occ-sensor.c @@ -322,7 +322,7 @@ static inline u32 sensor_handler(int occ_num, int sensor_id, int attr) return sensor_make_handler(SENSOR_OCC, occ_num, sensor_id, attr); } -int occ_sensor_read(u32 handle, u32 *data) +int occ_sensor_read(u32 handle, u64 *data) { struct occ_sensor_data_header *hb; struct occ_sensor_name *md; diff --git a/include/cpu.h b/include/cpu.h index 2804105..805e01b 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -111,7 +111,7 @@ struct cpu_thread { */ struct lock dts_lock; struct timer dts_timer; - void *sensor_data; + u64 *sensor_data; u32 sensor_attr; u32 token; bool dts_read_in_progress; diff --git a/include/dts.h b/include/dts.h index 17e2e15..30188ac 100644 --- a/include/dts.h +++ b/include/dts.h @@ -19,7 +19,7 @@ #include -extern int64_t dts_sensor_read(u32 sensor_hndl, int token, u32 *sensor_data); +extern int64_t dts_sensor_read(u32 sensor_hndl, int token, u64 *sensor_data); extern bool dts_sensor_create_nodes(struct dt_node *sensors); #endif /* __DTS_H */ diff --git a/include/fsp.h b/include/fsp.h index c34a518..9b96d5d 100644 --- a/include/fsp.h +++ b/include/fsp.h @@ -822,7 +822,7 @@ extern void fsp_memory_err_init(void); /* Sensor */ extern void fsp_init_sensor(void); extern int64_t fsp_opal_read_sensor(uint32_t sensor_hndl, int token, - uint32_t *sensor_data); + uint64_t *sensor_data); /* Diagnostic */ extern void fsp_init_diag(void); diff --git a/include/opal-api.h b/include/opal-api.h index 1c1b9cc..7c7a23f 100644 --- a/include/opal-api.h +++ b/include/opal-api.h @@ -215,7 +215,8 @@ #define OPAL_SENSOR_GROUP_CLEAR 156 #define OPAL_PCI_SET_P2P 157 #define OPAL_QUIESCE 158 -#define OPAL_LAST 158 +#define OPAL_SENSOR_READ_U64 159 +#define OPAL_LAST 159 #define QUIESCE_HOLD 1 /* Spin all calls at entry */ #define QUIESCE_REJECT 2 /* Fail all calls with OPAL_BUSY */ diff --git a/include/platform.h b/include/platform.h index f3af390..e6ece27 100644 --- a/include/platform.h +++ b/include/platform.h @@ -183,7 +183,7 @@ struct platform { * Read a sensor value */ int64_t (*sensor_read)(uint32_t sensor_hndl, int token, - uint32_t *sensor_data); + uint64_t *sensor_data); /* * Return the heartbeat time */ diff --git a/include/sensor.h b/include/sensor.h index 445a6bc..40b275a 100644 --- a/include/sensor.h +++ b/include/sensor.h @@ -63,5 +63,6 @@ enum { extern struct dt_node *sensor_node; extern void sensor_init(void); +extern void check_sensor_read(int token); #endif /* __SENSOR_H */ diff --git a/include/skiboot.h b/include/skiboot.h index db91325..298ea0d 100644 --- a/include/skiboot.h +++ b/include/skiboot.h @@ -328,7 +328,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_sensor_read(u32 handle, u64 *data); extern int occ_sensor_group_clear(u32 group_hndl, int token); extern void occ_add_sensor_groups(struct dt_node *sg, u32 *phandles, int nr_phandles, int chipid); diff --git a/platforms/ibm-fsp/common.c b/platforms/ibm-fsp/common.c index e916c39..87afbb6 100644 --- a/platforms/ibm-fsp/common.c +++ b/platforms/ibm-fsp/common.c @@ -230,7 +230,7 @@ int64_t ibm_fsp_cec_power_down(uint64_t request) } int64_t ibm_fsp_sensor_read(uint32_t sensor_hndl, int token, - uint32_t *sensor_data) + uint64_t *sensor_data) { return fsp_opal_read_sensor(sensor_hndl, token, sensor_data); } diff --git a/platforms/ibm-fsp/ibm-fsp.h b/platforms/ibm-fsp/ibm-fsp.h index 3f6e9c5..6c19978 100644 --- a/platforms/ibm-fsp/ibm-fsp.h +++ b/platforms/ibm-fsp/ibm-fsp.h @@ -28,7 +28,7 @@ struct errorlog; extern int elog_fsp_commit(struct errorlog *buf); extern int64_t ibm_fsp_sensor_read(uint32_t sensor_hndl, int token, - uint32_t *sensor_data); + uint64_t *sensor_data); /* Apollo PCI support */ extern void apollo_pci_setup_phb(struct phb *phb, From patchwork Fri Dec 15 07:21:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shilpasri G Bhat X-Patchwork-Id: 849001 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yyhgw29xmz9ryQ for ; Fri, 15 Dec 2017 18:21:48 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yyhgv3LwTzDrnZ for ; Fri, 15 Dec 2017 18:21:47 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=shilpa.bhat@linux.vnet.ibm.com; receiver=) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yyhgP0YnqzDrmx for ; Fri, 15 Dec 2017 18:21:20 +1100 (AEDT) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBF7Jr6w109371 for ; Fri, 15 Dec 2017 02:21:18 -0500 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ev6p96uns-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 15 Dec 2017 02:21:18 -0500 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 15 Dec 2017 07:21:16 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 15 Dec 2017 07:21:15 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBF7LEjc53608660; Fri, 15 Dec 2017 07:21:14 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 596DEA4040; Fri, 15 Dec 2017 07:15:32 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 93601A4051; Fri, 15 Dec 2017 07:15:31 +0000 (GMT) Received: from oc4502181600.ibm.com (unknown [9.79.203.247]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 15 Dec 2017 07:15:31 +0000 (GMT) From: Shilpasri G Bhat To: skiboot@lists.ozlabs.org Date: Fri, 15 Dec 2017 12:51:01 +0530 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1513322463-24801-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> References: <1513322463-24801-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17121507-0012-0000-0000-000005996414 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17121507-0013-0000-0000-000019148292 Message-Id: <1513322463-24801-3-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-15_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712150105 Subject: [Skiboot] [PATCH V2 2/4] sensors: occ: Add energy counters X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Export the accumulated power values as energy sensors. The accumulator field of power sensors are used for representing energy counters which can be exported as energy counters in Linux hwmon interface. Signed-off-by: Shilpasri G Bhat --- hw/occ-sensor.c | 189 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 117 insertions(+), 72 deletions(-) diff --git a/hw/occ-sensor.c b/hw/occ-sensor.c index 11a45c9..eb9c7cf 100644 --- a/hw/occ-sensor.c +++ b/hw/occ-sensor.c @@ -266,6 +266,7 @@ enum sensor_attr { SENSOR_SAMPLE_MAX, SENSOR_CSM_MIN, /* CSM's min/max */ SENSOR_CSM_MAX, + SENSOR_ACCUMULATOR, MAX_SENSOR_ATTR, }; @@ -322,36 +323,38 @@ static inline u32 sensor_handler(int occ_num, int sensor_id, int attr) return sensor_make_handler(SENSOR_OCC, occ_num, sensor_id, attr); } -int occ_sensor_read(u32 handle, u64 *data) +static u64 read_sensor(struct occ_sensor_record *sensor, int attr) { - struct occ_sensor_data_header *hb; - struct occ_sensor_name *md; - struct occ_sensor_record *sping, *spong; - struct occ_sensor_record *sensor = NULL; - u8 *ping, *pong; - u16 id = sensor_get_rid(handle); - u8 occ_num = sensor_get_frc(handle); - u8 attr = sensor_get_attr(handle); + switch (attr) { + case SENSOR_SAMPLE: + return sensor->sample; + case SENSOR_SAMPLE_MIN: + return sensor->sample_min; + case SENSOR_SAMPLE_MAX: + return sensor->sample_max; + case SENSOR_CSM_MIN: + return sensor->csm_min; + case SENSOR_CSM_MAX: + return sensor->csm_max; + case SENSOR_ACCUMULATOR: + return sensor->accumulator; + default: + break; + } - if (occ_num > MAX_OCCS) - return OPAL_PARAMETER; + return 0; +} - if (attr > MAX_SENSOR_ATTR) - return OPAL_PARAMETER; +static void *select_sensor_buffer(struct occ_sensor_data_header *hb, int id) +{ + struct occ_sensor_name *md; + u8 *ping, *pong; + void *buffer; - hb = get_sensor_header_block(occ_num); md = get_names_block(hb); - if (hb->valid != 1) - return OPAL_HARDWARE; - - if (id > hb->nr_sensors) - return OPAL_PARAMETER; - ping = (u8 *)((u64)hb + hb->reading_ping_offset); pong = (u8 *)((u64)hb + hb->reading_pong_offset); - sping = (struct occ_sensor_record *)((u64)ping + md[id].reading_offset); - spong = (struct occ_sensor_record *)((u64)pong + md[id].reading_offset); /* Check which buffer is valid and read the data from that. * Ping Pong Action @@ -360,40 +363,60 @@ int occ_sensor_read(u32 handle, u64 *data) * 1 0 Read Ping * 1 1 Read the buffer with latest timestamp */ + if (*ping && *pong) { - if (sping->timestamp > spong->timestamp) - sensor = sping; - else - sensor = spong; + u64 tping, tpong; + u64 ping_buf = (u64)ping + md[id].reading_offset; + u64 pong_buf = (u64)pong + md[id].reading_offset; + tping = ((struct occ_sensor_record *)ping_buf)->timestamp; + tpong = ((struct occ_sensor_record *)pong_buf)->timestamp; + + if (tping > tpong) + buffer = ping; + else + buffer = pong; } else if (*ping && !*pong) { - sensor = sping; + buffer = ping; } else if (!*ping && *pong) { - sensor = spong; + buffer = pong; } else if (!*ping && !*pong) { prlog(PR_DEBUG, "OCC: Both ping and pong sensor buffers are invalid\n"); - return OPAL_HARDWARE; + return NULL; } - switch (attr) { - case SENSOR_SAMPLE: - *data = sensor->sample; - break; - case SENSOR_SAMPLE_MIN: - *data = sensor->sample_min; - break; - case SENSOR_SAMPLE_MAX: - *data = sensor->sample_max; - break; - case SENSOR_CSM_MIN: - *data = sensor->csm_min; - break; - case SENSOR_CSM_MAX: - *data = sensor->csm_max; - break; - default: - *data = 0; - } + buffer = (void *)((u64)buffer + md[id].reading_offset); + + return buffer; +} + +int occ_sensor_read(u32 handle, u64 *data) +{ + struct occ_sensor_data_header *hb; + u16 id = sensor_get_rid(handle); + u8 occ_num = sensor_get_frc(handle); + u8 attr = sensor_get_attr(handle); + void *buff; + + if (occ_num > MAX_OCCS) + return OPAL_PARAMETER; + + if (attr > MAX_SENSOR_ATTR) + return OPAL_PARAMETER; + + hb = get_sensor_header_block(occ_num); + + if (hb->valid != 1) + return OPAL_HARDWARE; + + if (id > hb->nr_sensors) + return OPAL_PARAMETER; + + buff = select_sensor_buffer(hb, id); + if (!buff) + return OPAL_HARDWARE; + + *data = read_sensor(buff, attr); return OPAL_SUCCESS; } @@ -548,6 +571,38 @@ static const char *get_sensor_loc_string(enum occ_sensor_location loc) return "unknown"; } +static void add_sensor_node(const char *loc, const char *type, int i, int attr, + struct occ_sensor_name *md, u32 *phandle, u32 pir, + u32 occ_num, u32 chipid) +{ + char name[30]; + struct dt_node *node; + u32 handler; + + snprintf(name, sizeof(name), "%s-%s", loc, type); + handler = sensor_handler(occ_num, i, attr); + node = dt_new_addr(sensor_node, name, handler); + dt_add_property_string(node, "sensor-type", type); + dt_add_property_cells(node, "sensor-data", handler); + dt_add_property_cells(node, "reg", handler); + dt_add_property_string(node, "occ_label", md->name); + add_sensor_label(node, md, chipid); + + if (md->location == OCC_SENSOR_LOC_CORE) + dt_add_property_cells(node, "ibm,pir", pir); + + if (attr == SENSOR_SAMPLE) { + handler = sensor_handler(occ_num, i, SENSOR_CSM_MAX); + dt_add_property_cells(node, "sensor-data-max", handler); + + handler = sensor_handler(occ_num, i, SENSOR_CSM_MIN); + dt_add_property_cells(node, "sensor-data-min", handler); + } + + dt_add_property_string(node, "compatible", "ibm,opal-sensor"); + *phandle = node->phandle; +} + void occ_sensors_init(void) { struct proc_chip *chip; @@ -592,11 +647,8 @@ void occ_sensors_init(void) assert(phandles); for (i = 0; i < hb->nr_sensors; i++) { - char name[30]; const char *type, *loc; - struct dt_node *node; struct cpu_thread *c = NULL; - u32 handler; if (md[i].structure_type != OCC_SENSOR_READING_FULL) continue; @@ -616,29 +668,22 @@ void occ_sensors_init(void) type = get_sensor_type_string(md[i].type); loc = get_sensor_loc_string(md[i].location); - snprintf(name, sizeof(name), "%s-%s", loc, type); - handler = sensor_handler(occ_num, i, SENSOR_SAMPLE); - node = dt_new_addr(sensor_node, name, handler); - - dt_add_property_string(node, "sensor-type", type); - dt_add_property_cells(node, "sensor-data", handler); - dt_add_property_cells(node, "reg", handler); - - handler = sensor_handler(occ_num, i, SENSOR_CSM_MAX); - dt_add_property_cells(node, "sensor-data-max", handler); - - handler = sensor_handler(occ_num, i, SENSOR_CSM_MIN); - dt_add_property_cells(node, "sensor-data-min", handler); - - dt_add_property_string(node, "compatible", - "ibm,opal-sensor"); - dt_add_property_string(node, "occ_label", md[i].name); - add_sensor_label(node, &md[i], chip->id); + add_sensor_node(loc, type, i, SENSOR_SAMPLE, &md[i], + &phandles[phcount], c->pir, occ_num, + chip->id); + phcount++; + + /* Add energy sensors */ + if (md[i].type == OCC_SENSOR_TYPE_POWER && + md[i].structure_type == OCC_SENSOR_READING_FULL) { + add_sensor_node(loc, "energy", i, + SENSOR_ACCUMULATOR, &md[i], + &phandles[phcount], c->pir, + occ_num, chip->id); + phcount++; + } - if (md[i].location == OCC_SENSOR_LOC_CORE) - dt_add_property_cells(node, "ibm,pir", c->pir); - phandles[phcount++] = node->phandle; } occ_num++; occ_add_sensor_groups(sg, phandles, phcount, chip->id); From patchwork Fri Dec 15 07:21:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shilpasri G Bhat X-Patchwork-Id: 849002 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yyhhB6zt5z9ryQ for ; Fri, 15 Dec 2017 18:22:02 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yyhhB5YGfzDrmx for ; Fri, 15 Dec 2017 18:22:02 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=shilpa.bhat@linux.vnet.ibm.com; receiver=) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yyhgT2SJzzDrnH for ; Fri, 15 Dec 2017 18:21:25 +1100 (AEDT) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBF7Jj6u057620 for ; Fri, 15 Dec 2017 02:21:22 -0500 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ev7xpmk2t-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 15 Dec 2017 02:21:22 -0500 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 15 Dec 2017 07:21:19 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 15 Dec 2017 07:21:17 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBF7LHHo34144348; Fri, 15 Dec 2017 07:21:17 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 73F96A4040; Fri, 15 Dec 2017 07:15:34 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C753DA404D; Fri, 15 Dec 2017 07:15:33 +0000 (GMT) Received: from oc4502181600.ibm.com (unknown [9.79.203.247]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 15 Dec 2017 07:15:33 +0000 (GMT) From: Shilpasri G Bhat To: skiboot@lists.ozlabs.org Date: Fri, 15 Dec 2017 12:51:02 +0530 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1513322463-24801-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> References: <1513322463-24801-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17121507-0012-0000-0000-000005996416 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17121507-0013-0000-0000-000019148294 Message-Id: <1513322463-24801-4-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-15_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712150105 Subject: [Skiboot] [PATCH V2 3/4] sensors: occ: Scale the sensor values X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Scale the sensor values appropriately to match the HWMON requirements. OCC sensor values should be scaled as per "scale_factor' field and then converted to HWMON required unit. Sensors like temperature and power are already scaled by the kernel driver which convert the values to millidegree Celsius and microWatt respectively. So apart from temperature and power the remaining sensors are converted to HWMON standards. Signed-off-by: Shilpasri G Bhat --- hw/occ-sensor.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 4 deletions(-) diff --git a/hw/occ-sensor.c b/hw/occ-sensor.c index eb9c7cf..bc5085a 100644 --- a/hw/occ-sensor.c +++ b/hw/occ-sensor.c @@ -275,32 +275,80 @@ enum sensor_attr { OCC_SENSOR_TYPE_TEMPERATURE | \ OCC_SENSOR_TYPE_POWER) +/* + * Standard HWMON linux interface expects the below units for the + * environment sensors: + * - Current : milliampere + * - Voltage : millivolt + * - Temperature : millidegree Celsius (scaled in kernel) + * - Power : microWatt (scaled in kernel) + * - Energy : microJoule + */ + +/* + * OCC sensor units are obtained after scaling the sensor values. + * https://github.com/open-power/occ/blob/master/src/occ_405/sensor/sensor_info.c + */ + static struct str_map { const char *occ_str; const char *opal_str; } str_maps[] = { {"PWRSYS", "System"}, + /* Bulk power of the system: Watt */ {"PWRFAN", "Fan"}, + /* Power consumption of the system fans: Watt */ {"PWRIO", "IO"}, + /* Power consumption of the IO subsystem: Watt */ {"PWRSTORE", "Storage"}, + /* Power comsumption of the storage subsystem: Watt */ {"PWRGPU", "GPU"}, + /* Power consumption for GPUs per socket read from APSS: Watt */ {"PWRAPSSCH", "APSS"}, + /* Power Provided by APSS channel x (where x=0…15): Watt */ {"PWRPROC", ""}, + /* Power consumption for this Processor: Watt */ {"PWRVDD", "Vdd"}, - {"CURVDD", "Vdd"}, - {"VOLTVDDSENSE", "Vdd Remote Sense"}, - {"VOLTVDD", "Vdd"}, + /* Power consumption for this Processor's Vdd(AVSBus readings): Watt */ {"PWRVDN", "Vdn"}, + /* Power consumption for  this Processor's Vdn (nest) + * Calculated from AVSBus readings: Watt */ + {"PWRMEM", "Memory"}, + /* Power consumption for Memory  for this Processor read from APSS: + * Watt */ + {"CURVDD", "Vdd"}, + /* Processor Vdd Current (read from AVSBus): Ampere */ {"CURVDN", "Vdn"}, + /* Processor Vdn Current (read from AVSBus): Ampere */ + {"VOLTVDDSENSE", "Vdd Remote Sense"}, + /* Vdd Voltage at the remote sense. + * AVS reading adjusted for loadline: millivolt */ {"VOLTVDNSENSE", "Vdn Remote Sense"}, + /* Vdn Voltage at the remote sense. + * AVS reading adjusted for loadline: millivolt */ + {"VOLTVDD", "Vdd"}, + /* Processor Vdd Voltage (read from AVSBus): millivolt */ {"VOLTVDN", "Vdn"}, - {"PWRMEM", "Memory"}, + /* Processor Vdn Voltage (read from AVSBus): millivolt */ {"TEMPC", "Core"}, + /* Average temperature of core DTS sensors for Processor's Core y: + * Celsius */ {"TEMPQ", "Quad"}, + /* Average temperature of quad (in cache) DTS sensors for + * Processor’s Quad y: Celsius */ {"TEMPNEST", "Nest"}, + /* Average temperature of nest DTS sensors: Celsius */ {"TEMPPROCTHRMC", "Core"}, + /* The combined weighted core/quad temperature for processor core y: + * Celsius */ {"TEMPDIMM", "DIMM"}, + /* DIMM temperature for DIMM x: Celsius */ {"TEMPGPU", "GPU"}, + /* GPU x (0..2) board temperature: Celsius */ + /* TEMPGPUxMEM: GPU x hottest HBM temperature (individual memory + * temperatures are not available): Celsius */ + {"TEMPVDD", "VRM VDD"}, + /* VRM Vdd temperature: Celsius */ }; static u64 occ_sensor_base; @@ -323,6 +371,52 @@ static inline u32 sensor_handler(int occ_num, int sensor_id, int attr) return sensor_make_handler(SENSOR_OCC, occ_num, sensor_id, attr); } +/* + * The scaling factor for the sensors is encoded in the below format: + * (((UINT32)mantissa << 8) | (UINT32)((UINT8) 256 + (UINT8)exp)) + * https://github.com/open-power/occ/blob/master/src/occ_405/sensor/sensor.h + */ +static void scale_sensor(struct occ_sensor_name *md, u64 *sensor) +{ + u32 factor = md->scale_factor; + int i; + s8 exp; + + if (md->type == OCC_SENSOR_TYPE_CURRENT) + *sensor *= 1000; //convert to mA + + *sensor *= factor >> 8; + exp = factor & 0xFF; + + if (exp > 0) { + for (i = labs(exp); i > 0; i--) + *sensor *= 10; + } else { + for (i = labs(exp); sensor && i > 0; i--) + *sensor /= 10; + } +} + +static void scale_energy(struct occ_sensor_name *md, u64 *sensor) +{ + u32 factor = md->freq; + int i; + s8 exp; + + *sensor *= 1000000; //convert to uJ + + *sensor /= factor >> 8; + exp = factor & 0xFF; + + if (exp > 0) { + for (i = labs(exp); sensor && i > 0; i--) + *sensor /= 10; + } else { + for (i = labs(exp); i > 0; i--) + *sensor *= 10; + } +} + static u64 read_sensor(struct occ_sensor_record *sensor, int attr) { switch (attr) { @@ -393,6 +487,7 @@ static void *select_sensor_buffer(struct occ_sensor_data_header *hb, int id) int occ_sensor_read(u32 handle, u64 *data) { struct occ_sensor_data_header *hb; + struct occ_sensor_name *md; u16 id = sensor_get_rid(handle); u8 occ_num = sensor_get_frc(handle); u8 attr = sensor_get_attr(handle); @@ -417,6 +512,14 @@ int occ_sensor_read(u32 handle, u64 *data) return OPAL_HARDWARE; *data = read_sensor(buff, attr); + if (!*data) + return OPAL_SUCCESS; + + md = get_names_block(hb); + if (md[id].type == OCC_SENSOR_TYPE_POWER && attr == SENSOR_ACCUMULATOR) + scale_energy(&md[id], data); + else + scale_sensor(&md[id], data); return OPAL_SUCCESS; } From patchwork Fri Dec 15 07:21:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shilpasri G Bhat X-Patchwork-Id: 849003 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yyhhS6FQ6z9ryQ for ; Fri, 15 Dec 2017 18:22:16 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yyhhS57CyzDrnS for ; Fri, 15 Dec 2017 18:22:16 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=shilpa.bhat@linux.vnet.ibm.com; receiver=) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yyhgW3KYkzDrnb for ; Fri, 15 Dec 2017 18:21:27 +1100 (AEDT) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBF7KHIZ046342 for ; Fri, 15 Dec 2017 02:21:24 -0500 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ev8w2j91b-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 15 Dec 2017 02:21:24 -0500 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 15 Dec 2017 07:21:22 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 15 Dec 2017 07:21:19 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBF7LJxl32440478; Fri, 15 Dec 2017 07:21:19 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A2278A4051; Fri, 15 Dec 2017 07:15:36 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DC957A4040; Fri, 15 Dec 2017 07:15:35 +0000 (GMT) Received: from oc4502181600.ibm.com (unknown [9.79.203.247]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 15 Dec 2017 07:15:35 +0000 (GMT) From: Shilpasri G Bhat To: skiboot@lists.ozlabs.org Date: Fri, 15 Dec 2017 12:51:03 +0530 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1513322463-24801-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> References: <1513322463-24801-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17121507-0012-0000-0000-000005996418 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17121507-0013-0000-0000-000019148296 Message-Id: <1513322463-24801-5-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-15_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712150105 Subject: [Skiboot] [PATCH V2 4/4] sensors: occ: Filter out de-configured sensors X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" OCC copies APSS, GPU sensors on platforms that dont have them. The de-configured sensors are copied with 0 sensor values. So filter out the zero'ed environment sensors as they are not present on the system. Signed-off-by: Shilpasri G Bhat --- hw/occ-sensor.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hw/occ-sensor.c b/hw/occ-sensor.c index bc5085a..e41c850 100644 --- a/hw/occ-sensor.c +++ b/hw/occ-sensor.c @@ -706,6 +706,17 @@ static void add_sensor_node(const char *loc, const char *type, int i, int attr, *phandle = node->phandle; } +static bool check_sensor_sample(struct occ_sensor_data_header *hb, u32 offset) +{ + struct occ_sensor_record *ping, *pong; + + ping = (struct occ_sensor_record *)((u64)hb + hb->reading_ping_offset + + offset); + pong = (struct occ_sensor_record *)((u64)hb + hb->reading_pong_offset + + offset); + return ping->sample || pong->sample; +} + void occ_sensors_init(void) { struct proc_chip *chip; @@ -759,6 +770,9 @@ void occ_sensors_init(void) if (!(md[i].type & HWMON_SENSORS_MASK)) continue; + if (!check_sensor_sample(hb, md[i].reading_offset)) + continue; + if (md[i].location == OCC_SENSOR_LOC_CORE) { int num = parse_entity(md[i].name, NULL);