Move PCIe functions to common file

Move redfishPcieGenerationFromDbus, called from both pcie.hpp and
pcie_slots.hpp, and busSlotTypeToRf functions, called from
pcie_slots.hpp, to a common PCIe utility file.

In the future commit, when integrating PCIeSlot with PCIeDevice, we will
call the busSlotTypeToRf function from pcie.hpp, so having it in the
common utility file will make it readily available.

Tested: build successful, no additional testing needed.

Change-Id: I6286bd5547ddafa6eac4f224ac56f6d790a44c7a
Signed-off-by: Lakshmi Yadlapati <lakshmiy@us.ibm.com>
diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp
index 1c36b18..b5c6c15 100644
--- a/redfish-core/lib/pcie.hpp
+++ b/redfish-core/lib/pcie.hpp
@@ -18,11 +18,11 @@
 
 #include "app.hpp"
 #include "dbus_utility.hpp"
-#include "generated/enums/pcie_device.hpp"
 #include "query.hpp"
 #include "registries/privilege_registry.hpp"
 #include "utils/collection.hpp"
 #include "utils/dbus_utils.hpp"
+#include "utils/pcie_util.hpp"
 
 #include <boost/system/linux_error.hpp>
 #include <boost/url/format.hpp>
@@ -141,45 +141,6 @@
             std::bind_front(handlePCIeDeviceCollectionGet, std::ref(app)));
 }
 
-inline std::optional<pcie_device::PCIeTypes>
-    redfishPcieGenerationFromDbus(const std::string& generationInUse)
-{
-    if (generationInUse ==
-        "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen1")
-    {
-        return pcie_device::PCIeTypes::Gen1;
-    }
-    if (generationInUse ==
-        "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen2")
-    {
-        return pcie_device::PCIeTypes::Gen2;
-    }
-    if (generationInUse ==
-        "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen3")
-    {
-        return pcie_device::PCIeTypes::Gen3;
-    }
-    if (generationInUse ==
-        "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen4")
-    {
-        return pcie_device::PCIeTypes::Gen4;
-    }
-    if (generationInUse ==
-        "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen5")
-    {
-        return pcie_device::PCIeTypes::Gen5;
-    }
-    if (generationInUse.empty() ||
-        generationInUse ==
-            "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Unknown")
-    {
-        return pcie_device::PCIeTypes::Invalid;
-    }
-
-    // The value is not unknown or Gen1-5, need return an internal error.
-    return std::nullopt;
-}
-
 inline void
     getPCIeDeviceState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
                        const std::string& pcieDevicePath,
@@ -298,7 +259,7 @@
     if (generationInUse != nullptr)
     {
         std::optional<pcie_device::PCIeTypes> redfishGenerationInUse =
-            redfishPcieGenerationFromDbus(*generationInUse);
+            pcie_util::redfishPcieGenerationFromDbus(*generationInUse);
 
         if (!redfishGenerationInUse)
         {