Jason M. Bills | 779e1f8 | 2022-03-14 13:43:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2022 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | #include <systemd/sd-journal.h> |
| 18 | |
| 19 | #include <error_monitors/base_gpio_monitor.hpp> |
| 20 | #include <host_error_monitor.hpp> |
| 21 | #include <sdbusplus/asio/object_server.hpp> |
| 22 | |
| 23 | #include <bitset> |
| 24 | |
| 25 | namespace host_error_monitor::err_pin_monitor |
| 26 | { |
| 27 | static constexpr bool debug = false; |
| 28 | |
| 29 | class ErrPinMonitor : |
| 30 | public host_error_monitor::base_gpio_monitor::BaseGPIOMonitor |
| 31 | { |
| 32 | size_t errPin; |
| 33 | std::bitset<MAX_CPUS> errPinCPUs; |
| 34 | const static host_error_monitor::base_gpio_monitor::AssertValue |
| 35 | assertValue = |
| 36 | host_error_monitor::base_gpio_monitor::AssertValue::lowAssert; |
| 37 | |
| 38 | void logEvent() |
| 39 | { |
| 40 | checkErrPinCPUs(errPin, errPinCPUs); |
| 41 | if (errPinCPUs.none()) |
| 42 | { |
| 43 | return errPinLog(); |
| 44 | } |
| 45 | |
| 46 | for (size_t i = 0; i < errPinCPUs.size(); i++) |
| 47 | { |
| 48 | if (errPinCPUs[i]) |
| 49 | { |
| 50 | errPinLog(i); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | void errPinLog() |
| 56 | { |
| 57 | std::string msg = "ERR" + std::to_string(errPin); |
| 58 | |
| 59 | sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i", |
| 60 | LOG_INFO, "REDFISH_MESSAGE_ID=%s", |
| 61 | "OpenBMC.0.1.CPUError", "REDFISH_MESSAGE_ARGS=%s", |
| 62 | msg.c_str(), NULL); |
| 63 | } |
| 64 | |
| 65 | void errPinLog(const int cpuNum) |
| 66 | { |
| 67 | std::string msg = "ERR" + std::to_string(errPin) + " on CPU " + |
| 68 | std::to_string(cpuNum + 1); |
| 69 | |
| 70 | sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i", |
| 71 | LOG_INFO, "REDFISH_MESSAGE_ID=%s", |
| 72 | "OpenBMC.0.1.CPUError", "REDFISH_MESSAGE_ARGS=%s", |
| 73 | msg.c_str(), NULL); |
| 74 | } |
| 75 | |
| 76 | public: |
| 77 | ErrPinMonitor(boost::asio::io_service& io, |
| 78 | std::shared_ptr<sdbusplus::asio::connection> conn, |
| 79 | const std::string& signalName, const size_t errPin) : |
| 80 | BaseGPIOMonitor(io, conn, signalName, assertValue), |
| 81 | errPin(errPin) |
| 82 | { |
| 83 | if (valid) |
| 84 | { |
| 85 | startMonitoring(); |
| 86 | } |
| 87 | } |
| 88 | }; |
| 89 | } // namespace host_error_monitor::err_pin_monitor |