Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "store.hpp" |
| 4 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 5 | #include <cstddef> |
| 6 | |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 7 | namespace openpower |
| 8 | { |
| 9 | namespace vpd |
| 10 | { |
| 11 | namespace parser |
| 12 | { |
Deepak Kodihalli | 4a475bd | 2016-11-24 07:08:20 -0600 | [diff] [blame] | 13 | namespace keyword |
| 14 | { |
| 15 | |
| 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 */ |
| 23 | UD /**< Special decoding of UD meant for UUID */ |
Deepak Kodihalli | 4a475bd | 2016-11-24 07:08:20 -0600 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | } // namespace keyword |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 27 | |
Deepak Kodihalli | 023112f | 2016-11-22 22:02:14 -0600 | [diff] [blame] | 28 | namespace internal |
| 29 | { |
| 30 | |
Deepak Kodihalli | 4a475bd | 2016-11-24 07:08:20 -0600 | [diff] [blame] | 31 | using KeywordInfo = std::tuple<record::Keyword, keyword::Encoding>; |
Deepak Kodihalli | 023112f | 2016-11-22 22:02:14 -0600 | [diff] [blame] | 32 | using OffsetList = std::vector<uint32_t>; |
Deepak Kodihalli | 683bf72 | 2016-11-24 06:50:43 -0600 | [diff] [blame] | 33 | using KeywordMap = Parsed::mapped_type; |
Deepak Kodihalli | 023112f | 2016-11-22 22:02:14 -0600 | [diff] [blame] | 34 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 35 | } // namespace internal |
Deepak Kodihalli | 023112f | 2016-11-22 22:02:14 -0600 | [diff] [blame] | 36 | |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 37 | /** @class Impl |
| 38 | * @brief Implements parser for OpenPOWER VPD |
| 39 | * |
| 40 | * An Impl object must be constructed by passing in OpenPOWER VPD in |
| 41 | * binary format. To parse the VPD, call the run() method. The run() |
| 42 | * method returns an openpower::vpd::Store object, which contains |
| 43 | * parsed VPD, and provides access methods for the VPD. |
| 44 | * |
| 45 | * Following is the algorithm used to parse OpenPOWER VPD: |
| 46 | * 1) Validate that the first record is VHDR, the header record. |
| 47 | * 2) From the VHDR record, get the offset of the VTOC record, |
| 48 | * which is the table of contents record. |
| 49 | * 3) Process the VTOC record - note offsets of supported records. |
| 50 | * 4) For each supported record : |
| 51 | * 4.1) Jump to record via offset. Add record name to parser output. |
| 52 | * 4.2) Process record - for each contained and supported keyword: |
| 53 | * 4.2.1) Note keyword name and value, associate this information to |
| 54 | * to the record noted in step 4.1). |
| 55 | */ |
| 56 | class Impl |
| 57 | { |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 58 | public: |
| 59 | Impl() = delete; |
| 60 | Impl(const Impl&) = delete; |
| 61 | Impl& operator=(const Impl&) = delete; |
| 62 | Impl(Impl&&) = delete; |
| 63 | Impl& operator=(Impl&&) = delete; |
| 64 | ~Impl() = default; |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 65 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 66 | /** @brief Construct an Impl |
| 67 | * |
| 68 | * @param[in] vpdBuffer - Binary OpenPOWER VPD |
| 69 | */ |
| 70 | explicit Impl(Binary&& vpdBuffer) : vpd(std::move(vpdBuffer)), out{} |
| 71 | { |
| 72 | } |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 73 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 74 | /** @brief Run the parser on binary OpenPOWER VPD |
| 75 | * |
| 76 | * @returns openpower::vpd::Store object |
| 77 | */ |
| 78 | Store run(); |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 79 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 80 | private: |
| 81 | /** @brief Process the table of contents record, VHDR |
| 82 | * |
| 83 | * @returns List of offsets to records in VPD |
| 84 | */ |
| 85 | internal::OffsetList readTOC() const; |
Deepak Kodihalli | 023112f | 2016-11-22 22:02:14 -0600 | [diff] [blame] | 86 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 87 | /** @brief Read the PT keyword contained in the VHDR record, |
| 88 | * to obtain offsets to other records in the VPD. |
| 89 | * |
| 90 | * @param[in] iterator - iterator to buffer containing VPD |
| 91 | * @param[in] ptLength - Length of PT keyword data |
| 92 | * |
| 93 | * @returns List of offsets to records in VPD |
| 94 | */ |
| 95 | internal::OffsetList readPT(Binary::const_iterator iterator, |
| 96 | std::size_t ptLen) const; |
Deepak Kodihalli | 023112f | 2016-11-22 22:02:14 -0600 | [diff] [blame] | 97 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 98 | /** @brief Read VPD information contained within a record |
| 99 | * |
| 100 | * @param[in] recordOffset - offset to a record location |
| 101 | * within the binary OpenPOWER VPD |
| 102 | */ |
| 103 | void processRecord(std::size_t recordOffset); |
Deepak Kodihalli | a114346 | 2016-11-24 06:28:45 -0600 | [diff] [blame] | 104 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 105 | /** @brief Read keyword data |
| 106 | * |
| 107 | * @param[in] keyword - OpenPOWER VPD keyword |
| 108 | * @param[in] dataLength - Length of data to be read |
| 109 | * @param[in] iterator - iterator pointing to a Keyword's data in |
| 110 | * the VPD |
| 111 | * |
| 112 | * @returns keyword data as a string |
| 113 | */ |
| 114 | std::string readKwData(const internal::KeywordInfo& keyword, |
| 115 | std::size_t dataLength, |
| 116 | Binary::const_iterator iterator); |
Deepak Kodihalli | a114346 | 2016-11-24 06:28:45 -0600 | [diff] [blame] | 117 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 118 | /** @brief While we're pointing at the keyword section of |
| 119 | * a record in the VPD, this will read all contained |
| 120 | * keywords and their values. |
| 121 | * |
| 122 | * @param[in] iterator - iterator pointing to a Keyword in the VPD |
| 123 | * |
| 124 | * @returns map of keyword:data |
| 125 | */ |
| 126 | internal::KeywordMap readKeywords(Binary::const_iterator iterator); |
Deepak Kodihalli | 683bf72 | 2016-11-24 06:50:43 -0600 | [diff] [blame] | 127 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 128 | /** @brief Checks if the VHDR record is present in the VPD */ |
| 129 | void checkHeader() const; |
Deepak Kodihalli | 810c9de | 2016-11-22 11:42:51 -0600 | [diff] [blame] | 130 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 131 | /** @brief OpenPOWER VPD in binary format */ |
| 132 | Binary vpd; |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 133 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 134 | /** @brief parser output */ |
| 135 | Parsed out; |
Deepak Kodihalli | e08fcad | 2016-11-22 02:10:08 -0600 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | } // namespace parser |
| 139 | } // namespace vpd |
| 140 | } // namespace openpower |