Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 3 | #include "occ_command.hpp" |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 4 | #include "powermode.hpp" |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 5 | #include "utils.hpp" |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 6 | |
| 7 | #include <fmt/core.h> |
| 8 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 9 | #include <org/open_power/OCC/PassThrough/server.hpp> |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 10 | #include <phosphor-logging/log.hpp> |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 11 | #include <sdbusplus/bus.hpp> |
| 12 | #include <sdbusplus/server/object.hpp> |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 13 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 14 | #include <string> |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 15 | |
| 16 | namespace open_power |
| 17 | { |
| 18 | namespace occ |
| 19 | { |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 20 | |
| 21 | using Iface = sdbusplus::server::object::object< |
| 22 | sdbusplus::org::open_power::OCC::server::PassThrough>; |
| 23 | |
Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 24 | // For waiting on signals |
| 25 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 26 | |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 27 | /** @class PassThrough |
| 28 | * @brief Implements org.open_power.OCC.PassThrough |
| 29 | */ |
| 30 | class PassThrough : public Iface |
| 31 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 32 | public: |
| 33 | PassThrough() = delete; |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 34 | ~PassThrough() = default; |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 35 | PassThrough(const PassThrough&) = delete; |
| 36 | PassThrough& operator=(const PassThrough&) = delete; |
| 37 | PassThrough(PassThrough&&) = default; |
| 38 | PassThrough& operator=(PassThrough&&) = default; |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 39 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 40 | /** @brief Ctor to put pass-through d-bus object on the bus |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 41 | * @param[in] path - Path to attach at |
| 42 | */ |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 43 | explicit PassThrough( |
| 44 | const char* path |
| 45 | #ifdef POWER10 |
| 46 | , |
| 47 | std::unique_ptr<open_power::occ::powermode::PowerMode>& powerModeRef |
| 48 | #endif |
| 49 | ); |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 50 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 51 | /** @brief Pass through command to OCC from dbus |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 52 | * @param[in] command - command to pass-through |
| 53 | * @returns OCC response as an array |
| 54 | */ |
| 55 | std::vector<std::int32_t> send(std::vector<std::int32_t> command) override; |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 56 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 57 | /** @brief Pass through command to OCC from openpower-occ-control |
| 58 | * @param[in] command - command to pass-through |
| 59 | * @returns OCC response as an array |
| 60 | */ |
| 61 | std::vector<std::uint8_t> send(std::vector<std::uint8_t> command); |
| 62 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 63 | /** @brief Set a Power Mode |
| 64 | * |
| 65 | * @param[in] mode - desired System Power Mode |
| 66 | * @param[in] modeData - data associated some Power Modes |
| 67 | * |
| 68 | * @returns true if mode change was accepted |
| 69 | */ |
| 70 | bool setMode(const uint8_t mode, const uint16_t modeData); |
| 71 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 72 | private: |
| 73 | /** @brief Pass-through occ path on the bus */ |
| 74 | std::string path; |
Vishwanatha Subbanna | afd21a6 | 2017-04-13 20:17:13 +0530 | [diff] [blame] | 75 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 76 | #ifdef POWER10 |
| 77 | /** @brief OCC PowerMode object */ |
| 78 | std::unique_ptr<open_power::occ::powermode::PowerMode>& pmode; |
| 79 | #endif |
| 80 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 81 | /** @brief OCC device path |
| 82 | * For now, here is the hard-coded mapping until |
| 83 | * the udev rule is in. |
| 84 | * occ0 --> /dev/occ1 |
| 85 | * occ1 --> /dev/occ2 |
| 86 | * ... |
| 87 | */ |
| 88 | std::string devicePath; |
Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame] | 89 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 90 | /** @brief OCC instance number */ |
| 91 | int occInstance; |
| 92 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 93 | /** @brief Indicates whether or not the OCC is currently active */ |
| 94 | bool occActive = false; |
Eddie James | 4f4712d | 2018-06-21 15:57:02 -0500 | [diff] [blame] | 95 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 96 | /** @brief Subscribe to OCC Status signal |
| 97 | * |
| 98 | * Once the OCC status gets to active, only then we will get /dev/occ2 |
| 99 | * populated and hence need to wait on that before opening that |
| 100 | */ |
| 101 | sdbusplus::bus::match_t activeStatusSignal; |
Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 102 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 103 | /** @brief Object to send commands to the OCC */ |
| 104 | OccCommand occCmd; |
Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 105 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 106 | /** @brief Callback function on OCC Status change signals |
| 107 | * |
| 108 | * @param[in] msg - Data associated with subscribed signal |
| 109 | */ |
| 110 | void activeStatusEvent(sdbusplus::message::message& msg); |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 111 | }; |
| 112 | |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 113 | } // namespace occ |
| 114 | } // namespace open_power |