<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I think it would be good to put the IOCTL structures in their own header to make it easier to share with umr. No need to put it in uapi area though. We also need a umr branch that utilizes this to upstream the changes.<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Alex</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Tom St Denis <tom.stdenis@amd.com><br>
<b>Sent:</b> Wednesday, August 25, 2021 9:09 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> StDenis, Tom <Tom.StDenis@amd.com><br>
<b>Subject:</b> [PATCH] drm/amd/amdgpu: New debugfs interface for MMIO registers (v4)</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">This new debugfs interface uses an IOCTL interface in order to pass<br>
along state information like SRBM and GRBM bank switching. This<br>
new interface also allows a full 32-bit MMIO address range which<br>
the previous didn't. With this new design we have room to grow<br>
the flexibility of the file as need be.<br>
<br>
(v2): Move read/write to .read/.write, fix style, add comment<br>
for IOCTL data structure<br>
<br>
(v3): C style comments<br>
<br>
(v4): use u32 in struct and remove offset variable<br>
<br>
Signed-off-by: Tom St Denis <tom.stdenis@amd.com><br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 158 ++++++++++++++++++++<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h | 29 ++++<br>
2 files changed, 187 insertions(+)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c<br>
index 277128846dd1..6450f210f6c7 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c<br>
@@ -279,6 +279,152 @@ static ssize_t amdgpu_debugfs_regs_write(struct file *f, const char __user *buf,<br>
return amdgpu_debugfs_process_reg_op(false, f, (char __user *)buf, size, pos);<br>
}<br>
<br>
+static int amdgpu_debugfs_regs2_open(struct inode *inode, struct file *file)<br>
+{<br>
+ struct amdgpu_debugfs_regs2_data *rd;<br>
+<br>
+ rd = kzalloc(sizeof *rd, GFP_KERNEL);<br>
+ if (!rd)<br>
+ return -ENOMEM;<br>
+ rd->adev = file_inode(file)->i_private;<br>
+ file->private_data = rd;<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
+static int amdgpu_debugfs_regs2_release(struct inode *inode, struct file *file)<br>
+{<br>
+ kfree(file->private_data);<br>
+ return 0;<br>
+}<br>
+<br>
+static ssize_t amdgpu_debugfs_regs2_op(struct file *f, char __user *buf, u32 offset, size_t size, int write_en)<br>
+{<br>
+ struct amdgpu_debugfs_regs2_data *rd = f->private_data;<br>
+ struct amdgpu_device *adev = rd->adev;<br>
+ ssize_t result = 0;<br>
+ int r;<br>
+ uint32_t value;<br>
+<br>
+ if (size & 0x3 || offset & 0x3)<br>
+ return -EINVAL;<br>
+<br>
+ if (rd->id.use_grbm) {<br>
+ if (rd->id.grbm.se == 0x3FF)<br>
+ rd->id.grbm.se = 0xFFFFFFFF;<br>
+ if (rd->id.grbm.sh == 0x3FF)<br>
+ rd->id.grbm.sh = 0xFFFFFFFF;<br>
+ if (rd->id.grbm.instance == 0x3FF)<br>
+ rd->id.grbm.instance = 0xFFFFFFFF;<br>
+ }<br>
+<br>
+ r = pm_runtime_get_sync(adev_to_drm(adev)->dev);<br>
+ if (r < 0) {<br>
+ pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
+ return r;<br>
+ }<br>
+<br>
+ r = amdgpu_virt_enable_access_debugfs(adev);<br>
+ if (r < 0) {<br>
+ pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
+ return r;<br>
+ }<br>
+<br>
+ if (rd->id.use_grbm) {<br>
+ if ((rd->id.grbm.sh != 0xFFFFFFFF && rd->id.grbm.sh >= adev->gfx.config.max_sh_per_se) ||<br>
+ (rd->id.grbm.se != 0xFFFFFFFF && rd->id.grbm.se >= adev->gfx.config.max_shader_engines)) {<br>
+ pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
+ pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
+ amdgpu_virt_disable_access_debugfs(adev);<br>
+ return -EINVAL;<br>
+ }<br>
+ mutex_lock(&adev->grbm_idx_mutex);<br>
+ amdgpu_gfx_select_se_sh(adev, rd->id.grbm.se,<br>
+ rd->id.grbm.sh,<br>
+ rd->id.grbm.instance);<br>
+ }<br>
+<br>
+ if (rd->id.use_srbm) {<br>
+ mutex_lock(&adev->srbm_mutex);<br>
+ amdgpu_gfx_select_me_pipe_q(adev, rd->id.srbm.me, rd->id.srbm.pipe,<br>
+ rd->id.srbm.queue, rd->id.srbm.vmid);<br>
+ }<br>
+<br>
+ if (rd->id.pg_lock)<br>
+ mutex_lock(&adev->pm.mutex);<br>
+<br>
+ while (size) {<br>
+ if (!write_en) {<br>
+ value = RREG32(offset >> 2);<br>
+ r = put_user(value, (uint32_t *)buf);<br>
+ } else {<br>
+ r = get_user(value, (uint32_t *)buf);<br>
+ if (!r)<br>
+ amdgpu_mm_wreg_mmio_rlc(adev, offset >> 2, value);<br>
+ }<br>
+ if (r) {<br>
+ result = r;<br>
+ goto end;<br>
+ }<br>
+ offset += 4;<br>
+ size -= 4;<br>
+ result += 4;<br>
+ buf += 4;<br>
+ }<br>
+end:<br>
+ if (rd->id.use_grbm) {<br>
+ amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);<br>
+ mutex_unlock(&adev->grbm_idx_mutex);<br>
+ }<br>
+<br>
+ if (rd->id.use_srbm) {<br>
+ amdgpu_gfx_select_me_pipe_q(adev, 0, 0, 0, 0);<br>
+ mutex_unlock(&adev->srbm_mutex);<br>
+ }<br>
+<br>
+ if (rd->id.pg_lock)<br>
+ mutex_unlock(&adev->pm.mutex);<br>
+<br>
+ /* in umr (the likely user of this) flags are set per file operation<br>
+ * which means they're never "unset" explicitly. To avoid breaking<br>
+ * this convention we unset the flags after each operation<br>
+ * flags are for a single call (need to be set for every read/write) */<br>
+ rd->id.use_grbm = 0;<br>
+ rd->id.use_srbm = 0;<br>
+ rd->id.pg_lock = 0;<br>
+<br>
+ pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
+ pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
+<br>
+ amdgpu_virt_disable_access_debugfs(adev);<br>
+ return result;<br>
+}<br>
+<br>
+static long amdgpu_debugfs_regs2_ioctl(struct file *f, unsigned int cmd, unsigned long data)<br>
+{<br>
+ struct amdgpu_debugfs_regs2_data *rd = f->private_data;<br>
+<br>
+ switch (cmd) {<br>
+ case AMDGPU_DEBUGFS_REGS2_IOC_SET_STATE:<br>
+ if (copy_from_user(&rd->id, (struct amdgpu_debugfs_regs2_iocdata *)data, sizeof rd->id))<br>
+ return -EINVAL;<br>
+ break;<br>
+ default:<br>
+ return -EINVAL;<br>
+ }<br>
+ return 0;<br>
+}<br>
+<br>
+static ssize_t amdgpu_debugfs_regs2_read(struct file *f, char __user *buf, size_t size, loff_t *pos)<br>
+{<br>
+ return amdgpu_debugfs_regs2_op(f, buf, *pos, size, 0);<br>
+}<br>
+<br>
+static ssize_t amdgpu_debugfs_regs2_write(struct file *f, const char __user *buf, size_t size, loff_t *pos)<br>
+{<br>
+ return amdgpu_debugfs_regs2_op(f, (char __user *)buf, *pos, size, 1);<br>
+}<br>
+<br>
<br>
/**<br>
* amdgpu_debugfs_regs_pcie_read - Read from a PCIE register<br>
@@ -1091,6 +1237,16 @@ static ssize_t amdgpu_debugfs_gfxoff_read(struct file *f, char __user *buf,<br>
return result;<br>
}<br>
<br>
+static const struct file_operations amdgpu_debugfs_regs2_fops = {<br>
+ .owner = THIS_MODULE,<br>
+ .unlocked_ioctl = amdgpu_debugfs_regs2_ioctl,<br>
+ .read = amdgpu_debugfs_regs2_read,<br>
+ .write = amdgpu_debugfs_regs2_write,<br>
+ .open = amdgpu_debugfs_regs2_open,<br>
+ .release = amdgpu_debugfs_regs2_release,<br>
+ .llseek = default_llseek<br>
+};<br>
+<br>
static const struct file_operations amdgpu_debugfs_regs_fops = {<br>
.owner = THIS_MODULE,<br>
.read = amdgpu_debugfs_regs_read,<br>
@@ -1148,6 +1304,7 @@ static const struct file_operations amdgpu_debugfs_gfxoff_fops = {<br>
<br>
static const struct file_operations *debugfs_regs[] = {<br>
&amdgpu_debugfs_regs_fops,<br>
+ &amdgpu_debugfs_regs2_fops,<br>
&amdgpu_debugfs_regs_didt_fops,<br>
&amdgpu_debugfs_regs_pcie_fops,<br>
&amdgpu_debugfs_regs_smc_fops,<br>
@@ -1160,6 +1317,7 @@ static const struct file_operations *debugfs_regs[] = {<br>
<br>
static const char *debugfs_regs_names[] = {<br>
"amdgpu_regs",<br>
+ "amdgpu_regs2",<br>
"amdgpu_regs_didt",<br>
"amdgpu_regs_pcie",<br>
"amdgpu_regs_smc",<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h<br>
index 141a8474e24f..dcf20859c866 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h<br>
@@ -22,6 +22,8 @@<br>
* OTHER DEALINGS IN THE SOFTWARE.<br>
*<br>
*/<br>
+#include <linux/ioctl.h><br>
+#include <uapi/drm/amdgpu_drm.h><br>
<br>
/*<br>
* Debugfs<br>
@@ -38,3 +40,30 @@ void amdgpu_debugfs_fence_init(struct amdgpu_device *adev);<br>
void amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);<br>
void amdgpu_debugfs_gem_init(struct amdgpu_device *adev);<br>
int amdgpu_debugfs_wait_dump(struct amdgpu_device *adev);<br>
+<br>
+/*<br>
+ * MMIO debugfs IOCTL structure<br>
+ */<br>
+struct amdgpu_debugfs_regs2_iocdata {<br>
+ __u32 use_srbm, use_grbm, pg_lock;<br>
+ struct {<br>
+ __u32 se, sh, instance;<br>
+ } grbm;<br>
+ struct {<br>
+ __u32 me, pipe, queue, vmid;<br>
+ } srbm;<br>
+};<br>
+<br>
+/*<br>
+ * MMIO debugfs state data (per file* handle)<br>
+ */<br>
+struct amdgpu_debugfs_regs2_data {<br>
+ struct amdgpu_device *adev;<br>
+ struct amdgpu_debugfs_regs2_iocdata id;<br>
+};<br>
+<br>
+enum AMDGPU_DEBUGFS_REGS2_CMDS {<br>
+ AMDGPU_DEBUGFS_REGS2_CMD_SET_STATE=0,<br>
+};<br>
+<br>
+#define AMDGPU_DEBUGFS_REGS2_IOC_SET_STATE _IOWR(0x20, AMDGPU_DEBUGFS_REGS2_CMD_SET_STATE, struct amdgpu_debugfs_regs2_iocdata)<br>
-- <br>
2.31.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>