AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Deucher <alexander.deucher@amd.com>
To: <amd-gfx@lists.freedesktop.org>, <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Subject: [PATCH 08/23] drm/amdgpu/sdma5.2: add tlb invalidation buffer func callback
Date: Fri, 11 Sep 2026 13:55:29 -0400	[thread overview]
Message-ID: <20260911175544.1314467-9-alexander.deucher@amd.com> (raw)
In-Reply-To: <20260911175544.1314467-1-alexander.deucher@amd.com>

Will be used for TLB invalidation.

Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 49 ++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c b/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c
index 35cdf6c149f86..a10086de35957 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c
@@ -2038,6 +2038,52 @@ static void sdma_v5_2_emit_fill_buffer(struct amdgpu_ib *ib,
 	ib->ptr[ib->length_dw++] = byte_count - 1;
 }
 
+/**
+ * sdma_v5_2_emit_tlb_inv - Invalidate TLB using the sDMA engine
+ *
+ * @adev: amdgpu device structure
+ * @ib: indirect buffer to fill
+ * @vmid: vmid to target
+ * @vmhub: vmhub to target
+ * @eng: invalidation engine to use
+ * @flush_type: type of flush (lightweight, heavyweight)
+ * @xcc_inst: XCC to target
+ *
+ * Invalidate TLB using the DMA engine.
+ */
+static void sdma_v5_2_emit_tlb_inv(struct amdgpu_device *adev,
+				   struct amdgpu_ib *ib,
+				   unsigned int vmid,
+				   u32 vmhub,
+				   u32 eng,
+				   u32 flush_type,
+				   u32 xcc_inst)
+{
+	struct amdgpu_vmhub *hub = &adev->vmhub[vmhub];
+	u32 inv_req = hub->vmhub_funcs->get_invalidate_req(vmid, flush_type);
+	u32 mmhub_eng, gfxhub_eng;
+
+	if (AMDGPU_IS_GFXHUB(vmhub)) {
+		mmhub_eng = 0x1f;
+		gfxhub_eng = eng;
+	} else {
+		mmhub_eng = eng;
+		gfxhub_eng = 0x1f;
+	}
+
+	/* Trigger invalidation. */
+	ib->ptr[ib->length_dw++] =
+		(SDMA_PKT_VM_INVALIDATION_HEADER_OP(SDMA_OP_POLL_REGMEM) |
+		 SDMA_PKT_VM_INVALIDATION_HEADER_SUB_OP(SDMA_SUBOP_VM_INVALIDATION) |
+		 SDMA_PKT_VM_INVALIDATION_HEADER_GFX_ENG_ID(gfxhub_eng) |
+		 SDMA_PKT_VM_INVALIDATION_HEADER_MM_ENG_ID(mmhub_eng));
+	ib->ptr[ib->length_dw++] = inv_req;
+	ib->ptr[ib->length_dw++] = 0xFFFFFFFF;
+	ib->ptr[ib->length_dw++] =
+		(SDMA_PKT_VM_INVALIDATION_ADDRESSRANGEHI_INVALIDATEACK(1 << vmid) |
+		 SDMA_PKT_VM_INVALIDATION_ADDRESSRANGEHI_ADDRESSRANGEHI(0x1F));
+}
+
 static const struct amdgpu_buffer_funcs sdma_v5_2_buffer_funcs = {
 	.copy_max_bytes = 1 << 30,
 	.copy_num_dw = 7,
@@ -2046,6 +2092,9 @@ static const struct amdgpu_buffer_funcs sdma_v5_2_buffer_funcs = {
 	.fill_max_bytes = 1 << 30, /* HW supports 1 << 30, but PAL uses 1 << 22 */
 	.fill_num_dw = 5,
 	.emit_fill_buffer = sdma_v5_2_emit_fill_buffer,
+
+	.tlb_inv_num_dw = 4,
+	.emit_tlb_inv = sdma_v5_2_emit_tlb_inv,
 };
 
 static void sdma_v5_2_set_buffer_funcs(struct amdgpu_device *adev)
-- 
2.55.0


  parent reply	other threads:[~2026-09-11 17:56 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 17:55 [PATCH V3 00/23] Rework GPU TLB invalidation Alex Deucher
2026-09-11 17:55 ` [PATCH 01/23] drm/amdgpu/gmc9: disallow gfxoff around TLB flushes Alex Deucher
2026-09-11 17:55 ` [PATCH 02/23] drm/amdgpu/gmc10: " Alex Deucher
2026-09-11 17:55 ` [PATCH 03/23] drm/amdgpu/gmc11: " Alex Deucher
2026-09-11 17:55 ` [PATCH 04/23] drm/amdgpu/gmc12: " Alex Deucher
2026-09-11 17:55 ` [PATCH 05/23] drm/amdgpu/gmc9: set vmhub funcs for gfxhub and mmhub Alex Deucher
2026-09-11 17:55 ` [PATCH 06/23] drm/amdgpu: add a buffer funcs callback for TLB invalidation Alex Deucher
2026-09-11 17:55 ` [PATCH 07/23] drm/amdgpu/sdma5.0: add tlb invalidation buffer func callback Alex Deucher
2026-09-11 17:55 ` Alex Deucher [this message]
2026-09-11 17:55 ` [PATCH 09/23] drm/amdgpu/sdma6: " Alex Deucher
2026-09-11 17:55 ` [PATCH 10/23] drm/amdgpu/sdma7: " Alex Deucher
2026-09-11 17:55 ` [PATCH 11/23] drm/amdgpu: add tlb invalidation method enum Alex Deucher
2026-09-11 17:55 ` [PATCH 12/23] drm/amdgpu: plumb tlb inv method in amdgpu_gmc_flush_gpu_tlb() Alex Deucher
2026-09-11 17:55 ` [PATCH 13/23] drm/amdgpu: uplevel reset check " Alex Deucher
2026-09-11 17:55 ` [PATCH 14/23] drm/amdgpu/gmc: add new callback to lookup vmid to pasid mapping Alex Deucher
2026-09-11 17:55 ` [PATCH 15/23] drm/amdgpu: add a gmc callback for the inv semaphore Alex Deucher
2026-09-11 17:55 ` [PATCH 16/23] drm/amdgpu/gmc: rework pasid flushing Alex Deucher
2026-09-11 17:55 ` [PATCH 17/23] drm/amdgpu/gmc: add helpers for various tlb inv functions Alex Deucher
2026-09-11 17:55 ` [PATCH 18/23] drm/amdgpu/gmc10: use SDMA for gart TLB invalidation Alex Deucher
2026-09-11 17:55 ` [PATCH 19/23] drm/amdgpu/gmc11: " Alex Deucher
2026-09-11 17:55 ` [PATCH 20/23] drm/amdgpu/gmc12: " Alex Deucher
2026-09-11 17:55 ` [PATCH 21/23] drm/amdgpu/gmc10: use SDMA for pasid " Alex Deucher
2026-09-11 17:55 ` [PATCH 22/23] drm/amdgpu/gmc11: " Alex Deucher
2026-09-11 17:55 ` [PATCH 23/23] drm/amdgpu/gmc12: use MES or " Alex Deucher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260911175544.1314467-9-alexander.deucher@amd.com \
    --to=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox