dmaengine: dw-edma: Enable HDMA 64R/W Channels
Subsystems (2)
PATCH 1/1 dmaengine: dw-edma: Enable HDMA 64R/W Channels
As per 'Designware Cores PCI Express Controller Databook', Section 7.1 - Overview, HDMA supports 64 Read and 64 Write channels. Current controller driver supports up to 8 read and write channels only. In order to utilize all the channels the controller driver need to have the channel related structs and variables as per the number of channels supported by IP. Following changes are made to enable 64 Read / 64 Write channel support:
o Defined HDMA specific macros to reflect the channel count.
o The count of ll_regions and dt_regions in dw_edma_chip and dw_edma_pcie_data shall be in accordance to number of read and write channels.
o In dw_edma_probe() configure the channels as per the channels of the IP used.
--- drivers/dma/dw-edma/dw-edma-core.c | 15 +++++++++++---- drivers/dma/dw-edma/dw-edma-pcie.c | 8 ++++---- drivers/dma/dw-edma/dw-hdma-v0-regs.h | 2 +- include/linux/dma/edma.h | 10 ++++++---- 4 files changed, 22 insertions(+), 13 deletions(-)
drivers/dma/dw-edma/dw-edma-core.c +11 -4
@@ -1079,6 +1079,8 @@ int dw_edma_probe(struct dw_edma_chip *chip)struct dw_edma *dw;u32 wr_alloc =0 ;u32 rd_alloc =0 ; +u16 max_wr_cnt; +u16 max_rd_cnt;int i, err;if (!chip)
@@ -1094,20 +1096,25 @@ int dw_edma_probe(struct dw_edma_chip *chip) dw->chip = chip; -if (dw->chip->mf ==EDMA_MF_HDMA_NATIVE ) +if (dw->chip->mf ==EDMA_MF_HDMA_NATIVE ) {dw_hdma_v0_core_register (dw); -else + max_wr_cnt =HDMA_MAX_WR_CH ; + max_rd_cnt =HDMA_MAX_RD_CH ; + }else {dw_edma_v0_core_register (dw); + max_wr_cnt =EDMA_MAX_WR_CH ; + max_rd_cnt =EDMA_MAX_RD_CH ; + }raw_spin_lock_init (&dw->lock); dw->wr_ch_cnt =min_t (u16, chip->ll_wr_cnt,dw_edma_core_ch_count (dw,EDMA_DIR_WRITE )); - dw->wr_ch_cnt =min_t (u16, dw->wr_ch_cnt,EDMA_MAX_WR_CH ); + dw->wr_ch_cnt =min_t (u16, dw->wr_ch_cnt, max_wr_cnt); dw->rd_ch_cnt =min_t (u16, chip->ll_rd_cnt,dw_edma_core_ch_count (dw,EDMA_DIR_READ )); - dw->rd_ch_cnt =min_t (u16, dw->rd_ch_cnt,EDMA_MAX_RD_CH ); + dw->rd_ch_cnt =min_t (u16, dw->rd_ch_cnt, max_rd_cnt);if (!dw->wr_ch_cnt && !dw->rd_ch_cnt)return -EINVAL ;
drivers/dma/dw-edma/dw-edma-pcie.c +4 -4
@@ -61,11 +61,11 @@ struct dw_edma_pcie_data {/* eDMA registers location */ struct dw_edma_block rg;/* eDMA memory linked list location */ -struct dw_edma_block ll_wr[EDMA_MAX_WR_CH ]; -struct dw_edma_block ll_rd[EDMA_MAX_RD_CH ]; +struct dw_edma_block ll_wr[HDMA_MAX_WR_CH ]; +struct dw_edma_block ll_rd[HDMA_MAX_RD_CH ];/* eDMA memory data location */ -struct dw_edma_block dt_wr[EDMA_MAX_WR_CH ]; -struct dw_edma_block dt_rd[EDMA_MAX_RD_CH ]; +struct dw_edma_block dt_wr[HDMA_MAX_WR_CH ]; +struct dw_edma_block dt_rd[HDMA_MAX_RD_CH ];/* Other */ enum dw_edma_map_format mf;u8 irqs;
drivers/dma/dw-edma/dw-hdma-v0-regs.h +1 -1
@@ -11,7 +11,7 @@#include <linux/dmaengine.h> -#define HDMA_V0_MAX_NR_CH 8 +#define HDMA_V0_MAX_NR_CH 64#define HDMA_V0_CH_EN BIT(0)#define HDMA_V0_LOCAL_ABORT_INT_EN BIT(6)#define HDMA_V0_REMOTE_ABORT_INT_EN BIT(5)
include/linux/dma/edma.h +6 -4
@@ -14,6 +14,8 @@#define EDMA_MAX_WR_CH 8#define EDMA_MAX_RD_CH 8 +#define HDMA_MAX_WR_CH 64 +#define HDMA_MAX_RD_CH 64struct dw_edma ;
@@ -89,12 +91,12 @@ struct dw_edma_chip {u16 ll_wr_cnt;u16 ll_rd_cnt;/* link list address */ -struct dw_edma_region ll_region_wr[EDMA_MAX_WR_CH ]; -struct dw_edma_region ll_region_rd[EDMA_MAX_RD_CH ]; +struct dw_edma_region ll_region_wr[HDMA_MAX_WR_CH ]; +struct dw_edma_region ll_region_rd[HDMA_MAX_RD_CH ];/* data region */ -struct dw_edma_region dt_region_wr[EDMA_MAX_WR_CH ]; -struct dw_edma_region dt_region_rd[EDMA_MAX_RD_CH ]; +struct dw_edma_region dt_region_wr[HDMA_MAX_WR_CH ]; +struct dw_edma_region dt_region_rd[HDMA_MAX_RD_CH ];/* interrupt emulation */ int db_irq;
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Critical] Unbounded iteration in `dw_hdma_v0_core_off()` causes out-of-bounds MMIO writes to unmapped…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] Unbounded iteration in dw_hdma_v0_core_off() causes out-of-bounds MMIO writes to unmapped register space.
- [High] DesignWare PCIe controller glue driver bounds checks were not updated to support the new 64-channel limits.
- [Medium] Hardcoded channel limits in the PCIe endpoint driver prevent utilizing more than 8 channels. --
commit 5d2bdaca2c92c95288275a3210f192b8e7094b9e
Author: Devendra K Verma <[email protected]>
dmaengine: dw-edma: Enable HDMA 64R/W Channels
This commit adds support for up to 64 read and write channels in the Designware HDMA controller driver, as per the hardware specification. It introduces HDMA-specific macros and updates the initialization flow to use the appropriate channel limits based on the IP version.
Quoted 4 lines
drivers/dma/dw-edma/dw-edma-pcie.c +0
-0
[ ... ]
drivers/dma/dw-edma/dw-edma-pcie.c struct dw_edma_pcie_data { · line 68
Quoted 13 lines
drivers/dma/dw-edma/dw-edma-pcie.c +4
-4@@ -61,11 +61,11 @@ struct dw_edma_pcie_data {/* eDMA registers location */ struct dw_edma_block rg;/* eDMA memory linked list location */ -struct dw_edma_block ll_wr[EDMA_MAX_WR_CH ]; -struct dw_edma_block ll_rd[EDMA_MAX_RD_CH ]; +struct dw_edma_block ll_wr[HDMA_MAX_WR_CH ]; +struct dw_edma_block ll_rd[HDMA_MAX_RD_CH ];/* eDMA memory data location */ -struct dw_edma_block dt_wr[EDMA_MAX_WR_CH ]; -struct dw_edma_block dt_rd[EDMA_MAX_RD_CH ]; +struct dw_edma_block dt_wr[HDMA_MAX_WR_CH ]; +struct dw_edma_block dt_rd[HDMA_MAX_RD_CH ];
[Severity: Medium]
Will this update actually allow utilizing more than 8 channels, or do the static configuration structures still restrict it?
While these data structures are updated to support 64 channels, the static configuration structures like xilinx_mdb_data and snps_edda_data are left hardcoded to 8 and 2 channels, respectively.
During probe, dw_edma_pcie_get_xilinx_dma_data() computes the channel count using min(pdata->wr_ch_cnt, FIELD_GET(...)). Since the initial pdata->wr_ch_cnt is capped at 8, the driver will silently restrict the number of channels to a maximum of 8, even if the underlying IP reports support for up to 64 channels.
drivers/dma/dw-edma/dw-hdma-v0-regs.h line 14
Quoted 10 lines
drivers/dma/dw-edma/dw-hdma-v0-regs.h +1
-1@@ -11,7 +11,7 @@#include <linux/dmaengine.h> -#define HDMA_V0_MAX_NR_CH 8 +#define HDMA_V0_MAX_NR_CH 64
[Severity: Critical]
Does increasing this constant cause out-of-bounds MMIO writes during teardown?
Looking at dw_hdma_v0_core_off(), the code unconditionally iterates up to HDMA_V0_MAX_NR_CH to disable channels, rather than using the dynamically configured dw->wr_ch_cnt and dw->rd_ch_cnt.
Since each channel occupies 512 bytes, iterating 64 times writes to 32 KB of register space. Existing endpoint devices like Xilinx MDB map only 8 KB of register space.
Writing to MMIO offsets outside the mapped region can cause a translation fault or an unhandled kernel paging request, resulting in a regression.
include/linux/dma/edma.h line 18
Quoted 10 lines
include/linux/dma/edma.h +2
-0@@ -14,6 +14,8 @@#define EDMA_MAX_WR_CH 8#define EDMA_MAX_RD_CH 8 +#define HDMA_MAX_WR_CH 64 +#define HDMA_MAX_RD_CH 64
[Severity: High]
Are there missing updates in the DesignWare PCIe controller glue driver to support these new limits?
The function dw_pcie_edma_find_channels() in pcie-designware.c enforces a hard limit of EDMA_MAX_WR_CH. If a device is configured for more than 8 channels, the check pci->edma.ll_wr_cnt > EDMA_MAX_WR_CH will trigger and return -EINVAL, causing initialization to fail.
Additionally, dw_pcie_edma_irq_vector() returns -EINVAL if the IRQ index nr is greater than or equal to EDMA_MAX_WR_CH + EDMA_MAX_RD_CH, breaking interrupts for higher channels.
This prevents the newly added feature from functioning on native host controllers.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Public
Hi
Please check my comments inline.
Regards,
Devendra
Quoted 56 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Friday, May 29, 2026 18:40
To: Verma, Devendra <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1] dmaengine: dw-edma: Enable HDMA 64R/W ChannelsThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] Unbounded iteration indw_hdma_v0_core_off()causes out-of- bounds MMIO writes to unmapped register space.
- [High] DesignWare PCIe controller glue driver bounds checks were not updated to support the new 64-channel limits.
- [Medium] Hardcoded channel limits in the PCIe endpoint driver prevent utilizing more than 8 channels.
--commit
5d2bdaca2c92c95288275a3210f192b8e7094b9e
Author: Devendra K Verma <[email protected]>dmaengine: dw-edma: Enable HDMA 64R/W Channels
This commit adds support for up to 64 read and write channels in the Designware HDMA controller driver, as per the hardware specification. It introduces HDMA-specific macros and updates the initialization flow to use the appropriate channel limits based on the IP version.
Quoted 5 lines
drivers/dma/dw-edma/dw-edma-pcie.c +0
-0[ ... ]
drivers/dma/dw-edma/dw-edma-pcie.c struct dw_edma_pcie_data { · line 68
Quoted 13 lines
drivers/dma/dw-edma/dw-edma-pcie.c +4
-4@@ -61,11 +61,11 @@ struct dw_edma_pcie_data {/* eDMA registers location */ struct dw_edma_block rg;/* eDMA memory linked list location */ -struct dw_edma_block ll_wr[EDMA_MAX_WR_CH ]; -struct dw_edma_block ll_rd[EDMA_MAX_RD_CH ]; +struct dw_edma_block ll_wr[HDMA_MAX_WR_CH ]; +struct dw_edma_block ll_rd[HDMA_MAX_RD_CH ];/* eDMA memory data location */ -struct dw_edma_block dt_wr[EDMA_MAX_WR_CH ]; -struct dw_edma_block dt_rd[EDMA_MAX_RD_CH ]; +struct dw_edma_block dt_wr[HDMA_MAX_WR_CH ]; +struct dw_edma_block dt_rd[HDMA_MAX_RD_CH ];[Severity: Medium]
Will this update actually allow utilizing more than 8 channels, or do the static configuration structures still restrict it?While these data structures are updated to support 64 channels, the static configuration structures like
xilinx_mdb_dataandsnps_edda_dataare left hardcoded to 8 and 2 channels, respectively.
Quoted 7 lines
During probe,
dw_edma_pcie_get_xilinx_dma_data()computes the channel count usingmin(pdata->wr_ch_cnt, FIELD_GET(...)). Since the initialpdata->wr_ch_cntis capped at 8, the driver will silently restrict thepdata->number
of channels to a maximum of 8, even if the underlying IP reports support for up to 64 channels.
HDMA supports 64 Read and 64 Write channels. The code changes are required so that proportional number of structs are available for the channels. During the probe, for IPs that have fewer channels enabled can still be able to use the driver as is, without having to modify anything. This change enables the HDMA IP even when user wants to use 2 or 8 channels. So, it is OK if not all 64 channels Read/Write are enabled by the user to utilize.
Quoted 20 lines
drivers/dma/dw-edma/dw-hdma-v0-regs.h line 14
Quoted 11 lines
drivers/dma/dw-edma/dw-hdma-v0-regs.h +1
-1@@ -11,7 +11,7 @@#include <linux/dmaengine.h> -#define HDMA_V0_MAX_NR_CH 8 +#define HDMA_V0_MAX_NR_CH 64[Severity: Critical]
Does increasing this constant cause out-of-bounds MMIO writes during teardown?Looking at
dw_hdma_v0_core_off(), the code unconditionally iterates up toHDMA_V0_MAX_NR_CHto disable channels, rather than using the dynamically configureddw->wr_ch_cntanddw->rd_ch_cnt.
Quoted 7 lines
Since each channel occupies 512 bytes, iterating 64 times writes to 32 KB of register space. Existing endpoint devices like Xilinx MDB map only 8 KB of register space.
Writing to MMIO offsets outside the mapped region can cause a translation fault or an unhandled kernel paging request, resulting in a regression.
Yes, this is a valid issue. This will be fixed in the next version of the same patch series.
Quoted 15 lines
include/linux/dma/edma.h line 18
Quoted 10 lines
include/linux/dma/edma.h index renamed from include/linux/dma/edma.h +0
-0
1fafd5b0e3153..da7a5cc93ad43100644include/linux/dma/edma.h +2
-0@@ -14,6 +14,8 @@#define EDMA_MAX_WR_CH 8#define EDMA_MAX_RD_CH 8 +#define HDMA_MAX_WR_CH 64 +#define HDMA_MAX_RD_CH 64[Severity: High]
Are there missing updates in the DesignWare PCIe controller glue driver to support these new limits?
Quoted 5 lines
The function
dw_pcie_edma_find_channels()inpcie-designware.cenforces a hard limit ofEDMA_MAX_WR_CH. If a device is configured for more than 8 channels, the checkpci->edma.ll_wr_cnt>EDMA_MAX_WR_CHwill trigger and return-EINVAL, causing initialization to fail.
This limit is for the non-HDMA devices. Even though the number of channels increased for HDMA it would not affect the functionality of other IPs.
Quoted 7 lines
Additionally,
dw_pcie_edma_irq_vector()returns-EINVALif the IRQ index nr is greater than or equal toEDMA_MAX_WR_CH+EDMA_MAX_RD_CH, breaking interrupts for higher channels.This prevents the newly added feature from functioning on native host controllers.
A glue driver is required is needed to enable 64 Read & Write channels. This limit will not affect the functionality of the IPs for which this function is implemented. Moreover, this issue can be taken up in a separate patch series if channels number need to be enhanced.
Quoted 3 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260529122104.2533048-
[email protected]?part=1