16b492fbfSDeepak Kodihalli #pragma once
26b492fbfSDeepak Kodihalli 
3*a8857c50SChris Cain #include "occ_command.hpp"
4*a8857c50SChris Cain 
5*a8857c50SChris Cain #include <fmt/core.h>
6*a8857c50SChris Cain 
794df8c90SGunnar Mills #include <org/open_power/OCC/PassThrough/server.hpp>
8*a8857c50SChris Cain #include <phosphor-logging/log.hpp>
96b492fbfSDeepak Kodihalli #include <sdbusplus/bus.hpp>
106b492fbfSDeepak Kodihalli #include <sdbusplus/server/object.hpp>
1194df8c90SGunnar Mills #include <string>
126b492fbfSDeepak Kodihalli 
136b492fbfSDeepak Kodihalli namespace open_power
146b492fbfSDeepak Kodihalli {
156b492fbfSDeepak Kodihalli namespace occ
166b492fbfSDeepak Kodihalli {
176b492fbfSDeepak Kodihalli 
186b492fbfSDeepak Kodihalli using Iface = sdbusplus::server::object::object<
196b492fbfSDeepak Kodihalli     sdbusplus::org::open_power::OCC::server::PassThrough>;
206b492fbfSDeepak Kodihalli 
213e5422edSVishwanatha Subbanna // For waiting on signals
223e5422edSVishwanatha Subbanna namespace sdbusRule = sdbusplus::bus::match::rules;
233e5422edSVishwanatha Subbanna 
246b492fbfSDeepak Kodihalli /** @class PassThrough
256b492fbfSDeepak Kodihalli  *  @brief Implements org.open_power.OCC.PassThrough
266b492fbfSDeepak Kodihalli  */
276b492fbfSDeepak Kodihalli class PassThrough : public Iface
286b492fbfSDeepak Kodihalli {
296b492fbfSDeepak Kodihalli   public:
306b492fbfSDeepak Kodihalli     PassThrough() = delete;
31*a8857c50SChris Cain     ~PassThrough() = default;
326b492fbfSDeepak Kodihalli     PassThrough(const PassThrough&) = delete;
336b492fbfSDeepak Kodihalli     PassThrough& operator=(const PassThrough&) = delete;
346b492fbfSDeepak Kodihalli     PassThrough(PassThrough&&) = default;
356b492fbfSDeepak Kodihalli     PassThrough& operator=(PassThrough&&) = default;
366b492fbfSDeepak Kodihalli 
376b492fbfSDeepak Kodihalli     /** @brief Ctor to put pass-through d-bus object on the bus
386b492fbfSDeepak Kodihalli      *  @param[in] bus - Bus to attach to
396b492fbfSDeepak Kodihalli      *  @param[in] path - Path to attach at
406b492fbfSDeepak Kodihalli      */
4194df8c90SGunnar Mills     PassThrough(sdbusplus::bus::bus& bus, const char* path);
426b492fbfSDeepak Kodihalli 
43*a8857c50SChris 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 
49*a8857c50SChris Cain     /** @brief Pass through command to OCC from openpower-occ-control
50*a8857c50SChris Cain      *  @param[in] command - command to pass-through
51*a8857c50SChris Cain      *  @returns OCC response as an array
52*a8857c50SChris Cain      */
53*a8857c50SChris Cain     std::vector<std::uint8_t> send(std::vector<std::uint8_t> command);
54*a8857c50SChris 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 
68*a8857c50SChris Cain     /** @brief OCC instance number */
69*a8857c50SChris Cain     int occInstance;
70*a8857c50SChris 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 
81*a8857c50SChris Cain     /** @brief Object to send commands to the OCC */
82*a8857c50SChris 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