blob: 680ad6d15be846ca21bac70b3702847a083abbf8 [file] [log] [blame]
Kuiying Wang642f4372020-08-12 15:35:46 +08001/*
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 Josephf1101df2020-11-06 08:23:34 +053018#include "config.h"
19
Kuiying Wang642f4372020-08-12 15:35:46 +080020#include <sdbusplus/asio/object_server.hpp>
21#include <sdbusplus/server.hpp>
22#include <xyz/openbmc_project/BIOSConfig/Manager/server.hpp>
23
Tom Josephf1101df2020-11-06 08:23:34 +053024#include <filesystem>
Kuiying Wang642f4372020-08-12 15:35:46 +080025#include <string>
26
27namespace bios_config
28{
29
30static constexpr auto service = "xyz.openbmc_project.BIOSConfigManager";
31static constexpr auto objectPath = "/xyz/openbmc_project/bios_config/manager";
Tom Josephf1101df2020-11-06 08:23:34 +053032constexpr auto biosPersistFile = "biosData";
Kuiying Wang642f4372020-08-12 15:35:46 +080033
34using Base = sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager;
Tom Josephf1101df2020-11-06 08:23:34 +053035namespace fs = std::filesystem;
Kuiying Wang642f4372020-08-12 15:35:46 +080036
37/** @class Manager
38 *
39 * @brief Implements the BIOS Manager
40 */
41class Manager : public Base
42{
43 public:
44 using BaseTable = std::map<
45 std::string,
Arun Lal K M1a448ad2023-05-03 12:35:28 +000046 std::tuple<
47 AttributeType, bool, std::string, std::string, std::string,
48 std::variant<int64_t, std::string>,
49 std::variant<int64_t, std::string>,
50 std::vector<std::tuple<
51 BoundType, std::variant<int64_t, std::string>, std::string>>>>;
Kuiying Wang642f4372020-08-12 15:35:46 +080052
Snehalatha Venkatesh5e2cb722021-05-26 10:42:58 +000053 using ResetFlag = std::map<std::string, ResetFlag>;
54
Kuiying Wang642f4372020-08-12 15:35:46 +080055 using PendingAttributes =
56 std::map<std::string,
57 std::tuple<AttributeType, std::variant<int64_t, std::string>>>;
58
59 using PendingAttribute =
60 std::tuple<AttributeType, std::variant<int64_t, std::string>>;
61
62 using AttributeName = std::string;
63 using AttributeValue = std::variant<int64_t, std::string>;
64 using CurrentValue = std::variant<int64_t, std::string>;
65 using PendingValue = std::variant<int64_t, std::string>;
66 using AttributeDetails =
67 std::tuple<AttributeType, CurrentValue, PendingValue>;
68
69 Manager() = delete;
70 ~Manager() = default;
71 Manager(const Manager&) = delete;
72 Manager& operator=(const Manager&) = delete;
73 Manager(Manager&&) = delete;
74 Manager& operator=(Manager&&) = delete;
75
76 /** @brief Constructs Manager object.
77 *
78 * @param[in] objectServer - object server
79 * @param[in] systemBus - bus connection
80 */
81 Manager(sdbusplus::asio::object_server& objectServer,
82 std::shared_ptr<sdbusplus::asio::connection>& systemBus);
83
84 /** @brief Set the BIOS attribute with a new value, the new value is added
85 * to the PendingAttribute.
86 *
87 * @param[in] attribute - attribute name
88 * @param[in] value - new value for the attribute
89 *
90 * @return On error, throw exception
91 */
92 void setAttribute(AttributeName attribute, AttributeValue value) override;
93
94 /** @brief Get the details of the BIOS attribute
95 *
96 * @param[in] attribute - attribute name
97 *
98 * @return On success, return the attribute details: attribute type,
99 * current value, pending value. On error, throw exception
100 */
101 AttributeDetails getAttribute(AttributeName attribute) override;
102
103 /** @brief Set the BaseBIOSTable property and clears the PendingAttributes
104 * property
105 *
106 * @param[in] value - new BaseBIOSTable
107 *
108 * @return The new BaseBIOSTable that is applied.
109 */
110 BaseTable baseBIOSTable(BaseTable value) override;
111
Snehalatha Venkatesh5e2cb722021-05-26 10:42:58 +0000112 ResetFlag resetBIOSSettings(ResetFlag value);
113
Kuiying Wang642f4372020-08-12 15:35:46 +0800114 /** @brief Set the PendingAttributes property, additionally checks if the
115 * attributes are in the BaseBIOSTable, whether the attributes are
116 * read only and validate the attribute value based on the
117 * attribute type. PendingAttributes is cleared if value is empty.
118 *
119 * @param[in] value - new PendingAttributes to append to the
120 * PendingAttributes property
121 *
122 * @return On success, return the new PendingAttributes property that is
123 * set.Throw exception if the validation fails.
124 */
125 PendingAttributes pendingAttributes(PendingAttributes value) override;
126
127 private:
128 /** @enum Index into the fields in the BaseBIOSTable
129 */
130 enum class Index : uint8_t
131 {
132 attributeType = 0,
133 readOnly,
134 displayName,
135 description,
136 menuPath,
137 currentValue,
138 defaultValue,
139 options,
140 };
141
yesad54c7c2022-12-29 22:38:32 +0530142 bool validateEnumOption(
143 const std::string& attrValue,
Arun Lal K M1a448ad2023-05-03 12:35:28 +0000144 const std::vector<std::tuple<
145 BoundType, std::variant<int64_t, std::string>, std::string>>&
yesad54c7c2022-12-29 22:38:32 +0530146 options);
147
148 bool validateStringOption(
149 const std::string& attrValue,
Arun Lal K M1a448ad2023-05-03 12:35:28 +0000150 const std::vector<std::tuple<
151 BoundType, std::variant<int64_t, std::string>, std::string>>&
yesad54c7c2022-12-29 22:38:32 +0530152 options);
153
154 bool validateIntegerOption(
155 const int64_t& attrValue,
Arun Lal K M1a448ad2023-05-03 12:35:28 +0000156 const std::vector<std::tuple<
157 BoundType, std::variant<int64_t, std::string>, std::string>>&
yesad54c7c2022-12-29 22:38:32 +0530158 options);
159
Kuiying Wang642f4372020-08-12 15:35:46 +0800160 sdbusplus::asio::object_server& objServer;
161 std::shared_ptr<sdbusplus::asio::connection>& systemBus;
Tom Josephf1101df2020-11-06 08:23:34 +0530162 std::filesystem::path biosFile;
Kuiying Wang642f4372020-08-12 15:35:46 +0800163};
164
165} // namespace bios_config