blob: e3fbddf5433b15e5bf3ac44eaef0289a9354b973 [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());
George Liua881c172021-06-21 18:28:11 +080088 platformHandler->setOemPlatformHandler(oemPlatformHandler.get());
89 baseHandler->setOemPlatformHandler(oemPlatformHandler.get());
Manojkiran Edaa31ceb92021-07-22 09:19:02 +053090 slotHandler->setOemPlatformHandler(oemPlatformHandler.get());
George Liua881c172021-06-21 18:28:11 +080091
92 createOemIbmPlatformHandler();
93 oemIbmPlatformHandler->setPlatformHandler(platformHandler);
94
George Liub49b7d82021-02-08 14:10:17 +080095 createHostLampTestHandler();
96
George Liua881c172021-06-21 18:28:11 +080097 registerHandler();
98 }
99
100 private:
101 /** @brief Method for creating codeUpdate handler */
102 void createCodeUpdate()
103 {
104 codeUpdate = std::make_unique<pldm::responder::CodeUpdate>(dBusIntf);
105 codeUpdate->clearDirPath(LID_STAGING_DIR);
106 }
107
Manojkiran Edaa31ceb92021-07-22 09:19:02 +0530108 /** @brief Method for creating slot handler */
109 void createSlotHandler()
110 {
111 slotHandler =
112 std::make_unique<pldm::responder::SlotHandler>(event, repo);
113 }
114
George Liua881c172021-06-21 18:28:11 +0800115 /** @brief Method for creating oemPlatformHandler
116 *
117 * This method also assigns the oemPlatformHandler to the below
118 * different handlers.
119 */
120 void createOemPlatformHandler()
121 {
Manojkiran Edaa31ceb92021-07-22 09:19:02 +0530122 oemPlatformHandler = std::make_unique<oem_ibm_platform::Handler>(
123 dBusIntf, codeUpdate.get(), slotHandler.get(), mctp_fd, mctp_eid,
124 instanceIdDb, event, reqHandler);
George Liua881c172021-06-21 18:28:11 +0800125 }
126
Archana Kakani97a0f482025-03-10 05:39:38 -0500127 /** @brief Method for creating oemIbmBiosHandler */
128 void createOemIbmBiosHandler()
129 {
130 oemIbmBiosHandler =
131 std::make_unique<responder::oem_ibm_bios::Handler>();
132 }
133
George Liua881c172021-06-21 18:28:11 +0800134 /** @brief Method for creating oemIbmPlatformHandler */
135 void createOemIbmPlatformHandler()
136 {
137 oemIbmPlatformHandler =
138 dynamic_cast<pldm::responder::oem_ibm_platform::Handler*>(
139 oemPlatformHandler.get());
140 }
141
142 /** @brief Method for creating oemFruHandler */
143 void createOemFruHandler()
144 {
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530145 oemFruHandler = std::make_unique<responder::oem_ibm_fru::Handler>(repo);
George Liua881c172021-06-21 18:28:11 +0800146 }
147
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500148 /** @brief Method for creating oemIbmUtilsHandler */
149 void createOemIbmUtilsHandler()
150 {
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530151 oemUtilsHandler =
152 std::make_unique<responder::oem_ibm_utils::Handler>(dBusIntf);
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500153 }
154
George Liua881c172021-06-21 18:28:11 +0800155 /** @brief Method for creating oemIbmFruHandler */
156 void createOemIbmFruHandler()
157 {
158 oemIbmFruHandler = dynamic_cast<pldm::responder::oem_ibm_fru::Handler*>(
159 oemFruHandler.get());
160 }
161
George Liub49b7d82021-02-08 14:10:17 +0800162 void createHostLampTestHandler()
163 {
164 auto& bus = pldm::utils::DBusHandler::getBus();
165 hostLampTest = std::make_unique<pldm::led::HostLampTest>(
166 bus, "/xyz/openbmc_project/led/groups/host_lamp_test", mctp_eid,
167 instanceIdDb, repo, reqHandler);
168 }
169
George Liua881c172021-06-21 18:28:11 +0800170 /** @brief Method for registering PLDM OEM handler */
171 void registerHandler()
172 {
173 invoker.registerHandler(
174 PLDM_OEM, std::make_unique<pldm::responder::oem_ibm::Handler>(
175 oemPlatformHandler.get(), mctp_fd, mctp_eid,
176 &instanceIdDb, reqHandler));
177 }
178
179 private:
180 /** @brief D-Bus handler */
181 const pldm::utils::DBusHandler* dBusIntf;
182
183 /** @brief fd of MCTP communications socket */
184 int mctp_fd;
185
186 /** @brief MCTP EID of remote host firmware */
187 uint8_t mctp_eid;
188
189 /** @brief pointer to BMC's primary PDR repo */
190 pldm_pdr* repo;
191
192 /** @brief reference to an Instance ID database object, used to obtain PLDM
193 * instance IDs
194 */
195 pldm::InstanceIdDb& instanceIdDb;
196
197 /** @brief reference of main event loop of pldmd, primarily used to schedule
198 * work
199 */
200 sdeventplus::Event& event;
201
202 /** @brief Object to the invoker class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530203 responder::Invoker& invoker;
George Liua881c172021-06-21 18:28:11 +0800204
205 /** @brief pointer to the requester class*/
206 requester::Handler<requester::Request>* reqHandler;
207
208 /** @brief pointer to the oem_ibm_handler class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530209 std::unique_ptr<responder::oem_platform::Handler> oemPlatformHandler{};
George Liua881c172021-06-21 18:28:11 +0800210
211 /** @brief pointer to the oem_ibm_fru class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530212 std::unique_ptr<responder::oem_fru::Handler> oemFruHandler{};
George Liua881c172021-06-21 18:28:11 +0800213
214 /** @brief pointer to the CodeUpdate class*/
215 std::unique_ptr<pldm::responder::CodeUpdate> codeUpdate{};
216
Manojkiran Edaa31ceb92021-07-22 09:19:02 +0530217 /** @brief pointer to the SlotHanlder class*/
218 std::unique_ptr<pldm::responder::SlotHandler> slotHandler{};
219
George Liua881c172021-06-21 18:28:11 +0800220 /** @brief oem IBM Platform handler*/
221 pldm::responder::oem_ibm_platform::Handler* oemIbmPlatformHandler = nullptr;
222
223 /** @brief oem IBM Fru handler*/
224 pldm::responder::oem_ibm_fru::Handler* oemIbmFruHandler = nullptr;
George Liub49b7d82021-02-08 14:10:17 +0800225
Archana Kakani97a0f482025-03-10 05:39:38 -0500226 /** @brief pointer to the oem IBM Bios handler*/
227 std::unique_ptr<responder::oem_bios::Handler> oemIbmBiosHandler{};
228
George Liub49b7d82021-02-08 14:10:17 +0800229 std::unique_ptr<pldm::led::HostLampTest> hostLampTest;
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500230
231 /** @brief oem IBM Utils handler*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530232 std::unique_ptr<responder::oem_utils::Handler> oemUtilsHandler;
George Liua881c172021-06-21 18:28:11 +0800233};
234
235} // namespace oem_ibm
236} // namespace pldm