xref: /openbmc/openpower-occ-control/occ_manager.hpp (revision c488bac124fbbcb0dbe83e48922c3087a5aaa7bd)
12180b2daSVishwanatha Subbanna #pragma once
22180b2daSVishwanatha Subbanna 
32180b2daSVishwanatha Subbanna #include "occ_pass_through.hpp"
4307d80b3SVishwanatha Subbanna #include "occ_status.hpp"
5815f9f55STom Joseph #ifdef PLDM
6815f9f55STom Joseph #include "pldm.hpp"
7cbad219eSEddie James 
8720a3841SChris Cain #ifdef PHAL_SUPPORT
9cbad219eSEddie James #include <libphal.H>
10815f9f55STom Joseph #endif
11720a3841SChris Cain #endif
1240501a23SChris Cain #include "powercap.hpp"
13f3b7514eSGeorge Liu #include "utils.hpp"
1478e86012SChris Cain #ifdef POWER10
1578e86012SChris Cain #include "powermode.hpp"
1678e86012SChris Cain #endif
172180b2daSVishwanatha Subbanna 
1894df8c90SGunnar Mills #include <sdbusplus/bus.hpp>
19a8857c50SChris Cain #include <sdeventplus/event.hpp>
20a8857c50SChris Cain #include <sdeventplus/utility/timer.hpp>
21b5ca1015SGeorge Liu 
22b5ca1015SGeorge Liu #include <cstring>
23b5ca1015SGeorge Liu #include <functional>
2494df8c90SGunnar Mills #include <vector>
2594df8c90SGunnar Mills 
262180b2daSVishwanatha Subbanna namespace sdbusRule = sdbusplus::bus::match::rules;
272180b2daSVishwanatha Subbanna namespace open_power
282180b2daSVishwanatha Subbanna {
292180b2daSVishwanatha Subbanna namespace occ
302180b2daSVishwanatha Subbanna {
312180b2daSVishwanatha Subbanna 
32bb895cb8SChicago Duan #ifdef READ_OCC_SENSORS
33bb895cb8SChicago Duan enum occFruType
34bb895cb8SChicago Duan {
35bb895cb8SChicago Duan     processorCore = 0,
36bb895cb8SChicago Duan     internalMemCtlr = 1,
37bb895cb8SChicago Duan     dimm = 2,
38bb895cb8SChicago Duan     memCtrlAndDimm = 3,
39bb895cb8SChicago Duan     VRMVdd = 6,
40bb895cb8SChicago Duan     PMIC = 7,
41ace67d85SMatt Spinler     memCtlrExSensor = 8,
42ace67d85SMatt Spinler     processorIoRing = 9
43bb895cb8SChicago Duan };
44bb895cb8SChicago Duan #endif
45bb895cb8SChicago Duan 
46a8857c50SChris Cain /** @brief Default time, in seconds, between OCC poll commands */
4737923464SMatt Spinler #ifndef POWER10
48bb895cb8SChicago Duan constexpr unsigned int defaultPollingInterval = 1;
4937923464SMatt Spinler #else
5037923464SMatt Spinler constexpr unsigned int defaultPollingInterval = 5;
5137923464SMatt Spinler #endif
52a8857c50SChris Cain 
5317257673SChris Cain constexpr auto AMBIENT_PATH =
5417257673SChris Cain     "/xyz/openbmc_project/sensors/temperature/Ambient_Virtual_Temp";
5517257673SChris Cain constexpr auto AMBIENT_INTERFACE = "xyz.openbmc_project.Sensor.Value";
5617257673SChris Cain constexpr auto AMBIENT_PROP = "Value";
5717257673SChris Cain constexpr auto ALTITUDE_PATH = "/xyz/openbmc_project/sensors/altitude/Altitude";
5817257673SChris Cain constexpr auto ALTITUDE_INTERFACE = "xyz.openbmc_project.Sensor.Value";
5917257673SChris Cain constexpr auto ALTITUDE_PROP = "Value";
6017257673SChris Cain 
61d2b044f9SSheldon Bailey constexpr auto EXTN_LABEL_PWRM_MEMORY_POWER = "5057524d";
62d2b044f9SSheldon Bailey constexpr auto EXTN_LABEL_PWRP_PROCESSOR_POWER = "50575250";
63d2b044f9SSheldon Bailey 
642180b2daSVishwanatha Subbanna /** @class Manager
652180b2daSVishwanatha Subbanna  *  @brief Builds and manages OCC objects
662180b2daSVishwanatha Subbanna  */
672180b2daSVishwanatha Subbanna struct Manager
682180b2daSVishwanatha Subbanna {
692180b2daSVishwanatha Subbanna   public:
702180b2daSVishwanatha Subbanna     Manager() = delete;
712180b2daSVishwanatha Subbanna     Manager(const Manager&) = delete;
722180b2daSVishwanatha Subbanna     Manager& operator=(const Manager&) = delete;
73636577f4SEdward A. James     Manager(Manager&&) = delete;
74636577f4SEdward A. James     Manager& operator=(Manager&&) = delete;
752180b2daSVishwanatha Subbanna     ~Manager() = default;
762180b2daSVishwanatha Subbanna 
77307d80b3SVishwanatha Subbanna     /** @brief Adds OCC pass-through and status objects on the bus
78307d80b3SVishwanatha Subbanna      *         when corresponding CPU inventory is created.
79ee4d83dfSVishwanatha Subbanna      *
80ee4d83dfSVishwanatha Subbanna      *  @param[in] event - Unique ptr reference to sd_event
812180b2daSVishwanatha Subbanna      */
Manageropen_power::occ::Manager82f3a4a69fSGeorge Liu     explicit Manager(EventPtr& event) :
83f3b7514eSGeorge Liu         event(event), pollInterval(defaultPollingInterval),
84a8857c50SChris Cain         sdpEvent(sdeventplus::Event::get_default()),
85a8857c50SChris Cain         _pollTimer(
86a8857c50SChris Cain             std::make_unique<
87a8857c50SChris Cain                 sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>(
8817257673SChris Cain                 sdpEvent, std::bind(&Manager::pollerTimerExpired, this))),
8917257673SChris Cain         ambientPropChanged(
9017257673SChris Cain             utils::getBus(),
9117257673SChris Cain             sdbusRule::member("PropertiesChanged") +
9217257673SChris Cain                 sdbusRule::path(AMBIENT_PATH) +
9317257673SChris Cain                 sdbusRule::argN(0, AMBIENT_INTERFACE) +
9417257673SChris Cain                 sdbusRule::interface("org.freedesktop.DBus.Properties"),
9517257673SChris Cain             std::bind(&Manager::ambientCallback, this, std::placeholders::_1))
96d267cec2SMatt Spinler #ifdef POWER10
97d267cec2SMatt Spinler         ,
98d267cec2SMatt Spinler         discoverTimer(
99d267cec2SMatt Spinler             std::make_unique<
100d267cec2SMatt Spinler                 sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>(
101a7b74dc3SChris Cain                 sdpEvent, std::bind(&Manager::findAndCreateObjects, this))),
102a7b74dc3SChris Cain         waitForAllOccsTimer(
103a7b74dc3SChris Cain             std::make_unique<
104a7b74dc3SChris Cain                 sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>(
105a7b74dc3SChris Cain                 sdpEvent, std::bind(&Manager::occsNotAllRunning, this)))
106755af102SChris Cain #ifdef PLDM
107755af102SChris Cain         ,
108c33171bbSChris Cain         throttlePldmTraceTimer(
109755af102SChris Cain             std::make_unique<
110755af102SChris Cain                 sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>(
111c33171bbSChris Cain                 sdpEvent, std::bind(&Manager::throttlePldmTraceExpired, this)))
112d267cec2SMatt Spinler #endif
113755af102SChris Cain #endif // POWER10
1142180b2daSVishwanatha Subbanna     {
1150ab90ca7SLei YU #ifdef I2C_OCC
1160ab90ca7SLei YU         // I2C OCC status objects are initialized directly
1170ab90ca7SLei YU         initStatusObjects();
1180ab90ca7SLei YU #else
119dfc7ec73SVishwanatha Subbanna         findAndCreateObjects();
1200ab90ca7SLei YU #endif
12117257673SChris Cain         readAltitude();
1225f031f3cSDeepak Kodihalli     }
1232180b2daSVishwanatha Subbanna 
124720a3841SChris Cain     void createPldmHandle();
125720a3841SChris Cain 
126a8857c50SChris Cain     /** @brief Return the number of bound OCCs */
getNumOCCsopen_power::occ::Manager127636577f4SEdward A. James     inline auto getNumOCCs() const
128636577f4SEdward A. James     {
129636577f4SEdward A. James         return activeCount;
130636577f4SEdward A. James     }
131636577f4SEdward A. James 
132cbad219eSEddie James #ifdef PLDM
133cbad219eSEddie James     /** @brief Called by a Device to report that the SBE timed out
134cbad219eSEddie James      *         and appropriate action should be taken
135cbad219eSEddie James      *
136cbad219eSEddie James      * @param[in] instance - the OCC instance id
137cbad219eSEddie James      */
138cbad219eSEddie James     void sbeTimeout(unsigned int instance);
139cbad219eSEddie James #endif
140cbad219eSEddie James 
14117257673SChris Cain     /** @brief Return the latest ambient and altitude readings
14217257673SChris Cain      *
14317257673SChris Cain      *  @param[out] ambientValid - true if ambientTemp is valid
14417257673SChris Cain      *  @param[out] ambient - ambient temperature in degrees C
14517257673SChris Cain      *  @param[out] altitude - altitude in meters
14617257673SChris Cain      */
14717257673SChris Cain     void getAmbientData(bool& ambientValid, uint8_t& ambientTemp,
14817257673SChris Cain                         uint16_t& altitude) const;
14917257673SChris Cain 
15040501a23SChris Cain     /** @brief Notify pcap object to update bounds */
15140501a23SChris Cain     void updatePcapBounds() const;
15240501a23SChris Cain 
153c8dd4599SSheldon Bailey     /**
154c8dd4599SSheldon Bailey      * @brief Set all sensor values of this OCC to NaN.
155c8dd4599SSheldon Bailey      * @param[in] id - Id of the OCC.
156c8dd4599SSheldon Bailey      * */
157c8dd4599SSheldon Bailey     void setSensorValueToNaN(uint32_t id) const;
158c8dd4599SSheldon Bailey 
159373af757SSheldon Bailey     /** @brief Set all sensor values of this OCC to NaN and non functional.
160373af757SSheldon Bailey      *
161373af757SSheldon Bailey      *  @param[in] id - Id of the OCC.
162373af757SSheldon Bailey      */
163373af757SSheldon Bailey     void setSensorValueToNonFunctional(uint32_t id) const;
164373af757SSheldon Bailey 
165*c488bac1SChris Cain     /** @brief Clear any state flags that need to be reset when the host state
166*c488bac1SChris Cain      * is off */
167*c488bac1SChris Cain     void hostPoweredOff();
168*c488bac1SChris Cain 
1692dc9b1a2SVishwanatha Subbanna   private:
170d267cec2SMatt Spinler     /** @brief Creates the OCC D-Bus objects.
171dfc7ec73SVishwanatha Subbanna      */
172dfc7ec73SVishwanatha Subbanna     void findAndCreateObjects();
173dfc7ec73SVishwanatha Subbanna 
1742180b2daSVishwanatha Subbanna     /** @brief Callback that responds to cpu creation in the inventory -
175ee4d83dfSVishwanatha Subbanna      *         by creating the needed objects.
1762180b2daSVishwanatha Subbanna      *
1772180b2daSVishwanatha Subbanna      *  @param[in] msg - bus message
1782180b2daSVishwanatha Subbanna      *
1792180b2daSVishwanatha Subbanna      *  @returns 0 to indicate success
1802180b2daSVishwanatha Subbanna      */
181af40808fSPatrick Williams     int cpuCreated(sdbusplus::message_t& msg);
1825f031f3cSDeepak Kodihalli 
1835f031f3cSDeepak Kodihalli     /** @brief Create child OCC objects.
1845f031f3cSDeepak Kodihalli      *
1855f031f3cSDeepak Kodihalli      *  @param[in] occ - the occ name, such as occ0.
1865f031f3cSDeepak Kodihalli      */
187dfc7ec73SVishwanatha Subbanna     void createObjects(const std::string& occ);
1882180b2daSVishwanatha Subbanna 
1892dc9b1a2SVishwanatha Subbanna     /** @brief Callback handler invoked by Status object when the OccActive
1902dc9b1a2SVishwanatha Subbanna      *         property is changed. This is needed to make sure that the
1912dc9b1a2SVishwanatha Subbanna      *         error detection is started only after all the OCCs are bound.
1922dc9b1a2SVishwanatha Subbanna      *         Similarly, when one of the OCC gets its OccActive property
1932dc9b1a2SVishwanatha Subbanna      *         un-set, then the OCC error detection needs to be stopped on
1942dc9b1a2SVishwanatha Subbanna      *         all the OCCs
1952dc9b1a2SVishwanatha Subbanna      *
1962dc9b1a2SVishwanatha Subbanna      *  @param[in] status - OccActive status
1972dc9b1a2SVishwanatha Subbanna      */
198373af757SSheldon Bailey     void statusCallBack(instanceID instance, bool status);
1992dc9b1a2SVishwanatha Subbanna 
200f0295f52SChris Cain     /** @brief Set flag that a PM Complex reset is needed (to be initiated
201f0295f52SChris Cain      * later) */
202f0295f52SChris Cain     void resetOccRequest(instanceID instance);
203f0295f52SChris Cain 
204f0295f52SChris Cain     /** @brief Initiate the request to reset the PM Complex (PLDM -> HBRT) */
205f0295f52SChris Cain     void initiateOccRequest(instanceID instance);
206f0295f52SChris Cain 
207dfc7ec73SVishwanatha Subbanna     /** @brief Sends a Heartbeat command to host control command handler */
208dfc7ec73SVishwanatha Subbanna     void sendHeartBeat();
2092dc9b1a2SVishwanatha Subbanna 
210ee4d83dfSVishwanatha Subbanna     /** @brief reference to sd_event wrapped in unique_ptr */
211ee4d83dfSVishwanatha Subbanna     EventPtr& event;
212ee4d83dfSVishwanatha Subbanna 
2132180b2daSVishwanatha Subbanna     /** @brief OCC pass-through objects */
214307d80b3SVishwanatha Subbanna     std::vector<std::unique_ptr<PassThrough>> passThroughObjects;
215307d80b3SVishwanatha Subbanna 
216307d80b3SVishwanatha Subbanna     /** @brief OCC Status objects */
217307d80b3SVishwanatha Subbanna     std::vector<std::unique_ptr<Status>> statusObjects;
2182180b2daSVishwanatha Subbanna 
21940501a23SChris Cain     /** @brief Power cap monitor and occ notification object */
22040501a23SChris Cain     std::unique_ptr<open_power::occ::powercap::PowerCap> pcap;
22140501a23SChris Cain 
22278e86012SChris Cain #ifdef POWER10
22378e86012SChris Cain     /** @brief Power mode monitor and notification object */
22478e86012SChris Cain     std::unique_ptr<open_power::occ::powermode::PowerMode> pmode;
22578e86012SChris Cain #endif
22678e86012SChris Cain 
2272180b2daSVishwanatha Subbanna     /** @brief sbdbusplus match objects */
2282180b2daSVishwanatha Subbanna     std::vector<sdbusplus::bus::match_t> cpuMatches;
2292dc9b1a2SVishwanatha Subbanna 
2302dc9b1a2SVishwanatha Subbanna     /** @brief Number of OCCs that are bound */
2312dc9b1a2SVishwanatha Subbanna     uint8_t activeCount = 0;
2320ab90ca7SLei YU 
233a8857c50SChris Cain     /** @brief Number of seconds between poll commands */
234a8857c50SChris Cain     uint8_t pollInterval;
235a8857c50SChris Cain 
23617257673SChris Cain     /** @brief Ambient temperature of the system in degrees C */
23717257673SChris Cain     uint8_t ambient = 0xFF; // default: not available
23817257673SChris Cain 
23917257673SChris Cain     /** @brief Altitude of the system in meters */
24017257673SChris Cain     uint16_t altitude = 0xFFFF; // default: not available
24117257673SChris Cain 
242a8857c50SChris Cain     /** @brief Poll timer event */
243a8857c50SChris Cain     sdeventplus::Event sdpEvent;
244a8857c50SChris Cain 
245bae4d07eSChris Cain     /** @brief Flags to indicate if waiting for all of the OCC active sensors to
246bae4d07eSChris Cain      * come online */
247bae4d07eSChris Cain     bool waitingForAllOccActiveSensors = false;
248bae4d07eSChris Cain 
249bd551de3SChris Cain     /** @brief Set containing intance numbers of any OCCs that became active
250bd551de3SChris Cain      *         while waiting for status objects to be created */
251bd551de3SChris Cain     std::set<uint8_t> queuedActiveState;
252bd551de3SChris Cain 
253a8857c50SChris Cain     /**
254a8857c50SChris Cain      * @brief The timer to be used once the OCC goes active.  When it expires,
255a8857c50SChris Cain      *        a POLL command will be sent to the OCC and then timer restarted.
256a8857c50SChris Cain      */
257a8857c50SChris Cain     std::unique_ptr<
258a8857c50SChris Cain         sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>
259a8857c50SChris Cain         _pollTimer;
260a8857c50SChris Cain 
26117257673SChris Cain     /** @brief Subscribe to ambient temperature changed events */
26217257673SChris Cain     sdbusplus::bus::match_t ambientPropChanged;
26317257673SChris Cain 
264f0295f52SChris Cain     /** @brief Flag to indicate that a PM complex reset needs to happen */
265f0295f52SChris Cain     bool resetRequired = false;
266f0295f52SChris Cain     /** @brief Instance number of the OCC/processor that triggered the reset */
267f0295f52SChris Cain     uint8_t resetInstance = 255;
268f0295f52SChris Cain     /** @brief Set when a PM complex reset has been issued (to prevent multiple
269f0295f52SChris Cain      * requests) */
270f0295f52SChris Cain     bool resetInProgress = false;
271f0295f52SChris Cain 
2720ab90ca7SLei YU #ifdef I2C_OCC
2730ab90ca7SLei YU     /** @brief Init Status objects for I2C OCC devices
2740ab90ca7SLei YU      *
2750ab90ca7SLei YU      * It iterates in /sys/bus/i2c/devices, finds all occ hwmon devices
2760ab90ca7SLei YU      * and creates status objects.
2770ab90ca7SLei YU      */
278dfc7ec73SVishwanatha Subbanna     void initStatusObjects();
2790ab90ca7SLei YU #endif
280815f9f55STom Joseph 
281815f9f55STom Joseph #ifdef PLDM
282815f9f55STom Joseph     /** @brief Callback handler invoked by the PLDM event handler when state of
283815f9f55STom Joseph      *         the OCC is toggled by the host. The caller passes the instance
284815f9f55STom Joseph      *         of the OCC and state of the OCC.
285815f9f55STom Joseph      *
286815f9f55STom Joseph      *  @param[in] instance - instance of the OCC
287815f9f55STom Joseph      *  @param[in] status - true when the OCC goes active and false when the OCC
288815f9f55STom Joseph      *                      goes inactive
289815f9f55STom Joseph      *
290815f9f55STom Joseph      *  @return true if setting the state of OCC is successful and false if it
291815f9f55STom Joseph      *          fails.
292815f9f55STom Joseph      */
293815f9f55STom Joseph     bool updateOCCActive(instanceID instance, bool status);
294815f9f55STom Joseph 
29531a2f13aSSheldon Bailey     /** @brief Callback handler invoked by the PLDM event handler when mode of
29631a2f13aSSheldon Bailey      *         the OCC SAFE MODE is inacted or cleared.
29731a2f13aSSheldon Bailey      */
29831a2f13aSSheldon Bailey     void updateOccSafeMode(bool safeState);
29931a2f13aSSheldon Bailey 
300cbad219eSEddie James     /** @brief Callback handler invoked by PLDM sensor change when
301cbad219eSEddie James      *         the HRESET succeeds or fails.
302cbad219eSEddie James      *
303cbad219eSEddie James      *  @param[in] instance - the SBE instance id
304cbad219eSEddie James      *  @param[in] success - true if the HRESET succeeded, otherwise false
305cbad219eSEddie James      */
306cbad219eSEddie James     void sbeHRESETResult(instanceID instance, bool success);
307cbad219eSEddie James 
308720a3841SChris Cain #ifdef PHAL_SUPPORT
309cbad219eSEddie James     /** @brief Helper function to check whether an SBE dump should be collected
310cbad219eSEddie James      *         now.
311cbad219eSEddie James      *
312cbad219eSEddie James      *  @param[in] instance - the SBE instance id
313cbad219eSEddie James      *
314cbad219eSEddie James      *  @return true if an SBE dump should be collected and false if not
315cbad219eSEddie James      */
316cbad219eSEddie James     bool sbeCanDump(unsigned int instance);
317cbad219eSEddie James 
318cbad219eSEddie James     /** @brief Helper function to set the SBE state through PDBG/PHAL
319cbad219eSEddie James      *
320cbad219eSEddie James      * @param[in] instance - instance of the SBE
321cbad219eSEddie James      * @param[in] state - the state to which the SBE should be set
322cbad219eSEddie James      *
323cbad219eSEddie James      */
324cbad219eSEddie James     void setSBEState(unsigned int instance, enum sbe_state state);
325cbad219eSEddie James 
326cbad219eSEddie James     /** @brief Helper function to get the SBE instance PDBG processor target
327cbad219eSEddie James      *
328cbad219eSEddie James      * @param[in] instance - the SBE instance id
329cbad219eSEddie James      *
330cbad219eSEddie James      * @return a pointer to the PDBG target
331cbad219eSEddie James      */
332cbad219eSEddie James     struct pdbg_target* getPdbgTarget(unsigned int instance);
333cbad219eSEddie James 
334cbad219eSEddie James     /** @brief Whether pdbg_targets_init has been called */
335cbad219eSEddie James     bool pdbgInitialized = false;
336720a3841SChris Cain #endif
337cbad219eSEddie James 
338815f9f55STom Joseph     std::unique_ptr<pldm::Interface> pldmHandle = nullptr;
339815f9f55STom Joseph #endif
340a8857c50SChris Cain 
341d267cec2SMatt Spinler #ifdef POWER10
342d267cec2SMatt Spinler     /**
343d267cec2SMatt Spinler      * @brief Timer used when discovering OCCs in /dev.
344d267cec2SMatt Spinler      */
345d267cec2SMatt Spinler     std::unique_ptr<
346d267cec2SMatt Spinler         sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>
347d267cec2SMatt Spinler         discoverTimer;
348d267cec2SMatt Spinler 
349d267cec2SMatt Spinler     /**
350d267cec2SMatt Spinler      * @brief Used when discovering /dev/occ objects to know if
351d267cec2SMatt Spinler      *        any were added since the last check.
352d267cec2SMatt Spinler      */
353d267cec2SMatt Spinler     std::vector<int> prevOCCSearch;
354a7b74dc3SChris Cain 
355a7b74dc3SChris Cain     /**
356a7b74dc3SChris Cain      * @brief Timer used when waiting for OCCs to go active.
357a7b74dc3SChris Cain      */
358a7b74dc3SChris Cain     std::unique_ptr<
359a7b74dc3SChris Cain         sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>
360a7b74dc3SChris Cain         waitForAllOccsTimer;
361a7b74dc3SChris Cain 
362755af102SChris Cain #ifdef PLDM
363755af102SChris Cain     /**
364755af102SChris Cain      * @brief Timer used to throttle PLDM traces when there are problems
365755af102SChris Cain      determining the OCC status via pldm. Used to prevent excessive
366755af102SChris Cain      journal traces.
367755af102SChris Cain      */
368755af102SChris Cain     std::unique_ptr<
369755af102SChris Cain         sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>
370c33171bbSChris Cain         throttlePldmTraceTimer;
371c33171bbSChris Cain     /**
372c33171bbSChris Cain      * @brief onPldmTimeoutCreatePel flag will be used to indicate if
373c33171bbSChris Cain      *        a PEL should get created when the throttlePldmTraceTimer expires.
374c33171bbSChris Cain      *        The first time the throttlePldmTraceTimer expires, the traces
375c33171bbSChris Cain      *        will be throttled and then the timer gets restarted. The
376c33171bbSChris Cain      *        next time the timer expires, a PEL will get created.
377c33171bbSChris Cain      */
378c33171bbSChris Cain     bool onPldmTimeoutCreatePel = false;
379755af102SChris Cain 
380755af102SChris Cain     /** @brief Check if all of the OCC Active sensors are available and if not
381755af102SChris Cain      * restart the discoverTimer
382755af102SChris Cain      */
383c33171bbSChris Cain     void throttlePldmTraceExpired();
3844b82f3e3SChris Cain 
3854b82f3e3SChris Cain     /** @brief Create a PEL when the code is not able to obtain the OCC PDRs
386c33171bbSChris Cain      * via PLDM. This is called when the throttlePldmTraceTimer expires.
3874b82f3e3SChris Cain      */
3884b82f3e3SChris Cain     void createPldmSensorPEL();
389755af102SChris Cain #endif
390755af102SChris Cain 
391a7b74dc3SChris Cain     /** @brief Called when code times out waiting for all OCCs to be running or
392a7b74dc3SChris Cain      *         after the app is restarted (Status does not callback into
393a7b74dc3SChris Cain      * Manager).
394a7b74dc3SChris Cain      */
395a7b74dc3SChris Cain     void occsNotAllRunning();
396bae4d07eSChris Cain 
397bae4d07eSChris Cain     /** @brief Check if all of the OCC Active sensors are available and if not
398bae4d07eSChris Cain      * restart the discoverTimer
399bae4d07eSChris Cain      */
400bae4d07eSChris Cain     void checkAllActiveSensors();
401755af102SChris Cain #endif // POWER10
402d267cec2SMatt Spinler 
403a8857c50SChris Cain     /**
404a8857c50SChris Cain      * @brief Called when poll timer expires and forces a POLL command to the
405a8857c50SChris Cain      * OCC. The poll timer will then be restarted.
406a8857c50SChris Cain      * */
407a8857c50SChris Cain     void pollerTimerExpired();
408bb895cb8SChicago Duan 
409d267cec2SMatt Spinler     /**
410d267cec2SMatt Spinler      * @brief Finds the OCC devices in /dev
411d267cec2SMatt Spinler      *
412d267cec2SMatt Spinler      * @return The IDs of the OCCs - 0, 1, etc.
413d267cec2SMatt Spinler      */
414d267cec2SMatt Spinler     std::vector<int> findOCCsInDev();
415d267cec2SMatt Spinler 
416bb895cb8SChicago Duan #ifdef READ_OCC_SENSORS
417bb895cb8SChicago Duan     /**
418bb895cb8SChicago Duan      * @brief Gets the occ sensor values.
4195d66a0aaSChris Cain      * @param[in] occ - pointer to OCCs Status object
420bb895cb8SChicago Duan      * */
4215d66a0aaSChris Cain     void getSensorValues(std::unique_ptr<Status>& occ);
422bb895cb8SChicago Duan 
423bb895cb8SChicago Duan     /**
424bb895cb8SChicago Duan      * @brief Trigger OCC driver to read the temperature sensors.
425bb895cb8SChicago Duan      * @param[in] path - path of the OCC sensors.
426bb895cb8SChicago Duan      * @param[in] id - Id of the OCC.
427bb895cb8SChicago Duan      * */
428bb895cb8SChicago Duan     void readTempSensors(const fs::path& path, uint32_t id);
429bb895cb8SChicago Duan 
430bb895cb8SChicago Duan     /**
431d2b044f9SSheldon Bailey      * @brief Trigger OCC driver to read the extended sensors.
432d2b044f9SSheldon Bailey      * @param[in] path - path of the OCC sensors.
433d2b044f9SSheldon Bailey      * @param[in] id - Id of the OCC.
434d2b044f9SSheldon Bailey      * */
435d2b044f9SSheldon Bailey     void readExtnSensors(const fs::path& path, uint32_t id);
436d2b044f9SSheldon Bailey 
437d2b044f9SSheldon Bailey     /**
438bb895cb8SChicago Duan      * @brief Trigger OCC driver to read the power sensors.
439bb895cb8SChicago Duan      * @param[in] path - path of the OCC sensors.
440bb895cb8SChicago Duan      * @param[in] id - Id of the OCC.
441bb895cb8SChicago Duan      * */
442bb895cb8SChicago Duan     void readPowerSensors(const fs::path& path, uint32_t id);
443bb895cb8SChicago Duan 
444bb895cb8SChicago Duan     /** @brief Store the existing OCC sensors on D-BUS */
445bb895cb8SChicago Duan     std::map<std::string, uint32_t> existingSensors;
446bb895cb8SChicago Duan 
447bb895cb8SChicago Duan     /** @brief Get FunctionID from the `powerX_label` file.
448bb895cb8SChicago Duan      *  @param[in] value - the value of the `powerX_label` file.
449bb895cb8SChicago Duan      *  @returns FunctionID of the power sensors.
450bb895cb8SChicago Duan      */
4512d6ec909SPatrick Williams     std::optional<std::string> getPowerLabelFunctionID(
4522d6ec909SPatrick Williams         const std::string& value);
453bb895cb8SChicago Duan 
454bb895cb8SChicago Duan     /** @brief The power sensor names map */
455bb895cb8SChicago Duan     const std::map<std::string, std::string> powerSensorName = {
456bb895cb8SChicago Duan         {"system", "total_power"}, {"1", "p0_mem_power"},
457bb895cb8SChicago Duan         {"2", "p1_mem_power"},     {"3", "p2_mem_power"},
458bb895cb8SChicago Duan         {"4", "p3_mem_power"},     {"5", "p0_power"},
459bb895cb8SChicago Duan         {"6", "p1_power"},         {"7", "p2_power"},
460bb895cb8SChicago Duan         {"8", "p3_power"},         {"9", "p0_cache_power"},
461bb895cb8SChicago Duan         {"10", "p1_cache_power"},  {"11", "p2_cache_power"},
462bb895cb8SChicago Duan         {"12", "p3_cache_power"},  {"13", "io_a_power"},
463bb895cb8SChicago Duan         {"14", "io_b_power"},      {"15", "io_c_power"},
464bb895cb8SChicago Duan         {"16", "fans_a_power"},    {"17", "fans_b_power"},
465bb895cb8SChicago Duan         {"18", "storage_a_power"}, {"19", "storage_b_power"},
466bb895cb8SChicago Duan         {"23", "mem_cache_power"}, {"25", "p0_mem_0_power"},
46711fd1314SSheldon Bailey         {"26", "p0_mem_1_power"},  {"27", "p0_mem_2_power"},
46811fd1314SSheldon Bailey         {"35", "pcie_dcm0_power"}, {"36", "pcie_dcm1_power"},
46911fd1314SSheldon Bailey         {"37", "pcie_dcm2_power"}, {"38", "pcie_dcm3_power"},
47011fd1314SSheldon Bailey         {"39", "io_dcm0_power"},   {"40", "io_dcm1_power"},
47111fd1314SSheldon Bailey         {"41", "io_dcm2_power"},   {"42", "io_dcm3_power"},
47211fd1314SSheldon Bailey         {"43", "avdd_total_power"}};
473bb895cb8SChicago Duan 
474bb895cb8SChicago Duan     /** @brief The dimm temperature sensor names map  */
475bb895cb8SChicago Duan     const std::map<uint32_t, std::string> dimmTempSensorName = {
476bb895cb8SChicago Duan         {internalMemCtlr, "_intmb_temp"},
477bb895cb8SChicago Duan         {dimm, "_dram_temp"},
478bb895cb8SChicago Duan         {memCtrlAndDimm, "_dram_extmb_temp"},
479bb895cb8SChicago Duan         {PMIC, "_pmic_temp"},
480bb895cb8SChicago Duan         {memCtlrExSensor, "_extmb_temp"}};
481ad8f4524SMatt Spinler 
482ad8f4524SMatt Spinler     /** @brief The dimm DVFS temperature sensor names map  */
483ad8f4524SMatt Spinler     const std::map<uint32_t, std::string> dimmDVFSSensorName = {
484ad8f4524SMatt Spinler         {internalMemCtlr, "dimm_intmb_dvfs_temp"},
485ad8f4524SMatt Spinler         {dimm, "dimm_dram_dvfs_temp"},
486ad8f4524SMatt Spinler         {memCtrlAndDimm, "dimm_dram_extmb_dvfs_temp"},
487ad8f4524SMatt Spinler         {PMIC, "dimm_pmic_dvfs_temp"},
488ad8f4524SMatt Spinler         {memCtlrExSensor, "dimm_extmb_dvfs_temp"}};
489bb895cb8SChicago Duan #endif
49017257673SChris Cain 
49117257673SChris Cain     /** @brief Read the altitude from DBus */
49217257673SChris Cain     void readAltitude();
49317257673SChris Cain 
49417257673SChris Cain     /** @brief Callback function when ambient temperature changes
49517257673SChris Cain      *
49617257673SChris Cain      *  @param[in]  msg - Data associated with subscribed signal
49717257673SChris Cain      */
498af40808fSPatrick Williams     void ambientCallback(sdbusplus::message_t& msg);
499a7b74dc3SChris Cain 
500a7b74dc3SChris Cain     /** @brief Confirm that a single OCC master was found and start presence
501a7b74dc3SChris Cain      * monitoring
502a7b74dc3SChris Cain      */
503a7b74dc3SChris Cain     void validateOccMaster();
5042180b2daSVishwanatha Subbanna };
5052180b2daSVishwanatha Subbanna 
5062180b2daSVishwanatha Subbanna } // namespace occ
5072180b2daSVishwanatha Subbanna } // namespace open_power
508