From nobody Mon Mar 10 03:02:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1741250504; cv=pass; d=zohomail.com; s=zohoarc; b=iZpmDeZ4m4ZEYZdzQc1MWpGsyLsjwzSnCF3jUQhhNCbFQFkOeoVfCblXKGdL/5rhFul4e+7QEiC10KB0P4LrlA76RV9Y2teA+oehJt4Y4xWqou8avWqxdWsLysJQGSSqCQT6VMPNC8aPDdOd4mbtIx3bnvq6Iq7pB6gbA2aso1g= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741250504; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=piO4+883ZfVtGHcOIOHWtqXT2pybhGRl+F06YWzchwE=; b=h6xKOywgfGpafnd7njGQLYEixQuSnlbrBBlG2bw0TI4L9Cn8aSt4aFoubLMqm9yKSCxfLMHBaDgBEFscH7Wt8LnJSeti+6wbnlOWBVDYbITXB1HxS7lKFJd4Bo8jFyFasc6068BiaGdIJ0NmoDM9bGrOyt53/SLyMqbbggDpQg8= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1741250504782880.6834326050413; Thu, 6 Mar 2025 00:41:44 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.903116.1311105 (Exim 4.92) (envelope-from ) id 1tq6mb-00053L-7n; Thu, 06 Mar 2025 08:40:45 +0000 Received: by outflank-mailman (output) from mailman id 903116.1311105; Thu, 06 Mar 2025 08:40:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tq6mb-000535-3I; Thu, 06 Mar 2025 08:40:45 +0000 Received: by outflank-mailman (input) for mailman id 903116; Thu, 06 Mar 2025 08:40:43 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tq6mY-00031D-RM for xen-devel@lists.xenproject.org; Thu, 06 Mar 2025 08:40:42 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20602.outbound.protection.outlook.com [2a01:111:f403:2414::602]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ad7fa42e-fa66-11ef-9898-31a8f345e629; Thu, 06 Mar 2025 09:40:38 +0100 (CET) Received: from CH5P223CA0023.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:1f3::28) by MW4PR12MB7141.namprd12.prod.outlook.com (2603:10b6:303:213::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8511.16; Thu, 6 Mar 2025 08:40:31 +0000 Received: from CH1PEPF0000AD75.namprd04.prod.outlook.com (2603:10b6:610:1f3:cafe::d7) by CH5P223CA0023.outlook.office365.com (2603:10b6:610:1f3::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8511.16 via Frontend Transport; Thu, 6 Mar 2025 08:40:31 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH1PEPF0000AD75.mail.protection.outlook.com (10.167.244.54) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Thu, 6 Mar 2025 08:40:30 +0000 Received: from penny-System-Product-Name.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.2507.39; Thu, 6 Mar 2025 02:40:27 -0600 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ad7fa42e-fa66-11ef-9898-31a8f345e629 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TGLpXoeLfb5Opiao3AgN3Qs7BsENo3HQ0OOB20z3CprmUsrNvBGgbICtSZuAMdb4jBOVJA/BvbFBJroXSI3NZpWhEq2jZQsw4fMuAH/8O71DoHISb1zaZSC5TSFohvVFBaSbcucLe4GLgmpTMFFR8XjS1uQpMApp44Vfbh4jyCwuuqPeb4wE8DrvuAk5Dac0jnCjr8MgI+DU+Sj3tWpbSAAdFqVBM6JTfu9vDQx4ND42vQ4e2gLrKP9ayQaCQ6r3e+5nbc9uWmblPQUkgYfrK6Fl/xol/mbWyN5iwt07JGja9n4y4hpbR0Ys43BOG6DnnFtLVjQOPobIAL873UNm7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=piO4+883ZfVtGHcOIOHWtqXT2pybhGRl+F06YWzchwE=; b=OlVX/hu5OqLD56rE2NMh/iY8mGJ6KmZN7wsfhm99o5cgit7rb1ACVNFJwP6J3Ns08xxW874ZXaMwB/Kmw6bikjvE2jUH9dKlXdDSLPkMARBnnq33b1t0VYMcMbLndpzDfZIVm/hb7DD6hrA5ZhSX0b6ixA0V6raViY4DbLwkcQghuh5myJaLNa0CylTunp9uNdsb1JPeczD23DnSTiI5N+DyGfuN91TJfvsh9Mbe/T2cfbd28yLENJp+PMcrnjtslg4nLmbdF0A/dgcHLFl74j8knT9CtZ/JQuEs2y3xeR8tPkaDwUK7+diaASX6UZGHwDjWtEoM5ONPTEY06TJdnw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.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 (0) 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=piO4+883ZfVtGHcOIOHWtqXT2pybhGRl+F06YWzchwE=; b=KJU0ibhEXNSUm9rGFOPRfdsQwxFSoJ1nXXYlcSY/xqavyk7oDaaI7Ln+8bX2PnBgiAljzrkZ5+K5cw9ubK9LQgPraP0Dp/YA7XZyTimuetD7nxJkGg5q2x7HJWyYTolKe+Qw50kj6QvBguDMuUoNValRXEBvt8PcqbqF1lKOtCo= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 From: Penny Zheng To: CC: , Penny Zheng , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , "Julien Grall" , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v3 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline Date: Thu, 6 Mar 2025 16:39:39 +0800 Message-ID: <20250306083949.1503385-6-Penny.Zheng@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250306083949.1503385-1-Penny.Zheng@amd.com> References: <20250306083949.1503385-1-Penny.Zheng@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: CH1PEPF0000AD75:EE_|MW4PR12MB7141:EE_ X-MS-Office365-Filtering-Correlation-Id: 8b709cee-11e9-4740-aa51-08dd5c8a8db3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?uN2uaU9k5A8Cao0oGN9kz/aW+PTD8q+TN5mTUg2chxzP3mQksqq/gN2WJlYz?= =?us-ascii?Q?RrhjhBnQfJOxkufK6oNV4xDdZ7M+XZ25GFil3ugr/Y0E/kXwFbQotCn4V/rd?= =?us-ascii?Q?ZAWXsZu4B7smCaZBsAdmqZp+yASLbmUJlllS9wfQVffn229/t4IGr94jfpFZ?= =?us-ascii?Q?6Ua+lEjNShq64s+NcskD9u0Id0phMMcKVrz+WlDmZ/HYE2Rn59q7gRQNXDks?= =?us-ascii?Q?m995x+P9VkAT4bf01gxHycr273KF0pYgnYiZttO+rXt3bhmOavqTQZxCZMI5?= =?us-ascii?Q?Mty3VlUuMA+JddUWsNXCpaNxIJ+d7JtGf/aRaLFXm1uP8Wxn4NNjjC5aYtqA?= =?us-ascii?Q?xfvViMi7IW/LQKv+wr3ASIrS5rK6EDMlGzDwL6Rtc597ya+YvoQkfLqGNqum?= =?us-ascii?Q?Gq+uO1CthWG8+p9/XOxOoTJ82yPjZG4OpB/8X+yWZcdZggTHjQDSFbAGyDbo?= =?us-ascii?Q?+oViMZ/xiTVY/y6sSpEf4CqHqqWa7xYquFaMGoCEYsAxJD4jNnWiQQvHYah+?= =?us-ascii?Q?YAEv/b7tWTdHEe6nbSixdTqF+HKUieJGkrcH49maBt6+ITy1zjnYwZYBkgWU?= =?us-ascii?Q?y/4S0VNTJq9UTW2iUVC0NfqEkmmUfNZEfTI571U6INoBcpHVbwu34tLqcam3?= =?us-ascii?Q?u9vcqIrw4X0oainFhhWLz9n4Y1egdR7bzg2SPy3AVqJs7MO6EnS50vMgjAbK?= =?us-ascii?Q?vdcUTHEC05IHDGN5dx23TxDNvxcUWM9rjQXrCTEsTCwL2Et3rpbavApzxKL1?= =?us-ascii?Q?zXeeTw8zXZAnJlfuJK78kzi2MKS/TR+tPbM3LBTV9/YwjIIAGjp8AW2ACNRW?= =?us-ascii?Q?rViVQRX7ZASxDtjtWaF7Y0KoGD/KHynTa51utUM/jgL5H0dirLUzLKZyDi3B?= =?us-ascii?Q?eE6H+qcBxavbtbcRViSe6DdXranDuZ0vmFon7d5K4GCk6g9ELc6TS5efPAYb?= =?us-ascii?Q?exHH/dZLsbmkn8yuUbO+FC5vO2YXwv98Q8O/8lkBekiPVfSGXN9p24zNerAM?= =?us-ascii?Q?PQghKcQfzcJEcPtJeZsa6ursh23/wvo+A27CRhrdUvrA6LZkyxyHrb2RdPqI?= =?us-ascii?Q?ZAqCvFOWhksoa00vHlPNqjpGWXQ2R8CVSOvweE4yKSfFaVCg1YGlOEhxE4cG?= =?us-ascii?Q?BRGk3DOJXKrRQ7rstcjfPczNoc8XC6ZJj/2H/DVvHvOZ1wkqMOPmZ622ZbF0?= =?us-ascii?Q?XAbJUgh0syg8n2S503igmUWp6DaowKVO+9SM8dnG2pqH8vjqIdLMBrudxq/m?= =?us-ascii?Q?rh+zLYhJHXFhQFJTrSVeVBtSbY6/Z/cpDzcWNRpBJ8VTlsfPHnS8uuGYw9LK?= =?us-ascii?Q?AcJnEpTCbhR19IK25xq2cyioJ7eg70lkpsemFYeGgB8dXc+eERtNYOj0HAzL?= =?us-ascii?Q?CAZ0S+8gfc9SeWxfgeUDqVC4AIxc8o21mR2x8kL8a5DdMtGgWoax5Zd3Y+oy?= =?us-ascii?Q?erv/KjWG0u2ng5EE5lVLKkJm/Z1WYMyNIVPKb8JtderW8cZc5UXZ27ueiE9/?= =?us-ascii?Q?UnsfKA882UxdHFA=3D?= 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:(13230040)(36860700013)(1800799024)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2025 08:40:30.8301 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8b709cee-11e9-4740-aa51-08dd5c8a8db3 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: CH1PEPF0000AD75.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7141 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1741250506798019000 Content-Type: text/plain; charset="utf-8" Users need to set "cpufreq=3Damd-cppc" in xen cmdline to enable amd-cppc driver, which selects ACPI Collaborative Performance and Power Control (CPPC) on supported AMD hardware to provide a finer grained frequency control mechanism. `verbose` option can also be included to support verbose print. When users setting "cpufreq=3Damd-cppc", a new amd-cppc driver shall be registered and used. Actual implmentation will be introduced in the following commits. Xen is not expected to support both or mixed mode (CPPC & legacy PSS, _PCT, _PPC) operations, only one cpufreq driver gets registerd, either amd-cppc or legacy P-states driver, which is reflected and asserted by the incompatible flags XEN_PROCESSOR_PM_PX and XEN_PROCESSOR_PM_CPPC. Signed-off-by: Penny Zheng --- v1 -> v2: - Obey to alphabetic sorting and also strict it with CONFIG_AMD - Remove unnecessary empty comment line - Use __initconst_cf_clobber for pre-filled structure cpufreq_driver - Make new switch-case code apply to Hygon CPUs too - Change ENOSYS with EOPNOTSUPP - Blanks around binary operator - Change all amd_/-pstate defined values to amd_/-cppc --- v2 -> v3 - refactor too long lines - Make sure XEN_PROCESSOR_PM_PX and XEN_PROCESSOR_PM_CPPC incompatible flags after cpufreq register registrantion --- docs/misc/xen-command-line.pandoc | 16 +++-- xen/arch/x86/acpi/cpufreq/Makefile | 1 + xen/arch/x86/acpi/cpufreq/acpi.c | 12 +++- xen/arch/x86/acpi/cpufreq/amd-cppc.c | 78 +++++++++++++++++++++++ xen/arch/x86/acpi/cpufreq/cpufreq.c | 34 +++++++++- xen/arch/x86/platform_hypercall.c | 11 +++- xen/drivers/cpufreq/cpufreq.c | 17 +++++ xen/include/acpi/cpufreq/cpufreq.h | 4 ++ xen/include/acpi/cpufreq/processor_perf.h | 7 +- xen/include/public/sysctl.h | 1 + 10 files changed, 169 insertions(+), 12 deletions(-) create mode 100644 xen/arch/x86/acpi/cpufreq/amd-cppc.c diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index a440042471..b3c3ca2377 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -515,7 +515,7 @@ If set, force use of the performance counters for oprof= ile, rather than detectin available support. =20 ### cpufreq -> `=3D none | {{ | xen } { [:[powersave|performance|ondemand|use= rspace][,[]][,[]]] } [,verbose]} | dom0-kernel | hwp[:[][,verbose]]` +> `=3D none | {{ | xen } { [:[powersave|performance|ondemand|use= rspace][,[]][,[]]] } [,verbose]} | dom0-kernel | hwp[:[][,verbose]] | amd-cppc[:[verbose]]` =20 > Default: `xen` =20 @@ -526,7 +526,7 @@ choice of `dom0-kernel` is deprecated and not supported= by all Dom0 kernels. * `` and `` are integers which represent max and min pro= cessor frequencies respectively. * `verbose` option can be included as a string or also as `verbose=3D` - for `xen`. It is a boolean for `hwp`. + for `xen`. It is a boolean for `hwp` and `amd-cppc`. * `hwp` selects Hardware-Controlled Performance States (HWP) on supported = Intel hardware. HWP is a Skylake+ feature which provides better CPU power management. The default is disabled. If `hwp` is selected, but hardware @@ -534,13 +534,17 @@ choice of `dom0-kernel` is deprecated and not support= ed by all Dom0 kernels. * `` is a boolean to enable Hardware Duty Cycling (HDC). HDC enables= the processor to autonomously force physical package components into idle st= ate. The default is enabled, but the option only applies when `hwp` is enable= d. +* `amd-cppc` selects ACPI Collaborative Performance and Power Control (CPP= C) + on supported AMD hardware to provide finer grained frequency control + mechanism. The default is disabled. =20 User could use `;`-separated options to support universal options which th= ey would like to try on any agnostic platform, *but* under priority order, li= ke -`cpufreq=3Dhwp;xen,verbose`. This first tries `hwp` and falls back to `xe= n` if -unavailable. Note: The `verbose` suboption is handled globally. Setting = it -for either the primary or fallback option applies to both irrespective of = where -it is specified. +`cpufreq=3Dhwp;amd-cppc;xen,verbose`. This first tries `hwp` on Intel, or +`amd-cppc` on AMD, and it will fall back to `xen` if unavailable. Note: +The `verbose` suboption is handled globally. Setting it for either the +primary or fallback option applies to both irrespective of where it is +specified. =20 Note: grub2 requires to escape or quote ';', so `"cpufreq=3Dhwp;xen"` shou= ld be specified within double quotes inside grub.cfg. Refer to the grub2 diff --git a/xen/arch/x86/acpi/cpufreq/Makefile b/xen/arch/x86/acpi/cpufreq= /Makefile index e7dbe434a8..a2ba34bda0 100644 --- a/xen/arch/x86/acpi/cpufreq/Makefile +++ b/xen/arch/x86/acpi/cpufreq/Makefile @@ -1,4 +1,5 @@ obj-$(CONFIG_INTEL) +=3D acpi.o +obj-$(CONFIG_AMD) +=3D amd-cppc.o obj-y +=3D cpufreq.o obj-$(CONFIG_INTEL) +=3D hwp.o obj-$(CONFIG_AMD) +=3D powernow.o diff --git a/xen/arch/x86/acpi/cpufreq/acpi.c b/xen/arch/x86/acpi/cpufreq/a= cpi.c index 0cf94ab2d6..49c1795b25 100644 --- a/xen/arch/x86/acpi/cpufreq/acpi.c +++ b/xen/arch/x86/acpi/cpufreq/acpi.c @@ -13,6 +13,7 @@ =20 #include #include +#include #include #include =20 @@ -514,5 +515,14 @@ acpi_cpufreq_driver =3D { =20 int __init acpi_cpufreq_register(void) { - return cpufreq_register_driver(&acpi_cpufreq_driver); + int ret; + + ret =3D cpufreq_register_driver(&acpi_cpufreq_driver); + if ( ret ) + return ret; + + if ( IS_ENABLED(CONFIG_AMD) ) + xen_processor_pmbits &=3D ~XEN_PROCESSOR_PM_CPPC; + + return ret; } diff --git a/xen/arch/x86/acpi/cpufreq/amd-cppc.c b/xen/arch/x86/acpi/cpufr= eq/amd-cppc.c new file mode 100644 index 0000000000..7d482140a2 --- /dev/null +++ b/xen/arch/x86/acpi/cpufreq/amd-cppc.c @@ -0,0 +1,78 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * amd-cppc.c - AMD Processor CPPC Frequency Driver + * + * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. + * + * Author: Penny Zheng + * + * AMD CPPC cpufreq driver introduces a new CPU performance scaling design + * for AMD processors using the ACPI Collaborative Performance and Power + * Control (CPPC) feature which provides finer grained frequency control r= ange. + */ + +#include +#include +#include +#include + +static bool __init amd_cppc_handle_option(const char *s, const char *end) +{ + int ret; + + ret =3D parse_boolean("verbose", s, end); + if ( ret >=3D 0 ) + { + cpufreq_verbose =3D ret; + return true; + } + + return false; +} + +int __init amd_cppc_cmdline_parse(const char *s, const char *e) +{ + do + { + const char *end =3D strpbrk(s, ",;"); + + if ( !amd_cppc_handle_option(s, end) ) + { + printk(XENLOG_WARNING + "cpufreq/amd-cppc: option '%.*s' not recognized\n", + (int)((end ?: e) - s), s); + + return -EINVAL; + } + + s =3D end ? end + 1 : NULL; + } while ( s && s < e ); + + return 0; +} + +static const struct cpufreq_driver __initconst_cf_clobber +amd_cppc_cpufreq_driver =3D +{ + .name =3D XEN_AMD_CPPC_DRIVER_NAME, +}; + +int __init amd_cppc_register_driver(void) +{ + int ret; + + if ( !cpu_has_cppc ) + { + xen_processor_pmbits &=3D ~XEN_PROCESSOR_PM_CPPC; + return -ENODEV; + } + + ret =3D cpufreq_register_driver(&amd_cppc_cpufreq_driver); + if ( ret ) + return ret; + + /* Remove possible fallback option */ + xen_processor_pmbits &=3D ~XEN_PROCESSOR_PM_PX; + + return ret; +} diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufre= q/cpufreq.c index 61e98b67bd..690a285f11 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -148,6 +148,10 @@ static int __init cf_check cpufreq_driver_init(void) case CPUFREQ_none: ret =3D 0; break; + default: + printk(XENLOG_WARNING + "Unsupported cpufreq driver for vendor Intel\n"= ); + break; } =20 if ( ret !=3D -ENODEV ) @@ -157,7 +161,35 @@ static int __init cf_check cpufreq_driver_init(void) =20 case X86_VENDOR_AMD: case X86_VENDOR_HYGON: - ret =3D IS_ENABLED(CONFIG_AMD) ? powernow_register_driver() : = -ENODEV; + if ( !IS_ENABLED(CONFIG_AMD) ) + { + ret =3D -ENODEV; + break; + } + ret =3D -ENOENT; + + for ( unsigned int i =3D 0; i < cpufreq_xen_cnt; i++ ) + { + switch ( cpufreq_xen_opts[i] ) + { + case CPUFREQ_xen: + ret =3D powernow_register_driver(); + break; + case CPUFREQ_amd_cppc: + ret =3D amd_cppc_register_driver(); + break; + case CPUFREQ_none: + ret =3D 0; + break; + default: + printk(XENLOG_WARNING + "Unsupported cpufreq driver for vendor AMD\n"); + break; + } + + if ( ret !=3D -ENODEV ) + break; + } break; } } diff --git a/xen/arch/x86/platform_hypercall.c b/xen/arch/x86/platform_hype= rcall.c index 77390a0dbd..5dd1ba2949 100644 --- a/xen/arch/x86/platform_hypercall.c +++ b/xen/arch/x86/platform_hypercall.c @@ -542,6 +542,7 @@ ret_t do_platform_op( ret =3D -ENOSYS; break; } + ASSERT(!(xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC)); ret =3D set_px_pminfo(op->u.set_pminfo.id, &op->u.set_pminfo.u= .perf); break; =20 @@ -572,7 +573,8 @@ ret_t do_platform_op( break; } case XEN_PM_PSD: - if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_PX) ) + if ( !(xen_processor_pmbits & (XEN_PROCESSOR_PM_PX | + XEN_PROCESSOR_PM_CPPC)) ) { ret =3D -EOPNOTSUPP; break; @@ -584,6 +586,13 @@ ret_t do_platform_op( break; =20 case XEN_PM_CPPC: + if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC) ) + { + ret =3D -EOPNOTSUPP; + break; + } + ASSERT(!(xen_processor_pmbits & XEN_PROCESSOR_PM_PX)); + ret =3D set_cppc_pminfo(op->u.set_pminfo.id, &op->u.set_pminfo.u.cppc_data); break; diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index cfae16c15f..792e4dc02c 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -111,6 +111,19 @@ static int __init cpufreq_cmdline_parse_hwp(const char= *arg, const char *end) return ret; } =20 +static int __init cpufreq_cmdline_parse_cppc(const char *arg, const char *= end) +{ + int ret =3D 0; + + xen_processor_pmbits |=3D XEN_PROCESSOR_PM_CPPC; + cpufreq_controller =3D FREQCTL_xen; + cpufreq_xen_opts[cpufreq_xen_cnt++] =3D CPUFREQ_amd_cppc; + if ( arg[0] && arg[1] ) + ret =3D amd_cppc_cmdline_parse(arg + 1, end); + + return ret; +} + static int __init cf_check setup_cpufreq_option(const char *str) { const char *arg =3D strpbrk(str, ",:;"); @@ -159,6 +172,10 @@ static int __init cf_check setup_cpufreq_option(const = char *str) !cmdline_strcmp(str, "hwp") && !cpufreq_opts_contain(CPUFREQ_hwp) ) ret =3D cpufreq_cmdline_parse_hwp(arg, end); + else if ( IS_ENABLED(CONFIG_AMD) && choice < 0 && + !cmdline_strcmp(str, "amd-cppc") && + !cpufreq_opts_contain(CPUFREQ_amd_cppc) ) + ret =3D cpufreq_cmdline_parse_cppc(arg, end); else ret =3D -EINVAL; =20 diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 3f1b05a02e..a6fb10ea27 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -28,6 +28,7 @@ enum cpufreq_xen_opt { CPUFREQ_none, CPUFREQ_xen, CPUFREQ_hwp, + CPUFREQ_amd_cppc, }; extern enum cpufreq_xen_opt cpufreq_xen_opts[2]; extern unsigned int cpufreq_xen_cnt; @@ -267,4 +268,7 @@ int set_hwp_para(struct cpufreq_policy *policy, =20 int acpi_cpufreq_register(void); =20 +int amd_cppc_cmdline_parse(const char *s, const char *e); +int amd_cppc_register_driver(void); + #endif /* __XEN_CPUFREQ_PM_H__ */ diff --git a/xen/include/acpi/cpufreq/processor_perf.h b/xen/include/acpi/c= pufreq/processor_perf.h index 33edf112a0..ee12e0192b 100644 --- a/xen/include/acpi/cpufreq/processor_perf.h +++ b/xen/include/acpi/cpufreq/processor_perf.h @@ -6,9 +6,10 @@ #include =20 /* ability bits */ -#define XEN_PROCESSOR_PM_CX 1 -#define XEN_PROCESSOR_PM_PX 2 -#define XEN_PROCESSOR_PM_TX 4 +#define XEN_PROCESSOR_PM_CX 1 +#define XEN_PROCESSOR_PM_PX 2 +#define XEN_PROCESSOR_PM_TX 4 +#define XEN_PROCESSOR_PM_CPPC 8 =20 #define XEN_CPPC_INIT 0x40000000U #define XEN_PX_INIT 0x80000000U diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index b0fec271d3..42997252ef 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -423,6 +423,7 @@ struct xen_set_cppc_para { uint32_t activity_window; }; =20 +#define XEN_AMD_CPPC_DRIVER_NAME "amd-cppc" #define XEN_HWP_DRIVER_NAME "hwp" =20 /* --=20 2.34.1