Skip to contentSkip to conversation

drm/amdgpu: Deduplicate eop_irq v11/v12 functions to use helper

PATCH In review Erick Henrique 2 participants 2 messages Apr 17

Subsystems (2)
lore
Share & tools
lore
maintainer
#1 lore raw
In reply to Erick Henrique
Quoted 38 lines · Erick Henrique

From: Erick Henrique De Araujo Moreira <[email protected]>

Identical code implementations to handle the ISR for the EOP signal from the graphics and compute engines of AMD GPUS on the gfx_v11_0_eop_irq() and gfx_v12_0_eop_irq() functions.

Introduce a shared helper amdgpu_gfx_eop_irq() and convert the EOP implementations to use it.

This reduces duplication and improves maintainability without changing behaviour.

No functional changes intended.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 55 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h |  4 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c  | 48 +--------------------
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c  | 48 +--------------------
 4 files changed, 61 insertions(+), 94 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1 -0
index 2956e45c9..3ac7d9305 100644
@@ -34,6 +34,7 @@
 #include "amdgpu_xcp.h"
 #include "amdgpu_xgmi.h"
 #include "amdgpu_mes.h"
+#include "amdgpu_userq_fence.h"
 #include "nvd.h"
 
 /* delay 0.1 second to enable gfx off feature */
@@ -2684,3 +2685,57 @@ void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev)
 #endif

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev) · line 2695

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +8 -0
 }
 
+int amdgpu_gfx_eop_irq(struct amdgpu_device *adev,
+                            struct amdgpu_irq_src *source,
+                            struct amdgpu_iv_entry *entry)
+{
+       u32 doorbell_offset = entry->src_data[0];
+               u8 me_id, pipe_id, queue_id;
+               struct amdgpu_ring *ring;
+               int i;

The coding style here looks completely broken.

Additional to that the separation was intentional.

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +4 -0
+
+               DRM_DEBUG("IH: CP EOP\n");
+
+               if (adev->enable_mes && doorbell_offset) {
 

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev) · line 2708

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +9 -0
 
+                       struct xarray *xa = &adev->userq_doorbell_xa;
+                       struct amdgpu_usermode_queue *queue;
+                       unsigned long flags;
+
+                       xa_lock_irqsave(xa, flags);
+                       queue = xa_load(xa, doorbell_offset);
+                       if (queue)
+                               amdgpu_userq_fence_driver_process(queue->fence_drv);
+                       xa_unlock_irqrestore(xa, flags);

What we could do is to move this chunk into a common function, there should be multiple copies of it in the SDMA code as well.

Regards,
Christian.

Quoted 169 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +33 -0
+               } else {
+                       me_id = (entry->ring_id & 0x0c) >> 2;
+                       pipe_id = (entry->ring_id & 0x03) >> 0;
+                       queue_id = (entry->ring_id & 0x70) >> 4;
+
+                       switch (me_id) {
+                       case 0:
+                               if (pipe_id == 0)
+                                       amdgpu_fence_process(&adev->gfx.gfx_ring[0]);
+                               else
+                                       amdgpu_fence_process(&adev->gfx.gfx_ring[1]);
+                               break;
+                       case 1:
+                       case 2:
+                               for (i = 0; i < adev->gfx.num_compute_rings; i++) {
+                                       ring = &adev->gfx.compute_ring[i];
+                                       /* Per-queue interrupt is supported for MEC starting from VI.
+                                       * The interrupt can only be enabled/disabled per pipe instead
+                                       * of per queue.
+                                       */
+                                       if ((ring->me == me_id) &&
+                                               (ring->pipe == pipe_id) &&
+                                               (ring->queue == queue_id))
+                                               amdgpu_fence_process(ring);
+                               }
+                               break;
+                       }
+               }
+
+               return 0;
+
+}
+
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +4 -0
index a0cf0a3b4..a180d1903 100644
@@ -664,6 +664,10 @@ void amdgpu_gfx_csb_preamble_end(u32 *buffer, u32 count);
 void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
 void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
 
+int amdgpu_gfx_eop_irq(struct amdgpu_device *adev,
+                            struct amdgpu_irq_src *source,
+                            struct amdgpu_iv_entry *entry);
+
 static inline const char *amdgpu_gfx_compute_mode_desc(int mode)
 {
        switch (mode) {
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1 -47
index 5097de940..767887d7d 100644
@@ -6494,53 +6494,7 @@ static int gfx_v11_0_eop_irq(struct amdgpu_device *adev,
                             struct amdgpu_irq_src *source,
                             struct amdgpu_iv_entry *entry)
 {
-       u32 doorbell_offset = entry->src_data[0];
-       u8 me_id, pipe_id, queue_id;
-       struct amdgpu_ring *ring;
-       int i;
-
-       DRM_DEBUG("IH: CP EOP\n");
-
-       if (adev->enable_mes && doorbell_offset) {
-               struct amdgpu_usermode_queue *queue;
-               struct xarray *xa = &adev->userq_doorbell_xa;
-               unsigned long flags;
-
-               xa_lock_irqsave(xa, flags);
-               queue = xa_load(xa, doorbell_offset);
-               if (queue)
-                       amdgpu_userq_fence_driver_process(queue->fence_drv);
-               xa_unlock_irqrestore(xa, flags);
-       } else {
-               me_id = (entry->ring_id & 0x0c) >> 2;
-               pipe_id = (entry->ring_id & 0x03) >> 0;
-               queue_id = (entry->ring_id & 0x70) >> 4;
-
-               switch (me_id) {
-               case 0:
-                       if (pipe_id == 0)
-                               amdgpu_fence_process(&adev->gfx.gfx_ring[0]);
-                       else
-                               amdgpu_fence_process(&adev->gfx.gfx_ring[1]);
-                       break;
-               case 1:
-               case 2:
-                       for (i = 0; i < adev->gfx.num_compute_rings; i++) {
-                               ring = &adev->gfx.compute_ring[i];
-                               /* Per-queue interrupt is supported for MEC starting from VI.
-                                * The interrupt can only be enabled/disabled per pipe instead
-                                * of per queue.
-                                */
-                               if ((ring->me == me_id) &&
-                                   (ring->pipe == pipe_id) &&
-                                   (ring->queue == queue_id))
-                                       amdgpu_fence_process(ring);
-                       }
-                       break;
-               }
-       }
-
-       return 0;
+       return amdgpu_gfx_eop_irq(adev, source, entry);
 }
 
 static int gfx_v11_0_set_priv_reg_fault_state(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1 -48
index 65c33823a..aadebb4d2 100644
@@ -4846,53 +4846,7 @@ static int gfx_v12_0_eop_irq(struct amdgpu_device *adev,
                             struct amdgpu_irq_src *source,
                             struct amdgpu_iv_entry *entry)
 {
-       u32 doorbell_offset = entry->src_data[0];
-       u8 me_id, pipe_id, queue_id;
-       struct amdgpu_ring *ring;
-       int i;
-
-       DRM_DEBUG("IH: CP EOP\n");
-
-       if (adev->enable_mes && doorbell_offset) {
-               struct xarray *xa = &adev->userq_doorbell_xa;
-               struct amdgpu_usermode_queue *queue;
-               unsigned long flags;
-
-               xa_lock_irqsave(xa, flags);
-               queue = xa_load(xa, doorbell_offset);
-               if (queue)
-                       amdgpu_userq_fence_driver_process(queue->fence_drv);
-               xa_unlock_irqrestore(xa, flags);
-       } else {
-               me_id = (entry->ring_id & 0x0c) >> 2;
-               pipe_id = (entry->ring_id & 0x03) >> 0;
-               queue_id = (entry->ring_id & 0x70) >> 4;
-
-               switch (me_id) {
-               case 0:
-                       if (pipe_id == 0)
-                               amdgpu_fence_process(&adev->gfx.gfx_ring[0]);
-                       else
-                               amdgpu_fence_process(&adev->gfx.gfx_ring[1]);
-                       break;
-               case 1:
-               case 2:
-                       for (i = 0; i < adev->gfx.num_compute_rings; i++) {
-                               ring = &adev->gfx.compute_ring[i];
-                               /* Per-queue interrupt is supported for MEC starting from VI.
-                                * The interrupt can only be enabled/disabled per pipe instead
-                                * of per queue.
-                                */
-                               if ((ring->me == me_id) &&
-                                   (ring->pipe == pipe_id) &&
-                                   (ring->queue == queue_id))
-                                       amdgpu_fence_process(ring);
-                       }
-                       break;
-               }
-       }
-
-       return 0;
+       return amdgpu_gfx_eop_irq(adev, source, entry);
 }
 
 static int gfx_v12_0_set_priv_reg_fault_state(struct amdgpu_device *adev,
--

2.43.0

#0 lore raw

PATCH 1/1 drm/amdgpu: Deduplicate eop_irq v11/v12 functions to use helper

From: Erick Henrique De Araujo Moreira <[email protected]>

Identical code implementations to handle the ISR for the EOP signal from the graphics and compute engines of AMD GPUS on the gfx_v11_0_eop_irq() and gfx_v12_0_eop_irq() functions.

Introduce a shared helper amdgpu_gfx_eop_irq() and convert the EOP implementations to use it.

This reduces duplication and improves maintainability without changing behaviour.

No functional changes intended.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 55 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h |  4 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c  | 48 +--------------------
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c  | 48 +--------------------
 4 files changed, 61 insertions(+), 94 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +55 -0
index 2956e45c9..3ac7d9305 100644
@@ -34,6 +34,7 @@
 #include "amdgpu_xcp.h"
 #include "amdgpu_xgmi.h"
 #include "amdgpu_mes.h"
+#include "amdgpu_userq_fence.h"
 #include "nvd.h"
 
 /* delay 0.1 second to enable gfx off feature */
@@ -2684,3 +2685,57 @@ void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev)
 #endif
 }
 
+int amdgpu_gfx_eop_irq(struct amdgpu_device *adev,
+			     struct amdgpu_irq_src *source,
+			     struct amdgpu_iv_entry *entry)
+{
+	u32 doorbell_offset = entry->src_data[0];
+		u8 me_id, pipe_id, queue_id;
+		struct amdgpu_ring *ring;
+		int i;
+
+		DRM_DEBUG("IH: CP EOP\n");
+
+		if (adev->enable_mes && doorbell_offset) {
+			struct xarray *xa = &adev->userq_doorbell_xa;
+			struct amdgpu_usermode_queue *queue;
+			unsigned long flags;
+
+			xa_lock_irqsave(xa, flags);
+			queue = xa_load(xa, doorbell_offset);
+			if (queue)
+				amdgpu_userq_fence_driver_process(queue->fence_drv);
+			xa_unlock_irqrestore(xa, flags);
+		} else {
+			me_id = (entry->ring_id & 0x0c) >> 2;
+			pipe_id = (entry->ring_id & 0x03) >> 0;
+			queue_id = (entry->ring_id & 0x70) >> 4;
+
+			switch (me_id) {
+			case 0:
+				if (pipe_id == 0)
+					amdgpu_fence_process(&adev->gfx.gfx_ring[0]);
+				else
+					amdgpu_fence_process(&adev->gfx.gfx_ring[1]);
+				break;
+			case 1:
+			case 2:
+				for (i = 0; i < adev->gfx.num_compute_rings; i++) {
+					ring = &adev->gfx.compute_ring[i];
+					/* Per-queue interrupt is supported for MEC starting from VI.
+					* The interrupt can only be enabled/disabled per pipe instead
+					* of per queue.
+					*/
+					if ((ring->me == me_id) &&
+						(ring->pipe == pipe_id) &&
+						(ring->queue == queue_id))
+						amdgpu_fence_process(ring);
+				}
+				break;
+			}
+		}
+
+		return 0;
+
+}
+
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +4 -0
index a0cf0a3b4..a180d1903 100644
@@ -664,6 +664,10 @@ void amdgpu_gfx_csb_preamble_end(u32 *buffer, u32 count);
 void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
 void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
 
+int amdgpu_gfx_eop_irq(struct amdgpu_device *adev,
+			     struct amdgpu_irq_src *source,
+			     struct amdgpu_iv_entry *entry);
+
 static inline const char *amdgpu_gfx_compute_mode_desc(int mode)
 {
 	switch (mode) {
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1 -47

54 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1 -47

54 lines not on this page · raw message

Signature · 1 line
2.43.0