* [PATCH 11/15] dt-bindings: soc: xilinx: Add Versal AI Engine DT binding
2026-11-18 23:31 [PATCH 00/15] accel: Add AMD Versal AI Engine driver (with Versal Gen 2 firmware support) Gregory Williams
@ 2026-11-18 23:32 ` Gregory Williams
2026-11-18 23:45 ` sashiko-bot
2026-11-19 10:59 ` Krzysztof Kozlowski
2026-11-18 23:32 ` [PATCH 12/15] accel/amd-ai-engine: Add AMD AI Engine device driver Gregory Williams
` (4 subsequent siblings)
5 siblings, 2 replies; 13+ messages in thread
From: Gregory Williams @ 2026-11-18 23:32 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Michal Simek
Cc: dri-devel, devicetree, linux-arm-kernel, linux-kernel
Add documentation to describe Versal AI Engine device tree bindings. AI
Engine is a tile array based processor with many cores and local memory
cache. Data routing between the cores is done through internal switches,
interface tiles are used to connect to external sources such as memory
or PL. Configuration registers of the device are accessed through a
memory mapped AXI address space.
Signed-off-by: Gregory Williams <gregory.williams@amd.com>
---
.../bindings/soc/xilinx/xlnx,ai-engine.yaml | 61 +++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 Documentation/devicetree/bindings/soc/xilinx/xlnx,ai-engine.yaml
diff --git a/Documentation/devicetree/bindings/soc/xilinx/xlnx,ai-engine.yaml b/Documentation/devicetree/bindings/soc/xilinx/xlnx,ai-engine.yaml
new file mode 100644
index 000000000000..6c97b5f0fb03
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/xilinx/xlnx,ai-engine.yaml
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/xilinx/xlnx,ai-engine.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: AMD AI Engine for Versal SoCs
+
+maintainers:
+ - Gregory Williams <gregory.williams@amd.com>
+
+description:
+ The AMD AI Engine is a tile processor with many cores (up to 400) that
+ can run in parallel with some devices containing local cache (memory tiles).
+ The data routing between cores is configured through internal switches, and
+ shim tiles interface with external interconnect, such as memory or PL.
+
+properties:
+ compatible:
+ enum:
+ - xlnx,versal2-aieml
+
+ reg:
+ maxItems: 1
+
+ clocks:
+ maxItems: 1
+
+ clock-names:
+ const: aclk0
+
+ xlnx,firmware-device-id:
+ description:
+ Device identifier as defined by Versal firmware interface. This value is
+ passed unchanged to firmware calls.
+ $ref: /schemas/types.yaml#/definitions/uint32
+
+required:
+ - compatible
+ - reg
+ - clocks
+ - clock-names
+ - xlnx,firmware-device-id
+
+additionalProperties: false
+
+examples:
+ - |
+ soc {
+ #address-cells = <2>;
+ #size-cells = <2>;
+
+ ai_engine: ai-engine@20000000000 {
+ compatible = "xlnx,versal2-aieml";
+ reg = <0x200 0x00 0x01 0x00>;
+ clocks = <&aclk0>;
+ clock-names = "aclk0";
+ xlnx,firmware-device-id = <0x18224072>;
+ };
+ };
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 11/15] dt-bindings: soc: xilinx: Add Versal AI Engine DT binding
2026-11-18 23:32 ` [PATCH 11/15] dt-bindings: soc: xilinx: Add Versal AI Engine DT binding Gregory Williams
@ 2026-11-18 23:45 ` sashiko-bot
2026-11-19 10:59 ` Krzysztof Kozlowski
1 sibling, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-11-18 23:45 UTC (permalink / raw)
To: Gregory Williams; +Cc: dri-devel, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] dt-bindings: soc: xilinx: xlnx,firmware-device-id duplicates
power-domains
- [Low] dt-bindings: soc: xilinx: DTS example fails dt-check-style in
strict mode
--
commit b6e53e2eec4c5f256b86a96092363aef4bc4fe16
Author: Gregory Williams <gregory.williams@amd.com>
dt-bindings: soc: xilinx: Add Versal AI Engine DT binding
This commit adds the Device Tree binding schema for the AMD Versal AI Engine
tile array processor.
> diff --git a/Documentation/devicetree/bindings/soc/xilinx/xlnx,ai-engine.yaml b/Documentation/devicetree/bindings/soc/xilinx/xlnx,ai-engine.yaml
> new file mode 100644
> index 0000000000000..6c97b5f0fb036
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/soc/xilinx/xlnx,ai-engine.yaml
> @@ -0,0 +1,61 @@
[ ... ]
> + xlnx,firmware-device-id:
> + description:
> + Device identifier as defined by Versal firmware interface. This value is
> + passed unchanged to firmware calls.
> + $ref: /schemas/types.yaml#/definitions/uint32
> +
> +required:
> + - compatible
> + - reg
> + - clocks
> + - clock-names
> + - xlnx,firmware-device-id
> +
> +additionalProperties: false
[Severity: Medium]
Should this binding use the standard power-domains property instead of a
custom xlnx,firmware-device-id property?
The value 0x18224072 in the example below is PM_DEV_AI from
arch/arm64/boot/dts/xilinx/xlnx-versal-power.h, which is the Versal firmware
power-domain node ID used by the xlnx,zynqmp-firmware power-domain provider
(drivers/pmdomain/xilinx/zynqmp-pm-domains.c). Existing Versal drivers that
need the PM_DEV_* ID for firmware calls obtain it from power-domains (for
example, cqspi_of_get_pdata() in drivers/spi/spi-cadence-quadspi.c).
Omitting power-domains with additionalProperties: false also prevents DT
nodes from referencing the firmware power-domain provider.
> +
> +examples:
> + - |
> + soc {
> + #address-cells = <2>;
> + #size-cells = <2>;
> +
> + ai_engine: ai-engine@20000000000 {
> + compatible = "xlnx,versal2-aieml";
> + reg = <0x200 0x00 0x01 0x00>;
> + clocks = <&aclk0>;
> + clock-names = "aclk0";
> + xlnx,firmware-device-id = <0x18224072>;
> + };
> + };
[Severity: Low]
This example triggers indent-unit-strict and unused-labels warnings under
scripts/dtc/dt-check-style --mode=strict because it uses 2-space indentation
instead of 4-space indentation and defines the unused label ai_engine.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118233211.4121361-1-gregory.williams@amd.com?part=11
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH 11/15] dt-bindings: soc: xilinx: Add Versal AI Engine DT binding
2026-11-18 23:32 ` [PATCH 11/15] dt-bindings: soc: xilinx: Add Versal AI Engine DT binding Gregory Williams
2026-11-18 23:45 ` sashiko-bot
@ 2026-11-19 10:59 ` Krzysztof Kozlowski
1 sibling, 0 replies; 13+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-19 10:59 UTC (permalink / raw)
To: Gregory Williams, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Michal Simek
Cc: dri-devel, devicetree, linux-arm-kernel, linux-kernel
On 19/11/2026 00:32, Gregory Williams wrote:
> Add documentation to describe Versal AI Engine device tree bindings. AI
> Engine is a tile array based processor with many cores and local memory
> cache. Data routing between the cores is done through internal switches,
> interface tiles are used to connect to external sources such as memory
> or PL. Configuration registers of the device are accessed through a
> memory mapped AXI address space.
>
> Signed-off-by: Gregory Williams <gregory.williams@amd.com>
> ---
> .../bindings/soc/xilinx/xlnx,ai-engine.yaml | 61 +++++++++++++++++++
Soc is dumping ground of things which do not have clear function. This
has a clear function, so place it with other DSP/accel/NPU.
Subject - you almost hit the bingo. Missing only schema and YAML for the
full one.
A nit, subject: drop second/last, redundant "DT bindings". The
"dt-bindings" prefix is already stating that these are bindings.
See also:
https://elixir.bootlin.com/linux/v7.1-rc7/source/Documentation/devicetree/bindings/submitting-patches.rst#L23
> 1 file changed, 61 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/soc/xilinx/xlnx,ai-engine.yaml
>
> diff --git a/Documentation/devicetree/bindings/soc/xilinx/xlnx,ai-engine.yaml b/Documentation/devicetree/bindings/soc/xilinx/xlnx,ai-engine.yaml
> new file mode 100644
> index 000000000000..6c97b5f0fb03
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/soc/xilinx/xlnx,ai-engine.yaml
Please read writing bindings document. Filename must match compatible.
> @@ -0,0 +1,61 @@
> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
Why not using recommended license? Why doing this differently?
> +# Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/soc/xilinx/xlnx,ai-engine.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: AMD AI Engine for Versal SoCs
> +
> +maintainers:
> + - Gregory Williams <gregory.williams@amd.com>
> +
> +description:
> + The AMD AI Engine is a tile processor with many cores (up to 400) that
> + can run in parallel with some devices containing local cache (memory tiles).
> + The data routing between cores is configured through internal switches, and
> + shim tiles interface with external interconnect, such as memory or PL.
> +
> +properties:
> + compatible:
> + enum:
> + - xlnx,versal2-aieml
> +
> + reg:
> + maxItems: 1
> +
> + clocks:
> + maxItems: 1
> +
> + clock-names:
> + const: aclk0
Drop clock name. If you have to use output clock name as input name,
then it's just incorrect or incomplete, thus just drop it.
> +
> + xlnx,firmware-device-id:
You don't get device identifiers, sorry. See writing bindings.
> + description:
> + Device identifier as defined by Versal firmware interface. This value is
> + passed unchanged to firmware calls.
> + $ref: /schemas/types.yaml#/definitions/uint32
> +
> +required:
> + - compatible
> + - reg
> + - clocks
> + - clock-names
> + - xlnx,firmware-device-id
> +
> +additionalProperties: false
> +
> +examples:
> + - |
> + soc {
> + #address-cells = <2>;
> + #size-cells = <2>;
> +
> + ai_engine: ai-engine@20000000000 {
Don't use your own names. It is not an engine.
Node names should be generic. See also an explanation and list of
examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
If you cannot find a name matching your device, please check in kernel
sources for similar cases or you can grow the spec (via pull request to
DT spec repo).
> + compatible = "xlnx,versal2-aieml";
> + reg = <0x200 0x00 0x01 0x00>;
> + clocks = <&aclk0>;
> + clock-names = "aclk0";
> + xlnx,firmware-device-id = <0x18224072>;
> + };
> + };
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 12/15] accel/amd-ai-engine: Add AMD AI Engine device driver
2026-11-18 23:31 [PATCH 00/15] accel: Add AMD Versal AI Engine driver (with Versal Gen 2 firmware support) Gregory Williams
2026-11-18 23:32 ` [PATCH 11/15] dt-bindings: soc: xilinx: Add Versal AI Engine DT binding Gregory Williams
@ 2026-11-18 23:32 ` Gregory Williams
2026-11-18 23:45 ` sashiko-bot
2026-11-18 23:32 ` [PATCH 13/15] accel/amd-ai-engine: Add pm ops for firmware calls Gregory Williams
` (3 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Gregory Williams @ 2026-11-18 23:32 UTC (permalink / raw)
To: Oded Gabbay; +Cc: linux-kernel, dri-devel
Add support for AMD AI Engine on AMD Versal devices. AMD AI Engine is a
tile array based accelerator for applications like beamforming and machine
learning inference [1].
AI Engine device driver is responsible for the management of AI engine
partitions (groups of AI engine columns). At runtime applications request
a partition from the AI engine device. Applications use the partition
handle for application setup and control.
The driver architecture:
+-------------------------------------------+
| AIE Device |
| +----------------+ +----------------+ |
| | partition_0 | ... | partition_X | |
| +----------------+ +----------------+ |
+-------------------------------------------+
The driver provides the following functionality:
- AI Engine device probe
- Partition request and release
[1] https://www.amd.com/en/products/adaptive-socs-and-fpgas/technologies/ai-engine.html
Signed-off-by: Gregory Williams <gregory.williams@amd.com>
---
MAINTAINERS | 9 +
drivers/accel/Kconfig | 1 +
drivers/accel/Makefile | 3 +-
drivers/accel/amd-ai-engine/Kconfig | 15 ++
drivers/accel/amd-ai-engine/Makefile | 11 +
.../accel/amd-ai-engine/ai-engine-aiemlv2.c | 47 ++++
drivers/accel/amd-ai-engine/ai-engine-dev.c | 244 ++++++++++++++++++
.../accel/amd-ai-engine/ai-engine-internal.h | 160 ++++++++++++
drivers/accel/amd-ai-engine/ai-engine-part.c | 77 ++++++
drivers/accel/amd-ai-engine/ai-engine-res.c | 112 ++++++++
include/linux/amd-ai-engine.h | 59 +++++
11 files changed, 737 insertions(+), 1 deletion(-)
create mode 100644 drivers/accel/amd-ai-engine/Kconfig
create mode 100644 drivers/accel/amd-ai-engine/Makefile
create mode 100644 drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
create mode 100644 drivers/accel/amd-ai-engine/ai-engine-dev.c
create mode 100644 drivers/accel/amd-ai-engine/ai-engine-internal.h
create mode 100644 drivers/accel/amd-ai-engine/ai-engine-part.c
create mode 100644 drivers/accel/amd-ai-engine/ai-engine-res.c
create mode 100644 include/linux/amd-ai-engine.h
diff --git a/MAINTAINERS b/MAINTAINERS
index bcade5bfbafe..d8bfa7cbf8f6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1080,6 +1080,15 @@ L: linux-sound@vger.kernel.org
S: Supported
F: sound/soc/amd/
+AMD AI ENGINE DRIVER
+M: Gregory Williams <gregory.williams@amd.com>
+L: dri-devel@lists.freedesktop.org
+S: Maintained
+T: git https://gitlab.freedesktop.org/drm/misc/kernel.git
+F: Documentation/devicetree/bindings/soc/xilinx/xlnx,ai-engine.yaml
+F: drivers/accel/amd-ai-engine/
+F: include/linux/amd-ai-engine.h
+
AMD AXI I3C MASTER DRIVER
M: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
M: Shubham Patil <shubhamsanjay.patil@amd.com>
diff --git a/drivers/accel/Kconfig b/drivers/accel/Kconfig
index bdf48ccafcf2..b20a1445629d 100644
--- a/drivers/accel/Kconfig
+++ b/drivers/accel/Kconfig
@@ -24,6 +24,7 @@ menuconfig DRM_ACCEL
different device files, called accel/accel* (in /dev, sysfs
and debugfs).
+source "drivers/accel/amd-ai-engine/Kconfig"
source "drivers/accel/amdxdna/Kconfig"
source "drivers/accel/ethosu/Kconfig"
source "drivers/accel/habanalabs/Kconfig"
diff --git a/drivers/accel/Makefile b/drivers/accel/Makefile
index 1d3a7251b950..f0f09f3b6a56 100644
--- a/drivers/accel/Makefile
+++ b/drivers/accel/Makefile
@@ -1,8 +1,9 @@
# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_DRM_ACCEL_AMDAIE) += amd-ai-engine/
obj-$(CONFIG_DRM_ACCEL_AMDXDNA) += amdxdna/
obj-$(CONFIG_DRM_ACCEL_ARM_ETHOSU) += ethosu/
obj-$(CONFIG_DRM_ACCEL_HABANALABS) += habanalabs/
obj-$(CONFIG_DRM_ACCEL_IVPU) += ivpu/
obj-$(CONFIG_DRM_ACCEL_QAIC) += qaic/
-obj-$(CONFIG_DRM_ACCEL_ROCKET) += rocket/
\ No newline at end of file
+obj-$(CONFIG_DRM_ACCEL_ROCKET) += rocket/
diff --git a/drivers/accel/amd-ai-engine/Kconfig b/drivers/accel/amd-ai-engine/Kconfig
new file mode 100644
index 000000000000..7f32928cb20f
--- /dev/null
+++ b/drivers/accel/amd-ai-engine/Kconfig
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config DRM_ACCEL_AMDAIE
+ tristate "AMD Versal AI Engine"
+ depends on ARM64 || COMPILE_TEST
+ depends on ZYNQMP_FIRMWARE
+ depends on DRM_ACCEL
+ help
+ This option enables support for the AMD AI engine driver.
+ One AMD AI engine device can have multiple partitions (groups of
+ AI engine tiles). AMD AI engine device driver instance manages
+ AI engine partitions. Applications access its partitions through
+ AI engine partition device instance.
+
+ If unsure, say N.
diff --git a/drivers/accel/amd-ai-engine/Makefile b/drivers/accel/amd-ai-engine/Makefile
new file mode 100644
index 000000000000..cb456ee7ec37
--- /dev/null
+++ b/drivers/accel/amd-ai-engine/Makefile
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Makefile for AMD AI engine device driver
+
+obj-$(CONFIG_DRM_ACCEL_AMDAIE) += amd-aie.o
+
+amd-aie-$(CONFIG_DRM_ACCEL_AMDAIE) := \
+ ai-engine-aiemlv2.o \
+ ai-engine-dev.o \
+ ai-engine-part.o \
+ ai-engine-res.o
diff --git a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
new file mode 100644
index 000000000000..0c9c7ccdd54e
--- /dev/null
+++ b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AMD AI Engine driver AIEMLv2 device specific implementation
+ *
+ * Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
+ */
+
+#include <linux/amd-ai-engine.h>
+
+#include "ai-engine-internal.h"
+
+#define AIEMLV2_ARRAY_SHIFT 32U
+#define AIEMLV2_COL_SHIFT 25U
+#define AIEMLV2_ROW_SHIFT 20U
+
+static u32 aiemlv2_get_tile_type(struct aie_device *adev, struct aie_location *loc)
+{
+ u8 num_mem_rows = adev->ttype_attr[AIE_TILE_TYPE_MEMORY].num_rows;
+
+ if (loc->row > num_mem_rows)
+ return AIE_TILE_TYPE_TILE;
+ if (loc->row)
+ return AIE_TILE_TYPE_MEMORY;
+
+ return AIE_TILE_TYPE_SHIMNOC;
+}
+
+static const struct aie_tile_operations aiemlv2_ops = {
+ .get_tile_type = aiemlv2_get_tile_type,
+};
+
+/**
+ * aiemlv2_device_init() - Initialize AI engine device struct AIEMLV2 specific
+ * @adev: AI engine device
+ *
+ * This function initialize the AI engine device structure device version
+ * specific elements such as register addressing related array shift,
+ * column shift, and row shift; AIEMLV2 device specific device operations, device
+ * columns resource.
+ */
+void aiemlv2_device_init(struct aie_device *adev)
+{
+ adev->array_shift = AIEMLV2_ARRAY_SHIFT;
+ adev->col_shift = AIEMLV2_COL_SHIFT;
+ adev->row_shift = AIEMLV2_ROW_SHIFT;
+ adev->ops = &aiemlv2_ops;
+}
diff --git a/drivers/accel/amd-ai-engine/ai-engine-dev.c b/drivers/accel/amd-ai-engine/ai-engine-dev.c
new file mode 100644
index 000000000000..7dad3004e30a
--- /dev/null
+++ b/drivers/accel/amd-ai-engine/ai-engine-dev.c
@@ -0,0 +1,244 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AMD AI Engine device driver
+ *
+ * Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
+ */
+
+#include <linux/amd-ai-engine.h>
+#include <linux/clk.h>
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+
+#include "ai-engine-internal.h"
+
+/**
+ * aie_partition_request() - Request an AI engine partition
+ * @dev: AI engine device pointer
+ * @req: AI engine partition request arguments
+ *
+ * Return: pointer to the AI engine partition device, error pointer value for
+ * failure.
+ */
+struct device *aie_partition_request(struct device *dev, struct aie_partition_req *req)
+{
+ struct aie_device *adev = dev_get_drvdata(dev);
+ struct aie_partition *apart = NULL;
+ u8 start_col, num_col, end_col;
+ int ret;
+
+ if (!req)
+ return ERR_PTR(-EINVAL);
+
+ start_col = aie_part_id_get_start_col(req->partition_id);
+ num_col = aie_part_id_get_num_cols(req->partition_id);
+ if (num_col == 0) {
+ start_col = adev->range.start.col;
+ num_col = adev->range.size.col;
+ }
+
+ end_col = start_col + num_col - 1;
+ if (start_col < adev->range.start.col ||
+ end_col >= (adev->range.start.col + adev->range.size.col)) {
+ dev_err(adev->dev, "partition is outside of device range\n");
+ return ERR_PTR(-ERANGE);
+ }
+
+ mutex_lock(&adev->mlock);
+ ret = aie_resource_get_region(&adev->cols_res,
+ start_col - adev->range.start.col,
+ num_col);
+ if (ret != (u32)start_col - adev->range.start.col) {
+ /* column range returned is not what user requested */
+ if (ret > 0)
+ aie_resource_put_region(&adev->cols_res, ret, num_col);
+ mutex_unlock(&adev->mlock);
+ dev_err(adev->dev, "partition requested is busy\n");
+ return ERR_PTR(-EBUSY);
+ }
+
+ apart = aie_part_create(adev, start_col, num_col);
+ if (IS_ERR(apart)) {
+ aie_resource_put_region(&adev->cols_res, ret, num_col);
+ ret = PTR_ERR(apart);
+ mutex_unlock(&adev->mlock);
+ dev_err(adev->dev, "failed to create partition\n");
+ return ERR_PTR(ret);
+ }
+
+ list_add_tail(&apart->node, &adev->partitions);
+ mutex_unlock(&adev->mlock);
+ dev_dbg(adev->dev, "Partition (%u, %u) created successfully.\n",
+ apart->range.start.col, apart->range.size.col);
+
+ return &apart->dev;
+}
+EXPORT_SYMBOL_GPL(aie_partition_request);
+
+/**
+ * aie_partition_release() - Release the AI engine partition
+ * @dev: AI engine partition device pointer
+ */
+void aie_partition_release(struct device *dev)
+{
+ struct aie_partition *apart = dev_to_aiepart(dev);
+
+ mutex_lock(&apart->adev->mlock);
+ aie_part_release(apart);
+ mutex_unlock(&apart->adev->mlock);
+}
+EXPORT_SYMBOL_GPL(aie_partition_release);
+
+static int amd_ai_engine_probe(struct platform_device *pdev)
+{
+ const struct aie_device_cfg *match;
+ struct aie_device *adev;
+ u32 pm_reg;
+ int ret;
+
+ adev = devm_kzalloc(&pdev->dev, sizeof(*adev), GFP_KERNEL);
+ if (!adev)
+ return -ENOMEM;
+
+ platform_set_drvdata(pdev, adev);
+ INIT_LIST_HEAD(&adev->partitions);
+ mutex_init(&adev->mlock);
+
+ match = of_device_get_match_data(&pdev->dev);
+ if (!match) {
+ dev_err(&pdev->dev, "Failed to find aie device configuration\n");
+ return -ENODEV;
+ }
+
+ /* setup device layout configuration */
+ adev->dev = &pdev->dev;
+ adev->range.start.col = 0;
+ adev->range.size.col = match->num_columns;
+ adev->range.start.row = 0;
+ adev->range.size.row = match->mem_num_row + match->core_num_row + 1;
+ adev->ttype_attr[AIE_TILE_TYPE_SHIMPL].start_row = 0;
+ adev->ttype_attr[AIE_TILE_TYPE_SHIMPL].num_rows = 1;
+ adev->ttype_attr[AIE_TILE_TYPE_SHIMNOC].start_row = 0;
+ adev->ttype_attr[AIE_TILE_TYPE_SHIMNOC].num_rows = 0;
+ adev->ttype_attr[AIE_TILE_TYPE_TILE].start_row = match->core_start_row;
+ adev->ttype_attr[AIE_TILE_TYPE_TILE].num_rows = match->core_num_row;
+ adev->ttype_attr[AIE_TILE_TYPE_MEMORY].start_row = match->mem_start_row;
+ adev->ttype_attr[AIE_TILE_TYPE_MEMORY].num_rows = match->mem_num_row;
+
+ adev->dev_gen = match->aie_gen;
+ if (adev->dev_gen == AIE_DEVICE_GEN_AIEMLV2) {
+ aiemlv2_device_init(adev);
+ } else {
+ dev_err(&pdev->dev, "Device generation not supported\n");
+ return -EINVAL;
+ }
+
+ /*
+ * AI Engine platform management node ID is required for requesting
+ * services from firmware driver.
+ */
+ ret = of_property_read_u32(pdev->dev.of_node, "xlnx,firmware-device-id",
+ &pm_reg);
+ if (ret < 0) {
+ dev_err(&pdev->dev,
+ "Failed to read power management information\n");
+ return ret;
+ }
+ adev->fw_dev_id = pm_reg;
+
+ adev->clk = devm_clk_get(&pdev->dev, "aclk0");
+ if (IS_ERR(adev->clk)) {
+ dev_err(&pdev->dev, "Failed to get device clock.\n");
+ return PTR_ERR(adev->clk);
+ }
+
+ adev->base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(adev->base)) {
+ dev_err(&pdev->dev, "Failed to map IO resources\n");
+ return PTR_ERR(adev->base);
+ }
+
+ /*
+ * Initialize columns resource map to remember which columns have been
+ * assigned. Used for partition management.
+ */
+ ret = aie_resource_initialize(&adev->cols_res,
+ adev->range.size.col);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to initialize columns resource.\n");
+ return ret;
+ }
+
+ dev_dbg(&pdev->dev,
+ "AMD AI Engine device probed. Device generation: %u. Clock frequency: %luHz.\n",
+ adev->dev_gen, clk_get_rate(adev->clk));
+ dev_dbg(&pdev->dev,
+ "AI engine cols(%u, %u) aie_tile_rows(%u, %u) memory_tile_rows(%u, %u)\n",
+ adev->range.start.col, adev->range.size.col,
+ adev->ttype_attr[AIE_TILE_TYPE_TILE].start_row,
+ adev->ttype_attr[AIE_TILE_TYPE_TILE].num_rows,
+ adev->ttype_attr[AIE_TILE_TYPE_MEMORY].start_row,
+ adev->ttype_attr[AIE_TILE_TYPE_MEMORY].num_rows);
+ return 0;
+}
+
+static void amd_ai_engine_remove(struct platform_device *pdev)
+{
+ struct aie_device *adev = platform_get_drvdata(pdev);
+ struct aie_partition *apart, *lapart;
+
+ mutex_lock(&adev->mlock);
+ list_for_each_entry_safe(apart, lapart, &adev->partitions, node)
+ aie_part_release(apart);
+ mutex_unlock(&adev->mlock);
+
+ aie_resource_uninitialize(&adev->cols_res);
+}
+
+static const struct aie_device_cfg versal2_aieml = {
+ .num_columns = 32,
+ .mem_start_row = 1,
+ .mem_num_row = 2,
+ .core_start_row = 3,
+ .core_num_row = 4,
+ .aie_gen = AIE_DEVICE_GEN_AIEMLV2,
+};
+
+static const struct of_device_id amd_ai_engine_of_match[] = {
+ {
+ .compatible = "xlnx,versal2-aieml",
+ .data = &versal2_aieml,
+ },
+ { /* end of table */ },
+};
+MODULE_DEVICE_TABLE(of, amd_ai_engine_of_match);
+
+static struct platform_driver amd_ai_engine_driver = {
+ .probe = amd_ai_engine_probe,
+ .remove = amd_ai_engine_remove,
+ .driver = {
+ .name = "amd-ai-engine",
+ .of_match_table = amd_ai_engine_of_match,
+ },
+};
+
+static int __init amd_ai_engine_init(void)
+{
+ return platform_driver_register(&amd_ai_engine_driver);
+}
+module_init(amd_ai_engine_init);
+
+static void __exit amd_ai_engine_exit(void)
+{
+ platform_driver_unregister(&amd_ai_engine_driver);
+}
+module_exit(amd_ai_engine_exit);
+
+MODULE_AUTHOR("Advanced Micro Devices, Inc.");
+MODULE_DESCRIPTION("AMD Versal AI Engine driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/accel/amd-ai-engine/ai-engine-internal.h b/drivers/accel/amd-ai-engine/ai-engine-internal.h
new file mode 100644
index 000000000000..61ebd7f4b3d1
--- /dev/null
+++ b/drivers/accel/amd-ai-engine/ai-engine-internal.h
@@ -0,0 +1,160 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * AMD AI Engine driver internal header
+ *
+ * Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
+ */
+
+#ifndef AIE_INTERNAL_H
+#define AIE_INTERNAL_H
+
+#include <linux/amd-ai-engine.h>
+#include <linux/clk.h>
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+
+#define AIE_DEVICE_GEN_AIEMLV2 3U
+
+/*
+ * Macros for AI engine tile type
+ */
+enum aie_tile_type {
+ AIE_TILE_TYPE_TILE,
+ AIE_TILE_TYPE_SHIMPL,
+ AIE_TILE_TYPE_SHIMNOC,
+ AIE_TILE_TYPE_MEMORY,
+ AIE_TILE_TYPE_MAX
+};
+
+struct aie_device;
+struct aie_partition;
+
+/**
+ * struct aie_tile_operations - AI engine device operations
+ * @get_tile_type: get type of tile based on tile operation
+ * Different AI engine device version has its own device
+ * operation.
+ */
+struct aie_tile_operations {
+ u32 (*get_tile_type)(struct aie_device *adev, struct aie_location *loc);
+};
+
+/**
+ * struct aie_resource - AI engine resource structure
+ * @bitmap: resource bitmap
+ * @total: total number of resource
+ */
+struct aie_resource {
+ unsigned long *bitmap;
+ u32 total;
+};
+
+/**
+ * struct aie_range - AIE range information
+ * @start: start tile location
+ * @size: size of the range, number of columns and rows
+ */
+struct aie_range {
+ struct aie_location start;
+ struct aie_location size;
+};
+
+/**
+ * struct aie_tile_attr - AI engine device tile type attributes
+ * @start_row: start row
+ * @num_rows: number of rows
+ */
+struct aie_tile_attr {
+ u8 start_row;
+ u8 num_rows;
+};
+
+/**
+ * struct aie_device - AI engine device structure
+ * @partitions: list of partitions
+ * @dev: device pointer for the AI engine device
+ * @mlock: protection for AI engine device operations
+ * @clk: AI engine device clock
+ * @base: AI engine base virtual address
+ * @ops: tile operations
+ * @cols_res: AI engine columns resources to indicate
+ * while columns are occupied by partitions.
+ * @ttype_attr: tile type attributes
+ * @range: range of whole AI engine
+ * @array_shift: array address shift
+ * @col_shift: column address shift
+ * @row_shift: row address shift
+ * @dev_gen: aie hardware device generation
+ * @fw_dev_id: AI Engine firmware device ID
+ */
+struct aie_device {
+ struct list_head partitions;
+ struct device *dev;
+ struct mutex mlock;
+ struct clk *clk;
+ void __iomem *base;
+ const struct aie_tile_operations *ops;
+ struct aie_resource cols_res;
+ struct aie_tile_attr ttype_attr[AIE_TILE_TYPE_MAX];
+ struct aie_range range;
+ u32 array_shift;
+ u32 col_shift;
+ u32 row_shift;
+ u32 dev_gen;
+ u32 fw_dev_id;
+};
+
+/**
+ * struct aie_partition - AI engine partition structure
+ * @node: list node
+ * @dev: AI Engine partition device
+ * @adev: pointer to AI device instance
+ * @range: range of partition
+ * @mlock: protection for AI engine partition operations
+ */
+struct aie_partition {
+ struct list_head node;
+ struct device dev;
+ struct aie_device *adev;
+ struct aie_range range;
+ struct mutex mlock;
+};
+
+/**
+ * struct aie_device_cfg - AI engine device configuration and layout
+ * @num_columns: number of columns in the device
+ * @mem_start_row: start row index for memory tiles
+ * @mem_num_row: number of memory tile rows
+ * @core_start_row: start row index for core tiles
+ * @core_num_row: number of core tile rows
+ * @aie_gen: AI Engine generation
+ */
+struct aie_device_cfg {
+ u8 num_columns;
+ u8 mem_start_row;
+ u8 mem_num_row;
+ u8 core_start_row;
+ u8 core_num_row;
+ u8 aie_gen;
+};
+
+#define dev_to_aiepart(_dev) container_of((_dev), struct aie_partition, dev)
+
+void aiemlv2_device_init(struct aie_device *adev);
+struct aie_partition *aie_part_create(struct aie_device *adev,
+ u8 start_col, u8 num_col);
+void aie_part_release(struct aie_partition *apart);
+int aie_resource_initialize(struct aie_resource *res, int count);
+void aie_resource_uninitialize(struct aie_resource *res);
+int aie_resource_check_region(struct aie_resource *res, u32 start,
+ u32 count);
+int aie_resource_get_region(struct aie_resource *res, u32 start,
+ u32 count);
+void aie_resource_put_region(struct aie_resource *res, int start, u32 count);
+
+#endif /* AIE_INTERNAL_H */
diff --git a/drivers/accel/amd-ai-engine/ai-engine-part.c b/drivers/accel/amd-ai-engine/ai-engine-part.c
new file mode 100644
index 000000000000..f80a6fa433aa
--- /dev/null
+++ b/drivers/accel/amd-ai-engine/ai-engine-part.c
@@ -0,0 +1,77 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AMD AI Engine partition implementation
+ *
+ * Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
+ */
+
+#include <linux/amd-ai-engine.h>
+#include <linux/device.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+
+#include "ai-engine-internal.h"
+
+/**
+ * aie_part_release() - release an AI engine partition instance
+ * @apart: AI engine partition device
+ */
+void aie_part_release(struct aie_partition *apart)
+{
+ struct aie_device *adev = apart->adev;
+
+ list_del(&apart->node);
+ aie_resource_put_region(&adev->cols_res,
+ apart->range.start.col -
+ adev->range.start.col,
+ apart->range.size.col);
+ device_unregister(&apart->dev);
+}
+
+static void aie_part_release_device(struct device *dev)
+{
+ (void)dev;
+}
+
+/**
+ * aie_part_create() - create AI engine partition instance
+ * @adev: AI engine device
+ * @start_col: start column of AI engine partition
+ * @num_col: number of columns of AI engine partition
+ *
+ * Return: created AI engine partition pointer for success, and PTR_ERR
+ * for failure.
+ */
+struct aie_partition *aie_part_create(struct aie_device *adev,
+ u8 start_col, u8 num_col)
+{
+ struct aie_partition *apart;
+ struct device *dev;
+
+ apart = devm_kzalloc(adev->dev, sizeof(*apart), GFP_KERNEL);
+ if (!apart)
+ return ERR_PTR(-ENOMEM);
+
+ apart->adev = adev;
+ mutex_init(&apart->mlock);
+ apart->range.start.col = start_col;
+ apart->range.size.col = num_col;
+ apart->range.start.row = adev->range.start.row;
+ apart->range.size.row = adev->range.size.row;
+
+ /* create partition device */
+ dev = &apart->dev;
+ dev->parent = apart->adev->dev;
+ dev_set_name(dev, "aiepart_%u_%u", apart->range.start.col,
+ apart->range.size.col);
+ dev_set_drvdata(dev, apart);
+ dev->release = aie_part_release_device;
+
+ if (device_register(&apart->dev)) {
+ dev_err(adev->dev, "failed to register partition device\n");
+ put_device(dev);
+ return ERR_PTR(-ENODEV);
+ }
+
+ return apart;
+}
diff --git a/drivers/accel/amd-ai-engine/ai-engine-res.c b/drivers/accel/amd-ai-engine/ai-engine-res.c
new file mode 100644
index 000000000000..62df26edf87d
--- /dev/null
+++ b/drivers/accel/amd-ai-engine/ai-engine-res.c
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AMD AI Engine resource implementation
+ *
+ * Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
+ */
+
+#include <linux/bitmap.h>
+
+#include "ai-engine-internal.h"
+
+/**
+ * aie_resource_initialize() - initialize AI engine resource
+ * @res: pointer to AI engine resource
+ * @count: total number of element of this resource
+ *
+ * Return: 0 for success, negative value for failure.
+ *
+ * This function will initialize the data structure for the
+ * resource.
+ */
+int aie_resource_initialize(struct aie_resource *res, int count)
+{
+ res->bitmap = bitmap_zalloc(count, GFP_KERNEL);
+ if (!res->bitmap)
+ return -ENOMEM;
+ res->total = count;
+
+ return 0;
+}
+
+/**
+ * aie_resource_uninitialize() - uninitialize AI engine resource
+ * @res: pointer to AI engine resource
+ *
+ * This function will release the AI engine resource data members.
+ */
+void aie_resource_uninitialize(struct aie_resource *res)
+{
+ res->total = 0;
+ if (res->bitmap)
+ bitmap_free(res->bitmap);
+}
+
+/**
+ * aie_resource_check_region() - check availability of requested resource
+ * @res: pointer to AI engine resource to check
+ * @start: start index of the required resource
+ * @count: number of requested element
+ *
+ * Return: start resource id if the requested number of resources are available
+ * It will return negative value of errors.
+ *
+ * This function will check the availability. It will return start resource id
+ * if the requested number of resources are available.
+ */
+int aie_resource_check_region(struct aie_resource *res,
+ u32 start, u32 count)
+{
+ unsigned long id;
+
+ if (!res || !res->bitmap || !count)
+ return -EINVAL;
+ id = bitmap_find_next_zero_area(res->bitmap, res->total, start,
+ count, 0);
+ if (id >= res->total)
+ return -ERANGE;
+
+ return (int)id;
+}
+
+/**
+ * aie_resource_get_region() - get requested AI engine resource
+ * @res: pointer to AI engine resource to check
+ * @start: start index of the required resource
+ * @count: number of requested element
+ *
+ * Return: start resource id for success, and negative value for failure.
+ *
+ * This function check if the requested AI engine resource is available.
+ * If it is available, mark it used and return the start resource id.
+ */
+int aie_resource_get_region(struct aie_resource *res, u32 start, u32 count)
+{
+ unsigned long off;
+
+ if (!res || !res->bitmap || !count)
+ return -EINVAL;
+ off = bitmap_find_next_zero_area(res->bitmap, res->total, start,
+ count, 0);
+ if (off >= res->total)
+ return -ERANGE;
+
+ bitmap_set(res->bitmap, off, count);
+
+ return (int)off;
+}
+
+/**
+ * aie_resource_put_region() - release requested AI engine resource
+ * @res: pointer to AI engine resource to check
+ * @start: start index of the resource to release
+ * @count: number of elements to release
+ *
+ * This function release the requested AI engine resource.
+ */
+void aie_resource_put_region(struct aie_resource *res, int start, u32 count)
+{
+ if (!res || !count)
+ return;
+ bitmap_clear(res->bitmap, start, count);
+}
diff --git a/include/linux/amd-ai-engine.h b/include/linux/amd-ai-engine.h
new file mode 100644
index 000000000000..f5750d219e21
--- /dev/null
+++ b/include/linux/amd-ai-engine.h
@@ -0,0 +1,59 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * amd-ai-engine.h - AMD AI engine external interface
+ *
+ * Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
+ */
+
+#ifndef _AMD_AI_ENGINE_H_
+#define _AMD_AI_ENGINE_H_
+
+#include <linux/device.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+
+#define AIE_PART_ID_START_COL_SHIFT 0U
+#define AIE_PART_ID_NUM_COLS_SHIFT 8U
+#define AIE_PART_ID_START_COL_MASK (0xFFU << AIE_PART_ID_START_COL_SHIFT)
+#define AIE_PART_ID_NUM_COLS_MASK (0xFFU << AIE_PART_ID_NUM_COLS_SHIFT)
+
+#define aie_part_id_get_val(part_id, F) \
+ (((part_id) & AIE_PART_ID_##F ##_MASK) >> AIE_PART_ID_##F ##_SHIFT)
+#define aie_part_id_get_start_col(part_id) \
+ aie_part_id_get_val((part_id), START_COL)
+#define aie_part_id_get_num_cols(part_id) \
+ aie_part_id_get_val((part_id), NUM_COLS)
+#define aie_calc_part_id(start_col, num_col) \
+ (((start_col) << AIE_PART_ID_START_COL_SHIFT) + \
+ ((num_col) << AIE_PART_ID_NUM_COLS_SHIFT))
+
+/**
+ * struct aie_partition_req - AIE request partition arguments
+ * @partition_id: partition node id. It is used to identify the AI engine
+ * partition. Its format is:
+ * Reserved_16bits | start_col_8bits | num_cols_8bits
+ * @meta_data: meta data to indicate which resources used by application.
+ * @flag: used for application to indicate particular driver requirements
+ * application wants to have for the partition. e.g. do not clean
+ * resource when closing the partition.
+ */
+struct aie_partition_req {
+ u32 partition_id;
+ u64 meta_data;
+ u32 flag;
+};
+
+/**
+ * struct aie_location - AIE location information
+ * @col: column id
+ * @row: row id
+ */
+struct aie_location {
+ u32 col;
+ u32 row;
+};
+
+struct device *aie_partition_request(struct device *dev, struct aie_partition_req *req);
+void aie_partition_release(struct device *dev);
+
+#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 12/15] accel/amd-ai-engine: Add AMD AI Engine device driver
2026-11-18 23:32 ` [PATCH 12/15] accel/amd-ai-engine: Add AMD AI Engine device driver Gregory Williams
@ 2026-11-18 23:45 ` sashiko-bot
0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-11-18 23:45 UTC (permalink / raw)
To: Gregory Williams; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] accel/amd-ai-engine: memory leak and lifetime bug in
aie_part_create()
- [Low] accel/amd-ai-engine: dead code, unused exports, and missing
accel integration
--
commit 9d0271621aaf2e78655cf01aa521aa41dffc506a
Author: Gregory Williams <gregory.williams@amd.com>
accel/amd-ai-engine: Add AMD AI Engine device driver
This commit adds the initial AMD Versal AI Engine platform driver under
drivers/accel/amd-ai-engine, including device probing, column resource
tracking, and partition request and release APIs.
> diff --git a/drivers/accel/amd-ai-engine/Kconfig b/drivers/accel/amd-ai-engine/Kconfig
> new file mode 100644
> index 0000000000000..7f32928cb20f2
> --- /dev/null
> +++ b/drivers/accel/amd-ai-engine/Kconfig
> @@ -0,0 +1,15 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +config DRM_ACCEL_AMDAIE
> + tristate "AMD Versal AI Engine"
> + depends on ARM64 || COMPILE_TEST
> + depends on ZYNQMP_FIRMWARE
> + depends on DRM_ACCEL
> + help
> + This option enables support for the AMD AI engine driver.
> + One AMD AI engine device can have multiple partitions (groups of
> + AI engine tiles). AMD AI engine device driver instance manages
> + AI engine partitions. Applications access its partitions through
> + AI engine partition device instance.
> +
> + If unsure, say N.
[Severity: Low]
Why is this driver placed under drivers/accel/ with a dependency on
DRM_ACCEL when it does not register a drm_device with DRIVER_COMPUTE_ACCEL
or expose any userspace interface across the series?
Also, aie_partition_request() and aie_partition_release() in
ai-engine-dev.c are exported with EXPORT_SYMBOL_GPL() without any in-tree
callers in the series, and aie_resource_check_region() in ai-engine-res.c
is never called.
> diff --git a/drivers/accel/amd-ai-engine/ai-engine-part.c b/drivers/accel/amd-ai-engine/ai-engine-part.c
> new file mode 100644
> index 0000000000000..f80a6fa433aa1
> --- /dev/null
> +++ b/drivers/accel/amd-ai-engine/ai-engine-part.c
[ ... ]
> @@ -0,0 +1,77 @@
[ ... ]
> +void aie_part_release(struct aie_partition *apart)
> +{
> + struct aie_device *adev = apart->adev;
> +
> + list_del(&apart->node);
> + aie_resource_put_region(&adev->cols_res,
> + apart->range.start.col -
> + adev->range.start.col,
> + apart->range.size.col);
> + device_unregister(&apart->dev);
> +}
> +
> +static void aie_part_release_device(struct device *dev)
> +{
> + (void)dev;
> +}
> +
> +/**
> + * aie_part_create() - create AI engine partition instance
> + * @adev: AI engine device
> + * @start_col: start column of AI engine partition
> + * @num_col: number of columns of AI engine partition
> + *
> + * Return: created AI engine partition pointer for success, and PTR_ERR
> + * for failure.
> + */
> +struct aie_partition *aie_part_create(struct aie_device *adev,
> + u8 start_col, u8 num_col)
> +{
> + struct aie_partition *apart;
> + struct device *dev;
> +
> + apart = devm_kzalloc(adev->dev, sizeof(*apart), GFP_KERNEL);
> + if (!apart)
> + return ERR_PTR(-ENOMEM);
> +
> + apart->adev = adev;
> + mutex_init(&apart->mlock);
> + apart->range.start.col = start_col;
> + apart->range.size.col = num_col;
> + apart->range.start.row = adev->range.start.row;
> + apart->range.size.row = adev->range.size.row;
> +
> + /* create partition device */
> + dev = &apart->dev;
> + dev->parent = apart->adev->dev;
> + dev_set_name(dev, "aiepart_%u_%u", apart->range.start.col,
> + apart->range.size.col);
> + dev_set_drvdata(dev, apart);
> + dev->release = aie_part_release_device;
> +
> + if (device_register(&apart->dev)) {
> + dev_err(adev->dev, "failed to register partition device\n");
> + put_device(dev);
> + return ERR_PTR(-ENODEV);
> + }
> +
> + return apart;
> +}
[Severity: High]
Does allocating apart with devm_kzalloc(adev->dev, ...) and using a no-op
dev->release callback leak struct aie_partition across runtime partition
request and release cycles?
Every call to aie_partition_release() (as well as the device_register()
error path in aie_part_create()) drops the reference on apart->dev without
freeing apart, leaving it allocated on adev->dev's devres list until the
parent driver unbinds. In addition, tying a structure that embeds a
reference-counted struct device to parent devres frees apart on parent
unbind even if external references to apart->dev are still held, causing a
use-after-free when the last reference is dropped.
Allocating apart with kzalloc() and freeing it with kfree() in
aie_part_release_device() would tie its lifetime to apart->dev;
aie_partition_release() in ai-engine-dev.c would then also need to save
apart->adev in a local variable before calling aie_part_release(apart) so
that mutex_unlock(&adev->mlock) does not dereference apart after
device_unregister(&apart->dev) frees it.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118233211.4121361-1-gregory.williams@amd.com?part=12
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 13/15] accel/amd-ai-engine: Add pm ops for firmware calls
2026-11-18 23:31 [PATCH 00/15] accel: Add AMD Versal AI Engine driver (with Versal Gen 2 firmware support) Gregory Williams
2026-11-18 23:32 ` [PATCH 11/15] dt-bindings: soc: xilinx: Add Versal AI Engine DT binding Gregory Williams
2026-11-18 23:32 ` [PATCH 12/15] accel/amd-ai-engine: Add AMD AI Engine device driver Gregory Williams
@ 2026-11-18 23:32 ` Gregory Williams
2026-11-18 23:46 ` sashiko-bot
2026-11-18 23:32 ` [PATCH 14/15] accel/amd-ai-engine: Add support to enable/disable tile clocks Gregory Williams
` (2 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Gregory Williams @ 2026-11-18 23:32 UTC (permalink / raw)
To: Oded Gabbay; +Cc: linux-kernel, dri-devel
The AI engine array has privileged registers that can only be written to
by the trusted firmware. The registers are critical for device
functionality such as, memory resets, column and shim resets, routing of
NoC traffic and interrupts, and enabling/disabling of tile clocks.
Structures are defined for each operation type which contain an
operation type, length, and operation specific parameters. The ops are
packed into a buffer and passed directly to the firmware which will
execute operations sequentially.
Signed-off-by: Gregory Williams <gregory.williams@amd.com>
---
drivers/accel/amd-ai-engine/Makefile | 1 +
drivers/accel/amd-ai-engine/ai-engine-dev.c | 13 +-
.../accel/amd-ai-engine/ai-engine-internal.h | 168 ++++++-
drivers/accel/amd-ai-engine/ai-engine-part.c | 17 +-
drivers/accel/amd-ai-engine/ai-engine-pm.c | 472 ++++++++++++++++++
include/linux/amd-ai-engine.h | 53 +-
6 files changed, 714 insertions(+), 10 deletions(-)
create mode 100644 drivers/accel/amd-ai-engine/ai-engine-pm.c
diff --git a/drivers/accel/amd-ai-engine/Makefile b/drivers/accel/amd-ai-engine/Makefile
index cb456ee7ec37..8b0d857d3347 100644
--- a/drivers/accel/amd-ai-engine/Makefile
+++ b/drivers/accel/amd-ai-engine/Makefile
@@ -8,4 +8,5 @@ amd-aie-$(CONFIG_DRM_ACCEL_AMDAIE) := \
ai-engine-aiemlv2.o \
ai-engine-dev.o \
ai-engine-part.o \
+ ai-engine-pm.o \
ai-engine-res.o
diff --git a/drivers/accel/amd-ai-engine/ai-engine-dev.c b/drivers/accel/amd-ai-engine/ai-engine-dev.c
index 7dad3004e30a..8866d3cf6ed8 100644
--- a/drivers/accel/amd-ai-engine/ai-engine-dev.c
+++ b/drivers/accel/amd-ai-engine/ai-engine-dev.c
@@ -8,15 +8,19 @@
#include <linux/amd-ai-engine.h>
#include <linux/clk.h>
#include <linux/device.h>
+#include <linux/dma-mapping.h>
#include <linux/io.h>
#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/of.h>
+#include <linux/of_device.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include "ai-engine-internal.h"
+#define AIE_DMA_BIT_MASK 48
+
/**
* aie_partition_request() - Request an AI engine partition
* @dev: AI engine device pointer
@@ -115,8 +119,15 @@ static int amd_ai_engine_probe(struct platform_device *pdev)
return -ENODEV;
}
- /* setup device layout configuration */
+ /* setup dma */
adev->dev = &pdev->dev;
+ ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(AIE_DMA_BIT_MASK));
+ if (ret) {
+ dev_err(adev->dev, "Failed to set dma mask\n");
+ return ret;
+ }
+
+ /* setup device layout configuration */
adev->range.start.col = 0;
adev->range.size.col = match->num_columns;
adev->range.start.row = 0;
diff --git a/drivers/accel/amd-ai-engine/ai-engine-internal.h b/drivers/accel/amd-ai-engine/ai-engine-internal.h
index 61ebd7f4b3d1..d2857ec50033 100644
--- a/drivers/accel/amd-ai-engine/ai-engine-internal.h
+++ b/drivers/accel/amd-ai-engine/ai-engine-internal.h
@@ -74,6 +74,166 @@ struct aie_tile_attr {
u8 num_rows;
};
+/**
+ * struct aie_op_start_num_col - start/number of columns op
+ * @type: operation type
+ * @len: operation struct length
+ * @start_col: start column
+ * @num_col: number of columns
+ */
+struct aie_op_start_num_col {
+ u16 type;
+ u16 len;
+ u16 start_col;
+ u16 num_col;
+} __aligned(4);
+
+/**
+ * struct aie_op_l2_ctrl_irq - l2 control irq ops
+ * @type: operation type.
+ * @len: length of the op
+ * @irq: irq value to be written to l2
+ */
+struct aie_op_l2_ctrl_irq {
+ u16 type;
+ u16 len;
+ u16 irq;
+} __aligned(4);
+
+/**
+ * struct aie_op_type_len - op that just needs type
+ * @type: operation type
+ * @len: length of the op
+ */
+struct aie_op_type_len {
+ u16 type;
+ u16 len;
+} __aligned(4);
+
+/**
+ * struct aie_op_hw_err - hardware error op
+ * @type: operation type
+ * @len: length of the op
+ * @val: value of hardware interrupt mask or irq number
+ */
+struct aie_op_hw_err {
+ u16 type;
+ u16 len;
+ u16 val;
+} __aligned(4);
+
+/**
+ * struct aie_op_uc_zeroisation - zeroize uc memory op
+ * @type: operation type
+ * @len: length of the op
+ * @flag: flag contains the following data:
+ * bit(2) - zeroize uc data memory
+ * bit(1) - zeroize uc private data memory
+ * bit(0) - zeroize uc program memory
+ */
+struct aie_op_uc_zeroisation {
+ u16 type;
+ u16 len;
+ u16 flag;
+} __aligned(4);
+
+/**
+ * struct aie_op_handshake - set handshake region op
+ * @type: operation type
+ * @len: length of the op
+ * @offset: handshake region offset
+ * @high_addr: high part of physical address of buffer with handshake data
+ * @low_addr: low part of physical address of buffer with handshake data
+ */
+struct aie_op_handshake {
+ u16 type;
+ u16 len;
+ u32 offset;
+ u32 high_addr;
+ u32 low_addr;
+} __aligned(4);
+
+/**
+ * struct aie_op_nmu_switch - nmu switch ops
+ * @type: operation type
+ * @len: length of the op
+ * @c0_route: where to route nmu data in col 0
+ * @c1_route: where to route nmu data in col 1
+ */
+struct aie_op_nmu_switch {
+ u16 type;
+ u16 len;
+ u16 c0_route;
+ u16 c1_route;
+} __aligned(4);
+
+/**
+ * struct aie_op_aximm_isolation - set axi isolation ops
+ * @type: operation type
+ * @len: length of the op
+ * @traffic: value to write to axi isolation register
+ */
+struct aie_op_aximm_isolation {
+ u16 type;
+ u16 len;
+ u16 traffic;
+} __aligned(4);
+
+/**
+ * struct aie_op_ecc_scrub_period - set ecc scrub period op
+ * @type: operation type
+ * @len: length of the op
+ * @scrub_period: ECC scrub period
+ */
+struct aie_op_ecc_scrub_period {
+ u16 type;
+ u16 len;
+ u16 scrub_period;
+} __aligned(4);
+
+/**
+ * struct aie_op_tlast - tlast errors op
+ * @type: operation type
+ * @len: length of the op
+ * @state: state of the op
+ */
+struct aie_op_tlast {
+ u16 type;
+ u16 len;
+ u16 state;
+} __aligned(4);
+
+/**
+ * struct aie_pm_ops - AI engine pm calls struct.
+ * @pkt_va: pm ops data virtual address.
+ * @pkt_dma: pm ops data dma address.
+ * @size: size of pkt_va.
+ * @offset: offset within pkt_va;
+ * @op_range: pointer to pkt_va for latest range. All op headers added at offset
+ * will be for this range.
+ */
+struct aie_pm_ops {
+ void *pkt_va;
+ dma_addr_t pkt_dma;
+ size_t size;
+ size_t offset;
+ struct aie_op_start_num_col *op_range;
+};
+
+/**
+ * struct aie_op_handshake_addr - AI engine handshake region
+ * @hs_va: virtual address of handshake buffer
+ * @size: size of buffer.
+ * @offset: offset into buffer;
+ * @hs_dma: dma address of handshake buffer
+ */
+struct aie_op_handshake_addr {
+ void *hs_va;
+ size_t size;
+ size_t offset;
+ dma_addr_t hs_dma;
+};
+
/**
* struct aie_device - AI engine device structure
* @partitions: list of partitions
@@ -116,6 +276,7 @@ struct aie_device {
* @adev: pointer to AI device instance
* @range: range of partition
* @mlock: protection for AI engine partition operations
+ * @pm_ops: pm ops pkt and metadata for pm firmware calls
*/
struct aie_partition {
struct list_head node;
@@ -123,6 +284,7 @@ struct aie_partition {
struct aie_device *adev;
struct aie_range range;
struct mutex mlock;
+ struct aie_pm_ops pm_ops;
};
/**
@@ -156,5 +318,9 @@ int aie_resource_check_region(struct aie_resource *res, u32 start,
int aie_resource_get_region(struct aie_resource *res, u32 start,
u32 count);
void aie_resource_put_region(struct aie_resource *res, int start, u32 count);
-
+int aie_part_pm_ops_create(struct aie_partition *apart);
+void aie_part_pm_ops_destroy(struct aie_partition *apart);
+int aie_part_pm_ops_flush(struct aie_partition *apart);
+int aie_part_pm_ops(struct aie_partition *apart, void *data, u32 type,
+ struct aie_range range, bool flush);
#endif /* AIE_INTERNAL_H */
diff --git a/drivers/accel/amd-ai-engine/ai-engine-part.c b/drivers/accel/amd-ai-engine/ai-engine-part.c
index f80a6fa433aa..51580049f0e7 100644
--- a/drivers/accel/amd-ai-engine/ai-engine-part.c
+++ b/drivers/accel/amd-ai-engine/ai-engine-part.c
@@ -21,6 +21,7 @@ void aie_part_release(struct aie_partition *apart)
struct aie_device *adev = apart->adev;
list_del(&apart->node);
+ aie_part_pm_ops_destroy(apart);
aie_resource_put_region(&adev->cols_res,
apart->range.start.col -
adev->range.start.col,
@@ -47,6 +48,7 @@ struct aie_partition *aie_part_create(struct aie_device *adev,
{
struct aie_partition *apart;
struct device *dev;
+ int ret;
apart = devm_kzalloc(adev->dev, sizeof(*apart), GFP_KERNEL);
if (!apart)
@@ -67,11 +69,22 @@ struct aie_partition *aie_part_create(struct aie_device *adev,
dev_set_drvdata(dev, apart);
dev->release = aie_part_release_device;
- if (device_register(&apart->dev)) {
+ ret = device_register(&apart->dev);
+ if (ret) {
dev_err(adev->dev, "failed to register partition device\n");
put_device(dev);
- return ERR_PTR(-ENODEV);
+ return ERR_PTR(ret);
+ }
+
+ ret = aie_part_pm_ops_create(apart);
+ if (ret) {
+ dev_err(&apart->dev, "failed to create pm ops buffer\n");
+ goto err;
}
return apart;
+
+err:
+ device_unregister(&apart->dev);
+ return ERR_PTR(ret);
}
diff --git a/drivers/accel/amd-ai-engine/ai-engine-pm.c b/drivers/accel/amd-ai-engine/ai-engine-pm.c
new file mode 100644
index 000000000000..103879456f52
--- /dev/null
+++ b/drivers/accel/amd-ai-engine/ai-engine-pm.c
@@ -0,0 +1,472 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AMD AI Engine driver platform management implementations
+ *
+ * Copyright (C) 2026 Advanced Micro Devices, Inc.
+ */
+
+#include "ai-engine-internal.h"
+
+#include <linux/dma-mapping.h>
+#include <linux/firmware/xlnx-zynqmp.h>
+
+#define AIE_PM_OPS_PKT_SIZE 200
+
+int aie_part_pm_ops_create(struct aie_partition *apart)
+{
+ struct aie_pm_ops *pm_ops = &apart->pm_ops;
+
+ if (apart->adev->dev_gen != AIE_DEVICE_GEN_AIEMLV2)
+ return 0;
+
+ pm_ops->pkt_va = dma_alloc_coherent(apart->adev->dev,
+ AIE_PM_OPS_PKT_SIZE,
+ &pm_ops->pkt_dma, GFP_KERNEL);
+ if (!pm_ops->pkt_va)
+ return -ENOMEM;
+
+ pm_ops->size = AIE_PM_OPS_PKT_SIZE;
+ return 0;
+}
+
+void aie_part_pm_ops_destroy(struct aie_partition *apart)
+{
+ struct aie_pm_ops *pm_ops = &apart->pm_ops;
+
+ if (pm_ops->pkt_va)
+ dma_free_coherent(apart->adev->dev, pm_ops->size,
+ pm_ops->pkt_va, pm_ops->pkt_dma);
+
+ pm_ops->pkt_va = NULL;
+}
+
+int aie_part_pm_ops_flush(struct aie_partition *apart)
+{
+ struct aie_pm_ops *pm_ops = &apart->pm_ops;
+ int ret = 0;
+
+ /*
+ * If the last thing queued is a range header with no op after it,
+ * drop it: firmware has nothing to do for that range.
+ */
+ if (pm_ops->op_range &&
+ pm_ops->offset == (size_t)((u8 *)pm_ops->op_range -
+ (u8 *)pm_ops->pkt_va) +
+ sizeof(*pm_ops->op_range))
+ pm_ops->offset -= sizeof(*pm_ops->op_range);
+
+ if (pm_ops->offset)
+ ret = versal2_pm_aie2ps_operation(apart->adev->fw_dev_id,
+ pm_ops->offset,
+ upper_32_bits(pm_ops->pkt_dma),
+ lower_32_bits(pm_ops->pkt_dma));
+
+ pm_ops->offset = 0;
+ pm_ops->op_range = NULL;
+ memset(pm_ops->pkt_va, 0, AIE_PM_OPS_PKT_SIZE);
+
+ return ret;
+}
+
+int aie_part_pm_ops(struct aie_partition *apart, void *data, u32 type,
+ struct aie_range range, bool flush)
+{
+ struct aie_pm_ops *pm_ops = &apart->pm_ops;
+ struct aie_op_start_num_col *op_range;
+ ssize_t end;
+ int ret = 0;
+
+again:
+ op_range = pm_ops->op_range;
+ if (!op_range ||
+ op_range->num_col != range.size.col ||
+ op_range->start_col != range.start.col) {
+ if (check_add_overflow(pm_ops->offset, sizeof(*op_range), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ }
+ pm_ops->op_range = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*pm_ops->op_range);
+ op_range = pm_ops->op_range;
+ op_range->type = XILINX_AIE_OPS_START_NUM_COL;
+ op_range->start_col = range.start.col;
+ op_range->num_col = range.size.col;
+ op_range->len = sizeof(*op_range);
+ }
+
+ if (type & AIE_PART_INIT_OPT_COLUMN_RST) {
+ struct aie_op_type_len *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_COLUMN_RST;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_COL_RST;
+ op->len = sizeof(*op);
+ }
+ if (type & AIE_PART_INIT_OPT_SHIM_RST) {
+ struct aie_op_type_len *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_SHIM_RST;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_SHIM_RST;
+ op->len = sizeof(*op);
+ }
+ if (type & AIE_PART_INIT_OPT_BLOCK_NOCAXIMMERR) {
+ struct aie_op_type_len *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_BLOCK_NOCAXIMMERR;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_ENB_AXI_MM_ERR_EVENT;
+ op->len = sizeof(*op);
+ }
+ if (type & AIE_PART_INIT_OPT_ENB_COLCLK_BUFF) {
+ struct aie_op_type_len *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_ENB_COLCLK_BUFF;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_ENB_COL_CLK_BUFF;
+ op->len = sizeof(*op);
+ }
+ if (type & AIE_PART_INIT_OPT_DIS_COLCLK_BUFF) {
+ struct aie_op_type_len *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_DIS_COLCLK_BUFF;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_DIS_COL_CLK_BUFF;
+ op->len = sizeof(*op);
+ }
+ if (type & AIE_PART_INIT_OPT_ZEROIZEMEM) {
+ struct aie_op_type_len *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_ZEROIZEMEM;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_ZEROISATION;
+ op->len = sizeof(*op);
+ }
+ if (type & AIE_PART_INIT_OPT_UC_ENB_MEM_PRIV) {
+ struct aie_op_type_len *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_UC_ENB_MEM_PRIV;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_ENB_MEM_PRIV;
+ op->len = sizeof(*op);
+ }
+ if (type & AIE_PART_INIT_OPT_UC_DIS_MEM_PRIV) {
+ struct aie_op_type_len *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_UC_DIS_MEM_PRIV;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_DIS_MEM_PRIV;
+ op->len = sizeof(*op);
+ }
+ if (type & AIE_PART_INIT_OPT_ENB_NOC_DMA_PAUSE) {
+ struct aie_op_type_len *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_ENB_NOC_DMA_PAUSE;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_ENB_NOC_DMA_PAUSE;
+ op->len = sizeof(*op);
+ }
+ if (type & AIE_PART_INIT_OPT_ENB_UC_DMA_PAUSE) {
+ struct aie_op_type_len *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_ENB_UC_DMA_PAUSE;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_ENB_UC_DMA_PAUSE;
+ op->len = sizeof(*op);
+ }
+ if (type & AIE_PART_INIT_OPT_DIS_MEM_INTERLEAVE) {
+ struct aie_op_type_len *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_DIS_MEM_INTERLEAVE;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_DIS_MEM_INTERLEAVE;
+ op->len = sizeof(*op);
+ }
+ if (type & AIE_PART_INIT_OPT_UC_ZEROIZATION) {
+ struct aie_op_uc_zeroisation *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_UC_ZEROIZATION;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_UC_ZEROIZATION;
+ op->len = sizeof(*op);
+ op->flag = *((u16 *)data);
+ }
+ if (type & AIE_PART_INIT_OPT_ISOLATE) {
+ struct aie_op_aximm_isolation *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_ISOLATE;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_AXIMM_ISOLATION;
+ op->len = sizeof(*op);
+ op->traffic = *((u16 *)data);
+ }
+ if (type & AIE_PART_INIT_OPT_SET_L2_IRQ) {
+ struct aie_op_l2_ctrl_irq *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_SET_L2_IRQ;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_SET_L2_CTRL_NPI_INTR;
+ op->len = sizeof(*op);
+ op->irq = *((u16 *)data);
+ }
+ if (type & AIE_PART_INIT_OPT_NMU_CONFIG) {
+ struct aie_op_nmu_switch *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_NMU_CONFIG;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_NMU_CONFIG;
+ op->len = sizeof(*op);
+ /*
+ * Configure col0 to route data to east neighbor
+ * Configure col1 to accept data from west neighbor
+ */
+ op->c0_route = 0x1;
+ op->c1_route = 0x2;
+ }
+ if (type & AIE_PART_INIT_OPT_HW_ERR_INT) {
+ struct aie_op_hw_err *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_HW_ERR_INT;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_HW_ERR_INT;
+ op->len = sizeof(*op);
+ op->val = *((u16 *)data);
+ }
+ if (type & AIE_PART_INIT_OPT_HW_ERR_MASK) {
+ struct aie_op_hw_err *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_HW_ERR_MASK;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_HW_ERR_MASK;
+ op->len = sizeof(*op);
+ op->val = *((u16 *)data);
+ }
+ if (type & AIE_PART_INIT_OPT_SET_ECC_SCRUB_PERIOD) {
+ struct aie_op_ecc_scrub_period *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_SET_ECC_SCRUB_PERIOD;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_SET_ECC_SCRUB_PERIOD;
+ op->len = sizeof(*op);
+ op->scrub_period = *((u16 *)data);
+ }
+ if (type & AIE_PART_INIT_OPT_HW_ERR_STS) {
+ struct aie_op_hw_err *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_HW_ERR_STS;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_CLR_HW_ERR_STS;
+ op->len = sizeof(*op);
+ op->val = *((u16 *)data);
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ if (type & AIE_PART_INIT_OPT_DIS_TLAST_ERROR) {
+ struct aie_op_tlast *op;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+ type &= ~AIE_PART_INIT_OPT_DIS_TLAST_ERROR;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_CTRL_PKT_TLAST_ERR;
+ op->len = sizeof(*op);
+ op->state = *((u16 *)data);
+ }
+ if (type & AIE_PART_INIT_OPT_HANDSHAKE) {
+ struct aie_op_handshake *op;
+ struct aie_op_handshake_addr *hs_addr = data;
+
+ if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
+ end >= pm_ops->size) {
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ return ret;
+ goto again;
+ }
+
+ type &= ~AIE_PART_INIT_OPT_HANDSHAKE;
+ op = pm_ops->pkt_va + pm_ops->offset;
+ pm_ops->offset += sizeof(*op);
+ op->type = XILINX_AIE_OPS_HANDSHAKE;
+ op->len = sizeof(*op) + hs_addr->size;
+ op->offset = hs_addr->offset;
+ op->low_addr = hs_addr->hs_dma & 0xFFFFFFFFULL;
+ op->high_addr = hs_addr->hs_dma >> 32;
+ if (flush)
+ ret = aie_part_pm_ops_flush(apart);
+
+ if (ret)
+ return ret;
+ goto again;
+ }
+
+ if (type)
+ dev_warn(&apart->dev, "Unknown ops type: 0x%x\n", type);
+
+ if (flush)
+ ret = aie_part_pm_ops_flush(apart);
+
+ return ret;
+}
diff --git a/include/linux/amd-ai-engine.h b/include/linux/amd-ai-engine.h
index f5750d219e21..9df3463985af 100644
--- a/include/linux/amd-ai-engine.h
+++ b/include/linux/amd-ai-engine.h
@@ -12,6 +12,16 @@
#include <linux/list.h>
#include <linux/mutex.h>
+/**
+ * struct aie_location - AIE location information
+ * @col: column id
+ * @row: row id
+ */
+struct aie_location {
+ u32 col;
+ u32 row;
+};
+
#define AIE_PART_ID_START_COL_SHIFT 0U
#define AIE_PART_ID_NUM_COLS_SHIFT 8U
#define AIE_PART_ID_START_COL_MASK (0xFFU << AIE_PART_ID_START_COL_SHIFT)
@@ -43,14 +53,45 @@ struct aie_partition_req {
u32 flag;
};
+/*
+ * AI engine partition initialize options
+ */
+#define AIE_PART_INIT_OPT_START_NUM_COL 0U
+#define AIE_PART_INIT_OPT_COLUMN_RST BIT(0)
+#define AIE_PART_INIT_OPT_SHIM_RST BIT(1)
+#define AIE_PART_INIT_OPT_BLOCK_NOCAXIMMERR BIT(2)
+#define AIE_PART_INIT_OPT_ISOLATE BIT(3)
+#define AIE_PART_INIT_OPT_ZEROIZEMEM BIT(4)
+#define AIE_PART_INIT_OPT_UC_ENB_MEM_PRIV BIT(5)
+#define AIE_PART_INIT_ERROR_HANDLING BIT(6)
+#define AIE_PART_INIT_OPT_DIS_COLCLK_BUFF BIT(7)
+#define AIE_PART_INIT_OPT_SET_L2_IRQ BIT(8)
+#define AIE_PART_INIT_OPT_HW_ERR_INT BIT(9)
+#define AIE_PART_INIT_OPT_HW_ERR_MASK BIT(10)
+#define AIE_PART_INIT_OPT_SET_ECC_SCRUB_PERIOD BIT(11)
+#define AIE_PART_INIT_OPT_NMU_CONFIG BIT(12)
+#define AIE_PART_INIT_OPT_ENB_COLCLK_BUFF BIT(13)
+#define AIE_PART_INIT_OPT_UC_ZEROIZATION BIT(14)
+#define AIE_PART_INIT_OPT_UC_DIS_MEM_PRIV BIT(15)
+#define AIE_PART_INIT_OPT_ENB_NOC_DMA_PAUSE BIT(16)
+#define AIE_PART_INIT_OPT_ENB_UC_DMA_PAUSE BIT(17)
+#define AIE_PART_INIT_OPT_HW_ERR_STS BIT(18)
+#define AIE_PART_INIT_OPT_DIS_MEM_INTERLEAVE BIT(19)
+#define AIE_PART_INIT_OPT_HANDSHAKE BIT(20)
+#define AIE_PART_INIT_OPT_DIS_TLAST_ERROR BIT(21)
+#define AIE_PART_INIT_OPT_EN_TLAST_ERROR BIT(22)
+
/**
- * struct aie_location - AIE location information
- * @col: column id
- * @row: row id
+ * struct aie_op_handshake_data - AI engine uc handshake region information
+ * @addr: handshake data address from where the data needs to be copied.
+ * @size: handshake data size.
+ * @offset: offset for handshake region update.
*/
-struct aie_location {
- u32 col;
- u32 row;
+struct aie_op_handshake_data {
+ void *addr;
+ size_t size;
+ size_t offset;
+ struct aie_location loc;
};
struct device *aie_partition_request(struct device *dev, struct aie_partition_req *req);
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 13/15] accel/amd-ai-engine: Add pm ops for firmware calls
2026-11-18 23:32 ` [PATCH 13/15] accel/amd-ai-engine: Add pm ops for firmware calls Gregory Williams
@ 2026-11-18 23:46 ` sashiko-bot
0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-11-18 23:46 UTC (permalink / raw)
To: Gregory Williams; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] accel/amd-ai-engine: spurious goto again after flush in
aie_part_pm_ops()
- [Low] accel/amd-ai-engine: missing @loc kernel-doc in
aie_op_handshake_data
- [Low] accel/amd-ai-engine: 32-bit shift overflow on dma_addr_t in
aie_part_pm_ops()
--
commit d2e06ea50ba27d65c500c4af65cd1c3eb56d05cf
Author: Gregory Williams <gregory.williams@amd.com>
accel/amd-ai-engine: Add pm ops for firmware calls
This commit adds platform management operation structures and helpers to
pack and flush privileged AI Engine register operations to trusted
firmware via coherent DMA buffers.
> diff --git a/drivers/accel/amd-ai-engine/ai-engine-pm.c b/drivers/accel/amd-ai-engine/ai-engine-pm.c
> new file mode 100644
> index 0000000000000..103879456f520
> --- /dev/null
> +++ b/drivers/accel/amd-ai-engine/ai-engine-pm.c
> @@ -0,0 +1,472 @@
[ ... ]
> +int aie_part_pm_ops(struct aie_partition *apart, void *data, u32 type,
> + struct aie_range range, bool flush)
> +{
> + struct aie_pm_ops *pm_ops = &apart->pm_ops;
> + struct aie_op_start_num_col *op_range;
> + ssize_t end;
> + int ret = 0;
> +
> +again:
> + op_range = pm_ops->op_range;
> + if (!op_range ||
> + op_range->num_col != range.size.col ||
> + op_range->start_col != range.start.col) {
> + if (check_add_overflow(pm_ops->offset, sizeof(*op_range), &end) ||
> + end >= pm_ops->size) {
> + ret = aie_part_pm_ops_flush(apart);
> + if (ret)
> + return ret;
> + }
> + pm_ops->op_range = pm_ops->pkt_va + pm_ops->offset;
> + pm_ops->offset += sizeof(*pm_ops->op_range);
> + op_range = pm_ops->op_range;
> + op_range->type = XILINX_AIE_OPS_START_NUM_COL;
> + op_range->start_col = range.start.col;
> + op_range->num_col = range.size.col;
> + op_range->len = sizeof(*op_range);
> + }
[ ... ]
> + if (type & AIE_PART_INIT_OPT_HW_ERR_STS) {
> + struct aie_op_hw_err *op;
> +
> + if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
> + end >= pm_ops->size) {
> + ret = aie_part_pm_ops_flush(apart);
> + if (ret)
> + return ret;
> + goto again;
> + }
> + type &= ~AIE_PART_INIT_OPT_HW_ERR_STS;
> + op = pm_ops->pkt_va + pm_ops->offset;
> + pm_ops->offset += sizeof(*op);
> + op->type = XILINX_AIE_OPS_CLR_HW_ERR_STS;
> + op->len = sizeof(*op);
> + op->val = *((u16 *)data);
> + ret = aie_part_pm_ops_flush(apart);
> + if (ret)
> + return ret;
> + goto again;
> + }
> + if (type & AIE_PART_INIT_OPT_DIS_TLAST_ERROR) {
> + struct aie_op_tlast *op;
> +
> + if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
> + end >= pm_ops->size) {
> + ret = aie_part_pm_ops_flush(apart);
> + if (ret)
> + return ret;
> + goto again;
> + }
> + type &= ~AIE_PART_INIT_OPT_DIS_TLAST_ERROR;
> + op = pm_ops->pkt_va + pm_ops->offset;
> + pm_ops->offset += sizeof(*op);
> + op->type = XILINX_AIE_OPS_CTRL_PKT_TLAST_ERR;
> + op->len = sizeof(*op);
> + op->state = *((u16 *)data);
> + }
> + if (type & AIE_PART_INIT_OPT_HANDSHAKE) {
> + struct aie_op_handshake *op;
> + struct aie_op_handshake_addr *hs_addr = data;
> +
> + if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
> + end >= pm_ops->size) {
> + ret = aie_part_pm_ops_flush(apart);
> + if (ret)
> + return ret;
> + goto again;
> + }
> +
> + type &= ~AIE_PART_INIT_OPT_HANDSHAKE;
> + op = pm_ops->pkt_va + pm_ops->offset;
> + pm_ops->offset += sizeof(*op);
> + op->type = XILINX_AIE_OPS_HANDSHAKE;
> + op->len = sizeof(*op) + hs_addr->size;
> + op->offset = hs_addr->offset;
> + op->low_addr = hs_addr->hs_dma & 0xFFFFFFFFULL;
> + op->high_addr = hs_addr->hs_dma >> 32;
[Severity: Low]
Can shifting hs_addr->hs_dma by 32 bits trigger a -Wshift-count-overflow
warning on 32-bit COMPILE_TEST builds?
hs_dma has type dma_addr_t, which is 32 bits wide when
CONFIG_ARCH_DMA_ADDR_T_64BIT is disabled. Using lower_32_bits() and
upper_32_bits() as in aie_part_pm_ops_flush() avoids the shift overflow.
> + if (flush)
> + ret = aie_part_pm_ops_flush(apart);
> +
> + if (ret)
> + return ret;
> + goto again;
> + }
> +
> + if (type)
> + dev_warn(&apart->dev, "Unknown ops type: 0x%x\n", type);
> +
> + if (flush)
> + ret = aie_part_pm_ops_flush(apart);
> +
> + return ret;
> +}
[Severity: Medium]
Why do the AIE_PART_INIT_OPT_HW_ERR_STS and AIE_PART_INIT_OPT_HANDSHAKE
branches flush and jump back to again after queuing their operation?
Jumping to again after aie_part_pm_ops_flush() resets pm_ops->op_range to
NULL causes a new XILINX_AIE_OPS_START_NUM_COL range header to be written
into pm_ops->pkt_va even when no bits remain in type. When flush is
true, the function then flushes a second time at the end; when flush is
false with AIE_PART_INIT_OPT_HW_ERR_STS (which also ignores the flush
parameter), an empty range header is left in pm_ops->pkt_va and will not
be stripped by aie_part_pm_ops_flush() if the next call uses a different
column range.
> diff --git a/include/linux/amd-ai-engine.h b/include/linux/amd-ai-engine.h
> index f5750d219e211..9df3463985afd 100644
> --- a/include/linux/amd-ai-engine.h
> +++ b/include/linux/amd-ai-engine.h
[ ... ]
> +/**
> + * struct aie_op_handshake_data - AI engine uc handshake region information
> + * @addr: handshake data address from where the data needs to be copied.
> + * @size: handshake data size.
> + * @offset: offset for handshake region update.
> + */
> +struct aie_op_handshake_data {
> + void *addr;
> + size_t size;
> + size_t offset;
> + struct aie_location loc;
> +};
[Severity: Low]
The kernel-doc comment for struct aie_op_handshake_data is missing an
entry for @loc, which will trigger a kernel-doc warning under W=1.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118233211.4121361-1-gregory.williams@amd.com?part=13
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 14/15] accel/amd-ai-engine: Add support to enable/disable tile clocks
2026-11-18 23:31 [PATCH 00/15] accel: Add AMD Versal AI Engine driver (with Versal Gen 2 firmware support) Gregory Williams
` (2 preceding siblings ...)
2026-11-18 23:32 ` [PATCH 13/15] accel/amd-ai-engine: Add pm ops for firmware calls Gregory Williams
@ 2026-11-18 23:32 ` Gregory Williams
2026-11-18 23:45 ` sashiko-bot
2026-11-18 23:32 ` [PATCH 15/15] accel/amd-ai-engine: Add reset operations Gregory Williams
2026-11-19 8:19 ` [PATCH 00/15] accel: Add AMD Versal AI Engine driver (with Versal Gen 2 firmware support) Jerome Brunet
5 siblings, 1 reply; 13+ messages in thread
From: Gregory Williams @ 2026-11-18 23:32 UTC (permalink / raw)
To: Oded Gabbay; +Cc: linux-kernel, dri-devel
Add support for enabling tile clocks and requesting/releasing tiles.
Requesting tiles will enable the clocks of the tiles requested, releasing
tiles will disable the tile clocks.
Signed-off-by: Gregory Williams <gregory.williams@amd.com>
---
drivers/accel/amd-ai-engine/Makefile | 1 +
.../accel/amd-ai-engine/ai-engine-aiemlv2.c | 150 +++++++++++++++++
drivers/accel/amd-ai-engine/ai-engine-clock.c | 154 ++++++++++++++++++
.../accel/amd-ai-engine/ai-engine-internal.h | 43 +++++
drivers/accel/amd-ai-engine/ai-engine-part.c | 18 ++
drivers/accel/amd-ai-engine/ai-engine-res.c | 56 +++++++
include/linux/amd-ai-engine.h | 1 -
7 files changed, 422 insertions(+), 1 deletion(-)
create mode 100644 drivers/accel/amd-ai-engine/ai-engine-clock.c
diff --git a/drivers/accel/amd-ai-engine/Makefile b/drivers/accel/amd-ai-engine/Makefile
index 8b0d857d3347..c6d090257d6e 100644
--- a/drivers/accel/amd-ai-engine/Makefile
+++ b/drivers/accel/amd-ai-engine/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_DRM_ACCEL_AMDAIE) += amd-aie.o
amd-aie-$(CONFIG_DRM_ACCEL_AMDAIE) := \
ai-engine-aiemlv2.o \
ai-engine-dev.o \
+ ai-engine-clock.o \
ai-engine-part.o \
ai-engine-pm.o \
ai-engine-res.o
diff --git a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
index 0c9c7ccdd54e..26dd1d726bfa 100644
--- a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
+++ b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
@@ -13,6 +13,16 @@
#define AIEMLV2_COL_SHIFT 25U
#define AIEMLV2_ROW_SHIFT 20U
+/*
+ * Register offsets
+ */
+#define AIEMLV2_SHIMPL_COLCLOCK_CTRL_REGOFF 0x0007FF20U
+
+/*
+ * Register masks
+ */
+#define AIEMLV2_SHIMPL_COLCLOCK_CTRL_MASK GENMASK(1, 0)
+
static u32 aiemlv2_get_tile_type(struct aie_device *adev, struct aie_location *loc)
{
u8 num_mem_rows = adev->ttype_attr[AIE_TILE_TYPE_MEMORY].num_rows;
@@ -25,8 +35,148 @@ static u32 aiemlv2_get_tile_type(struct aie_device *adev, struct aie_location *l
return AIE_TILE_TYPE_SHIMNOC;
}
+static int aiemlv2_scan_part_clocks(struct aie_partition *apart)
+{
+ struct aie_range *range = &apart->range;
+ struct aie_device *adev = apart->adev;
+ struct aie_location loc;
+
+ /* Clear the bitmap of cores and memories clock state */
+ aie_resource_put_region(&apart->cores_clk_state, 0,
+ apart->cores_clk_state.total);
+
+ /*
+ * If the clock buffer on shim tile is enabled, then all tiles above in
+ * the same column are also enabled.
+ */
+
+ loc.row = 0;
+ for (loc.col = range->start.col;
+ loc.col < range->start.col + range->size.col;
+ loc.col++) {
+ void __iomem *va;
+ u32 val, nbitpos;
+
+ nbitpos = (loc.col - range->start.col) * (range->size.row - 1) + loc.row;
+
+ va = adev->base +
+ aie_cal_regoff(adev, loc,
+ AIEMLV2_SHIMPL_COLCLOCK_CTRL_REGOFF);
+ val = readl(va);
+
+ if (!((val & AIEMLV2_SHIMPL_COLCLOCK_CTRL_MASK) % 2))
+ continue;
+
+ aie_resource_set(&apart->cores_clk_state, nbitpos,
+ range->size.row - 1);
+ }
+ /*
+ * Set the tiles in use bitmap.
+ * In case of scanning, tiles which are powered on are considered as
+ * tiles in use.
+ */
+ bitmap_copy(apart->tiles_inuse.bitmap, apart->cores_clk_state.bitmap,
+ apart->tiles_inuse.total);
+
+ return 0;
+}
+
+static int aiemlv2_set_part_clocks(struct aie_partition *apart)
+{
+ struct aie_range *range = &apart->range;
+ struct aie_range prev_range = {};
+ struct aie_location loc;
+ int ret = -EINVAL;
+ u32 prev_ops = 0;
+
+ for (loc.col = 0; loc.col < range->size.col; loc.col++) {
+ u32 startbit, col_inuse = 0;
+
+ startbit = loc.col * (range->size.row - 1);
+
+ for (loc.row = range->start.row + 1;
+ loc.row < range->start.row + range->size.row;
+ loc.row++) {
+ u32 nbitpos = startbit + loc.row - 1;
+
+ if (aie_resource_testbit(&apart->tiles_inuse, nbitpos)) {
+ col_inuse = 1;
+ break;
+ }
+ }
+
+ if (col_inuse) {
+ struct aie_range op_range = {
+ .start.col = loc.col + range->start.col,
+ .size.col = 1,
+ };
+
+ ret = aie_resource_set(&apart->tiles_inuse, startbit,
+ apart->range.size.row - 1);
+ if (ret)
+ return ret;
+ ret = aie_resource_set(&apart->cores_clk_state, startbit,
+ apart->range.size.row - 1);
+ if (ret)
+ return ret;
+
+ if (!prev_ops) {
+ prev_range = op_range;
+ prev_ops = AIE_PART_INIT_OPT_ENB_COLCLK_BUFF;
+ continue;
+ }
+ if (prev_ops == AIE_PART_INIT_OPT_ENB_COLCLK_BUFF &&
+ ((prev_range.start.col + prev_range.size.col) == op_range.start.col)) {
+ prev_range.size.col += op_range.size.col;
+ continue;
+ }
+ ret = aie_part_pm_ops(apart, NULL, prev_ops, prev_range, 0);
+ if (ret)
+ return ret;
+ prev_ops = AIE_PART_INIT_OPT_ENB_COLCLK_BUFF;
+ prev_range = op_range;
+ } else {
+ struct aie_range op_range = {
+ .start.col = loc.col + range->start.col,
+ .size.col = 1,
+ };
+
+ ret = aie_resource_clear(&apart->tiles_inuse, startbit,
+ apart->range.size.row - 1);
+ if (ret)
+ return ret;
+ ret = aie_resource_clear(&apart->cores_clk_state, startbit,
+ apart->range.size.row - 1);
+ if (ret)
+ return ret;
+ if (!prev_ops) {
+ prev_range = op_range;
+ prev_ops = AIE_PART_INIT_OPT_DIS_COLCLK_BUFF;
+ continue;
+ }
+ if (prev_ops == AIE_PART_INIT_OPT_DIS_COLCLK_BUFF &&
+ ((prev_range.start.col + prev_range.size.col) == op_range.start.col)) {
+ prev_range.size.col += op_range.size.col;
+ continue;
+ }
+ ret = aie_part_pm_ops(apart, NULL, prev_ops, prev_range, 0);
+ if (ret)
+ return ret;
+ prev_ops = AIE_PART_INIT_OPT_DIS_COLCLK_BUFF;
+ prev_range = op_range;
+ }
+ }
+ if (prev_ops)
+ ret = aie_part_pm_ops(apart, NULL, prev_ops, prev_range, 0);
+ if (ret)
+ return ret;
+ return aie_part_pm_ops_flush(apart);
+}
+
static const struct aie_tile_operations aiemlv2_ops = {
.get_tile_type = aiemlv2_get_tile_type,
+ .scan_part_clocks = aiemlv2_scan_part_clocks,
+ .set_part_clocks = aiemlv2_set_part_clocks,
};
/**
diff --git a/drivers/accel/amd-ai-engine/ai-engine-clock.c b/drivers/accel/amd-ai-engine/ai-engine-clock.c
new file mode 100644
index 000000000000..f2bf373c1da0
--- /dev/null
+++ b/drivers/accel/amd-ai-engine/ai-engine-clock.c
@@ -0,0 +1,154 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AMD AI Engine clock operations
+ *
+ * Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
+ */
+
+#include <linux/amd-ai-engine.h>
+#include <linux/clk.h>
+#include <linux/firmware/xlnx-zynqmp.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+
+#include "ai-engine-internal.h"
+
+/**
+ * aie_part_init_clk_state() - initialize clock state and tiles in use bitmaps
+ * @apart: AI engine partition
+ *
+ * Return: error code for error 0 for success
+ */
+int aie_part_init_clk_state(struct aie_partition *apart)
+{
+ u32 num_tiles;
+ int ret;
+
+ /* SHIM row always enabled so it is not needed in the bitmap */
+ num_tiles = apart->range.size.col * (apart->range.size.row - 1);
+ ret = aie_resource_initialize(&apart->cores_clk_state, num_tiles);
+ if (ret) {
+ dev_err(&apart->dev, "failed to initialize clock state resource.\n");
+ return ret;
+ }
+
+ ret = aie_resource_initialize(&apart->tiles_inuse, num_tiles);
+ if (ret) {
+ dev_err(&apart->dev, "failed to initialize tiles in use resource.\n");
+ aie_resource_uninitialize(&apart->cores_clk_state);
+ return ret;
+ }
+
+ return 0;
+}
+
+/**
+ * aie_part_get_clk_state_bit() - return bit position of the clock state of a
+ * tile
+ * @apart: AI engine partition
+ * @loc: AI engine tile location
+ *
+ * Return: bit position for success, negative value for failure
+ */
+static int aie_part_get_clk_state_bit(struct aie_partition *apart,
+ struct aie_location *loc)
+{
+ u32 ttype = apart->adev->ops->get_tile_type(apart->adev, loc);
+
+ if (ttype != AIE_TILE_TYPE_TILE && ttype != AIE_TILE_TYPE_MEMORY)
+ return -EINVAL;
+
+ if (loc->col < apart->range.start.col)
+ return -EINVAL;
+
+ return (loc->col - apart->range.start.col) *
+ (apart->range.size.row - 1) + loc->row - 1;
+}
+
+/**
+ * aie_part_scan_clk_state() - scan the clock states of tiles of the AI engine
+ * partition
+ * @apart: AI engine partition
+ *
+ * Return: 0 for success, negative value for failure.
+ *
+ * This function will scan the clock status of both the memory and core
+ * modules.
+ */
+int aie_part_scan_clk_state(struct aie_partition *apart)
+{
+ return apart->adev->ops->scan_part_clocks(apart);
+}
+
+/**
+ * aie_part_request_tiles() - request tiles from an AI engine partition.
+ * @apart: AI engine partition
+ * @num_tiles: number of tiles to request. If it is 0, it means all tiles
+ * @locs: the AI engine tiles locations array which will be requested
+ *
+ * Return: 0 for success, negative value for failure.
+ *
+ * This function will enable clocks of the specified tiles.
+ */
+int aie_part_request_tiles(struct aie_partition *apart, u32 num_tiles,
+ struct aie_location *locs)
+{
+ int ret;
+
+ if (num_tiles == 0) {
+ aie_resource_set(&apart->tiles_inuse, 0,
+ apart->tiles_inuse.total);
+ } else {
+ u32 n;
+
+ if (!locs)
+ return -EINVAL;
+
+ for (n = 0; n < num_tiles; n++) {
+ int bit = aie_part_get_clk_state_bit(apart, &locs[n]);
+
+ if (bit >= 0)
+ aie_resource_set(&apart->tiles_inuse, bit, 1);
+ }
+ }
+ ret = apart->adev->ops->set_part_clocks(apart);
+
+ return ret;
+}
+
+/**
+ * aie_part_release_tiles() - release tiles from an AI engine partition.
+ * @apart: AI engine partition
+ * @num_tiles: number of tiles to release. If it is 0, it means all tiles
+ * @locs: the AI engine tiles locations array which will be released
+ *
+ * Return: 0 for success, negative value for failure.
+ *
+ * This function will disable clocks of the specified tiles.
+ */
+int aie_part_release_tiles(struct aie_partition *apart, u32 num_tiles,
+ struct aie_location *locs)
+{
+ int ret;
+
+ if (num_tiles == 0) {
+ aie_resource_clear(&apart->tiles_inuse, 0,
+ apart->tiles_inuse.total);
+ } else {
+ u32 n;
+
+ if (!locs)
+ return -EINVAL;
+
+ for (n = 0; n < num_tiles; n++) {
+ int bit = aie_part_get_clk_state_bit(apart, &locs[n]);
+
+ if (bit >= 0)
+ aie_resource_clear(&apart->tiles_inuse, bit, 1);
+ }
+ }
+
+ ret = apart->adev->ops->set_part_clocks(apart);
+
+ return ret;
+}
diff --git a/drivers/accel/amd-ai-engine/ai-engine-internal.h b/drivers/accel/amd-ai-engine/ai-engine-internal.h
index d2857ec50033..572476c97aad 100644
--- a/drivers/accel/amd-ai-engine/ai-engine-internal.h
+++ b/drivers/accel/amd-ai-engine/ai-engine-internal.h
@@ -37,11 +37,25 @@ struct aie_partition;
/**
* struct aie_tile_operations - AI engine device operations
* @get_tile_type: get type of tile based on tile operation
+ * @scan_part_clocks: scan partition modules to check whether the modules are
+ * clock gated or not, and update the soft clock states
+ * structure. It is required to be called when the partition
+ * is requested so that the driver knows which modules are
+ * clock gated when the partition is requested. This function
+ * expects the caller to apply partition lock before calling
+ * this function.
+ * @set_part_clocks: set partition modules clocks gate registers based on the
+ * partition clock states bitmap. This function expects the
+ * caller to apply partition lock before calling this
+ * function. The caller function will need to set the bitmap
+ * on which tiles are required to be clocked on.
* Different AI engine device version has its own device
* operation.
*/
struct aie_tile_operations {
u32 (*get_tile_type)(struct aie_device *adev, struct aie_location *loc);
+ int (*scan_part_clocks)(struct aie_partition *apart);
+ int (*set_part_clocks)(struct aie_partition *apart);
};
/**
@@ -275,6 +289,8 @@ struct aie_device {
* @dev: AI Engine partition device
* @adev: pointer to AI device instance
* @range: range of partition
+ * @cores_clk_state: bitmap to indicate the power state of core and mem tiles
+ * @tiles_inuse: bitmap to indicate if a tile is in use
* @mlock: protection for AI engine partition operations
* @pm_ops: pm ops pkt and metadata for pm firmware calls
*/
@@ -283,6 +299,8 @@ struct aie_partition {
struct device dev;
struct aie_device *adev;
struct aie_range range;
+ struct aie_resource cores_clk_state;
+ struct aie_resource tiles_inuse;
struct mutex mlock;
struct aie_pm_ops pm_ops;
};
@@ -307,10 +325,32 @@ struct aie_device_cfg {
#define dev_to_aiepart(_dev) container_of((_dev), struct aie_partition, dev)
+/**
+ * aie_cal_regoff() - calculate register offset to the whole AI engine
+ * device start address
+ * @adev: AI engine device
+ * @loc: AI engine tile location
+ * @regoff_intile: register offset within a tile
+ *
+ * Return: register offset to the whole AI engine device start address
+ */
+static inline u32 aie_cal_regoff(struct aie_device *adev,
+ struct aie_location loc, u32 regoff_intile)
+{
+ return regoff_intile + (loc.col << adev->col_shift) +
+ (loc.row << adev->row_shift);
+}
+
void aiemlv2_device_init(struct aie_device *adev);
struct aie_partition *aie_part_create(struct aie_device *adev,
u8 start_col, u8 num_col);
void aie_part_release(struct aie_partition *apart);
+int aie_part_init_clk_state(struct aie_partition *apart);
+int aie_part_scan_clk_state(struct aie_partition *apart);
+int aie_part_request_tiles(struct aie_partition *apart, u32 num_tiles,
+ struct aie_location *locs);
+int aie_part_release_tiles(struct aie_partition *apart, u32 num_tiles,
+ struct aie_location *locs);
int aie_resource_initialize(struct aie_resource *res, int count);
void aie_resource_uninitialize(struct aie_resource *res);
int aie_resource_check_region(struct aie_resource *res, u32 start,
@@ -318,6 +358,9 @@ int aie_resource_check_region(struct aie_resource *res, u32 start,
int aie_resource_get_region(struct aie_resource *res, u32 start,
u32 count);
void aie_resource_put_region(struct aie_resource *res, int start, u32 count);
+int aie_resource_set(struct aie_resource *res, u32 start, u32 count);
+int aie_resource_clear(struct aie_resource *res, u32 start, u32 count);
+bool aie_resource_testbit(struct aie_resource *res, u32 bit);
int aie_part_pm_ops_create(struct aie_partition *apart);
void aie_part_pm_ops_destroy(struct aie_partition *apart);
int aie_part_pm_ops_flush(struct aie_partition *apart);
diff --git a/drivers/accel/amd-ai-engine/ai-engine-part.c b/drivers/accel/amd-ai-engine/ai-engine-part.c
index 51580049f0e7..35451d1ed88a 100644
--- a/drivers/accel/amd-ai-engine/ai-engine-part.c
+++ b/drivers/accel/amd-ai-engine/ai-engine-part.c
@@ -26,6 +26,8 @@ void aie_part_release(struct aie_partition *apart)
apart->range.start.col -
adev->range.start.col,
apart->range.size.col);
+ aie_resource_uninitialize(&apart->cores_clk_state);
+ aie_resource_uninitialize(&apart->tiles_inuse);
device_unregister(&apart->dev);
}
@@ -82,6 +84,22 @@ struct aie_partition *aie_part_create(struct aie_device *adev,
goto err;
}
+ ret = aie_part_init_clk_state(apart);
+ if (ret) {
+ dev_err(&apart->dev, "failed to initialize clock state\n");
+ aie_part_pm_ops_destroy(apart);
+ goto err;
+ }
+
+ ret = aie_part_scan_clk_state(apart);
+ if (ret) {
+ dev_err(&apart->dev, "failed to scan clock state.");
+ aie_part_pm_ops_destroy(apart);
+ aie_resource_uninitialize(&apart->cores_clk_state);
+ aie_resource_uninitialize(&apart->tiles_inuse);
+ goto err;
+ }
+
return apart;
err:
diff --git a/drivers/accel/amd-ai-engine/ai-engine-res.c b/drivers/accel/amd-ai-engine/ai-engine-res.c
index 62df26edf87d..45b9447d896f 100644
--- a/drivers/accel/amd-ai-engine/ai-engine-res.c
+++ b/drivers/accel/amd-ai-engine/ai-engine-res.c
@@ -110,3 +110,59 @@ void aie_resource_put_region(struct aie_resource *res, int start, u32 count)
return;
bitmap_clear(res->bitmap, start, count);
}
+
+/**
+ * aie_resource_set() - set the AI engine resource bits
+ * @res: pointer to AI engine resource
+ * @start: start bit to set
+ * @count: number of bits to set
+ *
+ * Return: 0 for success and negative value for failure
+ *
+ * This function sets the specified number bits in the resource.
+ */
+int aie_resource_set(struct aie_resource *res, u32 start, u32 count)
+{
+ if (!res || !res->bitmap || !count ||
+ start > res->total || count > res->total - start)
+ return -EINVAL;
+
+ bitmap_set(res->bitmap, start, count);
+ return 0;
+}
+
+/**
+ * aie_resource_clear() - clear the AI engine resource bits
+ * @res: pointer to AI engine resource
+ * @start: start bit to set
+ * @count: number of bits to clear
+ *
+ * Return: 0 for success and negative value for failure
+ *
+ * This function clears the specified number bits in the resource.
+ */
+int aie_resource_clear(struct aie_resource *res, u32 start, u32 count)
+{
+ if (!res || !res->bitmap || !count ||
+ start > res->total || count > res->total - start)
+ return -EINVAL;
+
+ bitmap_clear(res->bitmap, start, count);
+ return 0;
+}
+
+/**
+ * aie_resource_testbit() - test if a bit is set in a AI engine resource
+ * @res: pointer to AI engine resource
+ * @bit: bit to check
+ *
+ * Return: true for set, false for not set
+ */
+bool aie_resource_testbit(struct aie_resource *res, u32 bit)
+{
+ if (!res || !res->bitmap || bit >= res->total)
+ return false;
+
+ /* Locate the unsigned long the required bit belongs to */
+ return test_bit(bit, res->bitmap);
+}
diff --git a/include/linux/amd-ai-engine.h b/include/linux/amd-ai-engine.h
index 9df3463985af..229434372fc0 100644
--- a/include/linux/amd-ai-engine.h
+++ b/include/linux/amd-ai-engine.h
@@ -96,5 +96,4 @@ struct aie_op_handshake_data {
struct device *aie_partition_request(struct device *dev, struct aie_partition_req *req);
void aie_partition_release(struct device *dev);
-
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 14/15] accel/amd-ai-engine: Add support to enable/disable tile clocks
2026-11-18 23:32 ` [PATCH 14/15] accel/amd-ai-engine: Add support to enable/disable tile clocks Gregory Williams
@ 2026-11-18 23:45 ` sashiko-bot
0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-11-18 23:45 UTC (permalink / raw)
To: Gregory Williams; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] accel/amd-ai-engine: aiemlv2_set_part_clocks() clobbers
tiles_inuse bitmap
- [Low] accel/amd-ai-engine: % 2 discards mask bit 1 in
aiemlv2_scan_part_clocks()
--
commit 31b6ed2773ef86bbc6d6e5049ee938eccc623dd5
Author: Gregory Williams <gregory.williams@amd.com>
accel/amd-ai-engine: Add support to enable/disable tile clocks
This commit adds partition clock scanning and tile clock enable/disable
operations for requesting and releasing AI Engine tiles.
> diff --git a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
> index 0c9c7ccdd54e0..26dd1d726bfad 100644
> --- a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
> +++ b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
> @@ -13,6 +13,16 @@
> #define AIEMLV2_COL_SHIFT 25U
> #define AIEMLV2_ROW_SHIFT 20U
>
> +/*
> + * Register offsets
> + */
> +#define AIEMLV2_SHIMPL_COLCLOCK_CTRL_REGOFF 0x0007FF20U
> +
> +/*
> + * Register masks
> + */
> +#define AIEMLV2_SHIMPL_COLCLOCK_CTRL_MASK GENMASK(1, 0)
> +
> static u32 aiemlv2_get_tile_type(struct aie_device *adev, struct aie_location *loc)
> {
> u8 num_mem_rows = adev->ttype_attr[AIE_TILE_TYPE_MEMORY].num_rows;
> @@ -25,8 +35,148 @@ static u32 aiemlv2_get_tile_type(struct aie_device *adev, struct aie_location *l
> return AIE_TILE_TYPE_SHIMNOC;
> }
>
> +static int aiemlv2_scan_part_clocks(struct aie_partition *apart)
> +{
> + struct aie_range *range = &apart->range;
> + struct aie_device *adev = apart->adev;
> + struct aie_location loc;
> +
> + /* Clear the bitmap of cores and memories clock state */
> + aie_resource_put_region(&apart->cores_clk_state, 0,
> + apart->cores_clk_state.total);
> +
> + /*
> + * If the clock buffer on shim tile is enabled, then all tiles above in
> + * the same column are also enabled.
> + */
> +
> + loc.row = 0;
> + for (loc.col = range->start.col;
> + loc.col < range->start.col + range->size.col;
> + loc.col++) {
> + void __iomem *va;
> + u32 val, nbitpos;
> +
> + nbitpos = (loc.col - range->start.col) * (range->size.row - 1) + loc.row;
> +
> + va = adev->base +
> + aie_cal_regoff(adev, loc,
> + AIEMLV2_SHIMPL_COLCLOCK_CTRL_REGOFF);
> + val = readl(va);
> +
> + if (!((val & AIEMLV2_SHIMPL_COLCLOCK_CTRL_MASK) % 2))
> + continue;
[Severity: Low]
Does applying "% 2" after masking with AIEMLV2_SHIMPL_COLCLOCK_CTRL_MASK
(GENMASK(1, 0)) unintentionally discard bit 1? Since (val & 0x3) % 2 only
tests bit 0, a column with bit 1 set and bit 0 clear will be treated as
clocked off during aie_part_create() -> aie_part_scan_clk_state().
> +
> + aie_resource_set(&apart->cores_clk_state, nbitpos,
> + range->size.row - 1);
> + }
> + /*
> + * Set the tiles in use bitmap.
> + * In case of scanning, tiles which are powered on are considered as
> + * tiles in use.
> + */
> + bitmap_copy(apart->tiles_inuse.bitmap, apart->cores_clk_state.bitmap,
> + apart->tiles_inuse.total);
> +
> + return 0;
> +}
> +
> +static int aiemlv2_set_part_clocks(struct aie_partition *apart)
> +{
> + struct aie_range *range = &apart->range;
> + struct aie_range prev_range = {};
> + struct aie_location loc;
> + int ret = -EINVAL;
> + u32 prev_ops = 0;
> +
> + for (loc.col = 0; loc.col < range->size.col; loc.col++) {
> + u32 startbit, col_inuse = 0;
> +
> + startbit = loc.col * (range->size.row - 1);
> +
> + for (loc.row = range->start.row + 1;
> + loc.row < range->start.row + range->size.row;
> + loc.row++) {
> + u32 nbitpos = startbit + loc.row - 1;
> +
> + if (aie_resource_testbit(&apart->tiles_inuse, nbitpos)) {
> + col_inuse = 1;
> + break;
> + }
> + }
> +
> + if (col_inuse) {
> + struct aie_range op_range = {
> + .start.col = loc.col + range->start.col,
> + .size.col = 1,
> + };
> +
> + ret = aie_resource_set(&apart->tiles_inuse, startbit,
> + apart->range.size.row - 1);
> + if (ret)
> + return ret;
> + ret = aie_resource_set(&apart->cores_clk_state, startbit,
> + apart->range.size.row - 1);
[Severity: Medium]
Should aiemlv2_set_part_clocks() avoid setting the entire column in
apart->tiles_inuse when col_inuse is true?
When aie_part_request_tiles() requests a subset of tiles in a column, it
sets only those tile bits in apart->tiles_inuse, but this call marks every
row in the column as in use. If the caller later releases the requested
tiles via aie_part_release_tiles(), only the specified tile bits are
cleared in apart->tiles_inuse, so aiemlv2_set_part_clocks() sees the remaining
row bits still set, re-sets the released bits in apart->tiles_inuse, and
never disables the column clock buffer.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118233211.4121361-1-gregory.williams@amd.com?part=14
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 15/15] accel/amd-ai-engine: Add reset operations
2026-11-18 23:31 [PATCH 00/15] accel: Add AMD Versal AI Engine driver (with Versal Gen 2 firmware support) Gregory Williams
` (3 preceding siblings ...)
2026-11-18 23:32 ` [PATCH 14/15] accel/amd-ai-engine: Add support to enable/disable tile clocks Gregory Williams
@ 2026-11-18 23:32 ` Gregory Williams
2026-11-18 23:51 ` sashiko-bot
2026-11-19 8:19 ` [PATCH 00/15] accel: Add AMD Versal AI Engine driver (with Versal Gen 2 firmware support) Jerome Brunet
5 siblings, 1 reply; 13+ messages in thread
From: Gregory Williams @ 2026-11-18 23:32 UTC (permalink / raw)
To: Oded Gabbay; +Cc: linux-kernel, dri-devel
Add reset operations partition initialize/teardown.
aie_partition_initialize should be called before application start,
aie_partition_teardown should be called after application has finished.
Initialize will reset the device configuration, clear memories, enable
clocks of used tiles, configure hardware error reporting and NMUs, and
will enable ECC scrubbing.
Teardown will clear tile memories and disable tile clocks.
Signed-off-by: Gregory Williams <gregory.williams@amd.com>
---
drivers/accel/amd-ai-engine/Makefile | 3 +-
.../accel/amd-ai-engine/ai-engine-aiemlv2.c | 244 ++++++++++++++++++
.../accel/amd-ai-engine/ai-engine-internal.h | 8 +
drivers/accel/amd-ai-engine/ai-engine-part.c | 32 +++
drivers/accel/amd-ai-engine/ai-engine-res.c | 16 ++
drivers/accel/amd-ai-engine/ai-engine-reset.c | 69 +++++
include/linux/amd-ai-engine.h | 16 ++
7 files changed, 387 insertions(+), 1 deletion(-)
create mode 100644 drivers/accel/amd-ai-engine/ai-engine-reset.c
diff --git a/drivers/accel/amd-ai-engine/Makefile b/drivers/accel/amd-ai-engine/Makefile
index c6d090257d6e..d5b6ccde0a35 100644
--- a/drivers/accel/amd-ai-engine/Makefile
+++ b/drivers/accel/amd-ai-engine/Makefile
@@ -10,4 +10,5 @@ amd-aie-$(CONFIG_DRM_ACCEL_AMDAIE) := \
ai-engine-clock.o \
ai-engine-part.o \
ai-engine-pm.o \
- ai-engine-res.o
+ ai-engine-res.o \
+ ai-engine-reset.o
diff --git a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
index 26dd1d726bfa..910a9bda2305 100644
--- a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
+++ b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
@@ -16,12 +16,16 @@
/*
* Register offsets
*/
+#define AIEMLV2_SHIMNOC_AXI_OUTSTANDING_TX_REGOFF 0x00002120U
#define AIEMLV2_SHIMPL_COLCLOCK_CTRL_REGOFF 0x0007FF20U
+#define AIEMLV2_SHIMUC_AXI_OUTSTANDING_TX_REGOFF 0x000C0024U
/*
* Register masks
*/
+#define AIEMLV2_SHIMNOC_AXI_OUTSTANDING_TX_MASK BIT(0)
#define AIEMLV2_SHIMPL_COLCLOCK_CTRL_MASK GENMASK(1, 0)
+#define AIEMLV2_SHIMUC_AXI_OUTSTANDING_TX_MASK GENMASK(1, 0)
static u32 aiemlv2_get_tile_type(struct aie_device *adev, struct aie_location *loc)
{
@@ -173,10 +177,250 @@ static int aiemlv2_set_part_clocks(struct aie_partition *apart)
return aie_part_pm_ops_flush(apart);
}
+static int aiemlv2_maskpoll_uc_outstanding_aximm_txn(struct aie_partition *apart)
+{
+ u32 end_col = apart->range.start.col + apart->range.size.col;
+ struct aie_location loc = {.row = 0};
+ int ret = 0;
+ u32 regoff;
+
+ for (loc.col = apart->range.start.col; loc.col < end_col; loc.col++) {
+ regoff = aie_cal_regoff(apart->adev, loc,
+ AIEMLV2_SHIMUC_AXI_OUTSTANDING_TX_REGOFF);
+ ret = aie_part_maskpoll_register(apart, regoff, 0x0,
+ AIEMLV2_SHIMUC_AXI_OUTSTANDING_TX_MASK,
+ 2000000);
+ if (ret < 0) {
+ dev_err(&apart->dev,
+ "failed due to outstanding UC AXIMM transactions!\n");
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static int aiemlv2_maskpoll_noc_outstanding_aximm_txn(struct aie_partition *apart)
+{
+ u32 end_col = apart->range.start.col + apart->range.size.col;
+ struct aie_location loc = {.row = 0};
+ int ret = 0;
+ u32 regoff;
+
+ for (loc.col = apart->range.start.col; loc.col < end_col; loc.col++) {
+ regoff = aie_cal_regoff(apart->adev, loc,
+ AIEMLV2_SHIMNOC_AXI_OUTSTANDING_TX_REGOFF);
+ ret = aie_part_maskpoll_register(apart, regoff, 0x0,
+ AIEMLV2_SHIMNOC_AXI_OUTSTANDING_TX_MASK,
+ 2000000);
+ if (ret < 0) {
+ dev_err(&apart->dev,
+ "failed due to outstanding NoC AXIMM transactions!\n");
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static int aiemlv2_part_init(struct aie_partition *apart,
+ struct aie_partition_init_args *args)
+{
+ u32 opts;
+ int ret;
+
+ mutex_lock(&apart->mlock);
+ opts = AIE_PART_INIT_OPT_ENB_UC_DMA_PAUSE | AIE_PART_INIT_OPT_ENB_NOC_DMA_PAUSE;
+ ret = aie_part_pm_ops(apart, NULL, opts, apart->range, 1);
+ if (ret)
+ goto out;
+
+ ret = aiemlv2_maskpoll_noc_outstanding_aximm_txn(apart);
+ if (ret)
+ goto out;
+
+ ret = aiemlv2_maskpoll_uc_outstanding_aximm_txn(apart);
+ if (ret)
+ goto out;
+
+ aie_resource_clear_all(&apart->tiles_inuse);
+ aie_resource_clear_all(&apart->cores_clk_state);
+
+ /* First lets send non-data aie_op_type_len ops */
+ opts = 0;
+ /* This operation will do first 4 steps of sequence */
+ opts |= (args->init_opts & AIE_PART_INIT_OPT_COLUMN_RST);
+ opts |= (args->init_opts & AIE_PART_INIT_OPT_SHIM_RST);
+ opts |= (args->init_opts & AIE_PART_INIT_OPT_BLOCK_NOCAXIMMERR);
+ opts |= (args->init_opts & AIE_PART_INIT_OPT_ENB_COLCLK_BUFF);
+
+ /*
+ * push opts to pm and flush, these ops need to be completed before we
+ * call the next ones
+ */
+ ret = aie_part_pm_ops(apart, NULL, opts, apart->range, 1);
+ if (ret) {
+ dev_err(&apart->dev, "pm ops: 0x%x failed: %d\n", opts, ret);
+ goto out;
+ }
+
+ if (args->init_opts & AIE_PART_INIT_OPT_ZEROIZEMEM) {
+ opts |= AIE_PART_INIT_OPT_ZEROIZEMEM;
+ ret = aie_part_pm_ops(apart, NULL, AIE_PART_INIT_OPT_ZEROIZEMEM,
+ apart->range, 1);
+ if (ret)
+ goto out;
+ }
+
+ if (args->init_opts & AIE_PART_INIT_OPT_UC_ZEROIZATION) {
+ u16 data = 0x6;
+
+ opts |= AIE_PART_INIT_OPT_UC_ZEROIZATION;
+ ret = aie_part_pm_ops(apart, &data, AIE_PART_INIT_OPT_UC_ZEROIZATION,
+ apart->range, 1);
+ if (ret)
+ goto out;
+ }
+
+ if (args->init_opts & AIE_PART_INIT_OPT_NMU_CONFIG) {
+ struct aie_range range = {0};
+
+ opts |= AIE_PART_INIT_OPT_NMU_CONFIG;
+ if (apart->range.start.col == 0) {
+ range.size.col = 2;
+ ret = aie_part_pm_ops(apart, NULL, AIE_PART_INIT_OPT_NMU_CONFIG,
+ range, 0);
+ if (ret)
+ goto out;
+ }
+ }
+
+ if (args->init_opts & AIE_PART_INIT_OPT_HW_ERR_INT) {
+ u16 data = 0;
+
+ opts |= AIE_PART_INIT_OPT_HW_ERR_INT;
+ ret = aie_part_pm_ops(apart, &data, AIE_PART_INIT_OPT_HW_ERR_INT,
+ apart->range, 0);
+ if (ret)
+ goto out;
+ }
+
+ if (args->init_opts & AIE_PART_INIT_OPT_HW_ERR_MASK) {
+ u16 data = 0x2;
+
+ opts |= AIE_PART_INIT_OPT_HW_ERR_MASK;
+ ret = aie_part_pm_ops(apart, &data, AIE_PART_INIT_OPT_HW_ERR_MASK,
+ apart->range, 0);
+ if (ret)
+ goto out;
+ }
+
+ if (args->init_opts & AIE_PART_INIT_OPT_SET_ECC_SCRUB_PERIOD) {
+ u16 data;
+
+ if (args->ecc_scrub > U16_MAX) {
+ ret = -EINVAL;
+ goto out;
+ }
+
+ data = args->ecc_scrub;
+ opts |= AIE_PART_INIT_OPT_SET_ECC_SCRUB_PERIOD;
+ ret = aie_part_pm_ops(apart, &data,
+ AIE_PART_INIT_OPT_SET_ECC_SCRUB_PERIOD,
+ apart->range, 0);
+ if (ret)
+ goto out;
+ }
+
+ if (args->init_opts & AIE_PART_INIT_OPT_UC_ENB_MEM_PRIV) {
+ opts |= AIE_PART_INIT_OPT_UC_ENB_MEM_PRIV;
+
+ ret = aie_part_pm_ops(apart, NULL, AIE_PART_INIT_OPT_UC_ENB_MEM_PRIV,
+ apart->range, 0);
+ if (ret)
+ goto out;
+ }
+
+ /* Request tile locations */
+ ret = aie_part_request_tiles(apart, args->num_tiles, args->locs);
+ if (ret)
+ goto out;
+
+ if (args->init_opts & AIE_PART_INIT_OPT_DIS_TLAST_ERROR) {
+ u16 data = 0;
+
+ opts |= AIE_PART_INIT_OPT_DIS_TLAST_ERROR;
+ ret = aie_part_pm_ops(apart, &data,
+ AIE_PART_INIT_OPT_DIS_TLAST_ERROR,
+ apart->range, 1);
+ if (ret)
+ goto out;
+ }
+
+ if (opts != args->init_opts)
+ dev_warn(&apart->dev, "Invalid init_opts: 0x%x\n", opts ^ args->init_opts);
+
+out:
+ mutex_unlock(&apart->mlock);
+ return ret;
+}
+
+static int aiemlv2_part_teardown(struct aie_partition *apart)
+{
+ u32 opts;
+ u16 data;
+ int ret;
+
+ mutex_lock(&apart->mlock);
+
+ opts = AIE_PART_INIT_OPT_ENB_UC_DMA_PAUSE | AIE_PART_INIT_OPT_ENB_NOC_DMA_PAUSE;
+ ret = aie_part_pm_ops(apart, NULL, opts, apart->range, 1);
+ if (ret)
+ goto out;
+
+ ret = aiemlv2_maskpoll_noc_outstanding_aximm_txn(apart);
+ if (ret)
+ goto out;
+
+ ret = aiemlv2_maskpoll_uc_outstanding_aximm_txn(apart);
+ if (ret)
+ goto out;
+
+ opts = AIE_PART_INIT_OPT_COLUMN_RST |
+ AIE_PART_INIT_OPT_SHIM_RST |
+ AIE_PART_INIT_OPT_ZEROIZEMEM;
+ ret = aie_part_pm_ops(apart, NULL, opts, apart->range, 0);
+ if (ret)
+ goto out;
+
+ /* Zeroizes the uc-DM and uc shared DM */
+ data = 0x6;
+ ret = aie_part_pm_ops(apart, &data, AIE_PART_INIT_OPT_UC_ZEROIZATION, apart->range, 1);
+ if (ret)
+ goto out;
+ ret = aie_part_pm_ops(apart, NULL, AIE_PART_INIT_OPT_DIS_COLCLK_BUFF, apart->range, 0);
+ if (ret)
+ goto out;
+ ret = aie_part_pm_ops_flush(apart);
+ if (ret)
+ goto out;
+
+ /* Clear resources */
+ aie_resource_clear_all(&apart->tiles_inuse);
+ aie_resource_clear_all(&apart->cores_clk_state);
+
+out:
+ mutex_unlock(&apart->mlock);
+
+ return ret;
+}
+
static const struct aie_tile_operations aiemlv2_ops = {
.get_tile_type = aiemlv2_get_tile_type,
.scan_part_clocks = aiemlv2_scan_part_clocks,
.set_part_clocks = aiemlv2_set_part_clocks,
+ .part_init = aiemlv2_part_init,
+ .part_teardown = aiemlv2_part_teardown,
};
/**
diff --git a/drivers/accel/amd-ai-engine/ai-engine-internal.h b/drivers/accel/amd-ai-engine/ai-engine-internal.h
index 572476c97aad..64691223ff9c 100644
--- a/drivers/accel/amd-ai-engine/ai-engine-internal.h
+++ b/drivers/accel/amd-ai-engine/ai-engine-internal.h
@@ -49,6 +49,8 @@ struct aie_partition;
* caller to apply partition lock before calling this
* function. The caller function will need to set the bitmap
* on which tiles are required to be clocked on.
+ * @part_init: initialize partition with user options.
+ * @part_teardown: teardown partition
* Different AI engine device version has its own device
* operation.
*/
@@ -56,6 +58,9 @@ struct aie_tile_operations {
u32 (*get_tile_type)(struct aie_device *adev, struct aie_location *loc);
int (*scan_part_clocks)(struct aie_partition *apart);
int (*set_part_clocks)(struct aie_partition *apart);
+ int (*part_init)(struct aie_partition *apart,
+ struct aie_partition_init_args *args);
+ int (*part_teardown)(struct aie_partition *apart);
};
/**
@@ -360,10 +365,13 @@ int aie_resource_get_region(struct aie_resource *res, u32 start,
void aie_resource_put_region(struct aie_resource *res, int start, u32 count);
int aie_resource_set(struct aie_resource *res, u32 start, u32 count);
int aie_resource_clear(struct aie_resource *res, u32 start, u32 count);
+int aie_resource_clear_all(struct aie_resource *res);
bool aie_resource_testbit(struct aie_resource *res, u32 bit);
int aie_part_pm_ops_create(struct aie_partition *apart);
void aie_part_pm_ops_destroy(struct aie_partition *apart);
int aie_part_pm_ops_flush(struct aie_partition *apart);
int aie_part_pm_ops(struct aie_partition *apart, void *data, u32 type,
struct aie_range range, bool flush);
+int aie_part_maskpoll_register(struct aie_partition *apart, u32 offset, u32 data,
+ u32 mask, u32 timeout);
#endif /* AIE_INTERNAL_H */
diff --git a/drivers/accel/amd-ai-engine/ai-engine-part.c b/drivers/accel/amd-ai-engine/ai-engine-part.c
index 35451d1ed88a..2cd93c02246e 100644
--- a/drivers/accel/amd-ai-engine/ai-engine-part.c
+++ b/drivers/accel/amd-ai-engine/ai-engine-part.c
@@ -6,6 +6,7 @@
*/
#include <linux/amd-ai-engine.h>
+#include <linux/delay.h>
#include <linux/device.h>
#include <linux/list.h>
#include <linux/mutex.h>
@@ -106,3 +107,34 @@ struct aie_partition *aie_part_create(struct aie_device *adev,
device_unregister(&apart->dev);
return ERR_PTR(ret);
}
+
+/**
+ * aie_part_maskpoll_register() - Mask polls an address for a data in a partition.
+ * @apart: AI engine partition.
+ * @offset: AI engine register offset.
+ * @data: data to poll.
+ * @mask: if it is non 0, it is mask read.
+ * @timeout: Timeout in microseconds.
+ *
+ * Return: zero for success, or -EBUSY for failure
+ */
+int aie_part_maskpoll_register(struct aie_partition *apart, u32 offset, u32 data,
+ u32 mask, u32 timeout)
+{
+ u32 usleep_time = 10;
+ u32 value;
+ u32 i;
+
+ for (i = 0; i < timeout; i += usleep_time) {
+ value = readl(apart->adev->base + offset);
+ if ((value & mask) == data)
+ return 0;
+ usleep_range(usleep_time, usleep_time + 10);
+ }
+
+ value = readl(apart->adev->base + offset);
+ if ((value & mask) == data)
+ return 0;
+
+ return -EBUSY;
+}
diff --git a/drivers/accel/amd-ai-engine/ai-engine-res.c b/drivers/accel/amd-ai-engine/ai-engine-res.c
index 45b9447d896f..d35c27141cdd 100644
--- a/drivers/accel/amd-ai-engine/ai-engine-res.c
+++ b/drivers/accel/amd-ai-engine/ai-engine-res.c
@@ -151,6 +151,22 @@ int aie_resource_clear(struct aie_resource *res, u32 start, u32 count)
return 0;
}
+/**
+ * aie_resource_clear_all() - clear all the AI engine resource bits
+ * @res: pointer to AI engine resource
+ * @return: 0 for success and negative value for failure
+ *
+ * This function clears all the bits in the resource.
+ */
+int aie_resource_clear_all(struct aie_resource *res)
+{
+ if (!res || !res->bitmap)
+ return -EINVAL;
+
+ bitmap_clear(res->bitmap, 0, res->total);
+ return 0;
+}
+
/**
* aie_resource_testbit() - test if a bit is set in a AI engine resource
* @res: pointer to AI engine resource
diff --git a/drivers/accel/amd-ai-engine/ai-engine-reset.c b/drivers/accel/amd-ai-engine/ai-engine-reset.c
new file mode 100644
index 000000000000..f34d8d687d0e
--- /dev/null
+++ b/drivers/accel/amd-ai-engine/ai-engine-reset.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AMD AI Engine device driver reset implementation
+ *
+ * Copyright (C) 2025 Advanced Micro Devices, Inc.
+ */
+
+#include <linux/amd-ai-engine.h>
+#include <linux/firmware/xlnx-zynqmp.h>
+#include <linux/io.h>
+#include <linux/mutex.h>
+
+#include "ai-engine-internal.h"
+
+/**
+ * aie_partition_initialize() - AI engine partition initialization
+ * @dev: AI engine partition device
+ * @args: User initialization options
+ *
+ * Return: 0 for success and negative value for failure
+ *
+ * Based on user passed options this function will:
+ * - enable column and shim reset
+ * - ungate all columns
+ * - disable column reset
+ * - zeroize memories
+ * - setup NMU traffic and hardware error reporting
+ */
+int aie_partition_initialize(struct device *dev,
+ struct aie_partition_init_args *args)
+{
+ struct aie_partition *apart;
+
+ if (!dev || !args)
+ return -EINVAL;
+
+ apart = dev_to_aiepart(dev);
+ if (apart->adev->ops->part_init)
+ return apart->adev->ops->part_init(apart, args);
+
+ return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(aie_partition_initialize);
+
+/**
+ * aie_partition_teardown() - AI engine partition teardown
+ * @dev: AI engine partition device
+ *
+ * Return: 0 for success and negative value for failure
+ *
+ * This function will:
+ * - reset columns and shim
+ * - zeroize memories
+ * - gate all columns
+ */
+int aie_partition_teardown(struct device *dev)
+{
+ struct aie_partition *apart;
+
+ if (!dev)
+ return -EINVAL;
+
+ apart = dev_to_aiepart(dev);
+ if (apart->adev->ops->part_teardown)
+ return apart->adev->ops->part_teardown(apart);
+
+ return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(aie_partition_teardown);
diff --git a/include/linux/amd-ai-engine.h b/include/linux/amd-ai-engine.h
index 229434372fc0..95884b782742 100644
--- a/include/linux/amd-ai-engine.h
+++ b/include/linux/amd-ai-engine.h
@@ -94,6 +94,22 @@ struct aie_op_handshake_data {
struct aie_location loc;
};
+/*
+ * struct aie_partition_init_args - AIE partition initialization arguments
+ * @locs: Allocated array of tile locations that will be used
+ * @num_tiles: Number of tiles to use
+ * @init_opts: Partition initialization options
+ * @ecc_scrub: ecc_scrub period.
+ */
+struct aie_partition_init_args {
+ struct aie_location *locs;
+ u32 num_tiles;
+ u32 init_opts;
+ u32 ecc_scrub;
+};
+
struct device *aie_partition_request(struct device *dev, struct aie_partition_req *req);
void aie_partition_release(struct device *dev);
+int aie_partition_initialize(struct device *dev, struct aie_partition_init_args *args);
+int aie_partition_teardown(struct device *dev);
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 15/15] accel/amd-ai-engine: Add reset operations
2026-11-18 23:32 ` [PATCH 15/15] accel/amd-ai-engine: Add reset operations Gregory Williams
@ 2026-11-18 23:51 ` sashiko-bot
0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-11-18 23:51 UTC (permalink / raw)
To: Gregory Williams; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] accel/amd-ai-engine: unflushed pm_ops on error in
aiemlv2_part_init()
- [Medium] accel/amd-ai-engine: unchecked 2-column NMU range in
aiemlv2_part_init()
- [Low] accel/amd-ai-engine: open-coded polling in
aie_part_maskpoll_register()
--
commit 7ceb805ff0b7740b5882eeff9e935665efc44bc8
Author: Gregory Williams <gregory.williams@amd.com>
accel/amd-ai-engine: Add reset operations
This commit adds partition initialization and teardown callbacks for AI
Engine partitions, configuring resets, memory zeroization, NMU routing,
ECC scrubbing, error reporting, and tile clocks.
> diff --git a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
> index 26dd1d726bfad..910a9bda23055 100644
> --- a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
> +++ b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
[ ... ]
> @@ -173,10 +177,250 @@ static int aiemlv2_set_part_clocks(struct aie_partition *apart)
[ ... ]
> +static int aiemlv2_part_init(struct aie_partition *apart,
> + struct aie_partition_init_args *args)
> +{
> + u32 opts;
> + int ret;
[ ... ]
> + if (args->init_opts & AIE_PART_INIT_OPT_NMU_CONFIG) {
> + struct aie_range range = {0};
> +
> + opts |= AIE_PART_INIT_OPT_NMU_CONFIG;
> + if (apart->range.start.col == 0) {
> + range.size.col = 2;
> + ret = aie_part_pm_ops(apart, NULL, AIE_PART_INIT_OPT_NMU_CONFIG,
> + range, 0);
> + if (ret)
> + goto out;
> + }
> + }
[Severity: Medium]
Can this configure column 1 outside the partition's allocated columns?
If a 1-column partition is requested at column 0 (apart->range.start.col
== 0, apart->range.size.col == 1), setting range.size.col = 2 without
checking apart->range.size.col >= 2 programs NMU routing on column 1 as
well, which may belong to another partition.
> +
> + if (args->init_opts & AIE_PART_INIT_OPT_HW_ERR_INT) {
> + u16 data = 0;
> +
> + opts |= AIE_PART_INIT_OPT_HW_ERR_INT;
> + ret = aie_part_pm_ops(apart, &data, AIE_PART_INIT_OPT_HW_ERR_INT,
> + apart->range, 0);
> + if (ret)
> + goto out;
> + }
> +
> + if (args->init_opts & AIE_PART_INIT_OPT_HW_ERR_MASK) {
> + u16 data = 0x2;
> +
> + opts |= AIE_PART_INIT_OPT_HW_ERR_MASK;
> + ret = aie_part_pm_ops(apart, &data, AIE_PART_INIT_OPT_HW_ERR_MASK,
> + apart->range, 0);
> + if (ret)
> + goto out;
> + }
> +
> + if (args->init_opts & AIE_PART_INIT_OPT_SET_ECC_SCRUB_PERIOD) {
> + u16 data;
> +
> + if (args->ecc_scrub > U16_MAX) {
> + ret = -EINVAL;
> + goto out;
> + }
> +
> + data = args->ecc_scrub;
> + opts |= AIE_PART_INIT_OPT_SET_ECC_SCRUB_PERIOD;
> + ret = aie_part_pm_ops(apart, &data,
> + AIE_PART_INIT_OPT_SET_ECC_SCRUB_PERIOD,
> + apart->range, 0);
> + if (ret)
> + goto out;
> + }
> +
> + if (args->init_opts & AIE_PART_INIT_OPT_UC_ENB_MEM_PRIV) {
> + opts |= AIE_PART_INIT_OPT_UC_ENB_MEM_PRIV;
> +
> + ret = aie_part_pm_ops(apart, NULL, AIE_PART_INIT_OPT_UC_ENB_MEM_PRIV,
> + apart->range, 0);
> + if (ret)
> + goto out;
> + }
> +
> + /* Request tile locations */
> + ret = aie_part_request_tiles(apart, args->num_tiles, args->locs);
> + if (ret)
> + goto out;
> +
> + if (args->init_opts & AIE_PART_INIT_OPT_DIS_TLAST_ERROR) {
> + u16 data = 0;
> +
> + opts |= AIE_PART_INIT_OPT_DIS_TLAST_ERROR;
> + ret = aie_part_pm_ops(apart, &data,
> + AIE_PART_INIT_OPT_DIS_TLAST_ERROR,
> + apart->range, 1);
> + if (ret)
> + goto out;
> + }
> +
> + if (opts != args->init_opts)
> + dev_warn(&apart->dev, "Invalid init_opts: 0x%x\n", opts ^ args->init_opts);
> +
> +out:
> + mutex_unlock(&apart->mlock);
> + return ret;
> +}
[Severity: Medium]
Does the error path leave unflushed commands queued in apart->pm_ops?
The operations from AIE_PART_INIT_OPT_NMU_CONFIG through
AIE_PART_INIT_OPT_UC_ENB_MEM_PRIV are queued with flush = 0 and rely on
aie_part_request_tiles() -> aiemlv2_set_part_clocks() ->
aie_part_pm_ops_flush() to flush and reset the buffer. If args->ecc_scrub
> U16_MAX or aie_part_request_tiles() fails (for example, when
args->num_tiles > 0 and args->locs is NULL), jumping to out leaves those
descriptors in apart->pm_ops.pkt_va, so they will be sent to firmware
ahead of the DMA pause operations on the next initialize or teardown call.
Validating args before modifying hardware state and resetting
apart->pm_ops on failure would avoid both the stale command buffer and
leaving the partition partially reset on -EINVAL.
> diff --git a/drivers/accel/amd-ai-engine/ai-engine-part.c b/drivers/accel/amd-ai-engine/ai-engine-part.c
> index 35451d1ed88a4..2cd93c02246e5 100644
> --- a/drivers/accel/amd-ai-engine/ai-engine-part.c
> +++ b/drivers/accel/amd-ai-engine/ai-engine-part.c
[ ... ]
> @@ -106,3 +107,34 @@ struct aie_partition *aie_part_create(struct aie_device *adev,
> device_unregister(&apart->dev);
> return ERR_PTR(ret);
> }
> +
> +/**
> + * aie_part_maskpoll_register() - Mask polls an address for a data in a partition.
> + * @apart: AI engine partition.
> + * @offset: AI engine register offset.
> + * @data: data to poll.
> + * @mask: if it is non 0, it is mask read.
> + * @timeout: Timeout in microseconds.
> + *
> + * Return: zero for success, or -EBUSY for failure
> + */
> +int aie_part_maskpoll_register(struct aie_partition *apart, u32 offset, u32 data,
> + u32 mask, u32 timeout)
> +{
> + u32 usleep_time = 10;
> + u32 value;
> + u32 i;
> +
> + for (i = 0; i < timeout; i += usleep_time) {
> + value = readl(apart->adev->base + offset);
> + if ((value & mask) == data)
> + return 0;
> + usleep_range(usleep_time, usleep_time + 10);
> + }
> +
> + value = readl(apart->adev->base + offset);
> + if ((value & mask) == data)
> + return 0;
> +
> + return -EBUSY;
> +}
[Severity: Low]
Can this use readl_poll_timeout() from linux/iopoll.h instead of an
open-coded loop? Advancing i by 10 us per iteration while calling
usleep_range(10, 20) does not account for sleeps up to 20 us or scheduler
wakeup overhead, so a 2000000 us timeout can block for much longer than 2
seconds per column while holding apart->mlock.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118233211.4121361-1-gregory.williams@amd.com?part=15
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 00/15] accel: Add AMD Versal AI Engine driver (with Versal Gen 2 firmware support)
2026-11-18 23:31 [PATCH 00/15] accel: Add AMD Versal AI Engine driver (with Versal Gen 2 firmware support) Gregory Williams
` (4 preceding siblings ...)
2026-11-18 23:32 ` [PATCH 15/15] accel/amd-ai-engine: Add reset operations Gregory Williams
@ 2026-11-19 8:19 ` Jerome Brunet
5 siblings, 0 replies; 13+ messages in thread
From: Jerome Brunet @ 2026-11-19 8:19 UTC (permalink / raw)
To: Gregory Williams
Cc: Stephen Boyd, Brian Masney, Jerome Brunet, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Michal Simek, Oded Gabbay,
kishore Manne, Izhar Ameer Shaikh, Greg Kroah-Hartman,
Jay Buddhabhatti, Ronak Jain, linux-clk, devicetree, linux-kernel,
linux-arm-kernel, dri-devel
On mer. 18 nov. 2026 at 15:31, Gregory Williams <gregory.williams@amd.com> wrote:
> This series adds a driver for the AMD AI Engine (AIE) found on Versal
> devices, together with the firmware changes the driver depends on. AI Engine
> is a tile array based accelerator used for applications such as beamforming and
> machine learning inference. Tiles are organised in columns, and groups of
> columns form partitions that an application requests, initialises and releases.
>
> Several registers in the AI Engine array (column and shim resets, memory
> zeroisation, tile clock gating, NoC and interrupt routing) are privileged
> and can only be written by the trusted firmware. The driver therefore
> packs operations into a DMA buffer and hands it to the platform firmware,
> which executes them in order.
>
> Firmware patches included
> -------------------------
> Patches 1-10 are not part of the AI Engine driver itself, but the driver
> cannot work without them, so they are included here to keep the series
> self-contained and reviewable in one place:
>
> - 1-5: zynqmp firmware driver refactoring and a va_start()/va_end()
> fix (patch 2 carries Fixes: tags), preparing for the extended
> SMCCC call format.
> - 6-7: Versal Gen 2 compatible string and firmware support, where all
> EEMI APIs use the extended SMCCC payload.
> - 8-9: Versal Gen 2 clock binding and clk driver match entry.
> - 10: firmware IOCTL support for the Versal Gen 2 AIE run time
> operations, used by the driver.
>
> I am happy to split out or reorder the firmware and clock patches if the
> maintainers prefer to take them through their own trees, and would
> appreciate guidance on how the series should be merged.
For the clock, it would defenitely be prefered if you could split out
clock part, especially if you later need an immutable branch.
`b4` makes it very easy to handle series deps, please consider using the
related tags
https://b4.docs.kernel.org/en/latest/contributor/prep.html#working-with-series-dependencies
>
> AI Engine driver
> ----------------
> - 11: devicetree binding for the AI Engine.
> - 12: driver core: device probe, partition request and release.
> - 13: pm ops: building and sending firmware operation packets.
> - 14: enabling and disabling tile clocks.
> - 15: partition initialize and teardown (reset operations).
>
> Previous submission
> -------------------
> This driver was posted for review a little over a year ago:
>
> https://lore.kernel.org/dri-devel/20250702155630.1737227-1-gregory.williams@amd.com/
>
> Since then the scope of what is proposed for upstream has changed, this series
> is considerably different from that posting, in particular targeting only Versal
> Gen 2 support. All comments received on the earlier posting have been addressed
> or in this version.
>
> Abhyuday Godhasara (1):
> drivers: firmware: xilinx: Add IOCTL support for the AIE run time
> operations
>
> Gregory Williams (5):
> dt-bindings: soc: xilinx: Add Versal AI Engine DT binding
> accel/amd-ai-engine: Add AMD AI Engine device driver
> accel/amd-ai-engine: Add pm ops for firmware calls
> accel/amd-ai-engine: Add support to enable/disable tile clocks
> accel/amd-ai-engine: Add reset operations
>
> Naman Trivedi (1):
> dt-bindings: clock: versal: add Versal Gen 2 compatible string
>
> Senthil Nathan Thangaraj (8):
> firmware: xilinx: Separate TF-A checking
> firmware: xilinx: Call va_start after pm feature check
> firmware: xilinx: Add comments about number of arguments
> firmware: xilinx: Use match data for ZynqMP/Versal
> firmware: xilinx: Rename zynqmp_pm_invoke_fw_fn()
> dt-bindings: firmware: xilinx: Add Versal Gen 2 compatible string
> firmware: xilinx: Add support for Versal Gen 2
> clk: zynqmp: Add Versal Gen 2 compatible string
>
> .../bindings/clock/xlnx,versal-clk.yaml | 5 +-
> .../firmware/xilinx/xlnx,zynqmp-firmware.yaml | 3 +
> .../bindings/soc/xilinx/xlnx,ai-engine.yaml | 61 +++
> MAINTAINERS | 9 +
> drivers/accel/Kconfig | 1 +
> drivers/accel/Makefile | 3 +-
> drivers/accel/amd-ai-engine/Kconfig | 15 +
> drivers/accel/amd-ai-engine/Makefile | 14 +
> .../accel/amd-ai-engine/ai-engine-aiemlv2.c | 441 ++++++++++++++++
> drivers/accel/amd-ai-engine/ai-engine-clock.c | 154 ++++++
> drivers/accel/amd-ai-engine/ai-engine-dev.c | 255 ++++++++++
> .../accel/amd-ai-engine/ai-engine-internal.h | 377 ++++++++++++++
> drivers/accel/amd-ai-engine/ai-engine-part.c | 140 ++++++
> drivers/accel/amd-ai-engine/ai-engine-pm.c | 472 ++++++++++++++++++
> drivers/accel/amd-ai-engine/ai-engine-res.c | 184 +++++++
> drivers/accel/amd-ai-engine/ai-engine-reset.c | 69 +++
> drivers/clk/zynqmp/clkc.c | 1 +
> drivers/firmware/xilinx/zynqmp.c | 340 +++++++++++--
> include/linux/amd-ai-engine.h | 115 +++++
> include/linux/firmware/xlnx-zynqmp.h | 65 ++-
> 20 files changed, 2679 insertions(+), 45 deletions(-)
> create mode 100644 Documentation/devicetree/bindings/soc/xilinx/xlnx,ai-engine.yaml
> create mode 100644 drivers/accel/amd-ai-engine/Kconfig
> create mode 100644 drivers/accel/amd-ai-engine/Makefile
> create mode 100644 drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
> create mode 100644 drivers/accel/amd-ai-engine/ai-engine-clock.c
> create mode 100644 drivers/accel/amd-ai-engine/ai-engine-dev.c
> create mode 100644 drivers/accel/amd-ai-engine/ai-engine-internal.h
> create mode 100644 drivers/accel/amd-ai-engine/ai-engine-part.c
> create mode 100644 drivers/accel/amd-ai-engine/ai-engine-pm.c
> create mode 100644 drivers/accel/amd-ai-engine/ai-engine-res.c
> create mode 100644 drivers/accel/amd-ai-engine/ai-engine-reset.c
> create mode 100644 include/linux/amd-ai-engine.h
>
> --
> 2.34.1
>
--
Jerome
^ permalink raw reply [flat|nested] 13+ messages in thread