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;
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
59#ifdef CONFIG_CORE_COUNT
60#define IPC_DSP_CORE_COUNT CONFIG_CORE_COUNT
61#else
62#define IPC_DSP_CORE_COUNT 1
63#endif
64
65struct ipc_user {
66 struct k_thread *thread[IPC_DSP_CORE_COUNT];
67 struct k_sem *sem;
68 struct k_event *event[IPC_DSP_CORE_COUNT];
70 uint32_t ipc_msg_pri;
72 uint32_t ipc_msg_ext;
74 int result;
76 uint32_t reply_ext;
78 uint32_t reply_tx_size;
81 struct ipc *ipc;
84 const struct comp_driver *init_drv;
94 uint8_t init_drv_data[160] __aligned(4);
95};
96
97struct ipc {
98 struct k_spinlock lock; /* locking mechanism */
99 void *comp_data;
100
101 /* PM */
102 int pm_prepare_D3; /* do we need to prepare for D3 */
103
104 struct list_item msg_list; /* queue of messages to be sent */
105 bool is_notification_pending; /* notification is being sent to host */
106 uint32_t task_mask; /* tasks to be completed by this IPC */
107 unsigned int core; /* core, processing the IPC */
108
109 struct list_item comp_list; /* list of component devices */
110
111 /* processing task */
112#if CONFIG_TWB_IPC_TASK
113 struct task *ipc_task;
114#else
116#endif
117
118#ifdef CONFIG_SOF_USERSPACE_LL
119 struct ipc_user *ipc_user_pdata;
120 struct mod_alloc_ctx *ll_alloc;
121#endif
122
123#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
124 /* io performance measurement */
125 struct io_perf_data_item *io_perf_in_msg_count;
126 struct io_perf_data_item *io_perf_out_msg_count;
127#endif
128
129#ifdef __ZEPHYR__
130 struct k_work_delayable z_delayed_work;
131 struct k_work_q ipc_send_wq;
132#endif
133
134 void *private;
135};
136
137#define ipc_set_drvdata(ipc, data) \
138 ((ipc)->private = data)
139#define ipc_get_drvdata(ipc) \
140 ((ipc)->private)
141
142extern struct task_ops ipc_task_ops;
143
144#ifdef CONFIG_SOF_USERSPACE_LL
145
146struct ipc *ipc_get(void);
147
148#else
149
154static inline struct ipc *ipc_get(void)
155{
156 return sof_get()->ipc;
157}
158
159#endif /* CONFIG_SOF_USERSPACE_LL */
160
166int ipc_init(struct sof *sof);
167
172void ipc_free(struct ipc *ipc);
173
181 /* DMA */
182#if CONFIG_ZEPHYR_NATIVE_DRIVERS
183 struct sof_dma *dmac;
184#else
185 struct dma *dmac;
186#endif
187 uint8_t *page_table;
188};
189
200 struct sof_ipc_host_buffer *ring,
201 uint32_t direction,
202 struct dma_sg_elem_array *elem_array,
203 uint32_t *ring_size);
204
210
215
216struct dai_data;
221int ipc_dai_data_config(struct dai_data *dd, struct comp_dev *dev);
222
230
238
244void ipc_compound_msg_done(uint32_t msg_id, int error);
245
251void ipc_boot_complete_msg(struct ipc_cmd_hdr *header, uint32_t data);
252
253#if defined(CONFIG_PM_DEVICE) && defined(CONFIG_IPC_SERVICE_BACKEND_INTEL_ADSP_HOST_IPC)
265void ipc_send_failed_power_transition_response(void);
266#endif /* CONFIG_PM_DEVICE && CONFIG_IPC_SERVICE_BACKEND_INTEL_ADSP_HOST_IPC */
272
278
285
291struct ipc_cmd_hdr *ipc_prepare_to_send(const struct ipc_msg *msg);
292
298
306void ipc_cmd(struct ipc_cmd_hdr *_hdr);
307
314int ipc_process_on_core(uint32_t core, bool blocking);
315
320
321/* GDB stub: should enter GDB after completing the IPC processing */
322extern bool ipc_enter_gdb;
323
324#ifdef CONFIG_SOF_USERSPACE_LL
336int ipc_user_forward_cmd(uint32_t primary, uint32_t extension, unsigned int core);
337
347int ipc_user_thread_dispatch(struct ipc_user *ipc_user);
348
355int ipc_user_init_secondary(unsigned int core);
356#endif
357
361struct k_thread *ipc_thread_user(unsigned int core);
362
363#endif /* __SOF_DRIVERS_IPC_H__ */
Memory allocation API, zones, heaps, and alignment utilities.
uint8_t data[0]
Binary byte payload for raw controls.
Definition header.h:5
union @28 extension
union @27 primary
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
struct k_thread * ipc_thread_user(unsigned int core)
get pointer to the userspace IPC thread for core
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:154
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
#define IPC_DSP_CORE_COUNT
Definition common.h:62
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.
Sound Open Firmware global runtime context.
struct sof * sof_get(void)
Get the global Sound Open Firmware runtime instance pointer.
RTOS spinlock primitives and initialization.
User-space ABI log levels and binary trace packet header definitions.
Audio component base device "class" used by all other component types.
Definition component.h:587
Audio component base driver "class".
Definition component.h:528
DAI runtime data.
Definition dai-zephyr.h:119
SG elem array.
Definition dma.h:155
Definition dma.h:209
Standard 64-bit IPC4 message request envelope.
Definition header.h:127
Generic message header.
Definition header.h:36
Data provided by the platform which use ipc...page_descriptors().
Definition common.h:180
struct dma * dmac
Definition common.h:185
uint8_t * page_table
Definition common.h:187
Definition msg.h:34
Definition common.h:65
uint8_t init_drv_data[160]
User-accessible copy of comp_driver + tr_ctx for create().
Definition common.h:94
const struct comp_driver * init_drv
Original kernel driver pointer for restoring dev->drv after create.
Definition common.h:84
uint32_t reply_tx_size
Reply TX data size from user thread (e.g.
Definition common.h:78
uint32_t reply_ext
Reply extension word from user thread (e.g.
Definition common.h:76
uint32_t ipc_msg_ext
Copy of IPC4 message extension word forwarded to user thread.
Definition common.h:72
int result
Result code from user thread processing.
Definition common.h:74
struct k_thread * audio_thread[IPC_DSP_CORE_COUNT]
Definition common.h:82
struct ipc * ipc
Definition common.h:81
struct k_thread * thread[IPC_DSP_CORE_COUNT]
Definition common.h:66
struct k_sem * sem
Definition common.h:67
uint32_t ipc_msg_pri
Copy of IPC4 message primary word forwarded to user thread.
Definition common.h:70
bool init_needed[IPC_DSP_CORE_COUNT]
Definition common.h:85
void * reply_tx_data
Reply TX data pointer from user thread (e.g.
Definition common.h:80
Definition common.h:97
bool is_notification_pending
Definition common.h:105
struct k_work_q ipc_send_wq
Definition common.h:131
unsigned int core
Definition common.h:107
int pm_prepare_D3
Definition common.h:102
void * comp_data
Definition common.h:99
struct k_work_delayable z_delayed_work
Definition common.h:130
struct k_spinlock lock
Definition common.h:98
struct list_item msg_list
Definition common.h:104
uint32_t task_mask
Definition common.h:106
struct task ipc_task
Definition common.h:115
struct list_item comp_list
Definition common.h:109
Definition list.h:16
Module and pipeline allocation context aggregating a Zephyr heap and optional virtual region.
Definition alloc.h:251
Definition stream.h:63
General firmware context.
Definition sof.h:50
struct ipc * ipc
Definition sof.h:57
Operations and callbacks associated with a scheduling task.
Definition task.h:72
Core task structure managed by SOF schedulers.
Definition task.h:81
Definition trace.h:132
Core task descriptor, task operations, and task execution state machine.