Skip to content

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

Open
agicy wants to merge 13 commits into
syswonder:mainfrom
agicy:refactor/virtio-scmi
Open

refactor: adopt virtual-ID ABI and per-device context for SCMI protocols#110
agicy wants to merge 13 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 from 132b15e to 11651d3 Compare July 27, 2026 14:18
@agicy
agicy force-pushed the refactor/virtio-scmi branch from 11651d3 to 57a8665 Compare July 29, 2026 07:22
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

1 participant