1 #pragma once
2 
3 #include "occ_command.hpp"
4 #include "powermode.hpp"
5 #include "utils.hpp"
6 
7 #include <org/open_power/OCC/PassThrough/server.hpp>
8 #include <phosphor-logging/log.hpp>
9 #include <sdbusplus/bus.hpp>
10 #include <sdbusplus/server/object.hpp>
11 
12 #include <format>
13 #include <string>
14 
15 namespace open_power
16 {
17 namespace occ
18 {
19 
20 using Iface = sdbusplus::server::object_t<
21     sdbusplus::org::open_power::OCC::server::PassThrough>;
22 
23 // For waiting on signals
24 namespace sdbusRule = sdbusplus::bus::match::rules;
25 
26 /** @class PassThrough
27  *  @brief Implements org.open_power.OCC.PassThrough
28  */
29 class PassThrough : public Iface
30 {
31   public:
32     PassThrough() = delete;
33     ~PassThrough() = default;
34     PassThrough(const PassThrough&) = delete;
35     PassThrough& operator=(const PassThrough&) = delete;
36     PassThrough(PassThrough&&) = default;
37     PassThrough& operator=(PassThrough&&) = default;
38 
39     /** @brief Ctor to put pass-through d-bus object on the bus
40      *  @param[in] path - Path to attach at
41      */
42     explicit PassThrough(
43         const char* path
44 #ifdef POWER10
45         ,
46         std::unique_ptr<open_power::occ::powermode::PowerMode>& powerModeRef
47 #endif
48     );
49 
50     /** @brief Pass through command to OCC from dbus
51      *  @param[in] command - command to pass-through
52      *  @returns OCC response as an array
53      */
54     std::vector<std::int32_t> send(std::vector<std::int32_t> command) override;
55 
56     /** @brief Pass through command to OCC from openpower-occ-control
57      *  @param[in] command - command to pass-through
58      *  @returns OCC response as an array
59      */
60     std::vector<std::uint8_t> send(std::vector<std::uint8_t> command);
61 
62     /** @brief Set a Power Mode
63      *
64      *  @param[in] mode - desired System Power Mode
65      *  @param[in] modeData - data associated some Power Modes
66      *
67      *  @returns true if mode change was accepted
68      */
69     bool setMode(const uint8_t mode, const uint16_t modeData);
70 
71   private:
72     /** @brief Pass-through occ path on the bus */
73     std::string path;
74 
75 #ifdef POWER10
76     /** @brief OCC PowerMode object */
77     std::unique_ptr<open_power::occ::powermode::PowerMode>& pmode;
78 #endif
79 
80     /** @brief OCC device path
81      *  For now, here is the hard-coded mapping until
82      *  the udev rule is in.
83      *  occ0 --> /dev/occ1
84      *  occ1 --> /dev/occ2
85      *  ...
86      */
87     std::string devicePath;
88 
89     /** @brief OCC instance number */
90     int occInstance;
91 
92     /** @brief Indicates whether or not the OCC is currently active */
93     bool occActive = false;
94 
95     /** @brief Subscribe to OCC Status signal
96      *
97      *  Once the OCC status gets to active, only then we will get /dev/occ2
98      *  populated and hence need to wait on that before opening that
99      */
100     sdbusplus::bus::match_t activeStatusSignal;
101 
102     /** @brief Object to send commands to the OCC */
103     OccCommand occCmd;
104 
105     /** @brief Callback function on OCC Status change signals
106      *
107      *  @param[in]  msg - Data associated with subscribed signal
108      */
109     void activeStatusEvent(sdbusplus::message_t& msg);
110 };
111 
112 } // namespace occ
113 } // namespace open_power
114