From: Lizhi Hou <lizhi.hou@amd.com>
To: Mario Limonciello <superm1@kernel.org>, <ogabbay@kernel.org>,
<quic_jhugo@quicinc.com>, <maciej.falkowski@linux.intel.com>,
<dri-devel@lists.freedesktop.org>
Cc: <linux-kernel@vger.kernel.org>, <max.zhen@amd.com>,
<sonal.santan@amd.com>
Subject: Re: [PATCH V1] accel/amdxdna: Support preemption requests
Date: Wed, 5 Nov 2025 09:05:21 -0800 [thread overview]
Message-ID: <29234ea6-5cb0-cfed-d9a3-be48a914ab4f@amd.com> (raw)
In-Reply-To: <851cd32b-e64e-4e56-bf49-7c8b3336815f@kernel.org>
Applied to drm-misc-next
On 11/4/25 11:30, Mario Limonciello wrote:
> On 11/4/25 1:28 PM, Lizhi Hou wrote:
>>
>> On 11/4/25 10:58, Mario Limonciello wrote:
>>> On 11/4/25 12:53 PM, Lizhi Hou wrote:
>>>> The driver checks the firmware version during initialization.If
>>>> preemption
>>>> is supported, the driver configures preemption accordingly and handles
>>>> userspace preemption requests. Otherwise, the driver returns an
>>>> error for
>>>> userspace preemption requests.
>>>>
>>>> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
>>>> ---
>>>> drivers/accel/amdxdna/aie2_message.c | 95
>>>> +++++++++++++++++++++++++
>>>> drivers/accel/amdxdna/aie2_msg_priv.h | 3 +
>>>> drivers/accel/amdxdna/aie2_pci.c | 63 ++++++++++++++++
>>>> drivers/accel/amdxdna/aie2_pci.h | 8 +++
>>>> drivers/accel/amdxdna/amdxdna_ctx.h | 17 +++++
>>>> drivers/accel/amdxdna/amdxdna_pci_drv.c | 3 +-
>>>> drivers/accel/amdxdna/npu4_regs.c | 4 ++
>>>> include/uapi/drm/amdxdna_accel.h | 16 ++++-
>>>> 8 files changed, 207 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/drivers/accel/amdxdna/aie2_message.c b/drivers/accel/
>>>> amdxdna/aie2_message.c
>>>> index 69cdce9ff208..d493bb1c3360 100644
>>>> --- a/drivers/accel/amdxdna/aie2_message.c
>>>> +++ b/drivers/accel/amdxdna/aie2_message.c
>>>> @@ -210,6 +210,14 @@ int aie2_create_context(struct amdxdna_dev_hdl
>>>> *ndev, struct amdxdna_hwctx *hwct
>>>> hwctx->fw_ctx_id = resp.context_id;
>>>> WARN_ONCE(hwctx->fw_ctx_id == -1, "Unexpected context id");
>>>> + if (ndev->force_preempt_enabled) {
>>>> + ret = aie2_runtime_cfg(ndev, AIE2_RT_CFG_FORCE_PREEMPT,
>>>> &hwctx->fw_ctx_id);
>>>> + if (ret) {
>>>> + XDNA_ERR(xdna, "failed to enable force preempt %d", ret);
>>>> + return ret;
>>>> + }
>>>> + }
>>>> +
>>>> cq_pair = &resp.cq_pair[0];
>>>> x2i.mb_head_ptr_reg = AIE2_MBOX_OFF(ndev, cq_pair-
>>>> >x2i_q.head_addr);
>>>> x2i.mb_tail_ptr_reg = AIE2_MBOX_OFF(ndev, cq_pair-
>>>> >x2i_q.tail_addr);
>>>> @@ -601,6 +609,11 @@ aie2_cmdlist_fill_dpu(struct amdxdna_gem_obj
>>>> *cmd_bo, void *slot, size_t *size)
>>>> return 0;
>>>> }
>>>> +static int aie2_cmdlist_unsupp(struct amdxdna_gem_obj *cmd_bo,
>>>> void *slot, size_t *size)
>>>> +{
>>>> + return -EOPNOTSUPP;
>>>> +}
>>>> +
>>>> static u32 aie2_get_chain_msg_op(u32 cmd_op)
>>>> {
>>>> switch (cmd_op) {
>>>> @@ -621,6 +634,8 @@ static struct aie2_exec_msg_ops
>>>> legacy_exec_message_ops = {
>>>> .init_chain_req = aie2_init_exec_chain_req,
>>>> .fill_cf_slot = aie2_cmdlist_fill_cf,
>>>> .fill_dpu_slot = aie2_cmdlist_fill_dpu,
>>>> + .fill_preempt_slot = aie2_cmdlist_unsupp,
>>>> + .fill_elf_slot = aie2_cmdlist_unsupp,
>>>> .get_chain_msg_op = aie2_get_chain_msg_op,
>>>> };
>>>> @@ -680,6 +695,74 @@ aie2_cmdlist_fill_npu_dpu(struct
>>>> amdxdna_gem_obj *cmd_bo, void *slot, size_t *si
>>>> return 0;
>>>> }
>>>> +static int
>>>> +aie2_cmdlist_fill_npu_preempt(struct amdxdna_gem_obj *cmd_bo, void
>>>> *slot, size_t *size)
>>>> +{
>>>> + struct cmd_chain_slot_npu *npu_slot = slot;
>>>> + struct amdxdna_cmd_preempt_data *pd;
>>>> + u32 cmd_len;
>>>> + u32 arg_sz;
>>>> +
>>>> + pd = amdxdna_cmd_get_payload(cmd_bo, &cmd_len);
>>>> + arg_sz = cmd_len - sizeof(*pd);
>>>> + if (cmd_len < sizeof(*pd) || arg_sz > MAX_NPU_ARGS_SIZE)
>>>> + return -EINVAL;
>>>> +
>>>> + if (*size < sizeof(*npu_slot) + arg_sz)
>>>> + return -EINVAL;
>>>> +
>>>> + npu_slot->cu_idx = amdxdna_cmd_get_cu_idx(cmd_bo);
>>>> + if (npu_slot->cu_idx == INVALID_CU_IDX)
>>>> + return -EINVAL;
>>>> +
>>>> + memset(npu_slot, 0, sizeof(*npu_slot));
>>>> + npu_slot->type = EXEC_NPU_TYPE_PREEMPT;
>>>> + npu_slot->inst_buf_addr = pd->inst_buf;
>>>> + npu_slot->save_buf_addr = pd->save_buf;
>>>> + npu_slot->restore_buf_addr = pd->restore_buf;
>>>> + npu_slot->inst_size = pd->inst_size;
>>>> + npu_slot->save_size = pd->save_size;
>>>> + npu_slot->restore_size = pd->restore_size;
>>>> + npu_slot->inst_prop_cnt = pd->inst_prop_cnt;
>>>> + npu_slot->arg_cnt = arg_sz / sizeof(u32);
>>>> + memcpy(npu_slot->args, pd->prop_args, arg_sz);
>>>
>>> Am I following this right? I would think this should be:
>>>
>>> memcpy(npu_slot->args, pd->prop_args, npu_slot->arg_cnt);
>>
>> npu_slot->arg_cnt is the number of u32. So arg_sz is used for memcpy
>> here.
>>
>>
> Got it thanks. No other concerns.
>
> Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
prev parent reply other threads:[~2025-11-05 17:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 18:53 Lizhi Hou
2025-11-04 18:58 ` Mario Limonciello
2025-11-04 19:28 ` Lizhi Hou
2025-11-04 19:30 ` Mario Limonciello
2025-11-05 17:05 ` Lizhi Hou [this message]
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=29234ea6-5cb0-cfed-d9a3-be48a914ab4f@amd.com \
--to=lizhi.hou@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maciej.falkowski@linux.intel.com \
--cc=max.zhen@amd.com \
--cc=ogabbay@kernel.org \
--cc=quic_jhugo@quicinc.com \
--cc=sonal.santan@amd.com \
--cc=superm1@kernel.org \
/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
all inboxes | Powered by JetHome®