Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 1 | /** |
| 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 Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 16 | #include "config.h" |
| 17 | |
| 18 | #include "runtime_monitor.hpp" |
| 19 | |
| 20 | #include "elog-errors.hpp" |
| 21 | #include "utility.hpp" |
| 22 | |
Matt Spinler | 882ce95 | 2017-10-05 16:12:41 -0500 | [diff] [blame] | 23 | #include <org/open_power/Witherspoon/Fault/error.hpp> |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 24 | #include <phosphor-logging/log.hpp> |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 25 | |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 26 | namespace phosphor |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 27 | { |
| 28 | namespace power |
| 29 | { |
| 30 | |
| 31 | using namespace phosphor::logging; |
Matt Spinler | 882ce95 | 2017-10-05 16:12:41 -0500 | [diff] [blame] | 32 | using namespace sdbusplus::org::open_power::Witherspoon::Fault::Error; |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 33 | |
| 34 | int RuntimeMonitor::run() |
| 35 | { |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 36 | #ifdef UCD90160_DEVICE_ACCESS |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 37 | return DeviceMonitor::run(); |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 38 | #else |
| 39 | return EXIT_SUCCESS; |
| 40 | #endif |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 41 | } |
| 42 | |
Brad Bishop | 11cb672 | 2019-09-03 14:30:06 -0400 | [diff] [blame] | 43 | void RuntimeMonitor::onPowerLost(sdbusplus::message::message&) |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 44 | { |
| 45 | log<level::INFO>("PGOOD failure detected. Checking for faults."); |
| 46 | |
| 47 | try |
| 48 | { |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 49 | timer.setEnabled(false); |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 50 | |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 51 | #ifdef UCD90160_DEVICE_ACCESS |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 52 | device->onFailure(); |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 53 | #endif |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 54 | // 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 Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 57 | |
Matt Spinler | 882ce95 | 2017-10-05 16:12:41 -0500 | [diff] [blame] | 58 | util::powerOff<Shutdown>(bus); |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 59 | } |
| 60 | catch (std::exception& e) |
| 61 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 62 | // No need to crash |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 63 | log<level::ERR>(e.what()); |
| 64 | } |
| 65 | } |
| 66 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 67 | } // namespace power |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 68 | } // namespace phosphor |