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