Skip to content

Commit bd4f0e1

Browse files
lyakhlgirdwood
authored andcommitted
coherence: convert buffer and audio-stream APIs to use __sparse_cache
To properly use buffer-locking functions many buffer and audio-stream API functions have to use the __sparse_cache annotation too. Note, that we don't convert comp_update_buffer_consume() and comp_update_buffer_produce() yet. They will be converted together with all the buffer API users to also move buffer acquisition out of those functions into the caller scope. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 559266e commit bd4f0e1

5 files changed

Lines changed: 118 additions & 90 deletions

File tree

src/audio/buffer.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ DECLARE_TR_CTX(buffer_tr, SOF_UUID(buffer_uuid), LOG_LEVEL_INFO);
2929
struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t align)
3030
{
3131
struct comp_buffer *buffer;
32+
struct comp_buffer __sparse_cache *buffer_c;
3233

3334
tr_dbg(&buffer_tr, "buffer_alloc()");
3435

@@ -55,15 +56,19 @@ struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t align)
5556
return NULL;
5657
}
5758

58-
buffer_init(buffer, size, caps);
59-
coherent_init_thread(buffer, c);
6059
list_init(&buffer->source_list);
6160
list_init(&buffer->sink_list);
6261

62+
coherent_init_thread(buffer, c);
63+
64+
buffer_c = buffer_acquire(buffer);
65+
buffer_init(buffer_c, size, caps);
66+
buffer_release(buffer_c);
67+
6368
return buffer;
6469
}
6570

66-
void buffer_zero(struct comp_buffer *buffer)
71+
void buffer_zero(struct comp_buffer __sparse_cache *buffer)
6772
{
6873
buf_dbg(buffer, "stream_zero()");
6974

@@ -73,7 +78,7 @@ void buffer_zero(struct comp_buffer *buffer)
7378
buffer->stream.size);
7479
}
7580

76-
int buffer_set_size(struct comp_buffer *buffer, uint32_t size)
81+
int buffer_set_size(struct comp_buffer __sparse_cache *buffer, uint32_t size)
7782
{
7883
void *new_ptr = NULL;
7984

@@ -105,8 +110,8 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size)
105110
return 0;
106111
}
107112

108-
int buffer_set_params(struct comp_buffer *buffer, struct sof_ipc_stream_params *params,
109-
bool force_update)
113+
int buffer_set_params(struct comp_buffer __sparse_cache *buffer,
114+
struct sof_ipc_stream_params *params, bool force_update)
110115
{
111116
int ret;
112117
int i;
@@ -134,8 +139,8 @@ int buffer_set_params(struct comp_buffer *buffer, struct sof_ipc_stream_params *
134139
return 0;
135140
}
136141

137-
bool buffer_params_match(struct comp_buffer *buffer, struct sof_ipc_stream_params *params,
138-
uint32_t flag)
142+
bool buffer_params_match(struct comp_buffer __sparse_cache *buffer,
143+
struct sof_ipc_stream_params *params, uint32_t flag)
139144
{
140145
assert(params);
141146

src/audio/component.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ void sys_comp_init(struct sof *sof)
149149
k_spinlock_init(&sof->comp_drivers->lock);
150150
}
151151

152-
void comp_get_copy_limits(struct comp_buffer *source, struct comp_buffer *sink,
152+
void comp_get_copy_limits(struct comp_buffer __sparse_cache *source,
153+
struct comp_buffer __sparse_cache *sink,
153154
struct comp_copy_limits *cl)
154155
{
155156
cl->frames = audio_stream_avail_frames(&source->stream, &sink->stream);
@@ -165,6 +166,7 @@ struct comp_dev *comp_make_shared(struct comp_dev *dev)
165166
struct list_item *old_bsink_list = &dev->bsink_list;
166167
struct list_item *buffer_list, *clist;
167168
struct comp_buffer *buffer;
169+
struct comp_buffer __sparse_cache *buffer_c;
168170
int dir;
169171

170172
/* flush cache to share */
@@ -191,15 +193,17 @@ struct comp_dev *comp_make_shared(struct comp_dev *dev)
191193
list_for_item(clist, buffer_list) {
192194
buffer = buffer_from_list(clist, struct comp_buffer, dir);
193195

194-
buffer_set_comp(buffer, dev, dir);
196+
buffer_c = buffer_acquire(buffer);
197+
buffer_set_comp(buffer_c, dev, dir);
198+
buffer_release(buffer_c);
195199
}
196200
}
197201

198202
return dev;
199203
}
200204

201-
int audio_stream_copy(const struct audio_stream *source, uint32_t ioffset,
202-
struct audio_stream *sink, uint32_t ooffset, uint32_t samples)
205+
int audio_stream_copy(const struct audio_stream __sparse_cache *source, uint32_t ioffset,
206+
struct audio_stream __sparse_cache *sink, uint32_t ooffset, uint32_t samples)
203207
{
204208
int ssize = audio_stream_sample_bytes(source); /* src fmt == sink fmt */
205209
uint8_t *src = audio_stream_wrap(source, (uint8_t *)source->r_ptr + ioffset * ssize);
@@ -223,8 +227,9 @@ int audio_stream_copy(const struct audio_stream *source, uint32_t ioffset,
223227
return samples;
224228
}
225229

226-
void audio_stream_copy_from_linear(void *linear_source, int ioffset,
227-
struct audio_stream *sink, int ooffset, unsigned int samples)
230+
void audio_stream_copy_from_linear(const void *linear_source, int ioffset,
231+
struct audio_stream __sparse_cache *sink, int ooffset,
232+
unsigned int samples)
228233
{
229234
int ssize = audio_stream_sample_bytes(sink); /* src fmt == sink fmt */
230235
uint8_t *src = (uint8_t *)linear_source + ioffset * ssize;
@@ -243,7 +248,7 @@ void audio_stream_copy_from_linear(void *linear_source, int ioffset,
243248
}
244249
}
245250

246-
void audio_stream_copy_to_linear(struct audio_stream *source, int ioffset,
251+
void audio_stream_copy_to_linear(const struct audio_stream __sparse_cache *source, int ioffset,
247252
void *linear_sink, int ooffset, unsigned int samples)
248253
{
249254
int ssize = audio_stream_sample_bytes(source); /* src fmt == sink fmt */

0 commit comments

Comments
 (0)