From patchwork Thu Feb 16 08:17:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wyes Karny X-Patchwork-Id: 654735 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABFEDC636D7 for ; Thu, 16 Feb 2023 08:19:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229843AbjBPITf (ORCPT ); Thu, 16 Feb 2023 03:19:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229800AbjBPITe (ORCPT ); Thu, 16 Feb 2023 03:19:34 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2049.outbound.protection.outlook.com [40.107.93.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A7AF457E7; Thu, 16 Feb 2023 00:19:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iFOPd6wsaJGocgC/QaHy1ffrNE8Ze2UBJbmJOV6LAGM6uhrYwrAp2FebguXJYeXGd220CAKtdrgTSKv0fq/A8uPNccQSSkwdJggM35dUnBZ/n/6/EQj/pr5A6XlX5WLsLk0NqrdaNizdAPEFNVIGT22tjuXSspmBfz56L+jgOcrnNDtW/fQRbzQ6twy1ndkY63Yap0lEPSAHgIz3+AF3tpCBuf8/r+L1ogCCkNfbK2mdA56aNlTNFnNz1T75jnNoqaM2KNHsmEg93RPAJeH5k9uj9a78bdDNmuYLX6QAe0xeklx3xQNoFK8cHyJWC2PJuuSmjBkWW659jgXl3oODfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=s05DLwfqzGln07Ac5hEi1Vheaivud9Tu7PP/F7KN7uU=; b=M/p2V6ivaEHn93AjuAKhxH6uPhhOYYMqbXuyq+ZbUQeh3sap406o2dxrZk4LaTTDlVCeZO00D1J38GK6LF9p01TAd/VtOUUbe8AYXmSFhmk6DhTX5iUGSzafEPYPT7fTDLvv+EroutaPD344eQOp/HKnSNDtz4QDeYdKqZMvhq+UpSpnuaAfSldgJQ8cYeusu6SY3F4jy6AUUl0s/D9IgycD70YcCEVchXuArfio+y0hwjH2m3q/rcnIoGNbOah+VrMnvXmD1t6albBanrcehI4zjHdVzT1M71ubSF9y7udkxXZsFmnAfKR0/x2IeDISSSXKf0WDGCOjjTn8vblc2w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=s05DLwfqzGln07Ac5hEi1Vheaivud9Tu7PP/F7KN7uU=; b=bknSTmFNAktHybWqMjJKt5wa22AUenUyi9oEvAZAQeIgrdnsCWF1LXIjWQSBIvZuWyOo4jiIRRtE3O5PGHFH+0xeBLor9O4n2SG+y03mzf4TU01LHJi1V+0u5iXH5ck1rQTL3nuxNpZlsIV+/u0j5tVw8LSn8Tsr/je3KaWlhZg= Received: from BN9PR03CA0842.namprd03.prod.outlook.com (2603:10b6:408:13d::7) by DM8PR12MB5414.namprd12.prod.outlook.com (2603:10b6:8:3e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.26; Thu, 16 Feb 2023 08:19:18 +0000 Received: from BN8NAM11FT086.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13d:cafe::4f) by BN9PR03CA0842.outlook.office365.com (2603:10b6:408:13d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6111.13 via Frontend Transport; Thu, 16 Feb 2023 08:19:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT086.mail.protection.outlook.com (10.13.176.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6111.13 via Frontend Transport; Thu, 16 Feb 2023 08:19:18 +0000 Received: from beas.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 16 Feb 2023 02:19:12 -0600 From: Wyes Karny To: Rafael J Wysocki , Huang Rui , Jonathan Corbet , Viresh Kumar , , CC: , , , Bagas Sanjaya , , Len Brown , Robert Moore , Borislav Petkov , Ananth Narayan , , Tor Vic , Russell Haley , Wyes Karny , Mario Limonciello Subject: [PATCH v7 2/6] acpi: cppc: Add auto select register read/write support Date: Thu, 16 Feb 2023 08:17:58 +0000 Message-ID: <20230216081802.38007-3-wyes.karny@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216081802.38007-1-wyes.karny@amd.com> References: <20230216081802.38007-1-wyes.karny@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT086:EE_|DM8PR12MB5414:EE_ X-MS-Office365-Filtering-Correlation-Id: 0202fdcf-4169-406a-f85d-08db0ff67ffa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TyXKeCGjiriB+KCn3AYZOR6J6kaACqtw4Ihudgw6X1ygK6EakNewlhYJ6HOAo7g39T6wdWjvMvChb5ZslqIDdKXUEXtLH1sDNl/HnsySUCC1jRjXdFwCXAF5BojO2fvPdXwFoLrfg9jsHs5xTFn4yf/xM0dp2zz4i5uqZ/mSVOyKNyfB1Kvt7H2YTRN57GELPJLeZOG12B0CB1ZBcPpWdXN1jcCci9FOAXoe2CiXVQXOCyyAjHL3kzxtis+re7gB9XuX69DmmNeGx+qOOnT+Xw7aZh84VPdC7mDTRql+KygksH6KUEO/3LQrHX/6uZlajw3LINSQTJAy6oXyL1pPAgF8LA9jbr8T47RtbnGEhOOGiTGluiaMP1EaePgWnArvoMEgE1S0Q1MuTbLK8bSty4flEn8lnlP8YRPc9FDL17dq/fSLfiWrmkHz6s0t6whU9JKK1v8pFx/YquyqCc8kPXn3S2hEV1nxoqFM2WeFfn4dYbHArliI1tvcHdnhn/NXeofd1bLA+3KSPnk0zhOlukz/uQ7mkAjxMU5OX5Y5QR9fnpBRavTp6Doxcl8ByjXFfWMn7+E8o/et0c1/7sT4xQ5ppuPWVp2x/lJ01ijhmeVJF/Di+yokK7HDPmtNeEv1dRcXZKn+mOz9heam/bcbdwRqIjBjHxB+NDYOSx5ml6R/h4X3HEsKAwa4++5sC5GeZ8OmnmPZjGM4VuW4n1sqKpain60RAEmlbPMzb3usoFg= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230025)(4636009)(376002)(136003)(396003)(39860400002)(346002)(451199018)(46966006)(36840700001)(40470700004)(70586007)(54906003)(4326008)(70206006)(8676002)(110136005)(316002)(6636002)(40460700003)(86362001)(36756003)(356005)(478600001)(81166007)(2616005)(16526019)(186003)(26005)(83380400001)(82740400003)(336012)(426003)(47076005)(82310400005)(41300700001)(8936002)(7696005)(2906002)(6666004)(1076003)(44832011)(5660300002)(40480700001)(7416002)(36860700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Feb 2023 08:19:18.6113 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0202fdcf-4169-406a-f85d-08db0ff67ffa X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT086.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8PR12MB5414 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org For some AMD shared memory based systems, the autonomous selection bit needed to be set explicitly. Add autonomous selection register related APIs to acpi driver, which amd_pstate driver uses later. Acked-by: Huang Rui Reviewed-by: Mario Limonciello Signed-off-by: Wyes Karny --- drivers/acpi/cppc_acpi.c | 97 ++++++++++++++++++++++++++++++++++++++++ include/acpi/cppc_acpi.h | 11 +++++ 2 files changed, 108 insertions(+) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index ad19e4a91e4e..e2fbc3c92891 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -1433,6 +1433,103 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable) } EXPORT_SYMBOL_GPL(cppc_set_epp_perf); +/* + * cppc_get_auto_sel_caps - Read autonomous selection register. + * @cpunum : CPU from which to read register. + * @perf_caps : struct where autonomous selection register value is updated. + */ +int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps) +{ + struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpunum); + struct cpc_register_resource *auto_sel_reg; + u64 auto_sel; + + if (!cpc_desc) { + pr_debug("No CPC descriptor for CPU:%d\n", cpunum); + return -ENODEV; + } + + auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE]; + + if (!CPC_SUPPORTED(auto_sel_reg)) + pr_warn_once("Autonomous mode is not unsupported!\n"); + + if (CPC_IN_PCC(auto_sel_reg)) { + int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpunum); + struct cppc_pcc_data *pcc_ss_data = NULL; + int ret = 0; + + if (pcc_ss_id < 0) + return -ENODEV; + + pcc_ss_data = pcc_data[pcc_ss_id]; + + down_write(&pcc_ss_data->pcc_lock); + + if (send_pcc_cmd(pcc_ss_id, CMD_READ) >= 0) { + cpc_read(cpunum, auto_sel_reg, &auto_sel); + perf_caps->auto_sel = (bool)auto_sel; + } else { + ret = -EIO; + } + + up_write(&pcc_ss_data->pcc_lock); + + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(cppc_get_auto_sel_caps); + +/* + * cppc_set_auto_sel - Write autonomous selection register. + * @cpu : CPU to which to write register. + * @enable : the desired value of autonomous selection resiter to be updated. + */ +int cppc_set_auto_sel(int cpu, bool enable) +{ + int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu); + struct cpc_register_resource *auto_sel_reg; + struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpu); + struct cppc_pcc_data *pcc_ss_data = NULL; + int ret = -EINVAL; + + if (!cpc_desc) { + pr_debug("No CPC descriptor for CPU:%d\n", cpu); + return -ENODEV; + } + + auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE]; + + if (CPC_IN_PCC(auto_sel_reg)) { + if (pcc_ss_id < 0) { + pr_debug("Invalid pcc_ss_id\n"); + return -ENODEV; + } + + if (CPC_SUPPORTED(auto_sel_reg)) { + ret = cpc_write(cpu, auto_sel_reg, enable); + if (ret) + return ret; + } + + pcc_ss_data = pcc_data[pcc_ss_id]; + + down_write(&pcc_ss_data->pcc_lock); + /* after writing CPC, transfer the ownership of PCC to platform */ + ret = send_pcc_cmd(pcc_ss_id, CMD_WRITE); + up_write(&pcc_ss_data->pcc_lock); + } else { + ret = -ENOTSUPP; + pr_debug("_CPC in PCC is not supported\n"); + } + + return ret; +} +EXPORT_SYMBOL_GPL(cppc_set_auto_sel); + + /** * cppc_set_enable - Set to enable CPPC on the processor by writing the * Continuous Performance Control package EnableRegister field. diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index 6b487a5bd638..6126c977ece0 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -109,6 +109,7 @@ struct cppc_perf_caps { u32 lowest_freq; u32 nominal_freq; u32 energy_perf; + bool auto_sel; }; struct cppc_perf_ctrls { @@ -153,6 +154,8 @@ extern int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val); extern int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val); extern int cppc_get_epp_perf(int cpunum, u64 *epp_perf); extern int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable); +extern int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps); +extern int cppc_set_auto_sel(int cpu, bool enable); #else /* !CONFIG_ACPI_CPPC_LIB */ static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf) { @@ -214,6 +217,14 @@ static inline int cppc_get_epp_perf(int cpunum, u64 *epp_perf) { return -ENOTSUPP; } +static inline int cppc_set_auto_sel(int cpu, bool enable) +{ + return -ENOTSUPP; +} +static inline int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps) +{ + return -ENOTSUPP; +} #endif /* !CONFIG_ACPI_CPPC_LIB */ #endif /* _CPPC_ACPI_H*/