blob: 918691679a8629b55fcd4f87fab3bc4c4e5f6960 [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 Pulie4e95652019-07-19 16:52:01 +053034 version = getVersionInfoCPLD(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 =
63 "xyz.openbmc_project.Software.Activation.Activations.Active";
64 std::string reqActNone =
65 "xyz.openbmc_project.Software.Activation.RequestedActivations.None";
66 auto activationIface = server.add_interface(
67 objPath, "xyz.openbmc_project.Software.Activation");
68 activationIface->register_property("Activation", activation);
69 activationIface->register_property("RequestedActivation", reqActNone);
70
71 activationIface->initialize();
AppaRao Pulie63eeda2019-07-05 16:25:38 +053072}
73
AppaRao Pulie4e95652019-07-19 16:52:01 +053074void PfrVersion::updateVersion()
AppaRao Pulie63eeda2019-07-05 16:25:38 +053075{
AppaRao Pulie4e95652019-07-19 16:52:01 +053076 if (versionIface && versionIface->is_initialized())
77 {
78 std::string ver = getVersionInfoCPLD(imgType);
79 internalSet = true;
80 versionIface->set_property(versionStr, ver);
81 internalSet = false;
82 }
83 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +053084}
85
86PfrConfig::PfrConfig(sdbusplus::asio::object_server &srv_,
87 std::shared_ptr<sdbusplus::asio::connection> &conn_) :
88 server(srv_),
89 conn(conn_)
90{
AppaRao Pulie4e95652019-07-19 16:52:01 +053091 pfrCfgIface =
AppaRao Pulie63eeda2019-07-05 16:25:38 +053092 server.add_interface("/xyz/openbmc_project/intel_pfr",
93 "xyz.openbmc_project.Intel_PFR.Attributes");
94
AppaRao Pulie4e95652019-07-19 16:52:01 +053095 getProvisioningStatus(ufmLocked, ufmProvisioned);
AppaRao Pulie63eeda2019-07-05 16:25:38 +053096
AppaRao Pulie4e95652019-07-19 16:52:01 +053097 pfrCfgIface->register_property(ufmProvisionedStr, ufmProvisioned,
98 // Override set
99 [this](const bool req, bool propertyValue) {
100 if (internalSet)
101 {
102 if (req != propertyValue)
103 {
104 ufmProvisioned = req;
105 propertyValue = req;
106 return 1;
107 }
108 }
109 return 0;
110 });
111
112 pfrCfgIface->register_property(ufmLockedStr, ufmLocked,
113 // Override set
114 [this](const bool req, bool propertyValue) {
115 if (internalSet)
116 {
117 if (req != propertyValue)
118 {
119 ufmLocked = req;
120 propertyValue = req;
121 return 1;
122 }
123 }
124 return 0;
125 });
126
127 pfrCfgIface->initialize();
128}
129
130void PfrConfig::updateProvisioningStatus()
131{
132 if (pfrCfgIface && pfrCfgIface->is_initialized())
133 {
134 bool lockVal = false;
135 bool provVal = false;
136 getProvisioningStatus(lockVal, provVal);
137 internalSet = true;
138 pfrCfgIface->set_property(ufmProvisionedStr, provVal);
139 pfrCfgIface->set_property(ufmLockedStr, lockVal);
140 internalSet = false;
141 }
142 return;
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530143}
144
145} // namespace pfr
146} // namespace intel