From: Junhua Shen <Junhua.Shen@amd.com>
To: <igt-dev@lists.freedesktop.org>
Cc: Vitaly Prosyak <vitaly.prosyak@amd.com>,
Jesse Zhang <Jesse.Zhang@amd.com>,
Sunil Khatri <sunil.khatri@amd.com>,
Honglei Huang <honglei1.huang@amd.com>,
Huang Rui <ray.huang@amd.com>, Yiru Ma <yiru.ma@amd.com>,
Junhua Shen <Junhua.Shen@amd.com>
Subject: [PATCH i-g-t v2 1/6] lib/amdgpu: document amdgpu_ring_context field contract
Date: Wed, 9 Sep 2026 18:45:57 +0800 [thread overview]
Message-ID: <20260909104602.13807-2-Junhua.Shen@amd.com> (raw)
In-Reply-To: <20260909104602.13807-1-Junhua.Shen@amd.com>
amdgpu_ring_context is the hand-off between the PM4 packet builders
(ip_block->funcs callbacks) and the submitter that drives them.
Make the contract explicit: document the builder/submitter roles and
annotate each field with its direction: IN (submitter sets, builder
reads), OUT (builder produces, e.g. pm4_dw) and INTERNAL (submitter-owned
pm4[] the builder fills). Also clarify the per-packet-type meaning of
write_length and bo_mc/bo_mc2.
Documentation only; no functional change.
Signed-off-by: Junhua Shen <Junhua.Shen@amd.com>
---
lib/amdgpu/amd_ip_blocks.h | 57 ++++++++++++++++++++++++++++++--------
1 file changed, 45 insertions(+), 12 deletions(-)
diff --git a/lib/amdgpu/amd_ip_blocks.h b/lib/amdgpu/amd_ip_blocks.h
index 40a9735be..37f38ed44 100644
--- a/lib/amdgpu/amd_ip_blocks.h
+++ b/lib/amdgpu/amd_ip_blocks.h
@@ -272,26 +272,59 @@ amdgpu_dma_default_bytes(const struct amdgpu_dma_limits *lim,
}
}
-/* aux struct to hold misc parameters for convenience to maintain */
+/*
+ * struct amdgpu_ring_context - hand-off structure shared by the packet builder
+ * and submitter roles.
+ *
+ * Builder role: the ip_block->funcs PM4 callbacks declared in struct
+ * amdgpu_ip_funcs (write_linear, copy_linear, const_fill, ...). A builder
+ * reads only the IN fields, populates pm4[], and reports the produced length
+ * in pm4_dw. It does not access the device, allocate buffer objects, or
+ * submit.
+ *
+ * Submitter role: the caller that drives a builder. It populates the IN fields
+ * required by the target packet type prior to invocation, then consumes the
+ * OUT fields (pm4[]/pm4_dw) to perform the command submission.
+ *
+ * This structure is the sole interface between the two roles; each field is
+ * annotated with a direction:
+ * IN set by the submitter before invocation; read by the builder.
+ * OUT set by the builder; read by the submitter.
+ * INTERNAL owned by the submitter; the builder populates its contents only.
+ */
struct amdgpu_ring_context {
int ring_id; /* ring_id from amdgpu_query_hw_ip_info */
- int res_cnt; /* num of bo in amdgpu_bo_handle resources[2] */
+ int res_cnt; /* IN: number of valid entries in resources[] */
- uint64_t write_length; /* transfer size in bytes */
- uint64_t write_length2; /* transfer size in bytes, second packet */
- uint32_t *pm4; /* data of the packet */
- uint32_t pm4_size; /* max allocated packet size */
- bool secure; /* secure or not */
+ /*
+ * IN: per-packet transfer size in bytes. The builder interprets it
+ * per packet type:
+ * write_linear/atomic - inlined as write_length/4 dwords into pm4[]
+ * (grows pm4_dw; pm4_size must accommodate it);
+ * copy_linear/const_fill - HW DMA transfer data count;
+ * compare/compare_pattern - verification span (num_compare = write_length/div).
+ */
+ uint64_t write_length;
+ uint64_t write_length2; /* IN: transfer size in bytes, second packet */
+ uint32_t *pm4; /* INTERNAL: packet buffer (submitter-owned, builder fills) */
+ uint32_t pm4_size; /* IN: capacity of pm4[] in dwords (required, non-zero) */
+ bool secure; /* IN: secure or not */
uint32_t priority; /* user queue priority */
- uint64_t bo_mc; /* GPU address of first buffer */
- uint64_t bo_mc2; /* GPU address for p4 packet */
+ /*
+ * Operand GPU virtual addresses, assigned per packet type by the
+ * submitter prior to builder invocation:
+ * WRITE/ATOMIC/FILL: bo_mc = destination VA
+ * COPY: bo_mc = source VA, bo_mc2 = destination VA
+ */
+ uint64_t bo_mc; /* IN: GPU VA, primary operand (destination, or source for copy) */
+ uint64_t bo_mc2; /* IN: GPU VA, secondary operand (destination for copy) */
uint64_t bo_mc3; /* GPU address of second buffer */
uint64_t bo_mc4; /* GPU address of second p4 packet */
- uint32_t pm4_dw; /* actual size of pm4 */
- uint32_t pm4_dw2; /* actual size of second pm4 */
+ uint32_t pm4_dw; /* OUT: actual packet size in dwords */
+ uint32_t pm4_dw2; /* OUT: actual size of second pm4 in dwords */
volatile uint32_t *bo_cpu; /* cpu adddress of mapped GPU buf */
volatile uint32_t *bo2_cpu; /* cpu adddress of mapped pm4 */
@@ -311,7 +344,7 @@ struct amdgpu_ring_context {
amdgpu_context_handle context_handle;
struct drm_amdgpu_info_hw_ip hw_ip_info; /* result of amdgpu_query_hw_ip_info */
- amdgpu_bo_handle resources[4]; /* amdgpu_bo_alloc_and_map */
+ amdgpu_bo_handle resources[4]; /* IN: bo_list residency set, maintained by the submitter */
amdgpu_va_handle va_handle; /* amdgpu_bo_alloc_and_map */
amdgpu_va_handle va_handle2; /* amdgpu_bo_alloc_and_map */
amdgpu_va_handle va_handle3; /* amdgpu_bo_alloc_and_map */
--
2.34.1
next prev parent reply other threads:[~2026-09-09 10:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 10:45 [PATCH i-g-t v2 0/6] lib/amdgpu: refactor cmd_context ownership and packet operands Junhua Shen
2026-09-09 10:45 ` Junhua Shen [this message]
2026-09-09 10:45 ` [PATCH i-g-t v2 2/6] lib/amdgpu: drop external BO from cmd_context Junhua Shen
2026-09-14 2:18 ` Zhang, Jesse(Jie)
2026-09-09 10:45 ` [PATCH i-g-t v2 3/6] lib/amdgpu: source packet operands from params and size the IB from pm4_size Junhua Shen
2026-09-09 10:46 ` [PATCH i-g-t v2 4/6] lib/amdgpu: add CONST_FILL packet type and pass caller fill value through Junhua Shen
2026-09-09 10:46 ` [PATCH i-g-t v2 5/6] tests/amdgpu: derive compute dispatch version from hw_ip_version_major Junhua Shen
2026-09-09 10:46 ` [PATCH i-g-t v2 6/6] tests/amdgpu: query KFD aperture node count before filling array Junhua Shen
2026-09-09 18:19 ` ✓ i915.CI.BAT: success for lib/amdgpu: refactor cmd_context ownership and packet operands (rev2) Patchwork
2026-09-09 18:20 ` ✓ Xe.CI.BAT: " Patchwork
2026-09-10 3:38 ` ✓ Xe.CI.FULL: " Patchwork
2026-09-10 11:49 ` ✗ i915.CI.Full: failure " Patchwork
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=20260909104602.13807-2-Junhua.Shen@amd.com \
--to=junhua.shen@amd.com \
--cc=Jesse.Zhang@amd.com \
--cc=honglei1.huang@amd.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=ray.huang@amd.com \
--cc=sunil.khatri@amd.com \
--cc=vitaly.prosyak@amd.com \
--cc=yiru.ma@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