Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "constants.hpp" |
| 4 | #include "exceptions.hpp" |
| 5 | #include "logger.hpp" |
| 6 | #include "parser_interface.hpp" |
| 7 | #include "types.hpp" |
| 8 | |
| 9 | namespace vpd |
| 10 | { |
| 11 | /** |
| 12 | * @brief Concrete class to implement DDIMM VPD parsing. |
| 13 | * |
| 14 | * The class inherits ParserInterface interface class and overrides the parser |
| 15 | * functionality to implement parsing logic for DDIMM VPD format. |
| 16 | */ |
| 17 | class DdimmVpdParser : public ParserInterface |
| 18 | { |
| 19 | public: |
| 20 | // Deleted API's |
| 21 | DdimmVpdParser() = delete; |
| 22 | DdimmVpdParser(const DdimmVpdParser&) = delete; |
| 23 | DdimmVpdParser& operator=(const DdimmVpdParser&) = delete; |
| 24 | DdimmVpdParser(DdimmVpdParser&&) = delete; |
| 25 | DdimmVpdParser& operator=(DdimmVpdParser&&) = delete; |
| 26 | |
| 27 | /** |
| 28 | * @brief Defaul destructor. |
| 29 | */ |
| 30 | ~DdimmVpdParser() = default; |
| 31 | |
| 32 | /** |
| 33 | * @brief Constructor |
| 34 | * |
| 35 | * @param[in] i_vpdVector - VPD data. |
| 36 | */ |
| 37 | DdimmVpdParser(const types::BinaryVector& i_vpdVector) : |
| 38 | m_vpdVector(i_vpdVector) |
| 39 | { |
| 40 | if ((constants::DDIMM_11S_BARCODE_START + |
| 41 | constants::DDIMM_11S_BARCODE_LEN) > m_vpdVector.size()) |
| 42 | { |
| 43 | throw(DataException("Malformed DDIMM VPD")); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @brief API to parse DDIMM VPD file. |
| 49 | * |
| 50 | * @return parsed VPD data |
| 51 | */ |
| 52 | virtual types::VPDMapVariant parse() override; |
| 53 | |
| 54 | private: |
| 55 | /** |
| 56 | * @brief API to read keyword data based on the type DDR4/DDR5. |
| 57 | * |
| 58 | * Updates the m_parsedVpdMap with read keyword data. |
| 59 | * @param[in] i_iterator - iterator to buffer containing VPD |
| 60 | */ |
| 61 | void readKeywords(types::BinaryVector::const_iterator i_iterator); |
| 62 | |
| 63 | /** |
| 64 | * @brief API to calculate DDIMM size from DDIMM VPD |
| 65 | * |
| 66 | * @param[in] i_iterator - iterator to buffer containing VPD |
| 67 | * @return calculated size or 0 in case of any error. |
| 68 | */ |
| 69 | size_t getDdimmSize(types::BinaryVector::const_iterator i_iterator); |
| 70 | |
| 71 | /** |
| 72 | * @brief This function calculates DDR5 based DDIMM's capacity |
| 73 | * |
| 74 | * @param[in] i_iterator - iterator to buffer containing VPD |
| 75 | * @return calculated size or 0 in case of any error. |
| 76 | */ |
| 77 | size_t |
| 78 | getDdr5BasedDdimmSize(types::BinaryVector::const_iterator i_iterator); |
| 79 | |
| 80 | /** |
| 81 | * @brief This function calculates DDR4 based DDIMM's capacity |
| 82 | * |
| 83 | * @param[in] i_iterator - iterator to buffer containing VPD |
| 84 | * @return calculated size or 0 in case of any error. |
| 85 | */ |
| 86 | size_t |
| 87 | getDdr4BasedDdimmSize(types::BinaryVector::const_iterator i_iterator); |
| 88 | |
| 89 | /** |
| 90 | * @brief This function calculates DDR5 based die per package |
| 91 | * |
| 92 | * @param[in] i_ByteValue - the bit value for calculation |
| 93 | * @return die per package value. |
| 94 | */ |
| 95 | uint8_t getDdr5DiePerPackage(uint8_t i_ByteValue); |
| 96 | |
| 97 | /** |
| 98 | * @brief This function calculates DDR5 based density per die |
| 99 | * |
| 100 | * @param[in] i_ByteValue - the bit value for calculation |
| 101 | * @return density per die. |
| 102 | */ |
| 103 | uint8_t getDdr5DensityPerDie(uint8_t i_ByteValue); |
| 104 | |
| 105 | /** |
| 106 | * @brief This function checks the validity of the bits |
| 107 | * |
| 108 | * @param[in] i_ByteValue - the byte value with relevant bits |
| 109 | * @param[in] i_shift - shifter value to selects needed bits |
| 110 | * @param[in] i_minValue - minimum value it can contain |
| 111 | * @param[in] i_maxValue - maximum value it can contain |
| 112 | * @return true if valid else false. |
| 113 | */ |
| 114 | bool checkValidValue(uint8_t i_ByteValue, uint8_t i_shift, |
| 115 | uint8_t i_minValue, uint8_t i_maxValue); |
| 116 | |
| 117 | // VPD file to be parsed |
| 118 | const types::BinaryVector& m_vpdVector; |
| 119 | |
| 120 | // Stores parsed VPD data. |
| 121 | types::DdimmVpdMap m_parsedVpdMap{}; |
| 122 | }; |
| 123 | } // namespace vpd |