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