-
Notifications
You must be signed in to change notification settings - Fork 363
ipc: add support for userspace IPC handling #10994
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
12
commits into
thesofproject:main
Choose a base branch
from
kv2019i:202607-user-ipc-forwarding
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.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
612ab8f
ipc: place global IPC context in user-accessible memory for user-spac…
kv2019i b643056
ipc4: add user-space command-forwarding context
kv2019i e218623
ipc4: handler: make config and pipeline-state processing context-agno…
kv2019i 987f2b5
ipc: make ipc_msg_reply and compound-message handlers syscalls
kv2019i 03c7169
ipc: allocate IPC objects from the user-accessible system heap
kv2019i 9b67276
zephyr: map IPC4 HOSTBOX partitions into user LL memory domain
kv2019i 63e118f
schedule: zephyr_ll: add user_ll_grant_access()
kv2019i 72287ac
ipc: add generic user-space IPC handling thread
kv2019i 235b6f4
ipc4: create components in user-space thread context
kv2019i 81db0de
ipc4: dispatch forwarded IPC commands in the user thread
kv2019i 776cbe8
ipc4: forward pipeline and module commands to the user thread
kv2019i 341fca5
ipc: move standalone-test check later in ipc_init()
kv2019i 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 |
|---|---|---|
|
|
@@ -22,8 +22,10 @@ | |
| #include <stdbool.h> | ||
| #include <stdint.h> | ||
|
|
||
| struct comp_driver; | ||
| struct dma_sg_elem_array; | ||
| struct ipc_msg; | ||
| struct ipc4_message_request; | ||
|
|
||
| /* validates internal non tail structures within IPC command structure */ | ||
| #define IPC_IS_SIZE_INVALID(object) \ | ||
|
|
@@ -53,6 +55,37 @@ extern struct tr_ctx ipc_tr; | |
| #define IPC_TASK_SECONDARY_CORE BIT(2) | ||
| #define IPC_TASK_POWERDOWN BIT(3) | ||
|
|
||
| struct ipc_user { | ||
| struct k_thread *thread; | ||
| struct k_sem *sem; | ||
| struct k_event *event; | ||
| /** @brief Copy of IPC4 message primary word forwarded to user thread */ | ||
| uint32_t ipc_msg_pri; | ||
| /** @brief Copy of IPC4 message extension word forwarded to user thread */ | ||
| uint32_t ipc_msg_ext; | ||
| /** @brief Result code from user thread processing */ | ||
| int result; | ||
| /** @brief Reply extension word from user thread (e.g. CONFIG_GET result) */ | ||
| uint32_t reply_ext; | ||
| /** @brief Reply TX data size from user thread (e.g. LARGE_CONFIG_GET result) */ | ||
| uint32_t reply_tx_size; | ||
| /** @brief Reply TX data pointer from user thread (e.g. LARGE_CONFIG_GET result) */ | ||
| void *reply_tx_data; | ||
| struct ipc *ipc; | ||
| struct k_thread *audio_thread; | ||
| /** @brief Original kernel driver pointer for restoring dev->drv after create */ | ||
| const struct comp_driver *init_drv; | ||
| /** | ||
| * @brief User-accessible copy of comp_driver + tr_ctx for create(). | ||
| * | ||
| * The comp_driver and tr_ctx structs reside in kernel memory | ||
| * (.rodata/.data) which is not user-readable. The kernel handler | ||
| * copies them here before forwarding to the user thread. | ||
| * Size verified by BUILD_ASSERT in handler-user.c. | ||
| */ | ||
| uint8_t init_drv_data[160] __aligned(4); | ||
| }; | ||
|
|
||
| struct ipc { | ||
| struct k_spinlock lock; /* locking mechanism */ | ||
| void *comp_data; | ||
|
|
@@ -74,6 +107,11 @@ struct ipc { | |
| struct task ipc_task; | ||
| #endif | ||
|
|
||
| #ifdef CONFIG_SOF_USERSPACE_LL | ||
| struct ipc_user *ipc_user_pdata; | ||
| struct mod_alloc_ctx *ll_alloc; | ||
| #endif | ||
|
|
||
| #ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS | ||
| /* io performance measurement */ | ||
| struct io_perf_data_item *io_perf_in_msg_count; | ||
|
|
@@ -95,6 +133,12 @@ struct ipc { | |
|
|
||
| extern struct task_ops ipc_task_ops; | ||
|
|
||
| #ifdef CONFIG_SOF_USERSPACE_LL | ||
|
|
||
| struct ipc *ipc_get(void); | ||
|
|
||
| #else | ||
|
|
||
| /** | ||
| * \brief Get the IPC global context. | ||
| * @return The global IPC context. | ||
|
|
@@ -104,6 +148,8 @@ static inline struct ipc *ipc_get(void) | |
| return sof_get()->ipc; | ||
| } | ||
|
|
||
| #endif /* CONFIG_SOF_USERSPACE_LL */ | ||
|
|
||
| /** | ||
| * \brief Initialise global IPC context. | ||
| * @param[in,out] sof Global SOF context. | ||
|
|
@@ -166,6 +212,56 @@ struct dai_data; | |
| */ | ||
| int ipc_dai_data_config(struct dai_data *dd, struct comp_dev *dev); | ||
|
|
||
| /** | ||
| * \brief Processes IPC4 userspace module message. | ||
| * @param[in] ipc4 IPC4 message request. | ||
| * @param[in] reply IPC message reply structure. | ||
| * @return IPC4_SUCCESS on success, error code otherwise. | ||
| */ | ||
| int ipc4_user_process_module_message(struct ipc4_message_request *ipc4, struct ipc_msg *reply); | ||
|
|
||
| /** | ||
| * \brief Processes IPC4 userspace global message. | ||
| * @param[in] ipc4 IPC4 message request. | ||
| * @param[in] reply IPC message reply structure. | ||
| * @return IPC4_SUCCESS on success, error code otherwise. | ||
| */ | ||
| int ipc4_user_process_glb_message(struct ipc4_message_request *ipc4, struct ipc_msg *reply); | ||
|
|
||
| /* | ||
| * When CONFIG_SOF_USERSPACE_LL is enabled, compound message functions are | ||
| * declared as syscalls in ipc4/handler.h — do not re-declare here with | ||
| * external linkage as that conflicts with the static inline syscall wrappers. | ||
| */ | ||
| #if !(defined(__ZEPHYR__) && defined(CONFIG_SOF_USERSPACE_LL)) | ||
|
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. these 3 under the |
||
| /** | ||
| * \brief Increment the IPC compound message pre-start counter. | ||
| * @param[in] msg_id IPC message ID. | ||
| */ | ||
| void ipc_compound_pre_start(int msg_id); | ||
|
|
||
| /** | ||
| * \brief Decrement the IPC compound message pre-start counter on return value status. | ||
| * @param[in] msg_id IPC message ID. | ||
| * @param[in] ret Return value of the IPC command. | ||
| * @param[in] delayed True if the reply is delayed. | ||
| */ | ||
| void ipc_compound_post_start(uint32_t msg_id, int ret, bool delayed); | ||
|
|
||
| /** | ||
| * \brief Wait for the IPC compound message to complete. | ||
| * @return 0 on success, error code otherwise on timeout. | ||
| */ | ||
| int ipc_wait_for_compound_msg(void); | ||
| #endif /* !CONFIG_SOF_USERSPACE_LL */ | ||
|
|
||
| /** | ||
| * \brief Complete the IPC compound message. | ||
| * @param[in] msg_id IPC message ID. | ||
| * @param[in] error Error code of the IPC command. | ||
| */ | ||
| void ipc_compound_msg_done(uint32_t msg_id, int error); | ||
|
|
||
| /** | ||
| * \brief create a IPC boot complete message. | ||
| * @param[in] header header. | ||
|
|
@@ -240,7 +336,7 @@ int ipc_process_on_core(uint32_t core, bool blocking); | |
| * \brief reply to an IPC message. | ||
| * @param[in] reply pointer to the reply structure. | ||
| */ | ||
| void ipc_msg_reply(struct sof_ipc_reply *reply); | ||
| #include <sof/ipc/ipc_reply.h> | ||
|
|
||
| /** | ||
| * \brief Call platform-specific IPC completion function. | ||
|
|
@@ -250,4 +346,30 @@ void ipc_complete_cmd(struct ipc *ipc); | |
| /* GDB stub: should enter GDB after completing the IPC processing */ | ||
| extern bool ipc_enter_gdb; | ||
|
|
||
| #ifdef CONFIG_SOF_USERSPACE_LL | ||
| /** | ||
| * @brief Forward an IPC command to the user-space thread and wait for it. | ||
| * | ||
| * Protocol-agnostic: only the two raw message words are handed across the | ||
| * kernel/user boundary. The active IPC major's ipc_user_thread_dispatch() | ||
| * interprets them in the user thread. | ||
| * | ||
| * @param primary Primary message word | ||
| * @param extension Extension message word | ||
| * @return Result code from user thread processing | ||
| */ | ||
| int ipc_user_forward_cmd(uint32_t primary, uint32_t extension); | ||
|
|
||
| /** | ||
| * @brief Protocol-specific dispatch of a forwarded IPC command. | ||
| * | ||
| * Runs in the user-space IPC thread. A __weak default returns -ENOSYS; | ||
| * the active IPC major (e.g. IPC4) provides the real implementation. | ||
| * | ||
| * @param ipc_user User IPC context holding the forwarded message words | ||
| * @return Result code to report back to the host | ||
| */ | ||
| int ipc_user_thread_dispatch(struct ipc_user *ipc_user); | ||
| #endif | ||
|
|
||
| #endif /* __SOF_DRIVERS_IPC_H__ */ | ||
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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* SPDX-License-Identifier: BSD-3-Clause | ||
| * | ||
| * Copyright(c) 2026 Intel Corporation. All rights reserved. | ||
| */ | ||
|
|
||
| #ifndef __SOF_IPC_IPC_REPLY_H__ | ||
| #define __SOF_IPC_IPC_REPLY_H__ | ||
|
|
||
| #include <ipc/header.h> | ||
|
|
||
| struct sof_ipc_reply; | ||
|
|
||
| /** | ||
| * \brief reply to an IPC message. | ||
| * @param[in] reply pointer to the reply structure. | ||
| */ | ||
| #if defined(__ZEPHYR__) && defined(CONFIG_SOF_USERSPACE_LL) | ||
| __syscall void ipc_msg_reply(struct sof_ipc_reply *reply); | ||
| #else | ||
| void z_impl_ipc_msg_reply(struct sof_ipc_reply *reply); | ||
| #define ipc_msg_reply z_impl_ipc_msg_reply | ||
| #endif | ||
|
|
||
| #if defined(__ZEPHYR__) && defined(CONFIG_SOF_USERSPACE_LL) | ||
| #include <zephyr/syscalls/ipc_reply.h> | ||
| #endif | ||
|
|
||
| #endif /* __SOF_IPC_IPC_REPLY_H__ */ |
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
Oops, something went wrong.
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.
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.
squashing: propose to squash with 378f458 (it won't apply directly, if you want to apply commits as is, you need 6edbb6c first)