Page MenuHomeFreeBSD

asmc: add raw SMC key read/write interface
Needs ReviewPublic

Authored by guest-seuros on Dec 31 2025, 6:54 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jan 24, 6:33 PM
Unknown Object (File)
Sat, Jan 17, 6:14 PM
Unknown Object (File)
Sat, Jan 17, 5:46 PM
Unknown Object (File)
Sat, Jan 17, 11:27 AM
Unknown Object (File)
Sat, Jan 17, 11:23 AM
Unknown Object (File)
Tue, Jan 13, 10:21 PM
Unknown Object (File)
Tue, Jan 13, 10:04 PM
Unknown Object (File)
Mon, Jan 12, 8:16 PM
Subscribers

Details

Reviewers
adrian
markj
imp
Summary

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.

Test Plan

Testing this is a little tricky :

sysctl dev.asmc.0.raw.key=AUPO
sysctl dev.asmc.0.raw.value # Returns "00" or "01"
sysctl dev.asmc.0.raw.type # Returns "ui8 "

sysctl dev.asmc.0.raw.value=01 # Enable WoL
sysctl dev.asmc.0.raw.value=00 # Disable WoL

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 70383
Build 67266: arc lint + arc unit

Event Timeline

guest-seuros created this revision.
sys/dev/asmc/asmc.c
1239

I see this pattern was copied from elsewhere, but it'd still be nice to have a proper loop.

Are the retries actually needed?

1260

Should this be documented in the asmc.4 man page?

1305

This line should be wrapped.

1310

The formatting can be handled with sysctl -x. Should we just provide the raw bytes and let userspace handle formatting?

1341

Missing parens around the return value.

1350

Missing parens around the return value.

sys/dev/asmc/asmc.c
1310
$ sysctl dev.asmc.0.raw.key=AUPO
$ sysctl -x dev.asmc.0.raw.value
dev.asmc.0.raw.value: Format: Length:1 Dump:0x01

However, sysctl -x only handles formatting for output.
For writing, the sysctl tool does not support opaque types at all:

$ sysctl -w dev.asmc.0.raw.value=00
sysctl: oid 'dev.asmc.0.raw.value' is type 5, cannot set that

The hex string approach allowed both.

I'm open to any approach, i already mapped most of this hardware.

markj added inline comments.
sys/dev/asmc/asmc.c
1234

error is never used, you can just return 0 at the end of the function.

This revision is now accepted and ready to land.Fri, Jan 9, 2:22 PM
guest-seuros edited the test plan for this revision. (Show Details)

Make dev.asmc.*.raw.len read-only to prevent user overrides

This revision now requires review to proceed.Wed, Feb 4, 1:34 AM