Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "types.hpp" |
| 4 | |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | namespace sdbusplus |
| 10 | { |
| 11 | namespace bus |
| 12 | { |
| 13 | class bus; |
| 14 | } // namespace bus |
| 15 | } // namespace sdbusplus |
| 16 | |
| 17 | namespace sdbusplus |
| 18 | { |
| 19 | namespace message |
| 20 | { |
| 21 | class message; |
| 22 | } // namespace message |
| 23 | } // namespace sdbusplus |
| 24 | |
| 25 | namespace openpower |
| 26 | { |
| 27 | namespace vpd |
| 28 | { |
| 29 | namespace manager |
| 30 | { |
| 31 | |
| 32 | class Manager; |
| 33 | /** |
| 34 | * @brief A class that handles changes to BIOS attributes backed by VPD. |
| 35 | * |
| 36 | * This class has APIs that handle updates to BIOS attributes that need to |
| 37 | * be backed up to VPD. It mainly does the following: |
| 38 | * 1) Checks if the VPD keywords that BIOS attributes are backed to are |
| 39 | * uninitialized. If so, it initializes them. |
| 40 | * 2) Listens for changes to BIOS attributes and synchronizes them to the |
| 41 | * appropriate VPD keyword. |
| 42 | * |
| 43 | * Since on a factory reset like scenario, the BIOS attributes are initialized |
| 44 | * by PLDM, this code waits until PLDM has grabbed a bus name before attempting |
| 45 | * any syncs. |
| 46 | */ |
| 47 | class BiosHandler |
| 48 | { |
| 49 | public: |
| 50 | // Some default and deleted constructors and assignments. |
| 51 | BiosHandler() = delete; |
| 52 | BiosHandler(const BiosHandler&) = delete; |
| 53 | BiosHandler& operator=(const BiosHandler&) = delete; |
| 54 | BiosHandler(Manager&&) = delete; |
| 55 | BiosHandler& operator=(BiosHandler&&) = delete; |
| 56 | ~BiosHandler() = default; |
| 57 | |
| 58 | BiosHandler(sdbusplus::bus::bus& bus, Manager& manager) : |
| 59 | bus(bus), manager(manager) |
| 60 | { |
| 61 | checkAndListenPLDMService(); |
| 62 | } |
| 63 | |
| 64 | private: |
| 65 | /** |
| 66 | * @brief Check if PLDM service is running and run BIOS sync |
| 67 | * |
| 68 | * This API checks if the PLDM service is running and if yes it will start |
| 69 | * an immediate sync of BIOS attributes. If the service is not running, it |
| 70 | * registers a listener to be notified when the service starts so that a |
| 71 | * restore can be performed. |
| 72 | */ |
| 73 | void checkAndListenPLDMService(); |
| 74 | |
| 75 | /** |
| 76 | * @brief Register listener for changes to BIOS Attributes. |
| 77 | * |
| 78 | * The VPD manager needs to listen to changes to certain BIOS attributes |
| 79 | * that are backed by VPD. When the attributes we are interested in |
| 80 | * change, the VPD manager will make sure that we write them back to the |
| 81 | * VPD keywords that back them up. |
| 82 | */ |
| 83 | void listenBiosAttribs(); |
| 84 | |
| 85 | /** |
| 86 | * @brief Callback for BIOS Attribute changes |
| 87 | * |
| 88 | * Checks if the BIOS attribute(s) changed are those backed up by VPD. If |
| 89 | * yes, it will update the VPD with the new attribute value. |
| 90 | * @param[in] msg - The callback message. |
| 91 | */ |
| 92 | void biosAttribsCallback(sdbusplus::message::message& msg); |
| 93 | |
| 94 | /** |
| 95 | * @brief Persistently saves the Memory mirror mode |
| 96 | * |
| 97 | * Memory mirror mode setting is saved to the UTIL/D0 keyword in the |
| 98 | * motherboard VPD. If the mirror mode in BIOS is "Disabled", set D0 to 1, |
| 99 | * if "Enabled" set D0 to 2 |
| 100 | * |
| 101 | * @param[in] mirrorMode - The mirror mode BIOS attribute. |
| 102 | */ |
| 103 | void saveAMMToVPD(const std::string& mirrorMode); |
| 104 | |
| 105 | /** |
| 106 | * @brief Persistently saves the Field Core Override setting |
| 107 | * |
| 108 | * Saves the field core override value (FCO) into the VSYS/RG keyword in |
| 109 | * the motherboard VPD. |
| 110 | * |
| 111 | * @param[in] fcoVal - The FCO value as an integer. |
| 112 | */ |
| 113 | void saveFCOToVPD(int64_t fcoVal); |
| 114 | |
| 115 | /** |
| 116 | * @brief Writes Memory mirror mode to BIOS |
| 117 | * |
Santosh Puranik | f7f8da6 | 2022-05-06 13:01:19 -0500 | [diff] [blame] | 118 | * Writes to the hb_memory_mirror_mode BIOS attribute, if the value is not |
| 119 | * already the same as we are trying to write. |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 120 | * |
| 121 | * @param[in] ammVal - The mirror mode as read from VPD. |
Santosh Puranik | f7f8da6 | 2022-05-06 13:01:19 -0500 | [diff] [blame] | 122 | * @param[in] ammInBIOS - The mirror more in the BIOS table. |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 123 | */ |
Santosh Puranik | f7f8da6 | 2022-05-06 13:01:19 -0500 | [diff] [blame] | 124 | void saveAMMToBIOS(const std::string& ammVal, const std::string& ammInBIOS); |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 125 | |
| 126 | /** |
| 127 | * @brief Writes Field Core Override to BIOS |
| 128 | * |
Santosh Puranik | f7f8da6 | 2022-05-06 13:01:19 -0500 | [diff] [blame] | 129 | * Writes to the hb_field_core_override BIOS attribute, if the value is not |
| 130 | * already the same as we are trying to write. |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 131 | * |
| 132 | * @param[in] fcoVal - The FCO value as read from VPD. |
Santosh Puranik | f7f8da6 | 2022-05-06 13:01:19 -0500 | [diff] [blame] | 133 | * @param[in] fcoInBIOS - The FCO value already in the BIOS table. |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 134 | */ |
Santosh Puranik | f7f8da6 | 2022-05-06 13:01:19 -0500 | [diff] [blame] | 135 | void saveFCOToBIOS(const std::string& fcoVal, int64_t fcoInBIOS); |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 136 | |
| 137 | /** |
| 138 | * @brief Reads the hb_memory_mirror_mode attribute |
| 139 | * |
| 140 | * @return int64_t - The AMM BIOS attribute. -1 on failure. |
| 141 | */ |
| 142 | std::string readBIOSAMM(); |
| 143 | |
| 144 | /** |
| 145 | * @brief Reads the hb_field_core_override attribute |
| 146 | * |
| 147 | * @return std::string - The FCO BIOS attribute. Empty string on failure. |
| 148 | */ |
| 149 | int64_t readBIOSFCO(); |
| 150 | |
| 151 | /** |
| 152 | * @brief Restore BIOS attributes |
| 153 | * |
| 154 | * This function checks if we are coming out of a factory reset. If yes, |
| 155 | * it checks the VPD cache for valid backed up copy of the FCO and AMM |
| 156 | * BIOS attributes. If valid values are found in the VPD, it will apply |
| 157 | * those to the BIOS attributes. |
| 158 | */ |
| 159 | void restoreBIOSAttribs(); |
| 160 | |
| 161 | /** |
| 162 | * @brief Reference to the bus. |
| 163 | */ |
| 164 | sdbusplus::bus::bus& bus; |
| 165 | |
| 166 | /** |
| 167 | * @brief Reference to the manager. |
| 168 | */ |
| 169 | Manager& manager; |
| 170 | }; // class BiosHandler |
| 171 | } // namespace manager |
| 172 | } // namespace vpd |
| 173 | } // namespace openpower |