The branch stable/14 has been updated by ngie:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=26f41f8e5ebee7faf2fb9a65baa18bb41ad63564

commit 26f41f8e5ebee7faf2fb9a65baa18bb41ad63564
Author:     Abdelkader Boudih <[email protected]>
AuthorDate: 2026-01-03 18:33:11 +0000
Commit:     Enji Cooper <[email protected]>
CommitDate: 2026-02-22 04:04:06 +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 3c63e959fc9f..e4b1afa9619d 100644
--- a/sys/dev/asmc/asmc.c
+++ b/sys/dev/asmc/asmc.c
@@ -806,10 +806,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
@@ -897,12 +903,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 73a8fc449c2c..b2fa62f8b6af 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;

Reply via email to