Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions posix/include/rtos/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define __SOF_LIB_CACHE_H__

#include <arch/lib/cache.h>
#include <zephyr/cache.h>

/* writeback and invalidate data */
#define CACHE_WRITEBACK_INV 0
Expand Down
20 changes: 10 additions & 10 deletions posix/include/sof/lib/mailbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ void mailbox_dspbox_write(size_t offset, const void *src, size_t bytes)
MAILBOX_DSPBOX_SIZE - offset, src, bytes);

assert(!dsp_write_err);
dcache_writeback_region((__sparse_force void __sparse_cache *)(MAILBOX_DSPBOX_BASE +
offset), bytes);
sys_cache_data_flush_range((void *)(MAILBOX_DSPBOX_BASE +
offset), bytes);
}

static inline
Expand All @@ -60,8 +60,8 @@ void mailbox_dspbox_read(void *dest, size_t dest_size,
{
int dsp_read_err __unused;

dcache_invalidate_region((__sparse_force void __sparse_cache *)(MAILBOX_DSPBOX_BASE +
offset), bytes);
sys_cache_data_invd_range((void *)(MAILBOX_DSPBOX_BASE +
offset), bytes);
dsp_read_err = memcpy_s(dest, dest_size,
(void *)(MAILBOX_DSPBOX_BASE + offset), bytes);
assert(!dsp_read_err);
Expand All @@ -81,8 +81,8 @@ void mailbox_hostbox_write(size_t offset, const void *src, size_t bytes)
MAILBOX_HOSTBOX_SIZE - offset, src, bytes);

assert(!host_write_err);
dcache_writeback_region((__sparse_force void __sparse_cache *)(MAILBOX_HOSTBOX_BASE +
offset), bytes);
sys_cache_data_flush_range((void *)(MAILBOX_HOSTBOX_BASE +
offset), bytes);
}

#endif
Expand All @@ -93,8 +93,8 @@ void mailbox_hostbox_read(void *dest, size_t dest_size,
{
int host_read_err __unused;

dcache_invalidate_region((__sparse_force void __sparse_cache *)(MAILBOX_HOSTBOX_BASE +
offset), bytes);
sys_cache_data_invd_range((void *)(MAILBOX_HOSTBOX_BASE +
offset), bytes);
host_read_err = memcpy_s(dest, dest_size,
(void *)(MAILBOX_HOSTBOX_BASE + offset), bytes);
assert(!host_read_err);
Expand All @@ -107,8 +107,8 @@ void mailbox_stream_write(size_t offset, const void *src, size_t bytes)
MAILBOX_STREAM_SIZE - offset, src, bytes);

assert(!stream_write_err);
dcache_writeback_region((__sparse_force void __sparse_cache *)(MAILBOX_STREAM_BASE +
offset), bytes);
sys_cache_data_flush_range((void *)(MAILBOX_STREAM_BASE +
offset), bytes);
}

#endif /* __SOF_LIB_MAILBOX_H__ */
6 changes: 3 additions & 3 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ void buffer_zero(struct comp_buffer *buffer)

bzero(audio_stream_get_addr(&buffer->stream), audio_stream_get_size(&buffer->stream));
if (buffer->flags & SOF_MEM_FLAG_DMA)
dcache_writeback_region((__sparse_force void __sparse_cache *)
audio_stream_get_addr(&buffer->stream),
audio_stream_get_size(&buffer->stream));
sys_cache_data_flush_range((void *)
audio_stream_get_addr(&buffer->stream),
audio_stream_get_size(&buffer->stream));
}

int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignment)
Expand Down
20 changes: 11 additions & 9 deletions src/audio/buffers/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ static inline void ring_buffer_invalidate_shared(struct ring_buffer *ring_buffer

/* wrap-around? */
if ((uintptr_t)ptr + size > (uintptr_t)ring_buffer_buffer_end(ring_buffer)) {
/* writeback till the end of circular buffer */
dcache_invalidate_region
(ptr, (uintptr_t)ring_buffer_buffer_end(ring_buffer) - (uintptr_t)ptr);
size -= (uintptr_t)ring_buffer_buffer_end(ring_buffer) - (uintptr_t)ptr;
size_t head = (uintptr_t)ring_buffer_buffer_end(ring_buffer) - (uintptr_t)ptr;

/* invalidate till the end of circular buffer */
sys_cache_data_invd_range((__sparse_force void *)ptr, head);
size -= head;
ptr = ring_buffer->_data_buffer;
}
/* invalidate rest of data */
dcache_invalidate_region(ptr, size);
sys_cache_data_invd_range((__sparse_force void *)ptr, size);
}

static inline void ring_buffer_writeback_shared(struct ring_buffer *ring_buffer,
Expand All @@ -78,14 +79,15 @@ static inline void ring_buffer_writeback_shared(struct ring_buffer *ring_buffer,

/* wrap-around? */
if ((uintptr_t)ptr + size > (uintptr_t)ring_buffer_buffer_end(ring_buffer)) {
size_t head = (uintptr_t)ring_buffer_buffer_end(ring_buffer) - (uintptr_t)ptr;

/* writeback till the end of circular buffer */
dcache_writeback_region
(ptr, (uintptr_t)ring_buffer_buffer_end(ring_buffer) - (uintptr_t)ptr);
size -= (uintptr_t)ring_buffer_buffer_end(ring_buffer) - (uintptr_t)ptr;
sys_cache_data_flush_range((__sparse_force void *)ptr, head);
size -= head;
ptr = ring_buffer->_data_buffer;
}
/* writeback rest of data */
dcache_writeback_region(ptr, size);
sys_cache_data_flush_range((__sparse_force void *)ptr, size);
}


Expand Down
14 changes: 7 additions & 7 deletions src/audio/copier/copier_ipcgtw.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ __cold int copier_ipcgtw_process(const struct ipc4_ipcgtw_cmd *cmd,

assert_can_be_cold();

dcache_invalidate_region((__sparse_force void __sparse_cache *)MAILBOX_HOSTBOX_BASE,
sizeof(struct ipc4_ipc_gateway_cmd_data));
sys_cache_data_invd_range((void *)MAILBOX_HOSTBOX_BASE,
sizeof(struct ipc4_ipc_gateway_cmd_data));
in = (const struct ipc4_ipc_gateway_cmd_data *)MAILBOX_HOSTBOX_BASE;

dev = find_ipcgtw_by_node_id(in->node_id);
Expand Down Expand Up @@ -174,11 +174,11 @@ __cold int copier_ipcgtw_process(const struct ipc4_ipcgtw_cmd *cmd,
if (sink) {
data_size = MIN(cmd->extension.r.data_size, SOF_IPC_MSG_MAX_SIZE - 4);
data_size = MIN(data_size, sink_get_free_size(sink));
dcache_invalidate_region((__sparse_force void __sparse_cache *)
MAILBOX_HOSTBOX_BASE,
data_size +
offsetof(struct ipc4_ipc_gateway_cmd_data,
payload));
sys_cache_data_invd_range((void *)
MAILBOX_HOSTBOX_BASE,
data_size +
offsetof(struct ipc4_ipc_gateway_cmd_data,
payload));
ret = sink_copy_bytes_from_linear(in->payload, sink, data_size);
if (ret)
return ret;
Expand Down
2 changes: 1 addition & 1 deletion src/audio/module_adapter/module/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ static const void *mod_fast_get_copy(struct processing_module *mod,
return NULL;

memcpy_s(ptr, size, dram_ptr, size);
dcache_writeback_region((__sparse_force void __sparse_cache *)ptr, size);
sys_cache_data_flush_range((void *)ptr, size);

return ptr;
}
Expand Down
12 changes: 6 additions & 6 deletions src/include/sof/audio/audio_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,10 @@ static inline void audio_stream_invalidate(struct audio_stream *buffer, uint32_t
tail_size = bytes - head_size;
}

dcache_invalidate_region((__sparse_force void __sparse_cache *)buffer->r_ptr, head_size);
sys_cache_data_invd_range((void *)buffer->r_ptr, head_size);
if (tail_size)
dcache_invalidate_region((__sparse_force void __sparse_cache *)buffer->addr,
tail_size);
sys_cache_data_invd_range((void *)buffer->addr,
tail_size);
}

/**
Expand All @@ -759,10 +759,10 @@ static inline void audio_stream_writeback(struct audio_stream *buffer, uint32_t
tail_size = bytes - head_size;
}

dcache_writeback_region((__sparse_force void __sparse_cache *)buffer->w_ptr, head_size);
sys_cache_data_flush_range((void *)buffer->w_ptr, head_size);
if (tail_size)
dcache_writeback_region((__sparse_force void __sparse_cache *)buffer->addr,
tail_size);
sys_cache_data_flush_range((void *)buffer->addr,
tail_size);
}

/**
Expand Down
22 changes: 11 additions & 11 deletions src/include/sof/coherent.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ __must_check static inline struct coherent __sparse_cache *coherent_acquire(stru
c->key = k_spin_lock(&c->lock);

/*
* FIXME: This is wrong. dcache_invalidate_region() only makes
* FIXME: This is wrong. Invalidating the cache here only makes
* sense if we assume, that dirty cache lines might exist for
* this object. But in that case those lines could be written
* back here thus overwriting either user data, or the coherent
Expand All @@ -175,7 +175,7 @@ __must_check static inline struct coherent __sparse_cache *coherent_acquire(stru
*/

/* invalidate local copy */
dcache_invalidate_region(cc, size);
sys_cache_data_invd_range((__sparse_force void *)cc, size);
}

/* client can now use cached object safely */
Expand Down Expand Up @@ -204,7 +204,7 @@ static inline void coherent_release(struct coherent __sparse_cache *c,
CHECK_COHERENT_CORE(c);

/* wtb and inv local data to coherent object */
dcache_writeback_invalidate_region(c, size);
sys_cache_data_flush_and_invd_range((__sparse_force void *)c, size);

/* unlock on uncache alias */
k_spin_unlock(&uc->lock, uc->key);
Expand Down Expand Up @@ -243,7 +243,7 @@ static inline void *__coherent_init(size_t offset, const size_t size)
c->core = cpu_get_id();
list_init(&c->list);
/* inv local data to coherent object */
dcache_invalidate_region(uncache_to_cache(object), size);
sys_cache_data_invd_range((__sparse_force void *)uncache_to_cache(object), size);

return object;
}
Expand Down Expand Up @@ -276,7 +276,7 @@ static inline void __coherent_shared(struct coherent *c, const size_t size)

c->key = k_spin_lock(&c->lock);
c->shared = true;
dcache_invalidate_region(uncache_to_cache(c), size);
sys_cache_data_invd_range((__sparse_force void *)uncache_to_cache(c), size);
k_spin_unlock(&c->lock, c->key);
}

Expand Down Expand Up @@ -320,7 +320,7 @@ __must_check static inline struct coherent __sparse_cache *coherent_acquire_thre
k_mutex_lock(&c->mutex, K_FOREVER);

/* invalidate local copy */
dcache_invalidate_region(cc, size);
sys_cache_data_invd_range((__sparse_force void *)cc, size);
}

/* client can now use cached object safely */
Expand Down Expand Up @@ -350,7 +350,7 @@ static inline void coherent_release_thread(struct coherent __sparse_cache *c,
CHECK_COHERENT_CORE(c);

/* wtb and inv local data to coherent object */
dcache_writeback_invalidate_region(c, size);
sys_cache_data_flush_and_invd_range((__sparse_force void *)c, size);

/* unlock on uncache alias */
k_mutex_unlock(&uc->mutex);
Expand Down Expand Up @@ -386,7 +386,7 @@ static inline void *__coherent_init_thread(size_t offset, const size_t size)
c->core = cpu_get_id();
list_init(&c->list);
/* inv local data to coherent object */
dcache_invalidate_region(uncache_to_cache(object), size);
sys_cache_data_invd_range((__sparse_force void *)uncache_to_cache(object), size);

return object;
}
Expand Down Expand Up @@ -420,7 +420,7 @@ static inline void __coherent_shared_thread(struct coherent *c, const size_t siz

k_mutex_lock(&c->mutex, K_FOREVER);
c->shared = true;
dcache_invalidate_region(uncache_to_cache(c), size);
sys_cache_data_invd_range((__sparse_force void *)uncache_to_cache(c), size);
k_mutex_unlock(&c->mutex);
}

Expand Down Expand Up @@ -450,8 +450,8 @@ static inline void __coherent_shared_thread(struct coherent *c, const size_t siz
/* assert if someone passes a cache address in here. */ \
ADDR_IS_COHERENT(object); \
/* wtb and inv local data to coherent object */ \
dcache_writeback_invalidate_region(uncache_to_cache(object), \
sizeof(*object)); \
sys_cache_data_flush_and_invd_range( \
(__sparse_force void *)uncache_to_cache(object), sizeof(*object)); \
rfree(object); \
} while (0)

Expand Down
20 changes: 10 additions & 10 deletions src/include/sof/lib/mailbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ void mailbox_dspbox_write(size_t offset, const void *src, size_t bytes)
MAILBOX_DSPBOX_SIZE - offset, src, bytes);

assert(!dsp_write_err);
dcache_writeback_region((__sparse_force void __sparse_cache *)(MAILBOX_DSPBOX_BASE +
offset), bytes);
sys_cache_data_flush_range((void *)(MAILBOX_DSPBOX_BASE +
offset), bytes);
}

static inline
Expand All @@ -59,8 +59,8 @@ void mailbox_dspbox_read(void *dest, size_t dest_size,
{
int dsp_read_err __unused;

dcache_invalidate_region((__sparse_force void __sparse_cache *)(MAILBOX_DSPBOX_BASE +
offset), bytes);
sys_cache_data_invd_range((void *)(MAILBOX_DSPBOX_BASE +
offset), bytes);
dsp_read_err = memcpy_s(dest, dest_size,
(void *)(MAILBOX_DSPBOX_BASE + offset), bytes);
assert(!dsp_read_err);
Expand All @@ -80,8 +80,8 @@ void mailbox_hostbox_write(size_t offset, const void *src, size_t bytes)
MAILBOX_HOSTBOX_SIZE - offset, src, bytes);

assert(!host_write_err);
dcache_writeback_region((__sparse_force void __sparse_cache *)(MAILBOX_HOSTBOX_BASE +
offset), bytes);
sys_cache_data_flush_range((void *)(MAILBOX_HOSTBOX_BASE +
offset), bytes);
}

#endif
Expand All @@ -92,8 +92,8 @@ void mailbox_hostbox_read(void *dest, size_t dest_size,
{
int host_read_err __unused;

dcache_invalidate_region((__sparse_force void __sparse_cache *)(MAILBOX_HOSTBOX_BASE +
offset), bytes);
sys_cache_data_invd_range((void *)(MAILBOX_HOSTBOX_BASE +
offset), bytes);
host_read_err = memcpy_s(dest, dest_size,
(void *)(MAILBOX_HOSTBOX_BASE + offset), bytes);
assert(!host_read_err);
Expand All @@ -114,8 +114,8 @@ void mailbox_stream_write(size_t offset, const void *src, size_t bytes)
MAILBOX_STREAM_SIZE - offset, src, bytes);

assert(!stream_write_err);
dcache_writeback_region((__sparse_force void __sparse_cache *)(MAILBOX_STREAM_BASE +
offset), bytes);
sys_cache_data_flush_range((void *)(MAILBOX_STREAM_BASE +
offset), bytes);
}
#endif

Expand Down
20 changes: 10 additions & 10 deletions src/ipc/ipc4/handler-user.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ static inline const struct ipc4_pipeline_set_state_data *ipc4_get_pipeline_data(
const struct ipc4_pipeline_set_state_data *ppl_data;

ppl_data = (const struct ipc4_pipeline_set_state_data *)MAILBOX_HOSTBOX_BASE;
dcache_invalidate_region((__sparse_force void __sparse_cache *)ppl_data,
sizeof(*ppl_data));
sys_cache_data_invd_range((void *)ppl_data,
sizeof(*ppl_data));

return ppl_data;
}
Expand Down Expand Up @@ -424,8 +424,8 @@ int ipc4_pipeline_id_get(struct ipc4_message_request *ipc4,
cnt);
return -EINVAL;
}
dcache_invalidate_region((__sparse_force void __sparse_cache *)ppl_data->ppl_id,
sizeof(int) * cnt);
sys_cache_data_invd_range((void *)ppl_data->ppl_id,
sizeof(int) * cnt);
if (ppl_count)
*ppl_count = cnt;
if (ppl_id)
Expand Down Expand Up @@ -745,8 +745,8 @@ __cold void ipc4_prepare_for_kcontrol_get(struct comp_dev *dev, uint8_t param_id
case SOF_IPC4_ENUM_CONTROL_PARAM_ID:
case SOF_IPC4_BYTES_CONTROL_PARAM_ID:
/* We have payload in hostbox */
dcache_invalidate_region((__sparse_force void __sparse_cache *)MAILBOX_HOSTBOX_BASE,
data_size);
sys_cache_data_invd_range((void *)MAILBOX_HOSTBOX_BASE,
data_size);

/* Copy the control payload header from inbox to outbox */
memcpy_s(data_out, data_size, hostbox,
Expand Down Expand Up @@ -910,8 +910,8 @@ __cold static int ipc4_process_large_config_get(struct ipc4_message_request *ipc
/* check for vendor param first */
if (config->extension.r.large_param_id == VENDOR_CONFIG_PARAM) {
/* For now only vendor_config case uses payload from hostbox */
dcache_invalidate_region((__sparse_force void __sparse_cache *)MAILBOX_HOSTBOX_BASE,
config->extension.r.data_off_size);
sys_cache_data_invd_range((void *)MAILBOX_HOSTBOX_BASE,
config->extension.r.data_off_size);
ret = ipc4_get_vendor_config_module_instance(dev, drv,
config->extension.r.init_block,
config->extension.r.final_block,
Expand Down Expand Up @@ -1062,8 +1062,8 @@ __cold int ipc4_process_large_config_set(struct ipc4_message_request *ipc4)

assert_can_be_cold();

dcache_invalidate_region((__sparse_force void __sparse_cache *)MAILBOX_HOSTBOX_BASE,
config->extension.r.data_off_size);
sys_cache_data_invd_range((void *)MAILBOX_HOSTBOX_BASE,
config->extension.r.data_off_size);
tr_dbg(&ipc_tr, "%x : %x",
(uint32_t)config->primary.r.module_id, (uint32_t)config->primary.r.instance_id);

Expand Down
Loading
Loading