Skip to content

Commit

Permalink
dynamic linking: working smart-amp test except stopping
Browse files Browse the repository at this point in the history
The smart-amp test is now working as a loadable module, except for
stopping, which still has to be fixed.

Signed-off-by: Guennadi Liakhovetski <[email protected]>
  • Loading branch information
lyakh committed Sep 1, 2023
1 parent d4dd725 commit a9a8c4c
Show file tree
Hide file tree
Showing 24 changed files with 356 additions and 139 deletions.
2 changes: 2 additions & 0 deletions app/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ CONFIG_DAI=y
CONFIG_HEAP_MEM_POOL_SIZE=2048

CONFIG_SAMPLE_SMART_AMP=n

CONFIG_MODULES=y
14 changes: 11 additions & 3 deletions lmdk/cmake/build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ foreach(MODULE ${MODULES_LIST})
add_library(${MODULE} SHARED)
include(${SOF_BASE}/src/samples/audio/pic-${MODULE}.cmake)

target_compile_options(${MODULE} PRIVATE -imacros${ZEPHYR_BUILD}/include/generated/autoconf.h)
target_compile_options(${MODULE} PRIVATE -imacros${ZEPHYR_BUILD}/include/generated/autoconf.h -save-temps -O2)
target_compile_definitions(${MODULE} PRIVATE ${MODULE_COMPILE_DEF})
set_target_properties(${MODULE} PROPERTIES ${MODULE_PROPERTIES})

Expand Down Expand Up @@ -68,10 +68,18 @@ foreach(MODULE ${MODULES_LIST})
#"-Wl,--no-undefined" "-Wl,--unresolved-symbols=report-all" "-Wl,--error-unresolved-symbols"
#"-Wl,--gc-sections" # may remove .bss and that will result in rimage error, do not use for now
"-Wl,-Map,$<TARGET_FILE:${MODULE}>.map" # optional: just for debug
"-T" "${MODULE}_ldscripts/elf32xtensa.x"
#"-T" "${MODULE}_ldscripts/elf32xtensa.x"
# FIXME: use a script to calculate values
"-Wl,-Ttext=0xa06ca000"
"-Wl,-Tdata=0xa06cb000"
"-Wl,--section-start=.rodata=0xa06cb100"
)

set(LIB_LIST ${LIB_LIST} lib${MODULE}.so)
add_custom_command(TARGET ${MODULE} POST_BUILD
COMMAND ${CMAKE_STRIP} -R .xt.* -o lib${MODULE}_out.so lib${MODULE}.so
)

set(LIB_LIST ${LIB_LIST} lib${MODULE}_out.so)

sof_append_relative_path_definitions(${MODULE})
endforeach()
Expand Down
8 changes: 8 additions & 0 deletions lmdk/cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@ cmake_path(ABSOLUTE_PATH LMDK_BASE NORMALIZE)
set(SOF_BASE ${LMDK_BASE}/..)
cmake_path(ABSOLUTE_PATH SOF_BASE NORMALIZE)

# zephyr root dir
set(ZEPHYR_BASE ${SOF_BASE}/../../../zephyr)
cmake_path(ABSOLUTE_PATH ZEPHYR_BASE NORMALIZE)

# zephyr build root dir
set(ZEPHYR_BUILD ${BUILD_DIR}/zephyr)
cmake_path(ABSOLUTE_PATH ZEPHYR_BUILD NORMALIZE)

set(RIMAGE_INCLUDE_DIR ${SOF_BASE}/rimage/src/include)
cmake_path(ABSOLUTE_PATH RIMAGE_INCLUDE_DIR NORMALIZE)
24 changes: 17 additions & 7 deletions lmdk/cmake/xtensa-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Xtensa CMake toolchain file. Apply it using CMAKE_TOOLCHAIN_FILE variable.

set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)

Expand All @@ -9,20 +12,24 @@ if(NOT XTENSA_TOOLCHAIN_PATH)
set(XTENSA_TOOLCHAIN_PATH $ENV{XTENSA_TOOLCHAIN_PATH})
endif()

if(NOT XTENSA_TOOLCHAIN_PATH)
message(FATAL_ERROR "Failed to find Xtensa toolchain: XTENSA_TOOLCHAIN_PATH (env or CMake) variable not defined.")
if(XTENSA_TOOLCHAIN_PATH)
cmake_path(CONVERT ${XTENSA_TOOLCHAIN_PATH} TO_CMAKE_PATH_LIST XTENSA_TOOLCHAIN_PATH)
cmake_path(APPEND XTENSA_TOOLCHAIN_PATH "XtensaTools" OUTPUT_VARIABLE TOOLCHAIN_BASE)
else()
cmake_path(CONVERT $ENV{XTENSA_SDK} TO_CMAKE_PATH_LIST TOOLCHAIN_BASE)
cmake_path(CONVERT $ENV{XTENSA_TOOLS} TO_CMAKE_PATH_LIST XTENSA_TOOLS)
endif()

cmake_path(CONVERT ${XTENSA_TOOLCHAIN_PATH} TO_CMAKE_PATH_LIST XTENSA_TOOLCHAIN_PATH)
cmake_path(APPEND XTENSA_TOOLCHAIN_PATH "XtensaTools" OUTPUT_VARIABLE TOOLCHAIN_BASE)
set(CROSS_COMPILE xt-)
cmake_path(CONVERT $ENV{XTENSA_ROOT} TO_CMAKE_PATH_LIST XTENSA_ROOT)
set(CROSS_COMPILE ${XTENSA_TOOLS}/xtensa-intel_ace15_mtpm_zephyr-elf-)
set(SYSROOT_DIR ${XTENSA_ROOT})

# clang or xcc
find_program(CMAKE_C_COMPILER NAMES ${CROSS_COMPILE}xcc
find_program(CMAKE_C_COMPILER NAMES ${CROSS_COMPILE}gcc
PATHS ${TOOLCHAIN_BASE} PATH_SUFFIXES "bin" REQUIRED NO_DEFAULT_PATH
)
# clang++ or xc++
find_program(CMAKE_CXX_COMPILER NAMES ${CROSS_COMPILE}xc++
find_program(CMAKE_CXX_COMPILER NAMES ${CROSS_COMPILE}g++
PATHS ${TOOLCHAIN_BASE} PATH_SUFFIXES "bin" REQUIRED NO_DEFAULT_PATH
)
find_program(CMAKE_LD NAMES ${CROSS_COMPILE}ld
Expand All @@ -43,6 +50,9 @@ find_program(CMAKE_OBJDUMP NAMES ${CROSS_COMPILE}objdump
find_program(CMAKE_NM NAMES ${CROSS_COMPILE}nm
PATHS ${TOOLCHAIN_BASE} PATH_SUFFIXES "bin" REQUIRED NO_DEFAULT_PATH
)
find_program(CMAKE_STRIP NAMES ${CROSS_COMPILE}strip
PATHS ${TOOLCHAIN_BASE} PATH_SUFFIXES "bin" REQUIRED NO_DEFAULT_PATH
)

cmake_path(APPEND TOOLCHAIN_BASE "xtensa-elf" OUTPUT_VARIABLE XTENSA_ELF_ROOT)
set(CMAKE_FIND_ROOT_PATH ${XTENSA_ELF_ROOT})
Expand Down
2 changes: 2 additions & 0 deletions src/audio/component.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <zephyr/modules/module.h>

#if defined(__XCC__)
#include <xtensa/config/core-isa.h>
Expand Down Expand Up @@ -49,6 +50,7 @@ int comp_register(struct comp_driver_info *drv)

return 0;
}
EXPORT_SYMBOL(comp_register);

void comp_unregister(struct comp_driver_info *drv)
{
Expand Down
4 changes: 4 additions & 0 deletions src/audio/data_blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <ipc/control.h>
#include <sof/audio/component.h>
#include <sof/audio/data_blob.h>
#include <zephyr/modules/module.h>

LOG_MODULE_REGISTER(data_blob, CONFIG_SOF_LOG_LEVEL);

Expand Down Expand Up @@ -426,6 +427,7 @@ int ipc4_comp_data_blob_set(struct comp_data_blob_handler *blob_handler,

return 0;
}
EXPORT_SYMBOL(comp_data_blob_set);

int comp_data_blob_set_cmd(struct comp_data_blob_handler *blob_handler,
struct sof_ipc_ctrl_data *cdata)
Expand Down Expand Up @@ -645,6 +647,7 @@ comp_data_blob_handler_new_ext(struct comp_dev *dev, bool single_blob,

return handler;
}
EXPORT_SYMBOL(comp_data_blob_handler_new_ext);

void comp_data_blob_handler_free(struct comp_data_blob_handler *blob_handler)
{
Expand All @@ -655,3 +658,4 @@ void comp_data_blob_handler_free(struct comp_data_blob_handler *blob_handler)

rfree(blob_handler);
}
EXPORT_SYMBOL(comp_data_blob_handler_free);
2 changes: 1 addition & 1 deletion src/audio/eq_fir/eq_fir.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ static int eq_fir_reset(struct processing_module *mod)
return 0;
}

static struct module_interface eq_fir_interface = {
static const struct module_interface eq_fir_interface = {
.init = eq_fir_init,
.free = eq_fir_free,
.set_configuration = eq_fir_set_config,
Expand Down
2 changes: 1 addition & 1 deletion src/audio/eq_iir/eq_iir.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ static int eq_iir_reset(struct processing_module *mod)
return 0;
}

static struct module_interface eq_iir_interface = {
static const struct module_interface eq_iir_interface = {
.init = eq_iir_init,
.prepare = eq_iir_prepare,
.process_audio_stream = eq_iir_process,
Expand Down
4 changes: 2 additions & 2 deletions src/audio/mixin_mixout/mixin_mixout.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ static int mixin_set_config(struct processing_module *mod, uint32_t config_id,
return 0;
}

static struct module_interface mixin_interface = {
static const struct module_interface mixin_interface = {
.init = mixin_init,
.prepare = mixin_prepare,
.process_audio_stream = mixin_process,
Expand All @@ -868,7 +868,7 @@ static struct module_interface mixin_interface = {
DECLARE_MODULE_ADAPTER(mixin_interface, mixin_uuid, mixin_tr);
SOF_MODULE_INIT(mixin, sys_comp_module_mixin_interface_init);

static struct module_interface mixout_interface = {
static const struct module_interface mixout_interface = {
.init = mixout_init,
.prepare = mixout_prepare,
.process_audio_stream = mixout_process,
Expand Down
3 changes: 0 additions & 3 deletions src/audio/module_adapter/library/native_system_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ void *native_system_agent_start(uint32_t *sys_service,
native_sys_agent.log_handle = log_handle;

void *system_agent_p = &native_sys_agent;
uint32_t **sys_service_p = &sys_service;

*sys_service_p = (uint32_t *)(&native_sys_agent.system_service);

native_create_instance_f ci = (native_create_instance_f)entry_point;

Expand Down
7 changes: 3 additions & 4 deletions src/audio/module_adapter/module/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int module_load_config(struct comp_dev *dev, const void *cfg, size_t size)
return ret;
}

int module_init(struct processing_module *mod, struct module_interface *interface)
int module_init(struct processing_module *mod, const struct module_interface *interface)
{
int ret;
struct module_data *md = &mod->priv;
Expand All @@ -99,7 +99,7 @@ int module_init(struct processing_module *mod, struct module_interface *interfac
if (!interface->init || !interface->prepare ||
!interface->reset || !interface->free ||
(!!interface->process + !!interface->process_audio_stream +
!!interface->process_raw_data != 1)) {
!!interface->process_raw_data < 1)) {
comp_err(dev, "module_init(): comp %d is missing mandatory interfaces",
dev_comp_id(dev));
return -EIO;
Expand Down Expand Up @@ -222,8 +222,7 @@ int module_prepare(struct processing_module *mod,
* as it has been applied during the procedure - it is safe to
* free it.
*/
if (md->cfg.data)
rfree(md->cfg.data);
rfree(md->cfg.data);

md->cfg.avail = false;
md->cfg.data = NULL;
Expand Down
85 changes: 64 additions & 21 deletions src/audio/module_adapter/module/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ static int modules_init(struct processing_module *mod)
const struct ipc4_base_module_cfg *src_cfg = &md->cfg.base_cfg;
int ret = 0;
byte_array_t mod_cfg;
const struct ipc4_base_module_extended_cfg *base_cfg = md->cfg.init_data;

comp_info(mod->dev, "modules_init() start, pins %d %d",
base_cfg->base_cfg_ext.nb_input_pins,
base_cfg->base_cfg_ext.nb_output_pins);

mod_cfg.data = (uint8_t *)md->cfg.init_data;
/* Intel modules expects DW size here */
Expand All @@ -78,10 +83,9 @@ static int modules_init(struct processing_module *mod)
return -EINVAL;
}
md->module_entry_point = module_entry_point;
comp_info(mod->dev, "modules_init() start");

uint32_t module_id = IPC4_MOD_ID(mod->dev->ipc_config.id);
uint32_t instance_id = IPC4_INST_ID(mod->dev->ipc_config.id);
uint32_t module_id = IPC4_MOD_ID(config->id);
uint32_t instance_id = IPC4_INST_ID(config->id);
uint32_t log_handle = (uint32_t) mod->dev->drv->tctx;
/* Connect loadable module interfaces with module adapter entity. */
/* Check if native Zephyr lib is loaded */
Expand All @@ -92,17 +96,11 @@ static int modules_init(struct processing_module *mod)
comp_err(dev, "modules_init(): Failed to load manifest");
return -ENOMEM;
}
struct sof_man_module *module_entry =
(struct sof_man_module *)((char *)desc + SOF_MAN_MODULE_OFFSET(0));

struct sof_module_api_build_info *mod_buildinfo =
(struct sof_module_api_build_info *)
(module_entry->segment[SOF_MAN_SEGMENT_TEXT].v_base_addr);

void *mod_adp;

/* Check if module is FDK*/
if (mod_buildinfo->api_version_number.fields.major < SOF_MODULE_API_MAJOR_VERSION) {
/* Check if module is FDK */
if (0/*mod_buildinfo->api_version_number.fields.major < SOF_MODULE_API_MAJOR_VERSION*/) {
mod_adp = system_agent_start(md->module_entry_point, module_id,
instance_id, 0, log_handle, &mod_cfg);
} else {
Expand All @@ -111,6 +109,9 @@ static int modules_init(struct processing_module *mod)
mod_adp = native_system_agent_start(mod->sys_service, md->module_entry_point,
module_id, instance_id, 0, log_handle,
&mod_cfg);
comp_info(mod->dev, "modules_init() got %p, init %p, need %u and %u",
mod_adp, ((const struct module_interface *)mod_adp)->init,
src_cfg->ibs, src_cfg->obs);
}

md->module_adapter = mod_adp;
Expand All @@ -136,10 +137,23 @@ static int modules_init(struct processing_module *mod)
struct module_interface *mod_in =
(struct module_interface *)md->module_adapter;

if (mod_in->process)
mod->proc_type = MODULE_PROCESS_TYPE_SOURCE_SINK;
else if (mod_in->process_audio_stream)
mod->proc_type = MODULE_PROCESS_TYPE_STREAM;
else if (mod_in->process_raw_data)
mod->proc_type = MODULE_PROCESS_TYPE_RAW;
else
return -EINVAL;

comp_info(mod->dev, "modules_init() calling %p @ %p, mod %p type %u",
mod_in->init, &mod_in->init, mod, mod->proc_type);

ret = mod_in->init(mod);
} else {
ret = iadk_wrapper_init(md->module_adapter);
}

return ret;
}

Expand Down Expand Up @@ -168,7 +182,7 @@ static int modules_prepare(struct processing_module *mod,
struct module_interface *mod_in =
(struct module_interface *)mod->priv.module_adapter;

ret = mod_in->prepare(mod, NULL, 0, NULL, 0);
ret = mod_in->prepare(mod, sources, num_of_sources, sinks, num_of_sinks);
} else {
ret = iadk_wrapper_prepare(mod->priv.module_adapter);
}
Expand All @@ -189,18 +203,45 @@ static int modules_init_process(struct processing_module *mod)
return 0;
}

static int modules_process(struct processing_module *mod,
struct sof_source __sparse_cache **sources, int num_of_sources,
struct sof_sink __sparse_cache **sinks, int num_of_sinks)
{
if (!mod->is_native_sof)
return -EOPNOTSUPP;

struct module_interface *mod_in = (struct module_interface *)mod->priv.module_adapter;

return mod_in->process(mod, sources, num_of_sources, sinks, num_of_sinks);
}

static int modules_process_audio_stream(struct processing_module *mod,
struct input_stream_buffer *input_buffers,
int num_input_buffers,
struct output_stream_buffer *output_buffers,
int num_output_buffers)
{
if (!mod->is_native_sof)
return -EOPNOTSUPP;

struct module_interface *mod_in = (struct module_interface *)mod->priv.module_adapter;

return mod_in->process_audio_stream(mod, input_buffers, num_input_buffers,
output_buffers, num_output_buffers);
}

/*
* \brief modules_process.
* \brief modules_process_raw.
* \param[in] mod - processing module pointer.
*
* \return: zero on success
* error code on failure
*/
static int modules_process(struct processing_module *mod,
struct input_stream_buffer *input_buffers,
int num_input_buffers,
struct output_stream_buffer *output_buffers,
int num_output_buffers)
static int modules_process_raw(struct processing_module *mod,
struct input_stream_buffer *input_buffers,
int num_input_buffers,
struct output_stream_buffer *output_buffers,
int num_output_buffers)
{
struct comp_dev *dev = mod->dev;
struct module_data *md = &mod->priv;
Expand Down Expand Up @@ -374,11 +415,13 @@ static int modules_reset(struct processing_module *mod)
return iadk_wrapper_reset(mod->priv.module_adapter);
}

/* Processing Module Adapter API*/
/* Processing Module Adapter API */
static struct module_interface interface = {
.init = modules_init,
.init = modules_init,
.prepare = modules_prepare,
.process_raw_data = modules_process,
.process_raw_data = modules_process_raw,
.process = modules_process,
.process_audio_stream = modules_process_audio_stream,
.set_processing_mode = modules_set_processing_mode,
.get_processing_mode = modules_get_processing_mode,
.set_configuration = modules_set_configuration,
Expand Down
2 changes: 1 addition & 1 deletion src/audio/module_adapter/module/volume/volume.c
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ DECLARE_MODULE_ADAPTER(volume_interface, volume_uuid, volume_tr);
SOF_MODULE_INIT(volume, sys_comp_module_volume_interface_init);

#if CONFIG_COMP_GAIN
static struct module_interface gain_interface = {
static const struct module_interface gain_interface = {
.init = volume_init,
.prepare = volume_prepare,
.process_audio_stream = volume_process,
Expand Down
Loading

0 comments on commit a9a8c4c

Please sign in to comment.