blob: 42a5c44f008d9fbb184eb2cd846df9e8127171ca [file] [log] [blame]
Deepak Kodihallie08fcad2016-11-22 02:10:08 -06001#pragma once
2
Deepak Kodihalli023112f2016-11-22 22:02:14 -06003#include <cstddef>
Deepak Kodihallie08fcad2016-11-22 02:10:08 -06004#include "store.hpp"
5
6namespace openpower
7{
8namespace vpd
9{
10namespace parser
11{
Deepak Kodihalli4a475bd2016-11-24 07:08:20 -060012namespace keyword
13{
14
15/** @brief Encoding scheme of a VPD keyword's data */
16enum 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 Kodihallie08fcad2016-11-22 02:10:08 -060025
Deepak Kodihalli023112f2016-11-22 22:02:14 -060026namespace internal
27{
28
Deepak Kodihalli4a475bd2016-11-24 07:08:20 -060029using KeywordInfo = std::tuple<record::Keyword, keyword::Encoding>;
Deepak Kodihalli023112f2016-11-22 22:02:14 -060030using OffsetList = std::vector<uint32_t>;
31
32}
33
Deepak Kodihallie08fcad2016-11-22 02:10:08 -060034/** @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 */
53class 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 Kodihalli023112f2016-11-22 22:02:14 -060079 /** @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 Kodihallia1143462016-11-24 06:28:45 -060096 /** @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 Kodihalli4a475bd2016-11-24 07:08:20 -0600103 /** @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 Kodihallia1143462016-11-24 06:28:45 -0600115
Deepak Kodihalli810c9de2016-11-22 11:42:51 -0600116 /** @brief Checks if the VHDR record is present in the VPD */
117 void checkHeader() const;
118
Deepak Kodihallie08fcad2016-11-22 02:10:08 -0600119 /** @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