blob: 8fb926e11fc710bbda0833f79b7d214365c1efe4 [file] [log] [blame]
Chau Lya743e382024-10-26 11:12:22 +00001#pragma once
2#include "../../common/utils.hpp"
3#include "../../libpldmresponder/base.hpp"
4#include "../../libpldmresponder/bios.hpp"
5#include "../../libpldmresponder/fru.hpp"
6#include "../../libpldmresponder/platform.hpp"
7#include "../../oem/ampere/event/oem_event_manager.hpp"
8#include "../../platform-mc/manager.hpp"
9#include "../../pldmd/invoker.hpp"
10#include "../../requester/request.hpp"
11
12namespace pldm
13{
14namespace oem_ampere
15{
16
17/**
18 * @class OemAMPERE
19 *
20 * @brief class for creating all the OEM AMPERE handlers
21 *
22 * Only in case of OEM_AMPERE this class object will be instantiated
23 */
24class OemAMPERE
25{
26 public:
27 OemAMPERE() = delete;
28 OemAMPERE& operator=(const OemAMPERE&) = delete;
29 OemAMPERE(OemAMPERE&&) = delete;
30 OemAMPERE& operator=(OemAMPERE&&) = delete;
31
32 public:
33 /** Constructs OemAMPERE object
34 *
35 * @param[in] dBusIntf - D-Bus handler
36 * @param[in] mctp_fd - fd of MCTP communications socket
37 * @param[in] mctp_eid - MCTP EID of remote host firmware
38 * @param[in] repo - pointer to BMC's primary PDR repo
39 * @param[in] instanceIdDb - pointer to an InstanceIdDb object
40 * @param[in] event - sd_event handler
41 * @param[in] invoker - invoker handler
42 * @param[in] hostPDRHandler - hostPDRHandler handler
43 * @param[in] platformHandler - platformHandler handler
44 * @param[in] fruHandler - fruHandler handler
45 * @param[in] baseHandler - baseHandler handler
46 * @param[in] biosHandler - biosHandler handler
47 * @param[in] reqHandler - reqHandler handler
48 */
49 explicit OemAMPERE(
50 const pldm::utils::DBusHandler* /* dBusIntf */, int /* mctp_fd */,
51 pldm_pdr* /* repo */, pldm::InstanceIdDb& instanceIdDb,
52 sdeventplus::Event& event, responder::Invoker& /* invoker */,
53 HostPDRHandler* /* hostPDRHandler */,
54 responder::platform::Handler* platformHandler,
55 responder::fru::Handler* /* fruHandler */,
56 responder::base::Handler* /* baseHandler */,
57 responder::bios::Handler* /* biosHandler */,
Thu Nguyen6894e902024-10-22 10:51:46 +000058 platform_mc::Manager* platformManager,
Chau Lya743e382024-10-26 11:12:22 +000059 pldm::requester::Handler<pldm::requester::Request>* reqHandler) :
60 instanceIdDb(instanceIdDb), event(event),
Thu Nguyen6894e902024-10-22 10:51:46 +000061 platformHandler(platformHandler), platformManager(platformManager),
62 reqHandler(reqHandler)
Chau Lya743e382024-10-26 11:12:22 +000063 {
64 oemEventManager = std::make_shared<oem_ampere::OemEventManager>(
65 this->event, this->reqHandler, this->instanceIdDb);
Thu Nguyen6894e902024-10-22 10:51:46 +000066 createOemEventHandler(oemEventManager, this->platformManager);
Chau Lya743e382024-10-26 11:12:22 +000067 }
68
69 private:
70 /** @brief Method for creating OemEventManager
71 *
72 * This method also assigns the OemEventManager to the below
73 * different handlers.
74 */
75 void createOemEventHandler(
Thu Nguyen6894e902024-10-22 10:51:46 +000076 std::shared_ptr<oem_ampere::OemEventManager> oemEventManager,
77 platform_mc::Manager* platformManager)
Chau Lya743e382024-10-26 11:12:22 +000078 {
79 platformHandler->registerEventHandlers(
80 PLDM_SENSOR_EVENT,
81 {[&oemEventManager](const pldm_msg* request, size_t payloadLength,
82 uint8_t formatVersion, uint8_t tid,
83 size_t eventDataOffset) {
84 return oemEventManager->handleSensorEvent(
85 request, payloadLength, formatVersion, tid,
86 eventDataOffset);
87 }});
Thu Nguyen6894e902024-10-22 10:51:46 +000088 /** CPEREvent class (0x07) is only available in DSP0248 V1.3.0.
89 * Before DSP0248 V1.3.0 spec, Ampere uses OEM event class 0xFA to
90 * report the CPER event
91 */
92 platformHandler->registerEventHandlers(
93 0xFA,
94 {[platformManager](const pldm_msg* request, size_t payloadLength,
95 uint8_t formatVersion, uint8_t tid,
96 size_t eventDataOffset) {
97 return platformManager->handleCperEvent(
98 request, payloadLength, formatVersion, tid,
99 eventDataOffset);
100 }});
101 /* Support handle the polled event with Ampere OEM CPER event class */
102 platformManager->registerPolledEventHandler(
103 0xFA,
104 [platformManager](pldm_tid_t tid, uint16_t eventId,
105 const uint8_t* eventData, size_t eventDataSize) {
106 return platformManager->handlePolledCperEvent(
107 tid, eventId, eventData, eventDataSize);
108 });
Chau Lya743e382024-10-26 11:12:22 +0000109 }
110
111 private:
112 /** @brief reference to an Instance ID database object, used to obtain PLDM
113 * instance IDs
114 */
115 pldm::InstanceIdDb& instanceIdDb;
116
117 /** @brief reference of main event loop of pldmd, primarily used to schedule
118 * work
119 */
120 sdeventplus::Event& event;
121
122 /** @brief Platform handler*/
123 responder::platform::Handler* platformHandler = nullptr;
124
Thu Nguyen6894e902024-10-22 10:51:46 +0000125 /** @brief MC Platform manager*/
126 platform_mc::Manager* platformManager = nullptr;
127
Chau Lya743e382024-10-26 11:12:22 +0000128 /** @brief pointer to the requester class*/
129 requester::Handler<requester::Request>* reqHandler = nullptr;
130
131 std::shared_ptr<oem_ampere::OemEventManager> oemEventManager{};
132};
133
134} // namespace oem_ampere
135} // namespace pldm