Jason M. Bills | 901cbca | 2020-12-11 15:34:50 -0800 | [diff] [blame] | 1 | /* |
Jason M. Bills | 1a08117 | 2022-08-29 09:18:06 -0700 | [diff] [blame] | 2 | // Copyright (c) 2021-2022 Intel Corporation |
Jason M. Bills | 901cbca | 2020-12-11 15:34:50 -0800 | [diff] [blame] | 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::cpu_thermtrip_monitor |
| 22 | { |
| 23 | class CPUThermtripMonitor : |
| 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 | 5c7776d | 2022-12-05 15:48:38 +0800 | [diff] [blame] | 29 | std::shared_ptr<sdbusplus::asio::dbus_interface> assertInterface; |
Jason M. Bills | 901cbca | 2020-12-11 15:34:50 -0800 | [diff] [blame] | 30 | size_t cpuNum; |
Jason M. Bills | 901cbca | 2020-12-11 15:34:50 -0800 | [diff] [blame] | 31 | |
| 32 | void logEvent() override |
| 33 | { |
JinFuLin | 5c7776d | 2022-12-05 15:48:38 +0800 | [diff] [blame] | 34 | assertInterface->set_property("Asserted", true); |
Jason M. Bills | 1a08117 | 2022-08-29 09:18:06 -0700 | [diff] [blame] | 35 | cpuThermTripLog(); |
Jason M. Bills | 901cbca | 2020-12-11 15:34:50 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | void cpuThermTripLog() |
| 39 | { |
| 40 | std::string msg = "CPU " + std::to_string(cpuNum) + " thermal trip"; |
| 41 | |
| 42 | sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i", |
| 43 | LOG_INFO, "REDFISH_MESSAGE_ID=%s", |
| 44 | "OpenBMC.0.1.CPUThermalTrip", "REDFISH_MESSAGE_ARGS=%d", |
| 45 | cpuNum, NULL); |
| 46 | } |
| 47 | |
JinFuLin | 5c7776d | 2022-12-05 15:48:38 +0800 | [diff] [blame] | 48 | void deassertHandler() override |
| 49 | { |
| 50 | assertInterface->set_property("Asserted", false); |
| 51 | } |
| 52 | |
Jason M. Bills | 901cbca | 2020-12-11 15:34:50 -0800 | [diff] [blame] | 53 | public: |
| 54 | CPUThermtripMonitor(boost::asio::io_service& io, |
| 55 | std::shared_ptr<sdbusplus::asio::connection> conn, |
JinFuLin | 5c7776d | 2022-12-05 15:48:38 +0800 | [diff] [blame] | 56 | const std::string& signalName, const size_t cpuNum, |
| 57 | const std::string& customName = std::string()) : |
Jason M. Bills | 901cbca | 2020-12-11 15:34:50 -0800 | [diff] [blame] | 58 | BaseGPIOMonitor(io, conn, signalName, assertValue), |
| 59 | cpuNum(cpuNum) |
| 60 | { |
JinFuLin | 5c7776d | 2022-12-05 15:48:38 +0800 | [diff] [blame] | 61 | sdbusplus::asio::object_server server = |
| 62 | sdbusplus::asio::object_server(conn); |
| 63 | std::string objectName = customName.empty() ? signalName : customName; |
| 64 | std::string path = |
| 65 | "/xyz/openbmc_project/host_error_monitor/processor/" + objectName; |
| 66 | |
| 67 | assertInterface = server.add_interface( |
| 68 | path, "xyz.openbmc_project.HostErrorMonitor.Processor.ThermalTrip"); |
| 69 | assertInterface->register_property("Asserted", false); |
| 70 | assertInterface->initialize(); |
Jason M. Bills | 901cbca | 2020-12-11 15:34:50 -0800 | [diff] [blame] | 71 | if (valid) |
| 72 | { |
| 73 | startMonitoring(); |
| 74 | } |
| 75 | } |
| 76 | }; |
| 77 | } // namespace host_error_monitor::cpu_thermtrip_monitor |