16b492fbfSDeepak Kodihalli #pragma once
26b492fbfSDeepak Kodihalli 
3a8857c50SChris Cain #include "occ_command.hpp"
4*f3b7514eSGeorge Liu #include "utils.hpp"
5a8857c50SChris Cain 
6a8857c50SChris Cain #include <fmt/core.h>
7a8857c50SChris Cain 
894df8c90SGunnar Mills #include <org/open_power/OCC/PassThrough/server.hpp>
9a8857c50SChris Cain #include <phosphor-logging/log.hpp>
106b492fbfSDeepak Kodihalli #include <sdbusplus/bus.hpp>
116b492fbfSDeepak Kodihalli #include <sdbusplus/server/object.hpp>
1294df8c90SGunnar Mills #include <string>
136b492fbfSDeepak Kodihalli 
146b492fbfSDeepak Kodihalli namespace open_power
156b492fbfSDeepak Kodihalli {
166b492fbfSDeepak Kodihalli namespace occ
176b492fbfSDeepak Kodihalli {
186b492fbfSDeepak Kodihalli 
196b492fbfSDeepak Kodihalli using Iface = sdbusplus::server::object::object<
206b492fbfSDeepak Kodihalli     sdbusplus::org::open_power::OCC::server::PassThrough>;
216b492fbfSDeepak Kodihalli 
223e5422edSVishwanatha Subbanna // For waiting on signals
233e5422edSVishwanatha Subbanna namespace sdbusRule = sdbusplus::bus::match::rules;
243e5422edSVishwanatha Subbanna 
256b492fbfSDeepak Kodihalli /** @class PassThrough
266b492fbfSDeepak Kodihalli  *  @brief Implements org.open_power.OCC.PassThrough
276b492fbfSDeepak Kodihalli  */
286b492fbfSDeepak Kodihalli class PassThrough : public Iface
296b492fbfSDeepak Kodihalli {
306b492fbfSDeepak Kodihalli   public:
316b492fbfSDeepak Kodihalli     PassThrough() = delete;
32a8857c50SChris Cain     ~PassThrough() = default;
336b492fbfSDeepak Kodihalli     PassThrough(const PassThrough&) = delete;
346b492fbfSDeepak Kodihalli     PassThrough& operator=(const PassThrough&) = delete;
356b492fbfSDeepak Kodihalli     PassThrough(PassThrough&&) = default;
366b492fbfSDeepak Kodihalli     PassThrough& operator=(PassThrough&&) = default;
376b492fbfSDeepak Kodihalli 
386b492fbfSDeepak Kodihalli     /** @brief Ctor to put pass-through d-bus object on the bus
396b492fbfSDeepak Kodihalli      *  @param[in] path - Path to attach at
406b492fbfSDeepak Kodihalli      */
41*f3b7514eSGeorge Liu     PassThrough(const char* path);
426b492fbfSDeepak Kodihalli 
43a8857c50SChris Cain     /** @brief Pass through command to OCC from dbus
446b492fbfSDeepak Kodihalli      *  @param[in] command - command to pass-through
456b492fbfSDeepak Kodihalli      *  @returns OCC response as an array
466b492fbfSDeepak Kodihalli      */
4794df8c90SGunnar Mills     std::vector<std::int32_t> send(std::vector<std::int32_t> command) override;
486b492fbfSDeepak Kodihalli 
49a8857c50SChris Cain     /** @brief Pass through command to OCC from openpower-occ-control
50a8857c50SChris Cain      *  @param[in] command - command to pass-through
51a8857c50SChris Cain      *  @returns OCC response as an array
52a8857c50SChris Cain      */
53a8857c50SChris Cain     std::vector<std::uint8_t> send(std::vector<std::uint8_t> command);
54a8857c50SChris Cain 
556b492fbfSDeepak Kodihalli   private:
566b492fbfSDeepak Kodihalli     /** @brief Pass-through occ path on the bus */
576b492fbfSDeepak Kodihalli     std::string path;
58afd21a65SVishwanatha Subbanna 
59afd21a65SVishwanatha Subbanna     /** @brief OCC device path
60afd21a65SVishwanatha Subbanna      *  For now, here is the hard-coded mapping until
6138b08d79SVishwanatha Subbanna      *  the udev rule is in.
623e5422edSVishwanatha Subbanna      *  occ0 --> /dev/occ1
633e5422edSVishwanatha Subbanna      *  occ1 --> /dev/occ2
64afd21a65SVishwanatha Subbanna      *  ...
65afd21a65SVishwanatha Subbanna      */
663e5422edSVishwanatha Subbanna     std::string devicePath;
6738b08d79SVishwanatha Subbanna 
68a8857c50SChris Cain     /** @brief OCC instance number */
69a8857c50SChris Cain     int occInstance;
70a8857c50SChris Cain 
714f4712d8SEddie James     /** @brief Indicates whether or not the OCC is currently active */
724f4712d8SEddie James     bool occActive = false;
734f4712d8SEddie James 
743e5422edSVishwanatha Subbanna     /** @brief Subscribe to OCC Status signal
753e5422edSVishwanatha Subbanna      *
763e5422edSVishwanatha Subbanna      *  Once the OCC status gets to active, only then we will get /dev/occ2
773e5422edSVishwanatha Subbanna      *  populated and hence need to wait on that before opening that
783e5422edSVishwanatha Subbanna      */
793e5422edSVishwanatha Subbanna     sdbusplus::bus::match_t activeStatusSignal;
803e5422edSVishwanatha Subbanna 
81a8857c50SChris Cain     /** @brief Object to send commands to the OCC */
82a8857c50SChris Cain     OccCommand occCmd;
833e5422edSVishwanatha Subbanna 
843e5422edSVishwanatha Subbanna     /** @brief Callback function on OCC Status change signals
853e5422edSVishwanatha Subbanna      *
863e5422edSVishwanatha Subbanna      *  @param[in]  msg - Data associated with subscribed signal
873e5422edSVishwanatha Subbanna      */
883e5422edSVishwanatha Subbanna     void activeStatusEvent(sdbusplus::message::message& msg);
896b492fbfSDeepak Kodihalli };
906b492fbfSDeepak Kodihalli 
916b492fbfSDeepak Kodihalli } // namespace occ
926b492fbfSDeepak Kodihalli } // namespace open_power
93