Handle host errors on host power-on

Some errors such as the Boot IVR (Thermtrip) could be asserted
when the host powers-on.  This change initializes the error
status on host power-on to handle those types of errors.

Tested:
Moved the jumper to persistently assert Thermtrip and pressed the
power button.  After the system immediately shut down, confirmed
that the Thermtrip event was logged.

Change-Id: Id782167e234d906aaadb6190d9b92beafa6ab84a
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 6ea0b9c..36b6384 100644
--- a/src/host_error_monitor.cpp
+++ b/src/host_error_monitor.cpp
@@ -211,16 +211,21 @@
             }
             hostOff = state == "xyz.openbmc_project.State.Host.HostState.Off";
 
-            // No host events should fire while off, so cancel any pending
-            // timers
             if (hostOff)
             {
+                // No host events should fire while off, so cancel any pending
+                // timers
                 caterrAssertTimer.cancel();
                 err0AssertTimer.cancel();
                 err1AssertTimer.cancel();
                 err2AssertTimer.cancel();
                 smiAssertTimer.cancel();
             }
+            else
+            {
+                // Handle any initial errors when the host turns on
+                initializeErrorState();
+            }
         });
 }
 
@@ -661,6 +666,11 @@
                            });
 }
 
+static void cpu1ThermtripAssertHandler()
+{
+    cpuThermTripLog(1);
+}
+
 static void cpu1ThermtripHandler()
 {
     if (!hostOff)
@@ -671,7 +681,7 @@
             gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
         if (cpu1Thermtrip)
         {
-            cpuThermTripLog(1);
+            cpu1ThermtripAssertHandler();
         }
     }
     cpu1ThermtripEvent.async_wait(
@@ -687,6 +697,11 @@
         });
 }
 
+static void cpu2ThermtripAssertHandler()
+{
+    cpuThermTripLog(2);
+}
+
 static void cpu2ThermtripHandler()
 {
     if (!hostOff)
@@ -697,7 +712,7 @@
             gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
         if (cpu2Thermtrip)
         {
-            cpuThermTripLog(2);
+            cpu2ThermtripAssertHandler();
         }
     }
     cpu2ThermtripEvent.async_wait(
@@ -713,6 +728,11 @@
         });
 }
 
+static void cpu1VRHotAssertHandler()
+{
+    cpuVRHotLog("CPU 1");
+}
+
 static void cpu1VRHotHandler()
 {
     if (!hostOff)
@@ -723,7 +743,7 @@
             gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
         if (cpu1VRHot)
         {
-            cpuVRHotLog("CPU 1");
+            cpu1VRHotAssertHandler();
         }
     }
     cpu1VRHotEvent.async_wait(boost::asio::posix::stream_descriptor::wait_read,
@@ -738,6 +758,11 @@
                               });
 }
 
+static void cpu1MemABCDVRHotAssertHandler()
+{
+    cpuVRHotLog("CPU 1 Memory ABCD");
+}
+
 static void cpu1MemABCDVRHotHandler()
 {
     if (!hostOff)
@@ -748,7 +773,7 @@
             gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
         if (cpu1MemABCDVRHot)
         {
-            cpuVRHotLog("CPU 1 Memory ABCD");
+            cpu1MemABCDVRHotAssertHandler();
         }
     }
     cpu1MemABCDVRHotEvent.async_wait(
@@ -764,6 +789,11 @@
         });
 }
 
+static void cpu1MemEFGHVRHotAssertHandler()
+{
+    cpuVRHotLog("CPU 1 Memory EFGH");
+}
+
 static void cpu1MemEFGHVRHotHandler()
 {
     if (!hostOff)
@@ -774,7 +804,7 @@
             gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
         if (cpu1MemEFGHVRHot)
         {
-            cpuVRHotLog("CPU 1 Memory EFGH");
+            cpu1MemEFGHVRHotAssertHandler();
         }
     }
     cpu1MemEFGHVRHotEvent.async_wait(
@@ -790,6 +820,11 @@
         });
 }
 
+static void cpu2VRHotAssertHandler()
+{
+    cpuVRHotLog("CPU 2");
+}
+
 static void cpu2VRHotHandler()
 {
     if (!hostOff)
@@ -800,7 +835,7 @@
             gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
         if (cpu2VRHot)
         {
-            cpuVRHotLog("CPU 2");
+            cpu2VRHotAssertHandler();
         }
     }
     cpu2VRHotEvent.async_wait(boost::asio::posix::stream_descriptor::wait_read,
@@ -815,6 +850,11 @@
                               });
 }
 
+static void cpu2MemABCDVRHotAssertHandler()
+{
+    cpuVRHotLog("CPU 2 Memory ABCD");
+}
+
 static void cpu2MemABCDVRHotHandler()
 {
     if (!hostOff)
@@ -825,7 +865,7 @@
             gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
         if (cpu2MemABCDVRHot)
         {
-            cpuVRHotLog("CPU 2 Memory ABCD");
+            cpu2MemABCDVRHotAssertHandler();
         }
     }
     cpu2MemABCDVRHotEvent.async_wait(
@@ -841,6 +881,11 @@
         });
 }
 
+static void cpu2MemEFGHVRHotAssertHandler()
+{
+    cpuVRHotLog("CPU 2 Memory EFGH");
+}
+
 static void cpu2MemEFGHVRHotHandler()
 {
     if (!hostOff)
@@ -851,7 +896,7 @@
             gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
         if (cpu2MemEFGHVRHot)
         {
-            cpuVRHotLog("CPU 2 Memory EFGH");
+            cpu2MemEFGHVRHotAssertHandler();
         }
     }
     cpu2MemEFGHVRHotEvent.async_wait(
@@ -1227,6 +1272,54 @@
         smiAssertHandler();
     }
 
+    // Handle CPU1_THERMTRIP if it's asserted now
+    if (cpu1ThermtripLine.get_value() == 0)
+    {
+        cpu1ThermtripAssertHandler();
+    }
+
+    // Handle CPU2_THERMTRIP if it's asserted now
+    if (cpu2ThermtripLine.get_value() == 0)
+    {
+        cpu2ThermtripAssertHandler();
+    }
+
+    // Handle CPU1_VRHOT if it's asserted now
+    if (cpu1VRHotLine.get_value() == 0)
+    {
+        cpu1VRHotAssertHandler();
+    }
+
+    // Handle CPU1_MEM_ABCD_VRHOT if it's asserted now
+    if (cpu1MemABCDVRHotLine.get_value() == 0)
+    {
+        cpu1MemABCDVRHotAssertHandler();
+    }
+
+    // Handle CPU1_MEM_EFGH_VRHOT if it's asserted now
+    if (cpu1MemEFGHVRHotLine.get_value() == 0)
+    {
+        cpu1MemEFGHVRHotAssertHandler();
+    }
+
+    // Handle CPU2_VRHOT if it's asserted now
+    if (cpu2VRHotLine.get_value() == 0)
+    {
+        cpu2VRHotAssertHandler();
+    }
+
+    // Handle CPU2_MEM_ABCD_VRHOT if it's asserted now
+    if (cpu2MemABCDVRHotLine.get_value() == 0)
+    {
+        cpu2MemABCDVRHotAssertHandler();
+    }
+
+    // Handle CPU2_MEM_EFGH_VRHOT if it's asserted now
+    if (cpu2MemEFGHVRHotLine.get_value() == 0)
+    {
+        cpu2MemEFGHVRHotAssertHandler();
+    }
+
     // Handle PCH_BMC_THERMTRIP if it's asserted now
     if (pchThermtripLine.get_value() == 0)
     {