blob: 13dfa92e2641e55c4830e23c7b672eef7e55bb74 [file] [log] [blame]
George Liua881c172021-06-21 18:28:11 +08001#pragma once
2
George Liub49b7d82021-02-08 14:10:17 +08003#include "../oem/ibm/host-bmc/host_lamp_test.hpp"
George Liua881c172021-06-21 18:28:11 +08004#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 Pateleb43d6c2024-05-01 06:11:31 -05007#include "../oem/ibm/libpldmresponder/utils.hpp"
George Liua881c172021-06-21 18:28:11 +08008#include "common/utils.hpp"
George Liua881c172021-06-21 18:28:11 +08009#include "host-bmc/dbus_to_event_handler.hpp"
10#include "invoker.hpp"
Pavithra Barithaya928e87f2024-07-31 14:11:52 +053011#include "libpldmresponder/base.hpp"
George Liua881c172021-06-21 18:28:11 +080012#include "libpldmresponder/fru.hpp"
13#include "requester/request.hpp"
14
Andrew Jeffery41ca40d2024-06-19 16:52:21 +093015#include <libpldm/pdr.h>
16
George Liua881c172021-06-21 18:28:11 +080017namespace pldm
18{
19namespace oem_ibm
20{
21
22using namespace pldm::state_sensor;
23using namespace pldm::dbus_api;
24
25/**
26 * @class OemIBM
27 *
28 * @brief class for creating all the OEM IBM handlers
29 *
30 * Only in case of OEM_IBM this class object will be instantiated
31 */
32class OemIBM
33{
34 public:
35 OemIBM() = delete;
36 OemIBM(const Pdr&) = delete;
37 OemIBM& operator=(const OemIBM&) = delete;
38 OemIBM(OemIBM&&) = delete;
39 OemIBM& operator=(OemIBM&&) = delete;
40
41 public:
42 /** Constructs OemIBM object
43 *
44 * @param[in] dBusIntf - D-Bus handler
45 * @param[in] mctp_fd - fd of MCTP communications socket
46 * @param[in] mctp_eid - MCTP EID of remote host firmware
47 * @param[in] repo - pointer to BMC's primary PDR repo
48 * @param[in] instanceIdDb - pointer to an InstanceIdDb object
49 * @param[in] event - sd_event handler
50 * @param[in] invoker - invoker handler
51 * @param[in] hostPDRHandler - hostPDRHandler handler
52 * @param[in] platformHandler - platformHandler handler
53 * @param[in] fruHandler - fruHandler handler
54 * @param[in] baseHandler - baseHandler handler
Archana Kakani97a0f482025-03-10 05:39:38 -050055 * @param[in] biosHandler - biosHandler handler
George Liua881c172021-06-21 18:28:11 +080056 * @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 Barithaya928e87f2024-07-31 14:11:52 +053061 sdeventplus::Event& event, responder::Invoker& invoker,
62 HostPDRHandler* hostPDRHandler,
63 responder::platform::Handler* platformHandler,
64 responder::fru::Handler* fruHandler,
65 responder::base::Handler* baseHandler,
Archana Kakani97a0f482025-03-10 05:39:38 -050066 responder::bios::Handler* biosHandler,
George Liua881c172021-06-21 18:28:11 +080067 pldm::requester::Handler<pldm::requester::Request>* reqHandler) :
Patrick Williams16c2a0a2024-08-16 15:20:59 -040068 dBusIntf(dBusIntf), mctp_fd(mctp_fd), mctp_eid(mctp_eid), repo(repo),
George Liua881c172021-06-21 18:28:11 +080069 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
Archana Kakani97a0f482025-03-10 05:39:38 -050078 createOemIbmBiosHandler();
79 biosHandler->setOemBiosHandler(oemIbmBiosHandler.get());
80
George Liua881c172021-06-21 18:28:11 +080081 createCodeUpdate();
Manojkiran Edaa31ceb92021-07-22 09:19:02 +053082 createSlotHandler();
George Liua881c172021-06-21 18:28:11 +080083 createOemPlatformHandler();
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -050084 createOemIbmUtilsHandler();
George Liua881c172021-06-21 18:28:11 +080085 codeUpdate->setOemPlatformHandler(oemPlatformHandler.get());
86 hostPDRHandler->setOemPlatformHandler(oemPlatformHandler.get());
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -050087 hostPDRHandler->setOemUtilsHandler(oemUtilsHandler.get());
Pavithra Barithayaaac7db32025-10-16 11:47:09 +053088 fruHandler->setOemPlatformHandler(oemPlatformHandler.get());
George Liua881c172021-06-21 18:28:11 +080089 platformHandler->setOemPlatformHandler(oemPlatformHandler.get());
90 baseHandler->setOemPlatformHandler(oemPlatformHandler.get());
Manojkiran Edaa31ceb92021-07-22 09:19:02 +053091 slotHandler->setOemPlatformHandler(oemPlatformHandler.get());
George Liua881c172021-06-21 18:28:11 +080092
93 createOemIbmPlatformHandler();
94 oemIbmPlatformHandler->setPlatformHandler(platformHandler);
95
George Liub49b7d82021-02-08 14:10:17 +080096 createHostLampTestHandler();
97
George Liua881c172021-06-21 18:28:11 +080098 registerHandler();
99 }
100
101 private:
102 /** @brief Method for creating codeUpdate handler */
103 void createCodeUpdate()
104 {
105 codeUpdate = std::make_unique<pldm::responder::CodeUpdate>(dBusIntf);
106 codeUpdate->clearDirPath(LID_STAGING_DIR);
107 }
108
Manojkiran Edaa31ceb92021-07-22 09:19:02 +0530109 /** @brief Method for creating slot handler */
110 void createSlotHandler()
111 {
112 slotHandler =
113 std::make_unique<pldm::responder::SlotHandler>(event, repo);
114 }
115
George Liua881c172021-06-21 18:28:11 +0800116 /** @brief Method for creating oemPlatformHandler
117 *
118 * This method also assigns the oemPlatformHandler to the below
119 * different handlers.
120 */
121 void createOemPlatformHandler()
122 {
Manojkiran Edaa31ceb92021-07-22 09:19:02 +0530123 oemPlatformHandler = std::make_unique<oem_ibm_platform::Handler>(
124 dBusIntf, codeUpdate.get(), slotHandler.get(), mctp_fd, mctp_eid,
125 instanceIdDb, event, reqHandler);
George Liua881c172021-06-21 18:28:11 +0800126 }
127
Archana Kakani97a0f482025-03-10 05:39:38 -0500128 /** @brief Method for creating oemIbmBiosHandler */
129 void createOemIbmBiosHandler()
130 {
131 oemIbmBiosHandler =
132 std::make_unique<responder::oem_ibm_bios::Handler>();
133 }
134
George Liua881c172021-06-21 18:28:11 +0800135 /** @brief Method for creating oemIbmPlatformHandler */
136 void createOemIbmPlatformHandler()
137 {
138 oemIbmPlatformHandler =
139 dynamic_cast<pldm::responder::oem_ibm_platform::Handler*>(
140 oemPlatformHandler.get());
141 }
142
143 /** @brief Method for creating oemFruHandler */
144 void createOemFruHandler()
145 {
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530146 oemFruHandler = std::make_unique<responder::oem_ibm_fru::Handler>(repo);
George Liua881c172021-06-21 18:28:11 +0800147 }
148
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500149 /** @brief Method for creating oemIbmUtilsHandler */
150 void createOemIbmUtilsHandler()
151 {
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530152 oemUtilsHandler =
153 std::make_unique<responder::oem_ibm_utils::Handler>(dBusIntf);
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500154 }
155
George Liua881c172021-06-21 18:28:11 +0800156 /** @brief Method for creating oemIbmFruHandler */
157 void createOemIbmFruHandler()
158 {
159 oemIbmFruHandler = dynamic_cast<pldm::responder::oem_ibm_fru::Handler*>(
160 oemFruHandler.get());
161 }
162
George Liub49b7d82021-02-08 14:10:17 +0800163 void createHostLampTestHandler()
164 {
165 auto& bus = pldm::utils::DBusHandler::getBus();
166 hostLampTest = std::make_unique<pldm::led::HostLampTest>(
167 bus, "/xyz/openbmc_project/led/groups/host_lamp_test", mctp_eid,
168 instanceIdDb, repo, reqHandler);
169 }
170
George Liua881c172021-06-21 18:28:11 +0800171 /** @brief Method for registering PLDM OEM handler */
172 void registerHandler()
173 {
174 invoker.registerHandler(
175 PLDM_OEM, std::make_unique<pldm::responder::oem_ibm::Handler>(
176 oemPlatformHandler.get(), mctp_fd, mctp_eid,
177 &instanceIdDb, reqHandler));
178 }
179
180 private:
181 /** @brief D-Bus handler */
182 const pldm::utils::DBusHandler* dBusIntf;
183
184 /** @brief fd of MCTP communications socket */
185 int mctp_fd;
186
187 /** @brief MCTP EID of remote host firmware */
188 uint8_t mctp_eid;
189
190 /** @brief pointer to BMC's primary PDR repo */
191 pldm_pdr* repo;
192
193 /** @brief reference to an Instance ID database object, used to obtain PLDM
194 * instance IDs
195 */
196 pldm::InstanceIdDb& instanceIdDb;
197
198 /** @brief reference of main event loop of pldmd, primarily used to schedule
199 * work
200 */
201 sdeventplus::Event& event;
202
203 /** @brief Object to the invoker class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530204 responder::Invoker& invoker;
George Liua881c172021-06-21 18:28:11 +0800205
206 /** @brief pointer to the requester class*/
207 requester::Handler<requester::Request>* reqHandler;
208
209 /** @brief pointer to the oem_ibm_handler class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530210 std::unique_ptr<responder::oem_platform::Handler> oemPlatformHandler{};
George Liua881c172021-06-21 18:28:11 +0800211
212 /** @brief pointer to the oem_ibm_fru class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530213 std::unique_ptr<responder::oem_fru::Handler> oemFruHandler{};
George Liua881c172021-06-21 18:28:11 +0800214
215 /** @brief pointer to the CodeUpdate class*/
216 std::unique_ptr<pldm::responder::CodeUpdate> codeUpdate{};
217
Manojkiran Edaa31ceb92021-07-22 09:19:02 +0530218 /** @brief pointer to the SlotHanlder class*/
219 std::unique_ptr<pldm::responder::SlotHandler> slotHandler{};
220
George Liua881c172021-06-21 18:28:11 +0800221 /** @brief oem IBM Platform handler*/
222 pldm::responder::oem_ibm_platform::Handler* oemIbmPlatformHandler = nullptr;
223
224 /** @brief oem IBM Fru handler*/
225 pldm::responder::oem_ibm_fru::Handler* oemIbmFruHandler = nullptr;
George Liub49b7d82021-02-08 14:10:17 +0800226
Archana Kakani97a0f482025-03-10 05:39:38 -0500227 /** @brief pointer to the oem IBM Bios handler*/
228 std::unique_ptr<responder::oem_bios::Handler> oemIbmBiosHandler{};
229
George Liub49b7d82021-02-08 14:10:17 +0800230 std::unique_ptr<pldm::led::HostLampTest> hostLampTest;
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500231
232 /** @brief oem IBM Utils handler*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530233 std::unique_ptr<responder::oem_utils::Handler> oemUtilsHandler;
George Liua881c172021-06-21 18:28:11 +0800234};
235
236} // namespace oem_ibm
237} // namespace pldm