-
Notifications
You must be signed in to change notification settings - Fork 349
zephyr: userspace_helper: add test_mailbox.c (plus a test) #10477
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| #include <rtos/userspace_helper.h> | ||
| #include <sof/audio/module_adapter/module/generic.h> | ||
| #include <sof/audio/module_adapter/library/userspace_proxy.h> | ||
| #include <sof/lib/mailbox.h> | ||
|
|
||
| #define MODULE_DRIVER_HEAP_CACHED CONFIG_SOF_ZEPHYR_HEAP_CACHED | ||
|
|
||
|
|
@@ -82,6 +83,46 @@ int user_memory_init_shared(k_tid_t thread_id, struct processing_module *mod) | |
| return k_mem_domain_add_thread(comp_dom, thread_id); | ||
| } | ||
|
|
||
| int user_access_to_mailbox(struct k_mem_domain *domain, k_tid_t thread_id) | ||
| { | ||
| struct k_mem_partition mem_partition; | ||
| int ret; | ||
|
|
||
| /* | ||
| * Start with mailbox_swregs. This is aligned with mailbox.h | ||
| * implementation with uncached addressed used for register I/O. | ||
| */ | ||
| mem_partition.start = | ||
| (uintptr_t)sys_cache_uncached_ptr_get((void __sparse_cache *)MAILBOX_SW_REG_BASE); | ||
|
|
||
| BUILD_ASSERT(MAILBOX_SW_REG_SIZE == CONFIG_MMU_PAGE_SIZE); | ||
| mem_partition.size = CONFIG_MMU_PAGE_SIZE; | ||
| mem_partition.attr = K_MEM_PARTITION_P_RW_U_RW; | ||
|
|
||
| ret = k_mem_domain_add_partition(domain, &mem_partition); | ||
| if (ret < 0) | ||
| return ret; | ||
|
|
||
| #ifndef CONFIG_IPC_MAJOR_4 | ||
| /* | ||
| * Next mailbox_stream (not available in IPC4). Stream access is cached, | ||
| * so different mapping this time. | ||
| */ | ||
| mem_partition.start = | ||
| (uintptr_t)sys_cache_cached_ptr_get((void *)SRAM_STREAM_BASE); | ||
| BUILD_ASSERT(MAILBOX_STREAM_SIZE == CONFIG_MMU_PAGE_SIZE); | ||
| /* size and attr the same as for mailbox_swregs */ | ||
|
|
||
| ret = k_mem_domain_add_partition(domain, &mem_partition); | ||
| if (ret < 0) | ||
| return ret; | ||
| #endif | ||
|
|
||
| k_mem_domain_add_thread(domain, thread_id); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| #else /* CONFIG_USERSPACE */ | ||
|
|
||
| void *user_stack_allocate(size_t stack_size, uint32_t options) | ||
|
|
@@ -102,4 +143,9 @@ int user_stack_free(void *p_stack) | |
| void module_driver_heap_remove(struct k_heap *mod_drv_heap) | ||
| { } | ||
|
|
||
| int user_access_to_mailbox(struct k_mem_domain *domain, k_tid_t thread_id) | ||
|
Member
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. nitpick: we can make this static inline in the header and it would save a little TEXT. |
||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| #endif /* CONFIG_USERSPACE */ | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,123 @@ | ||||||
| // SPDX-License-Identifier: BSD-3-Clause | ||||||
| /* | ||||||
| * Copyright(c) 2026 Intel Corporation. | ||||||
| */ | ||||||
|
|
||||||
| /* | ||||||
| * Test case for sof/mailbox.h interface use from a Zephyr user | ||||||
| * thread. | ||||||
| */ | ||||||
|
|
||||||
| #include <sof/boot_test.h> | ||||||
| #include <sof/lib/mailbox.h> | ||||||
| #include <rtos/userspace_helper.h> | ||||||
|
|
||||||
| #include <zephyr/kernel.h> | ||||||
| #include <zephyr/ztest.h> | ||||||
| #include <zephyr/logging/log.h> | ||||||
| #include <zephyr/app_memory/app_memdomain.h> | ||||||
|
|
||||||
| #include <ipc4/fw_reg.h> /* mailbox definitions */ | ||||||
|
|
||||||
| LOG_MODULE_DECLARE(sof_boot_test, LOG_LEVEL_DBG); | ||||||
|
|
||||||
| #define USER_STACKSIZE 2048 | ||||||
|
|
||||||
| static struct k_thread user_thread; | ||||||
| static K_THREAD_STACK_DEFINE(user_stack, USER_STACKSIZE); | ||||||
|
|
||||||
| static void mailbox_write_to_pipeline_regs(void) | ||||||
| { | ||||||
| unsigned int offset = | ||||||
| offsetof(struct ipc4_fw_registers, pipeline_regs); | ||||||
|
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. wouldn't it fit in 100 characters in a single line? |
||||||
| struct ipc4_pipeline_registers pipe_reg; | ||||||
|
|
||||||
| pipe_reg.stream_start_offset = (uint64_t)-1; | ||||||
| pipe_reg.stream_end_offset = (uint64_t)-1; | ||||||
|
|
||||||
| LOG_INF("Write to IPC4 pipeline regs at offset %u", offset); | ||||||
|
|
||||||
| mailbox_sw_regs_write(offset, &pipe_reg, sizeof(pipe_reg)); | ||||||
| } | ||||||
|
|
||||||
| /* | ||||||
| * the "stream" mailbox not available on targets using IPC4 | ||||||
| * layout for shared memory between host and DSP | ||||||
| */ | ||||||
| #ifdef CONFIG_IPC_MAJOR_4 | ||||||
|
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. ditto IPC3? |
||||||
| static void mailbox_write_to_stream_posn(void) | ||||||
| { | ||||||
| } | ||||||
| #else | ||||||
| static void mailbox_write_to_stream_posn(void) | ||||||
| { | ||||||
| struct sof_ipc_stream_posn posn; | ||||||
| size_t offset = 0; /* first stream position slot */ | ||||||
|
|
||||||
| LOG_INF("Write to IPC4 stream#0 position info offset %u size %u.", | ||||||
|
||||||
| LOG_INF("Write to IPC4 stream#0 position info offset %u size %u.", | |
| LOG_INF("Write to stream#0 position info offset %u size %zu.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Userspace with IPC3? really?