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 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 20 | #include <app.hpp> |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 21 | #include <boost/container/flat_map.hpp> |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 22 | #include <registries/privilege_registry.hpp> |
Gunnar Mills | 116bcc5 | 2020-10-14 15:23:42 -0500 | [diff] [blame] | 23 | #include <utils/collection.hpp> |
Ed Tanous | f201ffb | 2021-10-09 14:49:28 -0700 | [diff] [blame] | 24 | #include <utils/hex_utils.hpp> |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 25 | #include <utils/json_utils.hpp> |
| 26 | |
| 27 | namespace redfish |
| 28 | { |
| 29 | |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 30 | using DimmProperty = |
| 31 | std::variant<std::string, std::vector<uint32_t>, std::vector<uint16_t>, |
| 32 | uint64_t, uint32_t, uint16_t, uint8_t, bool>; |
| 33 | |
| 34 | using DimmProperties = boost::container::flat_map<std::string, DimmProperty>; |
| 35 | |
Gunnar Mills | 313efb1 | 2020-10-26 16:05:08 -0500 | [diff] [blame] | 36 | inline std::string translateMemoryTypeToRedfish(const std::string& memoryType) |
| 37 | { |
| 38 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR") |
| 39 | { |
| 40 | return "DDR"; |
| 41 | } |
| 42 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2") |
| 43 | { |
| 44 | return "DDR2"; |
| 45 | } |
| 46 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR3") |
| 47 | { |
| 48 | return "DDR3"; |
| 49 | } |
| 50 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4") |
| 51 | { |
| 52 | return "DDR4"; |
| 53 | } |
| 54 | if (memoryType == |
| 55 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4E_SDRAM") |
| 56 | { |
| 57 | return "DDR4E_SDRAM"; |
| 58 | } |
Mansi Joshi | 11a2f0f | 2021-07-19 14:33:27 +0530 | [diff] [blame] | 59 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR5") |
| 60 | { |
| 61 | return "DDR5"; |
| 62 | } |
Gunnar Mills | 313efb1 | 2020-10-26 16:05:08 -0500 | [diff] [blame] | 63 | if (memoryType == |
| 64 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR4_SDRAM") |
| 65 | { |
| 66 | return "LPDDR4_SDRAM"; |
| 67 | } |
| 68 | if (memoryType == |
| 69 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR3_SDRAM") |
| 70 | { |
| 71 | return "LPDDR3_SDRAM"; |
| 72 | } |
| 73 | if (memoryType == |
| 74 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM") |
| 75 | { |
| 76 | return "DDR2_SDRAM_FB_DIMM"; |
| 77 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 78 | if (memoryType == |
| 79 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM_PROB") |
Gunnar Mills | 313efb1 | 2020-10-26 16:05:08 -0500 | [diff] [blame] | 80 | { |
| 81 | return "DDR2_SDRAM_FB_DIMM_PROBE"; |
| 82 | } |
| 83 | if (memoryType == |
| 84 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR_SGRAM") |
| 85 | { |
| 86 | return "DDR_SGRAM"; |
| 87 | } |
| 88 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.ROM") |
| 89 | { |
| 90 | return "ROM"; |
| 91 | } |
| 92 | if (memoryType == |
| 93 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.SDRAM") |
| 94 | { |
| 95 | return "SDRAM"; |
| 96 | } |
| 97 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.EDO") |
| 98 | { |
| 99 | return "EDO"; |
| 100 | } |
| 101 | if (memoryType == |
| 102 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.FastPageMode") |
| 103 | { |
| 104 | return "FastPageMode"; |
| 105 | } |
| 106 | if (memoryType == |
| 107 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.PipelinedNibble") |
| 108 | { |
| 109 | return "PipelinedNibble"; |
| 110 | } |
| 111 | if (memoryType == |
| 112 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.Logical") |
| 113 | { |
| 114 | return "Logical"; |
| 115 | } |
| 116 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM") |
| 117 | { |
| 118 | return "HBM"; |
| 119 | } |
| 120 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM2") |
| 121 | { |
| 122 | return "HBM2"; |
| 123 | } |
| 124 | // This is values like Other or Unknown |
| 125 | // Also D-Bus values: |
| 126 | // DRAM |
| 127 | // EDRAM |
| 128 | // VRAM |
| 129 | // SRAM |
| 130 | // RAM |
| 131 | // FLASH |
| 132 | // EEPROM |
| 133 | // FEPROM |
| 134 | // EPROM |
| 135 | // CDRAM |
| 136 | // ThreeDRAM |
| 137 | // RDRAM |
| 138 | // FBD2 |
| 139 | // LPDDR_SDRAM |
| 140 | // LPDDR2_SDRAM |
Mansi Joshi | 11a2f0f | 2021-07-19 14:33:27 +0530 | [diff] [blame] | 141 | // LPDDR5_SDRAM |
Gunnar Mills | 313efb1 | 2020-10-26 16:05:08 -0500 | [diff] [blame] | 142 | return ""; |
| 143 | } |
| 144 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 145 | inline void dimmPropToHex(const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 146 | const char* key, |
Ed Tanous | 80789c8 | 2020-08-19 09:19:09 -0700 | [diff] [blame] | 147 | const std::pair<std::string, DimmProperty>& property) |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 148 | { |
| 149 | const uint16_t* value = std::get_if<uint16_t>(&property.second); |
| 150 | if (value == nullptr) |
| 151 | { |
| 152 | messages::internalError(aResp->res); |
| 153 | BMCWEB_LOG_DEBUG << "Invalid property type for " << property.first; |
| 154 | return; |
| 155 | } |
| 156 | |
Ed Tanous | f201ffb | 2021-10-09 14:49:28 -0700 | [diff] [blame] | 157 | aResp->res.jsonValue[key] = "0x" + intToHexString(*value); |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 158 | } |
| 159 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 160 | inline void getPersistentMemoryProperties( |
| 161 | const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
| 162 | const DimmProperties& properties) |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 163 | { |
| 164 | for (const auto& property : properties) |
| 165 | { |
| 166 | if (property.first == "ModuleManufacturerID") |
| 167 | { |
| 168 | dimmPropToHex(aResp, "ModuleManufacturerID", property); |
| 169 | } |
| 170 | else if (property.first == "ModuleProductID") |
| 171 | { |
| 172 | dimmPropToHex(aResp, "ModuleProductID", property); |
| 173 | } |
| 174 | else if (property.first == "SubsystemVendorID") |
| 175 | { |
| 176 | dimmPropToHex(aResp, "MemorySubsystemControllerManufacturerID", |
| 177 | property); |
| 178 | } |
| 179 | else if (property.first == "SubsystemDeviceID") |
| 180 | { |
| 181 | dimmPropToHex(aResp, "MemorySubsystemControllerProductID", |
| 182 | property); |
| 183 | } |
| 184 | else if (property.first == "VolatileRegionSizeLimitInKiB") |
| 185 | { |
| 186 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 187 | |
| 188 | if (value == nullptr) |
| 189 | { |
| 190 | messages::internalError(aResp->res); |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 191 | BMCWEB_LOG_DEBUG |
| 192 | << "Invalid property type for VolatileRegionSizeLimitKiB"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 193 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 194 | } |
| 195 | aResp->res.jsonValue["VolatileRegionSizeLimitMiB"] = (*value) >> 10; |
| 196 | } |
| 197 | else if (property.first == "PmRegionSizeLimitInKiB") |
| 198 | { |
| 199 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 200 | |
| 201 | if (value == nullptr) |
| 202 | { |
| 203 | messages::internalError(aResp->res); |
| 204 | BMCWEB_LOG_DEBUG |
| 205 | << "Invalid property type for PmRegioSizeLimitKiB"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 206 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 207 | } |
| 208 | aResp->res.jsonValue["PersistentRegionSizeLimitMiB"] = |
| 209 | (*value) >> 10; |
| 210 | } |
| 211 | else if (property.first == "VolatileSizeInKiB") |
| 212 | { |
| 213 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 214 | |
| 215 | if (value == nullptr) |
| 216 | { |
| 217 | messages::internalError(aResp->res); |
| 218 | BMCWEB_LOG_DEBUG |
| 219 | << "Invalid property type for VolatileSizeInKiB"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 220 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 221 | } |
| 222 | aResp->res.jsonValue["VolatileSizeMiB"] = (*value) >> 10; |
| 223 | } |
| 224 | else if (property.first == "PmSizeInKiB") |
| 225 | { |
| 226 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 227 | if (value == nullptr) |
| 228 | { |
| 229 | messages::internalError(aResp->res); |
| 230 | BMCWEB_LOG_DEBUG << "Invalid property type for PmSizeInKiB"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 231 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 232 | } |
| 233 | aResp->res.jsonValue["NonVolatileSizeMiB"] = (*value) >> 10; |
| 234 | } |
| 235 | else if (property.first == "CacheSizeInKB") |
| 236 | { |
| 237 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 238 | if (value == nullptr) |
| 239 | { |
| 240 | messages::internalError(aResp->res); |
| 241 | BMCWEB_LOG_DEBUG << "Invalid property type for CacheSizeInKB"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 242 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 243 | } |
| 244 | aResp->res.jsonValue["CacheSizeMiB"] = (*value >> 10); |
| 245 | } |
| 246 | |
| 247 | else if (property.first == "VoltaileRegionMaxSizeInKib") |
| 248 | { |
| 249 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 250 | |
| 251 | if (value == nullptr) |
| 252 | { |
| 253 | messages::internalError(aResp->res); |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 254 | BMCWEB_LOG_DEBUG |
| 255 | << "Invalid property type for VolatileRegionMaxSizeInKib"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 256 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 257 | } |
| 258 | aResp->res.jsonValue["VolatileRegionSizeMaxMiB"] = (*value) >> 10; |
| 259 | } |
| 260 | else if (property.first == "PmRegionMaxSizeInKiB") |
| 261 | { |
| 262 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 263 | |
| 264 | if (value == nullptr) |
| 265 | { |
| 266 | messages::internalError(aResp->res); |
| 267 | BMCWEB_LOG_DEBUG |
| 268 | << "Invalid property type for PmRegionMaxSizeInKiB"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 269 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 270 | } |
| 271 | aResp->res.jsonValue["PersistentRegionSizeMaxMiB"] = (*value) >> 10; |
| 272 | } |
| 273 | else if (property.first == "AllocationIncrementInKiB") |
| 274 | { |
| 275 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 276 | |
| 277 | if (value == nullptr) |
| 278 | { |
| 279 | messages::internalError(aResp->res); |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 280 | BMCWEB_LOG_DEBUG |
| 281 | << "Invalid property type for AllocationIncrementInKiB"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 282 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 283 | } |
| 284 | aResp->res.jsonValue["AllocationIncrementMiB"] = (*value) >> 10; |
| 285 | } |
| 286 | else if (property.first == "AllocationAlignmentInKiB") |
| 287 | { |
| 288 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 289 | |
| 290 | if (value == nullptr) |
| 291 | { |
| 292 | messages::internalError(aResp->res); |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 293 | BMCWEB_LOG_DEBUG |
| 294 | << "Invalid property type for AllocationAlignmentInKiB"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 295 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 296 | } |
| 297 | aResp->res.jsonValue["AllocationAlignmentMiB"] = (*value) >> 10; |
| 298 | } |
| 299 | else if (property.first == "VolatileRegionNumberLimit") |
| 300 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 301 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 302 | if (value == nullptr) |
| 303 | { |
| 304 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 305 | return; |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 306 | } |
| 307 | aResp->res.jsonValue["VolatileRegionNumberLimit"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 308 | } |
| 309 | else if (property.first == "PmRegionNumberLimit") |
| 310 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 311 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 312 | if (value == nullptr) |
| 313 | { |
| 314 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 315 | return; |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 316 | } |
| 317 | aResp->res.jsonValue["PersistentRegionNumberLimit"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 318 | } |
| 319 | else if (property.first == "SpareDeviceCount") |
| 320 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 321 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 322 | if (value == nullptr) |
| 323 | { |
| 324 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 325 | return; |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 326 | } |
| 327 | aResp->res.jsonValue["SpareDeviceCount"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 328 | } |
| 329 | else if (property.first == "IsSpareDeviceInUse") |
| 330 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 331 | const bool* value = std::get_if<bool>(&property.second); |
| 332 | if (value == nullptr) |
| 333 | { |
| 334 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 335 | return; |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 336 | } |
| 337 | aResp->res.jsonValue["IsSpareDeviceEnabled"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 338 | } |
| 339 | else if (property.first == "IsRankSpareEnabled") |
| 340 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 341 | const bool* value = std::get_if<bool>(&property.second); |
| 342 | if (value == nullptr) |
| 343 | { |
| 344 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 345 | return; |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 346 | } |
| 347 | aResp->res.jsonValue["IsRankSpareEnabled"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 348 | } |
| 349 | else if (property.first == "MaxAveragePowerLimitmW") |
| 350 | { |
| 351 | const auto* value = |
| 352 | std::get_if<std::vector<uint32_t>>(&property.second); |
| 353 | if (value == nullptr) |
| 354 | { |
| 355 | messages::internalError(aResp->res); |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 356 | BMCWEB_LOG_DEBUG |
| 357 | << "Invalid property type for MaxAveragePowerLimitmW"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 358 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 359 | } |
| 360 | aResp->res.jsonValue["MaxTDPMilliWatts"] = *value; |
| 361 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 362 | else if (property.first == "ConfigurationLocked") |
| 363 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 364 | const bool* value = std::get_if<bool>(&property.second); |
| 365 | if (value == nullptr) |
| 366 | { |
| 367 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 368 | return; |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 369 | } |
| 370 | aResp->res.jsonValue["ConfigurationLocked"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 371 | } |
| 372 | else if (property.first == "AllowedMemoryModes") |
| 373 | { |
| 374 | const std::string* value = |
| 375 | std::get_if<std::string>(&property.second); |
| 376 | if (value == nullptr) |
| 377 | { |
| 378 | messages::internalError(aResp->res); |
| 379 | BMCWEB_LOG_DEBUG << "Invalid property type for FormFactor"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 380 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 381 | } |
| 382 | constexpr const std::array<const char*, 3> values{"Volatile", |
| 383 | "PMEM", "Block"}; |
| 384 | |
| 385 | for (const char* v : values) |
| 386 | { |
| 387 | if (boost::ends_with(*value, v)) |
| 388 | { |
| 389 | aResp->res.jsonValue["OperatingMemoryModes "] = v; |
| 390 | break; |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | else if (property.first == "MemoryMedia") |
| 395 | { |
| 396 | const std::string* value = |
| 397 | std::get_if<std::string>(&property.second); |
| 398 | if (value == nullptr) |
| 399 | { |
| 400 | messages::internalError(aResp->res); |
| 401 | BMCWEB_LOG_DEBUG << "Invalid property type for MemoryMedia"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 402 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 403 | } |
| 404 | constexpr const std::array<const char*, 3> values{"DRAM", "NAND", |
| 405 | "Intel3DXPoint"}; |
| 406 | |
| 407 | for (const char* v : values) |
| 408 | { |
| 409 | if (boost::ends_with(*value, v)) |
| 410 | { |
| 411 | aResp->res.jsonValue["MemoryMedia"] = v; |
| 412 | break; |
| 413 | } |
| 414 | } |
| 415 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 416 | // PersistantMemory.SecurityCapabilites interface |
| 417 | else if (property.first == "ConfigurationLockCapable" || |
| 418 | property.first == "DataLockCapable" || |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 419 | property.first == "PassphraseCapable") |
| 420 | { |
| 421 | const bool* value = std::get_if<bool>(&property.second); |
| 422 | if (value == nullptr) |
| 423 | { |
| 424 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 425 | return; |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 426 | } |
| 427 | aResp->res.jsonValue["SecurityCapabilities"][property.first] = |
| 428 | *value; |
| 429 | } |
| 430 | else if (property.first == "MaxPassphraseCount" || |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 431 | property.first == "PassphraseLockLimit") |
| 432 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 433 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 434 | if (value == nullptr) |
| 435 | { |
| 436 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 437 | return; |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 438 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 439 | aResp->res.jsonValue["SecurityCapabilities"][property.first] = |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 440 | *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 445 | inline void getDimmDataByService(std::shared_ptr<bmcweb::AsyncResp> aResp, |
Ed Tanous | 80789c8 | 2020-08-19 09:19:09 -0700 | [diff] [blame] | 446 | const std::string& dimmId, |
| 447 | const std::string& service, |
| 448 | const std::string& objPath) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 449 | { |
James Feist | 35e257a | 2020-06-05 13:30:51 -0700 | [diff] [blame] | 450 | auto health = std::make_shared<HealthPopulate>(aResp); |
| 451 | health->selfPath = objPath; |
| 452 | health->populate(); |
| 453 | |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 454 | BMCWEB_LOG_DEBUG << "Get available system components."; |
| 455 | crow::connections::systemBus->async_method_call( |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 456 | [dimmId, aResp{std::move(aResp)}](const boost::system::error_code ec, |
| 457 | const DimmProperties& properties) { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 458 | if (ec) |
| 459 | { |
| 460 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 461 | messages::internalError(aResp->res); |
| 462 | |
| 463 | return; |
| 464 | } |
| 465 | aResp->res.jsonValue["Id"] = dimmId; |
| 466 | aResp->res.jsonValue["Name"] = "DIMM Slot"; |
| 467 | |
| 468 | const auto memorySizeProperty = properties.find("MemorySizeInKB"); |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 469 | if (memorySizeProperty != properties.end()) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 470 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 471 | const uint32_t* memorySize = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 472 | std::get_if<uint32_t>(&memorySizeProperty->second); |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 473 | if (memorySize == nullptr) |
| 474 | { |
| 475 | // Important property not in desired type |
| 476 | messages::internalError(aResp->res); |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 477 | return; |
| 478 | } |
| 479 | aResp->res.jsonValue["CapacityMiB"] = (*memorySize >> 10); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 480 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 481 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 482 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 483 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 484 | for (const auto& property : properties) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 485 | { |
| 486 | if (property.first == "MemoryDataWidth") |
| 487 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 488 | const uint16_t* value = |
| 489 | std::get_if<uint16_t>(&property.second); |
| 490 | if (value == nullptr) |
| 491 | { |
| 492 | continue; |
| 493 | } |
| 494 | aResp->res.jsonValue["DataWidthBits"] = *value; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 495 | } |
Manojkiran Eda | 7e236ca | 2019-06-25 23:06:32 +0530 | [diff] [blame] | 496 | else if (property.first == "PartNumber") |
| 497 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 498 | const std::string* value = |
| 499 | std::get_if<std::string>(&property.second); |
| 500 | if (value == nullptr) |
| 501 | { |
| 502 | continue; |
| 503 | } |
| 504 | aResp->res.jsonValue["PartNumber"] = *value; |
Manojkiran Eda | 7e236ca | 2019-06-25 23:06:32 +0530 | [diff] [blame] | 505 | } |
| 506 | else if (property.first == "SerialNumber") |
| 507 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 508 | const std::string* value = |
| 509 | std::get_if<std::string>(&property.second); |
| 510 | if (value == nullptr) |
| 511 | { |
| 512 | continue; |
| 513 | } |
| 514 | aResp->res.jsonValue["SerialNumber"] = *value; |
Manojkiran Eda | 7e236ca | 2019-06-25 23:06:32 +0530 | [diff] [blame] | 515 | } |
| 516 | else if (property.first == "Manufacturer") |
| 517 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 518 | const std::string* value = |
| 519 | std::get_if<std::string>(&property.second); |
| 520 | if (value == nullptr) |
| 521 | { |
| 522 | continue; |
| 523 | } |
| 524 | aResp->res.jsonValue["Manufacturer"] = *value; |
Manojkiran Eda | 7e236ca | 2019-06-25 23:06:32 +0530 | [diff] [blame] | 525 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 526 | else if (property.first == "RevisionCode") |
| 527 | { |
| 528 | const uint16_t* value = |
| 529 | std::get_if<uint16_t>(&property.second); |
| 530 | |
| 531 | if (value == nullptr) |
| 532 | { |
| 533 | messages::internalError(aResp->res); |
| 534 | BMCWEB_LOG_DEBUG |
| 535 | << "Invalid property type for RevisionCode"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 536 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 537 | } |
| 538 | aResp->res.jsonValue["FirmwareRevision"] = |
| 539 | std::to_string(*value); |
| 540 | } |
Joshi-Mansi | 9a128eb | 2021-03-19 03:30:17 +0530 | [diff] [blame] | 541 | else if (property.first == "Present") |
| 542 | { |
| 543 | const bool* value = std::get_if<bool>(&property.second); |
| 544 | if (value == nullptr) |
| 545 | { |
| 546 | messages::internalError(aResp->res); |
| 547 | BMCWEB_LOG_DEBUG |
| 548 | << "Invalid property type for Dimm Presence"; |
| 549 | return; |
| 550 | } |
| 551 | if (*value == false) |
| 552 | { |
| 553 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 554 | } |
| 555 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 556 | else if (property.first == "MemoryTotalWidth") |
| 557 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 558 | const uint16_t* value = |
| 559 | std::get_if<uint16_t>(&property.second); |
| 560 | if (value == nullptr) |
| 561 | { |
| 562 | continue; |
| 563 | } |
| 564 | aResp->res.jsonValue["BusWidthBits"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 565 | } |
| 566 | else if (property.first == "ECC") |
| 567 | { |
| 568 | const std::string* value = |
| 569 | std::get_if<std::string>(&property.second); |
| 570 | if (value == nullptr) |
| 571 | { |
| 572 | messages::internalError(aResp->res); |
| 573 | BMCWEB_LOG_DEBUG << "Invalid property type for ECC"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 574 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 575 | } |
| 576 | constexpr const std::array<const char*, 4> values{ |
| 577 | "NoECC", "SingleBitECC", "MultiBitECC", |
| 578 | "AddressParity"}; |
| 579 | |
| 580 | for (const char* v : values) |
| 581 | { |
| 582 | if (boost::ends_with(*value, v)) |
| 583 | { |
| 584 | aResp->res.jsonValue["ErrorCorrection"] = v; |
| 585 | break; |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | else if (property.first == "FormFactor") |
| 590 | { |
| 591 | const std::string* value = |
| 592 | std::get_if<std::string>(&property.second); |
| 593 | if (value == nullptr) |
| 594 | { |
| 595 | messages::internalError(aResp->res); |
| 596 | BMCWEB_LOG_DEBUG |
| 597 | << "Invalid property type for FormFactor"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 598 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 599 | } |
| 600 | constexpr const std::array<const char*, 11> values{ |
| 601 | "RDIMM", "UDIMM", "SO_DIMM", |
| 602 | "LRDIMM", "Mini_RDIMM", "Mini_UDIMM", |
| 603 | "SO_RDIMM_72b", "SO_UDIMM_72b", "SO_DIMM_16b", |
| 604 | "SO_DIMM_32b", "Die"}; |
| 605 | |
| 606 | for (const char* v : values) |
| 607 | { |
| 608 | if (boost::ends_with(*value, v)) |
| 609 | { |
| 610 | aResp->res.jsonValue["BaseModuleType"] = v; |
| 611 | break; |
| 612 | } |
| 613 | } |
| 614 | } |
| 615 | else if (property.first == "AllowedSpeedsMT") |
| 616 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 617 | const std::vector<uint16_t>* value = |
| 618 | std::get_if<std::vector<uint16_t>>(&property.second); |
| 619 | if (value == nullptr) |
| 620 | { |
| 621 | continue; |
| 622 | } |
| 623 | nlohmann::json& jValue = |
| 624 | aResp->res.jsonValue["AllowedSpeedsMHz"]; |
| 625 | jValue = nlohmann::json::array(); |
| 626 | for (uint16_t subVal : *value) |
| 627 | { |
| 628 | jValue.push_back(subVal); |
| 629 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 630 | } |
| 631 | else if (property.first == "MemoryAttributes") |
| 632 | { |
| 633 | const uint8_t* value = |
| 634 | std::get_if<uint8_t>(&property.second); |
| 635 | |
| 636 | if (value == nullptr) |
| 637 | { |
| 638 | messages::internalError(aResp->res); |
| 639 | BMCWEB_LOG_DEBUG |
| 640 | << "Invalid property type for MemoryAttributes"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 641 | return; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 642 | } |
| 643 | aResp->res.jsonValue["RankCount"] = |
| 644 | static_cast<uint64_t>(*value); |
| 645 | } |
| 646 | else if (property.first == "MemoryConfiguredSpeedInMhz") |
| 647 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 648 | const uint16_t* value = |
| 649 | std::get_if<uint16_t>(&property.second); |
| 650 | if (value == nullptr) |
| 651 | { |
| 652 | continue; |
| 653 | } |
| 654 | aResp->res.jsonValue["OperatingSpeedMhz"] = *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 655 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 656 | else if (property.first == "MemoryType") |
| 657 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 658 | const auto* value = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 659 | std::get_if<std::string>(&property.second); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 660 | if (value != nullptr) |
| 661 | { |
Gunnar Mills | 313efb1 | 2020-10-26 16:05:08 -0500 | [diff] [blame] | 662 | std::string memoryDeviceType = |
| 663 | translateMemoryTypeToRedfish(*value); |
| 664 | // Values like "Unknown" or "Other" will return empty |
| 665 | // so just leave off |
| 666 | if (!memoryDeviceType.empty()) |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 667 | { |
Gunnar Mills | 313efb1 | 2020-10-26 16:05:08 -0500 | [diff] [blame] | 668 | aResp->res.jsonValue["MemoryDeviceType"] = |
| 669 | memoryDeviceType; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 670 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 671 | if (value->find("DDR") != std::string::npos) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 672 | { |
| 673 | aResp->res.jsonValue["MemoryType"] = "DRAM"; |
| 674 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 675 | else if (boost::ends_with(*value, "Logical")) |
| 676 | { |
| 677 | aResp->res.jsonValue["MemoryType"] = "IntelOptane"; |
| 678 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 679 | } |
| 680 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 681 | // memory location interface |
| 682 | else if (property.first == "Channel" || |
| 683 | property.first == "MemoryController" || |
| 684 | property.first == "Slot" || property.first == "Socket") |
| 685 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 686 | const std::string* value = |
| 687 | std::get_if<std::string>(&property.second); |
| 688 | if (value == nullptr) |
| 689 | { |
| 690 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 691 | return; |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 692 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 693 | aResp->res.jsonValue["MemoryLocation"][property.first] = |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 694 | *value; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 695 | } |
SunnySrivastava1984 | ee135e2 | 2020-12-15 12:42:19 -0600 | [diff] [blame] | 696 | else if (property.first == "SparePartNumber") |
| 697 | { |
| 698 | const std::string* value = |
| 699 | std::get_if<std::string>(&property.second); |
| 700 | if (value == nullptr) |
| 701 | { |
| 702 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 703 | return; |
SunnySrivastava1984 | ee135e2 | 2020-12-15 12:42:19 -0600 | [diff] [blame] | 704 | } |
| 705 | aResp->res.jsonValue["SparePartNumber"] = *value; |
| 706 | } |
| 707 | else if (property.first == "Model") |
| 708 | { |
| 709 | const std::string* value = |
| 710 | std::get_if<std::string>(&property.second); |
| 711 | if (value == nullptr) |
| 712 | { |
| 713 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 714 | return; |
SunnySrivastava1984 | ee135e2 | 2020-12-15 12:42:19 -0600 | [diff] [blame] | 715 | } |
| 716 | aResp->res.jsonValue["Model"] = *value; |
| 717 | } |
| 718 | else if (property.first == "LocationCode") |
| 719 | { |
| 720 | const std::string* value = |
| 721 | std::get_if<std::string>(&property.second); |
| 722 | if (value == nullptr) |
| 723 | { |
| 724 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 725 | return; |
SunnySrivastava1984 | ee135e2 | 2020-12-15 12:42:19 -0600 | [diff] [blame] | 726 | } |
| 727 | aResp->res |
| 728 | .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = |
| 729 | *value; |
| 730 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 731 | else |
| 732 | { |
| 733 | getPersistentMemoryProperties(aResp, properties); |
| 734 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 735 | } |
| 736 | }, |
| 737 | service, objPath, "org.freedesktop.DBus.Properties", "GetAll", ""); |
| 738 | } |
| 739 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 740 | inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> aResp, |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 741 | const std::string& service, |
| 742 | const std::string& path) |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 743 | { |
| 744 | crow::connections::systemBus->async_method_call( |
| 745 | [aResp{std::move(aResp)}]( |
| 746 | const boost::system::error_code ec, |
| 747 | const boost::container::flat_map< |
| 748 | std::string, std::variant<std::string, uint64_t, uint32_t, |
| 749 | bool>>& properties) { |
| 750 | if (ec) |
| 751 | { |
| 752 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 753 | messages::internalError(aResp->res); |
| 754 | |
| 755 | return; |
| 756 | } |
| 757 | |
| 758 | nlohmann::json& partition = |
| 759 | aResp->res.jsonValue["Regions"].emplace_back( |
| 760 | nlohmann::json::object()); |
| 761 | for (const auto& [key, val] : properties) |
| 762 | { |
| 763 | if (key == "MemoryClassification") |
| 764 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 765 | const std::string* value = std::get_if<std::string>(&val); |
| 766 | if (value == nullptr) |
| 767 | { |
| 768 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 769 | return; |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 770 | } |
| 771 | partition[key] = *value; |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 772 | } |
| 773 | else if (key == "OffsetInKiB") |
| 774 | { |
| 775 | const uint64_t* value = std::get_if<uint64_t>(&val); |
| 776 | if (value == nullptr) |
| 777 | { |
| 778 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 779 | return; |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | partition["OffsetMiB"] = (*value >> 10); |
| 783 | } |
| 784 | else if (key == "PartitionId") |
| 785 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 786 | const std::string* value = std::get_if<std::string>(&val); |
| 787 | if (value == nullptr) |
| 788 | { |
| 789 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 790 | return; |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 791 | } |
| 792 | partition["RegionId"] = *value; |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | else if (key == "PassphraseState") |
| 796 | { |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 797 | const bool* value = std::get_if<bool>(&val); |
| 798 | if (value == nullptr) |
| 799 | { |
| 800 | messages::internalError(aResp->res); |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 801 | return; |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 802 | } |
| 803 | partition["PassphraseEnabled"] = *value; |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 804 | } |
| 805 | else if (key == "SizeInKiB") |
| 806 | { |
| 807 | const uint64_t* value = std::get_if<uint64_t>(&val); |
| 808 | if (value == nullptr) |
| 809 | { |
| 810 | messages::internalError(aResp->res); |
| 811 | BMCWEB_LOG_DEBUG |
| 812 | << "Invalid property type for SizeInKiB"; |
Chicago Duan | 601af5e | 2021-04-15 16:59:25 +0800 | [diff] [blame] | 813 | return; |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 814 | } |
| 815 | partition["SizeMiB"] = (*value >> 10); |
| 816 | } |
| 817 | } |
| 818 | }, |
| 819 | |
| 820 | service, path, "org.freedesktop.DBus.Properties", "GetAll", |
| 821 | "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition"); |
| 822 | } |
| 823 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 824 | inline void getDimmData(std::shared_ptr<bmcweb::AsyncResp> aResp, |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 825 | const std::string& dimmId) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 826 | { |
| 827 | BMCWEB_LOG_DEBUG << "Get available system dimm resources."; |
| 828 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 829 | [dimmId, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 830 | const boost::system::error_code ec, |
| 831 | const boost::container::flat_map< |
| 832 | std::string, boost::container::flat_map< |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 833 | std::string, std::vector<std::string>>>& |
| 834 | subtree) { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 835 | if (ec) |
| 836 | { |
| 837 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 838 | messages::internalError(aResp->res); |
| 839 | |
| 840 | return; |
| 841 | } |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 842 | bool found = false; |
| 843 | for (const auto& [path, object] : subtree) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 844 | { |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 845 | if (path.find(dimmId) != std::string::npos) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 846 | { |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 847 | for (const auto& [service, interfaces] : object) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 848 | { |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 849 | if (!found && |
| 850 | (std::find( |
| 851 | interfaces.begin(), interfaces.end(), |
| 852 | "xyz.openbmc_project.Inventory.Item.Dimm") != |
| 853 | interfaces.end())) |
| 854 | { |
| 855 | getDimmDataByService(aResp, dimmId, service, path); |
| 856 | found = true; |
| 857 | } |
| 858 | |
| 859 | // partitions are separate as there can be multiple per |
| 860 | // device, i.e. |
| 861 | // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition1 |
| 862 | // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition2 |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 863 | if (std::find( |
| 864 | interfaces.begin(), interfaces.end(), |
| 865 | "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition") != |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 866 | interfaces.end()) |
| 867 | { |
| 868 | getDimmPartitionData(aResp, service, path); |
| 869 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | } |
| 873 | // Object not found |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 874 | if (!found) |
| 875 | { |
| 876 | messages::resourceNotFound(aResp->res, "Memory", dimmId); |
| 877 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 878 | return; |
| 879 | }, |
| 880 | "xyz.openbmc_project.ObjectMapper", |
| 881 | "/xyz/openbmc_project/object_mapper", |
| 882 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 883 | "/xyz/openbmc_project/inventory", 0, |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 884 | std::array<const char*, 2>{ |
| 885 | "xyz.openbmc_project.Inventory.Item.Dimm", |
| 886 | "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition"}); |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 887 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 888 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 889 | inline void requestRoutesMemoryCollection(App& app) |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 890 | { |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 891 | /** |
| 892 | * Functions triggers appropriate requests on DBus |
| 893 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 894 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Memory/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 895 | .privileges(redfish::privileges::getMemoryCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 896 | .methods(boost::beast::http::verb::get)( |
| 897 | [](const crow::Request&, |
| 898 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
| 899 | asyncResp->res.jsonValue["@odata.type"] = |
| 900 | "#MemoryCollection.MemoryCollection"; |
| 901 | asyncResp->res.jsonValue["Name"] = "Memory Module Collection"; |
| 902 | asyncResp->res.jsonValue["@odata.id"] = |
| 903 | "/redfish/v1/Systems/system/Memory"; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 904 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 905 | collection_util::getCollectionMembers( |
| 906 | asyncResp, "/redfish/v1/Systems/system/Memory", |
| 907 | {"xyz.openbmc_project.Inventory.Item.Dimm"}); |
| 908 | }); |
| 909 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 910 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 911 | inline void requestRoutesMemory(App& app) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 912 | { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 913 | /** |
| 914 | * Functions triggers appropriate requests on DBus |
| 915 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 916 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Memory/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 917 | .privileges(redfish::privileges::getMemory) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 918 | .methods(boost::beast::http::verb::get)( |
| 919 | [](const crow::Request&, |
| 920 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 921 | const std::string& dimmId) { |
| 922 | asyncResp->res.jsonValue["@odata.type"] = |
| 923 | "#Memory.v1_11_0.Memory"; |
| 924 | asyncResp->res.jsonValue["@odata.id"] = |
| 925 | "/redfish/v1/Systems/system/Memory/" + dimmId; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 926 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 927 | getDimmData(asyncResp, dimmId); |
| 928 | }); |
| 929 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 930 | |
| 931 | } // namespace redfish |