1*a1a69f19Skasunath #pragma once 2*a1a69f19Skasunath 3*a1a69f19Skasunath #include <cstdint> 4*a1a69f19Skasunath #include <memory> 5*a1a69f19Skasunath #include <optional> 6*a1a69f19Skasunath #include <span> 7*a1a69f19Skasunath #include <unordered_map> 8*a1a69f19Skasunath #include <vector> 9*a1a69f19Skasunath 10*a1a69f19Skasunath namespace bios_bmc_smm_error_logger 11*a1a69f19Skasunath { 12*a1a69f19Skasunath namespace rde 13*a1a69f19Skasunath { 14*a1a69f19Skasunath 15*a1a69f19Skasunath /** 16*a1a69f19Skasunath * @brief Resource ID for the annotation dictionary. The other entity 17*a1a69f19Skasunath * communicating with the BMC (Eg: BIOS) should use the same resource ID for the 18*a1a69f19Skasunath * annotation dictionary. 19*a1a69f19Skasunath */ 20*a1a69f19Skasunath constexpr uint32_t annotationResourceId = 0; 21*a1a69f19Skasunath 22*a1a69f19Skasunath /** 23*a1a69f19Skasunath * @brief Holds an RDE BEJ dictionary entry. 24*a1a69f19Skasunath */ 25*a1a69f19Skasunath struct DictionaryEntry 26*a1a69f19Skasunath { DictionaryEntrybios_bmc_smm_error_logger::rde::DictionaryEntry27*a1a69f19Skasunath DictionaryEntry(bool valid, const std::span<const uint8_t> data) : 28*a1a69f19Skasunath valid(valid), data(data.begin(), data.end()) 29*a1a69f19Skasunath {} 30*a1a69f19Skasunath // True indicates that the dictionary data is ready to be used. 31*a1a69f19Skasunath bool valid; 32*a1a69f19Skasunath std::vector<uint8_t> data; 33*a1a69f19Skasunath }; 34*a1a69f19Skasunath 35*a1a69f19Skasunath /** 36*a1a69f19Skasunath * @brief Manages RDE BEJ dictionaries. 37*a1a69f19Skasunath */ 38*a1a69f19Skasunath class DictionaryManager 39*a1a69f19Skasunath { 40*a1a69f19Skasunath public: 41*a1a69f19Skasunath DictionaryManager(); 42*a1a69f19Skasunath 43*a1a69f19Skasunath /** 44*a1a69f19Skasunath * @brief Starts a dictionary entry with the provided data. 45*a1a69f19Skasunath * 46*a1a69f19Skasunath * @param[in] resourceId - PDR resource id corresponding to the dictionary. 47*a1a69f19Skasunath * @param[in] data - dictionary data. 48*a1a69f19Skasunath */ 49*a1a69f19Skasunath void startDictionaryEntry(uint32_t resourceId, 50*a1a69f19Skasunath const std::span<const uint8_t> data); 51*a1a69f19Skasunath 52*a1a69f19Skasunath /** 53*a1a69f19Skasunath * @brief Set the dictionary valid status. Until this is called, dictionary 54*a1a69f19Skasunath * data is considered to be incomplete for use. 55*a1a69f19Skasunath * 56*a1a69f19Skasunath * @param[in] resourceId - PDR resource id corresponding to the dictionary. 57*a1a69f19Skasunath * @return true if successful. 58*a1a69f19Skasunath */ 59*a1a69f19Skasunath bool markDataComplete(uint32_t resourceId); 60*a1a69f19Skasunath 61*a1a69f19Skasunath /** 62*a1a69f19Skasunath * @brief Add more dictionary data for an existing entry. Adding data to a 63*a1a69f19Skasunath * completed dictionary will mark the dictionary as incomplete. 64*a1a69f19Skasunath * 65*a1a69f19Skasunath * @param[in] resourceId - PDR resource id corresponding to the dictionary. 66*a1a69f19Skasunath * @param[in] data - dictionary data. 67*a1a69f19Skasunath * @return true if successful. 68*a1a69f19Skasunath */ 69*a1a69f19Skasunath bool addDictionaryData(uint32_t resourceId, 70*a1a69f19Skasunath const std::span<const uint8_t> data); 71*a1a69f19Skasunath 72*a1a69f19Skasunath /** 73*a1a69f19Skasunath * @brief Get a dictionary. 74*a1a69f19Skasunath * 75*a1a69f19Skasunath * @param[in] resourceId - PDR resource id corresponding to the dictionary. 76*a1a69f19Skasunath * @return a pointer to the dictionary, if the dictionary is complete else 77*a1a69f19Skasunath * std::nullopt. 78*a1a69f19Skasunath */ 79*a1a69f19Skasunath std::optional<std::span<const uint8_t>> getDictionary(uint32_t resourceId); 80*a1a69f19Skasunath 81*a1a69f19Skasunath /** 82*a1a69f19Skasunath * @brief Get the annotation dictionary. 83*a1a69f19Skasunath * 84*a1a69f19Skasunath * @return a pointer to the annotation dictionary, if the dictionary is 85*a1a69f19Skasunath * complete else std::nullopt. 86*a1a69f19Skasunath */ 87*a1a69f19Skasunath std::optional<std::span<const uint8_t>> getAnnotationDictionary(); 88*a1a69f19Skasunath 89*a1a69f19Skasunath /** 90*a1a69f19Skasunath * @brief Get the completed dictionary count. 91*a1a69f19Skasunath * 92*a1a69f19Skasunath * @return number of completed dictionaries available. 93*a1a69f19Skasunath */ 94*a1a69f19Skasunath uint32_t getDictionaryCount(); 95*a1a69f19Skasunath 96*a1a69f19Skasunath /** 97*a1a69f19Skasunath * @brief Invalidate all dictionaries. 98*a1a69f19Skasunath */ 99*a1a69f19Skasunath void invalidateDictionaries(); 100*a1a69f19Skasunath 101*a1a69f19Skasunath private: 102*a1a69f19Skasunath uint32_t validDictionaryCount; 103*a1a69f19Skasunath std::unordered_map<uint32_t, std::unique_ptr<DictionaryEntry>> dictionaries; 104*a1a69f19Skasunath 105*a1a69f19Skasunath /** 106*a1a69f19Skasunath * @brief Set a dictionary entry to be invalid and reduce the valid 107*a1a69f19Skasunath * dictionary count. 108*a1a69f19Skasunath * 109*a1a69f19Skasunath * @param[in] entry - A dictionary entry. 110*a1a69f19Skasunath */ 111*a1a69f19Skasunath void invalidateDictionaryEntry(DictionaryEntry& entry); 112*a1a69f19Skasunath 113*a1a69f19Skasunath /** 114*a1a69f19Skasunath * @brief Set the dictionary entry valid flag and increase the valid 115*a1a69f19Skasunath * dictionary count. 116*a1a69f19Skasunath * 117*a1a69f19Skasunath * @param[in] entry - A dictionary entry. 118*a1a69f19Skasunath */ 119*a1a69f19Skasunath void validateDictionaryEntry(DictionaryEntry& entry); 120*a1a69f19Skasunath }; 121*a1a69f19Skasunath 122*a1a69f19Skasunath } // namespace rde 123*a1a69f19Skasunath } // namespace bios_bmc_smm_error_logger 124