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
22 changes: 4 additions & 18 deletions posix/include/rtos/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,18 @@
#ifndef __SOF_ATOMIC_H__
#define __SOF_ATOMIC_H__

#include <arch/atomic.h>
#include <zephyr/sys/atomic.h>
#include <stdint.h>

/* SOF names for atomic_set() and atomic_get(), as in zephyr/include/rtos/atomic.h */
static inline void atomic_init(atomic_t *a, int32_t value)
{
arch_atomic_init(a, value);
atomic_set(a, value);
}

static inline int32_t atomic_read(const atomic_t *a)
{
return arch_atomic_read(a);
}

static inline void atomic_set(atomic_t *a, int32_t value)
{
arch_atomic_set(a, value);
}

static inline int32_t atomic_add(atomic_t *a, int32_t value)
{
return arch_atomic_add(a, value);
}

static inline int32_t atomic_sub(atomic_t *a, int32_t value)
{
return arch_atomic_sub(a, value);
return atomic_get(a);
}

#endif /* __SOF_ATOMIC_H__ */
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
12 changes: 12 additions & 0 deletions posix/include/rtos/panic.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,21 @@ void __panic(uint32_t p, const char *filename, uint32_t linenum) SOF_NORETURN;

#define sof_panic(x) __panic((x), (RELATIVE_FILE), (__LINE__))

/*
* Zephyr k_panic() takes no panic code. Report SOF_IPC_PANIC_ASSERT, the code
* of a failed assert(): Zephyr also ends a failed assertion with k_panic().
*/
#define k_panic() sof_panic(SOF_IPC_PANIC_ASSERT)

/* runtime assertion */
#ifndef assert
#define assert(cond) (void)((cond) || (sof_panic(SOF_IPC_PANIC_ASSERT), 0))
#endif

/*
* The Zephyr assert macros. On Zephyr, rtos/panic.h provides them through
* <zephyr/kernel.h>.
*/
#include <zephyr/sys/__assert.h>

#endif /* __POSIX_RTOS_PANIC_H__ */
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__ */
47 changes: 47 additions & 0 deletions posix/include/zephyr/cache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright(c) 2026 Intel Corporation. All rights reserved.
*
* Stub for <zephyr/cache.h> used by the non-Zephyr host builds (the host
* library and the testbench), which compile the shared code against
* posix/include. Zephyr builds, native_sim included, use the Zephyr header.
*
* The host has no cache to maintain, so these return -ENOTSUP, like Zephyr
* built without CONFIG_CACHE_MANAGEMENT.
*/

#ifndef __POSIX_ZEPHYR_CACHE_H__
#define __POSIX_ZEPHYR_CACHE_H__

#include <errno.h>
#include <stddef.h>

static inline int sys_cache_data_flush_range(void *addr, size_t size)
{
(void)addr;
(void)size;
return -ENOTSUP;
}

static inline int sys_cache_data_invd_range(void *addr, size_t size)
{
(void)addr;
(void)size;
return -ENOTSUP;
}

static inline int sys_cache_data_flush_and_invd_range(void *addr, size_t size)
{
(void)addr;
(void)size;
return -ENOTSUP;
}

static inline int sys_cache_instr_invd_range(void *addr, size_t size)
{
(void)addr;
(void)size;
return -ENOTSUP;
}

#endif /* __POSIX_ZEPHYR_CACHE_H__ */
54 changes: 54 additions & 0 deletions posix/include/zephyr/sys/__assert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright(c) 2026 Intel Corporation. All rights reserved.
*
* Stub for <zephyr/sys/__assert.h> used by the non-Zephyr host builds (the host
* library and the testbench), which compile the shared code against
* posix/include. Zephyr builds, native_sim included, use the Zephyr header.
*
* The host checks its assertions in every build, as assert() does: a failed
* assertion prints the condition and any message, then panics with
* SOF_IPC_PANIC_ASSERT.
*/

#ifndef __POSIX_ZEPHYR_SYS___ASSERT_H__
#define __POSIX_ZEPHYR_SYS___ASSERT_H__

#include <rtos/panic.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>

/*
* Print a failed assertion. The variable arguments are the optional message
* format and its arguments, then NULL: NULL alone means there is no message.
*/
static inline void posix_assert_print(const char *test, const char *file, int line, ...)
{
const char *fmt;
va_list ap;

fprintf(stderr, "ASSERTION FAIL [%s] @ %s:%d\n", test, file, line);
va_start(ap, line);
fmt = va_arg(ap, const char *);
if (fmt) {
fprintf(stderr, "\t");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
va_end(ap);
}

/* as in Zephyr, the message format and its arguments are optional */
#define __ASSERT(test, ...) \
do { \
if (!(test)) { \
posix_assert_print(#test, RELATIVE_FILE, __LINE__, \
##__VA_ARGS__, NULL); \
sof_panic(SOF_IPC_PANIC_ASSERT); \
} \
} while (0)

#define __ASSERT_NO_MSG(test) __ASSERT(test)

#endif /* __POSIX_ZEPHYR_SYS___ASSERT_H__ */
41 changes: 41 additions & 0 deletions posix/include/zephyr/sys/atomic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright(c) 2026 Intel Corporation. All rights reserved.
*
* Stub for <zephyr/sys/atomic.h> used by the non-Zephyr host builds (the host
* library and the testbench), which compile the shared code against
* posix/include. Zephyr builds, native_sim included, use the Zephyr header.
*
* The functions have the Zephyr names and return values: atomic_set(),
* atomic_add() and atomic_sub() return the previous value.
*/

#ifndef __POSIX_ZEPHYR_SYS_ATOMIC_H__
#define __POSIX_ZEPHYR_SYS_ATOMIC_H__

#include <arch/atomic.h>
#include <stdint.h>

typedef int32_t atomic_val_t;

static inline atomic_val_t atomic_get(const atomic_t *target)
{
return arch_atomic_read(target);
}

static inline atomic_val_t atomic_set(atomic_t *target, atomic_val_t value)
{
return arch_atomic_swap(target, value);
}

static inline atomic_val_t atomic_add(atomic_t *target, atomic_val_t value)
{
return arch_atomic_add(target, value);
}

static inline atomic_val_t atomic_sub(atomic_t *target, atomic_val_t value)
{
return arch_atomic_sub(target, value);
}

#endif /* __POSIX_ZEPHYR_SYS_ATOMIC_H__ */
4 changes: 2 additions & 2 deletions src/audio/asrc/asrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static void src_copy_s16(struct processing_module *mod,
n_copy = (n < n_wrap_src) ? n : n_wrap_src;
s_copy = n_copy * sizeof(int16_t);
ret = memcpy_s(buf, s_copy, src, s_copy);
assert(!ret);
__ASSERT_NO_MSG(!ret);

/* Update and check both source and destination for wrap */
n -= n_copy;
Expand Down Expand Up @@ -172,7 +172,7 @@ static void src_copy_s16(struct processing_module *mod,
n_copy = (n < n_wrap_snk) ? n : n_wrap_snk;
s_copy = n_copy * sizeof(int16_t);
ret = memcpy_s(snk, s_copy, buf, s_copy);
assert(!ret);
__ASSERT_NO_MSG(!ret);

/* Update and check both source and destination for wrap */
n -= n_copy;
Expand Down
2 changes: 1 addition & 1 deletion src/audio/buffers/audio_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void audio_buffer_init(struct sof_audio_buffer *buffer, uint32_t buffer_type, bo
CORE_CHECK_STRUCT_INIT(buffer, is_shared);
buffer->buffer_type = buffer_type;
buffer->ops = audio_buffer_ops;
assert(audio_buffer_ops->free);
__ASSERT_NO_MSG(audio_buffer_ops->free);
buffer->audio_stream_params = audio_stream_params;
buffer->is_shared = is_shared;

Expand Down
18 changes: 9 additions & 9 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static void comp_buffer_free(struct sof_audio_buffer *audio_buffer)

struct mod_alloc_ctx *alloc = buffer->audio_buffer.alloc;

assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);
__ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

if (alloc)
sof_ctx_free(alloc, buffer->stream.addr);
Expand Down Expand Up @@ -292,7 +292,7 @@ struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint3
return NULL;
}

assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);
__ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

if (alloc)
stream_addr = sof_ctx_alloc(alloc, flags, size, align);
Expand Down Expand Up @@ -340,7 +340,7 @@ struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t prefe
if (preferred_size % minimum_size)
preferred_size += minimum_size - preferred_size % minimum_size;

assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);
__ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

for (size = preferred_size; size >= minimum_size; size -= minimum_size) {
if (alloc)
Expand Down 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 All @@ -403,7 +403,7 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen
if (size == audio_stream_get_size(&buffer->stream))
return 0;

assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);
__ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

if (alloc)
new_ptr = sof_ctx_alloc(alloc, buffer->flags, size, alignment);
Expand Down Expand Up @@ -458,7 +458,7 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
if (preferred_size == actual_size)
return 0;

assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);
__ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

for (new_size = preferred_size; new_size >= minimum_size;
new_size -= minimum_size) {
Expand Down Expand Up @@ -530,7 +530,7 @@ EXPORT_SYMBOL(buffer_set_params);
bool buffer_params_match(struct comp_buffer *buffer,
struct sof_ipc_stream_params *params, uint32_t flag)
{
assert(params);
__ASSERT_NO_MSG(params);
CORE_CHECK_STRUCT(&buffer->audio_buffer);

if ((flag & BUFF_PARAMS_FRAME_FMT) &&
Expand Down
Loading
Loading