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