Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 3 | #include "additional_data.hpp" |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 4 | #include "private_header.hpp" |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 5 | #include "registry.hpp" |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 6 | #include "user_header.hpp" |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <vector> |
| 10 | |
| 11 | namespace openpower |
| 12 | { |
| 13 | namespace pels |
| 14 | { |
| 15 | |
| 16 | /** @class PEL |
| 17 | * |
| 18 | * @brief This class represents a specific event log format referred to as a |
| 19 | * Platform Event Log. |
| 20 | * |
| 21 | * Every field in a PEL are in structures call sections, of which there are |
| 22 | * several types. Some sections are required, and some are optional. In some |
| 23 | * cases there may be more than one instance of a section type. |
| 24 | * |
| 25 | * The only two required sections for every type of PEL are the Private Header |
| 26 | * section and User Header section, which must be in the first and second |
| 27 | * positions, respectively. |
| 28 | * |
| 29 | * Every section starts with an 8 byte section header, which has the section |
| 30 | * size and type, among other things. |
| 31 | * |
| 32 | * This class represents all sections with objects. |
| 33 | * |
| 34 | * The available constructors are: |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 35 | * - PEL(std::vector<uint8_t>& data) - build this object out of a fully |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 36 | * formed flattened PEL. |
| 37 | * |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 38 | * - PEL(const openpower::pels::message::Entry& entry, |
| 39 | * uint32_t obmcLogID, |
| 40 | * uint64_t timestamp, |
| 41 | * phosphor::logging::Entry::Level severity) |
| 42 | * - build this object from an OpenBMC event log. |
| 43 | * |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 44 | * The data() method allows one to retrieve the PEL as a vector<uint8_t>. This |
| 45 | * is the format in which it is stored and transmitted. |
| 46 | */ |
| 47 | class PEL |
| 48 | { |
| 49 | public: |
| 50 | PEL() = delete; |
| 51 | ~PEL() = default; |
| 52 | PEL(const PEL&) = delete; |
| 53 | PEL& operator=(const PEL&) = delete; |
| 54 | PEL(PEL&&) = delete; |
| 55 | PEL& operator=(PEL&&) = delete; |
| 56 | |
| 57 | /** |
| 58 | * @brief Constructor |
| 59 | * |
| 60 | * Build a PEL from raw data. |
| 61 | * |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 62 | * Note: Neither this nor the following constructor can take a const vector& |
| 63 | * because the Stream class that is used to read from the vector cannot take |
| 64 | * a const. The alternative is to make a copy of the data, but as PELs can |
| 65 | * be up to 16KB that is undesireable. |
| 66 | * |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 67 | * @param[in] data - The PEL data |
| 68 | */ |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 69 | PEL(std::vector<uint8_t>& data); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * @brief Constructor |
| 73 | * |
| 74 | * Build a PEL from the raw data. |
| 75 | * |
| 76 | * @param[in] data - the PEL data |
| 77 | * @param[in] obmcLogID - the corresponding OpenBMC event log ID |
| 78 | */ |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 79 | PEL(std::vector<uint8_t>& data, uint32_t obmcLogID); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 80 | |
| 81 | /** |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 82 | * @brief Constructor |
| 83 | * |
| 84 | * Creates a PEL from an OpenBMC event log and its message |
| 85 | * registry entry. |
| 86 | * |
| 87 | * @param[in] entry - The message registry entry for this error |
| 88 | * @param[in] obmcLogID - ID of corresponding OpenBMC event log |
| 89 | * @param[in] timestamp - Timestamp from the event log |
| 90 | * @param[in] severity - Severity from the event log |
| 91 | */ |
| 92 | PEL(const openpower::pels::message::Entry& entry, uint32_t obmcLogID, |
| 93 | uint64_t timestamp, phosphor::logging::Entry::Level severity); |
| 94 | |
| 95 | /** |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 96 | * @brief Convenience function to return the log ID field from the |
| 97 | * Private Header section. |
| 98 | * |
| 99 | * @return uint32_t - the ID |
| 100 | */ |
| 101 | uint32_t id() const |
| 102 | { |
| 103 | return _ph->id(); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @brief Convenience function to return the PLID field from the |
| 108 | * Private Header section. |
| 109 | * |
| 110 | * @return uint32_t - the PLID |
| 111 | */ |
| 112 | uint32_t plid() const |
| 113 | { |
| 114 | return _ph->plid(); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * @brief Convenience function to return the OpenBMC event log ID field |
| 119 | * from the Private Header section. |
| 120 | * |
| 121 | * @return uint32_t - the OpenBMC event log ID |
| 122 | */ |
| 123 | uint32_t obmcLogID() const |
| 124 | { |
| 125 | return _ph->obmcLogID(); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * @brief Convenience function to return the commit time field from |
| 130 | * the Private Header section. |
| 131 | * |
| 132 | * @return BCDTime - the timestamp |
| 133 | */ |
| 134 | BCDTime commitTime() const |
| 135 | { |
| 136 | return _ph->commitTimestamp(); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * @brief Convenience function to return the create time field from |
| 141 | * the Private Header section. |
| 142 | * |
| 143 | * @return BCDTime - the timestamp |
| 144 | */ |
| 145 | BCDTime createTime() const |
| 146 | { |
| 147 | return _ph->createTimestamp(); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * @brief Gives access to the Private Header section class |
| 152 | * |
| 153 | * @return std::unique_ptr<PrivateHeader>& the private header |
| 154 | */ |
| 155 | std::unique_ptr<PrivateHeader>& privateHeader() |
| 156 | { |
| 157 | return _ph; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * @brief Gives access to the User Header section class |
| 162 | * |
| 163 | * @return std::unique_ptr<UserHeader>& the user header |
| 164 | */ |
| 165 | std::unique_ptr<UserHeader>& userHeader() |
| 166 | { |
| 167 | return _uh; |
| 168 | } |
| 169 | |
| 170 | /** |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 171 | * @brief Returns the optional sections, which is everything but |
| 172 | * the Private and User Headers. |
| 173 | * |
| 174 | * @return const std::vector<std::unique_ptr<Section>>& |
| 175 | */ |
| 176 | const std::vector<std::unique_ptr<Section>>& optionalSections() const |
| 177 | { |
| 178 | return _optionalSections; |
| 179 | } |
| 180 | |
| 181 | /** |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 182 | * @brief Returns the PEL data. |
| 183 | * |
| 184 | * @return std::vector<uint8_t> - the raw PEL data |
| 185 | */ |
| 186 | std::vector<uint8_t> data(); |
| 187 | |
| 188 | /** |
| 189 | * @brief Says if the PEL is valid (the sections are all valid) |
| 190 | * |
| 191 | * @return bool - if the PEL is valid |
| 192 | */ |
| 193 | bool valid() const; |
| 194 | |
| 195 | /** |
| 196 | * @brief Sets the commit timestamp to the current time |
| 197 | */ |
| 198 | void setCommitTime(); |
| 199 | |
| 200 | /** |
| 201 | * @brief Sets the error log ID field to a unique ID. |
| 202 | */ |
| 203 | void assignID(); |
| 204 | |
| 205 | private: |
| 206 | /** |
| 207 | * @brief Builds the section objects from a PEL data buffer |
| 208 | * |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 209 | * Note: The data parameter cannot be const for the same reasons |
| 210 | * as listed in the constructor. |
| 211 | * |
| 212 | * @param[in] data - The PEL data |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 213 | * @param[in] obmcLogID - The OpenBMC event log ID to use for that |
| 214 | * field in the Private Header. |
| 215 | */ |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 216 | void populateFromRawData(std::vector<uint8_t>& data, uint32_t obmcLogID); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 217 | |
| 218 | /** |
| 219 | * @brief Flattens the PEL objects into the buffer |
| 220 | * |
| 221 | * @param[out] pelBuffer - What the data will be written to |
| 222 | */ |
| 223 | void flatten(std::vector<uint8_t>& pelBuffer); |
| 224 | |
| 225 | /** |
| 226 | * @brief The PEL Private Header section |
| 227 | */ |
| 228 | std::unique_ptr<PrivateHeader> _ph; |
| 229 | |
| 230 | /** |
| 231 | * @brief The PEL User Header section |
| 232 | */ |
| 233 | std::unique_ptr<UserHeader> _uh; |
| 234 | |
| 235 | /** |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 236 | * @brief Holds all sections by the PH and UH. |
| 237 | */ |
| 238 | std::vector<std::unique_ptr<Section>> _optionalSections; |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | } // namespace pels |
| 242 | } // namespace openpower |