Jason M. Bills | 5b61509 | 2020-12-11 16:15:28 -0800 | [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 <error_monitors/base_gpio_monitor.hpp> |
| 18 | #include <host_error_monitor.hpp> |
| 19 | #include <sdbusplus/asio/object_server.hpp> |
| 20 | |
| 21 | namespace host_error_monitor::mem_thermtrip_monitor |
| 22 | { |
| 23 | class MemThermtripMonitor : |
| 24 | public host_error_monitor::base_gpio_monitor::BaseGPIOMonitor |
| 25 | { |
| 26 | const static host_error_monitor::base_gpio_monitor::AssertValue |
| 27 | assertValue = |
| 28 | host_error_monitor::base_gpio_monitor::AssertValue::lowAssert; |
JinFuLin | a3d4a14 | 2022-12-05 15:38:35 +0800 | [diff] [blame] | 29 | std::shared_ptr<sdbusplus::asio::dbus_interface> assertInterface; |
Jason M. Bills | 5b61509 | 2020-12-11 16:15:28 -0800 | [diff] [blame] | 30 | size_t cpuNum; |
| 31 | |
| 32 | void logEvent() override |
| 33 | { |
| 34 | std::string cpuNumber = "CPU " + std::to_string(cpuNum); |
| 35 | std::string msg = cpuNumber + " Memory Thermal trip."; |
| 36 | |
| 37 | sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i", |
| 38 | LOG_ERR, "REDFISH_MESSAGE_ID=%s", |
| 39 | "OpenBMC.0.1.MemoryThermTrip", |
| 40 | "REDFISH_MESSAGE_ARGS=%s", cpuNumber.c_str(), NULL); |
JinFuLin | a3d4a14 | 2022-12-05 15:38:35 +0800 | [diff] [blame] | 41 | assertInterface->set_property("Asserted", true); |
| 42 | } |
| 43 | |
| 44 | void deassertHandler() override |
| 45 | { |
| 46 | assertInterface->set_property("Asserted", false); |
Jason M. Bills | 5b61509 | 2020-12-11 16:15:28 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | public: |
| 50 | MemThermtripMonitor(boost::asio::io_service& io, |
| 51 | std::shared_ptr<sdbusplus::asio::connection> conn, |
JinFuLin | a3d4a14 | 2022-12-05 15:38:35 +0800 | [diff] [blame] | 52 | const std::string& signalName, const size_t cpuNum, |
| 53 | const std::string& customName = std::string()) : |
Jason M. Bills | 5b61509 | 2020-12-11 16:15:28 -0800 | [diff] [blame] | 54 | BaseGPIOMonitor(io, conn, signalName, assertValue), |
| 55 | cpuNum(cpuNum) |
| 56 | { |
JinFuLin | a3d4a14 | 2022-12-05 15:38:35 +0800 | [diff] [blame] | 57 | sdbusplus::asio::object_server server = |
| 58 | sdbusplus::asio::object_server(conn); |
| 59 | std::string objectName = customName.empty() ? signalName : customName; |
| 60 | std::string path = |
| 61 | "/xyz/openbmc_project/host_error_monitor/processor/" + objectName; |
| 62 | |
| 63 | assertInterface = server.add_interface( |
| 64 | path, "xyz.openbmc_project.HostErrorMonitor.Processor.ThermalTrip"); |
| 65 | assertInterface->register_property("Asserted", false); |
| 66 | assertInterface->initialize(); |
Jason M. Bills | 5b61509 | 2020-12-11 16:15:28 -0800 | [diff] [blame] | 67 | if (valid) |
| 68 | { |
| 69 | startMonitoring(); |
| 70 | } |
| 71 | } |
| 72 | }; |
| 73 | } // namespace host_error_monitor::mem_thermtrip_monitor |