Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
SunnySrivastava1984 | 19be6d3 | 2020-03-03 07:21:45 -0600 | [diff] [blame] | 3 | #include "const.hpp" |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 4 | #include "store.hpp" |
| 5 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 6 | #include <cstddef> |
| 7 | |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 8 | namespace openpower |
| 9 | { |
| 10 | namespace vpd |
| 11 | { |
| 12 | namespace parser |
| 13 | { |
Deepak Kodihalli | 4a475bd | 2016-11-24 07:08:20 -0600 | [diff] [blame] | 14 | namespace keyword |
| 15 | { |
Deepak Kodihalli | 4a475bd | 2016-11-24 07:08:20 -0600 | [diff] [blame] | 16 | /** @brief Encoding scheme of a VPD keyword's data */ |
| 17 | enum class Encoding |
| 18 | { |
| 19 | ASCII, /**< data encoded in ascii */ |
| 20 | RAW, /**< raw data */ |
| 21 | // Keywords needing custom decoding |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 22 | B1, /**< The keyword B1 needs to be decoded specially */ |
George Liu | ee79ca8 | 2019-07-12 11:05:33 +0800 | [diff] [blame] | 23 | MB, /**< Special decoding of MB meant for Build Date */ |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 24 | UD /**< Special decoding of UD meant for UUID */ |
Deepak Kodihalli | 4a475bd | 2016-11-24 07:08:20 -0600 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | } // namespace keyword |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 28 | |
Deepak Kodihalli | 023112f | 2016-11-22 22:02:14 -0600 | [diff] [blame] | 29 | namespace internal |
| 30 | { |
| 31 | |
Deepak Kodihalli | 4a475bd | 2016-11-24 07:08:20 -0600 | [diff] [blame] | 32 | using KeywordInfo = std::tuple<record::Keyword, keyword::Encoding>; |
Deepak Kodihalli | 023112f | 2016-11-22 22:02:14 -0600 | [diff] [blame] | 33 | using OffsetList = std::vector<uint32_t>; |
Deepak Kodihalli | 683bf72 | 2016-11-24 06:50:43 -0600 | [diff] [blame] | 34 | using KeywordMap = Parsed::mapped_type; |
Deepak Kodihalli | 023112f | 2016-11-22 22:02:14 -0600 | [diff] [blame] | 35 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 36 | } // namespace internal |
Deepak Kodihalli | 023112f | 2016-11-22 22:02:14 -0600 | [diff] [blame] | 37 | |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 38 | /** @class Impl |
Alpana Kumari | 26a74af | 2019-09-10 23:53:58 -0500 | [diff] [blame] | 39 | * @brief Implements parser for VPD |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 40 | * |
Alpana Kumari | 26a74af | 2019-09-10 23:53:58 -0500 | [diff] [blame] | 41 | * An Impl object must be constructed by passing in VPD in |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 42 | * binary format. To parse the VPD, call the run() method. The run() |
| 43 | * method returns an openpower::vpd::Store object, which contains |
| 44 | * parsed VPD, and provides access methods for the VPD. |
| 45 | * |
Alpana Kumari | 26a74af | 2019-09-10 23:53:58 -0500 | [diff] [blame] | 46 | * Following is the algorithm used to parse IPZ/OpenPower VPD: |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 47 | * 1) Validate that the first record is VHDR, the header record. |
| 48 | * 2) From the VHDR record, get the offset of the VTOC record, |
| 49 | * which is the table of contents record. |
| 50 | * 3) Process the VTOC record - note offsets of supported records. |
| 51 | * 4) For each supported record : |
| 52 | * 4.1) Jump to record via offset. Add record name to parser output. |
| 53 | * 4.2) Process record - for each contained and supported keyword: |
| 54 | * 4.2.1) Note keyword name and value, associate this information to |
| 55 | * to the record noted in step 4.1). |
| 56 | */ |
| 57 | class Impl |
| 58 | { |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 59 | public: |
| 60 | Impl() = delete; |
| 61 | Impl(const Impl&) = delete; |
| 62 | Impl& operator=(const Impl&) = delete; |
| 63 | Impl(Impl&&) = delete; |
| 64 | Impl& operator=(Impl&&) = delete; |
| 65 | ~Impl() = default; |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 66 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 67 | /** @brief Construct an Impl |
| 68 | * |
Alpana Kumari | 26a74af | 2019-09-10 23:53:58 -0500 | [diff] [blame] | 69 | * @param[in] vpdBuffer - Binary VPD |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 70 | */ |
| 71 | explicit Impl(Binary&& vpdBuffer) : vpd(std::move(vpdBuffer)), out{} |
| 72 | { |
| 73 | } |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 74 | |
Alpana Kumari | 26a74af | 2019-09-10 23:53:58 -0500 | [diff] [blame] | 75 | /** @brief Run the parser on binary VPD |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 76 | * |
| 77 | * @returns openpower::vpd::Store object |
| 78 | */ |
| 79 | Store run(); |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 80 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 81 | /** @brief check if VPD header is valid |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 82 | */ |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 83 | void checkVPDHeader(); |
| 84 | |
| 85 | private: |
| 86 | /** @brief Process the table of contents record |
| 87 | * |
| 88 | * @param[in] iterator - iterator to buffer containing VPD |
| 89 | * @returns Size of the PT keyword in VTOC |
| 90 | */ |
| 91 | std::size_t readTOC(Binary::const_iterator& iterator) const; |
Deepak Kodihalli | 023112f | 2016-11-22 22:02:14 -0600 | [diff] [blame] | 92 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 93 | /** @brief Read the PT keyword contained in the VHDR record, |
| 94 | * to obtain offsets to other records in the VPD. |
| 95 | * |
| 96 | * @param[in] iterator - iterator to buffer containing VPD |
| 97 | * @param[in] ptLength - Length of PT keyword data |
| 98 | * |
| 99 | * @returns List of offsets to records in VPD |
| 100 | */ |
| 101 | internal::OffsetList readPT(Binary::const_iterator iterator, |
| 102 | std::size_t ptLen) const; |
Deepak Kodihalli | 023112f | 2016-11-22 22:02:14 -0600 | [diff] [blame] | 103 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 104 | /** @brief Read VPD information contained within a record |
| 105 | * |
| 106 | * @param[in] recordOffset - offset to a record location |
Alpana Kumari | 26a74af | 2019-09-10 23:53:58 -0500 | [diff] [blame] | 107 | * within the binary VPD |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 108 | */ |
| 109 | void processRecord(std::size_t recordOffset); |
Deepak Kodihalli | a114346 | 2016-11-24 06:28:45 -0600 | [diff] [blame] | 110 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 111 | /** @brief Read keyword data |
| 112 | * |
Alpana Kumari | 26a74af | 2019-09-10 23:53:58 -0500 | [diff] [blame] | 113 | * @param[in] keyword - VPD keyword |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 114 | * @param[in] dataLength - Length of data to be read |
| 115 | * @param[in] iterator - iterator pointing to a Keyword's data in |
| 116 | * the VPD |
| 117 | * |
| 118 | * @returns keyword data as a string |
| 119 | */ |
| 120 | std::string readKwData(const internal::KeywordInfo& keyword, |
| 121 | std::size_t dataLength, |
| 122 | Binary::const_iterator iterator); |
Deepak Kodihalli | a114346 | 2016-11-24 06:28:45 -0600 | [diff] [blame] | 123 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 124 | /** @brief While we're pointing at the keyword section of |
| 125 | * a record in the VPD, this will read all contained |
| 126 | * keywords and their values. |
| 127 | * |
| 128 | * @param[in] iterator - iterator pointing to a Keyword in the VPD |
| 129 | * |
| 130 | * @returns map of keyword:data |
| 131 | */ |
| 132 | internal::KeywordMap readKeywords(Binary::const_iterator iterator); |
Deepak Kodihalli | 683bf72 | 2016-11-24 06:50:43 -0600 | [diff] [blame] | 133 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 134 | /** @brief Checks if the VHDR record is present in the VPD */ |
| 135 | void checkHeader() const; |
Deepak Kodihalli | 810c9de | 2016-11-22 11:42:51 -0600 | [diff] [blame] | 136 | |
Alpana Kumari | c0aeac3 | 2019-11-28 05:20:10 -0600 | [diff] [blame] | 137 | /** @brief Checks the ECC for VHDR Record. |
| 138 | * @returns Success(0) OR corrupted data(-1) |
| 139 | */ |
| 140 | int vhdrEccCheck() const; |
| 141 | |
| 142 | /** @brief Checks the ECC for VTOC Record. |
| 143 | * @returns Success(0) OR corrupted data(-1) |
| 144 | */ |
| 145 | int vtocEccCheck() const; |
| 146 | |
| 147 | /** @brief Checks the ECC for the given record. |
| 148 | * |
| 149 | * @param[in] iterator - iterator pointing to a record in the VPD |
| 150 | * @returns Success(0) OR corrupted data(-1) |
| 151 | */ |
| 152 | int recordEccCheck(Binary::const_iterator iterator) const; |
| 153 | |
| 154 | /** @brief This interface collects Offset of VTOC |
| 155 | * @returns VTOC Offset |
| 156 | */ |
SunnySrivastava1984 | 19be6d3 | 2020-03-03 07:21:45 -0600 | [diff] [blame] | 157 | openpower::vpd::constants::RecordOffset getVtocOffset() const; |
Alpana Kumari | c0aeac3 | 2019-11-28 05:20:10 -0600 | [diff] [blame] | 158 | |
Alpana Kumari | 26a74af | 2019-09-10 23:53:58 -0500 | [diff] [blame] | 159 | /** @brief VPD in binary format */ |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 160 | Binary vpd; |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 161 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 162 | /** @brief parser output */ |
| 163 | Parsed out; |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 164 | }; |
| 165 | |
| 166 | } // namespace parser |
| 167 | } // namespace vpd |
| 168 | } // namespace openpower |