Jason M. Bills | 267b349 | 2021-06-28 13:09:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2021 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 | namespace host_error_monitor::cpld_crc_monitor |
| 24 | { |
| 25 | class CPLDCRCMonitor : |
| 26 | public host_error_monitor::base_gpio_monitor::BaseGPIOMonitor |
| 27 | { |
| 28 | const static host_error_monitor::base_gpio_monitor::AssertValue |
| 29 | assertValue = |
| 30 | host_error_monitor::base_gpio_monitor::AssertValue::highAssert; |
| 31 | size_t cpuNum; |
| 32 | bool cpuPresent; |
| 33 | |
| 34 | void logEvent() override |
| 35 | { |
| 36 | std::string cpuNumber = "CPU " + std::to_string(cpuNum); |
| 37 | std::string msg = cpuNumber + " CPLD CRC error."; |
| 38 | |
| 39 | sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i", |
| 40 | LOG_INFO, "REDFISH_MESSAGE_ID=%s", |
| 41 | "OpenBMC.0.1.CPUError", "REDFISH_MESSAGE_ARGS=%s", |
| 42 | msg.c_str(), NULL); |
| 43 | } |
| 44 | |
| 45 | bool getCPUPresence(const std::string& cpuPresenceName) |
| 46 | { |
| 47 | // Find the GPIO line |
| 48 | gpiod::line cpuPresenceLine = gpiod::find_line(cpuPresenceName); |
| 49 | if (!cpuPresenceLine) |
| 50 | { |
| 51 | std::cerr << "Failed to find the " << cpuPresenceName << " line.\n"; |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | // Request GPIO input |
| 56 | try |
| 57 | { |
| 58 | cpuPresenceLine.request( |
| 59 | {"host-error-monitor", gpiod::line_request::DIRECTION_INPUT}); |
| 60 | } |
| 61 | catch (std::exception&) |
| 62 | { |
| 63 | std::cerr << "Failed to request " << cpuPresenceName << " input\n"; |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | // CPU presence is low-assert |
| 68 | cpuPresent = !cpuPresenceLine.get_value(); |
| 69 | |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | void assertHandler() override |
| 74 | { |
| 75 | // Ignore this if the CPU is not present |
| 76 | if (cpuPresent) |
| 77 | { |
| 78 | host_error_monitor::base_gpio_monitor::BaseGPIOMonitor:: |
| 79 | assertHandler(); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /** @brief Constructor to create a CPLD CRC signal monitor |
| 84 | * @param[in] io - ASIO io_service |
| 85 | * @param[in] conn - ASIO connection |
| 86 | * @param[in] signalName - GPIO name of the signal to monitor |
| 87 | * @param[in] cpuNum - CPU number associated with the signal |
| 88 | * @param[in] cpuPresenceName - Name of the GPIO that can be read to check |
| 89 | * if the CPU is present |
| 90 | */ |
| 91 | public: |
| 92 | CPLDCRCMonitor(boost::asio::io_service& io, |
| 93 | std::shared_ptr<sdbusplus::asio::connection> conn, |
| 94 | const std::string& signalName, const size_t cpuNum, |
| 95 | const std::string& cpuPresenceName) : |
| 96 | BaseGPIOMonitor(io, conn, signalName, assertValue), |
| 97 | cpuNum(cpuNum) |
| 98 | { |
| 99 | if (!getCPUPresence(cpuPresenceName)) |
| 100 | { |
| 101 | valid = false; |
| 102 | } |
| 103 | |
| 104 | if (valid) |
| 105 | { |
| 106 | startMonitoring(); |
| 107 | } |
| 108 | } |
| 109 | }; |
| 110 | } // namespace host_error_monitor::cpld_crc_monitor |