1642f437eSKuiying Wang /* 2642f437eSKuiying Wang // Copyright (c) 2020 Intel Corporation 3642f437eSKuiying Wang // 4642f437eSKuiying Wang // Licensed under the Apache License, Version 2.0 (the "License"); 5642f437eSKuiying Wang // you may not use this file except in compliance with the License. 6642f437eSKuiying Wang // You may obtain a copy of the License at 7642f437eSKuiying Wang // 8642f437eSKuiying Wang // http://www.apache.org/licenses/LICENSE-2.0 9642f437eSKuiying Wang // 10642f437eSKuiying Wang // Unless required by applicable law or agreed to in writing, software 11642f437eSKuiying Wang // distributed under the License is distributed on an "AS IS" BASIS, 12642f437eSKuiying Wang // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13642f437eSKuiying Wang // See the License for the specific language governing permissions and 14642f437eSKuiying Wang // limitations under the License. 15642f437eSKuiying Wang */ 16642f437eSKuiying Wang #pragma once 17642f437eSKuiying Wang 18642f437eSKuiying Wang #include <sdbusplus/asio/object_server.hpp> 19642f437eSKuiying Wang #include <sdbusplus/server.hpp> 20642f437eSKuiying Wang #include <xyz/openbmc_project/BIOSConfig/Manager/server.hpp> 21642f437eSKuiying Wang 22f1101df2STom Joseph #include <filesystem> 23642f437eSKuiying Wang #include <string> 24642f437eSKuiying Wang 25642f437eSKuiying Wang namespace bios_config 26642f437eSKuiying Wang { 27642f437eSKuiying Wang 28642f437eSKuiying Wang static constexpr auto service = "xyz.openbmc_project.BIOSConfigManager"; 29642f437eSKuiying Wang static constexpr auto objectPath = "/xyz/openbmc_project/bios_config/manager"; 30f1101df2STom Joseph constexpr auto biosPersistFile = "biosData"; 31642f437eSKuiying Wang 32642f437eSKuiying Wang using Base = sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager; 33f1101df2STom Joseph namespace fs = std::filesystem; 34642f437eSKuiying Wang 35642f437eSKuiying Wang /** @class Manager 36642f437eSKuiying Wang * 37642f437eSKuiying Wang * @brief Implements the BIOS Manager 38642f437eSKuiying Wang */ 39642f437eSKuiying Wang class Manager : public Base 40642f437eSKuiying Wang { 41642f437eSKuiying Wang public: 42642f437eSKuiying Wang using BaseTable = std::map< 43642f437eSKuiying Wang std::string, 441a448ad8SArun Lal K M std::tuple< 451a448ad8SArun Lal K M AttributeType, bool, std::string, std::string, std::string, 46642f437eSKuiying Wang std::variant<int64_t, std::string>, 47642f437eSKuiying Wang std::variant<int64_t, std::string>, 48642f437eSKuiying Wang std::vector<std::tuple< 491a448ad8SArun Lal K M BoundType, std::variant<int64_t, std::string>, std::string>>>>; 50642f437eSKuiying Wang 515e2cb720SSnehalatha Venkatesh using ResetFlag = std::map<std::string, ResetFlag>; 525e2cb720SSnehalatha Venkatesh 53642f437eSKuiying Wang using PendingAttributes = 54642f437eSKuiying Wang std::map<std::string, 55642f437eSKuiying Wang std::tuple<AttributeType, std::variant<int64_t, std::string>>>; 56642f437eSKuiying Wang 57642f437eSKuiying Wang using PendingAttribute = 58642f437eSKuiying Wang std::tuple<AttributeType, std::variant<int64_t, std::string>>; 59642f437eSKuiying Wang 60642f437eSKuiying Wang using AttributeName = std::string; 61642f437eSKuiying Wang using AttributeValue = std::variant<int64_t, std::string>; 62642f437eSKuiying Wang using CurrentValue = std::variant<int64_t, std::string>; 63642f437eSKuiying Wang using PendingValue = std::variant<int64_t, std::string>; 64642f437eSKuiying Wang using AttributeDetails = 65642f437eSKuiying Wang std::tuple<AttributeType, CurrentValue, PendingValue>; 66642f437eSKuiying Wang 67642f437eSKuiying Wang Manager() = delete; 68642f437eSKuiying Wang ~Manager() = default; 69642f437eSKuiying Wang Manager(const Manager&) = delete; 70642f437eSKuiying Wang Manager& operator=(const Manager&) = delete; 71642f437eSKuiying Wang Manager(Manager&&) = delete; 72642f437eSKuiying Wang Manager& operator=(Manager&&) = delete; 73642f437eSKuiying Wang 74642f437eSKuiying Wang /** @brief Constructs Manager object. 75642f437eSKuiying Wang * 76642f437eSKuiying Wang * @param[in] objectServer - object server 77642f437eSKuiying Wang * @param[in] systemBus - bus connection 78642f437eSKuiying Wang */ 79642f437eSKuiying Wang Manager(sdbusplus::asio::object_server& objectServer, 80*5c7e80d5SPatrick Williams std::shared_ptr<sdbusplus::asio::connection>& systemBus, 81*5c7e80d5SPatrick Williams std::string persistPath); 82642f437eSKuiying Wang 83642f437eSKuiying Wang /** @brief Set the BIOS attribute with a new value, the new value is added 84642f437eSKuiying Wang * to the PendingAttribute. 85642f437eSKuiying Wang * 86642f437eSKuiying Wang * @param[in] attribute - attribute name 87642f437eSKuiying Wang * @param[in] value - new value for the attribute 88642f437eSKuiying Wang * 89642f437eSKuiying Wang * @return On error, throw exception 90642f437eSKuiying Wang */ 91642f437eSKuiying Wang void setAttribute(AttributeName attribute, AttributeValue value) override; 92642f437eSKuiying Wang 93642f437eSKuiying Wang /** @brief Get the details of the BIOS attribute 94642f437eSKuiying Wang * 95642f437eSKuiying Wang * @param[in] attribute - attribute name 96642f437eSKuiying Wang * 97642f437eSKuiying Wang * @return On success, return the attribute details: attribute type, 98642f437eSKuiying Wang * current value, pending value. On error, throw exception 99642f437eSKuiying Wang */ 100642f437eSKuiying Wang AttributeDetails getAttribute(AttributeName attribute) override; 101642f437eSKuiying Wang 102642f437eSKuiying Wang /** @brief Set the BaseBIOSTable property and clears the PendingAttributes 103642f437eSKuiying Wang * property 104642f437eSKuiying Wang * 105642f437eSKuiying Wang * @param[in] value - new BaseBIOSTable 106642f437eSKuiying Wang * 107642f437eSKuiying Wang * @return The new BaseBIOSTable that is applied. 108642f437eSKuiying Wang */ 109642f437eSKuiying Wang BaseTable baseBIOSTable(BaseTable value) override; 110642f437eSKuiying Wang 1115e2cb720SSnehalatha Venkatesh ResetFlag resetBIOSSettings(ResetFlag value); 1125e2cb720SSnehalatha Venkatesh 113642f437eSKuiying Wang /** @brief Set the PendingAttributes property, additionally checks if the 114642f437eSKuiying Wang * attributes are in the BaseBIOSTable, whether the attributes are 115642f437eSKuiying Wang * read only and validate the attribute value based on the 116642f437eSKuiying Wang * attribute type. PendingAttributes is cleared if value is empty. 117642f437eSKuiying Wang * 118642f437eSKuiying Wang * @param[in] value - new PendingAttributes to append to the 119642f437eSKuiying Wang * PendingAttributes property 120642f437eSKuiying Wang * 121642f437eSKuiying Wang * @return On success, return the new PendingAttributes property that is 122642f437eSKuiying Wang * set.Throw exception if the validation fails. 123642f437eSKuiying Wang */ 124642f437eSKuiying Wang PendingAttributes pendingAttributes(PendingAttributes value) override; 125642f437eSKuiying Wang 126642f437eSKuiying Wang private: 127642f437eSKuiying Wang /** @enum Index into the fields in the BaseBIOSTable 128642f437eSKuiying Wang */ 129642f437eSKuiying Wang enum class Index : uint8_t 130642f437eSKuiying Wang { 131642f437eSKuiying Wang attributeType = 0, 132642f437eSKuiying Wang readOnly, 133642f437eSKuiying Wang displayName, 134642f437eSKuiying Wang description, 135642f437eSKuiying Wang menuPath, 136642f437eSKuiying Wang currentValue, 137642f437eSKuiying Wang defaultValue, 138642f437eSKuiying Wang options, 139642f437eSKuiying Wang }; 140642f437eSKuiying Wang 141ad54c7cbSyes bool validateEnumOption( 142ad54c7cbSyes const std::string& attrValue, 1431a448ad8SArun Lal K M const std::vector<std::tuple< 1441a448ad8SArun Lal K M BoundType, std::variant<int64_t, std::string>, std::string>>& 145ad54c7cbSyes options); 146ad54c7cbSyes 147ad54c7cbSyes bool validateStringOption( 148ad54c7cbSyes const std::string& attrValue, 1491a448ad8SArun Lal K M const std::vector<std::tuple< 1501a448ad8SArun Lal K M BoundType, std::variant<int64_t, std::string>, std::string>>& 151ad54c7cbSyes options); 152ad54c7cbSyes 153ad54c7cbSyes bool validateIntegerOption( 154ad54c7cbSyes const int64_t& attrValue, 1551a448ad8SArun Lal K M const std::vector<std::tuple< 1561a448ad8SArun Lal K M BoundType, std::variant<int64_t, std::string>, std::string>>& 157ad54c7cbSyes options); 158ad54c7cbSyes 159642f437eSKuiying Wang sdbusplus::asio::object_server& objServer; 160642f437eSKuiying Wang std::shared_ptr<sdbusplus::asio::connection>& systemBus; 161f1101df2STom Joseph std::filesystem::path biosFile; 162642f437eSKuiying Wang }; 163642f437eSKuiying Wang 164642f437eSKuiying Wang } // namespace bios_config 165