The branch main has been updated by adrian:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=3abc07947c14f5c30e5328d56a2da8dbf8412ebf

commit 3abc07947c14f5c30e5328d56a2da8dbf8412ebf
Author:     Abdelkader Boudih <[email protected]>
AuthorDate: 2026-05-18 14:01:20 +0000
Commit:     Adrian Chadd <[email protected]>
CommitDate: 2026-05-18 14:01:20 +0000

    asmc: fix asmc_key_dump() page fault on T2 MMIO backend
    
    asmc_key_dump() used I/O port macros (ASMC_DATAPORT_WRITE/READ,
    asmc_command()) unconditionally. On T2 Macs, sc_ioport is NULL
    (MMIO backend is used instead), causing a page fault when
    ASMC_DEBUG triggers asmc_dumpall() during attach.
    
    Add an MMIO guard at the top of asmc_key_dump(): delegate to
    asmc_key_dump_by_index() + asmc_key_read() for MMIO devices,
    consistent with the rest of the T2 code paths.
    
    Reviewed by:    adrian
    Differential Revision:  https://reviews.freebsd.org/D56748
---
 sys/dev/asmc/asmc.c | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/sys/dev/asmc/asmc.c b/sys/dev/asmc/asmc.c
index 8cd7842d03fd..30c5da698361 100644
--- a/sys/dev/asmc/asmc.c
+++ b/sys/dev/asmc/asmc.c
@@ -45,6 +45,7 @@
 #include <sys/malloc.h>
 #include <sys/module.h>
 #include <sys/mutex.h>
+#include <sys/sbuf.h>
 #include <sys/sysctl.h>
 #include <sys/systm.h>
 #include <sys/taskqueue.h>
@@ -1090,6 +1091,27 @@ asmc_key_dump(device_t dev, int number)
        uint8_t maxlen;
        int i, error = 1, try = 0;
 
+       if (sc->sc_is_mmio) {
+               uint8_t len = 0;
+               char mmio_type[ASMC_TYPELEN + 1] = { 0 };
+               if (asmc_key_dump_by_index(dev, number, key, mmio_type, &len))
+                       return (1);
+               memset(v, 0, sizeof(v));
+               len = MIN(len, sizeof(v));
+               asmc_key_read(dev, key, v, len);
+               struct sbuf sb;
+               char buf[128];
+               sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
+               sbuf_printf(&sb, "key %d: %s, type %s (len %d), data",
+                   number, key, mmio_type, len);
+               for (i = 0; i < len; i++)
+                       sbuf_printf(&sb, " %02x", v[i]);
+               sbuf_finish(&sb);
+               device_printf(dev, "%s\n", sbuf_data(&sb));
+               sbuf_delete(&sb);
+               return (0);
+       }
+
        mtx_lock_spin(&sc->sc_mtx);
 
        index[0] = (number >> 24) & 0xff;
@@ -1150,19 +1172,23 @@ out:
        maxlen = type[0];
        type[0] = ' ';
        type[5] = '\0';
-       if (maxlen > sizeof(v))
-               maxlen = sizeof(v);
+       maxlen = MIN(maxlen, sizeof(v));
 
        memset(v, 0, sizeof(v));
        error = asmc_key_read(dev, key, v, maxlen);
        if (error)
                return (error);
 
-       device_printf(dev, "key %d: %s, type%s (len %d), data",
+       struct sbuf sb;
+       char buf[128];
+       sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
+       sbuf_printf(&sb, "key %d: %s, type%s (len %d), data",
            number, key, type, maxlen);
        for (i = 0; i < maxlen; i++)
-               printf(" %02x", v[i]);
-       printf("\n");
+               sbuf_printf(&sb, " %02x", v[i]);
+       sbuf_finish(&sb);
+       device_printf(dev, "%s\n", sbuf_data(&sb));
+       sbuf_delete(&sb);
 
        return (0);
 }

Reply via email to