From nobody Fri Dec 19 00:53:39 2025 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2057.outbound.protection.outlook.com [40.107.237.57]) (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 E6A721C878E; Mon, 28 Apr 2025 06:30:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821861; cv=fail; b=C6JLYjuleEiz5vJ6h2K3bpUOoHlr3iudb+hOm3fqTWaVehW4AH1oW1A0defngoJb2k4+qoRt5/oonFNDuEgLihBXKaUO2TtAl1mqp4TVSXXXEjN+SpKMc0wL+3nmyKgee4ktLnSrVU65YCAR8Ij1p2K0tPC+PdYbdidtJEDD834= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821861; c=relaxed/simple; bh=U0r3uETX1km51zFmRoszMdSLaSs6tS9TBXnEVNOok+8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pR60ekYwnQ5eJFwLgjHiu3bn7KQciRbYvWhE6Ajm8QmPkZTQz29k+ZNVVDO6wQtxN3jA1eRlM67ZQjyHonpecO/O4X72CS4ciIMGwLLJe/78fxxqNUpOvOK0vfN5DPHCGA350USe10vLR7O6M0RQnVYF+Nj3xVI3/5H4tPmkypU= 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=dTK72NpG; arc=fail smtp.client-ip=40.107.237.57 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="dTK72NpG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kzhJyMYk9ghB+9e8BqYK2ZOuzNd95/6XBWavo2Tk+uDzqvnXFOTAQBJ+rbIb+fF7wBc4SR17Li/GS6yEBM8+9JOmpS6y0DON5AtD8bKD4tILAcui1dLHned66KHAcW4qeyBE0GO2TOuqIFPNkoWNFhXzzhpqMD6kqxf4munfEob5ERrPPJzciV86+tHeDa2belqgjgaPrUZp9RxPd4STDz+6o6cFJttOBD9RTqcHdQzEe0rMvKlA+vymFdJrnIUnsDIGlSWLIS/DGvof6pRfZftvCYL/WXL+XaE+ROYR+P3t1fbf1Pj0IxJPeRr3fqVi/c3V5PUrI70vUO3ZaR/TkQ== 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=XLyPdMhacxVIHD13lT49K3J74bdtcEX6Riy5Vz9C7SM=; b=vI0AONmSwNzUdqzkFbBt2Ee2hxIJBH70wEOwtS5R2Dh9juqO5CriKoFN6zgysuYAxtpYTB6oxbiz6ZcMW9MM3A++GycwvOs8i1MyZcZ4DtHFLQJPFSoGhf/vD9xgLlnuUYkY8F/ul+xzWv756Mm8Vj4w9UzIl89fuPa9sW6SW4k7Tty8kqIjI59TDgU2MMPwQnETv0r9ARwcP4OMK9YVsOjtnGmYn1DLbRWPCMtE9sdSfh+ox1+0a0BPxT12z2EQs+hJPYH/6EkgrTnUq9ffCBk087tNnMrTABmFvltMBTaX3Zaoq6Yyu/9Le0LNBWGvbYAQNGHyDUnDfcw4Hvnbpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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=XLyPdMhacxVIHD13lT49K3J74bdtcEX6Riy5Vz9C7SM=; b=dTK72NpGg7aGTRViSxLtxAZvnHY/fDSyhBe0vVXLoWXsNBHm44J4euNS8yKsjjxsUv/sxPy0EI9Zo6rRsP8J2t2CokzlfwdugSdqO/k7raULuy+YxJ8b/tg4ct1b/JrCcXo+4Ax00s3AzJyvhcn+kxtr7Oq74kdZsJ77vdR3CBI= Received: from PH7PR17CA0001.namprd17.prod.outlook.com (2603:10b6:510:324::25) by MN6PR12MB8568.namprd12.prod.outlook.com (2603:10b6:208:471::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8678.33; Mon, 28 Apr 2025 06:30:55 +0000 Received: from SN1PEPF0002BA52.namprd03.prod.outlook.com (2603:10b6:510:324:cafe::bb) by PH7PR17CA0001.outlook.office365.com (2603:10b6:510:324::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.37 via Frontend Transport; Mon, 28 Apr 2025 06:30:55 +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 SN1PEPF0002BA52.mail.protection.outlook.com (10.167.242.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8678.33 via Frontend Transport; Mon, 28 Apr 2025 06:30:55 +0000 Received: from amd.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; Mon, 28 Apr 2025 01:30:51 -0500 From: Akshay Gupta To: , CC: , , , , , , , , Akshay Gupta Subject: [PATCH v9 01/10] hwmon/misc: amd-sbi: Move core sbrmi from hwmon to misc Date: Mon, 28 Apr 2025 06:30:25 +0000 Message-ID: <20250428063034.2145566-2-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250428063034.2145566-1-akshay.gupta@amd.com> References: <20250428063034.2145566-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SN1PEPF0002BA52:EE_|MN6PR12MB8568:EE_ X-MS-Office365-Filtering-Correlation-Id: 7e0ea839-9f00-4718-995f-08dd861e3af0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?7pIRn18+ITOj5yaRJGmQXyJIoD7q6CXHuKCLxIDcw9hDuV+4ZspoSnryGTi5?= =?us-ascii?Q?Hb9rd8v+QYYR3lcT4nnu0wb0w3W0uTISyrLk8Kofu2VS2vF2c4I+SLPbdnUM?= =?us-ascii?Q?iQTB7RQkZAd+SKsEq8Ep4FqPoRk9dy5UpEzkntRbpLhiBs1fuRu0Rrb1I0vU?= =?us-ascii?Q?LKkF5pg2KnKBKDdoeMik9ZdWcccYx9TvxVCc0sR2boTD3FFiotJ3BeALxDWI?= =?us-ascii?Q?NBYYocHCINeAt1BfCrz4DC5fHVkwZyOd7DD/w154UNSMvQ8iKQAJFzTuolrt?= =?us-ascii?Q?9qAkidhpcsfMGIrka9msVxoPrg2n4CUhqsl+JsZVkWrREjMmDlEwBPCmST4q?= =?us-ascii?Q?aAJD02XfrQtswtrCLT029jlgnnjMtfypmI3mHIfAlT9sapRslO3gQL4malJk?= =?us-ascii?Q?Thyq5nlswgCtCDNZiHifHRMKrR6qIm48CZ/M6a/L4nA5gBtyLjH5GJWOs8q1?= =?us-ascii?Q?r8iegnV6RaC0OQmSMArfF1bfjqHz6zTTbQj2+dHmxUa4GS7g1EW0644is4O2?= =?us-ascii?Q?PxByRLWiYAesnJK/bby2BOTp4OWCFsJFF3wsFZSu1TtlCBVB7WNtPsefCCEA?= =?us-ascii?Q?00KiBtcdct/kuNDJL7Q8LrENTd9O4cQxKO3FRUt5Z73w2gOPzNYF0azThOnt?= =?us-ascii?Q?yO9xGciZEvD25kOSWtkEE0+N2nCr7bBMSabyspxr1YbJOSaVAfyrq90JGbCl?= =?us-ascii?Q?WFKFZsXYNf/jiqyUWoAne3CycICwYrrdlDMaEuL5LO6r/+Wy9T6B+KfN09Jb?= =?us-ascii?Q?tUcDxLcrgW6UxUd5dpYLqOm0o5h2Su1xVt/V7cxJxw+l+V/WAgRXY0OZXNlT?= =?us-ascii?Q?5vnFLzDl5rhWBu7SR7TXGo2pPZtmCtrvpEWVdrMKsbH6jBnAdvefLucDf8Us?= =?us-ascii?Q?CrmRcuJ1wVSM7A912Gz9LEAPUVuBE514+WK25cWzTfV/y2Nxc1M1g87jAwkU?= =?us-ascii?Q?d5KEYoKjrdIHTvy3x9EjdAQNoKwTmtBG4pqtCpPkV9vXe5QyLrHzu7Y3PU3D?= =?us-ascii?Q?/1EoYVjN5r4PZCLpgBRS+tRkJhRqr9Kc4syjHwPLHT5UWfkrNA5l02VzekyE?= =?us-ascii?Q?gXPxHQTnkR3R7de2tAKrtvTURSuEO1WhD9FrsHXNzmK54fjnTJDSVeePDUvH?= =?us-ascii?Q?z7MQQFkhE0M1dVr9kdxhFNxhDxqDV2rcD+YpqC8yixnPbCAQZvTBK5JPq4G6?= =?us-ascii?Q?GfPQ8U8SZPwcevXLt7dFC0/sq7Kyv3Jtgw/h94NCOR2VPF82WwWHD7MFkY7O?= =?us-ascii?Q?R21MA9SwIBcoSHCQMT83cmPwx0rbM0yK5qQ/kpYltS+X1YWFg1td1zOvbFpa?= =?us-ascii?Q?YN+WNxNXVjiHYSkjAvPyEZOvSep7Hc0YyY42cxIp+AfbMop4I9zdphGzdTXH?= =?us-ascii?Q?WW5iGSCWJrfys1/LIkmcloCWm0AwDUNf0tABpv4gukp0s9BmGsD2xj2oYxrJ?= =?us-ascii?Q?y8pp0C2aGnrKtVwCqvAEuQE1V4fQQFzwSTnlJb4a8rb6aq7bNg2SVYTkh+QI?= =?us-ascii?Q?uMtmf/+nOT1RdQWJjPdNMPG6HSxo345FIDby?= 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)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2025 06:30:55.1890 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7e0ea839-9f00-4718-995f-08dd861e3af0 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: SN1PEPF0002BA52.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8568 Content-Type: text/plain; charset="utf-8" This is done to support other functionality provided by the SBRMI, which does not fit in the hwmon subsystem. Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta Acked-by: Guenter Roeck --- Changes since v4: - Split in 3 new patches as per review comments 1. Bring drivers/hwmon to drivers/misc/amd-sbi 2. Move out the core functionality 3. Move out the hwmon functionality. Changes since v3: Rebase the patch Added Acked-by Changes since v2: Rebase the patch Changes since v1: - File name update - Add hwmon sensor registration in this patch - Update Copyright year drivers/hwmon/Kconfig | 10 ---------- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/amd-sbi/Kconfig | 9 +++++++++ drivers/misc/amd-sbi/Makefile | 2 ++ drivers/{hwmon =3D> misc/amd-sbi}/sbrmi.c | 0 6 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 drivers/misc/amd-sbi/Kconfig create mode 100644 drivers/misc/amd-sbi/Makefile rename drivers/{hwmon =3D> misc/amd-sbi}/sbrmi.c (100%) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index f91f713b0105..6ddc5f2b5338 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1887,16 +1887,6 @@ config SENSORS_SBTSI This driver can also be built as a module. If so, the module will be called sbtsi_temp. =20 -config SENSORS_SBRMI - tristate "Emulated SB-RMI sensor" - depends on I2C - help - If you say yes here you get support for emulated RMI - sensors on AMD SoCs with APML interface connected to a BMC device. - - This driver can also be built as a module. If so, the module will - be called sbrmi. - config SENSORS_SHT15 tristate "Sensiron humidity and temperature sensors. SHT15 and compat." depends on GPIOLIB || COMPILE_TEST diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 6b37d61150ee..9973cfd2ef5b 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -648,4 +648,5 @@ source "drivers/misc/uacce/Kconfig" source "drivers/misc/pvpanic/Kconfig" source "drivers/misc/mchp_pci1xxxx/Kconfig" source "drivers/misc/keba/Kconfig" +source "drivers/misc/amd-sbi/Kconfig" endmenu diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index d6c917229c45..3dc18bc69a53 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -74,3 +74,4 @@ lan966x-pci-objs :=3D lan966x_pci.o lan966x-pci-objs +=3D lan966x_pci.dtbo.o obj-$(CONFIG_MCHP_LAN966X_PCI) +=3D lan966x-pci.o obj-y +=3D keba/ +obj-y +=3D amd-sbi/ diff --git a/drivers/misc/amd-sbi/Kconfig b/drivers/misc/amd-sbi/Kconfig new file mode 100644 index 000000000000..be2d9e495eb7 --- /dev/null +++ b/drivers/misc/amd-sbi/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +config AMD_SBRMI_I2C + tristate "AMD side band RMI support" + depends on I2C + help + Side band RMI over I2C support for AMD out of band management. + + This driver can also be built as a module. If so, the module will + be called sbrmi-i2c. diff --git a/drivers/misc/amd-sbi/Makefile b/drivers/misc/amd-sbi/Makefile new file mode 100644 index 000000000000..304394bf5e59 --- /dev/null +++ b/drivers/misc/amd-sbi/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_AMD_SBRMI_I2C) +=3D sbrmi.o diff --git a/drivers/hwmon/sbrmi.c b/drivers/misc/amd-sbi/sbrmi.c similarity index 100% rename from drivers/hwmon/sbrmi.c rename to drivers/misc/amd-sbi/sbrmi.c --=20 2.25.1 From nobody Fri Dec 19 00:53:39 2025 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2077.outbound.protection.outlook.com [40.107.212.77]) (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 DC2EA1C8612; Mon, 28 Apr 2025 06:31:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821872; cv=fail; b=n/whkAq2rgCsAxNiMGd9QnrRQ+xoXimaWD4H0wmg0JFUWP/DPdf7fo3y3qQ2OBuWvLOu37+qW3ZQc81wAA52L8mSMzGoaKQ7z7Z0JIurGfN27flZquKs5ZibJA/3bZy/Yz90HTMqHE9J1wObv9ksHXMc13+uwFfPtKnKUz+DK4c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821872; c=relaxed/simple; bh=IO0EYlJ7bsAoCuzlB3+Wkxv8GWeMj39k89pPIF6cYP4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DJ4v19GVTQVIdxRBIBPcwLtRNzms2fXomlUlW2GC+zYPO5RdP90NdNOSkCMTtpCumhDObfKYJptvsH18t/OOuRGv/mc2UrcooQA5wZS10SZ6r5DBO9e3RTpcqTO8XwtkkFSmx2noqLh5tK4qG6hbsuRL+6mLnGCOudGePfJv14g= 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=KpnOU7wa; arc=fail smtp.client-ip=40.107.212.77 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="KpnOU7wa" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=V66xldR0Wys53dwAKcvsdOslo1f9sbbzHfEfGGXazrPNv8zQjbvsHEjNzSYuQcHTIVueKFgyCo6lfmTia946v0hd0ONKTTs58IgOepTmSRpLE4AFl3RiTl6V7vE4nl+Xl5dJUnh9NFZchVkDevrZM5VifOO2kSpdgjeyl6H6Pq5PXULSk9nY9JT3j9HJdMFnw8viOzoBTgsJ5MP3/qwGs1YePwwsbCK2+6o9OwgSCnRoFOs/Ohu5oG+XxQr2FW66wZdZJerfRhpxfawRLt3RofweW7qicPNyLU1qUk4/Zmz+4TDr0aVwy1joGdrmiq73aDh3pw3M9vxGpJZBsQmB2A== 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=rh7Vj4unT+uQoXiK0FYJz+e6kYTg2ceSDEeFnOH0FrQ=; b=BOsEX/+fF5VeJ5chxwxcObMlGsTWYx9GnwvH942utIr5o8cvc+Xur16C3hPIUlqvEs7BdbbMjodUB6ot7gS3/5TSbsBVSQdC7+YdCibHy7A+ZO+6P2a76el6i4CVVsV9gBYYyMus0zsDeE5ZETWyYoT6jEgEwAy/rZ1Qs6fPCLJZebRLCqj/WAOF/iTP3xrRN3MPxXbxXcUuYcGfMUBxJXBFw7JxioXPvxnsMmxE4pS9Kzbp1K4v1Crcbp+S7045WmfJuz/Oj2Gb+Nlr+m7gbBAi8AT5Q6Jf9tWsEqlNLF+WqR2ZVoZ9AKXq4JhBxdMb/wNP92RitIrBHHMVP+DeXg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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=rh7Vj4unT+uQoXiK0FYJz+e6kYTg2ceSDEeFnOH0FrQ=; b=KpnOU7wahfFiHKpK3TJqTsE8GvtH3uPi7CClJKB2koCxFoYCUVhpUWZVfG2yQlHjDEa08Qngy0vDz6G4wc6G+Fegm8RmMGkVARB2QGVqjhmmA+vIIyNYJerhkr5wpH14rjRMP96blWGrLiEa+HVSuzAOkUoqNVQx4PJ+ah+I4EQ= Received: from MW4PR03CA0051.namprd03.prod.outlook.com (2603:10b6:303:8e::26) by SN7PR12MB6813.namprd12.prod.outlook.com (2603:10b6:806:267::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8678.27; Mon, 28 Apr 2025 06:31:00 +0000 Received: from SN1PEPF0002BA4B.namprd03.prod.outlook.com (2603:10b6:303:8e:cafe::63) by MW4PR03CA0051.outlook.office365.com (2603:10b6:303:8e::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.41 via Frontend Transport; Mon, 28 Apr 2025 06:30:59 +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 SN1PEPF0002BA4B.mail.protection.outlook.com (10.167.242.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8678.33 via Frontend Transport; Mon, 28 Apr 2025 06:30:59 +0000 Received: from amd.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; Mon, 28 Apr 2025 01:30:55 -0500 From: Akshay Gupta To: , CC: , , , , , , , , Akshay Gupta Subject: [PATCH v9 02/10] misc: amd-sbi: Move protocol functionality to core file Date: Mon, 28 Apr 2025 06:30:26 +0000 Message-ID: <20250428063034.2145566-3-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250428063034.2145566-1-akshay.gupta@amd.com> References: <20250428063034.2145566-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SN1PEPF0002BA4B:EE_|SN7PR12MB6813:EE_ X-MS-Office365-Filtering-Correlation-Id: 76d19e28-d909-4d9d-4667-08dd861e3d8c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?/VRFpwZW3Sf8Vrw8r8nBqU0SkCzqsh41o+r7oupc+8+zlEyqW3gMgcEKGSPe?= =?us-ascii?Q?G+LrYxpgO7I56nbQ0wXw2olZ18eO0C6te8TmGVze7FuuHd8HdXBissuvRmed?= =?us-ascii?Q?a4fNhboETab9ZdF7/84uT+K/wBSOborLpKypxz3nTB9R13NsWrb+lH3XaxoV?= =?us-ascii?Q?bhG4DF7XYSQEGwJtO7FQyUiJoeO48EecN1QXIBCHE7Kc12eTCiSKeQu8TtlK?= =?us-ascii?Q?PvT/W3h/vKjicmLHSkGI3SGL83l1IKZKy7NpoHEhRK/ynKDoFHxq95jElwC6?= =?us-ascii?Q?QxzOfhGshKzLpl3AaNOW2gyId8zFvPjZAgNO4CIMkcgjn9748Rtic2C61ctC?= =?us-ascii?Q?mc0/3hrAIrgkbQgdoGB429h6d5GUQUTBUyW4kYuom39/vHGOOAUSzZzCEiHh?= =?us-ascii?Q?slct0GSx+4PUwBdfPyam/rCpWCUThMUoWEVVxYOCzTwvAQTgNWokSfIwqLS/?= =?us-ascii?Q?jhBHOOPraWeN64V+UY5JtyR80M6mmuPHaFEF0DjdCP5mFepmBKPdoATW1MpV?= =?us-ascii?Q?iT0qL4vRuwMTbxCOLfrhW4i+R74dl0zn1mnSvaHqfxdf+el6kEfrYruY6s/4?= =?us-ascii?Q?NUcwLqHzd5pD4SoYl+l+Oxsotzl399oKd5KY2DHjO0gtI+T4TxLV1OlTAHBz?= =?us-ascii?Q?0gKCmJNSfoMUAQlYqc+DP5FznAsesT3Dpgf88Vy61zf9O2kmLE6zlGvZoyKW?= =?us-ascii?Q?2TlsDgwoWHEg5jZPJSDU9//sfSNPJVu9CsCvJIw7VvRUS3XApvrvgRXzKVGM?= =?us-ascii?Q?dN6pLPhImFOJM3vPeN4ELaBUZA5mgx+6aNyoAZXEokjfYbWsS6c77ukY8t73?= =?us-ascii?Q?QF8e14YQXOiRkC1+ZqDl7/caJPykVCZDz8u2RxS5VCGcPwSt3WVX5B0Nd+Lw?= =?us-ascii?Q?AWRkLNO9ZKknCs31IwVexMfKfGfVw/Kh3flbg8NGjv5Hv7yxcak5N4oUgxU0?= =?us-ascii?Q?XHB1lHrAVZc9U/JbspYhM9OhDhpeNVfOZOXGZaNn2kLJFiGpENnx/P4lohLu?= =?us-ascii?Q?KlPEOJRrvBSfN6fspk2hoTK1gxlBBM/6MH0kCqyMfKC7pdeohlkj5J/YBrxm?= =?us-ascii?Q?VsZDItfUnvXFxlJOr65i0QzbwUiSQC2ow4dgmPWCqlaPnCTizxVM/AK4Orrh?= =?us-ascii?Q?QMgkwhZLaZMXM5hxAV5uSXMlIxeCnr18mnAsjvCKkPdT+HNed3CTyuE/ZzRi?= =?us-ascii?Q?3LK3mPet39p6hkzbLDwn3otEU2hn5pI4rM+toKzDVMWjYMyGIAcl8h6SlAdh?= =?us-ascii?Q?yTVpiniLt1O8OxC9tj27Kq1eYKMs6SdFpeCajh2m/XEPPlDbdgitzJk1N0t5?= =?us-ascii?Q?xu7Fql33V8VakwlKfLqj02YWF0bzSK4Lf3ltcN/d73b+w1cOx/weDu75vWqd?= =?us-ascii?Q?IWV9aIi+IcXd+WeVaXPhpE9/Hf7i0+fxhBdQUIPHgpeybv5RS8TtFc/v+7A8?= =?us-ascii?Q?kOuSIkhsFRyy9bFyGxjDfn4M+p1KCFyt47PnwAnrXLLdOyEz0JklQlhyUM53?= =?us-ascii?Q?9N2xG87SOmQzBOsSSEX3nEYTvf+tI7f3Nmno?= 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)(82310400026)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2025 06:30:59.5681 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 76d19e28-d909-4d9d-4667-08dd861e3d8c 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: SN1PEPF0002BA4B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6813 Content-Type: text/plain; charset="utf-8" - This is done to utilize the protocol functionality into other domains. - Increase the scalability of the module with different bus(i2c/i3c) Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v7: - Add dependency on hwmon subsystem Changes since v5: - Address kernel test robot error: - undefined reference to `devm_hwmon_device_register_with_info' Changes since v4: New patch: Patch split from v4 patch 1/9 - Update Copyright year to 2025 drivers/misc/amd-sbi/Kconfig | 9 +- drivers/misc/amd-sbi/Makefile | 3 +- drivers/misc/amd-sbi/rmi-core.c | 113 +++++++++++++ drivers/misc/amd-sbi/rmi-core.h | 63 ++++++++ drivers/misc/amd-sbi/{sbrmi.c =3D> rmi-i2c.c} | 166 ++------------------ 5 files changed, 192 insertions(+), 162 deletions(-) create mode 100644 drivers/misc/amd-sbi/rmi-core.c create mode 100644 drivers/misc/amd-sbi/rmi-core.h rename drivers/misc/amd-sbi/{sbrmi.c =3D> rmi-i2c.c} (53%) diff --git a/drivers/misc/amd-sbi/Kconfig b/drivers/misc/amd-sbi/Kconfig index be2d9e495eb7..0c8981f97f25 100644 --- a/drivers/misc/amd-sbi/Kconfig +++ b/drivers/misc/amd-sbi/Kconfig @@ -1,9 +1,10 @@ # SPDX-License-Identifier: GPL-2.0-only config AMD_SBRMI_I2C - tristate "AMD side band RMI support" - depends on I2C - help - Side band RMI over I2C support for AMD out of band management. + tristate "AMD side band RMI support" + depends on I2C + depends on HWMON + help + Side band RMI over I2C support for AMD out of band management. =20 This driver can also be built as a module. If so, the module will be called sbrmi-i2c. diff --git a/drivers/misc/amd-sbi/Makefile b/drivers/misc/amd-sbi/Makefile index 304394bf5e59..7cd8e0a1aa5d 100644 --- a/drivers/misc/amd-sbi/Makefile +++ b/drivers/misc/amd-sbi/Makefile @@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_AMD_SBRMI_I2C) +=3D sbrmi.o +sbrmi-i2c-objs :=3D rmi-i2c.o rmi-core.o +obj-$(CONFIG_AMD_SBRMI_I2C) +=3D sbrmi-i2c.o diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-cor= e.c new file mode 100644 index 000000000000..74456756270c --- /dev/null +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * sbrmi-core.c - file defining SB-RMI protocols compliant + * AMD SoC device. + * + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ +#include +#include +#include +#include +#include "rmi-core.h" + +/* Mask for Status Register bit[1] */ +#define SW_ALERT_MASK 0x2 + +/* Software Interrupt for triggering */ +#define START_CMD 0x80 +#define TRIGGER_MAILBOX 0x01 + +int rmi_mailbox_xfer(struct sbrmi_data *data, + struct sbrmi_mailbox_msg *msg) +{ + int i, ret, retry =3D 10; + int sw_status; + u8 byte; + + mutex_lock(&data->lock); + + /* Indicate firmware a command is to be serviced */ + ret =3D i2c_smbus_write_byte_data(data->client, + SBRMI_INBNDMSG7, START_CMD); + if (ret < 0) + goto exit_unlock; + + /* Write the command to SBRMI::InBndMsg_inst0 */ + ret =3D i2c_smbus_write_byte_data(data->client, + SBRMI_INBNDMSG0, msg->cmd); + if (ret < 0) + goto exit_unlock; + + /* + * For both read and write the initiator (BMC) writes + * Command Data In[31:0] to SBRMI::InBndMsg_inst[4:1] + * SBRMI_x3C(MSB):SBRMI_x39(LSB) + */ + for (i =3D 0; i < 4; i++) { + byte =3D (msg->data_in >> i * 8) & 0xff; + ret =3D i2c_smbus_write_byte_data(data->client, + SBRMI_INBNDMSG1 + i, byte); + if (ret < 0) + goto exit_unlock; + } + + /* + * Write 0x01 to SBRMI::SoftwareInterrupt to notify firmware to + * perform the requested read or write command + */ + ret =3D i2c_smbus_write_byte_data(data->client, + SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); + if (ret < 0) + goto exit_unlock; + + /* + * Firmware will write SBRMI::Status[SwAlertSts]=3D1 to generate + * an ALERT (if enabled) to initiator (BMC) to indicate completion + * of the requested command + */ + do { + sw_status =3D i2c_smbus_read_byte_data(data->client, + SBRMI_STATUS); + if (sw_status < 0) { + ret =3D sw_status; + goto exit_unlock; + } + if (sw_status & SW_ALERT_MASK) + break; + usleep_range(50, 100); + } while (retry--); + + if (retry < 0) { + dev_err(&data->client->dev, + "Firmware fail to indicate command completion\n"); + ret =3D -EIO; + goto exit_unlock; + } + + /* + * For a read operation, the initiator (BMC) reads the firmware + * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1] + * {SBRMI_x34(MSB):SBRMI_x31(LSB)}. + */ + if (msg->read) { + for (i =3D 0; i < 4; i++) { + ret =3D i2c_smbus_read_byte_data(data->client, + SBRMI_OUTBNDMSG1 + i); + if (ret < 0) + goto exit_unlock; + msg->data_out |=3D ret << i * 8; + } + } + + /* + * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the + * ALERT to initiator + */ + ret =3D i2c_smbus_write_byte_data(data->client, SBRMI_STATUS, + sw_status | SW_ALERT_MASK); + +exit_unlock: + mutex_unlock(&data->lock); + return ret; +} diff --git a/drivers/misc/amd-sbi/rmi-core.h b/drivers/misc/amd-sbi/rmi-cor= e.h new file mode 100644 index 000000000000..8e30a43ec714 --- /dev/null +++ b/drivers/misc/amd-sbi/rmi-core.h @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#ifndef _SBRMI_CORE_H_ +#define _SBRMI_CORE_H_ + +#include +#include +#include + +/* SB-RMI registers */ +enum sbrmi_reg { + SBRMI_CTRL =3D 0x01, + SBRMI_STATUS, + SBRMI_OUTBNDMSG0 =3D 0x30, + SBRMI_OUTBNDMSG1, + SBRMI_OUTBNDMSG2, + SBRMI_OUTBNDMSG3, + SBRMI_OUTBNDMSG4, + SBRMI_OUTBNDMSG5, + SBRMI_OUTBNDMSG6, + SBRMI_OUTBNDMSG7, + SBRMI_INBNDMSG0, + SBRMI_INBNDMSG1, + SBRMI_INBNDMSG2, + SBRMI_INBNDMSG3, + SBRMI_INBNDMSG4, + SBRMI_INBNDMSG5, + SBRMI_INBNDMSG6, + SBRMI_INBNDMSG7, + SBRMI_SW_INTERRUPT, +}; + +/* + * SB-RMI supports soft mailbox service request to MP1 (power management + * firmware) through SBRMI inbound/outbound message registers. + * SB-RMI message IDs + */ +enum sbrmi_msg_id { + SBRMI_READ_PKG_PWR_CONSUMPTION =3D 0x1, + SBRMI_WRITE_PKG_PWR_LIMIT, + SBRMI_READ_PKG_PWR_LIMIT, + SBRMI_READ_PKG_MAX_PWR_LIMIT, +}; + +/* Each client has this additional data */ +struct sbrmi_data { + struct i2c_client *client; + struct mutex lock; + u32 pwr_limit_max; +}; + +struct sbrmi_mailbox_msg { + u8 cmd; + bool read; + u32 data_in; + u32 data_out; +}; + +int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *ms= g); +#endif /*_SBRMI_CORE_H_*/ diff --git a/drivers/misc/amd-sbi/sbrmi.c b/drivers/misc/amd-sbi/rmi-i2c.c similarity index 53% rename from drivers/misc/amd-sbi/sbrmi.c rename to drivers/misc/amd-sbi/rmi-i2c.c index d48d8e5460ff..6412f00eb381 100644 --- a/drivers/misc/amd-sbi/sbrmi.c +++ b/drivers/misc/amd-sbi/rmi-i2c.c @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * sbrmi.c - hwmon driver for a SB-RMI mailbox - * compliant AMD SoC device. + * rmi-i2c.c - Side band RMI over I2C support for AMD out + * of band management * - * Copyright (C) 2020-2021 Advanced Micro Devices, Inc. + * Copyright (C) 2024 Advanced Micro Devices, Inc. */ =20 #include @@ -14,64 +14,10 @@ #include #include #include +#include "rmi-core.h" =20 /* Do not allow setting negative power limit */ #define SBRMI_PWR_MIN 0 -/* Mask for Status Register bit[1] */ -#define SW_ALERT_MASK 0x2 - -/* Software Interrupt for triggering */ -#define START_CMD 0x80 -#define TRIGGER_MAILBOX 0x01 - -/* - * SB-RMI supports soft mailbox service request to MP1 (power management - * firmware) through SBRMI inbound/outbound message registers. - * SB-RMI message IDs - */ -enum sbrmi_msg_id { - SBRMI_READ_PKG_PWR_CONSUMPTION =3D 0x1, - SBRMI_WRITE_PKG_PWR_LIMIT, - SBRMI_READ_PKG_PWR_LIMIT, - SBRMI_READ_PKG_MAX_PWR_LIMIT, -}; - -/* SB-RMI registers */ -enum sbrmi_reg { - SBRMI_CTRL =3D 0x01, - SBRMI_STATUS, - SBRMI_OUTBNDMSG0 =3D 0x30, - SBRMI_OUTBNDMSG1, - SBRMI_OUTBNDMSG2, - SBRMI_OUTBNDMSG3, - SBRMI_OUTBNDMSG4, - SBRMI_OUTBNDMSG5, - SBRMI_OUTBNDMSG6, - SBRMI_OUTBNDMSG7, - SBRMI_INBNDMSG0, - SBRMI_INBNDMSG1, - SBRMI_INBNDMSG2, - SBRMI_INBNDMSG3, - SBRMI_INBNDMSG4, - SBRMI_INBNDMSG5, - SBRMI_INBNDMSG6, - SBRMI_INBNDMSG7, - SBRMI_SW_INTERRUPT, -}; - -/* Each client has this additional data */ -struct sbrmi_data { - struct i2c_client *client; - struct mutex lock; - u32 pwr_limit_max; -}; - -struct sbrmi_mailbox_msg { - u8 cmd; - bool read; - u32 data_in; - u32 data_out; -}; =20 static int sbrmi_enable_alert(struct i2c_client *client) { @@ -94,100 +40,6 @@ static int sbrmi_enable_alert(struct i2c_client *client) return 0; } =20 -static int rmi_mailbox_xfer(struct sbrmi_data *data, - struct sbrmi_mailbox_msg *msg) -{ - int i, ret, retry =3D 10; - int sw_status; - u8 byte; - - mutex_lock(&data->lock); - - /* Indicate firmware a command is to be serviced */ - ret =3D i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG7, START_CMD); - if (ret < 0) - goto exit_unlock; - - /* Write the command to SBRMI::InBndMsg_inst0 */ - ret =3D i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG0, msg->cmd); - if (ret < 0) - goto exit_unlock; - - /* - * For both read and write the initiator (BMC) writes - * Command Data In[31:0] to SBRMI::InBndMsg_inst[4:1] - * SBRMI_x3C(MSB):SBRMI_x39(LSB) - */ - for (i =3D 0; i < 4; i++) { - byte =3D (msg->data_in >> i * 8) & 0xff; - ret =3D i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG1 + i, byte); - if (ret < 0) - goto exit_unlock; - } - - /* - * Write 0x01 to SBRMI::SoftwareInterrupt to notify firmware to - * perform the requested read or write command - */ - ret =3D i2c_smbus_write_byte_data(data->client, - SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); - if (ret < 0) - goto exit_unlock; - - /* - * Firmware will write SBRMI::Status[SwAlertSts]=3D1 to generate - * an ALERT (if enabled) to initiator (BMC) to indicate completion - * of the requested command - */ - do { - sw_status =3D i2c_smbus_read_byte_data(data->client, - SBRMI_STATUS); - if (sw_status < 0) { - ret =3D sw_status; - goto exit_unlock; - } - if (sw_status & SW_ALERT_MASK) - break; - usleep_range(50, 100); - } while (retry--); - - if (retry < 0) { - dev_err(&data->client->dev, - "Firmware fail to indicate command completion\n"); - ret =3D -EIO; - goto exit_unlock; - } - - /* - * For a read operation, the initiator (BMC) reads the firmware - * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1] - * {SBRMI_x34(MSB):SBRMI_x31(LSB)}. - */ - if (msg->read) { - for (i =3D 0; i < 4; i++) { - ret =3D i2c_smbus_read_byte_data(data->client, - SBRMI_OUTBNDMSG1 + i); - if (ret < 0) - goto exit_unlock; - msg->data_out |=3D ret << i * 8; - } - } - - /* - * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the - * ALERT to initiator - */ - ret =3D i2c_smbus_write_byte_data(data->client, SBRMI_STATUS, - sw_status | SW_ALERT_MASK); - -exit_unlock: - mutex_unlock(&data->lock); - return ret; -} - static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { @@ -297,7 +149,7 @@ static int sbrmi_get_max_pwr_limit(struct sbrmi_data *d= ata) return ret; } =20 -static int sbrmi_probe(struct i2c_client *client) +static int sbrmi_i2c_probe(struct i2c_client *client) { struct device *dev =3D &client->dev; struct device *hwmon_dev; @@ -323,12 +175,11 @@ static int sbrmi_probe(struct i2c_client *client) =20 hwmon_dev =3D devm_hwmon_device_register_with_info(dev, client->name, dat= a, &sbrmi_chip_info, NULL); - return PTR_ERR_OR_ZERO(hwmon_dev); } =20 static const struct i2c_device_id sbrmi_id[] =3D { - {"sbrmi"}, + {"sbrmi-i2c"}, {} }; MODULE_DEVICE_TABLE(i2c, sbrmi_id); @@ -343,15 +194,16 @@ MODULE_DEVICE_TABLE(of, sbrmi_of_match); =20 static struct i2c_driver sbrmi_driver =3D { .driver =3D { - .name =3D "sbrmi", + .name =3D "sbrmi-i2c", .of_match_table =3D of_match_ptr(sbrmi_of_match), }, - .probe =3D sbrmi_probe, + .probe =3D sbrmi_i2c_probe, .id_table =3D sbrmi_id, }; =20 module_i2c_driver(sbrmi_driver); =20 MODULE_AUTHOR("Akshay Gupta "); +MODULE_AUTHOR("Naveen Krishna Chatradhi "= ); MODULE_DESCRIPTION("Hwmon driver for AMD SB-RMI emulated sensor"); MODULE_LICENSE("GPL"); --=20 2.25.1 From nobody Fri Dec 19 00:53:39 2025 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2085.outbound.protection.outlook.com [40.107.92.85]) (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 8A4391D07BA; Mon, 28 Apr 2025 06:31:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821878; cv=fail; b=YuktO+HypYOWcSuPBjv793RN4S/TqRujS+0GASHG6yxroZigWtWb3BvmWUZ+3kKoOqg3/Jt83G6Bb8/DvLVUmRaYFN24sVvWnTqSYQ+L41LdhpNwH4KJBp2IqzocMLwvIdvzcKFEGrekZfcUfEaDqtqVzlAYMqC3WySrfKuNSfc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821878; c=relaxed/simple; bh=e/DWYp8yCWjO9OvYcRVnT0RsunCILDOAorbjnyzXtz0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MR5fGAqH3QiaFFu+tNPXGUczqh6TCdBJacCOPa8j+DSyivGzGKztgETrwpF9IBI2lcv2WvQl6f9OK9H6mh1IfSbF6h2M0hj8UqlXFwQc2Dp9YoY65akUaB69NIyGasQYhb1C52l0mgjLChCX20kN25iDjhgfW/vxv4FGQZQLAPQ= 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=tZ4LuJxQ; arc=fail smtp.client-ip=40.107.92.85 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="tZ4LuJxQ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nYN1Om1Zog87lPXGXhMkvb/MPvDgUct5yB+Cq9mFe01QIQcE+LZCXJ5oWTxvWprTV/jnylx3euTgOqZYIc5Ep011RV2sV+kKPQAMXPtbO1Ri56xwdOKV2ISuzt7W5yupvTuz3wc4ApLl8dMLwHzULPLvWrGuBfCs+Ph+NFcfka7mREVY8opcs63YCCYadRjlEuVBZIv20kYKXeDIhwGDzbWYXs3a1ynEnf66SrSZ5Mfxyb3GrkB468yFIVNV3N4Z2O3izK67Fp7oI93djfFOpMDWrfCFRg07ptjLhMv0DISTClzNnJcf1QnnRl3VbRa6K8fel4KbD790KWKCbnT3fQ== 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=Lo2ow+x214OSNQ448/bD6Pd9nvg/HePgjYmC5XUwpWQ=; b=lX6C+8dj1eTfRCGdVlMGSxbjDtt1fXaCF6mj2z1PGGtGhv3k3McLjUYfG66135OGvFuCRAzo634QMGuIuQ2gVlDf4Wup6wxqMWzSFKKO3bWofbNJ0CnDRCj4aaJBNHCuDt09j90Mo4Trcp8MTowoOheBgnLm0zArZTpJxkQ/K4h75SMH0FNZY+yIOIaq08t4w8Zy3SYERYFxq+CK+lKc64WzYvD9+2hjEKSVg75oCah9tzl9HzySaZJA5MZkXZlxxjNcYXQFooLmrLpL5Bqy/aVr3iokK9cUREf4dieMiRszNX2mQlTTh1xy+jqVnrFAOTdWwx1DMESmiYo+X4TmzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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=Lo2ow+x214OSNQ448/bD6Pd9nvg/HePgjYmC5XUwpWQ=; b=tZ4LuJxQb0rHU93wK799NMMCKaeQXBI1zXCWgNIyrA6U/PrLax4rTb+nQlUu7eF6Nj3cLaybV7qzw9P15aDQszVXjUxPGKhp5M40ba2bIqNGGcn9fN0rzOm95nZy5jORj/6Ym8nU6WXIav25CuQtBFp822AA21S5jNk8Lz1wF24= Received: from MW4PR03CA0038.namprd03.prod.outlook.com (2603:10b6:303:8e::13) by MN2PR12MB4175.namprd12.prod.outlook.com (2603:10b6:208:1d3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8678.29; Mon, 28 Apr 2025 06:31:09 +0000 Received: from SN1PEPF0002BA4B.namprd03.prod.outlook.com (2603:10b6:303:8e:cafe::8e) by MW4PR03CA0038.outlook.office365.com (2603:10b6:303:8e::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.36 via Frontend Transport; Mon, 28 Apr 2025 06:31:08 +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 SN1PEPF0002BA4B.mail.protection.outlook.com (10.167.242.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8678.33 via Frontend Transport; Mon, 28 Apr 2025 06:31:08 +0000 Received: from amd.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; Mon, 28 Apr 2025 01:30:59 -0500 From: Akshay Gupta To: , CC: , , , , , , , , Akshay Gupta Subject: [PATCH v9 03/10] misc: amd-sbi: Move hwmon device sensor as separate entity Date: Mon, 28 Apr 2025 06:30:27 +0000 Message-ID: <20250428063034.2145566-4-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250428063034.2145566-1-akshay.gupta@amd.com> References: <20250428063034.2145566-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SN1PEPF0002BA4B:EE_|MN2PR12MB4175:EE_ X-MS-Office365-Filtering-Correlation-Id: 30640314-2451-46ff-9ed2-08dd861e42c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?gAwfRbT4T9BKzyBR9aZ0P+J5CUp9jv/GXSi2MZr+KL/+u+vVf5hzk5L98s4q?= =?us-ascii?Q?jM3I+cx3rf7iBK4Ys6AUnDrElaw0/8Ghs5r+Gi5VRpRgYaf0JPyOyWSplVWJ?= =?us-ascii?Q?c7oHn4a6gb8CKczWK+kYpP/2SQYR5Dpgh4h9JFHdpEjNIVREUQ4IeCU7gHIP?= =?us-ascii?Q?KAYbY5exZaZoRaoqKRdnUAiTg21kodJnEV25bB2BfKeoTPWAATfRKk25+2/F?= =?us-ascii?Q?uyq75Ag0b3GCXEGmKZ5BEl9ZGl2ulVMak6lrO/Of73iUA7sMbz7l8qO4oKK6?= =?us-ascii?Q?uVajaP2PW7eiIOGWmuJu0OUVBbGu+qLHkszPP0o/gVKgpoEYwp/+s++7selF?= =?us-ascii?Q?XT93whZiYxIHX9oMSk/en1JF6DmeoWBU7mAppKKYcsK/5JXyx58/W7dlf0Gr?= =?us-ascii?Q?QM0qIr4VS68jDeZh3kIFP95JQ20B6KfbvRHlAcFOMYRoBpavV0egna4kCyns?= =?us-ascii?Q?EReLvCgv141V7FkgvhURSo1kLVGNoQ6mCbmY4C76WAiC0G64zD5KVnwx3TQt?= =?us-ascii?Q?3TbXQdWhKRtWDcL0/vkedDQTzfFfuEu/raWBpsndOhtiPlZTHhAhB1DtxQpa?= =?us-ascii?Q?NKuBpJ/y9YPE15u6doHsOrvmCi7zQkBbn1MmbETuLh8ZNymoz4Wb7lpg/h0b?= =?us-ascii?Q?kXwZEPVIryKKl9ckEr61hVAZ3cWZI2cQwozMDlvo5Mpbt5v0R2ec1ghRLwt+?= =?us-ascii?Q?xFYecDKuKksM06BEZAjGYGxKqNEZMOIHTxkIE14EL8tZrcvd+6jE/YI255NZ?= =?us-ascii?Q?xD23qV7kcmxGRrAtflXPh/GVuwOFLLMen+ko+F8HNjrht17PQXE8gSsJBLL0?= =?us-ascii?Q?OkDdyAe2c19WxtrcYIb1FqyQg1aFutTzT69xGuAYU4pLrB9Y6zVwnCLgg3oZ?= =?us-ascii?Q?67HujR5WSLGqLnExmNYA4peXkBRyiGGELtLSHLI9s/jRCMHPyhahNatVJXrT?= =?us-ascii?Q?+zAHTnWkmD8b4+yHXaA2R8tQsl2lHMcFgiK5vKzogb/Y61QMMUw37eyoppsH?= =?us-ascii?Q?MKkAUyguKH0A+yqerP0AUQjMxxl1WwxGYVv05UmGwhlO6n8k4gAwgdq+Tfdp?= =?us-ascii?Q?NP3ZUrcAzOlpS7jaV4JE0254ogvHpCJCBv+S2/RLOeyfhH+sPWIXrhqkfVMf?= =?us-ascii?Q?N67QjuMJCKhjb3FOfFzjoZBResZNlz+3Y/kmxSED7urqNeD0/X1mlUsupA1W?= =?us-ascii?Q?bbRI5BAPk0M/pvlVmWHitzPelQyhG4MQjQBPiFs8C8D74zjKCiPM89y+7DCi?= =?us-ascii?Q?c274G6BcT8dIXj9uYufG5Z+dDVPey5x4EbGeBM2puxFL315Uec8AFPl+F6Ud?= =?us-ascii?Q?23ovgOJDpZoiN1tLu/X1ogpw3p+3vNKTvgsfCcNxcUIrdxd/7ehUBcZKi8XO?= =?us-ascii?Q?24OmdlrgkKs9mgPgVIjs5M+GhDOWwORE9FKisWRLNj0EX4o21t/cwdMtVZj/?= =?us-ascii?Q?Uros5Fgxtgy5QJH19TNuxFgXPOzlK1WSjZav72cqdG6M4yMlSiBDlU/6+0TE?= =?us-ascii?Q?z3FQ6yw+Qc18q32nk07ewqhXqyxTjtuKpTSV?= 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)(36860700013)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2025 06:31:08.2993 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 30640314-2451-46ff-9ed2-08dd861e42c0 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: SN1PEPF0002BA4B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4175 Content-Type: text/plain; charset="utf-8" - Move hwmon device sensor to misc as only power is reported through hwmon sensor. Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v7: - Address Arnd review comment, adding new Kconfig symbol for hwmon enableme= nt Changes since v6: - Fix "Missing a blank line after declarations" warning Changes since v5: - Patch rebased Changes since v4: New patch: Patch split from v4 patch 1/9 - Update Copyright year to 2025 drivers/misc/amd-sbi/Kconfig | 10 ++- drivers/misc/amd-sbi/Makefile | 3 +- drivers/misc/amd-sbi/rmi-core.h | 8 ++ drivers/misc/amd-sbi/rmi-hwmon.c | 121 +++++++++++++++++++++++++++++++ drivers/misc/amd-sbi/rmi-i2c.c | 104 +------------------------- 5 files changed, 142 insertions(+), 104 deletions(-) create mode 100644 drivers/misc/amd-sbi/rmi-hwmon.c diff --git a/drivers/misc/amd-sbi/Kconfig b/drivers/misc/amd-sbi/Kconfig index 0c8981f97f25..4840831c84ca 100644 --- a/drivers/misc/amd-sbi/Kconfig +++ b/drivers/misc/amd-sbi/Kconfig @@ -2,9 +2,17 @@ config AMD_SBRMI_I2C tristate "AMD side band RMI support" depends on I2C - depends on HWMON help Side band RMI over I2C support for AMD out of band management. =20 This driver can also be built as a module. If so, the module will be called sbrmi-i2c. + +config AMD_SBRMI_HWMON + bool "SBRMI hardware monitoring" + depends on AMD_SBRMI_I2C && HWMON + depends on !(AMD_SBRMI_I2C=3Dy && HWMON=3Dm) + help + This provides support for RMI device hardware monitoring. If enabled, + a hardware monitoring device will be created for each socket in + the system. diff --git a/drivers/misc/amd-sbi/Makefile b/drivers/misc/amd-sbi/Makefile index 7cd8e0a1aa5d..38eaaa651fd9 100644 --- a/drivers/misc/amd-sbi/Makefile +++ b/drivers/misc/amd-sbi/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only -sbrmi-i2c-objs :=3D rmi-i2c.o rmi-core.o +sbrmi-i2c-objs +=3D rmi-i2c.o rmi-core.o +sbrmi-i2c-$(CONFIG_AMD_SBRMI_HWMON) +=3D rmi-hwmon.o obj-$(CONFIG_AMD_SBRMI_I2C) +=3D sbrmi-i2c.o diff --git a/drivers/misc/amd-sbi/rmi-core.h b/drivers/misc/amd-sbi/rmi-cor= e.h index 8e30a43ec714..977ee05af6a6 100644 --- a/drivers/misc/amd-sbi/rmi-core.h +++ b/drivers/misc/amd-sbi/rmi-core.h @@ -60,4 +60,12 @@ struct sbrmi_mailbox_msg { }; =20 int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *ms= g); +#ifdef CONFIG_AMD_SBRMI_HWMON +int create_hwmon_sensor_device(struct device *dev, struct sbrmi_data *data= ); +#else +static inline int create_hwmon_sensor_device(struct device *dev, struct sb= rmi_data *data) +{ + return 0; +} +#endif #endif /*_SBRMI_CORE_H_*/ diff --git a/drivers/misc/amd-sbi/rmi-hwmon.c b/drivers/misc/amd-sbi/rmi-hw= mon.c new file mode 100644 index 000000000000..720e800db1f0 --- /dev/null +++ b/drivers/misc/amd-sbi/rmi-hwmon.c @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * rmi-hwmon.c - hwmon sensor support for side band RMI + * + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ +#include +#include +#include "rmi-core.h" + +/* Do not allow setting negative power limit */ +#define SBRMI_PWR_MIN 0 + +static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + struct sbrmi_data *data =3D dev_get_drvdata(dev); + struct sbrmi_mailbox_msg msg =3D { 0 }; + int ret; + + if (!data) + return -ENODEV; + + if (type !=3D hwmon_power) + return -EINVAL; + + msg.read =3D true; + switch (attr) { + case hwmon_power_input: + msg.cmd =3D SBRMI_READ_PKG_PWR_CONSUMPTION; + ret =3D rmi_mailbox_xfer(data, &msg); + break; + case hwmon_power_cap: + msg.cmd =3D SBRMI_READ_PKG_PWR_LIMIT; + ret =3D rmi_mailbox_xfer(data, &msg); + break; + case hwmon_power_cap_max: + msg.data_out =3D data->pwr_limit_max; + ret =3D 0; + break; + default: + return -EINVAL; + } + if (ret < 0) + return ret; + /* hwmon power attributes are in microWatt */ + *val =3D (long)msg.data_out * 1000; + return ret; +} + +static int sbrmi_write(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long val) +{ + struct sbrmi_data *data =3D dev_get_drvdata(dev); + struct sbrmi_mailbox_msg msg =3D { 0 }; + + if (!data) + return -ENODEV; + + if (type !=3D hwmon_power && attr !=3D hwmon_power_cap) + return -EINVAL; + /* + * hwmon power attributes are in microWatt + * mailbox read/write is in mWatt + */ + val /=3D 1000; + + val =3D clamp_val(val, SBRMI_PWR_MIN, data->pwr_limit_max); + + msg.cmd =3D SBRMI_WRITE_PKG_PWR_LIMIT; + msg.data_in =3D val; + msg.read =3D false; + + return rmi_mailbox_xfer(data, &msg); +} + +static umode_t sbrmi_is_visible(const void *data, + enum hwmon_sensor_types type, + u32 attr, int channel) +{ + switch (type) { + case hwmon_power: + switch (attr) { + case hwmon_power_input: + case hwmon_power_cap_max: + return 0444; + case hwmon_power_cap: + return 0644; + } + break; + default: + break; + } + return 0; +} + +static const struct hwmon_channel_info * const sbrmi_info[] =3D { + HWMON_CHANNEL_INFO(power, + HWMON_P_INPUT | HWMON_P_CAP | HWMON_P_CAP_MAX), + NULL +}; + +static const struct hwmon_ops sbrmi_hwmon_ops =3D { + .is_visible =3D sbrmi_is_visible, + .read =3D sbrmi_read, + .write =3D sbrmi_write, +}; + +static const struct hwmon_chip_info sbrmi_chip_info =3D { + .ops =3D &sbrmi_hwmon_ops, + .info =3D sbrmi_info, +}; + +int create_hwmon_sensor_device(struct device *dev, struct sbrmi_data *data) +{ + struct device *hwmon_dev; + + hwmon_dev =3D devm_hwmon_device_register_with_info(dev, "sbrmi", data, + &sbrmi_chip_info, NULL); + return PTR_ERR_OR_ZERO(hwmon_dev); +} diff --git a/drivers/misc/amd-sbi/rmi-i2c.c b/drivers/misc/amd-sbi/rmi-i2c.c index 6412f00eb381..9ad4c8093399 100644 --- a/drivers/misc/amd-sbi/rmi-i2c.c +++ b/drivers/misc/amd-sbi/rmi-i2c.c @@ -8,7 +8,6 @@ =20 #include #include -#include #include #include #include @@ -16,9 +15,6 @@ #include #include "rmi-core.h" =20 -/* Do not allow setting negative power limit */ -#define SBRMI_PWR_MIN 0 - static int sbrmi_enable_alert(struct i2c_client *client) { int ctrl; @@ -40,100 +36,6 @@ static int sbrmi_enable_alert(struct i2c_client *client) return 0; } =20 -static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, - u32 attr, int channel, long *val) -{ - struct sbrmi_data *data =3D dev_get_drvdata(dev); - struct sbrmi_mailbox_msg msg =3D { 0 }; - int ret; - - if (type !=3D hwmon_power) - return -EINVAL; - - msg.read =3D true; - switch (attr) { - case hwmon_power_input: - msg.cmd =3D SBRMI_READ_PKG_PWR_CONSUMPTION; - ret =3D rmi_mailbox_xfer(data, &msg); - break; - case hwmon_power_cap: - msg.cmd =3D SBRMI_READ_PKG_PWR_LIMIT; - ret =3D rmi_mailbox_xfer(data, &msg); - break; - case hwmon_power_cap_max: - msg.data_out =3D data->pwr_limit_max; - ret =3D 0; - break; - default: - return -EINVAL; - } - if (ret < 0) - return ret; - /* hwmon power attributes are in microWatt */ - *val =3D (long)msg.data_out * 1000; - return ret; -} - -static int sbrmi_write(struct device *dev, enum hwmon_sensor_types type, - u32 attr, int channel, long val) -{ - struct sbrmi_data *data =3D dev_get_drvdata(dev); - struct sbrmi_mailbox_msg msg =3D { 0 }; - - if (type !=3D hwmon_power && attr !=3D hwmon_power_cap) - return -EINVAL; - /* - * hwmon power attributes are in microWatt - * mailbox read/write is in mWatt - */ - val /=3D 1000; - - val =3D clamp_val(val, SBRMI_PWR_MIN, data->pwr_limit_max); - - msg.cmd =3D SBRMI_WRITE_PKG_PWR_LIMIT; - msg.data_in =3D val; - msg.read =3D false; - - return rmi_mailbox_xfer(data, &msg); -} - -static umode_t sbrmi_is_visible(const void *data, - enum hwmon_sensor_types type, - u32 attr, int channel) -{ - switch (type) { - case hwmon_power: - switch (attr) { - case hwmon_power_input: - case hwmon_power_cap_max: - return 0444; - case hwmon_power_cap: - return 0644; - } - break; - default: - break; - } - return 0; -} - -static const struct hwmon_channel_info * const sbrmi_info[] =3D { - HWMON_CHANNEL_INFO(power, - HWMON_P_INPUT | HWMON_P_CAP | HWMON_P_CAP_MAX), - NULL -}; - -static const struct hwmon_ops sbrmi_hwmon_ops =3D { - .is_visible =3D sbrmi_is_visible, - .read =3D sbrmi_read, - .write =3D sbrmi_write, -}; - -static const struct hwmon_chip_info sbrmi_chip_info =3D { - .ops =3D &sbrmi_hwmon_ops, - .info =3D sbrmi_info, -}; - static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data) { struct sbrmi_mailbox_msg msg =3D { 0 }; @@ -152,7 +54,6 @@ static int sbrmi_get_max_pwr_limit(struct sbrmi_data *da= ta) static int sbrmi_i2c_probe(struct i2c_client *client) { struct device *dev =3D &client->dev; - struct device *hwmon_dev; struct sbrmi_data *data; int ret; =20 @@ -173,9 +74,8 @@ static int sbrmi_i2c_probe(struct i2c_client *client) if (ret < 0) return ret; =20 - hwmon_dev =3D devm_hwmon_device_register_with_info(dev, client->name, dat= a, - &sbrmi_chip_info, NULL); - return PTR_ERR_OR_ZERO(hwmon_dev); + dev_set_drvdata(dev, data); + return create_hwmon_sensor_device(dev, data); } =20 static const struct i2c_device_id sbrmi_id[] =3D { --=20 2.25.1 From nobody Fri Dec 19 00:53:39 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2063.outbound.protection.outlook.com [40.107.93.63]) (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 7E2A41D5165; Mon, 28 Apr 2025 06:31:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821880; cv=fail; b=Akx3OQ++OCmmqwbUfxxzzZsWNhRxGPtz33ptVbRGxhTaM797HSkUdJYKLBWLJZXpZBq5YR08pLe4lpsYkilXe5OFVcJrpdxQrQ5sAMU3v++6TV9MKpFF787hbaaYJTVS0aRQDRf1ncIXDpmIh1Yf5a3ujNDOnOHYb7ESjziAaWE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821880; c=relaxed/simple; bh=/hylpCazgtSHgUqctuy5zSLTFlF61o/rcxgXvvSFUQc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nLNYfgtDYIm0Wf9sTUNaPxlOyVRxY/EY+25lpmTJBIX1p+NseCShkXN56ZCZUzkU5Jh3G7Q/9Nl8l+kFPpx4/l8ZMO4jP8FeUaqsmRGIKMAnEY3GPozwij5mNq+O+Oto9R5VG/swQ+wxLpVARylmYOLW1qwsiNOnnX51RMig7+g= 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=C5LgOiWL; arc=fail smtp.client-ip=40.107.93.63 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="C5LgOiWL" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pZrB+If0ds5SCkuU9dFj4Xk42NUsou29JEA9b9+H5FcAUrUYCOFfLvZUVQDjFnB/UXV8qinzyIBiroOltGx5C7UVaM1QWI33kFVC4CLmACOFIQbb83KY8BJ6vwri//ON1F0viswzqaiwlImAv+w2gdlGXxxdm8PngiskTXZCmTECfsQyiScMUmTWcKZkB6viVaI4UfJWUOWaWkU3ghmiJiPh3f1GF4PNtiKJcIcOvonrp1BZGvt1GzpasmSdgRaoTrIp3toNOVN+4EsBDLsS7Aty8h4pqv8emdb68JPFEDcQEMOnq+7Q389QWKUHXoh3ov9EzroR9mbKNzvV3MaFrg== 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=TG/hsuXoeICZfIxIRNFbNIU6w59mt9fCZldXT79Y9Rs=; b=osclM33QOUKaY5Ifo7v2H57+9gg+usAwbJ8y9HYWfx5mBajVJyQuXR8l0Z27l/9OeTpvERrWJJR7C0CtoXzpTUg9RVRiqovsdOn0NFDp9YR7Q/7u2QIHo9wRVeaSgHV/MddRBkzcCxcOMDeYZjomiD/Y8cMYjKACZpFvnK1YNKORcI1+2NLXrMufMyvG9ExRE0+T9tlkjtdjiyHIKIfZAPViht7ZMe6B0GAXp61Q9l99TGhp+5VUGWHqzTK7OeK+1LCc8JAhPF3J77SD90cOo2B5i3EgnkHiFu/WAHBxjgZni9EMM7SDsMMNK/sx/4+fmdyuVcHHOP82EZ6RTZkayw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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=TG/hsuXoeICZfIxIRNFbNIU6w59mt9fCZldXT79Y9Rs=; b=C5LgOiWL3R0XhbTDso3000AUJQF8ttxtr4RpdjajW4vSYSf7I9zWOf4wHhwO6j465SnTdnCkOk4IPpG0GCzBmeKRd5GvVfJPVr0jKqWMDMG76vS09MLyj9lJtHI5WyvlwJajHfX+KSBoNHA7fwVq7kuKrTt8PQkYG2/HeSf3FuI= Received: from MW4PR03CA0044.namprd03.prod.outlook.com (2603:10b6:303:8e::19) by SJ0PR12MB7035.namprd12.prod.outlook.com (2603:10b6:a03:47c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8678.33; Mon, 28 Apr 2025 06:31:14 +0000 Received: from SN1PEPF0002BA4B.namprd03.prod.outlook.com (2603:10b6:303:8e:cafe::62) by MW4PR03CA0044.outlook.office365.com (2603:10b6:303:8e::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.36 via Frontend Transport; Mon, 28 Apr 2025 06:31:13 +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 SN1PEPF0002BA4B.mail.protection.outlook.com (10.167.242.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8678.33 via Frontend Transport; Mon, 28 Apr 2025 06:31:13 +0000 Received: from amd.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; Mon, 28 Apr 2025 01:31:03 -0500 From: Akshay Gupta To: , CC: , , , , , , , , Akshay Gupta Subject: [PATCH v9 04/10] misc: amd-sbi: Use regmap subsystem Date: Mon, 28 Apr 2025 06:30:28 +0000 Message-ID: <20250428063034.2145566-5-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250428063034.2145566-1-akshay.gupta@amd.com> References: <20250428063034.2145566-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SN1PEPF0002BA4B:EE_|SJ0PR12MB7035:EE_ X-MS-Office365-Filtering-Correlation-Id: 4d2feeed-8a0a-4418-386c-08dd861e45d0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?WvN20XpCw7bc1RgjlqYoX3JXv8it52XnB/Xfio8Qm8asBre21iJ+hWyaU4ta?= =?us-ascii?Q?oOLHSsEhh+32bGI0+A9o661XbDCAvxHcdMIfa+NoVXgXaZXBxd09ckTTjFyE?= =?us-ascii?Q?31LOOKwQq2s/11DYt7C8V8IwR1Lh1Pj89dQVnEbUzVWVhkl0xMb4k+AYPxXg?= =?us-ascii?Q?D4NX2vQm2W6klxgH7q5e36lIxi5U8Z/t1uVGS4Q/hOBw3KOfjhFyo5ZmWu0I?= =?us-ascii?Q?f92GlUma2Vq6aU8JAzFbUwR3WVN3eoizahJKncpey/PEHJYA6M0W08Hd2RCl?= =?us-ascii?Q?8gkL+zbADKy/OmgcTvnNmK5vgdQRoDW0hh3cwWZWDhfZlaboWWKsf5E+DbbM?= =?us-ascii?Q?sNjZ9/ansIJILrq/KsmzFIIA2iEFjariZoT7C1W/My9m3AYGgF2cxehLaNm6?= =?us-ascii?Q?isD5qWBnrQxuUjaKF5bU4aNOj8yyRHcrDSAiLBz0YKkK8/oVM9Osed+nYaxM?= =?us-ascii?Q?si0tjDxBQNeOY9RM5PAGvfWRg1jvaK3s2qt2S3mneO+Long36/KPODP6ta3x?= =?us-ascii?Q?g2MnyDy3eBrCDm1dzNPNlp+Rh7Z22QpUXhFyV+iZzZtsER/A/cdjb/zx/G/F?= =?us-ascii?Q?hiSJIWzcHTYSiMv2oyZ1xWTtALln2tz6BwvuKxFy74kaI25DShSh8ozlPGyH?= =?us-ascii?Q?yM98wyKjHm5HH2Hz/YULbrFWvPXyRCbYCpGjIh55Ssn3TvAPD6LdjikfvbaE?= =?us-ascii?Q?gUQ04F3GE3en1lvZkMtA/Fc5NlO7u14QgIWChgU17UTtpollVEgscV5So0hv?= =?us-ascii?Q?Ty3aMTjhrdUBtiRg7/NKND9YsWk/WWnEEVB4MC7/Gn7XynbHXssgd5gWvKiu?= =?us-ascii?Q?OOcyEqF5F4SaBdrXX7LLMqZYsQuQoV1Fe3ETlXiT+ahh0KXw8j0koADR5J88?= =?us-ascii?Q?OWAvfHlb19EQbWFqkN/gtRIkPX9jSOj1zad61E46amcWE/rU0jYe1w9ncSfI?= =?us-ascii?Q?RXkomh7o3v5LhypSSxh7NhKuhhnIgEWXUSCQpkxQq2mypn1BI8DIrbT5be6x?= =?us-ascii?Q?ppoELDwH+zD9CaV42HEgXtEVe+kljExpUMJJ1I1zabZE+5ahyW+SvdJyiJY2?= =?us-ascii?Q?/lhZRN8KB4W6rIHavw6qroe5Y6FwccqEoTlAtSy9R9qUsL7f4HMLTrmG+7Eq?= =?us-ascii?Q?KWDPDcXpNtDpeW5xCjSSa6AiF19Iq82jGHWP992USXGFIHv3GPONlSiTRlDI?= =?us-ascii?Q?T5xIW1ZmY74c7u77Dl65P4kSuE21p664rwsw68u1fjFR+UOjOXEgfmpukg+V?= =?us-ascii?Q?ItpBU7yZEMJRKUN4SsG3G3NrpraUp4LKuMjD2MtTRtEQN01Ub0vmp2IG25YV?= =?us-ascii?Q?q4Ar6xDHIvCwGGAlBBrYganfBTKxYVUEut3R7+UztbSvYSaqccpGJYe7hL68?= =?us-ascii?Q?oCec2vT2+zsMXAxLRe6x8uLtFtBfNSqvsMxueJyI21xLrFXJ0bDi+q9jKF6N?= =?us-ascii?Q?uHk4iwyDtZquS1IxRz0Jnn38t2VDO0smLXtQAJsPfuQOHwsmLXFTiAGta1z6?= =?us-ascii?Q?aOxiVLq+ZxLlacoMSQ0PxdglmBg9UqZQWrve?= 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)(36860700013)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2025 06:31:13.4331 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4d2feeed-8a0a-4418-386c-08dd861e45d0 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: SN1PEPF0002BA4B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB7035 Content-Type: text/plain; charset="utf-8" - regmap subsystem provides multiple benefits over direct smbus APIs - subsystem adds another abstraction layer on top of struct i2c_client to make it easy to read or write registers. - The subsystem can be helpful in following cases - Different types of bus (i2c/i3c), we have plans to support i3c. - Different Register address size (1byte/2byte) Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v4: - Previously patch 2 Changes since v1: - Previously patch 3 - Remove "__packed" from data structure drivers/misc/amd-sbi/rmi-core.c | 29 ++++++++++++----------------- drivers/misc/amd-sbi/rmi-core.h | 3 ++- drivers/misc/amd-sbi/rmi-i2c.c | 25 ++++++++++++++++--------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-cor= e.c index 74456756270c..663ab9176d95 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "rmi-core.h" =20 /* Mask for Status Register bit[1] */ @@ -21,6 +22,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg) { + unsigned int bytes; int i, ret, retry =3D 10; int sw_status; u8 byte; @@ -28,14 +30,12 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, mutex_lock(&data->lock); =20 /* Indicate firmware a command is to be serviced */ - ret =3D i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG7, START_CMD); + ret =3D regmap_write(data->regmap, SBRMI_INBNDMSG7, START_CMD); if (ret < 0) goto exit_unlock; =20 /* Write the command to SBRMI::InBndMsg_inst0 */ - ret =3D i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG0, msg->cmd); + ret =3D regmap_write(data->regmap, SBRMI_INBNDMSG0, msg->cmd); if (ret < 0) goto exit_unlock; =20 @@ -46,8 +46,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, */ for (i =3D 0; i < 4; i++) { byte =3D (msg->data_in >> i * 8) & 0xff; - ret =3D i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG1 + i, byte); + ret =3D regmap_write(data->regmap, SBRMI_INBNDMSG1 + i, byte); if (ret < 0) goto exit_unlock; } @@ -56,8 +55,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * Write 0x01 to SBRMI::SoftwareInterrupt to notify firmware to * perform the requested read or write command */ - ret =3D i2c_smbus_write_byte_data(data->client, - SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); + ret =3D regmap_write(data->regmap, SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); if (ret < 0) goto exit_unlock; =20 @@ -67,8 +65,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * of the requested command */ do { - sw_status =3D i2c_smbus_read_byte_data(data->client, - SBRMI_STATUS); + ret =3D regmap_read(data->regmap, SBRMI_STATUS, &sw_status); if (sw_status < 0) { ret =3D sw_status; goto exit_unlock; @@ -79,8 +76,6 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, } while (retry--); =20 if (retry < 0) { - dev_err(&data->client->dev, - "Firmware fail to indicate command completion\n"); ret =3D -EIO; goto exit_unlock; } @@ -92,11 +87,11 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, */ if (msg->read) { for (i =3D 0; i < 4; i++) { - ret =3D i2c_smbus_read_byte_data(data->client, - SBRMI_OUTBNDMSG1 + i); + ret =3D regmap_read(data->regmap, + SBRMI_OUTBNDMSG1 + i, &bytes); if (ret < 0) goto exit_unlock; - msg->data_out |=3D ret << i * 8; + msg->data_out |=3D bytes << i * 8; } } =20 @@ -104,8 +99,8 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the * ALERT to initiator */ - ret =3D i2c_smbus_write_byte_data(data->client, SBRMI_STATUS, - sw_status | SW_ALERT_MASK); + ret =3D regmap_write(data->regmap, SBRMI_STATUS, + sw_status | SW_ALERT_MASK); =20 exit_unlock: mutex_unlock(&data->lock); diff --git a/drivers/misc/amd-sbi/rmi-core.h b/drivers/misc/amd-sbi/rmi-cor= e.h index 977ee05af6a6..3a6028306d10 100644 --- a/drivers/misc/amd-sbi/rmi-core.h +++ b/drivers/misc/amd-sbi/rmi-core.h @@ -9,6 +9,7 @@ #include #include #include +#include =20 /* SB-RMI registers */ enum sbrmi_reg { @@ -47,7 +48,7 @@ enum sbrmi_msg_id { =20 /* Each client has this additional data */ struct sbrmi_data { - struct i2c_client *client; + struct regmap *regmap; struct mutex lock; u32 pwr_limit_max; }; diff --git a/drivers/misc/amd-sbi/rmi-i2c.c b/drivers/misc/amd-sbi/rmi-i2c.c index 9ad4c8093399..7a9801273a4c 100644 --- a/drivers/misc/amd-sbi/rmi-i2c.c +++ b/drivers/misc/amd-sbi/rmi-i2c.c @@ -13,24 +13,24 @@ #include #include #include +#include #include "rmi-core.h" =20 -static int sbrmi_enable_alert(struct i2c_client *client) +static int sbrmi_enable_alert(struct sbrmi_data *data) { - int ctrl; + int ctrl, ret; =20 /* * Enable the SB-RMI Software alert status * by writing 0 to bit 4 of Control register(0x1) */ - ctrl =3D i2c_smbus_read_byte_data(client, SBRMI_CTRL); - if (ctrl < 0) - return ctrl; + ret =3D regmap_read(data->regmap, SBRMI_CTRL, &ctrl); + if (ret < 0) + return ret; =20 if (ctrl & 0x10) { ctrl &=3D ~0x10; - return i2c_smbus_write_byte_data(client, - SBRMI_CTRL, ctrl); + return regmap_write(data->regmap, SBRMI_CTRL, ctrl); } =20 return 0; @@ -55,17 +55,24 @@ static int sbrmi_i2c_probe(struct i2c_client *client) { struct device *dev =3D &client->dev; struct sbrmi_data *data; + struct regmap_config sbrmi_i2c_regmap_config =3D { + .reg_bits =3D 8, + .val_bits =3D 8, + }; int ret; =20 data =3D devm_kzalloc(dev, sizeof(struct sbrmi_data), GFP_KERNEL); if (!data) return -ENOMEM; =20 - data->client =3D client; mutex_init(&data->lock); =20 + data->regmap =3D devm_regmap_init_i2c(client, &sbrmi_i2c_regmap_config); + if (IS_ERR(data->regmap)) + return PTR_ERR(data->regmap); + /* Enable alert for SB-RMI sequence */ - ret =3D sbrmi_enable_alert(client); + ret =3D sbrmi_enable_alert(data); if (ret < 0) return ret; =20 --=20 2.25.1 From nobody Fri Dec 19 00:53:39 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2062.outbound.protection.outlook.com [40.107.93.62]) (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 E9FF81D63F5; Mon, 28 Apr 2025 06:31:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821883; cv=fail; b=RJWF3/YMITIRVSajP91KfEA4Dp58LAga8ztl/wrpcXxQEsNP/54Hd2xfRfe0uD/D9d1pA0e+YtYwuWgFesnAAjkMCTe/VgaJLlN2+1MK6N3/h3D3UxZh5xzIiAbe/zCfKcLSJmDKyiOcQGAPJDQjNTyG4/H50PXnpM3POM/9yS4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821883; c=relaxed/simple; bh=5GtngUwv/pFLVs/5jP4e1YTBT+QZloysFbMq2j+bxzk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WurDtDw2ihSftgcjkIghpbgqQ0gC+vhV1Kcj+xpPq4VvaneoY/sb9cZFVF+vgrGFP7XPn1Lt0qAa4pmH7pkS0QdJnCjKp/oljXnDuLa13+Aki1zD93ItiEWJRn81a+3Cfj7G4MQe3HPf/fgei1JiXj9fVW3faFZGkowAje5akFE= 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=tQ41XWN7; arc=fail smtp.client-ip=40.107.93.62 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="tQ41XWN7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UbqdCP0XhR8qG4u7tAwtHMjhC/rUDe238QbDpkTNYWrjLur7AU/NMpytmcfeWIpU0zIzvn4TnHqDqwUKQ7zhzz11YUUQ62KXev9SU0c9wgH23pdUPPiQD0j+IAQ8AvN9tUI4TwtrhDXhc7QVvcya/q6pbMyGhCKzvKRNCekEvSUiF6jYNyzOcIcSYmQ4b1EbFHWLB2O0f1IovVam2E4plkVR0luP5y6Chq3ejJuJmJznSixGzGm2/gvB8EVpDFtsJqpSaHgmm2DYnI1PVd/eXaXnvpQnzO0nz66TDSfhr7VkqNo9ffLzNrNLvL8ejCPoTtAs5DDaq6I8PirYaGR0lA== 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=g1pRsfusff5dmd7COF46Efmf3bQtvGWyrIdbo/pp59w=; b=gGuet79jUCHoXzgCewb+yOxJBEzBHtblkzwHGIdWTah45tI+7zyMU0ZjRiaSewr6ov091IvLiZDn3Y6IFQlYm3QIlE69pw3mkFXbvyEC8sZrVD76rz2l/7cvdSO6SAxSBPQqncG0+9xhaE45AI/uu3Zv3gUaGw9x3w+Psp0yO+xqTUN6OrfYu+R50ocw8vwWfs/Qjm4Nrw/qcmhCwuGvBGrOafPEy3qppBmN6YPjuIw749yUaaJKA5POczlFVhh5xAJ8xNjy1tOgK/YlgwT6gi6FT5Fw+dyCzGcTe7ha0hXlvIaBee9YIQXZR0nt0lEG2rhoD72j+WvOL0z4L/5CBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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=g1pRsfusff5dmd7COF46Efmf3bQtvGWyrIdbo/pp59w=; b=tQ41XWN7HlEobDoj+1N01g00tE6hcB3ZTqww3l8mZwxS6kro9mFiI2ZWSlv8EOmRO8CD769RQz9lDeDcb6Ts+3YSzBaE/dbprk+VrnNj0sLo+CiprwdFfx+a/YbcAqdItinxr9mFbwC4uOhGhRRjI92+0nccy7kyuucZufe1+ao= Received: from SN7PR04CA0087.namprd04.prod.outlook.com (2603:10b6:806:121::32) by CH3PR12MB8936.namprd12.prod.outlook.com (2603:10b6:610:179::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8678.33; Mon, 28 Apr 2025 06:31:14 +0000 Received: from SN1PEPF0002BA4C.namprd03.prod.outlook.com (2603:10b6:806:121:cafe::6c) by SN7PR04CA0087.outlook.office365.com (2603:10b6:806:121::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.36 via Frontend Transport; Mon, 28 Apr 2025 06:31:13 +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 SN1PEPF0002BA4C.mail.protection.outlook.com (10.167.242.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8678.33 via Frontend Transport; Mon, 28 Apr 2025 06:31:13 +0000 Received: from amd.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; Mon, 28 Apr 2025 01:31:06 -0500 From: Akshay Gupta To: , CC: , , , , , , , , Akshay Gupta Subject: [PATCH v9 05/10] misc: amd-sbi: Optimize the wait condition for mailbox command completion Date: Mon, 28 Apr 2025 06:30:29 +0000 Message-ID: <20250428063034.2145566-6-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250428063034.2145566-1-akshay.gupta@amd.com> References: <20250428063034.2145566-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SN1PEPF0002BA4C:EE_|CH3PR12MB8936:EE_ X-MS-Office365-Filtering-Correlation-Id: 726626b8-941c-4370-7c86-08dd861e45ef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Gd4tg7XBth69CEm2nUbzf3302aKFSzIU8Qsfftvdm1+AFtxqyEYO+BwtCObx?= =?us-ascii?Q?INNAm7g2a7j3X+upPx3p+mEEqH/zV2aXVZJpj5gaL74dBTU1WWM+UJ/ZJ8zR?= =?us-ascii?Q?S2W0ENe1q5Q7xu2d34XwUXy6puXckYIX1PNa2AX/y8jPl4f0sWWMBYRBV/FC?= =?us-ascii?Q?kCrBYlNHC3voH02a21LzbwDZV3Uolt1veP/Okibp6Q2EQN153B05qOO/0L9t?= =?us-ascii?Q?MpbUNOkozWrGpMj0zlB0xbUJItboewp4NKwuVlflaoWuXprdKHbmFN8hrtiW?= =?us-ascii?Q?0uO7h6zou4bpo7kQnbZMxMbNk5ejutPJRpw5DEOdXfMh3uZEN94I8eOwI7Qt?= =?us-ascii?Q?QAO6C9QyadSdWofvj779CZE4FzKiL4Y2sr3mwoLaw8U6VTj/2MeAEsJILVsG?= =?us-ascii?Q?wG2QgXNXFsliig1hC3UTnDdAydFnmo6IFOFYlGfnUhO0lXTXsDBHU3YGAsZs?= =?us-ascii?Q?uIfrvN8iB9iA0d42B+Iq2tDzYf740IzUjXANwFaxRydllcmF0zbz7ztezTCb?= =?us-ascii?Q?SHPLTrUw1qnb1ML97Jn8GwAb4b/XE5hNwjpwfVmHbkg9CUQxw/axnT0UtwQu?= =?us-ascii?Q?e3HvZsOycGbjvKU5MReyPQb107hEIEoaunw0DWSDrqjJc0WeL6vZX9aBHn6n?= =?us-ascii?Q?5/Cc7PmiHFj27jFkWuVqC3t0nDf3cBVGde5DjA3typCCweomzEjnENdMHvsy?= =?us-ascii?Q?8xCu+kWOyqgovVKQqFTrsf1u4SeGNYIphkawfsNqU4lYNhj0UfYiCpThnVi8?= =?us-ascii?Q?mQHam4G29y0IJFOyVwuA6M3KEfLGRZxVw1pR2uOh0KiKia9fYec5kvqpmxcU?= =?us-ascii?Q?+SpiLDdzw76d+7wBXiiucGIKQcYiTCEZxmm4icN2u4jXi+A4YFbC9HZ6uEuD?= =?us-ascii?Q?kLo97xxr0NO4SaIdhSKBfBfKhfhDm8s6jsoYFwK+xxx8aYiTeH0s9sbdu7Np?= =?us-ascii?Q?/cdrU+WLCSQPfA3Gdmd9wGxeF9VhuYjYrgwiBKadAIq8aJjswkfGh9hQA70l?= =?us-ascii?Q?5Da2vb4N78MMZyFzZlJa4aFzJLOSbNAHoWIYXOygmjswrqmFn9unAOekKrtH?= =?us-ascii?Q?+L1Kzk6ykBMCA+nn8OXikUK+0CvabrEiaepBPizdMkI0mu+lvj2apvHpLb0i?= =?us-ascii?Q?g+wrs7Ofe264s/2LdwyhL0Tf6sMOhQ6aNcgelD+BG7vYsfN16hRNBH4KqaDN?= =?us-ascii?Q?0fFwtyiEpBjkLSz087jsdj+B//AjmdT6hoWWUkXM3Q1EnSCmLsFo4vFhAvmI?= =?us-ascii?Q?+1fMYZElV66+Zqhae73KLR8ZTX6HjgVzoExSe9c2sZb/GONLLd6BIfy1inDZ?= =?us-ascii?Q?RmzPRyBXQ/GDGAe9pctYmEbVPPYpFNVa/lEiL8rljhvJw+UezPY6xwhNDY88?= =?us-ascii?Q?XJoUlxFhR99Z9dv/lyGJXYiQTuunL1SUPHDbDuaHAYNfy/eP13rfHsr/hzr6?= =?us-ascii?Q?+rwtLYtg1t8BhQlRY2k0T2O6V+Qbd72tEU+yXep4i5l6nw0rlk7w0D1xKPc3?= =?us-ascii?Q?z/IEe3NhDvcxyQJ7fAC/yYQZkBMX24TjbWtS?= 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)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2025 06:31:13.6371 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 726626b8-941c-4370-7c86-08dd861e45ef 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: SN1PEPF0002BA4C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8936 Content-Type: text/plain; charset="utf-8" - optimize the wait condition to indicate command completion by replacing the do while loop with regmap subsystem API regmap_read_poll_timeout() Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v4: - Previously patch 3 Changes since v3: - New patch as per suggestion from Arnd drivers/misc/amd-sbi/rmi-core.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-cor= e.c index 663ab9176d95..1d5e2556ab88 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -23,7 +23,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg) { unsigned int bytes; - int i, ret, retry =3D 10; + int i, ret; int sw_status; u8 byte; =20 @@ -64,21 +64,10 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * an ALERT (if enabled) to initiator (BMC) to indicate completion * of the requested command */ - do { - ret =3D regmap_read(data->regmap, SBRMI_STATUS, &sw_status); - if (sw_status < 0) { - ret =3D sw_status; - goto exit_unlock; - } - if (sw_status & SW_ALERT_MASK) - break; - usleep_range(50, 100); - } while (retry--); - - if (retry < 0) { - ret =3D -EIO; + ret =3D regmap_read_poll_timeout(data->regmap, SBRMI_STATUS, sw_status, + sw_status & SW_ALERT_MASK, 500, 2000000); + if (ret) goto exit_unlock; - } =20 /* * For a read operation, the initiator (BMC) reads the firmware --=20 2.25.1 From nobody Fri Dec 19 00:53:39 2025 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2060.outbound.protection.outlook.com [40.107.244.60]) (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 EAA281D63F8; Mon, 28 Apr 2025 06:31:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821884; cv=fail; b=C7tkfe/tRMA1ukpKvArXNSwAFQUQT0ZKVT3bqkDR6pGCGjAiPtXgKuHMz2kWFe8T9vAp6Y5ofFplGybgXWkev3F0GO/6xPLTRMBXgQvnZ8/bDwsDr7e2zlSEAUOcpWyy/XJclet7fFN6qLH7EcJ1YFQ9Y/o9712UPKxronVxVUU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821884; c=relaxed/simple; bh=IuNCf6bnUwvnw8IDe0LAQf4yk2UGWE8bQlSXKOjiTug=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pHisIsV5nXwieXf4UsettGkfV9Z50Ly6S9b1njRmF+kpVBUo4bBhzZBkg+ZbLK+PaVPmxiKlOZR04Gu4W1kfmabNpjZ4Y0+lj3RP5M6viH9rmAzwZ3aDR02DZCkgpxHYrzyqgE7eo/V/44DQwzFsiWgxHVR4Boe8dat1A8ZcMpw= 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=PZk+aplr; arc=fail smtp.client-ip=40.107.244.60 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="PZk+aplr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DqVRg2ghbKrTVmkEGVLt9FYrmOZav7yy+cGtNOjqS+Zcfiie3KjSgPfqzf6fclW5bkQtjq9SH8SFaQezPMkYBg4puwKZhDLnsKChIDXWerKP9TbtdPNA2iElEr2RK3QfCak6sGbbXreX5OkJvhss8pjb6iWz8MXaQ11EWE0oeCwxVDzeCzKbgwqX4kJg3g09wZIzW8xSDoUT2UFA+JaeL+9FOrKnU0wlpKJK46V2S6xVRBuE4mRBO9PW10YztoM5o6Go1ypgd/e2h98kPpR7PL5S9jBfLLDRuKJiEsReInG07+K1PmYMbxLhVAGdTJpmYpfwpenAGmEjbSBG8RYE4Q== 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=O/kahapFlp8K+3dWMtIuVdgPzOOLqJ2YiHWrdTONz/I=; b=pGvHfFXTIiNInDKmyWERmeJnUBbQvngF0z5pFBWPe9EGITpJTG4iJ5mS5e72Uzgn3PXdcJ8QiDZs8zDHwP1BqpiMIfnHW2hA90K4Hy5vjb1cMpl/LOruZY6P1UCAUxsDDFFEdPuYZYGXSLtHr9HgLqbKxPQOCSy9Ddfh1NvDXQrwThMgnTZyAeFv2IYCoi0bUyjL7hXpxo4CUGow+F5nCSNobgU8+IEzHN49SS9JE2S4xyygr70XW/4zSRCCmBr1rHMzMXYgxY6b5GyDvzlGUSQshua/de9jiQ1dfmproDm1y7KSzOOlH1HvquddfNbJAJvBGVg0TAH+ctzndFVphA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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=O/kahapFlp8K+3dWMtIuVdgPzOOLqJ2YiHWrdTONz/I=; b=PZk+aplrTFcWZCcUChSU1KAxrNpZ6ZPOPK4QyAclcldpAOtxWJn+Az/wipSkCiMvHModB4OjOMRQXa+rNGS7E6imsqu+twm10gcOvrTil3JY/JMuesUCyJkzWCnhoLyDnm/XuoIB7may69QbB5ApBOeEVV/ijGGY9RcvGha7UT0= Received: from SN7PR04CA0067.namprd04.prod.outlook.com (2603:10b6:806:121::12) by CH3PR12MB7715.namprd12.prod.outlook.com (2603:10b6:610:151::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8678.31; Mon, 28 Apr 2025 06:31:15 +0000 Received: from SN1PEPF0002BA4C.namprd03.prod.outlook.com (2603:10b6:806:121:cafe::38) by SN7PR04CA0067.outlook.office365.com (2603:10b6:806:121::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.36 via Frontend Transport; Mon, 28 Apr 2025 06:31:15 +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 SN1PEPF0002BA4C.mail.protection.outlook.com (10.167.242.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8678.33 via Frontend Transport; Mon, 28 Apr 2025 06:31:15 +0000 Received: from amd.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; Mon, 28 Apr 2025 01:31:10 -0500 From: Akshay Gupta To: , CC: , , , , , , , , Akshay Gupta Subject: [PATCH v9 06/10] misc: amd-sbi: Add support for AMD_SBI IOCTL Date: Mon, 28 Apr 2025 06:30:30 +0000 Message-ID: <20250428063034.2145566-7-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250428063034.2145566-1-akshay.gupta@amd.com> References: <20250428063034.2145566-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SN1PEPF0002BA4C:EE_|CH3PR12MB7715:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ab30645-59d6-403e-eec1-08dd861e46dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?d8y7F1XrWQnA9lTptu4RHoeQFv/bjtA0FYT5lL3CqfjNcsYPZzxDXJTmfPgH?= =?us-ascii?Q?oV42A4iu/lVL9g+o4zf6vlL1cYASATpf81yGcicev8TT9kfTICYEf7n8HEy0?= =?us-ascii?Q?9wKU5zhhM1arJBLhcp3SOpX6O8u3kcgM9WGp98th2wQZL1h5sOGxNTRf+beJ?= =?us-ascii?Q?ORYeraqJOv7Trzvvr3ldkRXLDkd7zYOUeq7wnc59HPAPsHVZJDVFcGW+YHyV?= =?us-ascii?Q?eyVEYLpmAicMz1lmuhRmBxpNqSa9BjkViP9bJ2gXRhRwjaz20bK0V3GvMNVv?= =?us-ascii?Q?Ri6ppahY7KSTs7cW6Vztdm/p0FxYTiuUatelXtZU6AWgu5E9823dQuSKZss4?= =?us-ascii?Q?Nu4WE02W3YOJLyHcGTX5auHLv4cbildzQqrZ7zYkkJzk4kc3ct6u42A2vAvd?= =?us-ascii?Q?E6TCSGBEQXK19V0lyICU3+Q0c9Mc+dMTcchcet82K4jcS0l7ekRd34D1EFBD?= =?us-ascii?Q?jdZt5TzEXS4H5XX90uFTv1f6QaJhzxiHQzLyHLrcM8QDl2UsvQuxu/K1sRwJ?= =?us-ascii?Q?+MJvXUogIlMyyT7wpF07w11pXJgcn4tMJvWZnZwBs4rzKT85ulwn+aeE77WK?= =?us-ascii?Q?nxV2aax9R4kLFQEP+EKR6CaAltSEVFoMPCJwfcRPq95Pq0KDxOuvZNEV5+sO?= =?us-ascii?Q?UqZd/MjuexboZhzkOe+uqVf3k703NPmO4fuRgvHaOgKWAMGwY8KzdvpoV3lO?= =?us-ascii?Q?pNu04iCidFQ8yH961+slnAFYzc4MDLK7/W13ELc/xlWI+V9Um6ftlM5i6o3s?= =?us-ascii?Q?3AY19PgXurvu0pPIZJBFJCa/d6id+paZ9hNJKfNCWGgGB3/K7mxVKEZC3V0p?= =?us-ascii?Q?Yrc7AKGByowtSWEh7TMlWUl7P0d/3iVRfTOCLUg9Nf1ZBb4kDwT7ecJGHxuK?= =?us-ascii?Q?apAKSTPcZD90HnQOwb35cLjuNNuUXY0DAlrILG4FqUZ02yw5QmgQUhwVNsdC?= =?us-ascii?Q?tDtYbALeLiJ0Rdxy+39WjK5RbMYQ/5S3pAgygDwgbjvwzErDolz+eZf6zK2V?= =?us-ascii?Q?oQ/a0fPgynhdNF1Wes++X52w0tC027viiPxCd32HOj46J41/eR7pVZK5WR7B?= =?us-ascii?Q?sDDwTHWPFmR12z2liyxMGGDf413uT9PjvZRdADNT7+cbYu84y4icoQIjj2pd?= =?us-ascii?Q?DxcFzAVgbR2O2j9PUWaIIlj7VirV0mT6yC6FpphofOcm7KpzV/Hxz0jmIZyh?= =?us-ascii?Q?wJx5X1pprhANzYvykGGP7UYis+yo4LQmIeP+XuSprxAJdzQ4eJ38bFwWfgNH?= =?us-ascii?Q?lvHajZkxjBf+ASTMuX+iwkXkiGGMiqdWj+38EojBQJO3LtHO+EoFJp9HCwDb?= =?us-ascii?Q?WXg1XfhNvc8fmDcYsQm8kSqd494FTu28/qvOrUqE5w0ra11WInv1cUchsYxJ?= =?us-ascii?Q?ZRowjsP8iHDpLTM1aaumtAF+0JeII3enowm9WwRu1W1LaCrtmP/nBuzf7oRK?= =?us-ascii?Q?MAMMKTJRBzPI2zUYPD5sLit0Cq7wGgRWL800aCwKj4hD3A4O4LfLLeggE9Nk?= =?us-ascii?Q?p/kvdMKbzMw+fOnbpGXwftgi2Z43D6t5/Of3Rz+XQeDtBFQN7KPc2uTM0A?= =?us-ascii?Q?=3D=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)(82310400026)(376014)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2025 06:31:15.1942 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6ab30645-59d6-403e-eec1-08dd861e46dc 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: SN1PEPF0002BA4C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7715 Content-Type: text/plain; charset="utf-8" The present sbrmi module only support reporting power via hwmon. However, AMD data center range of processors support various system management functionality using custom protocols defined in Advanced Platform Management Link (APML) specification. Register a miscdevice, which creates a device /dev/sbrmiX with an IOCTL interface for the user space to invoke the APML Mailbox protocol, which is already defined in sbrmi_mailbox_xfer(). The APML protocols depend on a set of RMI registers. Having an IOCTL as a single entry point will help in providing synchronization among these protocols as multiple transactions on RMI register set may create race condition. Support for other protocols will be added in subsequent patches. APML mailbox protocol returns additional error codes written by SMU firmware in the out-bound register 0x37. These errors include, invalid core, message not supported over platform and others. This additional error codes can be used to provide more details to user space. Open-sourced and widely used https://github.com/amd/esmi_oob_library will continue to provide user-space programmable API. Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v7: - Address Arnd comment: - New IOCTL and structure defined to separate ioctl for each protocol Changes since v6: - Address Arnd comments - Squash patch 7 in this patch - Remove check on "cmd" size as it's implied - Update check on input structure, msg.cmd to max value of 0xFF Changes since v5: - Address review comment - Address Arnd comments - Add check for cmd in ioctl - Remove attribute packed from uapi header file structure apml_message{} - Address kernel test robot warn: - warn: can 'data' even be NULL? Changes since v4: - Address review comment - Address Greg review comments - Not initialize ret - return on error - Previously patch 4 - Fix documentation warning Changes since v3: - Previously patch 3 - Documentation and comments changes Changes since v2: - update the MACROS name as per feedback Changes since v1: - Previously patch 5 - Add IOCTL description in ioctl-number.rst - Split patch as per suggestion. Documentation/misc-devices/index.rst | 1 + .../userspace-api/ioctl/ioctl-number.rst | 2 + drivers/misc/amd-sbi/rmi-core.c | 92 ++++++++++++++++--- drivers/misc/amd-sbi/rmi-core.h | 15 ++- drivers/misc/amd-sbi/rmi-hwmon.c | 13 ++- drivers/misc/amd-sbi/rmi-i2c.c | 25 ++++- include/uapi/misc/amd-apml.h | 51 ++++++++++ 7 files changed, 167 insertions(+), 32 deletions(-) create mode 100644 include/uapi/misc/amd-apml.h diff --git a/Documentation/misc-devices/index.rst b/Documentation/misc-devi= ces/index.rst index 8c5b226d8313..081e79415e38 100644 --- a/Documentation/misc-devices/index.rst +++ b/Documentation/misc-devices/index.rst @@ -12,6 +12,7 @@ fit into other categories. :maxdepth: 2 =20 ad525x_dpot + amd-sbi apds990x bh1770glc c2port diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documenta= tion/userspace-api/ioctl/ioctl-number.rst index 7a1409ecc238..3191d96ea4da 100644 --- a/Documentation/userspace-api/ioctl/ioctl-number.rst +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst @@ -397,6 +397,8 @@ Code Seq# Include File = Comments 0xF8 all arch/x86/include/uapi/asm/amd_hsmp.h AMD H= SMP EPYC system management interface driver +0xF9 00-0F uapi/misc/amd-apml.h AMD side band syst= em management interface driver + 0xFD all linux/dm-ioctl.h 0xFE all linux/isst_if.h =3D=3D=3D=3D =3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-cor= e.c index 1d5e2556ab88..7d13c049c98d 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -7,7 +7,10 @@ */ #include #include +#include #include +#include +#include #include #include #include "rmi-core.h" @@ -20,15 +23,17 @@ #define TRIGGER_MAILBOX 0x01 =20 int rmi_mailbox_xfer(struct sbrmi_data *data, - struct sbrmi_mailbox_msg *msg) + struct apml_mbox_msg *msg) { - unsigned int bytes; + unsigned int bytes, ec; int i, ret; int sw_status; u8 byte; =20 mutex_lock(&data->lock); =20 + msg->fw_ret_code =3D 0; + /* Indicate firmware a command is to be serviced */ ret =3D regmap_write(data->regmap, SBRMI_INBNDMSG7, START_CMD); if (ret < 0) @@ -44,8 +49,8 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * Command Data In[31:0] to SBRMI::InBndMsg_inst[4:1] * SBRMI_x3C(MSB):SBRMI_x39(LSB) */ - for (i =3D 0; i < 4; i++) { - byte =3D (msg->data_in >> i * 8) & 0xff; + for (i =3D 0; i < AMD_SBI_MB_DATA_SIZE; i++) { + byte =3D (msg->mb_in_out >> i * 8) & 0xff; ret =3D regmap_write(data->regmap, SBRMI_INBNDMSG1 + i, byte); if (ret < 0) goto exit_unlock; @@ -69,29 +74,90 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, if (ret) goto exit_unlock; =20 + ret =3D regmap_read(data->regmap, SBRMI_OUTBNDMSG7, &ec); + if (ret || ec) + goto exit_clear_alert; /* * For a read operation, the initiator (BMC) reads the firmware * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1] * {SBRMI_x34(MSB):SBRMI_x31(LSB)}. */ - if (msg->read) { - for (i =3D 0; i < 4; i++) { - ret =3D regmap_read(data->regmap, - SBRMI_OUTBNDMSG1 + i, &bytes); - if (ret < 0) - goto exit_unlock; - msg->data_out |=3D bytes << i * 8; - } + for (i =3D 0; i < AMD_SBI_MB_DATA_SIZE; i++) { + ret =3D regmap_read(data->regmap, + SBRMI_OUTBNDMSG1 + i, &bytes); + if (ret < 0) + break; + msg->mb_in_out |=3D bytes << i * 8; } =20 +exit_clear_alert: /* * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the * ALERT to initiator */ ret =3D regmap_write(data->regmap, SBRMI_STATUS, sw_status | SW_ALERT_MASK); - + if (ec) { + ret =3D -EPROTOTYPE; + msg->fw_ret_code =3D ec; + } exit_unlock: mutex_unlock(&data->lock); return ret; } + +static int apml_mailbox_xfer(struct sbrmi_data *data, struct apml_mbox_msg= __user *arg) +{ + struct apml_mbox_msg msg =3D { 0 }; + int ret; + + /* Copy the structure from user */ + if (copy_from_user(&msg, arg, sizeof(struct apml_mbox_msg))) + return -EFAULT; + + /* Mailbox protocol */ + ret =3D rmi_mailbox_xfer(data, &msg); + if (ret && ret !=3D -EPROTOTYPE) + return ret; + + return copy_to_user(arg, &msg, sizeof(struct apml_mbox_msg)); +} + +static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long a= rg) +{ + void __user *argp =3D (void __user *)arg; + struct sbrmi_data *data; + + data =3D container_of(fp->private_data, struct sbrmi_data, sbrmi_misc_dev= ); + switch (cmd) { + case SBRMI_IOCTL_MBOX_CMD: + return apml_mailbox_xfer(data, argp); + default: + return -ENOTTY; + } +} + +static const struct file_operations sbrmi_fops =3D { + .owner =3D THIS_MODULE, + .unlocked_ioctl =3D sbrmi_ioctl, + .compat_ioctl =3D compat_ptr_ioctl, +}; + +int create_misc_rmi_device(struct sbrmi_data *data, + struct device *dev) +{ + data->sbrmi_misc_dev.name =3D devm_kasprintf(dev, + GFP_KERNEL, + "sbrmi-%x", + data->dev_static_addr); + data->sbrmi_misc_dev.minor =3D MISC_DYNAMIC_MINOR; + data->sbrmi_misc_dev.fops =3D &sbrmi_fops; + data->sbrmi_misc_dev.parent =3D dev; + data->sbrmi_misc_dev.nodename =3D devm_kasprintf(dev, + GFP_KERNEL, + "sbrmi-%x", + data->dev_static_addr); + data->sbrmi_misc_dev.mode =3D 0600; + + return misc_register(&data->sbrmi_misc_dev); +} diff --git a/drivers/misc/amd-sbi/rmi-core.h b/drivers/misc/amd-sbi/rmi-cor= e.h index 3a6028306d10..8ab31c6852d1 100644 --- a/drivers/misc/amd-sbi/rmi-core.h +++ b/drivers/misc/amd-sbi/rmi-core.h @@ -6,10 +6,12 @@ #ifndef _SBRMI_CORE_H_ #define _SBRMI_CORE_H_ =20 +#include #include #include #include #include +#include =20 /* SB-RMI registers */ enum sbrmi_reg { @@ -48,19 +50,15 @@ enum sbrmi_msg_id { =20 /* Each client has this additional data */ struct sbrmi_data { + struct miscdevice sbrmi_misc_dev; struct regmap *regmap; + /* Mutex locking */ struct mutex lock; u32 pwr_limit_max; + u8 dev_static_addr; }; =20 -struct sbrmi_mailbox_msg { - u8 cmd; - bool read; - u32 data_in; - u32 data_out; -}; - -int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *ms= g); +int rmi_mailbox_xfer(struct sbrmi_data *data, struct apml_mbox_msg *msg); #ifdef CONFIG_AMD_SBRMI_HWMON int create_hwmon_sensor_device(struct device *dev, struct sbrmi_data *data= ); #else @@ -69,4 +67,5 @@ static inline int create_hwmon_sensor_device(struct devic= e *dev, struct sbrmi_da return 0; } #endif +int create_misc_rmi_device(struct sbrmi_data *data, struct device *dev); #endif /*_SBRMI_CORE_H_*/ diff --git a/drivers/misc/amd-sbi/rmi-hwmon.c b/drivers/misc/amd-sbi/rmi-hw= mon.c index 720e800db1f0..f4f015605daa 100644 --- a/drivers/misc/amd-sbi/rmi-hwmon.c +++ b/drivers/misc/amd-sbi/rmi-hwmon.c @@ -6,6 +6,7 @@ */ #include #include +#include #include "rmi-core.h" =20 /* Do not allow setting negative power limit */ @@ -15,7 +16,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sens= or_types type, u32 attr, int channel, long *val) { struct sbrmi_data *data =3D dev_get_drvdata(dev); - struct sbrmi_mailbox_msg msg =3D { 0 }; + struct apml_mbox_msg msg =3D { 0 }; int ret; =20 if (!data) @@ -24,7 +25,6 @@ static int sbrmi_read(struct device *dev, enum hwmon_sens= or_types type, if (type !=3D hwmon_power) return -EINVAL; =20 - msg.read =3D true; switch (attr) { case hwmon_power_input: msg.cmd =3D SBRMI_READ_PKG_PWR_CONSUMPTION; @@ -35,7 +35,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sens= or_types type, ret =3D rmi_mailbox_xfer(data, &msg); break; case hwmon_power_cap_max: - msg.data_out =3D data->pwr_limit_max; + msg.mb_in_out =3D data->pwr_limit_max; ret =3D 0; break; default: @@ -44,7 +44,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sens= or_types type, if (ret < 0) return ret; /* hwmon power attributes are in microWatt */ - *val =3D (long)msg.data_out * 1000; + *val =3D (long)msg.mb_in_out * 1000; return ret; } =20 @@ -52,7 +52,7 @@ static int sbrmi_write(struct device *dev, enum hwmon_sen= sor_types type, u32 attr, int channel, long val) { struct sbrmi_data *data =3D dev_get_drvdata(dev); - struct sbrmi_mailbox_msg msg =3D { 0 }; + struct apml_mbox_msg msg =3D { 0 }; =20 if (!data) return -ENODEV; @@ -68,8 +68,7 @@ static int sbrmi_write(struct device *dev, enum hwmon_sen= sor_types type, val =3D clamp_val(val, SBRMI_PWR_MIN, data->pwr_limit_max); =20 msg.cmd =3D SBRMI_WRITE_PKG_PWR_LIMIT; - msg.data_in =3D val; - msg.read =3D false; + msg.mb_in_out =3D val; =20 return rmi_mailbox_xfer(data, &msg); } diff --git a/drivers/misc/amd-sbi/rmi-i2c.c b/drivers/misc/amd-sbi/rmi-i2c.c index 7a9801273a4c..f891f5af4bc6 100644 --- a/drivers/misc/amd-sbi/rmi-i2c.c +++ b/drivers/misc/amd-sbi/rmi-i2c.c @@ -38,15 +38,14 @@ static int sbrmi_enable_alert(struct sbrmi_data *data) =20 static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data) { - struct sbrmi_mailbox_msg msg =3D { 0 }; + struct apml_mbox_msg msg =3D { 0 }; int ret; =20 msg.cmd =3D SBRMI_READ_PKG_MAX_PWR_LIMIT; - msg.read =3D true; ret =3D rmi_mailbox_xfer(data, &msg); if (ret < 0) return ret; - data->pwr_limit_max =3D msg.data_out; + data->pwr_limit_max =3D msg.mb_in_out; =20 return ret; } @@ -81,8 +80,25 @@ static int sbrmi_i2c_probe(struct i2c_client *client) if (ret < 0) return ret; =20 + data->dev_static_addr =3D client->addr; dev_set_drvdata(dev, data); - return create_hwmon_sensor_device(dev, data); + + ret =3D create_hwmon_sensor_device(dev, data); + if (ret < 0) + return ret; + return create_misc_rmi_device(data, dev); +} + +static void sbrmi_i2c_remove(struct i2c_client *client) +{ + struct sbrmi_data *data =3D dev_get_drvdata(&client->dev); + + misc_deregister(&data->sbrmi_misc_dev); + /* Assign fops and parent of misc dev to NULL */ + data->sbrmi_misc_dev.fops =3D NULL; + data->sbrmi_misc_dev.parent =3D NULL; + dev_info(&client->dev, "Removed sbrmi-i2c driver\n"); + return; } =20 static const struct i2c_device_id sbrmi_id[] =3D { @@ -105,6 +121,7 @@ static struct i2c_driver sbrmi_driver =3D { .of_match_table =3D of_match_ptr(sbrmi_of_match), }, .probe =3D sbrmi_i2c_probe, + .remove =3D sbrmi_i2c_remove, .id_table =3D sbrmi_id, }; =20 diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h new file mode 100644 index 000000000000..a5f086f84b06 --- /dev/null +++ b/include/uapi/misc/amd-apml.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Copyright (C) 2021-2024 Advanced Micro Devices, Inc. + */ +#ifndef _AMD_APML_H_ +#define _AMD_APML_H_ + +#include + +/* Mailbox data size for data_in and data_out */ +#define AMD_SBI_MB_DATA_SIZE 4 + +struct apml_mbox_msg { + /* + * Mailbox Message ID + */ + __u32 cmd; + /* + * [0]...[3] mailbox 32bit input/output data + */ + __u32 mb_in_out; + /* + * Error code is returned in case of soft mailbox error + */ + __u32 fw_ret_code; +}; + +/* + * AMD sideband interface base IOCTL + */ +#define SB_BASE_IOCTL_NR 0xF9 + +/** + * DOC: SBRMI_IOCTL_MBOX_CMD + * + * @Parameters + * + * @struct apml_mbox_msg + * Pointer to the &struct apml_mbox_msg that will contain the protocol + * information + * + * @Description + * IOCTL command for APML messages using generic _IOWR + * The IOCTL provides userspace access to AMD sideband mailbox protocol + * - Mailbox message read/write(0x0~0xFF) + * - returning "-EFAULT" if none of the above + * "-EPROTOTYPE" error is returned to provide additional error details + */ +#define SBRMI_IOCTL_MBOX_CMD _IOWR(SB_BASE_IOCTL_NR, 0, struct apml_mbox_= msg) + +#endif /*_AMD_APML_H_*/ --=20 2.25.1 From nobody Fri Dec 19 00:53:39 2025 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2075.outbound.protection.outlook.com [40.107.92.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 59A431DDC3F; Mon, 28 Apr 2025 06:31:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821887; cv=fail; b=mH+we8eXTKIrlymxpJImofM+96NYxtYW6/tZqEYtd0F34x/hhzKKTkYrM2Plu34992mxWnLEy3teWY41VbyWj2b4UHjAqiF4B3fvnkBTPcRZwZvGlCX0yVNbaPbI7HBreQCZJ/s9oSWhpnP5fCkv0ELKw7AR4AyyLKl05qN9MRM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821887; c=relaxed/simple; bh=8opl4y0hnuZ9gx2dEW2/a9TrekbQPLO1eMV1qq96I2Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=H+Zi+daeeqOH6zF8nrcanOkH2QNwg2op/eAiWe4B2XGWq+1BZzz6WAa5haPaWuoH9LqDHdb1lFVzVg+HY4qOfiWov2kR46sxFNNP2PcawEQMTpPCeEt4yQo63S7NRKMbP2v0qVXCedZnoIle77Huw4UzmGEIFkmoiRhkFR2dh5s= 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=yFyB35Cj; arc=fail smtp.client-ip=40.107.92.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="yFyB35Cj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lj9KK/Bgu075Eht0ZPBG4lIDtH24SLtZaLRa2qRkkhojMEYL0cWfZcQYB1S5ujKOXyO7q9sY4duzLeyDv7RQvjVJSEDYoukCzzKuk3XOMI3DSSPDuPXz+CbLESO73mg03FAhzF150xvZsofpeYUr9IU/Haxa/40pWStIdn9OdqeMbwnDzBtw1vs8we2ylzXBi6V+Wa7HHsHUJ0p8k80xplsv544JviE5j89bbENkoifb/fzFgxeDGajkp+4JudRsGIajPx4/KIJUcHFvTg7Qv4KkpPgrKsODBAiZ+w7YEbuEA07ZbiMWWv21aCEPXwEvyi6jX9W3D+h2W2FG6wcNgQ== 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=LENG8yRUDJ2eVDDiT8rg4/91BvisxWe9lf7dFLhlMyo=; b=N0HENhX/6ocCYIF2tFnqX6DWyM5CuSksRbjPV8Lauz1dYNTbk5C5zfc4A/WjXsmKlOODE4R/H8e/DsYW+SZMPHXDiUYtAskCeS3XHUsykd9Q3fukvcCj3ftKiD9wYOB8HfznRKztckX77Kd/gF/WiZPdH87moJD23roBSZAbo5JJ7h+2IsmFM5zQZxLBhZtzov3ssRWAvuAI+h5FthKecNmcJ9C6xyOLmQQHGO/E7/ASaRRWf6mPqXBkJ9Kj5spjBUGkEZXnxapBdNnnMMwtWB5qqlO/+aEbfRQjUz7+skbeIZjIxAM9FBPksOi6avyQlDHF5/Nbz7idojzmtoySBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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=LENG8yRUDJ2eVDDiT8rg4/91BvisxWe9lf7dFLhlMyo=; b=yFyB35CjDqNHZUDcJ6vWqKr8JYergS1SgMpiI7rdmM3SohmXFyhevYY6EvNz9VUgs3437e+wKUY/UIVGGTQ0gqsQZb3gPZMw/82QiCNM6icmTdmnqYF9SmbyrCwnfN2MapAFKJhqsfQboqhsqYsvbfsUagPnuFd5Q6RfpwqupCo= Received: from MW4PR03CA0038.namprd03.prod.outlook.com (2603:10b6:303:8e::13) by PH7PR12MB6956.namprd12.prod.outlook.com (2603:10b6:510:1b9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8678.33; Mon, 28 Apr 2025 06:31:18 +0000 Received: from SN1PEPF0002BA4B.namprd03.prod.outlook.com (2603:10b6:303:8e:cafe::b0) by MW4PR03CA0038.outlook.office365.com (2603:10b6:303:8e::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.36 via Frontend Transport; Mon, 28 Apr 2025 06:31:17 +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 SN1PEPF0002BA4B.mail.protection.outlook.com (10.167.242.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8678.33 via Frontend Transport; Mon, 28 Apr 2025 06:31:17 +0000 Received: from amd.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; Mon, 28 Apr 2025 01:31:14 -0500 From: Akshay Gupta To: , CC: , , , , , , , , Akshay Gupta Subject: [PATCH v9 07/10] misc: amd-sbi: Add support for CPUID protocol Date: Mon, 28 Apr 2025 06:30:31 +0000 Message-ID: <20250428063034.2145566-8-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250428063034.2145566-1-akshay.gupta@amd.com> References: <20250428063034.2145566-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SN1PEPF0002BA4B:EE_|PH7PR12MB6956:EE_ X-MS-Office365-Filtering-Correlation-Id: 1294c6a4-1c39-4c9f-bba2-08dd861e485c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?KOofephLN8UFlEyAPbllQ+/szcTLuCHSHTyPNlgf4iIrcEblGwhCK0dx38iV?= =?us-ascii?Q?DqsW3mcSqZ6L1n3K7JHqwivc8gkxS5WNXeY/fugKDCWtnEUn9SmPQE6eFYeM?= =?us-ascii?Q?mhdoVLPx6+jmFIXTjv7c8UGw0PtQ72SY2Np7EUcfPWwaDBlRYFnWpsiOyT61?= =?us-ascii?Q?iup0+kTF0fyKmmUqPKa4vtWp2EUiYUGZRccFUjlzrrPA5oaWditcHDZX8Imz?= =?us-ascii?Q?rZ5V4y3OcyQ4+5pDY4gcWkOfctnacHegJ1+6feJxH//aZYkC5GbdzLDE4iAq?= =?us-ascii?Q?7oDTR1v0uuLM5/6A20ukUV4NDztdB/5lYyiOGRWKpMVzB3TQfVapScM8adoN?= =?us-ascii?Q?473PLeQ3UTCI7Wih/vYXYujRxyJk16hnV14oZI/j+SQl8jErtRow/bJClosU?= =?us-ascii?Q?Tm81vWNzcsTg18l4rfUk/wsZGTRa+MBC8VE490361IFQjOiIH+bITzEfWjJ6?= =?us-ascii?Q?unggPh12IBK/rGokF+dJuwoEC5dp0sSjI5JUaJbz4q5ld6MQj0J0u2+0US0l?= =?us-ascii?Q?D94eRyfblZzmPlqDQYN+pbLkpsH50mDD0XYiciq/oD0Ntv7hUMDPVczLhAQN?= =?us-ascii?Q?oghrtU65h6QE5riLin570ed0vSFMjvSe8c75D0YlNhjQBu4spd2wem/xphuw?= =?us-ascii?Q?kv+em+R2ydvbz3YdiDLVCNNg6/KuNON3Wtm8RiMSepfnHARK1bsx67kaeGP9?= =?us-ascii?Q?Gioin0G5K9KXz0CCUplIifB/2PzuJvMabwURu7NQzCQGdzr5eAO0n+sWCXRu?= =?us-ascii?Q?TnZPv3VL0O7JObT9v3dNQw4se6gTlt+rz9rp6Aw+oxKnCSlLSuEntyvkKTAb?= =?us-ascii?Q?VJciyfMVDSH27SEi3PeYtmyXRGWvABaOOez5oigrvk7p486+EyydH6UaiaLZ?= =?us-ascii?Q?RD7PsyysvaPz/HUuN0fyAyTpV4aZdowWrvZTb1V7tK0OFhkjAZqPLdwGTbx6?= =?us-ascii?Q?b4ouEFhgTw//7XRaq9BKeialG5hwguKXRA4wh52dECSER9oym4dYu5TKRV3N?= =?us-ascii?Q?Qa1GwkT4c5Gwbej6xXgme7LiOIydmjfVmwbzhwzjHu2HPA6PhF+frVJHyT77?= =?us-ascii?Q?Ukob7utdfg0oj0f/Zu1n74wB+cL7V4QTLwFg9Mig+kMn+wGy7Mw4RXyp7yMu?= =?us-ascii?Q?SQ3Cu+U11EZYKUP7apbO4dX2LcrHi0j7m8VDjC6XSNojWRL39ZviiW15MfuH?= =?us-ascii?Q?JPyF75KNzXsbahOOZxvizNCbiLBjKtfgSUdwxTk092KhdgbWkIwGrAiJvQJm?= =?us-ascii?Q?Lpd9oswa4MLPtycRRUSGOuxM7/16fqZTF716//p+X6EYVp2d7T2JS6abrLcK?= =?us-ascii?Q?HA/HdmTpAkOkHz6zlav1vVPha72Yov1LsBTaYj2K7AWuzxmpnJtF7X0XVtVN?= =?us-ascii?Q?ADVLVTMlzgeAv2ivQ+mVw6GkNAzn8WuYVBVCWUs/87QEyJGMpwJlOug4V385?= =?us-ascii?Q?t6LThmbhOrS3Krt4G3IS07rHuF0aPGKNMLYaTFtuirf3/c+CtFo0YMABCCtk?= =?us-ascii?Q?LyZCeNb+FTfWNeqljnWtsA4I5Ft7n0TySiTR?= 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)(36860700013)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2025 06:31:17.7109 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1294c6a4-1c39-4c9f-bba2-08dd861e485c 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: SN1PEPF0002BA4B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6956 Content-Type: text/plain; charset="utf-8" - AMD provides custom protocol to read Processor feature capabilities and configuration information through side band. The information is accessed by providing CPUID Function, extended function and thread ID to the protocol. Undefined function returns 0. Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v7: - Address Arnd comment: - New IOCTL and structure defined to separate ioctl for each protocol Changes since v6: - Address Arnd comment - Add padding to the uapi structure - Rebased patch, previously patch 8 Changes since v5: - Patch rebased Changes since v4: - Previously patch 6 - Address review comments Changes since v3: - Address review comments: - update the #define to inline function - pack the union inside the structure Changes since v2: - update the MACROS name as per feedback Changes since v1: - bifurcated from previous patch 5 drivers/misc/amd-sbi/rmi-core.c | 168 ++++++++++++++++++++++++++++++++ drivers/misc/amd-sbi/rmi-core.h | 5 +- include/uapi/misc/amd-apml.h | 37 +++++++ 3 files changed, 209 insertions(+), 1 deletion(-) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-cor= e.c index 7d13c049c98d..471f50f0c368 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -17,11 +17,160 @@ =20 /* Mask for Status Register bit[1] */ #define SW_ALERT_MASK 0x2 +/* Mask to check H/W Alert status bit */ +#define HW_ALERT_MASK 0x80 =20 /* Software Interrupt for triggering */ #define START_CMD 0x80 #define TRIGGER_MAILBOX 0x01 =20 +/* Default message lengths as per APML command protocol */ +/* CPUID */ +#define CPUID_RD_DATA_LEN 0x8 +#define CPUID_WR_DATA_LEN 0x8 +#define CPUID_RD_REG_LEN 0xa +#define CPUID_WR_REG_LEN 0x9 + +/* CPUID MSR Command Ids */ +#define CPUID_MCA_CMD 0x73 +#define RD_CPUID_CMD 0x91 + +/* CPUID MCAMSR mask & index */ +#define CPUID_MCA_THRD_MASK GENMASK(15, 0) +#define CPUID_MCA_THRD_INDEX 32 +#define CPUID_MCA_FUNC_MASK GENMASK(31, 0) +#define CPUID_EXT_FUNC_INDEX 56 + +/* input for bulk write to CPUID protocol */ +struct cpu_msr_indata { + u8 wr_len; /* const value */ + u8 rd_len; /* const value */ + u8 proto_cmd; /* const value */ + u8 thread; /* thread number */ + union { + u8 reg_offset[4]; /* input value */ + u32 value; + } __packed; + u8 ext; /* extended function */ +}; + +/* output for bulk read from CPUID protocol */ +struct cpu_msr_outdata { + u8 num_bytes; /* number of bytes return */ + u8 status; /* Protocol status code */ + union { + u64 value; + u8 reg_data[8]; + } __packed; +}; + +static inline void prepare_cpuid_input_message(struct cpu_msr_indata *inpu= t, + u8 thread_id, u32 func, + u8 ext_func) +{ + input->rd_len =3D CPUID_RD_DATA_LEN; + input->wr_len =3D CPUID_WR_DATA_LEN; + input->proto_cmd =3D RD_CPUID_CMD; + input->thread =3D thread_id << 1; + input->value =3D func; + input->ext =3D ext_func; +} + +static int sbrmi_get_rev(struct sbrmi_data *data) +{ + unsigned int rev; + u16 offset =3D SBRMI_REV; + int ret; + + ret =3D regmap_read(data->regmap, offset, &rev); + if (ret < 0) + return ret; + + data->rev =3D rev; + return 0; +} + +/* Read CPUID function protocol */ +static int rmi_cpuid_read(struct sbrmi_data *data, + struct apml_cpuid_msg *msg) +{ + struct cpu_msr_indata input =3D {0}; + struct cpu_msr_outdata output =3D {0}; + int val =3D 0; + int ret, hw_status; + u16 thread; + + mutex_lock(&data->lock); + /* cache the rev value to identify if protocol is supported or not */ + if (!data->rev) { + ret =3D sbrmi_get_rev(data); + if (ret < 0) + goto exit_unlock; + } + /* CPUID protocol for REV 0x10 is not supported*/ + if (data->rev =3D=3D 0x10) { + ret =3D -EOPNOTSUPP; + goto exit_unlock; + } + + thread =3D msg->cpu_in_out << CPUID_MCA_THRD_INDEX & CPUID_MCA_THRD_MASK; + + /* Thread > 127, Thread128 CS register, 1'b1 needs to be set to 1 */ + if (thread > 127) { + thread -=3D 128; + val =3D 1; + } + ret =3D regmap_write(data->regmap, SBRMI_THREAD128CS, val); + if (ret < 0) + goto exit_unlock; + + prepare_cpuid_input_message(&input, thread, + msg->cpu_in_out & CPUID_MCA_FUNC_MASK, + msg->cpu_in_out >> CPUID_EXT_FUNC_INDEX); + + ret =3D regmap_bulk_write(data->regmap, CPUID_MCA_CMD, + &input, CPUID_WR_REG_LEN); + if (ret < 0) + goto exit_unlock; + + /* + * For RMI Rev 0x20, new h/w status bit is introduced. which is used + * by firmware to indicate completion of commands (0x71, 0x72, 0x73). + * wait for the status bit to be set by the hardware before + * reading the data out. + */ + ret =3D regmap_read_poll_timeout(data->regmap, SBRMI_STATUS, hw_status, + hw_status & HW_ALERT_MASK, 500, 2000000); + if (ret) + goto exit_unlock; + + ret =3D regmap_bulk_read(data->regmap, CPUID_MCA_CMD, + &output, CPUID_RD_REG_LEN); + if (ret < 0) + goto exit_unlock; + + ret =3D regmap_write(data->regmap, SBRMI_STATUS, + HW_ALERT_MASK); + if (ret < 0) + goto exit_unlock; + + if (output.num_bytes !=3D CPUID_RD_REG_LEN - 1) { + ret =3D -EMSGSIZE; + goto exit_unlock; + } + if (output.status) { + ret =3D -EPROTOTYPE; + msg->fw_ret_code =3D output.status; + goto exit_unlock; + } + msg->cpu_in_out =3D output.value; +exit_unlock: + if (ret < 0) + msg->cpu_in_out =3D 0; + mutex_unlock(&data->lock); + return ret; +} + int rmi_mailbox_xfer(struct sbrmi_data *data, struct apml_mbox_msg *msg) { @@ -123,6 +272,23 @@ static int apml_mailbox_xfer(struct sbrmi_data *data, = struct apml_mbox_msg __use return copy_to_user(arg, &msg, sizeof(struct apml_mbox_msg)); } =20 +static int apml_cpuid_xfer(struct sbrmi_data *data, struct apml_cpuid_msg = __user *arg) +{ + struct apml_cpuid_msg msg =3D { 0 }; + int ret; + + /* Copy the structure from user */ + if (copy_from_user(&msg, arg, sizeof(struct apml_cpuid_msg))) + return -EFAULT; + + /* CPUID Protocol */ + ret =3D rmi_cpuid_read(data, &msg); + if (ret && ret !=3D -EPROTOTYPE) + return ret; + + return copy_to_user(arg, &msg, sizeof(struct apml_cpuid_msg)); +} + static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long a= rg) { void __user *argp =3D (void __user *)arg; @@ -132,6 +298,8 @@ static long sbrmi_ioctl(struct file *fp, unsigned int c= md, unsigned long arg) switch (cmd) { case SBRMI_IOCTL_MBOX_CMD: return apml_mailbox_xfer(data, argp); + case SBRMI_IOCTL_CPUID_CMD: + return apml_cpuid_xfer(data, argp); default: return -ENOTTY; } diff --git a/drivers/misc/amd-sbi/rmi-core.h b/drivers/misc/amd-sbi/rmi-cor= e.h index 8ab31c6852d1..975ae858e9fd 100644 --- a/drivers/misc/amd-sbi/rmi-core.h +++ b/drivers/misc/amd-sbi/rmi-core.h @@ -15,7 +15,8 @@ =20 /* SB-RMI registers */ enum sbrmi_reg { - SBRMI_CTRL =3D 0x01, + SBRMI_REV, + SBRMI_CTRL, SBRMI_STATUS, SBRMI_OUTBNDMSG0 =3D 0x30, SBRMI_OUTBNDMSG1, @@ -34,6 +35,7 @@ enum sbrmi_reg { SBRMI_INBNDMSG6, SBRMI_INBNDMSG7, SBRMI_SW_INTERRUPT, + SBRMI_THREAD128CS =3D 0x4b, }; =20 /* @@ -56,6 +58,7 @@ struct sbrmi_data { struct mutex lock; u32 pwr_limit_max; u8 dev_static_addr; + u8 rev; }; =20 int rmi_mailbox_xfer(struct sbrmi_data *data, struct apml_mbox_msg *msg); diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h index a5f086f84b06..bb57dc75758a 100644 --- a/include/uapi/misc/amd-apml.h +++ b/include/uapi/misc/amd-apml.h @@ -25,6 +25,24 @@ struct apml_mbox_msg { __u32 fw_ret_code; }; =20 +struct apml_cpuid_msg { + /* + * CPUID input + * [0]...[3] cpuid func, + * [4][5] cpuid: thread + * [6] cpuid: ext function & read eax/ebx or ecx/edx + * [7:0] -> bits [7:4] -> ext function & + * bit [0] read eax/ebx or ecx/edx + * CPUID output + */ + __u64 cpu_in_out; + /* + * Status code for CPUID read + */ + __u32 fw_ret_code; + __u32 pad; +}; + /* * AMD sideband interface base IOCTL */ @@ -48,4 +66,23 @@ struct apml_mbox_msg { */ #define SBRMI_IOCTL_MBOX_CMD _IOWR(SB_BASE_IOCTL_NR, 0, struct apml_mbox_= msg) =20 +/** + * DOC: SBRMI_IOCTL_CPUID_CMD + * + * @Parameters + * + * @struct apml_cpuid_msg + * Pointer to the &struct apml_cpuid_msg that will contain the protocol + * information + * + * @Description + * IOCTL command for APML messages using generic _IOWR + * The IOCTL provides userspace access to AMD sideband cpuid protocol + * - CPUID protocol to get CPU details for Function/Ext Function + * at thread level + * - returning "-EFAULT" if none of the above + * "-EPROTOTYPE" error is returned to provide additional error details + */ +#define SBRMI_IOCTL_CPUID_CMD _IOWR(SB_BASE_IOCTL_NR, 1, struct apml_cpui= d_msg) + #endif /*_AMD_APML_H_*/ --=20 2.25.1 From nobody Fri Dec 19 00:53:39 2025 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2079.outbound.protection.outlook.com [40.107.236.79]) (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 824931CAA7B; Mon, 28 Apr 2025 06:31:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821888; cv=fail; b=X44o6KSj/HEQv1dDN88f0TGLt1byeen3A+9WMcXgqmK4ZjjXuBUB441dRPgNDcANQ+RsUaKU+jCCwb5PnYvHJiPiDUptOASKuzoEdNiJMkLJN+H09NtpAI5HRZBZiLbQWGl20fFJgdxqgfw7PxnlNr3zjd6CBxCgBtKcx6gDykg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821888; c=relaxed/simple; bh=Rnx8RJYrz+aMV2vqmpxUJr6mlnIFAZ+52zVt2L4Ub34=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UHe/2iQKqZzt5KUiRxNieR4lhlrLFlM+eR6m70najj6wcX9ecbrSScTenQSZVMaDB0ldc1GibKJhON5ON/tzUH5+GD6qjvWamZg2MSQBUJI9c3I6SjL0IvxTpWxa1BTFaxfGlPDEy6l75OznHiNz98Sm1Bi9gKUBupUERW7C0T0= 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=ImJt+/83; arc=fail smtp.client-ip=40.107.236.79 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="ImJt+/83" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DlwRMbLM1iHGMRAUcIDFqt6U+KepBN2S5u2Wi3a+gSu1bhD8v8Ok2GLn4xV5zx/ygtSMWzme1tVNwHVUIg0Wz2zOQWLkoEhXcbJRoD9xrQiCWfvYltLc0R0QsrI1GWwSfNrB+UcH/MOAT//ykz3QiCIiorU5w90/bOdkGDgUw9snl26PFt/5ErRMP9b61rnRaiuWywCja25oTOyUbjQyZzw7rWnT9DHEC2J/8jsWm/UZiu2u4+aHXjahFfzvCev8kS8ETGDQJDHFwY0DlFYyU2prKBsq+S6Fs/Y+KOJvtUK46YyALSXHESdn1zrp5WVIqoe2H8iWeDbQs+B+1U/Q2Q== 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=j/B40bcmO+Pz3vROJyMu3i0f3dg+6qkDvocNPqvHUbs=; b=Am1GKYNdSkaZy3eu+a4M1f3+IdOi9tGsT+myn58W7hNqfBtJFLN1nQmygiwHCjgu0Z1Co1EqboUMJ3xlty0y6k41U4dEzMQ4IhvAnas5OR7o7EVkbD4edwOBY3WBrxbmdnlZn4cINSoz2ubxF83w2qPZfXhOxeI7W5jmYEgQWpPFp/P8FxiNmhii8koGLVffBpi057i14L03T4vXER6rOr+gtu8mIUQ8Ww3/yC6af4mZ0JfDAV738hLBcBFU9xPLlH08Zrrak3Owf/MhiAOeZh9QPO+JFg7hmrZB4ocWUyK4YXS3MKV+r51twvHtLoR9JYwGINAl7TkZSB2JfpUGBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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=j/B40bcmO+Pz3vROJyMu3i0f3dg+6qkDvocNPqvHUbs=; b=ImJt+/83KkeCWMQfpnQ69Ksj2ACiFM/sBaeTB6aNKVNwDSmR81PceXwhOmgIp/bGN8255vdf9oySIN4XfxvOH6qQRDoN/o8bh5Z+PjSKgr1XwvQH0x8IpTouVWtT94w5rkyhN7msvCFSiygR06T0pd32osR2SPVBtksviPcY87M= Received: from MW4PR03CA0046.namprd03.prod.outlook.com (2603:10b6:303:8e::21) by SA0PR12MB4352.namprd12.prod.outlook.com (2603:10b6:806:9c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8678.33; Mon, 28 Apr 2025 06:31:22 +0000 Received: from SN1PEPF0002BA4B.namprd03.prod.outlook.com (2603:10b6:303:8e:cafe::ad) by MW4PR03CA0046.outlook.office365.com (2603:10b6:303:8e::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.36 via Frontend Transport; Mon, 28 Apr 2025 06:31:21 +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 SN1PEPF0002BA4B.mail.protection.outlook.com (10.167.242.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8678.33 via Frontend Transport; Mon, 28 Apr 2025 06:31:21 +0000 Received: from amd.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; Mon, 28 Apr 2025 01:31:17 -0500 From: Akshay Gupta To: , CC: , , , , , , , , Akshay Gupta Subject: [PATCH v9 08/10] misc: amd-sbi: Add support for read MCA register protocol Date: Mon, 28 Apr 2025 06:30:32 +0000 Message-ID: <20250428063034.2145566-9-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250428063034.2145566-1-akshay.gupta@amd.com> References: <20250428063034.2145566-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SN1PEPF0002BA4B:EE_|SA0PR12MB4352:EE_ X-MS-Office365-Filtering-Correlation-Id: aacdfdfa-2ad2-4418-d22b-08dd861e4a9f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?FvNVdaykDLFn9SeRMXdRmQ1XLZBkiIk1Po1CmKloVV+UEqB8Dyxply+QldXc?= =?us-ascii?Q?KcPvv4HtpqRlhJ/6BSIiSPs2MH+/bz5am/368JN85B2p3wR8ZEltU079N8y3?= =?us-ascii?Q?WpVh3YatYwmZIS8awPjJxIm9gxeoScochQQeJ1u4awvqfnAL6++RoPBDsb/4?= =?us-ascii?Q?12lNAd47rAGJNHtHsntc3MBcmxaV95t6KYFfUI5LW0TDRbRsFPPoqGpUlJnR?= =?us-ascii?Q?BjI3SQKjmWdoznd+4+Kv6lVVGW8Fq9RP3Piz9W000zH29Od1Aik4c3V9Pufu?= =?us-ascii?Q?hcUYuEOrWvoNM8ZO7VFwlNQxbc6DSIvWWYrpgzltYa1zxtKqhyPytdpMxb4M?= =?us-ascii?Q?CupZxug4N8PK5U7D41CfoV8j22Uvc91vXxWBt8/Cij+rEYHoJwF7JgM5UyBt?= =?us-ascii?Q?Z1h8sQieU95dmxlbLQJgil0zG81c1WucmTDB+s7/VCBrLzCUFabxo0MsVi2P?= =?us-ascii?Q?1ltU4XodNbLGz2OhaqrDJ/5W7usThRzrkUQat6aCmHPKyqMLYyqnzk/zpDRO?= =?us-ascii?Q?kVNuzKNWm4/XqNLoz0W4plN5khqc1ERThI50ZMaqNCAVBw6fCuP8Ay4jD0jm?= =?us-ascii?Q?nKpDw2/P/uKAF0I3rtjXHzZx9b9gMpvXl0SKRvJjNgFoUeRREAjU+krGL/k1?= =?us-ascii?Q?9dHoDs8wvEFPXBT5UZuJUspOGsbUb1e21WvZp0z04zPbqn7hFwbOd9+AwyxO?= =?us-ascii?Q?wgake+sKRDxeieLSyZpSDgDB6IU0J61ywkZlXS8fySOBk08Vzn/Ol40aDbi1?= =?us-ascii?Q?wBN/ar0ly9f4gsPMv0738lfORb4E4rhIxoi5OpxK7JXHdsleJ5cPoMHhFnsT?= =?us-ascii?Q?LmdeYzasOOGAe3u5aeki8c9t6YEzmjxt1K0+kcvz7bvFjCSkjbb0ZRE6Fb5C?= =?us-ascii?Q?aHPTrX7EYZJ6F85lAgFeHNunFEcsJYXiKPWbDaaMKHKYRfd0yG1WaQTYx76Q?= =?us-ascii?Q?fDXssWh3dEdp3JoRoh/WZ0x6xKcVepmV+z9xm+mnrl0DMw+M1JQmcaptpzBs?= =?us-ascii?Q?ZGt0TASDBycFaLm/y/gphC7APifFVM0oJqdlA2s8pdJwfSwR6flWyvLmWlpE?= =?us-ascii?Q?FFHagpjkoE2PaLJaN5t5jOKo/K/qIOuXUfKT+iM+OOonQ1mEsRzS5hJwDVFL?= =?us-ascii?Q?7H+mTkq8wtVRA97fR9T22VCOc4+5/KmEKKGTVs37Ph2Kz79LWryXKFZ6eXX2?= =?us-ascii?Q?NaD0KLqIEn3FhDGWuMeEmzSjTUVfGZTBqXMJ6zsQOeUCQ3BVumiCIMz0qdgt?= =?us-ascii?Q?rUV8QJ4AT6iQA4bOHXXzzHhL/AHhsFdrxqYT5WyQX2IzwKL9Er+NnqJbMS60?= =?us-ascii?Q?l7TFPycEv8IgagUxHy3R+Z/BGpRROscJ/qYDrsoM6OkgJlhrWvwVbERQwZj4?= =?us-ascii?Q?mrZQKw5KmosqNXAUVI+8lLIVgiDkQ7iUjjmHjdBrdMRPA83pnufHWMf2sHuB?= =?us-ascii?Q?b/D4blJ/3hnWVjoqOd0ETOoQeEgWnnJVKDr3vgigVYrw+fO7l7tPEPf43m8q?= =?us-ascii?Q?ZIyc5mhJ7fkn5VEMU2SAbJIpHMVuU8R01Yo1?= 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)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2025 06:31:21.5057 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aacdfdfa-2ad2-4418-d22b-08dd861e4a9f 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: SN1PEPF0002BA4B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4352 Content-Type: text/plain; charset="utf-8" - AMD provides custom protocol to read Machine Check Architecture(MCA) registers over sideband. The information is accessed for range of MCA registers by passing register address and thread ID to the protocol. MCA register read command using the register address to access Core::X86::Msr::MCG_CAP which determines the number of MCA banks. Access is read-only Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v7: - Address Arnd comment: - New IOCTL and structure defined to separate ioctl for each protocol Changes since v6: - Rebased patch, previously patch 9 Changes since v5: - Patch rebased Changes since v4: - Previously patch 7 - Address review comment for documentation warning Changes since v3: - Address review comments: - update the #define to inline function - pack the union inside the structure Changes since v2: - update the MACROS name as per feedback Changes since v1: - bifurcated from previous patch 5 drivers/misc/amd-sbi/rmi-core.c | 114 ++++++++++++++++++++++++++++++++ include/uapi/misc/amd-apml.h | 33 +++++++++ 2 files changed, 147 insertions(+) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-cor= e.c index 471f50f0c368..171d6e871373 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -30,10 +30,16 @@ #define CPUID_WR_DATA_LEN 0x8 #define CPUID_RD_REG_LEN 0xa #define CPUID_WR_REG_LEN 0x9 +/* MSR */ +#define MSR_RD_REG_LEN 0xa +#define MSR_WR_REG_LEN 0x8 +#define MSR_RD_DATA_LEN 0x8 +#define MSR_WR_DATA_LEN 0x7 =20 /* CPUID MSR Command Ids */ #define CPUID_MCA_CMD 0x73 #define RD_CPUID_CMD 0x91 +#define RD_MCA_CMD 0x86 =20 /* CPUID MCAMSR mask & index */ #define CPUID_MCA_THRD_MASK GENMASK(15, 0) @@ -76,6 +82,16 @@ static inline void prepare_cpuid_input_message(struct cp= u_msr_indata *input, input->ext =3D ext_func; } =20 +static inline void prepare_mca_msr_input_message(struct cpu_msr_indata *in= put, + u8 thread_id, u32 data_in) +{ + input->rd_len =3D MSR_RD_DATA_LEN; + input->wr_len =3D MSR_WR_DATA_LEN; + input->proto_cmd =3D RD_MCA_CMD; + input->thread =3D thread_id << 1; + input->value =3D data_in; +} + static int sbrmi_get_rev(struct sbrmi_data *data) { unsigned int rev; @@ -171,6 +187,85 @@ static int rmi_cpuid_read(struct sbrmi_data *data, return ret; } =20 +/* MCA MSR protocol */ +static int rmi_mca_msr_read(struct sbrmi_data *data, + struct apml_mcamsr_msg *msg) +{ + struct cpu_msr_outdata output =3D {0}; + struct cpu_msr_indata input =3D {0}; + int ret, val =3D 0; + int hw_status; + u16 thread; + + mutex_lock(&data->lock); + /* cache the rev value to identify if protocol is supported or not */ + if (!data->rev) { + ret =3D sbrmi_get_rev(data); + if (ret < 0) + goto exit_unlock; + } + /* MCA MSR protocol for REV 0x10 is not supported*/ + if (data->rev =3D=3D 0x10) { + ret =3D -EOPNOTSUPP; + goto exit_unlock; + } + + thread =3D msg->mcamsr_in_out << CPUID_MCA_THRD_INDEX & CPUID_MCA_THRD_MA= SK; + + /* Thread > 127, Thread128 CS register, 1'b1 needs to be set to 1 */ + if (thread > 127) { + thread -=3D 128; + val =3D 1; + } + ret =3D regmap_write(data->regmap, SBRMI_THREAD128CS, val); + if (ret < 0) + goto exit_unlock; + + prepare_mca_msr_input_message(&input, thread, + msg->mcamsr_in_out & CPUID_MCA_FUNC_MASK); + + ret =3D regmap_bulk_write(data->regmap, CPUID_MCA_CMD, + &input, MSR_WR_REG_LEN); + if (ret < 0) + goto exit_unlock; + + /* + * For RMI Rev 0x20, new h/w status bit is introduced. which is used + * by firmware to indicate completion of commands (0x71, 0x72, 0x73). + * wait for the status bit to be set by the hardware before + * reading the data out. + */ + ret =3D regmap_read_poll_timeout(data->regmap, SBRMI_STATUS, hw_status, + hw_status & HW_ALERT_MASK, 500, 2000000); + if (ret) + goto exit_unlock; + + ret =3D regmap_bulk_read(data->regmap, CPUID_MCA_CMD, + &output, MSR_RD_REG_LEN); + if (ret < 0) + goto exit_unlock; + + ret =3D regmap_write(data->regmap, SBRMI_STATUS, + HW_ALERT_MASK); + if (ret < 0) + goto exit_unlock; + + if (output.num_bytes !=3D MSR_RD_REG_LEN - 1) { + ret =3D -EMSGSIZE; + goto exit_unlock; + } + if (output.status) { + ret =3D -EPROTOTYPE; + msg->fw_ret_code =3D output.status; + goto exit_unlock; + } + msg->mcamsr_in_out =3D output.value; + +exit_unlock: + mutex_unlock(&data->lock); + return ret; +} + int rmi_mailbox_xfer(struct sbrmi_data *data, struct apml_mbox_msg *msg) { @@ -289,6 +384,23 @@ static int apml_cpuid_xfer(struct sbrmi_data *data, st= ruct apml_cpuid_msg __user return copy_to_user(arg, &msg, sizeof(struct apml_cpuid_msg)); } =20 +static int apml_mcamsr_xfer(struct sbrmi_data *data, struct apml_mcamsr_ms= g __user *arg) +{ + struct apml_mcamsr_msg msg =3D { 0 }; + int ret; + + /* Copy the structure from user */ + if (copy_from_user(&msg, arg, sizeof(struct apml_mcamsr_msg))) + return -EFAULT; + + /* MCAMSR Protocol */ + ret =3D rmi_mca_msr_read(data, &msg); + if (ret && ret !=3D -EPROTOTYPE) + return ret; + + return copy_to_user(arg, &msg, sizeof(struct apml_mcamsr_msg)); +} + static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long a= rg) { void __user *argp =3D (void __user *)arg; @@ -300,6 +412,8 @@ static long sbrmi_ioctl(struct file *fp, unsigned int c= md, unsigned long arg) return apml_mailbox_xfer(data, argp); case SBRMI_IOCTL_CPUID_CMD: return apml_cpuid_xfer(data, argp); + case SBRMI_IOCTL_MCAMSR_CMD: + return apml_mcamsr_xfer(data, argp); default: return -ENOTTY; } diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h index bb57dc75758a..f718675d3966 100644 --- a/include/uapi/misc/amd-apml.h +++ b/include/uapi/misc/amd-apml.h @@ -43,6 +43,21 @@ struct apml_cpuid_msg { __u32 pad; }; =20 +struct apml_mcamsr_msg { + /* + * MCAMSR input + * [0]...[3] mca msr func, + * [4][5] thread + * MCAMSR output + */ + __u64 mcamsr_in_out; + /* + * Status code for MCA/MSR access + */ + __u32 fw_ret_code; + __u32 pad; +}; + /* * AMD sideband interface base IOCTL */ @@ -85,4 +100,22 @@ struct apml_cpuid_msg { */ #define SBRMI_IOCTL_CPUID_CMD _IOWR(SB_BASE_IOCTL_NR, 1, struct apml_cpui= d_msg) =20 +/** + * DOC: SBRMI_IOCTL_MCAMSR_CMD + * + * @Parameters + * + * @struct apml_mcamsr_msg + * Pointer to the &struct apml_mcamsr_msg that will contain the protocol + * information + * + * @Description + * IOCTL command for APML messages using generic _IOWR + * The IOCTL provides userspace access to AMD sideband MCAMSR protocol + * - MCAMSR protocol to get MCA bank details for Function at thread level + * - returning "-EFAULT" if none of the above + * "-EPROTOTYPE" error is returned to provide additional error details + */ +#define SBRMI_IOCTL_MCAMSR_CMD _IOWR(SB_BASE_IOCTL_NR, 2, struct apml_mca= msr_msg) + #endif /*_AMD_APML_H_*/ --=20 2.25.1 From nobody Fri Dec 19 00:53:39 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2074.outbound.protection.outlook.com [40.107.93.74]) (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 0A0F9610C; Mon, 28 Apr 2025 06:31:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821892; cv=fail; b=j811ZMC0wBqZXc8O08JKdou8TcIV1myZF+8ZAV7t8LLlXW7CYWEz3EATft7RxSHCT8MUIK3vSOtVEhFhMdc6dlCVnCkVlGr1OgPXWtR30hdTFmNmZm85KetBho6Jul7jE1kZm9EHQ5z7tuuvn70eZQXDb2O3tTmpOTzQzP/eKbA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821892; c=relaxed/simple; bh=0ekX2teoGyjbkOhLud3zXWMIN40wL0EBsyfUCg2XIho=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ite6I1+cDxzkBaMJR5yj6IJstP2M5tvzWsUWYYaZMgKrYGSsPP80ZXpDkieH8LmvBioh7vhLZdjaQj9IiTzSXjUygQm9MdVpG1eazwQy7S3hEOpQ2bUyVjbfBHkxjzg7TBZqFIlhj+pYH6bGUmL9EFpNF/OEYuu6x37utN8zF0k= 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=FnpFfR+l; arc=fail smtp.client-ip=40.107.93.74 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="FnpFfR+l" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RTmGMDCE+ltcorWPcUX8rwSXbgbdVnkfLdLDn9Pv2yhKh0nusBfaLrw0Wk/TRCbcOAlhn0VcBcggJqVnzTDYJ0ZDzU7DxH1HAsvsLL0gJVYj3By2a9YfnfTtRTtEX4kZhQ695armZbG8hDtUlD9I1fLYGMMxgejzXDQmWVKp+NRYG9FPSCdRA36WqSqS0mNBXAdRTuPu+wNWaINvptM3aef/pyFcUdUz3ahWG8wdVe4HbcRJz5sETUk5Oz3IBLR9bMjbSAF1fyuXLxJmI3xH7nyGSfigW8zUg4z3uSfToTgRfpPIrTeU6f0byGARbgrybmdFPPhGauDWYH21gPUkbA== 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=W+Zs9DGFr+e2t1LrIK3wxWePOb4KFd4Bq7S/aiOPqyc=; b=R0Fnh7jX7ns1GEPa7PubgLCxDdioCw7/SKB4qLzoBgBH34yaxQGPYwRHg8nGKptxZ5e7YTW7MhkPQ+CiWPafVJ+zgU6+04foZFfvq+uEoYcHQsQjcQ8Kyw9xN0gRHXJxTvtgJKLbEWGGpif3jcnf6jF4+H8QW5T3/+pthOLyJIt5yLyxAjsNWy/8E0EMuWTj3+a993M9cA8nrx5XjFs4yh7rflAXxPxN0F3euAeoRbUkh4a+QaOgcO6/s27cKzH+a8biZXcmH41B4alhDriu2EQ0IteokG3KwmBJGFhgmlDmW/jVAdFEHx8tvwFzsuX9FGSjwLTxRAOTcPtFUPR9DQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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=W+Zs9DGFr+e2t1LrIK3wxWePOb4KFd4Bq7S/aiOPqyc=; b=FnpFfR+lC8HH0+vpRtgYs01zQwG4UvHKEkdkygSVURejlT2i21zhiQ9w8lDK85C5gjYWGG5b4xBhb9d5i0COZRmvnf5wa+lUprz7HCaIQiDmHUDLHeYZg0NXZsdKRszx1aNsTeOFORsTC8Q5T5Mu1rHT6bWtUTxDRFMAO+4qWcc= Received: from SN7PR04CA0084.namprd04.prod.outlook.com (2603:10b6:806:121::29) by MW6PR12MB8997.namprd12.prod.outlook.com (2603:10b6:303:23e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8678.27; Mon, 28 Apr 2025 06:31:25 +0000 Received: from SN1PEPF0002BA4C.namprd03.prod.outlook.com (2603:10b6:806:121:cafe::bd) by SN7PR04CA0084.outlook.office365.com (2603:10b6:806:121::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.41 via Frontend Transport; Mon, 28 Apr 2025 06:31:25 +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 SN1PEPF0002BA4C.mail.protection.outlook.com (10.167.242.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8678.33 via Frontend Transport; Mon, 28 Apr 2025 06:31:25 +0000 Received: from amd.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; Mon, 28 Apr 2025 01:31:21 -0500 From: Akshay Gupta To: , CC: , , , , , , , , Akshay Gupta Subject: [PATCH v9 09/10] misc: amd-sbi: Add support for register xfer Date: Mon, 28 Apr 2025 06:30:33 +0000 Message-ID: <20250428063034.2145566-10-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250428063034.2145566-1-akshay.gupta@amd.com> References: <20250428063034.2145566-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SN1PEPF0002BA4C:EE_|MW6PR12MB8997:EE_ X-MS-Office365-Filtering-Correlation-Id: 0b93c326-cdf9-484f-2d7f-08dd861e4cd1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?9dwtRo7wRDXWSeKrUw1ZKd464YnezRjr1dEH48qE+bgDAqE5gKjhsqeocTNF?= =?us-ascii?Q?Sr3piDaSEzc6ITcQ8akzHNpQh2zp/xjuQqxXkMhhHLX6dV+XbTRAJbf78QcZ?= =?us-ascii?Q?AomXnj3e+XzozE+gIuJfE++8qqCjtKZrfuSW+keoOSHO+9qgDWUtlz2sXTBY?= =?us-ascii?Q?RzDStPDnDiij9Ez2+SySXfzk4CaX6uRopj7SxanSb+CfwoyBM4PD/gIVxU3y?= =?us-ascii?Q?auzz/HQcaDo+86G23yDtJ5qRb4dhsq7N9RePgmPjgR4+aHE80IHsAbBWxaXu?= =?us-ascii?Q?NG9os2sfhNL2yiphZjQa5Z79fM52yg+3psy51BecpVwrRQjWa0S1kDirbri/?= =?us-ascii?Q?5E82SsS7N/lL2tpfxMVDoSBUpwf9FdEf+QCpMgasoN5fyT54tWL5Ksk5r6yJ?= =?us-ascii?Q?C0Fqik4BmoxbgaoFEZeTM9l2BuXh2WiF6XmhhTLrxFI0xGLCXyr/O/5hRl9b?= =?us-ascii?Q?hE3vGxHj7LcEx4cMcIwKlEuaqVVJ1WOU81SEIbQL2Oqb7TcQeYl/CJH1/Q7X?= =?us-ascii?Q?wbqVg3hCojm9uu1QDPj5V/OCrVfvSFI1CtAdtyYa/QuK9LCCV0GB5okFvMZc?= =?us-ascii?Q?avJVNlVtU5TZZw+4qMGTtt0xNNYcUdL/SA2nrIWnh9du0iMJHuSfbA+ewvVs?= =?us-ascii?Q?6s/VPltWYLWpc2J+Bbzddbcg9kQ1icq/CKA4VulW9LE/fEub3xHdkYjWMJEu?= =?us-ascii?Q?i5xIl/pz9FJQENZ8v+WAnC5yTcuZO77SX9F2KTD/yDmPdupzMcVJrbQ+l+h4?= =?us-ascii?Q?5SGZ7fO79yilImjqp1eAcz+0sDN+Kx/JKOR57uCgdwKKnlxSbEU5jOnJAMND?= =?us-ascii?Q?ZBWG/EDKqy4SXxN7hXRv/yCJXsg5vsJk+c4zSd/Gj0aZAkpA6LETqRar6VK0?= =?us-ascii?Q?p1GJXTEk1qSVnJf4kZdApDKbYPMqKA3KY9NIqXUlnanSW9DTlsVM4elqhd7j?= =?us-ascii?Q?0siqYHHgwDLT++IVdJQPVSESfLsgrvZZOf8Tl7obj3Vx+QfvS4K5i3dWPUIB?= =?us-ascii?Q?Fj3SyGuHlBpDdRKDvP9JYmd147Iek5YjRXld3wLQabMKQAJ71nCIqVDwglUu?= =?us-ascii?Q?MiMbwT6rhfQtStMcbFvDdE1YFJQDDsrQ2cK0NIjBQZ8DmjrREaBlk7RRHHtS?= =?us-ascii?Q?4Cf4xYh1cPbrqrRYng5VDOxUzhSSuR4X2FW/TZXbyyobtowJ9t9eqjHvmNZH?= =?us-ascii?Q?JHnq/0ZOpiV66AOI0ZdKex2wiXDjo5V8rAGtvmr1jgJSMwXuLGccseS2kXmb?= =?us-ascii?Q?yY378NgXEXfux252dRXKj9j4g+UcJrMjXanNPe2RBQ4ZP6HVM0/lbUWOFaWO?= =?us-ascii?Q?j7HGfu96AyfdMWz3Lb9snAxgB8igqnaN7VgIL6E1WAmiuyBeEa7+742PCKHT?= =?us-ascii?Q?3FRQKfNbP3lSj2PDEdkSGKgALcqA0rlY3AY+KnS+m8ADkfUAydBSEA3MvJE1?= =?us-ascii?Q?M+W/wWSOlE3KO57dikIm95UGET8CoTs9lrXQ7jJG07oep2f1UQ7FceTlV+9C?= =?us-ascii?Q?P9ZmzgOmyKXxnVf+5R7FgJZe3ivpaNzRO6qU?= 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)(376014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2025 06:31:25.1852 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0b93c326-cdf9-484f-2d7f-08dd861e4cd1 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: SN1PEPF0002BA4C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8997 Content-Type: text/plain; charset="utf-8" - Provide user register access over IOCTL. Both register read and write are supported. - APML interface does not provide a synchronization method. By defining, a register access path, we use APML modules and library for all APML transactions. Without having to use external tools such as i2c-tools, which may cause race conditions. Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v8: - Address kernel test robot build error: - error: unknown type name 'u16' - error: unknown type name 'u8' Changes since v7: - Address Arnd comment: - New IOCTL and structure defined to separate ioctl for each protocol Changes since v6: - Rebased patch, previously patch 10 Changes since v5: - Patch rebased Changes since v4: - Previously patch 8 - Address review comment for documentation warning Changes since v3: - Add ioctl description comment Changes since v2: - update the MACROS name as per feedback Changes since v1: - bifurcated from previous patch 5 drivers/misc/amd-sbi/rmi-core.c | 29 +++++++++++++++++++++++++++++ include/uapi/misc/amd-apml.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-cor= e.c index 171d6e871373..b653a21a909e 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -350,6 +350,33 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, return ret; } =20 +static int apml_rmi_reg_xfer(struct sbrmi_data *data, + struct apml_reg_xfer_msg __user *arg) +{ + struct apml_reg_xfer_msg msg =3D { 0 }; + unsigned int data_read; + int ret; + + /* Copy the structure from user */ + if (copy_from_user(&msg, arg, sizeof(struct apml_reg_xfer_msg))) + return -EFAULT; + + mutex_lock(&data->lock); + if (msg.rflag) { + ret =3D regmap_read(data->regmap, msg.reg_addr, &data_read); + if (!ret) + msg.data_in_out =3D data_read; + } else { + ret =3D regmap_write(data->regmap, msg.reg_addr, msg.data_in_out); + } + + mutex_unlock(&data->lock); + + if (msg.rflag && !ret) + return copy_to_user(arg, &msg, sizeof(struct apml_reg_xfer_msg)); + return ret; +} + static int apml_mailbox_xfer(struct sbrmi_data *data, struct apml_mbox_msg= __user *arg) { struct apml_mbox_msg msg =3D { 0 }; @@ -414,6 +441,8 @@ static long sbrmi_ioctl(struct file *fp, unsigned int c= md, unsigned long arg) return apml_cpuid_xfer(data, argp); case SBRMI_IOCTL_MCAMSR_CMD: return apml_mcamsr_xfer(data, argp); + case SBRMI_IOCTL_REG_XFER_CMD: + return apml_rmi_reg_xfer(data, argp); default: return -ENOTTY; } diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h index f718675d3966..745b3338fc06 100644 --- a/include/uapi/misc/amd-apml.h +++ b/include/uapi/misc/amd-apml.h @@ -58,6 +58,21 @@ struct apml_mcamsr_msg { __u32 pad; }; =20 +struct apml_reg_xfer_msg { + /* + * RMI register address offset + */ + __u16 reg_addr; + /* + * Register data for read/write + */ + __u8 data_in_out; + /* + * Register read or write + */ + __u8 rflag; +}; + /* * AMD sideband interface base IOCTL */ @@ -118,4 +133,20 @@ struct apml_mcamsr_msg { */ #define SBRMI_IOCTL_MCAMSR_CMD _IOWR(SB_BASE_IOCTL_NR, 2, struct apml_mca= msr_msg) =20 +/** + * DOC: SBRMI_IOCTL_REG_XFER_CMD + * + * @Parameters + * + * @struct apml_reg_xfer_msg + * Pointer to the &struct apml_reg_xfer_msg that will contain the protocol + * information + * + * @Description + * IOCTL command for APML messages using generic _IOWR + * The IOCTL provides userspace access to AMD sideband register xfer proto= col + * - Register xfer protocol to get/set hardware register for given offset + */ +#define SBRMI_IOCTL_REG_XFER_CMD _IOWR(SB_BASE_IOCTL_NR, 3, struct apml_re= g_xfer_msg) + #endif /*_AMD_APML_H_*/ --=20 2.25.1 From nobody Fri Dec 19 00:53:39 2025 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2054.outbound.protection.outlook.com [40.107.244.54]) (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 94BBF1E0DBA; Mon, 28 Apr 2025 06:31:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821896; cv=fail; b=G67QwenGd9eKuyKuScEr4u9KZp79liQinXCNj7l4+8bOr0tFGnIQKEjgF7zsAurEeGpPWMcgDdfEc+D0peE06i/Mf/IJkbMvANIs41gQtSi/Z/R9dAJWEdXy5/vpTgOGDeiOzsxIxGgyGVt0SYBFg6AieyQlhihwYJir0C5EbrU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745821896; c=relaxed/simple; bh=lNYGOO7+kY6nsro6B/C6OXwpG+dO5AlDTt4VOcI8/u4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JXi0un8hWb9Dr77zc8RKAkx1sr8CQlk25pCQvp712KtGfMhDnviQ1vcVRiAD+M9ysrDMEvX3RWct0V+wOX/F+eAulfjWT6I2tqlbvF7am9et2WbSrFDS/WSB7drHmx1IXVotWRPmf5Ttk0N7+CP22ZuVO0yvuVWYfzaEjOigLA8= 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=Dk6ihpJP; arc=fail smtp.client-ip=40.107.244.54 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="Dk6ihpJP" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fEHBle4SOnjGJjsYBDjVo9lA0yBEkOzGVZL7YiuJLgeXCFsA08PYHebp8vJ3T92sTwkKkoE5prcEWDlzF6CyQwgByKhosB3dPM+AMFceJ3A2YPT3HNoU2uxHHsBBTmt4RzT1hrWuRQlJSb/ptMvsllI4dFcOHVbxw06+dHkVJZyVuwRM71FHyBjehcnOTYmEDvmYZCyh3MwsXz3XA/NAr4lLK+OOB8cRzqGD8zcAHY9vDTUXSXfPK5M8iLhwzh5ikoqI29F4pbpMRljz8ptfPKDgMwJdvExIPLmzjITyPH9rG4+iegw7Yh8lHKWchY3aLOeGxB8/RAhjbw5VPbiOfw== 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=u8xUb9f+T+4W8mDwJZ9vdFZfJQAWUEZxfL09lBFQKSI=; b=xZEWixG1i1KDrbYt1/spwFIv9cIY+pghgdRe0ikKigxDr5s8hiCi7oSKijNBSYrxdb9frIpHk0f9CKXxDrJlrl1D8MeyLDsuFMZto411PiJA0SLSjurmzSDpC4qawYwrul/qcAhe0V+AlbxnpheG0sCMV9pq4dBezzq1y2o8CYaEW2K2mx+qX3IFryc/RGe7yRlJpzazZ/AUrqw467YJBI7/ZEni/DdTJCo2zE943KaznOhBmoVlsjDxtv3j8qBe5AiLi65gUzxQr7QbR/lSoounmcXRHTVDzk+mk7d0sw7oDCMicus14zjerQSAcs8zgNv7BPF5WqId/SP3YCLh6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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=u8xUb9f+T+4W8mDwJZ9vdFZfJQAWUEZxfL09lBFQKSI=; b=Dk6ihpJPStd6Tnznt17A04ly30q+n4d/YJRJcUnC99IdARWMjpDQxwolz2xDq7Ay/LbxZeKWFHp8ebcaDZAb0bn9I12OKr5NSfTvyVQVAa5nTBKrPLtYFy6fbQcEKkpRSZ7nEXshnZs1aZF62pBsRVchaLzBOJCM1b/q0GS6hW0= Received: from MW4P220CA0012.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::17) by DS0PR12MB9059.namprd12.prod.outlook.com (2603:10b6:8:c5::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8678.33; Mon, 28 Apr 2025 06:31:31 +0000 Received: from SN1PEPF0002BA4F.namprd03.prod.outlook.com (2603:10b6:303:115:cafe::99) by MW4P220CA0012.outlook.office365.com (2603:10b6:303:115::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.36 via Frontend Transport; Mon, 28 Apr 2025 06:31:30 +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 SN1PEPF0002BA4F.mail.protection.outlook.com (10.167.242.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8678.33 via Frontend Transport; Mon, 28 Apr 2025 06:31:30 +0000 Received: from amd.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; Mon, 28 Apr 2025 01:31:25 -0500 From: Akshay Gupta To: , CC: , , , , , , , , Akshay Gupta Subject: [PATCH v9 10/10] misc: amd-sbi: Add document for AMD SB IOCTL description Date: Mon, 28 Apr 2025 06:30:34 +0000 Message-ID: <20250428063034.2145566-11-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250428063034.2145566-1-akshay.gupta@amd.com> References: <20250428063034.2145566-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SN1PEPF0002BA4F:EE_|DS0PR12MB9059:EE_ X-MS-Office365-Filtering-Correlation-Id: 57652d57-fb57-415d-e6a2-08dd861e4fce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|1800799024|82310400026|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?QsqFG+zDOkh1oDbkfEB2QCKVeg203boqAlouIE5f4MubSmrICow01MwEfMFS?= =?us-ascii?Q?GkyEWWypsdDWtkFLQVV0t05xrYvftVa6ZvlDJFzb6HNhbemhuP59q7B5sUg7?= =?us-ascii?Q?pNbtLotHKIyPKPpnY7IPsCQiNid+jQ9h31Wp22rD/2305cWKorZiTfHrilBk?= =?us-ascii?Q?yAnioLld4UCN0JdsRHdGUvGk1cJY25A6UxVQSVp4Ezce3QVGfZWVz5gKkbPd?= =?us-ascii?Q?NQ/4Gq4vgMMXcH4xptJ9/ds33+t0xUDn3mhrnnc+YxgWvcxEPYyTCbhkCQ5+?= =?us-ascii?Q?jaoEgvtxuhtL2gEV6VedgUUr3tr/bcXxPt0zoNG2Gj3e9jhW2EGEAU0vCb4x?= =?us-ascii?Q?hNGMHdV2i/KtxxF0vzTKGglh18FuC1PWiHq/zIJk04XORqfZ20xCr7tzpstc?= =?us-ascii?Q?Dsme+k7GTDMH0lP1jxCjPF5JJjUo3bz27ubjVYJ64snoqJirB/Vuuy/dGH9B?= =?us-ascii?Q?sT502GzEx9qV0W3vBjHEuJY1x+JFSzI6b8zIjZ+bvaRU05zjw2IwdRtXfdfV?= =?us-ascii?Q?OUy5hj45ANMDgxxMV0XIbKNKfqUumkDTTXGCCe9005kEr3Sokh81PputQsd4?= =?us-ascii?Q?/89tFxO7jurZDj1EWlL6T4Mi8KpX2uwxKS/boOc5CdPO2ubhKZM6+eSki3FI?= =?us-ascii?Q?ne2n249nZqPxVdftq1jE/LYsO2bjANl5ZU+sHal1BOcT99jkkbLVxjoo367O?= =?us-ascii?Q?p4d/IqCrm39aVW30aJK5yNe72pT9VxWjH6cMv5sj8w6hkaWkjheUBWcRktNC?= =?us-ascii?Q?5I1gdIiO09s9gxGTUIPpwHr39p3g5aQutFLgcvnj3kr0aUHq63758V5WPo/l?= =?us-ascii?Q?raFepSQRFx3okfkAlT4FsDvxBqVPlVb/J0CBafTMijDdPTROC8y79XP+yErm?= =?us-ascii?Q?Lv9sdI0ZLOSainWqwGi1Oy1Sm5uUSq7B5lbaMVESoDceGWpTGDRYj96E54B+?= =?us-ascii?Q?VogKqgH3QOFuml0+c8uAVVVlSf4p/Jxo3rjBixiy4nyRii2EgdoASiU/C2c+?= =?us-ascii?Q?8kBFLwZD3/qD1uWtVl3VaUidlCXT1rM73zSplAFBvk1I9RGzrmNoRvIA3N1E?= =?us-ascii?Q?YJ+Occjmiju6NVobWtrVMbAt2kiZRxl8Zc57YW2TkPl1mXJuOqKYXW7Lh+9M?= =?us-ascii?Q?5lniouxXmdxLVDafJkVRFtaCJhGivZpjsiS+pt0cCLiaeCdErz0GLEA1jO37?= =?us-ascii?Q?XsEY/78na/OIk/PMUcU987Xf00N0/3azYWIcJ7LJpyFIycpnCVup0Mg0d5Cb?= =?us-ascii?Q?90sAfBItkALmbioE9uvMLy9vY0pRuH7MC6QZeeNccNa0AsJAG6+XkiSMSjuf?= =?us-ascii?Q?qvT1LscFe4+JlrDxvuZDeJqjJxTo9+pVbKTvnFI8PchdzCUMTcm47Ym5Zmy7?= =?us-ascii?Q?Ck78icpKrgzLng54i8n5G9bk0mBhLsB8gckx+EO6+b5uoP+LP4oZCMvuu80U?= =?us-ascii?Q?qWcnOBqM2Yhrn8oDlP4g8Rz39kwRdiWtF9J1GaYqGhGC2ZFrhyGlkwdTziQq?= =?us-ascii?Q?YaQM/ylrQIbC8llwr2t26P3J5NlsU96ZhHNb2KeW+R3ZWzxD1hflgLpciQ?= =?us-ascii?Q?=3D=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)(376014)(36860700013)(1800799024)(82310400026)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2025 06:31:30.2023 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 57652d57-fb57-415d-e6a2-08dd861e4fce 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: SN1PEPF0002BA4F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9059 Content-Type: text/plain; charset="utf-8" - This document provides AMD side band IOCTL description defined for APML and its usage. Multiple AMD custom protocols defined for side band system management uses this IOCTL. User space C-APIs are made available by esmi_oob_library [1], which is provided by the E-SMS project [2]. Link: https://github.com/amd/esmi_oob_library [1] Link: https://www.amd.com/en/developer/e-sms.html [2] Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v7: - update the documentation as per changes in uapi header Changes since v6: - Rebased patch, previously patch 11 Changes since v4: - Previously patch 9 - Update description as per review comment - Address the review comments for documentation warning Changes since v3: - Address the review comments Changes since v2: - update the MACROS name as per feedback Changes since v1: - New patch Documentation/misc-devices/amd-sbi.rst | 99 ++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Documentation/misc-devices/amd-sbi.rst diff --git a/Documentation/misc-devices/amd-sbi.rst b/Documentation/misc-de= vices/amd-sbi.rst new file mode 100644 index 000000000000..5648fc6ec572 --- /dev/null +++ b/Documentation/misc-devices/amd-sbi.rst @@ -0,0 +1,99 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +AMD SIDE BAND interface +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Some AMD Zen based processors supports system management +functionality via side-band interface (SBI) called +Advanced Platform Management Link (APML). APML is an I2C/I3C +based 2-wire processor target interface. APML is used to +communicate with the Remote Management Interface +(SB Remote Management Interface (SB-RMI) +and SB Temperature Sensor Interface (SB-TSI)). + +More details on the interface can be found in chapter +"5 Advanced Platform Management Link (APML)" of the family/model PPR [1]_. + +.. [1] https://www.amd.com/content/dam/amd/en/documents/epyc-technical-doc= s/programmer-references/55898_B1_pub_0_50.zip + + +SBRMI device +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +apml_sbrmi driver under the drivers/misc/amd-sbi creates miscdevice +/dev/sbrmi-* to let user space programs run APML mailbox, CPUID, +MCAMSR and register xfer commands. + +Register sets is common across APML protocols. IOCTL is providing synchron= ization +among protocols as transactions may create race condition. + +$ ls -al /dev/sbrmi-3c +crw------- 1 root root 10, 53 Jul 10 11:13 /dev/sbrmi-3c + +apml_sbrmi driver registers hwmon sensors for monitoring power_cap_max, +current power consumption and managing power_cap. + +Characteristics of the dev node: + * Differnet xfer protocols are defined: + * Mailbox + * CPUID + * MCA_MSR + * Register xfer + +Access restrictions: + * Only root user is allowed to open the file. + * APML Mailbox messages and Register xfer access are read-write, + * CPUID and MCA_MSR access is read-only. + +Driver IOCTLs +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. c:macro:: SBRMI_IOCTL_MBOX_CMD +.. kernel-doc:: include/uapi/misc/amd-apml.h + :doc: SBRMI_IOCTL_MBOX_CMD +.. c:macro:: SBRMI_IOCTL_CPUID_CMD +.. kernel-doc:: include/uapi/misc/amd-apml.h + :doc: SBRMI_IOCTL_CPUID_CMD +.. c:macro:: SBRMI_IOCTL_MCAMSR_CMD +.. kernel-doc:: include/uapi/misc/amd-apml.h + :doc: SBRMI_IOCTL_MCAMSR_CMD +.. c:macro:: SBRMI_IOCTL_REG_XFER_CMD +.. kernel-doc:: include/uapi/misc/amd-apml.h + :doc: SBRMI_IOCTL_REG_XFER_CMD + +User-space usage +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +To access side band interface from a C program. +First, user need to include the headers:: + + #include + +Which defines the supported IOCTL and data structure to be passed +from the user space. + +Next thing, open the device file, as follows:: + + int file; + + file =3D open("/dev/sbrmi-*", O_RDWR); + if (file < 0) { + /* ERROR HANDLING */ + exit(1); + } + +The following IOCTLs are defined: + +``#define SB_BASE_IOCTL_NR 0xF9`` +``#define SBRMI_IOCTL_MBOX_CMD _IOWR(SB_BASE_IOCTL_NR, 0, struct apml_mbo= x_msg)`` +``#define SBRMI_IOCTL_CPUID_CMD _IOWR(SB_BASE_IOCTL_NR, 1, struct apml_cp= uid_msg)`` +``#define SBRMI_IOCTL_MCAMSR_CMD _IOWR(SB_BASE_IOCTL_NR, 2, struct apml_mc= amsr_msg)`` +``#define SBRMI_IOCTL_REG_XFER_CMD _IOWR(SB_BASE_IOCTL_NR, 3, struct apml_= reg_xfer_msg)`` + + +User space C-APIs are made available by esmi_oob_library, hosted at +[2]_ which is provided by the E-SMS project [3]_. + +.. [2] https://github.com/amd/esmi_oob_library +.. [3] https://www.amd.com/en/developer/e-sms.html --=20 2.25.1