Skip to content

Commit 1a84178

Browse files
author
Jyri Sarha
committed
zephyr: lib: Remove ctx_alloc.h and put the contents into rtos/alloc.h
Remove the ctx_alloc.h header and move the implementation into rtos/alloc.h. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 1f4b8f0 commit 1a84178

7 files changed

Lines changed: 69 additions & 86 deletions

File tree

src/audio/buffers/comp_buffer.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <rtos/alloc.h>
1818
#include <rtos/cache.h>
1919
#include <sof/lib/vregion.h>
20-
#include <sof/ctx_alloc.h>
2120
#include <sof/list.h>
2221
#include <sof/schedule/dp_schedule.h>
2322
#include <rtos/spinlock.h>

src/audio/buffers/ring_buffer.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <sof/trace/trace.h>
88
#include <sof/lib/uuid.h>
99
#include <sof/lib/vregion.h>
10-
#include <sof/ctx_alloc.h>
1110

1211
#include <sof/audio/module_adapter/module/generic.h>
1312
#include <sof/audio/ring_buffer.h>

src/audio/module_adapter/module/generic.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <sof/audio/data_blob.h>
1919
#include <sof/lib/fast-get.h>
2020
#include <sof/lib/vregion.h>
21-
#include <sof/ctx_alloc.h>
2221
#include <sof/schedule/dp_schedule.h>
2322
#if CONFIG_IPC_MAJOR_4
2423
#include <ipc4/header.h>

src/include/sof/audio/component.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <rtos/idc.h>
2424
#include <rtos/mutex.h>
2525
#include <rtos/userspace_helper.h>
26-
#include <sof/ctx_alloc.h>
2726
#include <sof/lib/dai.h>
2827
#include <sof/schedule/schedule.h>
2928
#include <ipc/control.h>

src/include/sof/ctx_alloc.h

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/include/sof/lib/dai-zephyr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <rtos/spinlock.h>
2727
#include <sof/trace/trace.h>
2828
#include <sof/ipc/topology.h>
29-
#include <sof/ctx_alloc.h>
3029
#include <sof/audio/pcm_converter.h>
3130
#include <sof/audio/ipc-config.h>
3231
#include <sof/audio/component.h>

zephyr/include/rtos/alloc.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,73 @@ size_t get_shared_buffer_heap_size(void);
150150

151151
#endif
152152

153+
#include <sof/lib/vregion.h>
154+
#include <string.h>
155+
156+
struct mod_alloc_ctx {
157+
struct k_heap *heap;
158+
struct vregion *vreg;
159+
};
160+
161+
/**
162+
* Allocate memory from a mod_alloc_ctx context.
163+
*
164+
* When the context has a vregion, allocates from the vregion interim
165+
* partition. Coherent memory is used when SOF_MEM_FLAG_COHERENT is set
166+
* in flags. Falls back to sof_heap_alloc() otherwise.
167+
*
168+
* @param ctx Allocation context (heap + optional vregion).
169+
* @param flags Allocation flags (SOF_MEM_FLAG_*).
170+
* @param size Size in bytes.
171+
* @param alignment Required alignment in bytes.
172+
* @return Pointer to allocated memory or NULL on failure.
173+
*/
174+
static inline void *sof_ctx_alloc(struct mod_alloc_ctx *ctx, uint32_t flags,
175+
size_t size, size_t alignment)
176+
{
177+
if (!ctx || !ctx->vreg)
178+
return sof_heap_alloc(ctx ? ctx->heap : NULL, flags, size, alignment);
179+
180+
if (flags & SOF_MEM_FLAG_COHERENT)
181+
return vregion_alloc_coherent_align(ctx->vreg, VREGION_MEM_TYPE_INTERIM,
182+
size, alignment);
183+
184+
return vregion_alloc_align(ctx->vreg, VREGION_MEM_TYPE_INTERIM, size, alignment);
185+
}
186+
187+
/**
188+
* Allocate zero-initialized memory from a mod_alloc_ctx context.
189+
* @param ctx Allocation context.
190+
* @param flags Allocation flags (SOF_MEM_FLAG_*).
191+
* @param size Size in bytes.
192+
* @param alignment Required alignment in bytes.
193+
* @return Pointer to allocated memory or NULL on failure.
194+
*/
195+
static inline void *sof_ctx_zalloc(struct mod_alloc_ctx *ctx, uint32_t flags,
196+
size_t size, size_t alignment)
197+
{
198+
void *ptr = sof_ctx_alloc(ctx, flags, size, alignment);
199+
200+
if (ptr)
201+
memset(ptr, 0, size);
202+
203+
return ptr;
204+
}
205+
206+
/**
207+
* Free memory allocated from a mod_alloc_ctx context.
208+
* @param ctx Allocation context.
209+
* @param ptr Pointer to free.
210+
*/
211+
static inline void sof_ctx_free(struct mod_alloc_ctx *ctx, void *ptr)
212+
{
213+
if (!ptr)
214+
return;
215+
216+
if (ctx && ctx->vreg)
217+
vregion_free(ctx->vreg, ptr);
218+
else
219+
sof_heap_free(ctx ? ctx->heap : NULL, ptr);
220+
}
221+
153222
#endif /* __ZEPHYR_RTOS_ALLOC_H__ */

0 commit comments

Comments
 (0)