blob: f1b77585f7b146e464391acdd73eccea6fade221 [file] [log] [blame]
Jason M. Bills901cbca2020-12-11 15:34:50 -08001/*
Jason M. Bills1a081172022-08-29 09:18:06 -07002// Copyright (c) 2021-2022 Intel Corporation
Jason M. Bills901cbca2020-12-11 15:34:50 -08003//
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
21namespace host_error_monitor::cpu_thermtrip_monitor
22{
23class 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;
JinFuLin5c7776d2022-12-05 15:48:38 +080029 std::shared_ptr<sdbusplus::asio::dbus_interface> assertInterface;
Jason M. Bills901cbca2020-12-11 15:34:50 -080030 size_t cpuNum;
Jason M. Bills901cbca2020-12-11 15:34:50 -080031
32 void logEvent() override
33 {
JinFuLin5c7776d2022-12-05 15:48:38 +080034 assertInterface->set_property("Asserted", true);
Jason M. Bills1a081172022-08-29 09:18:06 -070035 cpuThermTripLog();
Jason M. Bills901cbca2020-12-11 15:34:50 -080036 }
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
JinFuLin5c7776d2022-12-05 15:48:38 +080048 void deassertHandler() override
49 {
50 assertInterface->set_property("Asserted", false);
51 }
52
Jason M. Bills901cbca2020-12-11 15:34:50 -080053 public:
Ed Tanousee00ccc2023-03-01 10:37:43 -080054 CPUThermtripMonitor(boost::asio::io_context& io,
Jason M. Bills901cbca2020-12-11 15:34:50 -080055 std::shared_ptr<sdbusplus::asio::connection> conn,
JinFuLin5c7776d2022-12-05 15:48:38 +080056 const std::string& signalName, const size_t cpuNum,
57 const std::string& customName = std::string()) :
Jason M. Bills901cbca2020-12-11 15:34:50 -080058 BaseGPIOMonitor(io, conn, signalName, assertValue),
59 cpuNum(cpuNum)
60 {
JinFuLin5c7776d2022-12-05 15:48:38 +080061 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. Bills901cbca2020-12-11 15:34:50 -080071 if (valid)
72 {
73 startMonitoring();
74 }
75 }
76};
77} // namespace host_error_monitor::cpu_thermtrip_monitor