Skip to content

ASoC: SOF: add hostless FE PCM support and ultrasonic gesture sensing client - #6074

Draft
lgirdwood wants to merge 3 commits into
thesofproject:topic/sof-devfrom
lgirdwood:topic/ultrasound-gesture
Draft

lgirdwood wants to merge 3 commits into
thesofproject:topic/sof-devfrom
lgirdwood:topic/ultrasound-gesture

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Summary

Companion Linux kernel PR for SOF DSP-autonomous ultrasonic Doppler gesture and presence sensing:

Commits

  1. ASoC: SOF: core: support hostless DSP-autonomous FE PCM streams
    • Recognizes virtual aif_in/aif_out topology widgets with priv.size == 0 as swidget->hostless / spcm->stream[dir].hostless.
    • Skips DSP host-copier creation, virtual AIF 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.
    • Extends S0ix suspend_ignored and hda_dai_has_wov_fe() so hostless D0i3-compatible playback and capture streams (including ignore_suspend=1 links) retain DSP pipelines and BE links in D0I3 across s2idle.
  2. ASoC: SOF: ipc4: dispatch IPC4 RX notifications to SOF client drivers
    • Calls sof_client_ipc_rx_dispatcher() from sof_ipc4_rx_msg().
    • Fixes the IPC4 notification type bounds check in sof_client_register_ipc_rx_handler() (ipc_msg_type >= SOF_IPC4_NOTIFY_TYPE_LAST), defines SOF_IPC4_NOTIFY_MODULE_EVENTID_GESTURE_MAGIC_VAL, and exports sof_client_get_component().
  3. ASoC: SOF: client: add ultrasonic gesture and presence sensing driver
    • Adds CONFIG_SND_SOC_SOF_ULTRASOUND (snd-sof-ultrasound, depends on SND_SOC_SOF && SND_SOC_SOF_IPC4 && INPUT) and UAPI header include/uapi/sound/sof/ultrasound.h.
    • Manages hostless Ultrasound TX / Ultrasound RX PCMs directly in kernel space (auto-enabled on /dev/sof-ultrasound<N> open or via sysfs enable) with dynamic ignore_suspend save/restore.
    • Exposes /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 both CONFIG_SND_SOC_SOF_ULTRASOUND=m and =n.
  • Hardware-verified on Ladybird: hostless bring-up via sysfs and auto-enable on /dev/sof-ultrasound0 open, clean D3 teardown on close, zero host DMA period IRQs, simultaneous speaker playback & DMIC capture coexistence, 7/7 gesture & presence events with dropped=0, automatic D0I3 entry, and clean rtcwake -m freeze -s 4 (s2idle) retention without FW reload.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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
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

Comment thread sound/soc/sof/sof-audio.c Outdated
Comment on lines 495 to 496
if (!swidget || swidget->hostless)
goto sink_prepare;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +186 to +188
mutex_lock(&pcm->open_mutex);
err = snd_pcm_open_substream(pcm, dir, &priv->dummy_file, &substream);
mutex_unlock(&pcm->open_mutex);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +355 to +357
/* 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);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment on lines +691 to +693
mutex_lock(&priv->ctrl_mutex);
if (!priv->sysfs_enabled && priv->sensing_active)
sof_ultrasound_stop_sensing_locked(priv);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread sound/soc/sof/sof-client-ultrasound.c Outdated
priv->miscdev.groups = sof_ultrasound_groups;
priv->miscdev.parent = &auxdev->dev;

ret = misc_register(&priv->miscdev);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 <liam.r.girdwood@linux.intel.com>
…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 <liam.r.girdwood@linux.intel.com>
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 <liam.r.girdwood@linux.intel.com>
@lgirdwood
lgirdwood force-pushed the topic/ultrasound-gesture branch from 90f9c28 to afe5b56 Compare December 1, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants