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