blob: 9bfeaf080339402ce60100a5bb6c2cedf4be6be6 [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 Spinler882ce952017-10-05 16:12:41 -050016#include <org/open_power/Witherspoon/Fault/error.hpp>
Matt Spinler70849272017-08-22 09:14:40 -050017#include <phosphor-logging/log.hpp>
Matt Spinler45a054a2017-08-22 15:07:07 -050018#include "config.h"
Matt Spinler882ce952017-10-05 16:12:41 -050019#include "elog-errors.hpp"
Matt Spinler70849272017-08-22 09:14:40 -050020#include "runtime_monitor.hpp"
21#include "utility.hpp"
22
23namespace witherspoon
24{
25namespace power
26{
27
28using namespace phosphor::logging;
Matt Spinler882ce952017-10-05 16:12:41 -050029using namespace sdbusplus::org::open_power::Witherspoon::Fault::Error;
Matt Spinler70849272017-08-22 09:14:40 -050030
31int RuntimeMonitor::run()
32{
Matt Spinler45a054a2017-08-22 15:07:07 -050033#ifdef UCD90160_DEVICE_ACCESS
Matt Spinler70849272017-08-22 09:14:40 -050034 return DeviceMonitor::run();
Matt Spinler45a054a2017-08-22 15:07:07 -050035#else
36 return EXIT_SUCCESS;
37#endif
Matt Spinler70849272017-08-22 09:14:40 -050038}
39
40void RuntimeMonitor::onPowerLost(sdbusplus::message::message& msg)
41{
42 log<level::INFO>("PGOOD failure detected. Checking for faults.");
43
44 try
45 {
46 timer.stop();
47
Matt Spinler45a054a2017-08-22 15:07:07 -050048#ifdef UCD90160_DEVICE_ACCESS
Matt Spinler70849272017-08-22 09:14:40 -050049 device->onFailure();
Matt Spinler45a054a2017-08-22 15:07:07 -050050#endif
Matt Spinler70849272017-08-22 09:14:40 -050051 //Note: This application only runs when the system has
52 //power, so it will be killed by systemd sometime shortly
53 //after this power off is issued.
54
Matt Spinler882ce952017-10-05 16:12:41 -050055 util::powerOff<Shutdown>(bus);
Matt Spinler70849272017-08-22 09:14:40 -050056 }
57 catch (std::exception& e)
58 {
59 //No need to crash
60 log<level::ERR>(e.what());
61 }
62}
63
64}
65}