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