with wire up the DRM_AMDGPU_PROFILER ioctl introduced in the
UAPI patch by registering amdgpu_profiler_ioctl() as its
handler with DRM_AUTH|DRM_RENDER_ALLOW permissions.

Implement the first operation AMDGPU_PROFILER_VERSION, which
returns the profiler UAPI version to user space by packing
the major version into bits 31:16 and the minor version into
bits 15:0 of the args->version field. Unknown operations
return -EINVAL.

A helper macro AMDGPU_XCP_ID() is added to normalize the XCP
partition ID for display purposes: AMDGPU_XCP_NO_PARTITION
(device not yet initialized) is mapped to 0, while valid
partition IDs are passed through unchanged.

Signed-off-by: James Zhu <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c      |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 25 ++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h |  3 +++
 3 files changed, 29 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 52423c98ebf5..dcd36a6d2930 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -3064,6 +3064,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
        DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_SIGNAL, amdgpu_userq_signal_ioctl, 
DRM_AUTH|DRM_RENDER_ALLOW),
        DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_WAIT, amdgpu_userq_wait_ioctl, 
DRM_AUTH|DRM_RENDER_ALLOW),
        DRM_IOCTL_DEF_DRV(AMDGPU_GEM_LIST_HANDLES, 
amdgpu_gem_list_handles_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
+       DRM_IOCTL_DEF_DRV(AMDGPU_PROFILER, amdgpu_profiler_ioctl, 
DRM_AUTH|DRM_RENDER_ALLOW),
 };
 
 static const struct drm_driver amdgpu_kms_driver = {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c
index d2cf0520c6f1..bed43ea8bcc3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c
@@ -32,6 +32,31 @@
 #define AMDGPU_PROFILER_VERSION_MAJOR 1
 #define AMDGPU_PROFILER_VERSION_MINOR 1
 
+int amdgpu_profiler_ioctl(
+               struct drm_device *dev,
+               void *data,
+               struct drm_file *filp)
+{
+       struct amdgpu_fpriv *fpriv = filp->driver_priv;
+       struct amdgpu_device *adev = fpriv_to_adev(fpriv);
+       struct drm_amdgpu_profiler_args *args = data;
+
+       dev_dbg(adev->dev, "Profiler IOCTL op %d on render node %d xcp %d",
+               args->op, adev->ddev.render->index, 
AMDGPU_XCP_ID(fpriv->xcp_id));
+
+       switch (args->op) {
+       case AMDGPU_PROFILER_VERSION:
+               args->version = AMDGPU_PROFILER_VERSION_MAJOR << 16 |
+                                       AMDGPU_PROFILER_VERSION_MINOR;
+               return 0;
+
+       default:
+               dev_dbg(adev->dev, "Invalid option: %i", args->op);
+       }
+
+       return -EINVAL;
+}
+
 int amdgpu_profiler_mgr_init(
                struct amdgpu_profiler_mgr *prof_mgr,
                struct amdgpu_fpriv *fpriv)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h
index 2dfc0b1bb207..779cfe19fda2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h
@@ -25,6 +25,7 @@
 #ifndef AMDGPU_PROFILER_H_
 #define AMDGPU_PROFILER_H_
 
+#define AMDGPU_XCP_ID(x) (x == AMDGPU_XCP_NO_PARTITION ? 0 : x)
 #define fpriv_to_prof_mgr(fpriv) (&(fpriv)->userq_mgr.adev->prof_mgr)
 #define fpriv_to_adev(fpriv) ((fpriv)->userq_mgr.adev)
 
@@ -40,6 +41,8 @@ struct amdgpu_profiler_mgr {
        struct amdgpu_profiler_xcp_mgr prof_xcp_mgr[MAX_XCP];
 };
 
+int amdgpu_profiler_ioctl(struct drm_device *dev, void *data,
+                                       struct drm_file *filp);
 int amdgpu_profiler_mgr_init(struct amdgpu_profiler_mgr *prof_mgr,
                                        struct amdgpu_fpriv *fpriv);
 void amdgpu_profiler_mgr_fini(struct amdgpu_profiler_mgr *prof_mgr,
-- 
2.34.1

Reply via email to