blob: 5d17eb9f0eab8b22c3f29e78da19e949aa0b08cb [file] [log] [blame]
Matt Spinler70849272017-08-22 09:14:40 -05001/**
2 * Copyright © 2017 IBM 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 */
Matt Spinlerf0f02b92018-10-25 16:12:43 -050016#include "config.h"
17
18#include "runtime_monitor.hpp"
19
20#include "elog-errors.hpp"
21#include "utility.hpp"
22
Matt Spinler882ce952017-10-05 16:12:41 -050023#include <org/open_power/Witherspoon/Fault/error.hpp>
Matt Spinler70849272017-08-22 09:14:40 -050024#include <phosphor-logging/log.hpp>
Matt Spinler70849272017-08-22 09:14:40 -050025
26namespace witherspoon
27{
28namespace power
29{
30
31using namespace phosphor::logging;
Matt Spinler882ce952017-10-05 16:12:41 -050032using namespace sdbusplus::org::open_power::Witherspoon::Fault::Error;
Matt Spinler70849272017-08-22 09:14:40 -050033
34int RuntimeMonitor::run()
35{
Matt Spinler45a054a2017-08-22 15:07:07 -050036#ifdef UCD90160_DEVICE_ACCESS
Matt Spinler70849272017-08-22 09:14:40 -050037 return DeviceMonitor::run();
Matt Spinler45a054a2017-08-22 15:07:07 -050038#else
39 return EXIT_SUCCESS;
40#endif
Matt Spinler70849272017-08-22 09:14:40 -050041}
42
43void RuntimeMonitor::onPowerLost(sdbusplus::message::message& msg)
44{
45 log<level::INFO>("PGOOD failure detected. Checking for faults.");
46
47 try
48 {
William A. Kennington III1a0c9172018-10-18 17:57:49 -070049 timer.setEnabled(false);
Matt Spinler70849272017-08-22 09:14:40 -050050
Matt Spinler45a054a2017-08-22 15:07:07 -050051#ifdef UCD90160_DEVICE_ACCESS
Matt Spinler70849272017-08-22 09:14:40 -050052 device->onFailure();
Matt Spinler45a054a2017-08-22 15:07:07 -050053#endif
Matt Spinlerf0f02b92018-10-25 16:12:43 -050054 // Note: This application only runs when the system has
55 // power, so it will be killed by systemd sometime shortly
56 // after this power off is issued.
Matt Spinler70849272017-08-22 09:14:40 -050057
Matt Spinler882ce952017-10-05 16:12:41 -050058 util::powerOff<Shutdown>(bus);
Matt Spinler70849272017-08-22 09:14:40 -050059 }
60 catch (std::exception& e)
61 {
Matt Spinlerf0f02b92018-10-25 16:12:43 -050062 // No need to crash
Matt Spinler70849272017-08-22 09:14:40 -050063 log<level::ERR>(e.what());
64 }
65}
66
Matt Spinlerf0f02b92018-10-25 16:12:43 -050067} // namespace power
68} // namespace witherspoon