This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 652689a543ef5e74aa6b29e156026b664909a388
Author: wangshaoxin <[email protected]>
AuthorDate: Wed Sep 9 16:40:55 2026 +0800

    drivers/reset: add reset_ipc cross-core panic/reset module
    
    Add reset_ipc, a standalone multicore panic/reset coordination module
    (pause / panic / poweroff handshake over a pair of shared status words
    plus an IPI) that multiple cross-core transports can share.  The
    mechanism is transport-agnostic: everything it needs from the transport
    is abstracted behind reset_ipc_ops_s, leaving it a shared status word
    pair and an IPI doorbell.  The two words share a cache line, so they
    are required to be non-cacheable and the module does no cache
    maintenance on them.
    
    Each registered channel exposes the peer core to the reset framework as
    a reset_controller_dev named after the peer cpu, and reset_ipc_register()
    hands the caller a reset control on it, so everything the transport
    drives goes out through reset_control_reset[_reason]().
    
    A channel also brings its peer down when this core dies.  Each channel
    carries its own panic and reboot notifier blocks and puts them on the two
    chains at registration, so the chains are the list of channels and the
    module needs none of its own: no list, no lock, and nothing to walk from
    the dying path.  The blocks live in the channel, so unregistering leaves
    both chains before the channel is torn down.  A controller fronting a peer
    core is the only kind that needs any of this, which is why the notifiers
    belong here and not in the framework.
    
    When the peer is brought down follows CONFIG_BMP: under BMP each core dumps
    itself, so the peer is parked at PANIC_KERNEL and only released by the
    reboot notifier, while elsewhere this core collects the peers' dumps and
    tells them to panic from PANIC_KERNEL_FINAL.
    
    The shared status word encoding is the cross-core ABI and belongs to this
    module.  Each word holds the last reason sent as a single value, and a
    new value replaces the old one.  Besides the BOARDIOC causes the reason
    can be
    RESET_IPC_PAUSE, which only the panic notifier sends to park the peer, or
    RESET_REASON_PRIVATE, which this module reserves for the transport.
    reset_ipc_send() and the reset op pass the reason through unchanged;
    inbound, reset_ipc_register() gives the transport the callback that
    inspects the peer's word.
    
    RESET_REASON_PRIVATE is never interpreted here, since only the transport
    knows what it means, so it goes back out through the handle_status op.
    The reason values stay with this module because the word is one shared
    ABI that several transports may sit on.
    
    The status timeout and remote-panic-silent behavior are controlled by
    RESET_IPC_* Kconfig options; when the peer's reset is a panic its trace
    buffer is dumped first.  No transport uses it yet; this commit only adds
    the dormant module and wires it into the drivers build.
    
    RESET_IPC selects RESET rather than depending on it, which leaves RESET
    with no user that picks it directly, so drop its prompt and let
    RESET_RPMSG select it too.  The only defconfig that sets CONFIG_RESET
    by hand, qemu-intel64:nxterm, has no user of the framework, and a
    follow-up commit drops the symbol from it.
    
    Signed-off-by: wangshaoxin <[email protected]>
---
 drivers/reset/CMakeLists.txt    |   4 +
 drivers/reset/Kconfig           |  39 +++-
 drivers/reset/Make.defs         |   4 +-
 drivers/reset/reset_ipc.c       | 497 ++++++++++++++++++++++++++++++++++++++++
 include/nuttx/reset/reset_ipc.h | 196 ++++++++++++++++
 5 files changed, 736 insertions(+), 4 deletions(-)

diff --git a/drivers/reset/CMakeLists.txt b/drivers/reset/CMakeLists.txt
index 16d397d1eb3..8fac991c0f7 100644
--- a/drivers/reset/CMakeLists.txt
+++ b/drivers/reset/CMakeLists.txt
@@ -27,5 +27,9 @@ if(CONFIG_RESET)
     list(APPEND SRCS reset_rpmsg.c)
   endif()
 
+  if(CONFIG_RESET_IPC)
+    list(APPEND SRCS reset_ipc.c)
+  endif()
+
   target_sources(drivers PRIVATE ${SRCS})
 endif()
diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
index fc5beb7bdeb..9753a387a46 100644
--- a/drivers/reset/Kconfig
+++ b/drivers/reset/Kconfig
@@ -24,15 +24,17 @@
 # see the file kconfig-language.txt in the NuttX tools repository.
 #
 
-menuconfig RESET
-       bool "reset driver Support"
+config RESET
+       bool
        default n
        ---help---
                This selection enables building of the "upper-half" reset 
driver.
+               Selected by the drivers that need it, not chosen directly.
 
 config RESET_RPMSG
        bool "Reset rpmsg driver support"
-       depends on RESET && RPTUN
+       depends on RPTUN
+       select RESET
        default n
        ---help---
                This selection enables rpmsg support for reset.
@@ -50,3 +52,34 @@ config RESET_PROCFS
                interface says how many lines a controller has or what any of 
them
                is called, so without this the only way to see which peripherals
                are held is a program that knows the numbering already.
+
+config RESET_IPC
+       bool "Inter-Processor panic/reset notify support"
+       select RESET
+       default n
+       ---help---
+               RESET_IPC provides the multicore panic/reset coordination
+               mechanism (pause/panic/poweroff/stop handshake over a pair of
+               shared status words plus an IPI) shared by transports such as
+               RPTUN and RPMSG_BMP.  Each registered channel also exposes the
+               peer core to the reset framework, with one reset line per reset
+               reason (line id == BOARDIOC_SOFTRESETCAUSE_xxx).  It is selected
+               automatically by the transports that use it.
+
+if RESET_IPC
+
+config RESET_IPC_REMOTE_PANIC_SILENT
+       bool "Silence syslog on remote-triggered panic"
+       default n
+       ---help---
+               When a remote core triggers a panic on this core, silence
+               all syslog output by setting logmask to LOG_NONE.  The log
+               mask is restored at PANIC_KERNEL_FINAL before coredump and
+               RAMLOG dump, so only the originating core's crash log is
+               printed during the panic sequence.
+
+config RESET_IPC_STATUS_TIMEOUT_MS
+       int "reset_ipc status timeout ms"
+       default 5000
+
+endif # RESET_IPC
diff --git a/drivers/reset/Make.defs b/drivers/reset/Make.defs
index ba815dd3266..f8857b4b4d8 100644
--- a/drivers/reset/Make.defs
+++ b/drivers/reset/Make.defs
@@ -27,9 +27,11 @@ ifeq ($(CONFIG_RESET),y)
 CSRCS += core.c
 
 ifeq ($(CONFIG_RESET_RPMSG),y)
-
 CSRCS += reset_rpmsg.c
+endif
 
+ifeq ($(CONFIG_RESET_IPC),y)
+CSRCS += reset_ipc.c
 endif
 
 DEPPATH += --dep-path reset
diff --git a/drivers/reset/reset_ipc.c b/drivers/reset/reset_ipc.c
new file mode 100644
index 00000000000..e2cb4d872e8
--- /dev/null
+++ b/drivers/reset/reset_ipc.c
@@ -0,0 +1,497 @@
+/****************************************************************************
+ * drivers/reset/reset_ipc.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <string.h>
+#include <sys/boardctl.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/clock.h>
+#include <nuttx/irq.h>
+#include <nuttx/nuttx.h>
+#include <nuttx/panic_notifier.h>
+#include <nuttx/reboot_notifier.h>
+#include <nuttx/reset/reset-controller.h>
+#include <nuttx/reset/reset.h>
+#include <nuttx/reset/reset_ipc.h>
+#include <nuttx/signal.h>
+#include <nuttx/syslog/syslog.h>
+#include <nuttx/wqueue.h>
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int reset_ipc_rc_reset(FAR struct reset_controller_dev *rcdev,
+                              unsigned int id, unsigned int reason);
+static void reset_ipc_check_peer(FAR struct reset_ipc_s *ipc);
+static int reset_ipc_set_status(FAR struct reset_ipc_s *ipc,
+                                unsigned int reason);
+static int reset_ipc_panic_notifier(FAR struct notifier_block *nb,
+                                    unsigned long action, FAR void *data);
+static int reset_ipc_reboot_notifier(FAR struct notifier_block *nb,
+                                     unsigned long action, FAR void *data);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Only the self-deasserting reset op. */
+
+static const struct reset_control_ops g_reset_ipc_rc_ops =
+{
+  .reset = reset_ipc_rc_reset,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: reset_ipc_send
+ *
+ * Description:
+ *   Send a reset cause or RESET_REASON_PRIVATE to the peer.  A panic also
+ *   dumps the peer's trace buffer.
+ *
+ ****************************************************************************/
+
+static int reset_ipc_send(FAR struct reset_ipc_s *ipc, unsigned int reason)
+{
+  int ret;
+
+  if (reason > RESET_REASON_PRIVATE)
+    {
+      return -EINVAL;
+    }
+
+  ret = reset_ipc_set_status(ipc, reason);
+
+  if (reason == BOARDIOC_SOFTRESETCAUSE_PANIC && ipc->ops->dump != NULL)
+    {
+      ipc->ops->dump(ipc);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: reset_ipc_rc_reset
+ *
+ * Description:
+ *   reset framework op, passing the reason on to the peer.  id is unused.
+ *
+ ****************************************************************************/
+
+static int reset_ipc_rc_reset(FAR struct reset_controller_dev *rcdev,
+                              unsigned int id, unsigned int reason)
+{
+  FAR struct reset_ipc_s *ipc =
+    container_of(rcdev, struct reset_ipc_s, rcdev);
+
+  return reset_ipc_send(ipc, reason);
+}
+
+/****************************************************************************
+ * Name: reset_ipc_get_peer_status
+ ****************************************************************************/
+
+static inline_function unsigned int
+reset_ipc_get_peer_status(FAR struct reset_ipc_s *ipc)
+{
+  return *ipc->remote;
+}
+
+/****************************************************************************
+ * Name: reset_ipc_set_local_notify
+ ****************************************************************************/
+
+static inline_function void
+reset_ipc_set_local_notify(FAR struct reset_ipc_s *ipc,
+                           unsigned int reason)
+{
+  *ipc->local = reason;
+  ipc->ops->notify(ipc);
+}
+
+/****************************************************************************
+ * Name: reset_ipc_boardctl_work
+ ****************************************************************************/
+
+#if defined(CONFIG_BOARDCTL_RESET) || defined(CONFIG_BOARDCTL_POWEROFF)
+static void reset_ipc_boardctl_work(FAR void *arg)
+{
+  if ((unsigned long)arg == BOARDIOC_SOFTRESETCAUSE_POWEROFF)
+    {
+      boardctl(BOARDIOC_POWEROFF, 0u);
+    }
+  else
+    {
+      boardctl(BOARDIOC_RESET, (unsigned long)arg);
+    }
+}
+#endif
+
+/****************************************************************************
+ * Name: reset_ipc_check_peer
+ *
+ * Description:
+ *   React to a new value in the peer's status word.  Run by the transport
+ *   from its notification path.  A value already acted on, or the echo of
+ *   what this core sent, is ignored.
+ *
+ ****************************************************************************/
+
+static void reset_ipc_check_peer(FAR struct reset_ipc_s *ipc)
+{
+  unsigned int reason;
+  unsigned int status;
+
+  status = reset_ipc_get_peer_status(ipc);
+  if (status == ipc->shadow || status == *ipc->local)
+    {
+      return;
+    }
+
+  ipc->shadow = status;
+
+  if (status == RESET_IPC_PAUSE)
+    {
+      int timeout = CONFIG_RESET_IPC_STATUS_TIMEOUT_MS;
+
+      /* Wait for the crashing core to finish printing its log */
+
+      while (timeout-- > 0 &&
+             status == RESET_IPC_PAUSE)
+        {
+          status = reset_ipc_get_peer_status(ipc);
+          up_udelay(USEC_PER_MSEC);
+        }
+
+      if (timeout <= 0)
+        {
+          _emerg("FATAL: Timeout waiting for remote core panic: %s\n",
+                 ipc->rcdev.name);
+          return;
+        }
+
+      ipc->shadow = status;
+    }
+
+  reason = status;
+
+  if (reason < BOARDIOC_SOFTRESETCAUSE_MAX)
+    {
+      if (reason == BOARDIOC_SOFTRESETCAUSE_PANIC)
+        {
+          char msg[32];
+
+#ifdef CONFIG_RESET_IPC_REMOTE_PANIC_SILENT
+          /* Silence this passive panic; restored at PANIC_KERNEL_FINAL. */
+
+          nx_setlogmask(LOG_NONE);
+#endif
+
+          snprintf(msg, sizeof(msg), "Panic by remote core: %s",
+                   ipc->rcdev.name);
+          PANIC_WITH_MSG(msg);
+        }
+
+      _emerg("FATAL: Reset by remote core: %s reason: %u\n",
+             ipc->rcdev.name, reason);
+      if (reason == BOARDIOC_SOFTRESETCAUSE_POWEROFF)
+        {
+#ifdef CONFIG_BOARDCTL_POWEROFF
+          work_queue(HPWORK, &ipc->work, reset_ipc_boardctl_work,
+                     (FAR void *)BOARDIOC_SOFTRESETCAUSE_POWEROFF, 0);
+#else
+          reset_ipc_set_local_notify(ipc, BOARDIOC_SOFTRESETCAUSE_POWEROFF);
+#endif
+        }
+      else
+        {
+#ifdef CONFIG_BOARDCTL_RESET
+          work_queue(HPWORK, &ipc->work, reset_ipc_boardctl_work,
+                     (FAR void *)(uintptr_t)reason, 0);
+#else
+          reset_ipc_set_local_notify(ipc, reason);
+#endif
+        }
+    }
+  else if (reason == RESET_REASON_PRIVATE &&
+           ipc->ops->handle_status != NULL)
+    {
+      /* Transport-private: only it knows what this means. */
+
+      ipc->ops->handle_status(ipc, reason);
+    }
+}
+
+/****************************************************************************
+ * Name: reset_ipc_set_status
+ ****************************************************************************/
+
+static int reset_ipc_set_status(FAR struct reset_ipc_s *ipc,
+                                unsigned int reason)
+{
+  unsigned int status = reason;
+  int timeout = CONFIG_RESET_IPC_STATUS_TIMEOUT_MS;
+  int ret = -ENOTSUP;
+
+  /* Hardware delivery first; -ENOTSUP falls back to the handshake below. */
+
+  if (ipc->ops->set_status != NULL)
+    {
+      _emerg("Set status to remote %s reason: %u\n",
+             ipc->rcdev.name, reason);
+      ret = ipc->ops->set_status(ipc, reason);
+      _emerg("Set status to remote %s ret %d\n", ipc->rcdev.name, ret);
+    }
+
+  if (ret != -ENOTSUP)
+    {
+      return ret;
+    }
+
+  /* Already sent, or already sent by the peer: no re-notify. */
+
+  if (status == *ipc->local || status == ipc->shadow)
+    {
+      return OK;
+    }
+
+  reset_ipc_set_local_notify(ipc, reason);
+
+  /* Only a reset is echoed back; PAUSE and PRIVATE are fire-and-forget. */
+
+  if (reason >= BOARDIOC_SOFTRESETCAUSE_MAX)
+    {
+      return OK;
+    }
+
+  ret = -ETIMEDOUT;
+  while (timeout-- > 0)
+    {
+      if (reset_ipc_get_peer_status(ipc) == status)
+        {
+          ret = OK;
+          break;
+        }
+
+      if (timeout % MSEC_PER_SEC == 0)
+        {
+          _emerg("Waiting %s reset, timeout left %d ms\n",
+                 ipc->rcdev.name, timeout);
+        }
+
+      if (up_interrupt_context())
+        {
+          up_udelay(USEC_PER_MSEC);
+        }
+      else
+        {
+          nxsig_usleep(USEC_PER_MSEC);
+        }
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: reset_ipc_panic_notifier
+ *
+ * Description:
+ *   Panic chain entry of one channel, so its peer comes down with us.
+ *
+ ****************************************************************************/
+
+static int reset_ipc_panic_notifier(FAR struct notifier_block *nb,
+                                    unsigned long action, FAR void *data)
+{
+  FAR struct reset_ipc_s *ipc =
+    container_of(nb, struct reset_ipc_s, panic_nb);
+
+  if (action == PANIC_KERNEL)
+    {
+      /* Only park the peer for now: this core still has logging to do. */
+
+      reset_ipc_set_status(ipc, RESET_IPC_PAUSE);
+    }
+#ifndef CONFIG_BMP
+  else if (action == PANIC_KERNEL_FINAL)
+    {
+      /* This core collects the peers' dumps, so panic them here.  Under
+       * BMP each core dumps itself and the peer waits for the reboot.
+       */
+
+      reset_ipc_send(ipc, BOARDIOC_SOFTRESETCAUSE_PANIC);
+    }
+#endif
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: reset_ipc_reboot_notifier
+ *
+ * Description:
+ *   Reboot chain entry of one channel, mapping the event onto a cause.
+ *
+ ****************************************************************************/
+
+static int reset_ipc_reboot_notifier(FAR struct notifier_block *nb,
+                                     unsigned long action, FAR void *data)
+{
+  FAR struct reset_ipc_s *ipc =
+    container_of(nb, struct reset_ipc_s, reboot_nb);
+  unsigned int reason;
+
+  if (action == SYS_POWER_OFF)
+    {
+      reason = BOARDIOC_SOFTRESETCAUSE_POWEROFF;
+    }
+  else if (action == SYS_HALT)
+    {
+      reason = BOARDIOC_SOFTRESETCAUSE_PANIC;
+    }
+  else
+    {
+      reason = (uintptr_t)data;
+    }
+
+  reset_ipc_send(ipc, reason);
+
+  return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: reset_ipc_register
+ ****************************************************************************/
+
+FAR struct reset_control *
+reset_ipc_register(FAR struct reset_ipc_s *ipc,
+                   FAR const struct reset_ipc_ops_s *ops,
+                   FAR const char *cpuname,
+                   uintptr_t status, bool master)
+{
+  FAR uint32_t *sts = (FAR uint32_t *)status;
+  FAR struct reset_control *rstc;
+
+  DEBUGASSERT(ipc != NULL && ops != NULL && cpuname != NULL &&
+              status != 0 && (status % sizeof(uint32_t)) == 0);
+
+  /* Word 0 belongs to the master, word 1 to the slave. */
+
+  ipc->local      = master ? &sts[0] : &sts[1];
+  ipc->remote     = master ? &sts[1] : &sts[0];
+  ipc->ops        = ops;
+  ipc->rcdev.name = cpuname;
+  ipc->rcdev.ops  = &g_reset_ipc_rc_ops;
+
+  /* Start clean, so a status from a previous cycle is driven again. */
+
+  *ipc->local = UINT32_MAX;
+  ipc->shadow = UINT32_MAX;
+
+  if (reset_controller_register(&ipc->rcdev) < 0)
+    {
+      return NULL;
+    }
+
+  /* The callback the transport runs on every peer notification. */
+
+  if (ops->register_callback != NULL)
+    {
+      ops->register_callback(ipc, reset_ipc_check_peer);
+    }
+
+  /* Put this channel on both chains, last of all, so the peer is only taken
+   * down once everything else on this core has had its turn.
+   */
+
+  ipc->panic_nb.notifier_call  = reset_ipc_panic_notifier;
+#ifdef CONFIG_BMP
+  ipc->panic_nb.priority       = INT_MIN + 1;
+#else
+  ipc->panic_nb.priority       = INT_MIN + 2;
+#endif
+  ipc->reboot_nb.notifier_call = reset_ipc_reboot_notifier;
+  ipc->reboot_nb.priority      = INT_MIN;
+
+  panic_notifier_chain_register(&ipc->panic_nb);
+  register_reboot_notifier(&ipc->reboot_nb);
+
+  /* Hand back a reset control, so the caller drives the peer through the
+   * framework.  Roll back on failure: NULL means nothing is registered.
+   */
+
+  rstc = reset_control_get_exclusive(cpuname);
+  if (rstc == NULL)
+    {
+      rsterr("reset_ipc get reset control failed: %s\n", cpuname);
+      reset_ipc_unregister(ipc);
+    }
+
+  return rstc;
+}
+
+/****************************************************************************
+ * Name: reset_ipc_unregister
+ ****************************************************************************/
+
+void reset_ipc_unregister(FAR struct reset_ipc_s *ipc)
+{
+  /* Leave the chains first: they hold pointers into this channel. */
+
+  panic_notifier_chain_unregister(&ipc->panic_nb);
+  unregister_reboot_notifier(&ipc->reboot_nb);
+
+  /* Take the callback back, so no late notification reaches us. */
+
+  if (ipc->ops->register_callback != NULL)
+    {
+      ipc->ops->register_callback(ipc, NULL);
+    }
+
+  reset_controller_unregister(&ipc->rcdev);
+
+  /* Drop a pending boardctl and wait out a running one. */
+
+  work_cancel_sync(HPWORK, &ipc->work);
+
+  /* Nothing references the channel now; a stale use faults on NULL. */
+
+  memset(ipc, 0, sizeof(*ipc));
+}
diff --git a/include/nuttx/reset/reset_ipc.h b/include/nuttx/reset/reset_ipc.h
new file mode 100644
index 00000000000..a474e5ff9b7
--- /dev/null
+++ b/include/nuttx/reset/reset_ipc.h
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * include/nuttx/reset/reset_ipc.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_RESET_RESET_IPC_H
+#define __INCLUDE_NUTTX_RESET_RESET_IPC_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#ifdef CONFIG_RESET_IPC
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <sys/boardctl.h>
+
+#include <nuttx/compiler.h>
+#include <nuttx/notifier.h>
+#include <nuttx/reset/reset-controller.h>
+#include <nuttx/wqueue.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Reason reserved above the BOARDIOC_SOFTRESETCAUSE_xxx range: ask for
+ * whatever action the transport keeps for itself instead of resetting the
+ * peer.  The reset framework only carries it.
+ */
+
+#define RESET_REASON_PRIVATE     (BOARDIOC_SOFTRESETCAUSE_MAX + 0)
+
+/* Reason reset_ipc sends on its own to park the peer while this core logs
+ * a panic.  Never accepted from the reset framework.
+ */
+
+#define RESET_IPC_PAUSE          (BOARDIOC_SOFTRESETCAUSE_MAX + 1)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+struct reset_ipc_s;
+
+/* Run by the transport from its notification path, to pick up whatever the
+ * peer has put in the shared status word.
+ */
+
+typedef CODE void (*reset_ipc_callback_t)(FAR struct reset_ipc_s *ipc);
+
+struct reset_ipc_ops_s
+{
+  /* Trigger the inter-processor interrupt towards the peer core. */
+
+  CODE void (*notify)(FAR struct reset_ipc_s *ipc);
+
+  /* Optional hardware delivery of a reason, tried first by
+   * reset_ipc_set_status; return -ENOTSUP to fall back to the shared-word
+   * handshake.
+   */
+
+  CODE int (*set_status)(FAR struct reset_ipc_s *ipc,
+                         unsigned int reason);
+
+  /* Optional handler for RESET_REASON_PRIVATE from the peer, which
+   * reset_ipc reserves but cannot act on itself since only the transport
+   * knows what it means.
+   */
+
+  CODE void (*handle_status)(FAR struct reset_ipc_s *ipc,
+                             unsigned int reason);
+
+  /* Optional dump of the peer's trace buffer at reset time. */
+
+  CODE void (*dump)(FAR struct reset_ipc_s *ipc);
+
+  /* Take the callback to run whenever the peer notifies this core.  Called
+   * once from reset_ipc_register(), before the transport starts delivering
+   * notifications.  A transport that never notifies may leave it NULL.
+   */
+
+  CODE void (*register_callback)(FAR struct reset_ipc_s *ipc,
+                                 reset_ipc_callback_t callback);
+};
+
+/* One channel per peer core, embedded in the transport's per-peer private
+ * data.  rcdev is the reset framework device fronting that peer and comes
+ * first, so container_of() back from the framework is a plain cast; its name
+ * doubles as the peer cpu name.  local/remote are the two halves of the
+ * shared status pair and stay non-NULL while registered, so the status paths
+ * never check them.  shadow holds the last peer word acted on, for dedup,
+ * and starts clean at every reset_ipc_register() like local does.  The two
+ * notifier blocks put this channel on the panic and reboot chains, which is
+ * what brings the peer down with this core.
+ */
+
+struct reset_ipc_s
+{
+  struct reset_controller_dev       rcdev;     /* Reset framework device */
+  struct notifier_block             panic_nb;  /* Panic chain entry */
+  struct notifier_block             reboot_nb; /* Reboot chain entry */
+  FAR const struct reset_ipc_ops_s *ops;       /* Transport callbacks */
+  FAR uint32_t                     *local;     /* Local status word */
+  FAR uint32_t                     *remote;    /* Peer status word */
+  uint32_t                          shadow;    /* Last peer word seen */
+  struct work_s                     work;      /* Deferred boardctl */
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/****************************************************************************
+ * Name: reset_ipc_register
+ *
+ * Description:
+ *   Register a channel, exposing the peer core to the reset framework so it
+ *   can be reset through reset_control_* and joining the framework's
+ *   panic/reboot fan-out on the calling core.
+ *
+ *   Call before the transport starts delivering notifications, and from the
+ *   core that owns the channel.  Balance with reset_ipc_unregister() from
+ *   the stop path: the reset controller registration is not idempotent.
+ *
+ * Input Parameters:
+ *   ipc     - The channel embedded in the transport private data
+ *   ops     - Transport callbacks, must stay valid while registered
+ *   cpuname - Peer cpu name, used for log messages and as the reset
+ *             controller device name.  Not copied.
+ *   status  - Address of a uint32_t pair shared with the peer, same memory
+ *             on both sides.  Word 0 is written by the master, word 1 by the
+ *             slave, each core reading only the other's.  Must be uint32_t
+ *             aligned and non-cacheable (the words share a cache line), and
+ *             ideally survive a peer reset so the reason stays readable.
+ *   master  - True on the master core, false on the slave.
+ *
+ * Returned Value:
+ *   An exclusive reset control on the channel, to drive the peer with
+ *   reset_control_reset_reason(), or NULL on failure.  Release it with
+ *   reset_control_put() before reset_ipc_unregister().  A NULL return leaves
+ *   nothing registered, so there is nothing to undo.
+ *
+ ****************************************************************************/
+
+FAR struct reset_control *
+reset_ipc_register(FAR struct reset_ipc_s *ipc,
+                   FAR const struct reset_ipc_ops_s *ops,
+                   FAR const char *cpuname,
+                   uintptr_t status, bool master);
+
+/****************************************************************************
+ * Name: reset_ipc_unregister
+ *
+ * Description:
+ *   Remove a channel from the reset framework, which also drops it from the
+ *   panic/reboot fan-out, and drop its status words.  Takes a mutex, so not
+ *   callable from the interrupt path.  The transport must have stopped
+ *   delivering notifications first:
+ *   the callback is taken back here, but one already running races with it.
+ *
+ ****************************************************************************/
+
+void reset_ipc_unregister(FAR struct reset_ipc_s *ipc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CONFIG_RESET_IPC */
+#endif /* __INCLUDE_NUTTX_RESET_RESET_IPC_H */

Reply via email to