From 43c34bb081b9cc06cb57755ca8fad455777a669f Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Wed, 20 Nov 2024 16:31:51 +0200 Subject: [PATCH] audio: make clock control optional in SOF Zephyr builds Mark the few places in generic SOF code where SOF clock control interface is used. These cases are few as most usage has traditionally been in XTOS drivers and platform code. In Zephyr builds these are not used, making the clock interface mostly unnecessary. The one bigger exception is CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL feature for dynamically adjusting the DSP clock frequency based on IPC messages and audio pipeline configuration. This is an optional feature not used by all targets, so the requirement to have a clock abstraction implemented, should also be optional. Remaining uses are for IPC4 base firmware attributes and some informational use in logging. None of these are e.g. required by SOF Linux driver for any essential functionality, so can be disabled without side-effects. As the rtos/clk.h interfaces are still used in many places in platform code, this patch adds a new transition tool in form of CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK Kconfig option. This allows to incrementally transition targets to not use the clock framework. In longer term, the remaining uses will be transitioned to use Zephyr clock-control.h directly Signed-off-by: Kai Vehmanen --- src/audio/base_fw.c | 10 ++++++++++ src/audio/pipeline/pipeline-graph.c | 2 +- zephyr/CMakeLists.txt | 10 ++++++++-- zephyr/Kconfig | 6 ++++++ zephyr/include/rtos/clk.h | 5 ++++- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/audio/base_fw.c b/src/audio/base_fw.c index 54a09de4a437..d5284dbe515c 100644 --- a/src/audio/base_fw.c +++ b/src/audio/base_fw.c @@ -58,6 +58,7 @@ static int basefw_config(uint32_t *data_offset, char *data) tuple = tlv_next(tuple); tlv_value_uint32_set(tuple, IPC4_MEMORY_RECLAIMED_FW_CFG, 1); +#ifndef CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK tuple = tlv_next(tuple); tlv_value_uint32_set(tuple, IPC4_FAST_CLOCK_FREQ_HZ_FW_CFG, CLK_MAX_CPU_HZ); @@ -65,6 +66,7 @@ static int basefw_config(uint32_t *data_offset, char *data) tlv_value_uint32_set(tuple, IPC4_SLOW_CLOCK_FREQ_HZ_FW_CFG, clock_get_freq(CPU_LOWEST_FREQ_IDX)); +#endif tuple = tlv_next(tuple); tlv_value_uint32_set(tuple, IPC4_DL_MAILBOX_BYTES_FW_CFG, MAILBOX_HOSTBOX_SIZE); @@ -220,17 +222,21 @@ static int basefw_register_kcps(bool first_block, if (!(first_block && last_block)) return IPC4_ERROR_INVALID_PARAM; +#if CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL /* value of kcps to request on core 0. Can be negative */ if (core_kcps_adjust(0, *(int32_t *)data)) return IPC4_ERROR_INVALID_PARAM; +#endif return IPC4_SUCCESS; } static int basefw_kcps_allocation_request(struct ipc4_resource_kcps *request) { +#if CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL if (core_kcps_adjust(request->core_id, request->kcps)) return IPC4_ERROR_INVALID_PARAM; +#endif return IPC4_SUCCESS; } @@ -259,6 +265,7 @@ static int basefw_resource_allocation_request(bool first_block, static int basefw_power_state_info_get(uint32_t *data_offset, char *data) { +#if CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL struct sof_tlv *tuple = (struct sof_tlv *)data; uint32_t core_kcps[CONFIG_CORE_COUNT] = {0}; int core_id; @@ -275,6 +282,9 @@ static int basefw_power_state_info_get(uint32_t *data_offset, char *data) tuple = tlv_next(tuple); *data_offset = (int)((char *)tuple - data); return IPC4_SUCCESS; +#else + return IPC4_UNAVAILABLE; +#endif } static int basefw_libraries_info_get(uint32_t *data_offset, char *data) diff --git a/src/audio/pipeline/pipeline-graph.c b/src/audio/pipeline/pipeline-graph.c index 7abc5ed8c461..f30731fa4874 100644 --- a/src/audio/pipeline/pipeline-graph.c +++ b/src/audio/pipeline/pipeline-graph.c @@ -282,7 +282,7 @@ int pipeline_complete(struct pipeline *p, struct comp_dev *source, .comp_data = &data, }; -#if !UNIT_TEST && !CONFIG_LIBRARY +#if !UNIT_TEST && !CONFIG_LIBRARY && CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL int __maybe_unused freq = clock_get_freq(cpu_get_id()); #else int __maybe_unused freq = 0; diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index c583a837203d..1a5adce8c560 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -490,9 +490,7 @@ zephyr_library_sources( ${SOF_MATH_PATH}/exp_fcn_hifi.c # SOF library - parts to transition to Zephyr over time - ${SOF_LIB_PATH}/clk.c ${SOF_LIB_PATH}/notifier.c - ${SOF_LIB_PATH}/cpu-clk-manager.c ${SOF_LIB_PATH}/dma.c ${SOF_LIB_PATH}/dai.c @@ -530,6 +528,14 @@ zephyr_library_sources( lib.c ) +if(NOT CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK) + zephyr_library_sources(${SOF_LIB_PATH}/clk.c) +endif() + +zephyr_library_sources_ifdef(CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL + ${SOF_LIB_PATH}/cpu-clk-manager.c +) + # Optional math utility zephyr_library_sources_ifdef(CONFIG_MATH_LUT_SINE_FIXED ${SOF_MATH_PATH}/lut_trig.c diff --git a/zephyr/Kconfig b/zephyr/Kconfig index b348fd7b9728..535cb6bc59ea 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -76,4 +76,10 @@ config SOF_BOOT_TEST initialized. After that SOF will continue running and be usable as usual. +config SOF_ZEPHYR_NO_SOF_CLOCK + bool + help + Do not use SOF clk.h interface to set the DSP clock frequency. + Requires implementation of platform/lib/clk.h. + endif diff --git a/zephyr/include/rtos/clk.h b/zephyr/include/rtos/clk.h index b0fefc748334..6db452bdab88 100644 --- a/zephyr/include/rtos/clk.h +++ b/zephyr/include/rtos/clk.h @@ -6,9 +6,10 @@ #ifndef __ZEPHYR_RTOS_CLK_H__ #define __ZEPHYR_RTOS_CLK_H__ +#ifndef CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK + #include -/* TODO remove once drivers upstream */ #define __SOF_LIB_CLK_H__ #include @@ -77,4 +78,6 @@ static inline struct clock_info *clocks_get(void) return sof_get()->clocks; } +#endif /* CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK */ + #endif /* __ZEPHYR_RTOS_CLK_H__ */