blob: 8242c2297a42908a6984c4b59d480c596c857b26 [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>
Anwaar Hadi1f0193f2025-05-13 21:05:12 +000024#include <phosphor-logging/lg2.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
Matt Spinler882ce952017-10-05 16:12:41 -050031using namespace sdbusplus::org::open_power::Witherspoon::Fault::Error;
Matt Spinler70849272017-08-22 09:14:40 -050032
33int RuntimeMonitor::run()
34{
Andy YF Wang40247cc2019-09-06 18:30:56 +080035#ifdef DEVICE_ACCESS
Matt Spinler70849272017-08-22 09:14:40 -050036 return DeviceMonitor::run();
Matt Spinler45a054a2017-08-22 15:07:07 -050037#else
38 return EXIT_SUCCESS;
39#endif
Matt Spinler70849272017-08-22 09:14:40 -050040}
41
Patrick Williams7354ce62022-07-22 19:26:56 -050042void RuntimeMonitor::onPowerLost(sdbusplus::message_t&)
Matt Spinler70849272017-08-22 09:14:40 -050043{
Anwaar Hadi1f0193f2025-05-13 21:05:12 +000044 lg2::info("PGOOD failure detected. Checking for faults.");
Matt Spinler70849272017-08-22 09:14:40 -050045
46 try
47 {
William A. Kennington III1a0c9172018-10-18 17:57:49 -070048 timer.setEnabled(false);
Matt Spinler70849272017-08-22 09:14:40 -050049
Andy YF Wang40247cc2019-09-06 18:30:56 +080050#ifdef DEVICE_ACCESS
Matt Spinler70849272017-08-22 09:14:40 -050051 device->onFailure();
Matt Spinler45a054a2017-08-22 15:07:07 -050052#endif
Matt Spinlerf0f02b92018-10-25 16:12:43 -050053 // Note: This application only runs when the system has
54 // power, so it will be killed by systemd sometime shortly
55 // after this power off is issued.
Matt Spinler70849272017-08-22 09:14:40 -050056
Matt Spinler882ce952017-10-05 16:12:41 -050057 util::powerOff<Shutdown>(bus);
Matt Spinler70849272017-08-22 09:14:40 -050058 }
Patrick Williamsc1d4de52021-10-06 12:45:57 -050059 catch (const std::exception& e)
Matt Spinler70849272017-08-22 09:14:40 -050060 {
Matt Spinlerf0f02b92018-10-25 16:12:43 -050061 // No need to crash
Anwaar Hadi1f0193f2025-05-13 21:05:12 +000062 lg2::error(
63 "Exception occurred while checking for PGOOD faults in onPowerLost: {ERROR}",
64 "ERROR", e);
Matt Spinler70849272017-08-22 09:14:40 -050065 }
66}
67
Matt Spinlerf0f02b92018-10-25 16:12:43 -050068} // namespace power
Lei YUab093322019-10-09 16:43:22 +080069} // namespace phosphor