1 #pragma once
2 
3 #include "libpldm/pldm.h"
4 
5 #include "common/instance_id.hpp"
6 #include "common/types.hpp"
7 #include "oem_event_manager.hpp"
8 #include "platform-mc/manager.hpp"
9 #include "requester/handler.hpp"
10 #include "requester/request.hpp"
11 
12 namespace pldm
13 {
14 namespace oem_ampere
15 {
16 using namespace pldm::pdr;
17 
18 using EventToMsgMap_t = std::unordered_map<uint8_t, std::string>;
19 
20 enum sensor_ids
21 {
22     BOOT_OVERALL = 175,
23 };
24 
25 namespace boot
26 {
27 namespace status
28 {
29 enum boot_status
30 {
31     BOOT_STATUS_SUCCESS = 0x80,
32     BOOT_STATUS_FAILURE = 0x81,
33 };
34 } // namespace status
35 namespace stage
36 {
37 enum boot_stage
38 {
39     UEFI_STATUS_CLASS_CODE_MIN = 0x00,
40     UEFI_STATUS_CLASS_CODE_MAX = 0x7f,
41     SECPRO = 0x90,
42     MPRO = 0x91,
43     ATF_BL1 = 0x92,
44     ATF_BL2 = 0x93,
45     DDR_INITIALIZATION = 0x94,
46     DDR_TRAINING = 0x95,
47     S0_DDR_TRAINING_FAILURE = 0x96,
48     ATF_BL31 = 0x97,
49     ATF_BL32 = 0x98,
50     S1_DDR_TRAINING_FAILURE = 0x99,
51 };
52 } // namespace stage
53 } // namespace boot
54 
55 enum class log_level : int
56 {
57     OK,
58     BIOSFWPANIC,
59 };
60 
61 /**
62  * @brief OemEventManager
63  *
64  *
65  */
66 class OemEventManager
67 {
68   public:
69     OemEventManager() = delete;
70     OemEventManager(const OemEventManager&) = delete;
71     OemEventManager(OemEventManager&&) = delete;
72     OemEventManager& operator=(const OemEventManager&) = delete;
73     OemEventManager& operator=(OemEventManager&&) = delete;
74     virtual ~OemEventManager() = default;
75 
OemEventManager(sdeventplus::Event & event,requester::Handler<requester::Request> *,pldm::InstanceIdDb &)76     explicit OemEventManager(
77         sdeventplus::Event& event,
78         requester::Handler<requester::Request>* /* handler */,
79         pldm::InstanceIdDb& /* instanceIdDb */) : event(event) {};
80 
81     /** @brief Decode sensor event messages and handle correspondingly.
82      *
83      *  @param[in] request - the request message of sensor event
84      *  @param[in] payloadLength - the payload length of sensor event
85      *  @param[in] formatVersion - the format version of sensor event
86      *  @param[in] tid - TID
87      *  @param[in] eventDataOffset - the event data offset of sensor event
88      *
89      *  @return int - returned error code
90      */
91     int handleSensorEvent(const pldm_msg* request, size_t payloadLength,
92                           uint8_t /* formatVersion */, pldm_tid_t tid,
93                           size_t eventDataOffset);
94 
95   protected:
96     /** @brief Create prefix string for logging message.
97      *
98      *  @param[in] tid - TID
99      *  @param[in] sensorId - Sensor ID
100      *
101      *  @return std::string - the prefeix string
102      */
103     std::string prefixMsgStrCreation(pldm_tid_t tid, uint16_t sensorId);
104 
105     /** @brief Log the message into Redfish SEL.
106      *
107      *  @param[in] description - the logging message
108      *  @param[in] logLevel - the logging level
109      */
110     void sendJournalRedfish(const std::string& description,
111                             log_level& logLevel);
112 
113     /** @brief Convert the one-hot DIMM index byte into a string of DIMM
114      * indexes.
115      *
116      *  @param[in] dimmIdxs - the one-hot DIMM index byte
117      *
118      *  @return std::string - the string of DIMM indexes
119      */
120     std::string dimmIdxsToString(uint32_t dimmIdxs);
121 
122     /** @brief Handle numeric sensor event message from boot overall sensor.
123      *
124      *  @param[in] tid - TID
125      *  @param[in] sensorId - Sensor ID
126      *  @param[in] presentReading - the present reading of the sensor
127      */
128     void handleBootOverallEvent(pldm_tid_t /*tid*/, uint16_t /*sensorId*/,
129                                 uint32_t presentReading);
130 
131     /** @brief Handle numeric sensor event messages.
132      *
133      *  @param[in] tid - TID
134      *  @param[in] sensorId - Sensor ID
135      *  @param[in] sensorData - the sensor data
136      *  @param[in] sensorDataLength - the length of sensor data
137      *
138      *  @return int - returned error code
139      */
140     int processNumericSensorEvent(pldm_tid_t tid, uint16_t sensorId,
141                                   const uint8_t* sensorData,
142                                   size_t sensorDataLength);
143 
144     /** @brief Handle state sensor event messages.
145      *
146      *  @param[in] tid - TID
147      *  @param[in] sensorId - Sensor ID
148      *  @param[in] sensorData - the sensor data
149      *  @param[in] sensorDataLength - the length of sensor data
150      *
151      *  @return int - returned error code
152      */
153     int processStateSensorEvent(pldm_tid_t tid, uint16_t sensorId,
154                                 const uint8_t* sensorData,
155                                 size_t sensorDataLength);
156 
157     /** @brief Handle op state sensor event messages.
158      *
159      *  @param[in] tid - TID
160      *  @param[in] sensorId - Sensor ID
161      *  @param[in] sensorData - the sensor data
162      *  @param[in] sensorDataLength - the length of sensor data
163      *
164      *  @return int - returned error code
165      */
166     int processSensorOpStateEvent(pldm_tid_t tid, uint16_t sensorId,
167                                   const uint8_t* sensorData,
168                                   size_t sensorDataLength);
169 
170     /** @brief reference of main event loop of pldmd, primarily used to schedule
171      *  work
172      */
173     sdeventplus::Event& event;
174 };
175 } // namespace oem_ampere
176 } // namespace pldm
177