Repository navigation
Conversation
…atforms Platforms without host DMA (e.g. i.MX, where the DSP copies the host buffer) have no period interrupt, so nothing called snd_sof_pcm_period_elapsed() and playback relied on poll timeouts. Add SOF_IPC4_NOTIFY_HOST_PERIOD_ELAPSED (type 200), sent by the firmware host copier once per host period. The extension word holds the host gateway id, device * 2 + direction, from which the handler finds the substream to wake up, mirroring ipc3_period_elapsed(). Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
The IPC4 core assumes a bus-mastering host DMA that fills the ALSA buffer and link DMA position counters in fw_regs that report the stream position. i.MX DSPs have neither: the DSP copies the host buffer itself and reports progress through a byte counter. Add the pieces the core needs for such platforms: - a host_byte_cnt[] array in struct sof_ipc4_fw_registers, carved out of reserved space so existing offsets do not move - a host copier TLV with the physical address, size and period of the host PCM buffer, appended to the gateway attributes when the platform sets use_phy_address - a node index for SOF_DAI_IMX_SAI and acceptance in dai_config - a pcm_contiguous_buffer flag in snd_sof_dsp_ops to request a contiguous, coherent PCM buffer Nothing changes for platforms with host DMA. Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
…unter Platforms without link DMA have no link position counters in fw_regs and no get_dai_frame_counter op, so sof_ipc4_pcm_pointer() returned -EOPNOTSUPP and the stream position never moved. On such platforms the host byte counter already tracks how far the firmware has consumed or filled the host buffer, so use it directly as the stream position. Platforms with link DMA are not affected. Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
A DSP that reads the PCM buffer through a single physical address needs a contiguous, coherent buffer. With the default scatter-gather buffer it reads stale data. Add a pcm_contiguous_buffer flag to snd_sof_dsp_ops and allocate the buffer as SNDRV_DMA_TYPE_DEV when it is set. Platforms that do not set it are not affected. Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
i.MX has no IPC registers, so carry the 8-byte IPC4 header in an SRAM slot right before each mailbox payload and use the MU only as a doorbell. Replies and notifications both arrive through the request doorbell and are told apart by the SOF_IPC4_MSG_DIR bit. Add the IPC4 pieces to the common i.MX code: - imx_send_msg() and imx_handle_ipc4_msg() for the header slots - imx_get_mailbox_offset() and imx_get_window_offset() mapping the IPC4 windows onto the i.MX SRAM layout from chip info - imx_pcm_hw_params() setting the stream tag and buffer address, and imx_get_host_byte_counter() reading host_byte_cnt[] from fw_regs - imx_pre_fw_run() copying the image into DSP memory, since the generic IPC4 loader has no load_fw_to_dsp() - IMX_SOF_DEV_DESC_IPC4() advertising IPC3 and IPC4 with IPC3 as the default, so IPC4 is opt-in through the snd_sof.ipc_type parameter i.MX8MP is the first SoC using it. It also gets a core_shutdown op that stalls the HiFi4 before its clocks are cut, so a later reload works. Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Advertise IPC4 for the i.MX95 Cortex-M7 with IMX_SOF_DEV_DESC_IPC4() and add the IPC4 window offsets to the chip info. IPC3 stays the default. i.MX95 exposes the whole DSP address space through the single "sram" resource, so make imx_get_bar_index() fall back to the mailbox bar when no per-type region is mapped. Stop the M7 before setting its reset vector, since the system manager refuses that on a running LM. Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Both share the i.MX8MP mailbox layout, so add the same IPC4 window offsets to their chip info and switch the descriptors to IMX_SOF_DEV_DESC_IPC4(). IPC3 stays the default. Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Add the IPC4 window offsets to the i.MX8ULP chip info and switch the descriptor to IMX_SOF_DEV_DESC_IPC4(). The layout matches i.MX8MP apart from the larger 0x2800 debug window, which moves fw_regs to 0x804800. IPC3 stays the default. Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
IPC4 has no DAI_CONFIG message, so the SAI clock, format and TDM settings that IPC3 sends in struct sof_ipc_dai_config never reached the i.MX firmware and it had to hardcode them. Build the same struct from the BE DAI link hw_config, as sof_link_sai_load() does for IPC3, and append it to the DAI copier config_data as a SOF_IPC4_GTW_IMX_DAI_CONFIG_ID TLV right after the gateway attributes. The firmware applies it with dai_set_config(). Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
dbaluta
requested review from
bardliao,
kv2019i,
lgirdwood,
lyakh,
plbossart,
ranj063 and
ujfalusi
as code owners
November 16, 2026 10:02
There was a problem hiding this comment.
🟡 Changes recommended
Firmware loading and IPC4 mailbox handling can cause out-of-bounds reads and writes, with additional unresolved SAI configuration and PCM gateway-ID defects.
6 open issues
Limit IPC4 transfers to the 4088-byte mailbox payload · New Validate destination range against mapped BAR size · New Validate block source length before writing · New Map PCM gateway IDs to available host-counter slots · New Initialize and update SAI hardware-config selection · New Parse and preserve the SAI MCLK ID token · New
What changed in this PR
Introduces the Linux SOF changes for IPC4 on i.MX8-family and i.MX95 platforms, complementing the linked firmware work while retaining IPC3 as the default.
Changes:
- Adds IPC4 firmware profiles, image loading, and platform mailbox transport.
- Adds host-buffer and SAI configuration, shared byte counters, and DSP-driven period notifications.
- Supports contiguous PCM buffers and adjusts platform shutdown/reset handling.
| File | Description |
|---|---|
sound/soc/sof/sof-priv.h |
Adds a platform option for contiguous PCM buffers. |
sound/soc/sof/pcm.c |
Selects PCM buffer allocation using the platform option. |
sound/soc/sof/ipc4.c |
Handles DSP host-period notifications. |
sound/soc/sof/ipc4-topology.h |
Defines i.MX host-buffer and DAI configuration payloads. |
sound/soc/sof/ipc4-topology.c |
Builds host-buffer and SAI configuration for IPC4 copiers. |
sound/soc/sof/ipc4-pcm.c |
Supports position reporting from host byte counters alone. |
sound/soc/sof/ipc4-fw-reg.h |
Reserves shared-register space for host byte counters. |
sound/soc/sof/imx/Kconfig |
Enables IPC4 in the common i.MX SOF configuration. |
sound/soc/sof/imx/imx9.c |
Adds i.MX95 IPC4 setup and M7 reset-vector handling. |
sound/soc/sof/imx/imx8.c |
Adds IPC4 platform layouts and i.MX8M core shutdown. |
sound/soc/sof/imx/imx-common.h |
Defines IPC4 descriptors, mailbox offsets, and loader constants. |
sound/soc/sof/imx/imx-common.c |
Implements shared IPC4 transport, firmware loading, and PCM support. |
include/sound/sof/ipc4/header.h |
Defines the host-period notification identifier. |
Review effort: Balanced
Comment on lines
+176
to
+179
| if (msg_data->data_size) | ||
| sof_mailbox_write(sdev, sdev->host_box.offset, | ||
| msg_data->data_ptr, | ||
| msg_data->data_size); |
| case SOF_FW_BLK_TYPE_IRAM: | ||
| case SOF_FW_BLK_TYPE_DRAM: | ||
| case SOF_FW_BLK_TYPE_SRAM: | ||
| offset = block->offset; |
Comment on lines
+615
to
+626
| ret = snd_sof_dsp_block_write(sdev, block->type, offset, | ||
| (void *)(block + 1), | ||
| block->size); | ||
| if (ret < 0) { | ||
| dev_err(sdev->dev, | ||
| "failed to write block type %#x\n", | ||
| block->type); | ||
| return ret; | ||
| } | ||
|
|
||
| if (remaining < block->size) | ||
| return -EINVAL; |
| struct snd_sof_platform_stream_params *platform_params) | ||
| { | ||
| if (sdev->pdata->ipc_type == SOF_IPC_TYPE_4) { | ||
| platform_params->stream_tag = substream->pcm->device * 2 + substream->stream + 1; |
|
|
||
| found = false; | ||
| for (i = 0; i < slink->num_hw_configs; i++) { | ||
| if (dai->current_config == le32_to_cpu(slink->hw_configs[i].id)) { |
| return -EINVAL; | ||
| } | ||
|
|
||
| memset(cfg, 0, sizeof(*cfg)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


This is the Linux changes necessary to add IPC4 support for i.MX platforms.
Some changes might be needed after moving the mailbox stuff from SOF to Zephyr.
SOF changes are here: thesofproject/sof#11435