|
1 | 1 | # IPC4 Architecture |
2 | 2 |
|
3 | 3 | > **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). |
9 | 11 |
|
10 | 12 | 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. |
11 | 13 |
|
@@ -41,6 +43,67 @@ graph TD |
41 | 43 | end |
42 | 44 | ``` |
43 | 45 |
|
| 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 | + |
44 | 107 | ## Processing Flows |
45 | 108 |
|
46 | 109 | ### Pipeline State Management (`ipc4_set_pipeline_state`) |
|
0 commit comments