From: "John B. Moore" <jbmoore61@gmail.com>
To: alexdeucher@gmail.com
Cc: christian.koenig@amd.com, alexander.deucher@amd.com,
amd-gfx@lists.freedesktop.org,
"John B. Moore" <jbmoore61@gmail.com>
Subject: [PATCH] drm/amdgpu/gfx: extract compute wptr doorbell helpers to amdgpu_gfx.c
Date: Wed, 29 Apr 2026 15:25:18 -0500 [thread overview]
Message-ID: <20260429202518.21956-1-jbmoore61@gmail.com> (raw)
Move the duplicated doorbell-based get_wptr/set_wptr functions from
gfx_v9_0.c, gfx_v10_0.c, gfx_v11_0.c, and gfx_v12_0.c into common
helpers amdgpu_gfx_get_wptr_compute() and amdgpu_gfx_set_wptr_compute()
in amdgpu_gfx.c.
These functions are not HW generation dependent -- the doorbell path is
identical across all four GFX versions:
get: atomic64_read(ring->wptr_cpu_addr)
set: atomic64_set(ring->wptr_cpu_addr) + WDOORBELL64()
The non-doorbell fallback is replaced with WARN_ON_ONCE instead of BUG()
since doorbell is the only supported method on gfx9+ compute rings.
Not touched: gfx_v7_0, gfx_v8_0, gfx_v9_4_3 -- these have different
wptr access patterns (MMIO registers or wb.wb[] offsets).
Suggested-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: John Moore <jbmoore61@gmail.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 39 +++++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 3 ++
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 33 +++------------------
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 34 +++------------------
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 34 +++------------------
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 39 +++----------------------
6 files changed, 58 insertions(+), 124 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 77578ecc6..9e9c5cb81 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -2596,3 +2596,42 @@ void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev)
#endif
}
+/**
+ * amdgpu_gfx_get_wptr_compute - common get_wptr for compute rings using doorbells
+ * @ring: amdgpu_ring pointer
+ *
+ * Read the write pointer from the doorbell-mapped writeback address.
+ * This is HW-agnostic and shared across GFX generations that use
+ * doorbell-based compute queue management.
+ */
+u64 amdgpu_gfx_get_wptr_compute(struct amdgpu_ring *ring)
+{
+ /* XXX check if swapping is necessary on BE */
+ if (ring->use_doorbell)
+ return atomic64_read((atomic64_t *)ring->wptr_cpu_addr);
+
+ WARN_ON_ONCE(1);
+ return 0;
+}
+
+/**
+ * amdgpu_gfx_set_wptr_compute - common set_wptr for compute rings using doorbells
+ * @ring: amdgpu_ring pointer
+ *
+ * Write the write pointer to the doorbell-mapped writeback address and
+ * ring the doorbell. This is HW-agnostic and shared across GFX
+ * generations that use doorbell-based compute queue management.
+ */
+void amdgpu_gfx_set_wptr_compute(struct amdgpu_ring *ring)
+{
+ struct amdgpu_device *adev = ring->adev;
+
+ /* XXX check if swapping is necessary on BE */
+ if (ring->use_doorbell) {
+ atomic64_set((atomic64_t *)ring->wptr_cpu_addr, ring->wptr);
+ WDOORBELL64(ring->doorbell_index, ring->wptr);
+ } else {
+ WARN_ON_ONCE(1);
+ }
+}
+
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
index 585cc8e81..27f6beafb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
@@ -653,6 +653,9 @@ u32 amdgpu_gfx_csb_preamble_start(u32 *buffer);
u32 amdgpu_gfx_csb_data_parser(struct amdgpu_device *adev, u32 *buffer, u32 count);
void amdgpu_gfx_csb_preamble_end(u32 *buffer, u32 count);
+u64 amdgpu_gfx_get_wptr_compute(struct amdgpu_ring *ring);
+void amdgpu_gfx_set_wptr_compute(struct amdgpu_ring *ring);
+
void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
index 1893ceeeb..4c0272cba 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
@@ -8586,31 +8586,6 @@ static u64 gfx_v10_0_ring_get_rptr_compute(struct amdgpu_ring *ring)
return *(uint32_t *)ring->rptr_cpu_addr;
}
-static u64 gfx_v10_0_ring_get_wptr_compute(struct amdgpu_ring *ring)
-{
- u64 wptr;
-
- /* XXX check if swapping is necessary on BE */
- if (ring->use_doorbell)
- wptr = atomic64_read((atomic64_t *)ring->wptr_cpu_addr);
- else
- BUG();
- return wptr;
-}
-
-static void gfx_v10_0_ring_set_wptr_compute(struct amdgpu_ring *ring)
-{
- struct amdgpu_device *adev = ring->adev;
-
- if (ring->use_doorbell) {
- atomic64_set((atomic64_t *)ring->wptr_cpu_addr,
- ring->wptr);
- WDOORBELL64(ring->doorbell_index, ring->wptr);
- } else {
- BUG(); /* only DOORBELL method supported on gfx10 now */
- }
-}
-
static void gfx_v10_0_ring_emit_hdp_flush(struct amdgpu_ring *ring)
{
struct amdgpu_device *adev = ring->adev;
@@ -9881,8 +9856,8 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_compute = {
.nop = PACKET3(PACKET3_NOP, 0x3FFF),
.support_64bit_ptrs = true,
.get_rptr = gfx_v10_0_ring_get_rptr_compute,
- .get_wptr = gfx_v10_0_ring_get_wptr_compute,
- .set_wptr = gfx_v10_0_ring_set_wptr_compute,
+ .get_wptr = amdgpu_gfx_get_wptr_compute,
+ .set_wptr = amdgpu_gfx_set_wptr_compute,
.emit_frame_size =
20 + /* gfx_v10_0_ring_emit_gds_switch */
7 + /* gfx_v10_0_ring_emit_hdp_flush */
@@ -9921,8 +9896,8 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_kiq = {
.nop = PACKET3(PACKET3_NOP, 0x3FFF),
.support_64bit_ptrs = true,
.get_rptr = gfx_v10_0_ring_get_rptr_compute,
- .get_wptr = gfx_v10_0_ring_get_wptr_compute,
- .set_wptr = gfx_v10_0_ring_set_wptr_compute,
+ .get_wptr = amdgpu_gfx_get_wptr_compute,
+ .set_wptr = amdgpu_gfx_set_wptr_compute,
.emit_frame_size =
20 + /* gfx_v10_0_ring_emit_gds_switch */
7 + /* gfx_v10_0_ring_emit_hdp_flush */
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index 427975b5a..404604f2d 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -5818,32 +5818,6 @@ static u64 gfx_v11_0_ring_get_rptr_compute(struct amdgpu_ring *ring)
return *(uint32_t *)ring->rptr_cpu_addr;
}
-static u64 gfx_v11_0_ring_get_wptr_compute(struct amdgpu_ring *ring)
-{
- u64 wptr;
-
- /* XXX check if swapping is necessary on BE */
- if (ring->use_doorbell)
- wptr = atomic64_read((atomic64_t *)ring->wptr_cpu_addr);
- else
- BUG();
- return wptr;
-}
-
-static void gfx_v11_0_ring_set_wptr_compute(struct amdgpu_ring *ring)
-{
- struct amdgpu_device *adev = ring->adev;
-
- /* XXX check if swapping is necessary on BE */
- if (ring->use_doorbell) {
- atomic64_set((atomic64_t *)ring->wptr_cpu_addr,
- ring->wptr);
- WDOORBELL64(ring->doorbell_index, ring->wptr);
- } else {
- BUG(); /* only DOORBELL method supported on gfx11 now */
- }
-}
-
static void gfx_v11_0_ring_emit_hdp_flush(struct amdgpu_ring *ring)
{
struct amdgpu_device *adev = ring->adev;
@@ -7266,8 +7240,8 @@ static const struct amdgpu_ring_funcs gfx_v11_0_ring_funcs_compute = {
.nop = PACKET3(PACKET3_NOP, 0x3FFF),
.support_64bit_ptrs = true,
.get_rptr = gfx_v11_0_ring_get_rptr_compute,
- .get_wptr = gfx_v11_0_ring_get_wptr_compute,
- .set_wptr = gfx_v11_0_ring_set_wptr_compute,
+ .get_wptr = amdgpu_gfx_get_wptr_compute,
+ .set_wptr = amdgpu_gfx_set_wptr_compute,
.emit_frame_size =
5 + /* update_spm_vmid */
20 + /* gfx_v11_0_ring_emit_gds_switch */
@@ -7307,8 +7281,8 @@ static const struct amdgpu_ring_funcs gfx_v11_0_ring_funcs_kiq = {
.nop = PACKET3(PACKET3_NOP, 0x3FFF),
.support_64bit_ptrs = true,
.get_rptr = gfx_v11_0_ring_get_rptr_compute,
- .get_wptr = gfx_v11_0_ring_get_wptr_compute,
- .set_wptr = gfx_v11_0_ring_set_wptr_compute,
+ .get_wptr = amdgpu_gfx_get_wptr_compute,
+ .set_wptr = amdgpu_gfx_set_wptr_compute,
.emit_frame_size =
20 + /* gfx_v11_0_ring_emit_gds_switch */
7 + /* gfx_v11_0_ring_emit_hdp_flush */
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
index 79ea1af36..7ba436444 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
@@ -4363,32 +4363,6 @@ static u64 gfx_v12_0_ring_get_rptr_compute(struct amdgpu_ring *ring)
return *(uint32_t *)ring->rptr_cpu_addr;
}
-static u64 gfx_v12_0_ring_get_wptr_compute(struct amdgpu_ring *ring)
-{
- u64 wptr;
-
- /* XXX check if swapping is necessary on BE */
- if (ring->use_doorbell)
- wptr = atomic64_read((atomic64_t *)ring->wptr_cpu_addr);
- else
- BUG();
- return wptr;
-}
-
-static void gfx_v12_0_ring_set_wptr_compute(struct amdgpu_ring *ring)
-{
- struct amdgpu_device *adev = ring->adev;
-
- /* XXX check if swapping is necessary on BE */
- if (ring->use_doorbell) {
- atomic64_set((atomic64_t *)ring->wptr_cpu_addr,
- ring->wptr);
- WDOORBELL64(ring->doorbell_index, ring->wptr);
- } else {
- BUG(); /* only DOORBELL method supported on gfx12 now */
- }
-}
-
static void gfx_v12_0_ring_emit_hdp_flush(struct amdgpu_ring *ring)
{
struct amdgpu_device *adev = ring->adev;
@@ -5523,8 +5497,8 @@ static const struct amdgpu_ring_funcs gfx_v12_0_ring_funcs_compute = {
.nop = PACKET3(PACKET3_NOP, 0x3FFF),
.support_64bit_ptrs = true,
.get_rptr = gfx_v12_0_ring_get_rptr_compute,
- .get_wptr = gfx_v12_0_ring_get_wptr_compute,
- .set_wptr = gfx_v12_0_ring_set_wptr_compute,
+ .get_wptr = amdgpu_gfx_get_wptr_compute,
+ .set_wptr = amdgpu_gfx_set_wptr_compute,
.emit_frame_size =
7 + /* gfx_v12_0_ring_emit_hdp_flush */
5 + /* hdp invalidate */
@@ -5561,8 +5535,8 @@ static const struct amdgpu_ring_funcs gfx_v12_0_ring_funcs_kiq = {
.nop = PACKET3(PACKET3_NOP, 0x3FFF),
.support_64bit_ptrs = true,
.get_rptr = gfx_v12_0_ring_get_rptr_compute,
- .get_wptr = gfx_v12_0_ring_get_wptr_compute,
- .set_wptr = gfx_v12_0_ring_set_wptr_compute,
+ .get_wptr = amdgpu_gfx_get_wptr_compute,
+ .set_wptr = amdgpu_gfx_set_wptr_compute,
.emit_frame_size =
7 + /* gfx_v12_0_ring_emit_hdp_flush */
5 + /*hdp invalidate */
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index 8249135d7..798f94bca 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
@@ -5640,37 +5640,6 @@ static u64 gfx_v9_0_ring_get_rptr_compute(struct amdgpu_ring *ring)
return *ring->rptr_cpu_addr; /* gfx9 hardware is 32bit rptr */
}
-static u64 gfx_v9_0_ring_get_wptr_compute(struct amdgpu_ring *ring)
-{
- u64 wptr;
-
- /* XXX check if swapping is necessary on BE */
- if (ring->use_doorbell) {
- wptr = atomic64_read((atomic64_t *)ring->wptr_cpu_addr);
- } else {
- WARN_ONCE(1, "gfx_v9_0: non-doorbell wptr read on ring %s, "
- "only doorbell method supported on gfx9\n",
- ring->name);
- wptr = 0;
- }
- return wptr;
-}
-
-static void gfx_v9_0_ring_set_wptr_compute(struct amdgpu_ring *ring)
-{
- struct amdgpu_device *adev = ring->adev;
-
- /* XXX check if swapping is necessary on BE */
- if (ring->use_doorbell) {
- atomic64_set((atomic64_t *)ring->wptr_cpu_addr, ring->wptr);
- WDOORBELL64(ring->doorbell_index, ring->wptr);
- } else {
- WARN_ONCE(1, "gfx_v9_0: non-doorbell wptr write on ring %s, "
- "only doorbell method supported on gfx9\n",
- ring->name);
- }
-}
-
static void gfx_v9_0_ring_emit_fence_kiq(struct amdgpu_ring *ring, u64 addr,
u64 seq, unsigned int flags)
{
@@ -7627,8 +7596,8 @@ static const struct amdgpu_ring_funcs gfx_v9_0_ring_funcs_compute = {
.nop = PACKET3(PACKET3_NOP, 0x3FFF),
.support_64bit_ptrs = true,
.get_rptr = gfx_v9_0_ring_get_rptr_compute,
- .get_wptr = gfx_v9_0_ring_get_wptr_compute,
- .set_wptr = gfx_v9_0_ring_set_wptr_compute,
+ .get_wptr = amdgpu_gfx_get_wptr_compute,
+ .set_wptr = amdgpu_gfx_set_wptr_compute,
.emit_frame_size =
20 + /* gfx_v9_0_ring_emit_gds_switch */
7 + /* gfx_v9_0_ring_emit_hdp_flush */
@@ -7669,8 +7638,8 @@ static const struct amdgpu_ring_funcs gfx_v9_0_ring_funcs_kiq = {
.nop = PACKET3(PACKET3_NOP, 0x3FFF),
.support_64bit_ptrs = true,
.get_rptr = gfx_v9_0_ring_get_rptr_compute,
- .get_wptr = gfx_v9_0_ring_get_wptr_compute,
- .set_wptr = gfx_v9_0_ring_set_wptr_compute,
+ .get_wptr = amdgpu_gfx_get_wptr_compute,
+ .set_wptr = amdgpu_gfx_set_wptr_compute,
.emit_frame_size =
20 + /* gfx_v9_0_ring_emit_gds_switch */
7 + /* gfx_v9_0_ring_emit_hdp_flush */
--
2.43.0
next reply other threads:[~2026-04-30 7:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 20:25 John B. Moore [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-04-29 20:20 [PATCH] drm/amdgpu/gfx: extract compute wptr doorbell helpers to amdgpu_gfx.c John B. Moore
2026-04-29 20:29 ` Alex Deucher
2026-04-30 7:19 ` Christian König
2026-04-30 12:32 ` John Moore
2026-04-30 13:22 ` Christian König
2026-04-30 13:26 ` Alex Deucher
2026-04-30 13:49 ` Christian König
2026-04-30 13:57 ` John Moore
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=20260429202518.21956-1-jbmoore61@gmail.com \
--to=jbmoore61@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=alexdeucher@gmail.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