blob: 59b473ddc13d06b99623668764f13c1c65532559 [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"
Ed Tanousd7857202025-01-28 15:32:26 -08009#include "async_resp.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080010#include "dbus_utility.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080011#include "error_messages.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070012#include "generated/enums/memory.hpp"
13#include "generated/enums/resource.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080014#include "http_request.hpp"
15#include "logging.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080016#include "query.hpp"
17#include "registries/privilege_registry.hpp"
18#include "utils/collection.hpp"
19#include "utils/dbus_utils.hpp"
20#include "utils/hex_utils.hpp"
James Feist35e257a2020-06-05 13:30:51 -070021
Ed Tanousd7857202025-01-28 15:32:26 -080022#include <boost/beast/http/verb.hpp>
George Liue99073f2022-12-09 11:06:16 +080023#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070024#include <boost/url/format.hpp>
Nan Zhoud7f04fd2022-05-01 01:11:07 +000025#include <nlohmann/json.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080026#include <sdbusplus/message/native_types.hpp>
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +020027#include <sdbusplus/unpack_properties.hpp>
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020028
George Liu7a1dbc42022-12-07 16:03:22 +080029#include <array>
Ed Tanousd7857202025-01-28 15:32:26 -080030#include <cstddef>
31#include <cstdint>
32#include <memory>
33#include <string>
George Liu7a1dbc42022-12-07 16:03:22 +080034#include <string_view>
Ed Tanousd7857202025-01-28 15:32:26 -080035#include <utility>
36#include <vector>
George Liu7a1dbc42022-12-07 16:03:22 +080037
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020038namespace redfish
39{
40
Gunnar Mills313efb12020-10-26 16:05:08 -050041inline std::string translateMemoryTypeToRedfish(const std::string& memoryType)
42{
43 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR")
44 {
45 return "DDR";
46 }
47 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2")
48 {
49 return "DDR2";
50 }
51 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR3")
52 {
53 return "DDR3";
54 }
55 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4")
56 {
57 return "DDR4";
58 }
59 if (memoryType ==
60 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4E_SDRAM")
61 {
62 return "DDR4E_SDRAM";
63 }
Mansi Joshi11a2f0f2021-07-19 14:33:27 +053064 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR5")
65 {
66 return "DDR5";
67 }
Gunnar Mills313efb12020-10-26 16:05:08 -050068 if (memoryType ==
69 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR4_SDRAM")
70 {
71 return "LPDDR4_SDRAM";
72 }
73 if (memoryType ==
74 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR3_SDRAM")
75 {
76 return "LPDDR3_SDRAM";
77 }
78 if (memoryType ==
79 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM")
80 {
81 return "DDR2_SDRAM_FB_DIMM";
82 }
George Liu0fda0f12021-11-16 10:06:17 +080083 if (memoryType ==
84 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM_PROB")
Gunnar Mills313efb12020-10-26 16:05:08 -050085 {
86 return "DDR2_SDRAM_FB_DIMM_PROBE";
87 }
88 if (memoryType ==
89 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR_SGRAM")
90 {
91 return "DDR_SGRAM";
92 }
93 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.ROM")
94 {
95 return "ROM";
96 }
97 if (memoryType ==
98 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.SDRAM")
99 {
100 return "SDRAM";
101 }
102 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.EDO")
103 {
104 return "EDO";
105 }
106 if (memoryType ==
107 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.FastPageMode")
108 {
109 return "FastPageMode";
110 }
111 if (memoryType ==
112 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.PipelinedNibble")
113 {
114 return "PipelinedNibble";
115 }
116 if (memoryType ==
117 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.Logical")
118 {
119 return "Logical";
120 }
121 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM")
122 {
123 return "HBM";
124 }
125 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM2")
126 {
127 return "HBM2";
128 }
Tyson Tuckerbearce34d512022-09-13 16:26:15 -0700129 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM3")
130 {
131 return "HBM3";
132 }
Gunnar Mills313efb12020-10-26 16:05:08 -0500133 // This is values like Other or Unknown
134 // Also D-Bus values:
135 // DRAM
136 // EDRAM
137 // VRAM
138 // SRAM
139 // RAM
140 // FLASH
141 // EEPROM
142 // FEPROM
143 // EPROM
144 // CDRAM
145 // ThreeDRAM
146 // RDRAM
147 // FBD2
148 // LPDDR_SDRAM
149 // LPDDR2_SDRAM
Mansi Joshi11a2f0f2021-07-19 14:33:27 +0530150 // LPDDR5_SDRAM
Gunnar Mills313efb12020-10-26 16:05:08 -0500151 return "";
152}
153
Ed Tanousac106bf2023-06-07 09:24:59 -0700154inline void dimmPropToHex(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200155 const char* key, const uint16_t* value,
156 const nlohmann::json::json_pointer& jsonPtr)
James Feistc50e7c62020-07-27 15:39:36 -0700157{
James Feistc50e7c62020-07-27 15:39:36 -0700158 if (value == nullptr)
159 {
James Feistc50e7c62020-07-27 15:39:36 -0700160 return;
161 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700162 asyncResp->res.jsonValue[jsonPtr][key] = "0x" + intToHexString(*value, 4);
James Feistc50e7c62020-07-27 15:39:36 -0700163}
164
zhanghch058d1b46d2021-04-01 11:18:24 +0800165inline void getPersistentMemoryProperties(
Ed Tanousac106bf2023-06-07 09:24:59 -0700166 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200167 const dbus::utility::DBusPropertiesMap& properties,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000168 const nlohmann::json::json_pointer& jsonPtr)
James Feistc50e7c62020-07-27 15:39:36 -0700169{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200170 const uint16_t* moduleManufacturerID = nullptr;
171 const uint16_t* moduleProductID = nullptr;
172 const uint16_t* subsystemVendorID = nullptr;
173 const uint16_t* subsystemDeviceID = nullptr;
174 const uint64_t* volatileRegionSizeLimitInKiB = nullptr;
175 const uint64_t* pmRegionSizeLimitInKiB = nullptr;
176 const uint64_t* volatileSizeInKiB = nullptr;
177 const uint64_t* pmSizeInKiB = nullptr;
178 const uint64_t* cacheSizeInKB = nullptr;
179 const uint64_t* voltaileRegionMaxSizeInKib = nullptr;
180 const uint64_t* pmRegionMaxSizeInKiB = nullptr;
181 const uint64_t* allocationIncrementInKiB = nullptr;
182 const uint64_t* allocationAlignmentInKiB = nullptr;
183 const uint64_t* volatileRegionNumberLimit = nullptr;
184 const uint64_t* pmRegionNumberLimit = nullptr;
185 const uint64_t* spareDeviceCount = nullptr;
186 const bool* isSpareDeviceInUse = nullptr;
187 const bool* isRankSpareEnabled = nullptr;
188 const std::vector<uint32_t>* maxAveragePowerLimitmW = nullptr;
189 const bool* configurationLocked = nullptr;
190 const std::string* allowedMemoryModes = nullptr;
191 const std::string* memoryMedia = nullptr;
192 const bool* configurationLockCapable = nullptr;
193 const bool* dataLockCapable = nullptr;
194 const bool* passphraseCapable = nullptr;
195 const uint64_t* maxPassphraseCount = nullptr;
196 const uint64_t* passphraseLockLimit = nullptr;
James Feistc50e7c62020-07-27 15:39:36 -0700197
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200198 const bool success = sdbusplus::unpackPropertiesNoThrow(
199 dbus_utils::UnpackErrorPrinter(), properties, "ModuleManufacturerID",
200 moduleManufacturerID, "ModuleProductID", moduleProductID,
201 "SubsystemVendorID", subsystemVendorID, "SubsystemDeviceID",
202 subsystemDeviceID, "VolatileRegionSizeLimitInKiB",
203 volatileRegionSizeLimitInKiB, "PmRegionSizeLimitInKiB",
204 pmRegionSizeLimitInKiB, "VolatileSizeInKiB", volatileSizeInKiB,
205 "PmSizeInKiB", pmSizeInKiB, "CacheSizeInKB", cacheSizeInKB,
206 "VoltaileRegionMaxSizeInKib", voltaileRegionMaxSizeInKib,
207 "PmRegionMaxSizeInKiB", pmRegionMaxSizeInKiB,
208 "AllocationIncrementInKiB", allocationIncrementInKiB,
209 "AllocationAlignmentInKiB", allocationAlignmentInKiB,
210 "VolatileRegionNumberLimit", volatileRegionNumberLimit,
211 "PmRegionNumberLimit", pmRegionNumberLimit, "SpareDeviceCount",
212 spareDeviceCount, "IsSpareDeviceInUse", isSpareDeviceInUse,
213 "IsRankSpareEnabled", isRankSpareEnabled, "MaxAveragePowerLimitmW",
214 maxAveragePowerLimitmW, "ConfigurationLocked", configurationLocked,
215 "AllowedMemoryModes", allowedMemoryModes, "MemoryMedia", memoryMedia,
216 "ConfigurationLockCapable", configurationLockCapable, "DataLockCapable",
217 dataLockCapable, "PassphraseCapable", passphraseCapable,
218 "MaxPassphraseCount", maxPassphraseCount, "PassphraseLockLimit",
219 passphraseLockLimit);
220
221 if (!success)
222 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700223 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200224 return;
225 }
226
Ed Tanousac106bf2023-06-07 09:24:59 -0700227 dimmPropToHex(asyncResp, "ModuleManufacturerID", moduleManufacturerID,
228 jsonPtr);
229 dimmPropToHex(asyncResp, "ModuleProductID", moduleProductID, jsonPtr);
230 dimmPropToHex(asyncResp, "MemorySubsystemControllerManufacturerID",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200231 subsystemVendorID, jsonPtr);
Ed Tanousac106bf2023-06-07 09:24:59 -0700232 dimmPropToHex(asyncResp, "MemorySubsystemControllerProductID",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200233 subsystemDeviceID, jsonPtr);
234
235 if (volatileRegionSizeLimitInKiB != nullptr)
236 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700237 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionSizeLimitMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200238 (*volatileRegionSizeLimitInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800239 }
James Feistc50e7c62020-07-27 15:39:36 -0700240
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200241 if (pmRegionSizeLimitInKiB != nullptr)
242 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700243 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionSizeLimitMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200244 (*pmRegionSizeLimitInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800245 }
James Feistc50e7c62020-07-27 15:39:36 -0700246
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200247 if (volatileSizeInKiB != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800248 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700249 asyncResp->res.jsonValue[jsonPtr]["VolatileSizeMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200250 (*volatileSizeInKiB) >> 10;
251 }
252
253 if (pmSizeInKiB != nullptr)
254 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700255 asyncResp->res.jsonValue[jsonPtr]["NonVolatileSizeMiB"] =
256 (*pmSizeInKiB) >> 10;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200257 }
258
259 if (cacheSizeInKB != nullptr)
260 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700261 asyncResp->res.jsonValue[jsonPtr]["CacheSizeMiB"] =
262 (*cacheSizeInKB >> 10);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200263 }
264
265 if (voltaileRegionMaxSizeInKib != nullptr)
266 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700267 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionSizeMaxMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200268 (*voltaileRegionMaxSizeInKib) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800269 }
James Feistc50e7c62020-07-27 15:39:36 -0700270
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200271 if (pmRegionMaxSizeInKiB != nullptr)
272 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700273 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionSizeMaxMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200274 (*pmRegionMaxSizeInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800275 }
James Feistc50e7c62020-07-27 15:39:36 -0700276
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200277 if (allocationIncrementInKiB != nullptr)
278 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700279 asyncResp->res.jsonValue[jsonPtr]["AllocationIncrementMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200280 (*allocationIncrementInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800281 }
James Feistc50e7c62020-07-27 15:39:36 -0700282
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200283 if (allocationAlignmentInKiB != nullptr)
284 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700285 asyncResp->res.jsonValue[jsonPtr]["AllocationAlignmentMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200286 (*allocationAlignmentInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800287 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200288
289 if (volatileRegionNumberLimit != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800290 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700291 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionNumberLimit"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200292 *volatileRegionNumberLimit;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800293 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200294
295 if (pmRegionNumberLimit != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800296 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700297 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionNumberLimit"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200298 *pmRegionNumberLimit;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800299 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200300
301 if (spareDeviceCount != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800302 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700303 asyncResp->res.jsonValue[jsonPtr]["SpareDeviceCount"] =
304 *spareDeviceCount;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800305 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200306
307 if (isSpareDeviceInUse != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800308 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700309 asyncResp->res.jsonValue[jsonPtr]["IsSpareDeviceEnabled"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200310 *isSpareDeviceInUse;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800311 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200312
313 if (isRankSpareEnabled != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800314 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700315 asyncResp->res.jsonValue[jsonPtr]["IsRankSpareEnabled"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200316 *isRankSpareEnabled;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800317 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200318
319 if (maxAveragePowerLimitmW != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800320 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700321 asyncResp->res.jsonValue[jsonPtr]["MaxTDPMilliWatts"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200322 *maxAveragePowerLimitmW;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800323 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200324
325 if (configurationLocked != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800326 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700327 asyncResp->res.jsonValue[jsonPtr]["ConfigurationLocked"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200328 *configurationLocked;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800329 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200330
331 if (allowedMemoryModes != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800332 {
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800333 constexpr const std::array<const char*, 3> values{"Volatile", "PMEM",
334 "Block"};
James Feistc50e7c62020-07-27 15:39:36 -0700335
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800336 for (const char* v : values)
337 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200338 if (allowedMemoryModes->ends_with(v))
James Feistc50e7c62020-07-27 15:39:36 -0700339 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700340 asyncResp->res.jsonValue[jsonPtr]["OperatingMemoryModes"]
341 .push_back(v);
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800342 break;
James Feistc50e7c62020-07-27 15:39:36 -0700343 }
344 }
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800345 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200346
347 if (memoryMedia != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800348 {
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800349 constexpr const std::array<const char*, 3> values{"DRAM", "NAND",
350 "Intel3DXPoint"};
James Feistc50e7c62020-07-27 15:39:36 -0700351
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800352 for (const char* v : values)
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700353 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200354 if (memoryMedia->ends_with(v))
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700355 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700356 asyncResp->res.jsonValue[jsonPtr]["MemoryMedia"].push_back(v);
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800357 break;
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700358 }
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700359 }
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800360 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200361
362 if (configurationLockCapable != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800363 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700364 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
365 ["ConfigurationLockCapable"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200366 *configurationLockCapable;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800367 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200368
369 if (dataLockCapable != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800370 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400371 asyncResp->res
372 .jsonValue[jsonPtr]["SecurityCapabilities"]["DataLockCapable"] =
373 *dataLockCapable;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200374 }
375
376 if (passphraseCapable != nullptr)
377 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400378 asyncResp->res
379 .jsonValue[jsonPtr]["SecurityCapabilities"]["PassphraseCapable"] =
380 *passphraseCapable;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200381 }
382
383 if (maxPassphraseCount != nullptr)
384 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400385 asyncResp->res
386 .jsonValue[jsonPtr]["SecurityCapabilities"]["MaxPassphraseCount"] =
387 *maxPassphraseCount;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200388 }
389
390 if (passphraseLockLimit != nullptr)
391 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400392 asyncResp->res
393 .jsonValue[jsonPtr]["SecurityCapabilities"]["PassphraseLockLimit"] =
394 *passphraseLockLimit;
James Feistc50e7c62020-07-27 15:39:36 -0700395 }
396}
397
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400398inline void assembleDimmProperties(
399 std::string_view dimmId,
400 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
401 const dbus::utility::DBusPropertiesMap& properties,
402 const nlohmann::json::json_pointer& jsonPtr)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000403{
Ed Tanousac106bf2023-06-07 09:24:59 -0700404 asyncResp->res.jsonValue[jsonPtr]["Id"] = dimmId;
405 asyncResp->res.jsonValue[jsonPtr]["Name"] = "DIMM Slot";
Ed Tanous539d8c62024-06-19 14:38:27 -0700406 asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] =
407 resource::State::Enabled;
408 asyncResp->res.jsonValue[jsonPtr]["Status"]["Health"] =
409 resource::Health::OK;
Nan Zhou9a5acea2022-05-17 21:12:43 +0000410
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200411 const uint16_t* memoryDataWidth = nullptr;
412 const size_t* memorySizeInKB = nullptr;
413 const std::string* partNumber = nullptr;
414 const std::string* serialNumber = nullptr;
415 const std::string* manufacturer = nullptr;
416 const uint16_t* revisionCode = nullptr;
417 const bool* present = nullptr;
418 const uint16_t* memoryTotalWidth = nullptr;
419 const std::string* ecc = nullptr;
420 const std::string* formFactor = nullptr;
421 const std::vector<uint16_t>* allowedSpeedsMT = nullptr;
George Liu6995c1c2023-06-15 08:53:11 +0800422 const size_t* memoryAttributes = nullptr;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200423 const uint16_t* memoryConfiguredSpeedInMhz = nullptr;
424 const std::string* memoryType = nullptr;
Jayaprakash Mutyala6fde5972023-06-15 07:56:58 +0000425 const std::uint8_t* channel = nullptr;
426 const std::uint8_t* memoryController = nullptr;
427 const std::uint8_t* slot = nullptr;
428 const std::uint8_t* socket = nullptr;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200429 const std::string* sparePartNumber = nullptr;
430 const std::string* model = nullptr;
431 const std::string* locationCode = nullptr;
George Liu7fe6d532024-03-06 09:01:37 +0800432 const bool* functional = nullptr;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200433
434 const bool success = sdbusplus::unpackPropertiesNoThrow(
435 dbus_utils::UnpackErrorPrinter(), properties, "MemoryDataWidth",
436 memoryDataWidth, "MemorySizeInKB", memorySizeInKB, "PartNumber",
Nikhil Namjoshi656472d2022-09-13 20:54:44 +0000437 partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer,
438 "RevisionCode", revisionCode, "Present", present, "MemoryTotalWidth",
439 memoryTotalWidth, "ECC", ecc, "FormFactor", formFactor,
440 "AllowedSpeedsMT", allowedSpeedsMT, "MemoryAttributes",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200441 memoryAttributes, "MemoryConfiguredSpeedInMhz",
442 memoryConfiguredSpeedInMhz, "MemoryType", memoryType, "Channel",
443 channel, "MemoryController", memoryController, "Slot", slot, "Socket",
444 socket, "SparePartNumber", sparePartNumber, "Model", model,
George Liu7fe6d532024-03-06 09:01:37 +0800445 "LocationCode", locationCode, "Functional", functional);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200446
447 if (!success)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000448 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700449 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200450 return;
451 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000452
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200453 if (memoryDataWidth != nullptr)
454 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700455 asyncResp->res.jsonValue[jsonPtr]["DataWidthBits"] = *memoryDataWidth;
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 (memorySizeInKB != nullptr)
459 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700460 asyncResp->res.jsonValue[jsonPtr]["CapacityMiB"] =
461 (*memorySizeInKB >> 10);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200462 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000463
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200464 if (partNumber != nullptr)
465 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700466 asyncResp->res.jsonValue[jsonPtr]["PartNumber"] = *partNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200467 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000468
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200469 if (serialNumber != nullptr)
470 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700471 asyncResp->res.jsonValue[jsonPtr]["SerialNumber"] = *serialNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200472 }
473
474 if (manufacturer != nullptr)
475 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700476 asyncResp->res.jsonValue[jsonPtr]["Manufacturer"] = *manufacturer;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200477 }
478
479 if (revisionCode != nullptr)
480 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700481 asyncResp->res.jsonValue[jsonPtr]["FirmwareRevision"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200482 std::to_string(*revisionCode);
483 }
484
485 if (present != nullptr && !*present)
486 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700487 asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] =
488 resource::State::Absent;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200489 }
490
George Liu7fe6d532024-03-06 09:01:37 +0800491 if (functional != nullptr)
492 {
493 if (!*functional)
494 {
495 asyncResp->res.jsonValue[jsonPtr]["Status"]["Health"] =
496 resource::Health::Critical;
497 }
498 }
499
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200500 if (memoryTotalWidth != nullptr)
501 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700502 asyncResp->res.jsonValue[jsonPtr]["BusWidthBits"] = *memoryTotalWidth;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200503 }
504
505 if (ecc != nullptr)
506 {
507 constexpr const std::array<const char*, 4> values{
508 "NoECC", "SingleBitECC", "MultiBitECC", "AddressParity"};
509
510 for (const char* v : values)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000511 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200512 if (ecc->ends_with(v))
Nan Zhou9a5acea2022-05-17 21:12:43 +0000513 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700514 asyncResp->res.jsonValue[jsonPtr]["ErrorCorrection"] = v;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200515 break;
Nan Zhou9a5acea2022-05-17 21:12:43 +0000516 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000517 }
518 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200519
520 if (formFactor != nullptr)
521 {
522 constexpr const std::array<const char*, 11> values{
523 "RDIMM", "UDIMM", "SO_DIMM", "LRDIMM",
524 "Mini_RDIMM", "Mini_UDIMM", "SO_RDIMM_72b", "SO_UDIMM_72b",
525 "SO_DIMM_16b", "SO_DIMM_32b", "Die"};
526
527 for (const char* v : values)
528 {
529 if (formFactor->ends_with(v))
530 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700531 asyncResp->res.jsonValue[jsonPtr]["BaseModuleType"] = v;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200532 break;
533 }
534 }
535 }
536
537 if (allowedSpeedsMT != nullptr)
538 {
539 nlohmann::json& jValue =
Ed Tanousac106bf2023-06-07 09:24:59 -0700540 asyncResp->res.jsonValue[jsonPtr]["AllowedSpeedsMHz"];
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200541 jValue = nlohmann::json::array();
542 for (uint16_t subVal : *allowedSpeedsMT)
543 {
544 jValue.push_back(subVal);
545 }
546 }
547
548 if (memoryAttributes != nullptr)
549 {
George Liu6995c1c2023-06-15 08:53:11 +0800550 asyncResp->res.jsonValue[jsonPtr]["RankCount"] = *memoryAttributes;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200551 }
552
553 if (memoryConfiguredSpeedInMhz != nullptr)
554 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700555 asyncResp->res.jsonValue[jsonPtr]["OperatingSpeedMhz"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200556 *memoryConfiguredSpeedInMhz;
557 }
558
559 if (memoryType != nullptr)
560 {
561 std::string memoryDeviceType =
562 translateMemoryTypeToRedfish(*memoryType);
563 // Values like "Unknown" or "Other" will return empty
564 // so just leave off
565 if (!memoryDeviceType.empty())
566 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700567 asyncResp->res.jsonValue[jsonPtr]["MemoryDeviceType"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200568 memoryDeviceType;
569 }
570 if (memoryType->find("DDR") != std::string::npos)
571 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700572 asyncResp->res.jsonValue[jsonPtr]["MemoryType"] =
573 memory::MemoryType::DRAM;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200574 }
575 else if (memoryType->ends_with("Logical"))
576 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700577 asyncResp->res.jsonValue[jsonPtr]["MemoryType"] =
578 memory::MemoryType::IntelOptane;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200579 }
580 }
581
582 if (channel != nullptr)
583 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700584 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Channel"] =
585 *channel;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200586 }
587
588 if (memoryController != nullptr)
589 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400590 asyncResp->res
591 .jsonValue[jsonPtr]["MemoryLocation"]["MemoryController"] =
592 *memoryController;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200593 }
594
595 if (slot != nullptr)
596 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700597 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Slot"] = *slot;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200598 }
599
600 if (socket != nullptr)
601 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700602 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Socket"] = *socket;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200603 }
604
605 if (sparePartNumber != nullptr)
606 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700607 asyncResp->res.jsonValue[jsonPtr]["SparePartNumber"] = *sparePartNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200608 }
609
610 if (model != nullptr)
611 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700612 asyncResp->res.jsonValue[jsonPtr]["Model"] = *model;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200613 }
614
615 if (locationCode != nullptr)
616 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400617 asyncResp->res
618 .jsonValue[jsonPtr]["Location"]["PartLocation"]["ServiceLabel"] =
619 *locationCode;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200620 }
621
Ed Tanousac106bf2023-06-07 09:24:59 -0700622 getPersistentMemoryProperties(asyncResp, properties, jsonPtr);
Nan Zhou9a5acea2022-05-17 21:12:43 +0000623}
624
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400625inline void getDimmDataByService(
626 std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& dimmId,
627 const std::string& service, const std::string& objPath)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200628{
Ed Tanous62598e32023-07-17 17:06:25 -0700629 BMCWEB_LOG_DEBUG("Get available system components.");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800630 dbus::utility::getAllProperties(
631 service, objPath, "",
Ed Tanousac106bf2023-06-07 09:24:59 -0700632 [dimmId, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800633 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800634 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400635 if (ec)
636 {
637 BMCWEB_LOG_DEBUG("DBUS response error");
638 messages::internalError(asyncResp->res);
639 return;
640 }
641 assembleDimmProperties(dimmId, asyncResp, properties,
642 ""_json_pointer);
643 });
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200644}
645
Nan Zhouef00d7d2022-05-20 21:22:32 +0000646inline void assembleDimmPartitionData(
Ed Tanousac106bf2023-06-07 09:24:59 -0700647 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000648 const dbus::utility::DBusPropertiesMap& properties,
649 const nlohmann::json::json_pointer& regionPtr)
Nan Zhouef00d7d2022-05-20 21:22:32 +0000650{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200651 const std::string* memoryClassification = nullptr;
652 const uint64_t* offsetInKiB = nullptr;
653 const std::string* partitionId = nullptr;
654 const bool* passphraseState = nullptr;
655 const uint64_t* sizeInKiB = nullptr;
656
657 const bool success = sdbusplus::unpackPropertiesNoThrow(
658 dbus_utils::UnpackErrorPrinter(), properties, "MemoryClassification",
659 memoryClassification, "OffsetInKiB", offsetInKiB, "PartitionId",
660 partitionId, "PassphraseState", passphraseState, "SizeInKiB",
661 sizeInKiB);
662
663 if (!success)
Nan Zhouef00d7d2022-05-20 21:22:32 +0000664 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700665 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200666 return;
Nan Zhouef00d7d2022-05-20 21:22:32 +0000667 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200668
669 nlohmann::json::object_t partition;
670
671 if (memoryClassification != nullptr)
672 {
673 partition["MemoryClassification"] = *memoryClassification;
674 }
675
676 if (offsetInKiB != nullptr)
677 {
678 partition["OffsetMiB"] = (*offsetInKiB >> 10);
679 }
680
681 if (partitionId != nullptr)
682 {
683 partition["RegionId"] = *partitionId;
684 }
685
686 if (passphraseState != nullptr)
687 {
688 partition["PassphraseEnabled"] = *passphraseState;
689 }
690
691 if (sizeInKiB != nullptr)
692 {
693 partition["SizeMiB"] = (*sizeInKiB >> 10);
694 }
695
Ed Tanousac106bf2023-06-07 09:24:59 -0700696 asyncResp->res.jsonValue[regionPtr].emplace_back(std::move(partition));
Nan Zhouef00d7d2022-05-20 21:22:32 +0000697}
698
Ed Tanousac106bf2023-06-07 09:24:59 -0700699inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000700 const std::string& service,
701 const std::string& path)
James Feist45094ad2020-04-29 14:02:30 -0700702{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800703 dbus::utility::getAllProperties(
704 service, path,
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200705 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition",
Ed Tanousac106bf2023-06-07 09:24:59 -0700706 [asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800707 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800708 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400709 if (ec)
710 {
711 BMCWEB_LOG_DEBUG("DBUS response error");
712 messages::internalError(asyncResp->res);
James Feist45094ad2020-04-29 14:02:30 -0700713
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400714 return;
715 }
716 nlohmann::json::json_pointer regionPtr = "/Regions"_json_pointer;
717 assembleDimmPartitionData(asyncResp, properties, regionPtr);
Ed Tanous002d39b2022-05-31 08:59:27 -0700718 }
James Feist45094ad2020-04-29 14:02:30 -0700719
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200720 );
James Feist45094ad2020-04-29 14:02:30 -0700721}
722
Ed Tanousac106bf2023-06-07 09:24:59 -0700723inline void getDimmData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000724 const std::string& dimmId)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200725{
Ed Tanous62598e32023-07-17 17:06:25 -0700726 BMCWEB_LOG_DEBUG("Get available system dimm resources.");
George Liue99073f2022-12-09 11:06:16 +0800727 constexpr std::array<std::string_view, 2> dimmInterfaces = {
728 "xyz.openbmc_project.Inventory.Item.Dimm",
729 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition"};
730 dbus::utility::getSubTree(
731 "/xyz/openbmc_project/inventory", 0, dimmInterfaces,
Ed Tanousac106bf2023-06-07 09:24:59 -0700732 [dimmId, asyncResp{std::move(asyncResp)}](
George Liue99073f2022-12-09 11:06:16 +0800733 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800734 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400735 if (ec)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200736 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400737 BMCWEB_LOG_DEBUG("DBUS response error");
738 messages::internalError(asyncResp->res);
James Feist45094ad2020-04-29 14:02:30 -0700739
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400740 return;
741 }
742 bool found = false;
743 for (const auto& [rawPath, object] : subtree)
744 {
745 sdbusplus::message::object_path path(rawPath);
746 for (const auto& [service, interfaces] : object)
747 {
748 for (const auto& interface : interfaces)
Nan Zhou76686dc2022-06-17 23:01:51 +0000749 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400750 if (interface ==
751 "xyz.openbmc_project.Inventory.Item.Dimm" &&
752 path.filename() == dimmId)
753 {
754 getDimmDataByService(asyncResp, dimmId, service,
755 rawPath);
756 found = true;
757 }
758
759 // partitions are separate as there can be multiple
760 // per
761 // device, i.e.
762 // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition1
763 // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition2
764 if (interface ==
765 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition" &&
766 path.parent_path().filename() == dimmId)
767 {
768 getDimmPartitionData(asyncResp, service, rawPath);
769 }
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200770 }
771 }
772 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400773 // Object not found
774 if (!found)
775 {
776 messages::resourceNotFound(asyncResp->res, "Memory", dimmId);
777 return;
778 }
779 // Set @odata only if object is found
780 asyncResp->res.jsonValue["@odata.type"] = "#Memory.v1_11_0.Memory";
781 asyncResp->res.jsonValue["@odata.id"] =
782 boost::urls::format("/redfish/v1/Systems/{}/Memory/{}",
783 BMCWEB_REDFISH_SYSTEM_URI_NAME, dimmId);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200784 return;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400785 });
Ed Tanous271584a2019-07-09 16:24:22 -0700786}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200787
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700788inline void requestRoutesMemoryCollection(App& app)
Ed Tanous029573d2019-02-01 10:57:49 -0800789{
Ed Tanous029573d2019-02-01 10:57:49 -0800790 /**
791 * Functions triggers appropriate requests on DBus
792 */
Ed Tanous22d268c2022-05-19 09:39:07 -0700793 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/")
Ed Tanoused398212021-06-09 17:05:54 -0700794 .privileges(redfish::privileges::getMemoryCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700795 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700796 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -0700797 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
798 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400799 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
800 {
801 return;
802 }
803 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
804 {
805 // Option currently returns no systems. TBD
806 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
807 systemName);
808 return;
809 }
810 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
811 {
812 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
813 systemName);
814 return;
815 }
Ed Tanous22d268c2022-05-19 09:39:07 -0700816
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400817 asyncResp->res.jsonValue["@odata.type"] =
818 "#MemoryCollection.MemoryCollection";
819 asyncResp->res.jsonValue["Name"] = "Memory Module Collection";
820 asyncResp->res.jsonValue["@odata.id"] =
821 boost::urls::format("/redfish/v1/Systems/{}/Memory",
822 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200823
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400824 constexpr std::array<std::string_view, 1> interfaces{
825 "xyz.openbmc_project.Inventory.Item.Dimm"};
826 collection_util::getCollectionMembers(
827 asyncResp,
828 boost::urls::format("/redfish/v1/Systems/{}/Memory",
829 BMCWEB_REDFISH_SYSTEM_URI_NAME),
830 interfaces, "/xyz/openbmc_project/inventory");
831 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700832}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200833
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700834inline void requestRoutesMemory(App& app)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200835{
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200836 /**
837 * Functions triggers appropriate requests on DBus
838 */
Ed Tanous22d268c2022-05-19 09:39:07 -0700839 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700840 .privileges(redfish::privileges::getMemory)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700841 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700842 [&app](const crow::Request& req,
843 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -0700844 const std::string& systemName, const std::string& dimmId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400845 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
846 {
847 return;
848 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800849
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400850 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
851 {
852 // Option currently returns no systems. TBD
853 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
854 systemName);
855 return;
856 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800857
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400858 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
859 {
860 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
861 systemName);
862 return;
863 }
Ed Tanous22d268c2022-05-19 09:39:07 -0700864
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400865 getDimmData(asyncResp, dimmId);
866 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700867}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200868
869} // namespace redfish