The branch stable/15 has been updated by ngie: URL: https://cgit.FreeBSD.org/src/commit/?id=afa1058ff70a1850759802ff03124fb4e6772a0e
commit afa1058ff70a1850759802ff03124fb4e6772a0e Author: Abdelkader Boudih <[email protected]> AuthorDate: 2026-01-03 18:33:11 +0000 Commit: Enji Cooper <[email protected]> CommitDate: 2026-02-22 04:05:39 +0000 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 (cherry picked from commit 2a7c4685b7693bfa15e2bd4d5e82905a368b0030) --- sys/dev/asmc/asmc.c | 25 +++++++++++++++++-------- 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 da040b1e434a..5d3b97a065c9 100644 --- a/sys/dev/asmc/asmc.c +++ b/sys/dev/asmc/asmc.c @@ -833,10 +833,16 @@ asmc_resume(device_t dev) #ifdef ASMC_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 @@ -924,12 +930,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 ASMC_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;
