blob: 8e8c30122ad0f07890c2ae270eeaccfd8f6cb776 [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);
Dung Cao72c8aa02023-11-22 02:31:41 +000066 createOemEventHandler(oemEventManager.get(), 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 */
Dung Cao72c8aa02023-11-22 02:31:41 +000075 void createOemEventHandler(oem_ampere::OemEventManager* oemEventManager,
76 platform_mc::Manager* platformManager)
Chau Lya743e382024-10-26 11:12:22 +000077 {
78 platformHandler->registerEventHandlers(
79 PLDM_SENSOR_EVENT,
Dung Cao72c8aa02023-11-22 02:31:41 +000080 {[oemEventManager](const pldm_msg* request, size_t payloadLength,
81 uint8_t formatVersion, uint8_t tid,
82 size_t eventDataOffset) {
Chau Lya743e382024-10-26 11:12:22 +000083 return oemEventManager->handleSensorEvent(
84 request, payloadLength, formatVersion, tid,
85 eventDataOffset);
86 }});
Dung Cao72c8aa02023-11-22 02:31:41 +000087
88 /* Register Ampere OEM handler to the PLDM CPER events */
89 platformManager->registerPolledEventHandler(
90 0xFA,
91 {[oemEventManager](pldm_tid_t tid, uint16_t eventId,
92 const uint8_t* eventData, size_t eventDataSize) {
93 return oemEventManager->processOemMsgPollEvent(
94 tid, eventId, eventData, eventDataSize);
95 }});
96 platformManager->registerPolledEventHandler(
97 PLDM_CPER_EVENT,
98 {[oemEventManager](pldm_tid_t tid, uint16_t eventId,
99 const uint8_t* eventData, size_t eventDataSize) {
100 return oemEventManager->processOemMsgPollEvent(
101 tid, eventId, eventData, eventDataSize);
102 }});
103
Thu Nguyen6894e902024-10-22 10:51:46 +0000104 /** CPEREvent class (0x07) is only available in DSP0248 V1.3.0.
105 * Before DSP0248 V1.3.0 spec, Ampere uses OEM event class 0xFA to
106 * report the CPER event
107 */
108 platformHandler->registerEventHandlers(
109 0xFA,
110 {[platformManager](const pldm_msg* request, size_t payloadLength,
111 uint8_t formatVersion, uint8_t tid,
112 size_t eventDataOffset) {
113 return platformManager->handleCperEvent(
114 request, payloadLength, formatVersion, tid,
115 eventDataOffset);
116 }});
117 /* Support handle the polled event with Ampere OEM CPER event class */
118 platformManager->registerPolledEventHandler(
119 0xFA,
Thu Nguyen6dce7d12024-11-19 00:18:22 +0000120 {[platformManager](pldm_tid_t tid, uint16_t eventId,
121 const uint8_t* eventData, size_t eventDataSize) {
Thu Nguyen6894e902024-10-22 10:51:46 +0000122 return platformManager->handlePolledCperEvent(
123 tid, eventId, eventData, eventDataSize);
Thu Nguyen6dce7d12024-11-19 00:18:22 +0000124 }});
Thu Nguyen79f9ff62024-11-22 03:36:27 +0000125
126 /* Register OEM handling for pldmMessagePollEvent */
127 platformHandler->registerEventHandlers(
128 PLDM_MESSAGE_POLL_EVENT,
129 {[oemEventManager](const pldm_msg* request, size_t payloadLength,
130 uint8_t formatVersion, uint8_t tid,
131 size_t eventDataOffset) {
132 return oemEventManager->handlepldmMessagePollEvent(
133 request, payloadLength, formatVersion, tid,
134 eventDataOffset);
135 }});
Chau Lya743e382024-10-26 11:12:22 +0000136 }
137
138 private:
139 /** @brief reference to an Instance ID database object, used to obtain PLDM
140 * instance IDs
141 */
142 pldm::InstanceIdDb& instanceIdDb;
143
144 /** @brief reference of main event loop of pldmd, primarily used to schedule
145 * work
146 */
147 sdeventplus::Event& event;
148
149 /** @brief Platform handler*/
150 responder::platform::Handler* platformHandler = nullptr;
151
Thu Nguyen6894e902024-10-22 10:51:46 +0000152 /** @brief MC Platform manager*/
153 platform_mc::Manager* platformManager = nullptr;
154
Chau Lya743e382024-10-26 11:12:22 +0000155 /** @brief pointer to the requester class*/
156 requester::Handler<requester::Request>* reqHandler = nullptr;
157
158 std::shared_ptr<oem_ampere::OemEventManager> oemEventManager{};
159};
160
161} // namespace oem_ampere
162} // namespace pldm