From patchwork Wed Aug 14 09:59:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13763210 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2050.outbound.protection.outlook.com [40.107.223.50]) (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 464A51AD9C8; Wed, 14 Aug 2024 10:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629634; cv=fail; b=jwHff/hxqAB/5aCzmgnilxZJcLt03UwK/jnNgaEqRvAOQ4F5csHY9xxXJoR2zvSvngkHOa6d6CCoAR9ss1OGQ9pl0kPAr+ApqihpU/FMmzo73PNxEwLLN1gjIo1X6VV1tMZHIXcSPn+T6rl535rFp6W2PVvE7gcgDo89zXB7m38= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629634; c=relaxed/simple; bh=wustc/l8vYYXD769t7HhzQv4OF8jQerjsMFNEoiMbi8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oAaBHHpzT8Ro1f6AfdiTtpYv6x7SXN24BktSzXQNuzzQQ/CnsBoxcO/ceJtY3zHlmQCscVWIr4Aq2j9L137dY7RfzOItwTu7XKxjWo2Q7jvhVRHrvrbapTQiAYFtgrEibRatr2QWiRH45ygmK2iNv6LmRPQE7gGAKBQbYWsM7Oc= 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=fR+iP5fi; arc=fail smtp.client-ip=40.107.223.50 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="fR+iP5fi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BaZQOD7Q+ZHy/sNByCf+r1BdhkqMiVZsZl+22NbxePEVpPtZk4FqyVciuSb2oxPviICWDTsSAppf6RVsysiHHXuWLwyVvFGgi+DojFrEggY3l1TENAu7bI7l9WuIDiN0cKEY/l4evKly5LCqNYKLXAL5Nk6oCtdPJjriorj8cD3vngLpw30WnjonOkJ39Is3o3HSRsk2Q+Ktt43JxtoSJ+U2O0kLFunwUjEtrPGYW+P0P54Wxb3j6eR9tON8AujzqV8vDBNioLftY5/6lWnW9RZhldrVjKH+og3q95FiTsSHoi9/4bQ462VTXw6c/eHPXna0nv5qKzORCtlxdH4uEg== 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=glXmd0dS6gDHYKexD1/NobGNX3r1KqnnkIkJaSDTbJ4=; b=EpYSOMsfRm5bUI1bYQC0e7WZqm7+Pyct9uy7t7DUYs7QlmY6+dlB7AoL7PJQg+YwSZAd6x8JuzDK33YSU+o8H5rADxrhpShf6UfJ9xeH7U9nHHM7bWgGzw7jGe1aThBpXGZFheXdPOSoRht9DnYoT7vZmavg9DwmIkTenazvUZILDs2vpZZ+PJ0T65xSxxDRa9ZnAZzfG7rE2IflPlboMrsps16BQzvTy01p+/DmNnsHjR3ln/IR4kM3BYoVETb4rtQ5mOE1oRtNGqbyMzLeSG0cORlv2UuKWPDbgMuD3RYE0NE7Eo/WeeYz+wox5vi+sdLqN923RMm5Zvs1BCHANg== 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=glXmd0dS6gDHYKexD1/NobGNX3r1KqnnkIkJaSDTbJ4=; b=fR+iP5fiNWdoA957wfjozVwKjHGcdbrHcNtFHRfEJNvxigAXqAAHwdMKkZYw/FW+Vri+fIXX6EYZw6AGd/Zb3oRfzP2SXkFQzXdGleystwMDBO8gOjXBNRubsJ6Cr8n3Wjgvt8sPbv1pDM04BTmgwEl2+dCPtKMc9z2BLuLy8Sw= Received: from CH5PR05CA0023.namprd05.prod.outlook.com (2603:10b6:610:1f0::25) by IA1PR12MB8519.namprd12.prod.outlook.com (2603:10b6:208:44c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22; Wed, 14 Aug 2024 10:00:25 +0000 Received: from CH2PEPF00000141.namprd02.prod.outlook.com (2603:10b6:610:1f0:cafe::64) by CH5PR05CA0023.outlook.office365.com (2603:10b6:610:1f0::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.18 via Frontend Transport; Wed, 14 Aug 2024 10:00:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CH2PEPF00000141.mail.protection.outlook.com (10.167.244.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7849.8 via Frontend Transport; Wed, 14 Aug 2024 10:00:25 +0000 Received: from amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 14 Aug 2024 05:00:20 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v3 1/8] hwmon/misc: amd-sbi: Move core sbrmi from hwmon to misc Date: Wed, 14 Aug 2024 09:59:46 +0000 Message-ID: <20240814095954.2359863-2-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240814095954.2359863-1-akshay.gupta@amd.com> References: <20240814095954.2359863-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: CH2PEPF00000141:EE_|IA1PR12MB8519:EE_ X-MS-Office365-Filtering-Correlation-Id: 58fed0ba-a573-4d14-7716-08dcbc47eb06 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: 5Ol4vjHY5AqOQm7au7jyeAQOneL5gzbZOP4vqLqbvb1K3gRMaI7bGb8ePWqUHfgob92cGZzQt1NoEGEM8XaWD9m9UElD4gOthRgwt/TXxBV7Bqsf7+ToJvoY4NMrMorXMbaha852sLadbviUWGftOsKR5bCZhWcyWD6Pdc9m1NBXJ2657JQa3k8P7ctl+5Tmfk0tzXgfvWr+S3aNkvC2NaZtaEgE6OCeR5rrJVoEohLENFWyoicDZPqmxNp8LPNVdnbyiN8AP1JCdswiz0AcWCeS6jrI3lZahS8Mg8/1YNh5q2vvONZBE//thN3yIowbyhi917Q1dePTZAk7oc7Euw0QDjBI4MoXXcVZ6MaGlV+ycL2ohw6OfypjnIQpwsOyrD/5J0ZYFwpsmsDdtbasE6K4ksAM6Z4Nqno40VY4ezMzoQ8Wwqri2UHt6UcYc+OGJhn+ddLEE8/skH9Io/wdcSJnIndMwbTi23m8KOTKUZCX6CTAFW03lA4Y0k9vfgZN5ijOsLKcggig9RBSOZESs3nrTKDdD4n55gr4wOoX12L0+aQzj0/fFbRrsb7Gbj5Fa/rRGfsoyeY3hrGHmi8QWPltggvSJnu929Zk90bBFTvre7U815zkrzEZvDeweKNr9yWeOxtYRXupzAv2Wp/6aXrWyIIGvM8SfuAmsvbserfyucNzdQkiZ8im0NMu/v+GmE5aoC+7Ep5y5hKk413puiHMupgGYJYDZPsbr6Vl4HsnBMTzV1lTVXsSpombIqY/ 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)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2024 10:00:25.0599 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 58fed0ba-a573-4d14-7716-08dcbc47eb06 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: CH2PEPF00000141.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8519 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 Acked-by: Guenter Roeck --- Changes since v2: Rebase the patch Changes since v1: - File name update - Add hwmon sensor registration in this patch - Update Copyright year drivers/hwmon/Kconfig | 10 - drivers/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 b60fe2e58ad6..20bd7126362c 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1823,16 +1823,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 41c3d2821a78..add70bc22fee 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -618,4 +618,5 @@ source "drivers/misc/uacce/Kconfig" source "drivers/misc/pvpanic/Kconfig" source "drivers/misc/mchp_pci1xxxx/Kconfig" source "drivers/misc/keba/Kconfig" +source "drivers/misc/amd-sbi/Kconfig" endmenu diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index c2f990862d2b..5e70d2b34a11 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -71,3 +71,4 @@ obj-$(CONFIG_TPS6594_PFSM) += tps6594-pfsm.o obj-$(CONFIG_NSM) += nsm.o obj-$(CONFIG_MARVELL_CN10K_DPI) += mrvl_cn10k_dpi.o obj-y += keba/ +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 Aug 14 09:59:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13763211 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2085.outbound.protection.outlook.com [40.107.236.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF7E01AD9D0; Wed, 14 Aug 2024 10:00:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629636; cv=fail; b=HtlCIrbiEDkGYOKEV2hMGoKyfVMcn5GzuSErxO+yqfIiUscUUiFRhRvyxv7n+/KueMoPYcELCGnhAuYqx2r1cscr4x866FaL0Blu7nShaM5DAKIL44FFReJGpttuTNubFEvvLuDyWM0cAKorvs2Z6ZEbY8940hk1BbTvuNN9jNU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629636; c=relaxed/simple; bh=sGt9Qs4F1MJhqdQHyyzsE8tmK+KWohya7fEfI/KfLUE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tQpZxvelH1h30V+rf9Xwm7TnsauBnWf4IR0LZ0Qd/GgUO6nfdUfOunqIUyUTHyX/eOBBzh9eZwvWY9DJ/jXSZn34TjC/Dr05i+u4iAtUbZEplspNyuLuQw+udAYAQUjjK11uSpdIgJpKR9dhWAweIWxLneqKDqbmAaaUtnHVUS8= 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=W3igQmYO; arc=fail smtp.client-ip=40.107.236.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="W3igQmYO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GCf7xwSwe/Q+fnJHW6sWRFqNSpSaFTZmZMIKVSzHggtkfEVb32oX3nJO9zSQNswppCjtR0yaZgxSdTnravADjRwSrsH3GfsotV+aHs3vonsMgDq8/QcdovGCPYPosF3/jMeNypnJknuzJi3w5JPSkhxrZ1BBkXiWORNhYFBQNpRg9ysSXaZF4aqenJWC3LYZ/YUAnB2SRBX8FZBDZIuTnHIX3FjtR1tj938K4qjI1yqbol4qd5CWwtl+EPfjqxMuPmB7XnYq9J8NZ23wcoS9ivttMz9yaHkw2CZ2A6TxUWa5tQe+XgpBY0+cXVKjqLdp4z/KyWAT7qBLSqpn6uK5PQ== 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=fYeeNiCor1bR/r6+90Xf/glmMWBHzJBHFQ+ARzN1kQrzZJlYGcUpgli0a+1KxEmM323x6ucaJ+cLdWhxSYmeGOn+PUiL/fTn7VcLCILtO8YgwhJFBQDXLG0xxUm5xdkDI7pOcFKNGmZOp5JDmTpTU7XqJMjMit8BHwxaVAPOEY2sTbRxwaBtntp/L68lEgbVhvT5CnXa82Qszx6Du8GB6CHa4joXoMNYRW0nfPsw+kebn/A+HK95k9c7deBSgZ9CJbfveL8/ZDUzlZLwB5fq3Snx+fv5alocvZCnj2ZoTRtbGfr4aVkVY5VKFNFQGN1i5Mt6XAftsS1i+zqwDmWC4Q== 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=W3igQmYOFTgZTTAmyow3To/MP3BeAvSWD2aFILrQWlXsiuAHEwIMycQ1jhnBurit9k8znX1P9nMQgM2AXsI5TsXgqUtZvsfp4iEAb3UC4V5+EMD8vwUR4mytxi6UMgbia4aC7gzqKA93Fh4lZfIC1EXuQe13SG9IzKnOrPl6AAs= Received: from CH5PR05CA0020.namprd05.prod.outlook.com (2603:10b6:610:1f0::13) by SJ2PR12MB8034.namprd12.prod.outlook.com (2603:10b6:a03:4cb::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22; Wed, 14 Aug 2024 10:00:29 +0000 Received: from CH2PEPF00000141.namprd02.prod.outlook.com (2603:10b6:610:1f0:cafe::db) by CH5PR05CA0020.outlook.office365.com (2603:10b6:610:1f0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.16 via Frontend Transport; Wed, 14 Aug 2024 10:00:28 +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 CH2PEPF00000141.mail.protection.outlook.com (10.167.244.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7849.8 via Frontend Transport; Wed, 14 Aug 2024 10:00:28 +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, 14 Aug 2024 05:00:24 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v3 2/8] misc: amd-sbi: Use regmap subsystem Date: Wed, 14 Aug 2024 09:59:47 +0000 Message-ID: <20240814095954.2359863-3-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240814095954.2359863-1-akshay.gupta@amd.com> References: <20240814095954.2359863-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: CH2PEPF00000141:EE_|SJ2PR12MB8034:EE_ X-MS-Office365-Filtering-Correlation-Id: e27dce89-33c3-41cf-c07f-08dcbc47ed17 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|1800799024; X-Microsoft-Antispam-Message-Info: 8CMrTg4zNkPdATdEf8ygMY0qY2aKbEDQqiDtAfl0A6Rkgp1/MhMrR/H7NtYLZo8Xpr6aFh4cXQZs3eUFgkJB8hQIgmm7RdglVIGGgk9LtLYtauD3FkQGtkpFrXFzLD8vQFwS2PvA60NvPqKqzvis7sfElnUKwWU1eOnbRW+05RHDVKQR0+z4t/DrYbYIRB/b0VcZdRs6s4SWFqZhPKTxeZdllNdL1wMdQLZe4Dhli8Hlb6tA2ctT6wC6chbY/LfursdRCRqeJtDZ8/LHyLlDY1tLj3/Mc/kcB9rALk7ZUowcXnffzWEYwv9FGUwnH5KTXLdysvr2SJ+rLv8KfCRMIYCTsm9OOBd8I+YFSielNBAlmrXzFNAQr8B5VXV8DZMPvT9WJwvgxLQ+oZJ2cjCivTQrCFPzzzId2oTTI8h3V+y00eT3Rzq1c6a8qvGVYgoOxXb1CNmqegxtM0K1FCuw1e9b7ApEmnYwDjHP/EcLrnbfhXU1q6Wnp8qTnIzk6yU0DOst2H1M7QXU6pzcmZQQkss1PsB4ujPcRGtWG8sMDWpNooG1uMduXGbRuIokrMQniRl1hOKNoJMH3h/mFAJB/PXNmi1+CFiP4Ru9FwlHEed14hwAsDNOyxYjr6RSBsArdkQWcHDEqF1BXmpzsZZ0dJpwu0Likk3piFYCsx2toFEP5UrSQ6CAVQO9M7ga51b7rjyBli4KrjomV+Hque5NMw5o8J1cnPhmk47QiFd+tRg6pzGU1TdJE5BwSpvUc7y0 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2024 10:00:28.5287 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e27dce89-33c3-41cf-c07f-08dcbc47ed17 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: CH2PEPF00000141.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8034 - 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 Aug 14 09:59:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13763212 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2053.outbound.protection.outlook.com [40.107.94.53]) (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 47E781AD9F2; Wed, 14 Aug 2024 10:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629639; cv=fail; b=upvEw0VE9V4laSk95gp85//tr3tmnA/kSBGHKYsHnPtv5a7Pg/dPKV+Ru6fWAj8mI9FEdmpwpwImkHeCvS+XXD+GqLQ9gxSkHoWGR4FYSVKNKd6fIb8bVp/rCxcVJkGix71dEDx5tLztfKePb57rj0q8uraXgOxd6fWFN6eUDvY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629639; c=relaxed/simple; bh=HGHCTZe35h1oHsEN3Hnvb4qtyZ/1Bh+9PGWanej5nJ0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uAR4Df+1Agqc5oh6QwheiOwAn6FWzNqaCkJS9UjSEdwx15wSk2yOA4HZsB5miARsaLU0zdy+jVyKWt4tIC3HRT4WdWvwCGvCv4RwL8KNPk9Fe1yoQWLWE7w5SRuXUwbH9yRIPoC1YyprwtJMgp7PE6FHECdLStuWH2XMVun5NuY= 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=irsmJO+z; arc=fail smtp.client-ip=40.107.94.53 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="irsmJO+z" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QHfwrsNZDrUVEumqDaui22VLbVruSz/Eg5C4k6lSL+LxZMTrNW++cN7muBYTGfmTBFv0h1Zd+gNvlQ8D38Fl6kKKHpe0tM2fQtggggLFlaEz8R3Pp1xTKidGvuXVTDYgIMYqRhjLezCketwzQpVxWFqr1MiUU+F05L69tISFztctGi1gXHZF7ESjAhthRepKXL8c9rxkK2adUtmq0Za1ZpTm7yLIQIAvmcs/VV/0+EQduF7QFWpPsYvZUlGmroxjHqHlRQu+Il6EAqdOSZaHOyfNb/3UjNb1D1TbKJviBPL2FRROSyMge1AZKBdyK7os2yE6Hdrp+oa37dly+bl/Xw== 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=Q/0/w3II1iOIpl5DB1ApvNmZj1Panp3zXCUseA7KvHU=; b=laNsja83MNSwknnOpxyJwtT9tzjuBoVzZ6PLUTue6XwuVDv8FE2Yt6RzrrQjW6qFXCGJXrz2+koTf8ROzxv74QsbUPNtaepWsb2qEHC4jeYfeUnemcazRTkj2+fWORi9bTgLXjnzhJGWoguy4pxEm7XtaPd8/yxfUeAt4uFuMxliEewqFsIGcPqp3MBYMNHDzdgb7g6v09Kdxy2NNis1vRuhteqNurDo0lp1oaIyDIeuh4s/SV0G7Qy7YkEvUsf7JjVMQbINuiz1DUOIZ17PL7Mz5DwhFtlDDIPxKotMiTXgF6cxGxf2icCIvQAewxOPffhlkG9GgKpJ3lHNNF/VMw== 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=Q/0/w3II1iOIpl5DB1ApvNmZj1Panp3zXCUseA7KvHU=; b=irsmJO+zpqXbymK3J91MoyU6lWGggK6Nt6E2wVGaoWUcan9RoHmdEbHm4pYiCvdKtvI/vgSccV96eg7c8PUj24rvK+st/alko7n+bhQkaMuaP5oDjYilTvNW/+jo0zSWRxof2nEoeLRRIE0uh6gl2AmZ336PrTBkIYZ+NSE5M4M= Received: from CH5PR05CA0017.namprd05.prod.outlook.com (2603:10b6:610:1f0::7) by MN0PR12MB5764.namprd12.prod.outlook.com (2603:10b6:208:377::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.23; Wed, 14 Aug 2024 10:00:31 +0000 Received: from CH2PEPF00000141.namprd02.prod.outlook.com (2603:10b6:610:1f0:cafe::6e) by CH5PR05CA0017.outlook.office365.com (2603:10b6:610:1f0::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.17 via Frontend Transport; Wed, 14 Aug 2024 10:00:31 +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 CH2PEPF00000141.mail.protection.outlook.com (10.167.244.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7849.8 via Frontend Transport; Wed, 14 Aug 2024 10:00:31 +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, 14 Aug 2024 05:00:27 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v3 3/8] misc: amd-sbi: Add support for AMD_SBI IOCTL Date: Wed, 14 Aug 2024 09:59:48 +0000 Message-ID: <20240814095954.2359863-4-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240814095954.2359863-1-akshay.gupta@amd.com> References: <20240814095954.2359863-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: CH2PEPF00000141:EE_|MN0PR12MB5764:EE_ X-MS-Office365-Filtering-Correlation-Id: 75685492-8ce9-4b90-6e28-08dcbc47ef0c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: OvXADMlXfYg8FteYHPjjGkK0oqq3ahrkOunXdD0BqE45c+4VNrl1gcABRMjbghIIAHMchoZu23urmW2e6W5fx48nvRMwFKSn1QlqAb/2Op6crcAW8my+cePHhNTq51uvwFmGoaf9CTCCzjGssDkehf0rNbHkcmulUBf8ruLWiNdNis1C8Sa5A/eOQdAweK30Y1Wkqh7wq7X6bBNZ4szfaofPKgKh5XRxj/icshRRmP7aw4rKhVhRyBW9JJ9PrkObNx7xr771zrDibNXJJK0OKLiNiyuhU/mp+093OZBF1+W38byN5EosJTraqgqq/CfLaCX/Fm1e4F5yiEvtY08EJi4q7mR3LFS3c/DRvWl9nWQuSol/gj4rSAG+Om078Ivie0an92CCTO8AThdj4CyuVJ9SOm11pmtvm2ROsjb+X2WPnIxH11y6RaJV5iDiIseC/nN64mT3B0A4WE2WsXQNqNyCmAOi3pzOlG8eicQJwcbgzOV5OCgMHZjcCtS7AaYbcAxyFJDBD4wnGufihjkBL9EtaQaDNgOIaKosEnXAOGFIlOboYIWolGK4KUeX4bNwVYRpDK8wxvafcOnPzwL/icXUuPzWmzBeNgE0d7Gr3a1jvjIERAgs9AFiBcAhj/ZF+ZmseSSxKsM7ZTXv9qsLW4QL+EUKF3P2ZKjhBtuIahz1hDyJRtLu0g1K93DCcASxBRQ7f4PfuMN9tnXF2Q7PVmbdB+ySRbOwp4M0wGNiCLaHORn/bqdlrzf+89sDHoLQO75iIugdRqG2omgfYiTR3l7Myqt3liykZMI/Rk9p5cNaC5zyBP4cUjk8BEsfD5rzhOFqQcSwv4v/NH2+QAaNn2mg55QeZHWsoL+sCsW20gnysJGv5lonQVb7fTxOl78f3QT8u59BvZa0vUljTItMmzsL/1l6BD9DeaL8lssBiwpLfH1xm8ldWGpswrXhqrjPrTMbsowpDa9nsfwcW8P+wphqeFNjdmsgKezSsL9eaKwxtdSaFacz0oY53WMjp81QJ+QlQdjdpEQV3DA7POZ1o94wX3q4D17XXj5NP5Tsh3SoJA4Z/3WQ63pRbXzvfF46N3reQCxs3iLZvP5c5jc6CugcnDxcCckRzq2kXXaGSVuI9qcdpl2B5M5hyAV9QASmK7BRVNWuqrDzmrg1F5VSXMwQ0ZGLazNhlE1G1eHmu4VboLmaeSKZdkeIoHTt8N3K4lvVP5N72EV/k8nGrao/hYMOUZMmTKNaxdGzBTm4bMAFI9sFZjJ0u+nCGgLDoLJMPDMTDiFtq93SUmKFP6Xysfw8F/rYXW+VW/+TkwZ/gnZOBmPrQmnXYoZa10WhWaLeo7Xit81koGVwPfuSdZMVVtJ6OSW1W70lWaEL8Y1QD+y5wy9P3Pn+GJ3Z2sYDWKE2cSDMOUW4vSSUYoCEBF6sdQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2024 10:00:31.8255 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 75685492-8ce9-4b90-6e28-08dcbc47ef0c 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: CH2PEPF00000141.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5764 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 v2: - update the MACROS name as per feedback Changes since v1: - Previously patch 5 - Add IOCTL description in ioctl-number.rst - Split patch as per suggestion. .../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 e91c0376ee59..9fdcbe526127 100644 --- a/Documentation/userspace-api/ioctl/ioctl-number.rst +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst @@ -388,6 +388,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..2a59a3501f34 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 < AMD_SBI_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[AMD_SBI_RD_FLAG_INDEX]) { + for (i = 0; i < AMD_SBI_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[AMD_SBI_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..5f1634a17579 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[AMD_SBI_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[AMD_SBI_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[AMD_SBI_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[AMD_SBI_RD_WR_DATA_INDEX] = val; + msg.data_in.reg_in[AMD_SBI_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..0e80acc61d6e 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[AMD_SBI_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[AMD_SBI_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..ae597942e172 --- /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 AMD_SBI_RD_WR_DATA_INDEX 0 +#define AMD_SBI_REG_OFF_INDEX 0 +#define AMD_SBI_REG_VAL_INDEX 4 +#define AMD_SBI_RD_FLAG_INDEX 7 + +#define AMD_SBI_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 SB_BASE_IOCTL_NR 0xF9 +#define SBRMI_IOCTL_CMD _IOWR(SB_BASE_IOCTL_NR, 0, struct apml_message) + +#endif /*_AMD_APML_H_*/ From patchwork Wed Aug 14 09:59:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13763213 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2086.outbound.protection.outlook.com [40.107.236.86]) (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 F26EC1AD9C6; Wed, 14 Aug 2024 10:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629643; cv=fail; b=BfeZVBg5D6+H2bYpQilOQDw3/Y++Fm4rCRkFZFxLuYofbllMCGnzwDGQzfqk9ill3+01qK6Xk+1cTKROONsry2oLMH0F8ssv3vLKIIblysTRvjBJSEfwTSgkbTvTa4i2xZ64ravKLn5H3E/UYPYgExfDR8scwMFf+/qn3oFAQ3c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629643; c=relaxed/simple; bh=lPgZAE+fvvYMOt23+hxKtWRKTpGreYr/ZXPXp4mWja0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rzBressX4VpTHuHu9d7j6pwItSi0Vlj6XSu7l30lyoXfArLqTkofFQwl2cCx5SfmOC7QDzMCRjsZqEptXt3FPWlrnfLkoUx9Jkrxe6MlZe5UhOQwQSecE3bSJJ8p27vxz7mB0GLi/HsnclHZcUTOB7i7RnXSQo3D9E+7/z5zqQI= 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=mFlvJZU6; arc=fail smtp.client-ip=40.107.236.86 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="mFlvJZU6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vi+c9/WSriuFjGUNbMvV7pEWqGNlk79EovNL9i5/qRwtZeIdx8w+4VH5TzTiWXg4WvDATZcRRtNWAOZ7gku9Q/rE5fuUsdxVUuYwsxXZmpHXGibGyQ2NHFGmkxABTY+DcUzsdsNNVy6FtmyVRT9zEygTmK2smDzXAjQYWzAFZHx9R9g1h5MSDBKZa/OweMFJmhs2nkb/qU7PHf1f1QxoXUmj7E1QzUpAielPT074dV835PUTrOovIr+cb9PfO9+e9G++bSFlNo26rgt1TZMIUkgliI3y5W2zAeNMkMeyJ7H9QPqpj4VaLg559NhnSk25617tX1AvpslU8Kekb8RLJQ== 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=v+qJZ1YyFhIOF52WNIsLe9o33zou5yY8O4X38AKYe0Q=; b=xllDAqVv6O7YCcKYxa+d2hKrnuCuUVWMW9ZsK0nLBjUGnSZXUfvAByWp2qS9jJstssn/W62aOwpCTFFhSdse97/a0GnzvGLZZI2wkBjFwPVeLImXZvKi0mUNP2oTN5xehfNmv7UvBJRX/aGh+jTzTC0KibX05qTtqQkTWHGqVipgiEoPXTt/kL7WoH4jxBvrG4RTgC394kqs73r+P+08xjw3veiILbZ9ZwsuSxYENxurolOK8Uv+hD5MEiXcJLclEIAIGM4jyJnXq9YmQAqjwAxKa/KTOHrSe2poCAEcus4lyWKFsMKetran5+alFlQB8NdC981yTE4OfoJ+5oqCbQ== 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=v+qJZ1YyFhIOF52WNIsLe9o33zou5yY8O4X38AKYe0Q=; b=mFlvJZU6biX0pC0YtKotmpXa0nwj4JpCjAb0DqNLr/agYjZVgI0Dsy3LWqdY5MOQSPwvR5fP958SzyWMGBAGewTpuw4LfOnw7Behmyc1danUe9jd0TqjgxOMC3w+K+gljVB+9yuUk98qoc7qmRBav+yvRv6mM42hCvThzGXN2Jg= Received: from CH2PR18CA0058.namprd18.prod.outlook.com (2603:10b6:610:55::38) by SA1PR12MB5660.namprd12.prod.outlook.com (2603:10b6:806:238::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22; Wed, 14 Aug 2024 10:00:34 +0000 Received: from CH2PEPF0000013E.namprd02.prod.outlook.com (2603:10b6:610:55:cafe::70) by CH2PR18CA0058.outlook.office365.com (2603:10b6:610:55::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.23 via Frontend Transport; Wed, 14 Aug 2024 10:00:34 +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 CH2PEPF0000013E.mail.protection.outlook.com (10.167.244.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7849.8 via Frontend Transport; Wed, 14 Aug 2024 10:00:34 +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, 14 Aug 2024 05:00:31 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v3 4/8] misc: amd-sbi: Add support for mailbox error codes Date: Wed, 14 Aug 2024 09:59:49 +0000 Message-ID: <20240814095954.2359863-5-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240814095954.2359863-1-akshay.gupta@amd.com> References: <20240814095954.2359863-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: CH2PEPF0000013E:EE_|SA1PR12MB5660:EE_ X-MS-Office365-Filtering-Correlation-Id: e695af81-3d27-43cf-6bd3-08dcbc47f05f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: 2JS24ONkwTs5tiyv2ej6VfziGiA80VhLcQOkCemf8+B6cMNLl9909uHW2LyBHg39j3cgDAlqo9huONhdsi3rrrzhXSFQE0Ih/Xk+y5C4/3obgYczIlfP3NEd0c7Q/cMOJCxsPFiyEb8VTfqw6cj+JGZuqiGNJGRt9M7Zxc6JslAMw49BrSohByevpscnd6b2iSG0qaRsL/ZC1S1cA6oaXSHFcdkXYIBhS+f/iW4fGRmp/7pc+WwIs5agvq5BlES8pr/IKBC4ZryGlTC9whtWBpoOMYpYq1FmKry50hFGW/OFsgkW6Zh4GYN6A73clOnqYQcETeyPhxqm06jEul3/baMjhHBryldJHhg/8yyv4AKOB0cg2PjKgPj52VZbm8lYgjnK1ldUzKTuE68NMQdfRS7X1N1/IIV2zZxOrGpANtbjlNVjDOY8H/LUwcKl2jWhioVYXEYXJrNJM11htroWeMQFrjPUqos4VHu2S+cL2u4Mc6qwIpvu/TkaXhgpoKxNxY/0oYpmoKV8xSIeqF5JImCP1zYxKXfisJjm5X7GCU2zBUUCieh3BSq17raXlJj4SzH7VMCQqDpu0tvUK/eoIbpvAw6N3nZovngVOnmLKxxkH6PbuiST9fO4BLIsa8oDFtDS5NlTq2vtqLQzqpxK9Aft4w9/FLEI/yP06DFmD5e07DNCCMhJoW4LUL1R8KioBjIHfOp0bPZTQkVjtgLlkXlg3HkA+apLGHkmjd7pSBODasR2GbY9iivTVJnUTLVIZyimd4y2pXm7YRbnRrg3CwAN+P8gZYBeNFTwS6ZaG0vIbmxHS+I4T4yZSBbCVDLXxE6Cqu51rhkJlz59S7S5TQUu3fcFKQrNH6yv5IughYYp+YwsRiMQzXNC7TwSFgueOTz3aC5Hzqv86fDaZm62/ezrkmElIQBWMep7qaPszMvFv5cMnYK7DEaSFf1UzCrUCG5Gc35zIARtVWjHQEjneOhtAopaIWua66jbL5NTOe95zPbZ8AtTntp7DeD0i24jkzqlRmdBrmvx4pJT1Q94aFNdUpxHZuJUMU279pECoW7n7Grel7Kowa+UpKU9k/4HArLYO2838lAZ0kGem+J4CHZsWQofe5CzLbl8MVhN5lveAW0yksy1UQW/2OyxJ8vpliAJRglaeGXnSvC98Q7x9T3Xrxob3HW0BfLbh5Fo/aRjmoy0ATpJjSoz34ma/7SMoN56CGQpNPX897M/ypypoQSebQye8HIlyxmFf4po3MfD+aQbnskVKwdvAiDRhLllB9AdmUMA11E0kMHI7DBBP0FTIhbhtaV656T4oekwo2ndWmljQnaYylV89T45pG3OgJJFqQdwkt4CQq8oWOYFBJzjIlmRlzzItFeJM+xcyXmWG56fIWY9HqXZRZH3sa3kY52wCXbASVAGd91TVN1S5JClN83UiSk98koiv79yMYfzyV87tOYKfi0yDS3s9XZN X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2024 10:00:34.0471 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e695af81-3d27-43cf-6bd3-08dcbc47f05f 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: CH2PEPF0000013E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB5660 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 2a59a3501f34..a6364337dc5e 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 ae597942e172..b2d711d422cb 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 Aug 14 09:59:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13763214 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2060.outbound.protection.outlook.com [40.107.92.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6215D1AE851; Wed, 14 Aug 2024 10:00:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629647; cv=fail; b=tbic0FD8ueRud4Upff2Lfs0DzYThOTZDGMBFxq4W0lmMabvO2WBMgFieEUkoBmW4eV4EinxtN2A6wbhPb3FM1sVtNYsMPnEsjKcKM1U+oAXHgb8IRpQl1vwcdlh3Ia19xmuo/sighfkNie+ky3/SiAvteJfhVXT3punrtrjxpLE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629647; c=relaxed/simple; bh=3DY60OUbkJNZFkXM7N5542o+VeYxmQv/DMXU51BiRhA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E8X/GRiKmsiyD3uGKcfpUb0UW+ZGcvKiGVBN/qSw/dAEMu5EMJArUrKLFO7Ih8ihWTyK2eImNocOeVTj2178OWxhxkW/fcj5EXmeUOJPzBnnXDvRmbrrR9BKFTNwhRYNr/JEPdT41mEzxv5EHQxkGFL6mAgChhNQILgOXbgHPj8= 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=gnAvWr1U; arc=fail smtp.client-ip=40.107.92.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="gnAvWr1U" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xXURBCOqIrspKec1wvuSVogs1vt5Cty0pLpIi+MT2xHori7hmg4U+1Z8eOW1W3ZvhDLLyw5x3yn9VfKqGpsGJJZdikYTVmwZXHkRxViEvJhFP+dphiza2IxL+9xKy6//8B7Jy/LPJzOCGlog70DXfBq68M9Of5Ix5A/vJ8zRQx9pp33Wcl6xvWbk0qyhG6H1+UiC2PHu0Pg5SoaeeVF2fEJU/+tG0ylgyQ+QZfzyL+ZOiHn4GS5gKMYnBH1ciZBAqDk6Dk8m8zaKolJpYEih8EOUIBbYt7nS0B965+d+34SIRRKLPjJqY/JnDIyGFYsJcgKozeuVC0i3nbv15IT3wA== 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=4km2wvCIrJ3Hkgkp9XsrLga8DOCef7GR9NirxYsZkX0=; b=kvLVUMQaPFo0gHUEZFouRd21/PbDv3FkBG22tUXO3/HZ7Trp3Z3+owPXT1NQXLG0qmuhrasW1JagsVmzDZARtzTqWEZHg4/+JIn5m/F1FUVimsidZCL2Fs87y3G+L6gIHvj1UuIaeTTz4Bb+Ybdfwqc11MqUwSOJ1rBS05iyafzazaMPKtXKdv3nUSsaWaG7f2n2VSh+Lym5xIc2nYAJhflp+Z5ZQoGWudRkC0u3ZoBN1l8G6zBuLxDRx2V3E0b7F3odDs3b9xzAcRHHVmIakwr9n0PyES2Zz/x7IH3sacAkaEAfd/1DTQMmFgLDbCrXJESsht+IfNUrVyqs8qHqjQ== 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=4km2wvCIrJ3Hkgkp9XsrLga8DOCef7GR9NirxYsZkX0=; b=gnAvWr1UdJfIjh++1r1ZNsSxKwsTiCmVC7K81HGOE9z/TqYmtSm2JJd9qdrzMeSV3VWFEd6fN+2dC0z0qIhEwLXVhZXixom208q0lqQfn0nKPetcK4k0XH3a5l/9DyUZtDqI1EdYIn3llRi9ctjl8sIa0R7ytvNfUXWKKyEchHw= Received: from CH2PR18CA0037.namprd18.prod.outlook.com (2603:10b6:610:55::17) by CY5PR12MB6528.namprd12.prod.outlook.com (2603:10b6:930:43::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22; Wed, 14 Aug 2024 10:00:38 +0000 Received: from CH2PEPF0000013E.namprd02.prod.outlook.com (2603:10b6:610:55:cafe::62) by CH2PR18CA0037.outlook.office365.com (2603:10b6:610:55::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22 via Frontend Transport; Wed, 14 Aug 2024 10:00:38 +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 CH2PEPF0000013E.mail.protection.outlook.com (10.167.244.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7849.8 via Frontend Transport; Wed, 14 Aug 2024 10:00:38 +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, 14 Aug 2024 05:00:34 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v3 5/8] misc: amd-sbi: Add support for CPUID protocol Date: Wed, 14 Aug 2024 09:59:50 +0000 Message-ID: <20240814095954.2359863-6-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240814095954.2359863-1-akshay.gupta@amd.com> References: <20240814095954.2359863-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: CH2PEPF0000013E:EE_|CY5PR12MB6528:EE_ X-MS-Office365-Filtering-Correlation-Id: 30eab36c-cf41-4c63-4e7e-08dcbc47f309 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: 7ULjUcFCIXN3FDbYUoXN+QEnQGunDEUJDf90sTByHl5hkXOOHDncHOZOxZ/xrjpdzzkym8JHsGqyCcvguOTn1/x3rb+OdLrZpqhcMQERKyOjMRSwPnO+uG/wBe9f5NiiEMaKYd/eMytjXpyih8woQYdZb6CpBJU8Eu/Q9vFOSztS76cp+kbqr/gaJc9/MEB++s3Lqkd+emGMXIuoLeBKKIaX+QvLRZzNjqmveybDciiqvdDzURcT9QRidJIgAoUpDRDdrwWuz0gONDeXdwSWH1ReC/6GRJ96NXSHwSmanr8GtxKrBkRZnuzFvEEu4OSh+hvYTvvbIUCZx/fnLZ6/C8O+NskhgCRJ42H25Xtqcfv1YBxOWctwaXhW49UviLnOeYKS4iYe1VbUIuaQr05r04r8rTnbs0fQAi+cI0yg5nh1wxIj0jRDVXykPZT2JHKHRsk4seNFtBZL1Amwd48CaRHR6OBmsJqyjInBZoEyAcvpGFMR93Du/gwQ87tKN8HwkiTaO/w5KMV0xO3673VIWTgs/osvD8AbCy0YBLZGYe6fnY1TfR/ab1aKB6MvX1UdLzmO56VckAgOZxqKoZNl9V55uIvlec20s4PIymjSDqSIXdf6Ou9tVvzhORSB/kljOEFn0k64CnmZrujj3KMsGFReBmx8jkzRsCUPz8CB/03blWgRdgbQf2FfIdPVd4i8EqMMLjpvov9nXC+G6jALo8L7jf+pIbYAuT61I25/txRN+mpaoR2BL7MwdBzbiC6y 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)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2024 10:00:38.4222 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 30eab36c-cf41-4c63-4e7e-08dcbc47f309 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: CH2PEPF0000013E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6528 - 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 v2: - update the MACROS name as per feedback 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 a6364337dc5e..fdac6848ae9a 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[AMD_SBI_REG_OFF_INDEX] = SBRMI_REV; + msg.data_in.reg_in[AMD_SBI_RD_FLAG_INDEX] = 1; + ret = regmap_read(data->regmap, + msg.data_in.reg_in[AMD_SBI_REG_OFF_INDEX], + &msg.data_out.mb_out[AMD_SBI_RD_WR_DATA_INDEX]); + if (ret < 0) + return ret; + + data->rev = msg.data_out.reg_out[AMD_SBI_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[AMD_SBI_THREAD_LOW_INDEX] | + msg->data_in.reg_in[AMD_SBI_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[AMD_SBI_RD_WR_DATA_INDEX], + msg->data_in.reg_in[AMD_SBI_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 b2d711d422cb..30bb6307993b 100644 --- a/include/uapi/misc/amd-apml.h +++ b/include/uapi/misc/amd-apml.h @@ -7,38 +7,53 @@ #include +/* command ID to identify CPUID protocol */ +#define APML_CPUID 0x1000 /* These are byte indexes into data_in and data_out arrays */ #define AMD_SBI_RD_WR_DATA_INDEX 0 #define AMD_SBI_REG_OFF_INDEX 0 #define AMD_SBI_REG_VAL_INDEX 4 #define AMD_SBI_RD_FLAG_INDEX 7 +#define AMD_SBI_THREAD_LOW_INDEX 4 +#define AMD_SBI_THREAD_HI_INDEX 5 +#define AMD_SBI_EXT_FUNC_INDEX 6 #define AMD_SBI_MB_DATA_SIZE 4 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 Aug 14 09:59:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13763216 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2048.outbound.protection.outlook.com [40.107.243.48]) (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 E1B151AE867; Wed, 14 Aug 2024 10:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629649; cv=fail; b=NLT996jxjeV39y51rjgoH1mKLor2PvAwRccTZhisot622gwRDfLEQOYnrD5Yg62Vo1gWmVKpNbbF/9hPLZK4FYF86c8omDAyIlE4p69FlBHPCtGbdEkE4vw+713hWDlUFgFKkztluaW09qOGPDubqcJPImHge+Nzv469RTKstB8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629649; c=relaxed/simple; bh=iFVf/JO0cA7dy2pJy5xqprBiLAxpbM/aLUBMknlopmg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ivxs5EwrjCQ4G9pQM/yl2gUc2yZcAkhC/DPpYhB9/4oywRiKeBah0+BxeN/7TOfTQTad/zhOo45jPp5uoUjeLORtMjaI+U3LlqMrUYke8S2MzIimbMeKTzRMhYuw19Fc7RD1Kk7/4J0sudejn2L8LFp+/irD96kkzvoThA8cXLQ= 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=kPRVKJEt; arc=fail smtp.client-ip=40.107.243.48 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="kPRVKJEt" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=q1GrMPy33CPkjxBra0DpmHnV0z/Eii+OBQE5eEW5a2/JWMi5DxYkoMCaCix7HzK5XmG4RM26sVcDjPtjKKx9IO9gu4dxeZZ30KH0z1nkJ3Mn6cSb2sahBo8TXbp9IPC+d6dMymX55+NdrVs2r1iaXgMsza6jCWEofhTjU0l568oDrXDCrHRVMv9aD6ebdDUWwpZUJALu7gB/WZr5ySBgdcsFbtOXq35j9ct44GT+XG2REJYGQ27aG7wjFRhciST5RQ+9EfSMGtEDbGWS4Ks7iSg3abe6q0Haou3+mz142y2H8QK68tK1V8M9DpyKf3Um/4RwP1ewoKOF635DAC/rTA== 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=XFo1PztKPXFLoupSBTE9yk3PY7y5Hn3DRuA56sZiaf4=; b=l2PfxtZH3ZiYzRF43ylcE1BVyEnKPRPIgFbmnbZ4Tgwb1Py2eyPsuOvCB0K9lrrQlEzqzlhx1KDWifbd+61mwga090tpaGURMR+2b/dGqfBJzw2obJyCV7PrB0Nw3d7LkFMCs1BOiLNz+gIiZ5OSBZ9FmUZetx8EKp1JETqI3pPPFPjY9E3wPbRqNNI0cv94xAmIK9L8vnRP7HQVtDmmHt6YY8A3CiorG/jhTpWibFvhheHFp9SjGF05iKVq+xBxSGkhXr72pzdbWEs5siRZWJk3JEznTFOXV+AZRHrrjIGEwrJSVZ3Fo4GWcnwK2gXfNVgf5Ea0QGx7WPLvqQzexw== 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=XFo1PztKPXFLoupSBTE9yk3PY7y5Hn3DRuA56sZiaf4=; b=kPRVKJEtxTZWt9wbVrP9Ng2ZCmiaQ3LPKdgyWbEoANdnwqOJyGVxrTt38/NrqbkvWMllD/G91KM78AGUZgzg491h7xlTBkki1gzuhE4vf5WBjn8ssMUDRL9w+0TWwSgZ+81VYrmOwsdDK4GyrT9idHrWqpe3G4jOV0DtVPO9Lew= Received: from CH2PR18CA0036.namprd18.prod.outlook.com (2603:10b6:610:55::16) by CY5PR12MB6274.namprd12.prod.outlook.com (2603:10b6:930:21::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22; Wed, 14 Aug 2024 10:00:40 +0000 Received: from CH2PEPF0000013E.namprd02.prod.outlook.com (2603:10b6:610:55:cafe::7c) by CH2PR18CA0036.outlook.office365.com (2603:10b6:610:55::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.24 via Frontend Transport; Wed, 14 Aug 2024 10:00:40 +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 CH2PEPF0000013E.mail.protection.outlook.com (10.167.244.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7849.8 via Frontend Transport; Wed, 14 Aug 2024 10:00:40 +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, 14 Aug 2024 05:00:37 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v3 6/8] misc: amd-sbi: Add support for MCA register protocol Date: Wed, 14 Aug 2024 09:59:51 +0000 Message-ID: <20240814095954.2359863-7-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240814095954.2359863-1-akshay.gupta@amd.com> References: <20240814095954.2359863-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: CH2PEPF0000013E:EE_|CY5PR12MB6274:EE_ X-MS-Office365-Filtering-Correlation-Id: e4409ccf-682c-46dd-0789-08dcbc47f425 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: uhTWXE7sTQCBaZkjkNgWD2JIoPE9JsUnvJXAEAvF68ZRpJJPuidQrp+nmSbZIuJuynTylUrhFjnJooIKvnX0fkFKnjTF8RpjQ/oVWwOZcik+DhXFkImzgRTSZG+Ss32bYs4egN4/Q1xY1+GcpOmY24nHBWZ7SUri6h+Sleo6pce+spxFNVdq5Z8XsFCQJHQ8R3ynTpTACX6WPoWjlfyEWaVAKlXg51CQtUQJDQbWkt3haZVVAK4KMVfJU5/TH4G5S6iRvzemd1Kp8f/SVskE+5QgEpVRiVsAvFJMZcWZcMqy6l8kfjgpfk81lBdcn7X9JUAiJ78NjzF6d7xn4pvmpgrNFoFTplkRGTW0jmsLMGC6my/2iZfAehPCUY3LC7LwKm+slAquh6JdNcrGWC3uTli9xvB9nI2vBZCEZlaTlnpeZBn4mZJF7WfZnUGYDbEcnyUleFD4btMs+EToqkMzLUr5DPhIhmjvn4Zj2Ub9PAI2TpqJ1T3sMFIK9H7Uo+tkf7whtCClko3SfjRlwJdF97sDxtnteML7S/AITA1G6SZnf86vyJrZIu9crT0T9EKCNTq98JdPqGosh9C3f5sfmGNZ38ZLqKVRGlQY3BzLsF7C6zpMuW4vtkCIr7b5dN1ECs+HIFG7VHwmJDdf7rlaffbbYJDh0qFJkxxLKH9IhW95OPhmTLQsScKikEK+csYGdfKlWasfiJ9R8kE6+hKI8DjaFx5P0NF3Zsgefsj/w1ngwYYt4Kfk/YxZmJ+kbWQ37/qvwRMmM8ySWpKAl8SXSC0ytHoGV/LQOoJjhd1MHl/eFsIbXmjxbNeJ4DIiYoLzC7zpq9Hf1AvwLYX+sraue0zhGN4HiduxDsPDRSDUwZZfiCkCQymg9+5iW/UDrqTm4fHjxVGi1fyyPAflz6QBlxPkcNIaTgLKxWY0Ti75RMRcFhDAvWN4/pQy7+I5PJsogYCN7yZCBUO1PTPFT5W6eOTrrqTbpzPEpr3BNX5ecjr/vi47pEiNSxFYLuV+p8Qqj8JS2rtOp1oGt+WY+pi1oeMKO8QiSqb+rTL0ONwAX28FPyZ76vvYhhy1kj+TiJBlUOoMhmnSatp64xzQfGwKiNQZNnCjVsKiYPALurj2ebLP5FjwOZ2qf3Ijv7/HwVJV2ld0vba/zYaH2s5SjNzUPd6A+tkQ0qwRT7d3GeFNy5xeJH5XbFXapc+N2ZaGMCcq0U9PTsecNH3b4odMY/gWBXOm/pvq0xmpFOyj3VYUQVPsMIlB/gbpE9D4usveFdsZl9Zg49IEC7RCQK3Tu4yPHG1ZHOCN+VDFrVRJM4kaWDo2O9BRZJNyti1vU68ojdc2eMRFfkKoCSH8I0yHbJx2IhWXekLZ1dV4ptyZylhGz5rhZOp5vYkKN8KtkqHsQA9zjavLPjvLOrKW+CEkiTOnzWwPu+T3ZeeuKxF6bYr5LxjTSbJF8FoMNkDaRuZfsbCF X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2024 10:00:40.3753 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e4409ccf-682c-46dd-0789-08dcbc47f425 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: CH2PEPF0000013E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6274 - 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 v2: - update the MACROS name as per feedback 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 fdac6848ae9a..56fe09e1e54c 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[AMD_SBI_THREAD_LOW_INDEX] | + msg->data_in.reg_in[AMD_SBI_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[AMD_SBI_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 30bb6307993b..8d1fdf2a54f0 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 AMD_SBI_RD_WR_DATA_INDEX 0 #define AMD_SBI_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 Aug 14 09:59:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13763215 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2048.outbound.protection.outlook.com [40.107.243.48]) (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 053C31AD9D4; Wed, 14 Aug 2024 10:00:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629648; cv=fail; b=emDjiiHLoZS9JyE7Vvzcuzavpy1nVVp/0qPoxojUOS35Q3YR4J/+F9wMsAugi/5A8XpYirz6EiejBRKzEd8Qtc9Wqz3I9/2t2oLq6l93qd5DRR8OuDfoQIuXAATVX6ewa1eKBio2TWeSzPhWrxs/C/fhWYwUOdyj1U1U/HIjsdM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629648; c=relaxed/simple; bh=/PdeybAOlU+rLjQb4B/6p+ZW4cwvv50/Vj2sIIEn4WU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ad9CdGvqt/pGRfNk0RU6V+yc6xouH8GVkc5Klr4TIK8zCWaA33uwZJKiEx2HBIkzzwM72WYgYTVOf98GxKxGJ6c4uhd2UvsNjAgVYKEHzXGVPlmAjS7OIFUv4812y9sBwX7gbjtpY1y40isci+keHEtM6X0ymoZK9er8iM5c9xY= 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=FpWlzW8a; arc=fail smtp.client-ip=40.107.243.48 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="FpWlzW8a" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=x3EhTF7E2WaqBhRonz2lu6b3BUiqfZdqMH2xY+/8C1E5060CFVFdU2osc21KTD7kq5mPQyMBPIixYtGNl/mL8LHEMnPt60u/zd7L4fUKxB5cm6TAyUfD0TSZnNnrqnkQz1Gge5tygTgpwjm7dOOqK4EyZeDhKTXf/el1GALmgKRUWKRXgKYJsmZMEEtqxmcD6QDweZOAjgwsvGAJUyeMAxpEKTvvnppiWBebWt0HfcW48FEBRdezwKTOS9nv41ZNLF/m+ZzuvO/4nq1V5O3p5TC2Om+sGeMPgCLSOrDG4cydaF5EtUZxrBFxhBuKIgOnezx/M8LmrpeWIEx8XoEY6Q== 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=xNkVFQkP0h8U20a72RYPm4dRRJYk9LWpWeNot/K8fCs=; b=uDW1VihL72y4BHfdzKGGwljUT4u7hBm6V6b6vWx1bipQsAzPkg5XfRx7IYvlGnBhY9706h1OiWPlPUdDikpCkwiRzbGI7KwrRcKvLaCMOoUYJG+CrliSbQ6Yk7Wfqg5Q/D6iUiI58Dyak1s0rCGehaBgFbNp7S8Q+U5aCnixb1UmlJM5WqKE+pfMWKbCtDz4+UDCXu4fFjobV4dqZGq38PyamhGCSKZL9imVebRVhKkpdT/LL1hGRq6wXN+zoW1aVB1UtIGjslPpX9wWWmJkTOttPJmWG7d82JySsRZLn28xp4HzjUq9AUZhdS1LIBhGi/UleKM1VVAbIRDAESd9pw== 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=xNkVFQkP0h8U20a72RYPm4dRRJYk9LWpWeNot/K8fCs=; b=FpWlzW8aJlnZnvYbUn04XiW46UwiNjOgoLdCmAjL3nTIEDNzaGfU5aoZkwzusyx5y/9Pnu0ViESKRPe/dTkPyi3oEJUkiKmfuNrb+A6YRnPfWIyfp9VMV0z/bTNhhsv7i3F7dk2ffzzxqWKURTrgLUAlk8xevnm66tArdwf8tQU= Received: from CH5PR05CA0006.namprd05.prod.outlook.com (2603:10b6:610:1f0::11) by CH2PR12MB4037.namprd12.prod.outlook.com (2603:10b6:610:7a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22; Wed, 14 Aug 2024 10:00:43 +0000 Received: from CH2PEPF00000141.namprd02.prod.outlook.com (2603:10b6:610:1f0:cafe::da) by CH5PR05CA0006.outlook.office365.com (2603:10b6:610:1f0::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.16 via Frontend Transport; Wed, 14 Aug 2024 10:00:43 +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 CH2PEPF00000141.mail.protection.outlook.com (10.167.244.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7849.8 via Frontend Transport; Wed, 14 Aug 2024 10:00:43 +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, 14 Aug 2024 05:00:41 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v3 7/8] misc: amd-sbi: Add supoort for register xfer Date: Wed, 14 Aug 2024 09:59:52 +0000 Message-ID: <20240814095954.2359863-8-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240814095954.2359863-1-akshay.gupta@amd.com> References: <20240814095954.2359863-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: CH2PEPF00000141:EE_|CH2PR12MB4037:EE_ X-MS-Office365-Filtering-Correlation-Id: 1c6ad9b8-2ab9-4572-8fe1-08dcbc47f627 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: FBJraGkoRZjAgLuGunHK2BSJ1rKzm/r8bAkgoCAs17Zr1xNMh6pK/xr4+XYlkoGeudur/KEFPaop/ZhppZ3z4VUTCJgrMFbw2D93IrYCQoo9/ITxaemEZX/quRq8407Fvwmdi6p2Gc7TIfpQn0UE38zMhgdfmQZUN384v7buHI2HEPCcw36p4G03mFbzoZUEFlgRMqeCtbAAGNntIZ+EPYYOKIrhoOu5sTa98wEwsiEZsrmaJt2vrFNkqYw55ha65mgNn9m+7nzzOxjE/OGlCFoFrV5WuoMmFTJ01elVb1TYl2VUT0L9IVVM90uDCzWj4AbIRBzAPpyJ9tVvoO6v3VdoobAidM/t2Cw3b1VzdKe2Qh5wVi01h2ZhMqEPVip369Kp4VvA1G76NShU8HGzcEK1+ISIdzwz8roPogaGTiTfVpI/gfcCePIBePO4FRaMJb27T+V/1xgCv79h4T5LxBNrRQAnxJTo18IdgPzBtNLKF4OMePBkwzqbUc5TslZzPw6VqidPGrQLWYRKk1ZQBqX3xONmnTdrixVfWRKb016EFhTReaMM3gfc55wnqLnMsIAy/dH/B7T6bU5nXRNUQXFDwUOdrG+aNrzRKqyilwosinn8bGmxv6zyziN99mIIORFuxUb16Iq/veIOmrZnDB6wjgMGqzNscxqsPKF8JhErTPc3RpAsC50asBetjxlH5zbhm+ZvF+LfnitodB9oqMHbKhJtqZ5thPDCkf6+WpFpvg5pwQaGmR2y47uiGvjrUkfHfIG8vcD1ICmmKjso5vL+RFNlTxaZqcglu3k8zj/ZJENElMMFFe9H2ehP9EUIkWowXYwxvLcqTcJ8gPPHTYrqy+A0UZtsBW1fSW2BQ56lo7YxopAWlvhLt1K5wzIsdEWGxu7WwUr7VBcyN5xAx+V8ggh2iaHoJtFEp3Qm6IUWOdDeXo/bs7uIYYPhTiIYY71mypICTrziswo14veP4ydGyUCJg0odaMV12hevuawhKPhBq0l8CYXw3dMqtQwHzWSxu4+oBwOfiUCUut8ilW+xNd5W3AhFVYENJv/j6RdEHm28vyDlyNy0oVLE9lh5TYs6iICwlzUQ04wlm4PDsY9JWmmJ9mtQC12onYIlQU4bG6C6Ik/G0MPzH5sgCIdYi7cEmVVkF400ML4qES2/8Lb1+sgFF71fj+PDnqV5w6WEGgWnh2/A2QbFVrG7P91kaqdf9rpGmA/tU1N5p3c3kq/VKPyhuqBc128ttQC+Qjj39alvslPsOaQE7PK4dfIDZBHjcNiGAxTVeUsMnjr+AUp+i8Ko/7fSEXZS3M0Bl6S3snV9uLvcSCxlcWAqIyWHOLciR5zkWVIENrN7Pn0Cx5lCIZwyqVYdglo1bVyuFN4ho4fNGiE9YwwPIrs68YsJ4FtytpUdOXvdrRRyGcyrwD2qIMKPwaLJTFOzAvRfGfrbmezUoL6XtElNr8sXbH/1 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2024 10:00:43.7474 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1c6ad9b8-2ab9-4572-8fe1-08dcbc47f627 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: CH2PEPF00000141.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4037 - 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 v2: - update the MACROS name as per feedback 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 56fe09e1e54c..d5159a53c18b 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[AMD_SBI_RD_FLAG_INDEX]) + ret = regmap_read(data->regmap, + msg->data_in.reg_in[AMD_SBI_REG_OFF_INDEX], + &msg->data_out.mb_out[AMD_SBI_RD_WR_DATA_INDEX]); + else + ret = regmap_write(data->regmap, + msg->data_in.reg_in[AMD_SBI_REG_OFF_INDEX], + msg->data_in.reg_in[AMD_SBI_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 8d1fdf2a54f0..2d531519c108 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 Aug 14 09:59:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13763217 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2069.outbound.protection.outlook.com [40.107.96.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78D001AE87D; Wed, 14 Aug 2024 10:00:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629655; cv=fail; b=uEf8r+XlL3Wo1XR1gppbuvkT3iyrd5XLCHx2H5ORVUC+4bxORdprDASRkU6ahJkEqI2TNReHkd0UM9bdZehqSUaBpPL6HdVJpqhJNMmXCfu5A3oTG5dSx4nhn6gCPfRW49U/TtFyV1C/FpMEFDaj4e+17WlO0GoF9VgtogByQ94= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723629655; c=relaxed/simple; bh=MS8M7B2+m1GFrjqbrrquLrAusd6MXYIm+Ry6chG7qzc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZkT6B2zvmdnKgLPr3fQME3JyBRWhtlk0/0AjQ36LUFXDEquh/ZXY274MBgtO5GC1RhlZ2hKfdyo36b5MMOJ2yQbCpKCoGKJjNcszO8mKOxClxEqa9K3kpM8PO/Au1ajCBOoNUKbw145DzLlfv2/0/5ajXdN5gGCT6PNt4Ivs5Bs= 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=q0mH9ipn; arc=fail smtp.client-ip=40.107.96.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="q0mH9ipn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=L3NtThfoFxnW4imCq1qURTGTowOYpaH6i+032BR+wYyOR+35XI/sZgxYh8u43kU8uSFwX5wnPKnwJwsmZggq/V0GZ3EL+MqceiRXErpVWJk7S/+8wRhQHXEZrCM2ydIHgDp4APKOXKTxn6gWmGQwcs2OCAsn1OEDDMZtLebmgr3qD0JxIhw/s2BOwjCVz3pDLvNz+C2wT9YUDkLsjGmrpbeRqk2OOXHm4FgSEENRp4QpJV7rMrUTT0cQ6AKMCiVSBco43XDZPJxyHEdyTkeLq7VoE8GFyhBJ73Vx4puSG2K/99Ig7Zb/wwMI7RYVeKxNwHFbOz5yoPDtJTtJvDbNaQ== 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=2Kkw9F3hATkuoWEh2QUUZi1MimZ/XSJbMlmTc4oxDik=; b=FI8Igsu/SFTN6y/aw750zumHzbwR5xH6W+RSaEnoFyOM/6laXI6ysMsAv/4aPcP7BwuRH1AEhBNSXKDmhaKg1Q35MiTi4jJVVdZwSoT2t0OHQ2ofaIr5/o6JqXliEMksYDq9NjvfqbF8o1BoeYlCR0M/cU0a4jTsieCLHtgKrXyvoFKMtlwpGwXfveYklghVoKmZ7XB7xS/3zLvSPa8chdHHH4x+Kfgd6jYHJe6TJZg9KRq6dd8yX9N9EMI1sFeLKk0TCNEJt7fZYCGNs+ekyv6G5aYCosR716nJSBhKDYSnBBis1EAbLROdxYeaJuGHwX5irEHmHUUSeEsAIhPDOA== 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=2Kkw9F3hATkuoWEh2QUUZi1MimZ/XSJbMlmTc4oxDik=; b=q0mH9ipnS9Pc/PY7orEDJTbWvpRG3rU0em4M4RseJa7IzHjzCin1QfqENtq6iW7tZ1w1T/FJHEElwb12lfj6IrsxF0FVV4RQVHNFVqsO4qJaKORml3RSpn78P0ui0vD2U9LAIMAeK98oFXdBhMscdH8yKk1jRWkavsH6ggD7qZg= Received: from CH2PR18CA0041.namprd18.prod.outlook.com (2603:10b6:610:55::21) by CYXPR12MB9385.namprd12.prod.outlook.com (2603:10b6:930:e2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22; Wed, 14 Aug 2024 10:00:47 +0000 Received: from CH2PEPF0000013E.namprd02.prod.outlook.com (2603:10b6:610:55:cafe::f1) by CH2PR18CA0041.outlook.office365.com (2603:10b6:610:55::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.23 via Frontend Transport; Wed, 14 Aug 2024 10:00:46 +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 CH2PEPF0000013E.mail.protection.outlook.com (10.167.244.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7849.8 via Frontend Transport; Wed, 14 Aug 2024 10:00:46 +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, 14 Aug 2024 05:00:44 -0500 From: Akshay Gupta To: , CC: , , , , Akshay Gupta Subject: [PATCH v3 8/8] misc: amd-sbi: Add document for AMD SB IOCTL description Date: Wed, 14 Aug 2024 09:59:53 +0000 Message-ID: <20240814095954.2359863-9-akshay.gupta@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240814095954.2359863-1-akshay.gupta@amd.com> References: <20240814095954.2359863-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: CH2PEPF0000013E:EE_|CYXPR12MB9385:EE_ X-MS-Office365-Filtering-Correlation-Id: 0b3f5cd2-16e8-4e3c-2c78-08dcbc47f7f4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: SvdYM19fW+tWK3/eThKHyGftIyobCjl2Bg0zYPZMU4d+HFUnnnH+yPXvdS/O1n7FcFppq4pTTBwkx/npCpX1YBiAUenxpjfFs2aK+Z9b211fq/x2eTtSUy3wxefvUHOPAvHJHVqwT6W4+qWY455TQSTSgD0QBemkv2tW897gZOoQOwl6ZgVKI2a+96xT75r7Uusv+Fe9wvMA3JoUmSdCZf+4dAnM+vrQx/YnjJVMRNyt00mOHjw0zUyg/oQOWaB2d8UlNTMPCIaEEr7NdbbCnWSx8WsmYrSGHS3nt1xZOb2QBaGy3ne+Wrjrz3CjpGRiONb5brkeUPSh6J1qrv353UkLXWmNFbhCNuTsZB0930H1SwixcUa/Nxq27tMi4z61Juw64O95xQ+/wwL0qxmENGhUS4KLlZIRDf+mCzebGZ0pEfGForvqWpKXDL0q+m4LuzwhRXrvUFBCFnN1JiyLwwF6ACRBVTKNc4W/evClYqmaNClCu2Iiae++T4DTqLwlqvWzQk+pEHGWBpizLZqqLcwxqftmwImNQz0yAsWz+CG26ZZqVnOexDUo8fmxK9EU2jAioSJ7IMw2JdWqDOBZC5qxn2nbdY9/rZU0BiNN7uzGVVjZoMWtfwi8g4oos8Bd2s6UPpWXg0yYoniHMZO3Crvd/vzfE59kSJxlKAFWzfjYz20wMfAuNuPZVD5r0YrkBkFgcp06eMRib0WogosEYA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(36860700013)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2024 10:00:46.7504 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0b3f5cd2-16e8-4e3c-2c78-08dcbc47f7f4 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: CH2PEPF0000013E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYXPR12MB9385 - 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 v2: - update the MACROS name as per feedback 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..ff90ad50a29c --- /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 SB_BASE_IOCTL_NR 0xF9`` +``#define SBRMI_IOCTL_CMD _IOWR(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. +Link: https://github.com/amd/esmi_oob_library