1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2022 Intel Corporation. All rights reserved.
4  */
5 /*! \file system_service.h */
6 
7 #ifndef _ADSP_SYSTEM_SERVICE_H_
8 #define _ADSP_SYSTEM_SERVICE_H_
9 
10 #include "logger.h"
11 #include "adsp_stddef.h"
12 #include "adsp_error_code.h"
13 
14 #include <stdint.h>
15 
16 #ifdef __clang__
17 #pragma clang diagnostic push
18 #pragma clang diagnostic ignored "-Wextern-c-compat"
19 #endif //__clang__
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /*! \brief This struct defines the obfuscating type for notifications. */
26 typedef struct _AdspNotificationHandle {} *AdspNotificationHandle;
27 
28 /*! \brief Defines parameters used by ADSP system during notification creation. */
29 typedef struct _NotificationParams {
30 	uint32_t type;              /*!< Notification type */
31 	uint16_t user_val_1;        /*!< 16 bits user value available directly in IPC header
32 				     * for some notifications
33 				     */
34 	uint32_t user_val_2;        /*!< 30 bits user value available directly in IPC header
35 				     * for some notifications
36 				     */
37 	uint32_t max_payload_size;  /*!< Data size of payload (NotificationCreate updates this
38 				     * value to max possible payload size)
39 				     */
40 	uint8_t *payload;           /*!< Pointer on the payload */
41 } NotificationParams;
42 
43 /*! \brief Defines parameters used by ADSP system during Module Event notification creation. */
44 typedef struct _ModuleEventNotification {
45 	uint32_t module_instance_id; /*!< Module ID (MS word) + Module Instance ID (LS word) */
46 	uint32_t event_id;           /*!< Module specific event ID. */
47 	uint32_t event_data_size;    /*!< Size of event_data array in bytes. May be set to 0
48 				      * in case there is no data.
49 				      */
50 	uint32_t event_data[];       /*!< Optional event data (size set to 0 as it is optional
51 				      * data)
52 				      */
53 } ModuleEventNotification;
54 
55 /*! \brief Defines notification targets supported by ADSP system */
56 typedef enum _NotificationTarget {
57 	DSP_TO_HOST = 1,  /*!< Notification target is HOST */
58 	DSP_TO_ISH = 2    /*!< Notification target is ISH */
59 } NotificationTarget;
60 
61 /*! \brief Defines notification types supported by ADSP system */
62 typedef enum _NotificationType {
63 	VOICE_COMMAND_NOTIFICATION = 4,	/*!< intel_adsp define corresponding to PHRASE_DETECTED
64 					 * notification
65 					 */
66 	AUDIO_CLASSIFIER_RESULTS = 9,	/*!< intel_adsp define corresponding to FW_AUD_CLASS_RESULT
67 					 * notification
68 					 */
69 	MODULE_EVENT_NOTIFICATION = 12,	/*!< intel_adsp define corresponding to MODULE_NOTIFICATION
70 					 * notification
71 					 */
72 } NotificationType;
73 
74 /*! \brief Defines prototype of the "LogMessage" function
75  *
76  * \param log_priority define the log priority for the message to be sent.
77  *        The ADSP System may have been configured by the host to filter log message below
78  *        a given priority.
79  * \param log_entry provides information on log sender and log point location.
80  * \param log_handle \copybrief AdspLogHandle
81  * \param param1 some uint32_t value to include in the log message.
82  * \param param2 some uint32_t value to include in the log message.
83  * \param param3 some uint32_t value to include in the log message.
84  * \param param4 some uint32_t value to include in the log message.
85  *
86  * \see LOG_MESSAGE
87  */
88 typedef void (*SystemServiceLogMessageFct) (AdspLogPriority log_priority, uint32_t log_entry,
89 					    AdspLogHandle const *log_handle, uint32_t param1,
90 					    uint32_t param2, uint32_t param3, uint32_t param4);
91 
92 /*! \brief Defines prototype of the "SafeMemcpy" function
93  *
94  * \param dst define the address of destination buffer
95  * \param maxlen define the size of destination buffer
96  * \param src define the address of source buffer
97  * \param len define the number of bytes
98  * \return zero if success, error code otherwise
99  */
100 typedef AdspErrorCode (*SystemServiceSafeMemcpyFct) (void *RESTRICT dst, size_t maxlen,
101 						     const void *RESTRICT src, size_t len);
102 
103 /*! \brief Defines prototype of the "SafeMemmove" function
104  *
105  * \param dst define the address of destination buffer
106  * \param maxlen define the size of destination buffer
107  * \param src define the address of source buffer
108  * \param len define the number of bytes
109  * \return zero if success, error code otherwise
110  */
111 typedef AdspErrorCode (*SystemServiceSafeMemmoveFct) (void *dst, size_t maxlen,
112 						      const void *src, size_t len);
113 
114 /*! \brief Defines prototype of the "VecMemset" function
115  *
116  * \param dst define the address of destination buffer
117  * \param c define the fill byte
118  * \param len define the number of bytes
119  * \return pointer to dst
120  */
121 typedef void* (*SystemServiceVecMemsetFct) (void *dst, int c, size_t len);
122 
123 /*! \brief Defines prototype of the "NotificationCreate" function
124  *
125  * \param params pointer on NotificationParams input structure
126  * \param notification_buffer pointer on the notification buffer declared in module
127  * \param notification_buffer_size size of the notification buffer declared in module
128  * \param handle pointer on AdspNotificationHandle structure
129  * \return error if notification_buffer is too small or NULL
130  */
131 typedef AdspErrorCode (*SystemServiceCreateNotificationFct) (NotificationParams *params,
132 							     uint8_t *notification_buffer,
133 							     uint32_t notification_buffer_size,
134 							     AdspNotificationHandle *handle);
135 
136 /*! \brief Defines prototype of the "NotificationSend" function
137  *
138  * \param notification_target notification target is HOST or ISH
139  * \param message the AdspNotificationHandle structure used for notification
140  * \param actual_payload_size size of the notification data (excluding notification header)
141  * \return error if invalid target
142  */
143 typedef AdspErrorCode (*SystemServiceSendNotificationMessageFct) (
144 						    NotificationTarget notification_target,
145 						    AdspNotificationHandle message,
146 						    uint32_t actual_payload_size);
147 
148 typedef enum _AdspIfaceId {
149 	IfaceIdGNA = 0x1000,			/*!< Reserved for ADSP system */
150 	IfaceIdInferenceService = 0x1001,	/*!< See InferenceServiceInterface */
151 	IfaceIdSDCA = 0x1002,			/*!< See SdcaInterface */
152 	IfaceIdAsyncMessageService = 0x1003,	/*!< See AsyncMessageInterface */
153 	IfaceIdAMService = 0x1005,		/*!< Reserved for ADSP system */
154 	IfaceIdKpbService = 0x1006		/*!< See KpbInterface */
155 } AdspIfaceId;
156 
157 /*! \brief sub interface definition.
158  * This type may contain generic interface properties like id or struct size if needed.
159  */
160 typedef struct _SystemServiceIface {} SystemServiceIface;
161 
162 /*! \brief Defines prototype of the "GetInterface" function
163  *
164  * \param id service id
165  * \param iface pointer to retrieved interface
166  * \return error if service not supported
167  */
168 typedef AdspErrorCode (*SystemServiceGetInterfaceFct) (AdspIfaceId id, SystemServiceIface **iface);
169 
170 /*! \brief The AdspSystemService is actually a set of C-function pointers gathered in a C-struct
171  * which brings some basic functionalities to module in runtime.
172  *
173  * The system service can be retrieved with help of either the
174  * intel_adsp::ProcessingModuleFactory::GetSystemService() method
175  * or the intel_adsp::ProcessingModule::GetSysstemService() method.
176  */
177 typedef struct AdspSystemService {
178 	/*! The SystemService::LogMessage function provides capability to send some log message to
179 	 * the host for debugging purposes. This log can be caught by the FDK Tools and displayed
180 	 * in the Debug window. The prototype of this function is given by the
181 	 * \ref SystemServiceLogMessageFct typedef.
182 	 *
183 	 * \remarks This service function is not expected to be called directly by the user code.
184 	 * Instead, the LOG_MESSAGE should be invoked for this purpose.
185 	 */
186 	const SystemServiceLogMessageFct LogMessage;
187 
188 	/*! The SystemService::SafeMemcpy function provides capability to use SafeMemcpy function
189 	 * provided by ADSP System.
190 	 * The prototype of this function is given by the \ref SystemServiceSafeMemcpyFct typedef.
191 	 */
192 	const SystemServiceSafeMemcpyFct SafeMemcpy;
193 
194 	/*! The SystemService::SafeMemmove function provides capability to use SafeMemmove function
195 	 * provided by ADSP System.
196 	 * The prototype of this function is given by the \ref SystemServiceSafeMemmoveFct typedef.
197 	 */
198 	const SystemServiceSafeMemmoveFct SafeMemmove;
199 
200 	/*! The SystemService::VecMemset function provides capability to use VecMemset function
201 	 * provided by ADSP System.
202 	 * The prototype of this function is given by the \ref SystemServiceVecMemsetFct typedef.
203 	 */
204 	const SystemServiceVecMemsetFct VecMemset;
205 
206 	/*! The SystemService::NotificationCreate function provides capability to use
207 	 * NotificationCreate function provided by ADSP System.
208 	 * The prototype of this function is given by the
209 	 * \ref SystemServiceCreateNotificationFct typedef.
210 	 */
211 	const SystemServiceCreateNotificationFct NotificationCreate;
212 
213 	/*! The SystemService::NotificationSend function provides capability to use
214 	 * NotificationSend function provided by ADSP System.
215 	 * The prototype of this function is given by the \ref
216 	 * SystemServiceSendNotificationMessageFct typedef.
217 	 */
218 	const SystemServiceSendNotificationMessageFct NotificationSend;
219 
220 	/*! The SystemService::GetInterface function provides capability to retrieve additional
221 	 * services provided by ADSP System. The prototype of this function is given by the \ref
222 	 * SystemServiceGetInterfaceFct typedef.
223 	 */
224 	const SystemServiceGetInterfaceFct GetInterface;
225 
226 } AdspSystemService;
227 
228 #ifdef __cplusplus
229 namespace intel_adsp
230 {
231 /*! \brief Alias type of AdspSystemService which can be used in C++.
232  */
233 struct SystemService : public AdspSystemService {};
234 }
235 #endif
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 
241 #ifdef __clang__
242 #pragma clang diagnostic pop // ignored "-Wextern-c-compat"
243 #endif //__clang__
244 
245 #endif /* _ADSP_SYSTEM_SERVICE_H_ */
246