Matt Spinler | f02daec | 2017-08-14 14:00:46 -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 | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 16 | #include "config.h" |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 17 | |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 18 | #include "pgood_monitor.hpp" |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 19 | |
| 20 | #include "elog-errors.hpp" |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 21 | #include "utility.hpp" |
| 22 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 23 | #include <org/open_power/Witherspoon/Fault/error.hpp> |
Anwaar Hadi | 1f0193f | 2025-05-13 21:05:12 +0000 | [diff] [blame] | 24 | #include <phosphor-logging/lg2.hpp> |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 25 | |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 26 | namespace phosphor |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 27 | { |
| 28 | namespace power |
| 29 | { |
| 30 | |
| 31 | constexpr auto POWER_OBJ_PATH = "/org/openbmc/control/power0"; |
| 32 | constexpr auto POWER_INTERFACE = "org.openbmc.control.Power"; |
| 33 | |
Brandon Wyman | e0eb45c | 2017-10-06 12:58:42 -0500 | [diff] [blame] | 34 | using namespace sdbusplus::org::open_power::Witherspoon::Fault::Error; |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 35 | |
| 36 | bool PGOODMonitor::pgoodPending() |
| 37 | { |
| 38 | bool pending = false; |
| 39 | int32_t state = 0; |
| 40 | int32_t pgood = 0; |
| 41 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 42 | auto service = util::getService(POWER_OBJ_PATH, POWER_INTERFACE, bus); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 43 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 44 | util::getProperty<int32_t>(POWER_INTERFACE, "pgood", POWER_OBJ_PATH, |
| 45 | service, bus, pgood); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 46 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 47 | // When state = 1, system was switched on |
| 48 | util::getProperty<int32_t>(POWER_INTERFACE, "state", POWER_OBJ_PATH, |
| 49 | service, bus, state); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 50 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 51 | // On but no PGOOD |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 52 | if (state && !pgood) |
| 53 | { |
| 54 | pending = true; |
| 55 | } |
| 56 | |
| 57 | return pending; |
| 58 | } |
| 59 | |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 60 | void PGOODMonitor::analyze() |
| 61 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 62 | // Timer callback. |
| 63 | // The timer expired before it was stopped. |
| 64 | // If PGOOD is still pending (it should be), |
| 65 | // then there is a real failure. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 66 | |
| 67 | if (pgoodPending()) |
| 68 | { |
Andy YF Wang | 40247cc | 2019-09-06 18:30:56 +0800 | [diff] [blame] | 69 | #ifdef DEVICE_ACCESS |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 70 | device->onFailure(); |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 71 | #endif |
Anwaar Hadi | f8e8bc1 | 2025-06-05 21:08:06 +0000 | [diff] [blame] | 72 | phosphor::logging::report<PowerOnFailure>(); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 73 | } |
| 74 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 75 | // The pgood-wait service (with a longer timeout) |
| 76 | // will handle powering off the system. |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 77 | timer.get_event().exit(EXIT_SUCCESS); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void PGOODMonitor::propertyChanged() |
| 81 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 82 | // Multiple properties could have changed here. |
| 83 | // Keep things simple and just recheck the important ones. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 84 | if (!pgoodPending()) |
| 85 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 86 | // PGOOD is on, or system is off, so we are done. |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 87 | timer.get_event().exit(EXIT_SUCCESS); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
| 91 | void PGOODMonitor::startListening() |
| 92 | { |
| 93 | match = std::make_unique<sdbusplus::bus::match_t>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 94 | bus, |
| 95 | sdbusplus::bus::match::rules::propertiesChanged(POWER_OBJ_PATH, |
| 96 | POWER_INTERFACE), |
Brad Bishop | 11cb672 | 2019-09-03 14:30:06 -0400 | [diff] [blame] | 97 | [this](auto&) { this->propertyChanged(); }); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | int PGOODMonitor::run() |
| 101 | { |
| 102 | try |
| 103 | { |
| 104 | startListening(); |
| 105 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 106 | // If PGOOD came up before we got here, we're done. |
| 107 | // Otherwise if PGOOD doesn't get asserted before |
| 108 | // the timer expires, it's a failure. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 109 | if (!pgoodPending()) |
| 110 | { |
| 111 | return EXIT_SUCCESS; |
| 112 | } |
| 113 | |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 114 | return timer.get_event().loop(); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 115 | } |
Patrick Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 116 | catch (const std::exception& e) |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 117 | { |
Anwaar Hadi | 1f0193f | 2025-05-13 21:05:12 +0000 | [diff] [blame] | 118 | lg2::error("Unexpected failure prevented PGOOD checking: {ERROR}", |
| 119 | "ERROR", e); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 120 | } |
| 121 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 122 | // Letting the service fail won't help anything, so don't do it. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 123 | return EXIT_SUCCESS; |
| 124 | } |
| 125 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 126 | } // namespace power |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 127 | } // namespace phosphor |