xref: /openbmc/openpower-occ-control/occ_pass_through.hpp (revision 16a5adb204d261be727c67c4ea3b64a0965303e0)
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         std::unique_ptr<open_power::occ::powermode::PowerMode>& powerModeRef);
45 
46     /** @brief Pass through command to OCC from dbus
47      *  @param[in] command - command to pass-through
48      *  @returns OCC response as an array
49      */
50     std::vector<std::int32_t> send(std::vector<std::int32_t> command) override;
51 
52     /** @brief Pass through command to OCC from openpower-occ-control
53      *  @param[in] command - command to pass-through
54      *  @returns OCC response as an array
55      */
56     std::vector<std::uint8_t> send(std::vector<std::uint8_t> command);
57 
58     /** @brief Set a Power Mode
59      *
60      *  @param[in] mode - desired System Power Mode
61      *  @param[in] modeData - data associated some Power Modes
62      *
63      *  @returns true if mode change was accepted
64      */
65     bool setMode(const uint8_t mode, const uint16_t modeData);
66 
67   private:
68     /** @brief Pass-through occ path on the bus */
69     std::string path;
70 
71     /** @brief OCC PowerMode object */
72     std::unique_ptr<open_power::occ::powermode::PowerMode>& pmode;
73 
74     /** @brief OCC device path
75      *  For now, here is the hard-coded mapping until
76      *  the udev rule is in.
77      *  occ0 --> /dev/occ1
78      *  occ1 --> /dev/occ2
79      *  ...
80      */
81     std::string devicePath;
82 
83     /** @brief OCC instance number */
84     int occInstance;
85 
86     /** @brief Indicates whether or not the OCC is currently active */
87     bool occActive = false;
88 
89     /** @brief Subscribe to OCC Status signal
90      *
91      *  Once the OCC status gets to active, only then we will get /dev/occ2
92      *  populated and hence need to wait on that before opening that
93      */
94     sdbusplus::bus::match_t activeStatusSignal;
95 
96     /** @brief Object to send commands to the OCC */
97     OccCommand occCmd;
98 
99     /** @brief Callback function on OCC Status change signals
100      *
101      *  @param[in]  msg - Data associated with subscribed signal
102      */
103     void activeStatusEvent(sdbusplus::message_t& msg);
104 };
105 
106 } // namespace occ
107 } // namespace open_power
108