Skip to content
42 changes: 21 additions & 21 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ __cold void dai_common_free(struct dai_data *dd)
dai_group_put(dd->group);

if (dd->chan) {
dma_release_channel(dd->dma->z_dev, dd->chan->index);
sof_dma_release_channel(dd->dma, dd->chan->index);
dd->chan->dev_data = NULL;
}

Expand Down Expand Up @@ -798,7 +798,7 @@ static int dai_set_sg_config(struct dai_data *dd, struct comp_dev *dev, uint32_t

comp_dbg(dev, "fifo 0x%x", fifo);

err = dma_get_attribute(dd->dma->z_dev, DMA_ATTR_MAX_BLOCK_COUNT, &max_block_count);
err = sof_dma_get_attribute(dd->dma, DMA_ATTR_MAX_BLOCK_COUNT, &max_block_count);
if (err < 0) {
comp_err(dev, "can't get max block count, err = %d",
err);
Expand Down Expand Up @@ -954,14 +954,14 @@ static int dai_set_dma_buffer(struct dai_data *dd, struct comp_dev *dev,
return -EINVAL;
}

err = dma_get_attribute(dd->dma->z_dev, DMA_ATTR_BUFFER_ADDRESS_ALIGNMENT, &addr_align);
err = sof_dma_get_attribute(dd->dma, DMA_ATTR_BUFFER_ADDRESS_ALIGNMENT, &addr_align);
if (err < 0) {
comp_err(dev, "can't get dma buffer addr align, err = %d",
err);
return err;
}

err = dma_get_attribute(dd->dma->z_dev, DMA_ATTR_BUFFER_SIZE_ALIGNMENT, &align);
err = sof_dma_get_attribute(dd->dma, DMA_ATTR_BUFFER_SIZE_ALIGNMENT, &align);
if (err < 0 || !align) {
comp_err(dev, "no valid dma align, err = %d, align = %u",
err, align);
Expand Down Expand Up @@ -1155,7 +1155,7 @@ int dai_common_config_prepare(struct dai_data *dd, struct comp_dev *dev)
}

/* get DMA channel */
channel = dma_request_channel(dd->dma->z_dev, &channel);
channel = sof_dma_request_channel(dd->dma, channel);
if (channel < 0) {
comp_err(dev, "dma_request_channel() failed");
dd->chan = NULL;
Expand Down Expand Up @@ -1199,7 +1199,7 @@ int dai_common_prepare(struct dai_data *dd, struct comp_dev *dev)
return 0;
}

ret = dma_config(dd->chan->dma->z_dev, dd->chan->index, dd->z_config);
ret = sof_dma_config(dd->chan->dma, dd->chan->index, dd->z_config);
if (ret < 0)
comp_set_state(dev, COMP_TRIGGER_RESET);

Expand Down Expand Up @@ -1286,7 +1286,7 @@ static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev,

/* only start the DAI if we are not XRUN handling */
if (dd->xrun == 0) {
ret = dma_start(dd->chan->dma->z_dev, dd->chan->index);
ret = sof_dma_start(dd->chan->dma, dd->chan->index);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -1324,16 +1324,16 @@ static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev,
/* only start the DAI if we are not XRUN handling */
if (dd->xrun == 0) {
/* recover valid start position */
ret = dma_stop(dd->chan->dma->z_dev, dd->chan->index);
ret = sof_dma_stop(dd->chan->dma, dd->chan->index);
if (ret < 0)
return ret;

/* dma_config needed after stop */
ret = dma_config(dd->chan->dma->z_dev, dd->chan->index, dd->z_config);
ret = sof_dma_config(dd->chan->dma, dd->chan->index, dd->z_config);
if (ret < 0)
return ret;

ret = dma_start(dd->chan->dma->z_dev, dd->chan->index);
ret = sof_dma_start(dd->chan->dma, dd->chan->index);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -1361,11 +1361,11 @@ static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev,
* as soon as possible.
*/
#if CONFIG_COMP_DAI_STOP_TRIGGER_ORDER_REVERSE
ret = dma_stop(dd->chan->dma->z_dev, dd->chan->index);
ret = sof_dma_stop(dd->chan->dma, dd->chan->index);
dai_trigger_op(dd->dai, cmd, dev->direction);
#else
dai_trigger_op(dd->dai, cmd, dev->direction);
ret = dma_stop(dd->chan->dma->z_dev, dd->chan->index);
ret = sof_dma_stop(dd->chan->dma, dd->chan->index);
if (ret) {
comp_warn(dev, "dma was stopped earlier");
ret = 0;
Expand All @@ -1375,11 +1375,11 @@ static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev,
case COMP_TRIGGER_PAUSE:
comp_dbg(dev, "PAUSE");
#if CONFIG_COMP_DAI_STOP_TRIGGER_ORDER_REVERSE
ret = dma_suspend(dd->chan->dma->z_dev, dd->chan->index);
ret = sof_dma_suspend(dd->chan->dma, dd->chan->index);
dai_trigger_op(dd->dai, cmd, dev->direction);
#else
dai_trigger_op(dd->dai, cmd, dev->direction);
ret = dma_suspend(dd->chan->dma->z_dev, dd->chan->index);
ret = sof_dma_suspend(dd->chan->dma, dd->chan->index);
#endif
break;
case COMP_TRIGGER_PRE_START:
Expand Down Expand Up @@ -1471,7 +1471,7 @@ static int dai_comp_trigger(struct comp_dev *dev, int cmd)
/* get status from dma and check for xrun */
static int dai_get_status(struct comp_dev *dev, struct dai_data *dd, struct dma_status *stat)
{
int ret = dma_get_status(dd->chan->dma->z_dev, dd->chan->index, stat);
int ret = sof_dma_get_status(dd->chan->dma, dd->chan->index, stat);
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
if (ret == -EPIPE && !dd->xrun_notification_sent) {
struct ipc_msg *notify = ipc_notification_pool_get(IPC4_RESOURCE_EVENT_SIZE);
Expand Down Expand Up @@ -1582,7 +1582,7 @@ int dai_zephyr_multi_endpoint_copy(struct dai_data **dd, struct comp_dev *dev,
#endif

for (i = 0; i < num_endpoints; i++) {
ret = dma_reload(dd[i]->chan->dma->z_dev, dd[i]->chan->index, 0, 0, 0);
ret = sof_dma_reload(dd[i]->chan->dma, dd[i]->chan->index, 0);
if (ret < 0) {
dai_report_xrun(dd[i], dev, 0);
return ret;
Expand All @@ -1608,10 +1608,10 @@ int dai_zephyr_multi_endpoint_copy(struct dai_data **dd, struct comp_dev *dev,

status = dai_dma_multi_endpoint_cb(dd[i], dev, frames, multi_endpoint_buffer);
if (status == SOF_DMA_CB_STATUS_END)
dma_stop(dd[i]->chan->dma->z_dev, dd[i]->chan->index);
sof_dma_stop(dd[i]->chan->dma, dd[i]->chan->index);

copy_bytes = frames * audio_stream_frame_bytes(&dd[i]->dma_buffer->stream);
ret = dma_reload(dd[i]->chan->dma->z_dev, dd[i]->chan->index, 0, 0, copy_bytes);
ret = sof_dma_reload(dd[i]->chan->dma, dd[i]->chan->index, copy_bytes);
if (ret < 0) {
dai_report_xrun(dd[i], dev, copy_bytes);
return ret;
Expand Down Expand Up @@ -1800,7 +1800,7 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
comp_warn(dev, "nothing to copy, src_frames: %u, sink_frames: %u",
src_frames, sink_frames);
#endif
dma_reload(dd->chan->dma->z_dev, dd->chan->index, 0, 0, 0);
sof_dma_reload(dd->chan->dma, dd->chan->index, 0);
return 0;
}

Expand All @@ -1810,9 +1810,9 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
comp_warn(dev, "dai trigger copy failed");

if (dai_dma_cb(dd, dev, copy_bytes, converter) == SOF_DMA_CB_STATUS_END)
dma_stop(dd->chan->dma->z_dev, dd->chan->index);
sof_dma_stop(dd->chan->dma, dd->chan->index);

ret = dma_reload(dd->chan->dma->z_dev, dd->chan->index, 0, 0, copy_bytes);
ret = sof_dma_reload(dd->chan->dma, dd->chan->index, copy_bytes);
if (ret < 0) {
dai_report_xrun(dd, dev, copy_bytes);
return ret;
Expand Down
4 changes: 2 additions & 2 deletions src/include/ipc4/gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ struct ipc4_ipc_gateway_config_blob {
uint32_t buffer_size;

/**< Flags */
union flags {
struct bits {
union {
struct {
/**< Activates high threshold notification */
/*!
* Indicates whether notification should be sent to the host
Expand Down
9 changes: 4 additions & 5 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,10 @@ if(NOT DEFINED PLATFORM)
endif()
zephyr_include_directories(${SOF_PLATFORM_PATH}/${PLATFORM}/include)

zephyr_library_sources_ifdef(CONFIG_USERSPACE
syscall/sof_dma.c
)

zephyr_syscall_header(include/sof/lib/sof_dma.h)
if(CONFIG_SOF_USERSPACE_INTERFACE_DMA)
zephyr_library_sources(syscall/sof_dma.c)
zephyr_syscall_header(include/sof/lib/sof_dma.h)
endif()

# Mandatory Files used on all platforms.
# Commented files will be added/removed as integration dictates.
Expand Down
24 changes: 24 additions & 0 deletions zephyr/include/sof/lib/sof_dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ __syscall int sof_dma_get_status(struct sof_dma *dma, uint32_t channel, struct d

__syscall int sof_dma_reload(struct sof_dma *dma, uint32_t channel, size_t size);

__syscall int sof_dma_suspend(struct sof_dma *dma, uint32_t channel);

__syscall int sof_dma_resume(struct sof_dma *dma, uint32_t channel);

static inline int z_impl_sof_dma_get_attribute(struct sof_dma *dma, uint32_t type, uint32_t *value)
{
return dma_get_attribute(dma->z_dev, type, value);
Expand Down Expand Up @@ -95,6 +99,16 @@ static inline int z_impl_sof_dma_reload(struct sof_dma *dma, uint32_t channel, s
return dma_reload(dma->z_dev, channel, 0, 0, size);
}

static inline int z_impl_sof_dma_suspend(struct sof_dma *dma, uint32_t channel)
{
return dma_suspend(dma->z_dev, channel);
}

static inline int z_impl_sof_dma_resume(struct sof_dma *dma, uint32_t channel)
{
return dma_resume(dma->z_dev, channel);
}

#ifdef CONFIG_SOF_USERSPACE_INTERFACE_DMA

/* include definitions from generated file */
Expand Down Expand Up @@ -164,6 +178,16 @@ static inline int sof_dma_reload(struct sof_dma *dma, uint32_t channel, size_t s
return z_impl_sof_dma_reload(dma, channel, size);
}

static inline int sof_dma_suspend(struct sof_dma *dma, uint32_t channel)
{
return z_impl_sof_dma_suspend(dma, channel);
}

static inline int sof_dma_resume(struct sof_dma *dma, uint32_t channel)
{
return z_impl_sof_dma_resume(dma, channel);
}

#endif /* CONFIG_SOF_USERSPACE_INTERFACE_DMA */

#endif
16 changes: 16 additions & 0 deletions zephyr/syscall/sof_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,20 @@ static inline int z_vrfy_sof_dma_reload(struct sof_dma *dma, uint32_t channel, s
}
#include <zephyr/syscalls/sof_dma_reload_mrsh.c>

static inline int z_vrfy_sof_dma_suspend(struct sof_dma *dma, uint32_t channel)
{
K_OOPS(!sof_dma_is_valid(dma));

return z_impl_sof_dma_suspend(dma, channel);
}
#include <zephyr/syscalls/sof_dma_suspend_mrsh.c>

static inline int z_vrfy_sof_dma_resume(struct sof_dma *dma, uint32_t channel)
{
K_OOPS(!sof_dma_is_valid(dma));

return z_impl_sof_dma_resume(dma, channel);
}
#include <zephyr/syscalls/sof_dma_resume_mrsh.c>

#endif /* CONFIG_SOF_USERSPACE_INTERFACE_DMA */
7 changes: 5 additions & 2 deletions zephyr/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ if (CONFIG_SOF_BOOT_TEST)
)
endif()

if (CONFIG_SOF_BOOT_TEST_STANDALONE)
if (CONFIG_DT_HAS_INTEL_ADSP_HDA_HOST_IN_ENABLED AND CONFIG_SOF_USERSPACE_INTERFACE_DMA)
if (CONFIG_SOF_BOOT_TEST_STANDALONE AND CONFIG_SOF_USERSPACE_INTERFACE_DMA)
if (CONFIG_DT_HAS_INTEL_ADSP_HDA_HOST_IN_ENABLED)
zephyr_library_sources(userspace/test_intel_hda_dma.c)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it safe to run this test when userspace is active without CONFIG_SOF_USERSPACE_INTERFACE_DMA?
Was the change from test test_intel_hda_dma.c to test test_intel_ssp_dai.c intentional?
Shouldn't both tests be executed in this scenario?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

CONFIG_SOF_USERSPACE_INTERFACE_DMA depends on CONFIG_USERSPACE, so this is safe, but indeed the logic within the if case is not correct. This was messed up when I did the rebase, let me rework this in V2. Thanks!

endif()
if (CONFIG_DT_HAS_INTEL_ADSP_HDA_SSP_CAP_ENABLED)
zephyr_library_sources(userspace/test_intel_ssp_dai.c)
endif()
endif()
19 changes: 14 additions & 5 deletions zephyr/test/userspace/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
intel_hda_dma test
------------------
User-space interface tests for Intel ADSP
-----------------------------------------

This is a standalone test to exercise the Intel HDA DMA host interface
from a userspace Zephyr thread.
Build with ("ptl" example):
This folder contains multiple tests to exercise Intel DSP device interfaces
from a user-space Zephyr thread.

Available tests:
- test_intel_hda_dma.c
- Test Intel HDA DMA host interface from a userspace
Zephyr thread. Use cavstool.py as host runner.
- test_intel_ssp_dai.c
- Test Zephyr DAI interface, together with SOF DMA
wrapper from a user thread. Mimics the call flows done in
sof/src/audio/dai-zephyr.c. Use cavstool.py as host runner.

Building for Intel Panther Lake:
./scripts/xtensa-build-zephyr.py --cmake-args=-DCONFIG_SOF_BOOT_TEST_STANDALONE=y \
--cmake-args=-DCONFIG_SOF_USERSPACE_INTERFACE_DMA=y \
-o app/overlays/ptl/userspace_overlay.conf -o app/winconsole_overlay.conf ptl
Expand Down
3 changes: 2 additions & 1 deletion zephyr/test/userspace/test_intel_hda_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static void intel_hda_dma_user(void *p1, void *p2, void *p3)
LOG_INF("configure DMA channel");

channel = sof_dma_request_channel(dma, TEST_CHANNEL);
zassert_equal(channel, TEST_CHANNEL);
LOG_INF("sof_dma_request_channel: ret %d", channel);

err = sof_dma_get_attribute(dma, DMA_ATTR_BUFFER_ADDRESS_ALIGNMENT,
Expand Down Expand Up @@ -234,7 +235,7 @@ ZTEST_SUITE(userspace_intel_hda_dma, NULL, NULL, NULL, NULL, NULL);
*/
static int run_tests(void)
{
ztest_run_all(NULL, false, 1, 1);
ztest_run_test_suite(userspace_intel_hda_dma, false, 1, 1, NULL);
return 0;
}

Expand Down
Loading
Loading