From patchwork Fri Dec 6 03:19:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13896349 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2040.outbound.protection.outlook.com [40.107.220.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3E0B19258C; Fri, 6 Dec 2024 03:26:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733455575; cv=fail; b=ulWPEV3aTEUGYtV4yoKTBHPO1elgK4JVOSPDoENdZDQogFMTV6fUsbzOmzUeWo3FY86ujs1cYmB6PP67eWDfMrhpohmBHABNQ94qWhqs0/ngUJ+wVrb85NNDEhqoNLpmDEb9g7kSJAAged34AmA/gqTwraqfVC+oxPOafycIvoQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733455575; c=relaxed/simple; bh=deBmNxDPRllsYpGw84ggzNBpWk7/UUVrK/nhCONp3v4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=npwOjZn71doSfLoVqPrHLXXdS2ecpDRE6dMTSBB34h4cUDK3kmG22tmYP+GetwbUFutAlY+qWjgqUPP+fPriQqt4dtnMDMt3+zG+dgk4FWDKvF1Ytd+j2OCJae/+ChLhe0H3xr9NBD+dV+fDDBWEAby00XLFWR8wIPemMyDOoJA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=qgMKz6mV; arc=fail smtp.client-ip=40.107.220.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="qgMKz6mV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bryeuWsawTdv/yQp7LOqWSjq1jAJSwaG0xvABGIh3We6lC9F+nAqIAYDFEA0jHdu3ldBD7YAH8xOIPwRsNcJbaF3jJRk0GpJEbofLst7xJDKKqyZdqaUaqskshqpHHEOUomJueu+O7/BeGJWldkiz845+ca46aq5zRdz/YRAumxA1rkweTOco69EjrE13jKmtAby7W+XlJL6GaK8sPaMxUpaS3Pmasj3n/wgrpdM4UF0RNKS2rIOb01iCmHVx187uBrgzEG2dcZRMaqwlIkmFxCzzV2rtFalgeuogOSumePSrTYbOR4AVKfNJMW6X8QemODSTeBMTHmQUr1S3FSl/A== 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=Smp5omVcxem4nJZtzzeYdunSFxMaCj7p+L4/uAXrNJ4=; b=yFo1z+oaVclhX5hcvEmoSr89f4McHFA4ppQoQkEm6HaOkhV5u7UaqqtzLiwqP39xLdgZCqkLFZkDapCnotAM3M0b7K/x7glrMZZG6/6fAINqCsGPbSpakWAaHU2GpQg3b3gJrS01lO12vKlFpQEOFBTln8sZ8sritikA/+7dCc9mccQwsgSz6sY1sbbn6nBXzUGLWLxQHXxjfcGR259e7r7J9oxljZnwqf+ZLY4r9wB84qac+Zk4hZ45J+7s/ZnqMn9g15iauFmdYKA70ArXGoFsxA/Jbf8mPehu8mTbnla7r0ww88LyBzg9AYuqbdDUbP9Nk4ZfKWbdgPa0/kgfQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.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 (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=Smp5omVcxem4nJZtzzeYdunSFxMaCj7p+L4/uAXrNJ4=; b=qgMKz6mVPR0kzJwOd/xfRPJsCiV/GmCXREGf61Zli3ysIkPh/iwtxspUKQlOF6WYT3EyvlSUgj7mpfLBhMGOgoXfo4pqR+eLhcbFDym/Lt/gtN6F/bGiDA4mYfCDl7FuDQt7pbBI6cHH0pRJkST9COGnlRF6KoCy2+Ue75WLxpA= Received: from DS7PR03CA0068.namprd03.prod.outlook.com (2603:10b6:5:3bb::13) by PH7PR12MB5712.namprd12.prod.outlook.com (2603:10b6:510:1e3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.24; Fri, 6 Dec 2024 03:26:09 +0000 Received: from DS2PEPF00003445.namprd04.prod.outlook.com (2603:10b6:5:3bb:cafe::c7) by DS7PR03CA0068.outlook.office365.com (2603:10b6:5:3bb::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.9 via Frontend Transport; Fri, 6 Dec 2024 03:26:09 +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 DS2PEPF00003445.mail.protection.outlook.com (10.167.17.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Fri, 6 Dec 2024 03:26:09 +0000 Received: from AUS-P9-MLIMONCI.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, 5 Dec 2024 21:25:52 -0600 From: Mario Limonciello To: Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= CC: "Rafael J . Wysocki" , Len Brown , Maximilian Luz , Lee Chun-Yi , "Shyam Sundar S K" , Corentin Chary , "Luke D . Jones" , Ike Panhc , Henrique de Moraes Holschuh , "Alexis Belmonte" , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Ai Chao , Gergo Koteles , open list , "open list:ACPI" , "open list:MICROSOFT SURFACE PLATFORM PROFILE DRIVER" , "open list:THINKPAD ACPI EXTRAS DRIVER" , Mark Pearson , Matthew Schwartz , Mario Limonciello , Armin Wolf Subject: [PATCH v10 15/22] ACPI: platform_profile: Only show profiles common for all handlers Date: Thu, 5 Dec 2024 21:19:11 -0600 Message-ID: <20241206031918.1537-16-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241206031918.1537-1-mario.limonciello@amd.com> References: <20241206031918.1537-1-mario.limonciello@amd.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: DS2PEPF00003445:EE_|PH7PR12MB5712:EE_ X-MS-Office365-Filtering-Correlation-Id: c73f2996-6e7b-49a5-96e2-08dd15a5ba49 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|7416014|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?lTMLQY5jh64Jh33UxyY0ZqNbxii6X8U?= =?utf-8?q?4ijanuF17JqHTiVApdrCt6ul4mALX9eTJSihWqLafCg5BIWaWY603jENeQHeSej8d?= =?utf-8?q?JV6tR0wUnWtsGRWPbdojDp2vjkJqDuBzeI3xI2cuE9Pgb6qjbg7PGD4uUgOzxbz6E?= =?utf-8?q?IcpQgi0nGHdv5of2neOb1x05kFH/sWVKVjKKA0o6AigKHQYDreHPKJGaYGBieIKrZ?= =?utf-8?q?0uUBtP/GaZsuZHAw2XOEAO5/Lk/JbSQREb4mvnMZLC27zorEi0VyoTkq1ybZnZkSy?= =?utf-8?q?I4oKNu5865v4xfBNmOv4L2SbmCQ0I0NTG8oV7cfzev4fXg9q5/s0zS/Wg4lfUVKSI?= =?utf-8?q?JxlL7f8o3R6sWsMnKKjAolc2SFtpyMLDyvqZTlqBSshafqHDYhRYk15k63IIslqDf?= =?utf-8?q?L7Rwhg1PZ/N6zWRQJF6R7ycFB1D9cilDOwatSfulPw1dAF73vbAB0pWJtxs4g0E1X?= =?utf-8?q?YdZNTe5QP9JNvBDaPuVzy8WUzhRpoaZPXO+fOMO+dycdNi/t81UkSrSIi+BfIvtDR?= =?utf-8?q?beZFWeuFvonmGCbRo1YKQ3m7Gy3wuzNhEXUqKTOxvyw4ol2st+ReJk3GwP4/DDKh7?= =?utf-8?q?H0KslEk7CZ4bGf1VNu563t0KXdoMgtqNZHSVyzhPwFrc8rWuno3P/amLWU3f25BKd?= =?utf-8?q?Nko5XJh7xl/Tdd3FL5WxEAw5lf+KqOrhCUwO8zSlH/Iyi5lBO0s+ICosPGRPZ1p5F?= =?utf-8?q?/r7u5qK88bW2ULpVlp1DvPhB95WbMUELRocv6Y4Nkcw52Z8iF9EtbX+9oUcxXIn7+?= =?utf-8?q?0n5VvpilBCEkmNgheQ4ZyxP3/8R6ePZnvAxAxIhvAA8ayJeIXLGx0e5fPvS8kFVP6?= =?utf-8?q?Tmv43Yqp616nCz/Kv6UtMplzyLcuyF3C5mJuKMEkZtsbQgVNZhjEvBunpuwc+VdsT?= =?utf-8?q?vkY7r11XnU+dA+7zTwV7z/RrmvSVNHZPJW7MRihD3axtRsDB2Mq0M2qAXQ2EdHHMm?= =?utf-8?q?DuAWBGHfLPWvG6G/QsPxdBT1+bkzdfU4Y7mEXNlUkYV+lO7SGhFDf821BGlYXTTxU?= =?utf-8?q?dJotKAoQcRf8KSRRvEG73YlHNFIEMiGkn4KibMiyzjVlA2scVKK+m/7Fba2ZFFOnT?= =?utf-8?q?196NPcjI1GYrZWV8SFJT1RF77POyF8VBdUo+rmX3/DEFo2hP9kLVM8Mx/30xuQaC0?= =?utf-8?q?2uQXaVzKzwdartP73T+ICUarjkZMDE3Isi8TXKY9D3utJsFsdTvW0ygRZR8WdN4nx?= =?utf-8?q?mpnMA1V9XlC7IdU4Q9NpDnd4n2dinNGHStAL7bQdBPcCadenJRQbUqfBuLfrzn5z2?= =?utf-8?q?L7yALikyQrA+7tQgi5+tc6YSybgnUrHBVsBfvDyURVj2prM+vXzkcvgPhQcnd5U3B?= =?utf-8?q?3rpFijx/S2aACdguEpa+76ygYajbSufg3f0XrbFhekeqDO5Y84TDFgReq1wwvuVoc?= =?utf-8?q?yDpRT+fPv+f?= 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)(1800799024)(36860700013)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2024 03:26:09.4556 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c73f2996-6e7b-49a5-96e2-08dd15a5ba49 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: DS2PEPF00003445.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5712 If multiple platform profile handlers have been registered, don't allow switching to profiles unique to only one handler. Reviewed-by: Armin Wolf Tested-by: Mark Pearson Tested-by: Matthew Schwartz Reviewed-by: Mark Pearson Reviewed-by: Ilpo Järvinen Signed-off-by: Mario Limonciello --- v10: * whitespace --- drivers/acpi/platform_profile.c | 54 +++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c index 2a4f067c3c5c1..bdf69255ed9ca 100644 --- a/drivers/acpi/platform_profile.c +++ b/drivers/acpi/platform_profile.c @@ -198,22 +198,56 @@ static const struct class platform_profile_class = { .dev_groups = profile_groups, }; +/** + * _aggregate_choices - Aggregate the available profile choices + * @dev: The device + * @data: The available profile choices + * + * Return: 0 on success, -errno on failure + */ +static int _aggregate_choices(struct device *dev, void *data) +{ + struct platform_profile_handler *handler; + unsigned long *aggregate = data; + + lockdep_assert_held(&profile_lock); + handler = dev_get_drvdata(dev); + if (test_bit(PLATFORM_PROFILE_LAST, aggregate)) + bitmap_copy(aggregate, handler->choices, PLATFORM_PROFILE_LAST); + else + bitmap_and(aggregate, handler->choices, aggregate, PLATFORM_PROFILE_LAST); + + return 0; +} + +/** + * platform_profile_choices_show - Show the available profile choices for legacy sysfs interface + * @dev: The device + * @attr: The attribute + * @buf: The buffer to write to + * + * Return: The number of bytes written + */ static ssize_t platform_profile_choices_show(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { - int len = 0; - int i; + unsigned long aggregate[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)]; + int err; + set_bit(PLATFORM_PROFILE_LAST, aggregate); scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) { - if (!cur_profile) - return -ENODEV; - for_each_set_bit(i, cur_profile->choices, PLATFORM_PROFILE_LAST) - len += sysfs_emit_at(buf, len, len ? " %s": "%s", profile_names[i]); + err = class_for_each_device(&platform_profile_class, NULL, + aggregate, _aggregate_choices); + if (err) + return err; } - len += sysfs_emit_at(buf, len, "\n"); - return len; + /* no profile handler registered any more */ + if (bitmap_empty(aggregate, PLATFORM_PROFILE_LAST)) + return -EINVAL; + + return _commmon_choices_show(aggregate, buf); } static ssize_t platform_profile_show(struct device *dev,