mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Akshay Gupta <akshay.gupta@amd.com>
To: <linux-hwmon@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <linux@roeck-us.net>, <gregkh@linuxfoundation.org>,
	<arnd@arndb.de>, <shyam-sundar.s-k@amd.com>,
	<gautham.shenoy@amd.com>, <mario.limonciello@amd.com>,
	<naveenkrishna.chatradhi@amd.com>, <anand.umarji@amd.com>,
	Akshay Gupta <akshay.gupta@amd.com>
Subject: [PATCH v8 09/10] misc: amd-sbi: Add support for register xfer
Date: Fri, 11 Apr 2025 13:31:21 +0000	[thread overview]
Message-ID: <20250411133122.1806991-10-akshay.gupta@amd.com> (raw)
In-Reply-To: <20250411133122.1806991-1-akshay.gupta@amd.com>

- Provide user register access over IOCTL.
  Both register read and write are supported.
- APML interface does not provide a synchronization method. By defining,
  a register access path, we use APML modules and library for
  all APML transactions. Without having to use external tools such as
  i2c-tools, which may cause race conditions.

Reviewed-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>
Signed-off-by: Akshay Gupta <akshay.gupta@amd.com>
---
Changes since v7:
- Address Arnd comment:
  - New IOCTL and structure defined to separate
    ioctl for each protocol

Changes since v6:
- Rebased patch, previously patch 10

Changes since v5:
- Patch rebased

Changes since v4:
- Previously patch 8
- Address review comment for documentation warning

Changes since v3:
- Add ioctl description comment

Changes since v2:
- update the MACROS name as per feedback

Changes since v1:
- bifurcated from previous patch 5

 drivers/misc/amd-sbi/rmi-core.c | 29 +++++++++++++++++++++++++++++
 include/uapi/misc/amd-apml.h    | 31 +++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c
index 171d6e871373..b653a21a909e 100644
--- a/drivers/misc/amd-sbi/rmi-core.c
+++ b/drivers/misc/amd-sbi/rmi-core.c
@@ -350,6 +350,33 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,
 	return ret;
 }
 
+static int apml_rmi_reg_xfer(struct sbrmi_data *data,
+			     struct apml_reg_xfer_msg __user *arg)
+{
+	struct apml_reg_xfer_msg msg = { 0 };
+	unsigned int data_read;
+	int ret;
+
+	/* Copy the structure from user */
+	if (copy_from_user(&msg, arg, sizeof(struct apml_reg_xfer_msg)))
+		return -EFAULT;
+
+	mutex_lock(&data->lock);
+	if (msg.rflag) {
+		ret = regmap_read(data->regmap, msg.reg_addr, &data_read);
+		if (!ret)
+			msg.data_in_out = data_read;
+	} else {
+		ret = regmap_write(data->regmap, msg.reg_addr, msg.data_in_out);
+	}
+
+	mutex_unlock(&data->lock);
+
+	if (msg.rflag && !ret)
+		return copy_to_user(arg, &msg, sizeof(struct apml_reg_xfer_msg));
+	return ret;
+}
+
 static int apml_mailbox_xfer(struct sbrmi_data *data, struct apml_mbox_msg __user *arg)
 {
 	struct apml_mbox_msg msg = { 0 };
@@ -414,6 +441,8 @@ static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
 		return apml_cpuid_xfer(data, argp);
 	case SBRMI_IOCTL_MCAMSR_CMD:
 		return apml_mcamsr_xfer(data, argp);
+	case SBRMI_IOCTL_REG_XFER_CMD:
+		return apml_rmi_reg_xfer(data, argp);
 	default:
 		return -ENOTTY;
 	}
diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h
index f718675d3966..3b5f5af61a1e 100644
--- a/include/uapi/misc/amd-apml.h
+++ b/include/uapi/misc/amd-apml.h
@@ -58,6 +58,21 @@ struct apml_mcamsr_msg {
 	__u32 pad;
 };
 
+struct apml_reg_xfer_msg {
+	/*
+	 * RMI register address offset
+	 */
+	u16 reg_addr;
+	/*
+	 * Register data for read/write
+	 */
+	u8 data_in_out;
+	/*
+	 * Register read or write
+	 */
+	u8 rflag;
+};
+
 /*
  * AMD sideband interface base IOCTL
  */
@@ -118,4 +133,20 @@ struct apml_mcamsr_msg {
  */
 #define SBRMI_IOCTL_MCAMSR_CMD		_IOWR(SB_BASE_IOCTL_NR, 2, struct apml_mcamsr_msg)
 
+/**
+ * DOC: SBRMI_IOCTL_REG_XFER_CMD
+ *
+ * @Parameters
+ *
+ * @struct apml_reg_xfer_msg
+ *	Pointer to the &struct apml_reg_xfer_msg that will contain the protocol
+ *	information
+ *
+ * @Description
+ * IOCTL command for APML messages using generic _IOWR
+ * The IOCTL provides userspace access to AMD sideband register xfer protocol
+ * - Register xfer protocol to get/set hardware register for given offset
+ */
+#define SBRMI_IOCTL_REG_XFER_CMD	_IOWR(SB_BASE_IOCTL_NR, 3, struct apml_reg_xfer_msg)
+
 #endif /*_AMD_APML_H_*/
-- 
2.25.1


  parent reply	other threads:[~2025-04-11 13:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-11 13:31 [PATCH v8 00/10] misc: Move AMD side band interface(SBI) functionality Akshay Gupta
2025-04-11 13:31 ` [PATCH v8 01/10] hwmon/misc: amd-sbi: Move core sbrmi from hwmon to misc Akshay Gupta
2025-04-11 13:31 ` [PATCH v8 02/10] misc: amd-sbi: Move protocol functionality to core file Akshay Gupta
2025-04-11 13:31 ` [PATCH v8 03/10] misc: amd-sbi: Move hwmon device sensor as separate entity Akshay Gupta
2025-04-11 13:31 ` [PATCH v8 04/10] misc: amd-sbi: Use regmap subsystem Akshay Gupta
2025-04-11 13:31 ` [PATCH v8 05/10] misc: amd-sbi: Optimize the wait condition for mailbox command completion Akshay Gupta
2025-04-11 13:31 ` [PATCH v8 06/10] misc: amd-sbi: Add support for AMD_SBI IOCTL Akshay Gupta
2025-04-11 13:31 ` [PATCH v8 07/10] misc: amd-sbi: Add support for CPUID protocol Akshay Gupta
2025-04-11 13:31 ` [PATCH v8 08/10] misc: amd-sbi: Add support for read MCA register protocol Akshay Gupta
2025-04-11 13:31 ` Akshay Gupta [this message]
2025-04-14  5:55   ` [PATCH v8 09/10] misc: amd-sbi: Add support for register xfer kernel test robot
2025-04-11 13:31 ` [PATCH v8 10/10] misc: amd-sbi: Add document for AMD SB IOCTL description Akshay Gupta
2025-04-11 13:51 ` [PATCH v8 00/10] misc: Move AMD side band interface(SBI) functionality Arnd Bergmann
2025-04-15  9:35   ` Gupta, Akshay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250411133122.1806991-10-akshay.gupta@amd.com \
    --to=akshay.gupta@amd.com \
    --cc=anand.umarji@amd.com \
    --cc=arnd@arndb.de \
    --cc=gautham.shenoy@amd.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mario.limonciello@amd.com \
    --cc=naveenkrishna.chatradhi@amd.com \
    --cc=shyam-sundar.s-k@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®