Add CPU VRHOT monitoring and logging

This adds a monitor for the CPU VRHOT signals.

Tested:
Heated each CPU VR with a heat gun and verfied that the CPU VRHOT
event was logged.

Change-Id: Id9ed34a4fabf1e81461d267a74110efd6d4c817d
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
diff --git a/src/host_error_monitor.cpp b/src/host_error_monitor.cpp
index 58231db..e0cb2e4 100644
--- a/src/host_error_monitor.cpp
+++ b/src/host_error_monitor.cpp
@@ -62,6 +62,10 @@
 static boost::asio::posix::stream_descriptor cpu1ThermtripEvent(io);
 static gpiod::line cpu2ThermtripLine;
 static boost::asio::posix::stream_descriptor cpu2ThermtripEvent(io);
+static gpiod::line cpu1VRHotLine;
+static boost::asio::posix::stream_descriptor cpu1VRHotEvent(io);
+static gpiod::line cpu2VRHotLine;
+static boost::asio::posix::stream_descriptor cpu2VRHotEvent(io);
 //----------------------------------
 // PCH_BMC_THERMTRIP function related definition
 //----------------------------------
@@ -129,6 +133,16 @@
                     cpuNum, NULL);
 }
 
+static void cpuVRHotLog(const std::string& vr)
+{
+    std::string msg = vr + " Voltage Regulator Overheated.";
+
+    sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i",
+                    LOG_INFO, "REDFISH_MESSAGE_ID=%s",
+                    "OpenBMC.0.1.VoltageRegulatorOverheated",
+                    "REDFISH_MESSAGE_ARGS=%s", vr.c_str(), NULL);
+}
+
 static void ssbThermTripLog()
 {
     sd_journal_send("MESSAGE=HostError: SSB thermal trip", "PRIORITY=%i",
@@ -691,6 +705,56 @@
         });
 }
 
+static void cpu1VRHotHandler()
+{
+    if (!hostOff)
+    {
+        gpiod::line_event gpioLineEvent = cpu1VRHotLine.event_read();
+
+        bool cpu1VRHot =
+            gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
+        if (cpu1VRHot)
+        {
+            cpuVRHotLog("CPU 1");
+        }
+    }
+    cpu1VRHotEvent.async_wait(boost::asio::posix::stream_descriptor::wait_read,
+                              [](const boost::system::error_code ec) {
+                                  if (ec)
+                                  {
+                                      std::cerr << "CPU 1 VRHot handler error: "
+                                                << ec.message() << "\n";
+                                      return;
+                                  }
+                                  cpu1VRHotHandler();
+                              });
+}
+
+static void cpu2VRHotHandler()
+{
+    if (!hostOff)
+    {
+        gpiod::line_event gpioLineEvent = cpu2VRHotLine.event_read();
+
+        bool cpu2VRHot =
+            gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
+        if (cpu2VRHot)
+        {
+            cpuVRHotLog("CPU 2");
+        }
+    }
+    cpu2VRHotEvent.async_wait(boost::asio::posix::stream_descriptor::wait_read,
+                              [](const boost::system::error_code ec) {
+                                  if (ec)
+                                  {
+                                      std::cerr << "CPU 2 VRHot handler error: "
+                                                << ec.message() << "\n";
+                                      return;
+                                  }
+                                  cpu2VRHotHandler();
+                              });
+}
+
 static void pchThermtripHandler()
 {
     if (!hostOff)
@@ -1136,6 +1200,24 @@
         return -1;
     }
 
+    // Request CPU1_VRHOT GPIO events
+    if (!host_error_monitor::requestGPIOEvents(
+            "CPU1_VRHOT", host_error_monitor::cpu1VRHotHandler,
+            host_error_monitor::cpu1VRHotLine,
+            host_error_monitor::cpu1VRHotEvent))
+    {
+        return -1;
+    }
+
+    // Request CPU2_VRHOT GPIO events
+    if (!host_error_monitor::requestGPIOEvents(
+            "CPU2_VRHOT", host_error_monitor::cpu2VRHotHandler,
+            host_error_monitor::cpu2VRHotLine,
+            host_error_monitor::cpu2VRHotEvent))
+    {
+        return -1;
+    }
+
     // Request PCH_BMC_THERMTRIP GPIO events
     if (!host_error_monitor::requestGPIOEvents(
             "PCH_BMC_THERMTRIP", host_error_monitor::pchThermtripHandler,