Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 3 | #include "elog_entry.hpp" |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 4 | #include "pel_values.hpp" |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 5 | #include "registry.hpp" |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 6 | #include "section.hpp" |
| 7 | #include "stream.hpp" |
| 8 | |
| 9 | namespace openpower |
| 10 | { |
| 11 | namespace pels |
| 12 | { |
| 13 | |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 14 | static constexpr uint8_t userHeaderVersion = 0x01; |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 15 | |
| 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 | */ |
| 28 | class 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 Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 41 | * 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 Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 52 | * 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 Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 59 | * @brief Flatten the section into the stream |
| 60 | * |
| 61 | * @param[in] stream - The stream to write to |
| 62 | */ |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 63 | void flatten(Stream& stream) const override; |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 64 | |
| 65 | /** |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 66 | * @brief Returns the subsystem field. |
| 67 | * |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 68 | * @return uint8_t - the subsystem |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 69 | */ |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 70 | uint8_t subsystem() const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 71 | { |
| 72 | return _eventSubsystem; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @brief Returns the event scope field. |
| 77 | * |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 78 | * @return uint8_t - the event scope |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 79 | */ |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 80 | uint8_t scope() const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 81 | { |
| 82 | return _eventScope; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @brief Returns the severity field. |
| 87 | * |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 88 | * @return uint8_t - the severity |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 89 | */ |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 90 | uint8_t severity() const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 91 | { |
| 92 | return _eventSeverity; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @brief Returns the event type field. |
| 97 | * |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 98 | * @return uint8_t - the event type |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 99 | */ |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 100 | uint8_t eventType() const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 101 | { |
| 102 | return _eventType; |
| 103 | } |
| 104 | |
| 105 | /** |
Matt Spinler | f1e85e2 | 2019-11-01 11:31:31 -0500 | [diff] [blame] | 106 | * @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 Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 116 | * @brief Returns the problem domain field. |
| 117 | * |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 118 | * @return uint8_t - the problem domain |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 119 | */ |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 120 | uint8_t problemDomain() const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 121 | { |
| 122 | return _problemDomain; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @brief Returns the problem vector field. |
| 127 | * |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 128 | * @return uint8_t - the problem vector |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 129 | */ |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 130 | uint8_t problemVector() const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 131 | { |
| 132 | return _problemVector; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * @brief Returns the action flags field. |
| 137 | * |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 138 | * @return uint16_t - the action flags |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 139 | */ |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 140 | uint16_t actionFlags() const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 141 | { |
| 142 | return _actionFlags; |
| 143 | } |
| 144 | |
| 145 | /** |
Matt Spinler | f1e85e2 | 2019-11-01 11:31:31 -0500 | [diff] [blame] | 146 | * @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 Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 156 | * @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 Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 169 | /** |
| 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 Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 176 | private: |
| 177 | /** |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 178 | * @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 Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 185 | * @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 Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 235 | |
| 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 Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 244 | }; |
| 245 | |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 246 | } // namespace pels |
| 247 | } // namespace openpower |