George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
George Liu | b49b7d8 | 2021-02-08 14:10:17 +0800 | [diff] [blame] | 3 | #include "../oem/ibm/host-bmc/host_lamp_test.hpp" |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 4 | #include "../oem/ibm/libpldmresponder/file_io.hpp" |
| 5 | #include "../oem/ibm/libpldmresponder/fru_oem_ibm.hpp" |
| 6 | #include "../oem/ibm/libpldmresponder/oem_ibm_handler.hpp" |
Kamalkumar Patel | eb43d6c | 2024-05-01 06:11:31 -0500 | [diff] [blame] | 7 | #include "../oem/ibm/libpldmresponder/utils.hpp" |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 8 | #include "common/utils.hpp" |
| 9 | #include "dbus_impl_requester.hpp" |
| 10 | #include "host-bmc/dbus_to_event_handler.hpp" |
| 11 | #include "invoker.hpp" |
Pavithra Barithaya | 928e87f | 2024-07-31 14:11:52 +0530 | [diff] [blame^] | 12 | #include "libpldmresponder/base.hpp" |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 13 | #include "libpldmresponder/fru.hpp" |
| 14 | #include "requester/request.hpp" |
| 15 | |
Andrew Jeffery | 41ca40d | 2024-06-19 16:52:21 +0930 | [diff] [blame] | 16 | #include <libpldm/pdr.h> |
| 17 | |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 18 | namespace pldm |
| 19 | { |
| 20 | namespace oem_ibm |
| 21 | { |
| 22 | |
| 23 | using namespace pldm::state_sensor; |
| 24 | using namespace pldm::dbus_api; |
| 25 | |
| 26 | /** |
| 27 | * @class OemIBM |
| 28 | * |
| 29 | * @brief class for creating all the OEM IBM handlers |
| 30 | * |
| 31 | * Only in case of OEM_IBM this class object will be instantiated |
| 32 | */ |
| 33 | class OemIBM |
| 34 | { |
| 35 | public: |
| 36 | OemIBM() = delete; |
| 37 | OemIBM(const Pdr&) = delete; |
| 38 | OemIBM& operator=(const OemIBM&) = delete; |
| 39 | OemIBM(OemIBM&&) = delete; |
| 40 | OemIBM& operator=(OemIBM&&) = delete; |
| 41 | |
| 42 | public: |
| 43 | /** Constructs OemIBM object |
| 44 | * |
| 45 | * @param[in] dBusIntf - D-Bus handler |
| 46 | * @param[in] mctp_fd - fd of MCTP communications socket |
| 47 | * @param[in] mctp_eid - MCTP EID of remote host firmware |
| 48 | * @param[in] repo - pointer to BMC's primary PDR repo |
| 49 | * @param[in] instanceIdDb - pointer to an InstanceIdDb object |
| 50 | * @param[in] event - sd_event handler |
| 51 | * @param[in] invoker - invoker handler |
| 52 | * @param[in] hostPDRHandler - hostPDRHandler handler |
| 53 | * @param[in] platformHandler - platformHandler handler |
| 54 | * @param[in] fruHandler - fruHandler handler |
| 55 | * @param[in] baseHandler - baseHandler handler |
| 56 | * @param[in] reqHandler - reqHandler handler |
| 57 | */ |
| 58 | explicit OemIBM( |
| 59 | const pldm::utils::DBusHandler* dBusIntf, int mctp_fd, uint8_t mctp_eid, |
| 60 | pldm_pdr* repo, pldm::InstanceIdDb& instanceIdDb, |
Pavithra Barithaya | 928e87f | 2024-07-31 14:11:52 +0530 | [diff] [blame^] | 61 | sdeventplus::Event& event, responder::Invoker& invoker, |
| 62 | HostPDRHandler* hostPDRHandler, |
| 63 | responder::platform::Handler* platformHandler, |
| 64 | responder::fru::Handler* fruHandler, |
| 65 | responder::base::Handler* baseHandler, |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 66 | pldm::requester::Handler<pldm::requester::Request>* reqHandler) : |
| 67 | dBusIntf(dBusIntf), |
| 68 | mctp_fd(mctp_fd), mctp_eid(mctp_eid), repo(repo), |
| 69 | instanceIdDb(instanceIdDb), event(event), invoker(invoker), |
| 70 | reqHandler(reqHandler) |
| 71 | { |
| 72 | createOemFruHandler(); |
| 73 | fruHandler->setOemFruHandler(oemFruHandler.get()); |
| 74 | |
| 75 | createOemIbmFruHandler(); |
| 76 | oemIbmFruHandler->setIBMFruHandler(fruHandler); |
| 77 | |
| 78 | createCodeUpdate(); |
| 79 | createOemPlatformHandler(); |
Kamalkumar Patel | eb43d6c | 2024-05-01 06:11:31 -0500 | [diff] [blame] | 80 | createOemIbmUtilsHandler(); |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 81 | codeUpdate->setOemPlatformHandler(oemPlatformHandler.get()); |
| 82 | hostPDRHandler->setOemPlatformHandler(oemPlatformHandler.get()); |
Kamalkumar Patel | eb43d6c | 2024-05-01 06:11:31 -0500 | [diff] [blame] | 83 | hostPDRHandler->setOemUtilsHandler(oemUtilsHandler.get()); |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 84 | platformHandler->setOemPlatformHandler(oemPlatformHandler.get()); |
| 85 | baseHandler->setOemPlatformHandler(oemPlatformHandler.get()); |
| 86 | |
| 87 | createOemIbmPlatformHandler(); |
| 88 | oemIbmPlatformHandler->setPlatformHandler(platformHandler); |
| 89 | |
George Liu | b49b7d8 | 2021-02-08 14:10:17 +0800 | [diff] [blame] | 90 | createHostLampTestHandler(); |
| 91 | |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 92 | registerHandler(); |
| 93 | } |
| 94 | |
| 95 | private: |
| 96 | /** @brief Method for creating codeUpdate handler */ |
| 97 | void createCodeUpdate() |
| 98 | { |
| 99 | codeUpdate = std::make_unique<pldm::responder::CodeUpdate>(dBusIntf); |
| 100 | codeUpdate->clearDirPath(LID_STAGING_DIR); |
| 101 | } |
| 102 | |
| 103 | /** @brief Method for creating oemPlatformHandler |
| 104 | * |
| 105 | * This method also assigns the oemPlatformHandler to the below |
| 106 | * different handlers. |
| 107 | */ |
| 108 | void createOemPlatformHandler() |
| 109 | { |
Pavithra Barithaya | 928e87f | 2024-07-31 14:11:52 +0530 | [diff] [blame^] | 110 | oemPlatformHandler = |
| 111 | std::make_unique<responder::oem_ibm_platform::Handler>( |
| 112 | dBusIntf, codeUpdate.get(), mctp_fd, mctp_eid, instanceIdDb, |
| 113 | event, reqHandler); |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /** @brief Method for creating oemIbmPlatformHandler */ |
| 117 | void createOemIbmPlatformHandler() |
| 118 | { |
| 119 | oemIbmPlatformHandler = |
| 120 | dynamic_cast<pldm::responder::oem_ibm_platform::Handler*>( |
| 121 | oemPlatformHandler.get()); |
| 122 | } |
| 123 | |
| 124 | /** @brief Method for creating oemFruHandler */ |
| 125 | void createOemFruHandler() |
| 126 | { |
Pavithra Barithaya | 928e87f | 2024-07-31 14:11:52 +0530 | [diff] [blame^] | 127 | oemFruHandler = std::make_unique<responder::oem_ibm_fru::Handler>(repo); |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 128 | } |
| 129 | |
Kamalkumar Patel | eb43d6c | 2024-05-01 06:11:31 -0500 | [diff] [blame] | 130 | /** @brief Method for creating oemIbmUtilsHandler */ |
| 131 | void createOemIbmUtilsHandler() |
| 132 | { |
Pavithra Barithaya | 928e87f | 2024-07-31 14:11:52 +0530 | [diff] [blame^] | 133 | oemUtilsHandler = |
| 134 | std::make_unique<responder::oem_ibm_utils::Handler>(dBusIntf); |
Kamalkumar Patel | eb43d6c | 2024-05-01 06:11:31 -0500 | [diff] [blame] | 135 | } |
| 136 | |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 137 | /** @brief Method for creating oemIbmFruHandler */ |
| 138 | void createOemIbmFruHandler() |
| 139 | { |
| 140 | oemIbmFruHandler = dynamic_cast<pldm::responder::oem_ibm_fru::Handler*>( |
| 141 | oemFruHandler.get()); |
| 142 | } |
| 143 | |
George Liu | b49b7d8 | 2021-02-08 14:10:17 +0800 | [diff] [blame] | 144 | void createHostLampTestHandler() |
| 145 | { |
| 146 | auto& bus = pldm::utils::DBusHandler::getBus(); |
| 147 | hostLampTest = std::make_unique<pldm::led::HostLampTest>( |
| 148 | bus, "/xyz/openbmc_project/led/groups/host_lamp_test", mctp_eid, |
| 149 | instanceIdDb, repo, reqHandler); |
| 150 | } |
| 151 | |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 152 | /** @brief Method for registering PLDM OEM handler */ |
| 153 | void registerHandler() |
| 154 | { |
| 155 | invoker.registerHandler( |
| 156 | PLDM_OEM, std::make_unique<pldm::responder::oem_ibm::Handler>( |
| 157 | oemPlatformHandler.get(), mctp_fd, mctp_eid, |
| 158 | &instanceIdDb, reqHandler)); |
| 159 | } |
| 160 | |
| 161 | private: |
| 162 | /** @brief D-Bus handler */ |
| 163 | const pldm::utils::DBusHandler* dBusIntf; |
| 164 | |
| 165 | /** @brief fd of MCTP communications socket */ |
| 166 | int mctp_fd; |
| 167 | |
| 168 | /** @brief MCTP EID of remote host firmware */ |
| 169 | uint8_t mctp_eid; |
| 170 | |
| 171 | /** @brief pointer to BMC's primary PDR repo */ |
| 172 | pldm_pdr* repo; |
| 173 | |
| 174 | /** @brief reference to an Instance ID database object, used to obtain PLDM |
| 175 | * instance IDs |
| 176 | */ |
| 177 | pldm::InstanceIdDb& instanceIdDb; |
| 178 | |
| 179 | /** @brief reference of main event loop of pldmd, primarily used to schedule |
| 180 | * work |
| 181 | */ |
| 182 | sdeventplus::Event& event; |
| 183 | |
| 184 | /** @brief Object to the invoker class*/ |
Pavithra Barithaya | 928e87f | 2024-07-31 14:11:52 +0530 | [diff] [blame^] | 185 | responder::Invoker& invoker; |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 186 | |
| 187 | /** @brief pointer to the requester class*/ |
| 188 | requester::Handler<requester::Request>* reqHandler; |
| 189 | |
| 190 | /** @brief pointer to the oem_ibm_handler class*/ |
Pavithra Barithaya | 928e87f | 2024-07-31 14:11:52 +0530 | [diff] [blame^] | 191 | std::unique_ptr<responder::oem_platform::Handler> oemPlatformHandler{}; |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 192 | |
| 193 | /** @brief pointer to the oem_ibm_fru class*/ |
Pavithra Barithaya | 928e87f | 2024-07-31 14:11:52 +0530 | [diff] [blame^] | 194 | std::unique_ptr<responder::oem_fru::Handler> oemFruHandler{}; |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 195 | |
| 196 | /** @brief pointer to the CodeUpdate class*/ |
| 197 | std::unique_ptr<pldm::responder::CodeUpdate> codeUpdate{}; |
| 198 | |
| 199 | /** @brief oem IBM Platform handler*/ |
| 200 | pldm::responder::oem_ibm_platform::Handler* oemIbmPlatformHandler = nullptr; |
| 201 | |
| 202 | /** @brief oem IBM Fru handler*/ |
| 203 | pldm::responder::oem_ibm_fru::Handler* oemIbmFruHandler = nullptr; |
George Liu | b49b7d8 | 2021-02-08 14:10:17 +0800 | [diff] [blame] | 204 | |
| 205 | std::unique_ptr<pldm::led::HostLampTest> hostLampTest; |
Kamalkumar Patel | eb43d6c | 2024-05-01 06:11:31 -0500 | [diff] [blame] | 206 | |
| 207 | /** @brief oem IBM Utils handler*/ |
Pavithra Barithaya | 928e87f | 2024-07-31 14:11:52 +0530 | [diff] [blame^] | 208 | std::unique_ptr<responder::oem_utils::Handler> oemUtilsHandler; |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 209 | }; |
| 210 | |
| 211 | } // namespace oem_ibm |
| 212 | } // namespace pldm |