From patchwork Fri Dec 6 03:19:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 847878 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2075.outbound.protection.outlook.com [40.107.96.75]) (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 3E654191F74; Fri, 6 Dec 2024 03:25:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733455552; cv=fail; b=cmw9VC7ENTH0HgjCcfWEyI3F4Hho57aZbi9MToRg0mr3eJIk+F3DKD72989fvrtsyX12qphCHiEy7JGmqj63+KaySnx/Ka1CvztbtIW8xThvGtzmoRNdVxX36YRn8kCo44WS+ZB4L1sK2pME0sO0czD4WioIqFrqPt4rh3b1Fc8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733455552; c=relaxed/simple; bh=8TwRzJ07cFwIQ2NazLrB11fm542Y4UBOvveW1k6rnJA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sKGiVW9yXYdComOiK5epUJBZvqlm+ZBb3ZSuWOrE7vMkup0YCZyqbMgbxkgDZWlGHCIT9o//cyZB09O4LeHLLlJtUzgxZrWPDRL4A2zy4AAyfyrbgECUVF8k1l19DPRPN+lW8EnXKKu8+2dWew8PPWwbc7ytOi7vb0U0fPQuhqc= 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=nZpj+5rj; arc=fail smtp.client-ip=40.107.96.75 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="nZpj+5rj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vFgL/waPV3PSJAWGquzWJ18fUIOiHOpIyvrLmlX94sFO+6qzKaUpxjqCWqASL8fimmeUm4aXAlvwZ7/Dz6Pfh7j2YV1jWyUaCiq/rcHvTClqXKUsDEB9yIeqT11pF5A+3oRInitnSe7WNg+G8G3IF+JuuTIfAGBJdGSFLoXNh95GKX+2bM8r/cTeQjTIcRZ4+Bc0Xz3v8R/W/FODl8J/AQVWAr9HScqqxI7iedP4aazYhltbdimX59+PRu+VAyiLnoqTzWtEtEHroqfnvon1fqiwTB/UIuKsSHjsXdc54kryQGGQ/1AqQKis+zKwTOylibbKRJmUcPJItICQ4YbQBw== 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=FNQgXoRM05ChHUpIFMIBYhAgUYaFBj/pG27lt9b+pes=; b=kd2OYMRKp0fOCtss0D7eFfCtCMbDgOUHOxbQdAXjGHy/RFHRCLtYxHb/Y6+K33pMcwwQMrxIVoegAp3OFqg7h5kpiGAMsiYgwm+uDZiurtThwMdFv1TkQxu9YKeDFhlWCp2f6ZKvCc+aV44voybxa0JeXd8eCczUaU8o9GX0TFQQFsyHWtvi/POv+WTA26chj2UWXpnUPyma1ENw9Utx2B75bLtqye6tHtTijLZRuFcb5mUfMCU696BTMr4VcnCbxrTHEztEvBVvw7TZkKoltJfoRVqrm+2Vs159Pd3gsUTwApsu7+dWl42LWpvdVo61eUw+6maI9YeiA5+BLifmjw== 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=FNQgXoRM05ChHUpIFMIBYhAgUYaFBj/pG27lt9b+pes=; b=nZpj+5rjRfzldwlkLqMwb6It9XDdRczcE6MX/0TjUXVVNDNN8YTHqY10MmEriTKpQJXCP3IvqkIdTYQGdUR4NVA/iErAtKIL7C375WWBR5A+zSSReNar/vBFyzDrK4C1ZC6nobLqkhXMIdfPkpbPiVW9k8x3+xU+/WLY2o3tLgg= Received: from PH7P221CA0090.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:328::25) by SA3PR12MB7782.namprd12.prod.outlook.com (2603:10b6:806:31c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.19; Fri, 6 Dec 2024 03:25:47 +0000 Received: from MWH0EPF000A6732.namprd04.prod.outlook.com (2603:10b6:510:328:cafe::1e) by PH7P221CA0090.outlook.office365.com (2603:10b6:510:328::25) 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:25:47 +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 MWH0EPF000A6732.mail.protection.outlook.com (10.167.249.24) 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:25:47 +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:10 -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 10/22] ACPI: platform_profile: Create class for ACPI platform profile Date: Thu, 5 Dec 2024 21:19:06 -0600 Message-ID: <20241206031918.1537-11-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: MWH0EPF000A6732:EE_|SA3PR12MB7782:EE_ X-MS-Office365-Filtering-Correlation-Id: 30ade6d1-c751-462b-bcc4-08dd15a5ad36 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|7416014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Dley494L0BX8oyeXDhTfzDejDx90AdG?= =?utf-8?q?djQ5OtC1gFdpaB7hTbbFtBbgJbOU8kjiMrVPxr79Nx2pZm6aRcSsm4+qeSDMcbZE6?= =?utf-8?q?yo46hyNlNplp5XeADhfFN3GMSia/v9LDGFQL/Bcj0+mdsEa2manE+ZuKLlbhdhwuD?= =?utf-8?q?qZz5eP5SOngp6obFzUCbcypvwZG/nZln/9ZdKB0yAVlTSUZChEqiRkuataNX47oFn?= =?utf-8?q?3C08+1roFCy9/C7Jcuy1dOSqJASxDZhKkF/AkG3dokpkzN2yVqa8UaQb9EL6Z5siH?= =?utf-8?q?aKBaiGwK76U157up93rt2Wdff2mQAs/abveaqI9SlmtkUWcglcbZQ9xEn+pgWoNiU?= =?utf-8?q?FZw85aOtKpijeq/4OoSCOo1VQJZXQXGKAUiJasJ/5SejO/Am0YW5gguPTK21udkCp?= =?utf-8?q?K2y9iGSLu45tKIsHCfXHZU6twWBNRRFoueZrss+nw/iHsQIc+y2ffNZPZEh9DsayL?= =?utf-8?q?vURRJDnRv2bs18VXU27cxqkZo0MzBqFi3sGBj+P04xn7UUbVseUMWhqr9Li0Ih/QG?= =?utf-8?q?JAv7tJGMxLkbV8rQrL+7dFea6fvhGknMXXDK5WpJkltHS5b51BjVeHjlDwda4XXXL?= =?utf-8?q?sZijeOWvOZPCZQ7459bAuOHtRFVfgdIWHwmqyDSO8Fx0xfDw8ypTpLPf0nVzcs/Z6?= =?utf-8?q?20lZWE2HXNdljBVC3p68vHnuypGtF8evdndUJCuaQcqtiPWv0E7q/W+SEhJv4Lx8H?= =?utf-8?q?LG05AFEaCMYh/ZXH8TNs4FDsws5814VK37UHb2dhujP22b96CI0M0UM5mOXcIqvhR?= =?utf-8?q?jSsjCAWL3Hif1pgSP/6mLSiFiKJ3PnQUuSpmGaBM29T/tz9wq+xmwBngXlT4+ZE8W?= =?utf-8?q?Q0yFJtIKpynC8bUGIVfVV68NijzxaA4mgj5fdSGp5lSXhvvN+PutRSNmXn9NCK08L?= =?utf-8?q?IibawqmTFpKPMGTx1DuKKJy0f/lMT+Q6ZMhhn1nL/gjYMDuJDS1AA8951yjY/nTwr?= =?utf-8?q?fvY3HtAOY+w2jm9tyz1hbrUMAri53fWIpx3eq/gAufda53wC452dPiWEeJm+r5Cry?= =?utf-8?q?2nC+B1Ib2rqiWtyZlR20Qjcs4uRCuLS7Rvd76hrWdQa2SEmhMW/oJhuA+zp603c58?= =?utf-8?q?ZrT9E2wcHZsv5mAFg5EckpUMgT6k7UhkKvMvGZdUmt3RKzPBNWwn7iqAu6bRHbKT0?= =?utf-8?q?Q/ln7YRZeslBDhaBaR3xegbh8NDkI8wsvBcgUjJwpzcXJB404y8AoE/YmRzH2F0Pw?= =?utf-8?q?Vr7Hrdx4+X78C3iFsGRTYR2NU0/4k3o8jc0A94XmLXKBcqdCpw1pWTpF59f9eLZ/c?= =?utf-8?q?Zp9c+/rbDDPXcXmf6BzpNENejNuCaoRdRFhY8qPyLJ7T4ElZ0D2fBd95ZU4GSopVv?= =?utf-8?q?xKZOoFqBGzy8Wr/Zx0OOScbYlBsvXpiogXSjzio5W/Hj0ozvayHg+t1SxtYYfaC34?= =?utf-8?q?6ree1FRr3SZ?= 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)(376014)(7416014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2024 03:25:47.4904 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 30ade6d1-c751-462b-bcc4-08dd15a5ad36 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: MWH0EPF000A6732.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7782 When registering a platform profile handler create a class device that will allow changing a single platform profile handler. The class and sysfs group are no longer needed when the platform profile core is a module and unloaded, so remove them at that time as well. Reviewed-by: Armin Wolf Tested-by: Mark Pearson Reviewed-by: Mark Pearson Reviewed-by: Ilpo Järvinen Signed-off-by: Mario Limonciello --- drivers/acpi/platform_profile.c | 82 ++++++++++++++++++++++++++++++-- include/linux/platform_profile.h | 2 + 2 files changed, 79 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c index a1f0378f15e62..11eb60b09bac4 100644 --- a/drivers/acpi/platform_profile.c +++ b/drivers/acpi/platform_profile.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,12 @@ static const char * const profile_names[] = { }; static_assert(ARRAY_SIZE(profile_names) == PLATFORM_PROFILE_LAST); +static DEFINE_IDA(platform_profile_ida); + +static const struct class platform_profile_class = { + .name = "platform-profile", +}; + static ssize_t platform_profile_choices_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -101,8 +108,21 @@ static struct attribute *platform_profile_attrs[] = { NULL }; +static int profile_class_registered(struct device *dev, const void *data) +{ + return 1; +} + +static umode_t profile_class_is_visible(struct kobject *kobj, struct attribute *attr, int idx) +{ + if (!class_find_device(&platform_profile_class, NULL, NULL, profile_class_registered)) + return 0; + return attr->mode; +} + static const struct attribute_group platform_profile_group = { - .attrs = platform_profile_attrs + .attrs = platform_profile_attrs, + .is_visible = profile_class_is_visible, }; void platform_profile_notify(struct platform_profile_handler *pprof) @@ -160,25 +180,77 @@ int platform_profile_register(struct platform_profile_handler *pprof) if (cur_profile) return -EEXIST; - err = sysfs_create_group(acpi_kobj, &platform_profile_group); - if (err) - return err; + /* create class interface for individual handler */ + pprof->minor = ida_alloc(&platform_profile_ida, GFP_KERNEL); + if (pprof->minor < 0) + return pprof->minor; + pprof->class_dev = device_create(&platform_profile_class, pprof->dev, + MKDEV(0, 0), pprof, "platform-profile-%d", + pprof->minor); + if (IS_ERR(pprof->class_dev)) { + err = PTR_ERR(pprof->class_dev); + goto cleanup_ida; + } cur_profile = pprof; + + err = sysfs_update_group(acpi_kobj, &platform_profile_group); + if (err) + goto cleanup_cur; + return 0; + +cleanup_cur: + cur_profile = NULL; + device_unregister(pprof->class_dev); + +cleanup_ida: + ida_free(&platform_profile_ida, pprof->minor); + + return err; } EXPORT_SYMBOL_GPL(platform_profile_register); int platform_profile_remove(struct platform_profile_handler *pprof) { + int id; guard(mutex)(&profile_lock); - sysfs_remove_group(acpi_kobj, &platform_profile_group); cur_profile = NULL; + + id = pprof->minor; + device_unregister(pprof->class_dev); + ida_free(&platform_profile_ida, id); + + sysfs_update_group(acpi_kobj, &platform_profile_group); + return 0; } EXPORT_SYMBOL_GPL(platform_profile_remove); +static int __init platform_profile_init(void) +{ + int err; + + err = class_register(&platform_profile_class); + if (err) + return err; + + err = sysfs_create_group(acpi_kobj, &platform_profile_group); + if (err) + class_unregister(&platform_profile_class); + + return err; +} + +static void __exit platform_profile_exit(void) +{ + sysfs_remove_group(acpi_kobj, &platform_profile_group); + class_unregister(&platform_profile_class); +} +module_init(platform_profile_init); +module_exit(platform_profile_exit); + MODULE_AUTHOR("Mark Pearson "); MODULE_DESCRIPTION("ACPI platform profile sysfs interface"); MODULE_LICENSE("GPL"); diff --git a/include/linux/platform_profile.h b/include/linux/platform_profile.h index 8ec0b8da56db5..a888fd085c513 100644 --- a/include/linux/platform_profile.h +++ b/include/linux/platform_profile.h @@ -29,6 +29,8 @@ enum platform_profile_option { struct platform_profile_handler { const char *name; struct device *dev; + struct device *class_dev; + int minor; unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)]; int (*profile_get)(struct platform_profile_handler *pprof, enum platform_profile_option *profile);