Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1762943rwb; Fri, 2 Dec 2022 00:20:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf7S/hoBH2kmnq+K46rbnoUJv2kkhK04vLJ+QcTu185ahl54vf5hgYVy4f3UEoSoz7KcDF8i X-Received: by 2002:a17:906:a084:b0:7bd:f57f:76a4 with SMTP id q4-20020a170906a08400b007bdf57f76a4mr24009855ejy.413.1669969204184; Fri, 02 Dec 2022 00:20:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669969204; cv=pass; d=google.com; s=arc-20160816; b=uVqzWaBqpOmt8YwVZ5O2Ieegz7SAxML8f2KzjeQxvl7CpMsja71GJU9VMjib20ZxLA x8lVe3qsYYan1d8SD3D2852cbBaYhd8CgZQIY0DeyIiFaDx3wN8cGg17DujP7+Rcsdwv WOycygwJZn52MRrgdLNiun0CBfiEmiPLZ1QVq4b6/h1kaXyjHCTVAWsLMEFBfk7cWzYm yWnhLZB07mrYWPYwwIaNAYw1gHXUVrZFSagZqWeCGWmnsaxaErOLMGPzkU/F49wP02M8 pHVNRdZ9VUpJJHsUOjoFuqAyID3zysyRUbsiCyvk9LK4LUXXMb6gW1hr9066VtPSt0/h qpWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BvIyw8HFbFtq2U25prPTcw1zbk3kblDPX9Aa4Dr99F4=; b=0bLUCER8a0QvCqNgNR/wSJ+n6XwOhG13cMper1cKgVd7/mAmgd8RcyPa+mzGMAtriI C9a/BscfrXA2dQrusgrMfFum0K0G5ZpDd0JoUBkZW1+gRxc1rmOGsw60TDKDu9UOJhvt NKAMnlcRCyQdpF5fbbkwuSChAqJtU+YrPU3nrk1V03uodq4J3i/wmQNuc8fadI1jXJKm EaInOYrGkf7lKhRlhj5LE8js+vSnDZqkLmVxXKxmfkPUI6z5ZbbrOV69dJHTyuEYub6o ip0x8AL8fMt+cNCAzm7T0YNdAIq+eU7EMGD+WSg2CWloBjuHLygnaIbO04EeEZ5VV/aE xQHQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=H66Eflrw; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f18-20020a0564021e9200b0046b5f810167si6367507edf.279.2022.12.02.00.19.44; Fri, 02 Dec 2022 00:20:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=H66Eflrw; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232447AbiLBHue (ORCPT + 82 others); Fri, 2 Dec 2022 02:50:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231449AbiLBHuc (ORCPT ); Fri, 2 Dec 2022 02:50:32 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2056.outbound.protection.outlook.com [40.107.93.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1282337211; Thu, 1 Dec 2022 23:50:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jazRloqIT1AC2PoLIMiKK2a79oBW4omRgMUZlDLc3VnDMSc3EBrcUwXuoriI2Y3Keugbj8XSk2Tijary90Kq4ugiMdlGWl9N8g3oqZiX5eNaQaJ2f1Po8CPIUr+NO90Zj5T7N+3qscdUvauymMsHIdzD6gSuWZkRTy+BWSQd7gWUPwatP1c/AkbGnbYlRUdwuMbfLvKnOSo3i877KJLPCxLjOGwVKfqsYvdFJvH2y+2kry09TnLS9RbK1I+P74lZ+u2vaXHl5OYE+BorPZHuxyjsSsozR5KSh26TZxH6I01gwErsGAfOCEYkCT6ElqZ7cwy/4KvUoZ0bP2uRUUacSw== 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=BvIyw8HFbFtq2U25prPTcw1zbk3kblDPX9Aa4Dr99F4=; b=C51aXAlpygYy3uvr4LaVmGuoKa60rswwnaW7BCgFSftTb7iJpPGlr8XdIWeAdx1uLbo0AHYrgRKRia20NLpJ4wtEXyNBEfm+G3U+wDbgNhyS6zdZM2pc2h+wt2xpnsJOQ6VKVVlaoTVH/+wa3Zahs6VXnJd6ATMwEx3aANheTxPh6Ce9B6QZNkbIxCWI0eSj77cHiLRUtZhknQ9DffTkKW4M8xNp64Winlb7JyMFwHunGbGjrT3ljt25CLbd0MO8BeQd7jb1L6i5tlowR8IO1en/6Je/2O3e42XNEyXPAnuseeJEj/UtOiwgn7JmWVpFY/8sQQpGuBoaodNjxvkwzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com 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=BvIyw8HFbFtq2U25prPTcw1zbk3kblDPX9Aa4Dr99F4=; b=H66EflrwVZ2b5IzUntdj6UOqO15exS9a8GhWIia8aYUwxwMs9Ak5T9Dvub9XOa8JaoBlxpkf1T9eLZWNI6craMMyNooU160qq/zYcomS187d/LfTvbRZQPFnDeESL2nuCHqjYn9EvGqTxHWNj2sNGGobkOz9knCIZ2NgXF7fRk0= Received: from DM6PR07CA0119.namprd07.prod.outlook.com (2603:10b6:5:330::11) by CY5PR12MB6249.namprd12.prod.outlook.com (2603:10b6:930:23::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.23; Fri, 2 Dec 2022 07:50:29 +0000 Received: from DM6NAM11FT025.eop-nam11.prod.protection.outlook.com (2603:10b6:5:330:cafe::e) by DM6PR07CA0119.outlook.office365.com (2603:10b6:5:330::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.10 via Frontend Transport; Fri, 2 Dec 2022 07:50:28 +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 DM6NAM11FT025.mail.protection.outlook.com (10.13.172.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.10 via Frontend Transport; Fri, 2 Dec 2022 07:50:28 +0000 Received: from pyuan-Cloudripper.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; Fri, 2 Dec 2022 01:50:24 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v6 01/11] ACPI: CPPC: Add AMD pstate energy performance preference cppc control Date: Fri, 2 Dec 2022 15:47:09 +0800 Message-ID: <20221202074719.623673-2-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221202074719.623673-1-perry.yuan@amd.com> References: <20221202074719.623673-1-perry.yuan@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: DM6NAM11FT025:EE_|CY5PR12MB6249:EE_ X-MS-Office365-Filtering-Correlation-Id: cbcde4cd-d8c4-4a5c-89b3-08dad439e191 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sr4Ehlko3rcc1iJmaaEgublliActrU9pJXDkaqFj7GEfKGIidGma5RnhSlr1HEaa8k0Ld1BFEPW3h8cvPbtZe1krAIuoqnfNKjEKjDSisdOxGQARsA9mcnGiass7joZYfC2GNp8IVPFaoFru4cb1D1WI2ILhnHtXMXKwStFjLBbeTRu/G1EJjjEVcdRlvHau4prg9x4fVg+Z6vSSPgrAZ40fGxAxXyMX4OwGT8WFvjKp7e0TIjroRRAK8nIAbuPBxQMRzLO33avHH8yAaouVpveQP57M+INP5eds1iTXX/3WD3CtcdK5xA9xsqNgoyNLhXY1N3uJ6UnIrlx0mXKpGNplgJz9WgaKvPm5oFNDXhqRqL7UzmC1LKL9YCbSrWRGw1tRUt9uHSTeTsxBS0A69U/flCjn7yN+VQ39ai3yP5sKixFYkvCz6v21+HwY5jn5skC6dywrzX6W/H+tMtx7/7DqZdlNTj59Sq43c6UiZQ+kZHdFrktwNSivyHGLxxIyaVnC8ynNO7XGsj7rjVpLsowyz/AxglY4yh+RnVP6fH4PBah8nhPkGffvv0bdRmW9OjK7VJRHslR0E/Z/A0eTl7AI7k/FExju+PBR485Z3Gyp17MyvUjW4CjBnKAZlKnaFsiDHr5lSKaA7Vobv39wgSLxE6Ke9WLj0M3Wus9dcblC91W1pvYSXLUV47YiadgmhaYo6luPOF7v+Fr2oUQflJxdjnd0yWXkh67M5NMhNJw= 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:(13230022)(4636009)(136003)(39860400002)(376002)(346002)(396003)(451199015)(36840700001)(46966006)(40470700004)(8936002)(2906002)(44832011)(81166007)(36860700001)(40480700001)(40460700003)(86362001)(41300700001)(36756003)(186003)(426003)(82310400005)(54906003)(478600001)(336012)(356005)(82740400003)(16526019)(70206006)(1076003)(26005)(5660300002)(83380400001)(2616005)(316002)(8676002)(6666004)(47076005)(4326008)(7696005)(70586007)(110136005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 07:50:28.8201 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cbcde4cd-d8c4-4a5c-89b3-08dad439e191 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: DM6NAM11FT025.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6249 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Perry Yuan Add support for setting and querying EPP preferences to the generic CPPC driver. This enables downstream drivers such as amd-pstate to discover and use these values In order to get EPP worked, cppc_get_epp_caps() will query EPP preference value and cppc_set_epp_perf() will set EPP new value. Before the EPP works, pstate driver will use cppc_set_auto_epp() to enable EPP function from firmware firstly. Signed-off-by: Perry Yuan --- drivers/acpi/cppc_acpi.c | 114 +++++++++++++++++++++++++++++++++++++-- include/acpi/cppc_acpi.h | 12 +++++ 2 files changed, 121 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 093675b1a1ff..37fa75f25f62 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -1093,6 +1093,9 @@ static int cppc_get_perf(int cpunum, enum cppc_regs reg_idx, u64 *perf) { struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpunum); struct cpc_register_resource *reg; + int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpunum); + struct cppc_pcc_data *pcc_ss_data = NULL; + int ret = -EINVAL; if (!cpc_desc) { pr_debug("No CPC descriptor for CPU:%d\n", cpunum); @@ -1102,10 +1105,6 @@ static int cppc_get_perf(int cpunum, enum cppc_regs reg_idx, u64 *perf) reg = &cpc_desc->cpc_regs[reg_idx]; if (CPC_IN_PCC(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 -EIO; @@ -1125,7 +1124,7 @@ static int cppc_get_perf(int cpunum, enum cppc_regs reg_idx, u64 *perf) cpc_read(cpunum, reg, perf); - return 0; + return ret; } /** @@ -1365,6 +1364,111 @@ int cppc_get_perf_ctrs(int cpunum, struct cppc_perf_fb_ctrs *perf_fb_ctrs) } EXPORT_SYMBOL_GPL(cppc_get_perf_ctrs); +/** + * cppc_get_epp_caps - Get the energy preference register value. + * @cpunum: CPU from which to get epp preference level. + * @perf_caps: Return address. + * + * Return: 0 for success, -EIO otherwise. + */ +int cppc_get_epp_caps(int cpunum, struct cppc_perf_caps *perf_caps) +{ + struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpunum); + struct cpc_register_resource *energy_perf_reg; + u64 energy_perf; + + if (!cpc_desc) { + pr_debug("No CPC descriptor for CPU:%d\n", cpunum); + return -ENODEV; + } + + energy_perf_reg = &cpc_desc->cpc_regs[ENERGY_PERF]; + + if (!CPC_SUPPORTED(energy_perf_reg)) + pr_warn_once("energy perf reg update is unsupported!\n"); + + if (CPC_IN_PCC(energy_perf_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, energy_perf_reg, &energy_perf); + perf_caps->energy_perf = energy_perf; + } else { + ret = -EIO; + } + + up_write(&pcc_ss_data->pcc_lock); + + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(cppc_get_epp_caps); + +/* + * Set Energy Performance Preference Register value through + * Performance Controls Interface + */ +int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable) +{ + int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu); + struct cpc_register_resource *epp_set_reg; + 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]; + epp_set_reg = &cpc_desc->cpc_regs[ENERGY_PERF]; + + if (CPC_IN_PCC(epp_set_reg) || 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; + } + + if (CPC_SUPPORTED(epp_set_reg)) { + ret = cpc_write(cpu, epp_set_reg, perf_ctrls->energy_perf); + 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_epp_perf); + /** * 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 c5614444031f..a45bb876a19c 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -108,12 +108,14 @@ struct cppc_perf_caps { u32 lowest_nonlinear_perf; u32 lowest_freq; u32 nominal_freq; + u32 energy_perf; }; struct cppc_perf_ctrls { u32 max_perf; u32 min_perf; u32 desired_perf; + u32 energy_perf; }; struct cppc_perf_fb_ctrs { @@ -149,6 +151,8 @@ extern bool cpc_ffh_supported(void); extern bool cpc_supported_by_cpu(void); 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_caps(int cpunum, struct cppc_perf_caps *perf_caps); +extern int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable); #else /* !CONFIG_ACPI_CPPC_LIB */ static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf) { @@ -202,6 +206,14 @@ static inline int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val) { return -ENOTSUPP; } +static inline int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable) +{ + return -ENOTSUPP; +} +static inline int cppc_get_epp_caps(int cpunum, struct cppc_perf_caps *perf_caps) +{ + return -ENOTSUPP; +} #endif /* !CONFIG_ACPI_CPPC_LIB */ #endif /* _CPPC_ACPI_H*/ -- 2.34.1