Skip to content

Commit

Permalink
debug_module: added new loadable module
Browse files Browse the repository at this point in the history
Module added to be able to test various functionalities
that are only available from the FW side (DSP),
and cannot otherwise be tested from the host side.
Functions it implements: fw exception (force divide by zero),
start and not update watchdog,
access to DTF message preparation,
 access to HW from SHA counting,
tests access to GNA module.

Signed-off-by: Fabiola Kwasowiec <[email protected]>
  • Loading branch information
fkwasowi committed Jan 25, 2024
1 parent 109843b commit 584cbb5
Show file tree
Hide file tree
Showing 18 changed files with 445 additions and 14 deletions.
1 change: 1 addition & 0 deletions app/boards/intel_adsp_ace15_mtpm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ CONFIG_LOG_FUNC_NAME_PREFIX_INF=y
CONFIG_LOG_FUNC_NAME_PREFIX_DBG=y
CONFIG_COMP_VOLUME_WINDOWS_FADE=y
CONFIG_COMP_UP_DOWN_MIXER=n
CONFIG_COMP_DEBUG_MODULE=y
CONFIG_COMP_CHAIN_DMA=y
CONFIG_SAMPLE_KEYPHRASE=y
CONFIG_SYS_CLOCK_TICKS_PER_SEC=12000
Expand Down
1 change: 1 addition & 0 deletions app/boards/intel_adsp_ace20_lnl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ CONFIG_LOG_FUNC_NAME_PREFIX_INF=y
CONFIG_LOG_FUNC_NAME_PREFIX_DBG=y
CONFIG_COMP_VOLUME_WINDOWS_FADE=y
CONFIG_COMP_UP_DOWN_MIXER=y
CONFIG_COMP_DEBUG_MODULE=y
CONFIG_COMP_CHAIN_DMA=y
CONFIG_SAMPLE_KEYPHRASE=y
CONFIG_SYS_CLOCK_TICKS_PER_SEC=12000
Expand Down
1 change: 1 addition & 0 deletions app/stub_build_all_ipc4.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CONFIG_COMP_STUBS=y
CONFIG_COMP_ARIA=y
CONFIG_COMP_CHAIN_DMA=y
CONFIG_COMP_UP_DOWN_MIXER=y
CONFIG_COMP_DEBUG_MODULE=y
CONFIG_IPC_MAJOR_4=y
CONFIG_SAMPLES=y
CONFIG_SAMPLE_SMART_AMP=y
4 changes: 2 additions & 2 deletions lmdk/libraries/module_example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
cmake_minimum_required(VERSION 3.20)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/../../cmake/xtensa-toolchain.cmake")

project(example_up_down_mixer)
project(lp_validation)

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

# toml file for rimage to generate manifets
set(TOML "${CMAKE_CURRENT_LIST_DIR}/module_example_mtl.toml")
Expand Down
15 changes: 4 additions & 11 deletions lmdk/libraries/module_example/module_example_mtl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ load_offset = "0x40000"
count = 1

[[module.entry]]
name = "UPDWMIX"
uuid = "ffffffff-832F-4DBF-B247-51E961997B34"
name = "DEBUG"
uuid = "5fa8976c-581b-4ea6-8fd3-e94dd39a3669"
affinity_mask = "0x1"
instance_count = "15"
domain_types = "0"
load_type = "0"
module_type = "5"
module_type = "0xE"
auto_start = "0"
sched_caps = [1, 0x00008000]

Expand All @@ -74,12 +74,5 @@ count = 1
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]
mod_cfg = [0, 0, 0, 0, 4096, 100000, 10, 10, 0,1000, 0]

34 changes: 34 additions & 0 deletions lmdk/modules/debug_module/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
set(SOF_SRC_DIR ../../../src)
set(ZEPHYR_SRC_DIR ../../../../zephyr/lib/libc/minimal/include)
target_sources(debug_module PRIVATE ${SOF_SRC_DIR}/audio/debug_module/debug_module.c)

set_target_properties(debug_module PROPERTIES
HPSRAM_ADDR "0xa06b1000"
)

target_compile_definitions(debug_module PRIVATE __ZEPHYR__=1
CONFIG_ZEPHYR_NATIVE_DRIVERS=1
CONFIG_XTENSA=1
CONFIG_IPC_MAJOR_4=1
CONFIG_LIBRARY=1
__ZEPHYR_RTOS_IDC_H__=1
MODULE_PRIVAT=1
XCHAL_HAVE_HIFI3=1)

message( ${LMDK_DIR}${SOF_SRC_DIR}../posix/include )

target_include_directories(debug_module PRIVATE "${SOF_SRC_DIR}/include"
"${SOF_SRC_DIR}/include/coefficients"
"${SOF_SRC_DIR}/include/ipc"
"${SOF_SRC_DIR}/include/ipc4"
"${SOF_SRC_DIR}/include/math"
"${SOF_SRC_DIR}/include/lib"
"${SOF_SRC_DIR}/include/sof/audio/module_adapter/iadk"
"${SOF_SRC_DIR}/platform/library/include"
"${SOF_SRC_DIR}/../zephyr/include"
"${SOF_SRC_DIR}/../zephyr/include/zephyr/sys"
"${SOF_SRC_DIR}/../zephyr/lib/libc/minimal/include"
"${SOF_SRC_DIR}/../xtos/include")
# "${ZEPHYR_SRC_DIR}"
# "${ZEPHYR_SRC_DIR}/../../../../include"
# "${ZEPHYR_SRC_DIR}/../../../../include/zephyr")
3 changes: 3 additions & 0 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ if(NOT CONFIG_COMP_MODULE_SHARED_LIBRARY_BUILD)
endif()
if(CONFIG_COMP_UP_DOWN_MIXER)
add_subdirectory(up_down_mixer)
endif()
if(CONFIG_COMP_DEBUG_MODULE)
add_subdirectory(debug_module)
endif()
if(CONFIG_COMP_MFCC)
add_subdirectory(mfcc)
Expand Down
2 changes: 1 addition & 1 deletion src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ config IPC4_GATEWAY
IPC4 messages (set/get/flush commands).

rsource "up_down_mixer/Kconfig"

rsource "debug_module/Kconfig"
config COMP_BLOB
bool "Large IPC data as compound message blobs"
default y
Expand Down
3 changes: 3 additions & 0 deletions src/audio/debug_module/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: BSD-3-Clause

add_local_sources(sof debug_module.c)
9 changes: 9 additions & 0 deletions src/audio/debug_module/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: BSD-3-Clause

config COMP_DEBUG_MODULE
bool "DEBUG_MODULE component"
default n
depends on IPC_MAJOR_4
help
Debug module component

171 changes: 171 additions & 0 deletions src/audio/debug_module/debug_module.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2022 Intel Corporation. All rights reserved.
//
// Author: Bartosz Kokoszko <[email protected]>
// Author: Adrian Bonislawski <[email protected]>

#include <sof/audio/module_adapter/module/generic.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 "debug_module.h"

#include <errno.h>
#include <sof/audio/module_adapter/library/native_system_service.h>
#include <stdlib.h>
#include <stdint.h>

/* Logging is temporary disabled */
#define comp_err(...)
#define comp_dbg(...)

static struct native_system_service_api* system_service;
uint32_t heap_mem[2048] __attribute__((section(".heap_mem"))) __attribute__((aligned(4096)));

int32_t custom_coeffs[DEBUG_MODULE_COEFFS_LENGTH];

static int debug_module_free(struct processing_module *mod)
{
struct debug_module_data *cd = module_get_private_data(mod);

free(cd);

return 0;
}

static int debug_module_init(struct processing_module *mod)
{
struct module_config *dst = &mod->priv.cfg;
const struct ipc4_debug_module_cfg *debug_module = dst->init_data;
struct module_data *mod_data = &mod->priv;
struct comp_dev *dev = mod->dev;
struct debug_module_data *cd;
int ret;

cd = malloc(sizeof(struct debug_module_data));
if (!cd) {
free(dev);
return -ENOMEM;
}

mod_data->private = cd;

if (memcpy_s(&cd->config, sizeof(cd->config), debug_module, sizeof(*debug_module)) < 0) {
ret = -EINVAL;
goto err;
}

if (ret < 0) {
comp_err(dev, "debug_module_init(): failed to initialize debug_module");
goto err;
}

return 0;

err:
debug_module_free(mod);
return ret;
}

static int
debug_module_process(struct processing_module *mod,
struct sof_source **input_buffers, int num_input_buffers,
struct sof_sink **output_buffers, int num_output_buffers)
{
struct debug_module_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;

size_t output_frames, input_frames, ret, input_cirbuf_size, output_cirbuf_size;
const uint8_t *input0_pos, *input0_start;
uint8_t *output_pos, *output_start;

comp_dbg(dev, "debug_module_process()");

output_frames = sink_get_free_frames(output_buffers[0]);
input_frames = source_get_data_frames_available(input_buffers[0]);

const size_t output_frame_bytes = sink_get_frame_bytes(output_buffers[0]);

ret = sink_get_buffer(output_buffers[0], output_frames * output_frame_bytes,
(void **)&output_pos, (void **)&output_start, &output_cirbuf_size);
if (ret)
return -ENODATA;

const size_t input0_frame_bytes = source_get_frame_bytes(input_buffers[0]);

ret = source_get_data(input_buffers[0], input_frames * input0_frame_bytes,
(const void **)&input0_pos, (const void **)&input0_start,
&input_cirbuf_size);
if (ret) {
sink_commit_buffer(output_buffers[0], 0);
return -ENODATA;
}

//cd->mix_routine(cd, (const void *)input0_start, input_cirbuf_size, (void *)output_start);

ret = sink_commit_buffer(output_buffers[0], output_frames * output_frame_bytes);
if (ret)
return ret;

ret = source_release_data(input_buffers[0], input_frames * input0_frame_bytes);
if (ret)
return ret;
return 0;
}

static int debug_module_set_configuration(struct processing_module *mod,
uint32_t config_id,
enum module_cfg_fragment_position pos,
uint32_t data_offset_size,
const uint8_t *fragment, size_t fragment_size,
uint8_t *response,
size_t response_size)
{
struct comp_dev *dev = mod->dev;

comp_dbg(dev, "debug_module_set_config()");

switch (config_id) {
case IPC4_DEBUG_MODULE_INVALID:
return 0;
default:
return -EINVAL;
}
}

static const struct module_interface debug_module_interface = {
.init = debug_module_init,
.process = debug_module_process,
.free = debug_module_free,
.set_configuration = debug_module_set_configuration,
};

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 &debug_module_interface;
}

/* 5fa8976c-581b-4ea6-8fd3-e94dd39a3669 */
__attribute__((section(".module")))
const struct sof_man_module_manifest udm_manifest = {
.module = {
.name = "DEBUG",
.uuid = {0x6c, 0x97, 0xa8, 0x5f,
0x1b, 0x58,
0xa6, 0x4e,
0x8f,0xd3,
0xe9, 0x4d, 0xd3, 0x9a, 0x36, 0x69},
.entry_point = (uint32_t)entry_point,
.type = {.load_type = SOF_MAN_MOD_TYPE_MODULE,
.domain_ll = 1 },
.affinity_mask = 1,
}
};
60 changes: 60 additions & 0 deletions src/audio/debug_module/debug_module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2022 Intel Corporation. All rights reserved.
//
// Author: Bartosz Kokoszko <[email protected]>
// Author: Adrian Bonislawski <[email protected]>

#ifndef __SOF_AUDIO_DEBUG_MODULE_H__
#define __SOF_AUDIO_DEBUG_MODULE_H__
#ifndef MODULE_PRIVAT
#include <sof/audio/component_ext.h>
#include <sof/common.h>
#endif
#include <sof/audio/ipc-config.h>

#include <ipc/stream.h>
#ifndef MODULE_PRIVAT
#include <ipc4/module.h>
#endif
#include <ipc4/base-config.h>
#include <stddef.h>
#include <stdint.h>

#include "debug_module_ipc4.h"

/** forward declaration */
struct debug_module_data;

static inline uint8_t get_channel_location(const channel_map map,
const enum ipc4_channel_index channel)
{
uint8_t offset = 0xF;
uint8_t i;

/* Search through all 4 bits of each byte in the integer for the channel. */
for (i = 0; i < 8; i++) {
if (((map >> (i * 4)) & 0xF) == (uint8_t)channel) {
offset = i;
break;
}
}

return offset;
}

static inline enum ipc4_channel_index get_channel_index(const channel_map map,
const uint8_t location)
{
return (enum ipc4_channel_index)((map >> (location * 4)) & 0xF);
}

/**
* \brief debug_module component private data.
*/
struct debug_module_data {
struct ipc4_debug_module_cfg config;
};


#endif /* __SOF_AUDIO_DEBUG_MODULE_H__ */
Loading

0 comments on commit 584cbb5

Please sign in to comment.