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 | |
| 18 | #include <boost/container/flat_map.hpp> |
| 19 | #include <node.hpp> |
| 20 | #include <utils/json_utils.hpp> |
| 21 | |
| 22 | namespace redfish |
| 23 | { |
| 24 | |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 25 | using InterfacesProperties = boost::container::flat_map< |
| 26 | std::string, |
| 27 | boost::container::flat_map<std::string, dbus::utility::DbusVariantType>>; |
| 28 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 29 | void getResourceList(std::shared_ptr<AsyncResp> aResp, |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 30 | const std::string &subclass, |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 31 | const std::vector<const char *> &collectionName) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 32 | { |
| 33 | BMCWEB_LOG_DEBUG << "Get available system cpu/mem resources."; |
| 34 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 35 | [subclass, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 36 | const boost::system::error_code ec, |
| 37 | const boost::container::flat_map< |
| 38 | std::string, boost::container::flat_map< |
| 39 | std::string, std::vector<std::string>>> |
| 40 | &subtree) { |
| 41 | if (ec) |
| 42 | { |
| 43 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 44 | messages::internalError(aResp->res); |
| 45 | return; |
| 46 | } |
| 47 | nlohmann::json &members = aResp->res.jsonValue["Members"]; |
| 48 | members = nlohmann::json::array(); |
| 49 | |
| 50 | for (const auto &object : subtree) |
| 51 | { |
| 52 | auto iter = object.first.rfind("/"); |
| 53 | if ((iter != std::string::npos) && (iter < object.first.size())) |
| 54 | { |
| 55 | members.push_back( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 56 | {{"@odata.id", "/redfish/v1/Systems/system/" + |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 57 | subclass + "/" + |
| 58 | object.first.substr(iter + 1)}}); |
| 59 | } |
| 60 | } |
| 61 | aResp->res.jsonValue["Members@odata.count"] = members.size(); |
| 62 | }, |
| 63 | "xyz.openbmc_project.ObjectMapper", |
| 64 | "/xyz/openbmc_project/object_mapper", |
| 65 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 66 | "/xyz/openbmc_project/inventory", 0, collectionName); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 67 | } |
| 68 | |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 69 | void getCpuDataByInterface(std::shared_ptr<AsyncResp> aResp, |
| 70 | const InterfacesProperties &cpuInterfacesProperties) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 71 | { |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 72 | BMCWEB_LOG_DEBUG << "Get CPU resources by interface."; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 73 | |
Ed Tanous | 99131cd | 2019-10-24 11:12:47 -0700 | [diff] [blame] | 74 | const bool *present = nullptr; |
| 75 | const bool *functional = nullptr; |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 76 | for (const auto &interface : cpuInterfacesProperties) |
| 77 | { |
| 78 | for (const auto &property : interface.second) |
| 79 | { |
| 80 | if (property.first == "ProcessorCoreCount") |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 81 | { |
Ed Tanous | 883b311 | 2018-12-06 16:13:35 -0800 | [diff] [blame] | 82 | const uint16_t *coresCount = |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 83 | std::get_if<uint16_t>(&property.second); |
Ed Tanous | 883b311 | 2018-12-06 16:13:35 -0800 | [diff] [blame] | 84 | if (coresCount == nullptr) |
| 85 | { |
| 86 | // Important property not in desired type |
| 87 | messages::internalError(aResp->res); |
| 88 | return; |
| 89 | } |
| 90 | if (*coresCount == 0) |
| 91 | { |
| 92 | // Slot is not populated, set status end return |
| 93 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 94 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 95 | // HTTP Code will be set up automatically, just return |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | aResp->res.jsonValue["TotalCores"] = *coresCount; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 100 | } |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 101 | else if (property.first == "ProcessorType") |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 102 | { |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 103 | aResp->res.jsonValue["Name"] = property.second; |
| 104 | } |
| 105 | else if (property.first == "Manufacturer") |
| 106 | { |
| 107 | const std::string *value = |
| 108 | std::get_if<std::string>(&property.second); |
| 109 | if (value != nullptr) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 110 | { |
| 111 | aResp->res.jsonValue["Manufacturer"] = property.second; |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 112 | // Otherwise would be unexpected. |
| 113 | if (value->find("Intel") != std::string::npos) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 114 | { |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 115 | aResp->res.jsonValue["ProcessorArchitecture"] = "x86"; |
| 116 | aResp->res.jsonValue["InstructionSet"] = "x86-64"; |
| 117 | } |
| 118 | else if (value->find("IBM") != std::string::npos) |
| 119 | { |
| 120 | aResp->res.jsonValue["ProcessorArchitecture"] = "Power"; |
| 121 | aResp->res.jsonValue["InstructionSet"] = "PowerISA"; |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | else if (property.first == "ProcessorMaxSpeed") |
| 126 | { |
| 127 | aResp->res.jsonValue["MaxSpeedMHz"] = property.second; |
| 128 | } |
| 129 | else if (property.first == "ProcessorThreadCount") |
| 130 | { |
| 131 | aResp->res.jsonValue["TotalThreads"] = property.second; |
| 132 | } |
| 133 | else if (property.first == "Model") |
| 134 | { |
| 135 | const std::string *value = |
| 136 | std::get_if<std::string>(&property.second); |
| 137 | if (value != nullptr) |
| 138 | { |
| 139 | aResp->res.jsonValue["Model"] = *value; |
| 140 | } |
| 141 | } |
Gunnar Mills | f9dcc11 | 2020-02-13 13:19:43 -0600 | [diff] [blame] | 142 | else if (property.first == "PartNumber") |
| 143 | { |
| 144 | aResp->res.jsonValue["PartNumber"] = property.second; |
| 145 | } |
| 146 | else if (property.first == "SerialNumber") |
| 147 | { |
| 148 | aResp->res.jsonValue["SerialNumber"] = property.second; |
| 149 | } |
| 150 | else if (property.first == "Version") |
| 151 | { |
| 152 | aResp->res.jsonValue["Version"] = property.second; |
| 153 | } |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 154 | else if (property.first == "Present") |
| 155 | { |
| 156 | present = std::get_if<bool>(&property.second); |
| 157 | } |
| 158 | else if (property.first == "Functional") |
| 159 | { |
| 160 | functional = std::get_if<bool>(&property.second); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | if ((present == nullptr) || (functional == nullptr)) |
| 166 | { |
| 167 | // Important property not in desired type |
| 168 | messages::internalError(aResp->res); |
| 169 | return; |
| 170 | } |
| 171 | |
| 172 | if (*present == false) |
| 173 | { |
| 174 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 175 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 176 | } |
| 177 | else |
| 178 | { |
| 179 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 180 | if (*functional == true) |
| 181 | { |
| 182 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 183 | } |
| 184 | else |
| 185 | { |
| 186 | aResp->res.jsonValue["Status"]["Health"] = "Critical"; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | void getCpuDataByService(std::shared_ptr<AsyncResp> aResp, |
| 194 | const std::string &cpuId, const std::string &service, |
| 195 | const std::string &objPath) |
| 196 | { |
| 197 | BMCWEB_LOG_DEBUG << "Get available system cpu resources by service."; |
| 198 | |
| 199 | crow::connections::systemBus->async_method_call( |
| 200 | [cpuId, service, objPath, aResp{std::move(aResp)}]( |
| 201 | const boost::system::error_code ec, |
| 202 | const dbus::utility::ManagedObjectType &dbusData) { |
| 203 | if (ec) |
| 204 | { |
| 205 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 206 | messages::internalError(aResp->res); |
| 207 | return; |
| 208 | } |
| 209 | aResp->res.jsonValue["Id"] = cpuId; |
| 210 | aResp->res.jsonValue["Name"] = "Processor"; |
| 211 | aResp->res.jsonValue["ProcessorType"] = "CPU"; |
| 212 | |
| 213 | std::string corePath = objPath + "/core"; |
| 214 | size_t totalCores = 0; |
| 215 | for (const auto &object : dbusData) |
| 216 | { |
| 217 | if (object.first.str == objPath) |
| 218 | { |
| 219 | getCpuDataByInterface(aResp, object.second); |
| 220 | } |
| 221 | else if (boost::starts_with(object.first.str, corePath)) |
| 222 | { |
| 223 | for (const auto &interface : object.second) |
| 224 | { |
| 225 | if (interface.first == |
| 226 | "xyz.openbmc_project.Inventory.Item") |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 227 | { |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 228 | for (const auto &property : interface.second) |
| 229 | { |
| 230 | if (property.first == "Present") |
| 231 | { |
| 232 | const bool *present = |
| 233 | std::get_if<bool>(&property.second); |
| 234 | if (present != nullptr) |
| 235 | { |
| 236 | if (*present == true) |
| 237 | { |
| 238 | totalCores++; |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | } |
Gunnar Mills | b957ba5 | 2019-01-31 15:58:15 -0600 | [diff] [blame] | 243 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 244 | } |
| 245 | } |
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 | // In getCpuDataByInterface(), state and health are set |
| 248 | // based on the present and functional status. If core |
| 249 | // count is zero, then it has a higher precedence. |
| 250 | if (totalCores == 0) |
| 251 | { |
| 252 | // Slot is not populated, set status end return |
| 253 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 254 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 255 | } |
| 256 | aResp->res.jsonValue["TotalCores"] = totalCores; |
| 257 | return; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 258 | }, |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 259 | service, "/xyz/openbmc_project/inventory", |
| 260 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 261 | } |
| 262 | |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 263 | void getAcceleratorDataByService(std::shared_ptr<AsyncResp> aResp, |
| 264 | const std::string &acclrtrId, |
| 265 | const std::string &service, |
| 266 | const std::string &objPath) |
| 267 | { |
| 268 | BMCWEB_LOG_DEBUG |
| 269 | << "Get available system Accelerator resources by service."; |
| 270 | crow::connections::systemBus->async_method_call( |
| 271 | [acclrtrId, aResp{std::move(aResp)}]( |
| 272 | const boost::system::error_code ec, |
| 273 | const boost::container::flat_map< |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 274 | std::string, std::variant<std::string, uint32_t, uint16_t, |
| 275 | bool>> &properties) { |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 276 | if (ec) |
| 277 | { |
| 278 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 279 | messages::internalError(aResp->res); |
| 280 | return; |
| 281 | } |
| 282 | aResp->res.jsonValue["Id"] = acclrtrId; |
| 283 | aResp->res.jsonValue["Name"] = "Processor"; |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 284 | const bool *accPresent = nullptr; |
| 285 | const bool *accFunctional = nullptr; |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 286 | std::string state = ""; |
| 287 | |
| 288 | for (const auto &property : properties) |
| 289 | { |
| 290 | if (property.first == "Functional") |
| 291 | { |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 292 | accFunctional = std::get_if<bool>(&property.second); |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 293 | } |
| 294 | else if (property.first == "Present") |
| 295 | { |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 296 | accPresent = std::get_if<bool>(&property.second); |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
| 300 | if (!accPresent || !accFunctional) |
| 301 | { |
| 302 | BMCWEB_LOG_DEBUG << "Required properties missing in DBUS " |
| 303 | "response"; |
| 304 | messages::internalError(aResp->res); |
| 305 | return; |
| 306 | } |
| 307 | |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 308 | if (*accPresent && *accFunctional) |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 309 | { |
| 310 | state = "Enabled"; |
| 311 | } |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 312 | else if (*accPresent) |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 313 | { |
| 314 | state = "UnavailableOffline"; |
| 315 | } |
| 316 | else |
| 317 | { |
| 318 | state = "Absent"; |
| 319 | } |
| 320 | aResp->res.jsonValue["Status"]["State"] = state; |
| 321 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 322 | aResp->res.jsonValue["ProcessorType"] = "Accelerator"; |
| 323 | }, |
| 324 | service, objPath, "org.freedesktop.DBus.Properties", "GetAll", ""); |
| 325 | } |
| 326 | |
| 327 | void getCpuData(std::shared_ptr<AsyncResp> aResp, const std::string &cpuId, |
| 328 | const std::vector<const char *> inventoryItems) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 329 | { |
| 330 | BMCWEB_LOG_DEBUG << "Get available system cpu resources."; |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 331 | |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 332 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 333 | [cpuId, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 334 | const boost::system::error_code ec, |
| 335 | const boost::container::flat_map< |
| 336 | std::string, boost::container::flat_map< |
| 337 | std::string, std::vector<std::string>>> |
| 338 | &subtree) { |
| 339 | if (ec) |
| 340 | { |
| 341 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 342 | messages::internalError(aResp->res); |
| 343 | return; |
| 344 | } |
| 345 | for (const auto &object : subtree) |
| 346 | { |
| 347 | if (boost::ends_with(object.first, cpuId)) |
| 348 | { |
| 349 | for (const auto &service : object.second) |
| 350 | { |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 351 | for (const auto &inventory : service.second) |
| 352 | if (inventory == |
| 353 | "xyz.openbmc_project.Inventory.Item.Cpu") |
| 354 | { |
| 355 | getCpuDataByService(aResp, cpuId, service.first, |
| 356 | object.first); |
| 357 | } |
| 358 | else if (inventory == "xyz.openbmc_project." |
| 359 | "Inventory.Item.Accelerator") |
| 360 | { |
| 361 | getAcceleratorDataByService( |
| 362 | aResp, cpuId, service.first, object.first); |
| 363 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 364 | return; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | // Object not found |
| 369 | messages::resourceNotFound(aResp->res, "Processor", cpuId); |
| 370 | return; |
| 371 | }, |
| 372 | "xyz.openbmc_project.ObjectMapper", |
| 373 | "/xyz/openbmc_project/object_mapper", |
| 374 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 375 | "/xyz/openbmc_project/inventory", 0, inventoryItems); |
| 376 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 377 | |
| 378 | void getDimmDataByService(std::shared_ptr<AsyncResp> aResp, |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 379 | const std::string &dimmId, const std::string &service, |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 380 | const std::string &objPath) |
| 381 | { |
| 382 | BMCWEB_LOG_DEBUG << "Get available system components."; |
| 383 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 384 | [dimmId, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 385 | const boost::system::error_code ec, |
| 386 | const boost::container::flat_map< |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 387 | std::string, std::variant<std::string, uint32_t, uint16_t>> |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 388 | &properties) { |
| 389 | if (ec) |
| 390 | { |
| 391 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 392 | messages::internalError(aResp->res); |
| 393 | |
| 394 | return; |
| 395 | } |
| 396 | aResp->res.jsonValue["Id"] = dimmId; |
| 397 | aResp->res.jsonValue["Name"] = "DIMM Slot"; |
| 398 | |
| 399 | const auto memorySizeProperty = properties.find("MemorySizeInKB"); |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 400 | if (memorySizeProperty != properties.end()) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 401 | { |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 402 | const uint32_t *memorySize = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 403 | std::get_if<uint32_t>(&memorySizeProperty->second); |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 404 | if (memorySize == nullptr) |
| 405 | { |
| 406 | // Important property not in desired type |
| 407 | messages::internalError(aResp->res); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 408 | |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 409 | return; |
| 410 | } |
| 411 | if (*memorySize == 0) |
| 412 | { |
| 413 | // Slot is not populated, set status end return |
| 414 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 415 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 416 | // HTTP Code will be set up automatically, just return |
| 417 | return; |
| 418 | } |
| 419 | aResp->res.jsonValue["CapacityMiB"] = (*memorySize >> 10); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 420 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 421 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 422 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 423 | |
| 424 | for (const auto &property : properties) |
| 425 | { |
| 426 | if (property.first == "MemoryDataWidth") |
| 427 | { |
| 428 | aResp->res.jsonValue["DataWidthBits"] = property.second; |
| 429 | } |
Manojkiran Eda | 7e236ca | 2019-06-25 23:06:32 +0530 | [diff] [blame] | 430 | else if (property.first == "PartNumber") |
| 431 | { |
| 432 | aResp->res.jsonValue["PartNumber"] = property.second; |
| 433 | } |
| 434 | else if (property.first == "SerialNumber") |
| 435 | { |
| 436 | aResp->res.jsonValue["SerialNumber"] = property.second; |
| 437 | } |
| 438 | else if (property.first == "Manufacturer") |
| 439 | { |
| 440 | aResp->res.jsonValue["Manufacturer"] = property.second; |
| 441 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 442 | else if (property.first == "MemoryType") |
| 443 | { |
| 444 | const auto *value = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 445 | std::get_if<std::string>(&property.second); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 446 | if (value != nullptr) |
| 447 | { |
| 448 | aResp->res.jsonValue["MemoryDeviceType"] = *value; |
| 449 | if (boost::starts_with(*value, "DDR")) |
| 450 | { |
| 451 | aResp->res.jsonValue["MemoryType"] = "DRAM"; |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | }, |
| 457 | service, objPath, "org.freedesktop.DBus.Properties", "GetAll", ""); |
| 458 | } |
| 459 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 460 | void getDimmData(std::shared_ptr<AsyncResp> aResp, const std::string &dimmId) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 461 | { |
| 462 | BMCWEB_LOG_DEBUG << "Get available system dimm resources."; |
| 463 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 464 | [dimmId, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 465 | const boost::system::error_code ec, |
| 466 | const boost::container::flat_map< |
| 467 | std::string, boost::container::flat_map< |
| 468 | std::string, std::vector<std::string>>> |
| 469 | &subtree) { |
| 470 | if (ec) |
| 471 | { |
| 472 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 473 | messages::internalError(aResp->res); |
| 474 | |
| 475 | return; |
| 476 | } |
| 477 | for (const auto &object : subtree) |
| 478 | { |
| 479 | if (boost::ends_with(object.first, dimmId)) |
| 480 | { |
| 481 | for (const auto &service : object.second) |
| 482 | { |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 483 | getDimmDataByService(aResp, dimmId, service.first, |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 484 | object.first); |
| 485 | return; |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | // Object not found |
| 490 | messages::resourceNotFound(aResp->res, "Memory", dimmId); |
| 491 | return; |
| 492 | }, |
| 493 | "xyz.openbmc_project.ObjectMapper", |
| 494 | "/xyz/openbmc_project/object_mapper", |
| 495 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 496 | "/xyz/openbmc_project/inventory", 0, |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 497 | std::array<const char *, 1>{"xyz.openbmc_project.Inventory.Item.Dimm"}); |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 498 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 499 | |
| 500 | class ProcessorCollection : public Node |
| 501 | { |
| 502 | public: |
| 503 | /* |
| 504 | * Default Constructor |
| 505 | */ |
| 506 | ProcessorCollection(CrowApp &app) : |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 507 | Node(app, "/redfish/v1/Systems/system/Processors/") |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 508 | { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 509 | entityPrivileges = { |
| 510 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 511 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 512 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 513 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 514 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 515 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 516 | } |
| 517 | |
| 518 | private: |
| 519 | /** |
| 520 | * Functions triggers appropriate requests on DBus |
| 521 | */ |
| 522 | void doGet(crow::Response &res, const crow::Request &req, |
| 523 | const std::vector<std::string> ¶ms) override |
| 524 | { |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 525 | res.jsonValue["@odata.type"] = |
| 526 | "#ProcessorCollection.ProcessorCollection"; |
| 527 | res.jsonValue["Name"] = "Processor Collection"; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 528 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 529 | res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Processors/"; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 530 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 531 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 532 | getResourceList(asyncResp, "Processors", |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 533 | {"xyz.openbmc_project.Inventory.Item.Cpu", |
| 534 | "xyz.openbmc_project.Inventory.Item.Accelerator"}); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 535 | } |
| 536 | }; |
| 537 | |
| 538 | class Processor : public Node |
| 539 | { |
| 540 | public: |
| 541 | /* |
| 542 | * Default Constructor |
| 543 | */ |
| 544 | Processor(CrowApp &app) : |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 545 | Node(app, "/redfish/v1/Systems/system/Processors/<str>/", std::string()) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 546 | { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 547 | entityPrivileges = { |
| 548 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 549 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 550 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 551 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 552 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 553 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 554 | } |
| 555 | |
| 556 | private: |
| 557 | /** |
| 558 | * Functions triggers appropriate requests on DBus |
| 559 | */ |
| 560 | void doGet(crow::Response &res, const crow::Request &req, |
| 561 | const std::vector<std::string> ¶ms) override |
| 562 | { |
| 563 | // Check if there is required param, truly entering this shall be |
| 564 | // impossible |
| 565 | if (params.size() != 1) |
| 566 | { |
| 567 | messages::internalError(res); |
| 568 | |
| 569 | res.end(); |
| 570 | return; |
| 571 | } |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 572 | const std::string &processorId = params[0]; |
Gunnar Mills | f9dcc11 | 2020-02-13 13:19:43 -0600 | [diff] [blame] | 573 | res.jsonValue["@odata.type"] = "#Processor.v1_7_0.Processor"; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 574 | res.jsonValue["@odata.id"] = |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 575 | "/redfish/v1/Systems/system/Processors/" + processorId; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 576 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 577 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 578 | |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 579 | getCpuData(asyncResp, processorId, |
| 580 | {"xyz.openbmc_project.Inventory.Item.Cpu", |
| 581 | "xyz.openbmc_project.Inventory.Item.Accelerator"}); |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 582 | } |
| 583 | }; |
| 584 | |
| 585 | class MemoryCollection : public Node |
| 586 | { |
| 587 | public: |
| 588 | /* |
| 589 | * Default Constructor |
| 590 | */ |
| 591 | MemoryCollection(CrowApp &app) : |
| 592 | Node(app, "/redfish/v1/Systems/system/Memory/") |
| 593 | { |
| 594 | entityPrivileges = { |
| 595 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 596 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 597 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 598 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 599 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 600 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 601 | } |
| 602 | |
| 603 | private: |
| 604 | /** |
| 605 | * Functions triggers appropriate requests on DBus |
| 606 | */ |
| 607 | void doGet(crow::Response &res, const crow::Request &req, |
| 608 | const std::vector<std::string> ¶ms) override |
| 609 | { |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 610 | res.jsonValue["@odata.type"] = "#MemoryCollection.MemoryCollection"; |
| 611 | res.jsonValue["Name"] = "Memory Module Collection"; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 612 | res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Memory/"; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 613 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 614 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 615 | getResourceList(asyncResp, "Memory", |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 616 | {"xyz.openbmc_project.Inventory.Item.Dimm"}); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 617 | } |
| 618 | }; |
| 619 | |
| 620 | class Memory : public Node |
| 621 | { |
| 622 | public: |
| 623 | /* |
| 624 | * Default Constructor |
| 625 | */ |
| 626 | Memory(CrowApp &app) : |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 627 | Node(app, "/redfish/v1/Systems/system/Memory/<str>/", std::string()) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 628 | { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 629 | entityPrivileges = { |
| 630 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 631 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 632 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 633 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 634 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 635 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 636 | } |
| 637 | |
| 638 | private: |
| 639 | /** |
| 640 | * Functions triggers appropriate requests on DBus |
| 641 | */ |
| 642 | void doGet(crow::Response &res, const crow::Request &req, |
| 643 | const std::vector<std::string> ¶ms) override |
| 644 | { |
| 645 | // Check if there is required param, truly entering this shall be |
| 646 | // impossible |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 647 | if (params.size() != 1) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 648 | { |
| 649 | messages::internalError(res); |
| 650 | res.end(); |
| 651 | return; |
| 652 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 653 | const std::string &dimmId = params[0]; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 654 | |
Rapkiewicz, Pawel | bb3d994 | 2018-11-22 10:59:11 +0100 | [diff] [blame] | 655 | res.jsonValue["@odata.type"] = "#Memory.v1_6_0.Memory"; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 656 | res.jsonValue["@odata.id"] = |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 657 | "/redfish/v1/Systems/system/Memory/" + dimmId; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 658 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 659 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 660 | getDimmData(asyncResp, dimmId); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 661 | } |
| 662 | }; |
| 663 | |
| 664 | } // namespace redfish |