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