asmc: add raw SMC key read/write interface

This patch adds a debugging interface to read and write arbitrary
Apple SMC keys by name through sysctl, enabling hardware exploration
 and control of undocumented features.

The interface provides four sysctls under dev.asmc.0.raw.*:
  - key - Set the 4-character SMC key name (e.g., "AUPO")
  - value - Read/write key value as a hex string
  - len - Auto-detected key value length (can be overridden)
  - type - Read-only 4-character type string (e.g., "ui8", "flt")

Implementation includes a new asmc_key_getinfo() function using SMC
command 0x13 to query key metadata. The interface automatically
detects key lengths and types, uses hex string encoding for
arbitrary binary values, and is safe for concurrent access via
CTLFLAG_NEEDGIANT.

This interface was essential for discovering that the AUPO key
enables Wake-on-LAN from S5 state, and for mapping all 297 SMC keys
on Mac Mini 5,1.

Reviewed by:	ngie, adrian, markj
Differential Revision:	https://reviews.freebsd.org/D54441
This commit is contained in:
Abdelkader Boudih
2026-04-14 21:20:52 -07:00
committed by Adrian Chadd
parent 6b00c652db
commit 3e27114a7f
3 changed files with 288 additions and 47 deletions
+29
View File
@@ -112,6 +112,35 @@ minimum fan speed, the minimum speed and the maximum speed
respectively.
.Pp
All values are in RPM.
.Sh RAW SMC KEY ACCESS
When the kernel is compiled with the
.Dv ASMC_DEBUG
option, a set of sysctl nodes is provided under
.Va dev.asmc.%d.raw
for reading and writing arbitrary SMC keys by name.
.Pp
.Bl -tag -width "dev.asmc.%d.raw.value" -compact
.It Va dev.asmc.%d.raw.key
Set the 4-character SMC key name to access (e.g.,\&
.Dq AUPO ) .
Setting this automatically queries the key's length and type.
.It Va dev.asmc.%d.raw.value
Read or write the key's value as a hex string.
.It Va dev.asmc.%d.raw.len
The auto-detected value length in bytes (read-only).
.It Va dev.asmc.%d.raw.type
The 4-character SMC type string (e.g.,\&
.Dq ui8 ,
.Dq flt )
(read-only).
.El
.Pp
Example usage:
.Bd -literal -offset indent
sysctl dev.asmc.0.raw.key=AUPO
sysctl dev.asmc.0.raw.value
sysctl dev.asmc.0.raw.value=01
.Ed
.Sh SUDDEN MOTION SENSOR
The Sudden Motion Sensor (SMS for short) is a device that detects
laptop movement and notifies the operating system via an interrupt.