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