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