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

Erick Henrique erick.am em usp.br
Qua Abr 15 16:56:00 -03 2026


From: Erick Henrique <erick.am em usp.br>

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.

Signed-off-by: Erick Henrique <erick.am em usp.br>
Co-developed-by: Lais Alves Da Costa <laisalvesc em usp.br>
Signed-off-by: Lais Alves Da Costa <laisalvesc em usp.br>
---
 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(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 2956e45c9..3ac7d9305 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -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;
+
+}
+
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
index a0cf0a3b4..a180d1903 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
@@ -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) {
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index 5097de940..767887d7d 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -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,
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
index 65c33823a..aadebb4d2 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
@@ -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



Mais detalhes sobre a lista de discussão kernel