1 #pragma once 2 3 #include <cstddef> 4 #include "store.hpp" 5 6 namespace openpower 7 { 8 namespace vpd 9 { 10 namespace parser 11 { 12 13 namespace internal 14 { 15 16 using OffsetList = std::vector<uint32_t>; 17 18 } 19 20 /** @class Impl 21 * @brief Implements parser for OpenPOWER VPD 22 * 23 * An Impl object must be constructed by passing in OpenPOWER VPD in 24 * binary format. To parse the VPD, call the run() method. The run() 25 * method returns an openpower::vpd::Store object, which contains 26 * parsed VPD, and provides access methods for the VPD. 27 * 28 * Following is the algorithm used to parse OpenPOWER VPD: 29 * 1) Validate that the first record is VHDR, the header record. 30 * 2) From the VHDR record, get the offset of the VTOC record, 31 * which is the table of contents record. 32 * 3) Process the VTOC record - note offsets of supported records. 33 * 4) For each supported record : 34 * 4.1) Jump to record via offset. Add record name to parser output. 35 * 4.2) Process record - for each contained and supported keyword: 36 * 4.2.1) Note keyword name and value, associate this information to 37 * to the record noted in step 4.1). 38 */ 39 class Impl 40 { 41 public: 42 Impl() = delete; 43 Impl(const Impl&) = delete; 44 Impl& operator=(const Impl&) = delete; 45 Impl(Impl&&) = delete; 46 Impl& operator=(Impl&&) = delete; 47 ~Impl() = default; 48 49 /** @brief Construct an Impl 50 * 51 * @param[in] vpdBuffer - Binary OpenPOWER VPD 52 */ 53 explicit Impl(Binary&& vpdBuffer) 54 : vpd(std::move(vpdBuffer)), 55 out{} 56 {} 57 58 /** @brief Run the parser on binary OpenPOWER VPD 59 * 60 * @returns openpower::vpd::Store object 61 */ 62 Store run(); 63 64 private: 65 /** @brief Process the table of contents record, VHDR 66 * 67 * @returns List of offsets to records in VPD 68 */ 69 internal::OffsetList readTOC() const; 70 71 /** @brief Read the PT keyword contained in the VHDR record, 72 * to obtain offsets to other records in the VPD. 73 * 74 * @param[in] iterator - iterator to buffer containing VPD 75 * @param[in] ptLength - Length of PT keyword data 76 * 77 * @returns List of offsets to records in VPD 78 */ 79 internal::OffsetList readPT(Binary::const_iterator iterator, 80 std::size_t ptLen) const; 81 82 /** @brief Checks if the VHDR record is present in the VPD */ 83 void checkHeader() const; 84 85 /** @brief OpenPOWER VPD in binary format */ 86 Binary vpd; 87 88 /** @brief parser output */ 89 Parsed out; 90 }; 91 92 } // namespace parser 93 } // namespace vpd 94 } // namespace openpower 95