Skip to content

refactor: adopt virtual-ID ABI and per-device context for SCMI protocols - #110

Merged
agicy merged 16 commits into
syswonder:mainfrom
agicy:refactor/virtio-scmi
Aug 11, 2026
Merged

agicy merged 16 commits into
syswonder:mainfrom
agicy:refactor/virtio-scmi

Conversation

@agicy

@agicy agicy commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Refactor the virtio-scmi implementation to replace the phandle-based ABI with a virtual-ID ABI, and move from global protocol registration to per-device context. This prepares the way for multi-device SCMI support and eliminates dependencies on static phandle values.

Driver changes (driver/)

  • Split monolithic scmi_server.c into per-protocol files under driver/virtio/scmi/{server,clock,power,reset}.c. Each protocol is independently initialized from the hvisor DT node's clocks/resets/ power-domains properties using of_count_phandle_with_args().
  • Virtual-ID ABI: Clock, reset, and power domains are identified by their index in the hvisor device tree node, not by phandle. The old SET_PHANDLE ioctl subcommands are removed.
  • Lifecycle helpers: hvisor_scmi_init() / hvisor_scmi_cleanup() provide symmetric init/teardown with proper error-path rollback.
  • Resource caching: Clock and reset controls are cached after first lookup (of_clk_get / __of_reset_control_get) and released at module exit, avoiding repeated DT traversals.
  • Deleted reset-domains.c: The old dynamic reset-controller walk was replaced by direct DT property access, matching the approach used for clocks and power domains.

Tools changes (tools/)

  • Per-device protocol registration: Replaced the global scmi_protocol table with scmi_dev_register_protocol(), storing protocol handlers in SCMIDev. This allows multiple SCMI device instances with different protocol sets.
  • ID arrays instead of phandle/map: JSON config now uses direct clock_ids/reset_ids/power_ids arrays instead of *_phandle + *_max_num + allowed_list + *_map. The wildcard "*" syntax is replaced by explicit ID enumeration.
  • scmi_resp_ctx for safe response buffer tracking: all protocol handlers now use scmi_resp_write() to advance a write cursor, catching buffer overflows at write time.
  • Unified ioctl helper: hvisor_scmi_ioctl_cmd() uses the persistent ko_fd (opened once in virtio_start()), removing repeated open/close of /dev/hvisor.
  • Conditional compilation removed: ENABLE_VIRTIO_SCMI is gone — SCMI is always compiled in, reducing build complexity.

Compatibility

All kernel APIs used (genpd_dev_pm_attach_by_id, __of_reset_control_get, etc.) are available since Linux v5.1 or earlier. The code builds and runs on Linux 6.1 without regression.

References

Closes: #106, #107.
Refactor: #84.

@agicy
agicy force-pushed the refactor/virtio-scmi branch 2 times, most recently from 11651d3 to 57a8665 Compare July 29, 2026 07:22
@agicy
agicy force-pushed the refactor/virtio-scmi branch from 57a8665 to f6b0b72 Compare August 4, 2026 14:51
Comment thread driver/hvisor_main.c Outdated
Comment thread tools/virtio/devices/scmi/virtio_scmi.c
Comment thread examples/rk3588-aarch64/with_virtio_scmi/virtio_cfg.json Outdated
@agicy
agicy force-pushed the refactor/virtio-scmi branch from f6b0b72 to 4fbff3c Compare August 10, 2026 15:45
Comment thread driver/virtio/scmi/clock.c
@agicy
agicy requested a review from ForeverYolo August 10, 2026 16:19
@agicy
agicy force-pushed the refactor/virtio-scmi branch from 4fbff3c to 9e33198 Compare August 11, 2026 03:51

@ForeverYolo ForeverYolo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The issues from the last round have all been resolved, thanks for your cooperation!

Found the last issue while reviewing the code. Once this is fixed, the PR can be merged.

Comment thread driver/virtio/scmi/clock.c
@ForeverYolo

Copy link
Copy Markdown
Contributor

LGTM.

@agicy
agicy merged commit eb4b4c4 into syswonder:main Aug 11, 2026
1 check passed
@agicy
agicy deleted the refactor/virtio-scmi branch August 11, 2026 11:46
agicy added a commit that referenced this pull request Aug 24, 2026
refactor: adopt virtual-ID ABI and per-device context for SCMI protocols
agicy added a commit that referenced this pull request Aug 24, 2026
refactor: adopt virtual-ID ABI and per-device context for SCMI protocols
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.

virtio-scmi: reset driver depends on EXPORT_SYMBOL for internal kernel symbols

2 participants