Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Marri Devender Rao | 2b30dea | 2021-12-17 02:38:30 -0600 | [diff] [blame] | 3 | #include "xyz/openbmc_project/Logging/Entry/server.hpp" |
| 4 | |
Jayanth Othayoth | 2eb31ad | 2021-09-20 07:13:28 -0500 | [diff] [blame] | 5 | #include <phal_exception.H> |
| 6 | |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 7 | #include <nlohmann/json.hpp> |
Brad Bishop | 5e5d445 | 2020-10-27 19:46:13 -0400 | [diff] [blame] | 8 | |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
Jayanth Othayoth | e5ba5fd | 2022-01-27 09:29:01 -0600 | [diff] [blame] | 11 | |
| 12 | extern "C" |
| 13 | { |
| 14 | #include <libpdbg.h> |
| 15 | } |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 16 | namespace openpower |
| 17 | { |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 18 | namespace pel |
| 19 | { |
| 20 | using FFDCData = std::vector<std::pair<std::string, std::string>>; |
| 21 | |
| 22 | using json = nlohmann::json; |
| 23 | |
Jayanth Othayoth | 2eb31ad | 2021-09-20 07:13:28 -0500 | [diff] [blame] | 24 | using namespace openpower::phal; |
Marri Devender Rao | 2b30dea | 2021-12-17 02:38:30 -0600 | [diff] [blame] | 25 | using Severity = sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level; |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 26 | /** |
Jayanth Othayoth | 8fe9ff9 | 2021-11-14 09:15:59 -0600 | [diff] [blame] | 27 | * @brief Create PEL with additional parameters and callout |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 28 | * |
Jayanth Othayoth | 8fe9ff9 | 2021-11-14 09:15:59 -0600 | [diff] [blame] | 29 | * @param[in] event - the event type |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 30 | * @param[in] calloutData - callout data to append to PEL |
Jayanth Othayoth | 8fe9ff9 | 2021-11-14 09:15:59 -0600 | [diff] [blame] | 31 | * @param[in] ffdcData - failure data to append to PEL |
Marri Devender Rao | 4d5b5bf | 2022-05-23 09:23:31 -0500 | [diff] [blame] | 32 | * @param[in] severity - severity of the log default to Informational |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 33 | */ |
Jayanth Othayoth | 8fe9ff9 | 2021-11-14 09:15:59 -0600 | [diff] [blame] | 34 | void createErrorPEL(const std::string& event, const json& calloutData = {}, |
Marri Devender Rao | 4d5b5bf | 2022-05-23 09:23:31 -0500 | [diff] [blame] | 35 | const FFDCData& ffdcData = {}, |
| 36 | const Severity severity = Severity::Informational); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 37 | |
| 38 | /** |
Jayanth Othayoth | fe37aea | 2021-10-07 04:41:26 -0500 | [diff] [blame] | 39 | * @brief Create SBE boot error PEL and return id |
Jayanth Othayoth | 2eb31ad | 2021-09-20 07:13:28 -0500 | [diff] [blame] | 40 | * |
| 41 | * @param[in] event - the event type |
| 42 | * @param[in] sbeError - SBE error object |
| 43 | * @param[in] ffdcData - failure data to append to PEL |
Jayanth Othayoth | e5ba5fd | 2022-01-27 09:29:01 -0600 | [diff] [blame] | 44 | * @param[in] procTarget - pdbg processor target |
Marri Devender Rao | 2b30dea | 2021-12-17 02:38:30 -0600 | [diff] [blame] | 45 | * @param[in] severity - severity of the log |
Jayanth Othayoth | fe37aea | 2021-10-07 04:41:26 -0500 | [diff] [blame] | 46 | * @return Platform log id |
Jayanth Othayoth | 2eb31ad | 2021-09-20 07:13:28 -0500 | [diff] [blame] | 47 | */ |
Jayanth Othayoth | fe37aea | 2021-10-07 04:41:26 -0500 | [diff] [blame] | 48 | uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError, |
Marri Devender Rao | 2b30dea | 2021-12-17 02:38:30 -0600 | [diff] [blame] | 49 | const FFDCData& ffdcData, |
Jayanth Othayoth | e5ba5fd | 2022-01-27 09:29:01 -0600 | [diff] [blame] | 50 | struct pdbg_target* procTarget, |
Marri Devender Rao | 2b30dea | 2021-12-17 02:38:30 -0600 | [diff] [blame] | 51 | const Severity severity = Severity::Error); |
Jayanth Othayoth | 2eb31ad | 2021-09-20 07:13:28 -0500 | [diff] [blame] | 52 | |
| 53 | /** |
Jayanth Othayoth | a8d2f71 | 2021-09-20 07:02:51 -0500 | [diff] [blame] | 54 | * @brief Create a PEL for the specified event type and additional data |
Andrew Geissler | 61febf0 | 2021-06-22 17:19:32 -0500 | [diff] [blame] | 55 | * |
Jayanth Othayoth | 2eb31ad | 2021-09-20 07:13:28 -0500 | [diff] [blame] | 56 | * @param[in] event - the event type |
Jayanth Othayoth | a8d2f71 | 2021-09-20 07:02:51 -0500 | [diff] [blame] | 57 | * @param[in] ffdcData - failure data to append to PEL |
Matt Spinler | be14ec2 | 2023-03-24 15:59:48 -0500 | [diff] [blame] | 58 | * @param[in] severity - severity of the log |
Andrew Geissler | 61febf0 | 2021-06-22 17:19:32 -0500 | [diff] [blame] | 59 | */ |
Matt Spinler | be14ec2 | 2023-03-24 15:59:48 -0500 | [diff] [blame] | 60 | void createPEL(const std::string& event, const FFDCData& ffdcData = {}, |
| 61 | const Severity severity = Severity::Error); |
Andrew Geissler | 61febf0 | 2021-06-22 17:19:32 -0500 | [diff] [blame] | 62 | |
| 63 | /** |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 64 | * @class FFDCFile |
| 65 | * @brief This class is used to create ffdc data file and to get fd |
| 66 | */ |
| 67 | class FFDCFile |
| 68 | { |
| 69 | public: |
| 70 | FFDCFile() = delete; |
| 71 | FFDCFile(const FFDCFile&) = delete; |
| 72 | FFDCFile& operator=(const FFDCFile&) = delete; |
| 73 | FFDCFile(FFDCFile&&) = delete; |
| 74 | FFDCFile& operator=(FFDCFile&&) = delete; |
| 75 | |
| 76 | /** |
| 77 | * Used to pass json object to create unique ffdc file by using |
| 78 | * passed json data. |
| 79 | */ |
| 80 | explicit FFDCFile(const json& pHALCalloutData); |
| 81 | |
| 82 | /** |
| 83 | * Used to remove created ffdc file. |
| 84 | */ |
| 85 | ~FFDCFile(); |
| 86 | |
| 87 | /** |
| 88 | * Used to get created ffdc file file descriptor id. |
| 89 | * |
| 90 | * @return file descriptor id |
| 91 | */ |
| 92 | int getFileFD() const; |
| 93 | |
| 94 | private: |
| 95 | /** |
| 96 | * Used to store callout ffdc data from passed json object. |
| 97 | */ |
| 98 | std::string calloutData; |
| 99 | |
| 100 | /** |
| 101 | * Used to store unique ffdc file name. |
| 102 | */ |
| 103 | std::string calloutFile; |
| 104 | |
| 105 | /** |
| 106 | * Used to store created ffdc file descriptor id. |
| 107 | */ |
| 108 | int fileFD; |
| 109 | |
| 110 | /** |
| 111 | * Used to create ffdc file to pass PEL api for creating |
| 112 | * pel records. |
| 113 | * |
| 114 | * @return NULL |
| 115 | */ |
| 116 | void prepareFFDCFile(); |
| 117 | |
| 118 | /** |
| 119 | * Create unique ffdc file. |
| 120 | * |
| 121 | * @return NULL |
| 122 | */ |
| 123 | void createCalloutFile(); |
| 124 | |
| 125 | /** |
| 126 | * Used write json object value into created file. |
| 127 | * |
| 128 | * @return NULL |
| 129 | */ |
| 130 | void writeCalloutData(); |
| 131 | |
| 132 | /** |
| 133 | * Used set ffdc file seek position begining to consume by PEL |
| 134 | * |
| 135 | * @return NULL |
| 136 | */ |
| 137 | void setCalloutFileSeekPos(); |
| 138 | |
| 139 | /** |
| 140 | * Used to remove created ffdc file. |
| 141 | * |
| 142 | * @return NULL |
| 143 | */ |
| 144 | void removeCalloutFile(); |
| 145 | |
| 146 | }; // FFDCFile end |
| 147 | |
| 148 | } // namespace pel |
| 149 | } // namespace openpower |