blob: 4770a718f91a60ca39160687b15709c461a90b65 [file] [log] [blame]
Lei YU0bf1b782019-08-29 16:02:30 +08001/**
2 * Copyright © 2019 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 */
16#pragma once
17
Faisal Awada5dce1a72024-08-19 15:51:44 -050018#include "pmbus.hpp"
19
20#include <sdbusplus/bus.hpp>
21
Lei YU0bf1b782019-08-29 16:02:30 +080022#include <string>
Faisal Awada5dce1a72024-08-19 15:51:44 -050023#include <tuple>
Lei YU093b5912019-10-22 15:28:51 +080024#include <vector>
Lei YU0bf1b782019-08-29 16:02:30 +080025
26namespace version
27{
Shawn McCarney14572cf2024-11-06 12:17:57 -060028namespace internal
Faisal Awada5dce1a72024-08-19 15:51:44 -050029{
30// PsuInfo contains the device path, pmbus read type, and the version string
31using PsuVersionInfo =
32 std::tuple<std::string, phosphor::pmbus::Type, std::string>;
33
Lei YU0bf1b782019-08-29 16:02:30 +080034/**
Faisal Awada5dce1a72024-08-19 15:51:44 -050035 * @brief Get PSU version information
36 *
37 * @param[in] psuInventoryPath - The PSU inventory path.
38 *
39 * @return tuple - device path, pmbus read type and PSU version
40 */
41PsuVersionInfo getVersionInfo(const std::string& psuInventoryPath);
42
43/**
44 * @brief Get firmware latest version
45 *
46 * @param[in] versions - String of versions
47 *
48 * @return version - latest firmware level
49 */
50std::string getLatestDefault(const std::vector<std::string>& versions);
51
Shawn McCarney14572cf2024-11-06 12:17:57 -060052} // namespace internal
Faisal Awada5dce1a72024-08-19 15:51:44 -050053
54/**
55 * Get the software version of the PSU using sysfs
56 *
57 * @param[in] bus - Systemd bus connection
58 * @param[in] psuInventoryPath - The inventory path of the PSU
59 *
60 * @return The version of the PSU
61 */
62std::string getVersion(sdbusplus::bus_t& bus,
63 const std::string& psuInventoryPath);
64
65/**
66 * Get the software version of the PSU using psu.json
Lei YU0bf1b782019-08-29 16:02:30 +080067 *
68 * @param[in] psuInventoryPath - The inventory path of the PSU
Lei YU093b5912019-10-22 15:28:51 +080069 *
70 * @return The version of the PSU
Lei YU0bf1b782019-08-29 16:02:30 +080071 */
72std::string getVersion(const std::string& psuInventoryPath);
73
Lei YU093b5912019-10-22 15:28:51 +080074/**
75 * Get the latest version from a list of versions
76 *
77 * @param[in] versions - The list of PSU version strings
78 *
79 * @return The latest version
80 */
81std::string getLatest(const std::vector<std::string>& versions);
82
Lei YU0bf1b782019-08-29 16:02:30 +080083} // namespace version