Skip to content

Commit 4656235

Browse files
committed
audio: host-zephyr: make component usable from user-space
Ensure component heap is correctly passed whenever memory is allocated in the component. This allows to run the component both in kernel and user space. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 093a507 commit 4656235

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/audio/copier/host_copier.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct host_data {
113113
uint64_t next_sync;
114114
uint64_t period_in_cycles;
115115
#endif
116+
struct k_heap *heap;
116117
};
117118

118119
int host_common_new(struct host_data *hd, struct comp_dev *dev,

src/audio/host-zephyr.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <sof/lib/uuid.h>
2222
#include <sof/list.h>
2323
#include <sof/math/numbers.h>
24+
#include <sof/schedule/ll_schedule_domain.h>
2425
#include <rtos/string.h>
2526
#include <sof/ut.h>
2627
#include <sof/trace/trace.h>
@@ -755,6 +756,7 @@ __cold static struct comp_dev *host_new(const struct comp_driver *drv,
755756
struct comp_dev *dev;
756757
struct host_data *hd;
757758
const struct ipc_config_host *ipc_host = spec;
759+
struct k_heap *heap = NULL;
758760
int ret;
759761

760762
assert_can_be_cold();
@@ -766,10 +768,17 @@ __cold static struct comp_dev *host_new(const struct comp_driver *drv,
766768
return NULL;
767769
dev->ipc_config = *config;
768770

769-
hd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*hd));
771+
#ifdef CONFIG_SOF_USERSPACE_LL
772+
heap = zephyr_ll_user_heap();
773+
#endif
774+
775+
hd = sof_heap_alloc(heap, SOF_MEM_FLAG_USER, sizeof(*hd), 0);
770776
if (!hd)
771777
goto e_data;
772778

779+
memset(hd, 0, sizeof(*hd));
780+
hd->heap = heap;
781+
773782
hd->nobytes_last_logged = k_uptime_get();
774783
comp_set_drvdata(dev, hd);
775784

@@ -782,7 +791,7 @@ __cold static struct comp_dev *host_new(const struct comp_driver *drv,
782791
return dev;
783792

784793
e_dev:
785-
rfree(hd);
794+
sof_heap_free(heap, hd);
786795
e_data:
787796
comp_free_device(dev);
788797
return NULL;
@@ -806,7 +815,7 @@ __cold static void host_free(struct comp_dev *dev)
806815

807816
comp_dbg(dev, "entry");
808817
host_common_free(hd);
809-
rfree(hd);
818+
sof_heap_free(hd->heap, hd);
810819
comp_free_device(dev);
811820
}
812821

@@ -969,7 +978,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
969978
}
970979
} else {
971980
/* allocate not shared buffer */
972-
hd->dma_buffer = buffer_alloc_range(heap, buffer_size_preferred, buffer_size,
981+
hd->dma_buffer = buffer_alloc_range(hd->heap, buffer_size_preferred, buffer_size,
973982
SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA,
974983
addr_align, BUFFER_USAGE_NOT_SHARED);
975984
if (!hd->dma_buffer) {
@@ -1026,15 +1035,17 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
10261035

10271036
memset(dma_cfg, 0, sizeof(*dma_cfg));
10281037

1029-
dma_block_cfg = rzalloc(SOF_MEM_FLAG_USER,
1030-
sizeof(*dma_block_cfg));
1038+
dma_block_cfg = sof_heap_alloc(hd->heap, SOF_MEM_FLAG_USER,
1039+
sizeof(*dma_block_cfg), 0);
10311040

10321041
if (!dma_block_cfg) {
10331042
comp_err(dev, "dma_block_config allocation failed");
10341043
err = -ENOMEM;
10351044
goto err_release_channel;
10361045
}
10371046

1047+
memset(dma_block_cfg, 0, sizeof(*dma_block_cfg));
1048+
10381049
dma_cfg->block_count = 1;
10391050
dma_cfg->source_data_size = config->src_width;
10401051
dma_cfg->dest_data_size = config->dest_width;
@@ -1098,7 +1109,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
10981109

10991110
err_free_block_cfg:
11001111
dma_cfg->head_block = NULL;
1101-
rfree(dma_block_cfg);
1112+
sof_heap_free(hd->heap, dma_block_cfg);
11021113
err_release_channel:
11031114
sof_dma_release_channel(hd->dma, hd->chan_index);
11041115
hd->chan_index = -1;
@@ -1178,7 +1189,7 @@ void host_common_reset(struct host_data *hd, uint16_t state)
11781189

11791190
/* free DMA block configuration */
11801191
if (hd->z_config.head_block)
1181-
rfree(hd->z_config.head_block);
1192+
sof_heap_free(hd->heap, hd->z_config.head_block);
11821193

11831194
/* reset buffer pointers */
11841195
hd->local_pos = 0;

0 commit comments

Comments
 (0)