Page MenuHomeFreeBSD

asmc: add raw SMC key read/write interface
AcceptedPublic

Authored by guest-seuros on Wed, Dec 31, 6:54 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jan 10, 4:31 PM
Unknown Object (File)
Sat, Jan 10, 2:52 AM
Unknown Object (File)
Fri, Jan 9, 10:32 PM
Unknown Object (File)
Fri, Jan 9, 6:49 AM
Unknown Object (File)
Thu, Jan 8, 3:15 AM
Unknown Object (File)
Mon, Jan 5, 10:34 PM
Unknown Object (File)
Mon, Jan 5, 12:37 PM
Unknown Object (File)
Mon, Jan 5, 2:46 AM
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 Skipped
Unit
Tests Skipped

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