From patchwork Thu Nov 7 06:02:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13865858 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2072.outbound.protection.outlook.com [40.107.237.72]) (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 0C27A1DD525; Thu, 7 Nov 2024 06:03:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730959436; cv=fail; b=XpMOKZ+C4KWcs+emPaMnLilWVItYevmyOB1bac2ngQShm4rahy9i13uKNc8dFBpdmz8/S/feyN0li+zn+mSb/XhrANTElruJRf+CILj14yOqBF0UTCfUL60c8C23cTnXtzZmm121mllGVV64VJgmJ92ZBpyF8mLVIMFdZ2Sbqd8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730959436; c=relaxed/simple; bh=CTLNKCXi/cTsX4LriEwKBmAvKy6FoN1XxY8tEauqe5c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BCe3Y6hleGsWHiiMkZlFB81jS6DlFffOwN9+wnMtRh+N/vvpX0+Q9m1Ln7fuQcwLNwTOoR5kKujJwOKPVF0C+qlFCtsFYcKORPTlj7YL9i9giYNSIFOQMFetqNDSHTzZ0pJozHSaGStj9SGV3QnXLxRa/xxX2CHxWflx8cI0rC8= 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=D8WKsheZ; arc=fail smtp.client-ip=40.107.237.72 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="D8WKsheZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OdL1Knf0UGpiuc7UzbfzFYNboJw3VQxlEUjAqaKS1VLEl6KDnriNgGna/gJkxbFhFZLQceBRXFSmIO+2B9PKY+aZmOJYXVrixupINlJpWRkBx8uDZ+SK0uOD0ueWUUrN7cWARzoL271fc32Ewwv7jtQ0cEZILja6yeq5XVrQzHyTSUrHmU0bJSMmcnASF/D9Ppi9fPw13Zct+/bwPn4CRr6IR6o6hPb/0mGX1RsKkPXGZvXobw85thc4MDkRmpidMyqIkmxb4I9h7J0ZlHxVh7MfRicZJ2ZlKlRtLQ8OcA0W7gMH4bL/6skJ8MZTO3CPXa6/fyLdxTchCqOO7u0JjQ== 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=Ef2WNmNYKfJfZZJpNE5oKPFeLWiXbAbe7aodPN6BEec=; b=EBJTBXOC/dBeGCmTrN+0aphuym1RfnwrHyTXg346BKknl3CyTRKaHiKVCZVjhyrXnCelYQ/AnG9nPicQOCUDEPDTAEjIMsAkr3DdKv05eJG3J0Dd4tsqyKIPsk3oFID0rCMdhWZza/FuDxXn3Zp5ZC5JEg4wuuQdB2bwAo1WDPxoQEIe0ZBWoZwQtyXbq2ayqafry2+Adf+duRhmOBfU2fqn7AoexpyOD6Nby1zx+iSZXOZzsoISadklZvUtYZLr3U+ym8c+gRQrAoF1nkz4+jA/uqzROOu/d+JjLW2yKXqJd8V/YRIyMQZwp38UFfGT2OvRwfCW+jcbOsXuvKjwsA== 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=Ef2WNmNYKfJfZZJpNE5oKPFeLWiXbAbe7aodPN6BEec=; b=D8WKsheZNSMTu7ntmhdrQCJcXWBy2ZlHiwxRNSPIh8rgGmMp4mCBXw1PMa8dT5qd1WUgB9HnNIk2brU6BjbquUON5nNRpV4HP9wOP1fgKZWL9oHo0QJ5fBBIAFQb0+2L3cU3mM9aFUABu4D9D/DNHn+eJTnC2/T4ZIX6ql8Qr9Q= Received: from CH5P221CA0024.NAMP221.PROD.OUTLOOK.COM (2603:10b6:610:1f2::18) by SN7PR12MB8130.namprd12.prod.outlook.com (2603:10b6:806:32e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.19; Thu, 7 Nov 2024 06:03:52 +0000 Received: from CH2PEPF00000143.namprd02.prod.outlook.com (2603:10b6:610:1f2:cafe::17) by CH5P221CA0024.outlook.office365.com (2603:10b6:610:1f2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.19 via Frontend Transport; Thu, 7 Nov 2024 06:03:52 +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 CH2PEPF00000143.mail.protection.outlook.com (10.167.244.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8137.17 via Frontend Transport; Thu, 7 Nov 2024 06:03:52 +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, 7 Nov 2024 00:03:48 -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 Subject: [PATCH v5 14/20] ACPI: platform_profile: Only show profiles common for all handlers Date: Thu, 7 Nov 2024 00:02:48 -0600 Message-ID: <20241107060254.17615-15-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241107060254.17615-1-mario.limonciello@amd.com> References: <20241107060254.17615-1-mario.limonciello@amd.com> Precedence: bulk X-Mailing-List: platform-driver-x86@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: CH2PEPF00000143:EE_|SN7PR12MB8130:EE_ X-MS-Office365-Filtering-Correlation-Id: 40b61abe-03ec-4110-c9d8-08dcfef1f476 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014|7416014; X-Microsoft-Antispam-Message-Info: 53lHTZo8s/T29HjqZxqr2mzb11uv4fTAjocPEKBfpnZWnICJ3ADG+krNYcw20d6Sq3BIw807iIMH1UFleTjijEMPwjBJOML8qtGzWEV5Tux1wMJcwTCBUeYsigSfMv0UgOy6cyVLRDB9yh3/zVvcA/A1pSzZ7GsLvGVrttLXYgykJNeTAbdi3m/bK6VLlLcIS1IQ13R1NInBzWEEFPcoYnpnXm7hIuRG+H/A7fqb1CPwkh0CZR9/EICVARjRxR4dJOmtzQgfJK1WAkGShjYJiFBn9stCXV+9xG8uKz41c53SjlwJf2/VWL/GlvA6guxUPMjFsyx//8KObX11jrr1iXfibZyzI8oUqL1rsGIUoECJRi6XSLe0ZBJQpQE8I77RolpQ/OOxP3jbQKwg9yskn/km4pYyGqVtq+g7pTk0csfz4AZkZRQ6OLOAJHOlpC3ppJb5R8rFZGWAzJjM7UDqkt2D8WDuaSJ98JmdwcBDPJUHiGgULL7oQTo3I1zgFQVbpQ9VYtH+R4bVk45kQTlqxSWSI8qZP65Q1fA2hXLOn1kcWavxjLr+iW+aZRX3Ten6YWDu2GDpcPAhH9kLkryyrtu0glFc/Q9BwMUNelmWfklyQdMdMRRL/c61zBCHkxAmjda6OybE8MLl6qjTNmUniojGgcHu3W1+HbdGnEeMgK2EKvudf2NrQzHbdpVY64tU4FGTHTb7f8Hkqc7jmDg3VIskZX4+aoVHbkGrEsJr7wzM8aeZDCe1/xyi31ugTBKOilWAXyZjRsiEWssGpblMkL0njoW3xZXwoAy2TQoblBF3NXsmmBq0+jcaM1QRPn2NVQzLmLDV23zbuFKn0+uY7hQ1vv1OwpHtX3PGfmKTfz5MP+6OBhZeRuRjAneg6CXOEMSImALJwTgGE9VE+DvyrTwhyvM6ot3/iZCgQhPlktf+Q15RDdEkqLunDo8qywod4AvoZ8sr41tLUo7uyGKIs6XpgmDnaTHm7p7AK+39g1pA7N1+pkn/4FNYYJORx+3YiugB1E4QIu0ptJ1XycoLbfcazT7ItUM3Q0Pp1NukmcK6QSn5UOd3UEULuUmrO0Le7mhkBA8ruR7Z0GhI4jrC3dAsxmCFrsCDOWPTzuq/yo0yNiSQC/NBQJALYQ957UaoRqSfy/AB1F1zLbDFjac+stivSpy/vVq3ckfzDb3ou+hcNfVRgIVyKaTIt3NKPGk3b2XxvkBR1Xsis82dqBhcZHgYyKn7/gTkHD88XdO5pAz/9klHuSaNY9b0kA9+/WFjKxF7731W99cZfwrihRt1UTVz9+GxTubazBVB56BRqnMZIk31z0CK4Lic10csQT2VIPhLX/TtoteaQQZvRvcuC4tL6ErIqSRs59TFL1ZKtAQwqSql/372KF3JJMRP2Tt/CNtIe9uWfElK6ZFMmeXUkg== 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)(82310400026)(1800799024)(36860700013)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2024 06:03:52.0360 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 40b61abe-03ec-4110-c9d8-08dcfef1f476 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: CH2PEPF00000143.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8130 If multiple platform profile handlers have been registered, don't allow switching to profiles unique to only one handler. Tested-by: Mark Pearson Tested-by: Matthew Schwartz Signed-off-by: Mario Limonciello --- v5: * adjust mutex use --- drivers/acpi/platform_profile.c | 59 ++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c index 510e1435d3980..2ae0437623abb 100644 --- a/drivers/acpi/platform_profile.c +++ b/drivers/acpi/platform_profile.c @@ -231,27 +231,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) +{ + unsigned long *aggregate = data; + unsigned long choices = 0; + int err; + + err = _get_class_choices(dev, &choices); + if (err) + return err; + + if (!*aggregate) + *aggregate = choices; + else + *aggregate &= choices; + + 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 = 0; + int err; 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) { - if (len == 0) - len += sysfs_emit_at(buf, len, "%s", profile_names[i]); - else - len += sysfs_emit_at(buf, len, " %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 (!aggregate) + return -EINVAL; + + return _commmon_choices_show(aggregate, buf); } static ssize_t platform_profile_show(struct device *dev,