Skip to content

accel/amdxdna: DMA buffer helpers and AIE4 work buffer support#1229

Open
NishadSaraf wants to merge 4 commits intoamd:mainfrom
NishadSaraf:work
Open

accel/amdxdna: DMA buffer helpers and AIE4 work buffer support#1229
NishadSaraf wants to merge 4 commits intoamd:mainfrom
NishadSaraf:work

Conversation

@NishadSaraf
Copy link
Copy Markdown
Member

This series introduces a common DMA buffer abstraction for the amdxdna
driver and uses it to add DRAM work buffer support for AIE4 devices.
The NPU firmware has strict constraints on host-allocated DMA buffers:
sizes must be power-of-2, addresses must be naturally aligned, and
buffers must not cross a 64 MB boundary. Currently, the AIE2 code
opens its own alloc/free helpers without enforcing these rules.

Patches 1-2 introduce struct aie_dma_hdl with alloc/free/clflush
helpers that enforce the firmware constraints, then migrate the
existing AIE2 call sites.

Patch 3 builds on this to allocate and attach a DRAM work buffer
required by AIE4 firmware for runtime operation. Only the PF driver
performs the allocation; VF devices skip it.

Patch 4 fixes a minor SR-IOV teardown issue where the driver
unconditionally sent a destroy-VFs command even when no VFs existed.

@NishadSaraf NishadSaraf self-assigned this Apr 1, 2026
Add struct aie_dma_hdl and the aie_dma_buf_alloc/free helpers to
manage DMA buffers used for firmware communication. The allocator
rounds up to the nearest page-order power-of-2 (with an 8 KB floor)
and selects between IOMMU and non-coherent allocation paths.

Provide to_dma_addr(), to_cpu_addr(), and to_buf_size() macros for
accessing the underlying DMA address, CPU address, and buffer size.
Add aie_dma_buf_clflush() to flush the CPU cache for a DMA buffer
before handing it to the device.

This replaces the ad-hoc alloc/free pattern used by AIE2 and provides
a foundation for AIE4 DRAM work buffer support.

Signed-off-by: Nishad Saraf <[email protected]>
Migrate all aie2_alloc_msg_buffer/aie2_free_msg_buffer call sites in
aie2_message.c and aie2_error.c to use the new struct aie_dma_hdl and
aie_dma_buf_alloc/free helpers, then remove the now-unused legacy
functions and their declarations from aie2_pci.h.

Signed-off-by: Nishad Saraf <[email protected]>
The NPU firmware requires a host-allocated DRAM work buffer for
runtime operation. The buffer must be attached before any hardware
contexts can be created, and all contexts must be destroyed before
it can be released.

Allocate the work buffer (4 MB minimum, power-of-2 aligned) at device
init and attach it to firmware after mailbox init. The firmware
releases the work buffer internally as part of its suspend sequence,
so no explicit detach is needed from the driver. Only the PF driver
sends the attach command; VF devices skip work buffer allocation.

Signed-off-by: Nishad Saraf <[email protected]>
When unloading the driver, aie4_sriov_stop() unconditionally sends a
destroy VFs firmware command even when no VFs were ever created. This
causes the firmware to return an error:

  amdxdna: [drm] *ERROR* aie_send_mgmt_msg_wait: command opcode
  0x20002 failed, status 0x1
  amdxdna: [drm] *ERROR* aie4_destroy_vfs: destroy vfs op failed: -22

Fix this by checking pci_num_vf() at the top of aie4_sriov_stop() and
returning early if no VFs exist.

Signed-off-by: Nishad Saraf <[email protected]>
@xdavidz xdavidz requested a review from hlaccabu April 3, 2026 17:04
@xdavidz
Copy link
Copy Markdown
Contributor

xdavidz commented Apr 3, 2026

@NishadSaraf I thought that we could make the mgmt buffer common. Thus all buffers including work buffer should be allocated by the amdxdna APIs, maybe move code in aie.c but API name as amdxdna_xxx for buffer alloc and free.

The workbuffer alloc/free might be no-op for aie2. I discussed this with Max, we even bringstrom to have the workbuffer for aie2 even we don't use it today. Thus, we can make the code look simpler for the linux maintainer to review.
But for VE2 or embedded, this is really not needed, therefore this is questionable. I don't have a deeper thought further. Lizhi may have suggestions to make this area look nicer.

After that the extra ops is the attach or register (I think those different naming APIs are doing the same thing, just using different mailbox messages across aie2, aie4)

Given the current situation, I am not sure you plan. Are you going to make it done in next week? If yes, please arrange a meeting instead of chatting here for better communication.

Please also include @hlaccabu, I asked him to get familiar with this area too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants