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 | |
Willy Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame^] | 18 | #include "bmcweb_config.h" |
| 19 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 20 | #include "app.hpp" |
| 21 | #include "dbus_utility.hpp" |
James Feist | 35e257a | 2020-06-05 13:30:51 -0700 | [diff] [blame] | 22 | #include "health.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 23 | #include "query.hpp" |
| 24 | #include "registries/privilege_registry.hpp" |
| 25 | #include "utils/collection.hpp" |
| 26 | #include "utils/dbus_utils.hpp" |
| 27 | #include "utils/hex_utils.hpp" |
| 28 | #include "utils/json_utils.hpp" |
James Feist | 35e257a | 2020-06-05 13:30:51 -0700 | [diff] [blame] | 29 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 30 | #include <boost/system/error_code.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 31 | #include <boost/url/format.hpp> |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 32 | #include <nlohmann/json.hpp> |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 33 | #include <sdbusplus/asio/property.hpp> |
| 34 | #include <sdbusplus/unpack_properties.hpp> |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 35 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 36 | #include <array> |
| 37 | #include <string_view> |
| 38 | |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 39 | namespace redfish |
| 40 | { |
| 41 | |
Gunnar Mills | 313efb1 | 2020-10-26 16:05:08 -0500 | [diff] [blame] | 42 | inline std::string translateMemoryTypeToRedfish(const std::string& memoryType) |
| 43 | { |
| 44 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR") |
| 45 | { |
| 46 | return "DDR"; |
| 47 | } |
| 48 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2") |
| 49 | { |
| 50 | return "DDR2"; |
| 51 | } |
| 52 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR3") |
| 53 | { |
| 54 | return "DDR3"; |
| 55 | } |
| 56 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4") |
| 57 | { |
| 58 | return "DDR4"; |
| 59 | } |
| 60 | if (memoryType == |
| 61 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4E_SDRAM") |
| 62 | { |
| 63 | return "DDR4E_SDRAM"; |
| 64 | } |
Mansi Joshi | 11a2f0f | 2021-07-19 14:33:27 +0530 | [diff] [blame] | 65 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR5") |
| 66 | { |
| 67 | return "DDR5"; |
| 68 | } |
Gunnar Mills | 313efb1 | 2020-10-26 16:05:08 -0500 | [diff] [blame] | 69 | if (memoryType == |
| 70 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR4_SDRAM") |
| 71 | { |
| 72 | return "LPDDR4_SDRAM"; |
| 73 | } |
| 74 | if (memoryType == |
| 75 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR3_SDRAM") |
| 76 | { |
| 77 | return "LPDDR3_SDRAM"; |
| 78 | } |
| 79 | if (memoryType == |
| 80 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM") |
| 81 | { |
| 82 | return "DDR2_SDRAM_FB_DIMM"; |
| 83 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 84 | if (memoryType == |
| 85 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM_PROB") |
Gunnar Mills | 313efb1 | 2020-10-26 16:05:08 -0500 | [diff] [blame] | 86 | { |
| 87 | return "DDR2_SDRAM_FB_DIMM_PROBE"; |
| 88 | } |
| 89 | if (memoryType == |
| 90 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR_SGRAM") |
| 91 | { |
| 92 | return "DDR_SGRAM"; |
| 93 | } |
| 94 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.ROM") |
| 95 | { |
| 96 | return "ROM"; |
| 97 | } |
| 98 | if (memoryType == |
| 99 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.SDRAM") |
| 100 | { |
| 101 | return "SDRAM"; |
| 102 | } |
| 103 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.EDO") |
| 104 | { |
| 105 | return "EDO"; |
| 106 | } |
| 107 | if (memoryType == |
| 108 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.FastPageMode") |
| 109 | { |
| 110 | return "FastPageMode"; |
| 111 | } |
| 112 | if (memoryType == |
| 113 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.PipelinedNibble") |
| 114 | { |
| 115 | return "PipelinedNibble"; |
| 116 | } |
| 117 | if (memoryType == |
| 118 | "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.Logical") |
| 119 | { |
| 120 | return "Logical"; |
| 121 | } |
| 122 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM") |
| 123 | { |
| 124 | return "HBM"; |
| 125 | } |
| 126 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM2") |
| 127 | { |
| 128 | return "HBM2"; |
| 129 | } |
Tyson Tuckerbear | ce34d51 | 2022-09-13 16:26:15 -0700 | [diff] [blame] | 130 | if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM3") |
| 131 | { |
| 132 | return "HBM3"; |
| 133 | } |
Gunnar Mills | 313efb1 | 2020-10-26 16:05:08 -0500 | [diff] [blame] | 134 | // This is values like Other or Unknown |
| 135 | // Also D-Bus values: |
| 136 | // DRAM |
| 137 | // EDRAM |
| 138 | // VRAM |
| 139 | // SRAM |
| 140 | // RAM |
| 141 | // FLASH |
| 142 | // EEPROM |
| 143 | // FEPROM |
| 144 | // EPROM |
| 145 | // CDRAM |
| 146 | // ThreeDRAM |
| 147 | // RDRAM |
| 148 | // FBD2 |
| 149 | // LPDDR_SDRAM |
| 150 | // LPDDR2_SDRAM |
Mansi Joshi | 11a2f0f | 2021-07-19 14:33:27 +0530 | [diff] [blame] | 151 | // LPDDR5_SDRAM |
Gunnar Mills | 313efb1 | 2020-10-26 16:05:08 -0500 | [diff] [blame] | 152 | return ""; |
| 153 | } |
| 154 | |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 155 | inline void dimmPropToHex(const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
| 156 | const char* key, const uint16_t* value, |
| 157 | const nlohmann::json::json_pointer& jsonPtr) |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 158 | { |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 159 | if (value == nullptr) |
| 160 | { |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 161 | return; |
| 162 | } |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 163 | aResp->res.jsonValue[jsonPtr][key] = "0x" + intToHexString(*value, 4); |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 164 | } |
| 165 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 166 | inline void getPersistentMemoryProperties( |
| 167 | const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 168 | const dbus::utility::DBusPropertiesMap& properties, |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 169 | const nlohmann::json::json_pointer& jsonPtr) |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 170 | { |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 171 | const uint16_t* moduleManufacturerID = nullptr; |
| 172 | const uint16_t* moduleProductID = nullptr; |
| 173 | const uint16_t* subsystemVendorID = nullptr; |
| 174 | const uint16_t* subsystemDeviceID = nullptr; |
| 175 | const uint64_t* volatileRegionSizeLimitInKiB = nullptr; |
| 176 | const uint64_t* pmRegionSizeLimitInKiB = nullptr; |
| 177 | const uint64_t* volatileSizeInKiB = nullptr; |
| 178 | const uint64_t* pmSizeInKiB = nullptr; |
| 179 | const uint64_t* cacheSizeInKB = nullptr; |
| 180 | const uint64_t* voltaileRegionMaxSizeInKib = nullptr; |
| 181 | const uint64_t* pmRegionMaxSizeInKiB = nullptr; |
| 182 | const uint64_t* allocationIncrementInKiB = nullptr; |
| 183 | const uint64_t* allocationAlignmentInKiB = nullptr; |
| 184 | const uint64_t* volatileRegionNumberLimit = nullptr; |
| 185 | const uint64_t* pmRegionNumberLimit = nullptr; |
| 186 | const uint64_t* spareDeviceCount = nullptr; |
| 187 | const bool* isSpareDeviceInUse = nullptr; |
| 188 | const bool* isRankSpareEnabled = nullptr; |
| 189 | const std::vector<uint32_t>* maxAveragePowerLimitmW = nullptr; |
| 190 | const bool* configurationLocked = nullptr; |
| 191 | const std::string* allowedMemoryModes = nullptr; |
| 192 | const std::string* memoryMedia = nullptr; |
| 193 | const bool* configurationLockCapable = nullptr; |
| 194 | const bool* dataLockCapable = nullptr; |
| 195 | const bool* passphraseCapable = nullptr; |
| 196 | const uint64_t* maxPassphraseCount = nullptr; |
| 197 | const uint64_t* passphraseLockLimit = nullptr; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 198 | |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 199 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 200 | dbus_utils::UnpackErrorPrinter(), properties, "ModuleManufacturerID", |
| 201 | moduleManufacturerID, "ModuleProductID", moduleProductID, |
| 202 | "SubsystemVendorID", subsystemVendorID, "SubsystemDeviceID", |
| 203 | subsystemDeviceID, "VolatileRegionSizeLimitInKiB", |
| 204 | volatileRegionSizeLimitInKiB, "PmRegionSizeLimitInKiB", |
| 205 | pmRegionSizeLimitInKiB, "VolatileSizeInKiB", volatileSizeInKiB, |
| 206 | "PmSizeInKiB", pmSizeInKiB, "CacheSizeInKB", cacheSizeInKB, |
| 207 | "VoltaileRegionMaxSizeInKib", voltaileRegionMaxSizeInKib, |
| 208 | "PmRegionMaxSizeInKiB", pmRegionMaxSizeInKiB, |
| 209 | "AllocationIncrementInKiB", allocationIncrementInKiB, |
| 210 | "AllocationAlignmentInKiB", allocationAlignmentInKiB, |
| 211 | "VolatileRegionNumberLimit", volatileRegionNumberLimit, |
| 212 | "PmRegionNumberLimit", pmRegionNumberLimit, "SpareDeviceCount", |
| 213 | spareDeviceCount, "IsSpareDeviceInUse", isSpareDeviceInUse, |
| 214 | "IsRankSpareEnabled", isRankSpareEnabled, "MaxAveragePowerLimitmW", |
| 215 | maxAveragePowerLimitmW, "ConfigurationLocked", configurationLocked, |
| 216 | "AllowedMemoryModes", allowedMemoryModes, "MemoryMedia", memoryMedia, |
| 217 | "ConfigurationLockCapable", configurationLockCapable, "DataLockCapable", |
| 218 | dataLockCapable, "PassphraseCapable", passphraseCapable, |
| 219 | "MaxPassphraseCount", maxPassphraseCount, "PassphraseLockLimit", |
| 220 | passphraseLockLimit); |
| 221 | |
| 222 | if (!success) |
| 223 | { |
| 224 | messages::internalError(aResp->res); |
| 225 | return; |
| 226 | } |
| 227 | |
| 228 | dimmPropToHex(aResp, "ModuleManufacturerID", moduleManufacturerID, jsonPtr); |
| 229 | dimmPropToHex(aResp, "ModuleProductID", moduleProductID, jsonPtr); |
| 230 | dimmPropToHex(aResp, "MemorySubsystemControllerManufacturerID", |
| 231 | subsystemVendorID, jsonPtr); |
| 232 | dimmPropToHex(aResp, "MemorySubsystemControllerProductID", |
| 233 | subsystemDeviceID, jsonPtr); |
| 234 | |
| 235 | if (volatileRegionSizeLimitInKiB != nullptr) |
| 236 | { |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 237 | aResp->res.jsonValue[jsonPtr]["VolatileRegionSizeLimitMiB"] = |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 238 | (*volatileRegionSizeLimitInKiB) >> 10; |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 239 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 240 | |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 241 | if (pmRegionSizeLimitInKiB != nullptr) |
| 242 | { |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 243 | aResp->res.jsonValue[jsonPtr]["PersistentRegionSizeLimitMiB"] = |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 244 | (*pmRegionSizeLimitInKiB) >> 10; |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 245 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 246 | |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 247 | if (volatileSizeInKiB != nullptr) |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 248 | { |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 249 | aResp->res.jsonValue[jsonPtr]["VolatileSizeMiB"] = |
| 250 | (*volatileSizeInKiB) >> 10; |
| 251 | } |
| 252 | |
| 253 | if (pmSizeInKiB != nullptr) |
| 254 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 255 | aResp->res.jsonValue[jsonPtr]["NonVolatileSizeMiB"] = (*pmSizeInKiB) >> |
| 256 | 10; |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | if (cacheSizeInKB != nullptr) |
| 260 | { |
| 261 | aResp->res.jsonValue[jsonPtr]["CacheSizeMiB"] = (*cacheSizeInKB >> 10); |
| 262 | } |
| 263 | |
| 264 | if (voltaileRegionMaxSizeInKib != nullptr) |
| 265 | { |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 266 | aResp->res.jsonValue[jsonPtr]["VolatileRegionSizeMaxMiB"] = |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 267 | (*voltaileRegionMaxSizeInKib) >> 10; |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 268 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 269 | |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 270 | if (pmRegionMaxSizeInKiB != nullptr) |
| 271 | { |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 272 | aResp->res.jsonValue[jsonPtr]["PersistentRegionSizeMaxMiB"] = |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 273 | (*pmRegionMaxSizeInKiB) >> 10; |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 274 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 275 | |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 276 | if (allocationIncrementInKiB != nullptr) |
| 277 | { |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 278 | aResp->res.jsonValue[jsonPtr]["AllocationIncrementMiB"] = |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 279 | (*allocationIncrementInKiB) >> 10; |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 280 | } |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 281 | |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 282 | if (allocationAlignmentInKiB != nullptr) |
| 283 | { |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 284 | aResp->res.jsonValue[jsonPtr]["AllocationAlignmentMiB"] = |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 285 | (*allocationAlignmentInKiB) >> 10; |
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 | |
| 288 | if (volatileRegionNumberLimit != nullptr) |
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 | aResp->res.jsonValue[jsonPtr]["VolatileRegionNumberLimit"] = |
| 291 | *volatileRegionNumberLimit; |
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 | |
| 294 | if (pmRegionNumberLimit != nullptr) |
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 | aResp->res.jsonValue[jsonPtr]["PersistentRegionNumberLimit"] = |
| 297 | *pmRegionNumberLimit; |
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 | |
| 300 | if (spareDeviceCount != nullptr) |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 301 | { |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 302 | aResp->res.jsonValue[jsonPtr]["SpareDeviceCount"] = *spareDeviceCount; |
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 | |
| 305 | if (isSpareDeviceInUse != nullptr) |
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 | aResp->res.jsonValue[jsonPtr]["IsSpareDeviceEnabled"] = |
| 308 | *isSpareDeviceInUse; |
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 | |
| 311 | if (isRankSpareEnabled != nullptr) |
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 | aResp->res.jsonValue[jsonPtr]["IsRankSpareEnabled"] = |
| 314 | *isRankSpareEnabled; |
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 | |
| 317 | if (maxAveragePowerLimitmW != nullptr) |
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 | aResp->res.jsonValue[jsonPtr]["MaxTDPMilliWatts"] = |
| 320 | *maxAveragePowerLimitmW; |
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 | |
| 323 | if (configurationLocked != nullptr) |
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 | aResp->res.jsonValue[jsonPtr]["ConfigurationLocked"] = |
| 326 | *configurationLocked; |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 327 | } |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 328 | |
| 329 | if (allowedMemoryModes != nullptr) |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 330 | { |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 331 | constexpr const std::array<const char*, 3> values{"Volatile", "PMEM", |
| 332 | "Block"}; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 333 | |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 334 | for (const char* v : values) |
| 335 | { |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 336 | if (allowedMemoryModes->ends_with(v)) |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 337 | { |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 338 | aResp->res.jsonValue[jsonPtr]["OperatingMemoryModes"].push_back( |
| 339 | v); |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 340 | break; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 341 | } |
| 342 | } |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 343 | } |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 344 | |
| 345 | if (memoryMedia != nullptr) |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 346 | { |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 347 | constexpr const std::array<const char*, 3> values{"DRAM", "NAND", |
| 348 | "Intel3DXPoint"}; |
James Feist | c50e7c6 | 2020-07-27 15:39:36 -0700 | [diff] [blame] | 349 | |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 350 | for (const char* v : values) |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 351 | { |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 352 | if (memoryMedia->ends_with(v)) |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 353 | { |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 354 | aResp->res.jsonValue[jsonPtr]["MemoryMedia"].push_back(v); |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 355 | break; |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 356 | } |
Ed Tanous | 5fb91ba | 2020-09-28 15:41:28 -0700 | [diff] [blame] | 357 | } |
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 | |
| 360 | if (configurationLockCapable != nullptr) |
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 | aResp->res.jsonValue[jsonPtr]["SecurityCapabilities"] |
| 363 | ["ConfigurationLockCapable"] = |
| 364 | *configurationLockCapable; |
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 | |
| 367 | if (dataLockCapable != nullptr) |
Jiaqing Zhao | 80badf7 | 2022-03-18 17:48:53 +0800 | [diff] [blame] | 368 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 369 | aResp->res.jsonValue[jsonPtr]["SecurityCapabilities"] |
| 370 | ["DataLockCapable"] = *dataLockCapable; |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | if (passphraseCapable != nullptr) |
| 374 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 375 | aResp->res.jsonValue[jsonPtr]["SecurityCapabilities"] |
| 376 | ["PassphraseCapable"] = *passphraseCapable; |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | if (maxPassphraseCount != nullptr) |
| 380 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 381 | aResp->res.jsonValue[jsonPtr]["SecurityCapabilities"] |
| 382 | ["MaxPassphraseCount"] = *maxPassphraseCount; |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | if (passphraseLockLimit != nullptr) |
| 386 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 387 | aResp->res.jsonValue[jsonPtr]["SecurityCapabilities"] |
| 388 | ["PassphraseLockLimit"] = *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 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 594 | aResp->res.jsonValue[jsonPtr]["Location"]["PartLocation"] |
| 595 | ["ServiceLabel"] = *locationCode; |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | getPersistentMemoryProperties(aResp, properties, jsonPtr); |
Nan Zhou | 9a5acea | 2022-05-17 21:12:43 +0000 | [diff] [blame] | 599 | } |
| 600 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 601 | inline void getDimmDataByService(std::shared_ptr<bmcweb::AsyncResp> aResp, |
Ed Tanous | 80789c8 | 2020-08-19 09:19:09 -0700 | [diff] [blame] | 602 | const std::string& dimmId, |
| 603 | const std::string& service, |
| 604 | const std::string& objPath) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 605 | { |
Willy Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame^] | 606 | if constexpr (bmcwebEnableHealthPopulate) |
| 607 | { |
| 608 | auto health = std::make_shared<HealthPopulate>(aResp); |
| 609 | health->selfPath = objPath; |
| 610 | health->populate(); |
| 611 | } |
James Feist | 35e257a | 2020-06-05 13:30:51 -0700 | [diff] [blame] | 612 | |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 613 | BMCWEB_LOG_DEBUG << "Get available system components."; |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 614 | sdbusplus::asio::getAllProperties( |
| 615 | *crow::connections::systemBus, service, objPath, "", |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 616 | [dimmId, aResp{std::move(aResp)}]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 617 | const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 618 | const dbus::utility::DBusPropertiesMap& properties) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 619 | if (ec) |
| 620 | { |
| 621 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 622 | messages::internalError(aResp->res); |
| 623 | return; |
| 624 | } |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 625 | assembleDimmProperties(dimmId, aResp, properties, ""_json_pointer); |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 626 | }); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 627 | } |
| 628 | |
Nan Zhou | ef00d7d | 2022-05-20 21:22:32 +0000 | [diff] [blame] | 629 | inline void assembleDimmPartitionData( |
| 630 | const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 631 | const dbus::utility::DBusPropertiesMap& properties, |
| 632 | const nlohmann::json::json_pointer& regionPtr) |
Nan Zhou | ef00d7d | 2022-05-20 21:22:32 +0000 | [diff] [blame] | 633 | { |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 634 | const std::string* memoryClassification = nullptr; |
| 635 | const uint64_t* offsetInKiB = nullptr; |
| 636 | const std::string* partitionId = nullptr; |
| 637 | const bool* passphraseState = nullptr; |
| 638 | const uint64_t* sizeInKiB = nullptr; |
| 639 | |
| 640 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 641 | dbus_utils::UnpackErrorPrinter(), properties, "MemoryClassification", |
| 642 | memoryClassification, "OffsetInKiB", offsetInKiB, "PartitionId", |
| 643 | partitionId, "PassphraseState", passphraseState, "SizeInKiB", |
| 644 | sizeInKiB); |
| 645 | |
| 646 | if (!success) |
Nan Zhou | ef00d7d | 2022-05-20 21:22:32 +0000 | [diff] [blame] | 647 | { |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 648 | messages::internalError(aResp->res); |
| 649 | return; |
Nan Zhou | ef00d7d | 2022-05-20 21:22:32 +0000 | [diff] [blame] | 650 | } |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 651 | |
| 652 | nlohmann::json::object_t partition; |
| 653 | |
| 654 | if (memoryClassification != nullptr) |
| 655 | { |
| 656 | partition["MemoryClassification"] = *memoryClassification; |
| 657 | } |
| 658 | |
| 659 | if (offsetInKiB != nullptr) |
| 660 | { |
| 661 | partition["OffsetMiB"] = (*offsetInKiB >> 10); |
| 662 | } |
| 663 | |
| 664 | if (partitionId != nullptr) |
| 665 | { |
| 666 | partition["RegionId"] = *partitionId; |
| 667 | } |
| 668 | |
| 669 | if (passphraseState != nullptr) |
| 670 | { |
| 671 | partition["PassphraseEnabled"] = *passphraseState; |
| 672 | } |
| 673 | |
| 674 | if (sizeInKiB != nullptr) |
| 675 | { |
| 676 | partition["SizeMiB"] = (*sizeInKiB >> 10); |
| 677 | } |
| 678 | |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 679 | aResp->res.jsonValue[regionPtr].emplace_back(std::move(partition)); |
Nan Zhou | ef00d7d | 2022-05-20 21:22:32 +0000 | [diff] [blame] | 680 | } |
| 681 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 682 | inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> aResp, |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 683 | const std::string& service, |
| 684 | const std::string& path) |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 685 | { |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 686 | sdbusplus::asio::getAllProperties( |
| 687 | *crow::connections::systemBus, service, path, |
| 688 | "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition", |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 689 | [aResp{std::move(aResp)}]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 690 | const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 691 | const dbus::utility::DBusPropertiesMap& properties) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 692 | if (ec) |
| 693 | { |
| 694 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 695 | messages::internalError(aResp->res); |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 696 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 697 | return; |
| 698 | } |
Nan Zhou | d7f04fd | 2022-05-01 01:11:07 +0000 | [diff] [blame] | 699 | nlohmann::json::json_pointer regionPtr = "/Regions"_json_pointer; |
| 700 | assembleDimmPartitionData(aResp, properties, regionPtr); |
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 | |
Krzysztof Grobelny | c1343bf | 2022-08-31 13:15:26 +0200 | [diff] [blame] | 703 | ); |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 704 | } |
| 705 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 706 | inline void getDimmData(std::shared_ptr<bmcweb::AsyncResp> aResp, |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 707 | const std::string& dimmId) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 708 | { |
| 709 | BMCWEB_LOG_DEBUG << "Get available system dimm resources."; |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 710 | constexpr std::array<std::string_view, 2> dimmInterfaces = { |
| 711 | "xyz.openbmc_project.Inventory.Item.Dimm", |
| 712 | "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition"}; |
| 713 | dbus::utility::getSubTree( |
| 714 | "/xyz/openbmc_project/inventory", 0, dimmInterfaces, |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 715 | [dimmId, aResp{std::move(aResp)}]( |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 716 | const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 717 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 718 | if (ec) |
| 719 | { |
| 720 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 721 | messages::internalError(aResp->res); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 722 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 723 | return; |
| 724 | } |
| 725 | bool found = false; |
Nan Zhou | 76686dc | 2022-06-17 23:01:51 +0000 | [diff] [blame] | 726 | for (const auto& [rawPath, object] : subtree) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 727 | { |
Nan Zhou | 76686dc | 2022-06-17 23:01:51 +0000 | [diff] [blame] | 728 | sdbusplus::message::object_path path(rawPath); |
| 729 | for (const auto& [service, interfaces] : object) |
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 | for (const auto& interface : interfaces) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 732 | { |
Nan Zhou | 76686dc | 2022-06-17 23:01:51 +0000 | [diff] [blame] | 733 | if (interface == |
| 734 | "xyz.openbmc_project.Inventory.Item.Dimm" && |
| 735 | path.filename() == dimmId) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 736 | { |
Nan Zhou | 76686dc | 2022-06-17 23:01:51 +0000 | [diff] [blame] | 737 | getDimmDataByService(aResp, dimmId, service, rawPath); |
| 738 | found = true; |
| 739 | } |
James Feist | 45094ad | 2020-04-29 14:02:30 -0700 | [diff] [blame] | 740 | |
Nan Zhou | 76686dc | 2022-06-17 23:01:51 +0000 | [diff] [blame] | 741 | // partitions are separate as there can be multiple |
| 742 | // per |
| 743 | // device, i.e. |
| 744 | // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition1 |
| 745 | // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition2 |
| 746 | if (interface == |
| 747 | "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition" && |
| 748 | path.parent_path().filename() == dimmId) |
| 749 | { |
| 750 | getDimmPartitionData(aResp, service, rawPath); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 754 | } |
| 755 | // Object not found |
| 756 | if (!found) |
| 757 | { |
| 758 | messages::resourceNotFound(aResp->res, "Memory", dimmId); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 759 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 760 | } |
| 761 | // Set @odata only if object is found |
| 762 | aResp->res.jsonValue["@odata.type"] = "#Memory.v1_11_0.Memory"; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 763 | aResp->res.jsonValue["@odata.id"] = |
| 764 | boost::urls::format("/redfish/v1/Systems/system/Memory/{}", dimmId); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 765 | return; |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 766 | }); |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 767 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 768 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 769 | inline void requestRoutesMemoryCollection(App& app) |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 770 | { |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 771 | /** |
| 772 | * Functions triggers appropriate requests on DBus |
| 773 | */ |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 774 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 775 | .privileges(redfish::privileges::getMemoryCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 776 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 777 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 778 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 779 | const std::string& systemName) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 780 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 781 | { |
| 782 | return; |
| 783 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 784 | if (systemName != "system") |
| 785 | { |
| 786 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 787 | systemName); |
| 788 | return; |
| 789 | } |
| 790 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 791 | asyncResp->res.jsonValue["@odata.type"] = |
| 792 | "#MemoryCollection.MemoryCollection"; |
| 793 | asyncResp->res.jsonValue["Name"] = "Memory Module Collection"; |
| 794 | asyncResp->res.jsonValue["@odata.id"] = |
| 795 | "/redfish/v1/Systems/system/Memory"; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 796 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 797 | constexpr std::array<std::string_view, 1> interfaces{ |
| 798 | "xyz.openbmc_project.Inventory.Item.Dimm"}; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 799 | collection_util::getCollectionMembers( |
Willy Tu | ae9031f | 2022-09-27 05:48:07 +0000 | [diff] [blame] | 800 | asyncResp, boost::urls::url("/redfish/v1/Systems/system/Memory"), |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 801 | interfaces); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 802 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 803 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 804 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 805 | inline void requestRoutesMemory(App& app) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 806 | { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 807 | /** |
| 808 | * Functions triggers appropriate requests on DBus |
| 809 | */ |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 810 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 811 | .privileges(redfish::privileges::getMemory) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 812 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 813 | [&app](const crow::Request& req, |
| 814 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 815 | const std::string& systemName, const std::string& dimmId) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 816 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 817 | { |
| 818 | return; |
| 819 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 820 | if (systemName != "system") |
| 821 | { |
| 822 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 823 | systemName); |
| 824 | return; |
| 825 | } |
| 826 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 827 | getDimmData(asyncResp, dimmId); |
| 828 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 829 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 830 | |
| 831 | } // namespace redfish |