Skip to content

Commit 2fe741a

Browse files
committed
userspace: doc: describe the kernel DMA and chain DMA handling
Update the LL memory region section with the objects that are now in the kernel areas, the loadable drivers in the RO area and the DMA channel arrays in the RW area. Describe how chain DMA messages are handled and how kernel code drives DMA without trusting dma[], and note that kernel threads no longer use the LL user heap, while the heap system calls still run the allocator in supervisor mode. Move GLB_CHAIN_DMA to the kernel and user messages in the IPC4 routing table. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent a3b0bdb commit 2fe741a

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

‎src/include/sof/userspace/README.md‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,15 @@ calls from LL threads: only kernel threads can write objects there.
190190
Objects in the kernel areas:
191191

192192
- RO: the user scheduler list heads and descriptors (`struct schedule_data`, including the
193-
scheduler ops), and the LL allocation context `ipc->ll_alloc`. Kernel code finds the user
194-
scheduler lists through a kernel-only copy of the per-core list heads.
193+
scheduler ops), the LL allocation context `ipc->ll_alloc`, and the drivers of the loadable
194+
modules (`struct comp_driver`, including the component ops), which are never unregistered.
195+
Kernel code finds the user scheduler lists through a kernel-only copy of the per-core list
196+
heads.
195197
- RW: `struct ipc_user`, the IPC data buffer `ipc->comp_data`, the LL scheduler state
196198
(`struct zephyr_ll`), the LL scheduling domain and its Zephyr domain data, the DP scheduler
197-
data, and the LL tasks that kernel threads create at boot together with their task data.
199+
data, the LL tasks that kernel threads create at boot together with their task data, and
200+
the DMA channel arrays. A channel array is allocated on the first `sof_dma_get()` of its
201+
controller and kept in the kernel-only `struct sof_dma_kinfo` for the next one.
198202

199203
DP modules are created by kernel code, but their allocation context, pin format arrays and
200204
configuration buffers are in the module's own vregion, released with it, and the IPC user
@@ -205,9 +209,20 @@ The LL timer interrupt and the LL thread setup and teardown use kernel-only copi
205209
domain data pointer, the per-core semaphores and the LL threads, not the user-writable domain
206210
data.
207211

208-
The LL user heap keeps its `sys_heap` metadata in user-writable memory. Kernel code is being
209-
moved off it; `CONFIG_SOF_ZEPHYR_LL_HEAP_KERNEL_TRACE` logs the remaining uses by kernel
210-
threads. Kernel code still follows some pointers stored in user-writable memory, for example
212+
Chain DMA messages are forwarded to the IPC user thread like the pipeline messages, so the
213+
chain DMA component is created, run and freed in user space. The kernel only looks up the
214+
driver, and takes the runtime idle PM lock of a started chain itself, tracked in a kernel-only
215+
mask of host DMA channels. The IPC gateway is not supported and is disabled in the LL overlay.
216+
217+
User threads can write the `dma[]` array, so kernel code drives DMA through the `sof_dma_*()`
218+
wrappers, which take the Zephyr device from `struct sof_dma_kinfo` (`sof_dma_kdev()`), and
219+
never calls the Zephyr DMA API on `dma->z_dev`.
220+
221+
The LL user heap keeps its `sys_heap` metadata in user-writable memory. Kernel threads no
222+
longer allocate from it or free to it; `CONFIG_SOF_ZEPHYR_LL_HEAP_KERNEL_TRACE` logs any use
223+
by a kernel thread. User threads still allocate from it through the `sof_heap_alloc()` and
224+
`sof_heap_free()` system calls, so the allocator still runs in supervisor mode on this
225+
metadata. Kernel code still follows some pointers stored in user-writable memory, for example
211226
`task->sch` and the domain `ops`.
212227

213228
## Memory-partition markers

‎src/ipc/ipc4/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ graph TD
6666
Host[Host IPC] --> Disp["handler-kernel.c<br/>ipc4_process_glb/module_message()"]
6767
Disp -->|kernel only| KOnly["library load, D0ix/Dx"]
6868
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"]
69+
Routers -->|kernel only| KRouted["IPC gateway, GDB,<br/>base firmware LARGE_CONFIG"]
7070
Routers --> Route{"ipc4_route_*()"}
7171
Route -->|CONFIG_SOF_USERSPACE_LL| LLUser["handler-ll-user.c<br/>target core, driver lookup,<br/>module load, multicore sequencing"]
7272
Route -->|otherwise| LLKernel["handler-ll-kernel.c<br/>direct call"]
@@ -80,14 +80,14 @@ With `CONFIG_SOF_USERSPACE_LL`, the messages are handled as follows:
8080
| Message | Kernel only | Kernel and user | User |
8181
|---|---|---|---|
8282
| `GLB_LOAD_LIBRARY`, `GLB_LOAD_LIBRARY_PREPARE` | ✓ library manager | | |
83-
| `GLB_CHAIN_DMA` | ✓ | | |
84-
| `GLB_IPCGATEWAY_CMD` | ✓ | | |
83+
| `GLB_IPCGATEWAY_CMD` | ✓ (the IPC gateway is disabled in the LL overlay) | | |
8584
| `GLB_ENTER_GDB` | ✓ | | |
8685
| `MOD_SET_D0IX`, `MOD_SET_DX` | ✓ power management | | |
8786
| `MOD_LARGE_CONFIG_GET`/`SET`, base firmware (module_id 0) | ✓ reads the IMR manifest | | |
8887
| `GLB_CREATE_PIPELINE` | | kernel: target core; user: pipeline creation | |
8988
| `GLB_DELETE_PIPELINE` | | kernel: owning core; user: pipeline free | |
9089
| `GLB_SET_PIPELINE_STATE` | | kernel: pipeline list check, multicore prepare/trigger sequencing; user: prepare and trigger | |
90+
| `GLB_CHAIN_DMA` | | kernel: driver lookup, runtime idle PM lock of started chains; user: chain DMA creation, state changes and free | |
9191
| `MOD_INIT_INSTANCE` | | kernel: driver lookup, loadable module setup; user: component creation | |
9292
| `MOD_CONFIG_GET`/`SET` | | | ✓ |
9393
| `MOD_LARGE_CONFIG_GET`/`SET`, modules | | | ✓ |

0 commit comments

Comments
 (0)