From patchwork Wed Jul 17 08:10:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13735199 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2044.outbound.protection.outlook.com [40.107.220.44]) (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 9359E22EE5; Wed, 17 Jul 2024 08:10:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203855; cv=fail; b=I2RCE4HPW5FeTz5qLmKZjp+STl6ykgvr03LOlpoXugIWUQHXj/BYm2kKLvg24od8t/uJFeknzDgBboP8lZsE99BmSU/DzRubMHcjDBK3Rs9HH0OELcKYm2tSrk6w9Cn7s90Dpl/ikmdbnOsj5wYt1KtqXujcm3/GF/ce3kq/bHQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203855; c=relaxed/simple; bh=0A9AluLYfKiItqOdfjgxc09WLrlnEbZIg6A4aCWj10w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BNOPYEDkVR221gn7w+4v4B3NF66aECUK2haKLbIhQMcsO3wuZBBWElt/wL+y6TXyA+/dL9Tqm2E+1FrRDlVdE8dTHEFic5O4xBuIPW0l4JErvicEir7UuO98gxU6STTmMb48Y8iYH4ooBpZQUUPBqIeLq9n8xQxYUoH4LKqDkDY= 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=u0GPY5OA; arc=fail smtp.client-ip=40.107.220.44 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="u0GPY5OA" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Hyx5OaqaFZeuj/y6XQrdMAzlo2JOqZK5vnV8FdrBQ79qm6c5y1CXVNpKCc0F58q4BH0Y0Oxp5BKfDuBHGr5ohYSjZDBRJloAnorXS/cgAaKoz0SsF1hsNsrpogRcKBdufLK0YMxvHnobqKWCQolSCCsLtIN/wtK1jzecG1ruFIiXrHCU7gQpWCyeEJAEHOYvUSO0TqZqUHv9BxiDV8V3HvSwNuVXlrEhqWadtaDk210yd7ivgmUKJlhYpt4HaMkE3ExpaKC2WXs+1MpnfAHaSRkOAzU6NLqiikdqGhgfwMWrLXVNVLYj0yK8ir5fjuDPJzEnno8e2Lj0ml7gnDXuHw== 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=B0HtJ5MGCq0Z0Fxtx/DyLbRlO7zvi/+5nnfV/Dhe+Po=; b=y9+wYqtBiFak/6LKiwm+qNfwMvzU34gZ3hi/QoCbphKCXMZPseBA5jiYIddDjvnWDRg4rvIb/6QhJCfuw8kUEDB5pit5AZdjNDznL/bXaV1B7DiVuVLk95lWn49AnK99H7FfJ3wyw6AoUjlsK9uMyL8Ge09zlDCuWiuf+7Cig6bTw+g9c9tPGnZJXy08BrvJSF2VN5qPh6MDw4ruYlP3cxhDtH7hnxqx/LATEVKQzXT2G/OuekGsiQqyXdUYEqlkdFStRD9RsUjZ3kgBUvvdcNG479kGJK/ex5sTr3zC3YHTZRjYy4JrjKrywNz2t5nxMRfESXBZgpiKeCV0LXcKrA== 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=B0HtJ5MGCq0Z0Fxtx/DyLbRlO7zvi/+5nnfV/Dhe+Po=; b=u0GPY5OA/3lyyCG91ujn3ayHO1xrEkwENYvdffK7r98Ev0RjLzw8tHt0DgP6YG4mtvN0xN/32DlTsty3sounEqrSqN3Uk9agHOJmArHZtP4neElTgXN4zc0nogbP9JJRr9iznAD5SZAmkXPwfKgyCDKu2t39R3IO/Zp7N739vaU= Received: from CH2PR08CA0013.namprd08.prod.outlook.com (2603:10b6:610:5a::23) by MN2PR12MB4222.namprd12.prod.outlook.com (2603:10b6:208:19a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16; Wed, 17 Jul 2024 08:10:51 +0000 Received: from CH1PEPF0000A349.namprd04.prod.outlook.com (2603:10b6:610:5a:cafe::d2) by CH2PR08CA0013.outlook.office365.com (2603:10b6:610:5a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.29 via Frontend Transport; Wed, 17 Jul 2024 08:10:50 +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 CH1PEPF0000A349.mail.protection.outlook.com (10.167.244.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7784.11 via Frontend Transport; Wed, 17 Jul 2024 08:10:50 +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; Wed, 17 Jul 2024 03:10:47 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v2 1/8] hwmon/misc: amd-sbi: Move core sbrmi from hwmon to misc Date: Wed, 17 Jul 2024 08:10:20 +0000 Message-ID: <20240717081027.2079549-2-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240717081027.2079549-1-akshay.gupta@amd.com> References: <20240717081027.2079549-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CH1PEPF0000A349:EE_|MN2PR12MB4222:EE_ X-MS-Office365-Filtering-Correlation-Id: ba20ee17-6105-49b3-c7f1-08dca637f8e9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|36860700013; X-Microsoft-Antispam-Message-Info: +CHWgX7a0rjcRpeH2HyZJRxrsLoicnLMOZq8bCt25sG/MncnQcdfESnEicfyE22IG6mXEnvjTvchTLpvv28sAB4RNuBH2o34vVZ+7NF9VEFTMZSTOxBUjSV9hIPVZb81wa2wm2I9eI7FUL8PJJGQQieLX5ncEINUMmZU6JtF7Xa534UmxYHHxQj2H5wdcxIaJT5rfIsg6l3O4jZfAP+YEenP6VLvelV7jZZCsNAokosqQjHWvh+Z0OODrr1qMiD47PzJP1gIy3FgEmq51rMmZRNXng0ElOuJMQw6TghcfbT0qJkolrFPd4/EetZJ1gW+bHVAQBRPVPuAUbU0fJ0EoXtOPLfTg2Pn1gD2/6NDZK2LbsMOKGynQYv2KRgkh/ZRpqcBXIDEf4VVgD7pLucu1ajjyoa4wrhJsNL44DkWVr1kP6ZrN9BkDvSNZwX3IGDr5Tf+FnC4Neqr69Dc5vEw+eKSI26k2rYTNLmjK25UhZiaTCUNI5P9G9s1ZiQsYh8xnL3j0l6oJs+xtOOYyK2tBysMioybmX14BsoNofRKDJFfnmYtSzA0nU5bNpWP16i4m2ybfSs7/FLYk62fW9x0EzLiagRmIW94g8VZWFOjvbR0t9Lhn1hnQXzMIBA5dy1o2bUv0OF+OQAyUYqiQGlnm1x5LmQOd/ipslE6MRzOvYIGqn256ekiiIsTBzsZi6SgCYcHQFaRG1ww3gjp1tkx0jSUJE7rWu9KU7gPkSbWzrK0FY7gMxyhn7tN6ZYFT6it1Jr1cs2wyr7bRx8lGcK+inIML1Puv+8e7nhepbcyLrvx6yaDQ4ZxdLsezMbRKjan8Gsqf01HRUaT9kGKMVQ1eqGbMTCEBbdNwDKlWS+L331IWjL56GjQAqfBlNf5dSr+3IsnPG6l3pDgZLjGY1/Rm0eSpCrmE403V3AJn+nL2ObI9mTXrfq4kRHZ1VVHC/Akup52HXfzx8+gKUMvQITy6mUuyPEGMuOJT9UzoTgVzPq8qlcAx94/0g2yrMT0MaHmHaLMTzwiZOMT6zn+7tlNec8xzBtPM6l7+4rKAVdkyAOS+pKXeZMu+A6THD0EjCjP5PkUrs7/C/XV/vjZ/X6gI80HOFFYgG+XyiIkwiHaBzJupDlZA+T3/G2rXhGXwLMGu3PbNq0hvCi8Up9PujbXUec5JLfHqyXevIYCrJ+nWFGgwGzyI+xDNCv6M3tW3p2crxe5j+WkAq0tLvzMoK9CsY/RQ1g4qtFxwbOfCRAmvLArstpumbobmtc3MZGVqUHBmHst8OMRhjJF4CQZmBYwVDwLM5ZO/QOPowbcgkhpVx/GfQxCvrLfd0H7Ra+ey6OmwlghreB6My38HXDAO66LAfpDET5vv6fmhIjjjyUpf21Veaee817o2+90EC3xe/hqMH4Cpk83zgwfLIPbJD57l/cdLp2cPmeBS9t4w/Ngh8AS5UjcOXUuwIdpegrua7nG X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2024 08:10:50.8156 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ba20ee17-6105-49b3-c7f1-08dca637f8e9 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: CH1PEPF0000A349.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4222 This is done to support other functionality provided by the SBRMI, which does not fit in the hwmon subsystem. - Move the SBRMI core functionality and I2C device probing part to misc. - Move hwmon device sensor to misc as only power is reported through hwmon sensor. Signed-off-by: Akshay Gupta Reviewed-by: Naveen Krishna Chatradhi --- Changes since v1: - File name update - Add hwmon sensor registration in this patch - Update Copyright year drivers/hwmon/Kconfig | 10 - drivers/hwmon/sbrmi.c | 357 ------------------------------- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/amd-sbi/Kconfig | 9 + drivers/misc/amd-sbi/Makefile | 3 + drivers/misc/amd-sbi/rmi-core.c | 115 ++++++++++ drivers/misc/amd-sbi/rmi-core.h | 65 ++++++ drivers/misc/amd-sbi/rmi-hwmon.c | 121 +++++++++++ drivers/misc/amd-sbi/rmi-i2c.c | 111 ++++++++++ 10 files changed, 426 insertions(+), 367 deletions(-) delete mode 100644 drivers/hwmon/sbrmi.c create mode 100644 drivers/misc/amd-sbi/Kconfig create mode 100644 drivers/misc/amd-sbi/Makefile create mode 100644 drivers/misc/amd-sbi/rmi-core.c create mode 100644 drivers/misc/amd-sbi/rmi-core.h create mode 100644 drivers/misc/amd-sbi/rmi-hwmon.c create mode 100644 drivers/misc/amd-sbi/rmi-i2c.c diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index e14ae18a973b..bfdb7a91c803 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1836,16 +1836,6 @@ config SENSORS_SBTSI This driver can also be built as a module. If so, the module will be called sbtsi_temp. -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/hwmon/sbrmi.c b/drivers/hwmon/sbrmi.c deleted file mode 100644 index d48d8e5460ff..000000000000 --- a/drivers/hwmon/sbrmi.c +++ /dev/null @@ -1,357 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * sbrmi.c - hwmon driver for a SB-RMI mailbox - * compliant AMD SoC device. - * - * Copyright (C) 2020-2021 Advanced Micro Devices, Inc. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* 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 = 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 = 0x01, - SBRMI_STATUS, - SBRMI_OUTBNDMSG0 = 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; -}; - -static int sbrmi_enable_alert(struct i2c_client *client) -{ - int ctrl; - - /* - * Enable the SB-RMI Software alert status - * by writing 0 to bit 4 of Control register(0x1) - */ - ctrl = i2c_smbus_read_byte_data(client, SBRMI_CTRL); - if (ctrl < 0) - return ctrl; - - if (ctrl & 0x10) { - ctrl &= ~0x10; - return i2c_smbus_write_byte_data(client, - SBRMI_CTRL, ctrl); - } - - return 0; -} - -static int rmi_mailbox_xfer(struct sbrmi_data *data, - struct sbrmi_mailbox_msg *msg) -{ - int i, ret, retry = 10; - int sw_status; - u8 byte; - - mutex_lock(&data->lock); - - /* Indicate firmware a command is to be serviced */ - ret = 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 = 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 = 0; i < 4; i++) { - byte = (msg->data_in >> i * 8) & 0xff; - ret = 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 = i2c_smbus_write_byte_data(data->client, - SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); - if (ret < 0) - goto exit_unlock; - - /* - * Firmware will write SBRMI::Status[SwAlertSts]=1 to generate - * an ALERT (if enabled) to initiator (BMC) to indicate completion - * of the requested command - */ - do { - sw_status = i2c_smbus_read_byte_data(data->client, - SBRMI_STATUS); - if (sw_status < 0) { - ret = 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 = -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 = 0; i < 4; i++) { - ret = i2c_smbus_read_byte_data(data->client, - SBRMI_OUTBNDMSG1 + i); - if (ret < 0) - goto exit_unlock; - msg->data_out |= ret << i * 8; - } - } - - /* - * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the - * ALERT to initiator - */ - ret = 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) -{ - struct sbrmi_data *data = dev_get_drvdata(dev); - struct sbrmi_mailbox_msg msg = { 0 }; - int ret; - - if (type != hwmon_power) - return -EINVAL; - - msg.read = true; - switch (attr) { - case hwmon_power_input: - msg.cmd = SBRMI_READ_PKG_PWR_CONSUMPTION; - ret = rmi_mailbox_xfer(data, &msg); - break; - case hwmon_power_cap: - msg.cmd = SBRMI_READ_PKG_PWR_LIMIT; - ret = rmi_mailbox_xfer(data, &msg); - break; - case hwmon_power_cap_max: - msg.data_out = data->pwr_limit_max; - ret = 0; - break; - default: - return -EINVAL; - } - if (ret < 0) - return ret; - /* hwmon power attributes are in microWatt */ - *val = (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 = dev_get_drvdata(dev); - struct sbrmi_mailbox_msg msg = { 0 }; - - if (type != hwmon_power && attr != hwmon_power_cap) - return -EINVAL; - /* - * hwmon power attributes are in microWatt - * mailbox read/write is in mWatt - */ - val /= 1000; - - val = clamp_val(val, SBRMI_PWR_MIN, data->pwr_limit_max); - - msg.cmd = SBRMI_WRITE_PKG_PWR_LIMIT; - msg.data_in = val; - msg.read = 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[] = { - HWMON_CHANNEL_INFO(power, - HWMON_P_INPUT | HWMON_P_CAP | HWMON_P_CAP_MAX), - NULL -}; - -static const struct hwmon_ops sbrmi_hwmon_ops = { - .is_visible = sbrmi_is_visible, - .read = sbrmi_read, - .write = sbrmi_write, -}; - -static const struct hwmon_chip_info sbrmi_chip_info = { - .ops = &sbrmi_hwmon_ops, - .info = sbrmi_info, -}; - -static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data) -{ - struct sbrmi_mailbox_msg msg = { 0 }; - int ret; - - msg.cmd = SBRMI_READ_PKG_MAX_PWR_LIMIT; - msg.read = true; - ret = rmi_mailbox_xfer(data, &msg); - if (ret < 0) - return ret; - data->pwr_limit_max = msg.data_out; - - return ret; -} - -static int sbrmi_probe(struct i2c_client *client) -{ - struct device *dev = &client->dev; - struct device *hwmon_dev; - struct sbrmi_data *data; - int ret; - - data = devm_kzalloc(dev, sizeof(struct sbrmi_data), GFP_KERNEL); - if (!data) - return -ENOMEM; - - data->client = client; - mutex_init(&data->lock); - - /* Enable alert for SB-RMI sequence */ - ret = sbrmi_enable_alert(client); - if (ret < 0) - return ret; - - /* Cache maximum power limit */ - ret = sbrmi_get_max_pwr_limit(data); - if (ret < 0) - return ret; - - hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, data, - &sbrmi_chip_info, NULL); - - return PTR_ERR_OR_ZERO(hwmon_dev); -} - -static const struct i2c_device_id sbrmi_id[] = { - {"sbrmi"}, - {} -}; -MODULE_DEVICE_TABLE(i2c, sbrmi_id); - -static const struct of_device_id __maybe_unused sbrmi_of_match[] = { - { - .compatible = "amd,sbrmi", - }, - { }, -}; -MODULE_DEVICE_TABLE(of, sbrmi_of_match); - -static struct i2c_driver sbrmi_driver = { - .driver = { - .name = "sbrmi", - .of_match_table = of_match_ptr(sbrmi_of_match), - }, - .probe = sbrmi_probe, - .id_table = sbrmi_id, -}; - -module_i2c_driver(sbrmi_driver); - -MODULE_AUTHOR("Akshay Gupta "); -MODULE_DESCRIPTION("Hwmon driver for AMD SB-RMI emulated sensor"); -MODULE_LICENSE("GPL"); diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index faf983680040..1bb74da980f7 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -602,4 +602,5 @@ source "drivers/misc/cardreader/Kconfig" source "drivers/misc/uacce/Kconfig" source "drivers/misc/pvpanic/Kconfig" source "drivers/misc/mchp_pci1xxxx/Kconfig" +source "drivers/misc/amd-sbi/Kconfig" endmenu diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 153a3f4837e8..2edf1d7ceac8 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -69,3 +69,4 @@ obj-$(CONFIG_TMR_INJECT) += xilinx_tmr_inject.o obj-$(CONFIG_TPS6594_ESM) += tps6594-esm.o obj-$(CONFIG_TPS6594_PFSM) += tps6594-pfsm.o obj-$(CONFIG_NSM) += nsm.o +obj-y += 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..eac90a7635de --- /dev/null +++ b/drivers/misc/amd-sbi/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only +sbrmi-i2c-objs := rmi-i2c.o rmi-core.o rmi-hwmon.o +obj-$(CONFIG_AMD_SBRMI_I2C) += sbrmi-i2c.o diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c new file mode 100644 index 000000000000..5d93fb703fa0 --- /dev/null +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -0,0 +1,115 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * sbrmi-core.c - file defining SB-RMI protocols compliant + * AMD SoC device. + * + * Copyright (C) 2024 Advanced Micro Devices, Inc. + */ +#include +#include +#include +#include +#include "rmi-core.h" + +/* Mask for Status Register bit[1] */ +#define SW_ALERT_MASK 0x2 +/* Do not allow setting negative power limit */ +#define SBRMI_PWR_MIN 0 + +/* 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 = 10; + int sw_status; + u8 byte; + + mutex_lock(&data->lock); + + /* Indicate firmware a command is to be serviced */ + ret = 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 = 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 = 0; i < 4; i++) { + byte = (msg->data_in >> i * 8) & 0xff; + ret = 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 = i2c_smbus_write_byte_data(data->client, + SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); + if (ret < 0) + goto exit_unlock; + + /* + * Firmware will write SBRMI::Status[SwAlertSts]=1 to generate + * an ALERT (if enabled) to initiator (BMC) to indicate completion + * of the requested command + */ + do { + sw_status = i2c_smbus_read_byte_data(data->client, + SBRMI_STATUS); + if (sw_status < 0) { + ret = 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 = -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 = 0; i < 4; i++) { + ret = i2c_smbus_read_byte_data(data->client, + SBRMI_OUTBNDMSG1 + i); + if (ret < 0) + goto exit_unlock; + msg->data_out |= ret << i * 8; + } + } + + /* + * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the + * ALERT to initiator + */ + ret = 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-core.h new file mode 100644 index 000000000000..3d600e450e08 --- /dev/null +++ b/drivers/misc/amd-sbi/rmi-core.h @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2024 Advanced Micro Devices, Inc. + */ + +#ifndef _SBRMI_CORE_H_ +#define _SBRMI_CORE_H_ + +#include +#include +#include + +/* SB-RMI registers */ +enum sbrmi_reg { + SBRMI_CTRL = 0x01, + SBRMI_STATUS, + SBRMI_OUTBNDMSG0 = 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 = 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; + struct platform_device *pdev; + 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 *msg); +int create_hwmon_sensor_device(struct device *dev, struct sbrmi_data *data); +#endif /*_SBRMI_CORE_H_*/ diff --git a/drivers/misc/amd-sbi/rmi-hwmon.c b/drivers/misc/amd-sbi/rmi-hwmon.c new file mode 100644 index 000000000000..36913f105eef --- /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) 2024 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 = dev_get_drvdata(dev); + struct sbrmi_mailbox_msg msg = { 0 }; + int ret; + + if (!data) + return -ENODEV; + + if (type != hwmon_power) + return -EINVAL; + + msg.read = true; + switch (attr) { + case hwmon_power_input: + msg.cmd = SBRMI_READ_PKG_PWR_CONSUMPTION; + ret = rmi_mailbox_xfer(data, &msg); + break; + case hwmon_power_cap: + msg.cmd = SBRMI_READ_PKG_PWR_LIMIT; + ret = rmi_mailbox_xfer(data, &msg); + break; + case hwmon_power_cap_max: + msg.data_out = data->pwr_limit_max; + ret = 0; + break; + default: + return -EINVAL; + } + if (ret < 0) + return ret; + /* hwmon power attributes are in microWatt */ + *val = (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 = dev_get_drvdata(dev); + struct sbrmi_mailbox_msg msg = { 0 }; + + if (!data) + return -ENODEV; + + if (type != hwmon_power && attr != hwmon_power_cap) + return -EINVAL; + /* + * hwmon power attributes are in microWatt + * mailbox read/write is in mWatt + */ + val /= 1000; + + val = clamp_val(val, SBRMI_PWR_MIN, data->pwr_limit_max); + + msg.cmd = SBRMI_WRITE_PKG_PWR_LIMIT; + msg.data_in = val; + msg.read = 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[] = { + HWMON_CHANNEL_INFO(power, + HWMON_P_INPUT | HWMON_P_CAP | HWMON_P_CAP_MAX), + NULL +}; + +static const struct hwmon_ops sbrmi_hwmon_ops = { + .is_visible = sbrmi_is_visible, + .read = sbrmi_read, + .write = sbrmi_write, +}; + +static const struct hwmon_chip_info sbrmi_chip_info = { + .ops = &sbrmi_hwmon_ops, + .info = sbrmi_info, +}; + +int create_hwmon_sensor_device(struct device *dev, struct sbrmi_data *data) +{ + struct device *hwmon_dev; + + hwmon_dev = 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 new file mode 100644 index 000000000000..ae968cf3c29c --- /dev/null +++ b/drivers/misc/amd-sbi/rmi-i2c.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * rmi-i2c.c - Side band RMI over I2C support for AMD out + * of band management + * + * Copyright (C) 2024 Advanced Micro Devices, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "rmi-core.h" + +#define SBRMI_CTRL 0x1 + +static int sbrmi_enable_alert(struct i2c_client *client) +{ + int ctrl; + + /* + * Enable the SB-RMI Software alert status + * by writing 0 to bit 4 of Control register(0x1) + */ + ctrl = i2c_smbus_read_byte_data(client, SBRMI_CTRL); + if (ctrl < 0) + return ctrl; + + if (ctrl & 0x10) { + ctrl &= ~0x10; + return i2c_smbus_write_byte_data(client, + SBRMI_CTRL, ctrl); + } + + return 0; +} + +static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data) +{ + struct sbrmi_mailbox_msg msg = { 0 }; + int ret; + + msg.cmd = SBRMI_READ_PKG_MAX_PWR_LIMIT; + msg.read = true; + ret = rmi_mailbox_xfer(data, &msg); + if (ret < 0) + return ret; + data->pwr_limit_max = msg.data_out; + + return ret; +} + +static int sbrmi_i2c_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct sbrmi_data *data; + int ret; + + data = devm_kzalloc(dev, sizeof(struct sbrmi_data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->client = client; + mutex_init(&data->lock); + + /* Enable alert for SB-RMI sequence */ + ret = sbrmi_enable_alert(client); + if (ret < 0) + return ret; + + /* Cache maximum power limit */ + ret = sbrmi_get_max_pwr_limit(data); + if (ret < 0) + return ret; + + dev_set_drvdata(dev, data); + return create_hwmon_sensor_device(dev, data); +} + +static const struct i2c_device_id sbrmi_id[] = { + {"sbrmi-i2c"}, + {} +}; +MODULE_DEVICE_TABLE(i2c, sbrmi_id); + +static const struct of_device_id __maybe_unused sbrmi_of_match[] = { + { + .compatible = "amd,sbrmi", + }, + { }, +}; +MODULE_DEVICE_TABLE(of, sbrmi_of_match); + +static struct i2c_driver sbrmi_driver = { + .driver = { + .name = "sbrmi-i2c", + .of_match_table = of_match_ptr(sbrmi_of_match), + }, + .probe = sbrmi_i2c_probe, + .id_table = sbrmi_id, +}; + +module_i2c_driver(sbrmi_driver); + +MODULE_AUTHOR("Akshay Gupta "); +MODULE_AUTHOR("Naveen Krishna Chatradhi "); +MODULE_DESCRIPTION("Hwmon driver for AMD SB-RMI emulated sensor"); +MODULE_LICENSE("GPL"); From patchwork Wed Jul 17 08:10:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13735200 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2045.outbound.protection.outlook.com [40.107.101.45]) (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 C4C712E859; Wed, 17 Jul 2024 08:10:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203860; cv=fail; b=UH3j7iDFzM2gfPs4hrCLXD3gTVV7ovw/700ym2Ywn3a/4DbTgm1IhfSbzJ2bsmgNuuNA0Q82/wuMGFLiEodzgYh7dLAUgoscsD3cmvJ9z+Dq5FLeL/YWZAjPaylzXjG0vn0ECWM4bD/kP3PTEq5VqTG2UUkUa5XnX6tDd5RD+I4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203860; c=relaxed/simple; bh=sGt9Qs4F1MJhqdQHyyzsE8tmK+KWohya7fEfI/KfLUE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fPIEiHUOjN8Fqyyv6zS8PsPvnxOsawRQuWKg+WNOuOUXELJzAOIWIX5oge0XSkw9dHnCDcOI9Gy/YjkKBl24Ma5c3Gxv2D7yMws1ePmpblOpqIFB7uusv0ORDM4Jcw9Sf8MD1sC1HK7nlH5e0s86AEJ6coZiQ6FUyVcclMAKVVQ= 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=V9t0I5Pk; arc=fail smtp.client-ip=40.107.101.45 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="V9t0I5Pk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=koiZMBiQybeT7N9wb+mb8pthzPV6AeChWGPht0hYJ/4qrtG6ES0WrGiX7ykZ3g4HeknidnEVz3uiBODWHxd13Rome0ai4Y/Paa00UNfLtY35RNVGesXE68v97ZO4MFGJh7wjqTOb7eX4+L31FYgoNbaLRdfm6mt5pr+k9KCb8etjXCHCe4yhhUAkfkTZ04/eLdX/1WEVjU/bY7sEXCrFVpaWkK+b0T5a+E3XxPyFLpA7Vynl1/F2KxlH+7qmFxl8tv4MJLSicsiSpXXb49ZjRxn1pqoL0eKqfbrNuhog5t0xSyqlL6ac6qhj6zL0b602u418qR2KMfN8+3V5MfArhg== 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=g+0CAJa4/f0IjI5cDCGnVtbvAVOV4aCme+9KYrsrpRc=; b=btE2hfZGd4nK1FMi4YPVNYVPQ6ey2fzkKvaTDVRFc6O/Io4tsf4PtK9JEmKTkkIzIUt0eKy/YW2BVtpmINKA+xZIbMMZRU9skSoAxl+Y1orC2Cxny9oUPPt2T6ikbJhpDnQfFN9Ptypzg0IGY9j+9ORXiO04F2GykIYsMNZS1NM06yvHqe8HmnRUtKdJhBtNcr92WwED177QZ8onXrqJPz+3OFSDbCJ8G//4KWRx8FMBK8gk5dcwaP4idFa5+mBAZVmqjeMUqtf998UMA2Rf7zdTAIjiee+qQRaOMyt7zrjHOKg9kvzk/kBBL1T54FEDrvdsrhgBQdL5/TXCey0mGQ== 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=g+0CAJa4/f0IjI5cDCGnVtbvAVOV4aCme+9KYrsrpRc=; b=V9t0I5PknjBcyYu2uMqI+6a23bxGDmTvjzhSD5td/RCJy8s/l5llX2Rep3oTwwQIce0C+kJhcLsd6mBvFsf4IDrXcdwldUCmlHVKS3FxYeAS5aYngzhFHoEjU0PfnGdzqK3bkyjXbiOlDJ/8HiyaLLgfc5G+ujWalXDDxE7gxPM= Received: from DS7PR03CA0213.namprd03.prod.outlook.com (2603:10b6:5:3ba::8) by LV8PR12MB9231.namprd12.prod.outlook.com (2603:10b6:408:192::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.29; Wed, 17 Jul 2024 08:10:55 +0000 Received: from CH1PEPF0000A348.namprd04.prod.outlook.com (2603:10b6:5:3ba:cafe::3d) by DS7PR03CA0213.outlook.office365.com (2603:10b6:5:3ba::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16 via Frontend Transport; Wed, 17 Jul 2024 08:10: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 CH1PEPF0000A348.mail.protection.outlook.com (10.167.244.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7784.11 via Frontend Transport; Wed, 17 Jul 2024 08:10: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; Wed, 17 Jul 2024 03:10:52 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v2 2/8] misc: amd-sbi: Use regmap subsystem Date: Wed, 17 Jul 2024 08:10:21 +0000 Message-ID: <20240717081027.2079549-3-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240717081027.2079549-1-akshay.gupta@amd.com> References: <20240717081027.2079549-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CH1PEPF0000A348:EE_|LV8PR12MB9231:EE_ X-MS-Office365-Filtering-Correlation-Id: 91c10964-d678-433f-4b99-08dca637fbae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: rw6/pM7gq94eOrK4U9vFb+gOTXJhoktGzAzHl1zK2G51pepnlNTVSewMIr1cfk8Jlnh+zmNnHmYSNoDcwNmdPgakNOe80F+nnTX3UMahSPqCi/wrIOCIQtb+L7nEJNyu3Wyz3Go8/VaemXJLYySfKEGiRuKJgE5GqGR9WORg2sgvelOvgovNYQqQGHhBNABRWCGbBRjXm99ktRo95PQQghncrBMiV+z/UC1ANvb+pICRtAH3MPg5Gt7aRQACSKZYvuZMBNH3zHEXJ023cQ+7Ei4XI202Yu9x8t6FwBvoVbRB555YJhxwkkGThYOrr86SkVliVmPDtNl1abJllpjtyD90f1tFA84IwzNsKHs8gFDbi04DakEb8I96ENGbI/Re4y71PnFSKZKvN82n9fM/+JqRn/eWlXnuTr4FBPY4c+UwCdnnumScXFvdehVECIw8Jb6DRpvX1S24ovEUGiU1Uw23LUXNEnvTZJwao9ZKzxLVBXorLL2jXtmO5xEH3+dl1jgIInlUdtWqT8OKq1ABeCX4L0hZrghkRQsCP8Icg9kjEbGgAxfBX4lZ7Lb0zcttTRa92Tf5UkXkb+u7MJ8C/NfcPh4z6txzmlNjbrxrttYoWJ7/RBMsKZQIB/L9Zb6R5IYBYNtveXlFe8n7cZo6BF1aprC8aFUMVYId1Lf0YV5v4uz5El+SXdpwjuu6XxN8iyPUoTyk2jltsvdEiaeSGSp/vvRXssTXMs43nMMh6pOyDTp9D/Yd2GPp1W83NHzKVen+EW+DtJAtSJJ1rMd+N3JI/HuiA6hz0QjzXzZeoGSVOlqJ6BXyAB5Qm2w8eueUaFy+Z9v87eWyG6fwsmktzBR/G6toiNuDeBSP+kGQd2EJb5roIzK7tDyrjw/Zng5C3njNJiBR5mm0NdFUcRNe9f/BMBtMUtBf/486oebu6yq8KcSRCG2Lp77OQhynhjlDhK9f4fymd8zNeiV5IeKT+RFp6V3qRwfXYu5l9+T2c3T+iybBusFrn094BIYMkLvQa371tt6Z5x5AmiZbsTltPtQ0u/TjyGzVfGqHU2Sl9Xezw+2IeT3RyjzGW3P7qnfBWgx//W55Ky1/WpghokZKYaXg7I3gWcuyTb+qhKRg2yYa9GowGnK406w+dH0l5n9+ARrq9PThLC2DFsRGoqqWEjCOgdivAW7mI0rkYVwDZ1Qe/vddvlEEzennBbyOcEcb/aJWXz22BPlYu9pNbd9EzBEow7RcWFpbkwUxNQRZHk4MM+PwlZfB8GzhIk2yW3nA8xIxbbdgMZnbEWFZ4GKied3hwFZK3p3q93HsBveOltMS3aoGH0TpCpsWywxJTr5dyhbEHwR7i065RjOXM0h31O54L5AIdOa9jA4lpvzlbKm4r189Fj18QOJ8mhOXppyAcE1r6ZHgiHMibqTk6hZPuf1G/uoequTDNeCaPdhIt+tcj0QJ5XdU/H412366Nzqf 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)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2024 08:10:55.4746 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 91c10964-d678-433f-4b99-08dca637fbae 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: CH1PEPF0000A348.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9231 - regmap subsystem provides multiple benefits over direct smbus APIs - The susbsytem can be helpful in following cases - Differnet types of bus (i2c/i3c), we have plans to support i3c. - Different Register address size (1byte/2byte) Signed-off-by: Akshay Gupta Reviewed-by: Naveen Krishna Chatradhi --- 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-core.c index 5d93fb703fa0..5a0b7912cc4e 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" /* Mask for Status Register bit[1] */ @@ -23,6 +24,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg) { + unsigned int bytes; int i, ret, retry = 10; int sw_status; u8 byte; @@ -30,14 +32,12 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, mutex_lock(&data->lock); /* Indicate firmware a command is to be serviced */ - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG7, START_CMD); + ret = regmap_write(data->regmap, SBRMI_INBNDMSG7, START_CMD); if (ret < 0) goto exit_unlock; /* Write the command to SBRMI::InBndMsg_inst0 */ - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG0, msg->cmd); + ret = regmap_write(data->regmap, SBRMI_INBNDMSG0, msg->cmd); if (ret < 0) goto exit_unlock; @@ -48,8 +48,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, */ for (i = 0; i < 4; i++) { byte = (msg->data_in >> i * 8) & 0xff; - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG1 + i, byte); + ret = regmap_write(data->regmap, SBRMI_INBNDMSG1 + i, byte); if (ret < 0) goto exit_unlock; } @@ -58,8 +57,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 = i2c_smbus_write_byte_data(data->client, - SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); + ret = regmap_write(data->regmap, SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); if (ret < 0) goto exit_unlock; @@ -69,8 +67,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * of the requested command */ do { - sw_status = i2c_smbus_read_byte_data(data->client, - SBRMI_STATUS); + ret = regmap_read(data->regmap, SBRMI_STATUS, &sw_status); if (sw_status < 0) { ret = sw_status; goto exit_unlock; @@ -81,8 +78,6 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, } while (retry--); if (retry < 0) { - dev_err(&data->client->dev, - "Firmware fail to indicate command completion\n"); ret = -EIO; goto exit_unlock; } @@ -94,11 +89,11 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, */ if (msg->read) { for (i = 0; i < 4; i++) { - ret = i2c_smbus_read_byte_data(data->client, - SBRMI_OUTBNDMSG1 + i); + ret = regmap_read(data->regmap, + SBRMI_OUTBNDMSG1 + i, &bytes); if (ret < 0) goto exit_unlock; - msg->data_out |= ret << i * 8; + msg->data_out |= bytes << i * 8; } } @@ -106,8 +101,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 = i2c_smbus_write_byte_data(data->client, SBRMI_STATUS, - sw_status | SW_ALERT_MASK); + ret = regmap_write(data->regmap, SBRMI_STATUS, + sw_status | SW_ALERT_MASK); exit_unlock: mutex_unlock(&data->lock); diff --git a/drivers/misc/amd-sbi/rmi-core.h b/drivers/misc/amd-sbi/rmi-core.h index 3d600e450e08..24a6957c8fa0 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 /* SB-RMI registers */ enum sbrmi_reg { @@ -47,7 +48,7 @@ enum sbrmi_msg_id { /* Each client has this additional data */ struct sbrmi_data { - struct i2c_client *client; + struct regmap *regmap; struct mutex lock; struct platform_device *pdev; u32 pwr_limit_max; diff --git a/drivers/misc/amd-sbi/rmi-i2c.c b/drivers/misc/amd-sbi/rmi-i2c.c index ae968cf3c29c..c4207672d1e4 100644 --- a/drivers/misc/amd-sbi/rmi-i2c.c +++ b/drivers/misc/amd-sbi/rmi-i2c.c @@ -13,26 +13,26 @@ #include #include #include +#include #include "rmi-core.h" #define SBRMI_CTRL 0x1 -static int sbrmi_enable_alert(struct i2c_client *client) +static int sbrmi_enable_alert(struct sbrmi_data *data) { - int ctrl; + int ctrl, ret; /* * Enable the SB-RMI Software alert status * by writing 0 to bit 4 of Control register(0x1) */ - ctrl = i2c_smbus_read_byte_data(client, SBRMI_CTRL); - if (ctrl < 0) - return ctrl; + ret = regmap_read(data->regmap, SBRMI_CTRL, &ctrl); + if (ret < 0) + return ret; if (ctrl & 0x10) { ctrl &= ~0x10; - return i2c_smbus_write_byte_data(client, - SBRMI_CTRL, ctrl); + return regmap_write(data->regmap, SBRMI_CTRL, ctrl); } return 0; @@ -57,17 +57,24 @@ static int sbrmi_i2c_probe(struct i2c_client *client) { struct device *dev = &client->dev; struct sbrmi_data *data; + struct regmap_config sbrmi_i2c_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + }; int ret; data = devm_kzalloc(dev, sizeof(struct sbrmi_data), GFP_KERNEL); if (!data) return -ENOMEM; - data->client = client; mutex_init(&data->lock); + data->regmap = 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 = sbrmi_enable_alert(client); + ret = sbrmi_enable_alert(data); if (ret < 0) return ret; From patchwork Wed Jul 17 08:10:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13735201 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2074.outbound.protection.outlook.com [40.107.220.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 EBFAA3A8D8; Wed, 17 Jul 2024 08:11:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203865; cv=fail; b=MAI1UGQyjS6RHrtpv7Gekj5Kn1psb6GYQP9RylbQYvS9Pn8jNuPhM4oKIMh8UZaDz4mY3PhTs/Iy2w5/kxM9zBSgw4ApPN9nVr4w70zYDgfevt5BHBDBqXkYEGXvfzKTLKoChYz7gy9AFgjjrIZM1kbRQNKQr54/jyrw08SaYLg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203865; c=relaxed/simple; bh=j8/ad0R+XnipNczE2//66OlwyKdWdtZ0QEaPsRzGUqI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=utX7KXN5sq9rKF7TDqex7KawJFM0IgQ78WMeLLIPYxyRin/N5zBvQzxltmp2uohwPVIMlHUSNUfuWcD0I2JqFT1aj+g5EZRozWiYWE+l+pQwNehJ1ONu+eGU5BYvN07xqecggm31oZkLj52QUvl1inmmKoduXyT9Zn8VHbxCfw4= 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=dTNfFUPM; arc=fail smtp.client-ip=40.107.220.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="dTNfFUPM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RKsTn7djkvZucyhoxY+zKZh/O/LQVd1kwxyP1tl5OUZVCcZz+GsUR4bhsyCqFPzlZH757AsIDkQnGxakApqiKCeYk9lacKZIlF55rJfhkZqqajS+IoD5Sw9Vd3ZK8GnUD5ntlq2JFYx/NZep40MWecO9YzQU7bXmBLluf06S9ogtogasOc+etzfU/ItVYnCIbp0J14o4Hxlo46PpKPzFcSa9SmLQBLupYOJCzkcUP27NiBcplUpoeBriBUOrX7JixL/Rcj/01kdNPD7JTdTEZnEJHS6CWP4zPoudHRbaVp/IRGNUPDn2C4kTGhGxEBuW/Sbco7J4MyMvC/PCISRKdw== 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=g4sxeW7Y/O7kYe2/hsSIwgsd8XR4Gju8XqQ30vh5rbg=; b=r2fLqZnLviCeu/vgC+cqh7mobIemn4LwYB7wX0gna1jlDi8Al/R6qRUImJrxnTwUpjU7I0CB0KnlxxQQmPTG/FZNBR7TbU3AQFWal3C74Gn/GQ7yAwwES18NYs6307y4MlGRUlVwB+ZzcAVtT2tu9+axlUqGvHfzi0MB5LpDYMvyMZS0/doFQTyhhAj0WR+p9pSJfztYyraQnRto0JWOogG8Mgv+nmEvM94jpBj6yyIQAhvLCadlCXcoDSjC5mUVHVko2UEtN0As2r+rtp0JAjuQaEsWc+GFWwdNqP+Ik3Xtq6nkLgBFEK8F0qNqczPAZ11v7zgNx7XC3rPi5dXi4Q== 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=g4sxeW7Y/O7kYe2/hsSIwgsd8XR4Gju8XqQ30vh5rbg=; b=dTNfFUPMa2zEjhOJwqEA0vqJW38IjGab5lSZ+W4EQp6ltj0S3z8x/Dt6wVSvdk45ISlvcMf0QVGRZLnNcGrcQuSnPfV6vaV9kg38MR8lP5VoYzyD64r5wpOrw6YkQUDHArdyh09BIpg2VnHVS8ThYO05b5HzdrHpQ1D+ljMYdg0= Received: from CH0PR03CA0308.namprd03.prod.outlook.com (2603:10b6:610:118::10) by IA0PR12MB8325.namprd12.prod.outlook.com (2603:10b6:208:407::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.29; Wed, 17 Jul 2024 08:10:59 +0000 Received: from CH1PEPF0000A346.namprd04.prod.outlook.com (2603:10b6:610:118:cafe::fa) by CH0PR03CA0308.outlook.office365.com (2603:10b6:610:118::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.29 via Frontend Transport; Wed, 17 Jul 2024 08:10: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 CH1PEPF0000A346.mail.protection.outlook.com (10.167.244.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7784.11 via Frontend Transport; Wed, 17 Jul 2024 08:10: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; Wed, 17 Jul 2024 03:10:56 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v2 3/8] misc: amd-sbi: Add support for AMD_SBI IOCTL Date: Wed, 17 Jul 2024 08:10:22 +0000 Message-ID: <20240717081027.2079549-4-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240717081027.2079549-1-akshay.gupta@amd.com> References: <20240717081027.2079549-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CH1PEPF0000A346:EE_|IA0PR12MB8325:EE_ X-MS-Office365-Filtering-Correlation-Id: a413b20b-e8ec-46b8-5b3b-08dca637fdec 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: JNvAFn6d6IcErtUog1bbvaA5A3b7evsvcKc+5t69IaYkIb6/9LjtiasD5VkeCqRoG+fg7oM/E5wOZVAP/TSnbtUbkMeztSUGdAUQ14TcyOx53z8lB5ctbcjQg5dbW0Few1bUAj5GUDZHsI++hiJfpJJu+aX9gN5bWRh0HBK96bg6jXMAhYFZ18OC3Fbmb8+7OsSwt/MqHIIxXjRmd8FyiDk3606+eclHxBCas1nfuCZITAXgYLLi273G2uqCc66KZIiA9SE6OUd+C2f8/CSbftHLnuwk7VbkurMhotX2iAxzSlsI8s8D73edhmHDjMcYCcFL0QSqlDxNfHTwqL3M3xG/luNfDBVeVvsEikOlMbwP8Cgz965EdJae7vESkjFltR9Xc6p4Lw8LDU5GHRNLOUrCp+m+bcBIrjJlPaHyIdZzUjGgRBYenXw+KZLM7pugzTfIdmTrW4nwzG8AWst5wjRPOyFxVL0Tg2rYNpXXsahvNKmjob63eY2laZhONA47lJhz8iL/OZkO4QxX5xIuEFpCkY6bsHnH3eqQA/3oToG1Qxhp8Q4baGMWTyVacbjAX4VPqFvnjKosgcnpoBIsv4RIO0e+5OLNGnKdhg09f1qB7TDOYNqyms9uffKAcORYaxLa9av5nNDuCBQIdntiv9EqzL4/W+zBW06Sg2pnSymid+loX3gd2FP1vmj4xyPg04jSsoLDGINTGioJe5KQuqh70O6Jh9MSGeR6fkzsojBr12w4KPpeHPJnkASn5Q9AjSDP+lpqZ/CDEHb65ImSqJ26hapgLo5X7fn6bEAKTHMMTtF2uuAjhftXruTmOMsvNAkZ077kGVys9FlwBrq8ex6ozMrtcUcmwPbyMIwXPuwhprepoQmBGobcd0DsF8p1K9y+gCKw8EuFrIpPw1FVQ2B5pSSHNFgipmreCBH7tTrZmcIYq8BylAP5n7StT+TTEJIBmHbJZiKPYzZfLuhwUfNLaFYfC+4M/BVNcHn5SSOikfGoaUkTRKVBA80JbIl1GDuSdUkhowgfVJ8w08StlSOk4ExgnfmaGspQ9yUiJWcXOBJUGbi0wyqXAt0YUUnmXSnN2uplxm2Jlk8PnUjf69xR8hh6G37Ma+Hh9EMtdbp5zXPpTRjb+pPdw8YRaaz54cbyhRlAnO3TJv1PUwwk1wkN3sZfSwKKBOBvOVzcOuga4LIXlOnyiAxkXfVhQMo/1zlpJlHquu5r/7xl+zufBrCtQEhx0vnI5ewocZ+8p/XtUJEphWEWyllTNOwI8F4AtDVx8DE39v9jmttV7+PbexAJ+eZjOoALqaUp0Ul/hcLACy/DSaWuYqFp8LThWGaJZjP9B7eBH1gI0HTBduin5EHsFvC2VLzbbHt3Ss0d+j9sRtJTSHMC4qoN/xN0lzzAp5G9rGeED5NdfEhnmQgPPA== 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: 17 Jul 2024 08:10:59.2367 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a413b20b-e8ec-46b8-5b3b-08dca637fdec 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: CH1PEPF0000A346.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8325 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. Open-sourced and widely used https://github.com/amd/esmi_oob_library will continue to provide user-space programmable API. Signed-off-by: Akshay Gupta Reviewed-by: Naveen Krishna Chatradhi --- Changes since v1: - Previously patch 5 - Add IOCTL description in ioctl-number.rst - Split patch as per suggestion. .../userspace-api/ioctl/ioctl-number.rst | 2 + drivers/misc/amd-sbi/rmi-core.c | 89 +++++++++++++++++-- drivers/misc/amd-sbi/rmi-core.h | 16 ++-- drivers/misc/amd-sbi/rmi-hwmon.c | 15 ++-- drivers/misc/amd-sbi/rmi-i2c.c | 25 +++++- include/uapi/misc/amd-apml.h | 47 ++++++++++ 6 files changed, 166 insertions(+), 28 deletions(-) create mode 100644 include/uapi/misc/amd-apml.h diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst index 9a97030c6c8d..2665993148dd 100644 --- a/Documentation/userspace-api/ioctl/ioctl-number.rst +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst @@ -385,6 +385,8 @@ Code Seq# Include File Comments 0xF8 all arch/x86/include/uapi/asm/amd_hsmp.h AMD HSMP EPYC system management interface driver +0xF9 00-1F uapi/misc/amd-apml.h AMD side band system management interface driver + 0xFD all linux/dm-ioctl.h 0xFE all linux/isst_if.h ==== ===== ======================================================= ================================================================ diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c index 5a0b7912cc4e..e7778749940e 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" @@ -22,7 +25,7 @@ #define TRIGGER_MAILBOX 0x01 int rmi_mailbox_xfer(struct sbrmi_data *data, - struct sbrmi_mailbox_msg *msg) + struct apml_message *msg) { unsigned int bytes; int i, ret, retry = 10; @@ -46,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 = 0; i < 4; i++) { - byte = (msg->data_in >> i * 8) & 0xff; + for (i = 0; i < MB_DATA_SIZE; i++) { + byte = msg->data_in.reg_in[i]; ret = regmap_write(data->regmap, SBRMI_INBNDMSG1 + i, byte); if (ret < 0) goto exit_unlock; @@ -87,13 +90,13 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1] * {SBRMI_x34(MSB):SBRMI_x31(LSB)}. */ - if (msg->read) { - for (i = 0; i < 4; i++) { + if (msg->data_in.reg_in[RD_FLAG_INDEX]) { + for (i = 0; i < MB_DATA_SIZE; i++) { ret = regmap_read(data->regmap, SBRMI_OUTBNDMSG1 + i, &bytes); if (ret < 0) - goto exit_unlock; - msg->data_out |= bytes << i * 8; + break; + msg->data_out.reg_out[i] = bytes; } } @@ -103,8 +106,78 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, */ ret = regmap_write(data->regmap, SBRMI_STATUS, sw_status | SW_ALERT_MASK); - exit_unlock: mutex_unlock(&data->lock); return ret; } + +static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) +{ + int __user *arguser = (int __user *)arg; + struct apml_message msg = { 0 }; + bool read = false; + int ret = -EFAULT; + + struct sbrmi_data *data = container_of(fp->private_data, struct sbrmi_data, + sbrmi_misc_dev); + if (!data) + return -ENODEV; + + /* Copy the structure from user */ + if (copy_struct_from_user(&msg, sizeof(msg), arguser, + sizeof(struct apml_message))) + return ret; + + /* Is this a read/monitor/get request */ + if (msg.data_in.reg_in[RD_FLAG_INDEX]) + read = true; + + switch (msg.cmd) { + case 0 ... 0x999: + /* Mailbox protocol */ + ret = rmi_mailbox_xfer(data, &msg); + break; + default: + pr_err("Command:0x%x not recognized\n", msg.cmd); + break; + } + + /* Copy results back to user only for get/monitor commands and firmware failures */ + if ((read && !ret) || ret == -EPROTOTYPE) { + if (copy_to_user(arguser, &msg, sizeof(struct apml_message))) + ret = -EFAULT; + } + return ret; +} + +static const struct file_operations sbrmi_fops = { + .owner = THIS_MODULE, + .unlocked_ioctl = sbrmi_ioctl, + .compat_ioctl = sbrmi_ioctl, +}; + +int create_misc_rmi_device(struct sbrmi_data *data, + struct device *dev) +{ + int ret; + + data->sbrmi_misc_dev.name = devm_kasprintf(dev, + GFP_KERNEL, + "sbrmi-%x", + data->dev_static_addr); + data->sbrmi_misc_dev.minor = MISC_DYNAMIC_MINOR; + data->sbrmi_misc_dev.fops = &sbrmi_fops; + data->sbrmi_misc_dev.parent = dev; + data->sbrmi_misc_dev.nodename = devm_kasprintf(dev, + GFP_KERNEL, + "sbrmi-%x", + data->dev_static_addr); + data->sbrmi_misc_dev.mode = 0600; + + ret = misc_register(&data->sbrmi_misc_dev); + if (ret) + return ret; + + dev_info(dev, "register %s device\n", data->sbrmi_misc_dev.name); + return ret; +} diff --git a/drivers/misc/amd-sbi/rmi-core.h b/drivers/misc/amd-sbi/rmi-core.h index 24a6957c8fa0..b728f5582256 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_ +#include #include #include #include #include +#include /* SB-RMI registers */ enum sbrmi_reg { @@ -48,19 +50,15 @@ enum sbrmi_msg_id { /* Each client has this additional data */ struct sbrmi_data { + struct miscdevice sbrmi_misc_dev; struct regmap *regmap; + /* Mutex locking */ struct mutex lock; - struct platform_device *pdev; u32 pwr_limit_max; + u8 dev_static_addr; }; -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 *msg); +int rmi_mailbox_xfer(struct sbrmi_data *data, struct apml_message *msg); int create_hwmon_sensor_device(struct device *dev, struct sbrmi_data *data); +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-hwmon.c index 36913f105eef..dda9d9220b58 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" /* Do not allow setting negative power limit */ @@ -15,7 +16,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { struct sbrmi_data *data = dev_get_drvdata(dev); - struct sbrmi_mailbox_msg msg = { 0 }; + struct apml_message msg = { 0 }; int ret; if (!data) @@ -24,7 +25,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, if (type != hwmon_power) return -EINVAL; - msg.read = true; + msg.data_in.reg_in[RD_FLAG_INDEX] = 1; switch (attr) { case hwmon_power_input: msg.cmd = SBRMI_READ_PKG_PWR_CONSUMPTION; @@ -35,7 +36,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, ret = rmi_mailbox_xfer(data, &msg); break; case hwmon_power_cap_max: - msg.data_out = data->pwr_limit_max; + msg.data_out.mb_out[RD_WR_DATA_INDEX] = data->pwr_limit_max; ret = 0; break; default: @@ -44,7 +45,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, if (ret < 0) return ret; /* hwmon power attributes are in microWatt */ - *val = (long)msg.data_out * 1000; + *val = (long)msg.data_out.mb_out[RD_WR_DATA_INDEX] * 1000; return ret; } @@ -52,7 +53,7 @@ static int sbrmi_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long val) { struct sbrmi_data *data = dev_get_drvdata(dev); - struct sbrmi_mailbox_msg msg = { 0 }; + struct apml_message msg = { 0 }; if (!data) return -ENODEV; @@ -68,8 +69,8 @@ static int sbrmi_write(struct device *dev, enum hwmon_sensor_types type, val = clamp_val(val, SBRMI_PWR_MIN, data->pwr_limit_max); msg.cmd = SBRMI_WRITE_PKG_PWR_LIMIT; - msg.data_in = val; - msg.read = false; + msg.data_in.mb_in[RD_WR_DATA_INDEX] = val; + msg.data_in.reg_in[RD_FLAG_INDEX] = 0; 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 c4207672d1e4..e244e101f173 100644 --- a/drivers/misc/amd-sbi/rmi-i2c.c +++ b/drivers/misc/amd-sbi/rmi-i2c.c @@ -40,15 +40,15 @@ static int sbrmi_enable_alert(struct sbrmi_data *data) static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data) { - struct sbrmi_mailbox_msg msg = { 0 }; + struct apml_message msg = { 0 }; int ret; msg.cmd = SBRMI_READ_PKG_MAX_PWR_LIMIT; - msg.read = true; + msg.data_in.reg_in[RD_FLAG_INDEX] = 1; ret = rmi_mailbox_xfer(data, &msg); if (ret < 0) return ret; - data->pwr_limit_max = msg.data_out; + data->pwr_limit_max = msg.data_out.mb_out[RD_WR_DATA_INDEX]; return ret; } @@ -83,8 +83,24 @@ static int sbrmi_i2c_probe(struct i2c_client *client) if (ret < 0) return ret; + data->dev_static_addr = client->addr; dev_set_drvdata(dev, data); - return create_hwmon_sensor_device(dev, data); + ret = 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 = 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 = NULL; + data->sbrmi_misc_dev.parent = NULL; + dev_info(&client->dev, "Removed sbrmi-i2c driver\n"); + return; } static const struct i2c_device_id sbrmi_id[] = { @@ -107,6 +123,7 @@ static struct i2c_driver sbrmi_driver = { .of_match_table = of_match_ptr(sbrmi_of_match), }, .probe = sbrmi_i2c_probe, + .remove = sbrmi_i2c_remove, .id_table = sbrmi_id, }; diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h new file mode 100644 index 000000000000..81e505eccac4 --- /dev/null +++ b/include/uapi/misc/amd-apml.h @@ -0,0 +1,47 @@ +/* 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 + +/* These are byte indexes into data_in and data_out arrays */ +#define RD_WR_DATA_INDEX 0 +#define REG_OFF_INDEX 0 +#define REG_VAL_INDEX 4 +#define RD_FLAG_INDEX 7 + +#define MB_DATA_SIZE 4 + +struct apml_message { + /* message ids: + * Mailbox Messages: 0x0 ... 0x999 + */ + __u32 cmd; + + /* + * 8 bit data for reg read, + * 32 bit data in case of mailbox, + */ + union { + __u32 mb_out[2]; + __u8 reg_out[8]; + } data_out; + + /* + * [0]...[3] mailbox 32bit input + * [7] read/write functionality + */ + union { + __u32 mb_in[2]; + __u8 reg_in[8]; + } data_in; +} __attribute__((packed)); + +/* ioctl command for mailbox msgs using generic _IOWR */ +#define AMD_SBI_BASE_IOCTL_NR 0xF9 +#define SBRMI_IOCTL_CMD _IOWR(AMD_SBI_BASE_IOCTL_NR, 0, struct apml_message) + +#endif /*_AMD_APML_H_*/ From patchwork Wed Jul 17 08:10:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13735202 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2054.outbound.protection.outlook.com [40.107.237.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 5D63C25624; Wed, 17 Jul 2024 08:11:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203868; cv=fail; b=aTvrpSiY6WPg9EMrCXGAZTsZvPBfg8hyA80VyaLdCxNDBmoP1tYNPyHHw3QFGQxibuR8tcsNctSojCdhWq4Dl+kiiU+15FZEyY/E0GUPH0/0Z9ISvBM+0MOSQCjcSg4dLHvzQAk+9fpHHPEaoK/zmF1Xnq/6Jdi6+8NV5ZCo1do= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203868; c=relaxed/simple; bh=YWAPkUykjagh1DXqXPopSQhT4tP32QGbETuHcuJ3AdU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JM7cuD7clyBKvaNs8l5w8FhTbUqi/pc+uev2gr7kEXwKKsolWpD/C9p3XFS7Hm7YFWFXmGMky7PMRloBMBybh1iorTw+zfgKi6hPQY5QlVJP/19+MHgcvHg9qp0JRFENXniOONaMKFSqigm36AoG5aHim6jMQQu4Lt+TCwLughY= 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=U/Jg0djq; arc=fail smtp.client-ip=40.107.237.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="U/Jg0djq" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kEDxFm5VYuSVvW77juT1a1sj4MmM1FxGtmJGaxOijG+0Ot459NyMQBGmV8UH3RGRNuB1wLL67efBQkB0KEgW+/Bo6YgMuqoa4I0EXm2iMgGuQnjEGF1l4d2N15lNIlvHxr8tuDSviV6ml68sSCZO3fVNW+sElVbsUBY1sgLEFMbOnE6vEfTvyi32mEl8NRE9DF5WrmHhe2XwCQPcUPxfDuUHQJSaBv3Yc2scQp7tug5TaOgk5nHbRYwg5rQ9z8U8YjGSyg3lLtfSNjLHWc1yDA8BMB9k5f3idDhw9Xt5MypphrDCgyhVAlyIZYOktU9o1IRvl6Z5C9SRfyve1xqsgw== 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=piDOeZ0zlUoJ5vFQY5A8oy6w77pFMiORvykgLOCEQjw=; b=MKVBWCWXAfiwCtTvb9ree5lPHXP2tZxi6wGXbK9q1XprEoK3S6uyzwhmQd8KAnJlHXHjPme1JNU/FrQhdeJZT5PTTlJ9m/2IkQfSaRNx5O2asWVDTYVI6Q32QZI7oyt3V162UUWCNqxIMtwFZyXf14pa9Tw/wrP4JrzZ3UZzQYKRJiQCieunXhRzu3xJEpabxN+SMX2ixXcPz3YxKQ9DL3Q/NQyN5tyObpf/7PfP4/Rgx3rMFSZjOO49n9FNWGoFTARuRFrdxNAtWPIASwA0GT4pzQKrF8IAtFZB9aRL4PxJVWxrYZDOn8U/fLF8mVPdam4elWf3Hz8xUAuZhYXnkQ== 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=piDOeZ0zlUoJ5vFQY5A8oy6w77pFMiORvykgLOCEQjw=; b=U/Jg0djqv+f8/4T1VZRzcDwiy5Wg7z5PVZAQOs9RZIL+7xToZuPbIN7dzI4vJz4eMoJ7kiGg/cPLg3QPvXoHB4WbxpxosQ1jYFyeByM2wQYg6/5NQr7Vi3YX5zS5BLB2Ae2ijRxZAn4Htoro9LHvV/s85ZY1CzfmuiSmEQ+MQsI= Received: from DS7PR03CA0232.namprd03.prod.outlook.com (2603:10b6:5:3ba::27) by SJ0PR12MB6903.namprd12.prod.outlook.com (2603:10b6:a03:485::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.29; Wed, 17 Jul 2024 08:11:03 +0000 Received: from CH1PEPF0000A348.namprd04.prod.outlook.com (2603:10b6:5:3ba:cafe::54) by DS7PR03CA0232.outlook.office365.com (2603:10b6:5:3ba::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16 via Frontend Transport; Wed, 17 Jul 2024 08:11:03 +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 CH1PEPF0000A348.mail.protection.outlook.com (10.167.244.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7784.11 via Frontend Transport; Wed, 17 Jul 2024 08:11:03 +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; Wed, 17 Jul 2024 03:11:00 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v2 4/8] misc: amd-sbi: Add support for mailbox error codes Date: Wed, 17 Jul 2024 08:10:23 +0000 Message-ID: <20240717081027.2079549-5-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240717081027.2079549-1-akshay.gupta@amd.com> References: <20240717081027.2079549-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CH1PEPF0000A348:EE_|SJ0PR12MB6903:EE_ X-MS-Office365-Filtering-Correlation-Id: d5bfae46-7838-4643-c5ca-08dca6380058 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: 6sNHNluVcDwfpEVuQ76PoCGxZjvhBFvQ/moqXFExha6RYd5xN/1q33IVTVIk5ur/BWjA9XfmianWE4LnhWvbS8XVXEKPr0kvhMRshgwzNuBNPNifcsKOCF/n/liQxe57EDMmVXupxsysKhtbbg9FGgCHAIR5JaEZDUFQatKNAY6013gdw+VKLDQjAOgCUZB9HX1d9GaMQ1xxKr6dSFcZaBHbC1ztFymlE10I1nAupPfSafWaKkM50UFMjPk928OfD+ICj4Mw81iOrCY/nA/WndGKmkngsVMX6qRUnqfCMyKbjuYhrdeDEcaHKIt2rzhnpqLZ2rven8Eq56zPI8l9X2j6XOfE9WjUgsKLH7ThfKZNTIOJ9VDOV5NzKAq5rmootI/T0LykHdqRFxvV5zXtAGpVLiZq79i05pGVZWgXoqkBptL0xPpQHx6ySGEL83p602IvSqyqd7XvttyZ3XhCLtd5Rku9zN2Ify4Nd1ZJo76gnC5T6Sbt1vXMAzy77pSevA8C9jZYd/kT2TX0t6JyomgQ3oiUa7K3QYsCrrl3mfhbZmJ/a9BK1GynlWqdUKZGRIxEFUoE20fRLTHB9s8wIY78nOiDmbw4HR5+zXlKqHWhP1kpG2yg0Hv1N6i7N6LfY828qsRJZ2/2YArqYEMXZnamGqp2Cj9wLfUWsz1W359wm8YgL4P8mJ2qmQevOesXmow2Y93fXUykVD0Czvyb97GrwspgZBnkxD4ElIINJ2CCpU+8FBIhOl8ERCcLp6/E+VJ7mFeNxHQT1ysyA+ByauChP5l08O1ZVdNf4nL/0qvB7M5jt1W/cm+fQZJNCOzdk5nb7ei5U/ycuWMOqTR3Iwpu0RlYOMpHd+J8e4o4DLYJPiITcLJYP4IJ6HIR3RiNBfTITOYGHNurDfHoe9wq2I0zv2Oa3Hk9NPrcWsv0I/kLo1S3CsVx4bshJVLJiiHLrZgsxxkXEsc1fnbhsOCVHkI/Ni0jfoxWDIFce5XF5rBukpukomoqvovOudsjkSMvVpCzXQ9XelkiEfQCZi+LJ3GrJi2exG3VpT/n/J8e+PyhKq3D6erPsklYc+O95HJzEA426ypgoxAbt+iVPxQ5NHW+pf84TiyCXaf2Kxd85xyxUBE84H7oFHcvvnmw/MMcj6/M0OrvCOp8kJnmHul6S+9NxREJPNdaDgl5qBH5+66EvWltK+cxDReRt7g/ycXDqy9mx/JPMKwFxpUOVo4TQcVKQyhC7HJ1TIkv0gddd9fVPoY9cxjEkekishwIsQfEn1FM71f2O6MUlAmclLI/1iZzaUtYE9hsodbBra26tMut32dkiHmLxds9KfArf9u8Yq7qv3bqNWoqnVhM/I4IcwHcK9ApDkoReoipskKUJCCQLvfs17Wan+PL3brY0Fnae8v+qLCWeNFXdnPx1ADRVLU8zxr307V25cMZoBh8Mmm1zDv/pWdV4bQGXRCkUf+c 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)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2024 08:11:03.3027 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d5bfae46-7838-4643-c5ca-08dca6380058 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: CH1PEPF0000A348.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6903 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 userspace. Signed-off-by: Akshay Gupta Reviewed-by: Naveen Krishna Chatradhi --- Changes since v1: - bifurcated from previous patch 5 drivers/misc/amd-sbi/rmi-core.c | 12 +++++++++++- include/uapi/misc/amd-apml.h | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c index e7778749940e..01c3a6c9c15c 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -27,13 +27,15 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, struct apml_message *msg) { - unsigned int bytes; + unsigned int bytes, ec; int i, ret, retry = 10; int sw_status; u8 byte; mutex_lock(&data->lock); + msg->fw_ret_code = 0; + /* Indicate firmware a command is to be serviced */ ret = regmap_write(data->regmap, SBRMI_INBNDMSG7, START_CMD); if (ret < 0) @@ -85,6 +87,9 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, goto exit_unlock; } + ret = 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] @@ -100,12 +105,17 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, } } +exit_clear_alert: /* * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the * ALERT to initiator */ ret = regmap_write(data->regmap, SBRMI_STATUS, sw_status | SW_ALERT_MASK); + if (ec) { + ret = -EPROTOTYPE; + msg->fw_ret_code = ec; + } exit_unlock: mutex_unlock(&data->lock); return ret; diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h index 81e505eccac4..06e93a6a8f4b 100644 --- a/include/uapi/misc/amd-apml.h +++ b/include/uapi/misc/amd-apml.h @@ -38,6 +38,10 @@ struct apml_message { __u32 mb_in[2]; __u8 reg_in[8]; } data_in; + /* + * Error code is returned in case of soft mailbox + */ + __u32 fw_ret_code; } __attribute__((packed)); /* ioctl command for mailbox msgs using generic _IOWR */ From patchwork Wed Jul 17 08:10:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13735203 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2087.outbound.protection.outlook.com [40.107.237.87]) (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 BA41D482D7; Wed, 17 Jul 2024 08:11:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203873; cv=fail; b=sDUjy/HrvmeljP1lbYMq9EVYCMn8Pi+XCq5heEyOG3zczXaXnF86LET3ru/HwFLr1XU2vfPx5EeD14JnHiolA+somHtqNpvMQY9G8GU78rrFR1yM9eVC89E9zM0wjDMWLdY4klrS/36dv3y04CWg6il8g9xyU91bUtB7APGUdsQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203873; c=relaxed/simple; bh=uv0IuzTzxABfURpktfHXf5Fhs4XxaPg7MsiikBhoUAE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ViOdpyycuMedkajGcn4GNXCGG8Bmr8Xz9iSX25IsBUNBX++FBHLTw1sdpzbgNoiSicf9IVhsFJ+1DTSl3AIwYr508z8FgZZlr9YPztOoHLh7Lilq42JEj/MnoaIyt89BqtkkIa549VuYA2cxo1YwlQ1UfRaQOrSOBDrYnM8e/yk= 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=B3BJ+To0; arc=fail smtp.client-ip=40.107.237.87 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="B3BJ+To0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EsODCHOOxilm/Rax7lD3pQF19nL+uRoBJRsjD53V/GznyxxfFq500AS0D/TZQDDhuAFhP56nMaz8zhLhCXX1oJGSk4+0qUIG/1tk1JycrjU4zBSqGCTj6KsPeS21Te8AoAE0Tj53MhkgaPAXXDqnGWrLMwVzcXm8jfsVyMX4hb6KVTnEj77LxBwSK5ZL7F8CPxbSGDnD9CyqfKwugjXbwc5uXYS9uvI7y5oXpKKQRgsB4DduA+fMwc+LmLqtuMb44iYV14oK40i4Gqcimkrun7Fz3DYA9XLmCBTCIBSNYFw9pq9jIrFrWwgMQpL9nCrJzoa/I6DKDAm98KW8sIPPgQ== 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=BBtLQryjXxUBpXiNGGM8aWHmkwp9nf8Ib5io34VO0fQ=; b=YsyiOA1D2/+mxJyJQYFb+N0bpK9aU6/1Mza4pLaciq0YVmQXXXuZF81OPBnBoXsSMPd3J5Uhst7Cf8vS+OSZTwQm/2555oRhI0lKqlEIneMr+5m9abLcJHjpzhS+0TFM33o1kYxaj9X/FuSgIA6YInabkAPWB1RK1Ibm94XgY7uXIX81005NIwypKU2uQcEybquQOVSQ6WewuWGz+B0b7/jP4pEBP/UJ1L+gAd8TgEOvPAe13p6UT28pNpapNR/Y1lbJBTJMMK939TJTVCPGzAbXOSRzY0aVs3a/k/NrY8HjTJMBgeop65dolzZniKenCxBPY7R0vTlpD1DWfv3fww== 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=BBtLQryjXxUBpXiNGGM8aWHmkwp9nf8Ib5io34VO0fQ=; b=B3BJ+To04z4AWMP0QtiIaAJwUYe0czwZ0TsCQ1rt6kIBrNHDGr3kX9LtCdvwFyrsCo7ft63ophG3vMxHagmeP1qlMtrSTT5ZmzyTMZZkS9b/b0vWTg8PXjpJjZm3qIiW/OEWLorz7cCjg9BTv75a2En3SjHTjKoNKaTYfc/QwWo= Received: from CH2PR18CA0057.namprd18.prod.outlook.com (2603:10b6:610:55::37) by PH0PR12MB8823.namprd12.prod.outlook.com (2603:10b6:510:28e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.28; Wed, 17 Jul 2024 08:11:06 +0000 Received: from CH1PEPF0000A34B.namprd04.prod.outlook.com (2603:10b6:610:55:cafe::25) by CH2PR18CA0057.outlook.office365.com (2603:10b6:610:55::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.29 via Frontend Transport; Wed, 17 Jul 2024 08:11:06 +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 CH1PEPF0000A34B.mail.protection.outlook.com (10.167.244.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7784.11 via Frontend Transport; Wed, 17 Jul 2024 08:11:06 +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; Wed, 17 Jul 2024 03:11:03 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v2 5/8] misc: amd-sbi: Add support for CPUID protocol Date: Wed, 17 Jul 2024 08:10:24 +0000 Message-ID: <20240717081027.2079549-6-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240717081027.2079549-1-akshay.gupta@amd.com> References: <20240717081027.2079549-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CH1PEPF0000A34B:EE_|PH0PR12MB8823:EE_ X-MS-Office365-Filtering-Correlation-Id: 4aa2388b-7903-44a1-d406-08dca638024c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: XFUZjJ60R11P0vMqQo2j7em2gsmqh4r2OfMWdaQLJ8XY/gmqpMehVts4G6SAXh4Fx2bO6h5HovO3IZVl5CcMwzA4gQ6DEj84r+xShW7skhZ9gJP0bEuot5NbGNNtZrcsB7+YsT9/jmm+DkFVDkWg2MN3+ZOeQ1jJ9dQBxvuMIiZyuGNi4iPf8Qf2OHU97+KK9WGqsYm/awYuTqdl+cIDj+q8XksuN6VN0V7PB56XTjEvUedKCHieWb17Sz2zwuHKZhx4J/YJUCJagFX1AJvgnLwTb6123N2ttI0OVDIeaS/P9T+MdijSkrSaJbYNugNquneCXFlOMbO8PnseyCbxFirDztTcflBY1GVVzHyTaJ/1dHBTcrCBeCwQwOnVKRM3IKYNzVjZX/YIIevqzGNO9CDnB4+AggIB9kTiE8pDo1o41UvJBYMjvoGhMPOkn2ekIwVfkp32RER1f/o8Dnm4mFDCW8PxFU0ox4MW7tmOjlS8hUKXSp9sLr2OKMIKB/Sq5OnqYMkGclZDCrmgqw1lQhQky3J9YTB9zpz803/SbzXY37DmzJvDg/dTPzmq2BS+QDmafkWTuMVsy2RXfk2VszguqA96JMJ5TU6hpb2JyQ6f3w+8UJE1mw64U5H+K37PpMSNLJFQ1a5cRRuEFuvXE1EFQaUj8mAgiHwy22FKS8B+jjhBG7H315kviwdqo2xR39uY1W49FKpNRvGqnbloLqWD2S++WbWJKXDLNJlmn8B1ZwsI7HRRXNI5v5GSje3FWLqBWgy+vDl/ZhSxhTYxOseTDiRZQLqgt20vQK6XXG57Re8SsuuGZgk9DhkDV8AlT+zoiGdgMw3g+3EdtkCORWKbEhThPY4/b5Ed59D811yqxzQzZZ86s75UCiWvccvrt+uL625brlge/Q4IZ6EfPsQDF1b/L12TlDmiDkXahuwVD8xQwRfa0qP/GvTnY7WjHV44j2t4ynmkA4+NGngxWfSGXoapIfzE7kIAIx0ScYrhS4h5mzt9jwt6AxCh0S+C7OHXvCSTH06gAGj9L6P38dhXoyMc0w8tEiOMFI7PAXlIRSV7yMWDoCvNDXh6EBPM8opH5adZhR4mMz5DOY5XOCpZRH9VjrED0jlE4n3cZvIsckDBUdfWbZPVzc+d/Zy5g5wDLITyqQT22I7I6Ig+xELS/hRN+p4J7oyV/XczHF5wjsKpDEYA0be7EVGIUo6qGgGPdLz1dLykqxq/gdI5gQIn0feEZ+aYBVBvMy+eY6Ww3vRDL5BGA99CV0E7ZYzxYsU7cYrs1Orcmh+PxKedSPaUVojz7SWdU2c6PesoKa91Ie1wCa5tUFrK56YEenX2KKfTqFNh4Xbt3Z9KrPDmZw9/rzd56uKwiBcSB0C0PE443MCaJAt220VFb8mhPe+BcZsgTARED+WOr2uVm7Uben2jc+x7NEPQH4BXETSdaAPED0/hYJLOoXRAjV7jQKxi 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)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2024 08:11:06.5642 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4aa2388b-7903-44a1-d406-08dca638024c 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: CH1PEPF0000A34B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8823 - 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. Signed-off-by: Akshay Gupta Reviewed-by: Naveen Krishna Chatradhi --- Changes since v1: - bifurcated from previous patch 5 drivers/misc/amd-sbi/rmi-core.c | 170 ++++++++++++++++++++++++++++++++ drivers/misc/amd-sbi/rmi-core.h | 5 +- include/uapi/misc/amd-apml.h | 15 +++ 3 files changed, 189 insertions(+), 1 deletion(-) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c index 01c3a6c9c15c..57625bc1b4de 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -17,6 +17,8 @@ /* Mask for Status Register bit[1] */ #define SW_ALERT_MASK 0x2 +/* Mask to check H/W Alert status bit */ +#define HW_ALERT_MASK 0x80 /* Do not allow setting negative power limit */ #define SBRMI_PWR_MIN 0 @@ -24,6 +26,171 @@ #define START_CMD 0x80 #define TRIGGER_MAILBOX 0x01 +/* 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 + +/* 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; + }; + u8 ext; /* extended function */ +} __packed; + +/* 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; + +#define prepare_cpuid_input_message(input, thread_id, func, ext_func) \ + input.rd_len = CPUID_RD_DATA_LEN, \ + input.wr_len = CPUID_WR_DATA_LEN, \ + input.proto_cmd = RD_CPUID_CMD, \ + input.thread = thread_id << 1, \ + input.value = func, \ + input.ext = ext_func + +/* + * For Mailbox command software alert status bit is set by firmware + * to indicate command completion + * 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 firmware before + * reading the data out. + */ +static int sbrmi_wait_status(struct sbrmi_data *data, + int *status, int mask) +{ + int ret, retry = 100; + + do { + ret = regmap_read(data->regmap, SBRMI_STATUS, status); + if (ret < 0) + return ret; + + if (*status & mask) + break; + + /* Wait 1~2 second for firmware to return data out */ + if (retry > 95) + usleep_range(50, 100); + else + usleep_range(10000, 20000); + } while (retry--); + + if (retry < 0) + ret = -ETIMEDOUT; + return ret; +} + +static int sbrmi_get_rev(struct sbrmi_data *data) +{ + struct apml_message msg = { 0 }; + int ret; + + msg.data_in.reg_in[REG_OFF_INDEX] = SBRMI_REV; + msg.data_in.reg_in[RD_FLAG_INDEX] = 1; + ret = regmap_read(data->regmap, + msg.data_in.reg_in[REG_OFF_INDEX], + &msg.data_out.mb_out[RD_WR_DATA_INDEX]); + if (ret < 0) + return ret; + + data->rev = msg.data_out.reg_out[RD_WR_DATA_INDEX]; + return 0; +} + +/* Read CPUID function protocol */ +static int rmi_cpuid_read(struct sbrmi_data *data, + struct apml_message *msg) +{ + struct cpu_msr_indata input = {0}; + struct cpu_msr_outdata output = {0}; + int val = 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 = sbrmi_get_rev(data); + if (ret < 0) + goto exit_unlock; + } + /* CPUID protocol for REV 0x10 is not supported*/ + if (data->rev == 0x10) { + ret = -EOPNOTSUPP; + goto exit_unlock; + } + + thread = msg->data_in.reg_in[THREAD_LOW_INDEX] | + msg->data_in.reg_in[THREAD_HI_INDEX] << 8; + + /* Thread > 127, Thread128 CS register, 1'b1 needs to be set to 1 */ + if (thread > 127) { + thread -= 128; + val = 1; + } + ret = regmap_write(data->regmap, SBRMI_THREAD128CS, val); + if (ret < 0) + goto exit_unlock; + + prepare_cpuid_input_message(input, thread, + msg->data_in.mb_in[RD_WR_DATA_INDEX], + msg->data_in.reg_in[EXT_FUNC_INDEX]); + + ret = regmap_bulk_write(data->regmap, CPUID_MCA_CMD, + &input, CPUID_WR_REG_LEN); + if (ret < 0) + goto exit_unlock; + + ret = sbrmi_wait_status(data, &hw_status, HW_ALERT_MASK); + if (ret < 0) + goto exit_unlock; + + ret = regmap_bulk_read(data->regmap, CPUID_MCA_CMD, + &output, CPUID_RD_REG_LEN); + if (ret < 0) + goto exit_unlock; + + ret = regmap_write(data->regmap, SBRMI_STATUS, + HW_ALERT_MASK); + if (ret < 0) + goto exit_unlock; + + if (output.num_bytes != CPUID_RD_REG_LEN - 1) { + ret = -EMSGSIZE; + goto exit_unlock; + } + if (output.status) { + ret = -EPROTOTYPE; + msg->fw_ret_code = output.status; + goto exit_unlock; + } + msg->data_out.cpu_msr_out = output.value; +exit_unlock: + mutex_unlock(&data->lock); + return ret; +} + int rmi_mailbox_xfer(struct sbrmi_data *data, struct apml_message *msg) { @@ -147,6 +314,9 @@ static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) /* Mailbox protocol */ ret = rmi_mailbox_xfer(data, &msg); break; + case APML_CPUID: + ret = rmi_cpuid_read(data, &msg); + break; default: pr_err("Command:0x%x not recognized\n", msg.cmd); break; diff --git a/drivers/misc/amd-sbi/rmi-core.h b/drivers/misc/amd-sbi/rmi-core.h index b728f5582256..529c8284dec4 100644 --- a/drivers/misc/amd-sbi/rmi-core.h +++ b/drivers/misc/amd-sbi/rmi-core.h @@ -15,7 +15,8 @@ /* SB-RMI registers */ enum sbrmi_reg { - SBRMI_CTRL = 0x01, + SBRMI_REV = 0x00, + SBRMI_CTRL, SBRMI_STATUS, SBRMI_OUTBNDMSG0 = 0x30, SBRMI_OUTBNDMSG1, @@ -34,6 +35,7 @@ enum sbrmi_reg { SBRMI_INBNDMSG6, SBRMI_INBNDMSG7, SBRMI_SW_INTERRUPT, + SBRMI_THREAD128CS = 0x4b, }; /* @@ -56,6 +58,7 @@ struct sbrmi_data { struct mutex lock; u32 pwr_limit_max; u8 dev_static_addr; + u8 rev; }; int rmi_mailbox_xfer(struct sbrmi_data *data, struct apml_message *msg); diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h index 06e93a6a8f4b..21ea8c65daa6 100644 --- a/include/uapi/misc/amd-apml.h +++ b/include/uapi/misc/amd-apml.h @@ -7,10 +7,15 @@ #include +/* command ID to identify CPUID protocol */ +#define APML_CPUID 0x1000 /* These are byte indexes into data_in and data_out arrays */ #define RD_WR_DATA_INDEX 0 #define REG_OFF_INDEX 0 #define REG_VAL_INDEX 4 +#define THREAD_LOW_INDEX 4 +#define THREAD_HI_INDEX 5 +#define EXT_FUNC_INDEX 6 #define RD_FLAG_INDEX 7 #define MB_DATA_SIZE 4 @@ -18,27 +23,37 @@ struct apml_message { /* message ids: * Mailbox Messages: 0x0 ... 0x999 + * APML_CPUID: 0x1000 */ __u32 cmd; /* * 8 bit data for reg read, * 32 bit data in case of mailbox, + * up to 64 bit in case of cpuid */ union { + __u64 cpu_msr_out; __u32 mb_out[2]; __u8 reg_out[8]; } data_out; /* * [0]...[3] mailbox 32bit input + * cpuid, + * [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 * [7] read/write functionality */ union { + __u64 cpu_msr_in; __u32 mb_in[2]; __u8 reg_in[8]; } data_in; /* + * Status code is returned in case of CPUID access * Error code is returned in case of soft mailbox */ __u32 fw_ret_code; From patchwork Wed Jul 17 08:10:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13735204 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2040.outbound.protection.outlook.com [40.107.93.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4785A224E8; Wed, 17 Jul 2024 08:11:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203875; cv=fail; b=Zzwa2CEPptaCnCi+HLa7L07FdsjdKrMmx9RjzUha8zxv2aPOziSKOGafdtSBvj6OzdkIDIABwb5jG9m9AM4sm35RdZp1W/AHvhL8BuRtfTWuB6LXoWbRKDRB6gty82qr+2kBK0cShP89leQl2y1hbNT5UsNx/UXuVl99+8bpDLA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203875; c=relaxed/simple; bh=MdqBNc8j9NdnbkbtiXXCq9TCKug1ojLgITZCyWZUFl4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R4+6SpP6cSgJaNAUpIf4gBN9BO1ju8OvDeVjqwHBDeV8HzF5X0rDWNJ0MA+5nGutKFY6va9Mxl/DEY2d9AAkasg5DQPb3kA4FW9lSpB3UakhdjnBTSyqA0FXQ/qAyw4SwD53EoN9m8LGkPZuMGCTK8h+g8a8bfBiFWlnGIKXPRs= 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=wKP7GM38; arc=fail smtp.client-ip=40.107.93.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="wKP7GM38" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uSoUfe7wN1YFywj3JDRbiWhNNfOdA1Nn6xXIzIREoKkPTSPfgIaRoOxQTHSfjF45nPNjfYDyOpOl9zfrtyNkhsTEV4t2ihyKAavlA9C3Xd6ZQwXEbCeNbN9moF2lN6HSBSbfcIZT7n30zOCU/AxZ1XWy1hE1HfJI52KdxNPokUHV880G6n1W1XP87vzwnUnHW7aufX94NFZz0jQ5849xeC/1QyYYPyWiD0jxthYmFO0TBAgTuz2aL2YR6u9L98d9cHPLN6mloKveWEIJZBItKb2yBexVT7B5hxgu1xXHZBeHUF6cQYKs46ACelFEFBDMa7IX+Bk1udEMvOWdkZPp0w== 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=spchOJetAREOlHKyuf8iHakIbpzUNfpjXstPC2CQBdU=; b=i9XB0yNRz9uJC9MWKSXUeBxZ90haaaeQ3wmsd4Z5DYunqZ84AkeO+TUtuS2Zlq1pHK5BMSVO14/lZGtqf9XPjGMuEhVs1FeIDtAmSuPjs2ltr/HCu/xGkWwnZXnwVvnAy5R7xRb3nX5DXMmDprwvBwv0uxE7yZ5IUXCe1wUPYpyQR+4LvtBciq6sIfBQw49q2AVLaifYRloMvDOCqTnYQ2aKJwRJ67XlV+R58tU26syYt5iZuwTdH64+rNsQaye4IzRQ930gmwGEcHXNk9/39e3NmwgpQkGUxTO4x5vZvy2X0lJ4qXaYYIiWy3wzdixa1GIA0hUU46/wcvRowO/97A== 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=spchOJetAREOlHKyuf8iHakIbpzUNfpjXstPC2CQBdU=; b=wKP7GM38JGfNL5iH/eYlnCyAOFPb8cUm79emi5dMj8BKcHwO0e2kvqYsZatnvy+Lpc7ERgwixThPsnsvvva1nKCofoONJiSVc0eMoiqaLDLcCIUumpR5IzsCrFTIjjE9VFmh2Qgwvt7nUIL3puOx7p/b92CM6fF9oL297quWLic= Received: from DM6PR06CA0063.namprd06.prod.outlook.com (2603:10b6:5:54::40) by DS0PR12MB8341.namprd12.prod.outlook.com (2603:10b6:8:f8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.28; Wed, 17 Jul 2024 08:11:10 +0000 Received: from CH1PEPF0000A34C.namprd04.prod.outlook.com (2603:10b6:5:54:cafe::b7) by DM6PR06CA0063.outlook.office365.com (2603:10b6:5:54::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.29 via Frontend Transport; Wed, 17 Jul 2024 08:11:10 +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 CH1PEPF0000A34C.mail.protection.outlook.com (10.167.244.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7784.11 via Frontend Transport; Wed, 17 Jul 2024 08:11:10 +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; Wed, 17 Jul 2024 03:11:07 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v2 6/8] misc: amd-sbi: Add support for MCA register protocol Date: Wed, 17 Jul 2024 08:10:25 +0000 Message-ID: <20240717081027.2079549-7-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240717081027.2079549-1-akshay.gupta@amd.com> References: <20240717081027.2079549-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CH1PEPF0000A34C:EE_|DS0PR12MB8341:EE_ X-MS-Office365-Filtering-Correlation-Id: 733f0c79-c321-48c4-b3eb-08dca6380464 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: jg/9hMpfs02cmzpcOZLZ74GqBVUkwS5aoz1+WtG834n+XFLzFxVXjmeEwhN3sYoe1asDikB9eV3wefH0Ksv3CpXYCp8I2smldKt6y4qFuk4D41TOMpQcYiA1Apg/+aujQjvmNC4+XPT5wSY4J2eZQpiZH4ynKyQXbCaxLUp7o3ISuOg8/wD0RpT6VOr/Phds05A0N8EnK8ilGYkwzeTqg3meR2WJzCi1qF7n4UKWqW1K9hbXAeV3rSgHxkXQEzWvAeBcRBl2B+g4C3ALKnsXmifdpXY3v+b9McYpqnA+En9s5/OfR16rdvb8SEr0j8DTtB6QYyON2LRDzJNK8fpQpSumpcgLKrOpHP9NmD8nkiuowQqhXGwTJa0I03CGY3F45yYZA56YOJ6x8d5Zeagf1zunQ+vlnAqfxeQ0kNZue65QioFaT0Ojg82bahEPqDfsGsoSlQQNVw4jU39KvVm6kVifhlQnXvEXZk42FQEWAbKugsG+fTkY6elR1jQB5qNtp1pqTx/fL/FXYLizhticnhK6xt+Z2bLBc7QVli1vibWcwwHZVCEZwxPsSUJwHP9eaMxVa2fgA9J8B6um0TqWTiisxIeyYxV1BMzERAoYvFBbAPJkMOrpwUJ+TRHp75ZgOdcJUA7G7I/uCd106uHdHvTn/4PG6AWt5H8C0OKZsrQDw5b1eZSnHXaW8I4W3RTc7JmsxmcJr4sh0fByDyItfiUiECLlSxMvz+3WTXkYHTopZuqnOfdgtkORErNIWzfItBKEVB2IUvjLdi2rO1EModImCwdHatcgRspoqfn25kwZW++OnCgvWGNa7QkuH4YHdTm0i+f+gsOTekwGbvWQ+KTWUduv7EkEoRgKkVPh9fQfvCDU3cmB0uDkEWpRVlii4hK+4VHBaHJbiBEFOe28i+C5mKbqkQjFBJb+t94W6am9Ux50AnToYSZfIeK1ZzW4jWo6QsPk4lDdLrJgFREgVGQyVX5VgM+Hppb/980gwXJRVOGfnchl7vXpDrMpBJ+KAw0Buk80HI87pdcrJwr7XPGKhsT/vqzdC1E6wAm+CEAvouupRsIcWRWPaozfpWvH08BVsPN4SxzT7zotWz3AO0YURWt79YHVqkrogNXN0BbDoSmON8XtFr/hbk9vCUGlsc5CLzREpmPFi/x88OrYqGqBI3vIDeDAzTA1espK+xUhL4xGYmiehzWMj9ybiiPsFJMdiy4Yl8B5oDX0xhH80+SxA0LckChoJEzJMkUNyOp59CR6JwFoefm85Bpp7An1DFtpSpxg9OmkOpmeKHynmkGnLWt1+cPWvWtRRuWXxXvt4hpskBySaIrZIfNw9SVGRxmLOppbFQZHitn0fGsEFZk9i8eX3AkcZ0JMKshwdolHQkElC5+q26hmgZ41W0kNGpiTOeW2i3FUD81vhTjfFdcF1Zu/qks3OScxX4qRsOFU/mifbYBtOUKNo7d5V+/l X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2024 08:11:10.0918 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 733f0c79-c321-48c4-b3eb-08dca6380464 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: CH1PEPF0000A34C.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8341 - AMD provides custom protocol to read Machine Check Architecture(MCA) registers over sideband. The inforamtion is accessed for range of MCA registers by passing register address and thread ID to the protocol. Access is read-only Signed-off-by: Akshay Gupta Reviewed-by: Naveen Krishna Chatradhi --- Changes since v1: - bifurcated from previous patch 5 drivers/misc/amd-sbi/rmi-core.c | 90 +++++++++++++++++++++++++++++++++ include/uapi/misc/amd-apml.h | 17 ++++--- 2 files changed, 101 insertions(+), 6 deletions(-) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c index 57625bc1b4de..87bd2ffcbcc1 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -32,10 +32,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 /* CPUID MSR Command Ids */ #define CPUID_MCA_CMD 0x73 #define RD_CPUID_CMD 0x91 +#define RD_MCA_CMD 0x86 /* input for bulk write to CPUID protocol */ struct cpu_msr_indata { @@ -68,6 +74,13 @@ struct cpu_msr_outdata { input.value = func, \ input.ext = ext_func +#define prepare_mca_msr_input_message(input, thread_id, data_in) \ + input.rd_len = MSR_RD_DATA_LEN, \ + input.wr_len = MSR_WR_DATA_LEN, \ + input.proto_cmd = RD_MCA_CMD, \ + input.thread = thread_id << 1, \ + input.value = data_in + /* * For Mailbox command software alert status bit is set by firmware * to indicate command completion @@ -191,6 +204,79 @@ static int rmi_cpuid_read(struct sbrmi_data *data, return ret; } +/* MCA MSR protocol */ +static int rmi_mca_msr_read(struct sbrmi_data *data, + struct apml_message *msg) +{ + struct cpu_msr_outdata output = {0}; + struct cpu_msr_indata input = {0}; + int ret, val = 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 = sbrmi_get_rev(data); + if (ret < 0) + goto exit_unlock; + } + /* MCA MSR protocol for REV 0x10 is not supported*/ + if (data->rev == 0x10) { + ret = -EOPNOTSUPP; + goto exit_unlock; + } + + thread = msg->data_in.reg_in[THREAD_LOW_INDEX] | + msg->data_in.reg_in[THREAD_HI_INDEX] << 8; + + /* Thread > 127, Thread128 CS register, 1'b1 needs to be set to 1 */ + if (thread > 127) { + thread -= 128; + val = 1; + } + ret = regmap_write(data->regmap, SBRMI_THREAD128CS, val); + if (ret < 0) + goto exit_unlock; + + prepare_mca_msr_input_message(input, thread, + msg->data_in.mb_in[RD_WR_DATA_INDEX]); + + ret = regmap_bulk_write(data->regmap, CPUID_MCA_CMD, + &input, MSR_WR_REG_LEN); + if (ret < 0) + goto exit_unlock; + + ret = sbrmi_wait_status(data, &hw_status, HW_ALERT_MASK); + if (ret < 0) + goto exit_unlock; + + ret = regmap_bulk_read(data->regmap, CPUID_MCA_CMD, + &output, MSR_RD_REG_LEN); + if (ret < 0) + goto exit_unlock; + + ret = regmap_write(data->regmap, SBRMI_STATUS, + HW_ALERT_MASK); + if (ret < 0) + goto exit_unlock; + + if (output.num_bytes != MSR_RD_REG_LEN - 1) { + ret = -EMSGSIZE; + goto exit_unlock; + } + if (output.status) { + ret = -EPROTOTYPE; + msg->fw_ret_code = output.status; + goto exit_unlock; + } + msg->data_out.cpu_msr_out = output.value; + +exit_unlock: + mutex_unlock(&data->lock); + return ret; +} + int rmi_mailbox_xfer(struct sbrmi_data *data, struct apml_message *msg) { @@ -317,6 +403,10 @@ static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) case APML_CPUID: ret = rmi_cpuid_read(data, &msg); break; + case APML_MCA_MSR: + /* MCAMSR protocol */ + ret = rmi_mca_msr_read(data, &msg); + break; default: pr_err("Command:0x%x not recognized\n", msg.cmd); break; diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h index 21ea8c65daa6..3d536f2c8815 100644 --- a/include/uapi/misc/amd-apml.h +++ b/include/uapi/misc/amd-apml.h @@ -7,8 +7,11 @@ #include -/* command ID to identify CPUID protocol */ -#define APML_CPUID 0x1000 +enum apml_protocol { + APML_CPUID = 0x1000, + APML_MCA_MSR, +}; + /* These are byte indexes into data_in and data_out arrays */ #define RD_WR_DATA_INDEX 0 #define REG_OFF_INDEX 0 @@ -24,13 +27,14 @@ struct apml_message { /* message ids: * Mailbox Messages: 0x0 ... 0x999 * APML_CPUID: 0x1000 + * APML_MCA_MSR: 0x1001 */ __u32 cmd; /* * 8 bit data for reg read, * 32 bit data in case of mailbox, - * up to 64 bit in case of cpuid + * up to 64 bit in case of cpuid and mca msr */ union { __u64 cpu_msr_out; @@ -40,8 +44,9 @@ struct apml_message { /* * [0]...[3] mailbox 32bit input - * cpuid, - * [4][5] cpuid: thread + * cpuid & mca msr, + * [4][5] cpuid & mca msr: thread + * [4] rmi reg wr: value * [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 @@ -53,7 +58,7 @@ struct apml_message { __u8 reg_in[8]; } data_in; /* - * Status code is returned in case of CPUID access + * Status code is returned in case of CPUID/MCA access * Error code is returned in case of soft mailbox */ __u32 fw_ret_code; From patchwork Wed Jul 17 08:10:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13735205 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2052.outbound.protection.outlook.com [40.107.236.52]) (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 C59DE53E15; Wed, 17 Jul 2024 08:11:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203878; cv=fail; b=JWM8dOozN3rMganxqbfya71ngvwzR0Qidzdgbiu5vDH+R9OytxyRhBYYa46XEsEsSLCw7WvwofD/XePCB7qJeKeasMQFqHrXtAa72ofxopoVBOa+7qhGr1oBax0n+/ASmI4r5j9nt+k7xV0AMBFbIYf4teKjzYLhgKVyTozYPlc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203878; c=relaxed/simple; bh=wAtmzOsj2pzNP3lmh80KnAhOTOqx2d3HOjpB5UnRQWc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BIQ1Wv9XIuQWAOcsBaoJjST1K2bbMmH+ZMXjQ1ztvvH95G2Qy5aTYJpD538pH6tuSBDRuOWoeaoQjADjU5+z14FJMXeh8hR+1uv15glL1ksXXFvtb+4cwkkFFH1Cl/gM5epqr48EwnAGFKvhCGf5RGY7DY+s1KM2u1yg+7Euf1g= 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=SEVAhLcY; arc=fail smtp.client-ip=40.107.236.52 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="SEVAhLcY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=E3CFT21O9+xotkq42iu2BS4EY15T817S26ZsnvwMDJGvuU6BdDFs2VBPQ+8Mrf/uL8K94Ypk6Q3RNzMMcF1D6SwYfNbG4kYzNUkV6SKGVrKgXFedUJuwx8hZQTGoBV+XI3QuKvRC2m8Uv1pN/N3kc/KRMLWfDT0HqTFM/a6JT9dB0hL3lddZhxY8YomMGep5q+tGFFN1FRNzrz8NO2NxnhSHv3hGDVgxwXklwigdzeCltkqz4qSapViO+FLeCDPfKidCJEQ71FHEYKF8V5mNvn20wSZ1o60YEwWc4cCxfEfSOtehYdz8sK0EQGxgxgvYwzZqV4FS/JZoiJd/ZafjBg== 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=yoTT9s4dMPtmvhoRPiN9XWFX+RQTtI+IY3S7ygchNG8=; b=UFMyLCB07VBhECf0VHFL3oI3yLi5VtdxqeblGkEvL8yAE07146HqRlQhiLkUYxj9wLTVcHhLzqvOzT6h64cLY1w4KMXMf0Z+4MCO1q1HyTqsoxF9r6/JxJu6BITZGWnpJPoSMg6bdNdRZYKUSyEmqNs57mB/Os13csshGsIEFpRkevGdvdZIXvIchBvEl1anfArQBrXKNZup1LM3C4NObkIj3gP2w1PS1SdbdKDM5wSFWeAfdpQg5GgdvwInULjQ9et13T8NNT6hm8uNZA6QpvbqLlwYquWuJklg7LTpPjr24fvUn4H9ku0VUSOWp62sABFcfsoCrb6G+xK4apzS7Q== 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=yoTT9s4dMPtmvhoRPiN9XWFX+RQTtI+IY3S7ygchNG8=; b=SEVAhLcYwwKBsE2FrDzZmlDwlSy1Xbmk7DyZm37mtEPCkm2on7nt6P67zjWddiZHHYbzkuq8A/L7UvMvI3tZ997qLau+jKBRzQyobfsvVSpI8pYjhPQ2Q9np/c+riJRMbmJp0cEKyZJgUOF0tbObQzjgrLBV3RYSp8vy/Pdi/xE= Received: from CH2PR08CA0020.namprd08.prod.outlook.com (2603:10b6:610:5a::30) by MW6PR12MB8758.namprd12.prod.outlook.com (2603:10b6:303:23d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.17; Wed, 17 Jul 2024 08:11:14 +0000 Received: from CH1PEPF0000A349.namprd04.prod.outlook.com (2603:10b6:610:5a:cafe::80) by CH2PR08CA0020.outlook.office365.com (2603:10b6:610:5a::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.29 via Frontend Transport; Wed, 17 Jul 2024 08:11: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 CH1PEPF0000A349.mail.protection.outlook.com (10.167.244.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7784.11 via Frontend Transport; Wed, 17 Jul 2024 08:11: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; Wed, 17 Jul 2024 03:11:11 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v2 7/8] misc: amd-sbi: Add supoort for register xfer Date: Wed, 17 Jul 2024 08:10:26 +0000 Message-ID: <20240717081027.2079549-8-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240717081027.2079549-1-akshay.gupta@amd.com> References: <20240717081027.2079549-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CH1PEPF0000A349:EE_|MW6PR12MB8758:EE_ X-MS-Office365-Filtering-Correlation-Id: cf56067c-11bc-417e-9f9d-08dca638066f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: NDOZ1TrzZxICZyYW8TlenIVA6ceHrtACCOJ42HoIY6YmUphTZNhAmGJ9N6Q2fWIZGbGUH75VyJ820yqr6r6m2o9ysYmY44Fjai5Nk33aAPDSsIirsYiEvPj/+sXJ4cJ1yJuGWR3ty3NLpgthkm0HcOqwux78EwQCj3Dk+YLfG+2UWU/zEidBgI29gTDo5J5iTNc1x2vO4RL1r6EQlhTMYh1blJ+jY3jqPqzZyDjp+tztjpLr1pAwfuLfqqCtSO9kg1ZQMQ/0Er8nFgHjBunDmh3z8dvzGwa5abbxxSPnRT8B4uqWHEdFfZgDf28zDeXXpKiRmzGbKkTuBoHyBBtoglmQtdzhc8e+IZXz0uDsyH1mDO4Ent0ro2qHJvmy/kgF/sCeonqinKy/SMl9y7GvKayd+m1yDJ0FG7ZuySnd3A9qgKmNVeaDTVSnYPO1ibj27zqiyp3qeMgs9YjXztpixFCwqwdFC6rm6AjxT9P3iK4WCHbYc3ltpsuvxzwTNVt+RZU5kjcAG5TuK48BwMfYzXw2srvCXuQK7BpwJti0p3I6hq1We8r6Ovd0+LqoeTB1454tdrAdAMtpaQs+pkwx1Rdc5YTJpWC+ZvPMwYALOpohxILzjFlKlt4tzmdSyM8ABDbBzI1TZmAN3UwfBjYV3pkZ/U+oI9bTdjJ85eT/zB7WM1PBIG+alrJ32e43Q6xlqGOIsB3IAALAfUXqCBQ7gsU/3QfqV+So6uMu99CpUsxOsEPqUK9ZaYEg5vKpAVLgMnhudU3Ds2MlXWd6oGCL/wav0/8Gx9FvhUkgdzK/7ffnF7r/F4VrKzpPjvqNEyH1xzUzQ+s3YmB3PU7zDlIGbKSywKyIUoV4NNcsQJ7GTGos9H8go+cj3467jYEQyZr81jM5AmID0jMtjfR8sgQrxV0kLXFi2N8HjMwB2cmluYO7wHFRvPXnwBT68eqIoi0yKNx1qARScgTJ+3G4jf3oiiRBJRNws5TzQq5DAcREAst17Brtnmqn3Q3LL/gb7IyEDGHYr8vu1hm7VNdcnzDLPN7pxFpr8zxhxGijuES/JbkBvpDmB/X8Fm6m7/PyImTucMqoSh7sagOnWPmUETir31yAg+bmyG19vZ+ilA7tcso/HeUBpDAkTTzDUA9crTaVTlva2pg3xRphPqDnzICY1SXRNWCPDFnilCMJX9DC025KVfV3R5DrxX68TCMwHcIgKSmoRR1vcvf83PvfVtnbuQtTdY0yFo48Vfg8JGKBAMThKGFPyo82NzTl/M1rSxSJMNZ2JT+Na5y7K2mN+JnHgRoqwUCl8KLYy3pb8V2Fzua9Ya30JAZJrOCZIId/MDnICbwKgX53mCPmyG00OWKEEElpGb8EyHOpEapiOjiT0OdbP10mVqIyJvGEsNs356EQGVjR1VfwigsyZK4E7Jw/PpnY/AO12yCmBc8iMl8viB+pmru9is50UJTJKSZRRiDq X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2024 08:11:13.5032 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cf56067c-11bc-417e-9f9d-08dca638066f 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: CH1PEPF0000A349.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8758 - Provide user register access over IOCTL. Both register read and write are supported. - APML interface does not provide a syncronysation 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. Signed-off-by: Akshay Gupta Reviewed-by: Naveen Krishna Chatradhi --- Changes since v1: - bifurcated from previous patch 5 drivers/misc/amd-sbi/rmi-core.c | 22 ++++++++++++++++++++++ include/uapi/misc/amd-apml.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c index 87bd2ffcbcc1..da223e47d5df 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -374,6 +374,24 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, return ret; } +static int rmi_register_xfer(struct sbrmi_data *data, + struct apml_message *msg) +{ + int ret; + + mutex_lock(&data->lock); + if (msg->data_in.reg_in[RD_FLAG_INDEX]) + ret = regmap_read(data->regmap, + msg->data_in.reg_in[REG_OFF_INDEX], + &msg->data_out.mb_out[RD_WR_DATA_INDEX]); + else + ret = regmap_write(data->regmap, + msg->data_in.reg_in[REG_OFF_INDEX], + msg->data_in.reg_in[REG_VAL_INDEX]); + mutex_unlock(&data->lock); + return ret; +} + static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) { int __user *arguser = (int __user *)arg; @@ -407,6 +425,10 @@ static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) /* MCAMSR protocol */ ret = rmi_mca_msr_read(data, &msg); break; + case APML_REG: + /* REG R/W */ + ret = rmi_register_xfer(data, &msg); + break; default: pr_err("Command:0x%x not recognized\n", msg.cmd); break; diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h index 3d536f2c8815..6d74f4ffba10 100644 --- a/include/uapi/misc/amd-apml.h +++ b/include/uapi/misc/amd-apml.h @@ -10,6 +10,7 @@ enum apml_protocol { APML_CPUID = 0x1000, APML_MCA_MSR, + APML_REG, }; /* These are byte indexes into data_in and data_out arrays */ @@ -28,6 +29,7 @@ struct apml_message { * Mailbox Messages: 0x0 ... 0x999 * APML_CPUID: 0x1000 * APML_MCA_MSR: 0x1001 + * APML_REG: 0x1002 */ __u32 cmd; @@ -45,6 +47,7 @@ struct apml_message { /* * [0]...[3] mailbox 32bit input * cpuid & mca msr, + * rmi rd/wr: reg_offset * [4][5] cpuid & mca msr: thread * [4] rmi reg wr: value * [6] cpuid: ext function & read eax/ebx or ecx/edx From patchwork Wed Jul 17 08:10:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13735206 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2067.outbound.protection.outlook.com [40.107.212.67]) (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 F407C3839C; Wed, 17 Jul 2024 08:11:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203884; cv=fail; b=YvoBXyP/Ab95zi4g4ABZwpAtsCswyq+AnIWZmR6X2HCqQE0NNJSuhMzi/7WUthYmvwC6HC0civD5G57SCIdTgzyqeRTBlRz0kPb6FyvI9rw1HemP/VHY4EdvcphJUrk8dyqP+i+oHJlM5dFzauxlUwpYnLzF1/plLJ+5ps31P20= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721203884; c=relaxed/simple; bh=wzCAFswBd3naz7BS1OAajEC09T8XHis76wfenGeVN3k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hlwGiyDYMxhYXP+faDBlu7tzjHoh8RR37/6I5C4uYiNbvDYkhmut0HTdiaM63Xw7g4jw2eJVlYDpKgsuHXeThUZ1JG1vC0SVePFxo87RmkyxemJDj19b5W9FJT9axjSl/3G6T9iN4OeCRtv8AJDmYlyhcjA8wBJ2R4WRK29KTnc= 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=td5bFvgO; arc=fail smtp.client-ip=40.107.212.67 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="td5bFvgO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Fh/lfcEWKq6ONVEQk8BVTJp/ZI1WR2+RnD/yrs7mmrsKFPaqmzlVoPnLRzfan+w7Af4dzIvJrwPaxFS5zk4BhPzCl+09adKscPKer2hA8gTJ+hJW8dJpEvazLx1qHsZczy1vM2n6Zq+FOShH71SD86aZaH57o3gWXg+hWK3sVaN6WqZz5HQ3A8X67VTi6DSFYcLIsqq4de2PaaEXw44CsBSS/Hhr8lufk9qfmwJLMrsk4NN2c4eEUTjW4RbUEkP/Br9yqgDLUS3ygtTFXfA28hIlOh3U+tixjqouOZFXYo4LtctT734yJWzBCJXT9K5zUMom7iPS0y5KcDDkGiZ7iA== 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=DhLMxzM895EPttDLcr2whw/QtkidYrknO5Y2M2kty44=; b=aPXtNHvRrJ1VzYeQzv+k3mLQvYaMWnL+KIa6Ct4kvVk9O6bMC4sxdM+9ZpZ4F17rqRh1K503ix2qm8Y6e7aSMEGDo1SF55fJHYNwUl11Q/Wji+Q0W/4XlX5FH9YwSiL/7HWvvOQjNY9/UUfjaQnoOav1sqPT89uobvLj30+AxHrS9nfHQ1A3CJmSle7rAK/EvB/DRuqM2y0sT6bvF+wgpVyQjAhhYy6aP7txCIbtBNGPL7uvUMOgWki4i+TOFLR345vES7ahqsbUgEzABThWNdqRr6tsdBaMoav8SwheHL5v3k8xBq382csyGRpV7MlH9RIzUEhI5Wp2PPlrGNW4KQ== 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=DhLMxzM895EPttDLcr2whw/QtkidYrknO5Y2M2kty44=; b=td5bFvgOavuS021S/19qHZgUkikXHrIYf/aMAcmt6I1buj6fLMfgg5y+mYmMaKlGZut3DcZOZIwN1m3GW33V4bBIdjc4RfZqOzxrVcakP7561FtihdxzW3WiVypDSmwq7p9CA64YN38IoYAlWO+nf1+/drRSxv7Gi85H/8D+K44= Received: from DS7PR06CA0001.namprd06.prod.outlook.com (2603:10b6:8:2a::12) by DS0PR12MB7995.namprd12.prod.outlook.com (2603:10b6:8:14e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16; Wed, 17 Jul 2024 08:11:18 +0000 Received: from CH1PEPF0000A345.namprd04.prod.outlook.com (2603:10b6:8:2a:cafe::f0) by DS7PR06CA0001.outlook.office365.com (2603:10b6:8:2a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.29 via Frontend Transport; Wed, 17 Jul 2024 08:11: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 CH1PEPF0000A345.mail.protection.outlook.com (10.167.244.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7784.11 via Frontend Transport; Wed, 17 Jul 2024 08:11: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; Wed, 17 Jul 2024 03:11:15 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v2 8/8] misc: amd-sbi: Add document for AMD SB IOCTL description Date: Wed, 17 Jul 2024 08:10:27 +0000 Message-ID: <20240717081027.2079549-9-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240717081027.2079549-1-akshay.gupta@amd.com> References: <20240717081027.2079549-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CH1PEPF0000A345:EE_|DS0PR12MB7995:EE_ X-MS-Office365-Filtering-Correlation-Id: 012c7578-fa69-4885-314e-08dca6380901 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014; X-Microsoft-Antispam-Message-Info: IkZyte74prQXvEcsMimEe5w2M1WzzRT+GtXDYvGPqfkcMyYNtQJk1YkyDV2CX/rLo5mchMEWFh9Wz/LB9/YOvZD+9pNlHnXa4qlk2+4NqE4koyjs4d0U+2iWXQcAEDo6EygK4sOVUQYlDTltEvQfHUhsuOWOGnCaw3uV87G0Ft4gLBFCcwkLyC83EjsbvT6yYkWbhNv75HEKFn3jQ0RxXt6S8Me6gK3Rm9sXqYOZ5AckAEK8udzbiLBEsXJLx4ovcRGsnzRafrMK5RJu1JZdKGiFn44VRYSioFpE/cRyX9Sh16Q+1KmXYA7CtL69eqQAVqB1TE0zA0138wJptCBoMu9ZyXF2ntX3yUsPzPet4x2KuimMSGjTZ8xP+RH+idCS3YPrHy9Fi7bENz/17SBiZH6eucwAPZgGJvfYQx1S7Y1Qy/NtS2QlXEeOYs1+zmFovS8allumWix+WceUvtnnjsmAHluu1CS43DT1DDDHTvgC2rbbl+9OAyLzI3Iy9Pq7OQdjkYeo/Ceg03F+0BCWkR+/1dbU1eh14fWxa4gz4rdnvBkd65G22XilfzZsFZ5Z8GSqpVPNPeZ443F9NuKZum4rC+YAWNQrQesv4SA7tdbLH0AquB7uKAZ0Rli82bzCW3/uYM2eqSLRlOG5kthSVOZQ12fh5N4EKTbWqc1s+N/eYqop87/W5ifz7HVKAj878ZRWAIbjYtODiwZ1CXO3PGEbIZD6Y2bb/oMAzg5s4hsjsN3Tq8xx/uQiE8n0xmjnhKUA+edOzLVyomcFI8m46jS9ElgyuieogFeFlf3IasGe3GsIDH18oPTj3rp+QBVY1A8VcBzfhkLY7y2PpJdDB/JsgPFFn1jIQAVVxLc60O5nPfthEO9Tae6xiMPj/aLYqJMhahHm5sdXiFHNiSfTs7UJrLRUxlIisC7vHBrAtGq/oiUgGTvNbsdMpOMrXLdeIgwss97fT4q40VK86N8P05XjB0vFjkZNPyMtVePz8OB2TykilZ3/vBJuA/W7QQeVtfcCcCZhNmE2Ga3CwN8aVFbGk8xDzqok26NJ5zJMBVQSVro8f9vo8qH3SPFN0F+5XoZFQe0ULskfajh+Fk+nQTLiRr2Zu15ok140wuM+2icyeoCcEOnYGs2d+UgoikSH5slGeI52EWa6qtlrKefzbIfRiFbHTM0F7F4/Zg1OPkP37qbqfMJO0u/gUGxwYodkZ+hq1l9mTuGORrB/kGTKsN1RN9+CK4+wgcA9JontgXoyRi5hmBtuzoipr9L/xhrPacvmFOHtzYu4KslfxytY20VMoBdxOYYFq4/7TJ78FVWhWabLeHm4bYobIV3ap1tL7JLMiqj2JtYgr0ADPE6unIfhKua4fR08uJHXd1e78Sc4JHbRZtBca9qBfCpOo4XE/k2BeQ7fEY6xAygdVP2ztA== 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)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2024 08:11:17.8282 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 012c7578-fa69-4885-314e-08dca6380901 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: CH1PEPF0000A345.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7995 - This document provide 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 linking against the esmi_oob_library, which is provided by the E-SMS project https://www.amd.com/en/developer/e-sms.html. See: https://github.com/amd/esmi_oob_library Signed-off-by: Akshay Gupta Reviewed-by: Naveen Krishna Chatradhi --- Changes since v1: - New patch Documentation/misc-devices/amd-sbi.rst | 121 +++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 Documentation/misc-devices/amd-sbi.rst diff --git a/Documentation/misc-devices/amd-sbi.rst b/Documentation/misc-devices/amd-sbi.rst new file mode 100644 index 000000000000..16c9e9ace816 --- /dev/null +++ b/Documentation/misc-devices/amd-sbi.rst @@ -0,0 +1,121 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================= +AMD SIDE BAND interface +======================= + +AMD server line of 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 +Eg: https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/programmer-references/55898_B1_pub_0_50.zip + + +SBRMI device +============ + +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 synchronization +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: + * message ids are defined to run differnet xfer protocols: + * Mailbox: 0x0 ... 0x999 + * CPUID: 0x1000 + * MCA_MSR: 0x1001 + * Register xfer: 0x1002 + +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. + +User-space usage +================ + +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 = open("/dev/sbrmi-*", O_RDWR); + if (file < 0) { + /* ERROR HANDLING; you can check errno to see what went wrong */ + exit(1); + } + +The following IOCTL is defined: + +``#define AMD_SB_BASE_IOCTL_NR 0xF9`` +``#define AMD_SB_IOCTL_CMD _IOWR(AMD_SB_BASE_IOCTL_NR, 0, struct apml_message)`` + +Data structure:: + struct apml_message { + /* message ids: + * Mailbox Messages: 0x0 ... 0x999 + * APML_CPUID: 0x1000 + * APML_MCA_MSR: 0x1001 + * APML_REG: 0x1002 + */ + __u32 cmd; + /* + * 8 bit data for reg read, + * 32 bit data in case of mailbox, + * up to 64 bit in case of cpuid and mca msr + */ + union { + __u64 cpu_msr_out; + __u32 mb_out[2]; + __u8 reg_out[8]; + } data_out; + /* + * [0]...[3] mailbox 32bit input + * cpuid & mca msr, + * rmi rd/wr: reg_offset + * [4][5] cpuid & mca msr: thread + * [4] rmi reg wr: value + * [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 + * [7] read/write functionality + */ + union { + __u64 cpu_msr_in; + __u32 mb_in[2]; + __u8 reg_in[8]; + } data_in; + /* + * Status code is returned in case of CPUID/MCA access + * Error code is returned in case of soft mailbox + */ + __u32 fw_ret_code; + } __attribute__((packed)); + +The ioctl would return a non-zero on failure; user can read errno to see +what happened. The transaction returns 0 on success. + +User space C-APIs are made available by linking against the esmi_oob_library, +which is provided by the E-SMS project https://www.amd.com/en/developer/e-sms.html. +See: https://github.com/amd/esmi_oob_library