blob: 318abe2ac6d2fb8d7b08acf8445b79680e751015 [file] [log] [blame]
AppaRao Pulie63eeda2019-07-05 16:25:38 +05301/*
2// Copyright (c) 2019 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
17#include "pfr_mgr.hpp"
AppaRao Pulie63eeda2019-07-05 16:25:38 +053018
19namespace intel
20{
21namespace pfr
22{
23
24static constexpr uint8_t activeImage = 0;
25static constexpr uint8_t recoveryImage = 1;
26
27PfrVersion::PfrVersion(sdbusplus::asio::object_server &srv_,
28 std::shared_ptr<sdbusplus::asio::connection> &conn_,
AppaRao Pulie4e95652019-07-19 16:52:01 +053029 const std::string &path_, const ImageType &imgType_,
30 const std::string &purpose_) :
AppaRao Pulie63eeda2019-07-05 16:25:38 +053031 server(srv_),
AppaRao Pulie4e95652019-07-19 16:52:01 +053032 conn(conn_), path(path_), imgType(imgType_), purpose(purpose_)
AppaRao Pulie63eeda2019-07-05 16:25:38 +053033{
AppaRao Puli4b639a22019-10-01 18:12:59 +053034 version = getFirmwareVersion(imgType);
AppaRao Pulie63eeda2019-07-05 16:25:38 +053035
36 std::string objPath = "/xyz/openbmc_project/software/" + path;
AppaRao Pulie4e95652019-07-19 16:52:01 +053037 versionIface =
AppaRao Pulie63eeda2019-07-05 16:25:38 +053038 server.add_interface(objPath, "xyz.openbmc_project.Software.Version");
AppaRao Pulie4e95652019-07-19 16:52:01 +053039 versionIface->register_property("Purpose", purpose);
40 versionIface->register_property(
41 versionStr, version,
42 // Override set
43 [this](const std::string &req, std::string &propertyValue) {
44 if (internalSet)
45 {
46 if (req != propertyValue)
47 {
48 version = req;
49 propertyValue = req;
50 return 1;
51 }
52 }
53 return 0;
54 });
AppaRao Pulie63eeda2019-07-05 16:25:38 +053055
AppaRao Pulie4e95652019-07-19 16:52:01 +053056 versionIface->initialize();
AppaRao Pulid6f46c42019-07-19 22:34:04 +053057
58 /* Activation interface represents activation state for an associated
59 * xyz.openbmc_project.Software.Version. since these versions are already
60 * active, so we should set "activation" to Active and
61 * "RequestedActivation" to None. */
62 std::string activation =
Vikram Bodireddy336196d2019-12-05 10:58:37 +053063 (imgType == ImageType::bmcRecovery ||
64 imgType == ImageType::biosRecovery)
65 ? "xyz.openbmc_project.Software.Activation.Activations.StandbySpare"
66 : "xyz.openbmc_project.Software.Activation.Activations.Active";
AppaRao Pulid6f46c42019-07-19 22:34:04 +053067 std::string reqActNone =
68 "xyz.openbmc_project.Software.Activation.RequestedActivations.None";
69 auto activationIface = server.add_interface(
70 objPath, "xyz.openbmc_project.Software.Activation");
71 activationIface->register_property("Activation", activation);
72 activationIface->register_property("RequestedActivation", reqActNone);
73
74 activationIface->initialize();
AppaRao Pulie63eeda2019-07-05 16:25:38 +053075}
76
AppaRao Pulie4e95652019-07-19 16:52:01 +053077void PfrVersion::updateVersion()
AppaRao Pulie63eeda2019-07-05 16:25:38 +053078{
AppaRao Pulie4e95652019-07-19 16:52:01 +053079 if (versionIface && versionIface->is_initialized())
80 {
AppaRao Puli4b639a22019-10-01 18:12:59 +053081 std::string ver = getFirmwareVersion(imgType);
AppaRao Pulie4e95652019-07-19 16:52:01 +053082 internalSet = true;
83 versionIface->set_property(versionStr, ver);
84 internalSet = false;
85 }
86 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +053087}
88
89PfrConfig::PfrConfig(sdbusplus::asio::object_server &srv_,
90 std::shared_ptr<sdbusplus::asio::connection> &conn_) :
91 server(srv_),
92 conn(conn_)
93{
AppaRao Pulicc1ed682019-10-01 12:29:40 +053094 pfrCfgIface = server.add_interface("/xyz/openbmc_project/pfr",
95 "xyz.openbmc_project.PFR.Attributes");
AppaRao Pulie63eeda2019-07-05 16:25:38 +053096
AppaRao Pulie4e95652019-07-19 16:52:01 +053097 getProvisioningStatus(ufmLocked, ufmProvisioned);
AppaRao Pulie63eeda2019-07-05 16:25:38 +053098
AppaRao Pulie4e95652019-07-19 16:52:01 +053099 pfrCfgIface->register_property(ufmProvisionedStr, ufmProvisioned,
100 // Override set
101 [this](const bool req, bool propertyValue) {
102 if (internalSet)
103 {
104 if (req != propertyValue)
105 {
106 ufmProvisioned = req;
107 propertyValue = req;
108 return 1;
109 }
110 }
111 return 0;
112 });
113
114 pfrCfgIface->register_property(ufmLockedStr, ufmLocked,
115 // Override set
116 [this](const bool req, bool propertyValue) {
117 if (internalSet)
118 {
119 if (req != propertyValue)
120 {
121 ufmLocked = req;
122 propertyValue = req;
123 return 1;
124 }
125 }
126 return 0;
127 });
128
129 pfrCfgIface->initialize();
130}
131
132void PfrConfig::updateProvisioningStatus()
133{
134 if (pfrCfgIface && pfrCfgIface->is_initialized())
135 {
136 bool lockVal = false;
137 bool provVal = false;
138 getProvisioningStatus(lockVal, provVal);
139 internalSet = true;
140 pfrCfgIface->set_property(ufmProvisionedStr, provVal);
141 pfrCfgIface->set_property(ufmLockedStr, lockVal);
142 internalSet = false;
143 }
144 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530145}
146
147} // namespace pfr
148} // namespace intel