blob: 5ea0f4ef8404b99f3129044ecb4f850b18f6a5d5 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
3// SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +02004#pragma once
5
Willy Tu13451e32023-05-24 16:08:18 -07006#include "bmcweb_config.h"
7
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08008#include "app.hpp"
9#include "dbus_utility.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070010#include "generated/enums/memory.hpp"
11#include "generated/enums/resource.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080012#include "query.hpp"
13#include "registries/privilege_registry.hpp"
14#include "utils/collection.hpp"
15#include "utils/dbus_utils.hpp"
16#include "utils/hex_utils.hpp"
17#include "utils/json_utils.hpp"
James Feist35e257a2020-06-05 13:30:51 -070018
George Liue99073f2022-12-09 11:06:16 +080019#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070020#include <boost/url/format.hpp>
Nan Zhoud7f04fd2022-05-01 01:11:07 +000021#include <nlohmann/json.hpp>
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +020022#include <sdbusplus/asio/property.hpp>
23#include <sdbusplus/unpack_properties.hpp>
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020024
George Liu7a1dbc42022-12-07 16:03:22 +080025#include <array>
26#include <string_view>
27
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020028namespace redfish
29{
30
Gunnar Mills313efb12020-10-26 16:05:08 -050031inline std::string translateMemoryTypeToRedfish(const std::string& memoryType)
32{
33 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR")
34 {
35 return "DDR";
36 }
37 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2")
38 {
39 return "DDR2";
40 }
41 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR3")
42 {
43 return "DDR3";
44 }
45 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4")
46 {
47 return "DDR4";
48 }
49 if (memoryType ==
50 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4E_SDRAM")
51 {
52 return "DDR4E_SDRAM";
53 }
Mansi Joshi11a2f0f2021-07-19 14:33:27 +053054 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR5")
55 {
56 return "DDR5";
57 }
Gunnar Mills313efb12020-10-26 16:05:08 -050058 if (memoryType ==
59 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR4_SDRAM")
60 {
61 return "LPDDR4_SDRAM";
62 }
63 if (memoryType ==
64 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR3_SDRAM")
65 {
66 return "LPDDR3_SDRAM";
67 }
68 if (memoryType ==
69 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM")
70 {
71 return "DDR2_SDRAM_FB_DIMM";
72 }
George Liu0fda0f12021-11-16 10:06:17 +080073 if (memoryType ==
74 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM_PROB")
Gunnar Mills313efb12020-10-26 16:05:08 -050075 {
76 return "DDR2_SDRAM_FB_DIMM_PROBE";
77 }
78 if (memoryType ==
79 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR_SGRAM")
80 {
81 return "DDR_SGRAM";
82 }
83 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.ROM")
84 {
85 return "ROM";
86 }
87 if (memoryType ==
88 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.SDRAM")
89 {
90 return "SDRAM";
91 }
92 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.EDO")
93 {
94 return "EDO";
95 }
96 if (memoryType ==
97 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.FastPageMode")
98 {
99 return "FastPageMode";
100 }
101 if (memoryType ==
102 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.PipelinedNibble")
103 {
104 return "PipelinedNibble";
105 }
106 if (memoryType ==
107 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.Logical")
108 {
109 return "Logical";
110 }
111 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM")
112 {
113 return "HBM";
114 }
115 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM2")
116 {
117 return "HBM2";
118 }
Tyson Tuckerbearce34d512022-09-13 16:26:15 -0700119 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM3")
120 {
121 return "HBM3";
122 }
Gunnar Mills313efb12020-10-26 16:05:08 -0500123 // This is values like Other or Unknown
124 // Also D-Bus values:
125 // DRAM
126 // EDRAM
127 // VRAM
128 // SRAM
129 // RAM
130 // FLASH
131 // EEPROM
132 // FEPROM
133 // EPROM
134 // CDRAM
135 // ThreeDRAM
136 // RDRAM
137 // FBD2
138 // LPDDR_SDRAM
139 // LPDDR2_SDRAM
Mansi Joshi11a2f0f2021-07-19 14:33:27 +0530140 // LPDDR5_SDRAM
Gunnar Mills313efb12020-10-26 16:05:08 -0500141 return "";
142}
143
Ed Tanousac106bf2023-06-07 09:24:59 -0700144inline void dimmPropToHex(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200145 const char* key, const uint16_t* value,
146 const nlohmann::json::json_pointer& jsonPtr)
James Feistc50e7c62020-07-27 15:39:36 -0700147{
James Feistc50e7c62020-07-27 15:39:36 -0700148 if (value == nullptr)
149 {
James Feistc50e7c62020-07-27 15:39:36 -0700150 return;
151 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700152 asyncResp->res.jsonValue[jsonPtr][key] = "0x" + intToHexString(*value, 4);
James Feistc50e7c62020-07-27 15:39:36 -0700153}
154
zhanghch058d1b46d2021-04-01 11:18:24 +0800155inline void getPersistentMemoryProperties(
Ed Tanousac106bf2023-06-07 09:24:59 -0700156 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200157 const dbus::utility::DBusPropertiesMap& properties,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000158 const nlohmann::json::json_pointer& jsonPtr)
James Feistc50e7c62020-07-27 15:39:36 -0700159{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200160 const uint16_t* moduleManufacturerID = nullptr;
161 const uint16_t* moduleProductID = nullptr;
162 const uint16_t* subsystemVendorID = nullptr;
163 const uint16_t* subsystemDeviceID = nullptr;
164 const uint64_t* volatileRegionSizeLimitInKiB = nullptr;
165 const uint64_t* pmRegionSizeLimitInKiB = nullptr;
166 const uint64_t* volatileSizeInKiB = nullptr;
167 const uint64_t* pmSizeInKiB = nullptr;
168 const uint64_t* cacheSizeInKB = nullptr;
169 const uint64_t* voltaileRegionMaxSizeInKib = nullptr;
170 const uint64_t* pmRegionMaxSizeInKiB = nullptr;
171 const uint64_t* allocationIncrementInKiB = nullptr;
172 const uint64_t* allocationAlignmentInKiB = nullptr;
173 const uint64_t* volatileRegionNumberLimit = nullptr;
174 const uint64_t* pmRegionNumberLimit = nullptr;
175 const uint64_t* spareDeviceCount = nullptr;
176 const bool* isSpareDeviceInUse = nullptr;
177 const bool* isRankSpareEnabled = nullptr;
178 const std::vector<uint32_t>* maxAveragePowerLimitmW = nullptr;
179 const bool* configurationLocked = nullptr;
180 const std::string* allowedMemoryModes = nullptr;
181 const std::string* memoryMedia = nullptr;
182 const bool* configurationLockCapable = nullptr;
183 const bool* dataLockCapable = nullptr;
184 const bool* passphraseCapable = nullptr;
185 const uint64_t* maxPassphraseCount = nullptr;
186 const uint64_t* passphraseLockLimit = nullptr;
James Feistc50e7c62020-07-27 15:39:36 -0700187
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200188 const bool success = sdbusplus::unpackPropertiesNoThrow(
189 dbus_utils::UnpackErrorPrinter(), properties, "ModuleManufacturerID",
190 moduleManufacturerID, "ModuleProductID", moduleProductID,
191 "SubsystemVendorID", subsystemVendorID, "SubsystemDeviceID",
192 subsystemDeviceID, "VolatileRegionSizeLimitInKiB",
193 volatileRegionSizeLimitInKiB, "PmRegionSizeLimitInKiB",
194 pmRegionSizeLimitInKiB, "VolatileSizeInKiB", volatileSizeInKiB,
195 "PmSizeInKiB", pmSizeInKiB, "CacheSizeInKB", cacheSizeInKB,
196 "VoltaileRegionMaxSizeInKib", voltaileRegionMaxSizeInKib,
197 "PmRegionMaxSizeInKiB", pmRegionMaxSizeInKiB,
198 "AllocationIncrementInKiB", allocationIncrementInKiB,
199 "AllocationAlignmentInKiB", allocationAlignmentInKiB,
200 "VolatileRegionNumberLimit", volatileRegionNumberLimit,
201 "PmRegionNumberLimit", pmRegionNumberLimit, "SpareDeviceCount",
202 spareDeviceCount, "IsSpareDeviceInUse", isSpareDeviceInUse,
203 "IsRankSpareEnabled", isRankSpareEnabled, "MaxAveragePowerLimitmW",
204 maxAveragePowerLimitmW, "ConfigurationLocked", configurationLocked,
205 "AllowedMemoryModes", allowedMemoryModes, "MemoryMedia", memoryMedia,
206 "ConfigurationLockCapable", configurationLockCapable, "DataLockCapable",
207 dataLockCapable, "PassphraseCapable", passphraseCapable,
208 "MaxPassphraseCount", maxPassphraseCount, "PassphraseLockLimit",
209 passphraseLockLimit);
210
211 if (!success)
212 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700213 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200214 return;
215 }
216
Ed Tanousac106bf2023-06-07 09:24:59 -0700217 dimmPropToHex(asyncResp, "ModuleManufacturerID", moduleManufacturerID,
218 jsonPtr);
219 dimmPropToHex(asyncResp, "ModuleProductID", moduleProductID, jsonPtr);
220 dimmPropToHex(asyncResp, "MemorySubsystemControllerManufacturerID",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200221 subsystemVendorID, jsonPtr);
Ed Tanousac106bf2023-06-07 09:24:59 -0700222 dimmPropToHex(asyncResp, "MemorySubsystemControllerProductID",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200223 subsystemDeviceID, jsonPtr);
224
225 if (volatileRegionSizeLimitInKiB != nullptr)
226 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700227 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionSizeLimitMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200228 (*volatileRegionSizeLimitInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800229 }
James Feistc50e7c62020-07-27 15:39:36 -0700230
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200231 if (pmRegionSizeLimitInKiB != nullptr)
232 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700233 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionSizeLimitMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200234 (*pmRegionSizeLimitInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800235 }
James Feistc50e7c62020-07-27 15:39:36 -0700236
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200237 if (volatileSizeInKiB != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800238 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700239 asyncResp->res.jsonValue[jsonPtr]["VolatileSizeMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200240 (*volatileSizeInKiB) >> 10;
241 }
242
243 if (pmSizeInKiB != nullptr)
244 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700245 asyncResp->res.jsonValue[jsonPtr]["NonVolatileSizeMiB"] =
246 (*pmSizeInKiB) >> 10;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200247 }
248
249 if (cacheSizeInKB != nullptr)
250 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700251 asyncResp->res.jsonValue[jsonPtr]["CacheSizeMiB"] =
252 (*cacheSizeInKB >> 10);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200253 }
254
255 if (voltaileRegionMaxSizeInKib != nullptr)
256 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700257 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionSizeMaxMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200258 (*voltaileRegionMaxSizeInKib) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800259 }
James Feistc50e7c62020-07-27 15:39:36 -0700260
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200261 if (pmRegionMaxSizeInKiB != nullptr)
262 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700263 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionSizeMaxMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200264 (*pmRegionMaxSizeInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800265 }
James Feistc50e7c62020-07-27 15:39:36 -0700266
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200267 if (allocationIncrementInKiB != nullptr)
268 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700269 asyncResp->res.jsonValue[jsonPtr]["AllocationIncrementMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200270 (*allocationIncrementInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800271 }
James Feistc50e7c62020-07-27 15:39:36 -0700272
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200273 if (allocationAlignmentInKiB != nullptr)
274 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700275 asyncResp->res.jsonValue[jsonPtr]["AllocationAlignmentMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200276 (*allocationAlignmentInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800277 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200278
279 if (volatileRegionNumberLimit != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800280 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700281 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionNumberLimit"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200282 *volatileRegionNumberLimit;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800283 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200284
285 if (pmRegionNumberLimit != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800286 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700287 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionNumberLimit"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200288 *pmRegionNumberLimit;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800289 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200290
291 if (spareDeviceCount != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800292 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700293 asyncResp->res.jsonValue[jsonPtr]["SpareDeviceCount"] =
294 *spareDeviceCount;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800295 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200296
297 if (isSpareDeviceInUse != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800298 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700299 asyncResp->res.jsonValue[jsonPtr]["IsSpareDeviceEnabled"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200300 *isSpareDeviceInUse;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800301 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200302
303 if (isRankSpareEnabled != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800304 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700305 asyncResp->res.jsonValue[jsonPtr]["IsRankSpareEnabled"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200306 *isRankSpareEnabled;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800307 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200308
309 if (maxAveragePowerLimitmW != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800310 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700311 asyncResp->res.jsonValue[jsonPtr]["MaxTDPMilliWatts"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200312 *maxAveragePowerLimitmW;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800313 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200314
315 if (configurationLocked != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800316 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700317 asyncResp->res.jsonValue[jsonPtr]["ConfigurationLocked"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200318 *configurationLocked;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800319 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200320
321 if (allowedMemoryModes != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800322 {
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800323 constexpr const std::array<const char*, 3> values{"Volatile", "PMEM",
324 "Block"};
James Feistc50e7c62020-07-27 15:39:36 -0700325
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800326 for (const char* v : values)
327 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200328 if (allowedMemoryModes->ends_with(v))
James Feistc50e7c62020-07-27 15:39:36 -0700329 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700330 asyncResp->res.jsonValue[jsonPtr]["OperatingMemoryModes"]
331 .push_back(v);
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800332 break;
James Feistc50e7c62020-07-27 15:39:36 -0700333 }
334 }
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800335 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200336
337 if (memoryMedia != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800338 {
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800339 constexpr const std::array<const char*, 3> values{"DRAM", "NAND",
340 "Intel3DXPoint"};
James Feistc50e7c62020-07-27 15:39:36 -0700341
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800342 for (const char* v : values)
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700343 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200344 if (memoryMedia->ends_with(v))
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700345 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700346 asyncResp->res.jsonValue[jsonPtr]["MemoryMedia"].push_back(v);
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800347 break;
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700348 }
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700349 }
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800350 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200351
352 if (configurationLockCapable != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800353 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700354 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
355 ["ConfigurationLockCapable"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200356 *configurationLockCapable;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800357 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200358
359 if (dataLockCapable != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800360 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400361 asyncResp->res
362 .jsonValue[jsonPtr]["SecurityCapabilities"]["DataLockCapable"] =
363 *dataLockCapable;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200364 }
365
366 if (passphraseCapable != nullptr)
367 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400368 asyncResp->res
369 .jsonValue[jsonPtr]["SecurityCapabilities"]["PassphraseCapable"] =
370 *passphraseCapable;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200371 }
372
373 if (maxPassphraseCount != nullptr)
374 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400375 asyncResp->res
376 .jsonValue[jsonPtr]["SecurityCapabilities"]["MaxPassphraseCount"] =
377 *maxPassphraseCount;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200378 }
379
380 if (passphraseLockLimit != nullptr)
381 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400382 asyncResp->res
383 .jsonValue[jsonPtr]["SecurityCapabilities"]["PassphraseLockLimit"] =
384 *passphraseLockLimit;
James Feistc50e7c62020-07-27 15:39:36 -0700385 }
386}
387
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400388inline void assembleDimmProperties(
389 std::string_view dimmId,
390 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
391 const dbus::utility::DBusPropertiesMap& properties,
392 const nlohmann::json::json_pointer& jsonPtr)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000393{
Ed Tanousac106bf2023-06-07 09:24:59 -0700394 asyncResp->res.jsonValue[jsonPtr]["Id"] = dimmId;
395 asyncResp->res.jsonValue[jsonPtr]["Name"] = "DIMM Slot";
Ed Tanous539d8c62024-06-19 14:38:27 -0700396 asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] =
397 resource::State::Enabled;
398 asyncResp->res.jsonValue[jsonPtr]["Status"]["Health"] =
399 resource::Health::OK;
Nan Zhou9a5acea2022-05-17 21:12:43 +0000400
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200401 const uint16_t* memoryDataWidth = nullptr;
402 const size_t* memorySizeInKB = nullptr;
403 const std::string* partNumber = nullptr;
404 const std::string* serialNumber = nullptr;
405 const std::string* manufacturer = nullptr;
406 const uint16_t* revisionCode = nullptr;
407 const bool* present = nullptr;
408 const uint16_t* memoryTotalWidth = nullptr;
409 const std::string* ecc = nullptr;
410 const std::string* formFactor = nullptr;
411 const std::vector<uint16_t>* allowedSpeedsMT = nullptr;
George Liu6995c1c2023-06-15 08:53:11 +0800412 const size_t* memoryAttributes = nullptr;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200413 const uint16_t* memoryConfiguredSpeedInMhz = nullptr;
414 const std::string* memoryType = nullptr;
Jayaprakash Mutyala6fde5972023-06-15 07:56:58 +0000415 const std::uint8_t* channel = nullptr;
416 const std::uint8_t* memoryController = nullptr;
417 const std::uint8_t* slot = nullptr;
418 const std::uint8_t* socket = nullptr;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200419 const std::string* sparePartNumber = nullptr;
420 const std::string* model = nullptr;
421 const std::string* locationCode = nullptr;
422
423 const bool success = sdbusplus::unpackPropertiesNoThrow(
424 dbus_utils::UnpackErrorPrinter(), properties, "MemoryDataWidth",
425 memoryDataWidth, "MemorySizeInKB", memorySizeInKB, "PartNumber",
Nikhil Namjoshi656472d2022-09-13 20:54:44 +0000426 partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer,
427 "RevisionCode", revisionCode, "Present", present, "MemoryTotalWidth",
428 memoryTotalWidth, "ECC", ecc, "FormFactor", formFactor,
429 "AllowedSpeedsMT", allowedSpeedsMT, "MemoryAttributes",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200430 memoryAttributes, "MemoryConfiguredSpeedInMhz",
431 memoryConfiguredSpeedInMhz, "MemoryType", memoryType, "Channel",
432 channel, "MemoryController", memoryController, "Slot", slot, "Socket",
433 socket, "SparePartNumber", sparePartNumber, "Model", model,
434 "LocationCode", locationCode);
435
436 if (!success)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000437 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700438 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200439 return;
440 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000441
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200442 if (memoryDataWidth != nullptr)
443 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700444 asyncResp->res.jsonValue[jsonPtr]["DataWidthBits"] = *memoryDataWidth;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200445 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000446
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200447 if (memorySizeInKB != nullptr)
448 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700449 asyncResp->res.jsonValue[jsonPtr]["CapacityMiB"] =
450 (*memorySizeInKB >> 10);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200451 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000452
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200453 if (partNumber != nullptr)
454 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700455 asyncResp->res.jsonValue[jsonPtr]["PartNumber"] = *partNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200456 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000457
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200458 if (serialNumber != nullptr)
459 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700460 asyncResp->res.jsonValue[jsonPtr]["SerialNumber"] = *serialNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200461 }
462
463 if (manufacturer != nullptr)
464 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700465 asyncResp->res.jsonValue[jsonPtr]["Manufacturer"] = *manufacturer;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200466 }
467
468 if (revisionCode != nullptr)
469 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700470 asyncResp->res.jsonValue[jsonPtr]["FirmwareRevision"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200471 std::to_string(*revisionCode);
472 }
473
474 if (present != nullptr && !*present)
475 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700476 asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] =
477 resource::State::Absent;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200478 }
479
480 if (memoryTotalWidth != nullptr)
481 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700482 asyncResp->res.jsonValue[jsonPtr]["BusWidthBits"] = *memoryTotalWidth;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200483 }
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 Zhou9a5acea2022-05-17 21:12:43 +0000491 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200492 if (ecc->ends_with(v))
Nan Zhou9a5acea2022-05-17 21:12:43 +0000493 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700494 asyncResp->res.jsonValue[jsonPtr]["ErrorCorrection"] = v;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200495 break;
Nan Zhou9a5acea2022-05-17 21:12:43 +0000496 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000497 }
498 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200499
500 if (formFactor != nullptr)
501 {
502 constexpr const std::array<const char*, 11> values{
503 "RDIMM", "UDIMM", "SO_DIMM", "LRDIMM",
504 "Mini_RDIMM", "Mini_UDIMM", "SO_RDIMM_72b", "SO_UDIMM_72b",
505 "SO_DIMM_16b", "SO_DIMM_32b", "Die"};
506
507 for (const char* v : values)
508 {
509 if (formFactor->ends_with(v))
510 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700511 asyncResp->res.jsonValue[jsonPtr]["BaseModuleType"] = v;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200512 break;
513 }
514 }
515 }
516
517 if (allowedSpeedsMT != nullptr)
518 {
519 nlohmann::json& jValue =
Ed Tanousac106bf2023-06-07 09:24:59 -0700520 asyncResp->res.jsonValue[jsonPtr]["AllowedSpeedsMHz"];
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200521 jValue = nlohmann::json::array();
522 for (uint16_t subVal : *allowedSpeedsMT)
523 {
524 jValue.push_back(subVal);
525 }
526 }
527
528 if (memoryAttributes != nullptr)
529 {
George Liu6995c1c2023-06-15 08:53:11 +0800530 asyncResp->res.jsonValue[jsonPtr]["RankCount"] = *memoryAttributes;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200531 }
532
533 if (memoryConfiguredSpeedInMhz != nullptr)
534 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700535 asyncResp->res.jsonValue[jsonPtr]["OperatingSpeedMhz"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200536 *memoryConfiguredSpeedInMhz;
537 }
538
539 if (memoryType != nullptr)
540 {
541 std::string memoryDeviceType =
542 translateMemoryTypeToRedfish(*memoryType);
543 // Values like "Unknown" or "Other" will return empty
544 // so just leave off
545 if (!memoryDeviceType.empty())
546 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700547 asyncResp->res.jsonValue[jsonPtr]["MemoryDeviceType"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200548 memoryDeviceType;
549 }
550 if (memoryType->find("DDR") != std::string::npos)
551 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700552 asyncResp->res.jsonValue[jsonPtr]["MemoryType"] =
553 memory::MemoryType::DRAM;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200554 }
555 else if (memoryType->ends_with("Logical"))
556 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700557 asyncResp->res.jsonValue[jsonPtr]["MemoryType"] =
558 memory::MemoryType::IntelOptane;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200559 }
560 }
561
562 if (channel != nullptr)
563 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700564 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Channel"] =
565 *channel;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200566 }
567
568 if (memoryController != nullptr)
569 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400570 asyncResp->res
571 .jsonValue[jsonPtr]["MemoryLocation"]["MemoryController"] =
572 *memoryController;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200573 }
574
575 if (slot != nullptr)
576 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700577 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Slot"] = *slot;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200578 }
579
580 if (socket != nullptr)
581 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700582 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Socket"] = *socket;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200583 }
584
585 if (sparePartNumber != nullptr)
586 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700587 asyncResp->res.jsonValue[jsonPtr]["SparePartNumber"] = *sparePartNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200588 }
589
590 if (model != nullptr)
591 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700592 asyncResp->res.jsonValue[jsonPtr]["Model"] = *model;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200593 }
594
595 if (locationCode != nullptr)
596 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400597 asyncResp->res
598 .jsonValue[jsonPtr]["Location"]["PartLocation"]["ServiceLabel"] =
599 *locationCode;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200600 }
601
Ed Tanousac106bf2023-06-07 09:24:59 -0700602 getPersistentMemoryProperties(asyncResp, properties, jsonPtr);
Nan Zhou9a5acea2022-05-17 21:12:43 +0000603}
604
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400605inline void getDimmDataByService(
606 std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& dimmId,
607 const std::string& service, const std::string& objPath)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200608{
Ed Tanous62598e32023-07-17 17:06:25 -0700609 BMCWEB_LOG_DEBUG("Get available system components.");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800610 dbus::utility::getAllProperties(
611 service, objPath, "",
Ed Tanousac106bf2023-06-07 09:24:59 -0700612 [dimmId, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800613 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800614 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400615 if (ec)
616 {
617 BMCWEB_LOG_DEBUG("DBUS response error");
618 messages::internalError(asyncResp->res);
619 return;
620 }
621 assembleDimmProperties(dimmId, asyncResp, properties,
622 ""_json_pointer);
623 });
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200624}
625
Nan Zhouef00d7d2022-05-20 21:22:32 +0000626inline void assembleDimmPartitionData(
Ed Tanousac106bf2023-06-07 09:24:59 -0700627 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000628 const dbus::utility::DBusPropertiesMap& properties,
629 const nlohmann::json::json_pointer& regionPtr)
Nan Zhouef00d7d2022-05-20 21:22:32 +0000630{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200631 const std::string* memoryClassification = nullptr;
632 const uint64_t* offsetInKiB = nullptr;
633 const std::string* partitionId = nullptr;
634 const bool* passphraseState = nullptr;
635 const uint64_t* sizeInKiB = nullptr;
636
637 const bool success = sdbusplus::unpackPropertiesNoThrow(
638 dbus_utils::UnpackErrorPrinter(), properties, "MemoryClassification",
639 memoryClassification, "OffsetInKiB", offsetInKiB, "PartitionId",
640 partitionId, "PassphraseState", passphraseState, "SizeInKiB",
641 sizeInKiB);
642
643 if (!success)
Nan Zhouef00d7d2022-05-20 21:22:32 +0000644 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700645 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200646 return;
Nan Zhouef00d7d2022-05-20 21:22:32 +0000647 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200648
649 nlohmann::json::object_t partition;
650
651 if (memoryClassification != nullptr)
652 {
653 partition["MemoryClassification"] = *memoryClassification;
654 }
655
656 if (offsetInKiB != nullptr)
657 {
658 partition["OffsetMiB"] = (*offsetInKiB >> 10);
659 }
660
661 if (partitionId != nullptr)
662 {
663 partition["RegionId"] = *partitionId;
664 }
665
666 if (passphraseState != nullptr)
667 {
668 partition["PassphraseEnabled"] = *passphraseState;
669 }
670
671 if (sizeInKiB != nullptr)
672 {
673 partition["SizeMiB"] = (*sizeInKiB >> 10);
674 }
675
Ed Tanousac106bf2023-06-07 09:24:59 -0700676 asyncResp->res.jsonValue[regionPtr].emplace_back(std::move(partition));
Nan Zhouef00d7d2022-05-20 21:22:32 +0000677}
678
Ed Tanousac106bf2023-06-07 09:24:59 -0700679inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000680 const std::string& service,
681 const std::string& path)
James Feist45094ad2020-04-29 14:02:30 -0700682{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800683 dbus::utility::getAllProperties(
684 service, path,
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200685 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition",
Ed Tanousac106bf2023-06-07 09:24:59 -0700686 [asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800687 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800688 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400689 if (ec)
690 {
691 BMCWEB_LOG_DEBUG("DBUS response error");
692 messages::internalError(asyncResp->res);
James Feist45094ad2020-04-29 14:02:30 -0700693
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400694 return;
695 }
696 nlohmann::json::json_pointer regionPtr = "/Regions"_json_pointer;
697 assembleDimmPartitionData(asyncResp, properties, regionPtr);
Ed Tanous002d39b2022-05-31 08:59:27 -0700698 }
James Feist45094ad2020-04-29 14:02:30 -0700699
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200700 );
James Feist45094ad2020-04-29 14:02:30 -0700701}
702
Ed Tanousac106bf2023-06-07 09:24:59 -0700703inline void getDimmData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000704 const std::string& dimmId)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200705{
Ed Tanous62598e32023-07-17 17:06:25 -0700706 BMCWEB_LOG_DEBUG("Get available system dimm resources.");
George Liue99073f2022-12-09 11:06:16 +0800707 constexpr std::array<std::string_view, 2> dimmInterfaces = {
708 "xyz.openbmc_project.Inventory.Item.Dimm",
709 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition"};
710 dbus::utility::getSubTree(
711 "/xyz/openbmc_project/inventory", 0, dimmInterfaces,
Ed Tanousac106bf2023-06-07 09:24:59 -0700712 [dimmId, asyncResp{std::move(asyncResp)}](
George Liue99073f2022-12-09 11:06:16 +0800713 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800714 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400715 if (ec)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200716 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400717 BMCWEB_LOG_DEBUG("DBUS response error");
718 messages::internalError(asyncResp->res);
James Feist45094ad2020-04-29 14:02:30 -0700719
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400720 return;
721 }
722 bool found = false;
723 for (const auto& [rawPath, object] : subtree)
724 {
725 sdbusplus::message::object_path path(rawPath);
726 for (const auto& [service, interfaces] : object)
727 {
728 for (const auto& interface : interfaces)
Nan Zhou76686dc2022-06-17 23:01:51 +0000729 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400730 if (interface ==
731 "xyz.openbmc_project.Inventory.Item.Dimm" &&
732 path.filename() == dimmId)
733 {
734 getDimmDataByService(asyncResp, dimmId, service,
735 rawPath);
736 found = true;
737 }
738
739 // partitions are separate as there can be multiple
740 // per
741 // device, i.e.
742 // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition1
743 // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition2
744 if (interface ==
745 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition" &&
746 path.parent_path().filename() == dimmId)
747 {
748 getDimmPartitionData(asyncResp, service, rawPath);
749 }
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200750 }
751 }
752 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400753 // Object not found
754 if (!found)
755 {
756 messages::resourceNotFound(asyncResp->res, "Memory", dimmId);
757 return;
758 }
759 // Set @odata only if object is found
760 asyncResp->res.jsonValue["@odata.type"] = "#Memory.v1_11_0.Memory";
761 asyncResp->res.jsonValue["@odata.id"] =
762 boost::urls::format("/redfish/v1/Systems/{}/Memory/{}",
763 BMCWEB_REDFISH_SYSTEM_URI_NAME, dimmId);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200764 return;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400765 });
Ed Tanous271584a2019-07-09 16:24:22 -0700766}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200767
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700768inline void requestRoutesMemoryCollection(App& app)
Ed Tanous029573d2019-02-01 10:57:49 -0800769{
Ed Tanous029573d2019-02-01 10:57:49 -0800770 /**
771 * Functions triggers appropriate requests on DBus
772 */
Ed Tanous22d268c2022-05-19 09:39:07 -0700773 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/")
Ed Tanoused398212021-06-09 17:05:54 -0700774 .privileges(redfish::privileges::getMemoryCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700775 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700776 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -0700777 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
778 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400779 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
780 {
781 return;
782 }
783 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
784 {
785 // Option currently returns no systems. TBD
786 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
787 systemName);
788 return;
789 }
790 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
791 {
792 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
793 systemName);
794 return;
795 }
Ed Tanous22d268c2022-05-19 09:39:07 -0700796
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400797 asyncResp->res.jsonValue["@odata.type"] =
798 "#MemoryCollection.MemoryCollection";
799 asyncResp->res.jsonValue["Name"] = "Memory Module Collection";
800 asyncResp->res.jsonValue["@odata.id"] =
801 boost::urls::format("/redfish/v1/Systems/{}/Memory",
802 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200803
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400804 constexpr std::array<std::string_view, 1> interfaces{
805 "xyz.openbmc_project.Inventory.Item.Dimm"};
806 collection_util::getCollectionMembers(
807 asyncResp,
808 boost::urls::format("/redfish/v1/Systems/{}/Memory",
809 BMCWEB_REDFISH_SYSTEM_URI_NAME),
810 interfaces, "/xyz/openbmc_project/inventory");
811 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700812}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200813
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700814inline void requestRoutesMemory(App& app)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200815{
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200816 /**
817 * Functions triggers appropriate requests on DBus
818 */
Ed Tanous22d268c2022-05-19 09:39:07 -0700819 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700820 .privileges(redfish::privileges::getMemory)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700821 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700822 [&app](const crow::Request& req,
823 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -0700824 const std::string& systemName, const std::string& dimmId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400825 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
826 {
827 return;
828 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800829
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400830 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
831 {
832 // Option currently returns no systems. TBD
833 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
834 systemName);
835 return;
836 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800837
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400838 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
839 {
840 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
841 systemName);
842 return;
843 }
Ed Tanous22d268c2022-05-19 09:39:07 -0700844
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400845 getDimmData(asyncResp, dimmId);
846 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700847}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200848
849} // namespace redfish