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