From patchwork Thu Jul 13 06:47:42 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: 787532 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 3x7RH15S9Gz9s65 for ; Thu, 13 Jul 2017 16:48:29 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3x7RH14WG8zDqlD for ; Thu, 13 Jul 2017 16:48:29 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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 3x7RGT4vqGzDqlP for ; Thu, 13 Jul 2017 16:48:01 +1000 (AEST) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v6D6hdGx041137 for ; Thu, 13 Jul 2017 02:47:59 -0400 Received: from e23smtp03.au.ibm.com (e23smtp03.au.ibm.com [202.81.31.145]) by mx0b-001b2d01.pphosted.com with ESMTP id 2bnt3p273d-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 13 Jul 2017 02:47:59 -0400 Received: from localhost by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 13 Jul 2017 16:47:55 +1000 Received: from d23relay08.au.ibm.com (202.81.31.227) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 13 Jul 2017 16:47:53 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay08.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v6D6lqUx23658740 for ; Thu, 13 Jul 2017 16:47:52 +1000 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v6D6lhGs009539 for ; Thu, 13 Jul 2017 16:47:43 +1000 Received: from oc4502181600.in.ibm.com (oc4502181600.in.ibm.com [9.124.35.219]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v6D6lZHm009249; Thu, 13 Jul 2017 16:47:42 +1000 From: Shilpasri G Bhat To: skiboot@lists.ozlabs.org, stewart@linux.vnet.ibm.com, cyrilbur@gmail.com Date: Thu, 13 Jul 2017 12:17:42 +0530 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1499928462-31192-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> References: <1499928462-31192-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17071306-0008-0000-0000-00000150BD2A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17071306-0009-0000-0000-000009814A37 Message-Id: <1499928462-31192-4-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-07-13_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1707130102 Subject: [Skiboot] [RFC V5 3/3] powercap: occ: Add a generic powercap framework X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ego@linux.vnet.ibm.com MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This patch adds a generic powercap framework and exports OCC powercap sensors. Signed-off-by: Shilpasri G Bhat --- core/Makefile.inc | 2 +- core/powercap.c | 49 ++++++++++++++++++++++++ hw/occ.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/opal-api.h | 19 +++++++++- 4 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 core/powercap.c diff --git a/core/Makefile.inc b/core/Makefile.inc index b09c30c..b3c9e91 100644 --- a/core/Makefile.inc +++ b/core/Makefile.inc @@ -8,7 +8,7 @@ CORE_OBJS += pci-opal.o fast-reboot.o device.o exceptions.o trace.o affinity.o CORE_OBJS += vpd.o hostservices.o platform.o nvram.o nvram-format.o hmi.o CORE_OBJS += console-log.o ipmi.o time-utils.o pel.o pool.o errorlog.o CORE_OBJS += timer.o i2c.o rtc.o flash.o sensor.o ipmi-opal.o -CORE_OBJS += flash-subpartition.o bitmap.o buddy.o pci-quirk.o +CORE_OBJS += flash-subpartition.o bitmap.o buddy.o pci-quirk.o powercap.o ifeq ($(SKIBOOT_GCOV),1) CORE_OBJS += gcov-profiling.o diff --git a/core/powercap.c b/core/powercap.c new file mode 100644 index 0000000..f5d645a --- /dev/null +++ b/core/powercap.c @@ -0,0 +1,49 @@ +/* Copyright 2017 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 + +static inline int get_powercap_type(u32 handle) +{ + return ((handle >> 24) & 0xF); +} + +static int opal_get_powercap(u32 handle, u32 *data) +{ + u8 type = get_powercap_type(handle); + + if (!data || !opal_addr_valid(data)) + return OPAL_PARAMETER; + + if (type == OPAL_POWERCAP_TYPE_OCC) + return occ_get_powercap(handle, data); + + return OPAL_UNSUPPORTED; +}; + +opal_call(OPAL_GET_POWERCAP, opal_get_powercap, 2); + +static int opal_set_powercap(u32 handle, void *data, int token) +{ + u8 type = get_powercap_type(handle); + + if (type == OPAL_POWERCAP_TYPE_OCC) + return occ_set_powercap(token, data); + + return OPAL_UNSUPPORTED; +}; + +opal_call(OPAL_SET_POWERCAP, opal_set_powercap, 3); diff --git a/hw/occ.c b/hw/occ.c index cde52e7..f82fbe5 100644 --- a/hw/occ.c +++ b/hw/occ.c @@ -1244,6 +1244,111 @@ static void occ_cmd_interface_init(void) opal_register(OPAL_OCC_COMMAND, opal_occ_command, 4); } +enum occ_powercap_attr { + OCC_POWERCAP_ATTR_MIN, + OCC_POWERCAP_ATTR_MAX, + OCC_POWERCAP_ATTR_CUR, + OCC_POWERCAP_ATTR_LAST +}; + +int occ_get_powercap(u32 handle, u32 *data) +{ + struct occ_pstate_table *pdata; + struct occ_dynamic_data *ddata; + struct proc_chip *chip; + u8 attr = handle & 0xF; + + chip = next_chip(NULL); + pdata = get_occ_pstate_table(chip); + if (!pdata->valid) + return OPAL_BUSY; + + if (pdata->version != 0x90) + return OPAL_UNSUPPORTED; + + ddata = get_occ_dynamic_data(chip); + switch (attr) { + case OCC_POWERCAP_ATTR_MIN: + *data = ddata->min_pwr_cap; + break; + case OCC_POWERCAP_ATTR_MAX: + *data = ddata->max_pwr_cap; + break; + case OCC_POWERCAP_ATTR_CUR: + *data = ddata->cur_pwr_cap; + break; + default: + return OPAL_UNSUPPORTED; + } + + return OPAL_SUCCESS; +} + +int occ_set_powercap(int token, struct opal_occ_cmd_rsp_msg *msg) +{ + struct occ_pstate_table *pdata; + struct proc_chip *chip; + int i; + + chip = next_chip(NULL); + pdata = get_occ_pstate_table(chip); + if (!pdata->valid) + return OPAL_BUSY; + + if (pdata->version != 0x90) + return OPAL_UNSUPPORTED; + + for (i = 0; i < nr_occs; i++) + if (chips[i].occ_role == OCC_ROLE_MASTER) + break; + + return opal_occ_command(chips[i].id, msg, token, false); +}; + +static void occ_add_powercap_sensors(void) +{ + struct occ_pstate_table *pdata; + struct proc_chip *chip; + struct dt_node *power_mgt, *powercap; + int i; + const char *powercap_node_strings[] = { + "system-min-powercap", + "system-max-powercap", + "system-cur-powercap", + }; + + chip = next_chip(NULL); + pdata = get_occ_pstate_table(chip); + if (pdata->version != 0x90) + return; + + power_mgt = dt_find_by_path(dt_root, "/ibm,opal/power-mgt"); + if (!power_mgt) { + prerror("OCC: dt node /ibm,opal/power-mgt not found\n"); + return; + } + + powercap = dt_new(power_mgt, "powercap"); + if (!powercap) { + prerror("OCC: Failed to create powercap node\n"); + return; + } + + for (i = 0; i < OCC_POWERCAP_ATTR_LAST; i++) { + struct dt_node *node; + u32 handle; + + node = dt_new(powercap, powercap_node_strings[i]); + if (!node) { + prerror("OCC: Failed to create powercap sub node\n"); + return; + } + + handle = make_powercap_handle(OPAL_POWERCAP_TYPE_OCC, i); + dt_add_property_cells(node, "handle", handle); + } +} + /* CPU-OCC PState init */ /* Called after OCC init on P8 and P9 */ void occ_pstates_init(void) @@ -1314,6 +1419,9 @@ void occ_pstates_init(void) /* Init OPAL-OCC command-response interface */ occ_cmd_interface_init(); + + /* Add powercap sensors*/ + occ_add_powercap_sensors(); } struct occ_load_req { diff --git a/include/opal-api.h b/include/opal-api.h index b7b6e67..96c1ec9 100644 --- a/include/opal-api.h +++ b/include/opal-api.h @@ -209,7 +209,9 @@ #define OPAL_IMC_COUNTERS_START 150 #define OPAL_IMC_COUNTERS_STOP 151 #define OPAL_OCC_COMMAND 152 -#define OPAL_LAST 152 +#define OPAL_SET_POWERCAP 153 +#define OPAL_GET_POWERCAP 154 +#define OPAL_LAST 154 /* Device tree flags */ @@ -1110,6 +1112,21 @@ struct opal_occ_rsp_data { u8 data[]; }; +/* Powercap */ + +enum opal_powercap_type { + OPAL_POWERCAP_TYPE_OCC, +}; + +static inline int make_powercap_handle(u8 type, u8 attr) +{ + u32 handle = ((type << 24) | attr); + return handle; +} + +int occ_set_powercap(int token, struct opal_occ_cmd_rsp_msg *msg); +int occ_get_powercap(u32 handle, u32 *data); + enum opal_prd_msg_type { OPAL_PRD_MSG_TYPE_INIT = 0, /* HBRT --> OPAL */ OPAL_PRD_MSG_TYPE_FINI, /* HBRT/kernel --> OPAL */