Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 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 | |
James Feist | 35e257a | 2020-06-05 13:30:51 -0700 | [diff] [blame] | 18 | #include "health.hpp" |
| 19 | |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 20 | #include <boost/container/flat_map.hpp> |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 21 | #include <boost/format.hpp> |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 22 | #include <node.hpp> |
| 23 | #include <utils/json_utils.hpp> |
| 24 | |
| 25 | namespace redfish |
| 26 | { |
| 27 | |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 28 | using InterfacesProperties = boost::container::flat_map< |
| 29 | std::string, |
| 30 | boost::container::flat_map<std::string, dbus::utility::DbusVariantType>>; |
| 31 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 32 | inline void getResourceList(std::shared_ptr<AsyncResp> aResp, |
| 33 | const std::string& subclass, |
| 34 | const std::vector<const char*>& collectionName) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 35 | { |
| 36 | BMCWEB_LOG_DEBUG << "Get available system cpu/mem resources."; |
| 37 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 38 | [subclass, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 39 | const boost::system::error_code ec, |
| 40 | const boost::container::flat_map< |
| 41 | std::string, boost::container::flat_map< |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 42 | std::string, std::vector<std::string>>>& |
| 43 | subtree) { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 44 | if (ec) |
| 45 | { |
| 46 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 47 | messages::internalError(aResp->res); |
| 48 | return; |
| 49 | } |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 50 | nlohmann::json& members = aResp->res.jsonValue["Members"]; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 51 | members = nlohmann::json::array(); |
| 52 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 53 | for (const auto& object : subtree) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 54 | { |
| 55 | auto iter = object.first.rfind("/"); |
| 56 | if ((iter != std::string::npos) && (iter < object.first.size())) |
| 57 | { |
| 58 | members.push_back( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 59 | {{"@odata.id", "/redfish/v1/Systems/system/" + |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 60 | subclass + "/" + |
| 61 | object.first.substr(iter + 1)}}); |
| 62 | } |
| 63 | } |
| 64 | aResp->res.jsonValue["Members@odata.count"] = members.size(); |
| 65 | }, |
| 66 | "xyz.openbmc_project.ObjectMapper", |
| 67 | "/xyz/openbmc_project/object_mapper", |
| 68 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 69 | "/xyz/openbmc_project/inventory", 0, collectionName); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 70 | } |
| 71 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 72 | inline void |
| 73 | getCpuDataByInterface(std::shared_ptr<AsyncResp> aResp, |
| 74 | const InterfacesProperties& cpuInterfacesProperties) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 75 | { |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 76 | BMCWEB_LOG_DEBUG << "Get CPU resources by interface."; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 77 | |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 78 | // Added for future purpose. Once present and functional attributes added |
| 79 | // in busctl call, need to add actual logic to fetch original values. |
| 80 | bool present = false; |
| 81 | const bool functional = true; |
| 82 | auto health = std::make_shared<HealthPopulate>(aResp); |
| 83 | health->populate(); |
| 84 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 85 | for (const auto& interface : cpuInterfacesProperties) |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 86 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 87 | for (const auto& property : interface.second) |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 88 | { |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 89 | if (property.first == "CoreCount") |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 90 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 91 | const uint16_t* coresCount = |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 92 | std::get_if<uint16_t>(&property.second); |
Ed Tanous | 883b311 | 2018-12-06 16:13:35 -0800 | [diff] [blame] | 93 | if (coresCount == nullptr) |
| 94 | { |
| 95 | // Important property not in desired type |
| 96 | messages::internalError(aResp->res); |
| 97 | return; |
| 98 | } |
| 99 | if (*coresCount == 0) |
| 100 | { |
| 101 | // Slot is not populated, set status end return |
| 102 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
Ed Tanous | 883b311 | 2018-12-06 16:13:35 -0800 | [diff] [blame] | 103 | // HTTP Code will be set up automatically, just return |
| 104 | return; |
| 105 | } |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 106 | else |
| 107 | { |
| 108 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 109 | present = true; |
| 110 | } |
Ed Tanous | 883b311 | 2018-12-06 16:13:35 -0800 | [diff] [blame] | 111 | aResp->res.jsonValue["TotalCores"] = *coresCount; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 112 | } |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 113 | else if (property.first == "Socket") |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 114 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 115 | const std::string* value = |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 116 | std::get_if<std::string>(&property.second); |
| 117 | if (value != nullptr) |
| 118 | { |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 119 | aResp->res.jsonValue["Socket"] = *value; |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 120 | } |
| 121 | } |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 122 | else if (property.first == "ThreadCount") |
Gunnar Mills | f9dcc11 | 2020-02-13 13:19:43 -0600 | [diff] [blame] | 123 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 124 | const int64_t* value = std::get_if<int64_t>(&property.second); |
| 125 | if (value != nullptr) |
| 126 | { |
| 127 | aResp->res.jsonValue["TotalThreads"] = *value; |
| 128 | } |
Gunnar Mills | f9dcc11 | 2020-02-13 13:19:43 -0600 | [diff] [blame] | 129 | } |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 130 | else if (property.first == "Family") |
Gunnar Mills | f9dcc11 | 2020-02-13 13:19:43 -0600 | [diff] [blame] | 131 | { |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 132 | const std::string* value = |
| 133 | std::get_if<std::string>(&property.second); |
| 134 | if (value != nullptr) |
| 135 | { |
| 136 | aResp->res.jsonValue["ProcessorId"]["EffectiveFamily"] = |
| 137 | *value; |
| 138 | } |
Gunnar Mills | f9dcc11 | 2020-02-13 13:19:43 -0600 | [diff] [blame] | 139 | } |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 140 | else if (property.first == "Id") |
Gunnar Mills | f9dcc11 | 2020-02-13 13:19:43 -0600 | [diff] [blame] | 141 | { |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 142 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 143 | if (value != nullptr && *value != 0) |
| 144 | { |
| 145 | present = true; |
| 146 | aResp->res |
| 147 | .jsonValue["ProcessorId"]["IdentificationRegisters"] = |
| 148 | boost::lexical_cast<std::string>(*value); |
| 149 | } |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 154 | if (present == false) |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 155 | { |
| 156 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 157 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 158 | } |
| 159 | else |
| 160 | { |
| 161 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 162 | if (functional) |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 163 | { |
| 164 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | aResp->res.jsonValue["Status"]["Health"] = "Critical"; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | return; |
| 173 | } |
| 174 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 175 | inline void getCpuDataByService(std::shared_ptr<AsyncResp> aResp, |
| 176 | const std::string& cpuId, |
| 177 | const std::string& service, |
| 178 | const std::string& objPath) |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 179 | { |
| 180 | BMCWEB_LOG_DEBUG << "Get available system cpu resources by service."; |
| 181 | |
| 182 | crow::connections::systemBus->async_method_call( |
| 183 | [cpuId, service, objPath, aResp{std::move(aResp)}]( |
| 184 | const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 185 | const dbus::utility::ManagedObjectType& dbusData) { |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 186 | if (ec) |
| 187 | { |
| 188 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 189 | messages::internalError(aResp->res); |
| 190 | return; |
| 191 | } |
| 192 | aResp->res.jsonValue["Id"] = cpuId; |
| 193 | aResp->res.jsonValue["Name"] = "Processor"; |
| 194 | aResp->res.jsonValue["ProcessorType"] = "CPU"; |
| 195 | |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 196 | bool slotPresent = false; |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 197 | std::string corePath = objPath + "/core"; |
| 198 | size_t totalCores = 0; |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 199 | for (const auto& object : dbusData) |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 200 | { |
| 201 | if (object.first.str == objPath) |
| 202 | { |
| 203 | getCpuDataByInterface(aResp, object.second); |
| 204 | } |
| 205 | else if (boost::starts_with(object.first.str, corePath)) |
| 206 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 207 | for (const auto& interface : object.second) |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 208 | { |
| 209 | if (interface.first == |
| 210 | "xyz.openbmc_project.Inventory.Item") |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 211 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 212 | for (const auto& property : interface.second) |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 213 | { |
| 214 | if (property.first == "Present") |
| 215 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 216 | const bool* present = |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 217 | std::get_if<bool>(&property.second); |
| 218 | if (present != nullptr) |
| 219 | { |
| 220 | if (*present == true) |
| 221 | { |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 222 | slotPresent = true; |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 223 | totalCores++; |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | } |
Gunnar Mills | b957ba5 | 2019-01-31 15:58:15 -0600 | [diff] [blame] | 228 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 229 | } |
| 230 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 231 | } |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 232 | // In getCpuDataByInterface(), state and health are set |
| 233 | // based on the present and functional status. If core |
| 234 | // count is zero, then it has a higher precedence. |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 235 | if (slotPresent) |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 236 | { |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 237 | if (totalCores == 0) |
| 238 | { |
| 239 | // Slot is not populated, set status end return |
| 240 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 241 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 242 | } |
| 243 | aResp->res.jsonValue["TotalCores"] = totalCores; |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 244 | } |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 245 | return; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 246 | }, |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 247 | service, "/xyz/openbmc_project/inventory", |
| 248 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 249 | } |
| 250 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 251 | inline void getCpuAssetData(std::shared_ptr<AsyncResp> aResp, |
| 252 | const std::string& service, |
| 253 | const std::string& objPath) |
Zhikui Ren | 5e54a36 | 2020-07-13 15:31:38 -0700 | [diff] [blame] | 254 | { |
| 255 | BMCWEB_LOG_DEBUG << "Get Cpu Asset Data"; |
| 256 | crow::connections::systemBus->async_method_call( |
| 257 | [objPath, aResp{std::move(aResp)}]( |
| 258 | const boost::system::error_code ec, |
| 259 | const boost::container::flat_map< |
| 260 | std::string, std::variant<std::string, uint32_t, uint16_t, |
| 261 | bool>>& properties) { |
| 262 | if (ec) |
| 263 | { |
| 264 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 265 | messages::internalError(aResp->res); |
| 266 | return; |
| 267 | } |
| 268 | |
| 269 | for (const auto& property : properties) |
| 270 | { |
| 271 | if (property.first == "SerialNumber") |
| 272 | { |
| 273 | const std::string* sn = |
| 274 | std::get_if<std::string>(&property.second); |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 275 | if (sn != nullptr && !sn->empty()) |
Zhikui Ren | 5e54a36 | 2020-07-13 15:31:38 -0700 | [diff] [blame] | 276 | { |
| 277 | aResp->res.jsonValue["SerialNumber"] = *sn; |
| 278 | } |
| 279 | } |
| 280 | else if (property.first == "Model") |
| 281 | { |
| 282 | const std::string* model = |
| 283 | std::get_if<std::string>(&property.second); |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 284 | if (model != nullptr && !model->empty()) |
Zhikui Ren | 5e54a36 | 2020-07-13 15:31:38 -0700 | [diff] [blame] | 285 | { |
| 286 | aResp->res.jsonValue["Model"] = *model; |
| 287 | } |
| 288 | } |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 289 | else if (property.first == "Manufacturer") |
| 290 | { |
| 291 | |
| 292 | const std::string* mfg = |
| 293 | std::get_if<std::string>(&property.second); |
| 294 | if (mfg != nullptr) |
| 295 | { |
| 296 | aResp->res.jsonValue["Manufacturer"] = *mfg; |
| 297 | |
| 298 | // Otherwise would be unexpected. |
| 299 | if (mfg->find("Intel") != std::string::npos) |
| 300 | { |
| 301 | aResp->res.jsonValue["ProcessorArchitecture"] = |
| 302 | "x86"; |
| 303 | aResp->res.jsonValue["InstructionSet"] = "x86-64"; |
| 304 | } |
| 305 | else if (mfg->find("IBM") != std::string::npos) |
| 306 | { |
| 307 | aResp->res.jsonValue["ProcessorArchitecture"] = |
| 308 | "Power"; |
| 309 | aResp->res.jsonValue["InstructionSet"] = "PowerISA"; |
| 310 | } |
| 311 | } |
| 312 | } |
Zhikui Ren | 5e54a36 | 2020-07-13 15:31:38 -0700 | [diff] [blame] | 313 | } |
| 314 | }, |
| 315 | service, objPath, "org.freedesktop.DBus.Properties", "GetAll", |
| 316 | "xyz.openbmc_project.Inventory.Decorator.Asset"); |
| 317 | } |
| 318 | |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 319 | inline void getCpuRevisionData(std::shared_ptr<AsyncResp> aResp, |
| 320 | const std::string& service, |
| 321 | const std::string& objPath) |
| 322 | { |
| 323 | BMCWEB_LOG_DEBUG << "Get Cpu Revision Data"; |
| 324 | crow::connections::systemBus->async_method_call( |
| 325 | [objPath, aResp{std::move(aResp)}]( |
| 326 | const boost::system::error_code ec, |
| 327 | const boost::container::flat_map< |
| 328 | std::string, std::variant<std::string, uint32_t, uint16_t, |
| 329 | bool>>& properties) { |
| 330 | if (ec) |
| 331 | { |
| 332 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 333 | messages::internalError(aResp->res); |
| 334 | return; |
| 335 | } |
| 336 | |
| 337 | for (const auto& property : properties) |
| 338 | { |
| 339 | if (property.first == "Version") |
| 340 | { |
| 341 | const std::string* ver = |
| 342 | std::get_if<std::string>(&property.second); |
| 343 | if (ver != nullptr) |
| 344 | { |
| 345 | aResp->res.jsonValue["Version"] = *ver; |
| 346 | } |
| 347 | break; |
| 348 | } |
| 349 | } |
| 350 | }, |
| 351 | service, objPath, "org.freedesktop.DBus.Properties", "GetAll", |
| 352 | "xyz.openbmc_project.Inventory.Decorator.Revision"); |
| 353 | } |
| 354 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 355 | inline void getAcceleratorDataByService(std::shared_ptr<AsyncResp> aResp, |
| 356 | const std::string& acclrtrId, |
| 357 | const std::string& service, |
| 358 | const std::string& objPath) |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 359 | { |
| 360 | BMCWEB_LOG_DEBUG |
| 361 | << "Get available system Accelerator resources by service."; |
| 362 | crow::connections::systemBus->async_method_call( |
| 363 | [acclrtrId, aResp{std::move(aResp)}]( |
| 364 | const boost::system::error_code ec, |
| 365 | const boost::container::flat_map< |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 366 | std::string, std::variant<std::string, uint32_t, uint16_t, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 367 | bool>>& properties) { |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 368 | if (ec) |
| 369 | { |
| 370 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 371 | messages::internalError(aResp->res); |
| 372 | return; |
| 373 | } |
| 374 | aResp->res.jsonValue["Id"] = acclrtrId; |
| 375 | aResp->res.jsonValue["Name"] = "Processor"; |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 376 | const bool* accPresent = nullptr; |
| 377 | const bool* accFunctional = nullptr; |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 378 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 379 | for (const auto& property : properties) |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 380 | { |
| 381 | if (property.first == "Functional") |
| 382 | { |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 383 | accFunctional = std::get_if<bool>(&property.second); |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 384 | } |
| 385 | else if (property.first == "Present") |
| 386 | { |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 387 | accPresent = std::get_if<bool>(&property.second); |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | |
Alpana Kumari | c24e6b8 | 2020-10-01 06:58:46 -0500 | [diff] [blame] | 391 | std::string state = "Enabled"; |
| 392 | std::string health = "OK"; |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 393 | |
Alpana Kumari | c24e6b8 | 2020-10-01 06:58:46 -0500 | [diff] [blame] | 394 | if (accPresent != nullptr && *accPresent == false) |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 395 | { |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 396 | state = "Absent"; |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 397 | } |
Alpana Kumari | c24e6b8 | 2020-10-01 06:58:46 -0500 | [diff] [blame] | 398 | |
| 399 | if ((accFunctional != nullptr) && (*accFunctional == false)) |
| 400 | { |
| 401 | if (state == "Enabled") |
| 402 | { |
| 403 | health = "Critical"; |
| 404 | } |
| 405 | else |
| 406 | { |
| 407 | health = "UnavailableOffline"; |
| 408 | } |
| 409 | } |
| 410 | |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 411 | aResp->res.jsonValue["Status"]["State"] = state; |
Alpana Kumari | c24e6b8 | 2020-10-01 06:58:46 -0500 | [diff] [blame] | 412 | aResp->res.jsonValue["Status"]["Health"] = health; |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 413 | aResp->res.jsonValue["ProcessorType"] = "Accelerator"; |
| 414 | }, |
| 415 | service, objPath, "org.freedesktop.DBus.Properties", "GetAll", ""); |
| 416 | } |
| 417 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 418 | inline void getCpuData(std::shared_ptr<AsyncResp> aResp, |
| 419 | const std::string& cpuId, |
| 420 | const std::vector<const char*> inventoryItems) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 421 | { |
| 422 | BMCWEB_LOG_DEBUG << "Get available system cpu resources."; |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 423 | |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 424 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 425 | [cpuId, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 426 | const boost::system::error_code ec, |
| 427 | const boost::container::flat_map< |
| 428 | std::string, boost::container::flat_map< |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 429 | std::string, std::vector<std::string>>>& |
| 430 | subtree) { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 431 | if (ec) |
| 432 | { |
| 433 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 434 | messages::internalError(aResp->res); |
| 435 | return; |
| 436 | } |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 437 | for (const auto& object : subtree) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 438 | { |
| 439 | if (boost::ends_with(object.first, cpuId)) |
| 440 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 441 | for (const auto& service : object.second) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 442 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 443 | for (const auto& inventory : service.second) |
Zhikui Ren | 5e54a36 | 2020-07-13 15:31:38 -0700 | [diff] [blame] | 444 | { |
| 445 | if (inventory == "xyz.openbmc_project." |
| 446 | "Inventory.Decorator.Asset") |
| 447 | { |
| 448 | getCpuAssetData(aResp, service.first, |
| 449 | object.first); |
| 450 | } |
| 451 | else if (inventory == |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 452 | "xyz.openbmc_project." |
| 453 | "Inventory.Decorator.Revision") |
| 454 | { |
| 455 | getCpuRevisionData(aResp, service.first, |
| 456 | object.first); |
| 457 | } |
| 458 | else if (inventory == "xyz.openbmc_project." |
| 459 | "Inventory.Item.Cpu") |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 460 | { |
| 461 | getCpuDataByService(aResp, cpuId, service.first, |
| 462 | object.first); |
| 463 | } |
| 464 | else if (inventory == "xyz.openbmc_project." |
| 465 | "Inventory.Item.Accelerator") |
| 466 | { |
| 467 | getAcceleratorDataByService( |
| 468 | aResp, cpuId, service.first, object.first); |
| 469 | } |
Zhikui Ren | 5e54a36 | 2020-07-13 15:31:38 -0700 | [diff] [blame] | 470 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 471 | } |
Zhikui Ren | 5e54a36 | 2020-07-13 15:31:38 -0700 | [diff] [blame] | 472 | return; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | // Object not found |
| 476 | messages::resourceNotFound(aResp->res, "Processor", cpuId); |
| 477 | return; |
| 478 | }, |
| 479 | "xyz.openbmc_project.ObjectMapper", |
| 480 | "/xyz/openbmc_project/object_mapper", |
| 481 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 482 | "/xyz/openbmc_project/inventory", 0, inventoryItems); |
| 483 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 484 | |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 485 | using DimmProperty = |
| 486 | std::variant<std::string, std::vector<uint32_t>, std::vector<uint16_t>, |
| 487 | uint64_t, uint32_t, uint16_t, uint8_t, bool>; |
| 488 | |
| 489 | using DimmProperties = boost::container::flat_map<std::string, DimmProperty>; |
| 490 | |
Ed Tanous | 80789c8 | 2020-08-19 09:19:09 -0700 | [diff] [blame] | 491 | inline void dimmPropToHex(std::shared_ptr<AsyncResp> aResp, const char* key, |
| 492 | const std::pair<std::string, DimmProperty>& property) |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 493 | { |
| 494 | const uint16_t* value = std::get_if<uint16_t>(&property.second); |
| 495 | if (value == nullptr) |
| 496 | { |
| 497 | messages::internalError(aResp->res); |
| 498 | BMCWEB_LOG_DEBUG << "Invalid property type for " << property.first; |
| 499 | return; |
| 500 | } |
| 501 | |
| 502 | aResp->res.jsonValue[key] = (boost::format("0x%04x") % *value).str(); |
| 503 | } |
| 504 | |
Ed Tanous | 80789c8 | 2020-08-19 09:19:09 -0700 | [diff] [blame] | 505 | inline void getPersistentMemoryProperties(std::shared_ptr<AsyncResp> aResp, |
| 506 | const DimmProperties& properties) |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 507 | { |
| 508 | for (const auto& property : properties) |
| 509 | { |
| 510 | if (property.first == "ModuleManufacturerID") |
| 511 | { |
| 512 | dimmPropToHex(aResp, "ModuleManufacturerID", property); |
| 513 | } |
| 514 | else if (property.first == "ModuleProductID") |
| 515 | { |
| 516 | dimmPropToHex(aResp, "ModuleProductID", property); |
| 517 | } |
| 518 | else if (property.first == "SubsystemVendorID") |
| 519 | { |
| 520 | dimmPropToHex(aResp, "MemorySubsystemControllerManufacturerID", |
| 521 | property); |
| 522 | } |
| 523 | else if (property.first == "SubsystemDeviceID") |
| 524 | { |
| 525 | dimmPropToHex(aResp, "MemorySubsystemControllerProductID", |
| 526 | property); |
| 527 | } |
| 528 | else if (property.first == "VolatileRegionSizeLimitInKiB") |
| 529 | { |
| 530 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 531 | |
| 532 | if (value == nullptr) |
| 533 | { |
| 534 | messages::internalError(aResp->res); |
| 535 | BMCWEB_LOG_DEBUG << "Invalid property type for " |
| 536 | "VolatileRegionSizeLimitKiB"; |
| 537 | continue; |
| 538 | } |
| 539 | aResp->res.jsonValue["VolatileRegionSizeLimitMiB"] = (*value) >> 10; |
| 540 | } |
| 541 | else if (property.first == "PmRegionSizeLimitInKiB") |
| 542 | { |
| 543 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 544 | |
| 545 | if (value == nullptr) |
| 546 | { |
| 547 | messages::internalError(aResp->res); |
| 548 | BMCWEB_LOG_DEBUG |
| 549 | << "Invalid property type for PmRegioSizeLimitKiB"; |
| 550 | continue; |
| 551 | } |
| 552 | aResp->res.jsonValue["PersistentRegionSizeLimitMiB"] = |
| 553 | (*value) >> 10; |
| 554 | } |
| 555 | else if (property.first == "VolatileSizeInKiB") |
| 556 | { |
| 557 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 558 | |
| 559 | if (value == nullptr) |
| 560 | { |
| 561 | messages::internalError(aResp->res); |
| 562 | BMCWEB_LOG_DEBUG |
| 563 | << "Invalid property type for VolatileSizeInKiB"; |
| 564 | continue; |
| 565 | } |
| 566 | aResp->res.jsonValue["VolatileSizeMiB"] = (*value) >> 10; |
| 567 | } |
| 568 | else if (property.first == "PmSizeInKiB") |
| 569 | { |
| 570 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 571 | if (value == nullptr) |
| 572 | { |
| 573 | messages::internalError(aResp->res); |
| 574 | BMCWEB_LOG_DEBUG << "Invalid property type for PmSizeInKiB"; |
| 575 | continue; |
| 576 | } |
| 577 | aResp->res.jsonValue["NonVolatileSizeMiB"] = (*value) >> 10; |
| 578 | } |
| 579 | else if (property.first == "CacheSizeInKB") |
| 580 | { |
| 581 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 582 | if (value == nullptr) |
| 583 | { |
| 584 | messages::internalError(aResp->res); |
| 585 | BMCWEB_LOG_DEBUG << "Invalid property type for CacheSizeInKB"; |
| 586 | continue; |
| 587 | } |
| 588 | aResp->res.jsonValue["CacheSizeMiB"] = (*value >> 10); |
| 589 | } |
| 590 | |
| 591 | else if (property.first == "VoltaileRegionMaxSizeInKib") |
| 592 | { |
| 593 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 594 | |
| 595 | if (value == nullptr) |
| 596 | { |
| 597 | messages::internalError(aResp->res); |
| 598 | BMCWEB_LOG_DEBUG << "Invalid property type for " |
| 599 | "VolatileRegionMaxSizeInKib"; |
| 600 | continue; |
| 601 | } |
| 602 | aResp->res.jsonValue["VolatileRegionSizeMaxMiB"] = (*value) >> 10; |
| 603 | } |
| 604 | else if (property.first == "PmRegionMaxSizeInKiB") |
| 605 | { |
| 606 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 607 | |
| 608 | if (value == nullptr) |
| 609 | { |
| 610 | messages::internalError(aResp->res); |
| 611 | BMCWEB_LOG_DEBUG |
| 612 | << "Invalid property type for PmRegionMaxSizeInKiB"; |
| 613 | continue; |
| 614 | } |
| 615 | aResp->res.jsonValue["PersistentRegionSizeMaxMiB"] = (*value) >> 10; |
| 616 | } |
| 617 | else if (property.first == "AllocationIncrementInKiB") |
| 618 | { |
| 619 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 620 | |
| 621 | if (value == nullptr) |
| 622 | { |
| 623 | messages::internalError(aResp->res); |
| 624 | BMCWEB_LOG_DEBUG << "Invalid property type for " |
| 625 | "AllocationIncrementInKiB"; |
| 626 | continue; |
| 627 | } |
| 628 | aResp->res.jsonValue["AllocationIncrementMiB"] = (*value) >> 10; |
| 629 | } |
| 630 | else if (property.first == "AllocationAlignmentInKiB") |
| 631 | { |
| 632 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 633 | |
| 634 | if (value == nullptr) |
| 635 | { |
| 636 | messages::internalError(aResp->res); |
| 637 | BMCWEB_LOG_DEBUG << "Invalid property type for " |
| 638 | "AllocationAlignmentInKiB"; |
| 639 | continue; |
| 640 | } |
| 641 | aResp->res.jsonValue["AllocationAlignmentMiB"] = (*value) >> 10; |
| 642 | } |
| 643 | else if (property.first == "VolatileRegionNumberLimit") |
| 644 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 645 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 646 | if (value == nullptr) |
| 647 | { |
| 648 | messages::internalError(aResp->res); |
| 649 | continue; |
| 650 | } |
| 651 | aResp->res.jsonValue["VolatileRegionNumberLimit"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 652 | } |
| 653 | else if (property.first == "PmRegionNumberLimit") |
| 654 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 655 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 656 | if (value == nullptr) |
| 657 | { |
| 658 | messages::internalError(aResp->res); |
| 659 | continue; |
| 660 | } |
| 661 | aResp->res.jsonValue["PersistentRegionNumberLimit"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 662 | } |
| 663 | else if (property.first == "SpareDeviceCount") |
| 664 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 665 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 666 | if (value == nullptr) |
| 667 | { |
| 668 | messages::internalError(aResp->res); |
| 669 | continue; |
| 670 | } |
| 671 | aResp->res.jsonValue["SpareDeviceCount"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 672 | } |
| 673 | else if (property.first == "IsSpareDeviceInUse") |
| 674 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 675 | const bool* value = std::get_if<bool>(&property.second); |
| 676 | if (value == nullptr) |
| 677 | { |
| 678 | messages::internalError(aResp->res); |
| 679 | continue; |
| 680 | } |
| 681 | aResp->res.jsonValue["IsSpareDeviceEnabled"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 682 | } |
| 683 | else if (property.first == "IsRankSpareEnabled") |
| 684 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 685 | const bool* value = std::get_if<bool>(&property.second); |
| 686 | if (value == nullptr) |
| 687 | { |
| 688 | messages::internalError(aResp->res); |
| 689 | continue; |
| 690 | } |
| 691 | aResp->res.jsonValue["IsRankSpareEnabled"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 692 | } |
| 693 | else if (property.first == "MaxAveragePowerLimitmW") |
| 694 | { |
| 695 | const auto* value = |
| 696 | std::get_if<std::vector<uint32_t>>(&property.second); |
| 697 | if (value == nullptr) |
| 698 | { |
| 699 | messages::internalError(aResp->res); |
| 700 | BMCWEB_LOG_DEBUG << "Invalid property type for " |
| 701 | "MaxAveragePowerLimitmW"; |
| 702 | continue; |
| 703 | } |
| 704 | aResp->res.jsonValue["MaxTDPMilliWatts"] = *value; |
| 705 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 706 | else if (property.first == "ConfigurationLocked") |
| 707 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 708 | const bool* value = std::get_if<bool>(&property.second); |
| 709 | if (value == nullptr) |
| 710 | { |
| 711 | messages::internalError(aResp->res); |
| 712 | continue; |
| 713 | } |
| 714 | aResp->res.jsonValue["ConfigurationLocked"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 715 | } |
| 716 | else if (property.first == "AllowedMemoryModes") |
| 717 | { |
| 718 | const std::string* value = |
| 719 | std::get_if<std::string>(&property.second); |
| 720 | if (value == nullptr) |
| 721 | { |
| 722 | messages::internalError(aResp->res); |
| 723 | BMCWEB_LOG_DEBUG << "Invalid property type for FormFactor"; |
| 724 | continue; |
| 725 | } |
| 726 | constexpr const std::array<const char*, 3> values{"Volatile", |
| 727 | "PMEM", "Block"}; |
| 728 | |
| 729 | for (const char* v : values) |
| 730 | { |
| 731 | if (boost::ends_with(*value, v)) |
| 732 | { |
| 733 | aResp->res.jsonValue["OperatingMemoryModes "] = v; |
| 734 | break; |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | else if (property.first == "MemoryMedia") |
| 739 | { |
| 740 | const std::string* value = |
| 741 | std::get_if<std::string>(&property.second); |
| 742 | if (value == nullptr) |
| 743 | { |
| 744 | messages::internalError(aResp->res); |
| 745 | BMCWEB_LOG_DEBUG << "Invalid property type for MemoryMedia"; |
| 746 | continue; |
| 747 | } |
| 748 | constexpr const std::array<const char*, 3> values{"DRAM", "NAND", |
| 749 | "Intel3DXPoint"}; |
| 750 | |
| 751 | for (const char* v : values) |
| 752 | { |
| 753 | if (boost::ends_with(*value, v)) |
| 754 | { |
| 755 | aResp->res.jsonValue["MemoryMedia"] = v; |
| 756 | break; |
| 757 | } |
| 758 | } |
| 759 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 760 | // PersistantMemory.SecurityCapabilites interface |
| 761 | else if (property.first == "ConfigurationLockCapable" || |
| 762 | property.first == "DataLockCapable" || |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 763 | property.first == "PassphraseCapable") |
| 764 | { |
| 765 | const bool* value = std::get_if<bool>(&property.second); |
| 766 | if (value == nullptr) |
| 767 | { |
| 768 | messages::internalError(aResp->res); |
| 769 | continue; |
| 770 | } |
| 771 | aResp->res.jsonValue["SecurityCapabilities"][property.first] = |
| 772 | *value; |
| 773 | } |
| 774 | else if (property.first == "MaxPassphraseCount" || |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 775 | property.first == "PassphraseLockLimit") |
| 776 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 777 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 778 | if (value == nullptr) |
| 779 | { |
| 780 | messages::internalError(aResp->res); |
| 781 | continue; |
| 782 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 783 | aResp->res.jsonValue["SecurityCapabilities"][property.first] = |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 784 | *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | } |
| 788 | |
Ed Tanous | 80789c8 | 2020-08-19 09:19:09 -0700 | [diff] [blame] | 789 | inline void getDimmDataByService(std::shared_ptr<AsyncResp> aResp, |
| 790 | const std::string& dimmId, |
| 791 | const std::string& service, |
| 792 | const std::string& objPath) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 793 | { |
James Feist | 35e257a | 2020-06-05 13:30:51 -0700 | [diff] [blame] | 794 | auto health = std::make_shared<HealthPopulate>(aResp); |
| 795 | health->selfPath = objPath; |
| 796 | health->populate(); |
| 797 | |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 798 | BMCWEB_LOG_DEBUG << "Get available system components."; |
| 799 | crow::connections::systemBus->async_method_call( |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 800 | [dimmId, aResp{std::move(aResp)}](const boost::system::error_code ec, |
| 801 | const DimmProperties& properties) { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 802 | if (ec) |
| 803 | { |
| 804 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 805 | messages::internalError(aResp->res); |
| 806 | |
| 807 | return; |
| 808 | } |
| 809 | aResp->res.jsonValue["Id"] = dimmId; |
| 810 | aResp->res.jsonValue["Name"] = "DIMM Slot"; |
| 811 | |
| 812 | const auto memorySizeProperty = properties.find("MemorySizeInKB"); |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 813 | if (memorySizeProperty != properties.end()) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 814 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 815 | const uint32_t* memorySize = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 816 | std::get_if<uint32_t>(&memorySizeProperty->second); |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 817 | if (memorySize == nullptr) |
| 818 | { |
| 819 | // Important property not in desired type |
| 820 | messages::internalError(aResp->res); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 821 | |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 822 | return; |
| 823 | } |
| 824 | if (*memorySize == 0) |
| 825 | { |
| 826 | // Slot is not populated, set status end return |
| 827 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 828 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 829 | // HTTP Code will be set up automatically, just return |
| 830 | return; |
| 831 | } |
| 832 | aResp->res.jsonValue["CapacityMiB"] = (*memorySize >> 10); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 833 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 834 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 835 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 836 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 837 | for (const auto& property : properties) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 838 | { |
| 839 | if (property.first == "MemoryDataWidth") |
| 840 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 841 | const uint16_t* value = |
| 842 | std::get_if<uint16_t>(&property.second); |
| 843 | if (value == nullptr) |
| 844 | { |
| 845 | continue; |
| 846 | } |
| 847 | aResp->res.jsonValue["DataWidthBits"] = *value; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 848 | } |
Manojkiran Eda | 7e236ca | 2019-06-25 23:06:32 +0530 | [diff] [blame] | 849 | else if (property.first == "PartNumber") |
| 850 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 851 | const std::string* value = |
| 852 | std::get_if<std::string>(&property.second); |
| 853 | if (value == nullptr) |
| 854 | { |
| 855 | continue; |
| 856 | } |
| 857 | aResp->res.jsonValue["PartNumber"] = *value; |
Manojkiran Eda | 7e236ca | 2019-06-25 23:06:32 +0530 | [diff] [blame] | 858 | } |
| 859 | else if (property.first == "SerialNumber") |
| 860 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 861 | const std::string* value = |
| 862 | std::get_if<std::string>(&property.second); |
| 863 | if (value == nullptr) |
| 864 | { |
| 865 | continue; |
| 866 | } |
| 867 | aResp->res.jsonValue["SerialNumber"] = *value; |
Manojkiran Eda | 7e236ca | 2019-06-25 23:06:32 +0530 | [diff] [blame] | 868 | } |
| 869 | else if (property.first == "Manufacturer") |
| 870 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 871 | const std::string* value = |
| 872 | std::get_if<std::string>(&property.second); |
| 873 | if (value == nullptr) |
| 874 | { |
| 875 | continue; |
| 876 | } |
| 877 | aResp->res.jsonValue["Manufacturer"] = *value; |
Manojkiran Eda | 7e236ca | 2019-06-25 23:06:32 +0530 | [diff] [blame] | 878 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 879 | else if (property.first == "RevisionCode") |
| 880 | { |
| 881 | const uint16_t* value = |
| 882 | std::get_if<uint16_t>(&property.second); |
| 883 | |
| 884 | if (value == nullptr) |
| 885 | { |
| 886 | messages::internalError(aResp->res); |
| 887 | BMCWEB_LOG_DEBUG |
| 888 | << "Invalid property type for RevisionCode"; |
| 889 | continue; |
| 890 | } |
| 891 | aResp->res.jsonValue["FirmwareRevision"] = |
| 892 | std::to_string(*value); |
| 893 | } |
| 894 | else if (property.first == "MemoryTotalWidth") |
| 895 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 896 | const uint16_t* value = |
| 897 | std::get_if<uint16_t>(&property.second); |
| 898 | if (value == nullptr) |
| 899 | { |
| 900 | continue; |
| 901 | } |
| 902 | aResp->res.jsonValue["BusWidthBits"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 903 | } |
| 904 | else if (property.first == "ECC") |
| 905 | { |
| 906 | const std::string* value = |
| 907 | std::get_if<std::string>(&property.second); |
| 908 | if (value == nullptr) |
| 909 | { |
| 910 | messages::internalError(aResp->res); |
| 911 | BMCWEB_LOG_DEBUG << "Invalid property type for ECC"; |
| 912 | continue; |
| 913 | } |
| 914 | constexpr const std::array<const char*, 4> values{ |
| 915 | "NoECC", "SingleBitECC", "MultiBitECC", |
| 916 | "AddressParity"}; |
| 917 | |
| 918 | for (const char* v : values) |
| 919 | { |
| 920 | if (boost::ends_with(*value, v)) |
| 921 | { |
| 922 | aResp->res.jsonValue["ErrorCorrection"] = v; |
| 923 | break; |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | else if (property.first == "FormFactor") |
| 928 | { |
| 929 | const std::string* value = |
| 930 | std::get_if<std::string>(&property.second); |
| 931 | if (value == nullptr) |
| 932 | { |
| 933 | messages::internalError(aResp->res); |
| 934 | BMCWEB_LOG_DEBUG |
| 935 | << "Invalid property type for FormFactor"; |
| 936 | continue; |
| 937 | } |
| 938 | constexpr const std::array<const char*, 11> values{ |
| 939 | "RDIMM", "UDIMM", "SO_DIMM", |
| 940 | "LRDIMM", "Mini_RDIMM", "Mini_UDIMM", |
| 941 | "SO_RDIMM_72b", "SO_UDIMM_72b", "SO_DIMM_16b", |
| 942 | "SO_DIMM_32b", "Die"}; |
| 943 | |
| 944 | for (const char* v : values) |
| 945 | { |
| 946 | if (boost::ends_with(*value, v)) |
| 947 | { |
| 948 | aResp->res.jsonValue["BaseModuleType"] = v; |
| 949 | break; |
| 950 | } |
| 951 | } |
| 952 | } |
| 953 | else if (property.first == "AllowedSpeedsMT") |
| 954 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 955 | const std::vector<uint16_t>* value = |
| 956 | std::get_if<std::vector<uint16_t>>(&property.second); |
| 957 | if (value == nullptr) |
| 958 | { |
| 959 | continue; |
| 960 | } |
| 961 | nlohmann::json& jValue = |
| 962 | aResp->res.jsonValue["AllowedSpeedsMHz"]; |
| 963 | jValue = nlohmann::json::array(); |
| 964 | for (uint16_t subVal : *value) |
| 965 | { |
| 966 | jValue.push_back(subVal); |
| 967 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 968 | } |
| 969 | else if (property.first == "MemoryAttributes") |
| 970 | { |
| 971 | const uint8_t* value = |
| 972 | std::get_if<uint8_t>(&property.second); |
| 973 | |
| 974 | if (value == nullptr) |
| 975 | { |
| 976 | messages::internalError(aResp->res); |
| 977 | BMCWEB_LOG_DEBUG |
| 978 | << "Invalid property type for MemoryAttributes"; |
| 979 | continue; |
| 980 | } |
| 981 | aResp->res.jsonValue["RankCount"] = |
| 982 | static_cast<uint64_t>(*value); |
| 983 | } |
| 984 | else if (property.first == "MemoryConfiguredSpeedInMhz") |
| 985 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 986 | const uint16_t* value = |
| 987 | std::get_if<uint16_t>(&property.second); |
| 988 | if (value == nullptr) |
| 989 | { |
| 990 | continue; |
| 991 | } |
| 992 | aResp->res.jsonValue["OperatingSpeedMhz"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 993 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 994 | else if (property.first == "MemoryType") |
| 995 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 996 | const auto* value = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 997 | std::get_if<std::string>(&property.second); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 998 | if (value != nullptr) |
| 999 | { |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 1000 | size_t idx = value->rfind("."); |
| 1001 | if (idx == std::string::npos || |
| 1002 | idx + 1 >= value->size()) |
| 1003 | { |
| 1004 | messages::internalError(aResp->res); |
| 1005 | BMCWEB_LOG_DEBUG << "Invalid property type for " |
| 1006 | "MemoryType"; |
| 1007 | } |
| 1008 | std::string result = value->substr(idx + 1); |
| 1009 | aResp->res.jsonValue["MemoryDeviceType"] = result; |
| 1010 | if (value->find("DDR") != std::string::npos) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1011 | { |
| 1012 | aResp->res.jsonValue["MemoryType"] = "DRAM"; |
| 1013 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 1014 | else if (boost::ends_with(*value, "Logical")) |
| 1015 | { |
| 1016 | aResp->res.jsonValue["MemoryType"] = "IntelOptane"; |
| 1017 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1018 | } |
| 1019 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 1020 | // memory location interface |
| 1021 | else if (property.first == "Channel" || |
| 1022 | property.first == "MemoryController" || |
| 1023 | property.first == "Slot" || property.first == "Socket") |
| 1024 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 1025 | const std::string* value = |
| 1026 | std::get_if<std::string>(&property.second); |
| 1027 | if (value == nullptr) |
| 1028 | { |
| 1029 | messages::internalError(aResp->res); |
| 1030 | continue; |
| 1031 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 1032 | aResp->res.jsonValue["MemoryLocation"][property.first] = |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 1033 | *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 1034 | } |
| 1035 | else |
| 1036 | { |
| 1037 | getPersistentMemoryProperties(aResp, properties); |
| 1038 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1039 | } |
| 1040 | }, |
| 1041 | service, objPath, "org.freedesktop.DBus.Properties", "GetAll", ""); |
| 1042 | } |
| 1043 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1044 | inline void getDimmPartitionData(std::shared_ptr<AsyncResp> aResp, |
| 1045 | const std::string& service, |
| 1046 | const std::string& path) |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 1047 | { |
| 1048 | crow::connections::systemBus->async_method_call( |
| 1049 | [aResp{std::move(aResp)}]( |
| 1050 | const boost::system::error_code ec, |
| 1051 | const boost::container::flat_map< |
| 1052 | std::string, std::variant<std::string, uint64_t, uint32_t, |
| 1053 | bool>>& properties) { |
| 1054 | if (ec) |
| 1055 | { |
| 1056 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 1057 | messages::internalError(aResp->res); |
| 1058 | |
| 1059 | return; |
| 1060 | } |
| 1061 | |
| 1062 | nlohmann::json& partition = |
| 1063 | aResp->res.jsonValue["Regions"].emplace_back( |
| 1064 | nlohmann::json::object()); |
| 1065 | for (const auto& [key, val] : properties) |
| 1066 | { |
| 1067 | if (key == "MemoryClassification") |
| 1068 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 1069 | const std::string* value = std::get_if<std::string>(&val); |
| 1070 | if (value == nullptr) |
| 1071 | { |
| 1072 | messages::internalError(aResp->res); |
| 1073 | continue; |
| 1074 | } |
| 1075 | partition[key] = *value; |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 1076 | } |
| 1077 | else if (key == "OffsetInKiB") |
| 1078 | { |
| 1079 | const uint64_t* value = std::get_if<uint64_t>(&val); |
| 1080 | if (value == nullptr) |
| 1081 | { |
| 1082 | messages::internalError(aResp->res); |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 1083 | continue; |
| 1084 | } |
| 1085 | |
| 1086 | partition["OffsetMiB"] = (*value >> 10); |
| 1087 | } |
| 1088 | else if (key == "PartitionId") |
| 1089 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 1090 | const std::string* value = std::get_if<std::string>(&val); |
| 1091 | if (value == nullptr) |
| 1092 | { |
| 1093 | messages::internalError(aResp->res); |
| 1094 | continue; |
| 1095 | } |
| 1096 | partition["RegionId"] = *value; |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | else if (key == "PassphraseState") |
| 1100 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 1101 | const bool* value = std::get_if<bool>(&val); |
| 1102 | if (value == nullptr) |
| 1103 | { |
| 1104 | messages::internalError(aResp->res); |
| 1105 | continue; |
| 1106 | } |
| 1107 | partition["PassphraseEnabled"] = *value; |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 1108 | } |
| 1109 | else if (key == "SizeInKiB") |
| 1110 | { |
| 1111 | const uint64_t* value = std::get_if<uint64_t>(&val); |
| 1112 | if (value == nullptr) |
| 1113 | { |
| 1114 | messages::internalError(aResp->res); |
| 1115 | BMCWEB_LOG_DEBUG |
| 1116 | << "Invalid property type for SizeInKiB"; |
| 1117 | continue; |
| 1118 | } |
| 1119 | partition["SizeMiB"] = (*value >> 10); |
| 1120 | } |
| 1121 | } |
| 1122 | }, |
| 1123 | |
| 1124 | service, path, "org.freedesktop.DBus.Properties", "GetAll", |
| 1125 | "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition"); |
| 1126 | } |
| 1127 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1128 | inline void getDimmData(std::shared_ptr<AsyncResp> aResp, |
| 1129 | const std::string& dimmId) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1130 | { |
| 1131 | BMCWEB_LOG_DEBUG << "Get available system dimm resources."; |
| 1132 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1133 | [dimmId, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1134 | const boost::system::error_code ec, |
| 1135 | const boost::container::flat_map< |
| 1136 | std::string, boost::container::flat_map< |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1137 | std::string, std::vector<std::string>>>& |
| 1138 | subtree) { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1139 | if (ec) |
| 1140 | { |
| 1141 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 1142 | messages::internalError(aResp->res); |
| 1143 | |
| 1144 | return; |
| 1145 | } |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 1146 | bool found = false; |
| 1147 | for (const auto& [path, object] : subtree) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1148 | { |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 1149 | if (path.find(dimmId) != std::string::npos) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1150 | { |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 1151 | for (const auto& [service, interfaces] : object) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1152 | { |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 1153 | if (!found && |
| 1154 | (std::find( |
| 1155 | interfaces.begin(), interfaces.end(), |
| 1156 | "xyz.openbmc_project.Inventory.Item.Dimm") != |
| 1157 | interfaces.end())) |
| 1158 | { |
| 1159 | getDimmDataByService(aResp, dimmId, service, path); |
| 1160 | found = true; |
| 1161 | } |
| 1162 | |
| 1163 | // partitions are separate as there can be multiple per |
| 1164 | // device, i.e. |
| 1165 | // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition1 |
| 1166 | // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition2 |
| 1167 | if (std::find(interfaces.begin(), interfaces.end(), |
| 1168 | "xyz.openbmc_project.Inventory.Item." |
| 1169 | "PersistentMemory.Partition") != |
| 1170 | interfaces.end()) |
| 1171 | { |
| 1172 | getDimmPartitionData(aResp, service, path); |
| 1173 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | // Object not found |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 1178 | if (!found) |
| 1179 | { |
| 1180 | messages::resourceNotFound(aResp->res, "Memory", dimmId); |
| 1181 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1182 | return; |
| 1183 | }, |
| 1184 | "xyz.openbmc_project.ObjectMapper", |
| 1185 | "/xyz/openbmc_project/object_mapper", |
| 1186 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1187 | "/xyz/openbmc_project/inventory", 0, |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 1188 | std::array<const char*, 2>{ |
| 1189 | "xyz.openbmc_project.Inventory.Item.Dimm", |
| 1190 | "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition"}); |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1191 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1192 | |
| 1193 | class ProcessorCollection : public Node |
| 1194 | { |
| 1195 | public: |
| 1196 | /* |
| 1197 | * Default Constructor |
| 1198 | */ |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 1199 | ProcessorCollection(App& app) : |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1200 | Node(app, "/redfish/v1/Systems/system/Processors/") |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1201 | { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1202 | entityPrivileges = { |
| 1203 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 1204 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 1205 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 1206 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 1207 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 1208 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 1209 | } |
| 1210 | |
| 1211 | private: |
| 1212 | /** |
| 1213 | * Functions triggers appropriate requests on DBus |
| 1214 | */ |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1215 | void doGet(crow::Response& res, const crow::Request&, |
| 1216 | const std::vector<std::string>&) override |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1217 | { |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1218 | res.jsonValue["@odata.type"] = |
| 1219 | "#ProcessorCollection.ProcessorCollection"; |
| 1220 | res.jsonValue["Name"] = "Processor Collection"; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1221 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1222 | res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Processors/"; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1223 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 1224 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1225 | getResourceList(asyncResp, "Processors", |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 1226 | {"xyz.openbmc_project.Inventory.Item.Cpu", |
| 1227 | "xyz.openbmc_project.Inventory.Item.Accelerator"}); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1228 | } |
| 1229 | }; |
| 1230 | |
| 1231 | class Processor : public Node |
| 1232 | { |
| 1233 | public: |
| 1234 | /* |
| 1235 | * Default Constructor |
| 1236 | */ |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 1237 | Processor(App& app) : |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1238 | Node(app, "/redfish/v1/Systems/system/Processors/<str>/", std::string()) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1239 | { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1240 | entityPrivileges = { |
| 1241 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 1242 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 1243 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 1244 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 1245 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 1246 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 1247 | } |
| 1248 | |
| 1249 | private: |
| 1250 | /** |
| 1251 | * Functions triggers appropriate requests on DBus |
| 1252 | */ |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1253 | void doGet(crow::Response& res, const crow::Request&, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1254 | const std::vector<std::string>& params) override |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1255 | { |
| 1256 | // Check if there is required param, truly entering this shall be |
| 1257 | // impossible |
| 1258 | if (params.size() != 1) |
| 1259 | { |
| 1260 | messages::internalError(res); |
| 1261 | |
| 1262 | res.end(); |
| 1263 | return; |
| 1264 | } |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1265 | const std::string& processorId = params[0]; |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 1266 | res.jsonValue["@odata.type"] = "#Processor.v1_9_0.Processor"; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1267 | res.jsonValue["@odata.id"] = |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 1268 | "/redfish/v1/Systems/system/Processors/" + processorId; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1269 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1270 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 1271 | |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 1272 | getCpuData(asyncResp, processorId, |
| 1273 | {"xyz.openbmc_project.Inventory.Item.Cpu", |
Zhikui Ren | 5e54a36 | 2020-07-13 15:31:38 -0700 | [diff] [blame] | 1274 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 1275 | "xyz.openbmc_project.Inventory.Item.Accelerator"}); |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1276 | } |
| 1277 | }; |
| 1278 | |
| 1279 | class MemoryCollection : public Node |
| 1280 | { |
| 1281 | public: |
| 1282 | /* |
| 1283 | * Default Constructor |
| 1284 | */ |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 1285 | MemoryCollection(App& app) : Node(app, "/redfish/v1/Systems/system/Memory/") |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1286 | { |
| 1287 | entityPrivileges = { |
| 1288 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 1289 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 1290 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 1291 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 1292 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 1293 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 1294 | } |
| 1295 | |
| 1296 | private: |
| 1297 | /** |
| 1298 | * Functions triggers appropriate requests on DBus |
| 1299 | */ |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1300 | void doGet(crow::Response& res, const crow::Request&, |
| 1301 | const std::vector<std::string>&) override |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1302 | { |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1303 | res.jsonValue["@odata.type"] = "#MemoryCollection.MemoryCollection"; |
| 1304 | res.jsonValue["Name"] = "Memory Module Collection"; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 1305 | res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Memory"; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1306 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 1307 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1308 | getResourceList(asyncResp, "Memory", |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 1309 | {"xyz.openbmc_project.Inventory.Item.Dimm"}); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1310 | } |
| 1311 | }; |
| 1312 | |
| 1313 | class Memory : public Node |
| 1314 | { |
| 1315 | public: |
| 1316 | /* |
| 1317 | * Default Constructor |
| 1318 | */ |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 1319 | Memory(App& app) : |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1320 | Node(app, "/redfish/v1/Systems/system/Memory/<str>/", std::string()) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1321 | { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1322 | entityPrivileges = { |
| 1323 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 1324 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 1325 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 1326 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 1327 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 1328 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 1329 | } |
| 1330 | |
| 1331 | private: |
| 1332 | /** |
| 1333 | * Functions triggers appropriate requests on DBus |
| 1334 | */ |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1335 | void doGet(crow::Response& res, const crow::Request&, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1336 | const std::vector<std::string>& params) override |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1337 | { |
| 1338 | // Check if there is required param, truly entering this shall be |
| 1339 | // impossible |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1340 | if (params.size() != 1) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1341 | { |
| 1342 | messages::internalError(res); |
| 1343 | res.end(); |
| 1344 | return; |
| 1345 | } |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1346 | const std::string& dimmId = params[0]; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1347 | |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 1348 | res.jsonValue["@odata.type"] = "#Memory.v1_7_0.Memory"; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1349 | res.jsonValue["@odata.id"] = |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1350 | "/redfish/v1/Systems/system/Memory/" + dimmId; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1351 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 1352 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1353 | getDimmData(asyncResp, dimmId); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1354 | } |
| 1355 | }; |
| 1356 | |
| 1357 | } // namespace redfish |