From 5661b3f4a1237ec4fc150f59211da1c6907c4b5e Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Thu, 4 Jul 2024 12:55:45 +0200 Subject: [PATCH] fir: enable building FIR support code as an LLEXT object FIR support code is used by eq-fir and by tdfb. When both of them are built as LLEXT modules, FIR supporting functions can be dynamically loaded too. Signed-off-by: Guennadi Liakhovetski --- src/math/Kconfig | 2 +- src/math/fir.toml | 6 ++++++ src/math/fir_common.c | 18 ++++++++++++++++++ src/math/fir_generic.c | 2 ++ src/math/fir_hifi2ep.c | 2 ++ src/math/fir_hifi3.c | 1 + src/math/fir_llext/CMakeLists.txt | 10 ++++++++++ src/math/fir_llext/llext.toml.h | 5 +++++ uuid-registry.txt | 1 + zephyr/CMakeLists.txt | 16 +++++++++++----- 10 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 src/math/fir.toml create mode 100644 src/math/fir_common.c create mode 100644 src/math/fir_llext/CMakeLists.txt create mode 100644 src/math/fir_llext/llext.toml.h diff --git a/src/math/Kconfig b/src/math/Kconfig index ccd7520f20a7..b97f87bfe781 100644 --- a/src/math/Kconfig +++ b/src/math/Kconfig @@ -170,7 +170,7 @@ choice "FILTER_SIMD_LEVEL_SELECT" endchoice config MATH_FIR - bool "FIR filter library" + tristate "FIR filter library" default n help This option builds FIR (Finite Impulse Response) filter library. It diff --git a/src/math/fir.toml b/src/math/fir.toml new file mode 100644 index 000000000000..a81268637761 --- /dev/null +++ b/src/math/fir.toml @@ -0,0 +1,6 @@ + [[module.entry]] + name = "FIR" + uuid = "93446E12-1864-4E04-AFE0-3B1D778FFB79" + load_type = "3" + + index = __COUNTER__ diff --git a/src/math/fir_common.c b/src/math/fir_common.c new file mode 100644 index 000000000000..897ac857e07d --- /dev/null +++ b/src/math/fir_common.c @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2024 Intel Corporation. + +/* modular: llext dynamic link */ + +#include +#include +#include +#include +#include + +#include + +static const struct sof_man_module_manifest mod_manifest __section(".module") __used = + SOF_LLEXT_AUX_MANIFEST("FIR", NULL, SOF_REG_UUID(fir)); + +SOF_LLEXT_BUILDINFO; diff --git a/src/math/fir_generic.c b/src/math/fir_generic.c index 24fbdc665988..802242d4dbec 100644 --- a/src/math/fir_generic.c +++ b/src/math/fir_generic.c @@ -118,6 +118,7 @@ int32_t fir_32x16(struct fir_state_32x16 *fir, int32_t x) /* Q2.46 -> Q2.31, saturate to Q1.31 */ return sat_int32(y >> shift); } +EXPORT_SYMBOL(fir_32x16); void fir_32x16_2x(struct fir_state_32x16 *fir, int32_t x0, int32_t x1, int32_t *y0, int32_t *y1) { @@ -184,5 +185,6 @@ void fir_32x16_2x(struct fir_state_32x16 *fir, int32_t x0, int32_t x1, int32_t * *y0 = sat_int32(a0 >> shift); *y1 = sat_int32(a1 >> shift); } +EXPORT_SYMBOL(fir_32x16_2x); #endif diff --git a/src/math/fir_hifi2ep.c b/src/math/fir_hifi2ep.c index 7f3a2d42a829..2172e3e98d53 100644 --- a/src/math/fir_hifi2ep.c +++ b/src/math/fir_hifi2ep.c @@ -156,6 +156,7 @@ void fir_32x16_hifiep(struct fir_state_32x16 *fir, int32_t x, int32_t *y, int ls a = AE_SRAAQ56(AE_SLLASQ56S(a, lshift), rshift); AE_SQ32F_I(AE_ROUNDSQ32SYM(a), (ae_q32s *)y, 0); } +EXPORT_SYMBOL(fir_32x16_hifiep); /* HiFi EP has the follow number of reqisters that should not be exceeded * 4x 56 bit registers in register file Q @@ -249,5 +250,6 @@ void fir_32x16_2x_hifiep(struct fir_state_32x16 *fir, int32_t x0, int32_t x1, AE_SQ32F_I(AE_ROUNDSQ32SYM(b), (ae_q32s *)y1, 0); AE_SQ32F_I(AE_ROUNDSQ32SYM(a), (ae_q32s *)y0, 0); } +EXPORT_SYMBOL(fir_32x16_2x_hifiep); #endif diff --git a/src/math/fir_hifi3.c b/src/math/fir_hifi3.c index e71fc47fc900..a485bf235f79 100644 --- a/src/math/fir_hifi3.c +++ b/src/math/fir_hifi3.c @@ -162,6 +162,7 @@ void fir_32x16_hifi3(struct fir_state_32x16 *fir, ae_int32 x, ae_int32 *y, a = AE_SLAA64S(a, shift); AE_S32_L_I(AE_ROUND32F48SSYM(a), (ae_int32 *)y, 0); } +EXPORT_SYMBOL(fir_32x16_hifi3); /* HiFi EP has the follow number of reqisters that should not be exceeded * 4x 56 bit registers in register file Q diff --git a/src/math/fir_llext/CMakeLists.txt b/src/math/fir_llext/CMakeLists.txt new file mode 100644 index 000000000000..9b8d2531bea3 --- /dev/null +++ b/src/math/fir_llext/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2024 Intel Corporation. +# SPDX-License-Identifier: Apache-2.0 + +sof_llext_build("fir" + SOURCES ../fir_common.c + ../fir_generic.c + ../fir_hifi2ep.c + ../fir_hifi3.c + LIB openmodules +) diff --git a/src/math/fir_llext/llext.toml.h b/src/math/fir_llext/llext.toml.h new file mode 100644 index 000000000000..fa2eab98627b --- /dev/null +++ b/src/math/fir_llext/llext.toml.h @@ -0,0 +1,5 @@ +#include +#include "../fir.toml" + +[module] +count = __COUNTER__ diff --git a/uuid-registry.txt b/uuid-registry.txt index 7d7171ee1809..f06a9f259a1c 100644 --- a/uuid-registry.txt +++ b/uuid-registry.txt @@ -72,6 +72,7 @@ f6d15ad3-b122-458c-ae9b0ab0b5867aa0 dummy_dma 5150c0e6-27f9-4ec8-8351c705b642d12f eq_iir 889f6dcd-ddcd-4e05-aa5b0d39f8bca961 esai bfc7488c-75aa-4ce8-9dbed8da08a698c2 file +93446e12-1864-4e04-afe03b1d778ffb79 fir 61bca9a8-18d0-4a18-8e7b2639219804b7 gain c3c74249-058e-414f-82404da5f3fc2389 google_hotword bf0e1bbc-dc6a-45fe-bc902554cb137ab4 google_ctc_audio_processing diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 130736242587..567c03e5e5df 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -685,11 +685,17 @@ elseif(CONFIG_COMP_IIR) ) endif() -zephyr_library_sources_ifdef(CONFIG_MATH_FIR - ${SOF_MATH_PATH}/fir_generic.c - ${SOF_MATH_PATH}/fir_hifi2ep.c - ${SOF_MATH_PATH}/fir_hifi3.c -) +if(CONFIG_MATH_FIR STREQUAL "m") + add_subdirectory(${SOF_MATH_PATH}/fir_llext + ${PROJECT_BINARY_DIR}/fir_llext) + add_dependencies(app fir) +elseif(CONFIG_MATH_FIR) + zephyr_library_sources( + ${SOF_MATH_PATH}/fir_generic.c + ${SOF_MATH_PATH}/fir_hifi2ep.c + ${SOF_MATH_PATH}/fir_hifi3.c + ) +endif() zephyr_library_sources_ifdef(CONFIG_MATH_IIR_DF1 ${SOF_MATH_PATH}/iir_df1_generic.c