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
39 changes: 0 additions & 39 deletions posix/include/rtos/atomic.h

This file was deleted.

6 changes: 6 additions & 0 deletions posix/include/rtos/panic.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ 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))
Expand Down
4 changes: 2 additions & 2 deletions posix/include/sof/lib/agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef __SOF_LIB_AGENT_H__
#define __SOF_LIB_AGENT_H__

#include <rtos/atomic.h>
#include <zephyr/sys/atomic.h>
#include <sof/lib/memory.h>
#include <sof/lib/perf_cnt.h>
#include <rtos/task.h>
Expand Down Expand Up @@ -48,7 +48,7 @@ static inline void sa_set_panic_on_delay(bool enabled)
atomic_sub(&sa->panic_cnt, 1);

/* enable panic only if no refs */
sa->panic_on_delay = !atomic_read(&sa->panic_cnt);
sa->panic_on_delay = !atomic_get(&sa->panic_cnt);

}

Expand Down
2 changes: 1 addition & 1 deletion posix/include/sof/lib/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define __SOF_LIB_DMA_H__

#include <platform/lib/dma.h>
#include <rtos/atomic.h>
#include <zephyr/sys/atomic.h>
#include <rtos/bit.h>
#include <rtos/alloc.h>
#include <sof/lib/io.h>
Expand Down
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/module_adapter/module/dolby/dax.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Author: Jun Lai <jun.lai@dolby.com>
//

#include <rtos/atomic.h>
#include <zephyr/sys/atomic.h>
#include <rtos/init.h>
#include <sof/audio/data_blob.h>
#include <sof/audio/module_adapter/module/generic.h>
Expand Down Expand Up @@ -82,7 +82,7 @@ static int32_t flag_process(struct dax_adapter_data *adapter_data,
}
#else
/* Non-Zephyr builds run single-threaded (no DP mode), there is no synchronous problem */
int32_t old_flags = atomic_read(&adapter_data->proc_flags);
int32_t old_flags = atomic_get(&adapter_data->proc_flags);

switch (opt_mode) {
case DAX_FLAG_READ:
Expand Down
2 changes: 1 addition & 1 deletion src/audio/module_adapter/module/dolby/dax.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef DAX_H
#define DAX_H

#include <rtos/atomic.h>
#include <zephyr/sys/atomic.h>
#include <rtos/spinlock.h>
#include <sof/audio/module_adapter/module/generic.h>
#include <dax_inf.h>
Expand Down
4 changes: 2 additions & 2 deletions src/include/sof/lib/agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef __SOF_LIB_AGENT_H__
#define __SOF_LIB_AGENT_H__

#include <rtos/atomic.h>
#include <zephyr/sys/atomic.h>
#include <sof/lib/memory.h>
#include <sof/lib/perf_cnt.h>
#include <rtos/task.h>
Expand Down Expand Up @@ -48,7 +48,7 @@ static inline void sa_set_panic_on_delay(bool enabled)
atomic_sub(&sa->panic_cnt, 1);

/* enable panic only if no refs */
sa->panic_on_delay = !atomic_read(&sa->panic_cnt);
sa->panic_on_delay = !atomic_get(&sa->panic_cnt);

}

Expand Down
6 changes: 3 additions & 3 deletions src/include/sof/schedule/ll_schedule_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#ifndef __SOF_SCHEDULE_LL_SCHEDULE_DOMAIN_H__
#define __SOF_SCHEDULE_LL_SCHEDULE_DOMAIN_H__

#include <rtos/atomic.h>
#include <zephyr/sys/atomic.h>
#include <rtos/panic.h>
#include <rtos/alloc.h>
#include <sof/lib/cpu.h>
Expand Down Expand Up @@ -354,8 +354,8 @@ static inline struct ll_schedule_domain *domain_init
#else
k_spinlock_init(&domain->lock);
#endif
atomic_init(&domain->total_num_tasks, 0);
atomic_init(&domain->enabled_cores, 0);
atomic_set(&domain->total_num_tasks, 0);
atomic_set(&domain->enabled_cores, 0);

return domain;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/ipc4/handler-user.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <ipc/trace.h>
#include <user/trace.h>

#include <rtos/atomic.h>
#include <zephyr/sys/atomic.h>
#include <rtos/kernel.h>
#include <sof/lib_manager.h>

Expand Down
33 changes: 15 additions & 18 deletions src/kernel/arch/host/include/arch/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
*/

#ifdef __SOF_ATOMIC_H__
#ifdef __POSIX_ZEPHYR_SYS_ATOMIC_H__

#ifndef __ARCH_ATOMIC_H__
#define __ARCH_ATOMIC_H__
Expand All @@ -24,24 +24,20 @@ static inline int32_t arch_atomic_read(const atomic_t *a)
return __atomic_load_n(&a->value, __ATOMIC_SEQ_CST);
}

static inline void arch_atomic_set(atomic_t *a, int32_t value)
/* The swap, add and sub functions return the previous value, like Zephyr */
static inline int32_t arch_atomic_swap(atomic_t *a, int32_t value)
{
__atomic_store_n(&a->value, value, __ATOMIC_SEQ_CST);
}

static inline void arch_atomic_init(atomic_t *a, int32_t value)
{
__atomic_store_n(&a->value, value, __ATOMIC_SEQ_CST);
return __atomic_exchange_n(&a->value, value, __ATOMIC_SEQ_CST);
}

static inline int32_t arch_atomic_add(atomic_t *a, int32_t value)
{
return __atomic_add_fetch(&a->value, value, __ATOMIC_SEQ_CST);
return __atomic_fetch_add(&a->value, value, __ATOMIC_SEQ_CST);
}

static inline int32_t arch_atomic_sub(atomic_t *a, int32_t value)
{
return __atomic_sub_fetch(&a->value, value, __ATOMIC_SEQ_CST);
return __atomic_fetch_sub(&a->value, value, __ATOMIC_SEQ_CST);
}

#elif defined __XCC__
Expand All @@ -57,14 +53,15 @@ static inline int32_t arch_atomic_read(const atomic_t *a)
return a->value;
}

static inline void arch_atomic_set(atomic_t *a, int32_t value)
static inline int32_t arch_atomic_swap(atomic_t *a, int32_t value)
{
a->value = value;
}
int32_t tmp;

static inline void arch_atomic_init(atomic_t *a, int32_t value)
{
arch_atomic_set(a, value);
lock();
tmp = a->value;
a->value = value;
unlock();
return tmp;
}

static inline int32_t arch_atomic_add(atomic_t *a, int32_t value)
Expand Down Expand Up @@ -99,6 +96,6 @@ static inline int32_t arch_atomic_sub(atomic_t *a, int32_t value)

#else

#error "This file shouldn't be included from outside of sof/atomic.h"
#error "This file shouldn't be included from outside of zephyr/sys/atomic.h"

#endif /* __SOF_ATOMIC_H__ */
#endif /* __POSIX_ZEPHYR_SYS_ATOMIC_H__ */
4 changes: 2 additions & 2 deletions src/kernel/drivers/amd/common/acp_dmic_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//Author: Basavaraj Hiregoudar <basavaraj.hiregoudar@amd.com>
// SaiSurya, Ch <saisurya.chakkaveeravenkatanaga@amd.com>

#include <rtos/atomic.h>
#include <zephyr/sys/atomic.h>
#include <sof/audio/component.h>
#include <rtos/bit.h>
#include <sof/kernel/drivers/acp_dai_dma.h>
Expand Down Expand Up @@ -165,7 +165,7 @@ static int acp_dmic_dma_probe(struct dma *dma)
dma->chan[channel].index = channel;
dma->chan[channel].status = COMP_STATE_INIT;
}
atomic_init(&dma->num_channels_busy, 0);
atomic_set(&dma->num_channels_busy, 0);
return 0;
}

Expand Down
Loading
Loading