1 // SPDX-License-Identifier: BSD-3-Clause
2 //
3 // Copyright(c) 2020 Intel Corporation. All rights reserved.
4 //
5 // Author: Jaroslaw Stelter <jaroslaw.stelter@linux.intel.com>
6
7 /*
8 * System Service interface for ADSP loadable library.
9 */
10
11 #include <errno.h>
12 #include <stdbool.h>
13 #include <stdint.h>
14 #include <sof/common.h>
15 #include <rtos/sof.h>
16 #include <rtos/string.h>
17 #include <ipc4/notification.h>
18 #include <sof/ipc/msg.h>
19 #include <adsp_error_code.h>
20 #include <system_service.h>
21 #include <sof/lib_manager.h>
22
23 #define RSIZE_MAX 0x7FFFFFFF
24
SystemServiceLogMessage(AdspLogPriority log_priority,uint32_t log_entry,AdspLogHandle const * log_handle,uint32_t param1,uint32_t param2,uint32_t param3,uint32_t param4)25 void SystemServiceLogMessage(AdspLogPriority log_priority, uint32_t log_entry,
26 AdspLogHandle const *log_handle, uint32_t param1, uint32_t param2,
27 uint32_t param3, uint32_t param4)
28 {
29 uint32_t argc = (log_entry & 0x7);
30 /* TODO: Need to call here function like _log_sofdict, since we do not have format */
31 /* passed from library */
32 /* This function could be finished when cAVS/ACE logging formats support will be */
33 /* added to SOF.*/
34 switch (argc) {
35 case 1:
36 break;
37
38 case 2:
39 break;
40
41 case 3:
42 break;
43
44 case 4:
45 break;
46
47 default:
48 break;
49 }
50 }
51
SystemServiceSafeMemcpy(void * RESTRICT dst,size_t maxlen,const void * RESTRICT src,size_t len)52 AdspErrorCode SystemServiceSafeMemcpy(void *RESTRICT dst, size_t maxlen, const void *RESTRICT src,
53 size_t len)
54 {
55 return (AdspErrorCode) memcpy_s(dst, maxlen, src, len);
56 }
57
SystemServiceSafeMemmove(void * dst,size_t maxlen,const void * src,size_t len)58 AdspErrorCode SystemServiceSafeMemmove(void *dst, size_t maxlen, const void *src, size_t len)
59 {
60 if (dst == NULL || maxlen > RSIZE_MAX)
61 return ADSP_INVALID_PARAMETERS;
62
63 if (src == NULL || len > maxlen) {
64 memset(dst, 0, maxlen);
65 return ADSP_INVALID_PARAMETERS;
66 }
67
68 if (len != 0) {
69 /* TODO: now it is memcopy. Finally it will be remap maybe?
70 * Fix it when memory management API will be available.
71 * memmove(dst, src, len);
72 */
73 memcpy_s(dst, maxlen, src, len);
74 }
75 return ADSP_NO_ERROR;
76 }
77
SystemServiceVecMemset(void * dst,int c,size_t len)78 void *SystemServiceVecMemset(void *dst, int c, size_t len)
79 {
80 /* TODO: Currently simple memset. Should be changed. */
81 memset(dst, c, len);
82 return dst;
83 }
84
SystemServiceCreateNotification(NotificationParams * params,uint8_t * notification_buffer,uint32_t notification_buffer_size,AdspNotificationHandle * handle)85 AdspErrorCode SystemServiceCreateNotification(NotificationParams *params,
86 uint8_t *notification_buffer,
87 uint32_t notification_buffer_size,
88 AdspNotificationHandle *handle)
89 {
90 if ((params == NULL) || (notification_buffer == NULL)
91 || (notification_buffer_size <= 0) || (handle == NULL))
92 return ADSP_INVALID_PARAMETERS;
93
94 /* TODO: IPC header setup */
95 /* https://github.com/thesofproject/sof/pull/5720 needed for completion. */
96 union ipc4_notification_header header;
97
98 header.r.notif_type = params->type;
99 header.r._reserved_0 = params->user_val_1;
100 header.r.type = SOF_IPC4_GLB_NOTIFICATION;
101 header.r.rsp = SOF_IPC4_MESSAGE_DIR_MSG_REQUEST;
102 header.r.msg_tgt = SOF_IPC4_MESSAGE_TARGET_FW_GEN_MSG;
103 struct ipc_msg *msg = lib_notif_msg_init((uint32_t)header.dat, notification_buffer_size);
104
105 if (msg) {
106 *handle = (AdspNotificationHandle)msg;
107 params->payload = msg->tx_data;
108 }
109
110 return ADSP_NO_ERROR;
111 }
112
SystemServiceSendNotificationMessage(NotificationTarget notification_target,AdspNotificationHandle message,uint32_t actual_payload_size)113 AdspErrorCode SystemServiceSendNotificationMessage(NotificationTarget notification_target,
114 AdspNotificationHandle message,
115 uint32_t actual_payload_size)
116 {
117 if ((message == NULL) || (actual_payload_size == 0))
118 return ADSP_INVALID_PARAMETERS;
119
120 struct ipc_msg *msg = (struct ipc_msg *)message;
121
122 lib_notif_msg_send(msg);
123 return ADSP_NO_ERROR;
124 }
125
SystemServiceGetInterface(AdspIfaceId id,SystemServiceIface ** iface)126 AdspErrorCode SystemServiceGetInterface(AdspIfaceId id, SystemServiceIface **iface)
127 {
128 if (id < 0)
129 return ADSP_INVALID_PARAMETERS;
130 return ADSP_NO_ERROR;
131 }
132
133