Sound Open Firmware
Loading...
Searching...
No Matches
pipeline.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 */
7
8#ifndef __SOF_AUDIO_PIPELINE_H__
9#define __SOF_AUDIO_PIPELINE_H__
10
11#include <sof/lib/cpu.h>
12#include <sof/lib/mailbox.h>
13#include <sof/list.h>
14#include <rtos/task.h>
15#include <rtos/sof.h>
16#include <rtos/spinlock.h>
18#include <ipc/topology.h>
19#include <user/trace.h>
20#include <errno.h>
21#include <stdbool.h>
22#include <stdint.h>
23
24struct comp_buffer;
25struct comp_dev;
26struct ipc;
27struct ipc_msg;
28struct k_heap;
29
30/*
31 * Pipeline status to stop execution of current path, but to keep the
32 * pipeline alive, when processing COMP_TRIGGER_STOP or COMP_TRIGGER_PAUSE
33 */
34#define PPL_STATUS_PATH_STOP 1
35/*
36 * Pipeline status to stop execution of current path, and to terminate the
37 * pipeline, when processing COMP_TRIGGER_STOP or COMP_TRIGGER_PAUSE
38 */
39#define PPL_STATUS_PATH_TERMINATE 2
40
41/* Pipeline scheduled in another thread other than ipc thread */
42#define PPL_STATUS_SCHEDULED 2
43
44/* pipeline connection directions */
45#define PPL_CONN_DIR_COMP_TO_BUFFER 0
46#define PPL_CONN_DIR_BUFFER_TO_COMP 1
47
48/* pipeline processing directions */
49#define PPL_DIR_DOWNSTREAM 0
50#define PPL_DIR_UPSTREAM 1
51
52/*
53 * Audio pipeline.
54 */
55struct pipeline {
56 struct k_heap *heap;
57 uint32_t comp_id;
58 uint32_t pipeline_id;
59 uint32_t sched_id;
60 uint32_t core;
61 uint32_t period;
62 uint32_t priority;
63 uint32_t period_mips;
66 uint32_t time_domain;
67 uint32_t attributes;
68
69 /* runtime status */
70 int32_t xrun_bytes; /* last xrun length */
71 uint32_t status; /* pipeline status */
72 struct tr_ctx tctx; /* trace settings */
73 bool expect_eos; /* pipeline is expecting end of stream */
74
75 /* scheduling */
76#ifdef CONFIG_IPC_MAJOR_4
77 struct task *trigger_task; /* IPC4 pipeline trigger task */
78#endif
79 struct task *pipe_task; /* IPC3 pipeline processing task or IPC4 pipeline copy task */
80 struct pipeline *sched_next; /* pipeline scheduled after this */
81 struct pipeline *sched_prev; /* pipeline scheduled before this */
82
83 /* component that drives scheduling in this pipe */
85 /* source component for this pipe */
87 /* sink component for this pipe */
89
90 struct list_item list;
91
92 /* position update */
93 uint32_t posn_offset; /* position update array offset*/
94 struct ipc_msg *msg;
95 struct {
96 int cmd;
97 struct comp_dev *host;
98 unsigned int delay; /* period count */
99 bool aborted; /* STOP or PAUSE failed, stay active */
100 bool pending; /* trigger scheduled but not executed yet */
102};
103
105 int (*comp_func)(struct comp_dev *cd, struct comp_buffer *buffer,
106 struct pipeline_walk_context *ctx, int dir);
108 void (*buff_func)(struct comp_buffer *buffer, void *data);
113 /*
114 * If this flag is set, pipeline_for_each_comp() will skip all
115 * incompletely initialised components, i.e. those, whose .pipeline ==
116 * NULL. Such components should not be skipped during initialisation
117 * and clean up, but they should be skipped during streaming.
118 */
120};
121
122/* generic pipeline data used by pipeline_comp_* functions */
127 struct pipeline *p;
128 int cmd;
129 uint32_t delay_ms; /* between PRE_{START,RELEASE} and {START,RELEASE} */
130#if CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL
131 int32_t kcps[CONFIG_CORE_COUNT];
132#endif
133};
134
137 struct task task;
140};
141
142struct ipc4_pipeline_ext_obj_mem_data;
143
146 const struct ipc4_pipeline_ext_obj_mem_data *mem_data;
147};
148
149#define pipeline_task_get(t) container_of(t, struct pipeline_task, task)
150
151/*
152 * Pipeline Graph APIs
153 *
154 * These APIs are used to construct and bind pipeline graphs. They are also
155 * used to query pipeline fundamental configuration.
156 */
157
167struct pipeline *pipeline_new(struct k_heap *heap, uint32_t pipeline_id, uint32_t priority,
168 uint32_t comp_id, struct create_pipeline_params *pparams);
169
175int pipeline_free(struct pipeline *p);
176
184int pipeline_connect(struct comp_dev *comp, struct comp_buffer *buffer,
185 int dir);
186
193void pipeline_disconnect(struct comp_dev *comp, struct comp_buffer *buffer,
194 int dir);
195
203int pipeline_complete(struct pipeline *p, struct comp_dev *source,
204 struct comp_dev *sink);
205
211
212#ifdef CONFIG_SOF_USERSPACE_LL
217void pipeline_posn_grant_access(struct k_thread *thread);
218#endif
219
226int pipeline_reset(struct pipeline *p, struct comp_dev *host_cd);
227
236 struct pipeline_walk_context *ctx, int dir);
237
244struct comp_dev *pipeline_get_dai_comp(uint32_t pipeline_id, int dir);
245
246#if CONFIG_IPC_MAJOR_4
253struct comp_dev *pipeline_get_dai_comp_latency(uint32_t pipeline_id, uint32_t *latency);
254#endif
255
261static inline uint32_t pipeline_id(struct pipeline *p)
262{
263 return p->pipeline_id;
264}
265
266/*
267 * Pipeline configuration APIs
268 *
269 * These APIs are used to configure the runtime parameters of a pipeline.
270 */
271
279int pipeline_params(struct pipeline *p, struct comp_dev *cd,
280 struct sof_ipc_pcm_params *params);
281
288int pipeline_prepare(struct pipeline *p, struct comp_dev *cd);
289
290/*
291 * Pipeline stream APIs
292 *
293 * These APIs are used to control pipeline processing work.
294 */
295
303int pipeline_trigger(struct pipeline *p, struct comp_dev *host, int cmd);
304
312int pipeline_trigger_run(struct pipeline *p, struct comp_dev *host, int cmd);
313
319int pipeline_copy(struct pipeline *p);
320
327void pipeline_get_timestamp(struct pipeline *p, struct comp_dev *host_dev,
328 struct sof_ipc_stream_posn *posn);
329
330/*
331 * Pipeline scheduling APIs
332 *
333 * These APIs are used to schedule pipeline processing work.
334 */
335
342static inline bool pipeline_is_same_sched_comp(struct pipeline *current,
343 struct pipeline *previous)
344{
345 return current->sched_comp == previous->sched_comp;
346}
347
353static inline bool pipeline_is_timer_driven(struct pipeline *p)
354{
356}
357
363static inline bool pipeline_is_this_cpu(struct pipeline *p)
364{
365 return p->core == cpu_get_id();
366}
367
374
380
387
393void pipeline_schedule_copy(struct pipeline *p, uint64_t start);
394
402 struct comp_dev *comp,
403 struct pipeline_walk_context *ctx);
404
411 int cmd);
412
423void pipeline_schedule_config(struct pipeline *p, uint32_t sched_id,
424 uint32_t core, uint32_t period,
425 uint32_t period_mips, uint32_t frames_per_sched,
426 uint32_t time_domain);
427
428/*
429 * Pipeline error handling APIs
430 *
431 * These APIs are used to handle, report and recover from pipeline errors.
432 */
433
440
448
455void pipeline_xrun(struct pipeline *p, struct comp_dev *dev, int32_t bytes);
456
462int pipeline_xrun_set_limit(struct pipeline *p, uint32_t xrun_limit_usecs);
463
469void pipeline_comp_copy_error_notify(const struct comp_dev *component, int error_code);
470
471#endif /* __SOF_AUDIO_PIPELINE_H__ */
CPU header file.
static int cpu_get_id(void)
Definition cpu.h:98
uint32_t data[]
Definition debug_stream_slot.h:2
@ SOF_TIME_DOMAIN_TIMER
Timer interrupt.
Definition topology.h:285
#define list_item(item, type, member)
Definition list.h:80
static bool pipeline_is_this_cpu(struct pipeline *p)
Is pipeline is scheduled on this core.
Definition pipeline.h:363
static bool pipeline_is_same_sched_comp(struct pipeline *current, struct pipeline *previous)
Checks if two pipelines have the same scheduling component.
Definition pipeline.h:342
int pipeline_comp_ll_task_init(struct pipeline *p)
Init an LL task for a pipeline.
int pipeline_reset(struct pipeline *p, struct comp_dev *host_cd)
Resets the pipeline and free runtime resources.
int pipeline_prepare(struct pipeline *p, struct comp_dev *cd)
Prepares pipeline for processing.
void pipeline_schedule_config(struct pipeline *p, uint32_t sched_id, uint32_t core, uint32_t period, uint32_t period_mips, uint32_t frames_per_sched, uint32_t time_domain)
Configure pipeline scheduling.
void pipeline_comp_trigger_sched_comp(struct pipeline *p, struct comp_dev *comp, struct pipeline_walk_context *ctx)
Trigger pipeline's scheduling component.
void pipeline_schedule_triggered(struct pipeline_walk_context *ctx, int cmd)
Schedule all triggered pipelines.
static uint32_t pipeline_id(struct pipeline *p)
Retrieves pipeline id from pipeline.
Definition pipeline.h:261
int pipeline_for_each_comp(struct comp_dev *current, struct pipeline_walk_context *ctx, int dir)
Walks the pipeline graph for each component.
struct comp_dev * pipeline_get_dai_comp(uint32_t pipeline_id, int dir)
Walks pipeline graph to find dai component.
void pipeline_xrun(struct pipeline *p, struct comp_dev *dev, int32_t bytes)
notify host that we have XRUN.
int pipeline_free(struct pipeline *p)
Free's a pipeline.
void pipeline_get_timestamp(struct pipeline *p, struct comp_dev *host_dev, struct sof_ipc_stream_posn *posn)
Get time pipeline timestamps from host to dai.
int pipeline_params(struct pipeline *p, struct comp_dev *cd, struct sof_ipc_pcm_params *params)
Creates a new pipeline.
struct pipeline * pipeline_new(struct k_heap *heap, uint32_t pipeline_id, uint32_t priority, uint32_t comp_id, struct create_pipeline_params *pparams)
Creates a new pipeline.
int pipeline_copy(struct pipeline *p)
Copy data along a pipeline.
void pipeline_posn_init(struct sof *sof)
Initializes pipeline position structure.
int pipeline_complete(struct pipeline *p, struct comp_dev *source, struct comp_dev *sink)
Completes a pipeline.
int pipeline_trigger(struct pipeline *p, struct comp_dev *host, int cmd)
Trigger pipeline - IPC context.
int pipeline_xrun_set_limit(struct pipeline *p, uint32_t xrun_limit_usecs)
Set tolerance for pipeline xrun handling.
int pipeline_xrun_recover(struct pipeline *p)
Recover the pipeline from a XRUN condition.
int pipeline_trigger_run(struct pipeline *p, struct comp_dev *host, int cmd)
Trigger pipeline - either IPC or pipeline task context.
int pipeline_xrun_handle_trigger(struct pipeline *p, int cmd)
Perform xrun recovery.
void pipeline_comp_ll_task_free(struct pipeline *p)
Free the LL tasks owned by a pipeline.
int pipeline_comp_dp_task_init(struct comp_dev *comp)
Init a DP task for a component.
void pipeline_comp_copy_error_notify(const struct comp_dev *component, int error_code)
Sends an ipc notification that an error occurred in the module's processing function.
void pipeline_disconnect(struct comp_dev *comp, struct comp_buffer *buffer, int dir)
Creates a new pipeline.
void pipeline_schedule_copy(struct pipeline *p, uint64_t start)
Schedule a pipeline copy to run after a delay.
int pipeline_connect(struct comp_dev *comp, struct comp_buffer *buffer, int dir)
Connect components in a pipeline.
static bool pipeline_is_timer_driven(struct pipeline *p)
Is pipeline is scheduled with timer.
Definition pipeline.h:353
Definition buffer.h:130
Audio component base device "class".
Definition component.h:645
uint32_t period
component's processing period for LL modules is set to LL pipeline's period for DP module its meaning...
Definition component.h:658
For storing IPC payload data.
Definition pipeline.h:145
const struct ipc4_pipeline_ext_obj_mem_data * mem_data
Definition pipeline.h:146
Definition msg.h:33
Definition common.h:90
Definition pipeline.h:123
struct comp_dev * start
Definition pipeline.h:124
struct sof_ipc_pcm_params * params
Definition pipeline.h:125
uint32_t delay_ms
Definition pipeline.h:129
struct pipeline * p
Definition pipeline.h:127
struct sof_ipc_stream_posn * posn
Definition pipeline.h:126
int cmd
Definition pipeline.h:128
Task type registered by pipelines.
Definition pipeline.h:136
bool registrable
should task be registered on irq
Definition pipeline.h:138
struct task task
parent structure
Definition pipeline.h:137
struct comp_dev * sched_comp
pipeline scheduling component
Definition pipeline.h:139
Definition pipeline.h:104
void * comp_data
Definition pipeline.h:107
struct list_item pipelines
Definition pipeline.h:112
bool skip_incomplete
Definition pipeline.h:119
void(* buff_func)(struct comp_buffer *buffer, void *data)
Definition pipeline.h:108
int(* comp_func)(struct comp_dev *cd, struct comp_buffer *buffer, struct pipeline_walk_context *ctx, int dir)
Definition pipeline.h:105
struct comp_buffer * incoming
pipelines to be scheduled after trigger walk
Definition pipeline.h:110
void * buff_data
Definition pipeline.h:109
Definition pipeline.h:55
uint32_t priority
priority level 0 (low) to 10 (max)
Definition pipeline.h:62
uint32_t comp_id
component id for pipeline
Definition pipeline.h:57
uint32_t time_domain
scheduling time domain
Definition pipeline.h:66
uint32_t posn_offset
Definition pipeline.h:93
uint32_t core
core we run on
Definition pipeline.h:60
struct tr_ctx tctx
Definition pipeline.h:72
struct comp_dev * sched_comp
Definition pipeline.h:84
uint32_t pipeline_id
pipeline id
Definition pipeline.h:58
int cmd
Definition pipeline.h:96
int32_t xrun_bytes
Definition pipeline.h:70
struct k_heap * heap
heap used for allocating this pipeline
Definition pipeline.h:56
uint32_t period
execution period in us
Definition pipeline.h:61
struct comp_dev * sink_comp
Definition pipeline.h:88
struct comp_dev * host
Definition pipeline.h:97
struct task * pipe_task
Definition pipeline.h:79
bool expect_eos
Definition pipeline.h:73
unsigned int delay
Definition pipeline.h:98
struct list_item list
list in walk context
Definition pipeline.h:90
uint32_t xrun_limit_usecs
report xruns greater than limit
Definition pipeline.h:65
struct pipeline * sched_prev
Definition pipeline.h:81
uint32_t period_mips
worst case instruction count per period
Definition pipeline.h:63
bool aborted
Definition pipeline.h:99
struct ipc_msg * msg
Definition pipeline.h:94
struct comp_dev * source_comp
Definition pipeline.h:86
struct pipeline::@136334161205271162314161116057173351246237250367 trigger
uint32_t sched_id
Scheduling component id.
Definition pipeline.h:59
uint32_t status
Definition pipeline.h:71
bool pending
Definition pipeline.h:100
uint32_t frames_per_sched
output frames of pipeline, 0 is variable
Definition pipeline.h:64
uint32_t attributes
pipeline attributes from IPC extension msg/
Definition pipeline.h:67
struct pipeline * sched_next
Definition pipeline.h:80
Definition stream.h:95
Definition stream.h:134
General firmware context.
Definition sof.h:44
Task used by schedulers.
Definition task.h:56
Definition trace.h:135