1 #pragma once
2 
3 #include "elog_entry.hpp"
4 #include "registry.hpp"
5 #include "section.hpp"
6 #include "stream.hpp"
7 
8 namespace openpower
9 {
10 namespace pels
11 {
12 
13 static constexpr uint8_t userHeaderVersion = 0x01;
14 
15 /**
16  * @class UserHeader
17  *
18  * This represents the User Header section in a PEL.  It is required,
19  * and it is always the second section.
20  *
21  * The Section base class handles the section header structure that every
22  * PEL section has at offset zero.
23  *
24  * The fields in this class directly correspond to the order and sizes of
25  * the fields in the section.
26  */
27 class UserHeader : public Section
28 {
29   public:
30     UserHeader() = delete;
31     ~UserHeader() = default;
32     UserHeader(const UserHeader&) = default;
33     UserHeader& operator=(const UserHeader&) = default;
34     UserHeader(UserHeader&&) = default;
35     UserHeader& operator=(UserHeader&&) = default;
36 
37     /**
38      * @brief Constructor
39      *
40      * Creates a valid UserHeader with the passed in data.
41      *
42      * @param[in] entry - The message registry entry for this error
43      * @param[in] severity - The OpenBMC event log severity for this error
44      */
45     UserHeader(const message::Entry& entry,
46                phosphor::logging::Entry::Level severity);
47 
48     /**
49      * @brief Constructor
50      *
51      * Fills in this class's data fields from the stream.
52      *
53      * @param[in] pel - the PEL data stream
54      */
55     explicit UserHeader(Stream& pel);
56 
57     /**
58      * @brief Flatten the section into the stream
59      *
60      * @param[in] stream - The stream to write to
61      */
62     void flatten(Stream& stream) override;
63 
64     /**
65      * @brief Returns the subsystem field.
66      *
67      * @return uint8_t - the subsystem
68      */
69     uint8_t subsystem() const
70     {
71         return _eventSubsystem;
72     }
73 
74     /**
75      * @brief Returns the event scope field.
76      *
77      * @return uint8_t - the event scope
78      */
79     uint8_t scope() const
80     {
81         return _eventScope;
82     }
83 
84     /**
85      * @brief Returns the severity field.
86      *
87      * @return uint8_t - the severity
88      */
89     uint8_t severity() const
90     {
91         return _eventSeverity;
92     }
93 
94     /**
95      * @brief Returns the event type field.
96      *
97      * @return uint8_t - the event type
98      */
99     uint8_t eventType() const
100     {
101         return _eventType;
102     }
103 
104     /**
105      * @brief Returns the problem domain field.
106      *
107      * @return uint8_t - the problem domain
108      */
109     uint8_t problemDomain() const
110     {
111         return _problemDomain;
112     }
113 
114     /**
115      * @brief Returns the problem vector field.
116      *
117      * @return uint8_t - the problem vector
118      */
119     uint8_t problemVector() const
120     {
121         return _problemVector;
122     }
123 
124     /**
125      * @brief Returns the action flags field.
126      *
127      * @return uint16_t - the action flags
128      */
129     uint16_t actionFlags() const
130     {
131         return _actionFlags;
132     }
133 
134     /**
135      * @brief Returns the size of this section when flattened into a PEL
136      *
137      * @return size_t - the size of the section
138      */
139     static constexpr size_t flattenedSize()
140     {
141         return Section::flattenedSize() + sizeof(_eventSubsystem) +
142                sizeof(_eventScope) + sizeof(_eventSeverity) +
143                sizeof(_eventType) + sizeof(_reserved4Byte1) +
144                sizeof(_problemDomain) + sizeof(_problemVector) +
145                sizeof(_actionFlags) + sizeof(_reserved4Byte2);
146     }
147 
148   private:
149     /**
150      * @brief Fills in the object from the stream data
151      *
152      * @param[in] stream - The stream to read from
153      */
154     void unflatten(Stream& stream);
155 
156     /**
157      * @brief Validates the section contents
158      *
159      * Updates _valid (in Section) with the results.
160      */
161     void validate() override;
162 
163     /**
164      * @brief The subsystem associated with the event.
165      */
166     uint8_t _eventSubsystem;
167 
168     /**
169      * @brief The event scope field.
170      */
171     uint8_t _eventScope;
172 
173     /**
174      * @brief The event severity.
175      */
176     uint8_t _eventSeverity;
177 
178     /**
179      * @brief The event type.
180      */
181     uint8_t _eventType;
182 
183     /**
184      * @brief A reserved word placeholder
185      */
186     uint32_t _reserved4Byte1;
187 
188     /**
189      * @brief The problem domain field.
190      */
191     uint8_t _problemDomain;
192 
193     /**
194      * @brief The problem vector field.
195      */
196     uint8_t _problemVector;
197 
198     /**
199      * @brief The action flags field.
200      */
201     uint16_t _actionFlags;
202 
203     /**
204      * @brief The second reserved word placeholder.
205      */
206     uint32_t _reserved4Byte2;
207 };
208 
209 } // namespace pels
210 } // namespace openpower
211