blob: 0c01ae41dd0e533bdd0c9ca0b423abb0f06af3e2 [file] [log] [blame]
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -05001#pragma once
2
Chris Caina8857c52021-01-27 11:53:05 -06003#include "occ_command.hpp"
4
5#include <fmt/core.h>
6
Gunnar Mills94df8c92018-09-14 14:50:03 -05007#include <org/open_power/OCC/PassThrough/server.hpp>
Chris Caina8857c52021-01-27 11:53:05 -06008#include <phosphor-logging/log.hpp>
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -05009#include <sdbusplus/bus.hpp>
10#include <sdbusplus/server/object.hpp>
Gunnar Mills94df8c92018-09-14 14:50:03 -050011#include <string>
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050012
13namespace open_power
14{
15namespace occ
16{
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050017
18using Iface = sdbusplus::server::object::object<
19 sdbusplus::org::open_power::OCC::server::PassThrough>;
20
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053021// For waiting on signals
22namespace sdbusRule = sdbusplus::bus::match::rules;
23
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050024/** @class PassThrough
25 * @brief Implements org.open_power.OCC.PassThrough
26 */
27class PassThrough : public Iface
28{
Gunnar Mills94df8c92018-09-14 14:50:03 -050029 public:
30 PassThrough() = delete;
Chris Caina8857c52021-01-27 11:53:05 -060031 ~PassThrough() = default;
Gunnar Mills94df8c92018-09-14 14:50:03 -050032 PassThrough(const PassThrough&) = delete;
33 PassThrough& operator=(const PassThrough&) = delete;
34 PassThrough(PassThrough&&) = default;
35 PassThrough& operator=(PassThrough&&) = default;
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050036
Gunnar Mills94df8c92018-09-14 14:50:03 -050037 /** @brief Ctor to put pass-through d-bus object on the bus
38 * @param[in] bus - Bus to attach to
39 * @param[in] path - Path to attach at
40 */
41 PassThrough(sdbusplus::bus::bus& bus, const char* path);
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050042
Chris Caina8857c52021-01-27 11:53:05 -060043 /** @brief Pass through command to OCC from dbus
Gunnar Mills94df8c92018-09-14 14:50:03 -050044 * @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;
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050048
Chris Caina8857c52021-01-27 11:53:05 -060049 /** @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
Gunnar Mills94df8c92018-09-14 14:50:03 -050055 private:
56 /** @brief Pass-through occ path on the bus */
57 std::string path;
Vishwanatha Subbannaafd21a62017-04-13 20:17:13 +053058
Gunnar Mills94df8c92018-09-14 14:50:03 -050059 /** @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;
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +053067
Chris Caina8857c52021-01-27 11:53:05 -060068 /** @brief OCC instance number */
69 int occInstance;
70
Gunnar Mills94df8c92018-09-14 14:50:03 -050071 /** @brief Indicates whether or not the OCC is currently active */
72 bool occActive = false;
Eddie James4f4712d2018-06-21 15:57:02 -050073
Gunnar Mills94df8c92018-09-14 14:50:03 -050074 /** @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;
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053080
Chris Caina8857c52021-01-27 11:53:05 -060081 /** @brief Object to send commands to the OCC */
82 OccCommand occCmd;
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053083
Gunnar Mills94df8c92018-09-14 14:50:03 -050084 /** @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);
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050089};
90
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050091} // namespace occ
92} // namespace open_power