From: David Zhang <yidong.zhang@amd.com>
To: <quic_jhugo@quicinc.com>, <karol.wachowski@linux.intel.com>,
<max.zhen@amd.com>, <lizhi.hou@amd.com>, <ogabbay@kernel.org>,
<dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>
Cc: David Zhang <yidong.zhang@amd.com>, <sonal.santan@amd.com>,
<mario.limonciello@amd.com>
Subject: [PATCH V3 10/19] accel/amdxdna: Refactor AIE4 hardware initialization sequence
Date: Wed, 7 Oct 2026 20:23:39 -0700 [thread overview]
Message-ID: <20261008032348.2044667-11-yidong.zhang@amd.com> (raw)
In-Reply-To: <20261008032348.2044667-1-yidong.zhang@amd.com>
Reorganize AIE4 hardware initialization into distinct phases:
- aie4_query_fw(): Query NPU and CERT firmware versions.
- aie4_config_fw(): Attach work buffer and configure context switch
hysteresis.
- aie4_setup_aie(): Query AIE version, metadata, initialize DPM frequency
table, and initialize partitions.
Update aie4_pf_hw_start(), aie4_vf_hw_start(), and aie4_classic_hw_start()
to use these phases and unify error unwinding labels. As part of this,
aie4_pf_hw_start() now also calls aie4_query_fw(), which it previously
did not do.
Additionally:
- Zero-initialize struct smu_config smu_conf in aie4_prepare_firmware().
- Clean up iomem pointer type in aie4_fw_is_alive() to void __iomem *.
Signed-off-by: David Zhang <yidong.zhang@amd.com>
---
drivers/accel/amdxdna/aie4_pci.c | 79 +++++++++++++++++++-------------
1 file changed, 46 insertions(+), 33 deletions(-)
diff --git a/drivers/accel/amdxdna/aie4_pci.c b/drivers/accel/amdxdna/aie4_pci.c
index d051aa1b51e6..8fbbbea0d800 100644
--- a/drivers/accel/amdxdna/aie4_pci.c
+++ b/drivers/accel/amdxdna/aie4_pci.c
@@ -50,7 +50,7 @@ static int aie4_fw_is_alive(struct amdxdna_dev *xdna)
{
const struct amdxdna_dev_priv *npriv = xdna->dev_info->dev_priv;
struct amdxdna_dev_hdl *ndev = xdna->dev_handle;
- u32 __iomem *src;
+ void __iomem *src;
u32 fw_is_valid;
int ret;
@@ -279,7 +279,8 @@ static void aie4_partition_fini(struct amdxdna_dev_hdl *ndev)
XDNA_ERR(xdna, "partition fini failed: %d", ret);
}
-static int aie4_query(struct amdxdna_dev_hdl *ndev)
+/* Verify CERT protocol compatibility before starting hardware. */
+static int aie4_query_fw(struct amdxdna_dev_hdl *ndev)
{
struct amdxdna_dev *xdna = ndev->aie.xdna;
int ret;
@@ -292,25 +293,6 @@ static int aie4_query(struct amdxdna_dev_hdl *ndev)
if (ret)
return ret;
- ret = aie4_query_aie_version(ndev, &ndev->aie.version);
- if (ret)
- return ret;
-
- ret = aie4_query_aie_metadata(ndev, &ndev->aie.metadata);
- if (ret)
- return ret;
-
- ndev->total_col = min_t(u32, AIE4_TOTAL_COLUMN, ndev->aie.metadata.cols);
-
- ret = aie4_init_dpm_freq_table(ndev);
- if (ret) {
- if (ret == -ETIME)
- return ret;
- /* if query dpm from fw failed, using default value */
- if (ndev->priv->hw_ops && ndev->priv->hw_ops->set_dpm)
- (void)ndev->priv->hw_ops->set_dpm(&ndev->aie, 0);
- }
-
return 0;
}
@@ -339,6 +321,32 @@ static int aie4_config_fw(struct amdxdna_dev_hdl *ndev)
return 0;
}
+static int aie4_setup_aie(struct amdxdna_dev_hdl *ndev)
+{
+ int ret;
+
+ ret = aie4_query_aie_version(ndev, &ndev->aie.version);
+ if (ret)
+ return ret;
+
+ ret = aie4_query_aie_metadata(ndev, &ndev->aie.metadata);
+ if (ret)
+ return ret;
+
+ ndev->total_col = min_t(u32, AIE4_TOTAL_COLUMN, ndev->aie.metadata.cols);
+
+ ret = aie4_init_dpm_freq_table(ndev);
+ if (ret) {
+ if (ret == -ETIME)
+ return ret;
+ /* if query dpm from fw failed, using default value */
+ if (ndev->priv->hw_ops && ndev->priv->hw_ops->set_dpm)
+ (void)ndev->priv->hw_ops->set_dpm(&ndev->aie, 0);
+ }
+
+ return aie4_partition_init(ndev);
+}
+
static int aie4_pf_hw_start(struct amdxdna_dev_hdl *ndev)
{
int ret;
@@ -351,6 +359,10 @@ static int aie4_pf_hw_start(struct amdxdna_dev_hdl *ndev)
if (ret)
goto stop_fw;
+ ret = aie4_query_fw(ndev);
+ if (ret)
+ goto mbox_fini;
+
ret = aie4_config_fw(ndev);
if (ret)
goto mbox_fini;
@@ -388,13 +400,13 @@ static int aie4_vf_hw_start(struct amdxdna_dev_hdl *ndev)
if (ret)
return ret;
- ret = aie4_query(ndev);
+ ret = aie4_query_fw(ndev);
if (ret)
- goto mailbox_fini;
+ goto mbox_fini;
- ret = aie4_partition_init(ndev);
+ ret = aie4_setup_aie(ndev);
if (ret)
- goto mailbox_fini;
+ goto mbox_fini;
ret = aie4_restore_power_mode(ndev);
if (ret)
@@ -404,7 +416,7 @@ static int aie4_vf_hw_start(struct amdxdna_dev_hdl *ndev)
partition_fini:
aie4_partition_fini(ndev);
-mailbox_fini:
+mbox_fini:
aie4_mailbox_fini(ndev);
return ret;
}
@@ -431,17 +443,17 @@ static int aie4_classic_hw_start(struct amdxdna_dev_hdl *ndev)
if (ret)
goto stop_fw;
- ret = aie4_query(ndev);
+ ret = aie4_query_fw(ndev);
if (ret)
- goto mailbox_fini;
+ goto mbox_fini;
ret = aie4_config_fw(ndev);
if (ret)
- goto mailbox_fini;
+ goto mbox_fini;
- ret = aie4_partition_init(ndev);
+ ret = aie4_setup_aie(ndev);
if (ret)
- goto mailbox_fini;
+ goto mbox_fini;
ret = aie4_restore_power_mode(ndev);
if (ret)
@@ -451,10 +463,11 @@ static int aie4_classic_hw_start(struct amdxdna_dev_hdl *ndev)
partition_fini:
aie4_partition_fini(ndev);
-mailbox_fini:
+mbox_fini:
aie4_mailbox_fini(ndev);
stop_fw:
aie4_fw_stop(ndev);
+
return ret;
}
@@ -528,8 +541,8 @@ static int aie4_prepare_firmware(struct amdxdna_dev_hdl *ndev,
void __iomem *tbl[PCI_NUM_RESOURCES])
{
struct amdxdna_dev *xdna = ndev->aie.xdna;
+ struct smu_config smu_conf = {};
struct psp_config psp_conf;
- struct smu_config smu_conf;
int i;
psp_conf.fw_size = npufw->size;
--
2.34.1
next prev parent reply other threads:[~2026-10-08 3:24 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 3:23 [PATCH V3 00/19] accel/amdxdna: Kernel submission and PM for AIE4 David Zhang
2026-10-08 3:23 ` [PATCH V3 01/19] accel/amdxdna: Rename NPU3 firmware files David Zhang
2026-10-08 16:23 ` Lizhi Hou
2026-10-08 3:23 ` [PATCH V3 02/19] accel/amdxdna: Remove mmap for doorbell David Zhang
2026-10-08 3:23 ` [PATCH V3 03/19] accel/amdxdna: Add CERT firmware version support David Zhang
2026-10-08 17:12 ` Lizhi Hou
2026-10-08 17:26 ` Zhang, Yidong (David)
2026-10-08 3:23 ` [PATCH V3 04/19] accel/amdxdna: Upgrade firmware version to 6.0 David Zhang
2026-10-08 17:15 ` Lizhi Hou
2026-10-08 3:23 ` [PATCH V3 05/19] accel/amdxdna: Add NPU3 classic device support David Zhang
2026-10-08 3:23 ` [PATCH V3 06/19] accel/amdxdna: Add AIE version query to aie4_get_info David Zhang
2026-10-08 3:23 ` [PATCH V3 07/19] accel/amdxdna: Add get and set power_mode for AIE4 David Zhang
2026-10-08 3:23 ` [PATCH V3 08/19] accel/amdxdna: Add clock, DPM frequency, and resource info queries " David Zhang
2026-10-08 3:23 ` [PATCH V3 09/19] accel/amdxdna: Add context switch hysteresis with debugfs control David Zhang
2026-10-08 3:23 ` David Zhang [this message]
2026-10-08 3:23 ` [PATCH V3 11/19] accel/amdxdna: Decouple AIE4 doorbell and MSI-X notify transport hooks David Zhang
2026-10-08 3:23 ` [PATCH V3 12/19] accel/amdxdna: Implement AIE4 kernel queue lifecycle and memory layout David Zhang
2026-10-08 3:23 ` [PATCH V3 13/19] accel/amdxdna: Prepare for AIE4 command submission David Zhang
2026-10-08 3:23 ` [PATCH V3 14/19] accel/amdxdna: Move HMM invalidate wait into common GEM code David Zhang
2026-10-08 3:23 ` [PATCH V3 15/19] accel/amdxdna: Make populate_range common for AIE2 and AIE4 David Zhang
2026-10-08 3:23 ` [PATCH V3 16/19] accel/amdxdna: Implement AIE4 command packet building and submission David Zhang
2026-10-08 3:23 ` [PATCH V3 17/19] accel/amdxdna: Enable AIE4 firmware logging to DRAM David Zhang
2026-10-08 3:23 ` [PATCH V3 18/19] accel/amdxdna: Implement AIE4 suspend and resume David Zhang
2026-10-08 3:23 ` [PATCH V3 19/19] accel/amdxdna: Implement runtime suspend and resume support David Zhang
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=20261008032348.2044667-11-yidong.zhang@amd.com \
--to=yidong.zhang@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=karol.wachowski@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizhi.hou@amd.com \
--cc=mario.limonciello@amd.com \
--cc=max.zhen@amd.com \
--cc=ogabbay@kernel.org \
--cc=quic_jhugo@quicinc.com \
--cc=sonal.santan@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
all inboxes | Powered by JetHome®