blob: 047d4aed48f80473eb889feb5d3b0f5f61ed7957 [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"
Chris Cain36f9cde2021-11-22 11:18:21 -06004#include "powermode.hpp"
George Liuf3b75142021-06-10 11:22:50 +08005#include "utils.hpp"
Chris Caina8857c52021-01-27 11:53:05 -06006
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>
George Liub5ca1012021-09-10 12:53:11 +080011
Patrick Williams48002492024-02-13 21:43:32 -060012#include <format>
Gunnar Mills94df8c92018-09-14 14:50:03 -050013#include <string>
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050014
15namespace open_power
16{
17namespace occ
18{
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050019
Patrick Williamsaf408082022-07-22 19:26:54 -050020using Iface = sdbusplus::server::object_t<
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050021 sdbusplus::org::open_power::OCC::server::PassThrough>;
22
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053023// For waiting on signals
24namespace sdbusRule = sdbusplus::bus::match::rules;
25
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050026/** @class PassThrough
27 * @brief Implements org.open_power.OCC.PassThrough
28 */
29class PassThrough : public Iface
30{
Gunnar Mills94df8c92018-09-14 14:50:03 -050031 public:
32 PassThrough() = delete;
Chris Caina8857c52021-01-27 11:53:05 -060033 ~PassThrough() = default;
Gunnar Mills94df8c92018-09-14 14:50:03 -050034 PassThrough(const PassThrough&) = delete;
35 PassThrough& operator=(const PassThrough&) = delete;
36 PassThrough(PassThrough&&) = default;
37 PassThrough& operator=(PassThrough&&) = default;
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050038
Gunnar Mills94df8c92018-09-14 14:50:03 -050039 /** @brief Ctor to put pass-through d-bus object on the bus
Gunnar Mills94df8c92018-09-14 14:50:03 -050040 * @param[in] path - Path to attach at
41 */
Chris Cain36f9cde2021-11-22 11:18:21 -060042 explicit PassThrough(
Sheldon Bailey16a5adb2025-06-10 14:10:06 -050043 const char* path,
44 std::unique_ptr<open_power::occ::powermode::PowerMode>& powerModeRef);
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050045
Chris Caina8857c52021-01-27 11:53:05 -060046 /** @brief Pass through command to OCC from dbus
Gunnar Mills94df8c92018-09-14 14:50:03 -050047 * @param[in] command - command to pass-through
48 * @returns OCC response as an array
49 */
50 std::vector<std::int32_t> send(std::vector<std::int32_t> command) override;
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050051
Chris Caina8857c52021-01-27 11:53:05 -060052 /** @brief Pass through command to OCC from openpower-occ-control
53 * @param[in] command - command to pass-through
54 * @returns OCC response as an array
55 */
56 std::vector<std::uint8_t> send(std::vector<std::uint8_t> command);
57
Chris Cain36f9cde2021-11-22 11:18:21 -060058 /** @brief Set a Power Mode
59 *
60 * @param[in] mode - desired System Power Mode
61 * @param[in] modeData - data associated some Power Modes
62 *
63 * @returns true if mode change was accepted
64 */
65 bool setMode(const uint8_t mode, const uint16_t modeData);
66
Gunnar Mills94df8c92018-09-14 14:50:03 -050067 private:
68 /** @brief Pass-through occ path on the bus */
69 std::string path;
Vishwanatha Subbannaafd21a62017-04-13 20:17:13 +053070
Chris Cain36f9cde2021-11-22 11:18:21 -060071 /** @brief OCC PowerMode object */
72 std::unique_ptr<open_power::occ::powermode::PowerMode>& pmode;
Chris Cain36f9cde2021-11-22 11:18:21 -060073
Gunnar Mills94df8c92018-09-14 14:50:03 -050074 /** @brief OCC device path
75 * For now, here is the hard-coded mapping until
76 * the udev rule is in.
77 * occ0 --> /dev/occ1
78 * occ1 --> /dev/occ2
79 * ...
80 */
81 std::string devicePath;
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +053082
Chris Caina8857c52021-01-27 11:53:05 -060083 /** @brief OCC instance number */
84 int occInstance;
85
Gunnar Mills94df8c92018-09-14 14:50:03 -050086 /** @brief Indicates whether or not the OCC is currently active */
87 bool occActive = false;
Eddie James4f4712d2018-06-21 15:57:02 -050088
Gunnar Mills94df8c92018-09-14 14:50:03 -050089 /** @brief Subscribe to OCC Status signal
90 *
91 * Once the OCC status gets to active, only then we will get /dev/occ2
92 * populated and hence need to wait on that before opening that
93 */
94 sdbusplus::bus::match_t activeStatusSignal;
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053095
Chris Caina8857c52021-01-27 11:53:05 -060096 /** @brief Object to send commands to the OCC */
97 OccCommand occCmd;
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053098
Gunnar Mills94df8c92018-09-14 14:50:03 -050099 /** @brief Callback function on OCC Status change signals
100 *
101 * @param[in] msg - Data associated with subscribed signal
102 */
Patrick Williamsaf408082022-07-22 19:26:54 -0500103 void activeStatusEvent(sdbusplus::message_t& msg);
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -0500104};
105
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -0500106} // namespace occ
107} // namespace open_power