14#ifndef __SOF_AUDIO_BUFFER_H__
15#define __SOF_AUDIO_BUFFER_H__
30#include <sof/trace/trace.h>
31#include <ipc/stream.h>
32#include <ipc/topology.h>
55#define buf_get_id(buf_ptr) ((buf_ptr)->stream.runtime_stream_params.id)
57#if defined(__ZEPHYR__) && defined(CONFIG_ZEPHYR_LOG)
60#define __BUF_FMT "buf:%u %#x "
62#define __BUF_FMT "buf:%u.%u "
65#define buf_err(buf_ptr, __e, ...) LOG_ERR(__BUF_FMT __e, buffer_pipeline_id(buf_ptr), \
66 buf_get_id(buf_ptr), ##__VA_ARGS__)
68#define buf_warn(buf_ptr, __e, ...) LOG_WRN(__BUF_FMT __e, buffer_pipeline_id(buf_ptr), \
69 buf_get_id(buf_ptr), ##__VA_ARGS__)
71#define buf_info(buf_ptr, __e, ...) LOG_INF(__BUF_FMT __e, buffer_pipeline_id(buf_ptr), \
72 buf_get_id(buf_ptr), ##__VA_ARGS__)
74#define buf_dbg(buf_ptr, __e, ...) LOG_DBG(__BUF_FMT __e, buffer_pipeline_id(buf_ptr), \
75 buf_get_id(buf_ptr), ##__VA_ARGS__)
79#define trace_buf_get_tr_ctx(buf_ptr) (&(buf_ptr)->tctx)
82#define buf_err(buf_ptr, __e, ...) \
83 trace_dev_err(trace_buf_get_tr_ctx, buffer_pipeline_id, \
85 (__sparse_force const struct comp_buffer *)buf_ptr, \
89#define buf_warn(buf_ptr, __e, ...) \
90 trace_dev_warn(trace_buf_get_tr_ctx, buffer_pipeline_id, \
92 (__sparse_force const struct comp_buffer *)buf_ptr, \
96#define buf_info(buf_ptr, __e, ...) \
97 trace_dev_info(trace_buf_get_tr_ctx, buffer_pipeline_id, \
99 (__sparse_force const struct comp_buffer *)buf_ptr, \
103#if defined(CONFIG_LIBRARY)
104#define buf_dbg(buf_ptr, __e, ...)
106#define buf_dbg(buf_ptr, __e, ...) \
107 trace_dev_dbg(trace_buf_get_tr_ctx, buffer_pipeline_id, \
109 (__sparse_force const struct comp_buffer *)buf_ptr, \
120#define BUFF_CB_TYPE_PRODUCE BIT(0)
121#define BUFF_CB_TYPE_CONSUME BIT(1)
127#define BUFFER_UPDATE_IF_UNSET 0
128#define BUFFER_UPDATE_FORCE 1
134#define BUFF_PARAMS_FRAME_FMT BIT(0)
135#define BUFF_PARAMS_BUFFER_FMT BIT(1)
136#define BUFF_PARAMS_RATE BIT(2)
137#define BUFF_PARAMS_CHANNELS BIT(3)
143#define BUFFER_USAGE_SHARED true
144#define BUFFER_USAGE_NOT_SHARED false
160#if !CONFIG_ZEPHYR_LOG
179 void (*probe_cb_free)(
void *arg);
260#define buffer_from_list(ptr, dir) \
261 ((dir) == PPL_DIR_DOWNSTREAM ? \
262 container_of(ptr, struct comp_buffer, source_list) : \
263 container_of(ptr, struct comp_buffer, sink_list))
272#define buffer_set_cb(buffer, func, data, type) \
275 buffer->cb_data = data; \
276 buffer->cb_type = type; \
291 uint32_t align,
bool is_shared);
305 uint32_t
flags, uint32_t align,
bool is_shared);
Memory allocation API, zones, heaps, and alignment utilities.
Audio buffer operations, descriptors, and unified audio buffer interfaces.
RTOS data and instruction cache invalidation and writeback helpers.
Cache-coherent multi-core shared memory access abstractions.
#define container_of(ptr, type, member)
Definition common.h:117
struct comp_buffer * buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint32_t flags, uint32_t align, bool is_shared)
Allocate a pipeline component audio buffer with explicit size and alignment.
static void audio_stream_invalidate(struct audio_stream *buffer, uint32_t bytes)
Invalidates (in DSP d-cache) the buffer in range [r_ptr, r_ptr+bytes], with rollover if necessary.
Definition audio_stream.h:728
void audio_stream_init(struct audio_stream *audio_stream, void *buff_addr, uint32_t size)
Initializes the buffer with specified memory block and size.
static void comp_buffer_reset_source_list(struct comp_buffer *buffer)
Reset buffer source list node.
Definition buffer.h:231
static void comp_buffer_set_source_component(struct comp_buffer *buffer, struct comp_dev *comp)
Set component providing data to the buffer.
Definition buffer.h:211
int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignment)
Resize an existing pipeline component buffer.
int buffer_set_params(struct comp_buffer *buffer, struct sof_ipc_stream_params *params, bool force_update)
Set audio stream parameters on a component buffer.
static struct comp_buffer * comp_buffer_get_from_sink(struct sof_sink *sink)
Retrieve enclosing comp_buffer from an audio sink interface pointer.
Definition buffer.h:356
struct comp_buffer * buffer_new(struct mod_alloc_ctx *alloc, const struct sof_ipc_buffer *desc, bool is_shared)
Instantiate a pipeline component buffer from an IPC configuration descriptor.
bool buffer_params_match(struct comp_buffer *buffer, struct sof_ipc_stream_params *params, uint32_t flag)
Test if buffer stream parameters match requested parameters.
static void buffer_free(struct comp_buffer *buffer)
Free an interconnect component buffer and its underlying memory.
Definition buffer.h:367
static void buffer_stream_writeback(struct comp_buffer *buffer, uint32_t bytes)
Write back cache for a shared buffer stream if incoherent.
Definition buffer.h:432
void buffer_zero(struct comp_buffer *buffer)
Zero-fill the entire payload of an interconnect buffer.
static struct comp_buffer * comp_buffer_get_from_source(struct sof_source *source)
Retrieve enclosing comp_buffer from an audio source interface pointer.
Definition buffer.h:344
static struct comp_dev * buffer_get_comp(struct comp_buffer *buffer, int dir)
Get component connected to buffer in specified traversal direction.
Definition buffer.h:474
struct comp_buffer * buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t preferred_size, size_t minimum_size, uint32_t flags, uint32_t align, bool is_shared)
Allocate a pipeline component buffer with an elastic size range.
static struct comp_dev * comp_buffer_get_source_component(const struct comp_buffer *buffer)
Get component providing data to the buffer.
Definition buffer.h:190
static void comp_buffer_set_sink_component(struct comp_buffer *buffer, struct comp_dev *comp)
Set component consuming data from the buffer.
Definition buffer.h:222
static bool audio_buffer_is_shared(struct sof_audio_buffer *buffer)
Check if audio buffer is shared across cores.
Definition audio_buffer.h:210
void comp_update_buffer_produce(struct comp_buffer *buffer, uint32_t bytes)
Notify buffer that audio data has been produced by a component.
void comp_update_buffer_consume(struct comp_buffer *buffer, uint32_t bytes)
Notify buffer that audio data has been consumed by a component.
static struct comp_dev * comp_buffer_get_sink_component(const struct comp_buffer *buffer)
Get component consuming data from the buffer.
Definition buffer.h:200
static struct sof_audio_buffer * sof_audio_buffer_from_sink(struct sof_sink *sink)
Retrieve enclosing sof_audio_buffer from sink interface pointer.
Definition audio_buffer.h:317
static struct sof_audio_buffer * sof_audio_buffer_from_source(struct sof_source *source)
Retrieve enclosing sof_audio_buffer from source interface pointer.
Definition audio_buffer.h:331
int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, size_t minimum_size, uint32_t alignment)
Resize a pipeline component buffer within a preferred-to-minimum range.
static void comp_buffer_reset_sink_list(struct comp_buffer *buffer)
Reset buffer sink list node.
Definition buffer.h:240
int buffer_attach(struct comp_buffer *buffer, struct list_item *head, int dir)
Attach a new buffer at the beginning of a component buffer list.
static void buffer_init_stream(struct comp_buffer *buffer, size_t size)
Initialize circular stream buffer descriptor for a component buffer.
Definition buffer.h:497
static void audio_stream_writeback(struct audio_stream *buffer, uint32_t bytes)
Writes back (from DSP d-cache) the buffer in range [w_ptr, w_ptr+bytes], with rollover if necessary.
Definition audio_stream.h:751
static uint32_t buffer_pipeline_id(const struct comp_buffer *buffer)
Retrieve pipeline ID associated with a component buffer.
Definition buffer.h:487
static void buffer_stream_invalidate(struct comp_buffer *buffer, uint32_t bytes)
Invalidate cache for a shared buffer stream if incoherent.
Definition buffer.h:419
void buffer_detach(struct comp_buffer *buffer, struct list_item *head, int dir)
Detach a buffer from anywhere in a component buffer list.
void audio_buffer_free(struct sof_audio_buffer *buffer)
Free audio buffer and all allocated resources.
#define PPL_DIR_DOWNSTREAM
Downstream playback/processing direction.
Definition pipeline.h:65
static void list_init(struct list_item *list)
Definition list.h:25
Fixed-point arithmetic, saturation, rounding, and number format conversions.
Audio Stream API definition.
Audio pipeline management, graph scheduling, and execution control.
RTOS spinlock primitives and initialization.
User-space ABI log levels and binary trace packet header definitions.
Audio stream is a circular buffer aware of audio format of the data in the buffer so provides API for...
Definition audio_stream.h:51
struct sof_audio_stream_params runtime_stream_params
Definition audio_stream.h:65
void * addr
Buffer base address.
Definition audio_stream.h:58
Transaction descriptor passed to buffer probe callbacks.
Definition buffer.h:248
struct comp_buffer * buffer
Buffer being transacted.
Definition buffer.h:249
uint32_t transaction_amount
Number of bytes transacted.
Definition buffer.h:250
void * transaction_begin_address
Starting address of transaction.
Definition buffer.h:251
Audio component interconnect buffer connecting two pipeline components.
Definition buffer.h:150
struct tr_ctx tctx
Trace context.
Definition buffer.h:161
struct list_item source_list
List node in source component's buffer list.
Definition buffer.h:169
struct list_item sink_list
List node in sink component's buffer list.
Definition buffer.h:170
struct list_item buffers_list
List of buffers used in raw data processing.
Definition buffer.h:173
uint32_t core
DSP core ID managing this buffer.
Definition buffer.h:158
struct audio_stream stream
Legacy audio stream representation.
Definition buffer.h:154
struct comp_dev * source
Source component feeding this buffer.
Definition buffer.h:165
struct comp_dev * sink
Sink component consuming from this buffer.
Definition buffer.h:166
uint32_t flags
Buffer flags.
Definition buffer.h:157
struct sof_audio_buffer audio_buffer
Unified audio buffer base class.
Definition buffer.h:152
Audio component base device "class" used by all other component types.
Definition component.h:587
uint32_t size
Component allocated size in bytes.
Definition component.h:595
Module and pipeline allocation context aggregating a Zephyr heap and optional virtual region.
Definition alloc.h:251
Base class for all audio buffers.
Definition audio_buffer.h:92
uint32_t pipeline_id
Definition audio_stream.h:51
Definition topology.h:107
internals of sink API.
Definition sink_api.h:141
internals of source API.
Definition source_api.h:137