From patchwork Fri Dec 6 03:19:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 847874 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2069.outbound.protection.outlook.com [40.107.244.69]) (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 CBDA11D515D; Fri, 6 Dec 2024 03:26:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733455580; cv=fail; b=UE1y9bKUsF+LphmNf7VwwWMuZOBdLOSCaXLAVYki4vSbg1gfJhvREZagdCotqvi5+hcAOA2VtImckBb5wBRVCj/k/miBssyxPs+xr9KWEaocCtmRyA+83WJxedF5MHPyCJx/a4jgnmcZxbARlMyyWB6MP3P6ZKWvmDeHgNp7xws= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733455580; c=relaxed/simple; bh=73VCGxXEUH+QMSbDdxeJ397X7eVUA6+afqZAfy83QXk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BMMtfq12pTOMTiXF3SCwNsC1904gSEcdzvbjwgAOWG8uRHx8iJpNIZ4P79nxpYCzYXN5tqmu2YpjRegqiVB50c0+Nt0DskK8VYmArKe88salPqah9jbBWL6bsXz/pCSo5WKooHbUG+CEA+z72L8T7S2sOT7SmhTJ5A9zpsAzXGk= 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=oJDH3Swf; arc=fail smtp.client-ip=40.107.244.69 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="oJDH3Swf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vIIXvIASEIJQwzFiUl2gyQlTMpBd0oTgwhEGvWetBXdFucYv0xNuFHX/GqJlCVHaCb/VUhBAN+MzOTLwii1i5Am7oV4ZINLsxWT69CE3PUcC0EaQgwuIuLdNsR2/y+5f7xaiNnAXWi9CBnBnFHFAIiu4eJSHF/RVsoam0khGhflx66YcBvlZIb8aRyz/jWUUrMKySEMSPRWQMlh4iezX9dxr/1LB9MzsegBqcBkvYYmSb4DaUUBB0fr1LSSZThRf9vr7JXVOf8t++kQFiX3Q3fT4jjGWidOk8r/P8y7tQMUNBMmWB8H6yQXQk2Y1wqrQLg4kp6wuLdLzJ+5K7daTDQ== 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=/orDSLYV1gL0+Vvmo9e+6jP2d9Qr1AnkAhlrFTLpBHs=; b=i/7+xWndZuTSLqo4E1Sebk4vQnxGPlKD2cOW8Geq+42zny23To6v92S8h8zQ0bggixkpwvJkJ+txisAbz62iB1w0JQzrWF9EXM8UmUh3DEO0QgpF6goihR9k2X2Ahs8oXMk4TJ97/bs2DRvEk7l6MNrya3/Kx5ozrw/v6VpqzsNlZ7fqxXHDkWkzAQzWwMrFyNsR3iMKcMpblLZCqwpoiWAxNygXADWR0jblwNpK+Ma20kI8rLOUBQMJZv67sSOL1Wj836dnOtLCJUjdBC7Ve5DUwHu0rfHxtbx1fOVNKOJF4MpSrQ14rfeFC8nxaVEGgFLBCrNwIG6VoFWdquakVg== 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=/orDSLYV1gL0+Vvmo9e+6jP2d9Qr1AnkAhlrFTLpBHs=; b=oJDH3Swfua3jQ6GdSoVQ+vpV2ECvIC13KF0tqPTtG+msNsWpN+4kG5Y2WbY/IilYCZHC1pc8pv7L1a13hItkOaJfZO3GVWGo9MPLLCducMKD2WUrQyvwNi3rHCHj+5eiY8BjgpAKuvuTrmUmy8EMxRQAlmC2huiLO8IC7d751bI= Received: from DS7PR03CA0081.namprd03.prod.outlook.com (2603:10b6:5:3bb::26) by DS0PR12MB7701.namprd12.prod.outlook.com (2603:10b6:8:133::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.12; Fri, 6 Dec 2024 03:26:14 +0000 Received: from DS2PEPF00003445.namprd04.prod.outlook.com (2603:10b6:5:3bb:cafe::ad) by DS7PR03CA0081.outlook.office365.com (2603:10b6:5:3bb::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.10 via Frontend Transport; Fri, 6 Dec 2024 03:26:14 +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:14 +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:26:11 -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 17/22] ACPI: platform_profile: Make sure all profile handlers agree on profile Date: Thu, 5 Dec 2024 21:19:13 -0600 Message-ID: <20241206031918.1537-18-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_|DS0PR12MB7701:EE_ X-MS-Office365-Filtering-Correlation-Id: 107b3539-f11c-483b-86b9-08dd15a5bd44 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|376014|36860700013|7416014|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?aTMGOH2W2WMZgwJTL4LsaM77KrmcMLm?= =?utf-8?q?F/Gx87lr3iFOmkXGnAyR6SMTH3ZFlAeOhOMG+TNEfW986PtOZ+uPf68Iqe6FXfTlP?= =?utf-8?q?0P4A9xBj/+Fnx2pr+h3t03qauQ504dlj4AMTLal6zlIk/7reXHkyVqBWBF5ylRr0P?= =?utf-8?q?kt4pvXvZODE7gobTMO9A8EkB+VfrUP3CyjAMYrN3iZSqWmw0wlZhP41zLjoo8ZSYm?= =?utf-8?q?EM5CLQuGacjTw+yUG/XRZ7jKt0XMfpzR9eTanW2njd5UhMKqKZ1fnyIO5v8TJOt6z?= =?utf-8?q?MdyOkSPccxw0tngLRnP7NMlBoPNjY5Rs0BxmfLbmy7aECm8+nhmpjrI71WqSxYvNP?= =?utf-8?q?yPJqh5s8eDkCj2juaOY54trFpRvZvq3fYHOcKoo9DRPkLIOYeisZES3cf6SQOI/fo?= =?utf-8?q?urGdqGRnxxEB9ZGGeInHMTGZato8DUGmnm1Od/QVHeZB1Z0aWwL5iV3NCYIIRx3z8?= =?utf-8?q?zv7ingOPon9n+q0p0/KYe/xHqAw3Cbl5+XV17PJMKGC+h74fHizy1VadijrgJmrDZ?= =?utf-8?q?NRlZU0eCrMAQPV+cC71usg/spNyxTr9LFGBzxIc1Fcdgk/CwsO6GIEpILqzkVxP/M?= =?utf-8?q?lnovvTTpxFZqz9N1fJCsQxNXWT56dnxAj6z9M5d2pNWyXPNVSKhcXfAj5EJUPlIKi?= =?utf-8?q?BXQ3yJRCjEE9ZkvCO7VV0hu0/Nxjbb8nAM8Ar8uES3R7m6GRt5187+FuJWahtuJXn?= =?utf-8?q?QNlfr9j/XUb4APkgVXr4l9fA64j/K964d+rXHYhJkksSED+RZFujo0Fo2w5B4/ZSv?= =?utf-8?q?c+T1H+nPWz9UMqpeZN3162x0b6peiArO3utVrKfu6u8eQPRkwByQeigLKCTpIDB1e?= =?utf-8?q?VL/DrBTAxPI/xll2Se2iWAAgswrdGepuEFWqU23x1hq4M2+gDUFESQqSg32gNxGGG?= =?utf-8?q?rq+caw0juHxSL3Y2+ST//8TXA4TE5yT4LZ8SNrAuio3jSXSuxQOwQPtpbNHprJXkb?= =?utf-8?q?YgzHGenyl+T2qt9OSQM07e/kA1wA3vf88tExNukm7gk7W9GiTmuqtXxfcmEn3z3tT?= =?utf-8?q?Hd1R9QbwCrjj4tKbZ6pmVIj5aSzQoFcbdhLNs7gMSfuZFuVo7U071/FzUR142YRmH?= =?utf-8?q?2uaCUCAw+iS5fUtmoJuKaFoMUT7i/dlP+vix4CmhLPWgbvG4MxPjRraFe15Op4YI/?= =?utf-8?q?jjedVF9H4RD5n0ZFdhSM6riQn+TGlZGJWJd193W/t9cxmTnZW/IZIjreEQ5gprlAa?= =?utf-8?q?9pjTJmkSoMaga5DIQT26FcVZjhQVdqGSHwEPJ6pOXu82A1MnNmmgAF/vX36t9ncQa?= =?utf-8?q?CrodRIOIHR1YmFPIy4TUQPFHyo24UmcPGxhgzozBIjQKLz64HfsJRtT44kQctiJTR?= =?utf-8?q?9fBeTUf+IMUkNTq8gt5yr9nZRUcIrco9RIKrQBDX3Op6T7aYCtnYo5ldkrX/rAZgk?= =?utf-8?q?Yxuhl+C9fS3?= 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)(376014)(36860700013)(7416014)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2024 03:26:14.4556 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 107b3539-f11c-483b-86b9-08dd15a5bd44 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: DS0PR12MB7701 If for any reason multiple profile handlers don't agree on the profile return the custom profile. Reviewed-by: Armin Wolf Tested-by: Mark Pearson Reviewed-by: Mark Pearson Reviewed-by: Ilpo Järvinen Signed-off-by: Mario Limonciello --- v10: * Whitespace --- drivers/acpi/platform_profile.c | 125 ++++++++++++++++++++++++++------ 1 file changed, 102 insertions(+), 23 deletions(-) diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c index 54483269b8834..95aff045a1eb3 100644 --- a/drivers/acpi/platform_profile.c +++ b/drivers/acpi/platform_profile.c @@ -68,6 +68,24 @@ static int _store_class_profile(struct device *dev, void *data) return handler->profile_set(handler, *bit); } +/** + * _notify_class_profile - Notify the class device of a profile change + * @dev: The class device + * @data: Unused + * + * Return: 0 on success, -errno on failure + */ +static int _notify_class_profile(struct device *dev, void *data) +{ + struct platform_profile_handler *handler = dev_get_drvdata(dev); + + lockdep_assert_held(&profile_lock); + sysfs_notify(&handler->class_dev->kobj, NULL, "profile"); + kobject_uevent(&handler->class_dev->kobj, KOBJ_CHANGE); + + return 0; +} + /** * get_class_profile - Show the current profile for a class device * @dev: The class device @@ -251,51 +269,112 @@ static ssize_t platform_profile_choices_show(struct device *dev, return _commmon_choices_show(aggregate, buf); } +/** + * _aggregate_profiles - Aggregate the profiles for legacy sysfs interface + * @dev: The device + * @data: The profile to return + * + * Return: 0 on success, -errno on failure + */ +static int _aggregate_profiles(struct device *dev, void *data) +{ + enum platform_profile_option *profile = data; + enum platform_profile_option val; + int err; + + err = get_class_profile(dev, &val); + if (err) + return err; + + if (*profile != PLATFORM_PROFILE_LAST && *profile != val) + *profile = PLATFORM_PROFILE_CUSTOM; + else + *profile = val; + + return 0; +} + +/** + * _store_and_notify - Store and notify a class from legacy sysfs interface + * @dev: The device + * @data: The profile to return + * + * Return: 0 on success, -errno on failure + */ +static int _store_and_notify(struct device *dev, void *data) +{ + enum platform_profile_option *profile = data; + int err; + + err = _store_class_profile(dev, profile); + if (err) + return err; + return _notify_class_profile(dev, NULL); +} + +/** + * platform_profile_show - Show the current profile 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_show(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { - enum platform_profile_option profile = PLATFORM_PROFILE_BALANCED; + enum platform_profile_option profile = PLATFORM_PROFILE_LAST; int err; scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) { - if (!cur_profile) - return -ENODEV; - - err = cur_profile->profile_get(cur_profile, &profile); + err = class_for_each_device(&platform_profile_class, NULL, + &profile, _aggregate_profiles); if (err) return err; } - /* Check that profile is valid index */ - if (WARN_ON((profile < 0) || (profile >= ARRAY_SIZE(profile_names)))) - return -EIO; + /* no profile handler registered any more */ + if (profile == PLATFORM_PROFILE_LAST) + return -EINVAL; return sysfs_emit(buf, "%s\n", profile_names[profile]); } +/** + * platform_profile_store - Set the profile for legacy sysfs interface + * @dev: The device + * @attr: The attribute + * @buf: The buffer to read from + * @count: The number of bytes to read + * + * Return: The number of bytes read + */ static ssize_t platform_profile_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) + struct device_attribute *attr, + const char *buf, size_t count) { - int err, i; + unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)]; + int ret; + int i; /* Scan for a matching profile */ i = sysfs_match_string(profile_names, buf); - if (i < 0) + if (i < 0 || i == PLATFORM_PROFILE_CUSTOM) return -EINVAL; - + set_bit(PLATFORM_PROFILE_LAST, choices); scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) { - if (!cur_profile) - return -ENODEV; - - /* Check that platform supports this profile choice */ - if (!test_bit(i, cur_profile->choices)) + ret = class_for_each_device(&platform_profile_class, NULL, + choices, _aggregate_choices); + if (ret) + return ret; + if (!test_bit(i, choices)) return -EOPNOTSUPP; - err = cur_profile->profile_set(cur_profile, i); - if (err) - return err; + ret = class_for_each_device(&platform_profile_class, NULL, &i, + _store_and_notify); + if (ret) + return ret; } sysfs_notify(acpi_kobj, NULL, "platform_profile");