P9: threadStopall procedure support

This procedure is used to stop all instruction in the threads
for the p9 feature enabled systems. Here following best case
approach. Like issue processor level stop all chip-op with
ignore hardware error mode. Since this function is used in
power-off/error path.

Tested: verified procedure on p9 based systems

Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
Change-Id: I14af85340143d2383683d9fb823394b9ce7b56ca
diff --git a/meson.build b/meson.build
index ce7ff10..bbaeeed 100644
--- a/meson.build
+++ b/meson.build
@@ -86,6 +86,7 @@
         'procedures/p9/start_host.cpp',
         'procedures/p9/start_host_mpreboot.cpp',
         'procedures/p9/enter_mpreboot.cpp',
+        'procedures/p9/thread_stopall.cpp',
     ]
 endif
 if build_openfsi
diff --git a/procedures/p9/thread_stopall.cpp b/procedures/p9/thread_stopall.cpp
new file mode 100644
index 0000000..8d5f755
--- /dev/null
+++ b/procedures/p9/thread_stopall.cpp
@@ -0,0 +1,52 @@
+#include "registration.hpp"
+
+#include <fmt/format.h>
+extern "C"
+{
+#include <libpdbg.h>
+}
+#include <phosphor-logging/log.hpp>
+
+namespace openpower
+{
+namespace phal
+{
+using namespace phosphor::logging;
+
+/**
+ * @brief Stop instruction executions on all functional threads in the
+ *        host processors.
+ *        This procedure is used to stop all threads in the system in
+ *        attempt best case approach. Like issue processor level stopall
+ *        chip-op with ignore hardware error mode. Since this function
+ *        is used in power-off/error path, ignore the internal error now.
+ */
+void threadStopAll(void)
+{
+    // Set pdbg back-end to sbefifo.
+    pdbg_set_backend(PDBG_BACKEND_SBEFIFO, NULL);
+
+    // initialize the pdbg.
+    pdbg_targets_init(NULL);
+
+    struct pdbg_target* pibTarget;
+
+    pdbg_for_each_class_target("pib", pibTarget)
+    {
+        // probe pib traget.
+        pdbg_target_probe(pibTarget);
+    }
+
+    // Issue system level thread stop
+    if (thread_stop_all() < 0)
+    {
+        log<level::ERR>("Failed to stop all threads");
+        return;
+    }
+    log<level::INFO>("Processor thread stopall completed");
+}
+
+REGISTER_PROCEDURE("threadStopAll", threadStopAll)
+
+} // namespace phal
+} // namespace openpower