Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2020 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
Tom Joseph | f1101df | 2020-11-06 08:23:34 +0530 | [diff] [blame] | 18 | #include "config.h" |
| 19 | |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 20 | #include <sdbusplus/asio/object_server.hpp> |
| 21 | #include <sdbusplus/server.hpp> |
| 22 | #include <xyz/openbmc_project/BIOSConfig/Manager/server.hpp> |
| 23 | |
Tom Joseph | f1101df | 2020-11-06 08:23:34 +0530 | [diff] [blame] | 24 | #include <filesystem> |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 25 | #include <string> |
| 26 | |
| 27 | namespace bios_config |
| 28 | { |
| 29 | |
| 30 | static constexpr auto service = "xyz.openbmc_project.BIOSConfigManager"; |
| 31 | static constexpr auto objectPath = "/xyz/openbmc_project/bios_config/manager"; |
Tom Joseph | f1101df | 2020-11-06 08:23:34 +0530 | [diff] [blame] | 32 | constexpr auto biosPersistFile = "biosData"; |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 33 | |
| 34 | using Base = sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager; |
Tom Joseph | f1101df | 2020-11-06 08:23:34 +0530 | [diff] [blame] | 35 | namespace fs = std::filesystem; |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 36 | |
| 37 | /** @class Manager |
| 38 | * |
| 39 | * @brief Implements the BIOS Manager |
| 40 | */ |
| 41 | class Manager : public Base |
| 42 | { |
| 43 | public: |
| 44 | using BaseTable = std::map< |
| 45 | std::string, |
| 46 | std::tuple<AttributeType, bool, std::string, std::string, std::string, |
| 47 | std::variant<int64_t, std::string>, |
| 48 | std::variant<int64_t, std::string>, |
| 49 | std::vector<std::tuple< |
| 50 | BoundType, std::variant<int64_t, std::string>>>>>; |
| 51 | |
Snehalatha Venkatesh | 5e2cb72 | 2021-05-26 10:42:58 +0000 | [diff] [blame^] | 52 | using ResetFlag = std::map<std::string, ResetFlag>; |
| 53 | |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 54 | using PendingAttributes = |
| 55 | std::map<std::string, |
| 56 | std::tuple<AttributeType, std::variant<int64_t, std::string>>>; |
| 57 | |
| 58 | using PendingAttribute = |
| 59 | std::tuple<AttributeType, std::variant<int64_t, std::string>>; |
| 60 | |
| 61 | using AttributeName = std::string; |
| 62 | using AttributeValue = std::variant<int64_t, std::string>; |
| 63 | using CurrentValue = std::variant<int64_t, std::string>; |
| 64 | using PendingValue = std::variant<int64_t, std::string>; |
| 65 | using AttributeDetails = |
| 66 | std::tuple<AttributeType, CurrentValue, PendingValue>; |
| 67 | |
| 68 | Manager() = delete; |
| 69 | ~Manager() = default; |
| 70 | Manager(const Manager&) = delete; |
| 71 | Manager& operator=(const Manager&) = delete; |
| 72 | Manager(Manager&&) = delete; |
| 73 | Manager& operator=(Manager&&) = delete; |
| 74 | |
| 75 | /** @brief Constructs Manager object. |
| 76 | * |
| 77 | * @param[in] objectServer - object server |
| 78 | * @param[in] systemBus - bus connection |
| 79 | */ |
| 80 | Manager(sdbusplus::asio::object_server& objectServer, |
| 81 | std::shared_ptr<sdbusplus::asio::connection>& systemBus); |
| 82 | |
| 83 | /** @brief Set the BIOS attribute with a new value, the new value is added |
| 84 | * to the PendingAttribute. |
| 85 | * |
| 86 | * @param[in] attribute - attribute name |
| 87 | * @param[in] value - new value for the attribute |
| 88 | * |
| 89 | * @return On error, throw exception |
| 90 | */ |
| 91 | void setAttribute(AttributeName attribute, AttributeValue value) override; |
| 92 | |
| 93 | /** @brief Get the details of the BIOS attribute |
| 94 | * |
| 95 | * @param[in] attribute - attribute name |
| 96 | * |
| 97 | * @return On success, return the attribute details: attribute type, |
| 98 | * current value, pending value. On error, throw exception |
| 99 | */ |
| 100 | AttributeDetails getAttribute(AttributeName attribute) override; |
| 101 | |
| 102 | /** @brief Set the BaseBIOSTable property and clears the PendingAttributes |
| 103 | * property |
| 104 | * |
| 105 | * @param[in] value - new BaseBIOSTable |
| 106 | * |
| 107 | * @return The new BaseBIOSTable that is applied. |
| 108 | */ |
| 109 | BaseTable baseBIOSTable(BaseTable value) override; |
| 110 | |
Snehalatha Venkatesh | 5e2cb72 | 2021-05-26 10:42:58 +0000 | [diff] [blame^] | 111 | ResetFlag resetBIOSSettings(ResetFlag value); |
| 112 | |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 113 | /** @brief Set the PendingAttributes property, additionally checks if the |
| 114 | * attributes are in the BaseBIOSTable, whether the attributes are |
| 115 | * read only and validate the attribute value based on the |
| 116 | * attribute type. PendingAttributes is cleared if value is empty. |
| 117 | * |
| 118 | * @param[in] value - new PendingAttributes to append to the |
| 119 | * PendingAttributes property |
| 120 | * |
| 121 | * @return On success, return the new PendingAttributes property that is |
| 122 | * set.Throw exception if the validation fails. |
| 123 | */ |
| 124 | PendingAttributes pendingAttributes(PendingAttributes value) override; |
| 125 | |
| 126 | private: |
| 127 | /** @enum Index into the fields in the BaseBIOSTable |
| 128 | */ |
| 129 | enum class Index : uint8_t |
| 130 | { |
| 131 | attributeType = 0, |
| 132 | readOnly, |
| 133 | displayName, |
| 134 | description, |
| 135 | menuPath, |
| 136 | currentValue, |
| 137 | defaultValue, |
| 138 | options, |
| 139 | }; |
| 140 | |
| 141 | sdbusplus::asio::object_server& objServer; |
| 142 | std::shared_ptr<sdbusplus::asio::connection>& systemBus; |
Tom Joseph | f1101df | 2020-11-06 08:23:34 +0530 | [diff] [blame] | 143 | std::filesystem::path biosFile; |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | } // namespace bios_config |