blob: ef31826f5d6c2860b911161f70501ea5e5f13037 [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"
George Liuf3b75142021-06-10 11:22:50 +08004#include "utils.hpp"
Chris Caina8857c52021-01-27 11:53:05 -06005
6#include <fmt/core.h>
7
Gunnar Mills94df8c92018-09-14 14:50:03 -05008#include <org/open_power/OCC/PassThrough/server.hpp>
Chris Caina8857c52021-01-27 11:53:05 -06009#include <phosphor-logging/log.hpp>
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050010#include <sdbusplus/bus.hpp>
11#include <sdbusplus/server/object.hpp>
Gunnar Mills94df8c92018-09-14 14:50:03 -050012#include <string>
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050013
14namespace open_power
15{
16namespace occ
17{
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050018
19using Iface = sdbusplus::server::object::object<
20 sdbusplus::org::open_power::OCC::server::PassThrough>;
21
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053022// For waiting on signals
23namespace sdbusRule = sdbusplus::bus::match::rules;
24
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050025/** @class PassThrough
26 * @brief Implements org.open_power.OCC.PassThrough
27 */
28class PassThrough : public Iface
29{
Gunnar Mills94df8c92018-09-14 14:50:03 -050030 public:
31 PassThrough() = delete;
Chris Caina8857c52021-01-27 11:53:05 -060032 ~PassThrough() = default;
Gunnar Mills94df8c92018-09-14 14:50:03 -050033 PassThrough(const PassThrough&) = delete;
34 PassThrough& operator=(const PassThrough&) = delete;
35 PassThrough(PassThrough&&) = default;
36 PassThrough& operator=(PassThrough&&) = default;
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050037
Gunnar Mills94df8c92018-09-14 14:50:03 -050038 /** @brief Ctor to put pass-through d-bus object on the bus
Gunnar Mills94df8c92018-09-14 14:50:03 -050039 * @param[in] path - Path to attach at
40 */
George Liuf3b75142021-06-10 11:22:50 +080041 PassThrough(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