Add CPU early error monitor

This adds a monitor for an early error signal from the CPU.

Tested:
Used the GPIO mock-up driver to confirm that the CPU early error is
logged when the GPIO asserts.

Change-Id: I0e7fd40dc97a9164e433cef536686855d0bc084c
Signed-off-by: Jason M. Bills <jason.m.bills@intel.com>
diff --git a/include/error_monitors/cpu_early_error_monitor.hpp b/include/error_monitors/cpu_early_error_monitor.hpp
new file mode 100644
index 0000000..ea5808a
--- /dev/null
+++ b/include/error_monitors/cpu_early_error_monitor.hpp
@@ -0,0 +1,55 @@
+/*
+// Copyright (c) 2022 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+#pragma once
+#include <error_monitors/base_gpio_monitor.hpp>
+#include <host_error_monitor.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+
+namespace host_error_monitor::cpu_early_error_monitor
+{
+class CPUEarlyErrorMonitor :
+    public host_error_monitor::base_gpio_monitor::BaseGPIOMonitor
+{
+    const static host_error_monitor::base_gpio_monitor::AssertValue
+        assertValue =
+            host_error_monitor::base_gpio_monitor::AssertValue::lowAssert;
+    size_t cpuNum;
+
+    void logEvent() override
+    {
+        std::string cpuNumber = "CPU " + std::to_string(cpuNum);
+        std::string msg = cpuNumber + " early error.";
+
+        sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i",
+                        LOG_ERR, "REDFISH_MESSAGE_ID=%s",
+                        "OpenBMC.0.1.CPUError", "REDFISH_MESSAGE_ARGS=%s",
+                        msg.c_str(), NULL);
+    }
+
+  public:
+    CPUEarlyErrorMonitor(boost::asio::io_service& io,
+                         std::shared_ptr<sdbusplus::asio::connection> conn,
+                         const std::string& signalName, const size_t cpuNum) :
+        BaseGPIOMonitor(io, conn, signalName, assertValue),
+        cpuNum(cpuNum)
+    {
+        if (valid)
+        {
+            startMonitoring();
+        }
+    }
+};
+} // namespace host_error_monitor::cpu_early_error_monitor