blob: 0087d82dbbb6011df4b3c43f56d1e9798f307b05 [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. Bills250fa632019-08-28 15:58:25 -070047static gpiod::line cpu1VRHotLine;
48static boost::asio::posix::stream_descriptor cpu1VRHotEvent(io);
49static gpiod::line cpu2VRHotLine;
Jason M. Bills9647ba72019-08-29 14:19:19 -070050static boost::asio::posix::stream_descriptor cpu1MemABCDVRHotEvent(io);
51static gpiod::line cpu1MemEFGHVRHotLine;
52static boost::asio::posix::stream_descriptor cpu1MemEFGHVRHotEvent(io);
53static gpiod::line cpu2MemABCDVRHotLine;
Jason M. Bills250fa632019-08-28 15:58:25 -070054static boost::asio::posix::stream_descriptor cpu2VRHotEvent(io);
Jason M. Bills9647ba72019-08-29 14:19:19 -070055static gpiod::line cpu1MemABCDVRHotLine;
56static boost::asio::posix::stream_descriptor cpu2MemABCDVRHotEvent(io);
57static gpiod::line cpu2MemEFGHVRHotLine;
58static boost::asio::posix::stream_descriptor cpu2MemEFGHVRHotEvent(io);
Chen Yugange6c0f1c2019-08-02 20:36:42 +080059//----------------------------------
60// PCH_BMC_THERMTRIP function related definition
61//----------------------------------
Chen Yugange6c0f1c2019-08-02 20:36:42 +080062static gpiod::line pchThermtripLine;
63static boost::asio::posix::stream_descriptor pchThermtripEvent(io);
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +000064//----------------------------------
65// CPU_MEM_THERM_EVENT function related definition
66//----------------------------------
67static gpiod::line cpu1MemtripLine;
68static boost::asio::posix::stream_descriptor cpu1MemtripEvent(io);
69static gpiod::line cpu2MemtripLine;
70static boost::asio::posix::stream_descriptor cpu2MemtripEvent(io);
Jason M. Bills1490b142019-07-01 15:48:43 -070071
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +000072static void memThermTripLog(const int cpuNum)
73{
74 std::string cpuNumber = "CPU " + std::to_string(cpuNum);
75 std::string msg = cpuNumber + " Memory Thermal trip.";
76
77 sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i",
78 LOG_ERR, "REDFISH_MESSAGE_ID=%s",
79 "OpenBMC.0.1.MemoryThermTrip", "REDFISH_MESSAGE_ARGS=%s",
80 cpuNumber.c_str(), NULL);
81}
82
Jason M. Bills250fa632019-08-28 15:58:25 -070083static void cpuVRHotLog(const std::string& vr)
84{
85 std::string msg = vr + " Voltage Regulator Overheated.";
86
87 sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i",
88 LOG_INFO, "REDFISH_MESSAGE_ID=%s",
89 "OpenBMC.0.1.VoltageRegulatorOverheated",
90 "REDFISH_MESSAGE_ARGS=%s", vr.c_str(), NULL);
91}
92
Jason M. Bills08866542019-08-16 12:04:19 -070093static void ssbThermTripLog()
94{
95 sd_journal_send("MESSAGE=HostError: SSB thermal trip", "PRIORITY=%i",
96 LOG_INFO, "REDFISH_MESSAGE_ID=%s",
97 "OpenBMC.0.1.SsbThermalTrip", NULL);
98}
99
Jason M. Billsa15c2522019-08-16 10:01:44 -0700100static void initializeErrorState();
Jason M. Bills5245ed62020-12-04 16:50:21 -0800101static void init()
Jason M. Bills1490b142019-07-01 15:48:43 -0700102{
Jason M. Bills5245ed62020-12-04 16:50:21 -0800103 // Get the current host state to prepare to start the signal monitors
Jason M. Bills1490b142019-07-01 15:48:43 -0700104 conn->async_method_call(
105 [](boost::system::error_code ec,
106 const std::variant<std::string>& property) {
107 if (ec)
108 {
109 return;
110 }
111 const std::string* state = std::get_if<std::string>(&property);
112 if (state == nullptr)
113 {
114 std::cerr << "Unable to read host state value\n";
115 return;
116 }
117 hostOff = *state == "xyz.openbmc_project.State.Host.HostState.Off";
Jason M. Billsa15c2522019-08-16 10:01:44 -0700118 // If the system is on, initialize the error state
119 if (!hostOff)
120 {
121 initializeErrorState();
122 }
Jason M. Bills5245ed62020-12-04 16:50:21 -0800123
124 // Now we have the host state, start the signal monitors
125 if (!error_monitors::startMonitors(io, conn))
126 {
127 throw std::runtime_error("Failed to start signal monitors");
128 }
Jason M. Bills1490b142019-07-01 15:48:43 -0700129 },
130 "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
131 "org.freedesktop.DBus.Properties", "Get",
132 "xyz.openbmc_project.State.Host", "CurrentHostState");
133}
134
135static std::shared_ptr<sdbusplus::bus::match::match> startHostStateMonitor()
136{
137 return std::make_shared<sdbusplus::bus::match::match>(
138 *conn,
139 "type='signal',interface='org.freedesktop.DBus.Properties',"
Jason M. Bills2fbb9ea2020-06-19 14:46:54 -0700140 "member='PropertiesChanged',arg0='xyz.openbmc_project.State.Host'",
Jason M. Bills1490b142019-07-01 15:48:43 -0700141 [](sdbusplus::message::message& msg) {
142 std::string interfaceName;
143 boost::container::flat_map<std::string, std::variant<std::string>>
144 propertiesChanged;
Jason M. Bills1490b142019-07-01 15:48:43 -0700145 try
146 {
147 msg.read(interfaceName, propertiesChanged);
Jason M. Bills1490b142019-07-01 15:48:43 -0700148 }
149 catch (std::exception& e)
150 {
151 std::cerr << "Unable to read host state\n";
152 return;
153 }
Jason M. Bills566ccc42020-06-18 16:38:26 -0700154 // We only want to check for CurrentHostState
155 if (propertiesChanged.begin()->first != "CurrentHostState")
156 {
157 return;
158 }
159 std::string* state =
160 std::get_if<std::string>(&(propertiesChanged.begin()->second));
161 if (state == nullptr)
162 {
163 std::cerr << propertiesChanged.begin()->first
164 << " property invalid\n";
165 return;
166 }
167
168 hostOff = *state == "xyz.openbmc_project.State.Host.HostState.Off";
Jason M. Bills1490b142019-07-01 15:48:43 -0700169
Jason M. Bills8fa1c962020-12-10 14:33:56 -0800170 if (!hostOff)
Jason M. Billse94f5e12019-09-13 11:11:34 -0700171 {
172 // Handle any initial errors when the host turns on
173 initializeErrorState();
Jason M. Bills5245ed62020-12-04 16:50:21 -0800174 error_monitors::sendHostOn();
Jason M. Billse94f5e12019-09-13 11:11:34 -0700175 }
Jason M. Bills1490b142019-07-01 15:48:43 -0700176 });
177}
178
179static bool requestGPIOEvents(
180 const std::string& name, const std::function<void()>& handler,
181 gpiod::line& gpioLine,
182 boost::asio::posix::stream_descriptor& gpioEventDescriptor)
183{
184 // Find the GPIO line
185 gpioLine = gpiod::find_line(name);
186 if (!gpioLine)
187 {
188 std::cerr << "Failed to find the " << name << " line\n";
189 return false;
190 }
191
192 try
193 {
194 gpioLine.request(
195 {"host-error-monitor", gpiod::line_request::EVENT_BOTH_EDGES});
196 }
197 catch (std::exception&)
198 {
199 std::cerr << "Failed to request events for " << name << "\n";
200 return false;
201 }
202
203 int gpioLineFd = gpioLine.event_get_fd();
204 if (gpioLineFd < 0)
205 {
206 std::cerr << "Failed to get " << name << " fd\n";
207 return false;
208 }
209
210 gpioEventDescriptor.assign(gpioLineFd);
211
212 gpioEventDescriptor.async_wait(
213 boost::asio::posix::stream_descriptor::wait_read,
214 [&name, handler](const boost::system::error_code ec) {
215 if (ec)
216 {
217 std::cerr << name << " fd handler error: " << ec.message()
218 << "\n";
219 return;
220 }
221 handler();
222 });
223 return true;
224}
225
Jason M. Bills45e87e02019-09-09 14:45:38 -0700226static bool requestGPIOInput(const std::string& name, gpiod::line& gpioLine)
227{
228 // Find the GPIO line
229 gpioLine = gpiod::find_line(name);
230 if (!gpioLine)
231 {
232 std::cerr << "Failed to find the " << name << " line.\n";
233 return false;
234 }
235
236 // Request GPIO input
237 try
238 {
239 gpioLine.request({__FUNCTION__, gpiod::line_request::DIRECTION_INPUT});
240 }
241 catch (std::exception&)
242 {
243 std::cerr << "Failed to request " << name << " input\n";
244 return false;
245 }
246
247 return true;
248}
249
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000250static void cpu1MemtripHandler()
251{
Jason M. Bills5287c022020-05-19 11:16:09 -0700252 gpiod::line_event gpioLineEvent = cpu1MemtripLine.event_read();
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000253
Jason M. Bills5287c022020-05-19 11:16:09 -0700254 bool cpu1Memtrip =
255 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
256 if (cpu1Memtrip)
257 {
258 memThermTripLog(1);
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000259 }
Jason M. Bills5287c022020-05-19 11:16:09 -0700260
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000261 cpu1MemtripEvent.async_wait(
262 boost::asio::posix::stream_descriptor::wait_read,
263 [](const boost::system::error_code ec) {
264 if (ec)
265 {
266 std::cerr << "CPU 1 Memory Thermaltrip handler error: "
267 << ec.message() << "\n";
268 return;
269 }
270 cpu1MemtripHandler();
271 });
272}
273
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000274static void cpu2MemtripHandler()
275{
Jason M. Bills5287c022020-05-19 11:16:09 -0700276 gpiod::line_event gpioLineEvent = cpu2MemtripLine.event_read();
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000277
Jason M. Bills5287c022020-05-19 11:16:09 -0700278 bool cpu2Memtrip =
279 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
280 if (cpu2Memtrip)
281 {
282 memThermTripLog(2);
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000283 }
Jason M. Bills5287c022020-05-19 11:16:09 -0700284
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000285 cpu2MemtripEvent.async_wait(
286 boost::asio::posix::stream_descriptor::wait_read,
287 [](const boost::system::error_code ec) {
288 if (ec)
289 {
290 std::cerr << "CPU 2 Memory Thermaltrip handler error: "
291 << ec.message() << "\n";
292 return;
293 }
294 cpu2MemtripHandler();
295 });
296}
297
Jason M. Billse94f5e12019-09-13 11:11:34 -0700298static void cpu1VRHotAssertHandler()
299{
300 cpuVRHotLog("CPU 1");
301}
302
Jason M. Bills250fa632019-08-28 15:58:25 -0700303static void cpu1VRHotHandler()
304{
Jason M. Bills84951142020-04-17 15:57:11 -0700305 gpiod::line_event gpioLineEvent = cpu1VRHotLine.event_read();
Jason M. Bills250fa632019-08-28 15:58:25 -0700306
Jason M. Bills84951142020-04-17 15:57:11 -0700307 bool cpu1VRHot =
308 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
309 if (cpu1VRHot)
310 {
311 cpu1VRHotAssertHandler();
Jason M. Bills250fa632019-08-28 15:58:25 -0700312 }
Jason M. Bills84951142020-04-17 15:57:11 -0700313
Jason M. Bills250fa632019-08-28 15:58:25 -0700314 cpu1VRHotEvent.async_wait(boost::asio::posix::stream_descriptor::wait_read,
315 [](const boost::system::error_code ec) {
316 if (ec)
317 {
318 std::cerr << "CPU 1 VRHot handler error: "
319 << ec.message() << "\n";
320 return;
321 }
322 cpu1VRHotHandler();
323 });
324}
325
Jason M. Billse94f5e12019-09-13 11:11:34 -0700326static void cpu1MemABCDVRHotAssertHandler()
327{
328 cpuVRHotLog("CPU 1 Memory ABCD");
329}
330
Jason M. Bills9647ba72019-08-29 14:19:19 -0700331static void cpu1MemABCDVRHotHandler()
332{
Jason M. Bills84951142020-04-17 15:57:11 -0700333 gpiod::line_event gpioLineEvent = cpu1MemABCDVRHotLine.event_read();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700334
Jason M. Bills84951142020-04-17 15:57:11 -0700335 bool cpu1MemABCDVRHot =
336 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
337 if (cpu1MemABCDVRHot)
338 {
339 cpu1MemABCDVRHotAssertHandler();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700340 }
Jason M. Bills84951142020-04-17 15:57:11 -0700341
Jason M. Bills9647ba72019-08-29 14:19:19 -0700342 cpu1MemABCDVRHotEvent.async_wait(
343 boost::asio::posix::stream_descriptor::wait_read,
344 [](const boost::system::error_code ec) {
345 if (ec)
346 {
347 std::cerr << "CPU 1 Memory ABCD VRHot handler error: "
348 << ec.message() << "\n";
349 return;
350 }
351 cpu1MemABCDVRHotHandler();
352 });
353}
354
Jason M. Billse94f5e12019-09-13 11:11:34 -0700355static void cpu1MemEFGHVRHotAssertHandler()
356{
357 cpuVRHotLog("CPU 1 Memory EFGH");
358}
359
Jason M. Bills9647ba72019-08-29 14:19:19 -0700360static void cpu1MemEFGHVRHotHandler()
361{
Jason M. Bills84951142020-04-17 15:57:11 -0700362 gpiod::line_event gpioLineEvent = cpu1MemEFGHVRHotLine.event_read();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700363
Jason M. Bills84951142020-04-17 15:57:11 -0700364 bool cpu1MemEFGHVRHot =
365 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
366 if (cpu1MemEFGHVRHot)
367 {
368 cpu1MemEFGHVRHotAssertHandler();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700369 }
Jason M. Bills84951142020-04-17 15:57:11 -0700370
Jason M. Bills9647ba72019-08-29 14:19:19 -0700371 cpu1MemEFGHVRHotEvent.async_wait(
372 boost::asio::posix::stream_descriptor::wait_read,
373 [](const boost::system::error_code ec) {
374 if (ec)
375 {
376 std::cerr << "CPU 1 Memory EFGH VRHot handler error: "
377 << ec.message() << "\n";
378 return;
379 }
380 cpu1MemEFGHVRHotHandler();
381 });
382}
383
Jason M. Billse94f5e12019-09-13 11:11:34 -0700384static void cpu2VRHotAssertHandler()
385{
386 cpuVRHotLog("CPU 2");
387}
388
Jason M. Bills250fa632019-08-28 15:58:25 -0700389static void cpu2VRHotHandler()
390{
Jason M. Bills84951142020-04-17 15:57:11 -0700391 gpiod::line_event gpioLineEvent = cpu2VRHotLine.event_read();
Jason M. Bills250fa632019-08-28 15:58:25 -0700392
Jason M. Bills84951142020-04-17 15:57:11 -0700393 bool cpu2VRHot =
394 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
395 if (cpu2VRHot)
396 {
397 cpu2VRHotAssertHandler();
Jason M. Bills250fa632019-08-28 15:58:25 -0700398 }
Jason M. Bills84951142020-04-17 15:57:11 -0700399
Jason M. Bills250fa632019-08-28 15:58:25 -0700400 cpu2VRHotEvent.async_wait(boost::asio::posix::stream_descriptor::wait_read,
401 [](const boost::system::error_code ec) {
402 if (ec)
403 {
404 std::cerr << "CPU 2 VRHot handler error: "
405 << ec.message() << "\n";
406 return;
407 }
408 cpu2VRHotHandler();
409 });
410}
411
Jason M. Billse94f5e12019-09-13 11:11:34 -0700412static void cpu2MemABCDVRHotAssertHandler()
413{
414 cpuVRHotLog("CPU 2 Memory ABCD");
415}
416
Jason M. Bills9647ba72019-08-29 14:19:19 -0700417static void cpu2MemABCDVRHotHandler()
418{
Jason M. Bills84951142020-04-17 15:57:11 -0700419 gpiod::line_event gpioLineEvent = cpu2MemABCDVRHotLine.event_read();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700420
Jason M. Bills84951142020-04-17 15:57:11 -0700421 bool cpu2MemABCDVRHot =
422 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
423 if (cpu2MemABCDVRHot)
424 {
425 cpu2MemABCDVRHotAssertHandler();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700426 }
Jason M. Bills84951142020-04-17 15:57:11 -0700427
Jason M. Bills9647ba72019-08-29 14:19:19 -0700428 cpu2MemABCDVRHotEvent.async_wait(
429 boost::asio::posix::stream_descriptor::wait_read,
430 [](const boost::system::error_code ec) {
431 if (ec)
432 {
433 std::cerr << "CPU 2 Memory ABCD VRHot handler error: "
434 << ec.message() << "\n";
435 return;
436 }
437 cpu2MemABCDVRHotHandler();
438 });
439}
440
Jason M. Billse94f5e12019-09-13 11:11:34 -0700441static void cpu2MemEFGHVRHotAssertHandler()
442{
443 cpuVRHotLog("CPU 2 Memory EFGH");
444}
445
Jason M. Bills9647ba72019-08-29 14:19:19 -0700446static void cpu2MemEFGHVRHotHandler()
447{
Jason M. Bills84951142020-04-17 15:57:11 -0700448 gpiod::line_event gpioLineEvent = cpu2MemEFGHVRHotLine.event_read();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700449
Jason M. Bills84951142020-04-17 15:57:11 -0700450 bool cpu2MemEFGHVRHot =
451 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
452 if (cpu2MemEFGHVRHot)
453 {
454 cpu2MemEFGHVRHotAssertHandler();
Jason M. Bills9647ba72019-08-29 14:19:19 -0700455 }
Jason M. Bills84951142020-04-17 15:57:11 -0700456
Jason M. Bills9647ba72019-08-29 14:19:19 -0700457 cpu2MemEFGHVRHotEvent.async_wait(
458 boost::asio::posix::stream_descriptor::wait_read,
459 [](const boost::system::error_code ec) {
460 if (ec)
461 {
462 std::cerr << "CPU 2 Memory EFGH VRHot handler error: "
463 << ec.message() << "\n";
464 return;
465 }
466 cpu2MemEFGHVRHotHandler();
467 });
468}
469
Chen Yugange6c0f1c2019-08-02 20:36:42 +0800470static void pchThermtripHandler()
471{
Yong Li1429ca82020-04-27 16:49:45 +0800472 std::vector<Association> associations;
473
Jason M. Bills84951142020-04-17 15:57:11 -0700474 gpiod::line_event gpioLineEvent = pchThermtripLine.event_read();
Chen Yugange6c0f1c2019-08-02 20:36:42 +0800475
Jason M. Bills84951142020-04-17 15:57:11 -0700476 bool pchThermtrip =
477 gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
478 if (pchThermtrip)
479 {
480 ssbThermTripLog();
Yong Li1429ca82020-04-27 16:49:45 +0800481 associations.emplace_back(
482 "", "critical",
483 "/xyz/openbmc_project/host_error_monitor/ssb_thermal_trip");
484 associations.emplace_back("", "critical", host_error_monitor::rootPath);
Chen Yugange6c0f1c2019-08-02 20:36:42 +0800485 }
Yong Li1429ca82020-04-27 16:49:45 +0800486 else
487 {
488 associations.emplace_back("", "", "");
489 }
490 host_error_monitor::associationSSBThermTrip->set_property("Associations",
491 associations);
Jason M. Bills84951142020-04-17 15:57:11 -0700492
Chen Yugange6c0f1c2019-08-02 20:36:42 +0800493 pchThermtripEvent.async_wait(
494 boost::asio::posix::stream_descriptor::wait_read,
495 [](const boost::system::error_code ec) {
496 if (ec)
497 {
498 std::cerr << "PCH Thermal trip handler error: " << ec.message()
499 << "\n";
500 return;
501 }
502 pchThermtripHandler();
503 });
504}
505
Jason M. Billsa15c2522019-08-16 10:01:44 -0700506static void initializeErrorState()
507{
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000508 // Handle CPU1_MEM_THERM_EVENT (CPU1 DIMM Thermal trip) if it's asserted now
509 if (cpu1MemtripLine.get_value() == 0)
510 {
511 memThermTripLog(1);
512 }
513
514 // Handle CPU2_MEM_THERM_EVENT (CPU2 DIMM Thermal trip) if it's asserted now
515 if (cpu2MemtripLine.get_value() == 0)
516 {
517 memThermTripLog(2);
518 }
519
Jason M. Billse94f5e12019-09-13 11:11:34 -0700520 // Handle CPU1_VRHOT if it's asserted now
521 if (cpu1VRHotLine.get_value() == 0)
522 {
523 cpu1VRHotAssertHandler();
524 }
525
526 // Handle CPU1_MEM_ABCD_VRHOT if it's asserted now
527 if (cpu1MemABCDVRHotLine.get_value() == 0)
528 {
529 cpu1MemABCDVRHotAssertHandler();
530 }
531
532 // Handle CPU1_MEM_EFGH_VRHOT if it's asserted now
533 if (cpu1MemEFGHVRHotLine.get_value() == 0)
534 {
535 cpu1MemEFGHVRHotAssertHandler();
536 }
537
538 // Handle CPU2_VRHOT if it's asserted now
539 if (cpu2VRHotLine.get_value() == 0)
540 {
541 cpu2VRHotAssertHandler();
542 }
543
544 // Handle CPU2_MEM_ABCD_VRHOT if it's asserted now
545 if (cpu2MemABCDVRHotLine.get_value() == 0)
546 {
547 cpu2MemABCDVRHotAssertHandler();
548 }
549
550 // Handle CPU2_MEM_EFGH_VRHOT if it's asserted now
551 if (cpu2MemEFGHVRHotLine.get_value() == 0)
552 {
553 cpu2MemEFGHVRHotAssertHandler();
554 }
555
Jason M. Bills08866542019-08-16 12:04:19 -0700556 // Handle PCH_BMC_THERMTRIP if it's asserted now
557 if (pchThermtripLine.get_value() == 0)
558 {
559 ssbThermTripLog();
Yong Li1429ca82020-04-27 16:49:45 +0800560 std::vector<Association> associations;
561 associations.emplace_back(
562 "", "critical",
563 "/xyz/openbmc_project/host_error_monitor/ssb_thermal_trip");
564 associations.emplace_back("", "critical", host_error_monitor::rootPath);
565 host_error_monitor::associationSSBThermTrip->set_property(
566 "Associations", associations);
Jason M. Bills08866542019-08-16 12:04:19 -0700567 }
Jason M. Billsa15c2522019-08-16 10:01:44 -0700568}
Jason M. Bills1490b142019-07-01 15:48:43 -0700569} // namespace host_error_monitor
570
571int main(int argc, char* argv[])
572{
573 // setup connection to dbus
574 host_error_monitor::conn =
575 std::make_shared<sdbusplus::asio::connection>(host_error_monitor::io);
576
Jason M. Billsc4b91f22019-11-26 17:04:50 -0800577 // Host Error Monitor Service
Jason M. Bills1490b142019-07-01 15:48:43 -0700578 host_error_monitor::conn->request_name(
579 "xyz.openbmc_project.HostErrorMonitor");
580 sdbusplus::asio::object_server server =
581 sdbusplus::asio::object_server(host_error_monitor::conn);
582
Yong Li1429ca82020-04-27 16:49:45 +0800583 // Associations interface for led status
584 std::vector<host_error_monitor::Association> associations;
585 associations.emplace_back("", "", "");
586 host_error_monitor::associationSSBThermTrip = server.add_interface(
587 "/xyz/openbmc_project/host_error_monitor/ssb_thermal_trip",
588 "xyz.openbmc_project.Association.Definitions");
589 host_error_monitor::associationSSBThermTrip->register_property(
590 "Associations", associations);
591 host_error_monitor::associationSSBThermTrip->initialize();
592
Jason M. Bills1490b142019-07-01 15:48:43 -0700593 // Start tracking host state
594 std::shared_ptr<sdbusplus::bus::match::match> hostStateMonitor =
595 host_error_monitor::startHostStateMonitor();
596
Jason M. Bills250fa632019-08-28 15:58:25 -0700597 // Request CPU1_VRHOT GPIO events
598 if (!host_error_monitor::requestGPIOEvents(
599 "CPU1_VRHOT", host_error_monitor::cpu1VRHotHandler,
600 host_error_monitor::cpu1VRHotLine,
601 host_error_monitor::cpu1VRHotEvent))
602 {
603 return -1;
604 }
605
Jason M. Bills9647ba72019-08-29 14:19:19 -0700606 // Request CPU1_MEM_ABCD_VRHOT GPIO events
607 if (!host_error_monitor::requestGPIOEvents(
608 "CPU1_MEM_ABCD_VRHOT", host_error_monitor::cpu1MemABCDVRHotHandler,
609 host_error_monitor::cpu1MemABCDVRHotLine,
610 host_error_monitor::cpu1MemABCDVRHotEvent))
611 {
612 return -1;
613 }
614
615 // Request CPU1_MEM_EFGH_VRHOT GPIO events
616 if (!host_error_monitor::requestGPIOEvents(
617 "CPU1_MEM_EFGH_VRHOT", host_error_monitor::cpu1MemEFGHVRHotHandler,
618 host_error_monitor::cpu1MemEFGHVRHotLine,
619 host_error_monitor::cpu1MemEFGHVRHotEvent))
620 {
621 return -1;
622 }
623
Jason M. Bills250fa632019-08-28 15:58:25 -0700624 // Request CPU2_VRHOT GPIO events
625 if (!host_error_monitor::requestGPIOEvents(
626 "CPU2_VRHOT", host_error_monitor::cpu2VRHotHandler,
627 host_error_monitor::cpu2VRHotLine,
628 host_error_monitor::cpu2VRHotEvent))
629 {
630 return -1;
631 }
632
Jason M. Bills9647ba72019-08-29 14:19:19 -0700633 // Request CPU2_MEM_ABCD_VRHOT GPIO events
634 if (!host_error_monitor::requestGPIOEvents(
635 "CPU2_MEM_ABCD_VRHOT", host_error_monitor::cpu2MemABCDVRHotHandler,
636 host_error_monitor::cpu2MemABCDVRHotLine,
637 host_error_monitor::cpu2MemABCDVRHotEvent))
638 {
639 return -1;
640 }
641
642 // Request CPU2_MEM_EFGH_VRHOT GPIO events
643 if (!host_error_monitor::requestGPIOEvents(
644 "CPU2_MEM_EFGH_VRHOT", host_error_monitor::cpu2MemEFGHVRHotHandler,
645 host_error_monitor::cpu2MemEFGHVRHotLine,
646 host_error_monitor::cpu2MemEFGHVRHotEvent))
647 {
648 return -1;
649 }
650
Chen Yugange6c0f1c2019-08-02 20:36:42 +0800651 // Request PCH_BMC_THERMTRIP GPIO events
652 if (!host_error_monitor::requestGPIOEvents(
653 "PCH_BMC_THERMTRIP", host_error_monitor::pchThermtripHandler,
654 host_error_monitor::pchThermtripLine,
655 host_error_monitor::pchThermtripEvent))
656 {
657 return -1;
658 }
659
jayaprakash Mutyala009adbc2019-12-24 22:08:07 +0000660 // Request CPU1_MEM_THERM_EVENT GPIO events
661 if (!host_error_monitor::requestGPIOEvents(
662 "CPU1_MEM_THERM_EVENT", host_error_monitor::cpu1MemtripHandler,
663 host_error_monitor::cpu1MemtripLine,
664 host_error_monitor::cpu1MemtripEvent))
665 {
666 return -1;
667 }
668
669 // Request CPU2_MEM_THERM_EVENT GPIO events
670 if (!host_error_monitor::requestGPIOEvents(
671 "CPU2_MEM_THERM_EVENT", host_error_monitor::cpu2MemtripHandler,
672 host_error_monitor::cpu2MemtripLine,
673 host_error_monitor::cpu2MemtripEvent))
674 {
675 return -1;
676 }
677
Jason M. Bills5245ed62020-12-04 16:50:21 -0800678 // Initialize the signal monitors
679 host_error_monitor::init();
680
Jason M. Bills1490b142019-07-01 15:48:43 -0700681 host_error_monitor::io.run();
682
683 return 0;
684}