The device tree binding for the rpi_pico dma driver describes three
channel configuration flags (high-prio, byte swap and quiet irq) of
which only one (high-priority) is used in the driver.
This patch defines a set of macros to allow users to enable these flags
in the device tree dma channel specification, as described in the
binding, proposes a way to encode them into struct dma_config fields
that aren't used by the driver, and applies the configuration flags in
the config dma driver callback.
The main purpose of this change is to allow multiple word-sizes in
scenarios where byte swapping is required.
Signed-off-by: Ricardo Cañuelo Navarro <rcn@igalia.com>
When LV_Z_DRAW_PXP is enabled, the build requires the PXP driver
sources. Add it to the build.
Additionally, ensure `MCUX_PXP` is not enabled at the same time as
the PXP IRQ is required by both LVGL and the DMA driver resulting
in conflicts.
Signed-off-by: André Costa <andre_miguel_costa@hotmail.com>
If a transfer had completed but its interrupt had not been handled yet,
silabs_ldma_append_block() restarted the channel with the new descriptor
and cleared the pending interrupt. The completion of the previous block
was then never reported.
Link the new descriptor in this case as well. The interrupt handler
reports the completion and then loads the linked descriptor.
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
The interrupt handler cleared the CHDONE bit of a channel before
loading its linked descriptor with a read-modify-write of CHDONE,
which is shared by all channels. If another channel completed between
the read and the write, its done flag was lost, and
dma_get_status() then reported a non-zero remaining length for a
completed transfer.
Use the CHDONE_CLR register to clear only the flag of the channel
being handled.
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
STM32 series F2, F4 and F7 handle differently their channel number value
from other series. Since the channel number is not directly the field
value, the value from `struct dma_config->dma_slot` to `struct
DMA_InitTypeDef->Channel` needs to be translated.
While at it, correct the pre-processor condition in order to reflect
this and ease the review. Previous condition was confusing and hard for
interpretation.
Signed-off-by: Raphaël Gallais-Pou <raphael.gallais-pou@foss.st.com>
A burst length only turned bursts on, and 0 did not turn them off. On
the ESP32-S3 it now also sets the block size of PSRAM accesses (16, 32
or 64 bytes), which doubles PSRAM throughput at 64, and other lengths
are rejected there.
The GDMA writes PSRAM in whole aligned blocks, so an RX buffer in PSRAM
that does not start and end on a block boundary gets the largest block
size it is aligned to, down to the 16 bytes used before.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5.5
dma_reload() always reset the channel and rebuilt the descriptor list
from scratch, so a driver feeding a peripheral from a queue of buffers
had to let each transfer end, then reload and restart from its callback.
Between the last descriptor of one transfer and the first of the next
the peripheral is fed by its own FIFO alone, and the gap depends on the
interrupt latency. For the I2S TX FIFO of the ESP32-S3 that is about
1.5 ms of 16-bit stereo at 44.1 kHz, which Wi-Fi activity exceeds, so
every buffer boundary can glitch.
When a TX channel still has a transfer in flight, build the reloaded
buffer in the half of the descriptor list that transfer does not reach
into, link it behind the last descriptor and set the restart bit, so
that the GDMA goes on with it without stopping. At most two transfers
are in flight, and a third reload returns -EBUSY until one completes;
each one still ends with its own EOF callback. A buffer that does not
fit in half of the descriptors returns -ENOSPC, so that the caller can
fall back to a plain reload once the channel is idle. The chain state
is updated under the driver's lock, in the reload as in the EOF
interrupt. dma_start() on a channel that is already running leaves it
alone, so the usual reload-then-start pairing works in both cases. A
parked or stopped channel is reloaded as before. This is how
dma_mcux_edma.c queues a reload behind a running transfer, which
i2s_mcux_sai.c relies on.
Built for esp32s3_devkitc/esp32s3/procpu with samples/drivers/i2s/echo.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
Default DMA_InitTypeDef structure is different according to the DMA
version used. Reflect this in the comment of
dma_stm32_zcfg_to_halcfg().
While at it, fixes a field value.
Signed-off-by: Raphaël Gallais-Pou <raphael.gallais-pou@foss.st.com>
dma_reload() reset the channel but kept the events its previous transfer
had latched. One not handled yet, such as an RX EOF whose interrupt is
still pending, then completed the reloaded transfer as soon as it
started. Clear them, as dma_stop() does.
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The mcux_edma driver assigns pointers to and from uint32_t in several
places, which truncates on 64-bit hosts (AArch64) and produces
-Wpointer-to-int-cast / -Wint-to-pointer-cast warnings. On i.MX93 all
DMA-visible memory happens to live below 4 GiB so the truncation is
lossless today, but the pattern is unsafe on any future 64-bit NXP
SoC with DRAM above 4 GiB physical.
Route the conversions through uintptr_t so the compiler sees a
matching-width intermediate:
* Cast dma_block_config address fields through uintptr_t before
handing them to EDMA_PrepareTransfer as void *.
* Cast tcd (edma_tcd_t *) through uintptr_t before truncating to
uint32_t for comparison against hw_id, which comes from the 32-bit
EDMA_GetNextTCDAddress() hardware register.
* Cast the src/dst uint32_t arguments of edma_reload_dynamic through
uintptr_t before feeding them to EDMA_PrepareTransfer as void *.
No functional change on 32-bit targets; eliminates 9 build warnings
on nitrogen93_smarc/mimx9352/a55/nx611.
Assisted-by: Claude:claude-opus-4.7
Signed-off-by: Ryan Erickson <ryan.erickson@ezurio.com>
The MCUX eDMA v3 and v4 drivers program the DMA controller to read
transfer control descriptors (TCDs) and buffer chains directly from
memory without any cache-maintenance operations. On SoCs whose CPU
has a data cache and the DMA is not hardware cache-coherent (e.g.
i.MX93 A55), that produces stale reads and dropped writes at both
the TCD and the payload buffer, manifesting as random DMA misbehavior
or silent data corruption.
Add `imply NOCACHE_MEMORY if CPU_HAS_DCACHE` to DMA_MCUX_EDMA_V3 and
DMA_MCUX_EDMA_V4 so the kernel places DMA-visible regions in the
non-cacheable section by default. Users on cache-coherent SoCs can
still disable NOCACHE_MEMORY explicitly.
Assisted-by: Claude:claude-opus-4.7
Signed-off-by: Ryan Erickson <ryan.erickson@ezurio.com>
The LL_DMA_SetDestIncMode() function is wrongfully gated behind
`#ifdef GPDMA1` inside STM32CubeWBA v1.10.0's LL DMA header.
Since this condition is never satisfied on STM32WBA2x line SoCs,
which only contain an LPDMA, attempting to use the DMA driver fails
with a build error... even though the function SHOULD be available
since the underlying hardware feature does exist; in fact, the function
LL_DMA_GetDestIncMode() is not gated to GPDMA in that same header...
Implement the missing function by ourselves when the target is one of
the affected SoCs such that the driver can build, and redirect to the
original function on all other targets to prevent regressions. This
approach avoids need for a patch on the hal_stm32 side and an update
to zephyr.yml on the Zephyr side. This will be replaced after the
release with a proper patch on the HAL side.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
The STM32WBA2x SoC line contains only an LPDMA which doesn't support
the burst transfer feature. As temporary workaround to enable building
the DMA driver on this SoC line, add it to the same #ifdef which
prevented compilation of burst-related code on STM32C5 series for the
same reason.
This is temporary; a better approach shall replace this in the future.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
A memory-to-memory pair always selected the first ID of the M2M mask,
0 on the ESP32-S3, which is SPI2's. SPI2's DMA handshake then also
reached that pair and SPI2 TX ran dry.
Pick the highest ID no other channel selects. On the ESP32-S3 and
ESP32-C3 every ID of the mask is a real peripheral, and the ADC and
RMT drivers configure their channel on first use, so move a pair off
its ID when a peripheral channel is configured on it later. A pair in
the middle of a transfer selects its new ID at its next start, and a
spinlock keeps concurrent dma_config() calls from taking the same ID.
Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
An EOF leaves the channel running, and stopping it does not
discard the descriptors it has already prefetched or the events
it latched, so the next transfer inherited them and delivered
stale or truncated data.
Clear the channel where it is handed a new descriptor list, going
through the stop barrier so the reset takes the abort path an axi
channel needs. Doing it before the interrupts are enabled keeps a
callback from seeing a half-reset channel.
Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
On a soc with a write-back data cache the controller and the cpu
disagree about an rx buffer twice over.
Before the transfer the cpu still owns the buffer and the
controller may fill only part of it, so write the cached copy out
and drop it: memory then holds the cpu data and no stale line can
later be written over what the controller delivers.
After the transfer the cached copy is stale and must be dropped,
but the buffer rarely starts or ends on a cache line, so its two
edge lines are shared with data the cpu owns and keeps writing
while the transfer runs. Writing those lines back first would put
a stale copy of the buffer on top of the received data, and
dropping them whole would discard the cpu's writes. Save the
shared bytes, invalidate whole lines, and restore them.
Do this before every rx callback and not only on the end-of-frame
one: a consumer reading the buffer from a block callback would
otherwise see stale bytes.
Round to the widest line the build uses rather than to
CONFIG_DCACHE_LINE_SIZE, which holds the devicetree value and can
be narrower than the line the cache is programmed with: esp32s3
picks its data cache line at startup and esp32p4 keeps a second
level, and a range operation covers those whole.
Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
The controller writes the transferred length and the owner bit
back into the descriptor, so the cached copy the CPU reads is
stale once a transfer ends: on esp32p4 the length came back as
zero while the data had already landed in the buffer.
Where the SoC maps internal RAM through a non-cacheable alias,
read those fields through it, which leaves the CPU-owned fields
sharing the cache line untouched. Only esp32p4 has such an
alias, so elsewhere keep invalidating the descriptor.
Bound the alias to the internal RAM range rather than testing
esp_ptr_internal(), which also accepts regions that have no
alias.
Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Async UART API calls such as uart_tx_abort() are allowed from
the event callback, which runs in the GDMA interrupt, and they
read the channel state through dma_get_status(). Put get_status
in IRAM next to that interrupt handler and drop the logging on
its error paths.
While here, compare the status pointer against NULL explicitly.
Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
The rx status reads the transferred length from the prefetched
descriptor register, but the AHB instance on esp32p4 reports zero
there once the transfer has ended, so total_copied stayed zero
even though the data had been written to memory.
Read the successful-EOF descriptor register instead when the
prefetched one is unset. It still points at the last descriptor
the controller wrote back on every supported instance. That
register is a latch and keeps its value across a rearm, so take
it only while the descriptor it names is no longer owned by the
controller, or a new transfer would report the previous one's
byte count.
Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
channel_priority was ignored. Program it into the GDMA channel priority
registers, and reject values above what the hardware supports.
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Replace scripts/kconfig/hardened.csv with a distributed YAML database.
The CSV format could not carry any explanation for its recommendations,
had no validation (a malformed line was silently dropped), no notion of
profiles, no ownership story, and no way to extend it out of tree.
The database now lives where the code lives: the central
scripts/kconfig/hardening.yaml defines the hardening profiles (plus
rules for top-level Kconfig symbols), and per-subsystem hardening.yaml
fragments next to the relevant Kconfig files carry the rules, so each
rule is reviewed by the maintainers of the code it hardens. Every rule
has a required rationale and optional references, supports exact-value
and integer min/max recommendations (STACK_POINTER_RANDOM is now
'>=100' instead of '==100'), and belongs to a profile: 'base' (memory
protection and inherently insecure features) or 'strict' (extends base
with debug/observability feature removal). The default profile is
'strict', matching the rule set the CSV checked.
hardenconfig is restructured around a serializable HardeningReport
model so results can be consumed programmatically, and gains:
- a Rationale column in the report
- profile selection:
west build -t hardenconfig -- -DHARDENCONFIG_PROFILE=base
- HARDENCONFIG_SHOW_ALL to also list PASS/NA results
- HARDENCONFIG_STRICT to exit non-zero on failures, for CI use
- HARDENCONFIG_JSON to write machine-readable results, including which
database file each rule came from
- HARDENCONFIG_EXTRA_SOURCES to layer out-of-tree database files that
may add profiles/rules and override in-tree ones
The EXPERIMENTAL/DEPRECATED/NOT_SECURE marker symbol detection is
preserved unchanged.
Three CSV entries are intentionally not carried over because they were
redundant: BT_CONN_DISABLE_SECURITY and BT_OOB_DATA_FIXED can only be
enabled together with BT_TESTING, and TIMER_RANDOM_GENERATOR together
with TEST_RANDOM_GENERATOR, all of which the database already
recommends disabling for the same profiles.
Behavioral fix: the CSV's DEBUG_COREDUMP line used '=' instead of ','
and was silently ignored, so CONFIG_DEBUG_COREDUMP was never actually
checked; it now is.
Also add tabulate to requirements-base.txt: hardenconfig has always
imported it, but it was only pulled in via other requirements files.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Allow mismatch between source and destination size.
Mismatch can be used by peripherals that require 32-bit access,
but produce 16-bit value (e.g. ADC, DAC)
Signed-off-by: Adam BERLINGER <adam.berlinger@st.com>
dma_stm32_zcfg_to_halcfg() hardcoded MemBurst and PeriphBurst to single
transfers and ignored source_burst_length and dest_burst_length, so a
driver asking for a burst through the DMA API silently got none and had
to write the HAL fields itself after the call. Derive both from the
burst length and the data size instead.
Signed-off-by: Ibrahim Abdalkader <i.abdalkader@gmail.com>
The channel state validation in start computed -EINVAL but fell
through and started the transfer anyway, returning success. Bail
out like the channel range check above it.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Two-line copyright notices were wrapped in the SPDX "<text>...</text>"
construct, which is only valid in an SPDX document, not a file header.
Some notices did not have SPDX tags.
Remove the markers and tag the continuation line. Holder, year and
e-mail are left unchanged; only the syntax is fixed.
Signed-off-by: Wheeler Keith (ES ICW SW MTP EE) <Keith.Wheeler@infineon.com>
The XEC central DMA channel has no block-chain hardware: completion is
just MEM_ADDR reaching MEM_ADDR_END. Cache the dma_block_config chain
from configure() into a per-channel array (dma_xec_block[]) and program
only one block into hardware at a time. On each DONE, the ISR decides
whether to chain to the next cached block or terminate; cyclic wraps
back to block 0 instead of terminating after the last block.
Chaining reprograms the address registers from the ISR without tearing
down IENABLE/ACTV/GIRQ state, but per HW guidance for erratum
SCG_MR_22NM-131, a still-pending peripheral request can spontaneously
restart the channel the instant a raw reprogram makes MSA < MEA true
again, so dma_xec_chan_reprogram() forces the channel to HW idle via
ABORT (bounded to one unit-size AHB transfer) before rewriting
addresses.
Add DMA_MCHP_XEC_MAX_BLOCKS_PER_CHAN (default 1) to size the cached
block array; the default preserves today's single-block behavior and
RAM footprint bit-for-bit. reload() always re-arms a single buffer, so
it resets num_blocks/cur_block/cyclic to drop any chain left over from
a prior multi-block configure().
Signed-off-by: Manimaran A <manimaran.a@microchip.com>
Assisted-by: Claude:claude-opus-4-8
Introduce dma_xec_chan_reset() and use it from configure, reload and
stop to remove duplicated abort/clear sequences. Move channel
activation and interrupt enable from configure() to start(), so a
channel is armed only when a transfer actually begins.
Signed-off-by: Manimaran A <manimaran.a@microchip.com>
Derive pending_length from the memory end/start registers,
report total_copied as 0, and drop the now-unused counters.
Signed-off-by: Manimaran A <manimaran.a@microchip.com>
Assisted-by: Claude:claude-opus-4-7
Make the DMA driver API entry points follow the Zephyr contract and
validate input:
- config/reload/start: add xec_dma_chan_is_busy(), which requires both
the BUSY bit and a HW/SW flow-control run bit (BUSY alone can be set
without a transfer running), and route the -EBUSY guards through it.
- config: also reject zero-size blocks, half-complete callbacks,
mismatched handshake modes and invalid data sizes; drop the unused
block head/curr pointers.
- get_status: return -EIO on a latched bus error (hw_status is volatile).
- get_attribute: also report buffer address/size and copy alignment and
NULL-check the output.
- chan_filter: use enum dma_channel_filter and bounds-check the channel.
- stop: clear the GIRQ source latch to avoid a spurious pending interrupt.
Signed-off-by: Manimaran A <manimaran.a@microchip.com>
Assisted-by: Claude:claude-opus-4-8
Generate the per-channel ISRs and IRQ_CONNECT calls by iterating the
interrupt-names property instead of girqs, so the loop index aligns 1:1
with the interrupts entries, and look up the GIRQ enable from the config
by channel index. Mark interrupt-names required and name the mec172x DMA
channels chan0..chan15.
Signed-off-by: Manimaran A <manimaran.a@microchip.com>
The STM32MP13 DMA_InitTypeDef structure does not contain the Channel
member used by STM32 DMA V1 devices. It provides a Request member,
similar to the STM32H7 DMA HAL implementation.
Signed-off-by: Fabrice DJIATSA <fabrice.djiatsa-ext@st.com>
err is declared once outside the loop that walks the pending channels,
and the path without an error flag never clears it. When one interrupt
has several channels pending and a lower-numbered one carries an error,
every higher-numbered channel handled in the same pass gets that -EIO
in its callback although its own transfer succeeded.
The hardware keeps the error flags per channel, and the other drivers
that share one interrupt across channels compute the status inside the
loop: dma_silabs_ldma sets it per channel, dma_sam_xdmac reads its own
error register for each one.
The MIPI DBI PIO driver runs up to four channels on one device for its
split configurations, which is where this is reachable.
Signed-off-by: Hsiu-Chi Tsai <hctsai@linux.com>
Add Write-only mode where instead of copying from a real source, a
channel repeatedly writes a fixed pattern to the destination address.
Mode is selected via a new private channel_direction value
XILINX_ADMA_DIR_WRITE_ONLY.
Signed-off-by: Abin Joseph <abin.joseph@amd.com>
`pending_length` is supposed to be the "Pending length to be transferred
in bytes, HW specific", but the DMAC keeps track of a number of elements
remaning instead, and the driver returned this value verbatim.
Read the number of elements pending and multiply it by source data size
before returning it to comply with the API specification.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Fixes various issues with Kconfigs, including:
- Redundent `default n` on bools
- Not select deprecated on supposed deprecated symbols
- Using the wrong indentation
- Not having [DEPRECATED] in the prompt, or not having it at the
end
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit enables the new clock managers by switching the device
tree to use the new bindings. It also moves some initialization code
from the old clock manager to soc_early_init_hook() since some clocks
configuration needs to be done before the clock drivers are initialized.
Signed-off-by: Martin Hoff <martin.hoff@silabs.com>
GDMA_INLINK_STOP_CHn is a command strobe with no acknowledge, so a
channel can still be writing to the descriptor buffer after
dma_stop() has returned, and the caller then frees a buffer the DMA
overwrites. Reset the channel so the stop is observable, and clear
the events the abandoned transfer latched: the reset writes
conf0.in_rst and leaves int_raw set, while dma_reload() and
dma_start() do not clear.
An AXI channel cannot be reset mid-transaction, so every reset site
(configure, reload and stop) now goes through one helper that
aborts, waits for the reset to become available, resets, then
releases the abort (esp-idf 4393a0d0728b).
I have no ESP32-P4, so the AXI path is build-tested only.
Signed-off-by: Hsiu-Chi Tsai <hctsai@linux.com>
The DMA driver did not enable error interrupts, so the error
path in the interrupt handler was unreachable. Enable the
error interrupt and dispatch the error callback to the correct
channel if error_callback_dis isn't set.
Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
The new dma_stm32_zcfg_to_halcfg() relies heavily on default STM32
configuration. Document it in order not to loose the DMA consumer
drivers into wrong configuration.
Signed-off-by: Raphaël Gallais-Pou <raphael.gallais-pou@foss.st.com>
Add STM32U5 conversion from Zephyr dma_config into STM32 HAL DMA init
fields.
Translate direction, priority, burst length, address increment, data
width, and cyclic mode settings while preserving U5-specific linked-list
behavior.
This lets HAL-managed users use the common STM32 DMA helper on STM32U5
without open-coding the common init fields.
Assisted-by: Copilot:gpt-5.5
Signed-off-by: Raphaël Gallais-Pou <raphael.gallais-pou@foss.st.com>
Add BDMA-side conversion from Zephyr dma_config into STM32 HAL DMA init
fields for configurations that do not build the classic STM32 DMA v1/v2
helper.
Map direction, priority, address increment, data width, and mode values
so HAL-managed users can share the same DMA setup path on BDMA-only SoCs.
Assisted-by: Copilot:gpt-5.5
Signed-off-by: Raphaël Gallais-Pou <raphael.gallais-pou@foss.st.com>
Add a private STM32 DMA helper that converts Zephyr dma_config settings
into common STM32 HAL DMA_InitTypeDef fields.
int dma_stm32_zcfg_to_halcfg(const struct dma_config *zephyr_config,
DMA_InitTypeDef *hal_config);
Keep the helper as one exported implementation in the existing STM32 DMA
source and keep HAL-family differences local to the conversion flow.
Also build the helper for STM32U5 or BDMA-only configurations where the
classic DMA driver body is not enabled.
Assisted-by: Copilot:gpt-5.5
Signed-off-by: Raphaël Gallais-Pou <raphael.gallais-pou@foss.st.com>
Added pm_action suspend/resume/turn_on routine for DMA
Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Richard Mc Sweeney <Richard.McSweeney@infineon.com>
The PM policy lock was tracked by a single controller-wide flag, so when
two channel pairs ran memory-to-memory transfers at the same time, the
first one to finish released the lock while the other was still
streaming and the SoC could enter light sleep mid-transfer.
Track the lock with the per-pair flag that already exists, renamed to
pm_lock_held since it now only tells whether the pair holds the lock,
and let the PM subsystem count the nested requests, since its policy
locks are already reference counted. Taking the flag in the same helper
that takes the lock also prevents dma_esp32_start() from acquiring it
twice when both channels of a pair are started, and keeps the
test-and-clear atomic against a concurrent dma_esp32_stop() and RX EOF
interrupt.
Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
Some options from mcux_edma driver were enabled when other unrelated
drivers were enabled. Add a conditional to prevent that.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>