Matt Spinler | afb3913 | 2017-08-14 13:53:07 -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 | */ |
Andy YF Wang | 40247cc | 2019-09-06 18:30:56 +0800 | [diff] [blame] | 16 | #include "config.h" |
| 17 | |
Andy YF Wang | 40247cc | 2019-09-06 18:30:56 +0800 | [diff] [blame] | 18 | #include "mihawk-cpld.hpp" |
Matt Spinler | 56d90a8 | 2017-08-14 14:05:11 -0500 | [diff] [blame] | 19 | #include "pgood_monitor.hpp" |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 20 | #include "runtime_monitor.hpp" |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 21 | #include "ucd90160.hpp" |
Matt Spinler | afb3913 | 2017-08-14 13:53:07 -0500 | [diff] [blame] | 22 | |
George Liu | 130ac97 | 2023-08-14 18:01:59 +0800 | [diff] [blame] | 23 | #include <CLI/CLI.hpp> |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 24 | #include <phosphor-logging/log.hpp> |
| 25 | #include <sdeventplus/event.hpp> |
| 26 | |
Brandon Wyman | d1bc4ce | 2019-12-13 14:20:34 -0600 | [diff] [blame] | 27 | #include <chrono> |
| 28 | #include <iostream> |
| 29 | |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 30 | using namespace phosphor::power; |
Matt Spinler | 56d90a8 | 2017-08-14 14:05:11 -0500 | [diff] [blame] | 31 | using namespace phosphor::logging; |
Matt Spinler | afb3913 | 2017-08-14 13:53:07 -0500 | [diff] [blame] | 32 | |
| 33 | int main(int argc, char** argv) |
| 34 | { |
George Liu | 130ac97 | 2023-08-14 18:01:59 +0800 | [diff] [blame] | 35 | CLI::App app{"Phosphor sequencer monitor"}; |
| 36 | std::string action{}; |
| 37 | std::string interVal{}; |
Matt Spinler | afb3913 | 2017-08-14 13:53:07 -0500 | [diff] [blame] | 38 | |
George Liu | 130ac97 | 2023-08-14 18:01:59 +0800 | [diff] [blame] | 39 | std::vector<std::string> actionTypes = {"pgood-monitor", "runtime-monitor"}; |
| 40 | app.add_option("-a,--action", action, |
| 41 | "Action: pgood-monitor or runtime-monitor\n") |
| 42 | ->required() |
| 43 | ->transform(CLI::IsMember(actionTypes)); |
| 44 | app.add_option("-i,--interval", interVal, |
| 45 | "Interval in milliseconds:\n" |
| 46 | "PGOOD monitor: time allowed for PGOOD to come up\n" |
| 47 | "Runtime monitor: polling interval.\n") |
| 48 | ->required(); |
| 49 | |
| 50 | try |
Matt Spinler | afb3913 | 2017-08-14 13:53:07 -0500 | [diff] [blame] | 51 | { |
George Liu | 130ac97 | 2023-08-14 18:01:59 +0800 | [diff] [blame] | 52 | app.parse(argc, argv); |
| 53 | } |
| 54 | catch (CLI::Error& e) |
| 55 | { |
| 56 | return app.exit(e); |
Matt Spinler | afb3913 | 2017-08-14 13:53:07 -0500 | [diff] [blame] | 57 | } |
| 58 | |
George Liu | 130ac97 | 2023-08-14 18:01:59 +0800 | [diff] [blame] | 59 | auto i = strtoul(interVal.c_str(), nullptr, 10); |
Matt Spinler | afb3913 | 2017-08-14 13:53:07 -0500 | [diff] [blame] | 60 | if (i == 0) |
| 61 | { |
| 62 | std::cerr << "Invalid interval value\n"; |
| 63 | exit(EXIT_FAILURE); |
| 64 | } |
| 65 | |
Matt Spinler | 78c5c2b | 2017-12-14 10:42:07 -0600 | [diff] [blame] | 66 | std::chrono::milliseconds interval{i}; |
Matt Spinler | afb3913 | 2017-08-14 13:53:07 -0500 | [diff] [blame] | 67 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 68 | auto event = sdeventplus::Event::get_default(); |
Matt Spinler | 56d90a8 | 2017-08-14 14:05:11 -0500 | [diff] [blame] | 69 | auto bus = sdbusplus::bus::new_default(); |
| 70 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
| 71 | |
Andy YF Wang | 40247cc | 2019-09-06 18:30:56 +0800 | [diff] [blame] | 72 | auto device = std::make_unique<SEQUENCER>(0, bus); |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 73 | |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 74 | std::unique_ptr<DeviceMonitor> monitor; |
Matt Spinler | 56d90a8 | 2017-08-14 14:05:11 -0500 | [diff] [blame] | 75 | |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 76 | if (action == "pgood-monitor") |
| 77 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 78 | // If PGOOD doesn't turn on within a certain |
| 79 | // time, analyze the device for errors |
| 80 | monitor = std::make_unique<PGOODMonitor>(std::move(device), bus, event, |
| 81 | interval); |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 82 | } |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 83 | else // runtime-monitor |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 84 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 85 | // Continuously monitor this device both by polling |
| 86 | // and on 'power lost' signals. |
| 87 | monitor = std::make_unique<RuntimeMonitor>(std::move(device), bus, |
| 88 | event, interval); |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | return monitor->run(); |
Matt Spinler | afb3913 | 2017-08-14 13:53:07 -0500 | [diff] [blame] | 92 | } |