Add CPU_MISMATCH event handler

Issue: BMC is not logging CPU_MISMATCH event log in Redfish when
       CPUMismatch event occurred

Fix: Added CPU_MISMATCH event handler

Tested:
1. Replace CPU2 with mismatch CPU and power on
2. Verify event log generated on Redfish.
3. Redfish URI:
GET -  https://<BMC_IP>/redfish/v1/Systems/system/LogServices/
          EventLog/Entries
Response: For CPU1
   {
      "@odata.id": "/redfish/v1/Systems/system/LogServices/EventLog/
                   Entries/1584603142",
      "@odata.type": "#LogEntry.v1_4_0.LogEntry",
      "Created": "2020-03-19T07:32:22+00:00",
      "EntryType": "Event",
      "Id": "1584603142",
      "Message": "CPU 1 Mismatch.",
      "MessageArgs": [
        "1"
      ],
      "MessageId": "OpenBMC.0.1.CPUMismatch",
      "Name": "System Event Log Entry",
      "Severity": "Critical"
    },
   For CPU2:
   {
      "@odata.id": "/redfish/v1/Systems/system/LogServices/EventLog/
                   Entries/1584603142_1",
      "@odata.type": "#LogEntry.v1_4_0.LogEntry",
      "Created": "2020-03-19T07:32:22+00:00",
      "EntryType": "Event",
      "Id": "1584603142_1",
      "Message": "CPU 2 Mismatch.",
      "MessageArgs": [
        "2"
      ],
      "MessageId": "OpenBMC.0.1.CPUMismatch",
      "Name": "System Event Log Entry",
      "Severity": "Critical"
    },

Change-Id: I59ac07ee509dcd1cd594a0cc8ba6bedee0d190c3
Signed-off-by: Snehalatha V <SnehalathaX.V@intel.com>
Signed-off-by: jayaprakash Mutyala <mutyalax.jayaprakash@intel.com>
diff --git a/src/host_error_monitor.cpp b/src/host_error_monitor.cpp
index c1344df..806347f 100644
--- a/src/host_error_monitor.cpp
+++ b/src/host_error_monitor.cpp
@@ -90,6 +90,11 @@
 static boost::asio::posix::stream_descriptor cpu1MemtripEvent(io);
 static gpiod::line cpu2MemtripLine;
 static boost::asio::posix::stream_descriptor cpu2MemtripEvent(io);
+//---------------------------------
+// CPU_MISMATCH function related definition
+//---------------------------------
+static gpiod::line cpu1MismatchLine;
+static gpiod::line cpu2MismatchLine;
 
 // beep function for CPU error
 const static constexpr uint8_t beepCPUErr2 = 5;
@@ -191,6 +196,15 @@
                     cpuNumber.c_str(), NULL);
 }
 
+static void cpuMismatchLog(const int cpuNum)
+{
+    std::string msg = "CPU " + std::to_string(cpuNum) + " mismatch";
+
+    sd_journal_send("MESSAGE= %s", msg.c_str(), "PRIORITY=%i", LOG_ERR,
+                    "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.CPUMismatch",
+                    "REDFISH_MESSAGE_ARGS=%d", cpuNum, NULL);
+}
+
 static void cpuVRHotLog(const std::string& vr)
 {
     std::string msg = vr + " Voltage Regulator Overheated.";
@@ -1393,6 +1407,18 @@
 
 static void initializeErrorState()
 {
+    // Handle CPU1_MISMATCH if it's asserted now
+    if (cpu1MismatchLine.get_value() == 1)
+    {
+        cpuMismatchLog(1);
+    }
+
+    // Handle CPU2_MISMATCH if it's asserted now
+    if (cpu2MismatchLine.get_value() == 1)
+    {
+        cpuMismatchLog(2);
+    }
+
     // Handle CPU_CATERR if it's asserted now
     if (caterrLine.get_value() == 0)
     {
@@ -1530,6 +1556,20 @@
     std::shared_ptr<sdbusplus::bus::match::match> hostStateMonitor =
         host_error_monitor::startHostStateMonitor();
 
+    // Request CPU1_MISMATCH GPIO events
+    if (!host_error_monitor::requestGPIOInput(
+            "CPU1_MISMATCH", host_error_monitor::cpu1MismatchLine))
+    {
+        return -1;
+    }
+
+    // Request CPU2_MISMATCH GPIO events
+    if (!host_error_monitor::requestGPIOInput(
+            "CPU2_MISMATCH", host_error_monitor::cpu2MismatchLine))
+    {
+        return -1;
+    }
+
     // Initialize the host state
     host_error_monitor::initializeHostState();