Skip to content
Open
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
50 changes: 50 additions & 0 deletions posix/include/rtos/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,56 @@ void sof_heap_free(struct k_heap *heap, void *addr);
struct k_heap *sof_sys_heap_get(void);
struct k_heap *sof_sys_user_heap_get(void);

/* Posix version of struct mod_alloc_ctx without vregion support */
struct vregion;

struct mod_alloc_ctx {
struct k_heap *heap;
struct vregion *vreg;
};

/**
* Allocate memory from a mod_alloc_ctx context.
* Dummy version, only heap allocation is supported
*/
static inline void *sof_ctx_alloc(struct mod_alloc_ctx *ctx, uint32_t flags,
size_t size, size_t alignment)
{
return sof_heap_alloc(ctx ? ctx->heap : NULL, flags, size, alignment);
}

/**
* Allocate zero-initialized memory from a mod_alloc_ctx context.
* @param ctx Allocation context.
* @param flags Allocation flags (SOF_MEM_FLAG_*).
* @param size Size in bytes.
* @param alignment Required alignment in bytes.
* @return Pointer to allocated memory or NULL on failure.
*/
static inline void *sof_ctx_zalloc(struct mod_alloc_ctx *ctx, uint32_t flags,
size_t size, size_t alignment)
{
void *ptr = sof_ctx_alloc(ctx, flags, size, alignment);

if (ptr)
memset(ptr, 0, size);

return ptr;
}

/**
* Free memory allocated from a mod_alloc_ctx context.
* @param ctx Allocation context.
* @param ptr Pointer to free.
*/
static inline void sof_ctx_free(struct mod_alloc_ctx *ctx, void *ptr)
{
if (!ptr)
return;

sof_heap_free(ctx ? ctx->heap : NULL, ptr);
}

/**
* Calculates length of the null-terminated string.
* @param s String.
Expand Down
1 change: 0 additions & 1 deletion src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <rtos/alloc.h>
#include <rtos/cache.h>
#include <sof/lib/vregion.h>
#include <sof/ctx_alloc.h>
#include <sof/list.h>
#include <sof/schedule/dp_schedule.h>
#include <rtos/spinlock.h>
Expand Down
1 change: 0 additions & 1 deletion src/audio/buffers/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <sof/trace/trace.h>
#include <sof/lib/uuid.h>
#include <sof/lib/vregion.h>
#include <sof/ctx_alloc.h>

#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/ring_buffer.h>
Expand Down
1 change: 0 additions & 1 deletion src/audio/module_adapter/module/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <sof/audio/data_blob.h>
#include <sof/lib/fast-get.h>
#include <sof/lib/vregion.h>
#include <sof/ctx_alloc.h>
#include <sof/schedule/dp_schedule.h>
#if CONFIG_IPC_MAJOR_4
#include <ipc4/header.h>
Expand Down
5 changes: 2 additions & 3 deletions src/audio/module_adapter/module_adapter_ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ int module_ext_init_decode(const struct comp_driver *drv, struct module_ext_init
}
ext_data->dp_data = dp_data;
comp_cl_info(drv,
"init_ext_obj_dp_data domain %u stack %u interim %u lifetime %u shared %u",
"init_ext_obj_dp_data domain %u stack %u heap %u",
dp_data->domain_id, dp_data->stack_bytes,
dp_data->interim_heap_bytes, dp_data->lifetime_heap_bytes,
dp_data->shared_bytes);
dp_data->heap_bytes);
break;
}
case IPC4_MOD_INIT_DATA_ID_MODULE_DATA:
Expand Down
4 changes: 1 addition & 3 deletions src/include/ipc4/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ struct ipc4_module_init_ext_object {
struct ipc4_module_init_ext_obj_dp_data {
uint32_t domain_id; /* userspace domain ID */
uint32_t stack_bytes; /* required stack size in bytes */
uint32_t interim_heap_bytes; /* required interim heap size in bytes */
uint32_t lifetime_heap_bytes; /* required lifetime heap size in bytes */
uint32_t shared_bytes; /* required shared memory size in bytes */
uint32_t heap_bytes; /* required heap size in bytes */
} __attribute__((packed, aligned(4)));

/*
Expand Down
4 changes: 1 addition & 3 deletions src/include/ipc4/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ struct ipc4_pipeline_ext_object {
struct ipc4_pipeline_ext_obj_mem_data {
uint32_t domain_id; /* userspace domain ID */
uint32_t stack_bytes; /* required stack size in bytes */
uint32_t interim_heap_bytes; /* required interim heap size in bytes */
uint32_t lifetime_heap_bytes; /* required lifetime heap size in bytes */
uint32_t shared_bytes; /* required shared memory in bytes */
uint32_t heap_bytes; /* required heap size in bytes */
} __packed __aligned(4);

/*
Expand Down
1 change: 0 additions & 1 deletion src/include/sof/audio/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <rtos/idc.h>
#include <rtos/mutex.h>
#include <rtos/userspace_helper.h>
#include <sof/ctx_alloc.h>
#include <sof/lib/dai.h>
#include <sof/schedule/schedule.h>
#include <ipc/control.h>
Expand Down
81 changes: 0 additions & 81 deletions src/include/sof/ctx_alloc.h

This file was deleted.

1 change: 0 additions & 1 deletion src/include/sof/lib/dai-zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <rtos/spinlock.h>
#include <sof/trace/trace.h>
#include <sof/ipc/topology.h>
#include <sof/ctx_alloc.h>
#include <sof/audio/pcm_converter.h>
#include <sof/audio/ipc-config.h>
#include <sof/audio/component.h>
Expand Down
11 changes: 1 addition & 10 deletions src/include/sof/lib/vregion.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,20 @@ void vregion_mem_info(struct vregion *vr, size_t *size, uintptr_t *start);

#else /* CONFIG_SOF_VREGIONS */

#include <rtos/alloc.h>

struct vregion {
unsigned int use_count;
};

static inline struct vregion *vregion_create(size_t lifetime_size, size_t interim_size)
{
struct vregion *vr = rmalloc(0, sizeof(*vr));

vr->use_count = 1;
return vr;
return NULL;
}
static inline struct vregion *vregion_get(struct vregion *vr)
{
if (vr)
vr->use_count++;
return vr;
}
static inline struct vregion *vregion_put(struct vregion *vr)
{
if (vr && !--vr->use_count)
rfree(vr);
return vr;
}
static inline void *vregion_alloc(struct vregion *vr, enum vregion_mem_type type, size_t size)
Expand Down
5 changes: 2 additions & 3 deletions src/ipc/ipc4/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,9 @@ __cold static int ipc4_create_pipeline_payload_decode(char *data,
}
pparams->mem_data = mem_data;
tr_info(&ipc_tr,
"init_ext_obj_mem_data domain %u stack %u interim %u lifetime %u shared %u",
"init_ext_obj_mem_data domain %u stack %u heap %u",
mem_data->domain_id, mem_data->stack_bytes,
mem_data->interim_heap_bytes, mem_data->lifetime_heap_bytes,
mem_data->shared_bytes);
mem_data->heap_bytes);
break;
}
default:
Expand Down
68 changes: 68 additions & 0 deletions zephyr/include/rtos/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,72 @@ size_t get_shared_buffer_heap_size(void);

#endif

#include <sof/lib/vregion.h>

struct mod_alloc_ctx {
struct k_heap *heap;
struct vregion *vreg;
};

/**
* Allocate memory from a mod_alloc_ctx context.
*
* When the context has a vregion, allocates from the vregion interim
* partition. Coherent memory is used when SOF_MEM_FLAG_COHERENT is set
* in flags. Falls back to sof_heap_alloc() otherwise.
*
* @param ctx Allocation context (heap + optional vregion).
* @param flags Allocation flags (SOF_MEM_FLAG_*).
* @param size Size in bytes.
* @param alignment Required alignment in bytes.
* @return Pointer to allocated memory or NULL on failure.
*/
static inline void *sof_ctx_alloc(struct mod_alloc_ctx *ctx, uint32_t flags,
size_t size, size_t alignment)
{
if (!ctx || !ctx->vreg)
return sof_heap_alloc(ctx ? ctx->heap : NULL, flags, size, alignment);

if (flags & SOF_MEM_FLAG_COHERENT)
return vregion_alloc_coherent_align(ctx->vreg, VREGION_MEM_TYPE_INTERIM,
size, alignment);

return vregion_alloc_align(ctx->vreg, VREGION_MEM_TYPE_INTERIM, size, alignment);
}

/**
* Allocate zero-initialized memory from a mod_alloc_ctx context.
* @param ctx Allocation context.
* @param flags Allocation flags (SOF_MEM_FLAG_*).
* @param size Size in bytes.
* @param alignment Required alignment in bytes.
* @return Pointer to allocated memory or NULL on failure.
*/
static inline void *sof_ctx_zalloc(struct mod_alloc_ctx *ctx, uint32_t flags,
size_t size, size_t alignment)
{
void *ptr = sof_ctx_alloc(ctx, flags, size, alignment);

if (ptr)
memset(ptr, 0, size);

return ptr;
}

/**
* Free memory allocated from a mod_alloc_ctx context.
* @param ctx Allocation context.
* @param ptr Pointer to free.
*/
static inline void sof_ctx_free(struct mod_alloc_ctx *ctx, void *ptr)
{
if (!ptr)
return;

if (ctx && ctx->vreg)
vregion_free(ctx->vreg, ptr);
else
sof_heap_free(ctx ? ctx->heap : NULL, ptr);
}

#endif /* __ZEPHYR_RTOS_ALLOC_H__ */
Loading