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

Move log and system_service headers to module directory #9335

Merged
merged 2 commits into from
Aug 22, 2024
Merged
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
28 changes: 2 additions & 26 deletions src/audio/module_adapter/iadk/system_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
#include <rtos/string.h>
#include <utilities/array.h>
#include <module/iadk/adsp_error_code.h>
#include <native_system_service.h>
#include <system_service.h>
#include <system_agent_interface.h>
#include <module_initial_settings_concrete.h>
#include <iadk_module_adapter.h>
#include <system_agent.h>
#include <sof/audio/module_adapter/library/native_system_service.h>

using namespace intel_adsp;
using namespace intel_adsp::system;
Expand All @@ -30,31 +31,6 @@ void* operator new(size_t size, intel_adsp::ModuleHandle *placeholder) throw()
return placeholder;
}

extern "C" {
void native_system_service_log_message (AdspLogPriority log_priority, uint32_t log_entry,
AdspLogHandle const* log_handle, uint32_t param1,
uint32_t param2, uint32_t param3, uint32_t param4);

AdspErrorCode native_system_service_safe_memcpy(void *RESTRICT dst, size_t maxlen,
const void *RESTRICT src, size_t len);

AdspErrorCode native_system_service_safe_memmove(void *dst, size_t maxlen,
const void *src, size_t len);

void *native_system_service_vec_memset(void *dst, int c, size_t len);

AdspErrorCode native_system_service_create_notification(notification_params *params,
uint8_t *notification_buffer,
uint32_t notification_buffer_size,
adsp_notification_handle *handle);

AdspErrorCode native_system_service_send_notif_msg(adsp_notification_target notification_target,
adsp_notification_handle message,
uint32_t actual_payload_size);

AdspErrorCode native_system_service_get_interface(adsp_iface_id id, system_service_iface **iface);
}

namespace intel_adsp
{
namespace system
Expand Down
68 changes: 52 additions & 16 deletions src/audio/module_adapter/library/native_system_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright(c) 2020 Intel Corporation. All rights reserved.
*
* Author: Jaroslaw Stelter <jaroslaw.stelter@linux.intel.com>
* Adrian Warecki <adrian.warecki@intel.com>
*/
/*
* Native System Service interface for ADSP loadable library.
Expand All @@ -17,13 +18,44 @@
#include <sof/ipc/msg.h>
#include <native_system_service.h>
#include <sof/lib_manager.h>
#include <module/module/logger.h>

#define RSIZE_MAX 0x7FFFFFFF

void native_system_service_log_message(AdspLogPriority log_priority, uint32_t log_entry,
AdspLogHandle const *log_handle, uint32_t param1,
/*! Module log level priority to sof log level conversion array */
const int log_priority_map[L_MAX] = {
/*! Critical message. */
[L_CRITICAL] = LOG_LEVEL_CRITICAL,
/*! Error message. */
[L_ERROR] = LOG_LEVEL_ERROR,
/*! High importance log level. */
[L_HIGH] = LOG_LEVEL_ERROR,
/*! Warning message. */
[L_WARNING] = LOG_LEVEL_WARNING,
/*! Medium importance log level. */
[L_MEDIUM] = LOG_LEVEL_WARNING,
/*! Low importance log level. */
[L_LOW] = LOG_LEVEL_INFO,
/*! Information. */
[L_INFO] = LOG_LEVEL_INFO,
/*! Verbose message. */
[L_VERBOSE] = LOG_LEVEL_VERBOSE,
[L_DEBUG] = LOG_LEVEL_DEBUG
};

static int log_priority_to_sof_level(enum log_priority log_priority)
{
if ((uint32_t)log_priority >= L_DEBUG)
return LOG_LEVEL_DEBUG;

return log_priority_map[log_priority];
}

void native_system_service_log_message(enum log_priority log_priority, uint32_t log_entry,
struct log_handle const *log_handle, uint32_t param1,
uint32_t param2, uint32_t param3, uint32_t param4)
{
log_priority_to_sof_level(log_priority);
uint32_t argc = (log_entry & 0x7);
/* TODO: Need to call here function like _log_sofdict, since we do not have format */
/* passed from library */
Expand Down Expand Up @@ -82,10 +114,10 @@ void *native_system_service_vec_memset(void *dst, int c, size_t len)
return dst;
}

AdspErrorCode native_system_service_create_notification(notification_params *params,
AdspErrorCode native_system_service_create_notification(struct notification_params *params,
uint8_t *notification_buffer,
uint32_t notification_buffer_size,
adsp_notification_handle *handle)
struct notification_handle **handle)
{
if ((params == NULL) || (notification_buffer == NULL)
|| (notification_buffer_size <= 0) || (handle == NULL))
Expand All @@ -101,15 +133,16 @@ AdspErrorCode native_system_service_create_notification(notification_params *par
struct ipc_msg *msg = lib_notif_msg_init((uint32_t)header.dat, notification_buffer_size);

if (msg) {
*handle = (adsp_notification_handle)msg;
*handle = (struct notification_handle *)msg;
params->payload = msg->tx_data;
}

return ADSP_NO_ERROR;
}

AdspErrorCode native_system_service_send_notif_msg(adsp_notification_target notification_target,
adsp_notification_handle message,

AdspErrorCode native_system_service_send_notif_msg(enum notification_target notification_target,
struct notification_handle *message,
uint32_t actual_payload_size)
{
if ((message == NULL) || (actual_payload_size == 0))
Expand All @@ -121,19 +154,22 @@ AdspErrorCode native_system_service_send_notif_msg(adsp_notification_target noti
return ADSP_NO_ERROR;
}

AdspErrorCode native_system_service_get_interface(adsp_iface_id id, system_service_iface **iface)
AdspErrorCode native_system_service_get_interface(enum interface_id id,
struct system_service_iface **iface)
{
if (id < 0)
return ADSP_INVALID_PARAMETERS;
return ADSP_NO_ERROR;
}

const struct native_system_service_api native_system_service = {
.log_message = native_system_service_log_message,
.safe_memcpy = native_system_service_safe_memcpy,
.safe_memmove = native_system_service_safe_memmove,
.vec_memset = native_system_service_vec_memset,
.notification_create = native_system_service_create_notification,
.notification_send = native_system_service_send_notif_msg,
.get_interface = native_system_service_get_interface
const struct native_system_service native_system_service = {
.basic = {
.log_message = native_system_service_log_message,
.safe_memcpy = native_system_service_safe_memcpy,
.safe_memmove = native_system_service_safe_memmove,
.vec_memset = native_system_service_vec_memset,
.notification_create = native_system_service_create_notification,
.notification_send = native_system_service_send_notif_msg,
.get_interface = native_system_service_get_interface
}
};
32 changes: 32 additions & 0 deletions src/include/module/module/logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright(c) 2024 Intel Corporation. All rights reserved.
*
* Author: Adrian Warecki <adrian.warecki@intel.com>
*/

#ifndef __MODULE_MODULE_LOGGER_H__
#define __MODULE_MODULE_LOGGER_H__

/* Log level priority enumeration. */
enum log_priority {
L_CRITICAL, /* Critical message. */
L_ERROR, /* Error message. */
L_HIGH, /* High importance log level. */
L_WARNING, /* Warning message. */
L_MEDIUM, /* Medium importance log level. */
L_LOW, /* Low importance log level. */
L_INFO, /* Information. */
L_VERBOSE, /* Verbose message. */
L_DEBUG,
L_MAX,
};

/* struct log_handle identifies the log message sender.
*
* struct log_handle instance is passed to the system_service::log_message function.
* This struct should not be used directly.
*/
struct log_handle;

#endif /* __MODULE_MODULE_LOGGER_H__ */
113 changes: 113 additions & 0 deletions src/include/module/module/system_service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright(c) 2024 Intel Corporation. All rights reserved.
*
* Author: Adrian Warecki <adrian.warecki@intel.com>
*/

#ifndef MODULE_MODULE_SYSTEM_SERVICE_H
#define MODULE_MODULE_SYSTEM_SERVICE_H

#include <stdint.h>
#include <stddef.h>

#include "logger.h"
#include "../iadk/adsp_error_code.h"

#ifdef __XTENSA__
#define RESTRICT __restrict
#else
#define RESTRICT
#endif
Comment on lines +17 to +21
Copy link
Member

Choose a reason for hiding this comment

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

It may be best to comment why this cant come from Zephyr as I suspect Zephyr will define this too.

Copy link
Member

Choose a reason for hiding this comment

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

ping - this needs a comment at least so that no one tries to optimize this later on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lgirdwood
Indeed zephyr has a similar definition ZRESTRICT, but we want to be able to build lmdk modules without using zephyr headers so I didn't use it.


/*! This struct defines the obfuscating type for notifications. */
struct notification_handle;

/* Defines parameters used by ADSP system during notification creation. */
struct notification_params {
uint32_t type; /*!< Notification type */
uint16_t user_val_1; /*!< 16 bits user value available directly in IPC header
* for some notifications
*/
uint32_t user_val_2; /*!< 30 bits user value available directly in IPC header
* for some notifications
*/
uint32_t max_payload_size; /*!< Data size of payload (NotificationCreate updates this
* value to max possible payload size)
*/
uint8_t *payload; /*!< Pointer on the payload */
};

/* Defines parameters used by ADSP system during Module Event notification creation. */
struct module_event_notification {
uint32_t module_instance_id; /*!< Module ID (MS word) + Module Instance ID (LS word) */
uint32_t event_id; /*!< Module specific event ID. */
uint32_t event_data_size; /*!< Size of event_data array in bytes. May be set to 0
* in case there is no data.
*/
uint32_t event_data[]; /*!< Optional event data (size set to 0 as it is optional
* data)
*/
};

/* Defines notification targets supported by ADSP system
* FW defines only two notification targets, HOST and ISH (Integrated Sensor Hub).
*/
enum notification_target {
NOTIFICATION_TARGET_DSP_TO_HOST = 1, /* Notification target is HOST */
NOTIFICATION_TARGET_DSP_TO_ISH = 2 /* Notification target is ISH */
};

/* Defines notification types supported by ADSP system
* FW use reserved first 20 positions describing types of notifications.
*/
enum notification_type {
/* corresponding to PHRASE_DETECTED notification */
NOTIFICATION_TYPE_VOICE_COMMAND_NOTIFICATION = 4,

/* corresponding to FW_AUD_CLASS_RESULT notification */
NOTIFICATION_TYPE_AUDIO_CLASSIFIER_RESULTS = 9,

/* corresponding to MODULE_NOTIFICATION notification */
NOTIFICATION_TYPE_MODULE_EVENT_NOTIFICATION = 12,
};

/* Defines extended interfaces for IADK modules */
enum interface_id {
INTERFACE_ID_GNA = 0x1000, /* Reserved for ADSP system */
INTERFACE_ID_INFERENCE_SERVICE = 0x1001, /* See InferenceServiceInterface */
INTERFACE_ID_SDCA = 0x1002, /* See SdcaInterface */
INTERFACE_ID_ASYNC_MESSAGE_SERVICE = 0x1003, /* See AsyncMessageInterface */
INTERFACE_ID_AM_SERVICE = 0x1005, /* Reserved for ADSP system */
INTERFACE_ID_KPB_SERVICE = 0x1006 /* See KpbInterface */
};

/* sub interface definition.
* This type may contain generic interface properties like id or struct size if needed.
*/
struct system_service_iface;

struct system_service {
void (*log_message)(enum log_priority log_priority, uint32_t log_entry,
struct log_handle const *log_handle, uint32_t param1,
uint32_t param2, uint32_t param3, uint32_t param4);

AdspErrorCode (*safe_memcpy)(void *RESTRICT dst, size_t maxlen,
const void *RESTRICT src, size_t len);

AdspErrorCode (*safe_memmove)(void *dst, size_t maxlen,
const void *src, size_t len);

void* (*vec_memset)(void *dst, int c, size_t len);

AdspErrorCode (*notification_create)(struct notification_params *params,
uint8_t *notification_buffer,
uint32_t notification_buffer_size,
struct notification_handle **handle);
AdspErrorCode (*notification_send)(enum notification_target notification_target,
struct notification_handle *message,
uint32_t actual_payload_size);

AdspErrorCode (*get_interface)(enum interface_id id, struct system_service_iface **iface);
};
#endif /* MODULE_MODULE_SYSTEM_SERVICE_H */
38 changes: 6 additions & 32 deletions src/include/sof/audio/module_adapter/iadk/adsp_stddef.h
Original file line number Diff line number Diff line change
@@ -1,50 +1,24 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2022 Intel Corporation. All rights reserved.
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright(c) 2022 - 2024 Intel Corporation. All rights reserved.
*/

#ifndef _ADSP_STDDEF_H_
#define _ADSP_STDDEF_H_

#include <stddef.h>
#include <stdint.h>
#include <user/trace.h>
#include <rtos/string.h>

#ifdef __ZEPHYR__
#include <zephyr/sys/util.h>
#endif /* __ZEPHYR__ */

#ifdef __XTENSA__
#define RESTRICT __restrict
#else
#define RESTRICT
#endif
#include <module/module/logger.h>

/*! Log level priority enumeration. */
typedef enum log_priority {
/*! Critical message. */
L_CRITICAL = LOG_LEVEL_CRITICAL,
/*! Error message. */
L_ERROR = LOG_LEVEL_ERROR,
/*! High importance log level. */
L_HIGH = LOG_LEVEL_ERROR,
/*! Warning message. */
L_WARNING = LOG_LEVEL_WARNING,
/*! Medium importance log level. */
L_MEDIUM = LOG_LEVEL_WARNING,
/*! Low importance log level. */
L_LOW = LOG_LEVEL_INFO,
/*! Information. */
L_INFO = LOG_LEVEL_INFO,
/*! Verbose message. */
L_VERBOSE = LOG_LEVEL_VERBOSE,
L_DEBUG = LOG_LEVEL_DEBUG,
L_MAX = LOG_LEVEL_DEBUG,
} AdspLogPriority,
log_priority_e;
struct AdspLogHandle;
typedef struct AdspLogHandle AdspLogHandle;
typedef enum log_priority AdspLogPriority, log_priority_e;
typedef struct log_handle AdspLogHandle;

#ifdef __cplusplus
namespace intel_adsp
Expand Down
Loading
Loading