Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loadable up down mixer #8667

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lmdk/libraries/module_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

cmake_minimum_required(VERSION 3.20)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/../../cmake/xtensa-toolchain.cmake")

project(example_up_down_mixer)

# list of modules to be built and included into this loadable library
set(MODULES_LIST up_down_mixer)

# toml file for rimage to generate manifets
set(TOML "${CMAKE_CURRENT_LIST_DIR}/module_example_mtl.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)
85 changes: 85 additions & 0 deletions lmdk/libraries/module_example/module_example_mtl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
version = [3, 0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this file needed, and particularly in this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toml is modular now, so we can take the up/down mixer parts in the correct place.


[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 = "UPDWMIX"
uuid = "ffffffff-832F-4DBF-B247-51E961997B34"
affinity_mask = "0x1"
instance_count = "15"
domain_types = "0"
load_type = "0"
module_type = "5"
auto_start = "0"
sched_caps = [1, 0x00008000]

# pin = [dir, type, sample rate, size, container, channel-cfg]
pin = [0, 0, 0xffff, 0xc, 0x8, 0x05ff,
1, 0, 0xffff, 0xc, 0x8, 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, 216, 706000, 12, 16, 0, 0, 0,
1, 0, 0, 0, 216, 1271000, 8, 8, 0, 0, 0,
2, 0, 0, 0, 216, 1839000, 89, 118, 0, 0, 0,
3, 0, 0, 0, 216, 2435000, 48, 64, 0, 0, 0,
4, 0, 0, 0, 216, 3343000, 192, 192, 0, 0, 0,
5, 0, 0, 0, 216, 3961000, 177, 177, 0, 0, 0,
6, 0, 0, 0, 216, 4238000, 192, 256, 0, 0, 0,
7, 0, 0, 0, 216, 6691000, 192, 256, 0, 0, 0]

30 changes: 30 additions & 0 deletions lmdk/modules/up_down_mixer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
set(LMDK_BUILD 0)
set(SOF_SRC_DIR ../../../src)
set(LMDK_DIR_INCLUDE ../../../lmdk/include)
target_sources(up_down_mixer PRIVATE ${SOF_SRC_DIR}/audio/up_down_mixer/up_down_mixer.c ${SOF_SRC_DIR}/audio/up_down_mixer/up_down_mixer_hifi3.c)

set_target_properties(up_down_mixer PROPERTIES
HPSRAM_ADDR "0xa06b1000"
)

target_compile_definitions(up_down_mixer PRIVATE CONFIG_XTENSA=1
CONFIG_IPC_MAJOR_4=1
CONFIG_LIBRARY=1
MODULE_PRIVAT=1
XCHAL_HAVE_HIFI3=1
SOF_MODULE_API_PRIVATE=1)

if(LMDK_BUILD)
target_include_directories(up_down_mixer PRIVATE "${LMDK_DIR_INCLUDE}"
"${LMDK_DIR_INCLUDE}/sof"
"${LMDK_DIR_INCLUDE}/sof/audio"
"${LMDK_DIR_INCLUDE}/module/audio")
else()
target_include_directories(up_down_mixer PRIVATE "${SOF_SRC_DIR}/include"
"${SOF_SRC_DIR}/include/ipc"
"${SOF_SRC_DIR}/include/ipc4"
"${SOF_SRC_DIR}/include/sof/audio/module_adapter/iadk"
"${SOF_SRC_DIR}/../posix/include"
"${SOF_SRC_DIR}/../posix/include/sof"
)
endif()
83 changes: 47 additions & 36 deletions src/audio/up_down_mixer/up_down_mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,27 @@
// Author: Bartosz Kokoszko <[email protected]>
// Author: Adrian Bonislawski <[email protected]>

#include <sof/audio/buffer.h>
#include <sof/audio/format.h>
#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/pipeline.h>
#include <rtos/panic.h>
#include <sof/ipc/msg.h>
#include <rtos/alloc.h>
#include <rtos/cache.h>
#include <rtos/init.h>
#include <sof/lib/memory.h>
#include <sof/lib/notifier.h>
#include <sof/lib/uuid.h>
#include <sof/list.h>
#include <rtos/string.h>
#include <sof/ut.h>
#include <sof/trace/trace.h>
#include <user/trace.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <module/module/base.h>
#include <module/module/api_ver.h>
#include <rimage/sof/user/manifest.h>
#include <module/audio/source_api.h>
#include <module/audio/sink_api.h>

#include "up_down_mixer_coef.h"
#include "up_down_mixer.h"

LOG_MODULE_REGISTER(up_down_mixer, CONFIG_SOF_LOG_LEVEL);
#include <errno.h>
#include <sof/audio/module_adapter/library/native_system_service.h>
#include <stdlib.h>
#include <stdint.h>

/* these ids aligns windows driver requirement to support windows driver */
/* 42f8060c-832f-4dbf-b247-51e961997b34 */
DECLARE_SOF_RT_UUID("up_down_mixer", up_down_mixer_comp_uuid, 0x42f8060c, 0x832f,
0x4dbf, 0xb2, 0x47, 0x51, 0xe9, 0x61, 0x99, 0x7b, 0x34);
/* Logging is temporary disabled */
#define comp_err(...)
#define comp_dbg(...)

DECLARE_TR_CTX(up_down_mixer_comp_tr, SOF_UUID(up_down_mixer_comp_uuid),
LOG_LEVEL_INFO);
static struct native_system_service_api* system_service;
uint32_t heap_mem[2048] __attribute__((section(".heap_mem"))) __attribute__((aligned(4096)));

int32_t custom_coeffs[UP_DOWN_MIX_COEFFS_LENGTH];

Expand All @@ -51,7 +39,7 @@ static int set_downmix_coefficients(struct processing_module *mod,
int ret;

if (cd->downmix_coefficients) {
ret = memcpy_s(&custom_coeffs, sizeof(custom_coeffs), downmix_coefficients,
ret = system_service->safe_memcpy(&custom_coeffs, sizeof(custom_coeffs), downmix_coefficients,
sizeof(int32_t) * UP_DOWN_MIX_COEFFS_LENGTH);

if (ret < 0)
Expand Down Expand Up @@ -329,9 +317,9 @@ static int up_down_mixer_free(struct processing_module *mod)
{
struct up_down_mixer_data *cd = module_get_private_data(mod);

rfree(cd->buf_in);
rfree(cd->buf_out);
rfree(cd);
free(cd->buf_in);
free(cd->buf_out);
free(cd);

return 0;
}
Expand All @@ -345,16 +333,16 @@ static int up_down_mixer_init(struct processing_module *mod)
struct up_down_mixer_data *cd;
int ret;

cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd));
cd = malloc(sizeof(struct up_down_mixer_data));
if (!cd) {
comp_free(dev);
free(dev);
return -ENOMEM;
}

mod_data->private = cd;

cd->buf_in = rballoc(0, SOF_MEM_CAPS_RAM, mod->priv.cfg.base_cfg.ibs);
cd->buf_out = rballoc(0, SOF_MEM_CAPS_RAM, mod->priv.cfg.base_cfg.obs);
cd->buf_in = malloc(mod->priv.cfg.base_cfg.ibs);
cd->buf_out = malloc(mod->priv.cfg.base_cfg.obs);
if (!cd->buf_in || !cd->buf_out) {
ret = -ENOMEM;
goto err;
Expand Down Expand Up @@ -451,5 +439,28 @@ static const struct module_interface up_down_mixer_interface = {
.free = up_down_mixer_free
};

DECLARE_MODULE_ADAPTER(up_down_mixer_interface, up_down_mixer_comp_uuid, up_down_mixer_comp_tr);
SOF_MODULE_INIT(up_down_mixer, sys_comp_module_up_down_mixer_interface_init);
DECLARE_LOADABLE_MODULE_API_VERSION(udm);

static void* entry_point(void* mod_cfg, void* parent_ppl, void** mod_ptr)
{
system_service = *(const struct native_system_agent**)mod_ptr;

return &up_down_mixer_interface;
}

//"42F8060C-832F-4DBF-B247-51E961997B34"
__attribute__((section(".module")))
const struct sof_man_module_manifest udm_manifest = {
.module = {
.name = "UPDWMIX",
.uuid = {0x0c, 0x06, 0xf8, 0x42,
0x2f, 0x83,
0xbf, 0x4d,
0xb2, 0x47,
0x51, 0xe9, 0x61, 0x99, 0x7b, 0x34},
.entry_point = (uint32_t)entry_point,
.type = {.load_type = SOF_MAN_MOD_TYPE_MODULE,
.domain_ll = 1 },
.affinity_mask = 1,
}
};
5 changes: 0 additions & 5 deletions src/audio/up_down_mixer/up_down_mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@

#ifndef __SOF_AUDIO_UP_DOWN_MIXER_H__
#define __SOF_AUDIO_UP_DOWN_MIXER_H__

#include <sof/audio/component_ext.h>
#include <sof/audio/ipc-config.h>
#include <sof/common.h>
#include <ipc/stream.h>
#include <ipc4/module.h>
#include <ipc4/base-config.h>
#include <stddef.h>
#include <stdint.h>

Expand Down
105 changes: 71 additions & 34 deletions src/audio/up_down_mixer/up_down_mixer.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, all this must not be here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where can it be more suitable place to leave that toml?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where can it be more suitable place to leave that toml?

sorry, I meant that specific part that you're adding here. It's platform specific and it should be in a suitable .toml and they should be merged together by the C preprocessor similar to how https://github.com/thesofproject/sof/blob/main/tools/rimage/config/mtl.toml.h currently includes all module toml files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point


[[module.entry]]
name = "UPDWMIX"
uuid = "42F8060C-832F-4DBF-B247-51E961997B34"
Expand All @@ -9,40 +69,17 @@
auto_start = "0"
sched_caps = [1, 0x00008000]

// pin = [dir, type, sample rate, size, container, channel-cfg]
# pin = [dir, type, sample rate, size, container, channel-cfg]
pin = [0, 0, 0xffff, 0xc, 0x8, 0x05ff,
1, 0, 0xffff, 0xc, 0x8, 0x45ff]

// mod_cfg [PAR_0 PAR_1 PAR_2 PAR_3 IS_BYTES CPS IBS OBS MOD_FLAGS CPC OBLS]
mod_cfg = [1, 0, 0, 0, 216, 5044000, 384, 192, 0, 5044, 0,
2, 0, 0, 0, 216, 2660000, 384, 384, 0, 2660, 0,
3, 0, 0, 0, 216, 3164000, 576, 384, 0, 3164, 0,
4, 0, 0, 0, 216, 3316000, 768, 384, 0, 3316, 0,
5, 0, 0, 0, 216, 5264000, 768, 384, 0, 5264, 0,
6, 0, 0, 0, 216, 5440000, 768, 384, 0, 5440, 0,
7, 0, 0, 0, 216, 2888000, 768, 192, 0, 2888, 0,
8, 0, 0, 0, 216, 2856000, 768, 192, 0, 2856, 0,
9, 0, 0, 0, 216, 2876000, 768, 192, 0, 2876, 0,
10, 0, 0, 0, 216, 2956000, 960, 192, 0, 2956, 0,
11, 0, 0, 0, 216, 2888000, 1152, 192, 0, 2888, 0,
12, 0, 0, 0, 216, 2888000, 1152, 192, 0, 2888, 0,
13, 0, 0, 0, 216, 2816000, 1536, 192, 0, 2816, 0,
14, 0, 0, 0, 216, 2468000, 192, 384, 0, 2468, 0,
15, 0, 0, 0, 216, 3084000, 576, 384, 0, 3084, 0,
16, 0, 0, 0, 216, 3442000, 960, 384, 0, 3442, 0,
17, 0, 0, 0, 216, 3478000, 1152, 384, 0, 3478, 0,
18, 0, 0, 0, 216, 3478000, 1152, 384, 0, 3478, 0,
19, 0, 0, 0, 216, 3736000, 1536, 384, 0, 3736, 0,
20, 0, 0, 0, 216, 3216000, 192, 1152, 0, 3216, 0,
21, 0, 0, 0, 216, 3308000, 384, 1152, 0, 3308, 0,
22, 0, 0, 0, 216, 3616000, 768, 1152, 0, 3616, 0,
23, 0, 0, 0, 216, 3616000, 768, 1152, 0, 3616, 0,
24, 0, 0, 0, 216, 4916000, 1536, 1152, 0, 4916, 0,
25, 0, 0, 0, 216, 3228000, 192, 1152, 0, 3228, 0,
26, 0, 0, 0, 216, 3452000, 384, 1152, 0, 3452, 0,
27, 0, 0, 0, 216, 4016000, 768, 1152, 0, 4016, 0,
28, 0, 0, 0, 216, 5080000, 1536, 1152, 0, 5080, 0,
29, 0, 0, 0, 216, 3552000, 384, 1536, 0, 3552, 0,
30, 0, 0, 0, 216, 3728000, 768, 1152, 0, 3728, 0]

index = __COUNTER__
# 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, 216, 706000, 12, 16, 0, 0, 0,
1, 0, 0, 0, 216, 1271000, 8, 8, 0, 0, 0,
2, 0, 0, 0, 216, 1839000, 89, 118, 0, 0, 0,
3, 0, 0, 0, 216, 2435000, 48, 64, 0, 0, 0,
4, 0, 0, 0, 216, 3343000, 192, 192, 0, 0, 0,
5, 0, 0, 0, 216, 3961000, 177, 177, 0, 0, 0,
6, 0, 0, 0, 216, 4238000, 192, 256, 0, 0, 0,
7, 0, 0, 0, 216, 6691000, 192, 256, 0, 0, 0]

Loading
Loading