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