-
Notifications
You must be signed in to change notification settings - Fork 356
audio: host-zephyr: make component usable from user-space #10799
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
Open
kv2019i
wants to merge
1
commit into
thesofproject:main
Choose a base branch
from
kv2019i:202605-host-zephyr-user
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+34
−14
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| #include <sof/ut.h> | ||
| #include <sof/trace/trace.h> | ||
| #include <sof/debug/telemetry/performance_monitor.h> | ||
| #include <sof/schedule/ll_schedule_domain.h> /* zephyr_ll_user_heap() */ | ||
| #include <ipc/stream.h> | ||
| #include <ipc/topology.h> | ||
| #include <user/trace.h> | ||
|
|
@@ -610,7 +611,7 @@ static int create_local_elems(struct host_data *hd, struct comp_dev *dev, | |
| elem_array = &hd->local.elem_array; | ||
|
|
||
| /* config buffer will be used as proxy */ | ||
| err = dma_sg_alloc(NULL, &hd->config.elem_array, SOF_MEM_FLAG_USER, | ||
| err = dma_sg_alloc(hd->alloc_ctx.heap, &hd->config.elem_array, SOF_MEM_FLAG_USER, | ||
| dir, 1, 0, 0, 0); | ||
| if (err < 0) { | ||
| comp_err(dev, "dma_sg_alloc() failed"); | ||
|
|
@@ -620,7 +621,7 @@ static int create_local_elems(struct host_data *hd, struct comp_dev *dev, | |
| elem_array = &hd->config.elem_array; | ||
| } | ||
|
|
||
| err = dma_sg_alloc(NULL, elem_array, SOF_MEM_FLAG_USER, dir, buffer_count, | ||
| err = dma_sg_alloc(hd->alloc_ctx.heap, elem_array, SOF_MEM_FLAG_USER, dir, buffer_count, | ||
| buffer_bytes, | ||
| (uintptr_t)audio_stream_get_addr(&hd->dma_buffer->stream), 0); | ||
| if (err < 0) { | ||
|
|
@@ -729,6 +730,17 @@ __cold int host_common_new(struct host_data *hd, struct comp_dev *dev, | |
| hd->chan_index = -EINVAL; | ||
| hd->copy_type = COMP_COPY_NORMAL; | ||
|
|
||
| #ifdef CONFIG_SOF_USERSPACE_LL | ||
| /* | ||
| * copier_host_create() uses mod_zalloc() to allocate | ||
| * the 'hd' host data object and does not set hd->alloc_ctx. | ||
| * If LL is run in user-space, assign the 'heap' here. | ||
| */ | ||
| hd->alloc_ctx.heap = zephyr_ll_user_heap(); | ||
| #else | ||
| hd->alloc_ctx.heap = NULL; | ||
| #endif | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
|
|
@@ -739,6 +751,7 @@ __cold static struct comp_dev *host_new(const struct comp_driver *drv, | |
| struct comp_dev *dev; | ||
| struct host_data *hd; | ||
| const struct ipc_config_host *ipc_host = spec; | ||
| struct k_heap *heap = NULL; | ||
| int ret; | ||
|
|
||
| assert_can_be_cold(); | ||
|
|
@@ -750,10 +763,12 @@ __cold static struct comp_dev *host_new(const struct comp_driver *drv, | |
| return NULL; | ||
| dev->ipc_config = *config; | ||
|
|
||
| hd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*hd)); | ||
| hd = sof_heap_alloc(heap, SOF_MEM_FLAG_USER, sizeof(*hd), 0); | ||
|
Collaborator
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'd use
Collaborator
Author
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. |
||
| if (!hd) | ||
| goto e_data; | ||
|
|
||
| memset(hd, 0, sizeof(*hd)); | ||
|
|
||
| hd->nobytes_last_logged = k_uptime_get(); | ||
| comp_set_drvdata(dev, hd); | ||
|
|
||
|
|
@@ -766,7 +781,7 @@ __cold static struct comp_dev *host_new(const struct comp_driver *drv, | |
| return dev; | ||
|
|
||
| e_dev: | ||
| rfree(hd); | ||
| sof_heap_free(heap, hd); | ||
| e_data: | ||
| comp_free_device(dev); | ||
| return NULL; | ||
|
|
@@ -794,7 +809,7 @@ __cold void host_common_free(struct host_data *hd) | |
| sof_dma_put(hd->dma); | ||
|
|
||
| ipc_msg_free(hd->msg); | ||
| dma_sg_free(NULL, &hd->config.elem_array); | ||
| dma_sg_free(hd->alloc_ctx.heap, &hd->config.elem_array); | ||
| } | ||
|
|
||
| __cold static void host_free(struct comp_dev *dev) | ||
|
|
@@ -805,7 +820,8 @@ __cold static void host_free(struct comp_dev *dev) | |
|
|
||
| comp_dbg(dev, "entry"); | ||
| host_common_free(hd); | ||
| rfree(hd); | ||
| /* NULL heap passed in host_new(), must match! */ | ||
| sof_heap_free(NULL, hd); | ||
| comp_free_device(dev); | ||
| } | ||
|
|
||
|
|
@@ -963,7 +979,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev, | |
| } | ||
| } else { | ||
| /* allocate not shared buffer */ | ||
| hd->dma_buffer = buffer_alloc_range(NULL, buffer_size_preferred, buffer_size, | ||
| hd->dma_buffer = buffer_alloc_range(&hd->alloc_ctx, buffer_size_preferred, buffer_size, | ||
| SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA, | ||
| addr_align, BUFFER_USAGE_NOT_SHARED); | ||
| if (!hd->dma_buffer) { | ||
|
|
@@ -1020,15 +1036,17 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev, | |
|
|
||
| memset(dma_cfg, 0, sizeof(*dma_cfg)); | ||
|
|
||
| dma_block_cfg = rzalloc(SOF_MEM_FLAG_USER, | ||
| sizeof(*dma_block_cfg)); | ||
| dma_block_cfg = sof_heap_alloc(hd->alloc_ctx.heap, SOF_MEM_FLAG_USER, | ||
| sizeof(*dma_block_cfg), 0); | ||
|
|
||
| if (!dma_block_cfg) { | ||
| comp_err(dev, "dma_block_config allocation failed"); | ||
| err = -ENOMEM; | ||
| goto err_release_channel; | ||
| } | ||
|
|
||
| memset(dma_block_cfg, 0, sizeof(*dma_block_cfg)); | ||
|
|
||
| dma_cfg->block_count = 1; | ||
| dma_cfg->source_data_size = config->src_width; | ||
| dma_cfg->dest_data_size = config->dest_width; | ||
|
|
@@ -1110,7 +1128,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev, | |
|
|
||
| err_free_block_cfg: | ||
| dma_cfg->head_block = NULL; | ||
| rfree(dma_block_cfg); | ||
| sof_heap_free(hd->alloc_ctx.heap, dma_block_cfg); | ||
| err_release_channel: | ||
| sof_dma_release_channel(hd->dma, hd->chan_index); | ||
| hd->chan_index = -EINVAL; | ||
|
|
@@ -1178,9 +1196,9 @@ void host_common_reset(struct host_data *hd, uint16_t state) | |
| } | ||
|
|
||
| /* free all DMA elements */ | ||
| dma_sg_free(NULL, &hd->host.elem_array); | ||
| dma_sg_free(NULL, &hd->local.elem_array); | ||
| dma_sg_free(NULL, &hd->config.elem_array); | ||
| dma_sg_free(hd->alloc_ctx.heap, &hd->host.elem_array); | ||
| dma_sg_free(hd->alloc_ctx.heap, &hd->local.elem_array); | ||
| dma_sg_free(hd->alloc_ctx.heap, &hd->config.elem_array); | ||
|
|
||
| /* free DMA buffer */ | ||
| if (hd->dma_buffer) { | ||
|
|
@@ -1190,7 +1208,7 @@ void host_common_reset(struct host_data *hd, uint16_t state) | |
|
|
||
| /* free DMA block configuration */ | ||
| if (hd->z_config.head_block) | ||
| rfree(hd->z_config.head_block); | ||
| sof_heap_free(hd->alloc_ctx.heap, hd->z_config.head_block); | ||
|
|
||
| /* reset buffer pointers */ | ||
| hd->local_pos = 0; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.