Chau Ly | a743e38 | 2024-10-26 11:12:22 +0000 | [diff] [blame] | 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 | { |
Chau Ly | 3de0d94 | 2024-10-03 08:57:11 +0000 | [diff] [blame^] | 22 | PCIE_HOT_PLUG = 169, |
Chau Ly | a743e38 | 2024-10-26 11:12:22 +0000 | [diff] [blame] | 23 | BOOT_OVERALL = 175, |
| 24 | }; |
| 25 | |
| 26 | namespace boot |
| 27 | { |
| 28 | namespace status |
| 29 | { |
| 30 | enum boot_status |
| 31 | { |
| 32 | BOOT_STATUS_SUCCESS = 0x80, |
| 33 | BOOT_STATUS_FAILURE = 0x81, |
| 34 | }; |
| 35 | } // namespace status |
| 36 | namespace stage |
| 37 | { |
| 38 | enum boot_stage |
| 39 | { |
| 40 | UEFI_STATUS_CLASS_CODE_MIN = 0x00, |
| 41 | UEFI_STATUS_CLASS_CODE_MAX = 0x7f, |
| 42 | SECPRO = 0x90, |
| 43 | MPRO = 0x91, |
| 44 | ATF_BL1 = 0x92, |
| 45 | ATF_BL2 = 0x93, |
| 46 | DDR_INITIALIZATION = 0x94, |
| 47 | DDR_TRAINING = 0x95, |
| 48 | S0_DDR_TRAINING_FAILURE = 0x96, |
| 49 | ATF_BL31 = 0x97, |
| 50 | ATF_BL32 = 0x98, |
| 51 | S1_DDR_TRAINING_FAILURE = 0x99, |
| 52 | }; |
| 53 | } // namespace stage |
| 54 | } // namespace boot |
| 55 | |
| 56 | enum class log_level : int |
| 57 | { |
| 58 | OK, |
Chau Ly | 3de0d94 | 2024-10-03 08:57:11 +0000 | [diff] [blame^] | 59 | WARNING, |
| 60 | CRITICAL, |
Chau Ly | a743e38 | 2024-10-26 11:12:22 +0000 | [diff] [blame] | 61 | BIOSFWPANIC, |
| 62 | }; |
| 63 | |
Chau Ly | 3de0d94 | 2024-10-03 08:57:11 +0000 | [diff] [blame^] | 64 | /* |
| 65 | * PresentReading value format |
| 66 | * FIELD | COMMENT |
| 67 | * Bit 31 | Reserved |
| 68 | * Bit 30:24 | Media slot number (0 - 63) This field can be used by UEFI |
| 69 | * | to indicate the media slot number (such as NVMe/SSD slot) |
| 70 | * | (7 bits) |
| 71 | * Bit 23 | Operation status: 1 = operation failed |
| 72 | * | 0 = operation successful |
| 73 | * Bit 22 | Action: 0 - Insertion 1 - Removal |
| 74 | * Bit 21:18 | Function (4 bits) |
| 75 | * Bit 17:13 | Device (5 bits) |
| 76 | * Bit 12:5 | Bus (8 bits) |
| 77 | * Bit 4:0 | Segment (5 bits) |
| 78 | */ |
| 79 | typedef union |
| 80 | { |
| 81 | uint32_t value; |
| 82 | struct |
| 83 | { |
| 84 | uint32_t segment:5; |
| 85 | uint32_t bus:8; |
| 86 | uint32_t device:5; |
| 87 | uint32_t function:4; |
| 88 | uint32_t action:1; |
| 89 | uint32_t opStatus:1; |
| 90 | uint32_t mediaSlot:7; |
| 91 | uint32_t reserved:1; |
| 92 | } __attribute__((packed)) bits; |
| 93 | } PCIeHotPlugEventRecord_t; |
| 94 | |
Chau Ly | a743e38 | 2024-10-26 11:12:22 +0000 | [diff] [blame] | 95 | /** |
| 96 | * @brief OemEventManager |
| 97 | * |
| 98 | * |
| 99 | */ |
| 100 | class OemEventManager |
| 101 | { |
| 102 | public: |
| 103 | OemEventManager() = delete; |
| 104 | OemEventManager(const OemEventManager&) = delete; |
| 105 | OemEventManager(OemEventManager&&) = delete; |
| 106 | OemEventManager& operator=(const OemEventManager&) = delete; |
| 107 | OemEventManager& operator=(OemEventManager&&) = delete; |
| 108 | virtual ~OemEventManager() = default; |
| 109 | |
| 110 | explicit OemEventManager( |
| 111 | sdeventplus::Event& event, |
| 112 | requester::Handler<requester::Request>* /* handler */, |
| 113 | pldm::InstanceIdDb& /* instanceIdDb */) : event(event) {}; |
| 114 | |
| 115 | /** @brief Decode sensor event messages and handle correspondingly. |
| 116 | * |
| 117 | * @param[in] request - the request message of sensor event |
| 118 | * @param[in] payloadLength - the payload length of sensor event |
| 119 | * @param[in] formatVersion - the format version of sensor event |
| 120 | * @param[in] tid - TID |
| 121 | * @param[in] eventDataOffset - the event data offset of sensor event |
| 122 | * |
| 123 | * @return int - returned error code |
| 124 | */ |
| 125 | int handleSensorEvent(const pldm_msg* request, size_t payloadLength, |
| 126 | uint8_t /* formatVersion */, pldm_tid_t tid, |
| 127 | size_t eventDataOffset); |
| 128 | |
| 129 | protected: |
| 130 | /** @brief Create prefix string for logging message. |
| 131 | * |
| 132 | * @param[in] tid - TID |
| 133 | * @param[in] sensorId - Sensor ID |
| 134 | * |
| 135 | * @return std::string - the prefeix string |
| 136 | */ |
| 137 | std::string prefixMsgStrCreation(pldm_tid_t tid, uint16_t sensorId); |
| 138 | |
| 139 | /** @brief Log the message into Redfish SEL. |
| 140 | * |
| 141 | * @param[in] description - the logging message |
| 142 | * @param[in] logLevel - the logging level |
| 143 | */ |
| 144 | void sendJournalRedfish(const std::string& description, |
| 145 | log_level& logLevel); |
| 146 | |
| 147 | /** @brief Convert the one-hot DIMM index byte into a string of DIMM |
| 148 | * indexes. |
| 149 | * |
| 150 | * @param[in] dimmIdxs - the one-hot DIMM index byte |
| 151 | * |
| 152 | * @return std::string - the string of DIMM indexes |
| 153 | */ |
| 154 | std::string dimmIdxsToString(uint32_t dimmIdxs); |
| 155 | |
Chau Ly | 3de0d94 | 2024-10-03 08:57:11 +0000 | [diff] [blame^] | 156 | /** @brief Handle numeric sensor event message from PCIe hot-plug sensor. |
| 157 | * |
| 158 | * @param[in] tid - TID |
| 159 | * @param[in] sensorId - Sensor ID |
| 160 | * @param[in] presentReading - the present reading of the sensor |
| 161 | */ |
| 162 | void handlePCIeHotPlugEvent(pldm_tid_t tid, uint16_t sensorId, |
| 163 | uint32_t presentReading); |
| 164 | |
Chau Ly | a743e38 | 2024-10-26 11:12:22 +0000 | [diff] [blame] | 165 | /** @brief Handle numeric sensor event message from boot overall sensor. |
| 166 | * |
| 167 | * @param[in] tid - TID |
| 168 | * @param[in] sensorId - Sensor ID |
| 169 | * @param[in] presentReading - the present reading of the sensor |
| 170 | */ |
| 171 | void handleBootOverallEvent(pldm_tid_t /*tid*/, uint16_t /*sensorId*/, |
| 172 | uint32_t presentReading); |
| 173 | |
| 174 | /** @brief Handle numeric sensor event messages. |
| 175 | * |
| 176 | * @param[in] tid - TID |
| 177 | * @param[in] sensorId - Sensor ID |
| 178 | * @param[in] sensorData - the sensor data |
| 179 | * @param[in] sensorDataLength - the length of sensor data |
| 180 | * |
| 181 | * @return int - returned error code |
| 182 | */ |
| 183 | int processNumericSensorEvent(pldm_tid_t tid, uint16_t sensorId, |
| 184 | const uint8_t* sensorData, |
| 185 | size_t sensorDataLength); |
| 186 | |
| 187 | /** @brief Handle state sensor event messages. |
| 188 | * |
| 189 | * @param[in] tid - TID |
| 190 | * @param[in] sensorId - Sensor ID |
| 191 | * @param[in] sensorData - the sensor data |
| 192 | * @param[in] sensorDataLength - the length of sensor data |
| 193 | * |
| 194 | * @return int - returned error code |
| 195 | */ |
| 196 | int processStateSensorEvent(pldm_tid_t tid, uint16_t sensorId, |
| 197 | const uint8_t* sensorData, |
| 198 | size_t sensorDataLength); |
| 199 | |
| 200 | /** @brief Handle op state sensor event messages. |
| 201 | * |
| 202 | * @param[in] tid - TID |
| 203 | * @param[in] sensorId - Sensor ID |
| 204 | * @param[in] sensorData - the sensor data |
| 205 | * @param[in] sensorDataLength - the length of sensor data |
| 206 | * |
| 207 | * @return int - returned error code |
| 208 | */ |
| 209 | int processSensorOpStateEvent(pldm_tid_t tid, uint16_t sensorId, |
| 210 | const uint8_t* sensorData, |
| 211 | size_t sensorDataLength); |
| 212 | |
| 213 | /** @brief reference of main event loop of pldmd, primarily used to schedule |
| 214 | * work |
| 215 | */ |
| 216 | sdeventplus::Event& event; |
| 217 | }; |
| 218 | } // namespace oem_ampere |
| 219 | } // namespace pldm |