Repository navigation
Expand file tree
/
Copy pathcommon.h
More file actions
363 lines (309 loc) · 10.4 KB
/
Copy pathcommon.h
File metadata and controls
363 lines (309 loc) · 10.4 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2016 Intel Corporation. All rights reserved.
*
* Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
* Keyon Jie <yang.jie@linux.intel.com>
*/
#ifndef __SOF_IPC_COMMON_H__
#define __SOF_IPC_COMMON_H__
#include <rtos/bit.h>
#include <rtos/alloc.h>
#include <sof/list.h>
#include <rtos/task.h>
#include <rtos/spinlock.h>
#include <rtos/sof.h>
#include <user/trace.h>
#include <ipc/header.h>
#include <ipc/stream.h>
#include <sof/ipc/ipc_reply.h>
#include <stdbool.h>
#include <stdint.h>
struct comp_driver;
struct dma_sg_elem_array;
struct ipc_msg;
struct ipc4_message_request;
/* validates internal non tail structures within IPC command structure */
#define IPC_IS_SIZE_INVALID(object) \
((object).hdr.size != sizeof(object))
#define IPC_TAIL_IS_SIZE_INVALID(object) \
((object).comp.hdr.size + (object).comp.ext_data_length < sizeof(object))
/* ipc trace context, used by multiple units */
extern struct tr_ctx ipc_tr;
/* convenience error trace for mismatched internal structures */
#define IPC_SIZE_ERROR_TRACE(ctx, object) \
tr_err(ctx, "ipc: size %d expected %zu", \
(object).hdr.size, sizeof(object))
/* Returns pipeline source component */
#define ipc_get_ppl_src_comp(ipc, ppl_id) \
ipc_get_ppl_comp(ipc, ppl_id, PPL_DIR_UPSTREAM)
/* Returns pipeline sink component */
#define ipc_get_ppl_sink_comp(ipc, ppl_id) \
ipc_get_ppl_comp(ipc, ppl_id, PPL_DIR_DOWNSTREAM)
#define IPC_TASK_INLINE BIT(0)
#define IPC_TASK_IN_THREAD BIT(1)
#define IPC_TASK_SECONDARY_CORE BIT(2)
#define IPC_TASK_POWERDOWN BIT(3)
#ifdef CONFIG_CORE_COUNT
#define IPC_DSP_CORE_COUNT CONFIG_CORE_COUNT
#else
#define IPC_DSP_CORE_COUNT 1
#endif
struct ipc_user {
struct k_thread *thread[IPC_DSP_CORE_COUNT];
struct k_sem *sem;
struct k_event *event[IPC_DSP_CORE_COUNT];
/** @brief Copy of IPC4 message primary word forwarded to user thread */
uint32_t ipc_msg_pri;
/** @brief Copy of IPC4 message extension word forwarded to user thread */
uint32_t ipc_msg_ext;
/** @brief Result code from user thread processing */
int result;
/** @brief Reply extension word from user thread (e.g. CONFIG_GET result) */
uint32_t reply_ext;
/** @brief Reply TX data size from user thread (e.g. LARGE_CONFIG_GET result) */
uint32_t reply_tx_size;
/** @brief Reply TX data pointer from user thread (e.g. LARGE_CONFIG_GET result) */
void *reply_tx_data;
struct ipc *ipc;
struct k_thread *audio_thread[IPC_DSP_CORE_COUNT];
/** @brief Original kernel driver pointer for restoring dev->drv after create */
const struct comp_driver *init_drv;
bool init_needed[IPC_DSP_CORE_COUNT];
/**
* @brief User-accessible copy of comp_driver + tr_ctx for create().
*
* The comp_driver and tr_ctx structs reside in kernel memory
* (.rodata/.data) which is not user-readable. The kernel handler
* copies them here before forwarding to the user thread.
* Size verified by BUILD_ASSERT in handler-user.c.
*/
uint8_t init_drv_data[160] __aligned(4);
};
struct ipc {
struct k_spinlock lock; /* locking mechanism */
void *comp_data;
/* PM */
int pm_prepare_D3; /* do we need to prepare for D3 */
struct list_item msg_list; /* queue of messages to be sent */
bool is_notification_pending; /* notification is being sent to host */
uint32_t task_mask; /* tasks to be completed by this IPC */
unsigned int core; /* core, processing the IPC */
struct list_item comp_list; /* list of component devices */
/* processing task */
#if CONFIG_TWB_IPC_TASK
struct task *ipc_task;
#else
struct task ipc_task;
#endif
#ifdef CONFIG_SOF_USERSPACE_LL
struct ipc_user *ipc_user_pdata;
struct mod_alloc_ctx *ll_alloc;
#endif
#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
/* io performance measurement */
struct io_perf_data_item *io_perf_in_msg_count;
struct io_perf_data_item *io_perf_out_msg_count;
#endif
#ifdef __ZEPHYR__
struct k_work_delayable z_delayed_work;
struct k_work_q ipc_send_wq;
#endif
void *private;
};
#define ipc_set_drvdata(ipc, data) \
((ipc)->private = data)
#define ipc_get_drvdata(ipc) \
((ipc)->private)
extern struct task_ops ipc_task_ops;
#ifdef CONFIG_SOF_USERSPACE_LL
struct ipc *ipc_get(void);
#else
/**
* \brief Get the IPC global context.
* @return The global IPC context.
*/
static inline struct ipc *ipc_get(void)
{
return sof_get()->ipc;
}
#endif /* CONFIG_SOF_USERSPACE_LL */
/**
* \brief Initialise global IPC context.
* @param[in,out] sof Global SOF context.
* @return 0 on success.
*/
int ipc_init(struct sof *sof);
/**
* \brief Free global IPC context.
* @param[in] ipc Global IPC context.
*/
void ipc_free(struct ipc *ipc);
/**
* \brief Data provided by the platform which use ipc...page_descriptors().
*
* Note: this should be made private for ipc-host-ptable.c and ipc
* drivers for platforms that use ptables.
*/
struct ipc_data_host_buffer {
/* DMA */
#if CONFIG_ZEPHYR_NATIVE_DRIVERS
struct sof_dma *dmac;
#else
struct dma *dmac;
#endif
uint8_t *page_table;
};
/**
* \brief Processes page tables for the host buffer.
* @param[in] ipc Ipc
* @param[in] ring Ring description sent via Ipc
* @param[in] direction Direction (playback/capture)
* @param[out] elem_array Array of SG elements
* @param[out] ring_size Size of the ring
* @return Status, 0 if successful, error code otherwise.
*/
int ipc_process_host_buffer(struct ipc *ipc,
struct sof_ipc_host_buffer *ring,
uint32_t direction,
struct dma_sg_elem_array *elem_array,
uint32_t *ring_size);
/**
* \brief Send DMA trace host buffer position to host.
* @return 0 on success.
*/
int ipc_dma_trace_send_position(void);
/**
* \brief send a IPC buffer status notify message
*/
void ipc_send_buffer_status_notify(void);
struct dai_data;
/**
* \brief Configure DAI.
* @return 0 on success.
*/
int ipc_dai_data_config(struct dai_data *dd, struct comp_dev *dev);
/**
* \brief Processes IPC4 userspace module message.
* @param[in] ipc4 IPC4 message request.
* @param[in] reply IPC message reply structure.
* @return IPC4_SUCCESS on success, error code otherwise.
*/
int ipc4_user_process_module_message(struct ipc4_message_request *ipc4, struct ipc_msg *reply);
/**
* \brief Processes IPC4 userspace global message.
* @param[in] ipc4 IPC4 message request.
* @param[in] reply IPC message reply structure.
* @return IPC4_SUCCESS on success, error code otherwise.
*/
int ipc4_user_process_glb_message(struct ipc4_message_request *ipc4, struct ipc_msg *reply);
/**
* \brief Complete the IPC compound message.
* @param[in] msg_id IPC message ID.
* @param[in] error Error code of the IPC command.
*/
void ipc_compound_msg_done(uint32_t msg_id, int error);
/**
* \brief create a IPC boot complete message.
* @param[in] header header.
* @param[in] data data.
*/
void ipc_boot_complete_msg(struct ipc_cmd_hdr *header, uint32_t data);
#if defined(CONFIG_PM_DEVICE) && defined(CONFIG_IPC_SERVICE_BACKEND_INTEL_ADSP_HOST_IPC)
/**
* @brief Send an IPC response to Host power transition request informing
* that power transition failed.
* @note Normally an reply to the Host IPC message is performed in the
* low level assembly code to make sure DSP completed all operations before
* power cut-off.
* However, when power transition fails for some reason, we should send the
* IPC response informing about the failure.
* This happens in abnormal circumstances since the response is send not during
* IPC task but during power transition logic in the Idle thread.
*/
void ipc_send_failed_power_transition_response(void);
#endif /* CONFIG_PM_DEVICE && CONFIG_IPC_SERVICE_BACKEND_INTEL_ADSP_HOST_IPC */
/**
* \brief Send a IPC notification that FW has hit
* a DSP notification.
*/
void ipc_send_panic_notification(void);
/**
* \brief Read a compact IPC message or return NULL for normal message.
* @return Pointer to the compact message data.
*/
struct ipc_cmd_hdr *ipc_compact_read_msg(void);
/**
* \brief Write a compact IPC message.
* @param[in] hdr Compact message header data.
* @return Number of words written.
*/
int ipc_compact_write_msg(struct ipc_cmd_hdr *hdr);
/**
* \brief Prepare an IPC message for sending.
* @param[in] msg The ipc msg.
* @return pointer to raw header or NULL.
*/
struct ipc_cmd_hdr *ipc_prepare_to_send(const struct ipc_msg *msg);
/**
* \brief Validate mailbox contents for valid IPC header.
* @return pointer to header if valid or NULL.
*/
struct ipc_cmd_hdr *mailbox_validate(void);
/**
* Generic IPC command handler. Expects that IPC command (the header plus
* any optional payload) is deserialized from the IPC HW by the platform
* specific method.
*
* @param _hdr Points to the IPC command header.
*/
void ipc_cmd(struct ipc_cmd_hdr *_hdr);
/**
* \brief IPC message to be processed on other core.
* @param[in] core Core id for IPC to be processed on.
* @param[in] blocking Process in blocking mode: wait for completion.
* @return 1 if successful (reply sent by other core), error code otherwise.
*/
int ipc_process_on_core(uint32_t core, bool blocking);
/**
* \brief Call platform-specific IPC completion function.
*/
void ipc_complete_cmd(struct ipc *ipc);
/* GDB stub: should enter GDB after completing the IPC processing */
extern bool ipc_enter_gdb;
#ifdef CONFIG_SOF_USERSPACE_LL
/**
* @brief Forward an IPC command to the user-space thread and wait for it.
*
* Protocol-agnostic: only the two raw message words are handed across the
* kernel/user boundary. The active IPC major's ipc_user_thread_dispatch()
* interprets them in the user thread.
*
* @param primary Primary message word
* @param extension Extension message word
* @return Result code from user thread processing
*/
int ipc_user_forward_cmd(uint32_t primary, uint32_t extension, unsigned int core);
/**
* @brief Protocol-specific dispatch of a forwarded IPC command.
*
* Runs in the user-space IPC thread. A __weak default returns -ENOSYS;
* the active IPC major (e.g. IPC4) provides the real implementation.
*
* @param ipc_user User IPC context holding the forwarded message words
* @return Result code to report back to the host
*/
int ipc_user_thread_dispatch(struct ipc_user *ipc_user);
/**
* @brief Initialize IPC and LL scheduler threads on a booting secondary core.
*
* @param core Secondary core ID
* @return 0 or a negative error code
*/
int ipc_user_init_secondary(unsigned int core);
#endif
/**
* \brief get pointer to the userspace IPC thread for core
*/
struct k_thread *ipc_thread_user(unsigned int core);
#endif /* __SOF_DRIVERS_IPC_H__ */