* [PATCH v5 1/9] dmaengine: Support bus widths of 32 bytes and above
2026-10-09 15:52 [PATCH v5 0/9] dmaengine: Support bus widths of 32 bytes and above Nuno Sá
@ 2026-10-09 15:52 ` Nuno Sá
2026-10-09 19:33 ` Frank Li
2026-10-10 2:45 ` Frank Li
2026-10-09 15:52 ` [PATCH v5 2/9] dmaengine: dma-axi-dmac: Use bus width capability helpers Nuno Sá
` (7 subsequent siblings)
8 siblings, 2 replies; 12+ messages in thread
From: Nuno Sá @ 2026-10-09 15:52 UTC (permalink / raw)
To: linux-kernel, dmaengine, linux-arm-msm, linux-stm32,
linux-arm-kernel, linux-iio, linux-sound, linux-spi
Cc: Vinod Koul, Frank Li, Lars-Peter Clausen, Eugeniy Paltsev,
Amélie Delaunay, Maxime Coquelin, Alexandre Torgue,
Jonathan Cameron, David Lechner, Andy Shevchenko,
Jaroslav Kysela, Takashi Iwai, Mark Brown
The src_addr_widths and dst_addr_widths capability masks encode each
supported width as a bit whose position equals the corresponding
enum dma_slave_buswidth value (e.g. DMA_SLAVE_BUSWIDTH_4_BYTES sets bit
4). As these masks are plain u32, widths of 32 bytes and above
(DMA_SLAVE_BUSWIDTH_32/64/128_BYTES map to bits 32, 64 and 128) cannot
be represented at all.
Introduce bitmap-based bus width capabilities that span the full enum
range, through a new dma_buswidth_mask_t type modeled after
dma_cap_mask_t. To allow DMA controller drivers to be converted
incrementally, the legacy dma_device u32 fields are kept alongside the
new masks and the core folds a legacy-only driver's u32 into the mask
when the device is registered, so consumers only ever have to look at
the mask.
The fold is bidirectional while both representations coexist. A driver
that only fills in the legacy u32 gets its mask derived from it, so the
consumers already converted see it. A driver that only fills in the mask
gets its legacy u32 derived from the mask, so the consumers not
converted yet, which read the legacy dma_slave_caps fields, keep working.
On top of that, dma_get_slave_caps() derives the legacy dma_slave_caps
masks from the new ones when a device_caps() callback adjusted them, so
that a converted controller narrowing its per-channel capabilities is
still seen by the consumers not converted yet, while a driver adjusting
the legacy masks directly keeps working.
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
Andy, did not take your tag given that you're the one asking for the
split and since we ended up not doing it, not sure if the tag is
to be kept :)
---
drivers/dma/dmaengine.c | 51 +++++++++++-
include/linux/dmaengine.h | 208 +++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 246 insertions(+), 13 deletions(-)
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index c5fef57b5adf..4ba9d6c7448a 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -33,6 +33,7 @@
#include <linux/acpi.h>
#include <linux/acpi_dma.h>
+#include <linux/bitmap.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/dmaengine.h>
@@ -592,8 +593,11 @@ int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps)
if (!device->directions)
return -ENXIO;
+ dma_bus_width_copy(caps->src_bus_widths, device->src_bus_widths);
+ dma_bus_width_copy(caps->dst_bus_widths, device->dst_bus_widths);
caps->src_addr_widths = device->src_addr_widths;
caps->dst_addr_widths = device->dst_addr_widths;
+
caps->directions = device->directions;
caps->min_burst = device->min_burst;
caps->max_burst = device->max_burst;
@@ -611,9 +615,31 @@ int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps)
* callback to override the generic capabilities with
* channel-specific ones.
*/
- if (device->device_caps)
+ if (device->device_caps) {
device->device_caps(chan, caps);
+ /*
+ * A driver already converted to the bus width interface
+ * adjusts the masks, so derive the legacy capabilities from
+ * them for the consumers not converted yet. Drivers not
+ * converted adjust the legacy capabilities directly, in which
+ * case there is nothing to do.
+ *
+ * Goes away with the legacy dma_slave_caps fields.
+ */
+ if (!bitmap_equal(caps->src_bus_widths.bits,
+ device->src_bus_widths.bits,
+ DMA_SLAVE_BUSWIDTH_MAX))
+ caps->src_addr_widths = bitmap_read(caps->src_bus_widths.bits,
+ 0, 32);
+
+ if (!bitmap_equal(caps->dst_bus_widths.bits,
+ device->dst_bus_widths.bits,
+ DMA_SLAVE_BUSWIDTH_MAX))
+ caps->dst_addr_widths = bitmap_read(caps->dst_bus_widths.bits,
+ 0, 32);
+ }
+
return 0;
}
EXPORT_SYMBOL_GPL(dma_get_slave_caps);
@@ -1173,6 +1199,27 @@ void dma_async_device_channel_unregister(struct dma_device *device,
}
EXPORT_SYMBOL_GPL(dma_async_device_channel_unregister);
+/*
+ * DMA controller drivers not converted to the bus width helpers only fill in
+ * the legacy u32 masks, which cannot hold widths of 32 bytes and above. Fold
+ * them into the mask so that consumers only ever have to look at the mask.
+ *
+ * Goes away with the legacy dma_device fields.
+ */
+static void dma_device_fold_legacy_bus_widths(struct dma_device *device)
+{
+ if (bitmap_empty(device->src_bus_widths.bits, DMA_SLAVE_BUSWIDTH_MAX))
+ bitmap_from_arr32(device->src_bus_widths.bits, &device->src_addr_widths, 32);
+ /* consumers not converted yet still read the legacy caps */
+ else if (!device->src_addr_widths)
+ device->src_addr_widths = bitmap_read(device->src_bus_widths.bits, 0, 32);
+
+ if (bitmap_empty(device->dst_bus_widths.bits, DMA_SLAVE_BUSWIDTH_MAX))
+ bitmap_from_arr32(device->dst_bus_widths.bits, &device->dst_addr_widths, 32);
+ else if (!device->dst_addr_widths)
+ device->dst_addr_widths = bitmap_read(device->dst_bus_widths.bits, 0, 32);
+}
+
/**
* dma_async_device_register - registers DMA devices found
* @device: pointer to &struct dma_device
@@ -1234,6 +1281,8 @@ int dma_async_device_register(struct dma_device *device)
dev_dbg(device->dev,
"WARN: Device release is not defined so it is not safe to unbind this driver while in use\n");
+ dma_device_fold_legacy_bus_widths(device);
+
kref_init(&device->ref);
/* note: this only matters in the
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index 71cde09ff240..eb68eea840b5 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -427,8 +427,179 @@ enum dma_slave_buswidth {
DMA_SLAVE_BUSWIDTH_32_BYTES = 32,
DMA_SLAVE_BUSWIDTH_64_BYTES = 64,
DMA_SLAVE_BUSWIDTH_128_BYTES = 128,
+ DMA_SLAVE_BUSWIDTH_MAX
};
+/**
+ * typedef dma_buswidth_mask_t - bus width capabilities bitmap modeled after
+ * dma_cap_mask_t.
+ *
+ * Each supported bus width is represented by the bit whose position equals the
+ * corresponding enum dma_slave_buswidth value, e.g. a device supporting a bus
+ * width of 4 bytes has bit 4 set.
+ */
+typedef struct {
+ DECLARE_BITMAP(bits, DMA_SLAVE_BUSWIDTH_MAX);
+} dma_buswidth_mask_t;
+
+/**
+ * dma_bus_width_valid - test if a bus width is a valid one
+ * @width: bus width to validate
+ *
+ * Return: true if @width is a valid &enum dma_slave_buswidth, false otherwise.
+ */
+static inline bool dma_bus_width_valid(enum dma_slave_buswidth width)
+{
+ switch (width) {
+ case DMA_SLAVE_BUSWIDTH_UNDEFINED:
+ case DMA_SLAVE_BUSWIDTH_1_BYTE:
+ case DMA_SLAVE_BUSWIDTH_2_BYTES:
+ case DMA_SLAVE_BUSWIDTH_3_BYTES:
+ case DMA_SLAVE_BUSWIDTH_4_BYTES:
+ case DMA_SLAVE_BUSWIDTH_8_BYTES:
+ case DMA_SLAVE_BUSWIDTH_16_BYTES:
+ case DMA_SLAVE_BUSWIDTH_32_BYTES:
+ case DMA_SLAVE_BUSWIDTH_64_BYTES:
+ case DMA_SLAVE_BUSWIDTH_128_BYTES:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static inline int __dma_bus_width_set_many(dma_buswidth_mask_t *mask,
+ const enum dma_slave_buswidth *widths,
+ unsigned int n_widths)
+{
+ for (unsigned int i = 0; i < n_widths; i++) {
+ if (!dma_bus_width_valid(widths[i]))
+ return -EINVAL;
+
+ __set_bit(widths[i], mask->bits);
+ }
+
+ return 0;
+}
+
+/**
+ * dma_bus_width_set_many - set the supported bus widths
+ * @mask: bus width mask
+ * @widths: array of supported bus widths
+ * @n_widths: number of entries in @widths
+ *
+ * Like __set_bit(), the widths are added to @mask and the bits already set in it
+ * are left untouched, so @mask must be initialized by the caller.
+ *
+ * Return: 0 on success, -EINVAL if @widths contains an invalid bus width. Note
+ * that the bus widths validated before the failing one are still set.
+ */
+#define dma_bus_width_set_many(mask, widths, n_widths) \
+ __dma_bus_width_set_many(&(mask), (widths), (n_widths))
+
+/**
+ * dma_bus_width_set - set a single supported bus width
+ * @mask: bus width mask
+ * @width: supported bus width
+ *
+ * Like __set_bit(), @width is added to @mask and the bits already set in it are
+ * left untouched, so @mask must be initialized by the caller.
+ *
+ * Return: 0 on success, -EINVAL if @width is invalid.
+ */
+#define dma_bus_width_set(mask, width) \
+ __dma_bus_width_set_many(&(mask), (const enum dma_slave_buswidth[]){ (width) }, 1)
+
+static inline int __dma_bus_width_clear(dma_buswidth_mask_t *mask,
+ enum dma_slave_buswidth width)
+{
+ if (!dma_bus_width_valid(width))
+ return -EINVAL;
+
+ __clear_bit(width, mask->bits);
+
+ return 0;
+}
+
+/**
+ * dma_bus_width_clear - remove a bus width from a bus width mask
+ * @mask: bus width mask
+ * @width: bus width to clear
+ *
+ * Return: 0 on success, -EINVAL if @width is invalid.
+ */
+#define dma_bus_width_clear(mask, width) __dma_bus_width_clear(&(mask), (width))
+
+static inline bool __dma_bus_width_test(const dma_buswidth_mask_t *mask,
+ enum dma_slave_buswidth width)
+{
+ if (!dma_bus_width_valid(width))
+ return false;
+
+ return test_bit(width, mask->bits);
+}
+
+/**
+ * dma_bus_width_test - test if a bus width is part of a bus width mask
+ * @mask: bus width mask
+ * @width: bus width to test
+ *
+ * Return: true if @width is set in @mask, false otherwise.
+ */
+#define dma_bus_width_test(mask, width) __dma_bus_width_test(&(mask), (width))
+
+static inline enum dma_slave_buswidth
+__dma_bus_width_min(const dma_buswidth_mask_t *mask)
+{
+ enum dma_slave_buswidth width;
+
+ width = find_first_bit(mask->bits, DMA_SLAVE_BUSWIDTH_MAX);
+ if (width == DMA_SLAVE_BUSWIDTH_MAX)
+ return DMA_SLAVE_BUSWIDTH_UNDEFINED;
+
+ return width;
+}
+
+/**
+ * dma_bus_width_min - get the smallest bus width of a bus width mask
+ * @mask: bus width mask
+ *
+ * Return: the smallest bus width set in @mask, or
+ * %DMA_SLAVE_BUSWIDTH_UNDEFINED if @mask is empty.
+ */
+#define dma_bus_width_min(mask) __dma_bus_width_min(&(mask))
+
+static inline void __dma_bus_width_copy(dma_buswidth_mask_t *dst,
+ const dma_buswidth_mask_t *src)
+{
+ bitmap_copy(dst->bits, src->bits, DMA_SLAVE_BUSWIDTH_MAX);
+}
+
+/**
+ * dma_bus_width_copy - copy a bus width mask
+ * @dst: bus width mask to copy to
+ * @src: bus width mask to copy from
+ */
+#define dma_bus_width_copy(dst, src) __dma_bus_width_copy(&(dst), &(src))
+
+static inline bool __dma_bus_width_and(dma_buswidth_mask_t *dst,
+ const dma_buswidth_mask_t *src1,
+ const dma_buswidth_mask_t *src2)
+{
+ return bitmap_and(dst->bits, src1->bits, src2->bits,
+ DMA_SLAVE_BUSWIDTH_MAX);
+}
+
+/**
+ * dma_bus_width_and - intersect two bus width masks
+ * @dst: bus width mask to store the result in
+ * @src1: first bus width mask
+ * @src2: second bus width mask
+ *
+ * Return: true if @dst has at least one bus width set, false otherwise.
+ */
+#define dma_bus_width_and(dst, src1, src2) \
+ __dma_bus_width_and(&(dst), &(src1), &(src2))
+
/**
* struct dma_slave_config - dma slave channel runtime config
* @direction: whether the data shall go in or out on this slave
@@ -523,10 +694,11 @@ enum dma_residue_granularity {
/**
* struct dma_slave_caps - expose capabilities of a slave channel only
- * @src_addr_widths: bit mask of src addr widths the channel supports.
- * Width is specified in bytes, e.g. for a channel supporting
- * a width of 4 the mask should have BIT(4) set.
- * @dst_addr_widths: bit mask of dst addr widths the channel supports
+ * @src_bus_widths: mask of source bus widths the channel supports.
+ * @src_addr_widths: legacy bit mask of source bus widths the channel supports.
+ * @dst_bus_widths: mask of destination bus widths the channel supports.
+ * @dst_addr_widths: legacy bit mask of destination bus widths the channel
+ * supports.
* @directions: bit mask of slave directions the channel supports.
* Since the enum dma_transfer_direction is not defined as bit flag for
* each type, the dma controller should set BIT(<TYPE>) and same
@@ -545,8 +717,14 @@ enum dma_residue_granularity {
* resubmitted multiple times
*/
struct dma_slave_caps {
- u32 src_addr_widths;
- u32 dst_addr_widths;
+ struct {
+ dma_buswidth_mask_t src_bus_widths;
+ u32 src_addr_widths;
+ };
+ struct {
+ dma_buswidth_mask_t dst_bus_widths;
+ u32 dst_addr_widths;
+ };
u32 directions;
u32 min_burst;
u32 max_burst;
@@ -839,10 +1017,10 @@ struct dma_filter {
* @dev: struct device reference for dma mapping api
* @owner: owner module (automatically set based on the provided dev)
* @chan_ida: unique channel ID
- * @src_addr_widths: bit mask of src addr widths the device supports
- * Width is specified in bytes, e.g. for a device supporting
- * a width of 4 the mask should have BIT(4) set.
- * @dst_addr_widths: bit mask of dst addr widths the device supports
+ * @src_bus_widths: mask of source bus widths the device supports.
+ * @src_addr_widths: legacy bit mask of source bus widths the device supports.
+ * @dst_bus_widths: mask of destination bus widths the device supports.
+ * @dst_addr_widths: legacy bit mask of destination bus widths the device supports.
* @directions: bit mask of slave directions the device supports.
* Since the enum dma_transfer_direction is not defined as bit flag for
* each type, the dma controller should set BIT(<TYPE>) and same
@@ -924,8 +1102,14 @@ struct dma_device {
struct module *owner;
struct ida chan_ida;
- u32 src_addr_widths;
- u32 dst_addr_widths;
+ struct {
+ dma_buswidth_mask_t src_bus_widths;
+ u32 src_addr_widths;
+ };
+ struct {
+ dma_buswidth_mask_t dst_bus_widths;
+ u32 dst_addr_widths;
+ };
u32 directions;
u32 min_burst;
u32 max_burst;
--
2.56.0
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v5 1/9] dmaengine: Support bus widths of 32 bytes and above
2026-10-09 15:52 ` [PATCH v5 1/9] " Nuno Sá
@ 2026-10-09 19:33 ` Frank Li
2026-10-10 2:45 ` Frank Li
1 sibling, 0 replies; 12+ messages in thread
From: Frank Li @ 2026-10-09 19:33 UTC (permalink / raw)
To: Nuno Sá
Cc: linux-kernel, dmaengine, linux-arm-msm, linux-stm32,
linux-arm-kernel, linux-iio, linux-sound, linux-spi, Vinod Koul,
Frank Li, Lars-Peter Clausen, Eugeniy Paltsev,
Amélie Delaunay, Maxime Coquelin, Alexandre Torgue,
Jonathan Cameron, David Lechner, Andy Shevchenko,
Jaroslav Kysela, Takashi Iwai, Mark Brown
On Fri, Oct 09, 2026 at 04:52:53PM +0100, Nuno Sá wrote:
> The src_addr_widths and dst_addr_widths capability masks encode each
> supported width as a bit whose position equals the corresponding
> enum dma_slave_buswidth value (e.g. DMA_SLAVE_BUSWIDTH_4_BYTES sets bit
> 4). As these masks are plain u32, widths of 32 bytes and above
> (DMA_SLAVE_BUSWIDTH_32/64/128_BYTES map to bits 32, 64 and 128) cannot
> be represented at all.
>
> Introduce bitmap-based bus width capabilities that span the full enum
> range, through a new dma_buswidth_mask_t type modeled after
> dma_cap_mask_t. To allow DMA controller drivers to be converted
> incrementally, the legacy dma_device u32 fields are kept alongside the
> new masks and the core folds a legacy-only driver's u32 into the mask
> when the device is registered, so consumers only ever have to look at
> the mask.
>
> The fold is bidirectional while both representations coexist. A driver
> that only fills in the legacy u32 gets its mask derived from it, so the
> consumers already converted see it. A driver that only fills in the mask
> gets its legacy u32 derived from the mask, so the consumers not
> converted yet, which read the legacy dma_slave_caps fields, keep working.
>
> On top of that, dma_get_slave_caps() derives the legacy dma_slave_caps
> masks from the new ones when a device_caps() callback adjusted them, so
> that a converted controller narrowing its per-channel capabilities is
> still seen by the consumers not converted yet, while a driver adjusting
> the legacy masks directly keeps working.
>
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
>
> ---
>
> Andy, did not take your tag given that you're the one asking for the
> split and since we ended up not doing it, not sure if the tag is
> to be kept :)
> ---
> drivers/dma/dmaengine.c | 51 +++++++++++-
> include/linux/dmaengine.h | 208 +++++++++++++++++++++++++++++++++++++++++++---
> 2 files changed, 246 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index c5fef57b5adf..4ba9d6c7448a 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -33,6 +33,7 @@
>
> #include <linux/acpi.h>
> #include <linux/acpi_dma.h>
> +#include <linux/bitmap.h>
> #include <linux/device.h>
> #include <linux/dma-mapping.h>
> #include <linux/dmaengine.h>
> @@ -592,8 +593,11 @@ int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps)
> if (!device->directions)
> return -ENXIO;
>
> + dma_bus_width_copy(caps->src_bus_widths, device->src_bus_widths);
> + dma_bus_width_copy(caps->dst_bus_widths, device->dst_bus_widths);
> caps->src_addr_widths = device->src_addr_widths;
> caps->dst_addr_widths = device->dst_addr_widths;
> +
Remove this empty change.
> caps->directions = device->directions;
> caps->min_burst = device->min_burst;
> caps->max_burst = device->max_burst;
> @@ -611,9 +615,31 @@ int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps)
> * callback to override the generic capabilities with
> * channel-specific ones.
> */
> - if (device->device_caps)
> + if (device->device_caps) {
> device->device_caps(chan, caps);
...
> + * Return: 0 on success, -EINVAL if @widths contains an invalid bus width. Note
> + * that the bus widths validated before the failing one are still set.
> + */
> +#define dma_bus_width_set_many(mask, widths, n_widths) \
> + __dma_bus_width_set_many(&(mask), (widths), (n_widths))
This is not good to get first argument pointer here, which will cause
confused. check others.
#define dma_bus_width_set_many(mask, widths, n_widths) \
__dma_bus_width_set_many((mask), (widths), (n_widths))
Frank
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v5 1/9] dmaengine: Support bus widths of 32 bytes and above
2026-10-09 15:52 ` [PATCH v5 1/9] " Nuno Sá
2026-10-09 19:33 ` Frank Li
@ 2026-10-10 2:45 ` Frank Li
1 sibling, 0 replies; 12+ messages in thread
From: Frank Li @ 2026-10-10 2:45 UTC (permalink / raw)
To: Nuno Sá
Cc: linux-kernel, dmaengine, linux-arm-msm, linux-stm32,
linux-arm-kernel, linux-iio, linux-sound, linux-spi, Vinod Koul,
Frank Li, Lars-Peter Clausen, Eugeniy Paltsev,
Amélie Delaunay, Maxime Coquelin, Alexandre Torgue,
Jonathan Cameron, David Lechner, Andy Shevchenko,
Jaroslav Kysela, Takashi Iwai, Mark Brown
On Fri, Oct 09, 2026 at 04:52:53PM +0100, Nuno Sá wrote:
> The src_addr_widths and dst_addr_widths capability masks encode each
> supported width as a bit whose position equals the corresponding
> enum dma_slave_buswidth value (e.g. DMA_SLAVE_BUSWIDTH_4_BYTES sets bit
> 4). As these masks are plain u32, widths of 32 bytes and above
> (DMA_SLAVE_BUSWIDTH_32/64/128_BYTES map to bits 32, 64 and 128) cannot
> be represented at all.
>
> Introduce bitmap-based bus width capabilities that span the full enum
> range, through a new dma_buswidth_mask_t type modeled after
> dma_cap_mask_t. To allow DMA controller drivers to be converted
> incrementally, the legacy dma_device u32 fields are kept alongside the
> new masks and the core folds a legacy-only driver's u32 into the mask
> when the device is registered, so consumers only ever have to look at
> the mask.
>
> The fold is bidirectional while both representations coexist. A driver
> that only fills in the legacy u32 gets its mask derived from it, so the
> consumers already converted see it. A driver that only fills in the mask
> gets its legacy u32 derived from the mask, so the consumers not
> converted yet, which read the legacy dma_slave_caps fields, keep working.
>
> On top of that, dma_get_slave_caps() derives the legacy dma_slave_caps
> masks from the new ones when a device_caps() callback adjusted them, so
> that a converted controller narrowing its per-channel capabilities is
> still seen by the consumers not converted yet, while a driver adjusting
> the legacy masks directly keeps working.
>
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
>
> ---
>
> Andy, did not take your tag given that you're the one asking for the
> split and since we ended up not doing it, not sure if the tag is
> to be kept :)
> ---
> drivers/dma/dmaengine.c | 51 +++++++++++-
> include/linux/dmaengine.h | 208 +++++++++++++++++++++++++++++++++++++++++++---
> 2 files changed, 246 insertions(+), 13 deletions(-)
>
...
>
> /* note: this only matters in the
> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
> index 71cde09ff240..eb68eea840b5 100644
> --- a/include/linux/dmaengine.h
> +++ b/include/linux/dmaengine.h
> @@ -427,8 +427,179 @@ enum dma_slave_buswidth {
> DMA_SLAVE_BUSWIDTH_32_BYTES = 32,
> DMA_SLAVE_BUSWIDTH_64_BYTES = 64,
> DMA_SLAVE_BUSWIDTH_128_BYTES = 128,
> + DMA_SLAVE_BUSWIDTH_MAX
> };
>
...
> +/**
> + * dma_bus_width_min - get the smallest bus width of a bus width mask
> + * @mask: bus width mask
> + *
> + * Return: the smallest bus width set in @mask, or
> + * %DMA_SLAVE_BUSWIDTH_UNDEFINED if @mask is empty.
> + */
> +#define dma_bus_width_min(mask) __dma_bus_width_min(&(mask))
> +
We are working on make dma_device private. New API avoid direct use
dma_device field.
pass down dma_chan point, dma engine handle everything in core part.
> +static inline void __dma_bus_width_copy(dma_buswidth_mask_t *dst,
> + const dma_buswidth_mask_t *src)
> +{
> + bitmap_copy(dst->bits, src->bits, DMA_SLAVE_BUSWIDTH_MAX);
> +}
> +
> +/**
> + * dma_bus_width_copy - copy a bus width mask
> + * @dst: bus width mask to copy to
> + * @src: bus width mask to copy from
> + */
> +#define dma_bus_width_copy(dst, src) __dma_bus_width_copy(&(dst), &(src))
> +
> +static inline bool __dma_bus_width_and(dma_buswidth_mask_t *dst,
> + const dma_buswidth_mask_t *src1,
> + const dma_buswidth_mask_t *src2)
> +{
> + return bitmap_and(dst->bits, src1->bits, src2->bits,
> + DMA_SLAVE_BUSWIDTH_MAX);
> +}
> +
> +/**
> + * dma_bus_width_and - intersect two bus width masks
> + * @dst: bus width mask to store the result in
> + * @src1: first bus width mask
> + * @src2: second bus width mask
> + *
> + * Return: true if @dst has at least one bus width set, false otherwise.
> + */
> +#define dma_bus_width_and(dst, src1, src2) \
> + __dma_bus_width_and(&(dst), &(src1), &(src2))
> +
One thing I forget, new API should start from dmaengine_.
Frank
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v5 2/9] dmaengine: dma-axi-dmac: Use bus width capability helpers
2026-10-09 15:52 [PATCH v5 0/9] dmaengine: Support bus widths of 32 bytes and above Nuno Sá
2026-10-09 15:52 ` [PATCH v5 1/9] " Nuno Sá
@ 2026-10-09 15:52 ` Nuno Sá
2026-10-09 15:52 ` [PATCH v5 3/9] dmaengine: dw-axi-dmac: " Nuno Sá
` (6 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sá @ 2026-10-09 15:52 UTC (permalink / raw)
To: linux-kernel, dmaengine, linux-arm-msm, linux-stm32,
linux-arm-kernel, linux-iio, linux-sound, linux-spi
Cc: Vinod Koul, Frank Li, Lars-Peter Clausen, Eugeniy Paltsev,
Amélie Delaunay, Maxime Coquelin, Alexandre Torgue,
Jonathan Cameron, David Lechner, Andy Shevchenko,
Jaroslav Kysela, Takashi Iwai, Mark Brown, Frank Li
Advertise the source and destination bus widths through the new
dma_bus_width_set() helper instead of open-coding the legacy
BIT() mask. This moves the driver onto the representation that can
express widths of 32 bytes and above while keeping the legacy u32 fields
populated during the transition.
While at it, give the channel width members their proper
enum dma_slave_buswidth type.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
drivers/dma/dma-axi-dmac.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c
index d47ff27e1408..ca9cf1e0c5e4 100644
--- a/drivers/dma/dma-axi-dmac.c
+++ b/drivers/dma/dma-axi-dmac.c
@@ -152,8 +152,8 @@ struct axi_dmac_chan {
struct list_head active_descs;
enum dma_transfer_direction direction;
- unsigned int src_width;
- unsigned int dest_width;
+ enum dma_slave_buswidth src_width;
+ enum dma_slave_buswidth dest_width;
unsigned int src_type;
unsigned int dest_type;
@@ -1262,8 +1262,13 @@ static int axi_dmac_probe(struct platform_device *pdev)
dma_dev->device_terminate_all = axi_dmac_terminate_all;
dma_dev->device_synchronize = axi_dmac_synchronize;
dma_dev->dev = &pdev->dev;
- dma_dev->src_addr_widths = BIT(dmac->chan.src_width);
- dma_dev->dst_addr_widths = BIT(dmac->chan.dest_width);
+ ret = dma_bus_width_set(dma_dev->src_bus_widths, dmac->chan.src_width);
+ if (ret)
+ return ret;
+
+ ret = dma_bus_width_set(dma_dev->dst_bus_widths, dmac->chan.dest_width);
+ if (ret)
+ return ret;
dma_dev->directions = BIT(dmac->chan.direction);
dma_dev->residue_granularity = DMA_RESIDUE_GRANULARITY_DESCRIPTOR;
dma_dev->max_sg_burst = 31; /* 31 SGs maximum in one burst */
--
2.56.0
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH v5 3/9] dmaengine: dw-axi-dmac: Use bus width capability helpers
2026-10-09 15:52 [PATCH v5 0/9] dmaengine: Support bus widths of 32 bytes and above Nuno Sá
2026-10-09 15:52 ` [PATCH v5 1/9] " Nuno Sá
2026-10-09 15:52 ` [PATCH v5 2/9] dmaengine: dma-axi-dmac: Use bus width capability helpers Nuno Sá
@ 2026-10-09 15:52 ` Nuno Sá
2026-10-09 15:52 ` [PATCH v5 4/9] dmaengine: qcom: gpi: " Nuno Sá
` (5 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sá @ 2026-10-09 15:52 UTC (permalink / raw)
To: linux-kernel, dmaengine, linux-arm-msm, linux-stm32,
linux-arm-kernel, linux-iio, linux-sound, linux-spi
Cc: Vinod Koul, Frank Li, Lars-Peter Clausen, Eugeniy Paltsev,
Amélie Delaunay, Maxime Coquelin, Alexandre Torgue,
Jonathan Cameron, David Lechner, Andy Shevchenko,
Jaroslav Kysela, Takashi Iwai, Mark Brown, Frank Li
Advertise the supported bus widths through dma_bus_width_set_many()
instead of assigning the legacy u32 masks directly. This keeps the
driver using the new bitmap representation while preserving legacy
fields during the transition.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 37 +++++++++++++++-----------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
index 7520c78f55cc..7b745459f6ed 100644
--- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
+++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
@@ -34,20 +34,6 @@
#include "../dmaengine.h"
#include "../virt-dma.h"
-/*
- * The set of bus widths supported by the DMA controller. DW AXI DMAC supports
- * master data bus width up to 512 bits (for both AXI master interfaces), but
- * it depends on IP block configuration.
- */
-#define AXI_DMA_BUSWIDTHS \
- (DMA_SLAVE_BUSWIDTH_1_BYTE | \
- DMA_SLAVE_BUSWIDTH_2_BYTES | \
- DMA_SLAVE_BUSWIDTH_4_BYTES | \
- DMA_SLAVE_BUSWIDTH_8_BYTES | \
- DMA_SLAVE_BUSWIDTH_16_BYTES | \
- DMA_SLAVE_BUSWIDTH_32_BYTES | \
- DMA_SLAVE_BUSWIDTH_64_BYTES)
-
#define AXI_DMA_FLAG_HAS_APB_REGS BIT(0)
#define AXI_DMA_FLAG_HAS_RESETS BIT(1)
#define AXI_DMA_FLAG_USE_CFG2 BIT(2)
@@ -1476,6 +1462,20 @@ static int dw_probe(struct platform_device *pdev)
unsigned int flags;
u32 i;
int ret;
+ /*
+ * The set of bus widths supported by the DMA controller. DW AXI DMAC
+ * supports master data bus width up to 512 bits (for both AXI master
+ * interfaces), but it depends on IP block configuration.
+ */
+ enum dma_slave_buswidth buswidths[] = {
+ DMA_SLAVE_BUSWIDTH_1_BYTE,
+ DMA_SLAVE_BUSWIDTH_2_BYTES,
+ DMA_SLAVE_BUSWIDTH_4_BYTES,
+ DMA_SLAVE_BUSWIDTH_8_BYTES,
+ DMA_SLAVE_BUSWIDTH_16_BYTES,
+ DMA_SLAVE_BUSWIDTH_32_BYTES,
+ DMA_SLAVE_BUSWIDTH_64_BYTES,
+ };
chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
if (!chip)
@@ -1557,8 +1557,13 @@ static int dw_probe(struct platform_device *pdev)
/* DMA capabilities */
dw->dma.max_burst = hdata->axi_rw_burst_len;
- dw->dma.src_addr_widths = AXI_DMA_BUSWIDTHS;
- dw->dma.dst_addr_widths = AXI_DMA_BUSWIDTHS;
+ ret = dma_bus_width_set_many(dw->dma.src_bus_widths, buswidths, ARRAY_SIZE(buswidths));
+ if (ret)
+ return ret;
+
+ ret = dma_bus_width_set_many(dw->dma.dst_bus_widths, buswidths, ARRAY_SIZE(buswidths));
+ if (ret)
+ return ret;
dw->dma.directions = BIT(DMA_MEM_TO_MEM);
dw->dma.directions |= BIT(DMA_MEM_TO_DEV) | BIT(DMA_DEV_TO_MEM);
dw->dma.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
--
2.56.0
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH v5 4/9] dmaengine: qcom: gpi: Use bus width capability helpers
2026-10-09 15:52 [PATCH v5 0/9] dmaengine: Support bus widths of 32 bytes and above Nuno Sá
` (2 preceding siblings ...)
2026-10-09 15:52 ` [PATCH v5 3/9] dmaengine: dw-axi-dmac: " Nuno Sá
@ 2026-10-09 15:52 ` Nuno Sá
2026-10-09 15:52 ` [PATCH v5 5/9] dmaengine: stm32-dma3: " Nuno Sá
` (4 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sá @ 2026-10-09 15:52 UTC (permalink / raw)
To: linux-kernel, dmaengine, linux-arm-msm, linux-stm32,
linux-arm-kernel, linux-iio, linux-sound, linux-spi
Cc: Vinod Koul, Frank Li, Lars-Peter Clausen, Eugeniy Paltsev,
Amélie Delaunay, Maxime Coquelin, Alexandre Torgue,
Jonathan Cameron, David Lechner, Andy Shevchenko,
Jaroslav Kysela, Takashi Iwai, Mark Brown, Frank Li
Advertise the single supported source and destination bus width through
the new dma_bus_width_set() helper
instead of assigning the legacy u32 fields directly.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
drivers/dma/qcom/gpi.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/dma/qcom/gpi.c b/drivers/dma/qcom/gpi.c
index c41bfac65ddf..1959ff8d1b3c 100644
--- a/drivers/dma/qcom/gpi.c
+++ b/drivers/dma/qcom/gpi.c
@@ -2270,8 +2270,15 @@ static int gpi_probe(struct platform_device *pdev)
/* configure dmaengine apis */
gpi_dev->dma_device.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
gpi_dev->dma_device.residue_granularity = DMA_RESIDUE_GRANULARITY_DESCRIPTOR;
- gpi_dev->dma_device.src_addr_widths = DMA_SLAVE_BUSWIDTH_8_BYTES;
- gpi_dev->dma_device.dst_addr_widths = DMA_SLAVE_BUSWIDTH_8_BYTES;
+ ret = dma_bus_width_set(gpi_dev->dma_device.src_bus_widths,
+ DMA_SLAVE_BUSWIDTH_8_BYTES);
+ if (ret)
+ return ret;
+
+ ret = dma_bus_width_set(gpi_dev->dma_device.dst_bus_widths,
+ DMA_SLAVE_BUSWIDTH_8_BYTES);
+ if (ret)
+ return ret;
gpi_dev->dma_device.device_alloc_chan_resources = gpi_alloc_chan_resources;
gpi_dev->dma_device.device_free_chan_resources = gpi_free_chan_resources;
gpi_dev->dma_device.device_tx_status = dma_cookie_status;
--
2.56.0
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH v5 5/9] dmaengine: stm32-dma3: Use bus width capability helpers
2026-10-09 15:52 [PATCH v5 0/9] dmaengine: Support bus widths of 32 bytes and above Nuno Sá
` (3 preceding siblings ...)
2026-10-09 15:52 ` [PATCH v5 4/9] dmaengine: qcom: gpi: " Nuno Sá
@ 2026-10-09 15:52 ` Nuno Sá
2026-10-09 15:52 ` [PATCH v5 6/9] iio: buffer-dmaengine: Use dma_slave_caps bus width accessors Nuno Sá
` (3 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sá @ 2026-10-09 15:52 UTC (permalink / raw)
To: linux-kernel, dmaengine, linux-arm-msm, linux-stm32,
linux-arm-kernel, linux-iio, linux-sound, linux-spi
Cc: Vinod Koul, Frank Li, Lars-Peter Clausen, Eugeniy Paltsev,
Amélie Delaunay, Maxime Coquelin, Alexandre Torgue,
Jonathan Cameron, David Lechner, Andy Shevchenko,
Jaroslav Kysela, Takashi Iwai, Mark Brown, Frank Li
Advertise the controller-wide bus width capabilities through the new
dma_bus_width_set_many() helper and clear the per-channel unsupported
widths through dma_bus_width_clear().
While at it, validate the requested transfer bus widths against the new
capability mask instead of the legacy u32 one, so the driver does not
depend on the legacy field anymore.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Reviewed-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
drivers/dma/stm32/stm32-dma3.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/drivers/dma/stm32/stm32-dma3.c b/drivers/dma/stm32/stm32-dma3.c
index 4fe226541efa..8a8a0b9ab507 100644
--- a/drivers/dma/stm32/stm32-dma3.c
+++ b/drivers/dma/stm32/stm32-dma3.c
@@ -583,7 +583,8 @@ static int stm32_dma3_chan_prep_hw(struct stm32_dma3_chan *chan, enum dma_transf
dbl_max = chan->dma_config.dst_maxburst ? : 1;
/* Following conditions would raise User Setting Error interrupt */
- if (!(dma_device.src_addr_widths & BIT(sdw)) || !(dma_device.dst_addr_widths & BIT(ddw))) {
+ if (!dma_bus_width_test(dma_device.src_bus_widths, sdw) ||
+ !dma_bus_width_test(dma_device.dst_bus_widths, ddw)) {
dev_err(vchan_chan_dev(&chan->vchan), "Bus width (src=%u, dst=%u) not supported\n", sdw, ddw);
return -EINVAL;
}
@@ -1464,14 +1465,14 @@ static void stm32_dma3_caps(struct dma_chan *c, struct dma_slave_caps *caps)
if (!chan->fifo_size) {
caps->max_burst = 0;
- caps->src_addr_widths &= ~BIT(DMA_SLAVE_BUSWIDTH_8_BYTES);
- caps->dst_addr_widths &= ~BIT(DMA_SLAVE_BUSWIDTH_8_BYTES);
+ dma_bus_width_clear(caps->src_bus_widths, DMA_SLAVE_BUSWIDTH_8_BYTES);
+ dma_bus_width_clear(caps->dst_bus_widths, DMA_SLAVE_BUSWIDTH_8_BYTES);
} else {
/* Burst transfer should not exceed half of the fifo size */
caps->max_burst = chan->max_burst;
if (caps->max_burst < DMA_SLAVE_BUSWIDTH_8_BYTES) {
- caps->src_addr_widths &= ~BIT(DMA_SLAVE_BUSWIDTH_8_BYTES);
- caps->dst_addr_widths &= ~BIT(DMA_SLAVE_BUSWIDTH_8_BYTES);
+ dma_bus_width_clear(caps->src_bus_widths, DMA_SLAVE_BUSWIDTH_8_BYTES);
+ dma_bus_width_clear(caps->dst_bus_widths, DMA_SLAVE_BUSWIDTH_8_BYTES);
}
}
}
@@ -1729,6 +1730,12 @@ static int stm32_dma3_probe(struct platform_device *pdev)
struct reset_control *reset;
struct stm32_dma3_chan *chan;
struct dma_device *dma_dev;
+ enum dma_slave_buswidth buswidths[] = {
+ DMA_SLAVE_BUSWIDTH_1_BYTE,
+ DMA_SLAVE_BUSWIDTH_2_BYTES,
+ DMA_SLAVE_BUSWIDTH_4_BYTES,
+ DMA_SLAVE_BUSWIDTH_8_BYTES,
+ };
u32 master_ports, chan_reserved, i, verr;
u64 hwcfgr;
int ret;
@@ -1770,14 +1777,14 @@ static int stm32_dma3_probe(struct platform_device *pdev)
* channel, and can only access address at even boundaries, multiple of the buswidth.
*/
dma_dev->copy_align = DMAENGINE_ALIGN_8_BYTES;
- dma_dev->src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) |
- BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) |
- BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) |
- BIT(DMA_SLAVE_BUSWIDTH_8_BYTES);
- dma_dev->dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) |
- BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) |
- BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) |
- BIT(DMA_SLAVE_BUSWIDTH_8_BYTES);
+ ret = dma_bus_width_set_many(dma_dev->src_bus_widths, buswidths, ARRAY_SIZE(buswidths));
+ if (ret)
+ goto err_clk_disable;
+
+ ret = dma_bus_width_set_many(dma_dev->dst_bus_widths, buswidths, ARRAY_SIZE(buswidths));
+ if (ret)
+ goto err_clk_disable;
+
dma_dev->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV) | BIT(DMA_MEM_TO_MEM);
dma_dev->descriptor_reuse = true;
--
2.56.0
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH v5 6/9] iio: buffer-dmaengine: Use dma_slave_caps bus width accessors
2026-10-09 15:52 [PATCH v5 0/9] dmaengine: Support bus widths of 32 bytes and above Nuno Sá
` (4 preceding siblings ...)
2026-10-09 15:52 ` [PATCH v5 5/9] dmaengine: stm32-dma3: " Nuno Sá
@ 2026-10-09 15:52 ` Nuno Sá
2026-10-09 15:52 ` [PATCH v5 7/9] ALSA: pcm_dmaengine: Use dma_slave_caps bus width helpers Nuno Sá
` (2 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sá @ 2026-10-09 15:52 UTC (permalink / raw)
To: linux-kernel, dmaengine, linux-arm-msm, linux-stm32,
linux-arm-kernel, linux-iio, linux-sound, linux-spi
Cc: Vinod Koul, Frank Li, Lars-Peter Clausen, Eugeniy Paltsev,
Amélie Delaunay, Maxime Coquelin, Alexandre Torgue,
Jonathan Cameron, David Lechner, Andy Shevchenko,
Jaroslav Kysela, Takashi Iwai, Mark Brown, Frank Li,
Jonathan Cameron, Andy Shevchenko
Query the minimum supported source and destination bus widths through
the new dma_bus_width_min() helper rather than decoding the raw legacy
u32 width masks. This keeps the buffer working
with DMA controllers that advertise bus widths via the new bitmap
representation.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Acked-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
drivers/iio/buffer/industrialio-buffer-dmaengine.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
index ecc02a427b92..df78c1f811e0 100644
--- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c
+++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
@@ -265,14 +265,13 @@ static struct iio_buffer *iio_dmaengine_buffer_alloc(struct dma_chan *chan)
return ERR_PTR(-ENOMEM);
/* Needs to be aligned to the maximum of the minimums */
- if (caps.src_addr_widths)
- src_width = __ffs(caps.src_addr_widths);
- else
- src_width = 1;
- if (caps.dst_addr_widths)
- dest_width = __ffs(caps.dst_addr_widths);
- else
- dest_width = 1;
+ src_width = dma_bus_width_min(caps.src_bus_widths);
+ if (src_width == DMA_SLAVE_BUSWIDTH_UNDEFINED)
+ src_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
+ dest_width = dma_bus_width_min(caps.dst_bus_widths);
+ if (dest_width == DMA_SLAVE_BUSWIDTH_UNDEFINED)
+ dest_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
+
width = max(src_width, dest_width);
INIT_LIST_HEAD(&dmaengine_buffer->active);
--
2.56.0
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH v5 7/9] ALSA: pcm_dmaengine: Use dma_slave_caps bus width helpers
2026-10-09 15:52 [PATCH v5 0/9] dmaengine: Support bus widths of 32 bytes and above Nuno Sá
` (5 preceding siblings ...)
2026-10-09 15:52 ` [PATCH v5 6/9] iio: buffer-dmaengine: Use dma_slave_caps bus width accessors Nuno Sá
@ 2026-10-09 15:52 ` Nuno Sá
2026-10-09 15:53 ` [PATCH v5 8/9] spi: dw: " Nuno Sá
2026-10-09 15:53 ` [PATCH v5 9/9] dmaengine: Drop legacy bus width fields from dma_slave_caps Nuno Sá
8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sá @ 2026-10-09 15:52 UTC (permalink / raw)
To: linux-kernel, dmaengine, linux-arm-msm, linux-stm32,
linux-arm-kernel, linux-iio, linux-sound, linux-spi
Cc: Vinod Koul, Frank Li, Lars-Peter Clausen, Eugeniy Paltsev,
Amélie Delaunay, Maxime Coquelin, Alexandre Torgue,
Jonathan Cameron, David Lechner, Andy Shevchenko,
Jaroslav Kysela, Takashi Iwai, Mark Brown, Frank Li
Use the dma_slave_caps bus width helpers instead of reading the legacy
src_addr_widths and dst_addr_widths masks directly.
Keep the existing default assumption of 1, 2 and 4 byte widths when the
DMA channel does not report slave capabilities.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
Andy, I decided to not go with the implicit call to bitmap_zero() in
_set() and _set_many(). The reason is that almost all the users are dma
controllers where the bitmap is initialized (given it's part of the
dma_device struct) so it seems unnecessary churn just to make one caller
"happy". These APIs also follow bitmap (set_bit() included) semantics so
it makes sense to me to leave as-is. Added a note on the kernel doc
though.
And it's easier to add the implicit call in the future (if it proves
necessary). Removing it, not so easy...
---
sound/core/pcm_dmaengine.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c
index 1306b04be171..f7a061f07e95 100644
--- a/sound/core/pcm_dmaengine.c
+++ b/sound/core/pcm_dmaengine.c
@@ -408,16 +408,24 @@ int snd_dmaengine_pcm_refine_runtime_hwparams(
struct snd_pcm_hardware *hw,
struct dma_chan *chan)
{
+ enum dma_slave_buswidth default_widths[] = {
+ DMA_SLAVE_BUSWIDTH_1_BYTE,
+ DMA_SLAVE_BUSWIDTH_2_BYTES,
+ DMA_SLAVE_BUSWIDTH_4_BYTES,
+ };
struct dma_slave_caps dma_caps;
- u32 addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) |
- BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) |
- BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
+ dma_buswidth_mask_t bus_widths = {};
snd_pcm_format_t i;
int ret = 0;
if (!hw || !chan || !dma_data)
return -EINVAL;
+ ret = dma_bus_width_set_many(bus_widths, default_widths,
+ ARRAY_SIZE(default_widths));
+ if (ret)
+ return ret;
+
ret = dma_get_slave_caps(chan, &dma_caps);
if (ret == 0) {
if (dma_caps.cmd_pause && dma_caps.cmd_resume)
@@ -426,9 +434,9 @@ int snd_dmaengine_pcm_refine_runtime_hwparams(
hw->info |= SNDRV_PCM_INFO_BATCH;
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
- addr_widths = dma_caps.dst_addr_widths;
+ dma_bus_width_copy(bus_widths, dma_caps.dst_bus_widths);
else
- addr_widths = dma_caps.src_addr_widths;
+ dma_bus_width_copy(bus_widths, dma_caps.src_bus_widths);
}
/*
@@ -460,7 +468,7 @@ int snd_dmaengine_pcm_refine_runtime_hwparams(
case 24:
case 32:
case 64:
- if (addr_widths & (1 << (bits / 8)))
+ if (dma_bus_width_test(bus_widths, bits / 8))
hw->formats |= pcm_format_to_bits(i);
break;
default:
--
2.56.0
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH v5 8/9] spi: dw: Use dma_slave_caps bus width helpers
2026-10-09 15:52 [PATCH v5 0/9] dmaengine: Support bus widths of 32 bytes and above Nuno Sá
` (6 preceding siblings ...)
2026-10-09 15:52 ` [PATCH v5 7/9] ALSA: pcm_dmaengine: Use dma_slave_caps bus width helpers Nuno Sá
@ 2026-10-09 15:53 ` Nuno Sá
2026-10-09 15:53 ` [PATCH v5 9/9] dmaengine: Drop legacy bus width fields from dma_slave_caps Nuno Sá
8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sá @ 2026-10-09 15:53 UTC (permalink / raw)
To: linux-kernel, dmaengine, linux-arm-msm, linux-stm32,
linux-arm-kernel, linux-iio, linux-sound, linux-spi
Cc: Vinod Koul, Frank Li, Lars-Peter Clausen, Eugeniy Paltsev,
Amélie Delaunay, Maxime Coquelin, Alexandre Torgue,
Jonathan Cameron, David Lechner, Andy Shevchenko,
Jaroslav Kysela, Takashi Iwai, Mark Brown, Frank Li,
Andy Shevchenko
Store the common TX destination and RX source bus widths in a
driver-owned DMA bus width bitmap and populate it through the
dma_slave_caps helper.
This avoids depending on the legacy src_addr_widths and dst_addr_widths
masks returned by dma_get_slave_caps().
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Acked-by: Mark Brown <broonie@kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
drivers/spi/spi-dw-dma.c | 7 ++++---
drivers/spi/spi-dw.h | 3 ++-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c
index f7d848fec9ab..8fdeef653f5c 100644
--- a/drivers/spi/spi-dw-dma.c
+++ b/drivers/spi/spi-dw-dma.c
@@ -100,10 +100,11 @@ static int dw_spi_dma_caps_init(struct dw_spi *dws)
/*
* Assuming both channels belong to the same DMA controller hence the
- * peripheral side address width capabilities most likely would be
+ * peripheral side bus width capabilities most likely would be
* the same.
*/
- dws->dma_addr_widths = tx.dst_addr_widths & rx.src_addr_widths;
+ dma_bus_width_and(dws->dma_bus_widths, tx.dst_bus_widths,
+ rx.src_bus_widths);
return 0;
}
@@ -254,7 +255,7 @@ static bool dw_spi_can_dma(struct spi_controller *ctlr,
dma_bus_width = dw_spi_dma_convert_width(n_bytes);
- return dws->dma_addr_widths & BIT(dma_bus_width);
+ return dma_bus_width_test(dws->dma_bus_widths, dma_bus_width);
}
static int dw_spi_dma_wait(struct dw_spi *dws, unsigned int len, u32 speed)
diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h
index e62f919f1188..351034bcbb97 100644
--- a/drivers/spi/spi-dw.h
+++ b/drivers/spi/spi-dw.h
@@ -5,6 +5,7 @@
#include <linux/bits.h>
#include <linux/completion.h>
#include <linux/debugfs.h>
+#include <linux/dmaengine.h>
#include <linux/irqreturn.h>
#include <linux/io.h>
#include <linux/scatterlist.h>
@@ -228,7 +229,7 @@ struct dw_spi {
struct dma_chan *rxchan;
u32 rxburst;
u32 dma_sg_burst;
- u32 dma_addr_widths;
+ dma_buswidth_mask_t dma_bus_widths;
unsigned long dma_chan_busy;
dma_addr_t dma_addr; /* phy address of the Data register */
const struct dw_spi_dma_ops *dma_ops;
--
2.56.0
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH v5 9/9] dmaengine: Drop legacy bus width fields from dma_slave_caps
2026-10-09 15:52 [PATCH v5 0/9] dmaengine: Support bus widths of 32 bytes and above Nuno Sá
` (7 preceding siblings ...)
2026-10-09 15:53 ` [PATCH v5 8/9] spi: dw: " Nuno Sá
@ 2026-10-09 15:53 ` Nuno Sá
8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sá @ 2026-10-09 15:53 UTC (permalink / raw)
To: linux-kernel, dmaengine, linux-arm-msm, linux-stm32,
linux-arm-kernel, linux-iio, linux-sound, linux-spi
Cc: Vinod Koul, Frank Li, Lars-Peter Clausen, Eugeniy Paltsev,
Amélie Delaunay, Maxime Coquelin, Alexandre Torgue,
Jonathan Cameron, David Lechner, Andy Shevchenko,
Jaroslav Kysela, Takashi Iwai, Mark Brown, Frank Li,
Andy Shevchenko
All users of dma_get_slave_caps() that inspect bus width capabilities now
use the bitmap helpers.
Hence, remove the legacy u32 src_addr_widths and dst_addr_widths fields
from struct dma_slave_caps and stop copying the dma_device masks into
them.
Note the legacy u32 src_addr_widths and dst_addr_widths fields in struct
dma_device are kept for now as every DMA controller driver setting them
still has to be converted to the new helpers. dma_get_slave_caps() keeps
folding those masks into the bitmaps it returns so unconverted producers
continue to work during the transition.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
drivers/dma/dmaengine.c | 31 +------------------------------
include/linux/dmaengine.h | 13 ++-----------
2 files changed, 3 insertions(+), 41 deletions(-)
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 4ba9d6c7448a..51f706dadc7a 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -595,8 +595,6 @@ int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps)
dma_bus_width_copy(caps->src_bus_widths, device->src_bus_widths);
dma_bus_width_copy(caps->dst_bus_widths, device->dst_bus_widths);
- caps->src_addr_widths = device->src_addr_widths;
- caps->dst_addr_widths = device->dst_addr_widths;
caps->directions = device->directions;
caps->min_burst = device->min_burst;
@@ -615,31 +613,9 @@ int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps)
* callback to override the generic capabilities with
* channel-specific ones.
*/
- if (device->device_caps) {
+ if (device->device_caps)
device->device_caps(chan, caps);
- /*
- * A driver already converted to the bus width interface
- * adjusts the masks, so derive the legacy capabilities from
- * them for the consumers not converted yet. Drivers not
- * converted adjust the legacy capabilities directly, in which
- * case there is nothing to do.
- *
- * Goes away with the legacy dma_slave_caps fields.
- */
- if (!bitmap_equal(caps->src_bus_widths.bits,
- device->src_bus_widths.bits,
- DMA_SLAVE_BUSWIDTH_MAX))
- caps->src_addr_widths = bitmap_read(caps->src_bus_widths.bits,
- 0, 32);
-
- if (!bitmap_equal(caps->dst_bus_widths.bits,
- device->dst_bus_widths.bits,
- DMA_SLAVE_BUSWIDTH_MAX))
- caps->dst_addr_widths = bitmap_read(caps->dst_bus_widths.bits,
- 0, 32);
- }
-
return 0;
}
EXPORT_SYMBOL_GPL(dma_get_slave_caps);
@@ -1210,14 +1186,9 @@ static void dma_device_fold_legacy_bus_widths(struct dma_device *device)
{
if (bitmap_empty(device->src_bus_widths.bits, DMA_SLAVE_BUSWIDTH_MAX))
bitmap_from_arr32(device->src_bus_widths.bits, &device->src_addr_widths, 32);
- /* consumers not converted yet still read the legacy caps */
- else if (!device->src_addr_widths)
- device->src_addr_widths = bitmap_read(device->src_bus_widths.bits, 0, 32);
if (bitmap_empty(device->dst_bus_widths.bits, DMA_SLAVE_BUSWIDTH_MAX))
bitmap_from_arr32(device->dst_bus_widths.bits, &device->dst_addr_widths, 32);
- else if (!device->dst_addr_widths)
- device->dst_addr_widths = bitmap_read(device->dst_bus_widths.bits, 0, 32);
}
/**
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index eb68eea840b5..0b79bc4c5f74 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -695,10 +695,7 @@ enum dma_residue_granularity {
/**
* struct dma_slave_caps - expose capabilities of a slave channel only
* @src_bus_widths: mask of source bus widths the channel supports.
- * @src_addr_widths: legacy bit mask of source bus widths the channel supports.
* @dst_bus_widths: mask of destination bus widths the channel supports.
- * @dst_addr_widths: legacy bit mask of destination bus widths the channel
- * supports.
* @directions: bit mask of slave directions the channel supports.
* Since the enum dma_transfer_direction is not defined as bit flag for
* each type, the dma controller should set BIT(<TYPE>) and same
@@ -717,14 +714,8 @@ enum dma_residue_granularity {
* resubmitted multiple times
*/
struct dma_slave_caps {
- struct {
- dma_buswidth_mask_t src_bus_widths;
- u32 src_addr_widths;
- };
- struct {
- dma_buswidth_mask_t dst_bus_widths;
- u32 dst_addr_widths;
- };
+ dma_buswidth_mask_t src_bus_widths;
+ dma_buswidth_mask_t dst_bus_widths;
u32 directions;
u32 min_burst;
u32 max_burst;
--
2.56.0
^ permalink raw reply [flat|nested] 12+ messages in thread