forked from macchian/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.h
More file actions
271 lines (212 loc) · 7.47 KB
/
buffer.h
File metadata and controls
271 lines (212 loc) · 7.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2017 Intel Corporation. All rights reserved.
*
* Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
*/
#ifndef __SOF_AUDIO_BUFFER_H__
#define __SOF_AUDIO_BUFFER_H__
#include <sof/audio/audio_stream.h>
#include <sof/audio/pipeline.h>
#include <sof/math/numbers.h>
#include <sof/common.h>
#include <sof/debug/panic.h>
#include <sof/lib/alloc.h>
#include <sof/lib/cache.h>
#include <sof/lib/uuid.h>
#include <sof/list.h>
#include <sof/math/numbers.h>
#include <sof/spinlock.h>
#include <sof/string.h>
#include <sof/trace/trace.h>
#include <ipc/stream.h>
#include <ipc/topology.h>
#include <user/trace.h>
#include <sof/audio/format.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
struct comp_dev;
/** \name Trace macros
* @{
*/
/* buffer tracing */
extern struct tr_ctx buffer_tr;
/** \brief Retrieves trace context from the buffer */
#define trace_buf_get_tr_ctx(buf_ptr) (&(buf_ptr)->tctx)
/** \brief Retrieves id (pipe id) from the buffer */
#define trace_buf_get_id(buf_ptr) ((buf_ptr)->pipeline_id)
/** \brief Retrieves subid (comp id) from the buffer */
#define trace_buf_get_subid(buf_ptr) ((buf_ptr)->id)
/** \brief Trace error message from buffer */
#define buf_err(buf_ptr, __e, ...) \
trace_dev_err(trace_buf_get_tr_ctx, trace_buf_get_id, \
trace_buf_get_subid, buf_ptr, __e, ##__VA_ARGS__)
/** \brief Trace warning message from buffer */
#define buf_warn(buf_ptr, __e, ...) \
trace_dev_warn(trace_buf_get_tr_ctx, trace_buf_get_id, \
trace_buf_get_subid, buf_ptr, __e, ##__VA_ARGS__)
/** \brief Trace info message from buffer */
#define buf_info(buf_ptr, __e, ...) \
trace_dev_info(trace_buf_get_tr_ctx, trace_buf_get_id, \
trace_buf_get_subid, buf_ptr, __e, ##__VA_ARGS__)
/** \brief Trace debug message from buffer */
#define buf_dbg(buf_ptr, __e, ...) \
trace_dev_dbg(trace_buf_get_tr_ctx, trace_buf_get_id, \
trace_buf_get_subid, buf_ptr, __e, ##__VA_ARGS__)
/** @}*/
/* buffer callback types */
#define BUFF_CB_TYPE_PRODUCE BIT(0)
#define BUFF_CB_TYPE_CONSUME BIT(1)
#define BUFFER_UPDATE_IF_UNSET 0
#define BUFFER_UPDATE_FORCE 1
/* buffer parameters */
#define BUFF_PARAMS_FRAME_FMT BIT(0)
#define BUFF_PARAMS_BUFFER_FMT BIT(1)
#define BUFF_PARAMS_RATE BIT(2)
#define BUFF_PARAMS_CHANNELS BIT(3)
/* audio component buffer - connects 2 audio components together in pipeline */
struct comp_buffer {
spinlock_t *lock; /* locking mechanism */
/* data buffer */
struct audio_stream stream;
/* configuration */
uint32_t id;
uint32_t pipeline_id;
uint32_t caps;
uint32_t core;
bool inter_core; /* true if connected to a comp from another core */
struct tr_ctx tctx; /* trace settings */
/* connected components */
struct comp_dev *source; /* source component */
struct comp_dev *sink; /* sink component */
/* lists */
struct list_item source_list; /* list in comp buffers */
struct list_item sink_list; /* list in comp buffers */
/* runtime stream params */
uint32_t buffer_fmt; /**< enum sof_ipc_buffer_format */
uint16_t chmap[SOF_IPC_MAX_CHANNELS]; /**< channel map - SOF_CHMAP_ */
bool hw_params_configured; /**< indicates whether hw params were set */
bool walking; /**< indicates if the buffer is being walking */
};
struct buffer_cb_transact {
struct comp_buffer *buffer;
uint32_t transaction_amount;
void *transaction_begin_address;
};
struct buffer_cb_free {
struct comp_buffer *buffer;
};
#define buffer_comp_list(buffer, dir) \
((dir) == PPL_DIR_DOWNSTREAM ? &buffer->source_list : \
&buffer->sink_list)
#define buffer_from_list(ptr, type, dir) \
((dir) == PPL_DIR_DOWNSTREAM ? \
container_of(ptr, type, source_list) : \
container_of(ptr, type, sink_list))
#define buffer_get_comp(buffer, dir) \
((dir) == PPL_DIR_DOWNSTREAM ? buffer->sink : \
buffer->source)
#define buffer_set_comp(buffer, comp, dir) \
do { \
if (dir == PPL_CONN_DIR_COMP_TO_BUFFER) \
buffer->source = comp; \
else \
buffer->sink = comp; \
} while (0) \
#define buffer_set_cb(buffer, func, data, type) \
do { \
buffer->cb = func; \
buffer->cb_data = data; \
buffer->cb_type = type; \
} while (0)
/* pipeline buffer creation and destruction */
struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t align);
struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc);
int buffer_set_size(struct comp_buffer *buffer, uint32_t size);
void buffer_free(struct comp_buffer *buffer);
void buffer_zero(struct comp_buffer *buffer);
/* called by a component after producing data into this buffer */
void comp_update_buffer_produce(struct comp_buffer *buffer, uint32_t bytes);
/* called by a component after consuming data from this buffer */
void comp_update_buffer_consume(struct comp_buffer *buffer, uint32_t bytes);
int buffer_set_params(struct comp_buffer *buffer, struct sof_ipc_stream_params *params,
bool force_update);
bool buffer_params_match(struct comp_buffer *buffer, struct sof_ipc_stream_params *params,
uint32_t flag);
static inline void buffer_invalidate(struct comp_buffer *buffer, uint32_t bytes)
{
if (!buffer->inter_core)
return;
audio_stream_invalidate(&buffer->stream, bytes);
}
static inline void buffer_writeback(struct comp_buffer *buffer, uint32_t bytes)
{
if (!buffer->inter_core)
return;
audio_stream_writeback(&buffer->stream, bytes);
}
/**
* Locks buffer instance for buffers connecting components
* running on different cores. Buffer parameters will be invalidated
* to make sure the latest data can be retrieved.
* @param buffer Buffer instance.
* @param flags IRQ flags.
*/
static inline void buffer_lock(struct comp_buffer *buffer, uint32_t *flags)
{
if (!buffer->inter_core) {
/* Ignored by buffer_unlock() below, silences "may be
* used uninitialized" warning.
*/
*flags = 0xffffffff;
return;
}
/* Expands to: *flags = ... */
spin_lock_irq(buffer->lock, *flags);
/* invalidate in case something has changed during our wait */
dcache_invalidate_region(buffer, sizeof(*buffer));
}
/**
* Unlocks buffer instance for buffers connecting components
* running on different cores. Buffer parameters will be flushed
* to make sure all the changes are saved. Also they will be invalidated
* to spare the need of locking/unlocking buffer, when only reading parameters.
* @param buffer Buffer instance.
* @param flags IRQ flags.
*/
static inline void buffer_unlock(struct comp_buffer *buffer, uint32_t flags)
{
if (!buffer->inter_core)
return;
/* save lock pointer to avoid memory access after cache flushing */
spinlock_t *lock = buffer->lock;
/* wtb and inv to avoid buffer locking in read only situations */
dcache_writeback_invalidate_region(buffer, sizeof(*buffer));
spin_unlock_irq(lock, flags);
}
static inline void buffer_reset_pos(struct comp_buffer *buffer, void *data)
{
uint32_t flags = 0;
buffer_lock(buffer, &flags);
/* reset rw pointers and avail/free bytes counters */
audio_stream_reset(&buffer->stream);
/* clear buffer contents */
buffer_zero(buffer);
buffer_unlock(buffer, flags);
}
static inline void buffer_init(struct comp_buffer *buffer, uint32_t size,
uint32_t caps)
{
buffer->caps = caps;
/* addr should be set in alloc function */
audio_stream_init(&buffer->stream, buffer->stream.addr, size);
}
static inline void buffer_reset_params(struct comp_buffer *buffer, void *data)
{
uint32_t flags = 0;
buffer_lock(buffer, &flags);
buffer->hw_params_configured = false;
buffer_unlock(buffer, flags);
}
#endif /* __SOF_AUDIO_BUFFER_H__ */