drm/amd/pm: Add debugfs info for STB
authorAndrey Grodzovsky <andrey.grodzovsky@amd.com>
Fri, 24 Sep 2021 18:24:37 +0000 (14:24 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 22 Nov 2021 19:58:59 +0000 (14:58 -0500)
Add debugfs hook.

Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Reviewed-by: Luben Tuikov <luben.tuikov@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/pm/amdgpu_pm.c
drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

index 41472ed992530c8c4caa14fb63b1cc69188e7203..49df4c20f09ecdeff222dbd9a02f3f22b75e9a27 100644 (file)
@@ -3759,5 +3759,7 @@ void amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
                                         adev,
                                         &amdgpu_debugfs_pm_prv_buffer_fops,
                                         adev->pm.smu_prv_buffer_size);
+
+       amdgpu_smu_stb_debug_fs_init(adev);
 #endif
 }
index 4301403af76198e26ed032cc999b795c16fcaa09..f738f7dc20c90c52ab8c9272266834efec9124d7 100644 (file)
@@ -1420,6 +1420,7 @@ int smu_wait_for_event(struct amdgpu_device *adev, enum smu_event_type event,
                       uint64_t event_arg);
 int smu_get_ecc_info(struct smu_context *smu, void *umc_ecc);
 int smu_stb_collect_info(struct smu_context *smu, void *buff, uint32_t size);
+void amdgpu_smu_stb_debug_fs_init(struct amdgpu_device *adev);
 
 #endif
 #endif
index 97bafba4c5c9f4f4fb749aa5afb7f55e590c8a0c..f5e739d40b04672265081a4ce4c62c30f6bee04a 100644 (file)
@@ -3193,3 +3193,89 @@ int smu_stb_collect_info(struct smu_context *smu, void *buf, uint32_t size)
         */
        return smu->ppt_funcs->stb_collect_info(smu, buf, size);
 }
+
+#if defined(CONFIG_DEBUG_FS)
+
+static int smu_stb_debugfs_open(struct inode *inode, struct file *filp)
+{
+       struct amdgpu_device *adev = filp->f_inode->i_private;
+       struct smu_context *smu = &adev->smu;
+       unsigned char *buf;
+       int r;
+
+       buf = kvmalloc_array(smu->stb_context.stb_buf_size, sizeof(*buf), GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
+       r = smu_stb_collect_info(smu, buf, smu->stb_context.stb_buf_size);
+       if (r)
+               goto out;
+
+       filp->private_data = buf;
+
+       return 0;
+
+out:
+       kvfree(buf);
+       return r;
+}
+
+static ssize_t smu_stb_debugfs_read(struct file *filp, char __user *buf, size_t size,
+                               loff_t *pos)
+{
+       struct amdgpu_device *adev = filp->f_inode->i_private;
+       struct smu_context *smu = &adev->smu;
+
+
+       if (!filp->private_data)
+               return -EINVAL;
+
+       return simple_read_from_buffer(buf,
+                                      size,
+                                      pos, filp->private_data,
+                                      smu->stb_context.stb_buf_size);
+}
+
+static int smu_stb_debugfs_release(struct inode *inode, struct file *filp)
+{
+       kvfree(filp->private_data);
+       filp->private_data = NULL;
+
+       return 0;
+}
+
+/*
+ * We have to define not only read method but also
+ * open and release because .read takes up to PAGE_SIZE
+ * data each time so and so is invoked multiple times.
+ *  We allocate the STB buffer in .open and release it
+ *  in .release
+ */
+static const struct file_operations smu_stb_debugfs_fops = {
+       .owner = THIS_MODULE,
+       .open = smu_stb_debugfs_open,
+       .read = smu_stb_debugfs_read,
+       .release = smu_stb_debugfs_release,
+       .llseek = default_llseek,
+};
+
+#endif
+
+void amdgpu_smu_stb_debug_fs_init(struct amdgpu_device *adev)
+{
+#if defined(CONFIG_DEBUG_FS)
+
+       struct smu_context *smu = &adev->smu;
+
+       if (!smu->stb_context.stb_buf_size)
+               return;
+
+       debugfs_create_file_size("amdgpu_smu_stb_dump",
+                           S_IRUSR,
+                           adev_to_drm(adev)->primary->debugfs_root,
+                           adev,
+                           &smu_stb_debugfs_fops,
+                           smu->stb_context.stb_buf_size);
+#endif
+
+}