From 85ca0857ece7d7669de82d5010ca9df6d912ae93 Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Thu, 25 Jul 2024 02:08:18 +0200 Subject: [PATCH] module: Move system_service header to module directory Move definitions of functions exposed by system_service to the modules directory so that loadable modules can use them. Signed-off-by: Adrian Warecki --- .../module_adapter/iadk/system_agent.cpp | 29 +--- .../library/native_system_service.c | 37 ++--- src/include/module/module/system_service.h | 113 +++++++++++++++ .../audio/module_adapter/iadk/adsp_stddef.h | 13 +- .../module_adapter/iadk/system_service.h | 24 +--- .../library/native_system_agent.h | 2 +- .../library/native_system_service.h | 132 +++++------------- 7 files changed, 181 insertions(+), 169 deletions(-) create mode 100644 src/include/module/module/system_service.h diff --git a/src/audio/module_adapter/iadk/system_agent.cpp b/src/audio/module_adapter/iadk/system_agent.cpp index 77c0e120db9f..2eeaa2037d1a 100644 --- a/src/audio/module_adapter/iadk/system_agent.cpp +++ b/src/audio/module_adapter/iadk/system_agent.cpp @@ -15,12 +15,12 @@ #include #include #include -#include -#include +#include #include #include #include #include +#include using namespace intel_adsp; using namespace intel_adsp::system; @@ -31,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 diff --git a/src/audio/module_adapter/library/native_system_service.c b/src/audio/module_adapter/library/native_system_service.c index a15df91ca53b..b29255a32c00 100644 --- a/src/audio/module_adapter/library/native_system_service.c +++ b/src/audio/module_adapter/library/native_system_service.c @@ -3,6 +3,7 @@ * Copyright(c) 2020 Intel Corporation. All rights reserved. * * Author: Jaroslaw Stelter + * Adrian Warecki */ /* * Native System Service interface for ADSP loadable library. @@ -50,8 +51,8 @@ static int log_priority_to_sof_level(enum log_priority log_priority) return log_priority_map[log_priority]; } -void native_system_service_log_message(AdspLogPriority log_priority, uint32_t log_entry, - AdspLogHandle const *log_handle, uint32_t param1, +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); @@ -113,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)) @@ -132,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)) @@ -152,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; } -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 + } }; diff --git a/src/include/module/module/system_service.h b/src/include/module/module/system_service.h new file mode 100644 index 000000000000..ec9227a0335e --- /dev/null +++ b/src/include/module/module/system_service.h @@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Copyright(c) 2024 Intel Corporation. All rights reserved. + * + * Author: Adrian Warecki + */ + +#ifndef MODULE_MODULE_SYSTEM_SERVICE_H +#define MODULE_MODULE_SYSTEM_SERVICE_H + +#include +#include + +#include "logger.h" +#include "../iadk/adsp_error_code.h" + +#ifdef __XTENSA__ + #define RESTRICT __restrict +#else + #define RESTRICT +#endif + +/*! 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 descibing 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 */ diff --git a/src/include/sof/audio/module_adapter/iadk/adsp_stddef.h b/src/include/sof/audio/module_adapter/iadk/adsp_stddef.h index bb4dfc5697d5..b7ea435a3346 100644 --- a/src/include/sof/audio/module_adapter/iadk/adsp_stddef.h +++ b/src/include/sof/audio/module_adapter/iadk/adsp_stddef.h @@ -1,6 +1,6 @@ -/* 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_ @@ -16,13 +16,6 @@ #include -#ifdef __XTENSA__ - #define RESTRICT __restrict -#else - #define RESTRICT -#endif - - /*! Log level priority enumeration. */ typedef enum log_priority AdspLogPriority, log_priority_e; typedef struct log_handle AdspLogHandle; diff --git a/src/include/sof/audio/module_adapter/iadk/system_service.h b/src/include/sof/audio/module_adapter/iadk/system_service.h index 453247a38505..716105de418a 100644 --- a/src/include/sof/audio/module_adapter/iadk/system_service.h +++ b/src/include/sof/audio/module_adapter/iadk/system_service.h @@ -1,17 +1,16 @@ -/* 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. */ /*! \file system_service.h */ #ifndef _ADSP_SYSTEM_SERVICE_H_ #define _ADSP_SYSTEM_SERVICE_H_ -#include "logger.h" +#include #include "adsp_stddef.h" #include -#include "native_system_service.h" -#include +#include #ifdef __clang__ #pragma clang diagnostic push @@ -19,25 +18,16 @@ #endif //__clang__ #ifdef __cplusplus -extern "C" { -#endif - -typedef struct native_system_service_api AdspSystemService; - -#ifdef __cplusplus - namespace intel_adsp { +typedef struct system_service AdspSystemService; + /*! \brief Alias type of AdspSystemService which can be used in C++. */ struct SystemService : public AdspSystemService {}; } #endif -#ifdef __cplusplus -} -#endif - #ifdef __clang__ #pragma clang diagnostic pop // ignored "-Wextern-c-compat" #endif //__clang__ diff --git a/src/include/sof/audio/module_adapter/library/native_system_agent.h b/src/include/sof/audio/module_adapter/library/native_system_agent.h index 6563ef026975..7faf802debe1 100644 --- a/src/include/sof/audio/module_adapter/library/native_system_agent.h +++ b/src/include/sof/audio/module_adapter/library/native_system_agent.h @@ -12,7 +12,7 @@ #include struct native_system_agent { - struct native_system_service_api system_service; + struct system_service system_service; uint32_t log_handle; uint32_t core_id; uint32_t module_id; diff --git a/src/include/sof/audio/module_adapter/library/native_system_service.h b/src/include/sof/audio/module_adapter/library/native_system_service.h index 74f6a823192b..b4e5e2b608ad 100644 --- a/src/include/sof/audio/module_adapter/library/native_system_service.h +++ b/src/include/sof/audio/module_adapter/library/native_system_service.h @@ -1,116 +1,52 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright(c) 2023 Intel Corporation. All rights reserved. +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Copyright(c) 2023 - 2024 Intel Corporation. All rights reserved. */ -/*! \file native_system_service.h */ + #ifndef NATIVE_SYSTEM_SERVICE_H #define NATIVE_SYSTEM_SERVICE_H #include +#include -#include "logger.h" -#include "adsp_stddef.h" -#include +#ifdef __cplusplus +extern "C" { +#endif -/*! \brief This struct defines the obfuscating type for notifications. */ -typedef struct _adsp_notification_handle {} *adsp_notification_handle; +#include -/*! \brief Defines parameters used by ADSP system during notification creation. */ -typedef 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 */ -} notification_params; +struct native_system_service { + struct system_service basic; +}; -/*! \brief Defines parameters used by ADSP system during Module Event notification creation. */ -typedef 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) - */ -} module_event_notification; +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); -/*! \brief Defines notification targets supported by ADSP system - * Legacy FW defines only two notification targets, HOST and ISH (Integrated Sensor Hub). - */ -typedef enum _notification_target { - NOTIFICATION_TARGET_DSP_TO_HOST = 1, /*!< Notification target is HOST */ - NOTIFICATION_TARGET_DSP_TO_ISH = 2 /*!< Notification target is ISH */ -} adsp_notification_target; +AdspErrorCode native_system_service_safe_memcpy(void *RESTRICT dst, size_t maxlen, + const void *RESTRICT src, size_t len); -/*! \brief Defines notification types supported by ADSP system - * Legacy FW uses reserves first 20 positions descibing types of notifications. - */ -typedef enum _notification_type { - NOTIFICATION_TYPE_VOICE_COMMAND_NOTIFICATION = 4, /*!< intel_adsp define - * corresponding to PHRASE_DETECTED - * notification - */ - NOTIFICATION_TYPE_AUDIO_CLASSIFIER_RESULTS = 9, /*!< intel_adsp define - * corresponding to - * FW_AUD_CLASS_RESULT notification - */ - NOTIFICATION_TYPE_MODULE_EVENT_NOTIFICATION = 12, /*!< intel_adsp define - * corresponding to - * MODULE_NOTIFICATION notification - */ -} notification_type; +AdspErrorCode native_system_service_safe_memmove(void *dst, size_t maxlen, + const void *src, size_t len); -/*! \brief Defines extended interfaces for IADK modules*/ -typedef enum _adsp_iface_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 */ -} adsp_iface_id; +void *native_system_service_vec_memset(void *dst, int c, size_t len); -/*! \brief sub interface definition. - * This type may contain generic interface properties like id or struct size if needed. - */ -typedef struct _system_service_iface {} system_service_iface; +AdspErrorCode native_system_service_create_notification(struct notification_params *params, + uint8_t *notification_buffer, + uint32_t notification_buffer_size, + struct notification_handle **handle); -/*! \brief Defines prototype of the "GetInterface" function - * - * \param id service id - * \param iface pointer to retrieved interface - * \return error if service not supported - */ - -struct native_system_service_api { - void (*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_send_notif_msg(enum notification_target notification_target, + struct notification_handle * message, + uint32_t actual_payload_size); - AdspErrorCode (*safe_memcpy)(void *RESTRICT dst, size_t maxlen, - const void *RESTRICT src, size_t len); +AdspErrorCode native_system_service_get_interface(enum interface_id id, + struct system_service_iface **iface); - AdspErrorCode (*safe_memmove)(void *dst, size_t maxlen, - const void *src, size_t len); +extern const struct native_system_service native_system_service; - void* (*vec_memset)(void *dst, int c, size_t len); +#ifdef __cplusplus +} /* extern "C" */ +#endif - AdspErrorCode (*notification_create)(notification_params *params, - uint8_t *notification_buffer, - uint32_t notification_buffer_size, - adsp_notification_handle *handle); - AdspErrorCode (*notification_send)(adsp_notification_target notification_target, - adsp_notification_handle message, - uint32_t actual_payload_size); - - AdspErrorCode (*get_interface)(adsp_iface_id id, system_service_iface **iface); -}; -#endif /*NATIVE_SYSTEM_SERVICE_H*/ +#endif /* NATIVE_SYSTEM_SERVICE_H */