Skip to content
Closed
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
23 changes: 8 additions & 15 deletions src/audio/codec_adapter/codec/cadence.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int cadence_codec_init(struct comp_dev *dev)

comp_dbg(dev, "cadence_codec_init() start");

cd = codec_allocate_memory(dev, sizeof(struct cadence_codec_data), 0);
cd = comp_devm_alloc(dev, sizeof(struct cadence_codec_data), 0);
if (!cd) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this shouldn't be better called devm_comp_alloc(dev, ..) similar with its Linux counterpart.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sure. Can revisit the naming as I need to shuffle this around anyway...

comp_err(dev, "cadence_codec_init(): failed to allocate memory for cadence codec data");
return -ENOMEM;
Expand Down Expand Up @@ -122,22 +122,22 @@ int cadence_codec_init(struct comp_dev *dev)
if (ret != LIB_NO_ERROR) {
comp_err(dev, "cadence_codec_init() error %x: failed to get lib name",
ret);
codec_free_memory(dev, cd);
comp_devm_free(dev);
goto out;
}
/* Get codec object size */
API_CALL(cd, XA_API_CMD_GET_API_SIZE, 0, &obj_size, ret);
if (ret != LIB_NO_ERROR) {
comp_err(dev, "cadence_codec_init() error %x: failed to get lib object size",
ret);
codec_free_memory(dev, cd);
comp_devm_free(dev);
goto out;
}
/* Allocate space for codec object */
cd->self = codec_allocate_memory(dev, obj_size, 0);
cd->self = comp_devm_alloc(dev, obj_size, 0);
if (!cd->self) {
comp_err(dev, "cadence_codec_init(): failed to allocate space for lib object");
codec_free_memory(dev, cd);
comp_devm_free(dev);
goto out;
} else {
comp_dbg(dev, "cadence_codec_init(): allocated %d bytes for lib object",
Expand Down Expand Up @@ -254,7 +254,7 @@ static int init_memory_tables(struct comp_dev *dev)
goto err;
}
/* Allocate memory for this type, taking alignment into account */
ptr = codec_allocate_memory(dev, mem_size, mem_alignment);
ptr = comp_devm_alloc(dev, mem_size, mem_alignment);
if (!ptr) {
comp_err(dev, "init_memory_tables() error %x: failed to allocate memory for %d",
ret, mem_type);
Expand Down Expand Up @@ -297,14 +297,7 @@ static int init_memory_tables(struct comp_dev *dev)

return 0;
err:
if (scratch)
codec_free_memory(dev, scratch);
if (persistent)
codec_free_memory(dev, persistent);
if (codec->cpd.in_buff)
codec_free_memory(dev, codec->cpd.in_buff);
if (codec->cpd.out_buff)
codec_free_memory(dev, codec->cpd.out_buff);
comp_devm_free(dev);
return ret;
}

Expand Down Expand Up @@ -413,7 +406,7 @@ int cadence_codec_prepare(struct comp_dev *dev)
goto err;
}

cd->mem_tabs = codec_allocate_memory(dev, mem_tabs_size, 4);
cd->mem_tabs = comp_devm_alloc(dev, mem_tabs_size, 4);
if (!cd->mem_tabs) {
comp_err(dev, "cadence_codec_prepare() error: failed to allocate space for memtabs");
ret = -ENOMEM;
Expand Down
81 changes: 1 addition & 80 deletions src/audio/codec_adapter/codec/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,70 +124,7 @@ int codec_init(struct comp_dev *dev, struct codec_interface *interface)
return ret;
}

void *codec_allocate_memory(struct comp_dev *dev, uint32_t size,
uint32_t alignment)
{
struct codec_memory *container;
void *ptr;
struct comp_data *cd = comp_get_drvdata(dev);

if (!size) {
comp_err(dev, "codec_allocate_memory: requested allocation of 0 bytes.");
return NULL;
}

/* Allocate memory container */
container = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
sizeof(struct codec_memory));
if (!container) {
comp_err(dev, "codec_allocate_memory: failed to allocate memory container.");
return NULL;
}

/* Allocate memory for codec */
if (alignment)
ptr = rballoc_align(0, SOF_MEM_CAPS_RAM, size, alignment);
else
ptr = rballoc(0, SOF_MEM_CAPS_RAM, size);

if (!ptr) {
comp_err(dev, "codec_allocate_memory: failed to allocate memory for codec %x.",
cd->ca_config.codec_id);
return NULL;
}
/* Store reference to allocated memory */
container->ptr = ptr;
list_item_prepend(&container->mem_list, &cd->codec.memory.mem_list);

return ptr;
}

int codec_free_memory(struct comp_dev *dev, void *ptr)
{
struct comp_data *cd = comp_get_drvdata(dev);
struct codec_memory *mem;
struct list_item *mem_list;
struct list_item *_mem_list;

if (!ptr)
return 0;

/* Find which container keeps this memory */
list_for_item_safe(mem_list, _mem_list, &cd->codec.memory.mem_list) {
mem = container_of(mem_list, struct codec_memory, mem_list);
if (mem->ptr == ptr) {
rfree(mem->ptr);
list_item_del(&mem->mem_list);
rfree(mem);
return 0;
}
}

comp_err(dev, "codec_free_memory: error: could not find memory pointed by %p",
(uint32_t)ptr);

return -EINVAL;
}

static int validate_config(struct codec_config *cfg)
{
Expand Down Expand Up @@ -349,22 +286,6 @@ int codec_reset(struct comp_dev *dev)
return 0;
}

void codec_free_all_memory(struct comp_dev *dev)
{
struct comp_data *cd = comp_get_drvdata(dev);
struct codec_memory *mem;
struct list_item *mem_list;
struct list_item *_mem_list;

/* Find which container keeps this memory */
list_for_item_safe(mem_list, _mem_list, &cd->codec.memory.mem_list) {
mem = container_of(mem_list, struct codec_memory, mem_list);
rfree(mem->ptr);
list_item_del(&mem->mem_list);
rfree(mem);
}
}

int codec_free(struct comp_dev *dev)
{
int ret;
Expand All @@ -377,7 +298,7 @@ int codec_free(struct comp_dev *dev)
ret, cd->ca_config.codec_id);
}
/* Free all memory requested by codec */
codec_free_all_memory(dev);
comp_devm_free(dev);
/* Free all memory shared by codec_adapter & codec */
codec->s_cfg.avail = false;
codec->s_cfg.size = 0;
Expand Down
19 changes: 7 additions & 12 deletions src/audio/codec_adapter/codec/waves.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static int waves_effect_allocate(struct comp_dev *dev)
return -EINVAL;
}

waves_codec->effect = (MaxxEffect_t *)codec_allocate_memory(dev,
waves_codec->effect = (MaxxEffect_t *)comp_devm_alloc(dev,
waves_codec->effect_size, 16);

if (!waves_codec->effect) {
Expand Down Expand Up @@ -375,23 +375,23 @@ static int waves_effect_buffers(struct comp_dev *dev)
goto err;
}

response = codec_allocate_memory(dev, waves_codec->response_max_bytes, 16);
response = comp_devm_alloc(dev, waves_codec->response_max_bytes, 16);
if (!response) {
comp_err(dev, "waves_effect_buffers() failed to allocate %d bytes for response",
waves_codec->response_max_bytes);
ret = -ENOMEM;
goto err;
}

i_buffer = codec_allocate_memory(dev, waves_codec->buffer_bytes, 16);
i_buffer = comp_devm_alloc(dev, waves_codec->buffer_bytes, 16);
if (!i_buffer) {
comp_err(dev, "waves_effect_buffers() failed to allocate %d bytes for i_buffer",
waves_codec->buffer_bytes);
ret = -ENOMEM;
goto err;
}

o_buffer = codec_allocate_memory(dev, waves_codec->buffer_bytes, 16);
o_buffer = comp_devm_alloc(dev, waves_codec->buffer_bytes, 16);
if (!o_buffer) {
comp_err(dev, "waves_effect_buffers() failed to allocate %d bytes for o_buffer",
waves_codec->buffer_bytes);
Expand All @@ -415,12 +415,7 @@ static int waves_effect_buffers(struct comp_dev *dev)
return 0;

err:
if (i_buffer)
codec_free_memory(dev, i_buffer);
if (o_buffer)
codec_free_memory(dev, o_buffer);
if (response)
codec_free_memory(dev, response);
comp_devm_free(dev);
return ret;
}

Expand Down Expand Up @@ -606,7 +601,7 @@ int waves_codec_init(struct comp_dev *dev)

comp_dbg(dev, "waves_codec_init() start");

waves_codec = codec_allocate_memory(dev, sizeof(struct waves_codec_data), 16);
waves_codec = comp_devm_alloc(dev, sizeof(struct waves_codec_data), 16);
if (!waves_codec) {
comp_err(dev, "waves_codec_init() failed to allocate %d bytes for waves_codec_data",
sizeof(struct waves_codec_data));
Expand Down Expand Up @@ -756,7 +751,7 @@ int waves_codec_reset(struct comp_dev *dev)

int waves_codec_free(struct comp_dev *dev)
{
/* codec is using codec_adapter method codec_allocate_memory for all allocations
/* codec is using codec_adapter method comp_devm_alloc for all allocations
* codec_adapter will free it all on component free call
* nothing to do here
*/
Expand Down
54 changes: 54 additions & 0 deletions src/audio/component.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,57 @@ struct comp_dev *comp_make_shared(struct comp_dev *dev)

return dev;
}

void *comp_devm_alloc(struct comp_dev *dev, uint32_t size,
uint32_t alignment)
{
struct comp_dev_mem *container;
void *ptr;

if (!size) {
comp_err(dev, "comp_devm_alloc: requested allocation of 0 bytes.");
return NULL;
}

/* Allocate memory container */
container = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
sizeof(struct comp_dev_mem));
if (!container) {
comp_err(dev, "comp_devm_alloc: failed to allocate memory container.");
return NULL;
}

/* Allocate memory for codec */
if (alignment)
ptr = rballoc_align(0, SOF_MEM_CAPS_RAM, size, alignment);
else
ptr = rballoc(0, SOF_MEM_CAPS_RAM, size);

if (!ptr) {
comp_err(dev, "comp_devm_alloc: failed to allocate memory for comp_dev\n");
return NULL;
}

/* Store reference to allocated memory */
container->ptr = ptr;
list_item_prepend(&container->mem_list, &dev->mem.mem_list);

return ptr;
}

int comp_devm_free(struct comp_dev *dev)
{
struct comp_dev_mem *mem;
struct list_item *mem_list;
struct list_item *_mem_list;

/* Find which container keeps this memory */
list_for_item_safe(mem_list, _mem_list, &dev->mem.mem_list) {
mem = container_of(mem_list, struct comp_dev_mem, mem_list);
rfree(mem->ptr);
list_item_del(&mem->mem_list);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe first delete from the list, then free?

rfree(mem);
}

return 0;
}
6 changes: 6 additions & 0 deletions src/audio/pipeline/pipeline-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ void pipeline_posn_init(struct sof *sof)
spinlock_init(&sof->pipeline_posn->lock);
}

int pipeline_alloc_memory(struct pipeline *p, uint32_t bytes)
{
// TODO
return 0;
}

/* create new pipeline - returns pipeline id or negative error */
struct pipeline *pipeline_new(struct comp_dev *cd, uint32_t pipeline_id,
uint32_t priority, uint32_t comp_id)
Expand Down
13 changes: 7 additions & 6 deletions src/drivers/intel/cavs/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ void ipc_platform_complete_cmd(void *data)
int ipc_platform_send_msg(struct ipc_msg *msg)
{
struct ipc *ipc = ipc_get();
ipc_cmd_hdr *hdr;
int ret = 0;

if (ipc->is_notification_pending ||
Expand All @@ -246,20 +247,20 @@ int ipc_platform_send_msg(struct ipc_msg *msg)
goto out;
}

/* now send the message */
mailbox_dspbox_write(0, msg->tx_data, msg->tx_size);
list_item_del(&msg->list);
tr_dbg(&ipc_tr, "ipc: msg tx -> 0x%x", msg->header);

ipc->is_notification_pending = true;

hdr = ipc_process_msg(msg);

/* now interrupt host to tell it we have message sent */
#if CAVS_VERSION == CAVS_VERSION_1_5
ipc_write(IPC_DIPCIE, 0);
ipc_write(IPC_DIPCI, IPC_DIPCI_BUSY | msg->header);
ipc_write(IPC_DIPCIE, hdr[1]);
ipc_write(IPC_DIPCI, IPC_DIPCI_BUSY | hdr[0]);
#else
ipc_write(IPC_DIPCIDD, 0);
ipc_write(IPC_DIPCIDR, IPC_DIPCIDR_BUSY | msg->header);
ipc_write(IPC_DIPCIDD, hdr[1]);
ipc_write(IPC_DIPCIDR, IPC_DIPCIDR_BUSY | hdr[0]);
#endif

out:
Expand Down
45 changes: 45 additions & 0 deletions src/include/ipc4/alh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2021 Intel Corporation. All rights reserved.
*/

/*
* This file contains structures that are exact copies of an existing ABI used
* by IOT middleware. They are Intel specific and will be used by one middleware.
*
* Some of the structures may contain programming implementations that makes them
* unsuitable for generic use and general usage.
*/

/**
* \file include/ipc4/alh.h
* \brief IPC4 global definitions.
* NOTE: This ABI uses bit fields and is non portable.
*/

#ifndef __SOF_IPC4_ALH_H__
#define __SOF_IPC4_ALH_H__

#include <stdint.h>
#include <ipc4/gateway.h>

#define ALH_MAX_NUMBER_OF_GTW 16

struct ipc4_alh_multi_gtw_cfg {
/* Number of single channels (valid items in mapping array). */
uint32_t count;
/* Single to multi aggregation mapping item. */
struct {
/* Vindex of a single ALH channel aggregated. */
uint32_t alh_id;
/* Channel mask */
uint32_t channel_mask;
} mapping[ALH_MAX_NUMBER_OF_GTW]; /* < Mapping items */
} __attribute__((packed, aligned(4)));

struct sof_alh_configuration_blob {
union ipc4_gateway_attributes gtw_attributes;
struct ipc4_alh_multi_gtw_cfg alh_cfg;
} __attribute__((packed, aligned(4)));

#endif
Loading