blob: 459952baf2f491b831220e3646a33e7d91537948 [file] [log] [blame]
Matt Spinler03c1d912019-07-10 14:12:15 -05001#pragma once
2
Matt Spinlerfdb6a202019-09-20 14:09:20 -05003#include "elog_entry.hpp"
4#include "registry.hpp"
Matt Spinler03c1d912019-07-10 14:12:15 -05005#include "section.hpp"
6#include "stream.hpp"
7
8namespace openpower
9{
10namespace pels
11{
12
Matt Spinler1a94cc32019-09-11 13:32:12 -050013static constexpr uint8_t userHeaderVersion = 0x01;
Matt Spinler03c1d912019-07-10 14:12:15 -050014
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 */
27class 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 *
Matt Spinlerfdb6a202019-09-20 14:09:20 -050040 * 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 *
Matt Spinler03c1d912019-07-10 14:12:15 -050051 * 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 /**
Matt Spinlercf5a8d02019-09-05 12:58:53 -050058 * @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 /**
Matt Spinler03c1d912019-07-10 14:12:15 -050065 * @brief Returns the subsystem field.
66 *
Matt Spinler97d19b42019-10-29 11:34:03 -050067 * @return uint8_t - the subsystem
Matt Spinler03c1d912019-07-10 14:12:15 -050068 */
Matt Spinler97d19b42019-10-29 11:34:03 -050069 uint8_t subsystem() const
Matt Spinler03c1d912019-07-10 14:12:15 -050070 {
71 return _eventSubsystem;
72 }
73
74 /**
75 * @brief Returns the event scope field.
76 *
Matt Spinler97d19b42019-10-29 11:34:03 -050077 * @return uint8_t - the event scope
Matt Spinler03c1d912019-07-10 14:12:15 -050078 */
Matt Spinler97d19b42019-10-29 11:34:03 -050079 uint8_t scope() const
Matt Spinler03c1d912019-07-10 14:12:15 -050080 {
81 return _eventScope;
82 }
83
84 /**
85 * @brief Returns the severity field.
86 *
Matt Spinler97d19b42019-10-29 11:34:03 -050087 * @return uint8_t - the severity
Matt Spinler03c1d912019-07-10 14:12:15 -050088 */
Matt Spinler97d19b42019-10-29 11:34:03 -050089 uint8_t severity() const
Matt Spinler03c1d912019-07-10 14:12:15 -050090 {
91 return _eventSeverity;
92 }
93
94 /**
95 * @brief Returns the event type field.
96 *
Matt Spinler97d19b42019-10-29 11:34:03 -050097 * @return uint8_t - the event type
Matt Spinler03c1d912019-07-10 14:12:15 -050098 */
Matt Spinler97d19b42019-10-29 11:34:03 -050099 uint8_t eventType() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500100 {
101 return _eventType;
102 }
103
104 /**
105 * @brief Returns the problem domain field.
106 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500107 * @return uint8_t - the problem domain
Matt Spinler03c1d912019-07-10 14:12:15 -0500108 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500109 uint8_t problemDomain() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500110 {
111 return _problemDomain;
112 }
113
114 /**
115 * @brief Returns the problem vector field.
116 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500117 * @return uint8_t - the problem vector
Matt Spinler03c1d912019-07-10 14:12:15 -0500118 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500119 uint8_t problemVector() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500120 {
121 return _problemVector;
122 }
123
124 /**
125 * @brief Returns the action flags field.
126 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500127 * @return uint16_t - the action flags
Matt Spinler03c1d912019-07-10 14:12:15 -0500128 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500129 uint16_t actionFlags() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500130 {
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
Matt Spinler03c1d912019-07-10 14:12:15 -0500148 private:
149 /**
Matt Spinlercf5a8d02019-09-05 12:58:53 -0500150 * @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 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500157 * @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
Matt Spinler03c1d912019-07-10 14:12:15 -0500209} // namespace pels
210} // namespace openpower