xref: /openbmc/bios-settings-mgr/include/manager.hpp (revision fae5732530cc4bb63acc93eb84e354f2c41bbb22)
1642f437eSKuiying Wang /*
2*fae57325SManojkiran Eda  Copyright (c) 2020 Intel Corporation
3*fae57325SManojkiran Eda 
4*fae57325SManojkiran Eda  Licensed under the Apache License, Version 2.0 (the "License");
5*fae57325SManojkiran Eda  you may not use this file except in compliance with the License.
6*fae57325SManojkiran Eda  You may obtain a copy of the License at
7*fae57325SManojkiran Eda 
8*fae57325SManojkiran Eda       http:www.apache.org/licenses/LICENSE-2.0
9*fae57325SManojkiran Eda 
10*fae57325SManojkiran Eda  Unless required by applicable law or agreed to in writing, software
11*fae57325SManojkiran Eda  distributed under the License is distributed on an "AS IS" BASIS,
12*fae57325SManojkiran Eda  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*fae57325SManojkiran Eda  See the License for the specific language governing permissions and
14*fae57325SManojkiran Eda  limitations under the License.
15642f437eSKuiying Wang */
16*fae57325SManojkiran Eda 
17642f437eSKuiying Wang #pragma once
18642f437eSKuiying Wang 
19642f437eSKuiying Wang #include <sdbusplus/asio/object_server.hpp>
20642f437eSKuiying Wang #include <sdbusplus/server.hpp>
21642f437eSKuiying Wang #include <xyz/openbmc_project/BIOSConfig/Manager/server.hpp>
22642f437eSKuiying Wang 
23f1101df2STom Joseph #include <filesystem>
24642f437eSKuiying Wang #include <string>
25642f437eSKuiying Wang 
26642f437eSKuiying Wang namespace bios_config
27642f437eSKuiying Wang {
28642f437eSKuiying Wang 
29642f437eSKuiying Wang static constexpr auto service = "xyz.openbmc_project.BIOSConfigManager";
30642f437eSKuiying Wang static constexpr auto objectPath = "/xyz/openbmc_project/bios_config/manager";
31f1101df2STom Joseph constexpr auto biosPersistFile = "biosData";
32642f437eSKuiying Wang 
33642f437eSKuiying Wang using Base = sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager;
34f1101df2STom Joseph namespace fs = std::filesystem;
35642f437eSKuiying Wang 
36642f437eSKuiying Wang /** @class Manager
37642f437eSKuiying Wang  *
38642f437eSKuiying Wang  *  @brief Implements the BIOS Manager
39642f437eSKuiying Wang  */
40642f437eSKuiying Wang class Manager : public Base
41642f437eSKuiying Wang {
42642f437eSKuiying Wang   public:
43642f437eSKuiying Wang     using BaseTable = std::map<
44642f437eSKuiying Wang         std::string,
451a448ad8SArun Lal K M         std::tuple<
461a448ad8SArun Lal K M             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<
501a448ad8SArun Lal K M                 BoundType, std::variant<int64_t, std::string>, std::string>>>>;
51642f437eSKuiying Wang 
525e2cb720SSnehalatha Venkatesh     using ResetFlag = std::map<std::string, ResetFlag>;
535e2cb720SSnehalatha 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,
815c7e80d5SPatrick Williams             std::shared_ptr<sdbusplus::asio::connection>& systemBus,
825c7e80d5SPatrick Williams             std::string persistPath);
83642f437eSKuiying Wang 
84642f437eSKuiying Wang     /** @brief Set the BIOS attribute with a new value, the new value is added
85642f437eSKuiying Wang      *         to the PendingAttribute.
86642f437eSKuiying Wang      *
87642f437eSKuiying Wang      *  @param[in] attribute - attribute name
88642f437eSKuiying Wang      *  @param[in] value - new value for the attribute
89642f437eSKuiying Wang      *
90642f437eSKuiying Wang      *  @return On error, throw exception
91642f437eSKuiying Wang      */
92642f437eSKuiying Wang     void setAttribute(AttributeName attribute, AttributeValue value) override;
93642f437eSKuiying Wang 
94642f437eSKuiying Wang     /** @brief Get the details of the BIOS attribute
95642f437eSKuiying Wang      *
96642f437eSKuiying Wang      *  @param[in] attribute - attribute name
97642f437eSKuiying Wang      *
98642f437eSKuiying Wang      *  @return On success, return the attribute details: attribute type,
99642f437eSKuiying Wang      *          current value, pending value. On error, throw exception
100642f437eSKuiying Wang      */
101642f437eSKuiying Wang     AttributeDetails getAttribute(AttributeName attribute) override;
102642f437eSKuiying Wang 
103642f437eSKuiying Wang     /** @brief Set the BaseBIOSTable property and clears the PendingAttributes
104642f437eSKuiying Wang      *         property
105642f437eSKuiying Wang      *
106642f437eSKuiying Wang      *  @param[in] value - new BaseBIOSTable
107642f437eSKuiying Wang      *
108642f437eSKuiying Wang      *  @return The new BaseBIOSTable that is applied.
109642f437eSKuiying Wang      */
110642f437eSKuiying Wang     BaseTable baseBIOSTable(BaseTable value) override;
111642f437eSKuiying Wang 
1125e2cb720SSnehalatha Venkatesh     ResetFlag resetBIOSSettings(ResetFlag value);
1135e2cb720SSnehalatha Venkatesh 
114642f437eSKuiying Wang     /** @brief Set the PendingAttributes property, additionally checks if the
115642f437eSKuiying Wang      *         attributes are in the BaseBIOSTable, whether the attributes are
116642f437eSKuiying Wang      *         read only and validate the attribute value based on the
117642f437eSKuiying Wang      *         attribute type. PendingAttributes is cleared if value is empty.
118642f437eSKuiying Wang      *
119642f437eSKuiying Wang      *  @param[in] value - new PendingAttributes to append to the
120642f437eSKuiying Wang      *                     PendingAttributes property
121642f437eSKuiying Wang      *
122642f437eSKuiying Wang      *  @return On success, return the new PendingAttributes property that is
123642f437eSKuiying Wang      *          set.Throw exception if the validation fails.
124642f437eSKuiying Wang      */
125642f437eSKuiying Wang     PendingAttributes pendingAttributes(PendingAttributes value) override;
126642f437eSKuiying Wang 
127642f437eSKuiying Wang   private:
128642f437eSKuiying Wang     /** @enum Index into the fields in the BaseBIOSTable
129642f437eSKuiying Wang      */
130642f437eSKuiying Wang     enum class Index : uint8_t
131642f437eSKuiying Wang     {
132642f437eSKuiying Wang         attributeType = 0,
133642f437eSKuiying Wang         readOnly,
134642f437eSKuiying Wang         displayName,
135642f437eSKuiying Wang         description,
136642f437eSKuiying Wang         menuPath,
137642f437eSKuiying Wang         currentValue,
138642f437eSKuiying Wang         defaultValue,
139642f437eSKuiying Wang         options,
140642f437eSKuiying Wang     };
141642f437eSKuiying Wang 
142ad54c7cbSyes     bool validateEnumOption(
143ad54c7cbSyes         const std::string& attrValue,
1441a448ad8SArun Lal K M         const std::vector<std::tuple<
1451a448ad8SArun Lal K M             BoundType, std::variant<int64_t, std::string>, std::string>>&
146ad54c7cbSyes             options);
147ad54c7cbSyes 
148ad54c7cbSyes     bool validateStringOption(
149ad54c7cbSyes         const std::string& attrValue,
1501a448ad8SArun Lal K M         const std::vector<std::tuple<
1511a448ad8SArun Lal K M             BoundType, std::variant<int64_t, std::string>, std::string>>&
152ad54c7cbSyes             options);
153ad54c7cbSyes 
154ad54c7cbSyes     bool validateIntegerOption(
155ad54c7cbSyes         const int64_t& attrValue,
1561a448ad8SArun Lal K M         const std::vector<std::tuple<
1571a448ad8SArun Lal K M             BoundType, std::variant<int64_t, std::string>, std::string>>&
158ad54c7cbSyes             options);
159ad54c7cbSyes 
160642f437eSKuiying Wang     sdbusplus::asio::object_server& objServer;
161642f437eSKuiying Wang     std::shared_ptr<sdbusplus::asio::connection>& systemBus;
162f1101df2STom Joseph     std::filesystem::path biosFile;
163642f437eSKuiying Wang };
164642f437eSKuiying Wang 
165642f437eSKuiying Wang } // namespace bios_config
166