Skip to content

Commit

Permalink
module_adapter: native_system_agent: Introduce call and interface
Browse files Browse the repository at this point in the history
This is part of fw which helps loaded module in communication with adsp
Also it provides basic operations for creation of component driver
Common part for native loadable modules and iadk is put together and
remade into native API. That way system services are using generic
methods defined in native system service.

Signed-off-by: Dobrowolski, PawelX <pawelx.dobrowolski@intel.com>
  • Loading branch information
pjdobrowolski authored and lgirdwood committed Jul 12, 2023
1 parent e2ad42f commit 2cdf38c
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 253 deletions.
39 changes: 19 additions & 20 deletions src/audio/module_adapter/iadk/system_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <utilities/array.h>
#include <adsp_error_code.h>
#include <logger.h>
#include <system_service.h>
#include <native_system_service.h>
#include <system_agent_interface.h>
#include <module_initial_settings_concrete.h>
#include <iadk_module_adapter.h>
Expand All @@ -32,29 +32,28 @@ void* operator new(size_t size, intel_adsp::ModuleHandle *placeholder) throw()
}

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);

void SystemServiceLogMessage (AdspLogPriority log_priority, uint32_t log_entry,
AdspLogHandle const* log_handle, uint32_t param1,
uint32_t param2, uint32_t param3, uint32_t param4);

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

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

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

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

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

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

namespace intel_adsp
Expand All @@ -64,13 +63,13 @@ namespace system

/* Structure storing handles to system service operations */
AdspSystemService SystemAgent::system_service_ = {
SystemServiceLogMessage,
SystemServiceSafeMemcpy,
SystemServiceSafeMemmove,
SystemServiceVecMemset,
SystemServiceCreateNotification,
SystemServiceSendNotificationMessage,
SystemServiceGetInterface,
native_system_service_log_message,
native_system_service_safe_memcpy,
native_system_service_safe_memmove,
native_system_service_vec_memset,
native_system_service_create_notification,
native_system_service_send_notif_msg,
native_system_service_get_interface,
};

SystemAgent::SystemAgent(uint32_t module_id,
Expand Down
40 changes: 40 additions & 0 deletions src/audio/module_adapter/library/native_system_agent.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: BSD-3-Clause
/*
* Copyright(c) 2023 Intel Corporation. All rights reserved.
*
* Author: Pawel Dobrowolski <pawelx.dobrowolski@intel.com>
*/

#include <stdbool.h>
#include <stdint.h>
#include <utilities/array.h>
#include <native_system_agent.h>

/* The create_instance_f is a function call type known in module. The module entry_point
* points to this type of function which starts module creation.
*/

typedef void* (*native_create_instance_f)(void *mod_cfg, void *parent_ppl,
void **mod_ptr);

struct native_system_agent native_sys_agent;

void *native_system_agent_start(uint32_t *sys_service,
uint32_t entry_point, uint32_t module_id,
uint32_t instance_id, uint32_t core_id, uint32_t log_handle,
void *mod_cfg)
{
native_sys_agent.module_id = module_id;
native_sys_agent.instance_id = instance_id;
native_sys_agent.core_id = core_id;
native_sys_agent.log_handle = log_handle;

void *system_agent_p = &native_sys_agent;
uint32_t **sys_service_p = &sys_service;

*sys_service_p = (uint32_t *)(&native_sys_agent.system_service);

native_create_instance_f ci = (native_create_instance_f)entry_point;

return ci(mod_cfg, NULL, &system_agent_p);
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2020 Intel Corporation. All rights reserved.
//
// Author: Jaroslaw Stelter <jaroslaw.stelter@linux.intel.com>

/*
* System Service interface for ADSP loadable library.
* Copyright(c) 2020 Intel Corporation. All rights reserved.
*
* Author: Jaroslaw Stelter <jaroslaw.stelter@linux.intel.com>
*/
/*
* Native System Service interface for ADSP loadable library.
*/

#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <sof/common.h>
#include <rtos/sof.h>
#include <rtos/string.h>
#include <ipc4/notification.h>
#include <sof/ipc/msg.h>
#include <adsp_error_code.h>
#include <system_service.h>
#include <native_system_service.h>
#include <sof/lib_manager.h>

#define RSIZE_MAX 0x7FFFFFFF

void SystemServiceLogMessage(AdspLogPriority log_priority, uint32_t log_entry,
AdspLogHandle const *log_handle, uint32_t param1, uint32_t param2,
uint32_t param3, uint32_t param4)
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)
{
uint32_t argc = (log_entry & 0x7);
/* TODO: Need to call here function like _log_sofdict, since we do not have format */
Expand All @@ -49,13 +47,15 @@ void SystemServiceLogMessage(AdspLogPriority log_priority, uint32_t log_entry,
}
}

AdspErrorCode SystemServiceSafeMemcpy(void *RESTRICT dst, size_t maxlen, const void *RESTRICT src,
size_t len)
AdspErrorCode native_system_service_safe_memcpy(void *RESTRICT dst, size_t maxlen,
const void *RESTRICT src,
size_t len)
{
return (AdspErrorCode) memcpy_s(dst, maxlen, src, len);
}

AdspErrorCode SystemServiceSafeMemmove(void *dst, size_t maxlen, const void *src, size_t len)
AdspErrorCode native_system_service_safe_memmove(void *dst, size_t maxlen, const void *src,
size_t len)
{
if (dst == NULL || maxlen > RSIZE_MAX)
return ADSP_INVALID_PARAMETERS;
Expand All @@ -75,24 +75,22 @@ AdspErrorCode SystemServiceSafeMemmove(void *dst, size_t maxlen, const void *src
return ADSP_NO_ERROR;
}

void *SystemServiceVecMemset(void *dst, int c, size_t len)
void *native_system_service_vec_memset(void *dst, int c, size_t len)
{
/* TODO: Currently simple memset. Should be changed. */
memset(dst, c, len);
return dst;
}

AdspErrorCode SystemServiceCreateNotification(NotificationParams *params,
uint8_t *notification_buffer,
uint32_t notification_buffer_size,
AdspNotificationHandle *handle)
AdspErrorCode native_system_service_create_notification(notification_params *params,
uint8_t *notification_buffer,
uint32_t notification_buffer_size,
adsp_notification_handle *handle)
{
if ((params == NULL) || (notification_buffer == NULL)
|| (notification_buffer_size <= 0) || (handle == NULL))
return ADSP_INVALID_PARAMETERS;

/* TODO: IPC header setup */
/* https://github.com/thesofproject/sof/pull/5720 needed for completion. */
union ipc4_notification_header header;

header.r.notif_type = params->type;
Expand All @@ -103,15 +101,15 @@ AdspErrorCode SystemServiceCreateNotification(NotificationParams *params,
struct ipc_msg *msg = lib_notif_msg_init((uint32_t)header.dat, notification_buffer_size);

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

return ADSP_NO_ERROR;
}

AdspErrorCode SystemServiceSendNotificationMessage(NotificationTarget notification_target,
AdspNotificationHandle message,
AdspErrorCode native_system_service_send_notif_msg(adsp_notification_target notification_target,
adsp_notification_handle message,
uint32_t actual_payload_size)
{
if ((message == NULL) || (actual_payload_size == 0))
Expand All @@ -123,10 +121,19 @@ AdspErrorCode SystemServiceSendNotificationMessage(NotificationTarget notificati
return ADSP_NO_ERROR;
}

AdspErrorCode SystemServiceGetInterface(AdspIfaceId id, SystemServiceIface **iface)
AdspErrorCode native_system_service_get_interface(adsp_iface_id id, 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
};
3 changes: 1 addition & 2 deletions src/include/sof/audio/module_adapter/iadk/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Logger
uint32_t param2 = 0, uint32_t param3 = 0, uint32_t param4 = 0)
{
(void)_ignored;
system_service_.LogMessage(LOG_LEVEL, log_entry, &log_handle_,
system_service_.log_message(LOG_LEVEL, log_entry, &log_handle_,
param1, param2, param3, param4);
}

Expand All @@ -41,7 +41,6 @@ class Logger
AdspSystemService const &system_service_;
AdspLogHandle const &log_handle_;
};

} /* namespace intel_adsp */

#endif /* #ifdef __cplusplus */
Expand Down
Loading

0 comments on commit 2cdf38c

Please sign in to comment.