blob: 02668fa1c4b2d4c6e2b9d79ee6072bf329c5bb64 [file] [log] [blame]
Jason M. Bills1490b142019-07-01 15:48:43 -07001/*
2// Copyright (c) 2019 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*/
Jason M. Bills6a2cb692019-08-06 11:03:49 -070016#include <peci.h>
Chen Yugange6c0f1c2019-08-02 20:36:42 +080017#include <systemd/sd-journal.h>
18
Jason M. Bills08b2c7a2020-08-28 15:39:14 -070019#include <boost/asio/io_service.hpp>
Jason M. Bills1490b142019-07-01 15:48:43 -070020#include <boost/asio/posix/stream_descriptor.hpp>
Jason M. Bills08b2c7a2020-08-28 15:39:14 -070021#include <boost/asio/steady_timer.hpp>
Jason M. Bills5245ed62020-12-04 16:50:21 -080022#include <error_monitors.hpp>
Jason M. Bills1490b142019-07-01 15:48:43 -070023#include <gpiod.hpp>
Jason M. Billsd711cc82020-12-04 16:46:39 -080024#include <host_error_monitor.hpp>
Jason M. Bills1490b142019-07-01 15:48:43 -070025#include <sdbusplus/asio/object_server.hpp>
Jason M. Bills48e5dff2020-06-10 13:47:47 -070026
27#include <bitset>
28#include <iostream>
Jason M. Billsd1a19f62019-08-06 11:52:58 -070029#include <variant>
Jason M. Bills1490b142019-07-01 15:48:43 -070030
31namespace host_error_monitor
32{
33static boost::asio::io_service io;
34static std::shared_ptr<sdbusplus::asio::connection> conn;
35
Yong Li1429ca82020-04-27 16:49:45 +080036static std::shared_ptr<sdbusplus::asio::dbus_interface> associationSSBThermTrip;
Yong Li1429ca82020-04-27 16:49:45 +080037
38static const constexpr char* rootPath = "/xyz/openbmc_project/CallbackManager";
39
Jason M. Bills1490b142019-07-01 15:48:43 -070040static bool hostOff = true;
Jason M. Billsd711cc82020-12-04 16:46:39 -080041bool hostIsOff()
42{
43 return hostOff;
44}
Jason M. Bills1490b142019-07-01 15:48:43 -070045
Jason M. Bills1490b142019-07-01 15:48:43 -070046// GPIO Lines and Event Descriptors
Jason M. Bills45e87e02019-09-09 14:45:38 -070047static gpiod::line cpu1FIVRFaultLine;
Jason M. Bills78c5eed2019-08-28 14:00:40 -070048static gpiod::line cpu1ThermtripLine;
49static boost::asio::posix::stream_descriptor cpu1ThermtripEvent(io);
Jason M. Bills45e87e02019-09-09 14:45:38 -070050static gpiod::line cpu2FIVRFaultLine;
Jason M. Bills78c5eed2019-08-28 14:00:40 -070051static gpiod::line cpu2ThermtripLine;
52static boost::asio::posix::stream_descriptor cpu2ThermtripEvent(io);
Jason M. Bills250fa632019-08-28 15:58:25 -070053static gpiod::line cpu1VRHotLine;
54static boost::asio::posix::stream_descriptor cpu1VRHotEvent(io);
55static gpiod::line cpu2VRHotLine;
Jason M. Bills9647ba72019-08-29 14:19:19 -070056static boost::asio::posix::stream_descriptor cpu1MemABCDVRHotEvent(io);
57static gpiod::line cpu1MemEFGHVRHotLine;
58static boost::asio::posix::stream_descriptor cpu1MemEFGHVRHotEvent(io);
59static gpiod::line cpu2MemABCDVRHotLine;
Jason M. Bills250fa632019-08-28 15:58:25 -070060static boost::asio::posix::stream_descriptor cpu2VRHotEvent(io);
Jason M. Bills9647ba72019-08-29 14:19:19 -070061static gpiod::line cpu1MemABCDVRHotLine;
62static boost::asio::posix::stream_descriptor cpu2MemABCDVRHotEvent(io);
63static gpiod::line cpu2MemEFGHVRHotLine;
64static boost::asio::posix::stream_descriptor cpu2MemEFGHVRHotEvent(io);
Chen Yugange6c0f1c2019-08-02 20:36:42 +080065//----------------------------------
66// PCH_BMC_THERMTRIP function related definition
67//----------------------------------
Chen Yugange6c0f1c2019-08-02 20:36:42 +080068static gpiod::line pchThermtripLine;
69static boost::asio::posix::stream_descriptor pchThermtripEvent(io);
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +000070//----------------------------------
71// CPU_MEM_THERM_EVENT function related definition
72//----------------------------------
73static gpiod::line cpu1MemtripLine;
74static boost::asio::posix::stream_descriptor cpu1MemtripEvent(io);
75static gpiod::line cpu2MemtripLine;
76static boost::asio::posix::stream_descriptor cpu2MemtripEvent(io);
Jason M. Bills1490b142019-07-01 15:48:43 -070077
Jason M. Bills45e87e02019-09-09 14:45:38 -070078static void cpuBootFIVRFaultLog(const int cpuNum)
79{
80 std::string msg = "Boot FIVR Fault on CPU " + std::to_string(cpuNum);
81
82 sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i",
83 LOG_INFO, "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.CPUError",
84 "REDFISH_MESSAGE_ARGS=%s", msg.c_str(), NULL);
85}
86
Jason M. Bills78c5eed2019-08-28 14:00:40 -070087static void cpuThermTripLog(const int cpuNum)
88{
89 std::string msg = "CPU " + std::to_string(cpuNum) + " thermal trip";
90
91 sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i",
92 LOG_INFO, "REDFISH_MESSAGE_ID=%s",
93 "OpenBMC.0.1.CPUThermalTrip", "REDFISH_MESSAGE_ARGS=%d",
94 cpuNum, NULL);
95}
96
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +000097static void memThermTripLog(const int cpuNum)
98{
99 std::string cpuNumber = "CPU " + std::to_string(cpuNum);
100 std::string msg = cpuNumber + " Memory Thermal trip.";
101
102 sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i",
103 LOG_ERR, "REDFISH_MESSAGE_ID=%s",
104 "OpenBMC.0.1.MemoryThermTrip", "REDFISH_MESSAGE_ARGS=%s",
105 cpuNumber.c_str(), NULL);
106}
107
Jason M. Bills250fa632019-08-28 15:58:25 -0700108static void cpuVRHotLog(const std::string& vr)
109{
110 std::string msg = vr + " Voltage Regulator Overheated.";
111
112 sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i",
113 LOG_INFO, "REDFISH_MESSAGE_ID=%s",
114 "OpenBMC.0.1.VoltageRegulatorOverheated",
115 "REDFISH_MESSAGE_ARGS=%s", vr.c_str(), NULL);
116}
117
Jason M. Bills08866542019-08-16 12:04:19 -0700118static void ssbThermTripLog()
119{
120 sd_journal_send("MESSAGE=HostError: SSB thermal trip", "PRIORITY=%i",
121 LOG_INFO, "REDFISH_MESSAGE_ID=%s",
122 "OpenBMC.0.1.SsbThermalTrip", NULL);
123}
124
Jason M. Billsa15c2522019-08-16 10:01:44 -0700125static void initializeErrorState();
Jason M. Bills5245ed62020-12-04 16:50:21 -0800126static void init()
Jason M. Bills1490b142019-07-01 15:48:43 -0700127{
Jason M. Bills5245ed62020-12-04 16:50:21 -0800128 // Get the current host state to prepare to start the signal monitors
Jason M. Bills1490b142019-07-01 15:48:43 -0700129 conn->async_method_call(
130 [](boost::system::error_code ec,
131 const std::variant<std::string>& property) {
132 if (ec)
133 {
134 return;
135 }
136 const std::string* state = std::get_if<std::string>(&property);
137 if (state == nullptr)
138 {
139 std::cerr << "Unable to read host state value\n";
140 return;
141 }
142 hostOff = *state == "xyz.openbmc_project.State.Host.HostState.Off";
Jason M. Billsa15c2522019-08-16 10:01:44 -0700143 // If the system is on, initialize the error state
144 if (!hostOff)
145 {
146 initializeErrorState();
147 }
Jason M. Bills5245ed62020-12-04 16:50:21 -0800148
149 // Now we have the host state, start the signal monitors
150 if (!error_monitors::startMonitors(io, conn))
151 {
152 throw std::runtime_error("Failed to start signal monitors");
153 }
Jason M. Bills1490b142019-07-01 15:48:43 -0700154 },
155 "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
156 "org.freedesktop.DBus.Properties", "Get",
157 "xyz.openbmc_project.State.Host", "CurrentHostState");
158}
159
160static std::shared_ptr<sdbusplus::bus::match::match> startHostStateMonitor()
161{
162 return std::make_shared<sdbusplus::bus::match::match>(
163 *conn,
164 "type='signal',interface='org.freedesktop.DBus.Properties',"
Jason M. Bills2fbb9ea2020-06-19 14:46:54 -0700165 "member='PropertiesChanged',arg0='xyz.openbmc_project.State.Host'",
Jason M. Bills1490b142019-07-01 15:48:43 -0700166 [](sdbusplus::message::message& msg) {
167 std::string interfaceName;
168 boost::container::flat_map<std::string, std::variant<std::string>>
169 propertiesChanged;
Jason M. Bills1490b142019-07-01 15:48:43 -0700170 try
171 {
172 msg.read(interfaceName, propertiesChanged);
Jason M. Bills1490b142019-07-01 15:48:43 -0700173 }
174 catch (std::exception& e)
175 {
176 std::cerr << "Unable to read host state\n";
177 return;
178 }
Jason M. Bills566ccc42020-06-18 16:38:26 -0700179 // We only want to check for CurrentHostState
180 if (propertiesChanged.begin()->first != "CurrentHostState")
181 {
182 return;
183 }
184 std::string* state =
185 std::get_if<std::string>(&(propertiesChanged.begin()->second));
186 if (state == nullptr)
187 {
188 std::cerr << propertiesChanged.begin()->first
189 << " property invalid\n";
190 return;
191 }
192
193 hostOff = *state == "xyz.openbmc_project.State.Host.HostState.Off";
Jason M. Bills1490b142019-07-01 15:48:43 -0700194
Jason M. Bills8fa1c962020-12-10 14:33:56 -0800195 if (!hostOff)
Jason M. Billse94f5e12019-09-13 11:11:34 -0700196 {
197 // Handle any initial errors when the host turns on
198 initializeErrorState();
Jason M. Bills5245ed62020-12-04 16:50:21 -0800199 error_monitors::sendHostOn();
Jason M. Billse94f5e12019-09-13 11:11:34 -0700200 }
Jason M. Bills1490b142019-07-01 15:48:43 -0700201 });
202}
203
204static bool requestGPIOEvents(
205 const std::string& name, const std::function<void()>& handler,
206 gpiod::line& gpioLine,
207 boost::asio::posix::stream_descriptor& gpioEventDescriptor)
208{
209 // Find the GPIO line
210 gpioLine = gpiod::find_line(name);
211 if (!gpioLine)
212 {
213 std::cerr << "Failed to find the " << name << " line\n";
214 return false;
215 }
216
217 try
218 {
219 gpioLine.request(
220 {"host-error-monitor", gpiod::line_request::EVENT_BOTH_EDGES});
221 }
222 catch (std::exception&)
223 {
224 std::cerr << "Failed to request events for " << name << "\n";
225 return false;
226 }
227
228 int gpioLineFd = gpioLine.event_get_fd();
229 if (gpioLineFd < 0)
230 {
231 std::cerr << "Failed to get " << name << " fd\n";
232 return false;
233 }
234
235 gpioEventDescriptor.assign(gpioLineFd);
236
237 gpioEventDescriptor.async_wait(
238 boost::asio::posix::stream_descriptor::wait_read,
239 [&name, handler](const boost::system::error_code ec) {
240 if (ec)
241 {
242 std::cerr << name << " fd handler error: " << ec.message()
243 << "\n";
244 return;
245 }
246 handler();
247 });
248 return true;
249}
250
Jason M. Bills45e87e02019-09-09 14:45:38 -0700251static bool requestGPIOInput(const std::string& name, gpiod::line& gpioLine)
252{
253 // Find the GPIO line
254 gpioLine = gpiod::find_line(name);
255 if (!gpioLine)
256 {
257 std::cerr << "Failed to find the " << name << " line.\n";
258 return false;
259 }
260
261 // Request GPIO input
262 try
263 {
264 gpioLine.request({__FUNCTION__, gpiod::line_request::DIRECTION_INPUT});
265 }
266 catch (std::exception&)
267 {
268 std::cerr << "Failed to request " << name << " input\n";
269 return false;
270 }
271
272 return true;
273}
274
Jason M. Billse94f5e12019-09-13 11:11:34 -0700275static void cpu1ThermtripAssertHandler()
276{
Jason M. Bills45e87e02019-09-09 14:45:38 -0700277 if (cpu1FIVRFaultLine.get_value() == 0)
278 {
279 cpuBootFIVRFaultLog(1);
280 }
281 else
282 {
283 cpuThermTripLog(1);
284 }
Jason M. Billse94f5e12019-09-13 11:11:34 -0700285}
286
Jason M. Bills78c5eed2019-08-28 14:00:40 -0700287static void cpu1ThermtripHandler()
288{
Jason M. Bills84951142020-04-17 15:57:11 -0700289 gpiod::line_event gpioLineEvent = cpu1ThermtripLine.event_read();
Jason M. Bills78c5eed2019-08-28 14:00:40 -0700290
Jason M. Bills84951142020-04-17 15:57:11 -0700291 bool cpu1Thermtrip =
292 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
293 if (cpu1Thermtrip)
294 {
295 cpu1ThermtripAssertHandler();
Jason M. Bills78c5eed2019-08-28 14:00:40 -0700296 }
Jason M. Bills84951142020-04-17 15:57:11 -0700297
Jason M. Bills78c5eed2019-08-28 14:00:40 -0700298 cpu1ThermtripEvent.async_wait(
299 boost::asio::posix::stream_descriptor::wait_read,
300 [](const boost::system::error_code ec) {
301 if (ec)
302 {
303 std::cerr << "CPU 1 Thermtrip handler error: " << ec.message()
304 << "\n";
305 return;
306 }
307 cpu1ThermtripHandler();
308 });
309}
310
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000311static void cpu1MemtripHandler()
312{
Jason M. Bills5287c022020-05-19 11:16:09 -0700313 gpiod::line_event gpioLineEvent = cpu1MemtripLine.event_read();
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000314
Jason M. Bills5287c022020-05-19 11:16:09 -0700315 bool cpu1Memtrip =
316 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
317 if (cpu1Memtrip)
318 {
319 memThermTripLog(1);
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000320 }
Jason M. Bills5287c022020-05-19 11:16:09 -0700321
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000322 cpu1MemtripEvent.async_wait(
323 boost::asio::posix::stream_descriptor::wait_read,
324 [](const boost::system::error_code ec) {
325 if (ec)
326 {
327 std::cerr << "CPU 1 Memory Thermaltrip handler error: "
328 << ec.message() << "\n";
329 return;
330 }
331 cpu1MemtripHandler();
332 });
333}
334
Jason M. Billse94f5e12019-09-13 11:11:34 -0700335static void cpu2ThermtripAssertHandler()
336{
Jason M. Bills45e87e02019-09-09 14:45:38 -0700337 if (cpu2FIVRFaultLine.get_value() == 0)
338 {
339 cpuBootFIVRFaultLog(2);
340 }
341 else
342 {
343 cpuThermTripLog(2);
344 }
Jason M. Billse94f5e12019-09-13 11:11:34 -0700345}
346
Jason M. Bills78c5eed2019-08-28 14:00:40 -0700347static void cpu2ThermtripHandler()
348{
Jason M. Bills84951142020-04-17 15:57:11 -0700349 gpiod::line_event gpioLineEvent = cpu2ThermtripLine.event_read();
Jason M. Bills78c5eed2019-08-28 14:00:40 -0700350
Jason M. Bills84951142020-04-17 15:57:11 -0700351 bool cpu2Thermtrip =
352 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
353 if (cpu2Thermtrip)
354 {
355 cpu2ThermtripAssertHandler();
Jason M. Bills78c5eed2019-08-28 14:00:40 -0700356 }
Jason M. Bills84951142020-04-17 15:57:11 -0700357
Jason M. Bills78c5eed2019-08-28 14:00:40 -0700358 cpu2ThermtripEvent.async_wait(
359 boost::asio::posix::stream_descriptor::wait_read,
360 [](const boost::system::error_code ec) {
361 if (ec)
362 {
363 std::cerr << "CPU 2 Thermtrip handler error: " << ec.message()
364 << "\n";
365 return;
366 }
367 cpu2ThermtripHandler();
368 });
369}
370
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000371static void cpu2MemtripHandler()
372{
Jason M. Bills5287c022020-05-19 11:16:09 -0700373 gpiod::line_event gpioLineEvent = cpu2MemtripLine.event_read();
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000374
Jason M. Bills5287c022020-05-19 11:16:09 -0700375 bool cpu2Memtrip =
376 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
377 if (cpu2Memtrip)
378 {
379 memThermTripLog(2);
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000380 }
Jason M. Bills5287c022020-05-19 11:16:09 -0700381
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000382 cpu2MemtripEvent.async_wait(
383 boost::asio::posix::stream_descriptor::wait_read,
384 [](const boost::system::error_code ec) {
385 if (ec)
386 {
387 std::cerr << "CPU 2 Memory Thermaltrip handler error: "
388 << ec.message() << "\n";
389 return;
390 }
391 cpu2MemtripHandler();
392 });
393}
394
Jason M. Billse94f5e12019-09-13 11:11:34 -0700395static void cpu1VRHotAssertHandler()
396{
397 cpuVRHotLog("CPU 1");
398}
399
Jason M. Bills250fa632019-08-28 15:58:25 -0700400static void cpu1VRHotHandler()
401{
Jason M. Bills84951142020-04-17 15:57:11 -0700402 gpiod::line_event gpioLineEvent = cpu1VRHotLine.event_read();
Jason M. Bills250fa632019-08-28 15:58:25 -0700403
Jason M. Bills84951142020-04-17 15:57:11 -0700404 bool cpu1VRHot =
405 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
406 if (cpu1VRHot)
407 {
408 cpu1VRHotAssertHandler();
Jason M. Bills250fa632019-08-28 15:58:25 -0700409 }
Jason M. Bills84951142020-04-17 15:57:11 -0700410
Jason M. Bills250fa632019-08-28 15:58:25 -0700411 cpu1VRHotEvent.async_wait(boost::asio::posix::stream_descriptor::wait_read,
412 [](const boost::system::error_code ec) {
413 if (ec)
414 {
415 std::cerr << "CPU 1 VRHot handler error: "
416 << ec.message() << "\n";
417 return;
418 }
419 cpu1VRHotHandler();
420 });
421}
422
Jason M. Billse94f5e12019-09-13 11:11:34 -0700423static void cpu1MemABCDVRHotAssertHandler()
424{
425 cpuVRHotLog("CPU 1 Memory ABCD");
426}
427
Jason M. Bills9647ba72019-08-29 14:19:19 -0700428static void cpu1MemABCDVRHotHandler()
429{
Jason M. Bills84951142020-04-17 15:57:11 -0700430 gpiod::line_event gpioLineEvent = cpu1MemABCDVRHotLine.event_read();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700431
Jason M. Bills84951142020-04-17 15:57:11 -0700432 bool cpu1MemABCDVRHot =
433 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
434 if (cpu1MemABCDVRHot)
435 {
436 cpu1MemABCDVRHotAssertHandler();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700437 }
Jason M. Bills84951142020-04-17 15:57:11 -0700438
Jason M. Bills9647ba72019-08-29 14:19:19 -0700439 cpu1MemABCDVRHotEvent.async_wait(
440 boost::asio::posix::stream_descriptor::wait_read,
441 [](const boost::system::error_code ec) {
442 if (ec)
443 {
444 std::cerr << "CPU 1 Memory ABCD VRHot handler error: "
445 << ec.message() << "\n";
446 return;
447 }
448 cpu1MemABCDVRHotHandler();
449 });
450}
451
Jason M. Billse94f5e12019-09-13 11:11:34 -0700452static void cpu1MemEFGHVRHotAssertHandler()
453{
454 cpuVRHotLog("CPU 1 Memory EFGH");
455}
456
Jason M. Bills9647ba72019-08-29 14:19:19 -0700457static void cpu1MemEFGHVRHotHandler()
458{
Jason M. Bills84951142020-04-17 15:57:11 -0700459 gpiod::line_event gpioLineEvent = cpu1MemEFGHVRHotLine.event_read();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700460
Jason M. Bills84951142020-04-17 15:57:11 -0700461 bool cpu1MemEFGHVRHot =
462 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
463 if (cpu1MemEFGHVRHot)
464 {
465 cpu1MemEFGHVRHotAssertHandler();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700466 }
Jason M. Bills84951142020-04-17 15:57:11 -0700467
Jason M. Bills9647ba72019-08-29 14:19:19 -0700468 cpu1MemEFGHVRHotEvent.async_wait(
469 boost::asio::posix::stream_descriptor::wait_read,
470 [](const boost::system::error_code ec) {
471 if (ec)
472 {
473 std::cerr << "CPU 1 Memory EFGH VRHot handler error: "
474 << ec.message() << "\n";
475 return;
476 }
477 cpu1MemEFGHVRHotHandler();
478 });
479}
480
Jason M. Billse94f5e12019-09-13 11:11:34 -0700481static void cpu2VRHotAssertHandler()
482{
483 cpuVRHotLog("CPU 2");
484}
485
Jason M. Bills250fa632019-08-28 15:58:25 -0700486static void cpu2VRHotHandler()
487{
Jason M. Bills84951142020-04-17 15:57:11 -0700488 gpiod::line_event gpioLineEvent = cpu2VRHotLine.event_read();
Jason M. Bills250fa632019-08-28 15:58:25 -0700489
Jason M. Bills84951142020-04-17 15:57:11 -0700490 bool cpu2VRHot =
491 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
492 if (cpu2VRHot)
493 {
494 cpu2VRHotAssertHandler();
Jason M. Bills250fa632019-08-28 15:58:25 -0700495 }
Jason M. Bills84951142020-04-17 15:57:11 -0700496
Jason M. Bills250fa632019-08-28 15:58:25 -0700497 cpu2VRHotEvent.async_wait(boost::asio::posix::stream_descriptor::wait_read,
498 [](const boost::system::error_code ec) {
499 if (ec)
500 {
501 std::cerr << "CPU 2 VRHot handler error: "
502 << ec.message() << "\n";
503 return;
504 }
505 cpu2VRHotHandler();
506 });
507}
508
Jason M. Billse94f5e12019-09-13 11:11:34 -0700509static void cpu2MemABCDVRHotAssertHandler()
510{
511 cpuVRHotLog("CPU 2 Memory ABCD");
512}
513
Jason M. Bills9647ba72019-08-29 14:19:19 -0700514static void cpu2MemABCDVRHotHandler()
515{
Jason M. Bills84951142020-04-17 15:57:11 -0700516 gpiod::line_event gpioLineEvent = cpu2MemABCDVRHotLine.event_read();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700517
Jason M. Bills84951142020-04-17 15:57:11 -0700518 bool cpu2MemABCDVRHot =
519 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
520 if (cpu2MemABCDVRHot)
521 {
522 cpu2MemABCDVRHotAssertHandler();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700523 }
Jason M. Bills84951142020-04-17 15:57:11 -0700524
Jason M. Bills9647ba72019-08-29 14:19:19 -0700525 cpu2MemABCDVRHotEvent.async_wait(
526 boost::asio::posix::stream_descriptor::wait_read,
527 [](const boost::system::error_code ec) {
528 if (ec)
529 {
530 std::cerr << "CPU 2 Memory ABCD VRHot handler error: "
531 << ec.message() << "\n";
532 return;
533 }
534 cpu2MemABCDVRHotHandler();
535 });
536}
537
Jason M. Billse94f5e12019-09-13 11:11:34 -0700538static void cpu2MemEFGHVRHotAssertHandler()
539{
540 cpuVRHotLog("CPU 2 Memory EFGH");
541}
542
Jason M. Bills9647ba72019-08-29 14:19:19 -0700543static void cpu2MemEFGHVRHotHandler()
544{
Jason M. Bills84951142020-04-17 15:57:11 -0700545 gpiod::line_event gpioLineEvent = cpu2MemEFGHVRHotLine.event_read();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700546
Jason M. Bills84951142020-04-17 15:57:11 -0700547 bool cpu2MemEFGHVRHot =
548 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
549 if (cpu2MemEFGHVRHot)
550 {
551 cpu2MemEFGHVRHotAssertHandler();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700552 }
Jason M. Bills84951142020-04-17 15:57:11 -0700553
Jason M. Bills9647ba72019-08-29 14:19:19 -0700554 cpu2MemEFGHVRHotEvent.async_wait(
555 boost::asio::posix::stream_descriptor::wait_read,
556 [](const boost::system::error_code ec) {
557 if (ec)
558 {
559 std::cerr << "CPU 2 Memory EFGH VRHot handler error: "
560 << ec.message() << "\n";
561 return;
562 }
563 cpu2MemEFGHVRHotHandler();
564 });
565}
566
Chen Yugange6c0f1c2019-08-02 20:36:42 +0800567static void pchThermtripHandler()
568{
Yong Li1429ca82020-04-27 16:49:45 +0800569 std::vector<Association> associations;
570
Jason M. Bills84951142020-04-17 15:57:11 -0700571 gpiod::line_event gpioLineEvent = pchThermtripLine.event_read();
Chen Yugange6c0f1c2019-08-02 20:36:42 +0800572
Jason M. Bills84951142020-04-17 15:57:11 -0700573 bool pchThermtrip =
574 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
575 if (pchThermtrip)
576 {
577 ssbThermTripLog();
Yong Li1429ca82020-04-27 16:49:45 +0800578 associations.emplace_back(
579 "", "critical",
580 "/xyz/openbmc_project/host_error_monitor/ssb_thermal_trip");
581 associations.emplace_back("", "critical", host_error_monitor::rootPath);
Chen Yugange6c0f1c2019-08-02 20:36:42 +0800582 }
Yong Li1429ca82020-04-27 16:49:45 +0800583 else
584 {
585 associations.emplace_back("", "", "");
586 }
587 host_error_monitor::associationSSBThermTrip->set_property("Associations",
588 associations);
Jason M. Bills84951142020-04-17 15:57:11 -0700589
Chen Yugange6c0f1c2019-08-02 20:36:42 +0800590 pchThermtripEvent.async_wait(
591 boost::asio::posix::stream_descriptor::wait_read,
592 [](const boost::system::error_code ec) {
593 if (ec)
594 {
595 std::cerr << "PCH Thermal trip handler error: " << ec.message()
596 << "\n";
597 return;
598 }
599 pchThermtripHandler();
600 });
601}
602
Jason M. Billsa15c2522019-08-16 10:01:44 -0700603static void initializeErrorState()
604{
Jason M. Billse94f5e12019-09-13 11:11:34 -0700605 // Handle CPU1_THERMTRIP if it's asserted now
606 if (cpu1ThermtripLine.get_value() == 0)
607 {
608 cpu1ThermtripAssertHandler();
609 }
610
611 // Handle CPU2_THERMTRIP if it's asserted now
612 if (cpu2ThermtripLine.get_value() == 0)
613 {
614 cpu2ThermtripAssertHandler();
615 }
616
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000617 // Handle CPU1_MEM_THERM_EVENT (CPU1 DIMM Thermal trip) if it's asserted now
618 if (cpu1MemtripLine.get_value() == 0)
619 {
620 memThermTripLog(1);
621 }
622
623 // Handle CPU2_MEM_THERM_EVENT (CPU2 DIMM Thermal trip) if it's asserted now
624 if (cpu2MemtripLine.get_value() == 0)
625 {
626 memThermTripLog(2);
627 }
628
Jason M. Billse94f5e12019-09-13 11:11:34 -0700629 // Handle CPU1_VRHOT if it's asserted now
630 if (cpu1VRHotLine.get_value() == 0)
631 {
632 cpu1VRHotAssertHandler();
633 }
634
635 // Handle CPU1_MEM_ABCD_VRHOT if it's asserted now
636 if (cpu1MemABCDVRHotLine.get_value() == 0)
637 {
638 cpu1MemABCDVRHotAssertHandler();
639 }
640
641 // Handle CPU1_MEM_EFGH_VRHOT if it's asserted now
642 if (cpu1MemEFGHVRHotLine.get_value() == 0)
643 {
644 cpu1MemEFGHVRHotAssertHandler();
645 }
646
647 // Handle CPU2_VRHOT if it's asserted now
648 if (cpu2VRHotLine.get_value() == 0)
649 {
650 cpu2VRHotAssertHandler();
651 }
652
653 // Handle CPU2_MEM_ABCD_VRHOT if it's asserted now
654 if (cpu2MemABCDVRHotLine.get_value() == 0)
655 {
656 cpu2MemABCDVRHotAssertHandler();
657 }
658
659 // Handle CPU2_MEM_EFGH_VRHOT if it's asserted now
660 if (cpu2MemEFGHVRHotLine.get_value() == 0)
661 {
662 cpu2MemEFGHVRHotAssertHandler();
663 }
664
Jason M. Bills08866542019-08-16 12:04:19 -0700665 // Handle PCH_BMC_THERMTRIP if it's asserted now
666 if (pchThermtripLine.get_value() == 0)
667 {
668 ssbThermTripLog();
Yong Li1429ca82020-04-27 16:49:45 +0800669 std::vector<Association> associations;
670 associations.emplace_back(
671 "", "critical",
672 "/xyz/openbmc_project/host_error_monitor/ssb_thermal_trip");
673 associations.emplace_back("", "critical", host_error_monitor::rootPath);
674 host_error_monitor::associationSSBThermTrip->set_property(
675 "Associations", associations);
Jason M. Bills08866542019-08-16 12:04:19 -0700676 }
Jason M. Billsa15c2522019-08-16 10:01:44 -0700677}
Jason M. Bills1490b142019-07-01 15:48:43 -0700678} // namespace host_error_monitor
679
680int main(int argc, char* argv[])
681{
682 // setup connection to dbus
683 host_error_monitor::conn =
684 std::make_shared<sdbusplus::asio::connection>(host_error_monitor::io);
685
Jason M. Billsc4b91f22019-11-26 17:04:50 -0800686 // Host Error Monitor Service
Jason M. Bills1490b142019-07-01 15:48:43 -0700687 host_error_monitor::conn->request_name(
688 "xyz.openbmc_project.HostErrorMonitor");
689 sdbusplus::asio::object_server server =
690 sdbusplus::asio::object_server(host_error_monitor::conn);
691
Yong Li1429ca82020-04-27 16:49:45 +0800692 // Associations interface for led status
693 std::vector<host_error_monitor::Association> associations;
694 associations.emplace_back("", "", "");
695 host_error_monitor::associationSSBThermTrip = server.add_interface(
696 "/xyz/openbmc_project/host_error_monitor/ssb_thermal_trip",
697 "xyz.openbmc_project.Association.Definitions");
698 host_error_monitor::associationSSBThermTrip->register_property(
699 "Associations", associations);
700 host_error_monitor::associationSSBThermTrip->initialize();
701
Jason M. Bills1490b142019-07-01 15:48:43 -0700702 // Start tracking host state
703 std::shared_ptr<sdbusplus::bus::match::match> hostStateMonitor =
704 host_error_monitor::startHostStateMonitor();
705
Jason M. Bills45e87e02019-09-09 14:45:38 -0700706 // Request CPU1_FIVR_FAULT GPIO input
707 if (!host_error_monitor::requestGPIOInput(
708 "CPU1_FIVR_FAULT", host_error_monitor::cpu1FIVRFaultLine))
709 {
710 return -1;
711 }
712
Jason M. Bills78c5eed2019-08-28 14:00:40 -0700713 // Request CPU1_THERMTRIP GPIO events
714 if (!host_error_monitor::requestGPIOEvents(
715 "CPU1_THERMTRIP", host_error_monitor::cpu1ThermtripHandler,
716 host_error_monitor::cpu1ThermtripLine,
717 host_error_monitor::cpu1ThermtripEvent))
718 {
719 return -1;
720 }
721
Jason M. Bills45e87e02019-09-09 14:45:38 -0700722 // Request CPU2_FIVR_FAULT GPIO input
723 if (!host_error_monitor::requestGPIOInput(
724 "CPU2_FIVR_FAULT", host_error_monitor::cpu2FIVRFaultLine))
725 {
726 return -1;
727 }
728
Jason M. Bills78c5eed2019-08-28 14:00:40 -0700729 // Request CPU2_THERMTRIP GPIO events
730 if (!host_error_monitor::requestGPIOEvents(
731 "CPU2_THERMTRIP", host_error_monitor::cpu2ThermtripHandler,
732 host_error_monitor::cpu2ThermtripLine,
733 host_error_monitor::cpu2ThermtripEvent))
734 {
735 return -1;
736 }
737
Jason M. Bills250fa632019-08-28 15:58:25 -0700738 // Request CPU1_VRHOT GPIO events
739 if (!host_error_monitor::requestGPIOEvents(
740 "CPU1_VRHOT", host_error_monitor::cpu1VRHotHandler,
741 host_error_monitor::cpu1VRHotLine,
742 host_error_monitor::cpu1VRHotEvent))
743 {
744 return -1;
745 }
746
Jason M. Bills9647ba72019-08-29 14:19:19 -0700747 // Request CPU1_MEM_ABCD_VRHOT GPIO events
748 if (!host_error_monitor::requestGPIOEvents(
749 "CPU1_MEM_ABCD_VRHOT", host_error_monitor::cpu1MemABCDVRHotHandler,
750 host_error_monitor::cpu1MemABCDVRHotLine,
751 host_error_monitor::cpu1MemABCDVRHotEvent))
752 {
753 return -1;
754 }
755
756 // Request CPU1_MEM_EFGH_VRHOT GPIO events
757 if (!host_error_monitor::requestGPIOEvents(
758 "CPU1_MEM_EFGH_VRHOT", host_error_monitor::cpu1MemEFGHVRHotHandler,
759 host_error_monitor::cpu1MemEFGHVRHotLine,
760 host_error_monitor::cpu1MemEFGHVRHotEvent))
761 {
762 return -1;
763 }
764
Jason M. Bills250fa632019-08-28 15:58:25 -0700765 // Request CPU2_VRHOT GPIO events
766 if (!host_error_monitor::requestGPIOEvents(
767 "CPU2_VRHOT", host_error_monitor::cpu2VRHotHandler,
768 host_error_monitor::cpu2VRHotLine,
769 host_error_monitor::cpu2VRHotEvent))
770 {
771 return -1;
772 }
773
Jason M. Bills9647ba72019-08-29 14:19:19 -0700774 // Request CPU2_MEM_ABCD_VRHOT GPIO events
775 if (!host_error_monitor::requestGPIOEvents(
776 "CPU2_MEM_ABCD_VRHOT", host_error_monitor::cpu2MemABCDVRHotHandler,
777 host_error_monitor::cpu2MemABCDVRHotLine,
778 host_error_monitor::cpu2MemABCDVRHotEvent))
779 {
780 return -1;
781 }
782
783 // Request CPU2_MEM_EFGH_VRHOT GPIO events
784 if (!host_error_monitor::requestGPIOEvents(
785 "CPU2_MEM_EFGH_VRHOT", host_error_monitor::cpu2MemEFGHVRHotHandler,
786 host_error_monitor::cpu2MemEFGHVRHotLine,
787 host_error_monitor::cpu2MemEFGHVRHotEvent))
788 {
789 return -1;
790 }
791
Chen Yugange6c0f1c2019-08-02 20:36:42 +0800792 // Request PCH_BMC_THERMTRIP GPIO events
793 if (!host_error_monitor::requestGPIOEvents(
794 "PCH_BMC_THERMTRIP", host_error_monitor::pchThermtripHandler,
795 host_error_monitor::pchThermtripLine,
796 host_error_monitor::pchThermtripEvent))
797 {
798 return -1;
799 }
800
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000801 // Request CPU1_MEM_THERM_EVENT GPIO events
802 if (!host_error_monitor::requestGPIOEvents(
803 "CPU1_MEM_THERM_EVENT", host_error_monitor::cpu1MemtripHandler,
804 host_error_monitor::cpu1MemtripLine,
805 host_error_monitor::cpu1MemtripEvent))
806 {
807 return -1;
808 }
809
810 // Request CPU2_MEM_THERM_EVENT GPIO events
811 if (!host_error_monitor::requestGPIOEvents(
812 "CPU2_MEM_THERM_EVENT", host_error_monitor::cpu2MemtripHandler,
813 host_error_monitor::cpu2MemtripLine,
814 host_error_monitor::cpu2MemtripEvent))
815 {
816 return -1;
817 }
818
Jason M. Bills5245ed62020-12-04 16:50:21 -0800819 // Initialize the signal monitors
820 host_error_monitor::init();
821
Jason M. Bills1490b142019-07-01 15:48:43 -0700822 host_error_monitor::io.run();
823
824 return 0;
825}