PEL: Pass in subsystem to use with additional data

There is a requirement to pass in the subsystem to use with
the additional data field. In the process update the user
header code and SRC with the passed-in subsystem value
instead from the message registry.

Signed-off-by: Sumit Kumar <sumit_kumar@in.ibm.com>
Change-Id: I08c8c3bab100fec581df9043f4bb27b28cb556e1
diff --git a/extensions/openpower-pels/README.md b/extensions/openpower-pels/README.md
index 637a389..7f9df1d 100644
--- a/extensions/openpower-pels/README.md
+++ b/extensions/openpower-pels/README.md
@@ -120,6 +120,13 @@
 This is used to pass in an I2C bus and address to create callouts from.  See
 [here for details](#passing-callouts-in-with-the-additionaldata-property)
 
+#### PEL_SUBSYSTEM
+This keyword is used to pass in the subsystem that should be associated with
+this event log. The syntax is:
+PEL_SUBSYSTEM=<subsystem value in hex>
+e.g.
+PEL_SUBSYSTEM=0x20
+
 ### FFDC Intended For UserData PEL sections
 
 When one needs to add FFDC into the PEL UserData sections, the
diff --git a/extensions/openpower-pels/ascii_string.hpp b/extensions/openpower-pels/ascii_string.hpp
index 0970df9..0fdf124 100644
--- a/extensions/openpower-pels/ascii_string.hpp
+++ b/extensions/openpower-pels/ascii_string.hpp
@@ -72,7 +72,6 @@
      */
     std::string get() const;
 
-  private:
     /**
      * @brief Converts a byte of raw data to 2 characters
      *        and writes it to the offset.
@@ -91,6 +90,7 @@
      */
     void setByte(size_t offset, uint8_t value);
 
+  private:
     /**
      * @brief The ASCII string itself
      */
diff --git a/extensions/openpower-pels/src.cpp b/extensions/openpower-pels/src.cpp
index 5984287..f4807f5 100644
--- a/extensions/openpower-pels/src.cpp
+++ b/extensions/openpower-pels/src.cpp
@@ -363,6 +363,26 @@
 
     _asciiString = std::make_unique<src::AsciiString>(regEntry);
 
+    // Check for additional data - PEL_SUBSYSTEM
+    auto ss = additionalData.getValue("PEL_SUBSYSTEM");
+    if (ss)
+    {
+        auto eventSubsystem = std::stoul(*ss, NULL, 16);
+        std::string subsystem =
+            pv::getValue(eventSubsystem, pel_values::subsystemValues);
+        if (subsystem == "invalid")
+        {
+            log<level::WARNING>(
+                fmt::format("SRC: Invalid SubSystem value:{:#X}",
+                            eventSubsystem)
+                    .c_str());
+        }
+        else
+        {
+            _asciiString->setByte(2, eventSubsystem);
+        }
+    }
+
     addCallouts(regEntry, additionalData, jsonCallouts, dataIface);
 
     _size = baseSRCSize;
diff --git a/extensions/openpower-pels/user_header.cpp b/extensions/openpower-pels/user_header.cpp
index 34e2fa1..7aed654 100644
--- a/extensions/openpower-pels/user_header.cpp
+++ b/extensions/openpower-pels/user_header.cpp
@@ -20,6 +20,8 @@
 #include "pel_values.hpp"
 #include "severity.hpp"
 
+#include <fmt/format.h>
+
 #include <iostream>
 #include <phosphor-logging/log.hpp>
 
@@ -58,6 +60,25 @@
 
     _eventSubsystem = entry.subsystem;
 
+    // Check for additional data - PEL_SUBSYSTEM
+    auto ss = additionalData.getValue("PEL_SUBSYSTEM");
+    if (ss)
+    {
+        auto eventSubsystem = std::stoul(*ss, NULL, 16);
+        std::string subsystem =
+            pv::getValue(eventSubsystem, pel_values::subsystemValues);
+        if (subsystem == "invalid")
+        {
+            log<level::WARNING>(
+                fmt::format("UH: Invalid SubSystem value:{:#X}", eventSubsystem)
+                    .c_str());
+        }
+        else
+        {
+            _eventSubsystem = eventSubsystem;
+        }
+    }
+
     _eventScope = entry.eventScope.value_or(
         static_cast<uint8_t>(EventScope::entirePlatform));