Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "bcd_time.hpp" |
| 4 | #include "section.hpp" |
| 5 | #include "stream.hpp" |
| 6 | |
| 7 | namespace openpower |
| 8 | { |
| 9 | namespace pels |
| 10 | { |
| 11 | |
| 12 | struct CreatorVersion |
| 13 | { |
| 14 | uint8_t version[8]; |
Matt Spinler | 289aa47 | 2019-09-20 12:33:29 -0500 | [diff] [blame] | 15 | |
| 16 | CreatorVersion() |
| 17 | { |
| 18 | memset(version, '\0', sizeof(version)); |
| 19 | } |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 20 | }; |
| 21 | |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 22 | static constexpr uint8_t privateHeaderVersion = 0x01; |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 23 | static constexpr uint8_t minSectionCount = 2; |
| 24 | |
| 25 | /** |
| 26 | * @class PrivateHeader |
| 27 | * |
| 28 | * This represents the Private Header section in a PEL. It is required, |
| 29 | * and it is always the first section. |
| 30 | * |
| 31 | * The Section base class handles the section header structure that every |
| 32 | * PEL section has at offset zero. |
| 33 | * |
| 34 | * The fields in this class directly correspond to the order and sizes of |
| 35 | * the fields in the section. |
| 36 | */ |
| 37 | class PrivateHeader : public Section |
| 38 | { |
| 39 | public: |
| 40 | PrivateHeader() = delete; |
| 41 | ~PrivateHeader() = default; |
| 42 | PrivateHeader(const PrivateHeader&) = default; |
| 43 | PrivateHeader& operator=(const PrivateHeader&) = default; |
| 44 | PrivateHeader(PrivateHeader&&) = default; |
| 45 | PrivateHeader& operator=(PrivateHeader&&) = default; |
| 46 | |
| 47 | /** |
| 48 | * @brief Constructor |
| 49 | * |
Matt Spinler | 289aa47 | 2019-09-20 12:33:29 -0500 | [diff] [blame] | 50 | * Creates a valid PrivateHeader with the passed in data |
| 51 | * |
| 52 | * @param[in] componentID - the creator's component ID |
| 53 | * @param[in] obmcLogID - the corresponding OpenBMC event log ID |
| 54 | * @param[in] timestamp - the creation timestamp, in epoch milliseconds |
| 55 | */ |
| 56 | PrivateHeader(uint16_t componentID, uint32_t obmcLogID, uint64_t timestamp); |
| 57 | |
| 58 | /** |
| 59 | * @brief Constructor |
| 60 | * |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 61 | * Fills in this class's data fields from the stream. |
| 62 | * |
| 63 | * @param[in] pel - the PEL data stream |
| 64 | * |
| 65 | */ |
| 66 | explicit PrivateHeader(Stream& pel); |
| 67 | |
| 68 | /** |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 69 | * @brief Flatten the section into the stream |
| 70 | * |
| 71 | * @param[in] stream - The stream to write to |
| 72 | */ |
| 73 | void flatten(Stream& stream) override; |
| 74 | |
| 75 | /** |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 76 | * @brief Returns the creation timestamp |
| 77 | * |
| 78 | * @return BCDTime& - the timestamp |
| 79 | */ |
| 80 | BCDTime& createTimestamp() |
| 81 | { |
| 82 | return _createTimestamp; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @brief Returns the commit time timestamp |
| 87 | * |
| 88 | * @return BCDTime& - the timestamp |
| 89 | */ |
| 90 | BCDTime& commitTimestamp() |
| 91 | { |
| 92 | return _commitTimestamp; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @brief Returns the creator ID field |
| 97 | * |
| 98 | * @return uint8_t& - the creator ID |
| 99 | */ |
| 100 | uint8_t& creatorID() |
| 101 | { |
| 102 | return _creatorID; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @brief Returns the log type field |
| 107 | * |
| 108 | * @return uint8_t& - the log type |
| 109 | */ |
| 110 | uint8_t& logType() |
| 111 | { |
| 112 | return _logType; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * @brief Returns the section count field |
| 117 | * |
| 118 | * @return uint8_t& - the section count |
| 119 | */ |
| 120 | uint8_t& sectionCount() |
| 121 | { |
| 122 | return _sectionCount; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @brief Returns the OpenBMC log ID field |
| 127 | * |
| 128 | * This is the ID the OpenBMC event log that corresponds |
| 129 | * to this PEL. |
| 130 | * |
| 131 | * @return uint32_t& - the OpenBMC event log ID |
| 132 | */ |
| 133 | uint32_t& obmcLogID() |
| 134 | { |
| 135 | return _obmcLogID; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * @brief Returns the Creator Version field |
| 140 | * |
| 141 | * @return CreatorVersion& - the creator version |
| 142 | */ |
| 143 | CreatorVersion& creatorVersion() |
| 144 | { |
| 145 | return _creatorVersion; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * @brief Returns the error log ID field |
| 150 | * |
| 151 | * @return uint32_t& - the error log ID |
| 152 | */ |
| 153 | uint32_t& id() |
| 154 | { |
| 155 | return _id; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * @brief Returns the platform log ID field |
| 160 | * |
| 161 | * @return uint32_t& - the platform log ID |
| 162 | */ |
| 163 | uint32_t& plid() |
| 164 | { |
| 165 | return _plid; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * @brief Returns the size of this section when flattened into a PEL |
| 170 | * |
| 171 | * @return size_t - the size of the section |
| 172 | */ |
| 173 | static constexpr size_t flattenedSize() |
| 174 | { |
| 175 | return Section::flattenedSize() + sizeof(_createTimestamp) + |
| 176 | sizeof(_commitTimestamp) + sizeof(_creatorID) + |
| 177 | sizeof(_logType) + sizeof(_reservedByte) + |
| 178 | sizeof(_sectionCount) + sizeof(_obmcLogID) + |
| 179 | sizeof(_creatorVersion) + sizeof(_plid) + sizeof(_id); |
| 180 | } |
| 181 | |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 182 | private: |
| 183 | /** |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 184 | * @brief Fills in the object from the stream data |
| 185 | * |
| 186 | * @param[in] stream - The stream to read from |
| 187 | */ |
| 188 | void unflatten(Stream& stream); |
| 189 | |
| 190 | /** |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 191 | * @brief Validates the section contents |
| 192 | * |
| 193 | * Updates _valid (in Section) with the results. |
| 194 | */ |
| 195 | void validate() override; |
| 196 | |
| 197 | /** |
| 198 | * @brief The creation time timestamp |
| 199 | */ |
| 200 | BCDTime _createTimestamp; |
| 201 | |
| 202 | /** |
| 203 | * @brief The commit time timestamp |
| 204 | */ |
| 205 | BCDTime _commitTimestamp; |
| 206 | |
| 207 | /** |
| 208 | * @brief The creator ID field |
| 209 | */ |
| 210 | uint8_t _creatorID; |
| 211 | |
| 212 | /** |
| 213 | * @brief The log type field |
| 214 | */ |
| 215 | uint8_t _logType; |
| 216 | |
| 217 | /** |
| 218 | * @brief A reserved byte. |
| 219 | */ |
| 220 | uint8_t _reservedByte; |
| 221 | |
| 222 | /** |
| 223 | * @brief The section count field, which is the total number |
| 224 | * of sections in the PEL. |
| 225 | */ |
| 226 | uint8_t _sectionCount; |
| 227 | |
| 228 | /** |
| 229 | * @brief The OpenBMC event log ID that corresponds to this PEL. |
| 230 | */ |
| 231 | uint32_t _obmcLogID; |
| 232 | |
| 233 | /** |
| 234 | * @brief The creator subsystem version field |
| 235 | */ |
| 236 | CreatorVersion _creatorVersion; |
| 237 | |
| 238 | /** |
| 239 | * @brief The platform log ID field |
| 240 | */ |
| 241 | uint32_t _plid; |
| 242 | |
| 243 | /** |
| 244 | * @brief The log entry ID field |
| 245 | */ |
| 246 | uint32_t _id; |
| 247 | }; |
| 248 | |
| 249 | /** |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 250 | * @brief Stream extraction operator for the CreatorVersion |
| 251 | * |
| 252 | * @param[in] s - the stream |
| 253 | * @param[out] cv - the CreatorVersion object |
| 254 | */ |
| 255 | Stream& operator>>(Stream& s, CreatorVersion& cv); |
| 256 | |
| 257 | /** |
| 258 | * @brief Stream insertion operator for the CreatorVersion |
| 259 | * |
| 260 | * @param[out] s - the stream |
| 261 | * @param[in] cv - the CreatorVersion object |
| 262 | */ |
| 263 | Stream& operator<<(Stream& s, CreatorVersion& cv); |
| 264 | |
| 265 | } // namespace pels |
| 266 | } // namespace openpower |