diff --git a/app/boards/acp_6_0_adsp.conf b/app/boards/acp_6_0_adsp.conf index 2e4332e31dcd..a7cb8a9fc70c 100644 --- a/app/boards/acp_6_0_adsp.conf +++ b/app/boards/acp_6_0_adsp.conf @@ -6,5 +6,4 @@ CONFIG_DYNAMIC_INTERRUPTS=y CONFIG_SHARED_INTERRUPTS=n CONFIG_ZEPHYR_LOG=n CONFIG_DMA=y -CONFIG_ZEPHYR_NATIVE_DRIVERS=n CONFIG_AMS=n diff --git a/app/boards/imx8mp_evk_mimx8ml8_adsp.conf b/app/boards/imx8mp_evk_mimx8ml8_adsp.conf index da9e56d759a4..e12c74b28446 100644 --- a/app/boards/imx8mp_evk_mimx8ml8_adsp.conf +++ b/app/boards/imx8mp_evk_mimx8ml8_adsp.conf @@ -7,6 +7,5 @@ CONFIG_DMA_NXP_SDMA=y CONFIG_DAI_NXP_MICFIL=y CONFIG_TRACE=n CONFIG_SHARED_INTERRUPTS=y -CONFIG_ZEPHYR_NATIVE_DRIVERS=y CONFIG_SAI_HAS_MCLK_CONFIG_OPTION=y CONFIG_CLOCK_CONTROL_FIXED_RATE_CLOCK=y diff --git a/app/boards/imx8qm_mek_mimx8qm6_adsp.conf b/app/boards/imx8qm_mek_mimx8qm6_adsp.conf index 6c8eb26b6e9a..af6804f0f8f2 100644 --- a/app/boards/imx8qm_mek_mimx8qm6_adsp.conf +++ b/app/boards/imx8qm_mek_mimx8qm6_adsp.conf @@ -5,4 +5,4 @@ CONFIG_KPB_FORCE_COPY_TYPE_NORMAL=n CONFIG_DMA=y CONFIG_DMA_NXP_EDMA_ENABLE_HALFMAJOR_IRQ=y CONFIG_SHARED_INTERRUPTS=y -CONFIG_ZEPHYR_NATIVE_DRIVERS=y + diff --git a/app/boards/imx8qxp_mek_mimx8qx6_adsp.conf b/app/boards/imx8qxp_mek_mimx8qx6_adsp.conf index e6b3ce395c39..43fb1077fcac 100644 --- a/app/boards/imx8qxp_mek_mimx8qx6_adsp.conf +++ b/app/boards/imx8qxp_mek_mimx8qx6_adsp.conf @@ -5,4 +5,4 @@ CONFIG_KPB_FORCE_COPY_TYPE_NORMAL=n CONFIG_DMA=y CONFIG_DMA_NXP_EDMA_ENABLE_HALFMAJOR_IRQ=y CONFIG_SHARED_INTERRUPTS=y -CONFIG_ZEPHYR_NATIVE_DRIVERS=y + diff --git a/app/boards/imx8ulp_evk_mimx8ud7_adsp.conf b/app/boards/imx8ulp_evk_mimx8ud7_adsp.conf index 5df4c87d3c18..1c8e4e8e65d2 100644 --- a/app/boards/imx8ulp_evk_mimx8ud7_adsp.conf +++ b/app/boards/imx8ulp_evk_mimx8ud7_adsp.conf @@ -11,4 +11,3 @@ CONFIG_DMA_NXP_EDMA_ENABLE_HALFMAJOR_IRQ=y # from DAI bespoke configuration or DTS. CONFIG_SAI_FIFO_WORD_SIZE=2 -CONFIG_ZEPHYR_NATIVE_DRIVERS=y diff --git a/app/boards/imx93_evk_mimx9352_a55.conf b/app/boards/imx93_evk_mimx9352_a55.conf index 7c0667da66b9..3682990879bb 100644 --- a/app/boards/imx93_evk_mimx9352_a55.conf +++ b/app/boards/imx93_evk_mimx9352_a55.conf @@ -26,4 +26,3 @@ CONFIG_DMA_NXP_EDMA_ENABLE_HALFMAJOR_IRQ=y # channels. CONFIG_SHARED_INTERRUPTS=y -CONFIG_ZEPHYR_NATIVE_DRIVERS=y diff --git a/app/boards/imx95_evk_mimx9596_m7_ddr.conf b/app/boards/imx95_evk_mimx9596_m7_ddr.conf index aec33d7c7e91..8e13b91fb93d 100644 --- a/app/boards/imx95_evk_mimx9596_m7_ddr.conf +++ b/app/boards/imx95_evk_mimx9596_m7_ddr.conf @@ -1,5 +1,4 @@ CONFIG_DYNAMIC_INTERRUPTS=y -CONFIG_ZEPHYR_NATIVE_DRIVERS=y CONFIG_IMX95=y CONFIG_SAI_HAS_MCLK_CONFIG_OPTION=y diff --git a/app/boards/intel_adsp_ace15_mtpm.conf b/app/boards/intel_adsp_ace15_mtpm.conf index 64661f10ab3c..777aa9cb3b81 100644 --- a/app/boards/intel_adsp_ace15_mtpm.conf +++ b/app/boards/intel_adsp_ace15_mtpm.conf @@ -54,7 +54,6 @@ CONFIG_PROBE_DMA_MAX=2 CONFIG_SOF_TELEMETRY=y CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS=y CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS=y -CONFIG_ZEPHYR_NATIVE_DRIVERS=y CONFIG_ZEPHYR_DP_SCHEDULER=y CONFIG_ZEPHYR_TWB_SCHEDULER=y CONFIG_COLD_STORE_EXECUTE_DRAM=y diff --git a/app/boards/intel_adsp_ace20_lnl.conf b/app/boards/intel_adsp_ace20_lnl.conf index 1c47e5027a1d..004e59dcd8f5 100644 --- a/app/boards/intel_adsp_ace20_lnl.conf +++ b/app/boards/intel_adsp_ace20_lnl.conf @@ -43,7 +43,6 @@ CONFIG_SOF_TELEMETRY=y CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS=y CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS=y CONFIG_ZEPHYR_DP_SCHEDULER=y -CONFIG_ZEPHYR_NATIVE_DRIVERS=y CONFIG_COLD_STORE_EXECUTE_DRAM=y # SOF / loadable modules diff --git a/app/boards/intel_adsp_ace30_ptl.conf b/app/boards/intel_adsp_ace30_ptl.conf index 0e12f23a8b93..09f3f74adcd8 100644 --- a/app/boards/intel_adsp_ace30_ptl.conf +++ b/app/boards/intel_adsp_ace30_ptl.conf @@ -41,7 +41,6 @@ CONFIG_SOF_TELEMETRY=y CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS=y CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS=y CONFIG_ZEPHYR_DP_SCHEDULER=y -CONFIG_ZEPHYR_NATIVE_DRIVERS=y CONFIG_COLD_STORE_EXECUTE_DRAM=y # SOF / loadable modules diff --git a/app/boards/intel_adsp_ace30_ptl_sim.conf b/app/boards/intel_adsp_ace30_ptl_sim.conf index ef3f717f9082..18f3b9f3ea70 100644 --- a/app/boards/intel_adsp_ace30_ptl_sim.conf +++ b/app/boards/intel_adsp_ace30_ptl_sim.conf @@ -11,7 +11,6 @@ CONFIG_COMP_SRC_IPC4_FULL_MATRIX=y CONFIG_PM=n # enable Zephyr drivers -CONFIG_ZEPHYR_NATIVE_DRIVERS=y CONFIG_DAI=y CONFIG_DAI_INIT_PRIORITY=70 CONFIG_DAI_INTEL_DMIC=y diff --git a/app/boards/intel_adsp_ace30_wcl.conf b/app/boards/intel_adsp_ace30_wcl.conf index 8da2738668a0..3b10ce241398 100644 --- a/app/boards/intel_adsp_ace30_wcl.conf +++ b/app/boards/intel_adsp_ace30_wcl.conf @@ -30,7 +30,6 @@ CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL=n CONFIG_PROBE=y CONFIG_PROBE_DMA_MAX=2 CONFIG_ZEPHYR_DP_SCHEDULER=y -CONFIG_ZEPHYR_NATIVE_DRIVERS=y CONFIG_COLD_STORE_EXECUTE_DRAM=y # SOF / loadable modules diff --git a/app/boards/intel_adsp_ace30_wcl_sim.conf b/app/boards/intel_adsp_ace30_wcl_sim.conf index 64cfb22acd27..51fdb0671705 100644 --- a/app/boards/intel_adsp_ace30_wcl_sim.conf +++ b/app/boards/intel_adsp_ace30_wcl_sim.conf @@ -11,7 +11,6 @@ CONFIG_COMP_SRC_IPC4_FULL_MATRIX=y CONFIG_PM=n # enable Zephyr drivers -CONFIG_ZEPHYR_NATIVE_DRIVERS=y CONFIG_DAI=y CONFIG_DAI_INIT_PRIORITY=70 CONFIG_DAI_INTEL_DMIC=y diff --git a/app/boards/intel_adsp_cavs25.conf b/app/boards/intel_adsp_cavs25.conf index 3a0857ea2223..6155f1e9843f 100644 --- a/app/boards/intel_adsp_cavs25.conf +++ b/app/boards/intel_adsp_cavs25.conf @@ -36,7 +36,6 @@ CONFIG_PCM_CONVERTER_FORMAT_FLOAT=y CONFIG_AMS=y CONFIG_LP_MEMORY_BANKS=1 CONFIG_HP_MEMORY_BANKS=30 -CONFIG_ZEPHYR_NATIVE_DRIVERS=y # SOF / loadable modules CONFIG_INTEL_MODULES=y diff --git a/app/boards/intel_adsp_cavs25_tgph.conf b/app/boards/intel_adsp_cavs25_tgph.conf index 6ef138429bdf..85049e28a252 100644 --- a/app/boards/intel_adsp_cavs25_tgph.conf +++ b/app/boards/intel_adsp_cavs25_tgph.conf @@ -35,7 +35,6 @@ CONFIG_PCM_CONVERTER_FORMAT_FLOAT=y # SOF / infrastructure CONFIG_LP_MEMORY_BANKS=1 CONFIG_HP_MEMORY_BANKS=30 -CONFIG_ZEPHYR_NATIVE_DRIVERS=y # SOF / loadable modules CONFIG_INTEL_MODULES=y diff --git a/app/boards/native_sim_libfuzzer.conf b/app/boards/native_sim_libfuzzer.conf index ece1e35845c9..8637959908b4 100644 --- a/app/boards/native_sim_libfuzzer.conf +++ b/app/boards/native_sim_libfuzzer.conf @@ -5,7 +5,6 @@ CONFIG_ASSERT=y CONFIG_EXCEPTION_DEBUG=y CONFIG_ARCH_POSIX_TRAP_ON_FATAL=y CONFIG_SYS_HEAP_BIG_ONLY=y -CONFIG_ZEPHYR_NATIVE_DRIVERS=y CONFIG_ARCH_POSIX_LIBFUZZER=y CONFIG_ZEPHYR_POSIX_FUZZ_TICKS=100 CONFIG_ZEPHYR_LOG=n diff --git a/src/audio/CMakeLists.txt b/src/audio/CMakeLists.txt index 0a4a78d53ca8..ad588fc16255 100644 --- a/src/audio/CMakeLists.txt +++ b/src/audio/CMakeLists.txt @@ -113,13 +113,10 @@ if(NOT CONFIG_COMP_MODULE_SHARED_LIBRARY_BUILD) if(CONFIG_INTEL_ADSP_MIC_PRIVACY) add_subdirectory(mic_privacy_manager) endif() - if(CONFIG_ZEPHYR_NATIVE_DRIVERS) - list(APPEND base_files host-zephyr.c) - sof_list_append_ifdef(CONFIG_COMP_DAI base_files dai-zephyr.c) - else() - list(APPEND base_files host-legacy.c) - sof_list_append_ifdef(CONFIG_COMP_DAI base_files dai-legacy.c) - endif() + + list(APPEND base_files host-zephyr.c) + sof_list_append_ifdef(CONFIG_COMP_DAI base_files dai-zephyr.c) + if(CONFIG_COMP_TEMPLATE_COMP) add_subdirectory(template_comp) endif() diff --git a/src/audio/asrc/asrc.c b/src/audio/asrc/asrc.c index e8106d5112c9..3413d76b4b2b 100644 --- a/src/audio/asrc/asrc.c +++ b/src/audio/asrc/asrc.c @@ -713,11 +713,7 @@ static int asrc_prepare(struct processing_module *mod, static int asrc_control_loop(struct comp_dev *dev, struct comp_data *cd) { -#if CONFIG_ZEPHYR_NATIVE_DRIVERS struct dai_ts_data tsd; -#else - struct timestamp_data tsd; -#endif int64_t tmp; int32_t delta_sample; int32_t delta_ts; diff --git a/src/audio/asrc/asrc.h b/src/audio/asrc/asrc.h index 1c86a2cf757e..59cc6e3d9c8c 100644 --- a/src/audio/asrc/asrc.h +++ b/src/audio/asrc/asrc.h @@ -64,11 +64,8 @@ static inline bool asrc_get_asynchronous_mode(const struct ipc_config_asrc *ipc_ #endif -#if CONFIG_ZEPHYR_NATIVE_DRIVERS int asrc_dai_get_timestamp(struct comp_data *cd, struct dai_ts_data *tsd); -#else -int asrc_dai_get_timestamp(struct comp_data *cd, struct timestamp_data *tsd); -#endif + /* Simple count value to prevent first delta timestamp * from being input to low-pass filter. */ diff --git a/src/audio/asrc/asrc_ipc3.c b/src/audio/asrc/asrc_ipc3.c index 30dfbecddc6b..7984fce40243 100644 --- a/src/audio/asrc/asrc_ipc3.c +++ b/src/audio/asrc/asrc_ipc3.c @@ -43,11 +43,7 @@ int asrc_dai_stop_timestamp(struct comp_data *cd) return -EINVAL; } -#if CONFIG_ZEPHYR_NATIVE_DRIVERS int asrc_dai_get_timestamp(struct comp_data *cd, struct dai_ts_data *tsd) -#else -int asrc_dai_get_timestamp(struct comp_data *cd, struct timestamp_data *tsd) -#endif { if (!cd->dai_dev) return -EINVAL; diff --git a/src/audio/asrc/asrc_ipc4.c b/src/audio/asrc/asrc_ipc4.c index 3e5d8bf7818f..4425aee1c5fe 100644 --- a/src/audio/asrc/asrc_ipc4.c +++ b/src/audio/asrc/asrc_ipc4.c @@ -52,11 +52,7 @@ int asrc_dai_stop_timestamp(struct comp_data *cd) return ops->endpoint_ops->dai_ts_stop(cd->dai_dev); } -#if CONFIG_ZEPHYR_NATIVE_DRIVERS int asrc_dai_get_timestamp(struct comp_data *cd, struct dai_ts_data *tsd) -#else -int asrc_dai_get_timestamp(struct comp_data *cd, struct timestamp_data *tsd) -#endif { if (!cd->dai_dev) return -ENODEV; diff --git a/src/audio/copier/copier.c b/src/audio/copier/copier.c index 5d4b47a1d5fc..0949e7edb8f5 100644 --- a/src/audio/copier/copier.c +++ b/src/audio/copier/copier.c @@ -44,9 +44,7 @@ #include #endif -#if CONFIG_ZEPHYR_NATIVE_DRIVERS #include -#endif LOG_MODULE_REGISTER(copier, CONFIG_SOF_LOG_LEVEL); @@ -1132,11 +1130,7 @@ static int copier_dai_ts_start_op(struct comp_dev *dev) return dai_common_ts_start(dd, dev); } -#if CONFIG_ZEPHYR_NATIVE_DRIVERS static int copier_dai_ts_get_op(struct comp_dev *dev, struct dai_ts_data *tsd) -#else -static int copier_dai_ts_get_op(struct comp_dev *dev, struct timestamp_data *tsd) -#endif { struct processing_module *mod = comp_mod(dev); struct copier_data *cd = module_get_private_data(mod); diff --git a/src/audio/copier/dai_copier.h b/src/audio/copier/dai_copier.h index 0ec7f04ae6ac..8fc2996ec4a9 100644 --- a/src/audio/copier/dai_copier.h +++ b/src/audio/copier/dai_copier.h @@ -44,11 +44,7 @@ int dai_common_ts_start(struct dai_data *dd, struct comp_dev *dev); int dai_common_ts_stop(struct dai_data *dd, struct comp_dev *dev); -#if CONFIG_ZEPHYR_NATIVE_DRIVERS int dai_common_ts_get(struct dai_data *dd, struct comp_dev *dev, struct dai_ts_data *tsd); -#else -int dai_common_ts_get(struct dai_data *dd, struct comp_dev *dev, struct timestamp_data *tsd); -#endif int dai_common_get_hw_params(struct dai_data *dd, struct comp_dev *dev, struct sof_ipc_stream_params *params, int dir); diff --git a/src/audio/dai-legacy.c b/src/audio/dai-legacy.c deleted file mode 100644 index b212bb9ebdac..000000000000 --- a/src/audio/dai-legacy.c +++ /dev/null @@ -1,1141 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2016 Intel Corporation. All rights reserved. -// -// Author: Liam Girdwood -// Keyon Jie - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include /* for SHARED_DATA */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "copier/dai_copier.h" - -static const struct comp_driver comp_dai; - -LOG_MODULE_REGISTER(dai_comp, CONFIG_SOF_LOG_LEVEL); - -SOF_DEFINE_REG_UUID(dai); - -DECLARE_TR_CTX(dai_comp_tr, SOF_UUID(dai_uuid), LOG_LEVEL_INFO); - -#if CONFIG_COMP_DAI_GROUP - -static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev, int cmd); - -static void dai_atomic_trigger(void *arg, enum notify_id type, void *data) -{ - struct comp_dev *dev = arg; - struct dai_data *dd = comp_get_drvdata(dev); - struct dai_group *group = dd->group; - - /* Atomic context set by the last DAI to receive trigger command */ - group->trigger_ret = dai_comp_trigger_internal(dd, dev, group->trigger_cmd); -} - -/* Assign DAI to a group */ -int dai_assign_group(struct dai_data *dd, struct comp_dev *dev, uint32_t group_id) -{ - if (dd->group) { - if (dd->group->group_id != group_id) { - comp_err(dev, "dai_assign_group(), DAI already in group %d, requested %d", - dd->group->group_id, group_id); - return -EINVAL; - } - - /* No need to re-assign to the same group, do nothing */ - return 0; - } - - dd->group = dai_group_get(group_id, DAI_CREAT); - if (!dd->group) { - comp_err(dev, "dai_assign_group(), failed to assign group %d", - group_id); - return -EINVAL; - } - - comp_dbg(dev, "dai_assign_group(), group %d num %d", - group_id, dd->group->num_dais); - - /* Register for the atomic trigger event */ - notifier_register(dev, dd->group, NOTIFIER_ID_DAI_TRIGGER, - dai_atomic_trigger, 0); - - return 0; -} -#endif -/* this is called by DMA driver every time descriptor has completed */ -static void dai_dma_cb(void *arg, enum notify_id type, void *data) -{ - struct dma_cb_data *next = data; - struct comp_dev *dev = arg; - struct dai_data *dd = comp_get_drvdata(dev); - uint32_t bytes = next->elem.size; - int ret; - - comp_dbg(dev, "dai_dma_cb()"); - - next->status = SOF_DMA_CB_STATUS_RELOAD; - - /* stop dma copy for pause/stop/xrun */ - if (dev->state != COMP_STATE_ACTIVE || dd->xrun) { - /* stop the DAI */ - dai_trigger(dd->dai, COMP_TRIGGER_STOP, dev->direction); - - /* tell DMA not to reload */ - next->status = SOF_DMA_CB_STATUS_END; - } - - /* is our pipeline handling an XRUN ? */ - if (dd->xrun) { - /* make sure we only playback silence during an XRUN */ - if (dev->direction == SOF_IPC_STREAM_PLAYBACK) - /* fill buffer with silence */ - buffer_zero(dd->dma_buffer); - - return; - } - - if (dev->direction == SOF_IPC_STREAM_PLAYBACK) { - ret = dma_buffer_copy_to(dd->local_buffer, dd->dma_buffer, - dd->process, bytes, DUMMY_CHMAP); - } else { - ret = dma_buffer_copy_from(dd->dma_buffer, dd->local_buffer, - dd->process, bytes, DUMMY_CHMAP); - } - - /* assert dma_buffer_copy succeed */ - if (ret < 0) { - struct comp_buffer *source_c, *sink_c; - - source_c = dev->direction == SOF_IPC_STREAM_PLAYBACK ? - dd->local_buffer : dd->dma_buffer; - sink_c = dev->direction == SOF_IPC_STREAM_PLAYBACK ? - dd->dma_buffer : dd->local_buffer; - comp_err(dev, "dai_dma_cb() dma buffer copy failed, dir %d bytes %d avail %d free %d", - dev->direction, bytes, - audio_stream_get_avail_samples(&source_c->stream) * - audio_stream_frame_bytes(&source_c->stream), - audio_stream_get_free_samples(&sink_c->stream) * - audio_stream_frame_bytes(&sink_c->stream)); - } else { - /* update host position (in bytes offset) for drivers */ - dd->total_data_processed += bytes; - } -} - -int dai_common_new(struct dai_data *dd, struct comp_dev *dev, const struct ipc_config_dai *dai) -{ - uint32_t dir, caps, dma_dev; - - dd->dai = dai_get(dai->type, dai->dai_index, DAI_CREAT); - if (!dd->dai) { - comp_cl_err(&comp_dai, "dai_common_new(): dai_get() failed to create DAI."); - return -ENODEV; - } - dd->dai->dd = dd; - dd->ipc_config = *dai; - - /* request GP LP DMA with shared access privilege */ - dir = dai->direction == SOF_IPC_STREAM_PLAYBACK ? - DMA_DIR_MEM_TO_DEV : DMA_DIR_DEV_TO_MEM; - - caps = dai_get_info(dd->dai, DAI_INFO_DMA_CAPS); - dma_dev = dai_get_info(dd->dai, DAI_INFO_DMA_DEV); - - dd->dma = dma_get(dir, caps, dma_dev, DMA_ACCESS_SHARED); - if (!dd->dma) { - comp_cl_err(&comp_dai, "dai_common_new(): dma_get() failed to get shared access to DMA."); - return -ENODEV; - } - - dma_sg_init(&dd->config.elem_array); - dd->xrun = 0; - dd->chan = NULL; - - return 0; -} - -static struct comp_dev *dai_new(const struct comp_driver *drv, - const struct comp_ipc_config *config, - const void *spec) -{ - struct comp_dev *dev; - const struct ipc_config_dai *dai = spec; - struct dai_data *dd; - int ret; - - comp_cl_dbg(&comp_dai, "dai_new()"); - - dev = comp_alloc(drv, sizeof(*dev)); - if (!dev) - return NULL; - dev->ipc_config = *config; - - dd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*dd)); - if (!dd) { - rfree(dev); - return NULL; - } - - comp_set_drvdata(dev, dd); - - ret = dai_common_new(dd, dev, dai); - if (ret < 0) - goto error; - - dev->state = COMP_STATE_READY; - return dev; - -error: - rfree(dd); - rfree(dev); - return NULL; -} - -void dai_common_free(struct dai_data *dd) -{ - if (dd->group) - dai_group_put(dd->group); - - if (dd->chan) { - dd->chan->dev_data = NULL; - dma_channel_put_legacy(dd->chan); - } - - dma_put(dd->dma); - - dai_release_llp_slot(dd); - - dai_put(dd->dai); - - if (dd->dai_spec_config) - rfree(dd->dai_spec_config); -} - -static void dai_free(struct comp_dev *dev) -{ - struct dai_data *dd = comp_get_drvdata(dev); - - if (dd->group) - notifier_unregister(dev, dd->group, NOTIFIER_ID_DAI_TRIGGER); - - if (dd->chan) - notifier_unregister(dev, dd->chan, NOTIFIER_ID_DMA_COPY); - - dai_common_free(dd); - - rfree(dd); - rfree(dev); -} - -int dai_common_get_hw_params(struct dai_data *dd, struct comp_dev *dev, - struct sof_ipc_stream_params *params, int dir) -{ - int ret; - - comp_dbg(dev, "dai_hw_params()"); - - /* fetching hw dai stream params */ - ret = dai_get_hw_params(dd->dai, params, dir); - if (ret < 0) { - comp_err(dev, "dai_comp_get_hw_params(): dai_get_hw_params failed ret %d", - ret); - return ret; - } - - /* dai_comp_get_hw_params() function fetches hardware dai parameters, - * which then are propagating back through the pipeline, so that any - * component can convert specific stream parameter. Here, we overwrite - * frame_fmt hardware parameter as DAI component is able to convert - * stream with different frame_fmt's (using pcm converter) - */ - params->frame_fmt = dev->ipc_config.frame_fmt; - - return 0; -} - -static int dai_comp_get_hw_params(struct comp_dev *dev, - struct sof_ipc_stream_params *params, int dir) -{ - struct dai_data *dd = comp_get_drvdata(dev); - - return dai_common_get_hw_params(dd, dev, params, dir); -} - -static int dai_comp_hw_params(struct comp_dev *dev, - struct sof_ipc_stream_params *params) -{ - struct dai_data *dd = comp_get_drvdata(dev); - int ret; - - comp_dbg(dev, "dai_comp_hw_params()"); - - /* configure hw dai stream params */ - ret = dai_hw_params(dd->dai, params); - if (ret < 0) { - comp_err(dev, "dai_comp_hw_params(): dai_hw_params failed ret %d", - ret); - return ret; - } - - return 0; -} - -static int dai_verify_params(struct dai_data *dd, struct comp_dev *dev, - struct sof_ipc_stream_params *params) -{ - struct sof_ipc_stream_params hw_params; - int ret; - - ret = dai_common_get_hw_params(dd, dev, &hw_params, params->direction); - if (ret < 0) - return ret; - - /* checks whether pcm parameters match hardware DAI parameter set - * during dai_set_config(). If hardware parameter is equal to 0, it - * means that it can vary, so any value is acceptable. We do not check - * format parameter, because DAI is able to change format using - * pcm_converter functions. - */ - if (hw_params.rate && hw_params.rate != params->rate) { - comp_err(dev, "dai_verify_params(): pcm rate parameter %d does not match hardware rate %d", - params->rate, hw_params.rate); - return -EINVAL; - } - - if (hw_params.channels && hw_params.channels != params->channels) { - comp_err(dev, "dai_verify_params(): pcm channels parameter %d does not match hardware channels %d", - params->channels, hw_params.channels); - return -EINVAL; - } - - /* set component period frames */ - component_set_nearest_period_frames(dev, params->rate); - - return 0; -} - -/* set component audio SSP and DMA configuration */ -static int dai_playback_params(struct comp_dev *dev, uint32_t period_bytes, - uint32_t period_count) -{ - struct dai_data *dd = comp_get_drvdata(dev); - struct dma_sg_config *config = &dd->config; - uint32_t local_fmt = audio_stream_get_frm_fmt(&dd->local_buffer->stream); - uint32_t dma_fmt = audio_stream_get_frm_fmt(&dd->dma_buffer->stream); - uint32_t fifo; - int err = 0; - - /* set processing function */ - dd->process = pcm_get_conversion_function(local_fmt, dma_fmt); - - if (!dd->process) { - comp_err(dev, "dai_playback_params(): converter function NULL: local fmt %d dma fmt %d\n", - local_fmt, dma_fmt); - return -EINVAL; - } - - /* set up DMA configuration */ - config->direction = DMA_DIR_MEM_TO_DEV; - config->src_width = get_sample_bytes(dma_fmt); - config->dest_width = config->src_width; - config->cyclic = 1; - config->irq_disabled = pipeline_is_timer_driven(dev->pipeline); - config->dest_dev = dai_get_handshake(dd->dai, dev->direction, - dd->stream_id); - config->is_scheduling_source = comp_is_scheduling_source(dev); - config->period = dev->pipeline->period; - - comp_info(dev, "dai_playback_params() dest_dev = %d stream_id = %d src_width = %d dest_width = %d", - config->dest_dev, dd->stream_id, - config->src_width, config->dest_width); - - if (!config->elem_array.elems) { - fifo = dai_get_fifo(dd->dai, dev->direction, - dd->stream_id); - - comp_info(dev, "dai_playback_params() fifo 0x%x", fifo); - - err = dma_sg_alloc(&config->elem_array, SOF_MEM_ZONE_RUNTIME, - config->direction, - period_count, - period_bytes, - (uintptr_t)(audio_stream_get_addr(&dd->dma_buffer->stream)), - fifo); - if (err < 0) - comp_err(dev, "dai_playback_params(): dma_sg_alloc() for period_count %d period_bytes %d failed with err = %d", - period_count, period_bytes, err); - } - - return err; -} - -static int dai_capture_params(struct comp_dev *dev, uint32_t period_bytes, - uint32_t period_count) -{ - struct dai_data *dd = comp_get_drvdata(dev); - struct dma_sg_config *config = &dd->config; - uint32_t local_fmt = audio_stream_get_frm_fmt(&dd->local_buffer->stream); - uint32_t dma_fmt = audio_stream_get_frm_fmt(&dd->dma_buffer->stream); - uint32_t fifo; - int err = 0; - - /* set processing function */ - dd->process = pcm_get_conversion_function(dma_fmt, local_fmt); - - if (!dd->process) { - comp_err(dev, "dai_capture_params(): converter function NULL: local fmt %d dma fmt %d\n", - local_fmt, dma_fmt); - return -EINVAL; - } - - /* set up DMA configuration */ - config->direction = DMA_DIR_DEV_TO_MEM; - config->cyclic = 1; - config->irq_disabled = pipeline_is_timer_driven(dev->pipeline); - config->src_dev = dai_get_handshake(dd->dai, dev->direction, - dd->stream_id); - config->is_scheduling_source = comp_is_scheduling_source(dev); - config->period = dev->pipeline->period; - - /* TODO: Make this code platform-specific or move it driver callback */ - if (dai_get_info(dd->dai, DAI_INFO_TYPE) == SOF_DAI_INTEL_DMIC) { - /* For DMIC the DMA src and dest widths should always be 4 bytes - * due to 32 bit FIFO packer. Setting width to 2 bytes for - * 16 bit format would result in recording at double rate. - */ - config->src_width = 4; - config->dest_width = 4; - } else { - config->src_width = get_sample_bytes(dma_fmt); - config->dest_width = config->src_width; - } - - comp_info(dev, "dai_capture_params() src_dev = %d stream_id = %d src_width = %d dest_width = %d", - config->src_dev, dd->stream_id, - config->src_width, config->dest_width); - - if (!config->elem_array.elems) { - fifo = dai_get_fifo(dd->dai, dev->direction, - dd->stream_id); - - comp_info(dev, "dai_capture_params() fifo 0x%x", fifo); - - err = dma_sg_alloc(&config->elem_array, SOF_MEM_ZONE_RUNTIME, - config->direction, - period_count, - period_bytes, - (uintptr_t)(audio_stream_get_addr(&dd->dma_buffer->stream)), - fifo); - if (err < 0) - comp_err(dev, "dai_capture_params(): dma_sg_alloc() for period_count %d period_bytes %d failed with err = %d", - period_count, period_bytes, err); - } - - return err; -} - -int dai_common_params(struct dai_data *dd, struct comp_dev *dev, - struct sof_ipc_stream_params *params) -{ - struct sof_ipc_stream_params hw_params = *params; - uint32_t frame_size; - uint32_t period_count; - uint32_t period_bytes; - uint32_t buffer_size; - uint32_t addr_align; - uint32_t align; - int err; - - comp_dbg(dev, "dai_params()"); - - /* configure dai_data first */ - err = ipc_dai_data_config(dd, dev); - if (err < 0) - return err; - - err = dai_verify_params(dd, dev, params); - if (err < 0) { - comp_err(dev, "dai_params(): pcm params verification failed."); - return -EINVAL; - } - - /* params verification passed, so now configure hw dai stream params */ - err = dai_comp_hw_params(dev, params); - if (err < 0) { - comp_err(dev, "dai_params(): dai_comp_hw_params failed err %d", err); - return err; - } - - if (dev->direction == SOF_IPC_STREAM_PLAYBACK) - dd->local_buffer = comp_dev_get_first_data_producer(dev); - else - dd->local_buffer = comp_dev_get_first_data_consumer(dev); - - /* check if already configured */ - if (dev->state == COMP_STATE_PREPARE) { - comp_info(dev, "dai_params() component has been already configured."); - return 0; - } - - /* can set params on only init state */ - if (dev->state != COMP_STATE_READY) { - comp_err(dev, "dai_params(): Component is in state %d, expected COMP_STATE_READY.", - dev->state); - return -EINVAL; - } - - err = dma_get_attribute_legacy(dd->dma, DMA_ATTR_BUFFER_ADDRESS_ALIGNMENT, - &addr_align); - if (err < 0) { - comp_err(dev, "dai_params(): could not get dma buffer address alignment, err = %d", - err); - return err; - } - - err = dma_get_attribute_legacy(dd->dma, DMA_ATTR_BUFFER_ALIGNMENT, &align); - if (err < 0 || !align) { - comp_err(dev, "dai_params(): could not get valid dma buffer alignment, err = %d, align = %u", - err, align); - return -EINVAL; - } - - err = dma_get_attribute_legacy(dd->dma, DMA_ATTR_BUFFER_PERIOD_COUNT, - &period_count); - if (err < 0 || !period_count) { - comp_err(dev, "dai_params(): could not get valid dma buffer period count, err = %d, period_count = %u", - err, period_count); - return -EINVAL; - } - - /* calculate frame size */ - frame_size = get_frame_bytes(dev->ipc_config.frame_fmt, - audio_stream_get_channels(&dd->local_buffer->stream)); - - /* calculate period size */ - period_bytes = dev->frames * frame_size; - if (!period_bytes) { - comp_err(dev, "dai_params(): invalid period_bytes."); - return -EINVAL; - } - - dd->period_bytes = period_bytes; - - /* calculate DMA buffer size */ - period_count = MAX(period_count, - SOF_DIV_ROUND_UP(dd->ipc_config.dma_buffer_size, period_bytes)); - buffer_size = ALIGN_UP(period_count * period_bytes, align); - - /* alloc DMA buffer or change its size if exists */ - if (dd->dma_buffer) { - err = buffer_set_size(dd->dma_buffer, buffer_size, addr_align); - - if (err < 0) { - comp_err(dev, "dai_params(): buffer_set_size() failed, buffer_size = %u", - buffer_size); - return err; - } - } else { - dd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA, 0, - addr_align, false); - if (!dd->dma_buffer) { - comp_err(dev, "dai_params(): failed to alloc dma buffer"); - return -ENOMEM; - } - - /* - * dma_buffer should reffer to hardware dai parameters. - * Here, we overwrite frame_fmt hardware parameter as DAI - * component is able to convert stream with different - * frame_fmt's (using pcm converter). - */ - hw_params.frame_fmt = dev->ipc_config.frame_fmt; - buffer_set_params(dd->dma_buffer, &hw_params, - BUFFER_UPDATE_FORCE); - } - - return dev->direction == SOF_IPC_STREAM_PLAYBACK ? - dai_playback_params(dev, period_bytes, period_count) : - dai_capture_params(dev, period_bytes, period_count); -} - -static int dai_params(struct comp_dev *dev, struct sof_ipc_stream_params *params) -{ - struct dai_data *dd = comp_get_drvdata(dev); - - comp_dbg(dev, "dai_params()"); - - return dai_common_params(dd, dev, params); -} - -int dai_common_config_prepare(struct dai_data *dd, struct comp_dev *dev) -{ - int channel = 0; - - /* cannot configure DAI while active */ - if (dev->state == COMP_STATE_ACTIVE) { - comp_info(dev, "dai_common_config_prepare(): Component is in active state."); - return 0; - } - - if (!dd->dai_spec_config) { - comp_err(dev, "dai specific config is not set yet!"); - return -EINVAL; - } - - if (dd->chan) { - comp_info(dev, "dai_common_config_prepare(): dma channel index %d already configured", - dd->chan->index); - return 0; - } - - channel = dai_config_dma_channel(dd, dev, dd->dai_spec_config); - comp_info(dev, "dai_common_config_prepare(), channel = %d", channel); - - /* do nothing for asking for channel free, for compatibility. */ - if (channel == DMA_CHAN_INVALID) { - comp_err(dev, "dai_config is not set yet!"); - return -EINVAL; - } - - /* allocate DMA channel */ - dd->chan = dma_channel_get_legacy(dd->dma, channel); - if (!dd->chan) { - comp_err(dev, "dai_common_config_prepare(): dma_channel_get() failed"); - dd->chan = NULL; - return -EIO; - } - - dd->chan->dev_data = dd; - - comp_info(dev, "dai_common_config_prepare(): new configured dma channel index %d", - dd->chan->index); - - /* setup callback */ - notifier_register(dev, dd->chan, NOTIFIER_ID_DMA_COPY, - dai_dma_cb, 0); - - return 0; -} - -int dai_common_prepare(struct dai_data *dd, struct comp_dev *dev) -{ - int ret; - - dd->total_data_processed = 0; - - if (!dd->chan) { - comp_err(dev, "dai_prepare(): Missing dd->chan."); - comp_set_state(dev, COMP_TRIGGER_RESET); - return -EINVAL; - } - - if (!dd->config.elem_array.elems) { - comp_err(dev, "dai_prepare(): Missing dd->config.elem_array.elems."); - comp_set_state(dev, COMP_TRIGGER_RESET); - return -EINVAL; - } - - /* clear dma buffer to avoid pop noise */ - buffer_zero(dd->dma_buffer); - - /* dma reconfig not required if XRUN handling */ - if (dd->xrun) { - /* after prepare, we have recovered from xrun */ - dd->xrun = 0; - return 0; - } - - ret = dma_set_config_legacy(dd->chan, &dd->config); - if (ret < 0) - comp_set_state(dev, COMP_TRIGGER_RESET); - - return ret; -} - -static int dai_prepare(struct comp_dev *dev) -{ - struct dai_data *dd = comp_get_drvdata(dev); - int ret; - - comp_info(dev, "dai_prepare()"); - - ret = dai_common_config_prepare(dd, dev); - if (ret < 0) - return ret; - - ret = comp_set_state(dev, COMP_TRIGGER_PREPARE); - if (ret < 0) - return ret; - - if (ret == COMP_STATUS_STATE_ALREADY_SET) - return PPL_STATUS_PATH_STOP; - - return dai_common_prepare(dd, dev); -} - -void dai_common_reset(struct dai_data *dd, struct comp_dev *dev) -{ - struct dma_sg_config *config = &dd->config; - - /* - * DMA channel release should be skipped now for DAI's that support the two-step stop option. - * It will be done when the host sends the DAI_CONFIG IPC during hw_free. - */ - if (!dd->delayed_dma_stop) - dai_dma_release(dd, dev); - - dma_sg_free(&config->elem_array); - - if (dd->dma_buffer) { - buffer_free(dd->dma_buffer); - dd->dma_buffer = NULL; - } - - dd->wallclock = 0; - dd->total_data_processed = 0; - dd->xrun = 0; -} - -static int dai_reset(struct comp_dev *dev) -{ - struct dai_data *dd = comp_get_drvdata(dev); - - comp_info(dev, "dai_reset()"); - - dai_common_reset(dd, dev); - - comp_set_state(dev, COMP_TRIGGER_RESET); - - return 0; -} - -/* used to pass standard and bespoke command (with data) to component */ -static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev, int cmd) -{ - int ret; - - comp_dbg(dev, "dai_comp_trigger_internal(), command = %u", cmd); - - ret = comp_set_state(dev, cmd); - if (ret < 0) - return ret; - - if (ret == COMP_STATUS_STATE_ALREADY_SET) - return PPL_STATUS_PATH_STOP; - - switch (cmd) { - case COMP_TRIGGER_START: - comp_dbg(dev, "dai_comp_trigger_internal(), START"); - - /* only start the DAI if we are not XRUN handling */ - if (dd->xrun == 0) { - ret = dma_start_legacy(dd->chan); - if (ret < 0) - return ret; - /* start the DAI */ - dai_trigger(dd->dai, cmd, dev->direction); - } else { - dd->xrun = 0; - } - - platform_dai_wallclock(dev, &dd->wallclock); - break; - case COMP_TRIGGER_RELEASE: - /* before release, we clear the buffer data to 0s, - * then there is no history data sent out after release. - * this is only supported at capture mode. - */ - if (dev->direction == SOF_IPC_STREAM_CAPTURE) { - buffer_zero(dd->dma_buffer); - } - - /* only start the DAI if we are not XRUN handling */ - if (dd->xrun == 0) { - /* recover valid start position */ - ret = dma_release_legacy(dd->chan); - if (ret < 0) - return ret; - - /* start the DAI */ - dai_trigger(dd->dai, cmd, dev->direction); - ret = dma_start_legacy(dd->chan); - if (ret < 0) - return ret; - } else { - dd->xrun = 0; - } - - platform_dai_wallclock(dev, &dd->wallclock); - break; - case COMP_TRIGGER_XRUN: - comp_info(dev, "dai_comp_trigger_internal(), XRUN"); - dd->xrun = 1; - - COMPILER_FALLTHROUGH; - case COMP_TRIGGER_STOP: - comp_dbg(dev, "dai_comp_trigger_internal(), STOP"); -/* - * Some platforms cannot just simple disable - * DMA channel during the transfer, - * because it will hang the whole DMA controller. - * Therefore, stop the DMA first and let the DAI - * drain the FIFO in order to stop the channel - * as soon as possible. - */ -#if CONFIG_DMA_SUSPEND_DRAIN - ret = dma_stop_legacy(dd->chan); - dai_trigger(dd->dai, cmd, dev->direction); -#else - dai_trigger(dd->dai, cmd, dev->direction); - ret = dma_stop_legacy(dd->chan); -#endif - break; - case COMP_TRIGGER_PAUSE: - comp_dbg(dev, "dai_comp_trigger_internal(), PAUSE"); - ret = dma_pause_legacy(dd->chan); - dai_trigger(dd->dai, cmd, dev->direction); - break; - case COMP_TRIGGER_PRE_START: - case COMP_TRIGGER_PRE_RELEASE: - /* only start the DAI if we are not XRUN handling */ - if (dd->xrun) - dd->xrun = 0; - else - dai_trigger(dd->dai, cmd, dev->direction); - break; - } - - return ret; -} - -int dai_common_trigger(struct dai_data *dd, struct comp_dev *dev, int cmd) -{ - struct dai_group *group = dd->group; - uint32_t irq_flags; - int ret = 0; - - /* DAI not in a group, use normal trigger */ - if (!group) { - comp_dbg(dev, "dai_common_trigger(), non-atomic trigger"); - return dai_comp_trigger_internal(dd, dev, cmd); - } - - /* DAI is grouped, so only trigger when the entire group is ready */ - - if (!group->trigger_counter) { - /* First DAI to receive the trigger command, - * prepare for atomic trigger - */ - comp_dbg(dev, "dai_common_trigger(), begin atomic trigger for group %d", - group->group_id); - group->trigger_cmd = cmd; - group->trigger_counter = group->num_dais - 1; - } else if (group->trigger_cmd != cmd) { - /* Already processing a different trigger command */ - comp_err(dev, "dai_common_trigger(), already processing atomic trigger"); - ret = -EAGAIN; - } else { - /* Count down the number of remaining DAIs required - * to receive the trigger command before atomic trigger - * takes place - */ - group->trigger_counter--; - comp_dbg(dev, "dai_common_trigger(), trigger counter %d, group %d", - group->trigger_counter, group->group_id); - - if (!group->trigger_counter) { - /* The counter has reached 0, which means - * all DAIs have received the same trigger command - * and we may begin the actual trigger process - * synchronously. - */ - - irq_local_disable(irq_flags); - notifier_event(group, NOTIFIER_ID_DAI_TRIGGER, - BIT(cpu_get_id()), NULL, 0); - irq_local_enable(irq_flags); - - /* return error of last trigger */ - ret = group->trigger_ret; - } - } - - return ret; -} - -static int dai_comp_trigger(struct comp_dev *dev, int cmd) -{ - struct dai_data *dd = comp_get_drvdata(dev); - - return dai_common_trigger(dd, dev, cmd); -} - -/* report xrun occurrence */ -static void dai_report_xrun(struct comp_dev *dev, uint32_t bytes) -{ - struct dai_data *dd = comp_get_drvdata(dev); - - if (dev->direction == SOF_IPC_STREAM_PLAYBACK) { - comp_err(dev, "dai_report_xrun(): underrun due to no data available"); - comp_underrun(dev, dd->local_buffer, bytes); - } else { - comp_err(dev, "dai_report_xrun(): overrun due to no space available"); - comp_overrun(dev, dd->local_buffer, bytes); - } -} - -/* copy and process stream data from source to sink buffers */ -int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_func *converter) -{ - uint32_t dma_fmt; - uint32_t sampling; - uint32_t avail_bytes = 0; - uint32_t free_bytes = 0; - uint32_t copy_bytes = 0; - uint32_t src_samples; - uint32_t sink_samples; - uint32_t samples; - int ret; - - /* get data sizes from DMA */ - ret = dma_get_data_size_legacy(dd->chan, &avail_bytes, &free_bytes); - if (ret < 0) { - dai_report_xrun(dev, 0); - return ret; - } - - dma_fmt = audio_stream_get_frm_fmt(&dd->dma_buffer->stream); - sampling = get_sample_bytes(dma_fmt); - - /* calculate minimum size to copy */ - if (dev->direction == SOF_IPC_STREAM_PLAYBACK) { - src_samples = audio_stream_get_avail_samples(&dd->local_buffer->stream); - sink_samples = free_bytes / sampling; - samples = MIN(src_samples, sink_samples); - } else { - src_samples = avail_bytes / sampling; - sink_samples = audio_stream_get_free_samples(&dd->local_buffer->stream); - samples = MIN(src_samples, sink_samples); - } - - /* limit bytes per copy to one period for the whole pipeline - * in order to avoid high load spike - */ - samples = MIN(samples, dd->period_bytes / sampling); - - copy_bytes = samples * sampling; - - comp_dbg(dev, "dai_common_copy(), dir: %d copy_bytes= 0x%x, frames= %d", - dev->direction, copy_bytes, - samples / audio_stream_get_channels(&dd->local_buffer->stream)); - - /* Check possibility of glitch occurrence */ - if (dev->direction == SOF_IPC_STREAM_PLAYBACK && - copy_bytes + avail_bytes < dd->period_bytes) - comp_warn(dev, "dai_common_copy(): Copy_bytes %d + avail bytes %d < period bytes %d, possible glitch", - copy_bytes, avail_bytes, dd->period_bytes); - else if (dev->direction == SOF_IPC_STREAM_CAPTURE && - copy_bytes + free_bytes < dd->period_bytes) - comp_warn(dev, "dai_common_copy(): Copy_bytes %d + free bytes %d < period bytes %d, possible glitch", - copy_bytes, free_bytes, dd->period_bytes); - - /* return if nothing to copy */ - if (!copy_bytes) { - comp_warn(dev, "dai_common_copy(): nothing to copy"); - return 0; - } - - if (dd->dai->drv->ops.copy) - dd->dai->drv->ops.copy(dd->dai); - - ret = dma_copy_legacy(dd->chan, copy_bytes, 0); - if (ret < 0) { - dai_report_xrun(dev, copy_bytes); - return ret; - } - - dai_dma_position_update(dd, dev); - - return ret; -} - -static int dai_copy(struct comp_dev *dev) -{ - struct dai_data *dd = comp_get_drvdata(dev); - - comp_dbg(dev, "dai_copy()"); - - /* - * DAI devices will only ever have 1 sink, so no need to pass an array of PCM converter - * functions. The default one to use is set in dd->process. - */ - return dai_common_copy(dd, dev, NULL); -} - -/** - * \brief Get DAI parameters and configure timestamping - * \param[in, out] dev DAI device. - * \return Error code. - * - * This function retrieves various DAI parameters such as type, direction, index, and DMA - * controller information those are needed when configuring HW timestamping. Note that - * DAI must be prepared before this function is used (for DMA information). If not, an error - * is returned. - */ -int dai_common_ts_config_op(struct dai_data *dd, struct comp_dev *dev) -{ - struct timestamp_cfg *cfg = &dd->ts_config; - struct ipc_config_dai *dai = &dd->ipc_config; - - comp_dbg(dev, "dai_ts_config()"); - if (!dd->chan) { - comp_err(dev, "dai_ts_config(), No DMA channel information"); - return -EINVAL; - } - - cfg->type = dd->dai->drv->type; - cfg->direction = dai->direction; - cfg->index = dd->dai->index; - cfg->dma_id = dd->dma->plat_data.id; - cfg->dma_chan_index = dd->chan->index; - cfg->dma_chan_count = dd->dma->plat_data.channels; - if (!dd->dai->drv->ts_ops.ts_config) - return -ENXIO; - - return dd->dai->drv->ts_ops.ts_config(dd->dai, cfg); -} - -static int dai_ts_config(struct comp_dev *dev) -{ - struct dai_data *dd = comp_get_drvdata(dev); - - return dai_common_ts_config_op(dd, dev); -} - -int dai_common_ts_start(struct dai_data *dd, struct comp_dev *dev) -{ - if (!dd->dai->drv->ts_ops.ts_start) - return -ENXIO; - - return dd->dai->drv->ts_ops.ts_start(dd->dai, &dd->ts_config); -} - -static int dai_ts_start(struct comp_dev *dev) -{ - struct dai_data *dd = comp_get_drvdata(dev); - - comp_dbg(dev, "dai_ts_start()"); - - return dai_common_ts_start(dd, dev); -} - -int dai_common_ts_stop(struct dai_data *dd, struct comp_dev *dev) -{ - if (!dd->dai->drv->ts_ops.ts_stop) - return -ENXIO; - - return dd->dai->drv->ts_ops.ts_stop(dd->dai, &dd->ts_config); -} - -static int dai_ts_stop(struct comp_dev *dev) -{ - struct dai_data *dd = comp_get_drvdata(dev); - - comp_dbg(dev, "dai_ts_stop()"); - - return dai_common_ts_stop(dd, dev); -} - -int dai_common_ts_get(struct dai_data *dd, struct comp_dev *dev, struct timestamp_data *tsd) -{ - if (!dd->dai->drv->ts_ops.ts_get) - return -ENXIO; - - return dd->dai->drv->ts_ops.ts_get(dd->dai, &dd->ts_config, tsd); -} - -static int dai_ts_get(struct comp_dev *dev, struct timestamp_data *tsd) -{ - struct dai_data *dd = comp_get_drvdata(dev); - - comp_dbg(dev, "dai_ts_get()"); - - return dai_common_ts_get(dd, dev, tsd); -} - -static uint64_t dai_get_processed_data(struct comp_dev *dev, uint32_t stream_no, bool input) -{ - struct dai_data *dd = comp_get_drvdata(dev); - uint64_t ret = 0; - bool source = dev->direction == SOF_IPC_STREAM_CAPTURE; - - /* Return value only if direction and stream number match. - * The dai supports only one stream. - */ - if (stream_no == 0 && source == input) - ret = dd->total_data_processed; - - return ret; -} - -static const struct comp_driver comp_dai = { - .type = SOF_COMP_DAI, - .uid = SOF_RT_UUID(dai_uuid), - .tctx = &dai_comp_tr, - .ops = { - .create = dai_new, - .free = dai_free, - .params = dai_params, - .dai_get_hw_params = dai_comp_get_hw_params, - .trigger = dai_comp_trigger, - .copy = dai_copy, - .prepare = dai_prepare, - .reset = dai_reset, - .dai_config = dai_config, - .position = dai_position, - .dai_ts_config = dai_ts_config, - .dai_ts_start = dai_ts_start, - .dai_ts_stop = dai_ts_stop, - .dai_ts_get = dai_ts_get, - .get_total_data_processed = dai_get_processed_data, - }, -}; - -static SHARED_DATA struct comp_driver_info comp_dai_info = { - .drv = &comp_dai, -}; - -UT_STATIC void sys_comp_dai_init(void) -{ - comp_register(platform_shared_get(&comp_dai_info, - sizeof(comp_dai_info))); -} - -DECLARE_MODULE(sys_comp_dai_init); -SOF_MODULE_INIT(dai, sys_comp_dai_init); diff --git a/src/audio/host-legacy.c b/src/audio/host-legacy.c deleted file mode 100644 index e8d62e17301d..000000000000 --- a/src/audio/host-legacy.c +++ /dev/null @@ -1,1032 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2016 Intel Corporation. All rights reserved. -// -// Author: Liam Girdwood -// Keyon Jie - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include /* for SHARED_DATA */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "copier/host_copier.h" - -static const struct comp_driver comp_host; - -LOG_MODULE_REGISTER(host, CONFIG_SOF_LOG_LEVEL); - -SOF_DEFINE_REG_UUID(host); - -DECLARE_TR_CTX(host_tr, SOF_UUID(host_uuid), LOG_LEVEL_INFO); - -static inline struct dma_sg_elem *next_buffer(struct hc_buf *hc) -{ - if (!hc->elem_array.elems || !hc->elem_array.count) - return NULL; - if (++hc->current == hc->elem_array.count) - hc->current = 0; - return hc->elem_array.elems + hc->current; -} - -static uint32_t host_dma_get_split(struct host_data *hd, uint32_t bytes) -{ - struct dma_sg_elem *local_elem = hd->config.elem_array.elems; - uint32_t split_src = 0; - uint32_t split_dst = 0; - - if (local_elem->src + bytes > hd->source->current_end) - split_src = bytes - - (hd->source->current_end - local_elem->src); - - if (local_elem->dest + bytes > hd->sink->current_end) - split_dst = bytes - - (hd->sink->current_end - local_elem->dest); - - /* get max split, so the current copy will be minimum */ - return MAX(split_src, split_dst); -} - -#if CONFIG_FORCE_DMA_COPY_WHOLE_BLOCK - -static int host_dma_set_config_and_copy(struct host_data *hd, struct comp_dev *dev, uint32_t bytes) -{ - struct dma_sg_elem *local_elem = hd->config.elem_array.elems; - int ret = 0; - - local_elem->size = bytes; - - /* reconfigure transfer */ - ret = dma_set_config_legacy(hd->chan, &hd->config); - if (ret < 0) { - comp_err(dev, "host_dma_set_config_and_copy(): dma_set_config() failed, ret = %d", - ret); - return ret; - } - - ret = dma_copy_legacy(hd->chan, bytes, DMA_COPY_ONE_SHOT | DMA_COPY_BLOCKING); - if (ret < 0) { - comp_err(dev, "host_dma_set_config_and_copy(): dma_copy() failed, ret = %d", - ret); - return ret; - } - - return ret; -} - -/** - * Calculates bytes to be copied in one shot mode. - * @param dev Host component device. - * @return Bytes to be copied. - */ -static uint32_t host_get_copy_bytes_one_shot(struct host_data *hd, struct comp_dev *dev) -{ - uint32_t copy_bytes; - - /* calculate minimum size to copy */ - if (dev->direction == SOF_IPC_STREAM_PLAYBACK) - copy_bytes = audio_stream_get_free_bytes(&hd->local_buffer->stream); - else - copy_bytes = audio_stream_get_avail_bytes(&hd->local_buffer->stream); - - /* copy_bytes should be aligned to minimum possible chunk of - * data to be copied by dma. - */ - return ALIGN_DOWN(copy_bytes, hd->dma_copy_align); -} - -/** - * Performs copy operation for host component working in one shot mode. - * It means DMA needs to be reconfigured after every transfer. - * @param dev Host component device. - * @return 0 if succeeded, error code otherwise. - */ -static int host_copy_one_shot(struct host_data *hd, struct comp_dev *dev, copy_callback_t cb) -{ - uint32_t copy_bytes = 0; - uint32_t split_value = 0; - int ret = 0; - - comp_dbg(dev, "host_copy_one_shot()"); - - copy_bytes = host_get_copy_bytes_one_shot(hd, dev); - if (!copy_bytes) { - comp_info(dev, "host_copy_one_shot(): no bytes to copy"); - return ret; - } - - while (copy_bytes) { - /* get split value */ - split_value = host_dma_get_split(hd, copy_bytes); - copy_bytes -= split_value; - - ret = host_dma_set_config_and_copy(hd, dev, copy_bytes); - if (ret < 0) - return ret; - - /* update copy bytes */ - copy_bytes = split_value; - } - - return ret; -} - -#else /* CONFIG_FORCE_DMA_COPY_WHOLE_BLOCK */ - -/** - * Calculates bytes to be copied in one shot mode. - * @param dev Host component device. - * @return Bytes to be copied. - */ -static uint32_t host_get_copy_bytes_one_shot(struct host_data *hd, struct comp_dev *dev) -{ - struct dma_sg_elem *local_elem = hd->config.elem_array.elems; - uint32_t copy_bytes; - uint32_t split_value; - - /* calculate minimum size to copy */ - if (dev->direction == SOF_IPC_STREAM_PLAYBACK) - copy_bytes = audio_stream_get_free_bytes(&hd->local_buffer->stream); - else - copy_bytes = audio_stream_get_avail_bytes(&hd->local_buffer->stream); - - /* copy_bytes should be aligned to minimum possible chunk of - * data to be copied by dma. - */ - copy_bytes = ALIGN_DOWN(copy_bytes, hd->dma_copy_align); - - split_value = host_dma_get_split(hd, copy_bytes); - if (!IS_ENABLED(CONFIG_DISABLE_DESCRIPTOR_SPLIT) && split_value) - copy_bytes -= split_value; - - local_elem->size = copy_bytes; - - return copy_bytes; -} - -/** - * Performs copy operation for host component working in one shot mode. - * It means DMA needs to be reconfigured after every transfer. - * @param dev Host component device. - * @return 0 if succeeded, error code otherwise. - */ -static int host_copy_one_shot(struct host_data *hd, struct comp_dev *dev, copy_callback_t cb) -{ - uint32_t copy_bytes = 0; - int ret = 0; - - comp_dbg(dev, "host_copy_one_shot()"); - - copy_bytes = host_get_copy_bytes_one_shot(hd, dev); - if (!copy_bytes) { - comp_info(dev, "host_copy_one_shot(): no bytes to copy"); - return ret; - } - - /* reconfigure transfer */ - ret = dma_set_config_legacy(hd->chan, &hd->config); - if (ret < 0) { - comp_err(dev, "host_copy_one_shot(): dma_set_config() failed, ret = %u", ret); - return ret; - } - - ret = dma_copy_legacy(hd->chan, copy_bytes, DMA_COPY_ONE_SHOT); - if (ret < 0) { - comp_err(dev, "host_copy_one_shot(): dma_copy() failed, ret = %u", ret); - return ret; - } - - return ret; -} -#endif - -void host_common_update(struct host_data *hd, struct comp_dev *dev, uint32_t bytes) -{ - struct comp_buffer *source; - struct comp_buffer *sink; - int ret; - bool update_mailbox = false; - bool send_ipc = false; - - if (dev->direction == SOF_IPC_STREAM_PLAYBACK) { - source = hd->dma_buffer; - sink = hd->local_buffer; - ret = dma_buffer_copy_from(source, sink, hd->process, bytes, DUMMY_CHMAP); - } else { - source = hd->local_buffer; - sink = hd->dma_buffer; - ret = dma_buffer_copy_to(source, sink, hd->process, bytes, DUMMY_CHMAP); - } - - /* assert dma_buffer_copy succeed */ - if (ret < 0) - comp_err(dev, "host_common_update() dma buffer copy failed, dir %d bytes %d avail %d free %d", - dev->direction, bytes, - audio_stream_get_avail_samples(&source->stream) * - audio_stream_frame_bytes(&source->stream), - audio_stream_get_free_samples(&sink->stream) * - audio_stream_frame_bytes(&sink->stream)); - - if (ret < 0) - return; - - hd->total_data_processed += bytes; - - /* new local period, update host buffer position blks - * local_pos is queried by the ops.position() API - */ - hd->local_pos += bytes; - - /* buffer overlap, hardcode host buffer size at the moment */ - if (hd->local_pos >= hd->host_size) -#if CONFIG_WRAP_ACTUAL_POSITION - hd->local_pos %= hd->host_size; -#else - hd->local_pos = 0; -#endif - if (hd->cont_update_posn) - update_mailbox = true; - - /* Don't send stream position if no_stream_position == 1 */ - if (!hd->no_stream_position) { - hd->report_pos += bytes; - - /* host_period_bytes is set to zero to disable position update - * by IPC for FW version before 3.11, so send IPC message to - * driver according to this condition and report_pos. - */ - if (hd->host_period_bytes != 0 && - hd->report_pos >= hd->host_period_bytes) { - hd->report_pos = 0; - - /* send timestamped position to host - * (updates position first, by calling ops.position()) - */ - update_mailbox = true; - send_ipc = true; - } - } - - if (update_mailbox) { - pipeline_get_timestamp(dev->pipeline, dev, &hd->posn); - mailbox_stream_write(dev->pipeline->posn_offset, - &hd->posn, sizeof(hd->posn)); - if (send_ipc) - ipc_msg_send(hd->msg, &hd->posn, false); - } -} - -/* The host memory is not guaranteed to be continuous and also not guaranteed - * to have a period/buffer size that is a multiple of the DSP period size. - * This means we must check we do not overflow host period/buffer/page - * boundaries on each transfer and split the DMA transfer if we do overflow. - */ -void host_common_one_shot(struct host_data *hd, uint32_t bytes) -{ - struct dma_sg_elem *local_elem = hd->config.elem_array.elems; - struct dma_sg_elem *source_elem; - struct dma_sg_elem *sink_elem; - - /* update src and dest positions and check for overflow */ - local_elem->src += bytes; - local_elem->dest += bytes; - - if (local_elem->src == hd->source->current_end) { - /* end of element, so use next */ - source_elem = next_buffer(hd->source); - if (source_elem) { - hd->source->current_end = source_elem->src + - source_elem->size; - local_elem->src = source_elem->src; - } - } - - if (local_elem->dest == hd->sink->current_end) { - /* end of element, so use next */ - sink_elem = next_buffer(hd->sink); - if (sink_elem) { - hd->sink->current_end = sink_elem->dest + - sink_elem->size; - local_elem->dest = sink_elem->dest; - } - } -} - -/* This is called by DMA driver every time when DMA completes its current - * transfer between host and DSP. - */ -static void host_dma_cb(void *arg, enum notify_id type, void *data) -{ - struct dma_cb_data *next = data; - struct comp_dev *dev = arg; - struct host_data *hd = comp_get_drvdata(dev); - uint32_t bytes = next->elem.size; - - comp_dbg(dev, "host_dma_cb() %p", &comp_host); - - /* update position */ - host_common_update(hd, dev, bytes); - - /* callback for one shot copy */ - if (hd->copy_type == COMP_COPY_ONE_SHOT) - host_common_one_shot(hd, bytes); -} - -/** - * Calculates bytes to be copied in normal mode. - * @param dev Host component device. - * @return Bytes to be copied. - */ -static uint32_t host_get_copy_bytes_normal(struct host_data *hd, struct comp_dev *dev) -{ - uint32_t avail_bytes = 0; - uint32_t free_bytes = 0; - uint32_t copy_bytes = 0; - int ret; - - /* get data sizes from DMA */ - ret = dma_get_data_size_legacy(hd->chan, &avail_bytes, &free_bytes); - if (ret < 0) { - comp_err(dev, "host_get_copy_bytes_normal(): dma_get_data_size() failed, ret = %u", - ret); - /* return 0 copy_bytes in case of error to skip DMA copy */ - return 0; - } - - /* calculate minimum size to copy */ - if (dev->direction == SOF_IPC_STREAM_PLAYBACK) { - /* limit bytes per copy to one period for the whole pipeline - * in order to avoid high load spike - */ - free_bytes = audio_stream_get_free_bytes(&hd->local_buffer->stream); - copy_bytes = MIN(hd->period_bytes, MIN(avail_bytes, free_bytes)); - if (!copy_bytes) - comp_info(dev, "no bytes to copy, %d free in buffer, %d available in DMA", - free_bytes, avail_bytes); - } else { - avail_bytes = audio_stream_get_avail_bytes(&hd->local_buffer->stream); - copy_bytes = MIN(avail_bytes, free_bytes); - if (!copy_bytes) - comp_info(dev, "no bytes to copy, %d avail in buffer, %d free in DMA", - avail_bytes, free_bytes); - } - - /* copy_bytes should be aligned to minimum possible chunk of - * data to be copied by dma. - */ - return ALIGN_DOWN(copy_bytes, hd->dma_copy_align); -} - -/** - * Performs copy operation for host component working in normal mode. - * It means DMA works continuously and doesn't need reconfiguration. - * @param dev Host component device. - * @return 0 if succeeded, error code otherwise. - */ -static int host_copy_normal(struct host_data *hd, struct comp_dev *dev, copy_callback_t cb) -{ - uint32_t copy_bytes = 0; - uint32_t flags = 0; - int ret; - - comp_dbg(dev, "host_copy_normal()"); - - if (hd->copy_type == COMP_COPY_BLOCKING) - flags |= DMA_COPY_BLOCKING; - - copy_bytes = host_get_copy_bytes_normal(hd, dev); - if (!copy_bytes) - return 0; - - ret = dma_copy_legacy(hd->chan, copy_bytes, flags); - if (ret < 0) - comp_err(dev, "host_copy_normal(): dma_copy() failed, ret = %u", ret); - - return ret; -} - -static int create_local_elems(struct host_data *hd, struct comp_dev *dev, uint32_t buffer_count, - uint32_t buffer_bytes) -{ - struct dma_sg_elem_array *elem_array; - uint32_t dir; - int err; - - dir = dev->direction == SOF_IPC_STREAM_PLAYBACK ? - DMA_DIR_HMEM_TO_LMEM : DMA_DIR_LMEM_TO_HMEM; - - /* if host buffer set we need to allocate local buffer */ - if (hd->host.elem_array.count) { - elem_array = &hd->local.elem_array; - - /* config buffer will be used as proxy */ - err = dma_sg_alloc(&hd->config.elem_array, SOF_MEM_ZONE_RUNTIME, - dir, 1, 0, 0, 0); - if (err < 0) { - comp_err(dev, "create_local_elems(): dma_sg_alloc() failed"); - return err; - } - } else { - elem_array = &hd->config.elem_array; - } - - err = dma_sg_alloc(elem_array, SOF_MEM_ZONE_RUNTIME, dir, buffer_count, - buffer_bytes, - (uintptr_t)(audio_stream_get_addr(&hd->dma_buffer->stream)), 0); - if (err < 0) { - comp_err(dev, "create_local_elems(): dma_sg_alloc() failed"); - return err; - } - - return 0; -} - -/** - * \brief Command handler. - * \param[in,out] dev Device - * \param[in] cmd Command - * \return 0 if successful, error code otherwise. - * - * Used to pass standard and bespoke commands (with data) to component. - * This function is common for all dma types, with one exception: - * dw-dma is run on demand, so no start()/stop() is issued. - */ -int host_common_trigger(struct host_data *hd, struct comp_dev *dev, int cmd) -{ - int ret; - - /* we should ignore any trigger commands besides start - * when doing one shot, because transfers will stop automatically - */ - if (cmd != COMP_TRIGGER_START && hd->copy_type == COMP_COPY_ONE_SHOT) - return 0; - - if (!hd->chan) { - comp_err(dev, "host_trigger(): no dma channel configured"); - return -EINVAL; - } - - switch (cmd) { - case COMP_TRIGGER_START: - ret = dma_start_legacy(hd->chan); - if (ret < 0) - comp_err(dev, "host_trigger(): dma_start() failed, ret = %u", - ret); - break; - case COMP_TRIGGER_STOP: - case COMP_TRIGGER_XRUN: - ret = dma_stop_legacy(hd->chan); - if (ret < 0) - comp_err(dev, "host_trigger(): dma stop failed: %d", - ret); - break; - default: - ret = 0; - break; - } - - return ret; -} - -static int host_trigger(struct comp_dev *dev, int cmd) -{ - struct host_data *hd = comp_get_drvdata(dev); - int ret; - - comp_dbg(dev, "host_trigger()"); - - ret = comp_set_state(dev, cmd); - if (ret < 0) - return ret; - - if (ret == COMP_STATUS_STATE_ALREADY_SET) - return PPL_STATUS_PATH_STOP; - - return host_common_trigger(hd, dev, cmd); -} - -int host_common_new(struct host_data *hd, struct comp_dev *dev, - const struct ipc_config_host *ipc_host, uint32_t config_id) -{ - uint32_t dir; - - hd->ipc_host = *ipc_host; - /* request HDA DMA with shared access privilege */ - dir = hd->ipc_host.direction == SOF_IPC_STREAM_PLAYBACK ? - DMA_DIR_HMEM_TO_LMEM : DMA_DIR_LMEM_TO_HMEM; - - hd->dma = dma_get(dir, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED); - if (!hd->dma) { - comp_err(dev, "host_common_new(): dma_get() returned NULL"); - return -ENODEV; - } - - /* init buffer elems */ - dma_sg_init(&hd->config.elem_array); - dma_sg_init(&hd->host.elem_array); - dma_sg_init(&hd->local.elem_array); - - ipc_build_stream_posn(&hd->posn, SOF_IPC_STREAM_POSITION, config_id); - - hd->msg = ipc_msg_init(hd->posn.rhdr.hdr.cmd, hd->posn.rhdr.hdr.size); - if (!hd->msg) { - comp_err(dev, "host_common_new(): ipc_msg_init failed"); - dma_put(hd->dma); - return -ENOMEM; - } - hd->chan = NULL; - hd->copy_type = COMP_COPY_NORMAL; - - return 0; -} - -static struct comp_dev *host_new(const struct comp_driver *drv, - const struct comp_ipc_config *config, - const void *spec) -{ - struct comp_dev *dev; - struct host_data *hd; - const struct ipc_config_host *ipc_host = spec; - int ret; - - comp_cl_dbg(&comp_host, "host_new()"); - - dev = comp_alloc(drv, sizeof(*dev)); - if (!dev) - return NULL; - dev->ipc_config = *config; - - hd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*hd)); - if (!hd) - goto e_data; - - comp_set_drvdata(dev, hd); - - ret = host_common_new(hd, dev, ipc_host, dev->ipc_config.id); - if (ret) - goto e_dev; - - dev->state = COMP_STATE_READY; - - return dev; - -e_dev: - rfree(hd); -e_data: - rfree(dev); - return NULL; -} - -void host_common_free(struct host_data *hd) -{ - dma_put(hd->dma); - - ipc_msg_free(hd->msg); - dma_sg_free(&hd->config.elem_array); -} - -static void host_free(struct comp_dev *dev) -{ - struct host_data *hd = comp_get_drvdata(dev); - - comp_dbg(dev, "host_free()"); - host_common_free(hd); - rfree(hd); - rfree(dev); -} - -static int host_elements_reset(struct host_data *hd, struct comp_dev *dev) -{ - struct dma_sg_elem *source_elem; - struct dma_sg_elem *sink_elem; - struct dma_sg_elem *local_elem; - - /* setup elem to point to first source elem */ - source_elem = hd->source->elem_array.elems; - if (source_elem) { - hd->source->current = 0; - hd->source->current_end = source_elem->src + source_elem->size; - } - - /* setup elem to point to first sink elem */ - sink_elem = hd->sink->elem_array.elems; - if (sink_elem) { - hd->sink->current = 0; - hd->sink->current_end = sink_elem->dest + sink_elem->size; - } - - /* local element */ - if (source_elem && sink_elem) { - local_elem = hd->config.elem_array.elems; - local_elem->dest = sink_elem->dest; - local_elem->size = - dev->direction == SOF_IPC_STREAM_PLAYBACK ? - sink_elem->size : source_elem->size; - local_elem->src = source_elem->src; - } - - return 0; -} - -static int host_verify_params(struct comp_dev *dev, - struct sof_ipc_stream_params *params) -{ - int ret; - - comp_dbg(dev, "host_verify_params()"); - - ret = comp_verify_params(dev, 0, params); - if (ret < 0) { - comp_err(dev, "host_verify_params(): comp_verify_params() failed"); - return ret; - } - - return 0; -} - -/* configure the DMA params and descriptors for host buffer IO */ -int host_common_params(struct host_data *hd, struct comp_dev *dev, - struct sof_ipc_stream_params *params, notifier_callback_t cb) -{ - struct dma_sg_config *config = &hd->config; - uint32_t period_count; - uint32_t period_bytes; - uint32_t buffer_size; - uint32_t addr_align; - uint32_t align; - int err; - - /* host params always installed by pipeline IPC */ - hd->host_size = params->buffer.size; - hd->stream_tag = params->stream_tag; - hd->no_stream_position = params->no_stream_position; - hd->host_period_bytes = params->host_period_bytes; - hd->cont_update_posn = params->cont_update_posn; - - /* retrieve DMA buffer address alignment */ - err = dma_get_attribute_legacy(hd->dma, DMA_ATTR_BUFFER_ADDRESS_ALIGNMENT, - &addr_align); - if (err < 0) { - comp_err(dev, "host_params(): could not get dma buffer address alignment, err = %d", - err); - return err; - } - - /* retrieve DMA buffer size alignment */ - err = dma_get_attribute_legacy(hd->dma, DMA_ATTR_BUFFER_ALIGNMENT, &align); - if (err < 0 || !align) { - comp_err(dev, "host_params(): could not get valid dma buffer alignment, err = %d, align = %u", - err, align); - return -EINVAL; - } - - /* retrieve DMA buffer period count */ - err = dma_get_attribute_legacy(hd->dma, DMA_ATTR_BUFFER_PERIOD_COUNT, - &period_count); - if (err < 0 || !period_count) { - comp_err(dev, "host_params(): could not get valid dma buffer period count, err = %d, period_count = %u", - err, period_count); - return -EINVAL; - } - - if (dev->direction == SOF_IPC_STREAM_PLAYBACK) - hd->local_buffer = comp_dev_get_first_data_consumer(dev); - else - hd->local_buffer = comp_dev_get_first_data_producer(dev); - - period_bytes = dev->frames * - audio_stream_frame_bytes(&hd->local_buffer->stream); - - if (!period_bytes) { - comp_err(dev, "host_params(): invalid period_bytes"); - err = -EINVAL; - goto out; - } - - /* determine source and sink buffer elements */ - if (dev->direction == SOF_IPC_STREAM_PLAYBACK) { - config->direction = DMA_DIR_HMEM_TO_LMEM; - hd->source = &hd->host; - hd->sink = &hd->local; - } else { - config->direction = DMA_DIR_LMEM_TO_HMEM; - hd->source = &hd->local; - hd->sink = &hd->host; - } - - /* TODO: should be taken from DMA */ - if (hd->host.elem_array.count) { - period_bytes *= period_count; - period_count = 1; - } - - /* calculate DMA buffer size */ - buffer_size = ALIGN_UP(period_bytes, align) * period_count; - buffer_size = MAX(buffer_size, ALIGN_UP(hd->ipc_host.dma_buffer_size, align)); - - /* alloc DMA buffer or change its size if exists */ - /* - * Host DMA buffer cannot be shared. So we actually don't need to lock, - * but we have to write back caches after we finish anyway - */ - if (hd->dma_buffer) { - err = buffer_set_size(hd->dma_buffer, buffer_size, addr_align); - if (err < 0) { - comp_err(dev, "host_params(): buffer_set_size() failed, buffer_size = %u", - buffer_size); - goto out; - } - } else { - hd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA, 0, - addr_align, false); - if (!hd->dma_buffer) { - comp_err(dev, "host_params(): failed to alloc dma buffer"); - err = -ENOMEM; - goto out; - } - - buffer_set_params(hd->dma_buffer, params, BUFFER_UPDATE_FORCE); - } - - /* create SG DMA elems for local DMA buffer */ - err = create_local_elems(hd, dev, period_count, buffer_size / period_count); - if (err < 0) - goto out; - - /* set up DMA configuration - copy in sample bytes. */ - config->src_width = audio_stream_sample_bytes(&hd->local_buffer->stream); - config->dest_width = audio_stream_sample_bytes(&hd->local_buffer->stream); - config->cyclic = 0; - config->irq_disabled = pipeline_is_timer_driven(dev->pipeline); - config->is_scheduling_source = comp_is_scheduling_source(dev); - config->period = dev->pipeline->period; - - host_elements_reset(hd, dev); - - hd->stream_tag -= 1; - /* get DMA channel from DMAC - * note: stream_tag is ignored by dw-dma - */ - hd->chan = dma_channel_get_legacy(hd->dma, hd->stream_tag); - if (!hd->chan) { - comp_err(dev, "host_params(): hd->chan is NULL"); - err = -ENODEV; - goto out; - } - - err = dma_set_config_legacy(hd->chan, &hd->config); - if (err < 0) { - comp_err(dev, "host_params(): dma_set_config() failed"); - dma_channel_put_legacy(hd->chan); - hd->chan = NULL; - goto out; - } - - err = dma_get_attribute_legacy(hd->dma, DMA_ATTR_COPY_ALIGNMENT, - &hd->dma_copy_align); - - if (err < 0) { - comp_err(dev, "host_params(): dma_get_attribute()"); - - goto out; - } - - /* minimal copied data shouldn't be less than alignment */ - hd->period_bytes = ALIGN_UP(period_bytes, hd->dma_copy_align); - - /* set copy function */ - hd->copy = hd->copy_type == COMP_COPY_ONE_SHOT ? host_copy_one_shot : - host_copy_normal; - - /* set processing function */ - hd->process = - pcm_get_conversion_function(audio_stream_get_frm_fmt(&hd->local_buffer->stream), - audio_stream_get_frm_fmt(&hd->local_buffer->stream)); - -out: - - hd->cb_dev = dev; - - if (err >= 0) - /* set up callback */ - notifier_register(dev, hd->chan, NOTIFIER_ID_DMA_COPY, - cb ? : host_dma_cb, 0); - - return err; -} - -static int host_params(struct comp_dev *dev, - struct sof_ipc_stream_params *params) -{ - struct host_data *hd = comp_get_drvdata(dev); - int err; - - comp_dbg(dev, "host_params()"); - - err = host_verify_params(dev, params); - if (err < 0) { - comp_err(dev, "host_params(): pcm params verification failed."); - return err; - } - - return host_common_params(hd, dev, params, NULL); -} - -int host_common_prepare(struct host_data *hd) -{ - buffer_zero(hd->dma_buffer); - return 0; -} - -static int host_prepare(struct comp_dev *dev) -{ - struct host_data *hd = comp_get_drvdata(dev); - int ret; - - comp_dbg(dev, "host_prepare()"); - - ret = comp_set_state(dev, COMP_TRIGGER_PREPARE); - if (ret < 0) - return ret; - - if (ret == COMP_STATUS_STATE_ALREADY_SET) - return PPL_STATUS_PATH_STOP; - - return host_common_prepare(hd); -} - -static int host_position(struct comp_dev *dev, - struct sof_ipc_stream_posn *posn) -{ - struct host_data *hd = comp_get_drvdata(dev); - - /* TODO: improve accuracy by adding current DMA position */ - posn->host_posn = hd->local_pos; - - return 0; -} - -void host_common_reset(struct host_data *hd, uint16_t state) -{ - if (hd->chan) { - dma_stop_delayed_legacy(hd->chan); - - /* remove callback */ - notifier_unregister(hd->cb_dev, hd->chan, NOTIFIER_ID_DMA_COPY); - - dma_channel_put_legacy(hd->chan); - hd->chan = NULL; - } - - /* free all DMA elements */ - dma_sg_free(&hd->host.elem_array); - dma_sg_free(&hd->local.elem_array); - dma_sg_free(&hd->config.elem_array); - - /* It's safe that cleaning out `hd->config` after `dma_sg_free` for config.elem_array */ - memset(&hd->config, 0, sizeof(hd->config)); - - /* free DMA buffer */ - if (hd->dma_buffer) { - buffer_free(hd->dma_buffer); - hd->dma_buffer = NULL; - } - - /* reset buffer pointers */ - hd->local_pos = 0; - hd->report_pos = 0; - hd->total_data_processed = 0; - - hd->copy_type = COMP_COPY_NORMAL; - hd->source = NULL; - hd->sink = NULL; -} - -static int host_reset(struct comp_dev *dev) -{ - struct host_data *hd = comp_get_drvdata(dev); - - comp_dbg(dev, "host_reset()"); - - host_common_reset(hd, dev->state); - dev->state = COMP_STATE_READY; - - return 0; -} - -static int host_copy(struct comp_dev *dev) -{ - struct host_data *hd = comp_get_drvdata(dev); - - if (dev->state != COMP_STATE_ACTIVE) - return 0; - - return host_common_copy(hd, dev, NULL); -} - -static int host_get_attribute(struct comp_dev *dev, uint32_t type, - void *value) -{ - struct host_data *hd = comp_get_drvdata(dev); - - switch (type) { - case COMP_ATTR_COPY_TYPE: - *(enum comp_copy_type *)value = hd->copy_type; - break; - case COMP_ATTR_COPY_DIR: - *(uint32_t *)value = hd->ipc_host.direction; - break; - default: - return -EINVAL; - } - - return 0; -} - -static int host_set_attribute(struct comp_dev *dev, uint32_t type, - void *value) -{ - struct host_data *hd = comp_get_drvdata(dev); - - switch (type) { - case COMP_ATTR_COPY_TYPE: - hd->copy_type = *(enum comp_copy_type *)value; - break; - case COMP_ATTR_HOST_BUFFER: - hd->host.elem_array = *(struct dma_sg_elem_array *)value; - break; - default: - return -EINVAL; - } - - return 0; -} - -static uint64_t host_get_processed_data(struct comp_dev *dev, uint32_t stream_no, bool input) -{ - struct host_data *hd = comp_get_drvdata(dev); - uint64_t ret = 0; - bool source = dev->direction == SOF_IPC_STREAM_PLAYBACK; - - /* Return value only if direction and stream number match. - * The host supports only one stream. - */ - if (stream_no == 0 && source == input) - ret = hd->total_data_processed; - - return ret; -} - -static const struct comp_driver comp_host = { - .type = SOF_COMP_HOST, - .uid = SOF_RT_UUID(host_uuid), - .tctx = &host_tr, - .ops = { - .create = host_new, - .free = host_free, - .params = host_params, - .reset = host_reset, - .trigger = host_trigger, - .copy = host_copy, - .prepare = host_prepare, - .position = host_position, - .get_attribute = host_get_attribute, - .set_attribute = host_set_attribute, - .get_total_data_processed = host_get_processed_data, - }, -}; - -static SHARED_DATA struct comp_driver_info comp_host_info = { - .drv = &comp_host, -}; - -UT_STATIC void sys_comp_host_init(void) -{ - comp_register(platform_shared_get(&comp_host_info, - sizeof(comp_host_info))); -} - -DECLARE_MODULE(sys_comp_host_init); -SOF_MODULE_INIT(host, sys_comp_host_init); diff --git a/src/audio/module_adapter/module_adapter.c b/src/audio/module_adapter/module_adapter.c index 7311bbcf87e9..d1b919b97b80 100644 --- a/src/audio/module_adapter/module_adapter.c +++ b/src/audio/module_adapter/module_adapter.c @@ -1339,11 +1339,7 @@ EXPORT_SYMBOL(module_adapter_ts_stop_op); * 0 - success * value < 0 - failure. */ -#if CONFIG_ZEPHYR_NATIVE_DRIVERS int module_adapter_ts_get_op(struct comp_dev *dev, struct dai_ts_data *tsd) -#else -int module_adapter_ts_get_op(struct comp_dev *dev, struct timestamp_data *tsd) -#endif { struct processing_module *mod = comp_mod(dev); const struct module_interface *const interface = mod->dev->drv->adapter_ops; diff --git a/src/drivers/imx/ipc.c b/src/drivers/imx/ipc.c index 1b398088cb1c..4e55c446efe7 100644 --- a/src/drivers/imx/ipc.c +++ b/src/drivers/imx/ipc.c @@ -205,13 +205,10 @@ int platform_ipc_init(struct ipc *ipc) PLATFORM_PAGE_TABLE_SIZE); if (iipc->dh_buffer.page_table) bzero(iipc->dh_buffer.page_table, PLATFORM_PAGE_TABLE_SIZE); -#if CONFIG_ZEPHYR_NATIVE_DRIVERS + iipc->dh_buffer.dmac = sof_dma_get(SOF_DMA_DIR_HMEM_TO_LMEM, 0, SOF_DMA_DEV_HOST, SOF_DMA_ACCESS_SHARED); -#else - iipc->dh_buffer.dmac = dma_get(SOF_DMA_DIR_HMEM_TO_LMEM, 0, SOF_DMA_DEV_HOST, - SOF_DMA_ACCESS_SHARED); -#endif + if (!iipc->dh_buffer.dmac) { tr_err(&ipc_tr, "Unable to find DMA for host page table"); sof_panic(SOF_IPC_PANIC_IPC); diff --git a/src/include/sof/audio/component.h b/src/include/sof/audio/component.h index 337730ccae7d..14523f6da98d 100644 --- a/src/include/sof/audio/component.h +++ b/src/include/sof/audio/component.h @@ -501,12 +501,7 @@ struct comp_ops { * Mandatory for components that allocate DAI. * Usually shouldn't be __cold. */ -#if CONFIG_ZEPHYR_NATIVE_DRIVERS int (*dai_ts_get)(struct comp_dev *dev, struct dai_ts_data *tsd); -#else - int (*dai_ts_get)(struct comp_dev *dev, - struct timestamp_data *tsd); -#endif /** * Bind, atomic - used to notify component of bind event. diff --git a/src/include/sof/audio/module_adapter/module/generic.h b/src/include/sof/audio/module_adapter/module/generic.h index fb7f4ca02202..7b1de5a82402 100644 --- a/src/include/sof/audio/module_adapter/module/generic.h +++ b/src/include/sof/audio/module_adapter/module/generic.h @@ -306,11 +306,7 @@ int module_adapter_position(struct comp_dev *dev, struct sof_ipc_stream_posn *po int module_adapter_ts_config_op(struct comp_dev *dev); int module_adapter_ts_start_op(struct comp_dev *dev); int module_adapter_ts_stop_op(struct comp_dev *dev); -#if CONFIG_ZEPHYR_NATIVE_DRIVERS int module_adapter_ts_get_op(struct comp_dev *dev, struct dai_ts_data *tsd); -#else -int module_adapter_ts_get_op(struct comp_dev *dev, struct timestamp_data *tsd); -#endif void module_update_buffer_position(struct input_stream_buffer *input_buffers, struct output_stream_buffer *output_buffers, diff --git a/src/include/sof/audio/module_adapter/module/module_interface.h b/src/include/sof/audio/module_adapter/module/module_interface.h index ccddcf6fda0a..b27f3e21f037 100644 --- a/src/include/sof/audio/module_adapter/module/module_interface.h +++ b/src/include/sof/audio/module_adapter/module/module_interface.h @@ -77,11 +77,7 @@ struct module_endpoint_ops { * * Mandatory for components that allocate DAI. */ -#if CONFIG_ZEPHYR_NATIVE_DRIVERS int (*dai_ts_get)(struct comp_dev *dev, struct dai_ts_data *tsd); -#else - int (*dai_ts_get)(struct comp_dev *dev, struct timestamp_data *tsd); -#endif /** * Fetches hardware stream parameters. diff --git a/src/ipc/ipc3/dai.c b/src/ipc/ipc3/dai.c index 17b12aeefc26..cdf367536db9 100644 --- a/src/ipc/ipc3/dai.c +++ b/src/ipc/ipc3/dai.c @@ -63,20 +63,12 @@ int dai_config_dma_channel(struct dai_data *dd, struct comp_dev *dev, const void case SOF_DAI_IMX_ESAI: handshake = dai_get_handshake(dd->dai, dai->direction, dd->stream_id); -/* TODO: remove this when transition to native drivers is complete on all NXP platforms */ -#ifndef CONFIG_ZEPHYR_NATIVE_DRIVERS - channel = EDMA_HS_GET_CHAN(handshake); -#else channel = handshake & GENMASK(7, 0); -#endif /* CONFIG_ZEPHYR_NATIVE_DRIVERS */ break; case SOF_DAI_IMX_MICFIL: channel = dai_get_handshake(dd->dai, dai->direction, dd->stream_id); -/* TODO: remove ifdef when transitioning to native drivers is complete on all NXP platforms */ -#ifdef CONFIG_ZEPHYR_NATIVE_DRIVERS channel = channel & GENMASK(7, 0); -#endif break; case SOF_DAI_AMD_BT: channel = dai_get_handshake(dd->dai, dai->direction, @@ -289,11 +281,7 @@ void dai_dma_release(struct dai_data *dd, struct comp_dev *dev) if (dd->chan) { /* remove callback */ notifier_unregister(dev, dd->chan, NOTIFIER_ID_DMA_COPY); -#if CONFIG_ZEPHYR_NATIVE_DRIVERS dma_release_channel(dd->chan->dma->z_dev, dd->chan->index); -#else - dma_channel_put_legacy(dd->chan); -#endif dd->chan->dev_data = NULL; dd->chan = NULL; } @@ -339,11 +327,7 @@ int dai_config(struct dai_data *dd, struct comp_dev *dev, struct ipc_config_dai /* stop DMA and reset config for two-step stop DMA */ if (dd->delayed_dma_stop) { -#if CONFIG_ZEPHYR_NATIVE_DRIVERS ret = dma_stop(dd->chan->dma->z_dev, dd->chan->index); -#else - ret = dma_stop_delayed_legacy(dd->chan); -#endif if (ret < 0) return ret; @@ -354,11 +338,7 @@ int dai_config(struct dai_data *dd, struct comp_dev *dev, struct ipc_config_dai case SOF_DAI_CONFIG_FLAGS_PAUSE: if (!dd->chan) return 0; -#if CONFIG_ZEPHYR_NATIVE_DRIVERS return dma_stop(dd->chan->dma->z_dev, dd->chan->index); -#else - return dma_stop_delayed_legacy(dd->chan); -#endif default: break; } diff --git a/src/ipc/ipc3/host-page-table.c b/src/ipc/ipc3/host-page-table.c index 414dd4f57ef0..2f3638dc1200 100644 --- a/src/ipc/ipc3/host-page-table.c +++ b/src/ipc/ipc3/host-page-table.c @@ -81,7 +81,6 @@ static int ipc_parse_page_descriptors(uint8_t *page_table, return 0; } -#ifdef CONFIG_ZEPHYR_NATIVE_DRIVERS /* * Copy the audio buffer page tables from the host to the DSP max of 4K. */ @@ -144,67 +143,6 @@ static int ipc_get_page_descriptors(struct dma *dmac, uint8_t *page_table, return ret; } -#else -static int ipc_get_page_descriptors(struct dma *dmac, uint8_t *page_table, - struct sof_ipc_host_buffer *ring) -{ - struct dma_sg_config config; - struct dma_sg_elem elem; - struct dma_chan_data *chan; - uint32_t dma_copy_align; - int ret = 0; - - /* get DMA channel from DMAC */ - chan = dma_channel_get_legacy(dmac, 0); - if (!chan) { - tr_err(&ipc_tr, "ipc_get_page_descriptors(): chan is NULL"); - return -ENODEV; - } - - /* set up DMA configuration */ - config.direction = DMA_DIR_HMEM_TO_LMEM; - config.src_width = sizeof(uint32_t); - config.dest_width = sizeof(uint32_t); - config.cyclic = 0; - config.irq_disabled = false; - dma_sg_init(&config.elem_array); - - ring->phy_addr = host_to_local(ring->phy_addr); - /* set up DMA descriptor */ - elem.dest = (uintptr_t)page_table; - elem.src = ring->phy_addr; - - /* source buffer size is always PAGE_SIZE bytes */ - /* 20 bits for each page, round up to minimum DMA copy size */ - ret = dma_get_attribute_legacy(dmac, DMA_ATTR_COPY_ALIGNMENT, &dma_copy_align); - if (ret < 0) { - tr_err(&ipc_tr, "ipc_get_page_descriptors(): dma_get_attribute() failed"); - goto out; - } - elem.size = SOF_DIV_ROUND_UP(ring->pages * 20, 8); - elem.size = ALIGN_UP(elem.size, dma_copy_align); - config.elem_array.elems = &elem; - config.elem_array.count = 1; - - ret = dma_set_config_legacy(chan, &config); - if (ret < 0) { - tr_err(&ipc_tr, "ipc_get_page_descriptors(): dma_set_config() failed"); - goto out; - } - - /* start the copy of page table to DSP */ - ret = dma_copy_legacy(chan, elem.size, DMA_COPY_ONE_SHOT | DMA_COPY_BLOCKING); - if (ret < 0) { - tr_err(&ipc_tr, "ipc_get_page_descriptors(): dma_start() failed"); - goto out; - } - - /* compressed page tables now in buffer at _ipc->page_table */ -out: - dma_channel_put_legacy(chan); - return ret; -} -#endif /* CONFIG_ZEPHYR_NATIVE_DRIVERS */ int ipc_process_host_buffer(struct ipc *ipc, struct sof_ipc_host_buffer *ring, diff --git a/src/ipc/ipc4/dai.c b/src/ipc/ipc4/dai.c index b0e1905b6c81..3fd7ec3b8266 100644 --- a/src/ipc/ipc4/dai.c +++ b/src/ipc/ipc4/dai.c @@ -130,9 +130,7 @@ int ipc_dai_data_config(struct dai_data *dd, struct comp_dev *dev) { struct ipc_config_dai *dai = &dd->ipc_config; struct ipc4_copier_module_cfg *copier_cfg = dd->dai_spec_config; -#ifdef CONFIG_ZEPHYR_NATIVE_DRIVERS struct dai *dai_p = dd->dai; -#endif if (!dai) { comp_err(dev, "dai_data_config(): no dai!\n"); @@ -161,12 +159,8 @@ int ipc_dai_data_config(struct dai_data *dd, struct comp_dev *dev) case SOF_DAI_INTEL_HDA: break; case SOF_DAI_INTEL_ALH: -#ifdef CONFIG_ZEPHYR_NATIVE_DRIVERS dd->stream_id = dai_get_stream_id(dai_p, dai->direction); -#else - /* only native Zephyr driver supported */ - return -EINVAL; -#endif + /* SDW HW FIFO always requires 32bit MSB aligned sample data for * all formats, such as 8/16/24/32 bits. */ @@ -226,15 +220,11 @@ void dai_dma_release(struct dai_data *dd, struct comp_dev *dev) * pause to stop. * TODO: refine power management when stream is paused */ -#if CONFIG_ZEPHYR_NATIVE_DRIVERS /* if reset is after pause dma has already been stopped */ dma_stop(dd->chan->dma->z_dev, dd->chan->index); dma_release_channel(dd->chan->dma->z_dev, dd->chan->index); -#else - dma_stop_legacy(dd->chan); - dma_channel_put_legacy(dd->chan); -#endif + dd->chan->dev_data = NULL; dd->chan = NULL; } @@ -399,7 +389,6 @@ __cold int dai_config(struct dai_data *dd, struct comp_dev *dev, return dai_set_config(dd->dai, common_config, copier_cfg->gtw_cfg.config_data); } -#if CONFIG_ZEPHYR_NATIVE_DRIVERS int dai_common_position(struct dai_data *dd, struct comp_dev *dev, struct sof_ipc_stream_posn *posn) { @@ -451,51 +440,3 @@ void dai_dma_position_update(struct dai_data *dd, struct comp_dev *dev) mailbox_sw_regs_write(dd->slot_info.reg_offset, &slot, sizeof(slot)); } -#else -int dai_common_position(struct dai_data *dd, struct comp_dev *dev, - struct sof_ipc_stream_posn *posn) -{ - struct dma_chan_status status; - - /* total processed bytes count */ - posn->dai_posn = dd->total_data_processed; - - platform_dai_wallclock(dev, &dd->wallclock); - posn->wallclock = dd->wallclock; - - status.ipc_posn_data = &posn->comp_posn; - dma_status_legacy(dd->chan, &status, dev->direction); - - return 0; -} - -int dai_position(struct comp_dev *dev, struct sof_ipc_stream_posn *posn) -{ - struct dai_data *dd = comp_get_drvdata(dev); - - return dai_common_position(dd, dev, posn); -} - -void dai_dma_position_update(struct dai_data *dd, struct comp_dev *dev) -{ - struct ipc4_llp_reading_slot slot; - struct dma_chan_status status; - uint32_t llp_data[2]; - - if (!dd->slot_info.node_id) - return; - - status.ipc_posn_data = llp_data; - dma_status_legacy(dd->chan, &status, dev->direction); - - platform_dai_wallclock(dev, &dd->wallclock); - - slot.node_id = dd->slot_info.node_id; - slot.reading.llp_l = llp_data[0]; - slot.reading.llp_u = llp_data[1]; - slot.reading.wclk_l = (uint32_t)dd->wallclock; - slot.reading.wclk_u = (uint32_t)(dd->wallclock >> 32); - - mailbox_sw_regs_write(dd->slot_info.reg_offset, &slot, sizeof(slot)); -} -#endif diff --git a/src/ipc/ipc4/handler.c b/src/ipc/ipc4/handler.c index 16156a29b6db..e7e84c02c2ea 100644 --- a/src/ipc/ipc4/handler.c +++ b/src/ipc/ipc4/handler.c @@ -1503,10 +1503,6 @@ __cold static int ipc4_module_process_dx(struct ipc4_message_request *ipc4) /* do platform specific suspending */ platform_context_save(sof_get()); -#if !defined(CONFIG_LIBRARY) && !defined(CONFIG_ZEPHYR_NATIVE_DRIVERS) - arch_irq_lock(); - platform_timer_stop(timer_get()); -#endif ipc_get()->pm_prepare_D3 = 1; } diff --git a/src/lib/dai.c b/src/lib/dai.c index 9e07a4c66d54..e33f45d65226 100644 --- a/src/lib/dai.c +++ b/src/lib/dai.c @@ -18,10 +18,9 @@ #include #include -#if CONFIG_ZEPHYR_NATIVE_DRIVERS #include #include -#endif + LOG_MODULE_REGISTER(dai, CONFIG_SOF_LOG_LEVEL); SOF_DEFINE_REG_UUID(dai_lib); @@ -136,8 +135,6 @@ __cold void dai_group_put(struct dai_group *group) group->group_id = 0; } -#if CONFIG_ZEPHYR_NATIVE_DRIVERS - #define GET_DEVICE_LIST(node) DEVICE_DT_GET(node), const struct device *zephyr_dev[] = { @@ -308,72 +305,3 @@ void dai_put(struct dai *dai) rfree(dai); } -#else -static inline const struct dai_type_info *dai_find_type(uint32_t type) -{ - const struct dai_info *info = dai_info_get(); - const struct dai_type_info *dti; - - for (dti = info->dai_type_array; - dti < info->dai_type_array + info->num_dai_types; dti++) { - if (dti->type == type) - return dti; - } - return NULL; -} - -struct dai *dai_get(uint32_t type, uint32_t index, uint32_t flags) -{ - int ret = 0; - const struct dai_type_info *dti; - struct dai *d; - k_spinlock_key_t key; - - dti = dai_find_type(type); - if (!dti) - return NULL; /* type not found */ - - for (d = dti->dai_array; d < dti->dai_array + dti->num_dais; d++) { - if (d->index != index) { - continue; - } - /* device created? */ - key = k_spin_lock(&d->lock); - if (d->sref == 0) { - if (flags & DAI_CREAT) - ret = dai_probe(d); - else - ret = -ENODEV; - } - if (!ret) - d->sref++; - - tr_info(&dai_tr, "dai_get type %d index %d new sref %d", - type, index, d->sref); - - k_spin_unlock(&d->lock, key); - - return !ret ? d : NULL; - } - tr_err(&dai_tr, "dai_get: type %d index %d not found", type, index); - return NULL; -} - -void dai_put(struct dai *dai) -{ - int ret; - k_spinlock_key_t key; - - key = k_spin_lock(&dai->lock); - if (--dai->sref == 0) { - ret = dai_remove(dai); - if (ret < 0) { - tr_err(&dai_tr, "dai_put: type %d index %d dai_remove() failed ret = %d", - dai->drv->type, dai->index, ret); - } - } - tr_info(&dai_tr, "dai_put type %d index %d new sref %d", - dai->drv->type, dai->index, dai->sref); - k_spin_unlock(&dai->lock, key); -} -#endif diff --git a/src/lib/dma.c b/src/lib/dma.c index afd7dac001ca..29b738dd7a6e 100644 --- a/src/lib/dma.c +++ b/src/lib/dma.c @@ -33,7 +33,6 @@ SOF_DEFINE_REG_UUID(dma); DECLARE_TR_CTX(dma_tr, SOF_UUID(dma_uuid), LOG_LEVEL_INFO); -#if CONFIG_ZEPHYR_NATIVE_DRIVERS static int dma_init(struct dma *dma); struct dma *sof_dma_get(uint32_t dir, uint32_t cap, uint32_t dev, uint32_t flags) @@ -170,125 +169,6 @@ static int dma_init(struct dma *dma) } EXPORT_SYMBOL(sof_dma_get); EXPORT_SYMBOL(sof_dma_put); -#else -struct dma *dma_get(uint32_t dir, uint32_t cap, uint32_t dev, uint32_t flags) -{ - const struct dma_info *info = dma_info_get(); - int users, ret; - int min_users = INT32_MAX; - struct dma *d = NULL, *dmin = NULL; - k_spinlock_key_t key; - - if (!info->num_dmas) { - tr_err(&dma_tr, "dma_get(): No DMACs installed"); - return NULL; - } - - /* find DMAC with free channels that matches request */ - for (d = info->dma_array; d < info->dma_array + info->num_dmas; - d++) { - /* skip if this DMAC does not support the requested dir */ - if (dir && (d->plat_data.dir & dir) == 0) - continue; - - /* skip if this DMAC does not support the requested caps */ - if (cap && (d->plat_data.caps & cap) == 0) - continue; - - /* skip if this DMAC does not support the requested dev */ - if (dev && (d->plat_data.devs & dev) == 0) - continue; - - /* skip if this DMAC has 1 user per avail channel */ - /* TODO: this should be fixed in dai.c to allow more users */ - if (d->sref >= d->plat_data.channels) - continue; - - /* if exclusive access is requested */ - if (flags & DMA_ACCESS_EXCLUSIVE) { - /* ret DMA with no users */ - if (!d->sref) { - dmin = d; - break; - } - } else { - /* get number of users for this DMAC*/ - users = d->sref; - - /* pick DMAC with the least num of users */ - if (users < min_users) { - dmin = d; - min_users = users; - } - } - } - - if (!dmin) { - tr_err(&dma_tr, "No DMAC dir %d caps 0x%x dev 0x%x flags 0x%x", - dir, cap, dev, flags); - - for (d = info->dma_array; - d < info->dma_array + info->num_dmas; - d++) { - tr_err(&dma_tr, " DMAC ID %d users %d busy channels %ld", - d->plat_data.id, d->sref, - atomic_read(&d->num_channels_busy)); - tr_err(&dma_tr, " caps 0x%x dev 0x%x", - d->plat_data.caps, d->plat_data.devs); - } - - return NULL; - } - - /* return DMAC */ - tr_dbg(&dma_tr, "dma_get(), dma-probe id = %d", - dmin->plat_data.id); - - /* Shared DMA controllers with multiple channels - * may be requested many times, let the probe() - * do on-first-use initialization. - */ - key = k_spin_lock(&dmin->lock); - - ret = 0; - if (!dmin->sref) { - ret = dma_probe_legacy(dmin); - if (ret < 0) { - tr_err(&dma_tr, "dma_get(): dma-probe failed id = %d, ret = %d", - dmin->plat_data.id, ret); - } - } - if (!ret) - dmin->sref++; - - tr_info(&dma_tr, "dma_get() ID %d sref = %d busy channels %ld", - dmin->plat_data.id, dmin->sref, - atomic_read(&dmin->num_channels_busy)); - - k_spin_unlock(&dmin->lock, key); - return !ret ? dmin : NULL; -} - -void dma_put(struct dma *dma) -{ - k_spinlock_key_t key; - int ret; - - key = k_spin_lock(&dma->lock); - if (--dma->sref == 0) { - ret = dma_remove_legacy(dma); - if (ret < 0) { - tr_err(&dma_tr, "dma_put(): dma_remove() failed id = %d, ret = %d", - dma->plat_data.id, ret); - } - } - tr_info(&dma_tr, "dma_put(), dma = %p, sref = %d", - dma, dma->sref); - k_spin_unlock(&dma->lock, key); -} -EXPORT_SYMBOL(dma_get); -EXPORT_SYMBOL(dma_put); -#endif int dma_sg_alloc(struct dma_sg_elem_array *elem_array, enum mem_zone zone, diff --git a/src/probe/probe.c b/src/probe/probe.c index 6892474c9354..5e0f69e7da7b 100644 --- a/src/probe/probe.c +++ b/src/probe/probe.c @@ -119,74 +119,6 @@ static int probe_dma_buffer_init(struct probe_dma_buf *buffer, uint32_t size, return 0; } -#if !CONFIG_ZEPHYR_NATIVE_DRIVERS -/** - * \brief Request DMA and initialize DMA for probes with correct alignment, - * size and specific channel. - * - * \param[out] dma probe returned - * \param[in] direction of the DMA - * \return 0 on success, error code otherwise. - */ -static int probe_dma_init(struct probe_dma_ext *dma, uint32_t direction) -{ - uint32_t elem_addr, addr_align; - const uint32_t elem_size = sizeof(uint64_t) * DMA_ELEM_SIZE; - const uint32_t elem_num = PROBE_BUFFER_LOCAL_SIZE / elem_size; - uint32_t channel; - int err = 0; - -#if CONFIG_IPC_MAJOR_4 - channel = ((union ipc4_connector_node_id)dma->stream_tag).f.v_index + 1; -#else - channel = dma->stream_tag; -#endif - /* request DMA in the dir LMEM->HMEM with shared access */ - dma->dc.dmac = dma_get(direction, 0, SOF_DMA_DEV_HOST, - SOF_DMA_ACCESS_SHARED); - if (!dma->dc.dmac) { - tr_err(&pr_tr, "probe_dma_init(): dma->dc.dmac = NULL"); - return -ENODEV; - } - dma->dc.dmac->priv_data = &dma->dc.dmac->chan->index; - /* get required address alignment for dma buffer */ -#if CONFIG_ZEPHYR_NATIVE_DRIVERS - err = dma_get_attribute(dma->dc.dmac->z_dev, DMA_ATTR_BUFFER_ADDRESS_ALIGNMENT, - &addr_align); -#else - err = dma_get_attribute_legacy(dma->dc.dmac, DMA_ATTR_BUFFER_ADDRESS_ALIGNMENT, - &addr_align); -#endif - if (err < 0) - return err; - - /* initialize dma buffer */ - err = probe_dma_buffer_init(&dma->dmapb, PROBE_BUFFER_LOCAL_SIZE, addr_align); - if (err < 0) - return err; - - err = dma_copy_set_stream_tag(&dma->dc, channel); - if (err < 0) - return err; - - elem_addr = (uint32_t)dma->dmapb.addr; - - dma->config.direction = direction; - dma->config.src_width = sizeof(uint32_t); - dma->config.dest_width = sizeof(uint32_t); - dma->config.cyclic = 0; - - err = dma_sg_alloc(&dma->config.elem_array, SOF_MEM_ZONE_RUNTIME, - dma->config.direction, elem_num, elem_size, elem_addr, 0); - if (err < 0) - return err; - - err = dma_set_config_legacy(dma->dc.chan, &dma->config); - if (err < 0) - return err; - return 0; -} -#else static int probe_dma_init(struct probe_dma_ext *dma, uint32_t direction) { uint32_t addr_align; @@ -246,7 +178,7 @@ static int probe_dma_init(struct probe_dma_ext *dma, uint32_t direction) return 0; } -#endif + /** * \brief Stop, deinit and free DMA and buffer used by probes. * @@ -256,22 +188,13 @@ static int probe_dma_deinit(struct probe_dma_ext *dma) { int err = 0; dma_sg_free(&dma->config.elem_array); -#if CONFIG_ZEPHYR_NATIVE_DRIVERS err = dma_stop(dma->dc.dmac->z_dev, dma->dc.chan->index); -#else - err = dma_stop_legacy(dma->dc.chan); -#endif if (err < 0) { tr_err(&pr_tr, "probe_dma_deinit(): dma_stop() failed"); return err; } -#if CONFIG_ZEPHYR_NATIVE_DRIVERS dma_release_channel(dma->dc.dmac->z_dev, dma->dc.chan->index); sof_dma_put(dma->dc.dmac); -#else - dma_channel_put_legacy(dma->dc.chan); - dma_put(dma->dc.dmac); -#endif rfree((void *)dma->dmapb.addr); dma->dmapb.addr = 0; @@ -295,13 +218,8 @@ static enum task_state probe_task(void *data) if (!_probe->ext_dma.dmapb.avail) return SOF_TASK_STATE_RESCHEDULE; -#if CONFIG_ZEPHYR_NATIVE_DRIVERS err = dma_get_attribute(_probe->ext_dma.dc.dmac->z_dev, DMA_ATTR_COPY_ALIGNMENT, ©_align); -#else - err = dma_get_attribute_legacy(_probe->ext_dma.dc.dmac, DMA_ATTR_COPY_ALIGNMENT, - ©_align); -#endif if (err < 0) { tr_err(&pr_tr, "probe_task(): dma_get_attribute failed."); return SOF_TASK_STATE_COMPLETED; @@ -312,15 +230,8 @@ static enum task_state probe_task(void *data) avail = _probe->ext_dma.dmapb.end_addr - _probe->ext_dma.dmapb.r_ptr; if (avail > 0) -#if CONFIG_ZEPHYR_NATIVE_DRIVERS err = dma_reload(_probe->ext_dma.dc.dmac->z_dev, _probe->ext_dma.dc.chan->index, 0, 0, avail); -#else - err = dma_copy_to_host_nowait(&_probe->ext_dma.dc, - &_probe->ext_dma.config, 0, - (void *)_probe->ext_dma.dmapb.r_ptr, - avail); -#endif else return SOF_TASK_STATE_RESCHEDULE; @@ -375,11 +286,7 @@ int probe_init(const struct probe_dma *probe_dma) _probe->ext_dma.stream_tag = PROBE_DMA_INVALID; return err; } -#if CONFIG_ZEPHYR_NATIVE_DRIVERS err = dma_start(_probe->ext_dma.dc.dmac->z_dev, _probe->ext_dma.dc.chan->index); -#else - err = dma_start_legacy(_probe->ext_dma.dc.chan); -#endif if (err < 0) { tr_err(&pr_tr, "probe_init(): failed to start extraction dma"); @@ -955,17 +862,11 @@ static void probe_cb_produce(void *arg, enum notify_id type, void *data) } dma = &_probe->inject_dma[j]; /* get avail data info */ -#if CONFIG_ZEPHYR_NATIVE_DRIVERS struct dma_status stat; ret = dma_get_status(dma->dc.dmac->z_dev, dma->dc.chan->index, &stat); dma->dmapb.avail = stat.pending_length; free_bytes = stat.free; -#else - ret = dma_get_data_size_legacy(dma->dc.chan, - &dma->dmapb.avail, - &free_bytes); -#endif if (ret < 0) { tr_err(&pr_tr, "probe_cb_produce(): dma_get_data_size() failed, ret = %u", ret); @@ -1007,15 +908,8 @@ static void probe_cb_produce(void *arg, enum notify_id type, void *data) /* check if copy_bytes is still valid for dma copy */ if (copy_bytes > 0) { -#if CONFIG_ZEPHYR_NATIVE_DRIVERS ret = dma_reload(dma->dc.dmac->z_dev, dma->dc.chan->index, 0, 0, copy_bytes); -#else - ret = dma_copy_to_host_nowait(&dma->dc, - &dma->config, 0, - (void *)dma->dmapb.r_ptr, - copy_bytes); -#endif if (ret < 0) goto err; @@ -1236,12 +1130,8 @@ int probe_point_add(uint32_t count, const struct probe_point *probe) return -EINVAL; } -#if CONFIG_ZEPHYR_NATIVE_DRIVERS if (dma_start(_probe->inject_dma[j].dc.dmac->z_dev, _probe->inject_dma[j].dc.chan->index) < 0) { -#else - if (dma_start_legacy(_probe->inject_dma[j].dc.chan) < 0) { -#endif tr_err(&pr_tr, "probe_point_add(): failed to start dma"); return -EBUSY; diff --git a/src/trace/dma-trace.c b/src/trace/dma-trace.c index a1dbda7d10bb..083e4c155667 100644 --- a/src/trace/dma-trace.c +++ b/src/trace/dma-trace.c @@ -196,13 +196,8 @@ int dma_trace_init_complete(struct dma_trace_data *d) "dma_trace_init_complete(): dma_copy_new() failed: %d", ret); goto out; } -#if CONFIG_ZEPHYR_NATIVE_DRIVERS ret = dma_get_attribute(d->dc.dmac->z_dev, DMA_ATTR_COPY_ALIGNMENT, &d->dma_copy_align); -#else - ret = dma_get_attribute_legacy(d->dc.dmac, DMA_ATTR_COPY_ALIGNMENT, - &d->dma_copy_align); -#endif if (ret < 0) { mtrace_printf(LOG_LEVEL_ERROR, "dma_trace_init_complete(): dma_get_attribute() failed: %d", ret); @@ -273,13 +268,8 @@ static int dma_trace_buffer_init(struct dma_trace_data *d) "dma_trace_buffer_init() failed, no DMAC! d=%p", d); return -ENODEV; } -#if CONFIG_ZEPHYR_NATIVE_DRIVERS err = dma_get_attribute(d->dc.dmac->z_dev, DMA_ATTR_BUFFER_ADDRESS_ALIGNMENT, &addr_align); -#else - err = dma_get_attribute_legacy(d->dc.dmac, DMA_ATTR_BUFFER_ADDRESS_ALIGNMENT, - &addr_align); -#endif if (err < 0) return err; diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 983c0f13c71c..34631c8870cf 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -19,15 +19,6 @@ config SOF_ZEPHYR_HEAP_CACHED Enable cached heap by mapping cached SOF memory zones to different Zephyr sys_heap objects and enable caching for non-shared zones. -config ZEPHYR_NATIVE_DRIVERS - bool "Use Zephyr native drivers" - default n - help - Enable Zephyr native api drivers for host and dai audio components - host-zephyr - dai-zephyr - will be used instead of legacy xtos version. - config DMA_DOMAIN bool "Enable the usage of DMA domain." help diff --git a/zephyr/include/rtos/sof.h b/zephyr/include/rtos/sof.h index 1de60c5cd6ff..2d5be7e31a59 100644 --- a/zephyr/include/rtos/sof.h +++ b/zephyr/include/rtos/sof.h @@ -12,9 +12,6 @@ #include #include -#ifndef CONFIG_ZEPHYR_NATIVE_DRIVERS -struct cascade_root; -#endif struct clock_info; struct comp_driver_list; struct dai_info; @@ -23,9 +20,6 @@ struct dma_trace_data; struct ipc; struct ll_schedule_domain; struct mm; -#ifndef CONFIG_ZEPHYR_NATIVE_DRIVERS -struct mn; -#endif struct ams_shared_context; struct notify_data; struct pm_runtime_data; @@ -87,19 +81,9 @@ struct sof { /* platform DMA information */ const struct dma_info *dma_info; -#ifndef CONFIG_ZEPHYR_NATIVE_DRIVERS - /* cascading interrupt controller root */ - struct cascade_root *cascade_root; -#endif - /* list of registered component drivers */ struct comp_driver_list *comp_drivers; -#ifndef CONFIG_ZEPHYR_NATIVE_DRIVERS - /* M/N dividers */ - struct mn *mn; -#endif - /* probes */ struct probe_pdata *probe; diff --git a/zephyr/include/sof/lib/dai.h b/zephyr/include/sof/lib/dai.h index cc6914370b58..0e734ebd45bc 100644 --- a/zephyr/include/sof/lib/dai.h +++ b/zephyr/include/sof/lib/dai.h @@ -6,10 +6,6 @@ #ifndef __SOF_LIB_DAI_H__ #define __SOF_LIB_DAI_H__ -#ifdef CONFIG_ZEPHYR_NATIVE_DRIVERS #include -#else -#include -#endif #endif /* __SOF_LIB_DAI_H__ */ diff --git a/zephyr/include/sof/lib/dma-legacy.h b/zephyr/include/sof/lib/dma-legacy.h deleted file mode 100644 index 016434e2f143..000000000000 --- a/zephyr/include/sof/lib/dma-legacy.h +++ /dev/null @@ -1,309 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright(c) 2024 Intel Corporation. - */ - -#ifndef __SOF_LIB_DMA_LEGACY_H__ -#define __SOF_LIB_DMA_LEGACY_H__ - -/* DMA attributes */ -#define DMA_ATTR_BUFFER_ALIGNMENT 0 -#define DMA_ATTR_COPY_ALIGNMENT 1 -#define DMA_ATTR_BUFFER_ADDRESS_ALIGNMENT 2 -#define DMA_ATTR_BUFFER_PERIOD_COUNT 3 - -/* Compatibility for definitions without SOF_ namespace */ -#define DMA_DIR_MEM_TO_MEM SOF_DMA_DIR_MEM_TO_MEM -#define DMA_DIR_HMEM_TO_LMEM SOF_DMA_DIR_HMEM_TO_LMEM -#define DMA_DIR_LMEM_TO_HMEM SOF_DMA_DIR_LMEM_TO_HMEM -#define DMA_DIR_MEM_TO_DEV SOF_DMA_DIR_MEM_TO_DEV -#define DMA_DIR_DEV_TO_MEM SOF_DMA_DIR_DEV_TO_MEM -#define DMA_DIR_DEV_TO_DEV SOF_DMA_DIR_DEV_TO_DEV -#define DMA_COPY_BLOCKING SOF_DMA_COPY_BLOCKING -#define DMA_COPY_ONE_SHOT SOF_DMA_COPY_ONE_SHOT -#define DMA_DEV_HOST SOF_DMA_DEV_HOST -#define DMA_ACCESS_EXCLUSIVE SOF_DMA_ACCESS_EXCLUSIVE -#define DMA_ACCESS_SHARED SOF_DMA_ACCESS_SHARED -#define DMA_CHAN_INVALID SOF_DMA_CHAN_INVALID -#define DMA_CORE_INVALID SOF_DMA_CORE_INVALID - -struct dma *dma_get(uint32_t dir, uint32_t caps, uint32_t dev, uint32_t flags); -void dma_put(struct dma *dma); - -enum dma_cb_status { - DMA_CB_STATUS_RELOAD = 0, - DMA_CB_STATUS_END, -}; - -/* DMA interrupt commands */ -enum dma_irq_cmd { - DMA_IRQ_STATUS_GET = 0, - DMA_IRQ_CLEAR, - DMA_IRQ_MASK, - DMA_IRQ_UNMASK -}; - -/* DMA operations */ -struct dma_ops { - - struct dma_chan_data *(*channel_get)(struct dma *dma, - unsigned int req_channel); - void (*channel_put)(struct dma_chan_data *channel); - - int (*start)(struct dma_chan_data *channel); - int (*stop)(struct dma_chan_data *channel); - int (*stop_delayed)(struct dma_chan_data *channel); - int (*copy)(struct dma_chan_data *channel, int bytes, uint32_t flags); - int (*pause)(struct dma_chan_data *channel); - int (*release)(struct dma_chan_data *channel); - int (*status)(struct dma_chan_data *channel, - struct dma_chan_status *status, uint8_t direction); - - int (*set_config)(struct dma_chan_data *channel, - struct dma_sg_config *config); - - int (*probe)(struct dma *dma); - int (*remove)(struct dma *dma); - - int (*get_data_size)(struct dma_chan_data *channel, uint32_t *avail, - uint32_t *free); - - int (*get_attribute)(struct dma *dma, uint32_t type, uint32_t *value); - - int (*interrupt)(struct dma_chan_data *channel, enum dma_irq_cmd cmd); -}; - -/* DMA API - * Programming flow is :- - * - * 1) dma_channel_get() - * 2) notifier_register() - * 3) dma_set_config() - * 4) dma_start() - * ... DMA now running ... - * 5) dma_stop() - * 6) dma_stop_delayed() - * 7) dma_channel_put() - */ - -static inline struct dma_chan_data *dma_channel_get_legacy(struct dma *dma, - int req_channel) -{ - if (!dma || !dma->ops || !dma->ops->channel_get) - return NULL; - - struct dma_chan_data *chan = dma->ops->channel_get(dma, req_channel); - - return chan; -} - -static inline void dma_channel_put_legacy(struct dma_chan_data *channel) -{ - channel->dma->ops->channel_put(channel); -} - -static inline int dma_start_legacy(struct dma_chan_data *channel) -{ - return channel->dma->ops->start(channel); -} - -static inline int dma_stop_legacy(struct dma_chan_data *channel) -{ - if (channel->dma->ops->stop) - return channel->dma->ops->stop(channel); - - return 0; -} - -static inline int dma_stop_delayed_legacy(struct dma_chan_data *channel) -{ - if (channel->dma->ops->stop_delayed) - return channel->dma->ops->stop_delayed(channel); - - return 0; -} - -/** \defgroup sof_dma_copy_func static int dma_copy (struct dma_chan_data * channel, int bytes, uint32_t flags) - * - * This function is in a separate subgroup to solve a name clash with - * struct dma_copy {} - * @{ - */ -static inline int dma_copy_legacy(struct dma_chan_data *channel, int bytes, - uint32_t flags) -{ - return channel->dma->ops->copy(channel, bytes, flags); -} -/** @} */ - -static inline int dma_pause_legacy(struct dma_chan_data *channel) -{ - if (channel->dma->ops->pause) - return channel->dma->ops->pause(channel); - - return 0; -} - -static inline int dma_release_legacy(struct dma_chan_data *channel) -{ - if (channel->dma->ops->release) - return channel->dma->ops->release(channel); - - return 0; -} - -static inline int dma_status_legacy(struct dma_chan_data *channel, - struct dma_chan_status *status, uint8_t direction) -{ - return channel->dma->ops->status(channel, status, direction); -} - -static inline int dma_set_config_legacy(struct dma_chan_data *channel, - struct dma_sg_config *config) -{ - return channel->dma->ops->set_config(channel, config); -} - -static inline int dma_probe_legacy(struct dma *dma) -{ - return dma->ops->probe(dma); -} - -static inline int dma_remove_legacy(struct dma *dma) -{ - return dma->ops->remove(dma); -} - -static inline int dma_get_data_size_legacy(struct dma_chan_data *channel, - uint32_t *avail, uint32_t *free) -{ - return channel->dma->ops->get_data_size(channel, avail, free); -} - -static inline int dma_get_attribute_legacy(struct dma *dma, uint32_t type, - uint32_t *value) -{ - return dma->ops->get_attribute(dma, type, value); -} - -static inline int dma_interrupt_legacy(struct dma_chan_data *channel, - enum dma_irq_cmd cmd) -{ - return channel->dma->ops->interrupt(channel, cmd); -} - -#define dma_set_drvdata(dma, data) \ - (dma->priv_data = data) -#define dma_get_drvdata(dma) \ - dma->priv_data -#define dma_base(dma) \ - dma->plat_data.base -#define dma_irq(dma) \ - dma->plat_data.irq -#define dma_irq_name(dma) \ - dma->plat_data.irq_name -#define dma_chan_size(dma) \ - dma->plat_data.chan_size -#define dma_chan_base(dma, chan) \ - (dma->plat_data.base + chan * dma->plat_data.chan_size) -#define dma_chan_get_data(chan) \ - ((chan)->priv_data) -#define dma_chan_set_data(chan, data) \ - ((chan)->priv_data = data) - -/* DMA hardware register operations */ -static inline uint32_t dma_reg_read(struct dma *dma, uint32_t reg) -{ - return io_reg_read(dma_base(dma) + reg); -} - -static inline uint16_t dma_reg_read16(struct dma *dma, uint32_t reg) -{ - return io_reg_read16(dma_base(dma) + reg); -} - -static inline void dma_reg_write(struct dma *dma, uint32_t reg, uint32_t value) -{ - io_reg_write(dma_base(dma) + reg, value); -} - -static inline void dma_reg_write16(struct dma *dma, uint32_t reg, - uint16_t value) -{ - io_reg_write16(dma_base(dma) + reg, value); -} - -static inline void dma_reg_update_bits(struct dma *dma, uint32_t reg, - uint32_t mask, uint32_t value) -{ - io_reg_update_bits(dma_base(dma) + reg, mask, value); -} - -static inline uint32_t dma_chan_reg_read(struct dma_chan_data *channel, - uint32_t reg) -{ - return io_reg_read(dma_chan_base(channel->dma, channel->index) + reg); -} - -static inline uint16_t dma_chan_reg_read16(struct dma_chan_data *channel, - uint32_t reg) -{ - return io_reg_read16(dma_chan_base(channel->dma, channel->index) + reg); -} - -static inline void dma_chan_reg_write(struct dma_chan_data *channel, - uint32_t reg, uint32_t value) -{ - io_reg_write(dma_chan_base(channel->dma, channel->index) + reg, value); -} - -static inline void dma_chan_reg_write16(struct dma_chan_data *channel, - uint32_t reg, uint16_t value) -{ - io_reg_write16(dma_chan_base(channel->dma, channel->index) + reg, - value); -} - -static inline void dma_chan_reg_update_bits(struct dma_chan_data *channel, - uint32_t reg, uint32_t mask, - uint32_t value) -{ - io_reg_update_bits(dma_chan_base(channel->dma, channel->index) + reg, - mask, value); -} - -static inline void dma_chan_reg_update_bits16(struct dma_chan_data *channel, - uint32_t reg, uint16_t mask, - uint16_t value) -{ - io_reg_update_bits16(dma_chan_base(channel->dma, channel->index) + reg, - mask, value); -} - -/* init dma copy context */ -int dma_copy_new(struct dma_copy *dc); - -/* free dma copy context resources */ -static inline void dma_copy_free(struct dma_copy *dc) -{ - dma_channel_put_legacy(dc->chan); -} - -/* DMA copy data from host to DSP */ -int dma_copy_from_host(struct dma_copy *dc, struct dma_sg_config *host_sg, - int32_t host_offset, void *local_ptr, int32_t size); -int dma_copy_from_host_nowait(struct dma_copy *dc, - struct dma_sg_config *host_sg, - int32_t host_offset, void *local_ptr, - int32_t size); - -/* DMA copy data from DSP to host */ -int dma_copy_to_host(struct dma_copy *dc, struct dma_sg_config *host_sg, - int32_t host_offset, void *local_ptr, int32_t size); -int dma_copy_to_host_nowait(struct dma_copy *dc, struct dma_sg_config *host_sg, - int32_t host_offset, void *local_ptr, int32_t size); - - -int dma_copy_set_stream_tag(struct dma_copy *dc, uint32_t stream_tag); - -#endif /* __SOF_LIB_DMA_LEGACY_H__ */ diff --git a/zephyr/include/sof/lib/dma.h b/zephyr/include/sof/lib/dma.h index adec97dc1a1e..0f19d6f010fa 100644 --- a/zephyr/include/sof/lib/dma.h +++ b/zephyr/include/sof/lib/dma.h @@ -263,10 +263,6 @@ struct dma *sof_dma_get(uint32_t dir, uint32_t caps, uint32_t dev, uint32_t flag */ void sof_dma_put(struct dma *dma); -#ifndef CONFIG_ZEPHYR_NATIVE_DRIVERS -#include "dma-legacy.h" -#endif /* !CONFIG_ZEPHYR_NATIVE_DRIVERS */ - #if defined(CONFIG_SCHEDULE_DMA_MULTI_CHANNEL) || \ defined(CONFIG_SCHEDULE_DMA_SINGLE_CHANNEL) diff --git a/zephyr/lib/cpu.c b/zephyr/lib/cpu.c index 97ac6cf6060f..d5b7d66416fc 100644 --- a/zephyr/lib/cpu.c +++ b/zephyr/lib/cpu.c @@ -43,7 +43,6 @@ static void secondary_init(void *arg) secondary_core_init(sof_get()); } -#if CONFIG_ZEPHYR_NATIVE_DRIVERS #include #include @@ -302,61 +301,6 @@ int cpu_enabled_cores(void) return mask; } -#else -static int w_core_enable_mask = 0x1; /*Core 0 is always active*/ - -int cpu_enable_core(int id) -{ - pm_runtime_get(PM_RUNTIME_DSP, PWRD_BY_TPLG | id); - - /* only called from single core, no RMW lock */ - __ASSERT_NO_MSG(cpu_get_id() == PLATFORM_PRIMARY_CORE_ID); - - w_core_enable_mask |= BIT(id); - - return 0; -} - -int cpu_enable_secondary_core(int id) -{ - if (arch_cpu_active(id)) - return 0; - - /* During kernel initialization, the next pm state is set to ACTIVE. By checking this - * value, we determine if this is the first core boot, if not, we need to skip idle thread - * initialization. By reinitializing the idle thread, we would overwrite the kernel structs - * and the idle thread stack. - */ - if (pm_state_next_get(id)->state == PM_STATE_ACTIVE) { - k_smp_cpu_start(id, secondary_init, NULL); - return 0; - } - - k_smp_cpu_resume(id, secondary_init, NULL, true, false); - - return 0; -} - -void cpu_disable_core(int id) -{ - /* TODO: call Zephyr API */ - - /* only called from single core, no RMW lock */ - __ASSERT_NO_MSG(cpu_get_id() == PLATFORM_PRIMARY_CORE_ID); - - w_core_enable_mask &= ~BIT(id); -} - -int cpu_is_core_enabled(int id) -{ - return w_core_enable_mask & BIT(id); -} - -int cpu_enabled_cores(void) -{ - return w_core_enable_mask; -} -#endif /* CONFIG_ZEPHYR_NATIVE_DRIVERS */ void cpu_power_down_core(uint32_t flags) {