From patchwork Fri Apr 3 08:56:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Goel X-Patchwork-Id: 1265959 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48tv3202CHz9sRR for ; Fri, 3 Apr 2020 19:57:50 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 48tv315L5nzDrq8 for ; Fri, 3 Apr 2020 19:57:49 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=huntbag@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com 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 48tv2l6ghBzDrQv for ; Fri, 3 Apr 2020 19:57:28 +1100 (AEDT) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0338iajY141198 for ; Fri, 3 Apr 2020 04:57:26 -0400 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 304g88a6xh-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 03 Apr 2020 04:57:25 -0400 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 3 Apr 2020 09:57:11 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 3 Apr 2020 09:57:08 +0100 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 0338vKNo17891578 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 3 Apr 2020 08:57:20 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2F5E6A4055; Fri, 3 Apr 2020 08:57:20 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0B85BA4051; Fri, 3 Apr 2020 08:57:19 +0000 (GMT) Received: from ltc-wspoon6.aus.stglabs.ibm.com (unknown [9.40.193.95]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 3 Apr 2020 08:57:18 +0000 (GMT) From: Abhishek Goel To: skiboot@lists.ozlabs.org Date: Fri, 3 Apr 2020 03:56:38 -0500 X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 x-cbid: 20040308-0008-0000-0000-000003699A55 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20040308-0009-0000-0000-00004A8B2966 Message-Id: <20200403085638.39427-1-huntbag@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.676 definitions=2020-04-03_05:2020-04-02, 2020-04-03 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 impostorscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 adultscore=0 mlxscore=0 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004030068 Subject: [Skiboot] [RFC] opal : Support for pre-entry and post-exit of stop state in opal X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 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, vaidy@linux.ibm.com MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This patch provides opal support for save restore of sprs in idle stop loop for LE opal. Opal support for stop states is needed to selectively enable stop states or to introduce a quirk quickly in case a buggy stop state is present. We make a opal call from kernel if firmware-stop-support for stop states is enabled. All the quirks for pre-entry of stop state is handled inside opal. A call from opal is made into kernel where we execute stop afer saving of NVGPRs. After waking up from 0x100 vector in kernel, we enter back into opal. All the quirks in post exit path, if any, are then handled in opal, from where we return successfully back to kernel. For deep stop states in which additional SPRs are lost, saving and restoration will be done in OPAL. This idea was first proposed by Nick here: https://patchwork.ozlabs.org/patch/1208159/ Will combine this patch with the idle-stop versioning patch for BE opal proposed here : https://patchwork.ozlabs.org/patch/1249114/ Signed-off-by: Abhishek Goel Signed-off-by: Nicholas Piggin --- core/opal.c | 57 +++++++++++++++++++++++++++++++++++++++++ hw/slw.c | 3 +++ include/opal-api.h | 8 +++++- include/opal-internal.h | 10 ++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/core/opal.c b/core/opal.c index 64fdfe62..e7fa087c 100644 --- a/core/opal.c +++ b/core/opal.c @@ -44,6 +44,7 @@ static uint64_t opal_dynamic_events; extern uint32_t attn_trigger; extern uint32_t hir_trigger; +struct os_ops os_ops; void opal_table_init(void) { @@ -422,6 +423,62 @@ void add_opal_node(void) memcons_add_properties(); } +/* + * Function to register all the os operations in opal. + * Currently registering a os_ops that will handle idle stop + * saving and restoring of sprs in kernel. + */ +static int64_t opal_register_os_ops(struct opal_os_ops *__os_ops) +{ + struct cpu_thread *cpu; + + for_each_cpu(cpu) { + if (cpu == this_cpu()) + continue; + if (cpu->state == cpu_state_os) + return OPAL_BUSY; + } + + os_ops.os_idle_stop = (void *)be64_to_cpu(__os_ops->os_idle_stop); + + return OPAL_SUCCESS; +} +opal_call(OPAL_REGISTER_OS_OPS, opal_register_os_ops, 1); + +/* + * Opal function to handle idle stop in kernel. + */ +static uint64_t opal_cpu_idle(__be64 srr1_addr, uint64_t psscr) +{ + u64 *le_srr1 = (u64 *)be64_to_cpu(srr1_addr); + + if (!os_ops.os_idle_stop) + return OPAL_UNSUPPORTED; + + if (proc_gen != proc_gen_p9) + return OPAL_UNSUPPORTED; + + /* + * This will contain all the kernel code or quirks which + * manages saving of sprs before entering into stop. + * Saving of Additional SPRs required for deep stop states will + * be done here. + */ + if (!(psscr & (OPAL_PM_PSSCR_EC|OPAL_PM_PSSCR_ESL))) + *le_srr1 = os_ops.os_idle_stop(psscr, false); + else + *le_srr1 = os_ops.os_idle_stop(psscr, true); + /* + * This will contain all the kernel code or quirks which + * manages restoring of sprs after exiting from stop. + * Restoration of additional SPRs that are lost for deep stop + * states will be done here. + */ + + return OPAL_SUCCESS; +} +opal_call(OPAL_CPU_IDLE, opal_cpu_idle, 2); + static struct lock evt_lock = LOCK_UNLOCKED; void opal_update_pending_evt(uint64_t evt_mask, uint64_t evt_values) diff --git a/hw/slw.c b/hw/slw.c index beb129a8..96e7152f 100644 --- a/hw/slw.c +++ b/hw/slw.c @@ -958,6 +958,9 @@ void add_cpu_idle_state_properties(void) dt_add_property(power_mgt, "ibm,cpu-idle-state-psscr-mask", pm_ctrl_reg_mask_buf, num_supported_idle_states * sizeof(u64)); + if (__BYTE_ORDER == __LITTLE_ENDIAN) + dt_add_property_string(power_mgt, "compatible", + "firmware-stop-supported"); } else { dt_add_property(power_mgt, "ibm,cpu-idle-state-pmicr", pm_ctrl_reg_val_buf, diff --git a/include/opal-api.h b/include/opal-api.h index e90cab1e..a1e7d122 100644 --- a/include/opal-api.h +++ b/include/opal-api.h @@ -227,7 +227,9 @@ #define OPAL_SECVAR_ENQUEUE_UPDATE 178 #define OPAL_PHB_SET_OPTION 179 #define OPAL_PHB_GET_OPTION 180 -#define OPAL_LAST 180 +#define OPAL_REGISTER_OS_OPS 181 +#define OPAL_CPU_IDLE 182 +#define OPAL_LAST 182 #define QUIESCE_HOLD 1 /* Spin all calls at entry */ #define QUIESCE_REJECT 2 /* Fail all calls with OPAL_BUSY */ @@ -1255,6 +1257,10 @@ struct opal_mpipl_fadump { struct opal_mpipl_region region[]; }; +struct opal_os_ops { + __be64 os_idle_stop; +}; + #endif /* __ASSEMBLY__ */ #endif /* __OPAL_API_H */ diff --git a/include/opal-internal.h b/include/opal-internal.h index f6ca7ac3..9368fb79 100644 --- a/include/opal-internal.h +++ b/include/opal-internal.h @@ -18,6 +18,14 @@ struct opal_table_entry { u32 nargs; }; +struct os_ops { + /* + * save_gprs help us distinguish between lite states and + * non-lite states. + */ + int64_t (*os_idle_stop)(uint64_t psscr, bool save_gprs); +}; + #ifdef __CHECKER__ #define __opal_func_test_arg(__func, __nargs) 0 #else @@ -75,6 +83,8 @@ extern void opal_run_pollers(void); extern void opal_add_host_sync_notifier(bool (*notify)(void *data), void *data); extern void opal_del_host_sync_notifier(bool (*notify)(void *data), void *data); +extern int64_t os_idle_stop(uint64_t psscr, bool save_gprs); + /* * Opal internal function prototype */