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