1fe5b5c66SFaisal Awada /** 2fe5b5c66SFaisal Awada * Copyright © 2025 IBM Corporation 3fe5b5c66SFaisal Awada * 4fe5b5c66SFaisal Awada * Licensed under the Apache License, Version 2.0 (the "License"); 5fe5b5c66SFaisal Awada * you may not use this file except in compliance with the License. 6fe5b5c66SFaisal Awada * You may obtain a copy of the License at 7fe5b5c66SFaisal Awada * 8fe5b5c66SFaisal Awada * http://www.apache.org/licenses/LICENSE-2.0 9fe5b5c66SFaisal Awada * 10fe5b5c66SFaisal Awada * Unless required by applicable law or agreed to in writing, software 11fe5b5c66SFaisal Awada * distributed under the License is distributed on an "AS IS" BASIS, 12fe5b5c66SFaisal Awada * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fe5b5c66SFaisal Awada * See the License for the specific language governing permissions and 14fe5b5c66SFaisal Awada * limitations under the License. 15fe5b5c66SFaisal Awada */ 16fe5b5c66SFaisal Awada 17fe5b5c66SFaisal Awada #pragma once 18fe5b5c66SFaisal Awada 19fe5b5c66SFaisal Awada #include "types.hpp" 20fe5b5c66SFaisal Awada #include "utility.hpp" 21fe5b5c66SFaisal Awada 22fe5b5c66SFaisal Awada #include <sdbusplus/bus.hpp> 23fe5b5c66SFaisal Awada 24fe5b5c66SFaisal Awada #include <string> 25fe5b5c66SFaisal Awada 26fe5b5c66SFaisal Awada namespace validator 27fe5b5c66SFaisal Awada { 28fe5b5c66SFaisal Awada using namespace phosphor::power::util; 29fe5b5c66SFaisal Awada /** 30fe5b5c66SFaisal Awada * @class PSUUpdateValidator 31fe5b5c66SFaisal Awada * @brief This class validates PSU configurations in OpenBMC. 32fe5b5c66SFaisal Awada */ 33fe5b5c66SFaisal Awada class PSUUpdateValidator 34fe5b5c66SFaisal Awada { 35fe5b5c66SFaisal Awada public: 36fe5b5c66SFaisal Awada /** 37fe5b5c66SFaisal Awada * @brief Constructor - Initializes D-Bus connection. 38fe5b5c66SFaisal Awada * 39fe5b5c66SFaisal Awada * @param bus The sdbusplus DBus bus connection 40fe5b5c66SFaisal Awada * @param psuPath PSU inventory path 41fe5b5c66SFaisal Awada */ PSUUpdateValidator(sdbusplus::bus_t & bus,const std::string & psuPath)42fe5b5c66SFaisal Awada PSUUpdateValidator(sdbusplus::bus_t& bus, const std::string& psuPath) : 43fe5b5c66SFaisal Awada bus(bus), psuPath(psuPath) 44fe5b5c66SFaisal Awada {} 45fe5b5c66SFaisal Awada 46fe5b5c66SFaisal Awada /** 47fe5b5c66SFaisal Awada * @brief Checks if all PSUs are of the same model. 48fe5b5c66SFaisal Awada * 49fe5b5c66SFaisal Awada * @return true if all PSUs have the same model. 50fe5b5c66SFaisal Awada * @return false if any PSU has a different model. 51fe5b5c66SFaisal Awada */ 52fe5b5c66SFaisal Awada bool areAllPsuSameModel(); 53fe5b5c66SFaisal Awada 54fe5b5c66SFaisal Awada /** 55fe5b5c66SFaisal Awada * @brief Counts the number of PSUs that are physically present and 56fe5b5c66SFaisal Awada * operational 57fe5b5c66SFaisal Awada * 58fe5b5c66SFaisal Awada * @return true if successfully counted present PSUs. 59fe5b5c66SFaisal Awada * @return false on failure. 60fe5b5c66SFaisal Awada */ 61fe5b5c66SFaisal Awada bool countPresentPsus(); 62fe5b5c66SFaisal Awada 63fe5b5c66SFaisal Awada /** 64fe5b5c66SFaisal Awada * @brief Retrieves the required number of PSUs for redundancy. 65fe5b5c66SFaisal Awada * 66fe5b5c66SFaisal Awada * @return true if successfully retrieved redundancy count. 67fe5b5c66SFaisal Awada * @return false on failure. 68fe5b5c66SFaisal Awada */ 69fe5b5c66SFaisal Awada bool getRequiredPsus(); 70fe5b5c66SFaisal Awada 71fe5b5c66SFaisal Awada /** 72fe5b5c66SFaisal Awada * @brief Ensure all PSUs have same model, validate all PSUs present 73fe5b5c66SFaisal Awada * and functional meet or exceed the number of PSUs required for this 74fe5b5c66SFaisal Awada * system 75fe5b5c66SFaisal Awada * 76fe5b5c66SFaisal Awada * @return true if all configuration requirement are met. 77fe5b5c66SFaisal Awada * @return otherwise false 78fe5b5c66SFaisal Awada */ 79fe5b5c66SFaisal Awada bool validToUpdate(); 80fe5b5c66SFaisal Awada 81fe5b5c66SFaisal Awada /** 82fe5b5c66SFaisal Awada * @brief Retrieves the operational PSU status. 83fe5b5c66SFaisal Awada * 84fe5b5c66SFaisal Awada * @return true if operational 85fe5b5c66SFaisal Awada * @return false on operational failure. 86fe5b5c66SFaisal Awada */ 87fe5b5c66SFaisal Awada bool isItFunctional(const std::string& path); 88fe5b5c66SFaisal Awada 89fe5b5c66SFaisal Awada private: 90*2ae58218SPatrick Williams sdbusplus::bus_t& bus; // D-Bus connection instance 91fe5b5c66SFaisal Awada std::vector<std::string> psuPaths; // List of PSU object paths 92fe5b5c66SFaisal Awada std::string targetPsuModel; // Model name of the reference PSU 93fe5b5c66SFaisal Awada std::string psuPath; // Path of the referenced PSU 94fe5b5c66SFaisal Awada DbusSubtree supportedObjects; // D-Bus PSU supported objects 95fe5b5c66SFaisal Awada DbusPropertyMap properties; // D-Bus PSU properties 96fe5b5c66SFaisal Awada int presentPsuCount = 0; // Count of physically present PSUs 97fe5b5c66SFaisal Awada int redundantCount = 0; // Total number of PSUs required to be 98fe5b5c66SFaisal Awada // in this system configuration. 99fe5b5c66SFaisal Awada }; 100fe5b5c66SFaisal Awada 101fe5b5c66SFaisal Awada } // namespace validator 102