Sound Open Firmware
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 2016 Intel Corporation. All rights reserved.
4 *
5 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
6 * Keyon Jie <yang.jie@linux.intel.com>
7 */
8
9#ifndef __SOF_IPC_COMMON_H__
10#define __SOF_IPC_COMMON_H__
11
12#include <rtos/bit.h>
13#include <rtos/alloc.h>
14#include <sof/list.h>
15#include <rtos/task.h>
16#include <rtos/spinlock.h>
17#include <rtos/sof.h>
18#include <user/trace.h>
19#include <ipc/header.h>
20#include <ipc/stream.h>
21#include <sof/ipc/ipc_reply.h>
22
23#include <stdbool.h>
24#include <stdint.h>
25
26struct comp_driver;
28struct ipc_msg;
29struct ipc4_message_request;
30
31/* validates internal non tail structures within IPC command structure */
32#define IPC_IS_SIZE_INVALID(object) \
33 ((object).hdr.size != sizeof(object))
34
35#define IPC_TAIL_IS_SIZE_INVALID(object) \
36 ((object).comp.hdr.size + (object).comp.ext_data_length < sizeof(object))
37
38/* ipc trace context, used by multiple units */
39extern struct tr_ctx ipc_tr;
40
41/* convenience error trace for mismatched internal structures */
42#define IPC_SIZE_ERROR_TRACE(ctx, object) \
43 tr_err(ctx, "ipc: size %d expected %zu", \
44 (object).hdr.size, sizeof(object))
45
46/* Returns pipeline source component */
47#define ipc_get_ppl_src_comp(ipc, ppl_id) \
48 ipc_get_ppl_comp(ipc, ppl_id, PPL_DIR_UPSTREAM)
49
50/* Returns pipeline sink component */
51#define ipc_get_ppl_sink_comp(ipc, ppl_id) \
52 ipc_get_ppl_comp(ipc, ppl_id, PPL_DIR_DOWNSTREAM)
53
54#define IPC_TASK_INLINE BIT(0)
55#define IPC_TASK_IN_THREAD BIT(1)
56#define IPC_TASK_SECONDARY_CORE BIT(2)
57#define IPC_TASK_POWERDOWN BIT(3)
58
59struct ipc_user {
60 struct k_thread *thread;
61 struct k_sem *sem;
62 struct k_event *event;
64 uint32_t ipc_msg_pri;
66 uint32_t ipc_msg_ext;
68 int result;
70 uint32_t reply_ext;
72 uint32_t reply_tx_size;
75 struct ipc *ipc;
76 struct k_thread *audio_thread;
78 const struct comp_driver *init_drv;
87 uint8_t init_drv_data[160] __aligned(4);
88};
89
90struct ipc {
91 struct k_spinlock lock; /* locking mechanism */
92 void *comp_data;
93
94 /* PM */
95 int pm_prepare_D3; /* do we need to prepare for D3 */
96
97 struct list_item msg_list; /* queue of messages to be sent */
98 bool is_notification_pending; /* notification is being sent to host */
99 uint32_t task_mask; /* tasks to be completed by this IPC */
100 unsigned int core; /* core, processing the IPC */
101
102 struct list_item comp_list; /* list of component devices */
103
104 /* processing task */
105#if CONFIG_TWB_IPC_TASK
106 struct task *ipc_task;
107#else
109#endif
110
111#ifdef CONFIG_SOF_USERSPACE_LL
112 struct ipc_user *ipc_user_pdata;
113 struct mod_alloc_ctx *ll_alloc;
114#endif
115
116#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
117 /* io performance measurement */
118 struct io_perf_data_item *io_perf_in_msg_count;
119 struct io_perf_data_item *io_perf_out_msg_count;
120#endif
121
122#ifdef __ZEPHYR__
123 struct k_work_delayable z_delayed_work;
124 struct k_work_q ipc_send_wq;
125#endif
126
127 void *private;
128};
129
130#define ipc_set_drvdata(ipc, data) \
131 ((ipc)->private = data)
132#define ipc_get_drvdata(ipc) \
133 ((ipc)->private)
134
135extern struct task_ops ipc_task_ops;
136
137#ifdef CONFIG_SOF_USERSPACE_LL
138
139struct ipc *ipc_get(void);
140
141#else
142
147static inline struct ipc *ipc_get(void)
148{
149 return sof_get()->ipc;
150}
151
152#endif /* CONFIG_SOF_USERSPACE_LL */
153
159int ipc_init(struct sof *sof);
160
165void ipc_free(struct ipc *ipc);
166
174 /* DMA */
175#if CONFIG_ZEPHYR_NATIVE_DRIVERS
176 struct sof_dma *dmac;
177#else
178 struct dma *dmac;
179#endif
180 uint8_t *page_table;
181};
182
194 uint32_t direction,
195 struct dma_sg_elem_array *elem_array,
196 uint32_t *ring_size);
197
203
208
209struct dai_data;
214int ipc_dai_data_config(struct dai_data *dd, struct comp_dev *dev);
215
222int ipc4_user_process_module_message(struct ipc4_message_request *ipc4, struct ipc_msg *reply);
223
230int ipc4_user_process_glb_message(struct ipc4_message_request *ipc4, struct ipc_msg *reply);
231
237void ipc_compound_msg_done(uint32_t msg_id, int error);
238
244void ipc_boot_complete_msg(struct ipc_cmd_hdr *header, uint32_t data);
245
246#if defined(CONFIG_PM_DEVICE) && defined(CONFIG_IPC_SERVICE_BACKEND_INTEL_ADSP_HOST_IPC)
258void ipc_send_failed_power_transition_response(void);
259#endif /* CONFIG_PM_DEVICE && CONFIG_IPC_SERVICE_BACKEND_INTEL_ADSP_HOST_IPC */
265
270struct ipc_cmd_hdr *ipc_compact_read_msg(void);
271
277int ipc_compact_write_msg(struct ipc_cmd_hdr *hdr);
278
284struct ipc_cmd_hdr *ipc_prepare_to_send(const struct ipc_msg *msg);
285
290struct ipc_cmd_hdr *mailbox_validate(void);
291
299void ipc_cmd(struct ipc_cmd_hdr *_hdr);
300
307int ipc_process_on_core(uint32_t core, bool blocking);
308
313
314/* GDB stub: should enter GDB after completing the IPC processing */
315extern bool ipc_enter_gdb;
316
317#ifdef CONFIG_SOF_USERSPACE_LL
329int ipc_user_forward_cmd(uint32_t primary, uint32_t extension);
330
340int ipc_user_thread_dispatch(struct ipc_user *ipc_user);
341#endif
342
343#endif /* __SOF_DRIVERS_IPC_H__ */
uint32_t data[]
Definition debug_stream_slot.h:2
void ipc_compound_msg_done(uint32_t msg_id, int error)
Complete the IPC compound message.
int ipc_dma_trace_send_position(void)
Send DMA trace host buffer position to host.
int ipc_dai_data_config(struct dai_data *dd, struct comp_dev *dev)
Configure DAI.
bool ipc_enter_gdb
int ipc4_user_process_glb_message(struct ipc4_message_request *ipc4, struct ipc_msg *reply)
Processes IPC4 userspace global message.
void ipc_cmd(struct ipc_cmd_hdr *_hdr)
Generic IPC command handler.
int ipc_init(struct sof *sof)
Initialise global IPC context.
int ipc_process_on_core(uint32_t core, bool blocking)
IPC message to be processed on other core.
struct ipc_cmd_hdr * mailbox_validate(void)
Validate mailbox contents for valid IPC header.
struct ipc_cmd_hdr * ipc_prepare_to_send(const struct ipc_msg *msg)
Prepare an IPC message for sending.
struct ipc_cmd_hdr * ipc_compact_read_msg(void)
Read a compact IPC message or return NULL for normal message.
void ipc_boot_complete_msg(struct ipc_cmd_hdr *header, uint32_t data)
create a IPC boot complete message.
void ipc_send_buffer_status_notify(void)
send a IPC buffer status notify message
struct tr_ctx ipc_tr
static struct ipc * ipc_get(void)
Get the IPC global context.
Definition common.h:147
int ipc_compact_write_msg(struct ipc_cmd_hdr *hdr)
Write a compact IPC message.
int ipc4_user_process_module_message(struct ipc4_message_request *ipc4, struct ipc_msg *reply)
Processes IPC4 userspace module message.
void ipc_send_panic_notification(void)
Send a IPC notification that FW has hit a DSP notification.
void ipc_complete_cmd(struct ipc *ipc)
Call platform-specific IPC completion function.
struct task_ops ipc_task_ops
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)
Processes page tables for the host buffer.
void ipc_free(struct ipc *ipc)
Free global IPC context.
IPC command header.
IPC definitions for streams.
#define list_item(item, type, member)
Definition list.h:80
struct sof * sof_get(void)
Audio component base device "class".
Definition component.h:645
Audio component base driver "class".
Definition component.h:587
DAI runtime data.
Definition dai-zephyr.h:119
SG elem array.
Definition dma.h:155
Definition dma.h:209
Data provided by the platform which use ipc...page_descriptors().
Definition common.h:173
struct dma * dmac
Definition common.h:178
uint8_t * page_table
Definition common.h:180
Definition msg.h:33
Definition common.h:59
struct k_thread * audio_thread
Definition common.h:76
struct k_event * event
Definition common.h:62
const struct comp_driver * init_drv
Original kernel driver pointer for restoring dev->drv after create.
Definition common.h:78
uint32_t reply_tx_size
Reply TX data size from user thread (e.g.
Definition common.h:72
uint32_t reply_ext
Reply extension word from user thread (e.g.
Definition common.h:70
uint8_t init_drv_data[160] __aligned(4)
User-accessible copy of comp_driver + tr_ctx for create().
uint32_t ipc_msg_ext
Copy of IPC4 message extension word forwarded to user thread.
Definition common.h:66
int result
Result code from user thread processing.
Definition common.h:68
struct ipc * ipc
Definition common.h:75
struct k_sem * sem
Definition common.h:61
uint32_t ipc_msg_pri
Copy of IPC4 message primary word forwarded to user thread.
Definition common.h:64
struct k_thread * thread
Definition common.h:60
void * reply_tx_data
Reply TX data pointer from user thread (e.g.
Definition common.h:74
Definition common.h:90
bool is_notification_pending
Definition common.h:98
unsigned int core
Definition common.h:100
int pm_prepare_D3
Definition common.h:95
void * comp_data
Definition common.h:92
struct k_spinlock lock
Definition common.h:91
struct list_item msg_list
Definition common.h:97
uint32_t task_mask
Definition common.h:99
struct task ipc_task
Definition common.h:108
struct list_item comp_list
Definition common.h:102
Definition alloc.h:167
Definition ringbuffer.h:21
Definition stream.h:63
General firmware context.
Definition sof.h:44
struct ipc * ipc
Definition sof.h:51
Task operations.
Definition task.h:49
Task used by schedulers.
Definition task.h:56
Definition trace.h:135