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 | 882ce95 | 2017-10-05 16:12:41 -0500 | [diff] [blame] | 16 | #include <org/open_power/Witherspoon/Fault/error.hpp> |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 17 | #include <phosphor-logging/log.hpp> |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 18 | #include "config.h" |
Matt Spinler | 882ce95 | 2017-10-05 16:12:41 -0500 | [diff] [blame] | 19 | #include "elog-errors.hpp" |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 20 | #include "runtime_monitor.hpp" |
| 21 | #include "utility.hpp" |
| 22 | |
| 23 | namespace witherspoon |
| 24 | { |
| 25 | namespace power |
| 26 | { |
| 27 | |
| 28 | using namespace phosphor::logging; |
Matt Spinler | 882ce95 | 2017-10-05 16:12:41 -0500 | [diff] [blame] | 29 | using namespace sdbusplus::org::open_power::Witherspoon::Fault::Error; |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 30 | |
| 31 | int RuntimeMonitor::run() |
| 32 | { |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 33 | #ifdef UCD90160_DEVICE_ACCESS |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 34 | return DeviceMonitor::run(); |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 35 | #else |
| 36 | return EXIT_SUCCESS; |
| 37 | #endif |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void 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 Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 48 | #ifdef UCD90160_DEVICE_ACCESS |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 49 | device->onFailure(); |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 50 | #endif |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 51 | //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 Spinler | 882ce95 | 2017-10-05 16:12:41 -0500 | [diff] [blame] | 55 | util::powerOff<Shutdown>(bus); |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 56 | } |
| 57 | catch (std::exception& e) |
| 58 | { |
| 59 | //No need to crash |
| 60 | log<level::ERR>(e.what()); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | } |
| 65 | } |