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