Attn: Self boot engine (SBE) attention support

When an SBE vital attention is detected a plateform event log entry will
be created and an SBE dump will be requested. A request to transition
the host will be issued once the dump is completed.

Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: I3e53292d7eb429a76a920bda0dfb051afbc9fe6b
diff --git a/attn/attn_dump.cpp b/attn/attn_dump.cpp
index 95976be..3f325bd 100644
--- a/attn/attn_dump.cpp
+++ b/attn/attn_dump.cpp
@@ -108,6 +108,14 @@
                     ["com.ibm.Dump.Create.CreateParameters.FailingUnitId"] =
                         i_dumpParameters.unitId;
             }
+            else if (DumpType::SBE == i_dumpParameters.dumpType)
+            {
+                createParams["com.ibm.Dump.Create.CreateParameters.DumpType"] =
+                    "com.ibm.Dump.Create.DumpType.SBE";
+                createParams
+                    ["com.ibm.Dump.Create.CreateParameters.FailingUnitId"] =
+                        i_dumpParameters.unitId;
+            }
             method.append(createParams);
 
             // using system dbus
diff --git a/attn/attn_dump.hpp b/attn/attn_dump.hpp
index 6480b15..04c51e7 100644
--- a/attn/attn_dump.hpp
+++ b/attn/attn_dump.hpp
@@ -7,7 +7,8 @@
 enum class DumpType
 {
     Hostboot,
-    Hardware
+    Hardware,
+    SBE
 };
 
 /** @brief Structure for dump request parameters */
diff --git a/attn/attn_logging.cpp b/attn/attn_logging.cpp
index d85a66c..8aed00f 100644
--- a/attn/attn_logging.cpp
+++ b/attn/attn_logging.cpp
@@ -332,10 +332,14 @@
  * @param  i_event - The event type
  * @param  i_additional - Additional PEL data
  * @param  i_ffdc - FFDC PEL data
+ * @return Event log Id (0 if no event log generated)
  */
-void event(EventType i_event, std::map<std::string, std::string>& i_additional,
-           const std::vector<util::FFDCFile>& i_ffdc)
+uint32_t event(EventType i_event,
+               std::map<std::string, std::string>& i_additional,
+               const std::vector<util::FFDCFile>& i_ffdc)
 {
+    uint32_t pelId = 0; // assume no event log generated
+
     bool eventValid = false; // assume no event created
     bool tiEvent    = false; // assume not a terminate event
 
@@ -370,8 +374,7 @@
     {
         // Create PEL with additional data and FFDC data. The newly created
         // PEL's platform log-id will be returned.
-        auto pelId =
-            createPel(eventName, i_additional, createFFDCTuples(i_ffdc));
+        pelId = createPel(eventName, i_additional, createFFDCTuples(i_ffdc));
 
         // If this is a TI event we will create an additional PEL that is
         // specific to the subsystem that generated the TI.
@@ -420,6 +423,7 @@
             }
         }
     }
+    return pelId;
 }
 
 /**
@@ -465,14 +469,14 @@
           createFFDCFiles(i_tiInfoData, tiInfoSize));
 }
 
-/** @brief Commit SBE vital event to log */
-void eventVital()
+/** @brief Commit SBE vital event to log, returns event log ID */
+uint32_t eventVital()
 {
     // Additional data for log
     std::map<std::string, std::string> additionalData;
 
     // Create log event with additional data and FFDC data
-    event(EventType::Vital, additionalData, createFFDCFiles(nullptr, 0));
+    return event(EventType::Vital, additionalData, createFFDCFiles(nullptr, 0));
 }
 
 /**
diff --git a/attn/attn_logging.hpp b/attn/attn_logging.hpp
index 842f677..e790d94 100644
--- a/attn/attn_logging.hpp
+++ b/attn/attn_logging.hpp
@@ -44,8 +44,8 @@
 void eventTerminate(std::map<std::string, std::string> i_additionalData,
                     char* i_tiInfoData);
 
-/** @brief Commit SBE vital event to log */
-void eventVital();
+/** @brief Commit SBE vital event to log, returns event log Id */
+uint32_t eventVital();
 
 /** @brief Commit attention handler failure event to log */
 void eventAttentionFail(int i_error);
diff --git a/attn/vital_handler.cpp b/attn/vital_handler.cpp
index 910c005..c07dfc7 100644
--- a/attn/vital_handler.cpp
+++ b/attn/vital_handler.cpp
@@ -1,5 +1,6 @@
 #include <attn/attention.hpp>
 #include <attn/attn_common.hpp>
+#include <attn/attn_dump.hpp>
 #include <attn/attn_logging.hpp>
 #include <sdbusplus/bus.hpp>
 #include <util/dbus.hpp>
@@ -28,11 +29,18 @@
     }
     else
     {
-        // transition host state after analyses
-        util::dbus::transitionHost(util::dbus::HostState::Quiesce);
-
         // generate pel
-        eventVital();
+        auto pelId = eventVital();
+
+        // conditionally request dump
+        if ((0 != pelId) && (util::dbus::HostRunningState::NotStarted ==
+                             util::dbus::hostRunningState()))
+        {
+            requestDump(DumpParameters{pelId, 0, DumpType::SBE});
+        }
+
+        // transition host
+        util::dbus::transitionHost(util::dbus::HostState::Quiesce);
     }
 
     return rc;
diff --git a/test/end2end/logging.cpp b/test/end2end/logging.cpp
index 4adb5af..d75625e 100644
--- a/test/end2end/logging.cpp
+++ b/test/end2end/logging.cpp
@@ -42,9 +42,10 @@
     }
 }
 
-void eventVital()
+uint32_t eventVital()
 {
     std::cout << "event: vital" << std::endl;
+    return 0;
 }
 
 } // namespace attn