Skip to content

Commit cf14128

Browse files
akky16gregkh
authored andcommitted
misc: amd-sbi: Add support for register xfer
- 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 <[email protected]> Signed-off-by: Akshay Gupta <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 69b1ba8 commit cf14128

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

drivers/misc/amd-sbi/rmi-core.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,33 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,
350350
return ret;
351351
}
352352

353+
static int apml_rmi_reg_xfer(struct sbrmi_data *data,
354+
struct apml_reg_xfer_msg __user *arg)
355+
{
356+
struct apml_reg_xfer_msg msg = { 0 };
357+
unsigned int data_read;
358+
int ret;
359+
360+
/* Copy the structure from user */
361+
if (copy_from_user(&msg, arg, sizeof(struct apml_reg_xfer_msg)))
362+
return -EFAULT;
363+
364+
mutex_lock(&data->lock);
365+
if (msg.rflag) {
366+
ret = regmap_read(data->regmap, msg.reg_addr, &data_read);
367+
if (!ret)
368+
msg.data_in_out = data_read;
369+
} else {
370+
ret = regmap_write(data->regmap, msg.reg_addr, msg.data_in_out);
371+
}
372+
373+
mutex_unlock(&data->lock);
374+
375+
if (msg.rflag && !ret)
376+
return copy_to_user(arg, &msg, sizeof(struct apml_reg_xfer_msg));
377+
return ret;
378+
}
379+
353380
static int apml_mailbox_xfer(struct sbrmi_data *data, struct apml_mbox_msg __user *arg)
354381
{
355382
struct apml_mbox_msg msg = { 0 };
@@ -414,6 +441,8 @@ static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
414441
return apml_cpuid_xfer(data, argp);
415442
case SBRMI_IOCTL_MCAMSR_CMD:
416443
return apml_mcamsr_xfer(data, argp);
444+
case SBRMI_IOCTL_REG_XFER_CMD:
445+
return apml_rmi_reg_xfer(data, argp);
417446
default:
418447
return -ENOTTY;
419448
}

include/uapi/misc/amd-apml.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ struct apml_mcamsr_msg {
5858
__u32 pad;
5959
};
6060

61+
struct apml_reg_xfer_msg {
62+
/*
63+
* RMI register address offset
64+
*/
65+
__u16 reg_addr;
66+
/*
67+
* Register data for read/write
68+
*/
69+
__u8 data_in_out;
70+
/*
71+
* Register read or write
72+
*/
73+
__u8 rflag;
74+
};
75+
6176
/*
6277
* AMD sideband interface base IOCTL
6378
*/
@@ -118,4 +133,20 @@ struct apml_mcamsr_msg {
118133
*/
119134
#define SBRMI_IOCTL_MCAMSR_CMD _IOWR(SB_BASE_IOCTL_NR, 2, struct apml_mcamsr_msg)
120135

136+
/**
137+
* DOC: SBRMI_IOCTL_REG_XFER_CMD
138+
*
139+
* @Parameters
140+
*
141+
* @struct apml_reg_xfer_msg
142+
* Pointer to the &struct apml_reg_xfer_msg that will contain the protocol
143+
* information
144+
*
145+
* @Description
146+
* IOCTL command for APML messages using generic _IOWR
147+
* The IOCTL provides userspace access to AMD sideband register xfer protocol
148+
* - Register xfer protocol to get/set hardware register for given offset
149+
*/
150+
#define SBRMI_IOCTL_REG_XFER_CMD _IOWR(SB_BASE_IOCTL_NR, 3, struct apml_reg_xfer_msg)
151+
121152
#endif /*_AMD_APML_H_*/

0 commit comments

Comments
 (0)