xref: /openbmc/phosphor-logging/extensions/openpower-pels/data_interface.hpp (revision 25291157927273a4ac459c6479c1d3090ddc6a16)
1c8705e2bSMatt Spinler #pragma once
2c8705e2bSMatt Spinler 
32a28c936SMatt Spinler #include "dbus_types.hpp"
42a28c936SMatt Spinler #include "dbus_watcher.hpp"
52a28c936SMatt Spinler 
6ff35be3eSDeepa Karthikeyan #ifdef PEL_ENABLE_PHAL
7ff35be3eSDeepa Karthikeyan #include <libguard/guard_interface.hpp>
8ff35be3eSDeepa Karthikeyan #include <libguard/include/guard_record.hpp>
9ff35be3eSDeepa Karthikeyan #endif
10ff35be3eSDeepa Karthikeyan 
11a167a7d9SMatt Spinler #include <phosphor-logging/lg2.hpp>
12c8705e2bSMatt Spinler #include <sdbusplus/bus.hpp>
13c8705e2bSMatt Spinler #include <sdbusplus/bus/match.hpp>
14c8705e2bSMatt Spinler 
15d8ae618aSArya K Padman #include <expected>
162544b419SPatrick Williams #include <filesystem>
172544b419SPatrick Williams #include <fstream>
18d8ae618aSArya K Padman #include <unordered_map>
192544b419SPatrick Williams 
20ff35be3eSDeepa Karthikeyan #ifdef PEL_ENABLE_PHAL
21ff35be3eSDeepa Karthikeyan using GardType = openpower::guard::GardType;
22ff35be3eSDeepa Karthikeyan namespace libguard = openpower::guard;
23ff35be3eSDeepa Karthikeyan #endif
24ff35be3eSDeepa Karthikeyan 
25c8705e2bSMatt Spinler namespace openpower
26c8705e2bSMatt Spinler {
27c8705e2bSMatt Spinler namespace pels
28c8705e2bSMatt Spinler {
29c8705e2bSMatt Spinler 
30c8705e2bSMatt Spinler /**
31c8705e2bSMatt Spinler  * @class DataInterface
32c8705e2bSMatt Spinler  *
3319e89ce4SMatt Spinler  * A base class for gathering data about the system for use
3419e89ce4SMatt Spinler  * in PELs. Implemented this way to facilitate mocking.
35c8705e2bSMatt Spinler  */
36c8705e2bSMatt Spinler class DataInterfaceBase
37c8705e2bSMatt Spinler {
38c8705e2bSMatt Spinler   public:
39c8705e2bSMatt Spinler     DataInterfaceBase() = default;
40c8705e2bSMatt Spinler     virtual ~DataInterfaceBase() = default;
41c8705e2bSMatt Spinler     DataInterfaceBase(const DataInterfaceBase&) = default;
42c8705e2bSMatt Spinler     DataInterfaceBase& operator=(const DataInterfaceBase&) = default;
43c8705e2bSMatt Spinler     DataInterfaceBase(DataInterfaceBase&&) = default;
44c8705e2bSMatt Spinler     DataInterfaceBase& operator=(DataInterfaceBase&&) = default;
45c8705e2bSMatt Spinler 
46c8705e2bSMatt Spinler     /**
4719e89ce4SMatt Spinler      * @brief Returns the machine Type/Model
48c8705e2bSMatt Spinler      *
49c8705e2bSMatt Spinler      * @return string - The machine Type/Model string
50c8705e2bSMatt Spinler      */
5181b4dcabSVijay Lobo     virtual std::string getMachineTypeModel() const = 0;
52c8705e2bSMatt Spinler 
53c8705e2bSMatt Spinler     /**
5419e89ce4SMatt Spinler      * @brief Returns the machine serial number
55c8705e2bSMatt Spinler      *
56c8705e2bSMatt Spinler      * @return string - The machine serial number
57c8705e2bSMatt Spinler      */
5881b4dcabSVijay Lobo     virtual std::string getMachineSerialNumber() const = 0;
5919e89ce4SMatt Spinler 
60a7d9d961SMatt Spinler     /**
61cce1411aSMatt Spinler      * @brief Says if the system is managed by a hardware
62cce1411aSMatt Spinler      *        management console.
63cce1411aSMatt Spinler      * @return bool - If the system is HMC managed
64cce1411aSMatt Spinler      */
isHMCManaged() const65cce1411aSMatt Spinler     virtual bool isHMCManaged() const
66cce1411aSMatt Spinler     {
67cce1411aSMatt Spinler         return _hmcManaged;
68cce1411aSMatt Spinler     }
69cce1411aSMatt Spinler 
70cce1411aSMatt Spinler     /**
71a7d9d961SMatt Spinler      * @brief Says if the host is up and running
72a7d9d961SMatt Spinler      *
73a7d9d961SMatt Spinler      * @return bool - If the host is running
74a7d9d961SMatt Spinler      */
isHostUp() const75a7d9d961SMatt Spinler     virtual bool isHostUp() const
76a7d9d961SMatt Spinler     {
77a7d9d961SMatt Spinler         return _hostUp;
78a7d9d961SMatt Spinler     }
79a7d9d961SMatt Spinler 
80a7d9d961SMatt Spinler     using HostStateChangeFunc = std::function<void(bool)>;
81a7d9d961SMatt Spinler 
82a7d9d961SMatt Spinler     /**
83a7d9d961SMatt Spinler      * @brief Register a callback function that will get
84a7d9d961SMatt Spinler      *        called on all host on/off transitions.
85a7d9d961SMatt Spinler      *
86a7d9d961SMatt Spinler      * The void(bool) function will get passed the new
87a7d9d961SMatt Spinler      * value of the host state.
88a7d9d961SMatt Spinler      *
89a7d9d961SMatt Spinler      * @param[in] name - The subscription name
90a7d9d961SMatt Spinler      * @param[in] func - The function to run
91a7d9d961SMatt Spinler      */
subscribeToHostStateChange(const std::string & name,HostStateChangeFunc func)92a7d9d961SMatt Spinler     void subscribeToHostStateChange(const std::string& name,
93a7d9d961SMatt Spinler                                     HostStateChangeFunc func)
94a7d9d961SMatt Spinler     {
95a7d9d961SMatt Spinler         _hostChangeCallbacks[name] = func;
96a7d9d961SMatt Spinler     }
97a7d9d961SMatt Spinler 
98a7d9d961SMatt Spinler     /**
99a7d9d961SMatt Spinler      * @brief Unsubscribe from host state changes.
100a7d9d961SMatt Spinler      *
101a7d9d961SMatt Spinler      * @param[in] name - The subscription name
102a7d9d961SMatt Spinler      */
unsubscribeFromHostStateChange(const std::string & name)103a7d9d961SMatt Spinler     void unsubscribeFromHostStateChange(const std::string& name)
104a7d9d961SMatt Spinler     {
105a7d9d961SMatt Spinler         _hostChangeCallbacks.erase(name);
106a7d9d961SMatt Spinler     }
107a7d9d961SMatt Spinler 
1085b423651SMatt Spinler     using FRUPresentFunc =
1095b423651SMatt Spinler         std::function<void(const std::string& /* locationCode */)>;
1105b423651SMatt Spinler 
1115b423651SMatt Spinler     /**
1125b423651SMatt Spinler      * @brief Register a callback function that will get
1135b423651SMatt Spinler      *        called when certain FRUs become present.
1145b423651SMatt Spinler      *
1155b423651SMatt Spinler      * The void(std::string) function will get passed the
1165b423651SMatt Spinler      * location code of the FRU.
1175b423651SMatt Spinler      *
1185b423651SMatt Spinler      * @param[in] name - The subscription name
1195b423651SMatt Spinler      * @param[in] func - The function to run
1205b423651SMatt Spinler      */
subscribeToFruPresent(const std::string & name,FRUPresentFunc func)1215b423651SMatt Spinler     void subscribeToFruPresent(const std::string& name, FRUPresentFunc func)
1225b423651SMatt Spinler     {
1235b423651SMatt Spinler         _fruPresentCallbacks[name] = std::move(func);
1245b423651SMatt Spinler     }
1255b423651SMatt Spinler 
126cad9c2bdSMatt Spinler     /**
127cad9c2bdSMatt Spinler      * @brief Returns the BMC firmware version
128cad9c2bdSMatt Spinler      *
129cad9c2bdSMatt Spinler      * @return std::string - The BMC version
130cad9c2bdSMatt Spinler      */
getBMCFWVersion() const131cad9c2bdSMatt Spinler     virtual std::string getBMCFWVersion() const
132cad9c2bdSMatt Spinler     {
133cad9c2bdSMatt Spinler         return _bmcFWVersion;
134cad9c2bdSMatt Spinler     }
135cad9c2bdSMatt Spinler 
136cad9c2bdSMatt Spinler     /**
137cad9c2bdSMatt Spinler      * @brief Returns the server firmware version
138cad9c2bdSMatt Spinler      *
139cad9c2bdSMatt Spinler      * @return std::string - The server firmware version
140cad9c2bdSMatt Spinler      */
getServerFWVersion() const141cad9c2bdSMatt Spinler     virtual std::string getServerFWVersion() const
142cad9c2bdSMatt Spinler     {
143cad9c2bdSMatt Spinler         return _serverFWVersion;
144cad9c2bdSMatt Spinler     }
145cad9c2bdSMatt Spinler 
1464dcd3f46SMatt Spinler     /**
147677381b8SMatt Spinler      * @brief Returns the BMC FW version ID
148677381b8SMatt Spinler      *
149677381b8SMatt Spinler      * @return std::string - The BMC FW version ID
150677381b8SMatt Spinler      */
getBMCFWVersionID() const151677381b8SMatt Spinler     virtual std::string getBMCFWVersionID() const
152677381b8SMatt Spinler     {
153677381b8SMatt Spinler         return _bmcFWVersionID;
154677381b8SMatt Spinler     }
155677381b8SMatt Spinler 
156677381b8SMatt Spinler     /**
1574dcd3f46SMatt Spinler      * @brief Returns the process name given its PID.
1584dcd3f46SMatt Spinler      *
1594dcd3f46SMatt Spinler      * @param[in] pid - The PID value as a string
1604dcd3f46SMatt Spinler      *
1614dcd3f46SMatt Spinler      * @return std::optional<std::string> - The name, or std::nullopt
1624dcd3f46SMatt Spinler      */
getProcessName(const std::string & pid) const1634dcd3f46SMatt Spinler     std::optional<std::string> getProcessName(const std::string& pid) const
1644dcd3f46SMatt Spinler     {
1654dcd3f46SMatt Spinler         namespace fs = std::filesystem;
1664dcd3f46SMatt Spinler 
1674dcd3f46SMatt Spinler         fs::path path{"/proc"};
1684dcd3f46SMatt Spinler         path /= fs::path{pid} / "exe";
1694dcd3f46SMatt Spinler 
1704dcd3f46SMatt Spinler         if (fs::exists(path))
1714dcd3f46SMatt Spinler         {
1724dcd3f46SMatt Spinler             return fs::read_symlink(path);
1734dcd3f46SMatt Spinler         }
1744dcd3f46SMatt Spinler 
1754dcd3f46SMatt Spinler         return std::nullopt;
1764dcd3f46SMatt Spinler     }
1774dcd3f46SMatt Spinler 
1789cf3cfdaSMatt Spinler     /**
1799ac0d9b8SGeorge Liu      * @brief Returns the time the system was running.
1809ac0d9b8SGeorge Liu      *
1819ac0d9b8SGeorge Liu      * @return std::optional<uint64_t> - The System uptime or std::nullopt
1829ac0d9b8SGeorge Liu      */
getUptimeInSeconds() const1839ac0d9b8SGeorge Liu     std::optional<uint64_t> getUptimeInSeconds() const
1849ac0d9b8SGeorge Liu     {
1859ac0d9b8SGeorge Liu         std::ifstream versionFile{"/proc/uptime"};
1869ac0d9b8SGeorge Liu         std::string line{};
1879ac0d9b8SGeorge Liu 
1889ac0d9b8SGeorge Liu         std::getline(versionFile, line);
1899ac0d9b8SGeorge Liu         auto pos = line.find(" ");
1909ac0d9b8SGeorge Liu         if (pos == std::string::npos)
1919ac0d9b8SGeorge Liu         {
1929ac0d9b8SGeorge Liu             return std::nullopt;
1939ac0d9b8SGeorge Liu         }
1949ac0d9b8SGeorge Liu 
1959ac0d9b8SGeorge Liu         uint64_t seconds = atol(line.substr(0, pos).c_str());
1969ac0d9b8SGeorge Liu         if (seconds == 0)
1979ac0d9b8SGeorge Liu         {
1989ac0d9b8SGeorge Liu             return std::nullopt;
1999ac0d9b8SGeorge Liu         }
2009ac0d9b8SGeorge Liu 
2019ac0d9b8SGeorge Liu         return seconds;
2029ac0d9b8SGeorge Liu     }
2039ac0d9b8SGeorge Liu 
2049ac0d9b8SGeorge Liu     /**
2059ac0d9b8SGeorge Liu      * @brief Returns the time the system was running.
2069ac0d9b8SGeorge Liu      *
2079ac0d9b8SGeorge Liu      * @param[in] seconds - The number of seconds the system has been running
2089ac0d9b8SGeorge Liu      *
2099ac0d9b8SGeorge Liu      * @return std::string - days/hours/minutes/seconds
2109ac0d9b8SGeorge Liu      */
getBMCUptime(uint64_t seconds) const2119ac0d9b8SGeorge Liu     std::string getBMCUptime(uint64_t seconds) const
2129ac0d9b8SGeorge Liu     {
2139ac0d9b8SGeorge Liu         time_t t(seconds);
2149ac0d9b8SGeorge Liu         tm* p = gmtime(&t);
2159ac0d9b8SGeorge Liu 
216075c7923SPatrick Williams         std::string uptime =
217075c7923SPatrick Williams             std::to_string(p->tm_year - 70) + "y " +
218075c7923SPatrick Williams             std::to_string(p->tm_yday) + "d " + std::to_string(p->tm_hour) +
219075c7923SPatrick Williams             "h " + std::to_string(p->tm_min) + "m " +
2209ac0d9b8SGeorge Liu             std::to_string(p->tm_sec) + "s";
2219ac0d9b8SGeorge Liu 
2229ac0d9b8SGeorge Liu         return uptime;
2239ac0d9b8SGeorge Liu     }
2249ac0d9b8SGeorge Liu 
2259ac0d9b8SGeorge Liu     /**
2269ac0d9b8SGeorge Liu      * @brief Returns the system load average over the past 1 minute, 5 minutes
2279ac0d9b8SGeorge Liu      *        and 15 minutes.
2289ac0d9b8SGeorge Liu      *
2299ac0d9b8SGeorge Liu      * @return std::string - The system load average
2309ac0d9b8SGeorge Liu      */
getBMCLoadAvg() const2319ac0d9b8SGeorge Liu     std::string getBMCLoadAvg() const
2329ac0d9b8SGeorge Liu     {
2339ac0d9b8SGeorge Liu         std::string loadavg{};
2349ac0d9b8SGeorge Liu 
2359ac0d9b8SGeorge Liu         std::ifstream loadavgFile{"/proc/loadavg"};
2369ac0d9b8SGeorge Liu         std::string line;
2379ac0d9b8SGeorge Liu         std::getline(loadavgFile, line);
2389ac0d9b8SGeorge Liu 
2399ac0d9b8SGeorge Liu         size_t count = 3;
2409ac0d9b8SGeorge Liu         for (size_t i = 0; i < count; i++)
2419ac0d9b8SGeorge Liu         {
2429ac0d9b8SGeorge Liu             auto pos = line.find(" ");
2439ac0d9b8SGeorge Liu             if (pos == std::string::npos)
2449ac0d9b8SGeorge Liu             {
2459ac0d9b8SGeorge Liu                 return {};
2469ac0d9b8SGeorge Liu             }
2479ac0d9b8SGeorge Liu 
2489ac0d9b8SGeorge Liu             if (i != count - 1)
2499ac0d9b8SGeorge Liu             {
2509ac0d9b8SGeorge Liu                 loadavg.append(line.substr(0, pos + 1));
2519ac0d9b8SGeorge Liu             }
2529ac0d9b8SGeorge Liu             else
2539ac0d9b8SGeorge Liu             {
2549ac0d9b8SGeorge Liu                 loadavg.append(line.substr(0, pos));
2559ac0d9b8SGeorge Liu             }
2569ac0d9b8SGeorge Liu 
2579ac0d9b8SGeorge Liu             line = line.substr(pos + 1);
2589ac0d9b8SGeorge Liu         }
2599ac0d9b8SGeorge Liu 
2609ac0d9b8SGeorge Liu         return loadavg;
2619ac0d9b8SGeorge Liu     }
2629ac0d9b8SGeorge Liu 
2639ac0d9b8SGeorge Liu     /**
2649cf3cfdaSMatt Spinler      * @brief Returns the 'send event logs to host' setting.
2659cf3cfdaSMatt Spinler      *
2669cf3cfdaSMatt Spinler      * @return bool - If sending PELs to the host is enabled.
2679cf3cfdaSMatt Spinler      */
getHostPELEnablement() const2689cf3cfdaSMatt Spinler     virtual bool getHostPELEnablement() const
2699cf3cfdaSMatt Spinler     {
2709cf3cfdaSMatt Spinler         return _sendPELsToHost;
2719cf3cfdaSMatt Spinler     }
2729cf3cfdaSMatt Spinler 
2734aa23a1fSMatt Spinler     /**
2744aa23a1fSMatt Spinler      * @brief Returns the BMC state
2754aa23a1fSMatt Spinler      *
2764aa23a1fSMatt Spinler      * @return std::string - The BMC state property value
2774aa23a1fSMatt Spinler      */
getBMCState() const2784aa23a1fSMatt Spinler     virtual std::string getBMCState() const
2794aa23a1fSMatt Spinler     {
2804aa23a1fSMatt Spinler         return _bmcState;
2814aa23a1fSMatt Spinler     }
2824aa23a1fSMatt Spinler 
2834aa23a1fSMatt Spinler     /**
2844aa23a1fSMatt Spinler      * @brief Returns the Chassis state
2854aa23a1fSMatt Spinler      *
2864aa23a1fSMatt Spinler      * @return std::string - The chassis state property value
2874aa23a1fSMatt Spinler      */
getChassisState() const2884aa23a1fSMatt Spinler     virtual std::string getChassisState() const
2894aa23a1fSMatt Spinler     {
2904aa23a1fSMatt Spinler         return _chassisState;
2914aa23a1fSMatt Spinler     }
2924aa23a1fSMatt Spinler 
2934aa23a1fSMatt Spinler     /**
2944aa23a1fSMatt Spinler      * @brief Returns the chassis requested power
2954aa23a1fSMatt Spinler      *        transition value.
2964aa23a1fSMatt Spinler      *
2974aa23a1fSMatt Spinler      * @return std::string - The chassis transition property
2984aa23a1fSMatt Spinler      */
getChassisTransition() const2994aa23a1fSMatt Spinler     virtual std::string getChassisTransition() const
3004aa23a1fSMatt Spinler     {
3014aa23a1fSMatt Spinler         return _chassisTransition;
3024aa23a1fSMatt Spinler     }
3034aa23a1fSMatt Spinler 
3044aa23a1fSMatt Spinler     /**
3054aa23a1fSMatt Spinler      * @brief Returns the Host state
3064aa23a1fSMatt Spinler      *
3074aa23a1fSMatt Spinler      * @return std::string - The Host state property value
3084aa23a1fSMatt Spinler      */
getHostState() const3094aa23a1fSMatt Spinler     virtual std::string getHostState() const
3104aa23a1fSMatt Spinler     {
3114aa23a1fSMatt Spinler         return _hostState;
3124aa23a1fSMatt Spinler     }
3134aa23a1fSMatt Spinler 
314b3d488fdSMatt Spinler     /**
3152c36fddcSSumit Kumar      * @brief Returns the Boot state
3162c36fddcSSumit Kumar      *
3172c36fddcSSumit Kumar      * @return std::string - The Boot state property value
3182c36fddcSSumit Kumar      */
getBootState() const3192c36fddcSSumit Kumar     virtual std::string getBootState() const
3202c36fddcSSumit Kumar     {
3212c36fddcSSumit Kumar         return _bootState;
3222c36fddcSSumit Kumar     }
3232c36fddcSSumit Kumar 
3242c36fddcSSumit Kumar     /**
325b3d488fdSMatt Spinler      * @brief Returns the motherboard CCIN
326b3d488fdSMatt Spinler      *
327b3d488fdSMatt Spinler      * @return std::string The motherboard CCIN
328b3d488fdSMatt Spinler      */
32981b4dcabSVijay Lobo     virtual std::string getMotherboardCCIN() const = 0;
330b3d488fdSMatt Spinler 
33160c4e797SMatt Spinler     /**
332e32b7e76SBen Tyner      * @brief Returns the system IM
333e32b7e76SBen Tyner      *
334e32b7e76SBen Tyner      * @return std::string The system IM
335e32b7e76SBen Tyner      */
336e32b7e76SBen Tyner     virtual std::vector<uint8_t> getSystemIMKeyword() const = 0;
337e32b7e76SBen Tyner 
338e32b7e76SBen Tyner     /**
33960c4e797SMatt Spinler      * @brief Get the fields from the inventory necessary for doing
34060c4e797SMatt Spinler      *        a callout on an inventory path.
34160c4e797SMatt Spinler      *
34260c4e797SMatt Spinler      * @param[in] inventoryPath - The item to get the data for
34360c4e797SMatt Spinler      * @param[out] fruPartNumber - Filled in with the VINI/FN keyword
34460c4e797SMatt Spinler      * @param[out] ccin - Filled in with the VINI/CC keyword
34560c4e797SMatt Spinler      * @param[out] serialNumber - Filled in with the VINI/SN keyword
34660c4e797SMatt Spinler      */
347075c7923SPatrick Williams     virtual void getHWCalloutFields(
348075c7923SPatrick Williams         const std::string& inventoryPath, std::string& fruPartNumber,
349075c7923SPatrick Williams         std::string& ccin, std::string& serialNumber) const = 0;
35060c4e797SMatt Spinler 
3510398458dSMatt Spinler     /**
3529b90e2a2SMatt Spinler      * @brief Get the location code for an inventory item.
3539b90e2a2SMatt Spinler      *
3549b90e2a2SMatt Spinler      * @param[in] inventoryPath - The item to get the data for
3559b90e2a2SMatt Spinler      *
3569b90e2a2SMatt Spinler      * @return std::string - The location code
3579b90e2a2SMatt Spinler      */
358*25291157SPatrick Williams     virtual std::string getLocationCode(
359*25291157SPatrick Williams         const std::string& inventoryPath) const = 0;
3609b90e2a2SMatt Spinler 
3619b90e2a2SMatt Spinler     /**
3626ea4d5f7SMatt Spinler      * @brief Get the list of system type names the system is called.
3630398458dSMatt Spinler      *
3646ea4d5f7SMatt Spinler      * @return std::vector<std::string> - The list of names
3650398458dSMatt Spinler      */
3661ab6696fSMatt Spinler     virtual std::vector<std::string> getSystemNames() const = 0;
3670398458dSMatt Spinler 
3685fb24c11SMatt Spinler     /**
3695fb24c11SMatt Spinler      * @brief Fills in the placeholder 'Ufcs' in the passed in location
3705fb24c11SMatt Spinler      *        code with the machine feature code and serial number, which
3715fb24c11SMatt Spinler      *        is needed to create a valid location code.
3725fb24c11SMatt Spinler      *
3735fb24c11SMatt Spinler      * @param[in] locationCode - Location code value starting with Ufcs-, and
3745fb24c11SMatt Spinler      *                           if that isn't present it will be added first.
3755fb24c11SMatt Spinler      *
3765fb24c11SMatt Spinler      * @param[in] node - The node number the location is on.
3775fb24c11SMatt Spinler      *
3785fb24c11SMatt Spinler      * @return std::string - The expanded location code
3795fb24c11SMatt Spinler      */
3805fb24c11SMatt Spinler     virtual std::string expandLocationCode(const std::string& locationCode,
3815fb24c11SMatt Spinler                                            uint16_t node) const = 0;
3825fb24c11SMatt Spinler 
3835fb24c11SMatt Spinler     /**
384bad056beSMatt Spinler      * @brief Returns the inventory paths for the FRU that the location
3855fb24c11SMatt Spinler      *        code represents.
3865fb24c11SMatt Spinler      *
3872f9225a4SMatt Spinler      * @param[in] locationCode - If an expanded location code, then the
3882f9225a4SMatt Spinler      *                           full location code.
3892f9225a4SMatt Spinler      *                           If not expanded, a location code value
3902f9225a4SMatt Spinler      *                           starting with Ufcs-, and if that isn't
3912f9225a4SMatt Spinler      *                           present it will be added first.
3925fb24c11SMatt Spinler      *
3932f9225a4SMatt Spinler      * @param[in] node - The node number the location is on.  Ignored if the
3942f9225a4SMatt Spinler      *                   expanded location code is passed in.
3952f9225a4SMatt Spinler      *
3962f9225a4SMatt Spinler      * @param[in] expanded - If the location code already has the relevent
3972f9225a4SMatt Spinler      *                       VPD fields embedded in it.
3985fb24c11SMatt Spinler      *
399bad056beSMatt Spinler      * @return std::vector<std::string> - The inventory D-Bus objects
4005fb24c11SMatt Spinler      */
401*25291157SPatrick Williams     virtual std::vector<std::string> getInventoryFromLocCode(
402*25291157SPatrick Williams         const std::string& LocationCode, uint16_t node,
4032f9225a4SMatt Spinler         bool expanded) const = 0;
4045fb24c11SMatt Spinler 
40534a904cfSMatt Spinler     /**
40634a904cfSMatt Spinler      * @brief Sets the Asserted property on the LED group passed in.
40734a904cfSMatt Spinler      *
40834a904cfSMatt Spinler      * @param[in] ledGroup - The LED group D-Bus path
40934a904cfSMatt Spinler      * @param[in] value - The value to set it to
41034a904cfSMatt Spinler      */
41134a904cfSMatt Spinler     virtual void assertLEDGroup(const std::string& ledGroup,
41234a904cfSMatt Spinler                                 bool value) const = 0;
41334a904cfSMatt Spinler 
414993168deSMatt Spinler     /**
415993168deSMatt Spinler      * @brief Sets the Functional property on the OperationalStatus
416993168deSMatt Spinler      *        interface on a D-Bus object.
417993168deSMatt Spinler      *
418993168deSMatt Spinler      * @param[in] objectPath - The D-Bus object path
419993168deSMatt Spinler      * @param[in] functional - The value
420993168deSMatt Spinler      */
421993168deSMatt Spinler     virtual void setFunctional(const std::string& objectPath,
422993168deSMatt Spinler                                bool functional) const = 0;
423993168deSMatt Spinler 
4243b8ed7f2SSumit Kumar     /**
42576198a2eSSumit Kumar      * @brief Sets the critical association on the D-Bus object.
42676198a2eSSumit Kumar      *
42776198a2eSSumit Kumar      * @param[in] objectPath - The D-Bus object path
42876198a2eSSumit Kumar      */
429*25291157SPatrick Williams     virtual void setCriticalAssociation(
430*25291157SPatrick Williams         const std::string& objectPath) const = 0;
43176198a2eSSumit Kumar 
43276198a2eSSumit Kumar     /**
4333b8ed7f2SSumit Kumar      * @brief Returns the manufacturing QuiesceOnError property
4343b8ed7f2SSumit Kumar      *
4353b8ed7f2SSumit Kumar      * @return bool - Manufacturing QuiesceOnError property
4363b8ed7f2SSumit Kumar      */
4373b8ed7f2SSumit Kumar     virtual bool getQuiesceOnError() const = 0;
4383b8ed7f2SSumit Kumar 
4390d92b528SMatt Spinler     /**
4400d92b528SMatt Spinler      * @brief Split location code into base and connector segments
4410d92b528SMatt Spinler      *
4420d92b528SMatt Spinler      * A location code that ends in '-Tx', where 'x' is a number,
4430d92b528SMatt Spinler      * represents a connector, such as a USB cable connector.
4440d92b528SMatt Spinler      *
4450d92b528SMatt Spinler      * This function splits the passed in location code into a
4460d92b528SMatt Spinler      * base and connector segment.  e.g.:
4470d92b528SMatt Spinler      *   P0-T1 -> ['P0', '-T1']
4480d92b528SMatt Spinler      *   P0 -> ['P0', '']
4490d92b528SMatt Spinler      *
4500d92b528SMatt Spinler      * @param[in] locationCode - location code to split
4510d92b528SMatt Spinler      * @return pair<string, string> - The base and connector segments
4520d92b528SMatt Spinler      */
453*25291157SPatrick Williams     static std::pair<std::string, std::string> extractConnectorFromLocCode(
454*25291157SPatrick Williams         const std::string& locationCode);
4550d92b528SMatt Spinler 
456ff35be3eSDeepa Karthikeyan #ifdef PEL_ENABLE_PHAL
4579d43a727SSumit Kumar     /**
458ecaa2fceSJayanth Othayoth      * @brief Create guard record
459ecaa2fceSJayanth Othayoth      *
460ecaa2fceSJayanth Othayoth      *  @param[in] binPath: phal devtree binary path used as key
461ff35be3eSDeepa Karthikeyan      *  @param[in] eGardType: Guard type enum value
462ff35be3eSDeepa Karthikeyan      *  @param[in] plid: Pel ID
463ecaa2fceSJayanth Othayoth      */
464ecaa2fceSJayanth Othayoth     virtual void createGuardRecord(const std::vector<uint8_t>& binPath,
465ff35be3eSDeepa Karthikeyan                                    GardType eGardType, uint32_t plid) const = 0;
466ff35be3eSDeepa Karthikeyan #endif
467ecaa2fceSJayanth Othayoth 
4683e274432SSumit Kumar     /**
4693e274432SSumit Kumar      * @brief Create Progress SRC property on the boot progress
4703e274432SSumit Kumar      *        interface on a D-Bus object.
4713e274432SSumit Kumar      *
4723e274432SSumit Kumar      * @param[in] priSRC - Primary SRC value (e.g. BD8D1001)
4733e274432SSumit Kumar      * @param[in] srcStruct - Full SRC base structure
4743e274432SSumit Kumar      */
475*25291157SPatrick Williams     virtual void createProgressSRC(
476*25291157SPatrick Williams         const uint64_t& priSRC,
4773e274432SSumit Kumar         const std::vector<uint8_t>& srcStruct) const = 0;
4783e274432SSumit Kumar 
479027bf285SSumit Kumar     /**
480027bf285SSumit Kumar      * @brief Get the list of unresolved OpenBMC event log ids that have an
481027bf285SSumit Kumar      * associated hardware isolation entry.
482027bf285SSumit Kumar      *
483027bf285SSumit Kumar      * @return std::vector<uint32_t> - The list of log ids
484027bf285SSumit Kumar      */
485027bf285SSumit Kumar     virtual std::vector<uint32_t> getLogIDWithHwIsolation() const = 0;
486027bf285SSumit Kumar 
487875b6c7bSVijay Lobo     /**
488875b6c7bSVijay Lobo      * @brief Returns the latest raw progress SRC from the State.Boot.Raw
489875b6c7bSVijay Lobo      *        D-Bus interface.
490875b6c7bSVijay Lobo      *
491875b6c7bSVijay Lobo      * @return std::vector<uint8_t> - The progress SRC bytes
492875b6c7bSVijay Lobo      */
493875b6c7bSVijay Lobo     virtual std::vector<uint8_t> getRawProgressSRC() const = 0;
494875b6c7bSVijay Lobo 
495d8ae618aSArya K Padman     /**
496d8ae618aSArya K Padman      * @brief Returns the FRUs DI property value hosted on the VINI iterface for
497d8ae618aSArya K Padman      * the given location code.
498d8ae618aSArya K Padman      *
499d8ae618aSArya K Padman      * @param[in] locationCode - The location code of the FRU
500d8ae618aSArya K Padman      *
501d8ae618aSArya K Padman      * @return std::optional<std::vector<uint8_t>> -  The FRUs DI or
502d8ae618aSArya K Padman      * std::nullopt
503d8ae618aSArya K Padman      */
504*25291157SPatrick Williams     virtual std::optional<std::vector<uint8_t>> getDIProperty(
505*25291157SPatrick Williams         const std::string& locationCode) const = 0;
506d8ae618aSArya K Padman 
507d8ae618aSArya K Padman     /**
508d8ae618aSArya K Padman      * @brief Wrpper API to call pHAL API 'getFRUType()' and check whether the
509d8ae618aSArya K Padman      * given location code is DIMM or not
510d8ae618aSArya K Padman      *
511d8ae618aSArya K Padman      * @param[in] locCode - The location code of the FRU
512d8ae618aSArya K Padman      *
513ced8ed77SArya K Padman      * @return - true, if the given location code is DIMM
514ced8ed77SArya K Padman      *         - false, if the given location code is not DIMM or if it fails to
515ced8ed77SArya K Padman      *         determine the FRU type.
516d8ae618aSArya K Padman      */
517ced8ed77SArya K Padman     bool isDIMM(const std::string& locCode);
518d8ae618aSArya K Padman 
519d8ae618aSArya K Padman     /**
520d8ae618aSArya K Padman      * @brief Check whether the given location code present in the cache
521d8ae618aSArya K Padman      * memory
522d8ae618aSArya K Padman      *
523d8ae618aSArya K Padman      * @param[in] locCode - The location code of the FRU
524d8ae618aSArya K Padman      *
525d8ae618aSArya K Padman      * @return true, if the given location code present in cache and is a DIMM
526d8ae618aSArya K Padman      *         false, if the given location code present in cache, but a non
527d8ae618aSArya K Padman      *         DIMM FRU
528d8ae618aSArya K Padman      *         std::nullopt, if the given location code is not present in the
529d8ae618aSArya K Padman      *         cache.
530d8ae618aSArya K Padman      */
531d8ae618aSArya K Padman     std::optional<bool> isDIMMLocCode(const std::string& locCode) const;
532d8ae618aSArya K Padman 
533d8ae618aSArya K Padman     /**
534d8ae618aSArya K Padman      * @brief add the given location code to the cache memory
535d8ae618aSArya K Padman      *
536d8ae618aSArya K Padman      * @param[in] locCode - The location code of the FRU
537d8ae618aSArya K Padman      * @param[in] isFRUDIMM - true indicates the FRU is a DIMM
538d8ae618aSArya K Padman      *                        false indicates the FRU is a non DIMM
539d8ae618aSArya K Padman      *
540d8ae618aSArya K Padman      */
541d8ae618aSArya K Padman     void addDIMMLocCode(const std::string& locCode, bool isFRUDIMM);
542d8ae618aSArya K Padman 
543d763db35Sharsh-agarwal1     /**
544d763db35Sharsh-agarwal1      * @brief Finds all D-Bus Associated paths that contain any of the
545d763db35Sharsh-agarwal1      *        interfaces passed in, by using GetAssociatedSubTreePaths.
546d763db35Sharsh-agarwal1      *
547d763db35Sharsh-agarwal1      * @param[in] associatedPath - The D-Bus object path
548d763db35Sharsh-agarwal1      * @param[in] subtree - The subtree path for which the result should be
549d763db35Sharsh-agarwal1      *                      fetched
550d763db35Sharsh-agarwal1      * @param[in] depth - The maximum subtree depth for which results should be
551d763db35Sharsh-agarwal1      *                    fetched
552d763db35Sharsh-agarwal1      * @param[in] interfaces - The desired interfaces
553d763db35Sharsh-agarwal1      *
554d763db35Sharsh-agarwal1      * @return The D-Bus paths.
555d763db35Sharsh-agarwal1      */
556d763db35Sharsh-agarwal1     virtual DBusPathList getAssociatedPaths(
557d763db35Sharsh-agarwal1         const DBusPath& associatedPath, const DBusPath& subtree, int32_t depth,
558d763db35Sharsh-agarwal1         const DBusInterfaceList& interfaces) const = 0;
559d763db35Sharsh-agarwal1 
56019e89ce4SMatt Spinler   protected:
56119e89ce4SMatt Spinler     /**
562a7d9d961SMatt Spinler      * @brief Sets the host on/off state and runs any
563a7d9d961SMatt Spinler      *        callback functions (if there was a change).
564a7d9d961SMatt Spinler      */
setHostUp(bool hostUp)5654aa23a1fSMatt Spinler     void setHostUp(bool hostUp)
566a7d9d961SMatt Spinler     {
5674aa23a1fSMatt Spinler         if (_hostUp != hostUp)
568a7d9d961SMatt Spinler         {
5694aa23a1fSMatt Spinler             _hostUp = hostUp;
570a7d9d961SMatt Spinler 
571a7d9d961SMatt Spinler             for (auto& [name, func] : _hostChangeCallbacks)
572a7d9d961SMatt Spinler             {
573a7d9d961SMatt Spinler                 try
574a7d9d961SMatt Spinler                 {
575a7d9d961SMatt Spinler                     func(_hostUp);
576a7d9d961SMatt Spinler                 }
57766491c61SPatrick Williams                 catch (const std::exception& e)
578a7d9d961SMatt Spinler                 {
579a167a7d9SMatt Spinler                     lg2::error(
580a167a7d9SMatt Spinler                         "A host state change callback threw an exception");
581a7d9d961SMatt Spinler                 }
582a7d9d961SMatt Spinler             }
583a7d9d961SMatt Spinler         }
584a7d9d961SMatt Spinler     }
585a7d9d961SMatt Spinler 
586a7d9d961SMatt Spinler     /**
5875b423651SMatt Spinler      * @brief Runs the callback functions registered when
5885b423651SMatt Spinler      *        FRUs become present.
5895b423651SMatt Spinler      */
setFruPresent(const std::string & locationCode)5905b423651SMatt Spinler     void setFruPresent(const std::string& locationCode)
5915b423651SMatt Spinler     {
5925b423651SMatt Spinler         for (const auto& [_, func] : _fruPresentCallbacks)
5935b423651SMatt Spinler         {
5945b423651SMatt Spinler             try
5955b423651SMatt Spinler             {
5965b423651SMatt Spinler                 func(locationCode);
5975b423651SMatt Spinler             }
5985b423651SMatt Spinler             catch (const std::exception& e)
5995b423651SMatt Spinler             {
600a167a7d9SMatt Spinler                 lg2::error("A FRU present callback threw an exception");
6015b423651SMatt Spinler             }
6025b423651SMatt Spinler         }
6035b423651SMatt Spinler     }
6045b423651SMatt Spinler 
6055b423651SMatt Spinler     /**
606cce1411aSMatt Spinler      * @brief The hardware management console status.  Always kept
607cce1411aSMatt Spinler      *        up to date.
608cce1411aSMatt Spinler      */
609cce1411aSMatt Spinler     bool _hmcManaged = false;
610cce1411aSMatt Spinler 
611cce1411aSMatt Spinler     /**
612a7d9d961SMatt Spinler      * @brief The host up status.  Always kept up to date.
613a7d9d961SMatt Spinler      */
614a7d9d961SMatt Spinler     bool _hostUp = false;
615a7d9d961SMatt Spinler 
616a7d9d961SMatt Spinler     /**
617a7d9d961SMatt Spinler      * @brief The map of host state change subscriber
618a7d9d961SMatt Spinler      *        names to callback functions.
619a7d9d961SMatt Spinler      */
620a7d9d961SMatt Spinler     std::map<std::string, HostStateChangeFunc> _hostChangeCallbacks;
621cad9c2bdSMatt Spinler 
622cad9c2bdSMatt Spinler     /**
6235b423651SMatt Spinler      * @brief The map of FRU present subscriber
6245b423651SMatt Spinler      *        names to callback functions.
6255b423651SMatt Spinler      */
6265b423651SMatt Spinler     std::map<std::string, FRUPresentFunc> _fruPresentCallbacks;
6275b423651SMatt Spinler 
6285b423651SMatt Spinler     /**
629cad9c2bdSMatt Spinler      * @brief The BMC firmware version string
630cad9c2bdSMatt Spinler      */
631cad9c2bdSMatt Spinler     std::string _bmcFWVersion;
632cad9c2bdSMatt Spinler 
633cad9c2bdSMatt Spinler     /**
634cad9c2bdSMatt Spinler      * @brief The server firmware version string
635cad9c2bdSMatt Spinler      */
636cad9c2bdSMatt Spinler     std::string _serverFWVersion;
637677381b8SMatt Spinler 
638677381b8SMatt Spinler     /**
639677381b8SMatt Spinler      * @brief The BMC firmware version ID string
640677381b8SMatt Spinler      */
641677381b8SMatt Spinler     std::string _bmcFWVersionID;
6429cf3cfdaSMatt Spinler 
6439cf3cfdaSMatt Spinler     /**
6449cf3cfdaSMatt Spinler      * @brief If sending PELs is enabled.
6459cf3cfdaSMatt Spinler      *
6469cf3cfdaSMatt Spinler      * This is usually set to false in manufacturing test.
6479cf3cfdaSMatt Spinler      */
6489cf3cfdaSMatt Spinler     bool _sendPELsToHost = true;
6494aa23a1fSMatt Spinler 
6504aa23a1fSMatt Spinler     /**
6514aa23a1fSMatt Spinler      * @brief The BMC state property
6524aa23a1fSMatt Spinler      */
6534aa23a1fSMatt Spinler     std::string _bmcState;
6544aa23a1fSMatt Spinler 
6554aa23a1fSMatt Spinler     /**
6564aa23a1fSMatt Spinler      * @brief The Chassis current power state property
6574aa23a1fSMatt Spinler      */
6584aa23a1fSMatt Spinler     std::string _chassisState;
6594aa23a1fSMatt Spinler 
6604aa23a1fSMatt Spinler     /**
6614aa23a1fSMatt Spinler      * @brief The Chassis requested power transition property
6624aa23a1fSMatt Spinler      */
6634aa23a1fSMatt Spinler     std::string _chassisTransition;
6644aa23a1fSMatt Spinler 
6654aa23a1fSMatt Spinler     /**
6664aa23a1fSMatt Spinler      * @brief The host state property
6674aa23a1fSMatt Spinler      */
6684aa23a1fSMatt Spinler     std::string _hostState;
6692c36fddcSSumit Kumar 
6702c36fddcSSumit Kumar     /**
6712c36fddcSSumit Kumar      * @brief The boot state property
6722c36fddcSSumit Kumar      */
6732c36fddcSSumit Kumar     std::string _bootState;
674d8ae618aSArya K Padman 
675d8ae618aSArya K Padman     /**
676d8ae618aSArya K Padman      * @brief A cache storage for location code and its FRU Type
677d8ae618aSArya K Padman      *  - The key 'std::string' represents the locationCode of the FRU
678d8ae618aSArya K Padman      *  - The bool value - true indicates the FRU is a DIMM
679d8ae618aSArya K Padman      *                     false indicates the FRU is a non DIMM.
680d8ae618aSArya K Padman      */
681d8ae618aSArya K Padman     std::unordered_map<std::string, bool> _locationCache;
682c8705e2bSMatt Spinler };
683c8705e2bSMatt Spinler 
684c8705e2bSMatt Spinler /**
685c8705e2bSMatt Spinler  * @class DataInterface
686c8705e2bSMatt Spinler  *
687c8705e2bSMatt Spinler  * Concrete implementation of DataInterfaceBase.
688c8705e2bSMatt Spinler  */
689c8705e2bSMatt Spinler class DataInterface : public DataInterfaceBase
690c8705e2bSMatt Spinler {
691c8705e2bSMatt Spinler   public:
692c8705e2bSMatt Spinler     DataInterface() = delete;
693c8705e2bSMatt Spinler     ~DataInterface() = default;
694c8705e2bSMatt Spinler     DataInterface(const DataInterface&) = default;
695c8705e2bSMatt Spinler     DataInterface& operator=(const DataInterface&) = default;
696c8705e2bSMatt Spinler     DataInterface(DataInterface&&) = default;
697c8705e2bSMatt Spinler     DataInterface& operator=(DataInterface&&) = default;
698c8705e2bSMatt Spinler 
699c8705e2bSMatt Spinler     /**
700c8705e2bSMatt Spinler      * @brief Constructor
701c8705e2bSMatt Spinler      *
702c8705e2bSMatt Spinler      * @param[in] bus - The sdbusplus bus object
703c8705e2bSMatt Spinler      */
70445e83521SPatrick Williams     explicit DataInterface(sdbusplus::bus_t& bus);
705c8705e2bSMatt Spinler 
706b3f5186eSMatt Spinler     /**
707c8705e2bSMatt Spinler      * @brief Finds the D-Bus service name that hosts the
708c8705e2bSMatt Spinler      *        passed in path and interface.
709c8705e2bSMatt Spinler      *
710c8705e2bSMatt Spinler      * @param[in] objectPath - The D-Bus object path
711c8705e2bSMatt Spinler      * @param[in] interface - The D-Bus interface
712c8705e2bSMatt Spinler      */
713c8705e2bSMatt Spinler     DBusService getService(const std::string& objectPath,
714b3f5186eSMatt Spinler                            const std::string& interface) const;
7159cf3cfdaSMatt Spinler 
716c8705e2bSMatt Spinler     /**
717c8705e2bSMatt Spinler      * @brief Wrapper for the 'GetAll' properties method call
718c8705e2bSMatt Spinler      *
719c8705e2bSMatt Spinler      * @param[in] service - The D-Bus service to call it on
720c8705e2bSMatt Spinler      * @param[in] objectPath - The D-Bus object path
721c8705e2bSMatt Spinler      * @param[in] interface - The interface to get the props on
722c8705e2bSMatt Spinler      *
723c8705e2bSMatt Spinler      * @return DBusPropertyMap - The property results
724c8705e2bSMatt Spinler      */
725c8705e2bSMatt Spinler     DBusPropertyMap getAllProperties(const std::string& service,
726c8705e2bSMatt Spinler                                      const std::string& objectPath,
7272a28c936SMatt Spinler                                      const std::string& interface) const;
728c8705e2bSMatt Spinler     /**
729a7d9d961SMatt Spinler      * @brief Wrapper for the 'Get' properties method call
730a7d9d961SMatt Spinler      *
731a7d9d961SMatt Spinler      * @param[in] service - The D-Bus service to call it on
732a7d9d961SMatt Spinler      * @param[in] objectPath - The D-Bus object path
733a7d9d961SMatt Spinler      * @param[in] interface - The interface to get the property on
734a7d9d961SMatt Spinler      * @param[in] property - The property name
735a7d9d961SMatt Spinler      * @param[out] value - Filled in with the property value.
736a7d9d961SMatt Spinler      */
737a7d9d961SMatt Spinler     void getProperty(const std::string& service, const std::string& objectPath,
738a7d9d961SMatt Spinler                      const std::string& interface, const std::string& property,
7392a28c936SMatt Spinler                      DBusValue& value) const;
74081b4dcabSVijay Lobo     /**
74181b4dcabSVijay Lobo      * @brief Returns the machine Type/Model
74281b4dcabSVijay Lobo      *
74381b4dcabSVijay Lobo      * @return string - The machine Type/Model string
74481b4dcabSVijay Lobo      */
74581b4dcabSVijay Lobo     std::string getMachineTypeModel() const override;
74681b4dcabSVijay Lobo 
74781b4dcabSVijay Lobo     /**
74881b4dcabSVijay Lobo      * @brief Returns the machine serial number
74981b4dcabSVijay Lobo      *
75081b4dcabSVijay Lobo      * @return string - The machine serial number
75181b4dcabSVijay Lobo      */
75281b4dcabSVijay Lobo     std::string getMachineSerialNumber() const override;
75381b4dcabSVijay Lobo 
75481b4dcabSVijay Lobo     /**
75581b4dcabSVijay Lobo      * @brief Returns the motherboard CCIN
75681b4dcabSVijay Lobo      *
75781b4dcabSVijay Lobo      * @return std::string The motherboard CCIN
75881b4dcabSVijay Lobo      */
75981b4dcabSVijay Lobo     std::string getMotherboardCCIN() const override;
7602a28c936SMatt Spinler 
76160c4e797SMatt Spinler     /**
762e32b7e76SBen Tyner      * @brief Returns the system IM
763e32b7e76SBen Tyner      *
764e32b7e76SBen Tyner      * @return std::vector The system IM keyword in 4 byte vector
765e32b7e76SBen Tyner      */
766e32b7e76SBen Tyner     std::vector<uint8_t> getSystemIMKeyword() const override;
767e32b7e76SBen Tyner 
768e32b7e76SBen Tyner     /**
76960c4e797SMatt Spinler      * @brief Get the fields from the inventory necessary for doing
77060c4e797SMatt Spinler      *        a callout on an inventory path.
77160c4e797SMatt Spinler      *
77260c4e797SMatt Spinler      * @param[in] inventoryPath - The item to get the data for
77360c4e797SMatt Spinler      * @param[out] fruPartNumber - Filled in with the VINI/FN keyword
77460c4e797SMatt Spinler      * @param[out] ccin - Filled in with the VINI/CC keyword
77560c4e797SMatt Spinler      * @param[out] serialNumber - Filled in with the VINI/SN keyword
77660c4e797SMatt Spinler      */
77760c4e797SMatt Spinler     void getHWCalloutFields(const std::string& inventoryPath,
77860c4e797SMatt Spinler                             std::string& fruPartNumber, std::string& ccin,
77960c4e797SMatt Spinler                             std::string& serialNumber) const override;
78060c4e797SMatt Spinler 
7819b90e2a2SMatt Spinler     /**
7829b90e2a2SMatt Spinler      * @brief Get the location code for an inventory item.
7839b90e2a2SMatt Spinler      *
7849b90e2a2SMatt Spinler      * Throws an exception if the inventory item doesn't have the
7859b90e2a2SMatt Spinler      * location code interface.
7869b90e2a2SMatt Spinler      *
7879b90e2a2SMatt Spinler      * @param[in] inventoryPath - The item to get the data for
7889b90e2a2SMatt Spinler      *
7899b90e2a2SMatt Spinler      * @return std::string - The location code
7909b90e2a2SMatt Spinler      */
791*25291157SPatrick Williams     std::string getLocationCode(
792*25291157SPatrick Williams         const std::string& inventoryPath) const override;
7939b90e2a2SMatt Spinler 
7945fb24c11SMatt Spinler     /**
7951ab6696fSMatt Spinler      * @brief Get the list of system type names the system is called.
7961ab6696fSMatt Spinler      *
7971ab6696fSMatt Spinler      * @return std::vector<std::string> - The list of names
7981ab6696fSMatt Spinler      */
7991ab6696fSMatt Spinler     std::vector<std::string> getSystemNames() const override;
8001ab6696fSMatt Spinler 
8011ab6696fSMatt Spinler     /**
8025fb24c11SMatt Spinler      * @brief Fills in the placeholder 'Ufcs' in the passed in location
8035fb24c11SMatt Spinler      *        code with the machine feature code and serial number, which
8045fb24c11SMatt Spinler      *        is needed to create a valid location code.
8055fb24c11SMatt Spinler      *
8065fb24c11SMatt Spinler      * @param[in] locationCode - Location code value starting with Ufcs-, and
8075fb24c11SMatt Spinler      *                           if that isn't present it will be added first.
8085fb24c11SMatt Spinler      *
8095fb24c11SMatt Spinler      * @param[in] node - The node number the location is one.
8105fb24c11SMatt Spinler      *
8115fb24c11SMatt Spinler      * @return std::string - The expanded location code
8125fb24c11SMatt Spinler      */
8135fb24c11SMatt Spinler     std::string expandLocationCode(const std::string& locationCode,
8145fb24c11SMatt Spinler                                    uint16_t node) const override;
8155fb24c11SMatt Spinler 
8165fb24c11SMatt Spinler     /**
817bad056beSMatt Spinler      * @brief Returns the inventory paths for the FRU that the location
8185fb24c11SMatt Spinler      *        code represents.
8195fb24c11SMatt Spinler      *
8202f9225a4SMatt Spinler      * @param[in] locationCode - If an expanded location code, then the
8212f9225a4SMatt Spinler      *                           full location code.
8222f9225a4SMatt Spinler      *                           If not expanded, a location code value
8232f9225a4SMatt Spinler      *                           starting with Ufcs-, and if that isn't
8242f9225a4SMatt Spinler      *                           present it will be added first.
8255fb24c11SMatt Spinler      *
8262f9225a4SMatt Spinler      * @param[in] node - The node number the location is on.  Ignored if the
8272f9225a4SMatt Spinler      *                   expanded location code is passed in.
8282f9225a4SMatt Spinler      *
8292f9225a4SMatt Spinler      * @param[in] expanded - If the location code already has the relevent
8302f9225a4SMatt Spinler      *                       VPD fields embedded in it.
8315fb24c11SMatt Spinler      *
832bad056beSMatt Spinler      * @return std::vector<std::string> - The inventory D-Bus objects
8335fb24c11SMatt Spinler      */
834*25291157SPatrick Williams     std::vector<std::string> getInventoryFromLocCode(
835*25291157SPatrick Williams         const std::string& locationCode, uint16_t node,
8362f9225a4SMatt Spinler         bool expanded) const override;
8375fb24c11SMatt Spinler 
83834a904cfSMatt Spinler     /**
83934a904cfSMatt Spinler      * @brief Sets the Asserted property on the LED group passed in.
84034a904cfSMatt Spinler      *
84134a904cfSMatt Spinler      * @param[in] ledGroup - The LED group D-Bus path
84234a904cfSMatt Spinler      * @param[in] value - The value to set it to
84334a904cfSMatt Spinler      */
84434a904cfSMatt Spinler     void assertLEDGroup(const std::string& ledGroup, bool value) const override;
84534a904cfSMatt Spinler 
846993168deSMatt Spinler     /**
847993168deSMatt Spinler      * @brief Sets the Functional property on the OperationalStatus
848993168deSMatt Spinler      *        interface on a D-Bus object.
849993168deSMatt Spinler      *
850993168deSMatt Spinler      * @param[in] objectPath - The D-Bus object path
851993168deSMatt Spinler      * @param[in] functional - The value
852993168deSMatt Spinler      */
853993168deSMatt Spinler     void setFunctional(const std::string& objectPath,
854993168deSMatt Spinler                        bool functional) const override;
855993168deSMatt Spinler 
8563b8ed7f2SSumit Kumar     /**
85776198a2eSSumit Kumar      * @brief Sets the critical association on the D-Bus object.
85876198a2eSSumit Kumar      *
85976198a2eSSumit Kumar      * @param[in] objectPath - The D-Bus object path
86076198a2eSSumit Kumar      */
86176198a2eSSumit Kumar     void setCriticalAssociation(const std::string& objectPath) const override;
86276198a2eSSumit Kumar 
86376198a2eSSumit Kumar     /**
8643b8ed7f2SSumit Kumar      * @brief Returns the manufacturing QuiesceOnError property
8653b8ed7f2SSumit Kumar      *
8663b8ed7f2SSumit Kumar      * @return bool - Manufacturing QuiesceOnError property
8673b8ed7f2SSumit Kumar      */
8683b8ed7f2SSumit Kumar     bool getQuiesceOnError() const override;
8693b8ed7f2SSumit Kumar 
870ff35be3eSDeepa Karthikeyan #ifdef PEL_ENABLE_PHAL
8719d43a727SSumit Kumar     /**
872ecaa2fceSJayanth Othayoth      * @brief Create guard record
873ecaa2fceSJayanth Othayoth      *
874ecaa2fceSJayanth Othayoth      *  @param[in] binPath: phal devtree binary path used as key
875ff35be3eSDeepa Karthikeyan      *  @param[in] eGardType: Guard type enum value
876ff35be3eSDeepa Karthikeyan      *   @param[in] plid: pel id to be associated to the guard record
877ecaa2fceSJayanth Othayoth      */
878ecaa2fceSJayanth Othayoth     void createGuardRecord(const std::vector<uint8_t>& binPath,
879ff35be3eSDeepa Karthikeyan                            GardType eGardType, uint32_t plid) const override;
880ff35be3eSDeepa Karthikeyan #endif
881ecaa2fceSJayanth Othayoth 
8823e274432SSumit Kumar     /**
8833e274432SSumit Kumar      * @brief Create Progress SRC property on the boot progress
8843e274432SSumit Kumar      *        interface on a D-Bus object.
8853e274432SSumit Kumar      *
8863e274432SSumit Kumar      * @param[in] priSRC - Primary SRC value
8873e274432SSumit Kumar      * @param[in] srcStruct - Full SRC base structure
8883e274432SSumit Kumar      */
889*25291157SPatrick Williams     void createProgressSRC(
890*25291157SPatrick Williams         const uint64_t& priSRC,
8913e274432SSumit Kumar         const std::vector<uint8_t>& srcStruct) const override;
8923e274432SSumit Kumar 
893027bf285SSumit Kumar     /**
894027bf285SSumit Kumar      * @brief Get the list of unresolved OpenBMC event log ids that have an
895027bf285SSumit Kumar      * associated hardware isolation entry.
896027bf285SSumit Kumar      *
897027bf285SSumit Kumar      * @return std::vector<uint32_t> - The list of log ids
898027bf285SSumit Kumar      */
899027bf285SSumit Kumar     std::vector<uint32_t> getLogIDWithHwIsolation() const override;
900027bf285SSumit Kumar 
901875b6c7bSVijay Lobo     /**
902875b6c7bSVijay Lobo      * @brief Returns the latest raw progress SRC from the State.Boot.Raw
903875b6c7bSVijay Lobo      *        D-Bus interface.
904875b6c7bSVijay Lobo      *
905875b6c7bSVijay Lobo      * @return std::vector<uint8_t>: The progress SRC bytes
906875b6c7bSVijay Lobo      */
907875b6c7bSVijay Lobo     std::vector<uint8_t> getRawProgressSRC() const override;
908875b6c7bSVijay Lobo 
909d8ae618aSArya K Padman     /**
910d8ae618aSArya K Padman      * @brief Returns the FRUs DI property value hosted on the VINI iterface for
911d8ae618aSArya K Padman      * the given location code.
912d8ae618aSArya K Padman      *
913d8ae618aSArya K Padman      * @param[in] locationCode - The location code of the FRU
914d8ae618aSArya K Padman      *
915d8ae618aSArya K Padman      * @return std::optional<std::vector<uint8_t>> -  The FRUs DI or
916d8ae618aSArya K Padman      * std::nullopt
917d8ae618aSArya K Padman      */
918*25291157SPatrick Williams     std::optional<std::vector<uint8_t>> getDIProperty(
919*25291157SPatrick Williams         const std::string& locationCode) const override;
920d8ae618aSArya K Padman 
921d763db35Sharsh-agarwal1     /**
922d763db35Sharsh-agarwal1      * @brief Finds all D-Bus Associated paths that contain any of the
923d763db35Sharsh-agarwal1      *        interfaces passed in, by using GetAssociatedSubTreePaths.
924d763db35Sharsh-agarwal1      *
925d763db35Sharsh-agarwal1      * @param[in] associatedPath - The D-Bus object path
926d763db35Sharsh-agarwal1      * @param[in] subtree - The subtree path for which the result should be
927d763db35Sharsh-agarwal1      *                      fetched
928d763db35Sharsh-agarwal1      * @param[in] depth - The maximum subtree depth for which results should be
929d763db35Sharsh-agarwal1      *                    fetched
930d763db35Sharsh-agarwal1      * @param[in] interfaces - The desired interfaces
931d763db35Sharsh-agarwal1      *
932d763db35Sharsh-agarwal1      * @return The D-Bus paths.
933d763db35Sharsh-agarwal1      */
934d763db35Sharsh-agarwal1     DBusPathList getAssociatedPaths(
935d763db35Sharsh-agarwal1         const DBusPath& associatedPath, const DBusPath& subtree, int32_t depth,
936d763db35Sharsh-agarwal1         const DBusInterfaceList& interfaces) const override;
937d763db35Sharsh-agarwal1 
9382a28c936SMatt Spinler   private:
9392a28c936SMatt Spinler     /**
9402a28c936SMatt Spinler      * @brief Reads the BMC firmware version string and puts it into
9412a28c936SMatt Spinler      *        _bmcFWVersion.
9422a28c936SMatt Spinler      */
9432a28c936SMatt Spinler     void readBMCFWVersion();
944a7d9d961SMatt Spinler 
945a7d9d961SMatt Spinler     /**
9462a28c936SMatt Spinler      * @brief Reads the server firmware version string and puts it into
9472a28c936SMatt Spinler      *        _serverFWVersion.
948c8705e2bSMatt Spinler      */
9492a28c936SMatt Spinler     void readServerFWVersion();
950c8705e2bSMatt Spinler 
951c8705e2bSMatt Spinler     /**
9522a28c936SMatt Spinler      * @brief Reads the BMC firmware version ID and puts it into
9532a28c936SMatt Spinler      *        _bmcFWVersionID.
954a7d9d961SMatt Spinler      */
9552a28c936SMatt Spinler     void readBMCFWVersionID();
956a7d9d961SMatt Spinler 
957a7d9d961SMatt Spinler     /**
958b3d488fdSMatt Spinler      * @brief Finds all D-Bus paths that contain any of the interfaces
959b3d488fdSMatt Spinler      *        passed in, by using GetSubTreePaths.
960b3d488fdSMatt Spinler      *
961b3d488fdSMatt Spinler      * @param[in] interfaces - The desired interfaces
962b3d488fdSMatt Spinler      *
963b3d488fdSMatt Spinler      * @return The D-Bus paths.
964b3d488fdSMatt Spinler      */
965b3d488fdSMatt Spinler     DBusPathList getPaths(const DBusInterfaceList& interfaces) const;
966b3d488fdSMatt Spinler 
967b3d488fdSMatt Spinler     /**
968b3d488fdSMatt Spinler      * @brief The interfacesAdded callback used on the inventory to
969b3d488fdSMatt Spinler      *        find the D-Bus object that has the motherboard interface.
970b3d488fdSMatt Spinler      *        When the motherboard is found, it then adds a PropertyWatcher
971b3d488fdSMatt Spinler      *        for the motherboard CCIN.
972b3d488fdSMatt Spinler      */
97345e83521SPatrick Williams     void motherboardIfaceAdded(sdbusplus::message_t& msg);
974b3d488fdSMatt Spinler 
975b3d488fdSMatt Spinler     /**
9765b423651SMatt Spinler      * @brief Start watching for the hotpluggable FRUs to become
9775b423651SMatt Spinler      *        present.
9785b423651SMatt Spinler      */
9795b423651SMatt Spinler     void startFruPlugWatch();
9805b423651SMatt Spinler 
9815b423651SMatt Spinler     /**
9825b423651SMatt Spinler      * @brief Create a D-Bus match object for the Present property
9835b423651SMatt Spinler      *        to change on the path passed in.
9845b423651SMatt Spinler      * @param[in] path - The path to watch.
9855b423651SMatt Spinler      */
9865b423651SMatt Spinler     void addHotplugWatch(const std::string& path);
9875b423651SMatt Spinler 
9885b423651SMatt Spinler     /**
9895b423651SMatt Spinler      * @brief Callback when an inventory interface was added.
9905b423651SMatt Spinler      *
9915b423651SMatt Spinler      * Only does something if it's one of the hotpluggable FRUs,
9925b423651SMatt Spinler      * in which case it will treat it as a hotplug if the
9935b423651SMatt Spinler      * Present property is true.
9945b423651SMatt Spinler      *
9955b423651SMatt Spinler      * @param[in] msg - The InterfacesAdded signal contents.
9965b423651SMatt Spinler      */
9975b423651SMatt Spinler     void inventoryIfaceAdded(sdbusplus::message_t& msg);
9985b423651SMatt Spinler 
9995b423651SMatt Spinler     /**
10005b423651SMatt Spinler      * @brief Callback when the Present property changes.
10015b423651SMatt Spinler      *
10025b423651SMatt Spinler      * If present, will run the registered callbacks.
10035b423651SMatt Spinler      *
10045b423651SMatt Spinler      * @param[in] msg - The PropertiesChanged signal contents.
10055b423651SMatt Spinler      */
10065b423651SMatt Spinler     void presenceChanged(sdbusplus::message_t& msg);
10075b423651SMatt Spinler 
10085b423651SMatt Spinler     /**
10095b423651SMatt Spinler      * @brief If the Present property is in the properties map
10105b423651SMatt Spinler      *        passed in and it is true, notify the subscribers.
10115b423651SMatt Spinler      *
10125b423651SMatt Spinler      * @param[in] path - The object path of the inventory item.
10135b423651SMatt Spinler      * @param[in] properties - The properties map
10145b423651SMatt Spinler      */
10155b423651SMatt Spinler     void notifyPresenceSubsribers(const std::string& path,
10165b423651SMatt Spinler                                   const DBusPropertyMap& properties);
10175b423651SMatt Spinler 
10185b423651SMatt Spinler     /**
10190e4d72edSMatt Spinler      * @brief Adds the Ufcs- prefix to the location code passed in
10200e4d72edSMatt Spinler      *        if necessary.
10215fb24c11SMatt Spinler      *
10220e4d72edSMatt Spinler      * Needed because the location codes that come back from the
10235fb24c11SMatt Spinler      * message registry and device callout JSON don't have it.
10245fb24c11SMatt Spinler      *
10255fb24c11SMatt Spinler      * @param[in] - The location code without a prefix, like P1-C1
10265fb24c11SMatt Spinler      *
10275fb24c11SMatt Spinler      * @return std::string - The location code with the prefix
10285fb24c11SMatt Spinler      */
10295fb24c11SMatt Spinler     static std::string addLocationCodePrefix(const std::string& locationCode);
10305fb24c11SMatt Spinler 
1031afba316cSArya K Padman     /**
1032afba316cSArya K Padman      * @brief A helper API to check whether the PHAL device tree is exists,
1033afba316cSArya K Padman      *        ensuring the PHAL init API can be invoked.
1034afba316cSArya K Padman      *
1035afba316cSArya K Padman      * @return true if the PHAL device tree is exists, otherwise false
1036afba316cSArya K Padman      */
1037afba316cSArya K Padman     bool isPHALDevTreeExist() const;
1038afba316cSArya K Padman 
10390b758fb0SArya K Padman #ifdef PEL_ENABLE_PHAL
1040afba316cSArya K Padman     /**
1041afba316cSArya K Padman      * @brief A helper API to init PHAL libraries
1042afba316cSArya K Padman      *
1043afba316cSArya K Padman      * @return None
1044afba316cSArya K Padman      */
1045afba316cSArya K Padman     void initPHAL();
10460b758fb0SArya K Padman #endif // PEL_ENABLE_PHAL
1047afba316cSArya K Padman 
1048afba316cSArya K Padman     /**
1049afba316cSArya K Padman      * @brief A helper API to subscribe to systemd signals
1050afba316cSArya K Padman      *
1051afba316cSArya K Padman      * @return None
1052afba316cSArya K Padman      */
1053afba316cSArya K Padman     void subscribeToSystemdSignals();
1054afba316cSArya K Padman 
1055afba316cSArya K Padman     /**
1056afba316cSArya K Padman      * @brief A helper API to unsubscribe to systemd signals
1057afba316cSArya K Padman      *
1058afba316cSArya K Padman      * @return None
1059afba316cSArya K Padman      */
1060afba316cSArya K Padman     void unsubscribeFromSystemdSignals();
1061afba316cSArya K Padman 
10625fb24c11SMatt Spinler     /**
10632a28c936SMatt Spinler      * @brief The D-Bus property or interface watchers that have callbacks
10642a28c936SMatt Spinler      *        registered that will set members in this class when
10652a28c936SMatt Spinler      *        they change.
1066c8705e2bSMatt Spinler      */
10672a28c936SMatt Spinler     std::vector<std::unique_ptr<DBusWatcher>> _properties;
1068a7d9d961SMatt Spinler 
10695b423651SMatt Spinler     std::unique_ptr<sdbusplus::bus::match_t> _invIaMatch;
10705b423651SMatt Spinler 
10715b423651SMatt Spinler     /**
10725b423651SMatt Spinler      * @brief The matches for watching for hotplugs.
10735b423651SMatt Spinler      *
10745b423651SMatt Spinler      * A map so we can check that we never get duplicates.
10755b423651SMatt Spinler      */
10765b423651SMatt Spinler     std::map<std::string, std::unique_ptr<sdbusplus::bus::match_t>>
10775b423651SMatt Spinler         _invPresentMatches;
10785b423651SMatt Spinler 
1079a7d9d961SMatt Spinler     /**
1080c8705e2bSMatt Spinler      * @brief The sdbusplus bus object for making D-Bus calls.
1081c8705e2bSMatt Spinler      */
108245e83521SPatrick Williams     sdbusplus::bus_t& _bus;
1083afba316cSArya K Padman 
1084afba316cSArya K Padman     /**
1085afba316cSArya K Padman      * @brief Watcher to check "openpower-update-bios-attr-table" service
1086afba316cSArya K Padman      *        is "done" to init PHAL libraires
1087afba316cSArya K Padman      */
1088afba316cSArya K Padman     std::unique_ptr<sdbusplus::bus::match_t> _systemdMatch;
1089afba316cSArya K Padman 
1090afba316cSArya K Padman     /**
1091afba316cSArya K Padman      * @brief A slot object for async dbus call
1092afba316cSArya K Padman      */
1093afba316cSArya K Padman     sdbusplus::slot_t _systemdSlot;
1094c8705e2bSMatt Spinler };
1095c8705e2bSMatt Spinler 
1096c8705e2bSMatt Spinler } // namespace pels
1097c8705e2bSMatt Spinler } // namespace openpower
1098