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 18f1101df2STom Joseph #include "config.h" 19f1101df2STom Joseph 20642f437eSKuiying Wang #include <sdbusplus/asio/object_server.hpp> 21642f437eSKuiying Wang #include <sdbusplus/server.hpp> 22642f437eSKuiying Wang #include <xyz/openbmc_project/BIOSConfig/Manager/server.hpp> 23642f437eSKuiying Wang 24f1101df2STom Joseph #include <filesystem> 25642f437eSKuiying Wang #include <string> 26642f437eSKuiying Wang 27642f437eSKuiying Wang namespace bios_config 28642f437eSKuiying Wang { 29642f437eSKuiying Wang 30642f437eSKuiying Wang static constexpr auto service = "xyz.openbmc_project.BIOSConfigManager"; 31642f437eSKuiying Wang static constexpr auto objectPath = "/xyz/openbmc_project/bios_config/manager"; 32f1101df2STom Joseph constexpr auto biosPersistFile = "biosData"; 33642f437eSKuiying Wang 34642f437eSKuiying Wang using Base = sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager; 35f1101df2STom Joseph namespace fs = std::filesystem; 36642f437eSKuiying Wang 37642f437eSKuiying Wang /** @class Manager 38642f437eSKuiying Wang * 39642f437eSKuiying Wang * @brief Implements the BIOS Manager 40642f437eSKuiying Wang */ 41642f437eSKuiying Wang class Manager : public Base 42642f437eSKuiying Wang { 43642f437eSKuiying Wang public: 44642f437eSKuiying Wang using BaseTable = std::map< 45642f437eSKuiying Wang std::string, 46642f437eSKuiying Wang std::tuple<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< 50642f437eSKuiying Wang BoundType, std::variant<int64_t, std::string>>>>>; 51642f437eSKuiying Wang 52*5e2cb720SSnehalatha Venkatesh using ResetFlag = std::map<std::string, ResetFlag>; 53*5e2cb720SSnehalatha Venkatesh 54642f437eSKuiying Wang using PendingAttributes = 55642f437eSKuiying Wang std::map<std::string, 56642f437eSKuiying Wang std::tuple<AttributeType, std::variant<int64_t, std::string>>>; 57642f437eSKuiying Wang 58642f437eSKuiying Wang using PendingAttribute = 59642f437eSKuiying Wang std::tuple<AttributeType, std::variant<int64_t, std::string>>; 60642f437eSKuiying Wang 61642f437eSKuiying Wang using AttributeName = std::string; 62642f437eSKuiying Wang using AttributeValue = std::variant<int64_t, std::string>; 63642f437eSKuiying Wang using CurrentValue = std::variant<int64_t, std::string>; 64642f437eSKuiying Wang using PendingValue = std::variant<int64_t, std::string>; 65642f437eSKuiying Wang using AttributeDetails = 66642f437eSKuiying Wang std::tuple<AttributeType, CurrentValue, PendingValue>; 67642f437eSKuiying Wang 68642f437eSKuiying Wang Manager() = delete; 69642f437eSKuiying Wang ~Manager() = default; 70642f437eSKuiying Wang Manager(const Manager&) = delete; 71642f437eSKuiying Wang Manager& operator=(const Manager&) = delete; 72642f437eSKuiying Wang Manager(Manager&&) = delete; 73642f437eSKuiying Wang Manager& operator=(Manager&&) = delete; 74642f437eSKuiying Wang 75642f437eSKuiying Wang /** @brief Constructs Manager object. 76642f437eSKuiying Wang * 77642f437eSKuiying Wang * @param[in] objectServer - object server 78642f437eSKuiying Wang * @param[in] systemBus - bus connection 79642f437eSKuiying Wang */ 80642f437eSKuiying Wang Manager(sdbusplus::asio::object_server& objectServer, 81642f437eSKuiying Wang std::shared_ptr<sdbusplus::asio::connection>& systemBus); 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 111*5e2cb720SSnehalatha Venkatesh ResetFlag resetBIOSSettings(ResetFlag value); 112*5e2cb720SSnehalatha 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 141642f437eSKuiying Wang sdbusplus::asio::object_server& objServer; 142642f437eSKuiying Wang std::shared_ptr<sdbusplus::asio::connection>& systemBus; 143f1101df2STom Joseph std::filesystem::path biosFile; 144642f437eSKuiying Wang }; 145642f437eSKuiying Wang 146642f437eSKuiying Wang } // namespace bios_config 147