Specify PEL callout priority and sort callouts.

Allow the priority to be passed in at creation time by calling the
CALLOUT_PRIORITY keyword. When creating a PEL, callouts will always
be sorted by priority instead of creation time, the order is as follows:
H,M,A,B,C,L.

Signed-off-by: Miguel Gomez <mgomez@mx1.ibm.com>
Change-Id: I84345aaf3fad7b2e4958b698ab761966f499986b
diff --git a/extensions/openpower-pels/callouts.cpp b/extensions/openpower-pels/callouts.cpp
index 2440621..885dda5 100644
--- a/extensions/openpower-pels/callouts.cpp
+++ b/extensions/openpower-pels/callouts.cpp
@@ -61,7 +61,19 @@
         using namespace phosphor::logging;
         log<level::INFO>("Dropping PEL callout because at max");
     }
+
+    // Mapping including the  3 Medium levels as A,B and C
+    const std::map<std::uint8_t, int> priorities = {
+        {'H', 10}, {'M', 9}, {'A', 8}, {'B', 7}, {'C', 6}, {'L', 5}};
+
+    auto sortPriority = [&priorities](const std::unique_ptr<Callout>& p1,
+                                      const std::unique_ptr<Callout>& p2) {
+        return priorities.at(p1->priority()) > priorities.at(p2->priority());
+    };
+
+    std::sort(_callouts.begin(), _callouts.end(), sortPriority);
 }
+
 } // namespace src
 } // namespace pels
-} // namespace openpower
+} // namespace openpower
\ No newline at end of file
diff --git a/extensions/openpower-pels/src.cpp b/extensions/openpower-pels/src.cpp
index 3fd62e8..643adec 100644
--- a/extensions/openpower-pels/src.cpp
+++ b/extensions/openpower-pels/src.cpp
@@ -748,7 +748,19 @@
         getRegistryCallouts(regEntry, additionalData, dataIface);
 
     auto item = additionalData.getValue("CALLOUT_INVENTORY_PATH");
+    auto priority = additionalData.getValue("CALLOUT_PRIORITY");
 
+    std::optional<CalloutPriority> calloutPriority;
+
+    // Only  H, M or L priority values.
+    if (priority && !(*priority).empty())
+    {
+        uint8_t p = (*priority)[0];
+        if (p == 'H' || p == 'M' || p == 'L')
+        {
+            calloutPriority = static_cast<CalloutPriority>(p);
+        }
+    }
     // If the first registry callout says to use the passed in inventory
     // path to get the location code for a symbolic FRU callout with a
     // trusted location code, then do not add the inventory path as a
@@ -759,7 +771,7 @@
 
     if (item && !useInvForSymbolicFRULocCode)
     {
-        addInventoryCallout(*item, std::nullopt, std::nullopt, dataIface);
+        addInventoryCallout(*item, calloutPriority, std::nullopt, dataIface);
     }
 
     addDevicePathCallouts(additionalData, dataIface);