diff options
| author | Abdelkader Boudih <oss@seuros.com> | 2026-01-03 18:33:11 +0000 |
|---|---|---|
| committer | Adrian Chadd <adrian@FreeBSD.org> | 2026-01-03 18:35:53 +0000 |
| commit | 2a7c4685b7693bfa15e2bd4d5e82905a368b0030 (patch) | |
| tree | c9372c4f70f630113aec21928a79c13ed9dfcdef | |
| parent | 8ac77ea6a3c6ce99d39e1dd4e19adb444b2b4d5a (diff) | |
asmc: improve asmc_dumpall to read actual SMC key count
The asmc_dumpall debug function previously used a hardcoded loop limit
of 0x100 (256) keys with a "XXX magic number" comment.
This change improves asmc_dumpall to:
* Read the actual number of keys from the ASMC_NKEYS SMC key
* Print the key count being dumped for better debugging output
* Loop only up to the actual key count (e.g., 297 on Mac Mini 5,1)
This provides more accurate debug output and removes the magic number.
Tested on Mac Mini 5,1 (FreeBSD 16.0-CURRENT):
* Rebuild kernel with DEBUG enabled in asmc driver
* Boot with new kernel
* Verify dmesg shows "asmc_dumpall: dumping 297 keys" (or actual count)
* Verify all 297 keys are dumped
Differential Revision: https://reviews.freebsd.org/D54436
Reviewed by: markj, adrian
| -rw-r--r-- | sys/dev/asmc/asmc.c | 25 | ||||
| -rw-r--r-- | sys/dev/asmc/asmcvar.h | 1 |
2 files changed, 18 insertions, 8 deletions
diff --git a/sys/dev/asmc/asmc.c b/sys/dev/asmc/asmc.c index d99c1d56e67c..bdb8ca7831c4 100644 --- a/sys/dev/asmc/asmc.c +++ b/sys/dev/asmc/asmc.c @@ -823,10 +823,16 @@ asmc_resume(device_t dev) #ifdef DEBUG void asmc_dumpall(device_t dev) { + struct asmc_softc *sc = device_get_softc(dev); int i; - /* XXX magic number */ - for (i=0; i < 0x100; i++) + if (sc->sc_nkeys == 0) { + device_printf(dev, "asmc_dumpall: key count not available\n"); + return; + } + + device_printf(dev, "asmc_dumpall: dumping %d keys\n", sc->sc_nkeys); + for (i = 0; i < sc->sc_nkeys; i++) asmc_key_dump(dev, i); } #endif @@ -914,12 +920,15 @@ nosms: sc->sc_nfan = ASMC_MAXFANS; } - if (bootverbose) { - /* - * The number of keys is a 32 bit buffer - */ - asmc_key_read(dev, ASMC_NKEYS, buf, 4); - device_printf(dev, "number of keys: %d\n", ntohl(*(uint32_t*)buf)); + /* + * Read and cache the number of SMC keys (32 bit buffer) + */ + if (asmc_key_read(dev, ASMC_NKEYS, buf, 4) == 0) { + sc->sc_nkeys = be32dec(buf); + if (bootverbose) + device_printf(dev, "number of keys: %d\n", sc->sc_nkeys); + } else { + sc->sc_nkeys = 0; } #ifdef DEBUG diff --git a/sys/dev/asmc/asmcvar.h b/sys/dev/asmc/asmcvar.h index d40dc1e7c8ff..b6d8686d9670 100644 --- a/sys/dev/asmc/asmcvar.h +++ b/sys/dev/asmc/asmcvar.h @@ -33,6 +33,7 @@ struct asmc_softc { device_t sc_dev; struct mtx sc_mtx; int sc_nfan; + int sc_nkeys; int16_t sms_rest_x; int16_t sms_rest_y; int16_t sms_rest_z; |
