Message ID | 20221219064042.661122-2-perry.yuan@amd.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2229554wrn; Sun, 18 Dec 2022 22:43:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf5H4Z3jmMqqljouNbzSOkW8ZetDiJ6InKqv7b5i3lkx5xZ1JdQwb870xe2BwXLeV5UeYcjJ X-Received: by 2002:a05:6a20:9f43:b0:a9:d06b:ef2 with SMTP id ml3-20020a056a209f4300b000a9d06b0ef2mr48537853pzb.36.1671432180677; Sun, 18 Dec 2022 22:43:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1671432180; cv=pass; d=google.com; s=arc-20160816; b=zdES3ijd3QNWmBB39gvlICtuhvPgqYHP2/vpGEVoqmmD5yMSlgNIO9jpts2Cl915aw eiCIR5yEoXHF6rohVSLX1lD/nCEkhBo+a566+c5r6H2N3cnuywI4FvTP4AzF7YF0iIII 4JWvw7Uz3UwK/EV6iVDTCVUCTmDNtMmDh6zIkefaqGzQPA5twNMCiH9uWt55uBb/T6uX 6GXFu+pIf9RjICou9ELWCa8nESvpmZEfjFiSL/zf81o3UfqNHP4vVf1oBkpNej+6c8Hm 0ENJOqaVlXvz9XkmzQ7rPsCcSLm3FbQ9xD2ehZ3jsc8DzCZCuM+2vQOV5SzENCAonUw8 hnFA== 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=RHxYqXJb+W2o+kIAEdJmKnJ1xkkYq9WRhSeSFWP3Ot4=; b=KfvSWM4qxbbvBRjwuLMLNYhMhcwjMSW+JasQI7kYBGwZ6hJmgggCUPTSKb0hh6bMbE utn+lS1EIJguyuFZMCQLoNbvsxCfU2QJuSFx1svPcwBBgfj7nLtDziIbLYgQISsfRefw vfoUrcIJ0v/+qyr1KXcqofuHYRkX90cuOPBJ19C9UE9q7dn9NJndAGqQ5/0l8625JlIh iAMhsfGThO3T2VDxcSUUIdqUuChEQk3Yz7h0+heJDCRit0ZgFjTJcxz2hCURgT2FjE9A 4pePE3xMaXHn8uSdPGrqT+ENU55rbRwkVJpREExC/CJzs5h4x1adCCUCpdhYK7MwjVJD kyng== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=gQTxVYBs; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h67-20020a636c46000000b00477a32da0a9si10725260pgc.455.2022.12.18.22.42.47; Sun, 18 Dec 2022 22:43:00 -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=gQTxVYBs; 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 S231147AbiLSGlV (ORCPT <rfc822;peekingduck44@gmail.com> + 99 others); Mon, 19 Dec 2022 01:41:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbiLSGlM (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 19 Dec 2022 01:41:12 -0500 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2062.outbound.protection.outlook.com [40.107.96.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1049F2674; Sun, 18 Dec 2022 22:41:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=crcS5XTVbL1tb3USTq8pNqaLfsKYN73Dc5gdlb4l6fBVnNemdH7u5uGrS2ZR/qDgWvZvMAWg7lQapCSQThzxVRnoonfRxJo2sIrK6EdRtYF4u0VzLp6AzKRwaRHYheywJ2Mh6ISANvTNM5cCYDxysyX1SzmPOxg0+/dgDKXiht6sJ9BCK+4CE3u5tb4zGDYiZuouhkj99aq6g5SlH+V9WysORG43KMnjsDdSa6gmaQ6fmT/SbbAWzApyrfm9HszpyQhebqnAtgqTK0h564Lrd3wxA4iQ4lVnaLtQiVa+vFYCZhIyzrra9LhHljfitlhZOsBEpOOAqJrEfkBvqM/InQ== 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=RHxYqXJb+W2o+kIAEdJmKnJ1xkkYq9WRhSeSFWP3Ot4=; b=eF+tvlw67k/fmuDOec1ZZ+f1UWZvz/iPr4U3KdLequ0Q/+OiS+7fqh6bC5XroMfKfo+vPgJyKKS+GphSVQtSO3EcOh/B49FPPPXJxiYGN4WzSpOaHhdHoK2vxhat55+/pIaueH67HYn5ykuvk8/wraieQTT+krro69JSiYGHRumBu6OqYefh0Mnlhk0RTNV1RT7uQkiwT6B3IInNooiTNzUpK2+40Bpz/1+uEifLrUMuCUmTKRdxRC2ze2W8dLAWnrB/X81hR465cNL9WNW0idKvPRAh5JNoxj0vDUdEbjM0iKsymH7+WGbm22w+IZB5Z6U+InRH1yRusmjW8DxWiw== 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=RHxYqXJb+W2o+kIAEdJmKnJ1xkkYq9WRhSeSFWP3Ot4=; b=gQTxVYBs89Yoo5UIaPPLgVRTl7VmOC2sw4AzHDJqLkbARrTiAO0zD764xlC1m8fMWDjsQdw6lE7XJEp/9okQBSikp8UL9pylIl/dbfXjJ2S/E+89hHXVr9vpNoozPnQhKC5e06ODI2kRovaexA23Bfl1AAZHds6viOUKT3AZmg4= Received: from DS7PR03CA0320.namprd03.prod.outlook.com (2603:10b6:8:2b::15) by BY5PR12MB4034.namprd12.prod.outlook.com (2603:10b6:a03:205::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Mon, 19 Dec 2022 06:41:08 +0000 Received: from DM6NAM11FT101.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2b:cafe::26) by DS7PR03CA0320.outlook.office365.com (2603:10b6:8:2b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.20 via Frontend Transport; Mon, 19 Dec 2022 06:41:07 +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 DM6NAM11FT101.mail.protection.outlook.com (10.13.172.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5924.16 via Frontend Transport; Mon, 19 Dec 2022 06:41:07 +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; Mon, 19 Dec 2022 00:41:03 -0600 From: Perry Yuan <perry.yuan@amd.com> To: <rafael.j.wysocki@intel.com>, <Mario.Limonciello@amd.com>, <ray.huang@amd.com>, <viresh.kumar@linaro.org> CC: <Deepak.Sharma@amd.com>, <Nathan.Fontenot@amd.com>, <Alexander.Deucher@amd.com>, <Shimmer.Huang@amd.com>, <Xiaojian.Du@amd.com>, <Li.Meng@amd.com>, <wyes.karny@amd.com>, <linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org> Subject: [PATCH v8 01/13] ACPI: CPPC: Add AMD pstate energy performance preference cppc control Date: Mon, 19 Dec 2022 14:40:30 +0800 Message-ID: <20221219064042.661122-2-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221219064042.661122-1-perry.yuan@amd.com> References: <20221219064042.661122-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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT101:EE_|BY5PR12MB4034:EE_ X-MS-Office365-Filtering-Correlation-Id: d56afac0-309f-4c98-ad5a-08dae18c0207 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DuHmAbSrkiG/y/PB/K8CVtqz9d8jDmxv0HrAA5TJw4i5GXi0F8GK8otACIw99ptbR/MnpVHmaXssIA5sBMeBywwSzi0txpP++CG0meZ5L4ccrH3YlTAobps/uFkQJpBsWsT7nIWzsZ+I8PgP6KQC8zSAzcbyxyhOS9pQFJ2jTATUM2GXgcdr0VaftuD5JSuxg84Ig/aXWUmAaF2yb5z1/0LAtyCyn6BDx7QVXoaoIk9w0OJTglwv9PzJthppqiHJ2kmgfEylV/gJAu00fFGFdRF513LDw5V4BtIJe1PCy5R5D6/A43GP16UN0aN7zKfSeGCYmAzNdWe1NfXhlYgL4/7KgYQap7gBCqmjKQYxUjViagpbTT9Fc4P5ggi38wF3XYuEfqZTJB2FTZbsjhdhD+F/Zl123PApkTZtmRVk3ZV14lgaec16Jq5tLQPjCSKl8c7zZcJ5lqNd7dEgKNB/Fc9XuHvY/YdhKHuVNfdDQ+7a3gNbfld2jupq9k8r8sY70qTkHbPvV9iOOCv63ab6Q6VkIHNn9brn1CUUlE2JRSxSvfrueQX3O5FXa58PBeqWH2swI6TdFRr2hchockCtHVGDMfS7kTPZNck/aTEzRi7VpqBnVdHEWtyMspoqJAZ+1eX0GhQQsxCWgrR16F4mXQzlSSQEDaLeedmdzyEUtlLxUY8bv5Hak5Xo4t0VqBPVAVuNx4cuLD8MFFJO9R0i1t2UvqjwOt50wILJYZGOXq8= 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)(396003)(136003)(346002)(376002)(39860400002)(451199015)(46966006)(40470700004)(36840700001)(86362001)(70586007)(40460700003)(70206006)(4326008)(8936002)(8676002)(5660300002)(36756003)(41300700001)(2616005)(1076003)(6666004)(7696005)(26005)(426003)(186003)(83380400001)(47076005)(336012)(36860700001)(40480700001)(356005)(110136005)(82740400003)(16526019)(82310400005)(54906003)(316002)(81166007)(478600001)(44832011)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Dec 2022 06:41:07.1293 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d56afac0-309f-4c98-ad5a-08dae18c0207 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: DM6NAM11FT101.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4034 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752623670204884333?= X-GMAIL-MSGID: =?utf-8?q?1752623670204884333?= |
Series |
Implement AMD Pstate EPP Driver
|
|
Commit Message
Yuan, Perry
Dec. 19, 2022, 6:40 a.m. UTC
From: Perry Yuan <Perry.Yuan@amd.com> 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 Downstream drivers that want to use the new symbols cppc_get_epp_caps and cppc_set_epp_perf for querying and setting EPP preferences will need to call cppc_set_epp_perf to enable the EPP function firstly. Signed-off-by: Perry Yuan <Perry.Yuan@amd.com> --- drivers/acpi/cppc_acpi.c | 76 +++++++++++++++++++++++++++++++++++++--- include/acpi/cppc_acpi.h | 12 +++++++ 2 files changed, 83 insertions(+), 5 deletions(-)
Comments
For this patch there's a few small nits you should fix for v9. With those fixed: Reviewed-by: Mario Limonciello <mario.limonciello@amd.com> On 12/19/2022 00:40, Perry Yuan wrote: > From: Perry Yuan <Perry.Yuan@amd.com> > > 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 Missing a period here at end of the sentence. > > Downstream drivers that want to use the new symbols cppc_get_epp_caps > and cppc_set_epp_perf for querying and setting EPP preferences will need > to call cppc_set_epp_perf to enable the EPP function firstly. > > Signed-off-by: Perry Yuan <Perry.Yuan@amd.com> > --- > drivers/acpi/cppc_acpi.c | 76 +++++++++++++++++++++++++++++++++++++--- > include/acpi/cppc_acpi.h | 12 +++++++ > 2 files changed, 83 insertions(+), 5 deletions(-) > > diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c > index 093675b1a1ff..81081eb899ea 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; > } > > /** > @@ -1153,6 +1152,19 @@ int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf) > return cppc_get_perf(cpunum, NOMINAL_PERF, nominal_perf); > } > > +/** > + * cppc_get_epp_perf - Get the epp register value. > + * @cpunum: CPU from which to get epp preference value. > + * @epp_perf: Return address. > + * > + * Return: 0 for success, -EIO otherwise. > + */ > +int cppc_get_epp_perf(int cpunum, u64 *epp_perf) > +{ > + return cppc_get_perf(cpunum, ENERGY_PERF, epp_perf); > +} > +EXPORT_SYMBOL_GPL(cppc_get_epp_perf); > + > /** > * cppc_get_perf_caps - Get a CPU's performance capabilities. > * @cpunum: CPU from which to get capabilities info. > @@ -1365,6 +1377,60 @@ int cppc_get_perf_ctrs(int cpunum, struct cppc_perf_fb_ctrs *perf_fb_ctrs) > } > EXPORT_SYMBOL_GPL(cppc_get_perf_ctrs); > > +/* > + * 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; AFAICT, you don't actually ever return -EINVAL in this function. I think you should just avoid initializing this variable. > + > + 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"); Would it perhaps be useful to note the cpu # for this message? > + 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..6b487a5bd638 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_perf(int cpunum, u64 *epp_perf); > +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_perf(int cpunum, u64 *epp_perf) > +{ > + return -ENOTSUPP; > +} > #endif /* !CONFIG_ACPI_CPPC_LIB */ > > #endif /* _CPPC_ACPI_H*/
On Mon, Dec 19, 2022 at 02:40:30PM +0800, Yuan, Perry wrote: > From: Perry Yuan <Perry.Yuan@amd.com> > > 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 > > Downstream drivers that want to use the new symbols cppc_get_epp_caps > and cppc_set_epp_perf for querying and setting EPP preferences will need > to call cppc_set_epp_perf to enable the EPP function firstly. > > Signed-off-by: Perry Yuan <Perry.Yuan@amd.com> > --- > drivers/acpi/cppc_acpi.c | 76 +++++++++++++++++++++++++++++++++++++--- > include/acpi/cppc_acpi.h | 12 +++++++ > 2 files changed, 83 insertions(+), 5 deletions(-) > > diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c > index 093675b1a1ff..81081eb899ea 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; > - Do you have any specific reason to move this piece out of if-condition? > 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; > } > > /** > @@ -1153,6 +1152,19 @@ int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf) > return cppc_get_perf(cpunum, NOMINAL_PERF, nominal_perf); > } > > +/** > + * cppc_get_epp_perf - Get the epp register value. > + * @cpunum: CPU from which to get epp preference value. > + * @epp_perf: Return address. > + * > + * Return: 0 for success, -EIO otherwise. > + */ > +int cppc_get_epp_perf(int cpunum, u64 *epp_perf) > +{ > + return cppc_get_perf(cpunum, ENERGY_PERF, epp_perf); > +} > +EXPORT_SYMBOL_GPL(cppc_get_epp_perf); > + This function is enough to get the epp value. Thanks, Ray > /** > * cppc_get_perf_caps - Get a CPU's performance capabilities. > * @cpunum: CPU from which to get capabilities info. > @@ -1365,6 +1377,60 @@ int cppc_get_perf_ctrs(int cpunum, struct cppc_perf_fb_ctrs *perf_fb_ctrs) > } > EXPORT_SYMBOL_GPL(cppc_get_perf_ctrs); > > +/* > + * 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..6b487a5bd638 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_perf(int cpunum, u64 *epp_perf); > +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_perf(int cpunum, u64 *epp_perf) > +{ > + return -ENOTSUPP; > +} > #endif /* !CONFIG_ACPI_CPPC_LIB */ > > #endif /* _CPPC_ACPI_H*/ > -- > 2.34.1 >
[AMD Official Use Only - General] > -----Original Message----- > From: Huang, Ray <Ray.Huang@amd.com> > Sent: Friday, December 23, 2022 10:16 AM > To: Yuan, Perry <Perry.Yuan@amd.com> > Cc: rafael.j.wysocki@intel.com; Limonciello, Mario > <Mario.Limonciello@amd.com>; viresh.kumar@linaro.org; Sharma, Deepak > <Deepak.Sharma@amd.com>; Fontenot, Nathan > <Nathan.Fontenot@amd.com>; Deucher, Alexander > <Alexander.Deucher@amd.com>; Huang, Shimmer > <Shimmer.Huang@amd.com>; Du, Xiaojian <Xiaojian.Du@amd.com>; Meng, > Li (Jassmine) <Li.Meng@amd.com>; Karny, Wyes <Wyes.Karny@amd.com>; > linux-pm@vger.kernel.org; linux-kernel@vger.kernel.org > Subject: Re: [PATCH v8 01/13] ACPI: CPPC: Add AMD pstate energy > performance preference cppc control > > On Mon, Dec 19, 2022 at 02:40:30PM +0800, Yuan, Perry wrote: > > From: Perry Yuan <Perry.Yuan@amd.com> > > > > 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 > > > > Downstream drivers that want to use the new symbols cppc_get_epp_caps > > and cppc_set_epp_perf for querying and setting EPP preferences will > > need to call cppc_set_epp_perf to enable the EPP function firstly. > > > > Signed-off-by: Perry Yuan <Perry.Yuan@amd.com> > > --- > > drivers/acpi/cppc_acpi.c | 76 > > +++++++++++++++++++++++++++++++++++++--- > > include/acpi/cppc_acpi.h | 12 +++++++ > > 2 files changed, 83 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index > > 093675b1a1ff..81081eb899ea 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; > > - > > Do you have any specific reason to move this piece out of if-condition? Move the declaration ahead of the If conditions like other functions did. It looks more reasonable and no functions impact. Perry. > > > 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; > > } > > > > /** > > @@ -1153,6 +1152,19 @@ int cppc_get_nominal_perf(int cpunum, u64 > *nominal_perf) > > return cppc_get_perf(cpunum, NOMINAL_PERF, nominal_perf); } > > > > +/** > > + * cppc_get_epp_perf - Get the epp register value. > > + * @cpunum: CPU from which to get epp preference value. > > + * @epp_perf: Return address. > > + * > > + * Return: 0 for success, -EIO otherwise. > > + */ > > +int cppc_get_epp_perf(int cpunum, u64 *epp_perf) { > > + return cppc_get_perf(cpunum, ENERGY_PERF, epp_perf); } > > +EXPORT_SYMBOL_GPL(cppc_get_epp_perf); > > + > > This function is enough to get the epp value. > > Thanks, > Ray > > > /** > > * cppc_get_perf_caps - Get a CPU's performance capabilities. > > * @cpunum: CPU from which to get capabilities info. > > @@ -1365,6 +1377,60 @@ int cppc_get_perf_ctrs(int cpunum, struct > > cppc_perf_fb_ctrs *perf_fb_ctrs) } > > EXPORT_SYMBOL_GPL(cppc_get_perf_ctrs); > > > > +/* > > + * 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..6b487a5bd638 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_perf(int cpunum, u64 *epp_perf); 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_perf(int cpunum, u64 *epp_perf) { > > + return -ENOTSUPP; > > +} > > #endif /* !CONFIG_ACPI_CPPC_LIB */ > > > > #endif /* _CPPC_ACPI_H*/ > > -- > > 2.34.1 > >
On Fri, Dec 23, 2022 at 11:19:57AM +0800, Yuan, Perry wrote: > [AMD Official Use Only - General] > > > > > -----Original Message----- > > From: Huang, Ray <Ray.Huang@amd.com> > > Sent: Friday, December 23, 2022 10:16 AM > > To: Yuan, Perry <Perry.Yuan@amd.com> > > Cc: rafael.j.wysocki@intel.com; Limonciello, Mario > > <Mario.Limonciello@amd.com>; viresh.kumar@linaro.org; Sharma, Deepak > > <Deepak.Sharma@amd.com>; Fontenot, Nathan > > <Nathan.Fontenot@amd.com>; Deucher, Alexander > > <Alexander.Deucher@amd.com>; Huang, Shimmer > > <Shimmer.Huang@amd.com>; Du, Xiaojian <Xiaojian.Du@amd.com>; Meng, > > Li (Jassmine) <Li.Meng@amd.com>; Karny, Wyes <Wyes.Karny@amd.com>; > > linux-pm@vger.kernel.org; linux-kernel@vger.kernel.org > > Subject: Re: [PATCH v8 01/13] ACPI: CPPC: Add AMD pstate energy > > performance preference cppc control > > > > On Mon, Dec 19, 2022 at 02:40:30PM +0800, Yuan, Perry wrote: > > > From: Perry Yuan <Perry.Yuan@amd.com> > > > > > > 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 > > > > > > Downstream drivers that want to use the new symbols cppc_get_epp_caps > > > and cppc_set_epp_perf for querying and setting EPP preferences will > > > need to call cppc_set_epp_perf to enable the EPP function firstly. > > > > > > Signed-off-by: Perry Yuan <Perry.Yuan@amd.com> > > > --- > > > drivers/acpi/cppc_acpi.c | 76 > > > +++++++++++++++++++++++++++++++++++++--- > > > include/acpi/cppc_acpi.h | 12 +++++++ > > > 2 files changed, 83 insertions(+), 5 deletions(-) > > > > > > diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index > > > 093675b1a1ff..81081eb899ea 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; > > > - > > > > Do you have any specific reason to move this piece out of if-condition? > > Move the declaration ahead of the If conditions like other functions did. > It looks more reasonable and no functions impact. > If one platform doesn't have any CPC registers, it even won't need define these variables like pcc_ss_id, pcc_ss_data, and it will save more time. Thanks, Ray
[AMD Official Use Only - General] > -----Original Message----- > From: Huang, Ray <Ray.Huang@amd.com> > Sent: Friday, December 23, 2022 5:06 PM > To: Yuan, Perry <Perry.Yuan@amd.com> > Cc: rafael.j.wysocki@intel.com; Limonciello, Mario > <Mario.Limonciello@amd.com>; viresh.kumar@linaro.org; Sharma, Deepak > <Deepak.Sharma@amd.com>; Fontenot, Nathan > <Nathan.Fontenot@amd.com>; Deucher, Alexander > <Alexander.Deucher@amd.com>; Huang, Shimmer > <Shimmer.Huang@amd.com>; Du, Xiaojian <Xiaojian.Du@amd.com>; Meng, > Li (Jassmine) <Li.Meng@amd.com>; Karny, Wyes <Wyes.Karny@amd.com>; > linux-pm@vger.kernel.org; linux-kernel@vger.kernel.org > Subject: Re: [PATCH v8 01/13] ACPI: CPPC: Add AMD pstate energy > performance preference cppc control > > On Fri, Dec 23, 2022 at 11:19:57AM +0800, Yuan, Perry wrote: > > [AMD Official Use Only - General] > > > > > > > > > -----Original Message----- > > > From: Huang, Ray <Ray.Huang@amd.com> > > > Sent: Friday, December 23, 2022 10:16 AM > > > To: Yuan, Perry <Perry.Yuan@amd.com> > > > Cc: rafael.j.wysocki@intel.com; Limonciello, Mario > > > <Mario.Limonciello@amd.com>; viresh.kumar@linaro.org; Sharma, > Deepak > > > <Deepak.Sharma@amd.com>; Fontenot, Nathan > <Nathan.Fontenot@amd.com>; > > > Deucher, Alexander <Alexander.Deucher@amd.com>; Huang, Shimmer > > > <Shimmer.Huang@amd.com>; Du, Xiaojian <Xiaojian.Du@amd.com>; > Meng, > > > Li (Jassmine) <Li.Meng@amd.com>; Karny, Wyes > <Wyes.Karny@amd.com>; > > > linux-pm@vger.kernel.org; linux-kernel@vger.kernel.org > > > Subject: Re: [PATCH v8 01/13] ACPI: CPPC: Add AMD pstate energy > > > performance preference cppc control > > > > > > On Mon, Dec 19, 2022 at 02:40:30PM +0800, Yuan, Perry wrote: > > > > From: Perry Yuan <Perry.Yuan@amd.com> > > > > > > > > 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 > > > > > > > > Downstream drivers that want to use the new symbols > > > > cppc_get_epp_caps and cppc_set_epp_perf for querying and setting > > > > EPP preferences will need to call cppc_set_epp_perf to enable the EPP > function firstly. > > > > > > > > Signed-off-by: Perry Yuan <Perry.Yuan@amd.com> > > > > --- > > > > drivers/acpi/cppc_acpi.c | 76 > > > > +++++++++++++++++++++++++++++++++++++--- > > > > include/acpi/cppc_acpi.h | 12 +++++++ > > > > 2 files changed, 83 insertions(+), 5 deletions(-) > > > > > > > > diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c > > > > index 093675b1a1ff..81081eb899ea 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; > > > > - > > > > > > Do you have any specific reason to move this piece out of if-condition? > > > > Move the declaration ahead of the If conditions like other functions did. > > It looks more reasonable and no functions impact. > > > > If one platform doesn't have any CPC registers, it even won't need define > these variables like pcc_ss_id, pcc_ss_data, and it will save more time. > > Thanks, > Ray Make sense , get it fixed in V9
diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 093675b1a1ff..81081eb899ea 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; } /** @@ -1153,6 +1152,19 @@ int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf) return cppc_get_perf(cpunum, NOMINAL_PERF, nominal_perf); } +/** + * cppc_get_epp_perf - Get the epp register value. + * @cpunum: CPU from which to get epp preference value. + * @epp_perf: Return address. + * + * Return: 0 for success, -EIO otherwise. + */ +int cppc_get_epp_perf(int cpunum, u64 *epp_perf) +{ + return cppc_get_perf(cpunum, ENERGY_PERF, epp_perf); +} +EXPORT_SYMBOL_GPL(cppc_get_epp_perf); + /** * cppc_get_perf_caps - Get a CPU's performance capabilities. * @cpunum: CPU from which to get capabilities info. @@ -1365,6 +1377,60 @@ int cppc_get_perf_ctrs(int cpunum, struct cppc_perf_fb_ctrs *perf_fb_ctrs) } EXPORT_SYMBOL_GPL(cppc_get_perf_ctrs); +/* + * 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..6b487a5bd638 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_perf(int cpunum, u64 *epp_perf); +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_perf(int cpunum, u64 *epp_perf) +{ + return -ENOTSUPP; +} #endif /* !CONFIG_ACPI_CPPC_LIB */ #endif /* _CPPC_ACPI_H*/