Instead of waiting for the inbound item to show up in the interrupt
authorpatrick <patrick@openbsd.org>
Tue, 4 Jul 2023 14:32:21 +0000 (14:32 +0000)
committerpatrick <patrick@openbsd.org>
Tue, 4 Jul 2023 14:32:21 +0000 (14:32 +0000)
handler, allocate it ourselves.  The firmware doesn't seem to mind
that it's us doing the allocation.  This fixes a splassert, because
the code that retrieves the item reaches through the shared memory
driver, which acquires the hardware mutex, which in turn mallocs.

ok kettenis@

sys/dev/fdt/qcsmptp.c

index 50fe857..40f68c9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: qcsmptp.c,v 1.1 2023/05/19 21:26:10 patrick Exp $     */
+/*     $OpenBSD: qcsmptp.c,v 1.2 2023/07/04 14:32:21 patrick Exp $     */
 /*
  * Copyright (c) 2023 Patrick Wildt <patrick@blueri.se>
  *
@@ -182,6 +182,18 @@ qcsmptp_deferred(struct device *self)
                return;
        }
 
+       if (qcsmem_alloc(sc->sc_remote_pid, sc->sc_smem_id[0],
+           sizeof(*sc->sc_in)) != 0) {
+               printf(": can't alloc smp2p item\n");
+               return;
+       }
+
+       sc->sc_in = qcsmem_get(sc->sc_remote_pid, sc->sc_smem_id[0], NULL);
+       if (sc->sc_in == NULL) {
+               printf(": can't get smp2p item\n");
+               return;
+       }
+
        if (qcsmem_alloc(sc->sc_remote_pid, sc->sc_smem_id[1],
            sizeof(*sc->sc_out)) != 0) {
                printf(": can't alloc smp2p item\n");
@@ -254,15 +266,6 @@ qcsmptp_intr(void *arg)
        uint32_t changed, val;
        int do_ack = 0, i;
 
-       /* Inbound item exists as soon as remoteproc is up. */
-       if (sc->sc_in == NULL)
-               sc->sc_in = qcsmem_get(sc->sc_remote_pid,
-                   sc->sc_smem_id[0], NULL);
-       if (sc->sc_in == NULL) {
-               printf("%s: can't get smp2p item\n", sc->sc_dev.dv_xname);
-               return 1;
-       }
-
        /* Do initial feature negotiation if inbound is new. */
        if (!sc->sc_negotiated) {
                if (sc->sc_in->version != sc->sc_out->version)