Skip to content

Conversation

@SurajSonawane2415
Copy link
Contributor

@SurajSonawane2415 SurajSonawane2415 commented Jul 31, 2025

This PR is part of the GSoC 2025 Project: Add Virtual DAI Component to SOF and is based on SOF Issue #9349.

We introduce a new SOF_DAI_VIRTUAL type and its associated support to enable audio pipelines that do not rely on physical DAI hardware. This is useful in the following scenarios:

  • Debugging and rapid prototyping: Quickly create and test audio pipelines without needing actual hardware.
  • Software loopback preparation: Lays the groundwork for a memory-to-memory audio pipeline within SOF.

Virtual DAI Behavior

  • Playback: Acts like /dev/null — consumes data from the source and logs or discards it.
  • Capture: Acts like /dev/zero — generates dummy data (currently zero-filled) and passes it to the sink.

Key Changes

  • Added Virtual DAI support on i.MX8MP
    • Added a new DAI type SOF_DAI_VIRTUAL for rapid prototyping and software loopback.
    • Defined IPC config structure and updated Zephyr DAI mapping for Virtual DAI recognition.
    • Enabled software-based audio pipelines without requiring physical DAI hardware.
  • Topology support for i.MX8
    • Introduced a new topology file enabling Virtual DAI on i.MX8 platforms.
  • DMA configuration update
    • Integrated emul_dma to enable Virtual DAI functionality on i.MX8MP.
    • Allows playback/record flows in the absence of real hardware DMA.

Testing

  • Platform: i.MX8MP EVK with Virtual DAI topology.
  • Environment: Zephyr-based SOF build.
  • Results:
    • NoCodec card + Virtual DAI detected.
    • Probe, config, and removal flows working as expected.
    • All test cases executed successfully, all tests passed

Logs:

*** Booting Zephyr OS build 6e3ea447cbfb ***
[00:00:00.046,014] <inf> main: SOF on imx8mp_evk
[00:00:00.051,043] <inf> main: SOF initialized
[00:00:00.055,909] <inf> ipc: ipc: new cmd 0x90030000
[00:00:00.061,749] <inf> ipc: ipc: new cmd 0x30100000
[00:00:00.066,973] <inf> pipe: pipeline new pipe_id 1 priority 0
[00:00:00.074,086] <inf> ipc: ipc: new cmd 0x30010000
[00:00:00.079,312] <inf> ipc: comp new 0x924549b4U type 2 id 1.4
[00:00:00.085,734] <inf> dai_comp: DAIZ: dai_new()
[00:00:00.090,941] <inf> dai_comp: DAIZ: dai_common_new()
[00:00:00.096,757] <inf> virtual_dai: virtual_dai_config_get
[00:00:00.102,833] <inf> virtual_dai: virtual_dai_probe
[00:00:00.108,476] <inf> dma: sof_dma_get: dir=0, cap=0x0, dev=0x0, flags=0x0
[00:00:00.116,028] <inf> dma: dma_init
[00:00:00.120,198] <inf> dma: sof_dma_get(): Final selection -> ID 0, sref=1, busy=0
[00:00:00.129,043] <inf> ipc: ipc: new cmd 0x80010000
[00:00:00.134,266] <inf> ipc: ipc: dai 16.7 -> config 
[00:00:00.139,820] <inf> virtual_dai: virtual_dai_config_get
[00:00:00.145,896] <inf> virtual_dai: virtual_dai_probe
[00:00:00.151,539] <inf> dai_comp: DAIZ: dai_set_config()
[00:00:00.157,354] <inf> virtual_dai: virtual_dai_config_set
[00:00:00.163,429] <inf> virtual_dai: virtual_dai_remove
[00:00:00.169,163] <inf> ipc: ipc_comp_dai_config() dai type = 16 index = 7
[00:00:00.176,541] <inf> ipc: comp:1.4 dai_config() dai type = 16 index = 7 dd 0x92c05ee0
[00:00:00.185,132] <inf> dai_comp: DAIZ: dai_get_handshake()
[00:00:00.191,208] <inf> virtual_dai: virtual_dai_get_properties

Related PR & Commits

  • Zephyr PR: #95233 drivers: dai: Add virtual DAI driver and tests
    Includes Virtual DAI driver, DTS binding, Kconfig/CMake updates, and ztest-based API tests.

  • linux-imx PR: #30 ASoC: SOF: Add Virtual DAI support for i.MX8M
    Introduces SOF_DAI_VIRTUAL type and configuration, adds topology tokens, extends IPC3 parsing, and registers a Virtual DAI backend for i.MX8M. Enables prototyping and loopback pipelines without physical DAI hardware.

  • linux-imx nocodec feature commit: Enabled NoCodec support for the i.MX8M platform to allow pipeline testing without real codecs.
    Link: nocodec-commit

Future Work

  • Implement playback and record:
    • Playback: log output frames and discard.
    • Record: generate frames filled with zeroes.
      (Current limitation: To get aplay and arecord working, I replaced the real DMA with emul_dma for Virtual DAI. All functions execute, but data is not being copied in dma_emul_work_handler during playback.)

@sofci
Copy link
Collaborator

sofci commented Jul 31, 2025

Can one of the admins verify this patch?

reply test this please to run this test once

@SurajSonawane2415 SurajSonawane2415 force-pushed the feature/virtual-dai-support branch from 86aa27b to 7168fe9 Compare July 31, 2025 19:31
SOF_DAI_IMX_MICFIL, /**< i.MX MICFIL */
SOF_DAI_AMD_SW_AUDIO /**<Amd SW AUDIO */
SOF_DAI_AMD_SW_AUDIO, /**<Amd SW AUDIO */
SOF_DAI_VIRTUAL /**< Virtual DAI for testing/debugging*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a comma at the end to prepare for the next addition?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SurajSonawane2415 please add comma after last member e.g SOF_DAI_VIRTUAL,

src/lib/dai.c Outdated
d->dma_caps = SOF_DMA_CAP_HDA;
break;
case SOF_DAI_VIRTUAL:
break;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already handled by default below


# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s24le
PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4,
1, 0, 2, s24le,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why s24le? it should be s32le.

@@ -0,0 +1,72 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This topology seems to be quite generic, not specific to 8MP.
@dbaluta maybe you can test this on 8QM or 8QXP so we can be sure it works on other platforms as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SurajSonawane2415 since this is virtual it may be possible to create a ztest for this feature (in another PR), this would mean the feature would be tested by CI. i.e. a small pipeline with virtual loopback as a ztest.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgirdwood something like this zephyr/tests/drivers/i2s/i2s_api/src/test_i2s_loopback.c but for DAI, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fwiw, this would allow a higher level ztest where we could have a small loopback pipeline and test that we can copy A -> B, this would invoke a lot of pipeline logic/infra and could be easily run in CI. Depends if time permits for development though.

@SurajSonawane2415 SurajSonawane2415 force-pushed the feature/virtual-dai-support branch 2 times, most recently from 3b19886 to 9a09895 Compare August 4, 2025 02:22
Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

compatible = "nxp,sof-host-dma";
dma-channels = <32>;
#dma-cells = <0>;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SurajSonawane2415 we should not enable DAI_VIRTUAL and DMA_EMUL by default so please remove them from the config file.

zephyr/lib/dma.c Outdated
},
.z_dev = DEVICE_DT_GET(DT_NODELABEL(emul_dma)),
},
#else
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you should just add #endif.

@SurajSonawane2415 SurajSonawane2415 force-pushed the feature/virtual-dai-support branch 3 times, most recently from bc0bb10 to 2db9df2 Compare August 22, 2025 10:05

SectionVendorTokens."sof_virtual_tokens" {
SOF_TKN_DAI_VIRTUAL_MCLK_ID "2102"
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be SOF_TKN_DAI_VIRTUAL_MCLK_ID 22000 to allow sufficient space between members.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SurajSonawane2415 can you add the same token ID to topology 2 tokens too, just to make sure we have alignment.

@SurajSonawane2415 SurajSonawane2415 force-pushed the feature/virtual-dai-support branch from 2db9df2 to 52b5f8c Compare August 25, 2025 04:52

SectionVendorTokens."sof_virtual_tokens" {
SOF_TKN_DAI_VIRTUAL_MCLK_ID "2102"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SurajSonawane2415 can you add the same token ID to topology 2 tokens too, just to make sure we have alignment.

Comment on lines +499 to +501
#if CONFIG_DAI_VIRTUAL
dir = SOF_DMA_DIR_MEM_TO_MEM;
#else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anyway we can do this without the ifdef i.e. we may want to be able to combine virtual and real DAIs, you could add a flag to the dai structure to indicate virtual ?

Introduce a new DAI type, SOF_DAI_VIRTUAL, to enable rapid prototyping,
software loopback, and testing without requiring physical DAI hardware.

Define the IPC config structure for the virtual DAI and update the
Zephyr DAI mapping logic to recognize and configure this backend.
Enable virtual DAI for i.MX8MP to support software-based audio pipelines.

Signed-off-by: Suraj Sonawane <surajsonawane0215@gmail.com>
@SurajSonawane2415 SurajSonawane2415 force-pushed the feature/virtual-dai-support branch from 52b5f8c to 9441b0c Compare August 27, 2025 05:50
Add a new topology file for i.MX8 platforms that enables Virtual DAI
support, allowing software-based audio pipelines without physical DAI
hardware.

Signed-off-by: Suraj Sonawane <surajsonawane0215@gmail.com>
Add emul_dma configuration to enable Virtual DAI with memory-to-memory
DMA for software-based audio pipelines on i.MX8MP.

Signed-off-by: Suraj Sonawane <surajsonawane0215@gmail.com>
@SurajSonawane2415 SurajSonawane2415 force-pushed the feature/virtual-dai-support branch from 9441b0c to dace206 Compare August 27, 2025 06:09
@SurajSonawane2415 SurajSonawane2415 changed the title [RFC] dai: Add support for Virtual DAI for rapid prototyping and software loopback dai: Add support for Virtual DAI for rapid prototyping and software loopback Aug 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants