diff --git a/lmdk/cmake/ldscripts/common_rodata_linker_script.txt b/lmdk/cmake/ldscripts/common_rodata_linker_script.txt index 2f3e4bfad4d9..343107e7d37d 100644 --- a/lmdk/cmake/ldscripts/common_rodata_linker_script.txt +++ b/lmdk/cmake/ldscripts/common_rodata_linker_script.txt @@ -1,7 +1,4 @@ - -PHDRS { - rodata_phdr PT_LOAD; -} +/* The .rodata PHDR is already defined in data_linker_script.txt */ SECTIONS { .common.rodata : ALIGN(4096) { diff --git a/lmdk/cmake/ldscripts/common_text_linker_script.txt b/lmdk/cmake/ldscripts/common_text_linker_script.txt index 10468dc4bf3a..ecdd39d738c4 100644 --- a/lmdk/cmake/ldscripts/common_text_linker_script.txt +++ b/lmdk/cmake/ldscripts/common_text_linker_script.txt @@ -1,7 +1,4 @@ - -PHDRS { - text_phdr PT_LOAD; -} +/* The .text PHDR is already defined in text_linker_script.txt */ SECTIONS { .common.text : ALIGN(4096){ diff --git a/lmdk/cmake/ldscripts/data_linker_script.txt b/lmdk/cmake/ldscripts/data_linker_script.txt index cbdf8001c0be..63eed21cb07a 100644 --- a/lmdk/cmake/ldscripts/data_linker_script.txt +++ b/lmdk/cmake/ldscripts/data_linker_script.txt @@ -15,7 +15,7 @@ SECTIONS { _data_end = ABSOLUTE(.); } >HPSRAM_seg : data_phdr - .rodata : { + .rodata : ALIGN(4096) { _rodata_start = ABSOLUTE(.); *(.gnu.linkonce.r.*) *(.rodata) diff --git a/lmdk/libraries/smart_amp_test/CMakeLists.txt b/lmdk/libraries/smart_amp_test/CMakeLists.txt new file mode 100644 index 000000000000..0282a83bbf90 --- /dev/null +++ b/lmdk/libraries/smart_amp_test/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.20) +set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/../../cmake/xtensa-toolchain.cmake") + +project(smart_amp_test) + +macro(is_zephyr ret) + if(CONFIG_ZEPHYR_SOF_MODULE) + set(${ret} TRUE) + else() + set(${ret} FALSE) + endif() +endmacro() + +# list of modules to be built and included into this loadable library +set(MODULES_LIST smart_amp_test) + +# toml file for rimage to generate manifets +set(TOML "${CMAKE_CURRENT_LIST_DIR}/smart_amp_test.toml") + +# TODO: Move it somewhere??? +add_definitions(-DMAJOR_IADSP_API_VERSION=5) +add_definitions(-DMIDDLE_IADSP_API_VERSION=0) +add_definitions(-DMINOR_IADSP_API_VERSION=0) + +include(../../cmake/build.cmake) diff --git a/lmdk/libraries/smart_amp_test/smart_amp_test.toml b/lmdk/libraries/smart_amp_test/smart_amp_test.toml new file mode 100644 index 000000000000..34f3463343dd --- /dev/null +++ b/lmdk/libraries/smart_amp_test/smart_amp_test.toml @@ -0,0 +1,79 @@ +version = [3, 0] + +[adsp] +name = "mtl" +image_size = "0x2C0000" # (22) bank * 128KB +alias_mask = "0xE0000000" + +[[adsp.mem_zone]] +type = "ROM" +base = "0x1FF80000" +size = "0x400" +[[adsp.mem_zone]] +type = "IMR" +base = "0xA104A000" +size = "0x2000" +[[adsp.mem_zone]] +type = "SRAM" +base = "0xa00f0000" +size = "0x100000" + +[[adsp.mem_alias]] +type = "uncached" +base = "0x40000000" +[[adsp.mem_alias]] +type = "cached" +base = "0xA0000000" + +[cse] +partition_name = "ADSP" +[[cse.entry]] +name = "ADSP.man" +offset = "0x5c" +length = "0x464" +[[cse.entry]] +name = "ADSP.met" +offset = "0x4c0" +length = "0x70" +[[cse.entry]] +name = "ADSP" +offset = "0x540" +length = "0x0" # calculated by rimage + +[css] + +[signed_pkg] +name = "ADSP" +[[signed_pkg.module]] +name = "ADSP.met" + +[adsp_file] +[[adsp_file.comp]] +base_offset = "0x2000" + +[fw_desc.header] +name = "ADSPFW" +load_offset = "0x40000" + +[module] +count = 1 + + [[module.entry]] + name = "SMATEST" + uuid = "167A961E-8AE4-11EA-89F1-000C29CE1635" + affinity_mask = "0x1" + instance_count = "1" + domain_types = "0" + load_type = "0" + init_config = "1" + module_type = "0xD" + auto_start = "0" + sched_caps = [1, 0x00008000] + + # pin = [dir, type, sample rate, size, container, channel-cfg] + pin = [0, 0, 0xfeef, 0xf, 0xa, 0x45ff, + 0, 0, 0xfeef, 0xf, 0xa, 0x45ff, + 1, 0, 0xfeef, 0xf, 0xa, 0x45ff] + + # mod_cfg [PAR_0 PAR_1 PAR_2 PAR_3 IS_BYTES CPS IBS OBS MOD_FLAGS CPC OBLS] + mod_cfg = [0, 0, 0, 0, 4096, 1000000, 128, 128, 0, 0, 0] diff --git a/lmdk/modules/smart_amp_test/CMakeLists.txt b/lmdk/modules/smart_amp_test/CMakeLists.txt new file mode 100644 index 000000000000..37fcdb87108b --- /dev/null +++ b/lmdk/modules/smart_amp_test/CMakeLists.txt @@ -0,0 +1,13 @@ +target_sources(smart_amp_test PRIVATE ${SOF_BASE}/src/samples/audio/smart_amp_test_ipc4.c) + +set_target_properties(smart_amp_test PROPERTIES + HPSRAM_ADDR "0xa06c1000" +) + +target_compile_definitions(smart_amp_test PRIVATE + __SOF_MODULE_SERVICE_BUILD__=1 + CONFIG_XTENSA=1 + CONFIG_IPC_MAJOR_4=1 +) + +target_include_directories(smart_amp_test PRIVATE "${SOF_BASE}/src/include") diff --git a/src/audio/module_adapter/module/generic.c b/src/audio/module_adapter/module/generic.c index 3ab9f991feb9..565209af6951 100644 --- a/src/audio/module_adapter/module/generic.c +++ b/src/audio/module_adapter/module/generic.c @@ -98,7 +98,7 @@ int module_init(struct processing_module *mod, const struct module_interface *in /* check interface, there must be one and only one of processing procedure */ if (!interface->init || (!!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; @@ -258,10 +258,10 @@ int module_process_legacy(struct processing_module *mod, /* set state to processing */ md->state = MODULE_PROCESSING; #endif - if (md->ops->process_audio_stream) + if (IS_PROCESSING_MODE_AUDIO_STREAM(mod)) ret = md->ops->process_audio_stream(mod, input_buffers, num_input_buffers, output_buffers, num_output_buffers); - else if (md->ops->process_raw_data) + else if (IS_PROCESSING_MODE_RAW_DATA(mod)) ret = md->ops->process_raw_data(mod, input_buffers, num_input_buffers, output_buffers, num_output_buffers); else diff --git a/src/audio/module_adapter/module/modules.c b/src/audio/module_adapter/module/modules.c index 1f7ee82b6a42..61bcd7b02421 100644 --- a/src/audio/module_adapter/module/modules.c +++ b/src/audio/module_adapter/module/modules.c @@ -142,10 +142,22 @@ static int modules_init(struct processing_module *mod) struct module_interface *mod_in = (struct module_interface *)md->module_adapter; + /* The order of preference */ + 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; + ret = mod_in->init(mod); } else { + mod->proc_type = MODULE_PROCESS_TYPE_RAW; ret = iadk_wrapper_init(md->module_adapter); } + return ret; } @@ -174,7 +186,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); } @@ -195,18 +207,45 @@ static int modules_init_process(struct processing_module *mod) return 0; } +static int modules_process(struct processing_module *mod, + struct sof_source **sources, int num_of_sources, + struct sof_sink **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; @@ -384,7 +423,9 @@ static int modules_reset(struct processing_module *mod) static const struct module_interface interface = { .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, diff --git a/src/audio/module_adapter/module_adapter.c b/src/audio/module_adapter/module_adapter.c index e30c6cbc51cb..3a8fff55c0f5 100644 --- a/src/audio/module_adapter/module_adapter.c +++ b/src/audio/module_adapter/module_adapter.c @@ -93,6 +93,16 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv, mod->max_sources = 1; mod->max_sinks = 1; + /* The order of preference */ + if (interface->process) + mod->proc_type = MODULE_PROCESS_TYPE_SOURCE_SINK; + else if (interface->process_audio_stream) + mod->proc_type = MODULE_PROCESS_TYPE_STREAM; + else if (interface->process_raw_data) + mod->proc_type = MODULE_PROCESS_TYPE_RAW; + else + goto err; + /* Init processing module */ ret = module_init(mod, interface); if (ret) { diff --git a/src/include/ipc4/base-config.h b/src/include/ipc4/base-config.h index b95ecbd3e1f9..07a35a47e9aa 100644 --- a/src/include/ipc4/base-config.h +++ b/src/include/ipc4/base-config.h @@ -23,8 +23,9 @@ #ifndef __SOF_IPC4_BASE_CONFIG_H__ #define __SOF_IPC4_BASE_CONFIG_H__ - +#ifndef __SOF_MODULE_SERVICE_BUILD__ #include +#endif #include struct sof_ipc_stream_params; diff --git a/src/include/module/module/base.h b/src/include/module/module/base.h index 56964162467f..ea951412c653 100644 --- a/src/include/module/module/base.h +++ b/src/include/module/module/base.h @@ -60,6 +60,12 @@ struct module_data { #endif /* SOF_MODULE_PRIVATE */ }; +enum module_processing_type { + MODULE_PROCESS_TYPE_SOURCE_SINK, + MODULE_PROCESS_TYPE_STREAM, + MODULE_PROCESS_TYPE_RAW, +}; + /* * A pointer to this structure is passed to module API functions (from struct module_interface). * This structure should contain only fields that should be available to a module. @@ -153,6 +159,8 @@ struct processing_module { /* max source/sinks supported by the module */ uint32_t max_sources; uint32_t max_sinks; + + enum module_processing_type proc_type; #endif /* SOF_MODULE_PRIVATE */ }; diff --git a/src/include/sof/audio/module_adapter/module/generic.h b/src/include/sof/audio/module_adapter/module/generic.h index 1ab2485fe348..a108b81f1404 100644 --- a/src/include/sof/audio/module_adapter/module/generic.h +++ b/src/include/sof/audio/module_adapter/module/generic.h @@ -25,14 +25,9 @@ * helpers to determine processing type * Needed till all the modules use PROCESSING_MODE_SINK_SOURCE */ -#define IS_PROCESSING_MODE_AUDIO_STREAM(mod) \ - (!!((struct module_data *)&(mod)->priv)->ops->process_audio_stream) - -#define IS_PROCESSING_MODE_RAW_DATA(mod) \ - (!!((struct module_data *)&(mod)->priv)->ops->process_raw_data) - -#define IS_PROCESSING_MODE_SINK_SOURCE(mod) \ - (!!((struct module_data *)&(mod)->priv)->ops->process) +#define IS_PROCESSING_MODE_AUDIO_STREAM(mod) ((mod)->proc_type == MODULE_PROCESS_TYPE_STREAM) +#define IS_PROCESSING_MODE_RAW_DATA(mod) ((mod)->proc_type == MODULE_PROCESS_TYPE_RAW) +#define IS_PROCESSING_MODE_SINK_SOURCE(mod) ((mod)->proc_type == MODULE_PROCESS_TYPE_SOURCE_SINK) #define MAX_BLOB_SIZE 8192 #define MODULE_MAX_SOURCES 8 diff --git a/src/include/sof/samples/audio/smart_amp_test.h b/src/include/sof/samples/audio/smart_amp_test.h index 3feda5005125..c5ddd8032d99 100644 --- a/src/include/sof/samples/audio/smart_amp_test.h +++ b/src/include/sof/samples/audio/smart_amp_test.h @@ -8,8 +8,10 @@ #ifndef __SOF_AUDIO_SMART_AMP_H__ #define __SOF_AUDIO_SMART_AMP_H__ +#ifndef __SOF_MODULE_SERVICE_BUILD__ #include #include +#endif #if CONFIG_IPC_MAJOR_4 #include @@ -19,10 +21,20 @@ #define SMART_AMP_MAX_STREAM_CHAN 8 +/* Max channels for all intel platforms are 8 */ +#define MAX_CHANNELS 8 + /** IPC blob types */ #define SOF_SMART_AMP_CONFIG 0 #define SOF_SMART_AMP_MODEL 1 +#ifdef __SOF_MODULE_SERVICE_BUILD__ +#define LOG_ERR(...) +#define LOG_WRN(...) +#define LOG_DBG(...) +#define LOG_INF(...) +#endif + struct smart_amp_model_data { uint32_t data_size; void *data; @@ -83,8 +95,8 @@ struct smart_amp_model_data { struct sof_smart_amp_config { uint32_t size; uint32_t feedback_channels; - int8_t source_ch_map[PLATFORM_MAX_CHANNELS]; - int8_t feedback_ch_map[PLATFORM_MAX_CHANNELS]; + int8_t source_ch_map[MAX_CHANNELS]; + int8_t feedback_ch_map[MAX_CHANNELS]; }; #if CONFIG_IPC_MAJOR_4 diff --git a/src/samples/audio/smart_amp_test_ipc4.c b/src/samples/audio/smart_amp_test_ipc4.c index d09a8f9a9720..f6ffd6dae115 100644 --- a/src/samples/audio/smart_amp_test_ipc4.c +++ b/src/samples/audio/smart_amp_test_ipc4.c @@ -3,8 +3,9 @@ // Copyright(c) 2020 Intel Corporation. All rights reserved. // // Author: Bartosz Kokoszko + +#ifndef __SOF_MODULE_SERVICE_BUILD__ #include -#include #include #include #include @@ -18,6 +19,7 @@ #include LOG_MODULE_REGISTER(smart_amp_test, CONFIG_SOF_LOG_LEVEL); +#include /* 167a961e-8ae4-11ea-89f1-000c29ce1635 */ DECLARE_SOF_RT_UUID("smart_amp-test", smart_amp_test_comp_uuid, 0x167a961e, 0x8ae4, @@ -25,110 +27,104 @@ DECLARE_SOF_RT_UUID("smart_amp-test", smart_amp_test_comp_uuid, 0x167a961e, 0x8a DECLARE_TR_CTX(smart_amp_test_comp_tr, SOF_UUID(smart_amp_test_comp_uuid), LOG_LEVEL_INFO); -typedef int(*smart_amp_proc)(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, - int8_t *chan_map); +#else +#include +#include +#include + +#include +#include +#include +#include +#include +#include