Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Critical error-path and PCM lifetime bugs can crash the kernel, while missing suspend/resume handling can leave sensing streams unable to recover after S3 or hibernation.
5 open issues
Initialize widget_ops before bypassing hostless widgets · New Protect kernel-owned PCM streams through card disconnect · New Handle kernel-owned PCM streams across system suspend · New Recheck reader count under lock before stopping sensing · New Register the misc device only after IPC handler setup · New
What changed in this PR
Adds Linux SOF support for DSP-autonomous ultrasonic gesture and presence sensing, complementing the linked firmware/topology PR.
Changes:
- Supports hostless frontend PCM streams without host DMA, including S0ix pipeline retention.
- Routes IPC4 notifications to SOF clients.
- Adds an ultrasound client with stream control, event delivery, input reporting, and sysfs telemetry.
| File | Description |
|---|---|
sound/soc/sof/topology.c |
Identifies hostless AIF widgets and skips their DSP setup. |
sound/soc/sof/sof-client.h |
Declares the component-access helper. |
sound/soc/sof/sof-client.c |
Registers the ultrasound client and corrects notification validation. |
sound/soc/sof/sof-client-ultrasound.c |
Implements sensing lifecycle and userspace interfaces. |
sound/soc/sof/sof-audio.h |
Adds hostless stream and widget flags. |
sound/soc/sof/sof-audio.c |
Handles hostless widget traversal and suspend retention. |
sound/soc/sof/pcm.c |
Bypasses host DMA operations for hostless streams. |
sound/soc/sof/Makefile |
Adds the ultrasound module build target. |
sound/soc/sof/Kconfig |
Adds the ultrasound configuration option. |
sound/soc/sof/ipc4.c |
Dispatches received notifications to clients. |
sound/soc/sof/ipc4-pcm.c |
Skips host timestamp setup for hostless streams. |
sound/soc/sof/intel/hda-dai.c |
Extends backend retention to compatible hostless streams. |
include/uapi/sound/sof/ultrasound.h |
Defines event records and ioctl interfaces. |
include/sound/sof/ipc4/header.h |
Defines the gesture notification identifier. |
Review effort: Balanced
| if (!swidget || swidget->hostless) | ||
| goto sink_prepare; |
There was a problem hiding this comment.
Fixed in 3e2f44e: moved widget_ops lookup and NULL validation ahead of if (!swidget || swidget->hostless) goto sink_prepare; so downstream preparation errors never unwind with an uninitialized widget_ops.
| mutex_lock(&pcm->open_mutex); | ||
| err = snd_pcm_open_substream(pcm, dir, &priv->dummy_file, &substream); | ||
| mutex_unlock(&pcm->open_mutex); |
There was a problem hiding this comment.
Fixed in e7e5add and afe5b56: registered a SNDRV_DEV_LOWLEVEL card-disconnect hook in sof_pcm_probe() dispatching to client drivers under a dedicated sdev->card_disconnect_mutex (separate from client_event_handler_mutex so blocking PCM/IPC/SoundWire teardown never blocks sof_client_ipc_rx_dispatcher() in the shared AudioDSP IRQ thread), cleared sdev->component in sof_pcm_remove(), and held try_module_get(snd_card->module) + snd_card_file_add()/snd_card_file_remove() (balancing fops_put() if snd_card_disconnect() swapped f_op to &snd_shutdown_f_ops) while sensing is active. Live-verified on Ladybird WCL: unbinding sof_sdw while hostless sensing is running cleanly stops/releases both streams in ~365 ms with zero hang/oops/UAF, and re-binding cleanly restarts sensing.
| /* Approach B: mark FE and BE links ignore_suspend while hostless sensing is active */ | ||
| sof_ultrasound_save_ignore_suspend(priv, tx_rtd->dai_link); | ||
| sof_ultrasound_save_ignore_suspend(priv, rx_rtd->dai_link); |
There was a problem hiding this comment.
Fixed in e7e5add and afe5b56: exported sof_client_is_s0ix_suspend() and added sof_ultrasound_pm_ops (.prepare/.complete via pm_sleep_ptr()). On non-S0ix sleep (S3/hibernation), pm_prepare() tears down the kernel-owned streams and restores ignore_suspend before ASoC/SOF suspend, and pm_complete() restarts sensing after resume if still enabled or readers remain; S0ix (s2idle) continues preserving running streams in D0i3 (live-verified on Ladybird via rtcwake -m freeze -s 4).
| mutex_lock(&priv->ctrl_mutex); | ||
| if (!priv->sysfs_enabled && priv->sensing_active) | ||
| sof_ultrasound_stop_sensing_locked(priv); |
There was a problem hiding this comment.
Fixed in afe5b56: re-checked priv->active_readers == 0 under priv->lock after acquiring priv->ctrl_mutex in sof_ultrasound_release() before stopping sensing. Verified on Ladybird with overlapping open/close readers.
| priv->miscdev.groups = sof_ultrasound_groups; | ||
| priv->miscdev.parent = &auxdev->dev; | ||
|
|
||
| ret = misc_register(&priv->miscdev); |
There was a problem hiding this comment.
Fixed in afe5b56: reordered sof_ultrasound_probe() to register the input device, IPC4 RX handler, and card-disconnect handler before calling misc_register(&priv->miscdev), with full reverse unwind on failure.
Enable front-end PCM streams that are driven autonomously inside the DSP without allocating or triggering a Host HDA DMA channel or instantiating a DSP host-copier module (e.g. always-on ultrasonic TX tone generation and terminal RX Doppler gesture detection). When an aif_in/aif_out topology widget carries zero private token payload (tw->priv.size == 0), mark swidget->hostless and propagate it to spcm->stream[dir].hostless: - Skip DSP copier creation and IPC4 MOD_BIND on the virtual AIF widget while still traversing connected DSP processing and BE pipelines (with widget_ops initialized before the hostless jump so downstream unwind is always safe). - Skip Host DMA open, hw_params, trigger, hw_free, close, page-table setup, and host/DAI time_info registration; advertise SNDRV_PCM_INFO_RESUME for seamless S0ix retention. - Allow hostless D0i3-compatible playback and capture streams (including those with ignore_suspend=1 on their FE DAI link) to keep both DSP pipelines and their connected BE DAI links running in D0i3 across S0ix suspend/resume. Signed-off-by: Liam Girdwood <[email protected]>
…cle helpers Wire sof_client_ipc_rx_dispatcher() into sof_ipc4_rx_msg() so auxiliary SOF client drivers can subscribe to IPC4 firmware notifications (such as SOF_IPC4_NOTIFY_MODULE_NOTIFICATION). Also fix the IPC4 notification type bounds check in sof_client_register_ipc_rx_handler() (ipc_msg_type is a shifted enum value, not a pre-shifted header mask, so validate against SOF_IPC4_NOTIFY_TYPE_LAST), define the gesture module notification magic prefix SOF_IPC4_NOTIFY_MODULE_EVENTID_GESTURE_MAGIC_VAL, and export helpers needed by client drivers managing kernel-owned hostless streams: - sof_client_get_component() (clearing sdev->component in sof_pcm_remove) - sof_client_is_s0ix_suspend() to distinguish retained-D0 S0ix from S3/S4 - sof_client_register/unregister_card_disconnect_handler() invoked from a SNDRV_DEV_LOWLEVEL card device registered in sof_pcm_probe() under a dedicated sdev->card_disconnect_mutex (separate from client_event_handler_mutex so blocking PCM/IPC/SoundWire teardown never blocks sof_client_ipc_rx_dispatcher() in the shared AudioDSP IRQ thread) Signed-off-by: Liam Girdwood <[email protected]>
Add the snd-sof-ultrasound auxiliary client driver
(CONFIG_SND_SOC_SOF_ULTRASOUND) and UAPI header
(include/uapi/sound/sof/ultrasound.h) for DSP-autonomous ultrasonic
Doppler gesture and presence sensing on IPC4 platforms:
- Kernel-managed hostless stream lifecycle: opens, configures (48 kHz
S32_LE, NO_PERIOD_WAKEUP, zero host DMA), and starts the hostless
"Ultrasound TX" and "Ultrasound RX" DPCM streams either automatically
when a userspace reader opens /dev/sof-ultrasound<N> (auto_enable=1) or
explicitly via /sys/class/misc/sof-ultrasound<N>/enable.
- Card lifetime & disconnect safety: holds a card module reference and
tracks an ALSA card file via snd_card_file_add()/snd_card_file_remove()
while sensing is active, and registers a card-disconnect handler so
independent machine/card unbind stops and releases the kernel-owned
streams before snd_card_disconnect_sync() waits on active card files.
- System PM lifecycle: preserves running hostless streams and
ignore_suspend only during S0ix (retained D0/D0i3); on non-S0ix
suspend (S3/hibernation), tears down the streams in pm_prepare() and
restarts them in pm_complete() after resume.
- Userspace event interfaces (published only after input device, IPC4 RX
handler, and card-disconnect handler registration succeed):
1. /dev/sof-ultrasound<N> multi-reader kfifo supporting read(), poll(),
SOF_ULTRASOUND_IOC_GET_STATS, and SOF_ULTRASOUND_IOC_FLUSH.
2. Linux input device ("SOF Ultrasound Gesture") emitting EV_MSC /
MSC_GESTURE and EV_SW / SW_FRONT_PROXIMITY events.
3. Sysfs controls and telemetry (enable, active, auto_enable, stats,
last_event).
Signed-off-by: Liam Girdwood <[email protected]>
90f9c28 to
afe5b56
Compare


Summary
Companion Linux kernel PR for SOF DSP-autonomous ultrasonic Doppler gesture and presence sensing:
Commits
ASoC: SOF: core: support hostless DSP-autonomous FE PCM streamsaif_in/aif_outtopology widgets withpriv.size == 0asswidget->hostless/spcm->stream[dir].hostless.MOD_BIND, and all Host HDA DMA operations (open/hw_params/trigger/hw_free/close/page-table/time_info) while keeping connected DSP and BE pipelines active.suspend_ignoredandhda_dai_has_wov_fe()so hostless D0i3-compatible playback and capture streams (includingignore_suspend=1links) retain DSP pipelines and BE links inD0I3acrosss2idle.ASoC: SOF: ipc4: dispatch IPC4 RX notifications to SOF client driverssof_client_ipc_rx_dispatcher()fromsof_ipc4_rx_msg().sof_client_register_ipc_rx_handler()(ipc_msg_type >= SOF_IPC4_NOTIFY_TYPE_LAST), definesSOF_IPC4_NOTIFY_MODULE_EVENTID_GESTURE_MAGIC_VAL, and exportssof_client_get_component().ASoC: SOF: client: add ultrasonic gesture and presence sensing driverCONFIG_SND_SOC_SOF_ULTRASOUND(snd-sof-ultrasound, depends onSND_SOC_SOF && SND_SOC_SOF_IPC4 && INPUT) and UAPI headerinclude/uapi/sound/sof/ultrasound.h.Ultrasound TX/Ultrasound RXPCMs directly in kernel space (auto-enabled on/dev/sof-ultrasound<N>open or via sysfsenable) with dynamicignore_suspendsave/restore./dev/sof-ultrasound<N>(multi-reader kfifo,read/poll/ioctl), Linux input device ("SOF Ultrasound Gesture",EV_MSC/MSC_GESTURE&EV_SW/SW_FRONT_PROXIMITY), and sysfs telemetry.Verification (Wildcat Lake / ACE 3.0 + RT722 + 4-ch Intel PDM DMIC)
scripts/checkpatch.pl: 0 errors, 0 warnings across all 3 patches.make M=sound/soc/sof W=1: 0 warnings with bothCONFIG_SND_SOC_SOF_ULTRASOUND=mand=n./dev/sof-ultrasound0open, clean D3 teardown on close, zero host DMA period IRQs, simultaneous speaker playback & DMIC capture coexistence, 7/7 gesture & presence events withdropped=0, automaticD0I3entry, and cleanrtcwake -m freeze -s 4(s2idle) retention without FW reload.