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 Flatten the section into the stream
55      *
56      * @param[in] stream - The stream to write to
57      */
58     void flatten(Stream& stream) override;
59 
60     /**
61      * @brief Returns the creation timestamp
62      *
63      * @return BCDTime& - the timestamp
64      */
65     BCDTime& createTimestamp()
66     {
67         return _createTimestamp;
68     }
69 
70     /**
71      * @brief Returns the commit time timestamp
72      *
73      * @return BCDTime& - the timestamp
74      */
75     BCDTime& commitTimestamp()
76     {
77         return _commitTimestamp;
78     }
79 
80     /**
81      * @brief Returns the creator ID field
82      *
83      * @return uint8_t& - the creator ID
84      */
85     uint8_t& creatorID()
86     {
87         return _creatorID;
88     }
89 
90     /**
91      * @brief Returns the log type field
92      *
93      * @return uint8_t& - the log type
94      */
95     uint8_t& logType()
96     {
97         return _logType;
98     }
99 
100     /**
101      * @brief Returns the section count field
102      *
103      * @return uint8_t& - the section count
104      */
105     uint8_t& sectionCount()
106     {
107         return _sectionCount;
108     }
109 
110     /**
111      * @brief Returns the OpenBMC log ID field
112      *
113      * This is the ID the OpenBMC event log that corresponds
114      * to this PEL.
115      *
116      * @return uint32_t& - the OpenBMC event log ID
117      */
118     uint32_t& obmcLogID()
119     {
120         return _obmcLogID;
121     }
122 
123     /**
124      * @brief Returns the Creator Version field
125      *
126      * @return CreatorVersion& - the creator version
127      */
128     CreatorVersion& creatorVersion()
129     {
130         return _creatorVersion;
131     }
132 
133     /**
134      * @brief Returns the error log ID field
135      *
136      * @return uint32_t& - the error log ID
137      */
138     uint32_t& id()
139     {
140         return _id;
141     }
142 
143     /**
144      * @brief Returns the platform log ID field
145      *
146      * @return uint32_t& - the platform log ID
147      */
148     uint32_t& plid()
149     {
150         return _plid;
151     }
152 
153     /**
154      * @brief Returns the size of this section when flattened into a PEL
155      *
156      * @return size_t - the size of the section
157      */
158     static constexpr size_t flattenedSize()
159     {
160         return Section::flattenedSize() + sizeof(_createTimestamp) +
161                sizeof(_commitTimestamp) + sizeof(_creatorID) +
162                sizeof(_logType) + sizeof(_reservedByte) +
163                sizeof(_sectionCount) + sizeof(_obmcLogID) +
164                sizeof(_creatorVersion) + sizeof(_plid) + sizeof(_id);
165     }
166 
167   private:
168     /**
169      * @brief Fills in the object from the stream data
170      *
171      * @param[in] stream - The stream to read from
172      */
173     void unflatten(Stream& stream);
174 
175     /**
176      * @brief Validates the section contents
177      *
178      * Updates _valid (in Section) with the results.
179      */
180     void validate() override;
181 
182     /**
183      * @brief The creation time timestamp
184      */
185     BCDTime _createTimestamp;
186 
187     /**
188      * @brief The commit time timestamp
189      */
190     BCDTime _commitTimestamp;
191 
192     /**
193      * @brief The creator ID field
194      */
195     uint8_t _creatorID;
196 
197     /**
198      * @brief The log type field
199      */
200     uint8_t _logType;
201 
202     /**
203      * @brief A reserved byte.
204      */
205     uint8_t _reservedByte;
206 
207     /**
208      * @brief The section count field, which is the total number
209      * of sections in the PEL.
210      */
211     uint8_t _sectionCount;
212 
213     /**
214      * @brief The OpenBMC event log ID that corresponds to this PEL.
215      */
216     uint32_t _obmcLogID;
217 
218     /**
219      * @brief The creator subsystem version field
220      */
221     CreatorVersion _creatorVersion;
222 
223     /**
224      * @brief The platform log ID field
225      */
226     uint32_t _plid;
227 
228     /**
229      * @brief The log entry ID field
230      */
231     uint32_t _id;
232 };
233 
234 /**
235  * @brief Stream extraction operator for the CreatorVersion
236  *
237  * @param[in] s - the stream
238  * @param[out] cv - the CreatorVersion object
239  */
240 Stream& operator>>(Stream& s, CreatorVersion& cv);
241 
242 /**
243  * @brief Stream insertion operator for the CreatorVersion
244  *
245  * @param[out] s - the stream
246  * @param[in] cv - the CreatorVersion object
247  */
248 Stream& operator<<(Stream& s, CreatorVersion& cv);
249 
250 } // namespace pels
251 } // namespace openpower
252