From patchwork Fri Feb 20 14:27:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 441980 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 AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DAC91401AB for ; Sat, 21 Feb 2015 01:30:04 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3E1551A0F3A for ; Sat, 21 Feb 2015 01:30:04 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from e06smtp17.uk.ibm.com (e06smtp17.uk.ibm.com [195.75.94.113]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 8BA901A0A52 for ; Sat, 21 Feb 2015 01:29:46 +1100 (AEDT) Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 20 Feb 2015 14:29:42 -0000 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp17.uk.ibm.com (192.168.101.147) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 20 Feb 2015 14:29:39 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 857211B0804B for ; Fri, 20 Feb 2015 14:29:52 +0000 (GMT) Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t1KETdqP1900834 for ; Fri, 20 Feb 2015 14:29:39 GMT Received: from d06av01.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t1KETc9S004172 for ; Fri, 20 Feb 2015 07:29:38 -0700 Received: from hermes.ibm.com (sig-9-78-75-46.uk.ibm.com [9.78.75.46]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t1KETZdl004057; Fri, 20 Feb 2015 07:29:37 -0700 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: skiboot@lists.ozlabs.org Date: Fri, 20 Feb 2015 15:27:25 +0100 Message-Id: <1424442456-11979-3-git-send-email-clg@fr.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1423117857-32759-1-git-send-email-clg@fr.ibm.com> References: <1423117857-32759-1-git-send-email-clg@fr.ibm.com> MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15022014-0029-0000-0000-00000372E911 Subject: [Skiboot] [PATCH v2 02/13] dts: add support to read the core temperatures X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.18 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" This patch adds a new sensor family for Digital Temperature Sensors and a new resource class to capture the core temperatures. Each core has four DTS located in different zones (LSU, ISU, FXU, L3). The max of the four temperatures is computed and returned for the core as well as a global trip point value. This is based on the meltbox tool. Signed-off-by: Cédric Le Goater --- Changes since v1: - moved dts_sensor_read() in common routine opal_sensor_read() Changes since RFC: - moved XSCOM registers definitions in dts.c - renamed a few types to make room for mem dts - call dts_sensor_read from platform op core/sensor.c | 4 ++ hw/Makefile.inc | 2 +- hw/dts.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/dts.h | 24 ++++++++ include/sensor.h | 3 + 5 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 hw/dts.c create mode 100644 include/dts.h diff --git a/core/sensor.c b/core/sensor.c index 6c37a913a848..f2f86c8813ca 100644 --- a/core/sensor.c +++ b/core/sensor.c @@ -20,12 +20,16 @@ #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) { + if (sensor_is_dts(sensor_hndl)) + return dts_sensor_read(sensor_hndl, sensor_data); + if (platform.sensor_read) return platform.sensor_read(sensor_hndl, token, sensor_data); diff --git a/hw/Makefile.inc b/hw/Makefile.inc index 416d23c3c854..a40ebf4ac357 100644 --- a/hw/Makefile.inc +++ b/hw/Makefile.inc @@ -5,7 +5,7 @@ HW_OBJS = xscom.o chiptod.o gx.o cec.o lpc.o lpc-uart.o psi.o HW_OBJS += homer.o slw.o occ.o fsi-master.o centaur.o HW_OBJS += nx.o nx-rng.o nx-crypto.o nx-842.o HW_OBJS += p7ioc.o p7ioc-inits.o p7ioc-phb.o p5ioc2.o p5ioc2-phb.o -HW_OBJS += phb3.o sfc-ctrl.o fake-rtc.o bt.o p8-i2c.o +HW_OBJS += phb3.o sfc-ctrl.o fake-rtc.o bt.o p8-i2c.o dts.o HW=hw/built-in.o include $(SRC)/hw/fsp/Makefile.inc diff --git a/hw/dts.c b/hw/dts.c new file mode 100644 index 000000000000..8affac34c9c5 --- /dev/null +++ b/hw/dts.c @@ -0,0 +1,165 @@ +/* Copyright 2013-2014 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +/* Per core Digital Thermal Sensors */ +#define EX_THERM_DTS_RESULT0 0x10050000 +#define EX_THERM_DTS_RESULT1 0x10050001 + +/* Per core Digital Thermal Sensors control registers */ +#define EX_THERM_MODE_REG 0x1005000F +#define EX_THERM_CONTROL_REG 0x10050012 +#define EX_THERM_ERR_STATUS_REG 0x10050013 + +struct dts { + uint8_t valid; + uint8_t trip; + int16_t temp; +}; + + +/* Therm mac result masking for DTS (result(0:15) + * 0:3 - 0x0 + * 4:11 - Temperature in degrees C + * 12:13 - trip bits: 00 - no trip; 01 - warning; 10 - critical; 11 - fatal + * 14 - spare + * 15 - valid + */ +static void dts_decode_one_dts(uint16_t raw, struct dts *dts) +{ + /* + * The value is both signed and unsigned :-) 0xff could be + * either 255C or -1C, so for now we treat this as unsigned + * which is sufficient for our purpose. We could try to be + * a bit smarter and treat it as signed for values between + * -10 and 0 and unsigned to 239 or something like that... + */ + dts->valid = raw & 1; + if (dts->valid) { + dts->temp = (raw >> 4) & 0xff; + dts->trip = (raw >> 2) & 0x3; + } else { + dts->temp = 0; + dts->trip = 0; + } +} + +/* Different sensor locations */ +#define P8_CT_ZONE_LSU 0 +#define P8_CT_ZONE_ISU 1 +#define P8_CT_ZONE_FXU 2 +#define P8_CT_ZONE_L3C 3 +#define P8_CT_ZONES 4 + +/* + * Returns the temperature as the max of all 4 zones and a global trip + * attribute. + */ +static int dts_read_core_temp(uint32_t pir, struct dts *dts) +{ + int32_t chip_id = pir_to_chip_id(pir); + int32_t core = pir_to_core_id(pir); + uint64_t dts0, dts1; + struct dts temps[P8_CT_ZONES]; + int i; + int rc; + + rc = xscom_read(chip_id, XSCOM_ADDR_P8_EX(core, EX_THERM_DTS_RESULT0), + &dts0); + if (rc) + return rc; + + rc = xscom_read(chip_id, XSCOM_ADDR_P8_EX(core, EX_THERM_DTS_RESULT1), + &dts1); + if (rc) + return rc; + + dts_decode_one_dts(dts0 >> 48, &temps[P8_CT_ZONE_LSU]); + dts_decode_one_dts(dts0 >> 32, &temps[P8_CT_ZONE_ISU]); + dts_decode_one_dts(dts0 >> 16, &temps[P8_CT_ZONE_FXU]); + dts_decode_one_dts(dts1 >> 48, &temps[P8_CT_ZONE_L3C]); + + for (i = 0; i < P8_CT_ZONES; i++) { + int16_t t = temps[i].temp; + + if (!temps[i].valid) + continue; + + /* keep the max temperature of all 4 sensors */ + if (t > dts->temp) + dts->temp = t; + + dts->valid++; + dts->trip |= temps[i].trip; + } + + prlog(PR_TRACE, "DTS: Chip %x Core %x temp:%dC trip:%x\n", + chip_id, core, dts->temp, dts->trip); + return 0; +} + +/* + * DTS sensor class ids. Only one for the moment: the core + * temperature. + */ +enum sensor_dts_class { + SENSOR_DTS_CORE_TEMP, + /* To be continued */ +}; + +/* + * Attributes for the core temperature sensor + */ +enum { + SENSOR_DTS_ATTR_TEMP_MAX, + SENSOR_DTS_ATTR_TEMP_TRIP +}; + +int64_t dts_sensor_read(uint32_t sensor_hndl, uint32_t *sensor_data) +{ + uint8_t attr = sensor_get_attr(sensor_hndl); + uint32_t rid = sensor_get_rid(sensor_hndl); + struct dts dts; + int64_t rc; + + if (attr > SENSOR_DTS_ATTR_TEMP_TRIP) + return OPAL_PARAMETER; + + memset(&dts, 0, sizeof(struct dts)); + + switch (sensor_get_frc(sensor_hndl) & ~SENSOR_DTS) { + case SENSOR_DTS_CORE_TEMP: + rc = dts_read_core_temp(rid, &dts); + break; + default: + rc = OPAL_PARAMETER; + break; + } + if (rc) + return rc; + + if (attr == SENSOR_DTS_ATTR_TEMP_MAX) + *sensor_data = dts.temp; + else if (attr == SENSOR_DTS_ATTR_TEMP_TRIP) + *sensor_data = dts.trip; + + return 0; +} diff --git a/include/dts.h b/include/dts.h new file mode 100644 index 000000000000..18933909ee08 --- /dev/null +++ b/include/dts.h @@ -0,0 +1,24 @@ +/* Copyright 2013-2014 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __DTS_H +#define __DTS_H + +#include + +extern int64_t dts_sensor_read(uint32_t sensor_hndl, uint32_t *sensor_data); + +#endif /* __DTS_H */ diff --git a/include/sensor.h b/include/sensor.h index bd099c3748af..fdd7432cb12c 100644 --- a/include/sensor.h +++ b/include/sensor.h @@ -44,6 +44,9 @@ * the appropriate component. FSP is the initial family. */ #define SENSOR_FSP 0x0 +#define SENSOR_DTS 0x80 + +#define sensor_is_dts(handler) (sensor_get_frc(handler) & SENSOR_DTS) /* * root node of all sensors : /ibm,opal/sensors