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: 35*07eefc54SMatt Spinler * - PEL(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 * 62*07eefc54SMatt Spinler * Note: Neither this nor the following constructor can take a const vector& 63*07eefc54SMatt Spinler * because the Stream class that is used to read from the vector cannot take 64*07eefc54SMatt Spinler * a const. The alternative is to make a copy of the data, but as PELs can 65*07eefc54SMatt Spinler * be up to 16KB that is undesireable. 66*07eefc54SMatt Spinler * 67cb6b059eSMatt Spinler * @param[in] data - The PEL data 68cb6b059eSMatt Spinler */ 69*07eefc54SMatt Spinler PEL(std::vector<uint8_t>& data); 70cb6b059eSMatt Spinler 71cb6b059eSMatt Spinler /** 72cb6b059eSMatt Spinler * @brief Constructor 73cb6b059eSMatt Spinler * 74cb6b059eSMatt Spinler * Build a PEL from the raw data. 75cb6b059eSMatt Spinler * 76cb6b059eSMatt Spinler * @param[in] data - the PEL data 77cb6b059eSMatt Spinler * @param[in] obmcLogID - the corresponding OpenBMC event log ID 78cb6b059eSMatt Spinler */ 79*07eefc54SMatt Spinler PEL(std::vector<uint8_t>& data, uint32_t obmcLogID); 80cb6b059eSMatt Spinler 81cb6b059eSMatt Spinler /** 82b832363dSMatt Spinler * @brief Constructor 83b832363dSMatt Spinler * 84b832363dSMatt Spinler * Creates a PEL from an OpenBMC event log and its message 85b832363dSMatt Spinler * registry entry. 86b832363dSMatt Spinler * 87b832363dSMatt Spinler * @param[in] entry - The message registry entry for this error 88b832363dSMatt Spinler * @param[in] obmcLogID - ID of corresponding OpenBMC event log 89b832363dSMatt Spinler * @param[in] timestamp - Timestamp from the event log 90b832363dSMatt Spinler * @param[in] severity - Severity from the event log 91b832363dSMatt Spinler */ 92b832363dSMatt Spinler PEL(const openpower::pels::message::Entry& entry, uint32_t obmcLogID, 93b832363dSMatt Spinler uint64_t timestamp, phosphor::logging::Entry::Level severity); 94b832363dSMatt Spinler 95b832363dSMatt Spinler /** 96cb6b059eSMatt Spinler * @brief Convenience function to return the log ID field from the 97cb6b059eSMatt Spinler * Private Header section. 98cb6b059eSMatt Spinler * 99cb6b059eSMatt Spinler * @return uint32_t - the ID 100cb6b059eSMatt Spinler */ 101cb6b059eSMatt Spinler uint32_t id() const 102cb6b059eSMatt Spinler { 103cb6b059eSMatt Spinler return _ph->id(); 104cb6b059eSMatt Spinler } 105cb6b059eSMatt Spinler 106cb6b059eSMatt Spinler /** 107cb6b059eSMatt Spinler * @brief Convenience function to return the PLID field from the 108cb6b059eSMatt Spinler * Private Header section. 109cb6b059eSMatt Spinler * 110cb6b059eSMatt Spinler * @return uint32_t - the PLID 111cb6b059eSMatt Spinler */ 112cb6b059eSMatt Spinler uint32_t plid() const 113cb6b059eSMatt Spinler { 114cb6b059eSMatt Spinler return _ph->plid(); 115cb6b059eSMatt Spinler } 116cb6b059eSMatt Spinler 117cb6b059eSMatt Spinler /** 118cb6b059eSMatt Spinler * @brief Convenience function to return the OpenBMC event log ID field 119cb6b059eSMatt Spinler * from the Private Header section. 120cb6b059eSMatt Spinler * 121cb6b059eSMatt Spinler * @return uint32_t - the OpenBMC event log ID 122cb6b059eSMatt Spinler */ 123cb6b059eSMatt Spinler uint32_t obmcLogID() const 124cb6b059eSMatt Spinler { 125cb6b059eSMatt Spinler return _ph->obmcLogID(); 126cb6b059eSMatt Spinler } 127cb6b059eSMatt Spinler 128cb6b059eSMatt Spinler /** 129cb6b059eSMatt Spinler * @brief Convenience function to return the commit time field from 130cb6b059eSMatt Spinler * the Private Header section. 131cb6b059eSMatt Spinler * 132cb6b059eSMatt Spinler * @return BCDTime - the timestamp 133cb6b059eSMatt Spinler */ 134cb6b059eSMatt Spinler BCDTime commitTime() const 135cb6b059eSMatt Spinler { 136cb6b059eSMatt Spinler return _ph->commitTimestamp(); 137cb6b059eSMatt Spinler } 138cb6b059eSMatt Spinler 139cb6b059eSMatt Spinler /** 140cb6b059eSMatt Spinler * @brief Convenience function to return the create time field from 141cb6b059eSMatt Spinler * the Private Header section. 142cb6b059eSMatt Spinler * 143cb6b059eSMatt Spinler * @return BCDTime - the timestamp 144cb6b059eSMatt Spinler */ 145cb6b059eSMatt Spinler BCDTime createTime() const 146cb6b059eSMatt Spinler { 147cb6b059eSMatt Spinler return _ph->createTimestamp(); 148cb6b059eSMatt Spinler } 149cb6b059eSMatt Spinler 150cb6b059eSMatt Spinler /** 151cb6b059eSMatt Spinler * @brief Gives access to the Private Header section class 152cb6b059eSMatt Spinler * 153cb6b059eSMatt Spinler * @return std::unique_ptr<PrivateHeader>& the private header 154cb6b059eSMatt Spinler */ 155cb6b059eSMatt Spinler std::unique_ptr<PrivateHeader>& privateHeader() 156cb6b059eSMatt Spinler { 157cb6b059eSMatt Spinler return _ph; 158cb6b059eSMatt Spinler } 159cb6b059eSMatt Spinler 160cb6b059eSMatt Spinler /** 161cb6b059eSMatt Spinler * @brief Gives access to the User Header section class 162cb6b059eSMatt Spinler * 163cb6b059eSMatt Spinler * @return std::unique_ptr<UserHeader>& the user header 164cb6b059eSMatt Spinler */ 165cb6b059eSMatt Spinler std::unique_ptr<UserHeader>& userHeader() 166cb6b059eSMatt Spinler { 167cb6b059eSMatt Spinler return _uh; 168cb6b059eSMatt Spinler } 169cb6b059eSMatt Spinler 170cb6b059eSMatt Spinler /** 171131870c7SMatt Spinler * @brief Returns the optional sections, which is everything but 172131870c7SMatt Spinler * the Private and User Headers. 173131870c7SMatt Spinler * 174131870c7SMatt Spinler * @return const std::vector<std::unique_ptr<Section>>& 175131870c7SMatt Spinler */ 176131870c7SMatt Spinler const std::vector<std::unique_ptr<Section>>& optionalSections() const 177131870c7SMatt Spinler { 178131870c7SMatt Spinler return _optionalSections; 179131870c7SMatt Spinler } 180131870c7SMatt Spinler 181131870c7SMatt Spinler /** 182cb6b059eSMatt Spinler * @brief Returns the PEL data. 183cb6b059eSMatt Spinler * 184cb6b059eSMatt Spinler * @return std::vector<uint8_t> - the raw PEL data 185cb6b059eSMatt Spinler */ 186cb6b059eSMatt Spinler std::vector<uint8_t> data(); 187cb6b059eSMatt Spinler 188cb6b059eSMatt Spinler /** 189cb6b059eSMatt Spinler * @brief Says if the PEL is valid (the sections are all valid) 190cb6b059eSMatt Spinler * 191cb6b059eSMatt Spinler * @return bool - if the PEL is valid 192cb6b059eSMatt Spinler */ 193cb6b059eSMatt Spinler bool valid() const; 194cb6b059eSMatt Spinler 195cb6b059eSMatt Spinler /** 196cb6b059eSMatt Spinler * @brief Sets the commit timestamp to the current time 197cb6b059eSMatt Spinler */ 198cb6b059eSMatt Spinler void setCommitTime(); 199cb6b059eSMatt Spinler 200cb6b059eSMatt Spinler /** 201cb6b059eSMatt Spinler * @brief Sets the error log ID field to a unique ID. 202cb6b059eSMatt Spinler */ 203cb6b059eSMatt Spinler void assignID(); 204cb6b059eSMatt Spinler 205cb6b059eSMatt Spinler private: 206cb6b059eSMatt Spinler /** 207cb6b059eSMatt Spinler * @brief Builds the section objects from a PEL data buffer 208cb6b059eSMatt Spinler * 209*07eefc54SMatt Spinler * Note: The data parameter cannot be const for the same reasons 210*07eefc54SMatt Spinler * as listed in the constructor. 211*07eefc54SMatt Spinler * 212*07eefc54SMatt Spinler * @param[in] data - The PEL data 213cb6b059eSMatt Spinler * @param[in] obmcLogID - The OpenBMC event log ID to use for that 214cb6b059eSMatt Spinler * field in the Private Header. 215cb6b059eSMatt Spinler */ 216*07eefc54SMatt Spinler void populateFromRawData(std::vector<uint8_t>& data, uint32_t obmcLogID); 217cb6b059eSMatt Spinler 218cb6b059eSMatt Spinler /** 219cb6b059eSMatt Spinler * @brief Flattens the PEL objects into the buffer 220cb6b059eSMatt Spinler * 221cb6b059eSMatt Spinler * @param[out] pelBuffer - What the data will be written to 222cb6b059eSMatt Spinler */ 223cb6b059eSMatt Spinler void flatten(std::vector<uint8_t>& pelBuffer); 224cb6b059eSMatt Spinler 225cb6b059eSMatt Spinler /** 226cb6b059eSMatt Spinler * @brief The PEL Private Header section 227cb6b059eSMatt Spinler */ 228cb6b059eSMatt Spinler std::unique_ptr<PrivateHeader> _ph; 229cb6b059eSMatt Spinler 230cb6b059eSMatt Spinler /** 231cb6b059eSMatt Spinler * @brief The PEL User Header section 232cb6b059eSMatt Spinler */ 233cb6b059eSMatt Spinler std::unique_ptr<UserHeader> _uh; 234cb6b059eSMatt Spinler 235cb6b059eSMatt Spinler /** 236131870c7SMatt Spinler * @brief Holds all sections by the PH and UH. 237131870c7SMatt Spinler */ 238131870c7SMatt Spinler std::vector<std::unique_ptr<Section>> _optionalSections; 239cb6b059eSMatt Spinler }; 240cb6b059eSMatt Spinler 241cb6b059eSMatt Spinler } // namespace pels 242cb6b059eSMatt Spinler } // namespace openpower 243