blob: a287593b26d2cd541057a698e6d078f6176918eb [file] [log] [blame]
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +02001/*
Ed Tanous6be832e2024-09-10 11:44:48 -07002Copyright (c) 2018 Intel Corporation
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020015*/
16#pragma once
17
Willy Tu13451e32023-05-24 16:08:18 -070018#include "bmcweb_config.h"
19
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080020#include "app.hpp"
21#include "dbus_utility.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070022#include "generated/enums/memory.hpp"
23#include "generated/enums/resource.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080024#include "query.hpp"
25#include "registries/privilege_registry.hpp"
26#include "utils/collection.hpp"
27#include "utils/dbus_utils.hpp"
28#include "utils/hex_utils.hpp"
29#include "utils/json_utils.hpp"
James Feist35e257a2020-06-05 13:30:51 -070030
George Liue99073f2022-12-09 11:06:16 +080031#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070032#include <boost/url/format.hpp>
Nan Zhoud7f04fd2022-05-01 01:11:07 +000033#include <nlohmann/json.hpp>
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +020034#include <sdbusplus/asio/property.hpp>
35#include <sdbusplus/unpack_properties.hpp>
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020036
George Liu7a1dbc42022-12-07 16:03:22 +080037#include <array>
38#include <string_view>
39
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020040namespace redfish
41{
42
Gunnar Mills313efb12020-10-26 16:05:08 -050043inline std::string translateMemoryTypeToRedfish(const std::string& memoryType)
44{
45 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR")
46 {
47 return "DDR";
48 }
49 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2")
50 {
51 return "DDR2";
52 }
53 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR3")
54 {
55 return "DDR3";
56 }
57 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4")
58 {
59 return "DDR4";
60 }
61 if (memoryType ==
62 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4E_SDRAM")
63 {
64 return "DDR4E_SDRAM";
65 }
Mansi Joshi11a2f0f2021-07-19 14:33:27 +053066 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR5")
67 {
68 return "DDR5";
69 }
Gunnar Mills313efb12020-10-26 16:05:08 -050070 if (memoryType ==
71 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR4_SDRAM")
72 {
73 return "LPDDR4_SDRAM";
74 }
75 if (memoryType ==
76 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR3_SDRAM")
77 {
78 return "LPDDR3_SDRAM";
79 }
80 if (memoryType ==
81 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM")
82 {
83 return "DDR2_SDRAM_FB_DIMM";
84 }
George Liu0fda0f12021-11-16 10:06:17 +080085 if (memoryType ==
86 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM_PROB")
Gunnar Mills313efb12020-10-26 16:05:08 -050087 {
88 return "DDR2_SDRAM_FB_DIMM_PROBE";
89 }
90 if (memoryType ==
91 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR_SGRAM")
92 {
93 return "DDR_SGRAM";
94 }
95 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.ROM")
96 {
97 return "ROM";
98 }
99 if (memoryType ==
100 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.SDRAM")
101 {
102 return "SDRAM";
103 }
104 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.EDO")
105 {
106 return "EDO";
107 }
108 if (memoryType ==
109 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.FastPageMode")
110 {
111 return "FastPageMode";
112 }
113 if (memoryType ==
114 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.PipelinedNibble")
115 {
116 return "PipelinedNibble";
117 }
118 if (memoryType ==
119 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.Logical")
120 {
121 return "Logical";
122 }
123 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM")
124 {
125 return "HBM";
126 }
127 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM2")
128 {
129 return "HBM2";
130 }
Tyson Tuckerbearce34d512022-09-13 16:26:15 -0700131 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM3")
132 {
133 return "HBM3";
134 }
Gunnar Mills313efb12020-10-26 16:05:08 -0500135 // This is values like Other or Unknown
136 // Also D-Bus values:
137 // DRAM
138 // EDRAM
139 // VRAM
140 // SRAM
141 // RAM
142 // FLASH
143 // EEPROM
144 // FEPROM
145 // EPROM
146 // CDRAM
147 // ThreeDRAM
148 // RDRAM
149 // FBD2
150 // LPDDR_SDRAM
151 // LPDDR2_SDRAM
Mansi Joshi11a2f0f2021-07-19 14:33:27 +0530152 // LPDDR5_SDRAM
Gunnar Mills313efb12020-10-26 16:05:08 -0500153 return "";
154}
155
Ed Tanousac106bf2023-06-07 09:24:59 -0700156inline void dimmPropToHex(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200157 const char* key, const uint16_t* value,
158 const nlohmann::json::json_pointer& jsonPtr)
James Feistc50e7c62020-07-27 15:39:36 -0700159{
James Feistc50e7c62020-07-27 15:39:36 -0700160 if (value == nullptr)
161 {
James Feistc50e7c62020-07-27 15:39:36 -0700162 return;
163 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700164 asyncResp->res.jsonValue[jsonPtr][key] = "0x" + intToHexString(*value, 4);
James Feistc50e7c62020-07-27 15:39:36 -0700165}
166
zhanghch058d1b46d2021-04-01 11:18:24 +0800167inline void getPersistentMemoryProperties(
Ed Tanousac106bf2023-06-07 09:24:59 -0700168 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200169 const dbus::utility::DBusPropertiesMap& properties,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000170 const nlohmann::json::json_pointer& jsonPtr)
James Feistc50e7c62020-07-27 15:39:36 -0700171{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200172 const uint16_t* moduleManufacturerID = nullptr;
173 const uint16_t* moduleProductID = nullptr;
174 const uint16_t* subsystemVendorID = nullptr;
175 const uint16_t* subsystemDeviceID = nullptr;
176 const uint64_t* volatileRegionSizeLimitInKiB = nullptr;
177 const uint64_t* pmRegionSizeLimitInKiB = nullptr;
178 const uint64_t* volatileSizeInKiB = nullptr;
179 const uint64_t* pmSizeInKiB = nullptr;
180 const uint64_t* cacheSizeInKB = nullptr;
181 const uint64_t* voltaileRegionMaxSizeInKib = nullptr;
182 const uint64_t* pmRegionMaxSizeInKiB = nullptr;
183 const uint64_t* allocationIncrementInKiB = nullptr;
184 const uint64_t* allocationAlignmentInKiB = nullptr;
185 const uint64_t* volatileRegionNumberLimit = nullptr;
186 const uint64_t* pmRegionNumberLimit = nullptr;
187 const uint64_t* spareDeviceCount = nullptr;
188 const bool* isSpareDeviceInUse = nullptr;
189 const bool* isRankSpareEnabled = nullptr;
190 const std::vector<uint32_t>* maxAveragePowerLimitmW = nullptr;
191 const bool* configurationLocked = nullptr;
192 const std::string* allowedMemoryModes = nullptr;
193 const std::string* memoryMedia = nullptr;
194 const bool* configurationLockCapable = nullptr;
195 const bool* dataLockCapable = nullptr;
196 const bool* passphraseCapable = nullptr;
197 const uint64_t* maxPassphraseCount = nullptr;
198 const uint64_t* passphraseLockLimit = nullptr;
James Feistc50e7c62020-07-27 15:39:36 -0700199
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200200 const bool success = sdbusplus::unpackPropertiesNoThrow(
201 dbus_utils::UnpackErrorPrinter(), properties, "ModuleManufacturerID",
202 moduleManufacturerID, "ModuleProductID", moduleProductID,
203 "SubsystemVendorID", subsystemVendorID, "SubsystemDeviceID",
204 subsystemDeviceID, "VolatileRegionSizeLimitInKiB",
205 volatileRegionSizeLimitInKiB, "PmRegionSizeLimitInKiB",
206 pmRegionSizeLimitInKiB, "VolatileSizeInKiB", volatileSizeInKiB,
207 "PmSizeInKiB", pmSizeInKiB, "CacheSizeInKB", cacheSizeInKB,
208 "VoltaileRegionMaxSizeInKib", voltaileRegionMaxSizeInKib,
209 "PmRegionMaxSizeInKiB", pmRegionMaxSizeInKiB,
210 "AllocationIncrementInKiB", allocationIncrementInKiB,
211 "AllocationAlignmentInKiB", allocationAlignmentInKiB,
212 "VolatileRegionNumberLimit", volatileRegionNumberLimit,
213 "PmRegionNumberLimit", pmRegionNumberLimit, "SpareDeviceCount",
214 spareDeviceCount, "IsSpareDeviceInUse", isSpareDeviceInUse,
215 "IsRankSpareEnabled", isRankSpareEnabled, "MaxAveragePowerLimitmW",
216 maxAveragePowerLimitmW, "ConfigurationLocked", configurationLocked,
217 "AllowedMemoryModes", allowedMemoryModes, "MemoryMedia", memoryMedia,
218 "ConfigurationLockCapable", configurationLockCapable, "DataLockCapable",
219 dataLockCapable, "PassphraseCapable", passphraseCapable,
220 "MaxPassphraseCount", maxPassphraseCount, "PassphraseLockLimit",
221 passphraseLockLimit);
222
223 if (!success)
224 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700225 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200226 return;
227 }
228
Ed Tanousac106bf2023-06-07 09:24:59 -0700229 dimmPropToHex(asyncResp, "ModuleManufacturerID", moduleManufacturerID,
230 jsonPtr);
231 dimmPropToHex(asyncResp, "ModuleProductID", moduleProductID, jsonPtr);
232 dimmPropToHex(asyncResp, "MemorySubsystemControllerManufacturerID",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200233 subsystemVendorID, jsonPtr);
Ed Tanousac106bf2023-06-07 09:24:59 -0700234 dimmPropToHex(asyncResp, "MemorySubsystemControllerProductID",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200235 subsystemDeviceID, jsonPtr);
236
237 if (volatileRegionSizeLimitInKiB != nullptr)
238 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700239 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionSizeLimitMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200240 (*volatileRegionSizeLimitInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800241 }
James Feistc50e7c62020-07-27 15:39:36 -0700242
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200243 if (pmRegionSizeLimitInKiB != nullptr)
244 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700245 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionSizeLimitMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200246 (*pmRegionSizeLimitInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800247 }
James Feistc50e7c62020-07-27 15:39:36 -0700248
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200249 if (volatileSizeInKiB != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800250 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700251 asyncResp->res.jsonValue[jsonPtr]["VolatileSizeMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200252 (*volatileSizeInKiB) >> 10;
253 }
254
255 if (pmSizeInKiB != nullptr)
256 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700257 asyncResp->res.jsonValue[jsonPtr]["NonVolatileSizeMiB"] =
258 (*pmSizeInKiB) >> 10;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200259 }
260
261 if (cacheSizeInKB != nullptr)
262 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700263 asyncResp->res.jsonValue[jsonPtr]["CacheSizeMiB"] =
264 (*cacheSizeInKB >> 10);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200265 }
266
267 if (voltaileRegionMaxSizeInKib != nullptr)
268 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700269 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionSizeMaxMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200270 (*voltaileRegionMaxSizeInKib) >> 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 (pmRegionMaxSizeInKiB != nullptr)
274 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700275 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionSizeMaxMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200276 (*pmRegionMaxSizeInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800277 }
James Feistc50e7c62020-07-27 15:39:36 -0700278
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200279 if (allocationIncrementInKiB != nullptr)
280 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700281 asyncResp->res.jsonValue[jsonPtr]["AllocationIncrementMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200282 (*allocationIncrementInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800283 }
James Feistc50e7c62020-07-27 15:39:36 -0700284
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200285 if (allocationAlignmentInKiB != nullptr)
286 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700287 asyncResp->res.jsonValue[jsonPtr]["AllocationAlignmentMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200288 (*allocationAlignmentInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800289 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200290
291 if (volatileRegionNumberLimit != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800292 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700293 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionNumberLimit"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200294 *volatileRegionNumberLimit;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800295 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200296
297 if (pmRegionNumberLimit != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800298 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700299 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionNumberLimit"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200300 *pmRegionNumberLimit;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800301 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200302
303 if (spareDeviceCount != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800304 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700305 asyncResp->res.jsonValue[jsonPtr]["SpareDeviceCount"] =
306 *spareDeviceCount;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800307 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200308
309 if (isSpareDeviceInUse != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800310 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700311 asyncResp->res.jsonValue[jsonPtr]["IsSpareDeviceEnabled"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200312 *isSpareDeviceInUse;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800313 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200314
315 if (isRankSpareEnabled != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800316 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700317 asyncResp->res.jsonValue[jsonPtr]["IsRankSpareEnabled"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200318 *isRankSpareEnabled;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800319 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200320
321 if (maxAveragePowerLimitmW != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800322 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700323 asyncResp->res.jsonValue[jsonPtr]["MaxTDPMilliWatts"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200324 *maxAveragePowerLimitmW;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800325 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200326
327 if (configurationLocked != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800328 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700329 asyncResp->res.jsonValue[jsonPtr]["ConfigurationLocked"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200330 *configurationLocked;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800331 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200332
333 if (allowedMemoryModes != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800334 {
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800335 constexpr const std::array<const char*, 3> values{"Volatile", "PMEM",
336 "Block"};
James Feistc50e7c62020-07-27 15:39:36 -0700337
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800338 for (const char* v : values)
339 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200340 if (allowedMemoryModes->ends_with(v))
James Feistc50e7c62020-07-27 15:39:36 -0700341 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700342 asyncResp->res.jsonValue[jsonPtr]["OperatingMemoryModes"]
343 .push_back(v);
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800344 break;
James Feistc50e7c62020-07-27 15:39:36 -0700345 }
346 }
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800347 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200348
349 if (memoryMedia != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800350 {
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800351 constexpr const std::array<const char*, 3> values{"DRAM", "NAND",
352 "Intel3DXPoint"};
James Feistc50e7c62020-07-27 15:39:36 -0700353
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800354 for (const char* v : values)
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700355 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200356 if (memoryMedia->ends_with(v))
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700357 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700358 asyncResp->res.jsonValue[jsonPtr]["MemoryMedia"].push_back(v);
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800359 break;
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700360 }
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700361 }
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800362 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200363
364 if (configurationLockCapable != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800365 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700366 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
367 ["ConfigurationLockCapable"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200368 *configurationLockCapable;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800369 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200370
371 if (dataLockCapable != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800372 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400373 asyncResp->res
374 .jsonValue[jsonPtr]["SecurityCapabilities"]["DataLockCapable"] =
375 *dataLockCapable;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200376 }
377
378 if (passphraseCapable != nullptr)
379 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400380 asyncResp->res
381 .jsonValue[jsonPtr]["SecurityCapabilities"]["PassphraseCapable"] =
382 *passphraseCapable;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200383 }
384
385 if (maxPassphraseCount != nullptr)
386 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400387 asyncResp->res
388 .jsonValue[jsonPtr]["SecurityCapabilities"]["MaxPassphraseCount"] =
389 *maxPassphraseCount;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200390 }
391
392 if (passphraseLockLimit != nullptr)
393 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400394 asyncResp->res
395 .jsonValue[jsonPtr]["SecurityCapabilities"]["PassphraseLockLimit"] =
396 *passphraseLockLimit;
James Feistc50e7c62020-07-27 15:39:36 -0700397 }
398}
399
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400400inline void assembleDimmProperties(
401 std::string_view dimmId,
402 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
403 const dbus::utility::DBusPropertiesMap& properties,
404 const nlohmann::json::json_pointer& jsonPtr)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000405{
Ed Tanousac106bf2023-06-07 09:24:59 -0700406 asyncResp->res.jsonValue[jsonPtr]["Id"] = dimmId;
407 asyncResp->res.jsonValue[jsonPtr]["Name"] = "DIMM Slot";
Ed Tanous539d8c62024-06-19 14:38:27 -0700408 asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] =
409 resource::State::Enabled;
410 asyncResp->res.jsonValue[jsonPtr]["Status"]["Health"] =
411 resource::Health::OK;
Nan Zhou9a5acea2022-05-17 21:12:43 +0000412
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200413 const uint16_t* memoryDataWidth = nullptr;
414 const size_t* memorySizeInKB = nullptr;
415 const std::string* partNumber = nullptr;
416 const std::string* serialNumber = nullptr;
417 const std::string* manufacturer = nullptr;
418 const uint16_t* revisionCode = nullptr;
419 const bool* present = nullptr;
420 const uint16_t* memoryTotalWidth = nullptr;
421 const std::string* ecc = nullptr;
422 const std::string* formFactor = nullptr;
423 const std::vector<uint16_t>* allowedSpeedsMT = nullptr;
George Liu6995c1c2023-06-15 08:53:11 +0800424 const size_t* memoryAttributes = nullptr;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200425 const uint16_t* memoryConfiguredSpeedInMhz = nullptr;
426 const std::string* memoryType = nullptr;
Jayaprakash Mutyala6fde5972023-06-15 07:56:58 +0000427 const std::uint8_t* channel = nullptr;
428 const std::uint8_t* memoryController = nullptr;
429 const std::uint8_t* slot = nullptr;
430 const std::uint8_t* socket = nullptr;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200431 const std::string* sparePartNumber = nullptr;
432 const std::string* model = nullptr;
433 const std::string* locationCode = nullptr;
434
435 const bool success = sdbusplus::unpackPropertiesNoThrow(
436 dbus_utils::UnpackErrorPrinter(), properties, "MemoryDataWidth",
437 memoryDataWidth, "MemorySizeInKB", memorySizeInKB, "PartNumber",
Nikhil Namjoshi656472d2022-09-13 20:54:44 +0000438 partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer,
439 "RevisionCode", revisionCode, "Present", present, "MemoryTotalWidth",
440 memoryTotalWidth, "ECC", ecc, "FormFactor", formFactor,
441 "AllowedSpeedsMT", allowedSpeedsMT, "MemoryAttributes",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200442 memoryAttributes, "MemoryConfiguredSpeedInMhz",
443 memoryConfiguredSpeedInMhz, "MemoryType", memoryType, "Channel",
444 channel, "MemoryController", memoryController, "Slot", slot, "Socket",
445 socket, "SparePartNumber", sparePartNumber, "Model", model,
446 "LocationCode", locationCode);
447
448 if (!success)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000449 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700450 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200451 return;
452 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000453
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200454 if (memoryDataWidth != nullptr)
455 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700456 asyncResp->res.jsonValue[jsonPtr]["DataWidthBits"] = *memoryDataWidth;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200457 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000458
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200459 if (memorySizeInKB != nullptr)
460 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700461 asyncResp->res.jsonValue[jsonPtr]["CapacityMiB"] =
462 (*memorySizeInKB >> 10);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200463 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000464
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200465 if (partNumber != nullptr)
466 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700467 asyncResp->res.jsonValue[jsonPtr]["PartNumber"] = *partNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200468 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000469
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200470 if (serialNumber != nullptr)
471 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700472 asyncResp->res.jsonValue[jsonPtr]["SerialNumber"] = *serialNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200473 }
474
475 if (manufacturer != nullptr)
476 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700477 asyncResp->res.jsonValue[jsonPtr]["Manufacturer"] = *manufacturer;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200478 }
479
480 if (revisionCode != nullptr)
481 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700482 asyncResp->res.jsonValue[jsonPtr]["FirmwareRevision"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200483 std::to_string(*revisionCode);
484 }
485
486 if (present != nullptr && !*present)
487 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700488 asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] =
489 resource::State::Absent;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200490 }
491
492 if (memoryTotalWidth != nullptr)
493 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700494 asyncResp->res.jsonValue[jsonPtr]["BusWidthBits"] = *memoryTotalWidth;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200495 }
496
497 if (ecc != nullptr)
498 {
499 constexpr const std::array<const char*, 4> values{
500 "NoECC", "SingleBitECC", "MultiBitECC", "AddressParity"};
501
502 for (const char* v : values)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000503 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200504 if (ecc->ends_with(v))
Nan Zhou9a5acea2022-05-17 21:12:43 +0000505 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700506 asyncResp->res.jsonValue[jsonPtr]["ErrorCorrection"] = v;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200507 break;
Nan Zhou9a5acea2022-05-17 21:12:43 +0000508 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000509 }
510 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200511
512 if (formFactor != nullptr)
513 {
514 constexpr const std::array<const char*, 11> values{
515 "RDIMM", "UDIMM", "SO_DIMM", "LRDIMM",
516 "Mini_RDIMM", "Mini_UDIMM", "SO_RDIMM_72b", "SO_UDIMM_72b",
517 "SO_DIMM_16b", "SO_DIMM_32b", "Die"};
518
519 for (const char* v : values)
520 {
521 if (formFactor->ends_with(v))
522 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700523 asyncResp->res.jsonValue[jsonPtr]["BaseModuleType"] = v;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200524 break;
525 }
526 }
527 }
528
529 if (allowedSpeedsMT != nullptr)
530 {
531 nlohmann::json& jValue =
Ed Tanousac106bf2023-06-07 09:24:59 -0700532 asyncResp->res.jsonValue[jsonPtr]["AllowedSpeedsMHz"];
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200533 jValue = nlohmann::json::array();
534 for (uint16_t subVal : *allowedSpeedsMT)
535 {
536 jValue.push_back(subVal);
537 }
538 }
539
540 if (memoryAttributes != nullptr)
541 {
George Liu6995c1c2023-06-15 08:53:11 +0800542 asyncResp->res.jsonValue[jsonPtr]["RankCount"] = *memoryAttributes;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200543 }
544
545 if (memoryConfiguredSpeedInMhz != nullptr)
546 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700547 asyncResp->res.jsonValue[jsonPtr]["OperatingSpeedMhz"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200548 *memoryConfiguredSpeedInMhz;
549 }
550
551 if (memoryType != nullptr)
552 {
553 std::string memoryDeviceType =
554 translateMemoryTypeToRedfish(*memoryType);
555 // Values like "Unknown" or "Other" will return empty
556 // so just leave off
557 if (!memoryDeviceType.empty())
558 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700559 asyncResp->res.jsonValue[jsonPtr]["MemoryDeviceType"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200560 memoryDeviceType;
561 }
562 if (memoryType->find("DDR") != std::string::npos)
563 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700564 asyncResp->res.jsonValue[jsonPtr]["MemoryType"] =
565 memory::MemoryType::DRAM;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200566 }
567 else if (memoryType->ends_with("Logical"))
568 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700569 asyncResp->res.jsonValue[jsonPtr]["MemoryType"] =
570 memory::MemoryType::IntelOptane;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200571 }
572 }
573
574 if (channel != nullptr)
575 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700576 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Channel"] =
577 *channel;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200578 }
579
580 if (memoryController != nullptr)
581 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400582 asyncResp->res
583 .jsonValue[jsonPtr]["MemoryLocation"]["MemoryController"] =
584 *memoryController;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200585 }
586
587 if (slot != nullptr)
588 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700589 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Slot"] = *slot;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200590 }
591
592 if (socket != nullptr)
593 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700594 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Socket"] = *socket;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200595 }
596
597 if (sparePartNumber != nullptr)
598 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700599 asyncResp->res.jsonValue[jsonPtr]["SparePartNumber"] = *sparePartNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200600 }
601
602 if (model != nullptr)
603 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700604 asyncResp->res.jsonValue[jsonPtr]["Model"] = *model;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200605 }
606
607 if (locationCode != nullptr)
608 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400609 asyncResp->res
610 .jsonValue[jsonPtr]["Location"]["PartLocation"]["ServiceLabel"] =
611 *locationCode;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200612 }
613
Ed Tanousac106bf2023-06-07 09:24:59 -0700614 getPersistentMemoryProperties(asyncResp, properties, jsonPtr);
Nan Zhou9a5acea2022-05-17 21:12:43 +0000615}
616
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400617inline void getDimmDataByService(
618 std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& dimmId,
619 const std::string& service, const std::string& objPath)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200620{
Ed Tanous62598e32023-07-17 17:06:25 -0700621 BMCWEB_LOG_DEBUG("Get available system components.");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800622 dbus::utility::getAllProperties(
623 service, objPath, "",
Ed Tanousac106bf2023-06-07 09:24:59 -0700624 [dimmId, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800625 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800626 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400627 if (ec)
628 {
629 BMCWEB_LOG_DEBUG("DBUS response error");
630 messages::internalError(asyncResp->res);
631 return;
632 }
633 assembleDimmProperties(dimmId, asyncResp, properties,
634 ""_json_pointer);
635 });
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200636}
637
Nan Zhouef00d7d2022-05-20 21:22:32 +0000638inline void assembleDimmPartitionData(
Ed Tanousac106bf2023-06-07 09:24:59 -0700639 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000640 const dbus::utility::DBusPropertiesMap& properties,
641 const nlohmann::json::json_pointer& regionPtr)
Nan Zhouef00d7d2022-05-20 21:22:32 +0000642{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200643 const std::string* memoryClassification = nullptr;
644 const uint64_t* offsetInKiB = nullptr;
645 const std::string* partitionId = nullptr;
646 const bool* passphraseState = nullptr;
647 const uint64_t* sizeInKiB = nullptr;
648
649 const bool success = sdbusplus::unpackPropertiesNoThrow(
650 dbus_utils::UnpackErrorPrinter(), properties, "MemoryClassification",
651 memoryClassification, "OffsetInKiB", offsetInKiB, "PartitionId",
652 partitionId, "PassphraseState", passphraseState, "SizeInKiB",
653 sizeInKiB);
654
655 if (!success)
Nan Zhouef00d7d2022-05-20 21:22:32 +0000656 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700657 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200658 return;
Nan Zhouef00d7d2022-05-20 21:22:32 +0000659 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200660
661 nlohmann::json::object_t partition;
662
663 if (memoryClassification != nullptr)
664 {
665 partition["MemoryClassification"] = *memoryClassification;
666 }
667
668 if (offsetInKiB != nullptr)
669 {
670 partition["OffsetMiB"] = (*offsetInKiB >> 10);
671 }
672
673 if (partitionId != nullptr)
674 {
675 partition["RegionId"] = *partitionId;
676 }
677
678 if (passphraseState != nullptr)
679 {
680 partition["PassphraseEnabled"] = *passphraseState;
681 }
682
683 if (sizeInKiB != nullptr)
684 {
685 partition["SizeMiB"] = (*sizeInKiB >> 10);
686 }
687
Ed Tanousac106bf2023-06-07 09:24:59 -0700688 asyncResp->res.jsonValue[regionPtr].emplace_back(std::move(partition));
Nan Zhouef00d7d2022-05-20 21:22:32 +0000689}
690
Ed Tanousac106bf2023-06-07 09:24:59 -0700691inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000692 const std::string& service,
693 const std::string& path)
James Feist45094ad2020-04-29 14:02:30 -0700694{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800695 dbus::utility::getAllProperties(
696 service, path,
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200697 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition",
Ed Tanousac106bf2023-06-07 09:24:59 -0700698 [asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800699 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800700 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400701 if (ec)
702 {
703 BMCWEB_LOG_DEBUG("DBUS response error");
704 messages::internalError(asyncResp->res);
James Feist45094ad2020-04-29 14:02:30 -0700705
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400706 return;
707 }
708 nlohmann::json::json_pointer regionPtr = "/Regions"_json_pointer;
709 assembleDimmPartitionData(asyncResp, properties, regionPtr);
Ed Tanous002d39b2022-05-31 08:59:27 -0700710 }
James Feist45094ad2020-04-29 14:02:30 -0700711
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200712 );
James Feist45094ad2020-04-29 14:02:30 -0700713}
714
Ed Tanousac106bf2023-06-07 09:24:59 -0700715inline void getDimmData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000716 const std::string& dimmId)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200717{
Ed Tanous62598e32023-07-17 17:06:25 -0700718 BMCWEB_LOG_DEBUG("Get available system dimm resources.");
George Liue99073f2022-12-09 11:06:16 +0800719 constexpr std::array<std::string_view, 2> dimmInterfaces = {
720 "xyz.openbmc_project.Inventory.Item.Dimm",
721 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition"};
722 dbus::utility::getSubTree(
723 "/xyz/openbmc_project/inventory", 0, dimmInterfaces,
Ed Tanousac106bf2023-06-07 09:24:59 -0700724 [dimmId, asyncResp{std::move(asyncResp)}](
George Liue99073f2022-12-09 11:06:16 +0800725 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800726 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400727 if (ec)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200728 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400729 BMCWEB_LOG_DEBUG("DBUS response error");
730 messages::internalError(asyncResp->res);
James Feist45094ad2020-04-29 14:02:30 -0700731
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400732 return;
733 }
734 bool found = false;
735 for (const auto& [rawPath, object] : subtree)
736 {
737 sdbusplus::message::object_path path(rawPath);
738 for (const auto& [service, interfaces] : object)
739 {
740 for (const auto& interface : interfaces)
Nan Zhou76686dc2022-06-17 23:01:51 +0000741 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400742 if (interface ==
743 "xyz.openbmc_project.Inventory.Item.Dimm" &&
744 path.filename() == dimmId)
745 {
746 getDimmDataByService(asyncResp, dimmId, service,
747 rawPath);
748 found = true;
749 }
750
751 // partitions are separate as there can be multiple
752 // per
753 // device, i.e.
754 // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition1
755 // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition2
756 if (interface ==
757 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition" &&
758 path.parent_path().filename() == dimmId)
759 {
760 getDimmPartitionData(asyncResp, service, rawPath);
761 }
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200762 }
763 }
764 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400765 // Object not found
766 if (!found)
767 {
768 messages::resourceNotFound(asyncResp->res, "Memory", dimmId);
769 return;
770 }
771 // Set @odata only if object is found
772 asyncResp->res.jsonValue["@odata.type"] = "#Memory.v1_11_0.Memory";
773 asyncResp->res.jsonValue["@odata.id"] =
774 boost::urls::format("/redfish/v1/Systems/{}/Memory/{}",
775 BMCWEB_REDFISH_SYSTEM_URI_NAME, dimmId);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200776 return;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400777 });
Ed Tanous271584a2019-07-09 16:24:22 -0700778}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200779
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700780inline void requestRoutesMemoryCollection(App& app)
Ed Tanous029573d2019-02-01 10:57:49 -0800781{
Ed Tanous029573d2019-02-01 10:57:49 -0800782 /**
783 * Functions triggers appropriate requests on DBus
784 */
Ed Tanous22d268c2022-05-19 09:39:07 -0700785 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/")
Ed Tanoused398212021-06-09 17:05:54 -0700786 .privileges(redfish::privileges::getMemoryCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700787 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700788 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -0700789 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
790 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400791 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
792 {
793 return;
794 }
795 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
796 {
797 // Option currently returns no systems. TBD
798 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
799 systemName);
800 return;
801 }
802 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
803 {
804 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
805 systemName);
806 return;
807 }
Ed Tanous22d268c2022-05-19 09:39:07 -0700808
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400809 asyncResp->res.jsonValue["@odata.type"] =
810 "#MemoryCollection.MemoryCollection";
811 asyncResp->res.jsonValue["Name"] = "Memory Module Collection";
812 asyncResp->res.jsonValue["@odata.id"] =
813 boost::urls::format("/redfish/v1/Systems/{}/Memory",
814 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200815
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400816 constexpr std::array<std::string_view, 1> interfaces{
817 "xyz.openbmc_project.Inventory.Item.Dimm"};
818 collection_util::getCollectionMembers(
819 asyncResp,
820 boost::urls::format("/redfish/v1/Systems/{}/Memory",
821 BMCWEB_REDFISH_SYSTEM_URI_NAME),
822 interfaces, "/xyz/openbmc_project/inventory");
823 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700824}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200825
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700826inline void requestRoutesMemory(App& app)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200827{
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200828 /**
829 * Functions triggers appropriate requests on DBus
830 */
Ed Tanous22d268c2022-05-19 09:39:07 -0700831 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700832 .privileges(redfish::privileges::getMemory)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700833 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700834 [&app](const crow::Request& req,
835 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -0700836 const std::string& systemName, const std::string& dimmId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400837 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
838 {
839 return;
840 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800841
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400842 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
843 {
844 // Option currently returns no systems. TBD
845 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
846 systemName);
847 return;
848 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800849
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400850 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
851 {
852 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
853 systemName);
854 return;
855 }
Ed Tanous22d268c2022-05-19 09:39:07 -0700856
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400857 getDimmData(asyncResp, dimmId);
858 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700859}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200860
861} // namespace redfish