blob: 5689a1ca76288fb1cdc56951d2a4969670d7f2c7 [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"
Aatir Manzurad0e0472019-10-07 13:18:37 -05004#include "pel_values.hpp"
Matt Spinlerfdb6a202019-09-20 14:09:20 -05005#include "registry.hpp"
Matt Spinler03c1d912019-07-10 14:12:15 -05006#include "section.hpp"
7#include "stream.hpp"
8
9namespace openpower
10{
11namespace pels
12{
13
Matt Spinler1a94cc32019-09-11 13:32:12 -050014static constexpr uint8_t userHeaderVersion = 0x01;
Matt Spinler03c1d912019-07-10 14:12:15 -050015
16/**
17 * @class UserHeader
18 *
19 * This represents the User Header section in a PEL. It is required,
20 * and it is always the second section.
21 *
22 * The Section base class handles the section header structure that every
23 * PEL section has at offset zero.
24 *
25 * The fields in this class directly correspond to the order and sizes of
26 * the fields in the section.
27 */
28class UserHeader : public Section
29{
30 public:
31 UserHeader() = delete;
32 ~UserHeader() = default;
33 UserHeader(const UserHeader&) = default;
34 UserHeader& operator=(const UserHeader&) = default;
35 UserHeader(UserHeader&&) = default;
36 UserHeader& operator=(UserHeader&&) = default;
37
38 /**
39 * @brief Constructor
40 *
Matt Spinlerfdb6a202019-09-20 14:09:20 -050041 * Creates a valid UserHeader with the passed in data.
42 *
43 * @param[in] entry - The message registry entry for this error
44 * @param[in] severity - The OpenBMC event log severity for this error
45 */
46 UserHeader(const message::Entry& entry,
47 phosphor::logging::Entry::Level severity);
48
49 /**
50 * @brief Constructor
51 *
Matt Spinler03c1d912019-07-10 14:12:15 -050052 * Fills in this class's data fields from the stream.
53 *
54 * @param[in] pel - the PEL data stream
55 */
56 explicit UserHeader(Stream& pel);
57
58 /**
Matt Spinlercf5a8d02019-09-05 12:58:53 -050059 * @brief Flatten the section into the stream
60 *
61 * @param[in] stream - The stream to write to
62 */
Matt Spinler06885452019-11-06 10:35:42 -060063 void flatten(Stream& stream) const override;
Matt Spinlercf5a8d02019-09-05 12:58:53 -050064
65 /**
Matt Spinler03c1d912019-07-10 14:12:15 -050066 * @brief Returns the subsystem field.
67 *
Matt Spinler97d19b42019-10-29 11:34:03 -050068 * @return uint8_t - the subsystem
Matt Spinler03c1d912019-07-10 14:12:15 -050069 */
Matt Spinler97d19b42019-10-29 11:34:03 -050070 uint8_t subsystem() const
Matt Spinler03c1d912019-07-10 14:12:15 -050071 {
72 return _eventSubsystem;
73 }
74
75 /**
76 * @brief Returns the event scope field.
77 *
Matt Spinler97d19b42019-10-29 11:34:03 -050078 * @return uint8_t - the event scope
Matt Spinler03c1d912019-07-10 14:12:15 -050079 */
Matt Spinler97d19b42019-10-29 11:34:03 -050080 uint8_t scope() const
Matt Spinler03c1d912019-07-10 14:12:15 -050081 {
82 return _eventScope;
83 }
84
85 /**
86 * @brief Returns the severity field.
87 *
Matt Spinler97d19b42019-10-29 11:34:03 -050088 * @return uint8_t - the severity
Matt Spinler03c1d912019-07-10 14:12:15 -050089 */
Matt Spinler97d19b42019-10-29 11:34:03 -050090 uint8_t severity() const
Matt Spinler03c1d912019-07-10 14:12:15 -050091 {
92 return _eventSeverity;
93 }
94
95 /**
96 * @brief Returns the event type field.
97 *
Matt Spinler97d19b42019-10-29 11:34:03 -050098 * @return uint8_t - the event type
Matt Spinler03c1d912019-07-10 14:12:15 -050099 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500100 uint8_t eventType() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500101 {
102 return _eventType;
103 }
104
105 /**
Matt Spinlerf1e85e22019-11-01 11:31:31 -0500106 * @brief Set the event type field
107 *
108 * @param[in] type - the new event type
109 */
110 void setEventType(uint8_t type)
111 {
112 _eventType = type;
113 }
114
115 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500116 * @brief Returns the problem domain field.
117 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500118 * @return uint8_t - the problem domain
Matt Spinler03c1d912019-07-10 14:12:15 -0500119 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500120 uint8_t problemDomain() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500121 {
122 return _problemDomain;
123 }
124
125 /**
126 * @brief Returns the problem vector field.
127 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500128 * @return uint8_t - the problem vector
Matt Spinler03c1d912019-07-10 14:12:15 -0500129 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500130 uint8_t problemVector() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500131 {
132 return _problemVector;
133 }
134
135 /**
136 * @brief Returns the action flags field.
137 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500138 * @return uint16_t - the action flags
Matt Spinler03c1d912019-07-10 14:12:15 -0500139 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500140 uint16_t actionFlags() const
Matt Spinler03c1d912019-07-10 14:12:15 -0500141 {
142 return _actionFlags;
143 }
144
145 /**
Matt Spinlerf1e85e22019-11-01 11:31:31 -0500146 * @brief Sets the action flags field
147 *
148 * @param[in] flags - the new action flags
149 */
150 void setActionFlags(uint16_t flags)
151 {
152 _actionFlags = flags;
153 }
154
155 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500156 * @brief Returns the size of this section when flattened into a PEL
157 *
158 * @return size_t - the size of the section
159 */
160 static constexpr size_t flattenedSize()
161 {
162 return Section::flattenedSize() + sizeof(_eventSubsystem) +
163 sizeof(_eventScope) + sizeof(_eventSeverity) +
164 sizeof(_eventType) + sizeof(_reserved4Byte1) +
165 sizeof(_problemDomain) + sizeof(_problemVector) +
166 sizeof(_actionFlags) + sizeof(_reserved4Byte2);
167 }
168
Aatir Manzurad0e0472019-10-07 13:18:37 -0500169 /**
170 * @brief Get section in JSON.
171 * @return std::optional<std::string> - If a section comes with a JSON
172 * repressentation, this would return the string for it.
173 */
174 std::optional<std::string> getJSON() const override;
175
Matt Spinler03c1d912019-07-10 14:12:15 -0500176 private:
177 /**
Matt Spinlercf5a8d02019-09-05 12:58:53 -0500178 * @brief Fills in the object from the stream data
179 *
180 * @param[in] stream - The stream to read from
181 */
182 void unflatten(Stream& stream);
183
184 /**
Matt Spinler03c1d912019-07-10 14:12:15 -0500185 * @brief Validates the section contents
186 *
187 * Updates _valid (in Section) with the results.
188 */
189 void validate() override;
190
191 /**
192 * @brief The subsystem associated with the event.
193 */
194 uint8_t _eventSubsystem;
195
196 /**
197 * @brief The event scope field.
198 */
199 uint8_t _eventScope;
200
201 /**
202 * @brief The event severity.
203 */
204 uint8_t _eventSeverity;
205
206 /**
207 * @brief The event type.
208 */
209 uint8_t _eventType;
210
211 /**
212 * @brief A reserved word placeholder
213 */
214 uint32_t _reserved4Byte1;
215
216 /**
217 * @brief The problem domain field.
218 */
219 uint8_t _problemDomain;
220
221 /**
222 * @brief The problem vector field.
223 */
224 uint8_t _problemVector;
225
226 /**
227 * @brief The action flags field.
228 */
229 uint16_t _actionFlags;
230
231 /**
232 * @brief The second reserved word placeholder.
233 */
234 uint32_t _reserved4Byte2;
Aatir Manzurad0e0472019-10-07 13:18:37 -0500235
236 /**
237 * @brief Helper function to get values from lookup tables.
238 * @return std::string - the value
239 * @param[in] uint8_t - field to get value for
240 * @param[in] PELValues - lookup table
241 */
242 std::string getValue(const uint8_t field,
243 const pel_values::PELValues& values) const;
Matt Spinler03c1d912019-07-10 14:12:15 -0500244};
245
Matt Spinler03c1d912019-07-10 14:12:15 -0500246} // namespace pels
247} // namespace openpower