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
14#ifndef __SOF_AUDIO_PIPELINE_H__
15#define __SOF_AUDIO_PIPELINE_H__
16
17#include <sof/lib/cpu.h>
18#include <sof/list.h>
19#include <rtos/task.h>
20#include <rtos/sof.h>
21#include <rtos/spinlock.h>
23#include <ipc/topology.h>
24#include <user/trace.h>
25#include <errno.h>
26#include <stdbool.h>
27#include <stdint.h>
28
33struct comp_buffer;
34struct comp_dev;
35struct ipc;
36struct ipc_msg;
37struct k_heap;
38struct mod_alloc_ctx;
39
44#define PPL_STATUS_PATH_STOP 1
45
50#define PPL_STATUS_PATH_TERMINATE 2
51
53#define PPL_STATUS_SCHEDULED 2
54
58#define PPL_CONN_DIR_COMP_TO_BUFFER 0
59#define PPL_CONN_DIR_BUFFER_TO_COMP 1
65#define PPL_DIR_DOWNSTREAM 0
66#define PPL_DIR_UPSTREAM 1
72struct pipeline {
74 uint32_t comp_id;
75 uint32_t pipeline_id;
76 uint32_t sched_id;
77 uint32_t core;
78 uint32_t period;
79 uint32_t priority;
80 uint32_t period_mips;
83 uint32_t time_domain;
84 uint32_t attributes;
86 /* runtime status */
87 int32_t xrun_bytes;
88 uint32_t status;
89 struct tr_ctx tctx;
91 /* scheduling */
92#ifdef CONFIG_IPC_MAJOR_4
94#endif
95 struct task *pipe_task;
99 /* component that drives scheduling in this pipe */
101 /* source component for this pipe */
103 /* sink component for this pipe */
108 /* position update */
109 uint32_t posn_offset;
110 struct ipc_msg *msg;
111 struct {
112 int cmd;
113 struct comp_dev *host;
114 unsigned int delay;
115 bool aborted;
116 bool pending;
118};
119
125 int (*comp_func)(struct comp_dev *cd, struct comp_buffer *buffer,
126 struct pipeline_walk_context *ctx, int dir);
127 void *comp_data;
129 void (*buff_func)(struct comp_buffer *buffer, void *data);
130 void *buff_data;
133 /*
134 * If this flag is set, pipeline_for_each_comp() will skip all
135 * incompletely initialised components, i.e. those, whose .pipeline ==
136 * NULL. Such components should not be skipped during initialisation
137 * and clean up, but they should be skipped during streaming.
138 */
140};
141
146 struct comp_dev *start;
149 struct pipeline *p;
150 int cmd;
151 uint32_t delay_ms;
152#if CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL
153 int32_t kcps[CONFIG_CORE_COUNT];
154#endif
155};
156
159 struct task task;
162};
163
165
170
172#define pipeline_task_get(t) container_of(t, struct pipeline_task, task)
173
174/*
175 * Pipeline Graph APIs
176 *
177 * These APIs are used to construct and bind pipeline graphs. They are also
178 * used to query pipeline fundamental configuration.
179 */
180
190struct pipeline *pipeline_new(struct k_heap *heap, uint32_t pipeline_id, uint32_t priority,
191 uint32_t comp_id, struct create_pipeline_params *pparams);
192
198int pipeline_free(struct pipeline *p);
199
207int pipeline_connect(struct comp_dev *comp, struct comp_buffer *buffer,
208 int dir);
209
216void pipeline_disconnect(struct comp_dev *comp, struct comp_buffer *buffer,
217 int dir);
218
226int pipeline_complete(struct pipeline *p, struct comp_dev *source,
227 struct comp_dev *sink);
228
234
235#ifdef CONFIG_SOF_USERSPACE_LL
240void pipeline_posn_grant_access(struct k_thread *thread);
241#endif
242
249int pipeline_reset(struct pipeline *p, struct comp_dev *host_cd);
250
256void pipeline_set_eos(struct pipeline *p, bool eos);
257
266 struct pipeline_walk_context *ctx, int dir);
267
274struct comp_dev *pipeline_get_dai_comp(uint32_t pipeline_id, int dir);
275
276#if CONFIG_IPC_MAJOR_4
283struct comp_dev *pipeline_get_dai_comp_latency(uint32_t pipeline_id, uint32_t *latency);
284#endif
285
291static inline uint32_t pipeline_id(struct pipeline *p)
292{
293 return p->pipeline_id;
294}
295
296/*
297 * Pipeline configuration APIs
298 *
299 * These APIs are used to configure the runtime parameters of a pipeline.
300 */
301
309int pipeline_params(struct pipeline *p, struct comp_dev *cd,
310 struct sof_ipc_pcm_params *params);
311
318int pipeline_prepare(struct pipeline *p, struct comp_dev *cd);
319
320/*
321 * Pipeline stream APIs
322 *
323 * These APIs are used to control pipeline processing work.
324 */
325
333int pipeline_trigger(struct pipeline *p, struct comp_dev *host, int cmd);
334
342int pipeline_trigger_run(struct pipeline *p, struct comp_dev *host, int cmd);
343
349int pipeline_copy(struct pipeline *p);
350
357void pipeline_get_timestamp(struct pipeline *p, struct comp_dev *host_dev,
358 struct sof_ipc_stream_posn *posn);
359
360/*
361 * Pipeline scheduling APIs
362 *
363 * These APIs are used to schedule pipeline processing work.
364 */
365
372static inline bool pipeline_is_same_sched_comp(struct pipeline *current,
373 struct pipeline *previous)
374{
375 return current->sched_comp == previous->sched_comp;
376}
377
383static inline bool pipeline_is_timer_driven(struct pipeline *p)
384{
386}
387
393static inline bool pipeline_is_this_cpu(struct pipeline *p)
394{
395 return p->core == cpu_get_id();
396}
397
404
410
417
423void pipeline_schedule_copy(struct pipeline *p, uint64_t start);
424
432 struct comp_dev *comp,
433 struct pipeline_walk_context *ctx);
434
441 int cmd);
442
453void pipeline_schedule_config(struct pipeline *p, uint32_t sched_id,
454 uint32_t core, uint32_t period,
455 uint32_t period_mips, uint32_t frames_per_sched,
456 uint32_t time_domain);
457
458/*
459 * Pipeline error handling APIs
460 *
461 * These APIs are used to handle, report and recover from pipeline errors.
462 */
463
470
478
485void pipeline_xrun(struct pipeline *p, struct comp_dev *dev, int32_t bytes);
486
493int pipeline_xrun_set_limit(struct pipeline *p, uint32_t xrun_limit_usecs);
494
500void pipeline_comp_copy_error_notify(const struct comp_dev *component, int error_code);
501
504#endif /* __SOF_AUDIO_PIPELINE_H__ */
CPU header file.
int cpu_get_id(void)
static bool pipeline_is_this_cpu(struct pipeline *p)
Checks if pipeline is scheduled on the current core.
Definition pipeline.h:393
static bool pipeline_is_same_sched_comp(struct pipeline *current, struct pipeline *previous)
Checks if two pipelines share the same scheduling component.
Definition pipeline.h:372
int pipeline_comp_ll_task_init(struct pipeline *p)
Initializes a low-latency (LL) task for a pipeline.
int pipeline_reset(struct pipeline *p, struct comp_dev *host_cd)
Resets the pipeline and frees runtime resources.
int pipeline_prepare(struct pipeline *p, struct comp_dev *cd)
Prepares pipeline for audio 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)
Configures pipeline scheduling parameters.
void pipeline_comp_trigger_sched_comp(struct pipeline *p, struct comp_dev *comp, struct pipeline_walk_context *ctx)
Triggers pipeline's scheduling component.
void pipeline_schedule_triggered(struct pipeline_walk_context *ctx, int cmd)
Schedules all triggered pipelines collected during traversal.
static uint32_t pipeline_id(struct pipeline *p)
Retrieves pipeline ID from pipeline structure.
Definition pipeline.h:291
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)
Notifies host and pipeline that an XRUN condition occurred.
int pipeline_free(struct pipeline *p)
Frees a pipeline and its associated resources.
void pipeline_get_timestamp(struct pipeline *p, struct comp_dev *host_dev, struct sof_ipc_stream_posn *posn)
Get pipeline timestamps from host to DAI.
int pipeline_params(struct pipeline *p, struct comp_dev *cd, struct sof_ipc_pcm_params *params)
Sets pipeline runtime audio stream parameters.
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.
struct comp_dev * pipeline_get_dai_comp_latency(uint32_t pipeline_id, uint32_t *latency)
Walks pipeline graph to find DAI component and latency.
int pipeline_copy(struct pipeline *p)
Copy and process stream 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 setup by verifying connectivity between source and sink.
int pipeline_trigger(struct pipeline *p, struct comp_dev *host, int cmd)
Trigger pipeline in IPC context.
int pipeline_xrun_set_limit(struct pipeline *p, uint32_t xrun_limit_usecs)
Sets tolerance limit for pipeline XRUN handling.
int pipeline_xrun_recover(struct pipeline *p)
Recovers the pipeline from an XRUN condition.
void pipeline_set_eos(struct pipeline *p, bool eos)
Sets End Of Stream state for all devices in the pipeline.
int pipeline_trigger_run(struct pipeline *p, struct comp_dev *host, int cmd)
Trigger pipeline in either IPC or pipeline task context.
int pipeline_xrun_handle_trigger(struct pipeline *p, int cmd)
Performs XRUN recovery trigger handling.
void pipeline_comp_ll_task_free(struct pipeline *p)
Frees the low-latency (LL) tasks owned by a pipeline.
int pipeline_comp_dp_task_init(struct comp_dev *comp)
Initializes a data processing (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 a module's processing function.
void pipeline_disconnect(struct comp_dev *comp, struct comp_buffer *buffer, int dir)
Disconnect components and buffers in a pipeline.
void pipeline_schedule_copy(struct pipeline *p, uint64_t start)
Schedules a pipeline copy operation 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)
Checks if pipeline is scheduled with timer.
Definition pipeline.h:383
uint8_t data[0]
Binary byte payload for raw controls.
Definition header.h:5
@ SOF_TIME_DOMAIN_TIMER
Timer interrupt.
Definition topology.h:285
Sound Open Firmware global runtime context.
RTOS spinlock primitives and initialization.
User-space ABI log levels and binary trace packet header definitions.
Audio component interconnect buffer connecting two pipeline components.
Definition buffer.h:150
Audio component base device "class" used by all other component types.
Definition component.h:587
uint32_t period
Component processing period in microseconds.
Definition component.h:596
For storing IPC payload data during pipeline creation.
Definition pipeline.h:167
const struct ipc4_pipeline_ext_obj_mem_data * mem_data
IPC4 pipeline external memory descriptor.
Definition pipeline.h:168
Memory allocation parameters for pipeline execution context.
Definition pipeline.h:86
Definition msg.h:34
Definition common.h:97
Definition list.h:16
Module and pipeline allocation context aggregating a Zephyr heap and optional virtual region.
Definition alloc.h:251
Generic pipeline data used by pipeline_comp_* functions.
Definition pipeline.h:145
struct comp_dev * start
Starting component device.
Definition pipeline.h:146
struct sof_ipc_pcm_params * params
Stream PCM parameters.
Definition pipeline.h:147
uint32_t delay_ms
Delay in milliseconds between pre and main trigger phases.
Definition pipeline.h:151
struct pipeline * p
Target pipeline.
Definition pipeline.h:149
struct sof_ipc_stream_posn * posn
Stream position structure.
Definition pipeline.h:148
int cmd
Command code.
Definition pipeline.h:150
Task type registered by pipelines.
Definition pipeline.h:158
bool registrable
Should task be registered on IRQ.
Definition pipeline.h:160
struct comp_dev * sched_comp
Pipeline scheduling component.
Definition pipeline.h:161
Pipeline traversal walk context for graph exploration and operations.
Definition pipeline.h:123
void * comp_data
Component callback user data.
Definition pipeline.h:127
struct list_item pipelines
Pipelines to be scheduled after trigger walk.
Definition pipeline.h:132
bool skip_incomplete
Skip incompletely initialized components.
Definition pipeline.h:139
void(* buff_func)(struct comp_buffer *buffer, void *data)
Callback function invoked for each buffer in walk.
Definition pipeline.h:129
int(* comp_func)(struct comp_dev *cd, struct comp_buffer *buffer, struct pipeline_walk_context *ctx, int dir)
Callback function invoked for each component in walk.
Definition pipeline.h:125
struct comp_buffer * incoming
Incoming buffer context.
Definition pipeline.h:131
void * buff_data
Buffer callback user data.
Definition pipeline.h:130
Audio pipeline structure representing a stream graph and execution context.
Definition pipeline.h:72
uint32_t priority
Priority level 0 (low) to 10 (max)
Definition pipeline.h:79
uint32_t comp_id
Component ID for pipeline.
Definition pipeline.h:74
struct pipeline::@135 trigger
Pipeline trigger control structure.
struct task * trigger_task
IPC4 pipeline trigger task.
Definition pipeline.h:93
uint32_t time_domain
Scheduling time domain.
Definition pipeline.h:83
uint32_t posn_offset
Position update array offset.
Definition pipeline.h:109
uint32_t core
Core we run on.
Definition pipeline.h:77
struct tr_ctx tctx
Trace settings.
Definition pipeline.h:89
struct mod_alloc_ctx * alloc
Alloc context used for allocating this pipeline.
Definition pipeline.h:73
struct comp_dev * sched_comp
Component that drives scheduling in this pipe.
Definition pipeline.h:100
uint32_t pipeline_id
Pipeline ID.
Definition pipeline.h:75
int cmd
Trigger command.
Definition pipeline.h:112
int32_t xrun_bytes
Last xrun length in bytes.
Definition pipeline.h:87
uint32_t period
Execution period in microseconds.
Definition pipeline.h:78
struct comp_dev * sink_comp
Sink component for this pipe.
Definition pipeline.h:104
struct comp_dev * host
Associated host component device.
Definition pipeline.h:113
struct task * pipe_task
IPC3 pipeline processing task or IPC4 pipeline copy task.
Definition pipeline.h:95
unsigned int delay
Period count delay.
Definition pipeline.h:114
struct list_item list
List item in walk context.
Definition pipeline.h:106
uint32_t xrun_limit_usecs
Report xruns greater than limit.
Definition pipeline.h:82
struct pipeline * sched_prev
Pipeline scheduled before this.
Definition pipeline.h:97
uint32_t period_mips
Worst case instruction count per period.
Definition pipeline.h:80
bool aborted
STOP or PAUSE failed, stay active.
Definition pipeline.h:115
struct ipc_msg * msg
IPC message pointer for position updates.
Definition pipeline.h:110
struct comp_dev * source_comp
Source component for this pipe.
Definition pipeline.h:102
uint32_t sched_id
Scheduling component ID.
Definition pipeline.h:76
uint32_t status
Pipeline status flags.
Definition pipeline.h:88
bool pending
Trigger scheduled but not executed yet.
Definition pipeline.h:116
uint32_t frames_per_sched
Output frames of pipeline, 0 is variable.
Definition pipeline.h:81
uint32_t attributes
Pipeline attributes from IPC extension message.
Definition pipeline.h:84
struct pipeline * sched_next
Pipeline scheduled after this.
Definition pipeline.h:96
Definition stream.h:95
Definition stream.h:134
General firmware context.
Definition sof.h:50
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.