Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include <sdbusplus/server.hpp> |
William A. Kennington III | e5a8b47 | 2018-10-18 00:40:04 -0700 | [diff] [blame] | 5 | #include <sdeventplus/event.hpp> |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 6 | #include "device.hpp" |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 7 | #include "device_monitor.hpp" |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 8 | |
| 9 | namespace witherspoon |
| 10 | { |
| 11 | namespace power |
| 12 | { |
| 13 | |
| 14 | /** |
| 15 | * @class PGOODMonitor |
| 16 | * |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 17 | * Monitors PGOOD and checks for errors on the power sequencer |
| 18 | * if it doesn't come on in time. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 19 | * |
| 20 | * The run() function is designed to be called right after the |
| 21 | * power sequencer device is told to kick off a power on. |
| 22 | * |
| 23 | * Future commits will analyze the power sequencer chip for errors |
| 24 | * on a PGOOD fail. |
| 25 | */ |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 26 | class PGOODMonitor : public DeviceMonitor |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 27 | { |
| 28 | public: |
| 29 | |
| 30 | PGOODMonitor() = delete; |
| 31 | ~PGOODMonitor() = default; |
| 32 | PGOODMonitor(const PGOODMonitor&) = delete; |
| 33 | PGOODMonitor& operator=(const PGOODMonitor&) = delete; |
| 34 | PGOODMonitor(PGOODMonitor&&) = delete; |
| 35 | PGOODMonitor& operator=(PGOODMonitor&&) = delete; |
| 36 | |
| 37 | /** |
| 38 | * Constructor |
| 39 | * |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 40 | * @param[in] d - the device to monitor |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 41 | * @param[in] b - D-Bus bus object |
| 42 | * @param[in] e - event object |
| 43 | * @param[in] t - time to allow PGOOD to come up |
| 44 | */ |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 45 | PGOODMonitor(std::unique_ptr<witherspoon::power::Device>&& d, |
| 46 | sdbusplus::bus::bus& b, |
William A. Kennington III | e5a8b47 | 2018-10-18 00:40:04 -0700 | [diff] [blame] | 47 | const sdeventplus::Event& e, |
Matt Spinler | 78c5c2b | 2017-12-14 10:42:07 -0600 | [diff] [blame] | 48 | std::chrono::milliseconds& t) : |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 49 | DeviceMonitor(std::move(d), e, t), |
| 50 | bus(b) |
| 51 | { |
| 52 | } |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 53 | |
| 54 | /** |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 55 | * Analyzes the power sequencer for fails and then |
| 56 | * notifies the event loop that it can exit. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 57 | * |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 58 | * The timer callback. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 59 | */ |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 60 | void analyze() override; |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Waits a specified amount of time for PGOOD to |
| 64 | * come on, and if it fails to come on in that time |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 65 | * it will analyze the power sequencer for faults. |
| 66 | * |
| 67 | * It will exit after either PGOOD is asserted or |
| 68 | * the device is analyzed for faults. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 69 | * |
| 70 | * @return - the return value from sd_event_loop() |
| 71 | */ |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 72 | int run() override; |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 73 | |
| 74 | private: |
| 75 | |
| 76 | /** |
| 77 | * Enables the properties changed signal callback |
| 78 | * on the power object so we can tell when PGOOD |
| 79 | * comes on. |
| 80 | */ |
| 81 | void startListening(); |
| 82 | |
| 83 | /** |
| 84 | * The callback function for the properties changed |
| 85 | * signal. |
| 86 | */ |
| 87 | void propertyChanged(); |
| 88 | |
| 89 | /** |
| 90 | * Returns true if the system has been turned on |
| 91 | * but PGOOD isn't up yet. |
| 92 | */ |
| 93 | bool pgoodPending(); |
| 94 | |
| 95 | /** |
| 96 | * Used to break out of the event loop in run() |
| 97 | */ |
| 98 | void exitEventLoop(); |
| 99 | |
| 100 | /** |
| 101 | * The D-Bus object |
| 102 | */ |
| 103 | sdbusplus::bus::bus& bus; |
| 104 | |
| 105 | /** |
| 106 | * The match object for the properties changed signal |
| 107 | */ |
| 108 | std::unique_ptr<sdbusplus::bus::match_t> match; |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | } |
| 112 | } |