blob: f706655786cf08b87c54bb2f36472389ad57cdc5 [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
Lei YUab093322019-10-09 16:43:22 +080026namespace phosphor
Matt Spinler70849272017-08-22 09:14:40 -050027{
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{
Andy YF Wang40247cc2019-09-06 18:30:56 +080036#ifdef 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
Brad Bishop11cb6722019-09-03 14:30:06 -040043void RuntimeMonitor::onPowerLost(sdbusplus::message::message&)
Matt Spinler70849272017-08-22 09:14:40 -050044{
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
Andy YF Wang40247cc2019-09-06 18:30:56 +080051#ifdef 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
Lei YUab093322019-10-09 16:43:22 +080068} // namespace phosphor