Move checkErrPinCPUs() to a common header

I will need to add a non-polling monitor for the ERR pin signals, so
this moves the checkErrPinCPUs() function to a common header to avoid
duplication.

Tested:
Confirmed that the correct CPU is still logged on an ERR pin event.

Signed-off-by: Jason M. Bills <jason.m.bills@intel.com>
Change-Id: I832336ee5a943c38b14d89d773eb9cf18d3ea5be
diff --git a/include/host_error_monitor.hpp b/include/host_error_monitor.hpp
index 8710a44..294dbef 100644
--- a/include/host_error_monitor.hpp
+++ b/include/host_error_monitor.hpp
@@ -18,6 +18,7 @@
 
 #include <sdbusplus/asio/object_server.hpp>
 
+#include <bitset>
 #include <iostream>
 
 namespace host_error_monitor
@@ -128,4 +129,66 @@
         "xyz.openbmc_project.BeepCode", "Beep", uint8_t(beepPriority));
 }
 
+static void checkErrPinCPUs(const size_t errPin,
+                            std::bitset<MAX_CPUS>& errPinCPUs)
+{
+    errPinCPUs.reset();
+    for (size_t cpu = 0, addr = MIN_CLIENT_ADDR; addr <= MAX_CLIENT_ADDR;
+         cpu++, addr++)
+    {
+        EPECIStatus peciStatus = PECI_CC_SUCCESS;
+        uint8_t cc = 0;
+        CPUModel model{};
+        uint8_t stepping = 0;
+        peciStatus = peci_GetCPUID(addr, &model, &stepping, &cc);
+        if (peciStatus != PECI_CC_SUCCESS)
+        {
+            if (peciStatus != PECI_CC_CPU_NOT_PRESENT)
+            {
+                printPECIError("CPUID", addr, peciStatus, cc);
+            }
+            continue;
+        }
+
+        switch (model)
+        {
+            case skx:
+            {
+                // Check the ERRPINSTS to see if this is the CPU that
+                // caused the ERRx (B(0) D8 F0 offset 210h)
+                uint32_t errpinsts = 0;
+                peciStatus = peci_RdPCIConfigLocal(addr, 0, 8, 0, 0x210,
+                                                   sizeof(uint32_t),
+                                                   (uint8_t*)&errpinsts, &cc);
+                if (peciError(peciStatus, cc))
+                {
+                    printPECIError("ERRPINSTS", addr, peciStatus, cc);
+                    continue;
+                }
+
+                errPinCPUs[cpu] = (errpinsts & (1 << errPin)) != 0;
+                break;
+            }
+            case icx:
+            {
+                // Check the ERRPINSTS to see if this is the CPU that
+                // caused the ERRx (B(30) D0 F3 offset 274h) (Note: Bus
+                // 30 is accessed on PECI as bus 13)
+                uint32_t errpinsts = 0;
+                peciStatus = peci_RdEndPointConfigPciLocal(
+                    addr, 0, 13, 0, 3, 0x274, sizeof(uint32_t),
+                    (uint8_t*)&errpinsts, &cc);
+                if (peciError(peciStatus, cc))
+                {
+                    printPECIError("ERRPINSTS", addr, peciStatus, cc);
+                    continue;
+                }
+
+                errPinCPUs[cpu] = (errpinsts & (1 << errPin)) != 0;
+                break;
+            }
+        }
+    }
+}
+
 } // namespace host_error_monitor