xref: /openbmc/phosphor-logging/extensions/openpower-pels/section_header.hpp (revision 075c79237505ea3b810a461f5f514e4d520a0c44)
11b5c72b5SMatt Spinler #pragma once
21b5c72b5SMatt Spinler 
31b5c72b5SMatt Spinler #include "stream.hpp"
41b5c72b5SMatt Spinler 
51b5c72b5SMatt Spinler #include <cstdint>
61b5c72b5SMatt Spinler 
71b5c72b5SMatt Spinler namespace openpower
81b5c72b5SMatt Spinler {
91b5c72b5SMatt Spinler namespace pels
101b5c72b5SMatt Spinler {
111b5c72b5SMatt Spinler 
121b5c72b5SMatt Spinler /**
131b5c72b5SMatt Spinler  * @class SectionHeader
141b5c72b5SMatt Spinler  *
151b5c72b5SMatt Spinler  * This header is at the start of every PEL section.  It has a size
161b5c72b5SMatt Spinler  * of 8 bytes.
171b5c72b5SMatt Spinler  */
181b5c72b5SMatt Spinler struct SectionHeader
191b5c72b5SMatt Spinler {
201b5c72b5SMatt Spinler   public:
211b5c72b5SMatt Spinler     /**
221b5c72b5SMatt Spinler      * @brief Constructor
231b5c72b5SMatt Spinler      */
SectionHeaderopenpower::pels::SectionHeader242544b419SPatrick Williams     SectionHeader() : id(0), size(0), version(0), subType(0), componentID(0) {}
251b5c72b5SMatt Spinler 
261b5c72b5SMatt Spinler     /**
271b5c72b5SMatt Spinler      * @brief Constructor
281b5c72b5SMatt Spinler      *
291b5c72b5SMatt Spinler      * @param[in] id - the ID field
301b5c72b5SMatt Spinler      * @param[in] size - the size field
311b5c72b5SMatt Spinler      * @param[in] version - the version field
321b5c72b5SMatt Spinler      * @param[in] subType - the sub-type field
331b5c72b5SMatt Spinler      * @param[in] componentID - the component ID field
341b5c72b5SMatt Spinler      */
SectionHeaderopenpower::pels::SectionHeader351b5c72b5SMatt Spinler     SectionHeader(uint16_t id, uint16_t size, uint8_t version, uint8_t subType,
361b5c72b5SMatt Spinler                   uint16_t componentID) :
37*075c7923SPatrick Williams         id(id), size(size), version(version), subType(subType),
38*075c7923SPatrick Williams         componentID(componentID)
392544b419SPatrick Williams     {}
401b5c72b5SMatt Spinler 
411b5c72b5SMatt Spinler     /**
421b5c72b5SMatt Spinler      * @brief A two character ASCII field which identifies the section type.
431b5c72b5SMatt Spinler      */
441b5c72b5SMatt Spinler     uint16_t id;
451b5c72b5SMatt Spinler 
461b5c72b5SMatt Spinler     /**
471b5c72b5SMatt Spinler      * @brief The size of the section in bytes, including this section header.
481b5c72b5SMatt Spinler      */
491b5c72b5SMatt Spinler     uint16_t size;
501b5c72b5SMatt Spinler 
511b5c72b5SMatt Spinler     /**
521b5c72b5SMatt Spinler      * @brief The section format version.
531b5c72b5SMatt Spinler      */
541b5c72b5SMatt Spinler     uint8_t version;
551b5c72b5SMatt Spinler 
561b5c72b5SMatt Spinler     /**
571b5c72b5SMatt Spinler      * @brief The section sub-type.
581b5c72b5SMatt Spinler      */
591b5c72b5SMatt Spinler     uint8_t subType;
601b5c72b5SMatt Spinler 
611b5c72b5SMatt Spinler     /**
621b5c72b5SMatt Spinler      * @brief The component ID, which has various meanings depending on the
631b5c72b5SMatt Spinler      * section.
641b5c72b5SMatt Spinler      */
651b5c72b5SMatt Spinler     uint16_t componentID;
661b5c72b5SMatt Spinler 
671b5c72b5SMatt Spinler     /**
681b5c72b5SMatt Spinler      * @brief Returns the size of header when flattened into a PEL.
691b5c72b5SMatt Spinler      *
701b5c72b5SMatt Spinler      * @return size_t - the size of the header
711b5c72b5SMatt Spinler      */
flattenedSizeopenpower::pels::SectionHeader721b5c72b5SMatt Spinler     static constexpr size_t flattenedSize()
731b5c72b5SMatt Spinler     {
741b5c72b5SMatt Spinler         return sizeof(id) + sizeof(size) + sizeof(version) + sizeof(subType) +
751b5c72b5SMatt Spinler                sizeof(componentID);
761b5c72b5SMatt Spinler     }
771b5c72b5SMatt Spinler };
781b5c72b5SMatt Spinler 
791b5c72b5SMatt Spinler /**
801b5c72b5SMatt Spinler  * @brief Stream extraction operator for the SectionHeader
811b5c72b5SMatt Spinler  *
821b5c72b5SMatt Spinler  * @param[in] s - the stream
831b5c72b5SMatt Spinler  * @param[out] header - the SectionHeader object
841b5c72b5SMatt Spinler  */
operator >>(Stream & s,SectionHeader & header)851b5c72b5SMatt Spinler inline Stream& operator>>(Stream& s, SectionHeader& header)
861b5c72b5SMatt Spinler {
871b5c72b5SMatt Spinler     s >> header.id >> header.size >> header.version >> header.subType >>
881b5c72b5SMatt Spinler         header.componentID;
891b5c72b5SMatt Spinler     return s;
901b5c72b5SMatt Spinler }
911b5c72b5SMatt Spinler 
921b5c72b5SMatt Spinler /**
931b5c72b5SMatt Spinler  * @brief Stream insertion operator for the section header
941b5c72b5SMatt Spinler  *
951b5c72b5SMatt Spinler  * @param[out] s - the stream
961b5c72b5SMatt Spinler  * @param[in] header - the SectionHeader object
971b5c72b5SMatt Spinler  */
operator <<(Stream & s,const SectionHeader & header)980688545bSMatt Spinler inline Stream& operator<<(Stream& s, const SectionHeader& header)
991b5c72b5SMatt Spinler {
1001b5c72b5SMatt Spinler     s << header.id << header.size << header.version << header.subType
1011b5c72b5SMatt Spinler       << header.componentID;
1021b5c72b5SMatt Spinler     return s;
1031b5c72b5SMatt Spinler }
1041b5c72b5SMatt Spinler 
1051b5c72b5SMatt Spinler } // namespace pels
1061b5c72b5SMatt Spinler } // namespace openpower
107