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 18*f1101df2STom Joseph #include "config.h" 19*f1101df2STom 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 24*f1101df2STom 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"; 32*f1101df2STom Joseph constexpr auto biosPersistFile = "biosData"; 33642f437eSKuiying Wang 34642f437eSKuiying Wang using Base = sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager; 35*f1101df2STom 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 52642f437eSKuiying Wang using PendingAttributes = 53642f437eSKuiying Wang std::map<std::string, 54642f437eSKuiying Wang std::tuple<AttributeType, std::variant<int64_t, std::string>>>; 55642f437eSKuiying Wang 56642f437eSKuiying Wang using PendingAttribute = 57642f437eSKuiying Wang std::tuple<AttributeType, std::variant<int64_t, std::string>>; 58642f437eSKuiying Wang 59642f437eSKuiying Wang using AttributeName = std::string; 60642f437eSKuiying Wang using AttributeValue = std::variant<int64_t, std::string>; 61642f437eSKuiying Wang using CurrentValue = std::variant<int64_t, std::string>; 62642f437eSKuiying Wang using PendingValue = std::variant<int64_t, std::string>; 63642f437eSKuiying Wang using AttributeDetails = 64642f437eSKuiying Wang std::tuple<AttributeType, CurrentValue, PendingValue>; 65642f437eSKuiying Wang 66642f437eSKuiying Wang Manager() = delete; 67642f437eSKuiying Wang ~Manager() = default; 68642f437eSKuiying Wang Manager(const Manager&) = delete; 69642f437eSKuiying Wang Manager& operator=(const Manager&) = delete; 70642f437eSKuiying Wang Manager(Manager&&) = delete; 71642f437eSKuiying Wang Manager& operator=(Manager&&) = delete; 72642f437eSKuiying Wang 73642f437eSKuiying Wang /** @brief Constructs Manager object. 74642f437eSKuiying Wang * 75642f437eSKuiying Wang * @param[in] objectServer - object server 76642f437eSKuiying Wang * @param[in] systemBus - bus connection 77642f437eSKuiying Wang */ 78642f437eSKuiying Wang Manager(sdbusplus::asio::object_server& objectServer, 79642f437eSKuiying Wang std::shared_ptr<sdbusplus::asio::connection>& systemBus); 80642f437eSKuiying Wang 81642f437eSKuiying Wang /** @brief Set the BIOS attribute with a new value, the new value is added 82642f437eSKuiying Wang * to the PendingAttribute. 83642f437eSKuiying Wang * 84642f437eSKuiying Wang * @param[in] attribute - attribute name 85642f437eSKuiying Wang * @param[in] value - new value for the attribute 86642f437eSKuiying Wang * 87642f437eSKuiying Wang * @return On error, throw exception 88642f437eSKuiying Wang */ 89642f437eSKuiying Wang void setAttribute(AttributeName attribute, AttributeValue value) override; 90642f437eSKuiying Wang 91642f437eSKuiying Wang /** @brief Get the details of the BIOS attribute 92642f437eSKuiying Wang * 93642f437eSKuiying Wang * @param[in] attribute - attribute name 94642f437eSKuiying Wang * 95642f437eSKuiying Wang * @return On success, return the attribute details: attribute type, 96642f437eSKuiying Wang * current value, pending value. On error, throw exception 97642f437eSKuiying Wang */ 98642f437eSKuiying Wang AttributeDetails getAttribute(AttributeName attribute) override; 99642f437eSKuiying Wang 100642f437eSKuiying Wang /** @brief Set the BaseBIOSTable property and clears the PendingAttributes 101642f437eSKuiying Wang * property 102642f437eSKuiying Wang * 103642f437eSKuiying Wang * @param[in] value - new BaseBIOSTable 104642f437eSKuiying Wang * 105642f437eSKuiying Wang * @return The new BaseBIOSTable that is applied. 106642f437eSKuiying Wang */ 107642f437eSKuiying Wang BaseTable baseBIOSTable(BaseTable value) override; 108642f437eSKuiying Wang 109642f437eSKuiying Wang /** @brief Set the PendingAttributes property, additionally checks if the 110642f437eSKuiying Wang * attributes are in the BaseBIOSTable, whether the attributes are 111642f437eSKuiying Wang * read only and validate the attribute value based on the 112642f437eSKuiying Wang * attribute type. PendingAttributes is cleared if value is empty. 113642f437eSKuiying Wang * 114642f437eSKuiying Wang * @param[in] value - new PendingAttributes to append to the 115642f437eSKuiying Wang * PendingAttributes property 116642f437eSKuiying Wang * 117642f437eSKuiying Wang * @return On success, return the new PendingAttributes property that is 118642f437eSKuiying Wang * set.Throw exception if the validation fails. 119642f437eSKuiying Wang */ 120642f437eSKuiying Wang PendingAttributes pendingAttributes(PendingAttributes value) override; 121642f437eSKuiying Wang 122642f437eSKuiying Wang private: 123642f437eSKuiying Wang /** @enum Index into the fields in the BaseBIOSTable 124642f437eSKuiying Wang */ 125642f437eSKuiying Wang enum class Index : uint8_t 126642f437eSKuiying Wang { 127642f437eSKuiying Wang attributeType = 0, 128642f437eSKuiying Wang readOnly, 129642f437eSKuiying Wang displayName, 130642f437eSKuiying Wang description, 131642f437eSKuiying Wang menuPath, 132642f437eSKuiying Wang currentValue, 133642f437eSKuiying Wang defaultValue, 134642f437eSKuiying Wang options, 135642f437eSKuiying Wang }; 136642f437eSKuiying Wang 137642f437eSKuiying Wang sdbusplus::asio::object_server& objServer; 138642f437eSKuiying Wang std::shared_ptr<sdbusplus::asio::connection>& systemBus; 139*f1101df2STom Joseph std::filesystem::path biosFile; 140642f437eSKuiying Wang }; 141642f437eSKuiying Wang 142642f437eSKuiying Wang } // namespace bios_config 143