Skip to content

Commit 7f002a2

Browse files
lrgirdwoclaude
authored andcommitted
docs: ipc: describe the user/kernel partitioning of IPC4
Add a User/Kernel Partitioning section to the IPC4 README. It shows how a message passes from the kernel dispatcher through the routers and the routing of the LL scheduler in user or kernel space to the user-space IPC thread, and lists which IPC4 messages are handled only in the kernel, in the kernel and in user space, and only in user space. Point the top-level IPC README at it and list the kernel and user halves of the split IPC files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent df29732 commit 7f002a2

2 files changed

Lines changed: 76 additions & 9 deletions

File tree

‎src/ipc/README.md‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Inter-Processor Communication (IPC) Core Architecture
22

33
> **Runs in:** Boundary / bridge — the kernel receives and dispatches IPC, then forwards
4-
> module-facing commands to a user thread. The split is visible in the file names
5-
> (`src/kernel/ipc/ipc4/handler-kernel.c` vs `ipc4/handler-user.c`,
6-
> `ipc4/notification-user.c`), and this subsystem hosts the `ipc_msg_*`, `ipc_compound_*` and
7-
> `send_resource_notif` syscalls. See
4+
> module-facing commands to a user thread. The kernel halves of the mixed files are in
5+
> `src/kernel/ipc` (`ipc-common-kernel.c`, `ipc4/handler-kernel.c`,
6+
> `ipc4/handler-user-kernel.c`, `ipc4/handler-ll-user.c`, `ipc4/handler-ll-kernel.c`,
7+
> `ipc4/helper-kernel.c`), the user halves stay here (`ipc-common.c`, `ipc4/handler-user.c`,
8+
> `ipc4/helper.c`, `ipc4/notification-user.c`), and this subsystem hosts the `ipc_msg_*`,
9+
> `ipc_compound_*` and `send_resource_notif` syscalls. Which IPC4 messages are handled in the
10+
> kernel, in user space or in both is listed in
11+
> [IPC4 User/Kernel Partitioning](ipc4/README.md#userkernel-partitioning). See also
812
> [User/kernel split](../include/sof/userspace/README.md).
913
1014
This directory contains the common foundation for all Inter-Processor Communication (IPC) within the Sound Open Firmware (SOF) project. It bridges the gap between hardware mailbox interrupts and the version-specific (IPC3/IPC4) message handlers.

‎src/ipc/ipc4/README.md‎

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# IPC4 Architecture
22

33
> **Runs in:** Boundary / bridge — `handler-user.c` and `notification-user.c` run in the user
4-
> thread that services modules. Their kernel counterparts, `handler-kernel.c` (the kernel
5-
> dispatcher), `handler-user-kernel.c` (the global and module message routers, which forward
6-
> commands to the user thread) and `notification.c`, are in `src/kernel/ipc/ipc4`, together
7-
> with the `z_vrfy_`/`z_impl_` pairs for the compound-message, reply and notification
8-
> syscalls. See [User/kernel split](../../include/sof/userspace/README.md).
4+
> thread that services modules. Their kernel counterparts are in `src/kernel/ipc/ipc4`:
5+
> `handler-kernel.c` (the kernel dispatcher), `handler-user-kernel.c` (the global and module
6+
> message routers), `handler-ll-user.c` and `handler-ll-kernel.c` (the routing for the LL
7+
> scheduler in user and in kernel space) and `notification.c`, together with the
8+
> `z_vrfy_`/`z_impl_` pairs for the compound-message, reply and notification syscalls. See
9+
> [User/Kernel Partitioning](#userkernel-partitioning) below and
10+
> [User/kernel split](../../include/sof/userspace/README.md).
911
1012
This directory holds the handlers and topology parsing logic for Inter-Processor Communication Version 4. IPC4 introduces a significantly denser, compound-command structure heavily based around the concept of "pipelines" and dynamic "modules" rather than static DSP stream roles.
1113

@@ -41,6 +43,67 @@ graph TD
4143
end
4244
```
4345

46+
## User/Kernel Partitioning
47+
48+
With the LL scheduler in user space (`CONFIG_SOF_USERSPACE_LL`), each IPC4 message is handled
49+
in up to two places:
50+
51+
- **Kernel IPC thread**: `handler-kernel.c` receives the message from the host mailbox and
52+
replies. It handles the kernel-only messages itself and passes the others to the routers in
53+
`handler-user-kernel.c`. The routers handle the messages that need kernel mode in all builds.
54+
For the rest they call the `ipc4_route_*()` functions of `handler-ll-user.c`, which do any
55+
privileged part of the message and forward it to the user-space IPC thread of the target
56+
core with `ipc_user_forward_cmd()`.
57+
- **User-space IPC thread**: `ipc_user_thread_dispatch()` in `handler-user.c` runs the handlers
58+
in `handler-user.c` and `helper.c` for the forwarded message.
59+
60+
Without `CONFIG_SOF_USERSPACE_LL`, `handler-ll-kernel.c` provides the `ipc4_route_*()`
61+
functions instead and calls the same handlers directly, so all messages are handled in the
62+
kernel IPC thread. The split still marks which code must be user-space safe.
63+
64+
```mermaid
65+
graph TD
66+
Host[Host IPC] --> Disp["handler-kernel.c<br/>ipc4_process_glb/module_message()"]
67+
Disp -->|kernel only| KOnly["library load, D0ix/Dx"]
68+
Disp --> Routers["handler-user-kernel.c<br/>ipc4_user_process_glb/module_message()"]
69+
Routers -->|kernel only| KRouted["CHAIN_DMA, IPC gateway, GDB,<br/>base firmware LARGE_CONFIG"]
70+
Routers --> Route{"ipc4_route_*()"}
71+
Route -->|CONFIG_SOF_USERSPACE_LL| LLUser["handler-ll-user.c<br/>target core, driver lookup,<br/>module load, multicore sequencing"]
72+
Route -->|otherwise| LLKernel["handler-ll-kernel.c<br/>direct call"]
73+
LLUser -->|ipc_user_forward_cmd| UThread["user-space IPC thread<br/>ipc_user_thread_dispatch()"]
74+
UThread --> Handlers["handler-user.c / helper.c handlers"]
75+
LLKernel --> Handlers
76+
```
77+
78+
With `CONFIG_SOF_USERSPACE_LL`, the messages are handled as follows:
79+
80+
| Message | Kernel only | Kernel and user | User |
81+
|---|---|---|---|
82+
| `GLB_LOAD_LIBRARY`, `GLB_LOAD_LIBRARY_PREPARE` | ✓ library manager | | |
83+
| `GLB_CHAIN_DMA` | ✓ | | |
84+
| `GLB_IPCGATEWAY_CMD` | ✓ | | |
85+
| `GLB_ENTER_GDB` | ✓ | | |
86+
| `MOD_SET_D0IX`, `MOD_SET_DX` | ✓ power management | | |
87+
| `MOD_LARGE_CONFIG_GET`/`SET`, base firmware (module_id 0) | ✓ reads the IMR manifest | | |
88+
| `GLB_CREATE_PIPELINE` | | kernel: target core; user: pipeline creation | |
89+
| `GLB_DELETE_PIPELINE` | | kernel: owning core; user: pipeline free | |
90+
| `GLB_SET_PIPELINE_STATE` | | kernel: pipeline list check, multicore prepare/trigger sequencing; user: prepare and trigger | |
91+
| `MOD_INIT_INSTANCE` | | kernel: driver lookup, loadable module setup; user: component creation | |
92+
| `MOD_CONFIG_GET`/`SET` | | | ✓ |
93+
| `MOD_LARGE_CONFIG_GET`/`SET`, modules | | | ✓ |
94+
| `MOD_BIND`, `MOD_UNBIND` | | | ✓ |
95+
| `MOD_DELETE_INSTANCE` | | | ✓ |
96+
97+
For the messages in the user column, the kernel only selects the target core from the module
98+
and forwards the message unchanged. DP modules and modules on another core are created by the
99+
kernel in `ipc4_init_module_instance()`. With `CONFIG_SOF_USERSPACE_APPLICATION`, the IPCs of a
100+
DP module are then passed on to its DP thread (`scheduler_dp_thread_ipc()`).
101+
102+
The other global messages (boot config, ROM control, performance measurements, multiple module
103+
load and unload, pipeline state get, context size, save and restore, internal messages and
104+
notifications) and the module restore messages are not implemented and are rejected by the
105+
routers.
106+
44107
## Processing Flows
45108

46109
### Pipeline State Management (`ipc4_set_pipeline_state`)

0 commit comments

Comments
 (0)