Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1433464ybb; Thu, 26 Mar 2020 00:12:17 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs5ZaxU7R53BlwiWbarkfYzPtDWFJHSHRXX9pWJT2uHyRea0u71W4u43rfM27++VVUrp6sq X-Received: by 2002:aca:ea05:: with SMTP id i5mr909884oih.162.1585206737767; Thu, 26 Mar 2020 00:12:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585206737; cv=none; d=google.com; s=arc-20160816; b=UUwHhulSuBrpo1OfnpsW9ynSS+sWAb3eViafJ/26eOwlY6sOQPfyY/E9ydC0Q5npyG eDUTyr1Id4vgJbo9SEj9Wa58nBWEXhdOgeCb5QWse1nf5S9Q+BHHZ+kIEHvfPPTkUqSy ykx8F6nhqUn+V3aAqJGx2LAUeMBHJaRGxeQWlmTqzcMOQXGy9cmJzi1bStCApm3x6F6g H213zpur/tq31ReIVwqZskREgFVHFBGVbRZHGERAmjV+1Jl1dUgL76VIF+8E1kiIrAe9 pnANwvqweFJhZ73crLEcbXmgVFp3zvs7mE9oa3qaukO2yHQCHE6XYmiSPdP6cNuI2KWe ZZTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:subject:to:from; bh=log8TKgg7H2K3kSdu4I9DeSHluwDkRcCLipu0jIO3Js=; b=rJ/sY617fMS8cFpXPZVEeu2hT0ej+X3iULr9Q8d2/pkoNHtplOBmF1M8Z+ARkFgV/y zkMWQqd9gk+vzFhhL0X0biTYU6TYFfbDcCq0LwdEqJr22qBIL8C6l3Q76FfOmumTonmq OyfgMdw5F8PrKyvoGyVKfA8ubYJJPz6WgtHTs/z219rfRwMfbWKGtX/MSN1+1kAHcVdW fDfA44bcoH72nMFkGPLTmlMTdY8tryQhRwWwmEoLs0fEi4hdSZlUsm3abIlPT/6LztTh fj7twHfQKh6ZqFr2/0UchOwzGhjNtB+wcEKLoewLghNbyOCdEoZM3tzujsJP1KUs9cWV oMqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v14si668915oou.5.2020.03.26.00.12.04; Thu, 26 Mar 2020 00:12:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727736AbgCZHKr (ORCPT + 99 others); Thu, 26 Mar 2020 03:10:47 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:12238 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726298AbgCZHKr (ORCPT ); Thu, 26 Mar 2020 03:10:47 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02Q74K5Y129874 for ; Thu, 26 Mar 2020 03:10:45 -0400 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 2yweww9tje-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 26 Mar 2020 03:10:45 -0400 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 26 Mar 2020 07:10:40 -0000 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) Thu, 26 Mar 2020 07:10:37 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 02Q7Ad3H40042742 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Mar 2020 07:10:39 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CDF364C04A; Thu, 26 Mar 2020 07:10:39 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A26BB4C050; Thu, 26 Mar 2020 07:10:37 +0000 (GMT) Received: from pratiks-thinkpad.ibmuc.com (unknown [9.199.35.246]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 26 Mar 2020 07:10:37 +0000 (GMT) From: Pratik Rajesh Sampat To: linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org, mpe@ellerman.id.au, skiboot@lists.ozlabs.org, oohall@gmail.com, ego@linux.vnet.ibm.com, linuxram@us.ibm.com, psampat@linux.ibm.com, pratik.r.sampat@gmail.com Subject: [PATCH v6 1/3] powerpc/powernv: Introduce interface for self-restore support Date: Thu, 26 Mar 2020 12:40:32 +0530 X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200326071034.12838-1-psampat@linux.ibm.com> References: <20200326071034.12838-1-psampat@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 20032607-0008-0000-0000-000003647BFD X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20032607-0009-0000-0000-00004A85EE5C Message-Id: <20200326071034.12838-2-psampat@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.645 definitions=2020-03-25_15:2020-03-24,2020-03-25 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 spamscore=0 clxscore=1015 malwarescore=0 impostorscore=0 bulkscore=0 phishscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003260043 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduces an interface that helps determine support for the self-restore API. The commit is isomorphic to the original interface of declaring SPRs to self-restore. Signed-off-by: Pratik Rajesh Sampat --- arch/powerpc/platforms/powernv/idle.c | 200 +++++++++++++++++++------- 1 file changed, 152 insertions(+), 48 deletions(-) diff --git a/arch/powerpc/platforms/powernv/idle.c b/arch/powerpc/platforms/powernv/idle.c index 78599bca66c2..858ceb86394d 100644 --- a/arch/powerpc/platforms/powernv/idle.c +++ b/arch/powerpc/platforms/powernv/idle.c @@ -32,10 +32,67 @@ #define P9_STOP_SPR_MSR 2000 #define P9_STOP_SPR_PSSCR 855 +/* + * Type of support for each SPR + * FIRMWARE_RESTORE: firmware restoration supported: calls self-restore OPAL API + */ +#define UNSUPPORTED 0x0 +#define FIRMWARE_RESTORE 0x1 + static u32 supported_cpuidle_states; struct pnv_idle_states_t *pnv_idle_states; int nr_pnv_idle_states; +struct preferred_sprs { + u64 spr; + u32 supported_mode; +}; + +/* + * Supported mode: Default support. Can be overwritten during system + * initialization + */ +struct preferred_sprs preferred_sprs[] = { + { + .spr = SPRN_HSPRG0, + .supported_mode = FIRMWARE_RESTORE, + }, + { + .spr = SPRN_LPCR, + .supported_mode = FIRMWARE_RESTORE, + }, + { + .spr = SPRN_HMEER, + .supported_mode = FIRMWARE_RESTORE, + }, + { + .spr = SPRN_HID0, + .supported_mode = FIRMWARE_RESTORE, + }, + { + .spr = P9_STOP_SPR_MSR, + .supported_mode = FIRMWARE_RESTORE, + }, + { + .spr = P9_STOP_SPR_PSSCR, + .supported_mode = FIRMWARE_RESTORE, + }, + { + .spr = SPRN_HID1, + .supported_mode = FIRMWARE_RESTORE, + }, + { + .spr = SPRN_HID4, + .supported_mode = FIRMWARE_RESTORE, + }, + { + .spr = SPRN_HID5, + .supported_mode = FIRMWARE_RESTORE, + } +}; + +const int nr_preferred_sprs = ARRAY_SIZE(preferred_sprs); + /* * The default stop state that will be used by ppc_md.power_save * function on platforms that support stop instruction. @@ -61,78 +118,125 @@ static bool deepest_stop_found; static unsigned long power7_offline_type; -static int pnv_save_sprs_for_deep_states(void) +static int pnv_self_restore_sprs(u64 pir, int cpu, u64 spr) { - int cpu; + u64 reg_val; int rc; - /* - * hid0, hid1, hid4, hid5, hmeer and lpcr values are symmetric across - * all cpus at boot. Get these reg values of current cpu and use the - * same across all cpus. - */ - uint64_t lpcr_val = mfspr(SPRN_LPCR); - uint64_t hid0_val = mfspr(SPRN_HID0); - uint64_t hid1_val = mfspr(SPRN_HID1); - uint64_t hid4_val = mfspr(SPRN_HID4); - uint64_t hid5_val = mfspr(SPRN_HID5); - uint64_t hmeer_val = mfspr(SPRN_HMEER); - uint64_t msr_val = MSR_IDLE; - uint64_t psscr_val = pnv_deepest_stop_psscr_val; - - for_each_present_cpu(cpu) { - uint64_t pir = get_hard_smp_processor_id(cpu); - uint64_t hsprg0_val = (uint64_t)paca_ptrs[cpu]; - - rc = opal_slw_set_reg(pir, SPRN_HSPRG0, hsprg0_val); + switch (spr) { + case SPRN_HSPRG0: + reg_val = (uint64_t)paca_ptrs[cpu]; + rc = opal_slw_set_reg(pir, SPRN_HSPRG0, reg_val); if (rc != 0) return rc; - - rc = opal_slw_set_reg(pir, SPRN_LPCR, lpcr_val); + break; + case SPRN_LPCR: + reg_val = mfspr(SPRN_LPCR); + rc = opal_slw_set_reg(pir, SPRN_LPCR, reg_val); if (rc != 0) return rc; - + break; + case P9_STOP_SPR_MSR: + reg_val = MSR_IDLE; if (cpu_has_feature(CPU_FTR_ARCH_300)) { - rc = opal_slw_set_reg(pir, P9_STOP_SPR_MSR, msr_val); + rc = opal_slw_set_reg(pir, P9_STOP_SPR_MSR, reg_val); if (rc) return rc; - - rc = opal_slw_set_reg(pir, - P9_STOP_SPR_PSSCR, psscr_val); - + } + break; + case P9_STOP_SPR_PSSCR: + reg_val = pnv_deepest_stop_psscr_val; + if (cpu_has_feature(CPU_FTR_ARCH_300)) { + rc = opal_slw_set_reg(pir, P9_STOP_SPR_PSSCR, reg_val); if (rc) return rc; } - - /* HIDs are per core registers */ + break; + case SPRN_HMEER: + reg_val = mfspr(SPRN_HMEER); if (cpu_thread_in_core(cpu) == 0) { - - rc = opal_slw_set_reg(pir, SPRN_HMEER, hmeer_val); - if (rc != 0) + rc = opal_slw_set_reg(pir, SPRN_HMEER, reg_val); + if (rc) return rc; - - rc = opal_slw_set_reg(pir, SPRN_HID0, hid0_val); - if (rc != 0) + } + break; + case SPRN_HID0: + reg_val = mfspr(SPRN_HID0); + if (cpu_thread_in_core(cpu) == 0) { + rc = opal_slw_set_reg(pir, SPRN_HID0, reg_val); + if (rc) return rc; + } + break; + case SPRN_HID1: + reg_val = mfspr(SPRN_HID1); + if (!cpu_has_feature(CPU_FTR_ARCH_300) && + cpu_thread_in_core(cpu) == 0) { + rc = opal_slw_set_reg(pir, SPRN_HID1, reg_val); + if (rc) + return rc; + } + break; + case SPRN_HID4: + reg_val = mfspr(SPRN_HID4); + if (!cpu_has_feature(CPU_FTR_ARCH_300) && + cpu_thread_in_core(cpu) == 0) { + rc = opal_slw_set_reg(pir, SPRN_HID4, reg_val); + if (rc) + return rc; + } + break; + case SPRN_HID5: + reg_val = mfspr(SPRN_HID5); + if (!cpu_has_feature(CPU_FTR_ARCH_300) && + cpu_thread_in_core(cpu) == 0) { + rc = opal_slw_set_reg(pir, SPRN_HID5, reg_val); + if (rc) + return rc; + } + break; + default: + return -EINVAL; + } + return 0; +} - /* Only p8 needs to set extra HID regiters */ - if (!cpu_has_feature(CPU_FTR_ARCH_300)) { - - rc = opal_slw_set_reg(pir, SPRN_HID1, hid1_val); - if (rc != 0) - return rc; - - rc = opal_slw_set_reg(pir, SPRN_HID4, hid4_val); - if (rc != 0) - return rc; +static int pnv_self_save_restore_sprs(void) +{ + int rc, index, cpu; + u64 pir; + struct preferred_sprs curr_spr; - rc = opal_slw_set_reg(pir, SPRN_HID5, hid5_val); + for_each_present_cpu(cpu) { + pir = get_hard_smp_processor_id(cpu); + for (index = 0; index < nr_preferred_sprs; index++) { + curr_spr = preferred_sprs[index]; + /* HIDs are per core register */ + if (cpu_thread_in_core(cpu) != 0 && + (curr_spr.spr == SPRN_HMEER || + curr_spr.spr == SPRN_HID0 || + curr_spr.spr == SPRN_HID1 || + curr_spr.spr == SPRN_HID4 || + curr_spr.spr == SPRN_HID5)) + continue; + if (curr_spr.supported_mode & FIRMWARE_RESTORE) { + rc = pnv_self_restore_sprs(pir, cpu, + curr_spr.spr); if (rc != 0) return rc; } } } + return 0; +} +static int pnv_save_sprs_for_deep_states(void) +{ + int rc; + + rc = pnv_self_save_restore_sprs(); + if (rc != 0) + return rc; return 0; } -- 2.17.1