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