Provide a helper to retrieve the per-file eventfd manager associated
with a user queue manager.

The helper resolves the eventfd manager through the existing drm_file ->
driver_priv link instead of storing an additional eventfd manager
pointer inside amdgpu_userq_mgr.

This keeps the ownership model unchanged and avoids maintaining
duplicate references between USERQ and EVENTFD state.

v10: (per Christian)
- Remove the extra eventfd_mgr pointer from userq_mgr.
- Use the existing drm_file link to access the eventfd manager when
  needed.

Cc: Alex Deucher <[email protected]>
Suggested-by: Christian König <[email protected]>
Signed-off-by: Srinivasan Shanmugam <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 16 ++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index 99c711ddf71e..376813e9623f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -34,6 +34,22 @@
 #include "amdgpu_hmm.h"
 #include "amdgpu_userq_fence.h"
 
+/*
+ * Get the per-file eventfd manager associated with this userq manager.
+ */
+struct amdgpu_eventfd_mgr *
+amdgpu_userq_eventfd_mgr(struct amdgpu_userq_mgr *userq_mgr)
+{
+       struct amdgpu_fpriv *fpriv;
+
+       if (!userq_mgr || !userq_mgr->file)
+               return NULL;
+
+       fpriv = userq_mgr->file->driver_priv;
+
+       return fpriv ? &fpriv->eventfd_mgr : NULL;
+}
+
 u32 amdgpu_userq_get_supported_ip_mask(struct amdgpu_device *adev)
 {
        int i;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
index d1751febaefe..8c4b55517a0a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
@@ -183,4 +183,6 @@ int amdgpu_userq_input_va_validate(struct amdgpu_device 
*adev,
 
 void amdgpu_userq_gem_va_unmap_validate(struct amdgpu_device *adev,
                                        struct amdgpu_bo_va_mapping *mapping);
+struct amdgpu_eventfd_mgr *
+amdgpu_userq_eventfd_mgr(struct amdgpu_userq_mgr *userq_mgr);
 #endif
-- 
2.34.1

Reply via email to