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