-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preparation for introducing the SOF ALSA plugin #8132
Changes from all commits
6206a16
b6a8a18
c9f06f7
82bf72f
8faa78c
23678fd
28c8db9
f0bb9f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target_include_directories(sof_public_headers INTERFACE include) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/* SPDX-License-Identifier: BSD-3-Clause | ||
* | ||
* Copyright(c) 2016 Intel Corporation. All rights reserved. | ||
* | ||
* Author: Liam Girdwood <[email protected]> | ||
* Keyon Jie <[email protected]> | ||
*/ | ||
|
||
/** | ||
* \file xtos/include/rtos/alloc.h | ||
* \brief Memory Allocation API definition | ||
* \author Liam Girdwood <[email protected]> | ||
* \author Keyon Jie <[email protected]> | ||
*/ | ||
|
||
#ifndef __SOF_LIB_ALLOC_H__ | ||
#define __SOF_LIB_ALLOC_H__ | ||
|
||
#include <rtos/bit.h> | ||
#include <rtos/string.h> | ||
#include <sof/trace/trace.h> | ||
#include <user/trace.h> | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
/** \addtogroup alloc_api Memory Allocation API | ||
* @{ | ||
*/ | ||
|
||
/** | ||
* \brief Heap Memory Zones | ||
* | ||
* The heap has three different zones from where memory can be allocated :- | ||
* | ||
* 1) System Zone. Fixed size heap where alloc always succeeds and is never | ||
* freed. Used by any init code that will never give up the memory. | ||
* | ||
* 2) System Runtime Zone. Heap zone intended for runtime objects allocated | ||
* by the kernel part of the code. | ||
* | ||
* 3) Runtime Zone. Main and larger heap zone where allocs are not guaranteed to | ||
* succeed. Memory can be freed here. | ||
* | ||
* 4) Buffer Zone. Largest heap zone intended for audio buffers. | ||
* | ||
* 5) Runtime Shared Zone. Similar to Runtime Zone, but content may be used and | ||
* fred from any enabled core. | ||
* | ||
* 6) System Shared Zone. Similar to System Zone, but content may be used from | ||
* any enabled core. | ||
* | ||
* See platform/memory.h for heap size configuration and mappings. | ||
*/ | ||
enum mem_zone { | ||
SOF_MEM_ZONE_SYS = 0, /**< System zone */ | ||
SOF_MEM_ZONE_SYS_RUNTIME, /**< System-runtime zone */ | ||
SOF_MEM_ZONE_RUNTIME, /**< Runtime zone */ | ||
SOF_MEM_ZONE_BUFFER, /**< Buffer zone */ | ||
SOF_MEM_ZONE_RUNTIME_SHARED, /**< Runtime shared zone */ | ||
SOF_MEM_ZONE_SYS_SHARED, /**< System shared zone */ | ||
}; | ||
|
||
/** \name Heap zone flags | ||
* @{ | ||
*/ | ||
|
||
/** \brief Indicates that original content should not be copied by realloc. */ | ||
#define SOF_MEM_FLAG_NO_COPY BIT(1) | ||
/** \brief Indicates that if we should return uncached address. */ | ||
#define SOF_MEM_FLAG_COHERENT BIT(2) | ||
|
||
/** @} */ | ||
|
||
/** | ||
* Allocates memory block. | ||
* @param zone Zone to allocate memory from, see enum mem_zone. | ||
* @param flags Flags, see SOF_MEM_FLAG_... | ||
* @param caps Capabilities, see SOF_MEM_CAPS_... | ||
* @param bytes Size in bytes. | ||
* @return Pointer to the allocated memory or NULL if failed. | ||
* | ||
* @note Do not use for buffers (SOF_MEM_ZONE_BUFFER zone). | ||
* Use rballoc(), rballoc_align() to allocate memory for buffers. | ||
*/ | ||
void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes); | ||
|
||
/** | ||
* Similar to rmalloc(), guarantees that returned block is zeroed. | ||
* | ||
* @note Do not use for buffers (SOF_MEM_ZONE_BUFFER zone). | ||
* rballoc(), rballoc_align() to allocate memory for buffers. | ||
*/ | ||
void *rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes); | ||
|
||
/** | ||
* Allocates memory block from SOF_MEM_ZONE_BUFFER. | ||
* @param flags Flags, see SOF_MEM_FLAG_... | ||
* @param caps Capabilities, see SOF_MEM_CAPS_... | ||
* @param bytes Size in bytes. | ||
* @param alignment Alignment in bytes. | ||
* @return Pointer to the allocated memory or NULL if failed. | ||
*/ | ||
void *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes, | ||
uint32_t alignment); | ||
|
||
/** | ||
* Similar to rballoc_align(), returns buffer aligned to PLATFORM_DCACHE_ALIGN. | ||
*/ | ||
static inline void *rballoc(uint32_t flags, uint32_t caps, size_t bytes) | ||
{ | ||
return rballoc_align(flags, caps, bytes, PLATFORM_DCACHE_ALIGN); | ||
} | ||
|
||
/** | ||
* Changes size of the memory block allocated from SOF_MEM_ZONE_BUFFER. | ||
* @param ptr Address of the block to resize. | ||
* @param flags Flags, see SOF_MEM_FLAG_... | ||
* @param caps Capabilities, see SOF_MEM_CAPS_... | ||
* @param bytes New size in bytes. | ||
* @param old_bytes Old size in bytes. | ||
* @param alignment Alignment in bytes. | ||
* @return Pointer to the resized memory of NULL if failed. | ||
*/ | ||
void *rbrealloc_align(void *ptr, uint32_t flags, uint32_t caps, size_t bytes, | ||
size_t old_bytes, uint32_t alignment); | ||
|
||
/** | ||
* Similar to rballoc_align(), returns resized buffer aligned to | ||
* PLATFORM_DCACHE_ALIGN. | ||
*/ | ||
static inline void *rbrealloc(void *ptr, uint32_t flags, uint32_t caps, | ||
size_t bytes, size_t old_bytes) | ||
{ | ||
return rbrealloc_align(ptr, flags, caps, bytes, old_bytes, | ||
PLATFORM_DCACHE_ALIGN); | ||
} | ||
|
||
/** | ||
* Frees the memory block. | ||
* @param ptr Pointer to the memory block. | ||
* | ||
* @note Blocks from SOF_MEM_ZONE_SYS cannot be freed, such a call causes | ||
* panic. | ||
*/ | ||
void rfree(void *ptr); | ||
|
||
/** | ||
* Allocates memory block from the system heap reserved for the specified core. | ||
* @param core Core id. | ||
* @param bytes Size in bytes. | ||
*/ | ||
void *rzalloc_core_sys(int core, size_t bytes); | ||
|
||
/** | ||
* Calculates length of the null-terminated string. | ||
* @param s String. | ||
* @return Length of the string in bytes. | ||
*/ | ||
int rstrlen(const char *s); | ||
|
||
/** | ||
* Compares two strings, see man strcmp. | ||
* @param s1 First string to compare. | ||
* @param s2 Second string to compare. | ||
* @return See man strcmp. | ||
*/ | ||
int rstrcmp(const char *s1, const char *s2); | ||
|
||
/** @}*/ | ||
|
||
#endif /* __SOF_LIB_ALLOC_H__ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* SPDX-License-Identifier: BSD-3-Clause | ||
* | ||
* Copyright(c) 2018 Intel Corporation. All rights reserved. | ||
* | ||
* Author: Liam Girdwood <[email protected]> | ||
*/ | ||
|
||
#ifndef __SOF_ATOMIC_H__ | ||
#define __SOF_ATOMIC_H__ | ||
|
||
#include <arch/atomic.h> | ||
#include <stdint.h> | ||
|
||
static inline void atomic_init(atomic_t *a, int32_t value) | ||
{ | ||
arch_atomic_init(a, value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this arch_foo() layer makes sense. If we pull the rtos layer out from XTOS (or Zephyr), then we don't need any dependency to a separate arch layer. I.e. this should use POSIX primitives (or Linux extensions) directly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kv2019i but the arch layer used here would use the gcc atomic builtins as defined in the host arch atomic.h. Isnt that good enough? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ranj063 This surely works and to be clear, I'm ok to merge this as an intermedia step, but I want to get aligned conceptually that there is no need to depend on the XTOS arch layer. |
||
} | ||
|
||
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); | ||
} | ||
|
||
#endif /* __SOF_ATOMIC_H__ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* SPDX-License-Identifier: BSD-3-Clause | ||
* | ||
* Copyright(c) 2018 Intel Corporation. All rights reserved. | ||
* | ||
* Author: Liam Girdwood <[email protected]> | ||
*/ | ||
|
||
#ifndef __XTOS_RTOS_BIT_H__ | ||
#define __XTOS_RTOS_BIT_H__ | ||
|
||
#if ASSEMBLY | ||
#define BIT(b) (1 << (b)) | ||
#else | ||
#define BIT(b) (1UL << (b)) | ||
#endif | ||
|
||
#define MASK(b_hi, b_lo) \ | ||
(((1ULL << ((b_hi) - (b_lo) + 1ULL)) - 1ULL) << (b_lo)) | ||
#define SET_BIT(b, x) (((x) & 1) << (b)) | ||
#define SET_BITS(b_hi, b_lo, x) \ | ||
(((x) & ((1ULL << ((b_hi) - (b_lo) + 1ULL)) - 1ULL)) << (b_lo)) | ||
#define GET_BIT(b, x) \ | ||
(((x) & (1ULL << (b))) >> (b)) | ||
#define GET_BITS(b_hi, b_lo, x) \ | ||
(((x) & MASK(b_hi, b_lo)) >> (b_lo)) | ||
|
||
#endif /* __XTOS_RTOS_BIT_H__ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* SPDX-License-Identifier: BSD-3-Clause | ||
* | ||
* Copyright(c) 2019 Intel Corporation. All rights reserved. | ||
* | ||
* Author: Tomasz Lauda <[email protected]> | ||
*/ | ||
|
||
/** | ||
* \file xtos/include/rtos/cache.h | ||
* \brief Cache header file | ||
* \authors Tomasz Lauda <[email protected]> | ||
*/ | ||
|
||
#ifndef __SOF_LIB_CACHE_H__ | ||
#define __SOF_LIB_CACHE_H__ | ||
|
||
#include <arch/lib/cache.h> | ||
|
||
/* writeback and invalidate data */ | ||
#define CACHE_WRITEBACK_INV 0 | ||
|
||
/* invalidate data */ | ||
#define CACHE_INVALIDATE 1 | ||
|
||
#endif /* __SOF_LIB_CACHE_H__ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* SPDX-License-Identifier: BSD-3-Clause | ||
* | ||
* Copyright(c) 2016 Intel Corporation. All rights reserved. | ||
* | ||
* Author: Liam Girdwood <[email protected]> | ||
* Janusz Jankowski <[email protected]> | ||
*/ | ||
|
||
#ifndef __SOF_LIB_CLK_H__ | ||
#define __SOF_LIB_CLK_H__ | ||
|
||
#include <platform/lib/clk.h> | ||
#include <rtos/sof.h> | ||
#include <rtos/spinlock.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
|
||
struct timer; | ||
|
||
#define CLOCK_NOTIFY_PRE 0 | ||
#define CLOCK_NOTIFY_POST 1 | ||
|
||
struct clock_notify_data { | ||
uint32_t old_freq; | ||
uint32_t old_ticks_per_msec; | ||
uint32_t freq; | ||
uint32_t ticks_per_msec; | ||
uint32_t message; | ||
}; | ||
|
||
struct freq_table { | ||
uint32_t freq; | ||
uint32_t ticks_per_msec; | ||
}; | ||
|
||
struct clock_info { | ||
uint32_t freqs_num; | ||
const struct freq_table *freqs; | ||
uint32_t default_freq_idx; | ||
uint32_t current_freq_idx; | ||
uint32_t lowest_freq_idx; /* lowest possible clock */ | ||
uint32_t notification_id; | ||
uint32_t notification_mask; | ||
|
||
/* persistent change clock value in active state, caller must hold clk_lock */ | ||
int (*set_freq)(int clock, int freq_idx); | ||
|
||
/* temporary change clock - don't modify default clock settings */ | ||
void (*low_power_mode)(int clock, bool enable); | ||
}; | ||
|
||
uint32_t clock_get_freq(int clock); | ||
|
||
void clock_set_freq(int clock, uint32_t hz); | ||
|
||
void clock_low_power_mode(int clock, bool enable); | ||
|
||
uint64_t clock_ms_to_ticks(int clock, uint64_t ms); | ||
|
||
uint64_t clock_us_to_ticks(int clock, uint64_t us); | ||
|
||
uint64_t clock_ns_to_ticks(int clock, uint64_t ns); | ||
|
||
uint64_t clock_ticks_per_sample(int clock, uint32_t sample_rate); | ||
|
||
extern struct k_spinlock clk_lock; | ||
|
||
static inline k_spinlock_key_t clock_lock(void) | ||
{ | ||
return k_spin_lock(&clk_lock); | ||
} | ||
|
||
static inline void clock_unlock(k_spinlock_key_t key) | ||
{ | ||
k_spin_unlock(&clk_lock, key); | ||
} | ||
|
||
static inline struct clock_info *clocks_get(void) | ||
{ | ||
return sof_get()->clocks; | ||
} | ||
|
||
#endif /* __SOF_LIB_CLK_H__ */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not able to include those headers? duplicate is not a good option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@btian1 this is for host build for testbench/tplg parser/plugin etc where zephyr/xtos doesnt feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so you mean plugin build does not have xtos/zephyr included?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we do already use SOF headers for library (testbench, cmocka) builds, cannot we also use them for this? Really should avoid duplicating - a sure path to breakage and confusion...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But which set? I think this approach has merits as well. I think we have three options:
I think (3) involves code duplication, but for a pure library build (that can be linked to any Linux application), I think this approach is cleanest. Especially if we longterm remove the the XTOS build. Using Zephyr posix build is one option, but I don't think that is really ideal for the library use (like an ALSA plugin, or exposing audio modules via some other framerwork like LV2).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the correct direction - its not perfect today but we still need to abstract some RTOS calls today for host usage (and this is this abstraction). Cmocka should also use this abstraction.
Long term our abstractions should continue and shrink so that we have a minimal abstraction surface on top of POSIX (if any).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move list.h and other generic (non RTOS api) level headers to a sof/lib (but this could be another patch).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these files are strictly identical then they should be copied at build time. See commit e0d8078 / #7244 for an example of a .h file copied at build time.
If this is a copy/paste/diverge then the copies should at least refer to each other to keep divergence damage somewhat under control.
Also, there's probably no need to duplicate all the doxygen, is it? Just point to the main copy instead. I don't think we publish ALL these doxygens do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lgirdwood Right, but we don't need XTOS arch code if plugin uses its own rtos implementation. sof/posix/rtos should be independent of sof/src/arch . cmocka uses it, but it was done before we had a rtos abstraction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not hugely important, but calling these "posix headers" is a bit confusing - don't think all these headers are POSIX