16b492fbfSDeepak Kodihalli #pragma once 26b492fbfSDeepak Kodihalli 3a8857c50SChris Cain #include "occ_command.hpp" 436f9cdedSChris Cain #include "powermode.hpp" 5f3b7514eSGeorge Liu #include "utils.hpp" 6a8857c50SChris Cain 794df8c90SGunnar Mills #include <org/open_power/OCC/PassThrough/server.hpp> 8a8857c50SChris Cain #include <phosphor-logging/log.hpp> 96b492fbfSDeepak Kodihalli #include <sdbusplus/bus.hpp> 106b492fbfSDeepak Kodihalli #include <sdbusplus/server/object.hpp> 11b5ca1015SGeorge Liu 12*48002498SPatrick Williams #include <format> 1394df8c90SGunnar Mills #include <string> 146b492fbfSDeepak Kodihalli 156b492fbfSDeepak Kodihalli namespace open_power 166b492fbfSDeepak Kodihalli { 176b492fbfSDeepak Kodihalli namespace occ 186b492fbfSDeepak Kodihalli { 196b492fbfSDeepak Kodihalli 20af40808fSPatrick Williams using Iface = sdbusplus::server::object_t< 216b492fbfSDeepak Kodihalli sdbusplus::org::open_power::OCC::server::PassThrough>; 226b492fbfSDeepak Kodihalli 233e5422edSVishwanatha Subbanna // For waiting on signals 243e5422edSVishwanatha Subbanna namespace sdbusRule = sdbusplus::bus::match::rules; 253e5422edSVishwanatha Subbanna 266b492fbfSDeepak Kodihalli /** @class PassThrough 276b492fbfSDeepak Kodihalli * @brief Implements org.open_power.OCC.PassThrough 286b492fbfSDeepak Kodihalli */ 296b492fbfSDeepak Kodihalli class PassThrough : public Iface 306b492fbfSDeepak Kodihalli { 316b492fbfSDeepak Kodihalli public: 326b492fbfSDeepak Kodihalli PassThrough() = delete; 33a8857c50SChris Cain ~PassThrough() = default; 346b492fbfSDeepak Kodihalli PassThrough(const PassThrough&) = delete; 356b492fbfSDeepak Kodihalli PassThrough& operator=(const PassThrough&) = delete; 366b492fbfSDeepak Kodihalli PassThrough(PassThrough&&) = default; 376b492fbfSDeepak Kodihalli PassThrough& operator=(PassThrough&&) = default; 386b492fbfSDeepak Kodihalli 396b492fbfSDeepak Kodihalli /** @brief Ctor to put pass-through d-bus object on the bus 406b492fbfSDeepak Kodihalli * @param[in] path - Path to attach at 416b492fbfSDeepak Kodihalli */ 4236f9cdedSChris Cain explicit PassThrough( 4336f9cdedSChris Cain const char* path 4436f9cdedSChris Cain #ifdef POWER10 4536f9cdedSChris Cain , 4636f9cdedSChris Cain std::unique_ptr<open_power::occ::powermode::PowerMode>& powerModeRef 4736f9cdedSChris Cain #endif 4836f9cdedSChris Cain ); 496b492fbfSDeepak Kodihalli 50a8857c50SChris Cain /** @brief Pass through command to OCC from dbus 516b492fbfSDeepak Kodihalli * @param[in] command - command to pass-through 526b492fbfSDeepak Kodihalli * @returns OCC response as an array 536b492fbfSDeepak Kodihalli */ 5494df8c90SGunnar Mills std::vector<std::int32_t> send(std::vector<std::int32_t> command) override; 556b492fbfSDeepak Kodihalli 56a8857c50SChris Cain /** @brief Pass through command to OCC from openpower-occ-control 57a8857c50SChris Cain * @param[in] command - command to pass-through 58a8857c50SChris Cain * @returns OCC response as an array 59a8857c50SChris Cain */ 60a8857c50SChris Cain std::vector<std::uint8_t> send(std::vector<std::uint8_t> command); 61a8857c50SChris Cain 6236f9cdedSChris Cain /** @brief Set a Power Mode 6336f9cdedSChris Cain * 6436f9cdedSChris Cain * @param[in] mode - desired System Power Mode 6536f9cdedSChris Cain * @param[in] modeData - data associated some Power Modes 6636f9cdedSChris Cain * 6736f9cdedSChris Cain * @returns true if mode change was accepted 6836f9cdedSChris Cain */ 6936f9cdedSChris Cain bool setMode(const uint8_t mode, const uint16_t modeData); 7036f9cdedSChris Cain 716b492fbfSDeepak Kodihalli private: 726b492fbfSDeepak Kodihalli /** @brief Pass-through occ path on the bus */ 736b492fbfSDeepak Kodihalli std::string path; 74afd21a65SVishwanatha Subbanna 7536f9cdedSChris Cain #ifdef POWER10 7636f9cdedSChris Cain /** @brief OCC PowerMode object */ 7736f9cdedSChris Cain std::unique_ptr<open_power::occ::powermode::PowerMode>& pmode; 7836f9cdedSChris Cain #endif 7936f9cdedSChris Cain 80afd21a65SVishwanatha Subbanna /** @brief OCC device path 81afd21a65SVishwanatha Subbanna * For now, here is the hard-coded mapping until 8238b08d79SVishwanatha Subbanna * the udev rule is in. 833e5422edSVishwanatha Subbanna * occ0 --> /dev/occ1 843e5422edSVishwanatha Subbanna * occ1 --> /dev/occ2 85afd21a65SVishwanatha Subbanna * ... 86afd21a65SVishwanatha Subbanna */ 873e5422edSVishwanatha Subbanna std::string devicePath; 8838b08d79SVishwanatha Subbanna 89a8857c50SChris Cain /** @brief OCC instance number */ 90a8857c50SChris Cain int occInstance; 91a8857c50SChris Cain 924f4712d8SEddie James /** @brief Indicates whether or not the OCC is currently active */ 934f4712d8SEddie James bool occActive = false; 944f4712d8SEddie James 953e5422edSVishwanatha Subbanna /** @brief Subscribe to OCC Status signal 963e5422edSVishwanatha Subbanna * 973e5422edSVishwanatha Subbanna * Once the OCC status gets to active, only then we will get /dev/occ2 983e5422edSVishwanatha Subbanna * populated and hence need to wait on that before opening that 993e5422edSVishwanatha Subbanna */ 1003e5422edSVishwanatha Subbanna sdbusplus::bus::match_t activeStatusSignal; 1013e5422edSVishwanatha Subbanna 102a8857c50SChris Cain /** @brief Object to send commands to the OCC */ 103a8857c50SChris Cain OccCommand occCmd; 1043e5422edSVishwanatha Subbanna 1053e5422edSVishwanatha Subbanna /** @brief Callback function on OCC Status change signals 1063e5422edSVishwanatha Subbanna * 1073e5422edSVishwanatha Subbanna * @param[in] msg - Data associated with subscribed signal 1083e5422edSVishwanatha Subbanna */ 109af40808fSPatrick Williams void activeStatusEvent(sdbusplus::message_t& msg); 1106b492fbfSDeepak Kodihalli }; 1116b492fbfSDeepak Kodihalli 1126b492fbfSDeepak Kodihalli } // namespace occ 1136b492fbfSDeepak Kodihalli } // namespace open_power 114