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