Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 1 | /* |
Manojkiran Eda | fae5732 | 2024-11-12 12:58:11 +0530 | [diff] [blame] | 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. |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 15 | */ |
Manojkiran Eda | fae5732 | 2024-11-12 12:58:11 +0530 | [diff] [blame] | 16 | |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 17 | #pragma once |
| 18 | |
| 19 | #include <sdbusplus/asio/object_server.hpp> |
| 20 | #include <sdbusplus/server.hpp> |
| 21 | #include <xyz/openbmc_project/BIOSConfig/Manager/server.hpp> |
| 22 | |
Tom Joseph | f1101df | 2020-11-06 08:23:34 +0530 | [diff] [blame] | 23 | #include <filesystem> |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 24 | #include <string> |
| 25 | |
| 26 | namespace bios_config |
| 27 | { |
| 28 | |
| 29 | static constexpr auto service = "xyz.openbmc_project.BIOSConfigManager"; |
| 30 | static constexpr auto objectPath = "/xyz/openbmc_project/bios_config/manager"; |
Tom Joseph | f1101df | 2020-11-06 08:23:34 +0530 | [diff] [blame] | 31 | constexpr auto biosPersistFile = "biosData"; |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 32 | |
| 33 | using Base = sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager; |
Tom Joseph | f1101df | 2020-11-06 08:23:34 +0530 | [diff] [blame] | 34 | namespace fs = std::filesystem; |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 35 | |
| 36 | /** @class Manager |
| 37 | * |
| 38 | * @brief Implements the BIOS Manager |
| 39 | */ |
| 40 | class Manager : public Base |
| 41 | { |
| 42 | public: |
| 43 | using BaseTable = std::map< |
| 44 | std::string, |
Arun Lal K M | 1a448ad | 2023-05-03 12:35:28 +0000 | [diff] [blame] | 45 | std::tuple< |
| 46 | 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>, std::string>>>>; |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 51 | |
Archana Kakani | 4e29f80 | 2024-08-20 08:11:18 -0500 | [diff] [blame^] | 52 | using oldBaseTable = std::map< |
| 53 | std::string, |
| 54 | std::tuple<AttributeType, bool, std::string, std::string, std::string, |
| 55 | std::variant<int64_t, std::string>, |
| 56 | std::variant<int64_t, std::string>, |
| 57 | std::vector<std::tuple< |
| 58 | BoundType, std::variant<int64_t, std::string>>>>>; |
| 59 | |
Snehalatha Venkatesh | 5e2cb72 | 2021-05-26 10:42:58 +0000 | [diff] [blame] | 60 | using ResetFlag = std::map<std::string, ResetFlag>; |
| 61 | |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 62 | using PendingAttributes = |
| 63 | std::map<std::string, |
| 64 | std::tuple<AttributeType, std::variant<int64_t, std::string>>>; |
| 65 | |
| 66 | using PendingAttribute = |
| 67 | std::tuple<AttributeType, std::variant<int64_t, std::string>>; |
| 68 | |
| 69 | using AttributeName = std::string; |
| 70 | using AttributeValue = std::variant<int64_t, std::string>; |
| 71 | using CurrentValue = std::variant<int64_t, std::string>; |
| 72 | using PendingValue = std::variant<int64_t, std::string>; |
| 73 | using AttributeDetails = |
| 74 | std::tuple<AttributeType, CurrentValue, PendingValue>; |
| 75 | |
| 76 | Manager() = delete; |
| 77 | ~Manager() = default; |
| 78 | Manager(const Manager&) = delete; |
| 79 | Manager& operator=(const Manager&) = delete; |
| 80 | Manager(Manager&&) = delete; |
| 81 | Manager& operator=(Manager&&) = delete; |
| 82 | |
| 83 | /** @brief Constructs Manager object. |
| 84 | * |
| 85 | * @param[in] objectServer - object server |
| 86 | * @param[in] systemBus - bus connection |
| 87 | */ |
| 88 | Manager(sdbusplus::asio::object_server& objectServer, |
Patrick Williams | 5c7e80d | 2024-10-18 21:24:12 -0400 | [diff] [blame] | 89 | std::shared_ptr<sdbusplus::asio::connection>& systemBus, |
| 90 | std::string persistPath); |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 91 | |
| 92 | /** @brief Set the BIOS attribute with a new value, the new value is added |
| 93 | * to the PendingAttribute. |
| 94 | * |
| 95 | * @param[in] attribute - attribute name |
| 96 | * @param[in] value - new value for the attribute |
| 97 | * |
| 98 | * @return On error, throw exception |
| 99 | */ |
| 100 | void setAttribute(AttributeName attribute, AttributeValue value) override; |
| 101 | |
| 102 | /** @brief Get the details of the BIOS attribute |
| 103 | * |
| 104 | * @param[in] attribute - attribute name |
| 105 | * |
| 106 | * @return On success, return the attribute details: attribute type, |
| 107 | * current value, pending value. On error, throw exception |
| 108 | */ |
| 109 | AttributeDetails getAttribute(AttributeName attribute) override; |
| 110 | |
| 111 | /** @brief Set the BaseBIOSTable property and clears the PendingAttributes |
| 112 | * property |
| 113 | * |
| 114 | * @param[in] value - new BaseBIOSTable |
| 115 | * |
| 116 | * @return The new BaseBIOSTable that is applied. |
| 117 | */ |
| 118 | BaseTable baseBIOSTable(BaseTable value) override; |
| 119 | |
Snehalatha Venkatesh | 5e2cb72 | 2021-05-26 10:42:58 +0000 | [diff] [blame] | 120 | ResetFlag resetBIOSSettings(ResetFlag value); |
| 121 | |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 122 | /** @brief Set the PendingAttributes property, additionally checks if the |
| 123 | * attributes are in the BaseBIOSTable, whether the attributes are |
| 124 | * read only and validate the attribute value based on the |
| 125 | * attribute type. PendingAttributes is cleared if value is empty. |
| 126 | * |
| 127 | * @param[in] value - new PendingAttributes to append to the |
| 128 | * PendingAttributes property |
| 129 | * |
| 130 | * @return On success, return the new PendingAttributes property that is |
| 131 | * set.Throw exception if the validation fails. |
| 132 | */ |
| 133 | PendingAttributes pendingAttributes(PendingAttributes value) override; |
| 134 | |
Archana Kakani | 4e29f80 | 2024-08-20 08:11:18 -0500 | [diff] [blame^] | 135 | /** @brief Convert the previosuly supported Base BIOS table to newly |
| 136 | * supported Base BIOS table |
| 137 | * |
| 138 | * @param[in] biosTbl - Old Base BIOS table (without VDN) |
| 139 | * @param[in] baseTable - Recently supported Base BIOS table (with VDN) |
| 140 | * |
| 141 | * @return void |
| 142 | * |
| 143 | */ |
| 144 | void convertBiosDataToVersion1(Manager::oldBaseTable biosTbl, |
| 145 | Manager::BaseTable& baseTable); |
| 146 | |
| 147 | /** @brief Convert the VDN supported Base BIOS table to old Base BIOS table |
| 148 | * |
| 149 | * @param[in] biosTbl - Old Base BIOS table (without VDN) |
| 150 | * @param[in] baseTable - Recently supported Base BIOS table (with VDN) |
| 151 | * |
| 152 | * @return void |
| 153 | */ |
| 154 | void convertBiosDataToVersion0(Manager::oldBaseTable& baseTable, |
| 155 | Manager::BaseTable& biosTbl); |
| 156 | |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 157 | private: |
| 158 | /** @enum Index into the fields in the BaseBIOSTable |
| 159 | */ |
| 160 | enum class Index : uint8_t |
| 161 | { |
| 162 | attributeType = 0, |
| 163 | readOnly, |
| 164 | displayName, |
| 165 | description, |
| 166 | menuPath, |
| 167 | currentValue, |
| 168 | defaultValue, |
| 169 | options, |
| 170 | }; |
| 171 | |
yes | ad54c7c | 2022-12-29 22:38:32 +0530 | [diff] [blame] | 172 | bool validateEnumOption( |
| 173 | const std::string& attrValue, |
Arun Lal K M | 1a448ad | 2023-05-03 12:35:28 +0000 | [diff] [blame] | 174 | const std::vector<std::tuple< |
| 175 | BoundType, std::variant<int64_t, std::string>, std::string>>& |
yes | ad54c7c | 2022-12-29 22:38:32 +0530 | [diff] [blame] | 176 | options); |
| 177 | |
| 178 | bool validateStringOption( |
| 179 | const std::string& attrValue, |
Arun Lal K M | 1a448ad | 2023-05-03 12:35:28 +0000 | [diff] [blame] | 180 | const std::vector<std::tuple< |
| 181 | BoundType, std::variant<int64_t, std::string>, std::string>>& |
yes | ad54c7c | 2022-12-29 22:38:32 +0530 | [diff] [blame] | 182 | options); |
| 183 | |
| 184 | bool validateIntegerOption( |
| 185 | const int64_t& attrValue, |
Arun Lal K M | 1a448ad | 2023-05-03 12:35:28 +0000 | [diff] [blame] | 186 | const std::vector<std::tuple< |
| 187 | BoundType, std::variant<int64_t, std::string>, std::string>>& |
yes | ad54c7c | 2022-12-29 22:38:32 +0530 | [diff] [blame] | 188 | options); |
| 189 | |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 190 | sdbusplus::asio::object_server& objServer; |
| 191 | std::shared_ptr<sdbusplus::asio::connection>& systemBus; |
Tom Joseph | f1101df | 2020-11-06 08:23:34 +0530 | [diff] [blame] | 192 | std::filesystem::path biosFile; |
Kuiying Wang | 642f437 | 2020-08-12 15:35:46 +0800 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | } // namespace bios_config |