Skip to content

Commit 1cdebd6

Browse files
committed
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 <[email protected]>
1 parent 4057a9e commit 1cdebd6

File tree

8 files changed

+69
-21
lines changed

8 files changed

+69
-21
lines changed

src/math/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ choice "FILTER_SIMD_LEVEL_SELECT"
172172
endchoice
173173

174174
config MATH_FIR
175-
bool "FIR filter library"
175+
tristate "FIR filter library"
176176
default n
177177
help
178178
This option builds FIR (Finite Impulse Response) filter library. It

src/math/fir.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[[module.entry]]
2+
name = "FIR"
3+
uuid = "93446E12-1864-4E04-AFE0-3B1D778FFB79"
4+
load_type = "3"
5+
6+
index = __COUNTER__

src/math/fir_generic.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void fir_reset(struct fir_state_32x16 *fir)
3434
* reset so omitting setting also fir->delay to NULL.
3535
*/
3636
}
37-
EXPORT_SYMBOL(fir_reset);
37+
LL_EXTENSION_SYMBOL(fir_reset);
3838

3939
int fir_delay_size(struct sof_fir_coef_data *config)
4040
{
@@ -51,7 +51,7 @@ int fir_delay_size(struct sof_fir_coef_data *config)
5151
*/
5252
return (config->length + 4) * sizeof(int32_t);
5353
}
54-
EXPORT_SYMBOL(fir_delay_size);
54+
LL_EXTENSION_SYMBOL(fir_delay_size);
5555

5656
int fir_init_coef(struct fir_state_32x16 *fir,
5757
struct sof_fir_coef_data *config)
@@ -63,14 +63,14 @@ int fir_init_coef(struct fir_state_32x16 *fir,
6363
fir->coef = ASSUME_ALIGNED(&config->coef[0], 4);
6464
return 0;
6565
}
66-
EXPORT_SYMBOL(fir_init_coef);
66+
LL_EXTENSION_SYMBOL(fir_init_coef);
6767

6868
void fir_init_delay(struct fir_state_32x16 *fir, int32_t **data)
6969
{
7070
fir->delay = *data;
7171
*data += fir->length; /* Point to next delay line start */
7272
}
73-
EXPORT_SYMBOL(fir_init_delay);
73+
LL_EXTENSION_SYMBOL(fir_init_delay);
7474

7575
int32_t fir_32x16(struct fir_state_32x16 *fir, int32_t x)
7676
{
@@ -118,6 +118,7 @@ int32_t fir_32x16(struct fir_state_32x16 *fir, int32_t x)
118118
/* Q2.46 -> Q2.31, saturate to Q1.31 */
119119
return sat_int32(y >> shift);
120120
}
121+
LL_EXTENSION_SYMBOL(fir_32x16);
121122

122123
void fir_32x16_2x(struct fir_state_32x16 *fir, int32_t x0, int32_t x1, int32_t *y0, int32_t *y1)
123124
{
@@ -184,5 +185,24 @@ void fir_32x16_2x(struct fir_state_32x16 *fir, int32_t x0, int32_t x1, int32_t *
184185
*y0 = sat_int32(a0 >> shift);
185186
*y1 = sat_int32(a1 >> shift);
186187
}
188+
LL_EXTENSION_SYMBOL(fir_32x16_2x);
189+
190+
#if CONFIG_MATH_FIR_MODULE
191+
/* modular: llext dynamic link */
192+
193+
#include <module/module/api_ver.h>
194+
#include <module/module/llext.h>
195+
#include <rimage/sof/user/manifest.h>
196+
197+
/* 93446e12-1864-4e04-afe0-3b1d778ffb79 */
198+
#define UUID_FIR 0x12, 0x6e, 0x44, 0x93, 0x64, 0x18, 0x04, 0x4e, \
199+
0xaf, 0xe0, 0x3b, 0x1d, 0x77, 0x8f, 0xfb, 0x79
200+
201+
static const struct sof_man_module_manifest mod_manifest __section(".module") __used =
202+
SOF_LLEXT_AUX_MANIFEST("FIR", NULL, UUID_FIR);
203+
204+
SOF_LLEXT_BUILDINFO;
205+
206+
#endif
187207

188208
#endif

src/math/fir_hifi2ep.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void fir_reset(struct fir_state_32x16 *fir)
3333
* reset so omitting setting also fir->delay to NULL.
3434
*/
3535
}
36-
EXPORT_SYMBOL(fir_reset);
36+
LL_EXTENSION_SYMBOL(fir_reset);
3737

3838
int fir_delay_size(struct sof_fir_coef_data *config)
3939
{
@@ -49,7 +49,7 @@ int fir_delay_size(struct sof_fir_coef_data *config)
4949
*/
5050
return (config->length + 2) * sizeof(int32_t);
5151
}
52-
EXPORT_SYMBOL(fir_delay_size);
52+
LL_EXTENSION_SYMBOL(fir_delay_size);
5353

5454
int fir_init_coef(struct fir_state_32x16 *fir,
5555
struct sof_fir_coef_data *config)
@@ -65,7 +65,7 @@ int fir_init_coef(struct fir_state_32x16 *fir,
6565
fir->coef = (ae_p16x2s *)&config->coef[0];
6666
return 0;
6767
}
68-
EXPORT_SYMBOL(fir_init_coef);
68+
LL_EXTENSION_SYMBOL(fir_init_coef);
6969

7070
void fir_init_delay(struct fir_state_32x16 *fir, int32_t **data)
7171
{
@@ -74,15 +74,15 @@ void fir_init_delay(struct fir_state_32x16 *fir, int32_t **data)
7474
fir->rwp = (ae_p24x2f *)(fir->delay + fir->length - 1);
7575
*data += fir->length; /* Point to next delay line start */
7676
}
77-
EXPORT_SYMBOL(fir_init_delay);
77+
LL_EXTENSION_SYMBOL(fir_init_delay);
7878

7979
void fir_get_lrshifts(struct fir_state_32x16 *fir, int *lshift,
8080
int *rshift)
8181
{
8282
*lshift = (fir->out_shift < 0) ? -fir->out_shift : 0;
8383
*rshift = (fir->out_shift > 0) ? fir->out_shift : 0;
8484
}
85-
EXPORT_SYMBOL(fir_get_lrshifts);
85+
LL_EXTENSION_SYMBOL(fir_get_lrshifts);
8686

8787
/* HiFi EP has the follow number of reqisters that should not be exceeded
8888
* 4x 56 bit registers in register file Q
@@ -156,6 +156,7 @@ void fir_32x16_hifiep(struct fir_state_32x16 *fir, int32_t x, int32_t *y, int ls
156156
a = AE_SRAAQ56(AE_SLLASQ56S(a, lshift), rshift);
157157
AE_SQ32F_I(AE_ROUNDSQ32SYM(a), (ae_q32s *)y, 0);
158158
}
159+
LL_EXTENSION_SYMBOL(fir_32x16_hifiep);
159160

160161
/* HiFi EP has the follow number of reqisters that should not be exceeded
161162
* 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,
249250
AE_SQ32F_I(AE_ROUNDSQ32SYM(b), (ae_q32s *)y1, 0);
250251
AE_SQ32F_I(AE_ROUNDSQ32SYM(a), (ae_q32s *)y0, 0);
251252
}
253+
LL_EXTENSION_SYMBOL(fir_32x16_2x_hifiep);
252254

253255
#endif

src/math/fir_hifi3.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void fir_reset(struct fir_state_32x16 *fir)
3333
* reset so omitting setting also fir->delay to NULL.
3434
*/
3535
}
36-
EXPORT_SYMBOL(fir_reset);
36+
LL_EXTENSION_SYMBOL(fir_reset);
3737

3838
int fir_delay_size(struct sof_fir_coef_data *config)
3939
{
@@ -50,7 +50,7 @@ int fir_delay_size(struct sof_fir_coef_data *config)
5050
*/
5151
return (config->length + 2) * sizeof(int32_t);
5252
}
53-
EXPORT_SYMBOL(fir_delay_size);
53+
LL_EXTENSION_SYMBOL(fir_delay_size);
5454

5555
int fir_init_coef(struct fir_state_32x16 *fir,
5656
struct sof_fir_coef_data *config)
@@ -66,7 +66,7 @@ int fir_init_coef(struct fir_state_32x16 *fir,
6666
fir->coef = (ae_f16x4 *)&config->coef[0];
6767
return 0;
6868
}
69-
EXPORT_SYMBOL(fir_init_coef);
69+
LL_EXTENSION_SYMBOL(fir_init_coef);
7070

7171
void fir_init_delay(struct fir_state_32x16 *fir, int32_t **data)
7272
{
@@ -75,15 +75,15 @@ void fir_init_delay(struct fir_state_32x16 *fir, int32_t **data)
7575
fir->rwp = (ae_int32 *)(fir->delay + fir->length - 1);
7676
*data += fir->length; /* Point to next delay line start */
7777
}
78-
EXPORT_SYMBOL(fir_init_delay);
78+
LL_EXTENSION_SYMBOL(fir_init_delay);
7979

8080
void fir_get_lrshifts(struct fir_state_32x16 *fir, int *lshift,
8181
int *rshift)
8282
{
8383
*lshift = (fir->out_shift < 0) ? -fir->out_shift : 0;
8484
*rshift = (fir->out_shift > 0) ? fir->out_shift : 0;
8585
}
86-
EXPORT_SYMBOL(fir_get_lrshifts);
86+
LL_EXTENSION_SYMBOL(fir_get_lrshifts);
8787

8888
/* HiFi EP has the follow number of reqisters that should not be exceeded
8989
* 4x 56 bit registers in register file Q
@@ -162,6 +162,7 @@ void fir_32x16_hifi3(struct fir_state_32x16 *fir, ae_int32 x, ae_int32 *y,
162162
a = AE_SLAA64S(a, shift);
163163
AE_S32_L_I(AE_ROUND32F48SSYM(a), (ae_int32 *)y, 0);
164164
}
165+
LL_EXTENSION_SYMBOL(fir_32x16_hifi3);
165166

166167
/* HiFi EP has the follow number of reqisters that should not be exceeded
167168
* 4x 56 bit registers in register file Q
@@ -251,6 +252,6 @@ void fir_32x16_2x_hifi3(struct fir_state_32x16 *fir, ae_int32 x0, ae_int32 x1,
251252
AE_S32_L_I(AE_ROUND32F48SSYM(b), (ae_int32 *)y1, 0);
252253
AE_S32_L_I(AE_ROUND32F48SSYM(a), (ae_int32 *)y0, 0);
253254
}
254-
EXPORT_SYMBOL(fir_32x16_2x_hifi3);
255+
LL_EXTENSION_SYMBOL(fir_32x16_2x_hifi3);
255256

256257
#endif

src/math/fir_llext/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2024 Intel Corporation.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
sof_llext_build("fir"
5+
SOURCES ../fir_generic.c
6+
../fir_hifi2ep.c
7+
../fir_hifi3.c
8+
)

src/math/fir_llext/llext.toml.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <tools/rimage/config/platform.toml>
2+
#include "../fir.toml"
3+
4+
[module]
5+
count = __COUNTER__

zephyr/CMakeLists.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,11 +601,17 @@ if(NOT CONFIG_COMP_IIR STREQUAL "n")
601601
)
602602
endif()
603603

604-
zephyr_library_sources_ifdef(CONFIG_MATH_FIR
605-
${SOF_MATH_PATH}/fir_generic.c
606-
${SOF_MATH_PATH}/fir_hifi2ep.c
607-
${SOF_MATH_PATH}/fir_hifi3.c
608-
)
604+
if(CONFIG_MATH_FIR STREQUAL "m")
605+
add_subdirectory(${SOF_MATH_PATH}/fir_llext
606+
${PROJECT_BINARY_DIR}/fir_llext)
607+
add_dependencies(app fir)
608+
elseif(CONFIG_MATH_FIR)
609+
zephyr_library_sources(
610+
${SOF_MATH_PATH}/fir_generic.c
611+
${SOF_MATH_PATH}/fir_hifi2ep.c
612+
${SOF_MATH_PATH}/fir_hifi3.c
613+
)
614+
endif()
609615

610616
zephyr_library_sources_ifdef(CONFIG_MATH_IIR_DF1
611617
${SOF_MATH_PATH}/iir_df1_generic.c

0 commit comments

Comments
 (0)