blob: d8af32d1a106faef733e1daea8fe58f867838b2f [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>;
Deepak Kodihalli683bf722016-11-24 06:50:43 -060031using KeywordMap = Parsed::mapped_type;
Deepak Kodihalli023112f2016-11-22 22:02:14 -060032
33}
34
Deepak Kodihallie08fcad2016-11-22 02:10:08 -060035/** @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 */
54class 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 Kodihalli023112f2016-11-22 22:02:14 -060080 /** @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 Kodihallia1143462016-11-24 06:28:45 -060097 /** @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 Kodihalli4a475bd2016-11-24 07:08:20 -0600104 /** @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 Kodihallia1143462016-11-24 06:28:45 -0600116
Deepak Kodihalli683bf722016-11-24 06:50:43 -0600117 /** @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 Kodihalli810c9de2016-11-22 11:42:51 -0600127 /** @brief Checks if the VHDR record is present in the VPD */
128 void checkHeader() const;
129
Deepak Kodihallie08fcad2016-11-22 02:10:08 -0600130 /** @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