Skip to content

Commit

Permalink
component.h - check
Browse files Browse the repository at this point in the history
this commit is not finished

Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
  • Loading branch information
tobonex authored and marcinszkudlinski committed Sep 1, 2023
1 parent a7acce3 commit 706150b
Show file tree
Hide file tree
Showing 17 changed files with 242 additions and 429 deletions.
25 changes: 7 additions & 18 deletions src/audio/audio_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ static int audio_stream_get_buffer(struct sof_sink *sink, size_t req_size,
static int audio_stream_commit_buffer(struct sof_sink *sink, size_t commit_size)
{
struct audio_stream *audio_stream = container_of(sink, struct audio_stream, sink_api);
struct comp_buffer __sparse_cache *buffer_c =
attr_container_of(audio_stream, struct comp_buffer __sparse_cache,
stream, __sparse_cache);
struct comp_buffer *buffer = container_of(audio_stream, struct comp_buffer, stream);

if (commit_size) {
buffer_stream_writeback(buffer_c, commit_size);
buffer_stream_writeback(buffer, commit_size);
audio_stream_produce(audio_stream, commit_size);
}

Expand All @@ -54,14 +52,12 @@ static int audio_stream_get_data(struct sof_source *source, size_t req_size,
void **data_ptr, void **buffer_start, size_t *buffer_size)
{
struct audio_stream *audio_stream = container_of(source, struct audio_stream, source_api);
struct comp_buffer __sparse_cache *buffer_c =
attr_container_of(audio_stream, struct comp_buffer __sparse_cache,
stream, __sparse_cache);
struct comp_buffer *buffer = container_of(audio_stream, struct comp_buffer, stream);

if (req_size > audio_stream_get_data_available(source))
return -ENODATA;

buffer_stream_invalidate(buffer_c, req_size);
buffer_stream_invalidate(buffer, req_size);

/* get circular buffer parameters */
*data_ptr = audio_stream->r_ptr;
Expand All @@ -85,9 +81,7 @@ static int audio_stream_set_ipc_params_source(struct sof_source *source,
bool force_update)
{
struct audio_stream *audio_stream = container_of(source, struct audio_stream, source_api);
struct comp_buffer __sparse_cache *buffer =
attr_container_of(audio_stream, struct comp_buffer __sparse_cache,
stream, __sparse_cache);
struct comp_buffer *buffer = container_of(audio_stream, struct comp_buffer, stream);

return buffer_set_params(buffer, params, force_update);
}
Expand All @@ -97,9 +91,7 @@ static int audio_stream_set_ipc_params_sink(struct sof_sink *sink,
bool force_update)
{
struct audio_stream *audio_stream = container_of(sink, struct audio_stream, sink_api);
struct comp_buffer __sparse_cache *buffer =
attr_container_of(audio_stream, struct comp_buffer __sparse_cache,
stream, __sparse_cache);
struct comp_buffer *buffer = container_of(audio_stream, struct comp_buffer, stream);

return buffer_set_params(buffer, params, force_update);
}
Expand Down Expand Up @@ -142,8 +134,7 @@ static const struct sink_ops audio_stream_sink_ops = {
.set_alignment_constants = audio_stream_sink_set_alignment_constants
};

void audio_stream_init(struct audio_stream __sparse_cache *audio_stream,
void *buff_addr, uint32_t size)
void audio_stream_init(struct audio_stream *audio_stream, void *buff_addr, uint32_t size)
{
audio_stream->size = size;
audio_stream->addr = buff_addr;
Expand All @@ -156,10 +147,8 @@ void audio_stream_init(struct audio_stream __sparse_cache *audio_stream,
audio_stream_init_alignment_constants(1, 1, audio_stream);

source_init(audio_stream_get_source(audio_stream), &audio_stream_source_ops,
(__sparse_force struct sof_audio_stream_params *)
&audio_stream->runtime_stream_params);
sink_init(audio_stream_get_sink(audio_stream), &audio_stream_sink_ops,
(__sparse_force struct sof_audio_stream_params *)
&audio_stream->runtime_stream_params);
audio_stream_reset(audio_stream);
}
41 changes: 12 additions & 29 deletions src/audio/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t flags, u
bool is_shared)
{
struct comp_buffer *buffer;
struct comp_buffer __sparse_cache *buffer_c;
void *stream_addr;

tr_dbg(&buffer_tr, "buffer_alloc()");
Expand Down Expand Up @@ -62,22 +61,19 @@ struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t flags, u
}

/* From here no more uncached access to the buffer object, except its list headers */
buffer_c = buffer_acquire(buffer);
audio_stream_set_addr(&buffer_c->stream, stream_addr);
buffer_init(buffer_c, size, caps);
audio_stream_set_addr(&buffer->stream, stream_addr);
buffer_init(buffer, size, caps);

audio_stream_set_underrun(&buffer_c->stream, !!(flags & SOF_BUF_UNDERRUN_PERMITTED));
audio_stream_set_overrun(&buffer_c->stream, !!(flags & SOF_BUF_OVERRUN_PERMITTED));

buffer_release(buffer_c);
audio_stream_set_underrun(&buffer->stream, !!(flags & SOF_BUF_UNDERRUN_PERMITTED));
audio_stream_set_overrun(&buffer->stream, !!(flags & SOF_BUF_OVERRUN_PERMITTED));

list_init(&buffer->source_list);
list_init(&buffer->sink_list);

return buffer;
}

void buffer_zero(struct comp_buffer __sparse_cache *buffer)
void buffer_zero(struct comp_buffer *buffer)
{
buf_dbg(buffer, "stream_zero()");

Expand All @@ -88,7 +84,7 @@ void buffer_zero(struct comp_buffer __sparse_cache *buffer)
audio_stream_get_size(&buffer->stream));
}

int buffer_set_size(struct comp_buffer __sparse_cache *buffer, uint32_t size, uint32_t alignment)
int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignment)
{
void *new_ptr = NULL;

Expand Down Expand Up @@ -124,7 +120,7 @@ int buffer_set_size(struct comp_buffer __sparse_cache *buffer, uint32_t size, ui
return 0;
}

int buffer_set_params(struct comp_buffer __sparse_cache *buffer,
int buffer_set_params(struct comp_buffer *buffer,
struct sof_ipc_stream_params *params, bool force_update)
{
int ret;
Expand Down Expand Up @@ -153,7 +149,7 @@ int buffer_set_params(struct comp_buffer __sparse_cache *buffer,
return 0;
}

bool buffer_params_match(struct comp_buffer __sparse_cache *buffer,
bool buffer_params_match(struct comp_buffer *buffer,
struct sof_ipc_stream_params *params, uint32_t flag)
{
assert(params);
Expand Down Expand Up @@ -195,19 +191,7 @@ void buffer_free(struct comp_buffer *buffer)
coherent_free_thread(buffer, c);
}

/*
* comp_update_buffer_produce() and comp_update_buffer_consume() send
* NOTIFIER_ID_BUFFER_PRODUCE and NOTIFIER_ID_BUFFER_CONSUME notifier events
* respectively. The only recipient of those notifications is probes. The
* target for those notifications is always the current core, therefore notifier
* callbacks will be called synchronously from notifier_event() calls. Therefore
* we cannot pass unlocked buffer pointers to probes, because if they try to
* acquire the buffer, that can cause a deadlock. In general locked objects
* shouldn't be passed to potentially asynchronous contexts, but here we have no
* choice but to use our knowledge of the local notifier behaviour and pass
* locked buffers to notification recipients.
*/
void comp_update_buffer_produce(struct comp_buffer __sparse_cache *buffer, uint32_t bytes)
void comp_update_buffer_produce(struct comp_buffer *buffer, uint32_t bytes)
{
struct buffer_cb_transact cb_data = {
.buffer = buffer,
Expand All @@ -229,8 +213,7 @@ void comp_update_buffer_produce(struct comp_buffer __sparse_cache *buffer, uint3

audio_stream_produce(&buffer->stream, bytes);

/* Notifier looks for the pointer value to match it against registration */
notifier_event(cache_to_uncache(buffer), NOTIFIER_ID_BUFFER_PRODUCE,
notifier_event(buffer, NOTIFIER_ID_BUFFER_PRODUCE,
NOTIFIER_TARGET_CORE_LOCAL, &cb_data, sizeof(cb_data));

#if CONFIG_SOF_LOG_DBG_BUFFER
Expand All @@ -246,7 +229,7 @@ void comp_update_buffer_produce(struct comp_buffer __sparse_cache *buffer, uint3
#endif
}

void comp_update_buffer_consume(struct comp_buffer __sparse_cache *buffer, uint32_t bytes)
void comp_update_buffer_consume(struct comp_buffer *buffer, uint32_t bytes)
{
struct buffer_cb_transact cb_data = {
.buffer = buffer,
Expand All @@ -268,7 +251,7 @@ void comp_update_buffer_consume(struct comp_buffer __sparse_cache *buffer, uint3

audio_stream_consume(&buffer->stream, bytes);

notifier_event(cache_to_uncache(buffer), NOTIFIER_ID_BUFFER_CONSUME,
notifier_event(buffer, NOTIFIER_ID_BUFFER_CONSUME,
NOTIFIER_TARGET_CORE_LOCAL, &cb_data, sizeof(cb_data));

#if CONFIG_SOF_LOG_DBG_BUFFER
Expand Down
14 changes: 4 additions & 10 deletions src/audio/chain_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,9 @@ static enum task_state chain_task_run(void *data)
* mode task will update read position based on transferred data size to avoid
* overwriting valid data and write position by half buffer size.
*/
struct comp_buffer __sparse_cache *buffer_c = buffer_acquire(cd->dma_buffer);
const size_t buff_size = audio_stream_get_size(&buffer_c->stream);
const size_t buff_size = audio_stream_get_size(&cd->dma_buffer->stream);
const size_t half_buff_size = buff_size / 2;

buffer_release(buffer_c);

if (!cd->first_data_received && host_avail_bytes > half_buff_size) {
ret = dma_reload(cd->chan_link->dma->z_dev,
cd->chan_link->index, 0, 0,
Expand Down Expand Up @@ -510,7 +507,6 @@ static int chain_task_init(struct comp_dev *dev, uint8_t host_dma_id, uint8_t li
uint32_t fifo_size)
{
struct chain_dma_data *cd = comp_get_drvdata(dev);
struct comp_buffer __sparse_cache *buffer_c;
uint32_t addr_align;
size_t buff_size;
void *buff_addr;
Expand Down Expand Up @@ -598,11 +594,9 @@ static int chain_task_init(struct comp_dev *dev, uint8_t host_dma_id, uint8_t li
}

/* clear dma buffer */
buffer_c = buffer_acquire(cd->dma_buffer);
buffer_zero(buffer_c);
buff_addr = audio_stream_get_addr(&buffer_c->stream);
buff_size = audio_stream_get_size(&buffer_c->stream);
buffer_release(buffer_c);
buffer_zero(cd->dma_buffer);
buff_addr = audio_stream_get_addr(&cd->dma_buffer->stream);
buff_size = audio_stream_get_size(&cd->dma_buffer->stream);

ret = chain_init(dev, buff_addr, buff_size);
if (ret < 0) {
Expand Down
20 changes: 10 additions & 10 deletions src/audio/component.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ void sys_comp_init(struct sof *sof)
k_spinlock_init(&sof->comp_drivers->lock);
}

void comp_get_copy_limits(struct comp_buffer __sparse_cache *source,
struct comp_buffer __sparse_cache *sink,
void comp_get_copy_limits(struct comp_buffer *source,
struct comp_buffer *sink,
struct comp_copy_limits *cl)
{
cl->frames = audio_stream_avail_frames(&source->stream, &sink->stream);
Expand All @@ -169,8 +169,8 @@ void comp_get_copy_limits(struct comp_buffer __sparse_cache *source,
cl->sink_bytes = cl->frames * cl->sink_frame_bytes;
}

void comp_get_copy_limits_frame_aligned(const struct comp_buffer __sparse_cache *source,
const struct comp_buffer __sparse_cache *sink,
void comp_get_copy_limits_frame_aligned(const struct comp_buffer *source,
const struct comp_buffer *sink,
struct comp_copy_limits *cl)
{
cl->frames = audio_stream_avail_frames_aligned(&source->stream, &sink->stream);
Expand All @@ -182,8 +182,8 @@ void comp_get_copy_limits_frame_aligned(const struct comp_buffer __sparse_cache

#ifdef STREAMCOPY_HIFI3

int audio_stream_copy(const struct audio_stream __sparse_cache *source, uint32_t ioffset,
struct audio_stream __sparse_cache *sink, uint32_t ooffset, uint32_t samples)
int audio_stream_copy(const struct audio_stream *source, uint32_t ioffset,
struct audio_stream *sink, uint32_t ooffset, uint32_t samples)
{
int ssize = audio_stream_sample_bytes(source); /* src fmt == sink fmt */
ae_int16x4 *src = (ae_int16x4 *)((int8_t *)audio_stream_get_rptr(source) + ioffset * ssize);
Expand Down Expand Up @@ -227,8 +227,8 @@ int audio_stream_copy(const struct audio_stream __sparse_cache *source, uint32_t

#else

int audio_stream_copy(const struct audio_stream __sparse_cache *source, uint32_t ioffset,
struct audio_stream __sparse_cache *sink, uint32_t ooffset, uint32_t samples)
int audio_stream_copy(const struct audio_stream *source, uint32_t ioffset,
struct audio_stream *sink, uint32_t ooffset, uint32_t samples)
{
int ssize = audio_stream_sample_bytes(source); /* src fmt == sink fmt */
uint8_t *src = audio_stream_wrap(source, (uint8_t *)audio_stream_get_rptr(source) +
Expand Down Expand Up @@ -279,7 +279,7 @@ void cir_buf_copy(void *src, void *src_addr, void *src_end, void *dst,
}

void audio_stream_copy_from_linear(const void *linear_source, int ioffset,
struct audio_stream __sparse_cache *sink, int ooffset,
struct audio_stream *sink, int ooffset,
unsigned int samples)
{
int ssize = audio_stream_sample_bytes(sink); /* src fmt == sink fmt */
Expand All @@ -300,7 +300,7 @@ void audio_stream_copy_from_linear(const void *linear_source, int ioffset,
}
}

void audio_stream_copy_to_linear(const struct audio_stream __sparse_cache *source, int ioffset,
void audio_stream_copy_to_linear(const struct audio_stream *source, int ioffset,
void *linear_sink, int ooffset, unsigned int samples)
{
int ssize = audio_stream_sample_bytes(source); /* src fmt == sink fmt */
Expand Down
Loading

0 comments on commit 706150b

Please sign in to comment.