1642f437eSKuiying Wang /* 2fae57325SManojkiran Eda Copyright (c) 2020 Intel Corporation 3fae57325SManojkiran Eda 4fae57325SManojkiran Eda Licensed under the Apache License, Version 2.0 (the "License"); 5fae57325SManojkiran Eda you may not use this file except in compliance with the License. 6fae57325SManojkiran Eda You may obtain a copy of the License at 7fae57325SManojkiran Eda 8fae57325SManojkiran Eda http:www.apache.org/licenses/LICENSE-2.0 9fae57325SManojkiran Eda 10fae57325SManojkiran Eda Unless required by applicable law or agreed to in writing, software 11fae57325SManojkiran Eda distributed under the License is distributed on an "AS IS" BASIS, 12fae57325SManojkiran Eda WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fae57325SManojkiran Eda See the License for the specific language governing permissions and 14fae57325SManojkiran Eda limitations under the License. 15642f437eSKuiying Wang */ 16fae57325SManojkiran Eda 17642f437eSKuiying Wang #pragma once 18642f437eSKuiying Wang 19642f437eSKuiying Wang #include <sdbusplus/asio/object_server.hpp> 20642f437eSKuiying Wang #include <sdbusplus/server.hpp> 21642f437eSKuiying Wang #include <xyz/openbmc_project/BIOSConfig/Manager/server.hpp> 22642f437eSKuiying Wang 23f1101df2STom Joseph #include <filesystem> 24642f437eSKuiying Wang #include <string> 25642f437eSKuiying Wang 26642f437eSKuiying Wang namespace bios_config 27642f437eSKuiying Wang { 28642f437eSKuiying Wang 29642f437eSKuiying Wang static constexpr auto service = "xyz.openbmc_project.BIOSConfigManager"; 30642f437eSKuiying Wang static constexpr auto objectPath = "/xyz/openbmc_project/bios_config/manager"; 31f1101df2STom Joseph constexpr auto biosPersistFile = "biosData"; 32642f437eSKuiying Wang 33642f437eSKuiying Wang using Base = sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager; 34f1101df2STom Joseph namespace fs = std::filesystem; 35642f437eSKuiying Wang 36642f437eSKuiying Wang /** @class Manager 37642f437eSKuiying Wang * 38642f437eSKuiying Wang * @brief Implements the BIOS Manager 39642f437eSKuiying Wang */ 40642f437eSKuiying Wang class Manager : public Base 41642f437eSKuiying Wang { 42642f437eSKuiying Wang public: 43642f437eSKuiying Wang using BaseTable = std::map< 44642f437eSKuiying Wang std::string, 451a448ad8SArun Lal K M std::tuple< 461a448ad8SArun Lal K M AttributeType, bool, std::string, std::string, std::string, 47642f437eSKuiying Wang std::variant<int64_t, std::string>, 48642f437eSKuiying Wang std::variant<int64_t, std::string>, 49642f437eSKuiying Wang std::vector<std::tuple< 501a448ad8SArun Lal K M BoundType, std::variant<int64_t, std::string>, std::string>>>>; 51642f437eSKuiying Wang 52*4e29f80bSArchana Kakani using oldBaseTable = std::map< 53*4e29f80bSArchana Kakani std::string, 54*4e29f80bSArchana Kakani std::tuple<AttributeType, bool, std::string, std::string, std::string, 55*4e29f80bSArchana Kakani std::variant<int64_t, std::string>, 56*4e29f80bSArchana Kakani std::variant<int64_t, std::string>, 57*4e29f80bSArchana Kakani std::vector<std::tuple< 58*4e29f80bSArchana Kakani BoundType, std::variant<int64_t, std::string>>>>>; 59*4e29f80bSArchana Kakani 605e2cb720SSnehalatha Venkatesh using ResetFlag = std::map<std::string, ResetFlag>; 615e2cb720SSnehalatha Venkatesh 62642f437eSKuiying Wang using PendingAttributes = 63642f437eSKuiying Wang std::map<std::string, 64642f437eSKuiying Wang std::tuple<AttributeType, std::variant<int64_t, std::string>>>; 65642f437eSKuiying Wang 66642f437eSKuiying Wang using PendingAttribute = 67642f437eSKuiying Wang std::tuple<AttributeType, std::variant<int64_t, std::string>>; 68642f437eSKuiying Wang 69642f437eSKuiying Wang using AttributeName = std::string; 70642f437eSKuiying Wang using AttributeValue = std::variant<int64_t, std::string>; 71642f437eSKuiying Wang using CurrentValue = std::variant<int64_t, std::string>; 72642f437eSKuiying Wang using PendingValue = std::variant<int64_t, std::string>; 73642f437eSKuiying Wang using AttributeDetails = 74642f437eSKuiying Wang std::tuple<AttributeType, CurrentValue, PendingValue>; 75642f437eSKuiying Wang 76642f437eSKuiying Wang Manager() = delete; 77642f437eSKuiying Wang ~Manager() = default; 78642f437eSKuiying Wang Manager(const Manager&) = delete; 79642f437eSKuiying Wang Manager& operator=(const Manager&) = delete; 80642f437eSKuiying Wang Manager(Manager&&) = delete; 81642f437eSKuiying Wang Manager& operator=(Manager&&) = delete; 82642f437eSKuiying Wang 83642f437eSKuiying Wang /** @brief Constructs Manager object. 84642f437eSKuiying Wang * 85642f437eSKuiying Wang * @param[in] objectServer - object server 86642f437eSKuiying Wang * @param[in] systemBus - bus connection 87642f437eSKuiying Wang */ 88642f437eSKuiying Wang Manager(sdbusplus::asio::object_server& objectServer, 895c7e80d5SPatrick Williams std::shared_ptr<sdbusplus::asio::connection>& systemBus, 905c7e80d5SPatrick Williams std::string persistPath); 91642f437eSKuiying Wang 92642f437eSKuiying Wang /** @brief Set the BIOS attribute with a new value, the new value is added 93642f437eSKuiying Wang * to the PendingAttribute. 94642f437eSKuiying Wang * 95642f437eSKuiying Wang * @param[in] attribute - attribute name 96642f437eSKuiying Wang * @param[in] value - new value for the attribute 97642f437eSKuiying Wang * 98642f437eSKuiying Wang * @return On error, throw exception 99642f437eSKuiying Wang */ 100642f437eSKuiying Wang void setAttribute(AttributeName attribute, AttributeValue value) override; 101642f437eSKuiying Wang 102642f437eSKuiying Wang /** @brief Get the details of the BIOS attribute 103642f437eSKuiying Wang * 104642f437eSKuiying Wang * @param[in] attribute - attribute name 105642f437eSKuiying Wang * 106642f437eSKuiying Wang * @return On success, return the attribute details: attribute type, 107642f437eSKuiying Wang * current value, pending value. On error, throw exception 108642f437eSKuiying Wang */ 109642f437eSKuiying Wang AttributeDetails getAttribute(AttributeName attribute) override; 110642f437eSKuiying Wang 111642f437eSKuiying Wang /** @brief Set the BaseBIOSTable property and clears the PendingAttributes 112642f437eSKuiying Wang * property 113642f437eSKuiying Wang * 114642f437eSKuiying Wang * @param[in] value - new BaseBIOSTable 115642f437eSKuiying Wang * 116642f437eSKuiying Wang * @return The new BaseBIOSTable that is applied. 117642f437eSKuiying Wang */ 118642f437eSKuiying Wang BaseTable baseBIOSTable(BaseTable value) override; 119642f437eSKuiying Wang 1205e2cb720SSnehalatha Venkatesh ResetFlag resetBIOSSettings(ResetFlag value); 1215e2cb720SSnehalatha Venkatesh 122642f437eSKuiying Wang /** @brief Set the PendingAttributes property, additionally checks if the 123642f437eSKuiying Wang * attributes are in the BaseBIOSTable, whether the attributes are 124642f437eSKuiying Wang * read only and validate the attribute value based on the 125642f437eSKuiying Wang * attribute type. PendingAttributes is cleared if value is empty. 126642f437eSKuiying Wang * 127642f437eSKuiying Wang * @param[in] value - new PendingAttributes to append to the 128642f437eSKuiying Wang * PendingAttributes property 129642f437eSKuiying Wang * 130642f437eSKuiying Wang * @return On success, return the new PendingAttributes property that is 131642f437eSKuiying Wang * set.Throw exception if the validation fails. 132642f437eSKuiying Wang */ 133642f437eSKuiying Wang PendingAttributes pendingAttributes(PendingAttributes value) override; 134642f437eSKuiying Wang 135*4e29f80bSArchana Kakani /** @brief Convert the previosuly supported Base BIOS table to newly 136*4e29f80bSArchana Kakani * supported Base BIOS table 137*4e29f80bSArchana Kakani * 138*4e29f80bSArchana Kakani * @param[in] biosTbl - Old Base BIOS table (without VDN) 139*4e29f80bSArchana Kakani * @param[in] baseTable - Recently supported Base BIOS table (with VDN) 140*4e29f80bSArchana Kakani * 141*4e29f80bSArchana Kakani * @return void 142*4e29f80bSArchana Kakani * 143*4e29f80bSArchana Kakani */ 144*4e29f80bSArchana Kakani void convertBiosDataToVersion1(Manager::oldBaseTable biosTbl, 145*4e29f80bSArchana Kakani Manager::BaseTable& baseTable); 146*4e29f80bSArchana Kakani 147*4e29f80bSArchana Kakani /** @brief Convert the VDN supported Base BIOS table to old Base BIOS table 148*4e29f80bSArchana Kakani * 149*4e29f80bSArchana Kakani * @param[in] biosTbl - Old Base BIOS table (without VDN) 150*4e29f80bSArchana Kakani * @param[in] baseTable - Recently supported Base BIOS table (with VDN) 151*4e29f80bSArchana Kakani * 152*4e29f80bSArchana Kakani * @return void 153*4e29f80bSArchana Kakani */ 154*4e29f80bSArchana Kakani void convertBiosDataToVersion0(Manager::oldBaseTable& baseTable, 155*4e29f80bSArchana Kakani Manager::BaseTable& biosTbl); 156*4e29f80bSArchana Kakani 157642f437eSKuiying Wang private: 158642f437eSKuiying Wang /** @enum Index into the fields in the BaseBIOSTable 159642f437eSKuiying Wang */ 160642f437eSKuiying Wang enum class Index : uint8_t 161642f437eSKuiying Wang { 162642f437eSKuiying Wang attributeType = 0, 163642f437eSKuiying Wang readOnly, 164642f437eSKuiying Wang displayName, 165642f437eSKuiying Wang description, 166642f437eSKuiying Wang menuPath, 167642f437eSKuiying Wang currentValue, 168642f437eSKuiying Wang defaultValue, 169642f437eSKuiying Wang options, 170642f437eSKuiying Wang }; 171642f437eSKuiying Wang 172ad54c7cbSyes bool validateEnumOption( 173ad54c7cbSyes const std::string& attrValue, 1741a448ad8SArun Lal K M const std::vector<std::tuple< 1751a448ad8SArun Lal K M BoundType, std::variant<int64_t, std::string>, std::string>>& 176ad54c7cbSyes options); 177ad54c7cbSyes 178ad54c7cbSyes bool validateStringOption( 179ad54c7cbSyes const std::string& attrValue, 1801a448ad8SArun Lal K M const std::vector<std::tuple< 1811a448ad8SArun Lal K M BoundType, std::variant<int64_t, std::string>, std::string>>& 182ad54c7cbSyes options); 183ad54c7cbSyes 184ad54c7cbSyes bool validateIntegerOption( 185ad54c7cbSyes const int64_t& attrValue, 1861a448ad8SArun Lal K M const std::vector<std::tuple< 1871a448ad8SArun Lal K M BoundType, std::variant<int64_t, std::string>, std::string>>& 188ad54c7cbSyes options); 189ad54c7cbSyes 190642f437eSKuiying Wang sdbusplus::asio::object_server& objServer; 191642f437eSKuiying Wang std::shared_ptr<sdbusplus::asio::connection>& systemBus; 192f1101df2STom Joseph std::filesystem::path biosFile; 193642f437eSKuiying Wang }; 194642f437eSKuiying Wang 195642f437eSKuiying Wang } // namespace bios_config 196