blob: 0a1879be85dee8b1e6e616b8b8cb2dd0b4929bd2 [file] [log] [blame]
Jason M. Bills901cbca2020-12-11 15:34:50 -08001/*
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
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;
29 size_t cpuNum;
30 gpiod::line cpuFIVRFaultLine;
31
32 void logEvent() override
33 {
34 if (cpuFIVRFaultLine.get_value() == 0)
35 {
36 cpuBootFIVRFaultLog();
37 }
38 else
39 {
40 cpuThermTripLog();
41 }
42 }
43
44 void cpuBootFIVRFaultLog()
45 {
46 std::string msg = "Boot FIVR Fault on CPU " + std::to_string(cpuNum);
47
48 sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i",
49 LOG_INFO, "REDFISH_MESSAGE_ID=%s",
50 "OpenBMC.0.1.CPUError", "REDFISH_MESSAGE_ARGS=%s",
51 msg.c_str(), NULL);
52 }
53
54 void cpuThermTripLog()
55 {
56 std::string msg = "CPU " + std::to_string(cpuNum) + " thermal trip";
57
58 sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i",
59 LOG_INFO, "REDFISH_MESSAGE_ID=%s",
60 "OpenBMC.0.1.CPUThermalTrip", "REDFISH_MESSAGE_ARGS=%d",
61 cpuNum, NULL);
62 }
63
64 bool requestCPUFIVRFaultInput(const std::string& fivrSignalName)
65 {
66 // Find the GPIO line
67 cpuFIVRFaultLine = gpiod::find_line(fivrSignalName);
68 if (!cpuFIVRFaultLine)
69 {
70 std::cerr << "Failed to find the " << fivrSignalName << " line.\n";
71 return false;
72 }
73
74 // Request GPIO input
75 try
76 {
77 cpuFIVRFaultLine.request(
78 {"host-error-monitor", gpiod::line_request::DIRECTION_INPUT});
79 }
80 catch (std::exception&)
81 {
82 std::cerr << "Failed to request " << fivrSignalName << " input\n";
83 return false;
84 }
85
86 return true;
87 }
88
89 public:
90 CPUThermtripMonitor(boost::asio::io_service& io,
91 std::shared_ptr<sdbusplus::asio::connection> conn,
92 const std::string& signalName, const size_t cpuNum,
93 const std::string& fivrSignalName) :
94 BaseGPIOMonitor(io, conn, signalName, assertValue),
95 cpuNum(cpuNum)
96 {
97 if (!requestCPUFIVRFaultInput(fivrSignalName))
98 {
99 valid = false;
100 }
101
102 if (valid)
103 {
104 startMonitoring();
105 }
106 }
107};
108} // namespace host_error_monitor::cpu_thermtrip_monitor