blob: a1873f5711569f7721ec727a6ec702bef2e3ab14 [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 */
Matt Spinler06885452019-11-06 10:35:42 -060062 void flatten(Stream& stream) const override;
Matt Spinlercf5a8d02019-09-05 12:58:53 -050063
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 /**
Matt Spinlerf1e85e22019-11-01 11:31:31 -0500105 * @brief Set the event type field
106 *
107 * @param[in] type - the new event type
108 */
109 void setEventType(uint8_t type)
110 {
111 _eventType = type;
112 }
113
114 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500115 * @brief Returns the problem domain field.
116 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500117 * @return uint8_t - the problem domain
Matt Spinler03c1d912019-07-10 14:12:15 -0500118 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500119 uint8_t problemDomain() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500120 {
121 return _problemDomain;
122 }
123
124 /**
125 * @brief Returns the problem vector field.
126 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500127 * @return uint8_t - the problem vector
Matt Spinler03c1d912019-07-10 14:12:15 -0500128 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500129 uint8_t problemVector() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500130 {
131 return _problemVector;
132 }
133
134 /**
135 * @brief Returns the action flags field.
136 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500137 * @return uint16_t - the action flags
Matt Spinler03c1d912019-07-10 14:12:15 -0500138 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500139 uint16_t actionFlags() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500140 {
141 return _actionFlags;
142 }
143
144 /**
Matt Spinlerf1e85e22019-11-01 11:31:31 -0500145 * @brief Sets the action flags field
146 *
147 * @param[in] flags - the new action flags
148 */
149 void setActionFlags(uint16_t flags)
150 {
151 _actionFlags = flags;
152 }
153
154 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500155 * @brief Returns the size of this section when flattened into a PEL
156 *
157 * @return size_t - the size of the section
158 */
159 static constexpr size_t flattenedSize()
160 {
161 return Section::flattenedSize() + sizeof(_eventSubsystem) +
162 sizeof(_eventScope) + sizeof(_eventSeverity) +
163 sizeof(_eventType) + sizeof(_reserved4Byte1) +
164 sizeof(_problemDomain) + sizeof(_problemVector) +
165 sizeof(_actionFlags) + sizeof(_reserved4Byte2);
166 }
167
Matt Spinler03c1d912019-07-10 14:12:15 -0500168 private:
169 /**
Matt Spinlercf5a8d02019-09-05 12:58:53 -0500170 * @brief Fills in the object from the stream data
171 *
172 * @param[in] stream - The stream to read from
173 */
174 void unflatten(Stream& stream);
175
176 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500177 * @brief Validates the section contents
178 *
179 * Updates _valid (in Section) with the results.
180 */
181 void validate() override;
182
183 /**
184 * @brief The subsystem associated with the event.
185 */
186 uint8_t _eventSubsystem;
187
188 /**
189 * @brief The event scope field.
190 */
191 uint8_t _eventScope;
192
193 /**
194 * @brief The event severity.
195 */
196 uint8_t _eventSeverity;
197
198 /**
199 * @brief The event type.
200 */
201 uint8_t _eventType;
202
203 /**
204 * @brief A reserved word placeholder
205 */
206 uint32_t _reserved4Byte1;
207
208 /**
209 * @brief The problem domain field.
210 */
211 uint8_t _problemDomain;
212
213 /**
214 * @brief The problem vector field.
215 */
216 uint8_t _problemVector;
217
218 /**
219 * @brief The action flags field.
220 */
221 uint16_t _actionFlags;
222
223 /**
224 * @brief The second reserved word placeholder.
225 */
226 uint32_t _reserved4Byte2;
227};
228
Matt Spinler03c1d912019-07-10 14:12:15 -0500229} // namespace pels
230} // namespace openpower