Ed Tanous | 2b314e4 | 2025-08-19 15:46:18 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: 2025 NVIDIA |
| 3 | |
Marc Olberding | 1e17db5 | 2025-08-27 12:25:28 -0700 | [diff] [blame] | 4 | #include "gpio.hpp" |
| 5 | #include "i2c.hpp" |
Marc Olberding | 801bc90 | 2025-08-27 12:55:42 -0700 | [diff] [blame] | 6 | #include "nvidia.hpp" |
Marc Olberding | 1e17db5 | 2025-08-27 12:25:28 -0700 | [diff] [blame] | 7 | #include "utilities.hpp" |
| 8 | |
Ed Tanous | 2b314e4 | 2025-08-19 15:46:18 -0700 | [diff] [blame] | 9 | #include <fcntl.h> |
| 10 | #include <systemd/sd-daemon.h> |
| 11 | |
| 12 | #include <CLI/CLI.hpp> |
| 13 | #include <gpiod.hpp> |
| 14 | |
Marc Olberding | 801bc90 | 2025-08-27 12:55:42 -0700 | [diff] [blame] | 15 | #include <algorithm> |
| 16 | #include <array> |
Ed Tanous | 2b314e4 | 2025-08-19 15:46:18 -0700 | [diff] [blame] | 17 | #include <iostream> |
Marc Olberding | 801bc90 | 2025-08-27 12:55:42 -0700 | [diff] [blame] | 18 | #include <string_view> |
| 19 | #include <utility> |
Ed Tanous | 2b314e4 | 2025-08-19 15:46:18 -0700 | [diff] [blame] | 20 | |
| 21 | constexpr std::array<std::pair<std::string_view, int (*)()>, 2> init_functions{ |
Marc Olberding | 801bc90 | 2025-08-27 12:55:42 -0700 | [diff] [blame] | 22 | {{"nvidia-gb200", nvidia::init_gb200_base}, |
| 23 | {"nvidia-gb200-with-p2020", nvidia::init_gb200_with_p2020}}}; |
Ed Tanous | 2b314e4 | 2025-08-19 15:46:18 -0700 | [diff] [blame] | 24 | |
| 25 | int main(int argc, char** argv) |
| 26 | { |
| 27 | CLI::App app("Platform init CLI"); |
| 28 | |
| 29 | app.require_subcommand(); |
| 30 | |
| 31 | CLI::App* init_sub = |
| 32 | app.add_subcommand("init", "Initialize the platform and daemonize"); |
| 33 | std::string platform_name; |
| 34 | init_sub |
| 35 | ->add_option("platform_name", platform_name, |
| 36 | "Name of the platform to init") |
| 37 | ->required(); |
| 38 | app.require_subcommand(); |
| 39 | |
| 40 | CLI11_PARSE(app, argc, argv) |
| 41 | |
| 42 | const auto* it = std::ranges::find_if( |
| 43 | init_functions, |
| 44 | [&platform_name](const std::pair<std::string_view, int (*)()> val) { |
| 45 | return val.first == platform_name; |
| 46 | }); |
| 47 | if (it == init_functions.end()) |
| 48 | { |
| 49 | std::cerr << init_sub->help() << "\n"; |
| 50 | return EXIT_FAILURE; |
| 51 | } |
| 52 | |
| 53 | return it->second(); |
| 54 | } |