-
Notifications
You must be signed in to change notification settings - Fork 350
Expand file tree
/
Copy pathnative_system_service.c
More file actions
176 lines (150 loc) · 4.73 KB
/
native_system_service.c
File metadata and controls
176 lines (150 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// SPDX-License-Identifier: BSD-3-Clause
/*
* 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.
*/
#include <errno.h>
#include <stdbool.h>
#include <sof/common.h>
#include <rtos/sof.h>
#include <rtos/string.h>
#include <ipc4/notification.h>
#include <sof/ipc/msg.h>
#include <native_system_service.h>
#include <sof/lib_manager.h>
#include <module/module/logger.h>
#include <rtos/userspace_helper.h>
#define RSIZE_MAX 0x7FFFFFFF
/*! 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 */
/* This function could be finished when cAVS/ACE logging formats support will be */
/* added to SOF.*/
switch (argc) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
break;
}
}
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 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;
if (src == NULL || len > maxlen) {
memset(dst, 0, maxlen);
return ADSP_INVALID_PARAMETERS;
}
if (len != 0) {
/* TODO: now it is memcopy. Finally it will be remap maybe?
* Fix it when memory management API will be available.
* memmove(dst, src, len);
*/
memcpy_s(dst, maxlen, src, len);
}
return ADSP_NO_ERROR;
}
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 native_system_service_create_notification(struct notification_params *params,
uint8_t *notification_buffer,
uint32_t notification_buffer_size,
struct notification_handle **handle)
{
if ((params == NULL) || (notification_buffer == NULL)
|| (notification_buffer_size <= 0) || (handle == NULL))
return ADSP_INVALID_PARAMETERS;
union ipc4_notification_header header;
header.r.notif_type = params->type;
header.r._reserved_0 = params->user_val_1;
header.r.type = SOF_IPC4_GLB_NOTIFICATION;
header.r.rsp = SOF_IPC4_MESSAGE_DIR_MSG_REQUEST;
header.r.msg_tgt = SOF_IPC4_MESSAGE_TARGET_FW_GEN_MSG;
struct ipc_msg *msg = lib_notif_msg_init((uint32_t)header.dat, notification_buffer_size);
if (msg) {
*handle = (struct notification_handle *)msg;
params->payload = msg->tx_data;
}
return ADSP_NO_ERROR;
}
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))
return ADSP_INVALID_PARAMETERS;
struct ipc_msg *msg = (struct ipc_msg *)message;
lib_notif_msg_send(msg);
return ADSP_NO_ERROR;
}
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 APP_TASK_DATA 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
}
};