blob: e9ceb7fbf7c8aadd57c8b64f7936f4e72dbd0865 [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;
432
433 const bool success = sdbusplus::unpackPropertiesNoThrow(
434 dbus_utils::UnpackErrorPrinter(), properties, "MemoryDataWidth",
435 memoryDataWidth, "MemorySizeInKB", memorySizeInKB, "PartNumber",
Nikhil Namjoshi656472d2022-09-13 20:54:44 +0000436 partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer,
437 "RevisionCode", revisionCode, "Present", present, "MemoryTotalWidth",
438 memoryTotalWidth, "ECC", ecc, "FormFactor", formFactor,
439 "AllowedSpeedsMT", allowedSpeedsMT, "MemoryAttributes",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200440 memoryAttributes, "MemoryConfiguredSpeedInMhz",
441 memoryConfiguredSpeedInMhz, "MemoryType", memoryType, "Channel",
442 channel, "MemoryController", memoryController, "Slot", slot, "Socket",
443 socket, "SparePartNumber", sparePartNumber, "Model", model,
444 "LocationCode", locationCode);
445
446 if (!success)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000447 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700448 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200449 return;
450 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000451
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200452 if (memoryDataWidth != nullptr)
453 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700454 asyncResp->res.jsonValue[jsonPtr]["DataWidthBits"] = *memoryDataWidth;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200455 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000456
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200457 if (memorySizeInKB != nullptr)
458 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700459 asyncResp->res.jsonValue[jsonPtr]["CapacityMiB"] =
460 (*memorySizeInKB >> 10);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200461 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000462
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200463 if (partNumber != nullptr)
464 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700465 asyncResp->res.jsonValue[jsonPtr]["PartNumber"] = *partNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200466 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000467
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200468 if (serialNumber != nullptr)
469 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700470 asyncResp->res.jsonValue[jsonPtr]["SerialNumber"] = *serialNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200471 }
472
473 if (manufacturer != nullptr)
474 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700475 asyncResp->res.jsonValue[jsonPtr]["Manufacturer"] = *manufacturer;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200476 }
477
478 if (revisionCode != nullptr)
479 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700480 asyncResp->res.jsonValue[jsonPtr]["FirmwareRevision"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200481 std::to_string(*revisionCode);
482 }
483
484 if (present != nullptr && !*present)
485 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700486 asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] =
487 resource::State::Absent;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200488 }
489
490 if (memoryTotalWidth != nullptr)
491 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700492 asyncResp->res.jsonValue[jsonPtr]["BusWidthBits"] = *memoryTotalWidth;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200493 }
494
495 if (ecc != nullptr)
496 {
497 constexpr const std::array<const char*, 4> values{
498 "NoECC", "SingleBitECC", "MultiBitECC", "AddressParity"};
499
500 for (const char* v : values)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000501 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200502 if (ecc->ends_with(v))
Nan Zhou9a5acea2022-05-17 21:12:43 +0000503 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700504 asyncResp->res.jsonValue[jsonPtr]["ErrorCorrection"] = v;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200505 break;
Nan Zhou9a5acea2022-05-17 21:12:43 +0000506 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000507 }
508 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200509
510 if (formFactor != nullptr)
511 {
512 constexpr const std::array<const char*, 11> values{
513 "RDIMM", "UDIMM", "SO_DIMM", "LRDIMM",
514 "Mini_RDIMM", "Mini_UDIMM", "SO_RDIMM_72b", "SO_UDIMM_72b",
515 "SO_DIMM_16b", "SO_DIMM_32b", "Die"};
516
517 for (const char* v : values)
518 {
519 if (formFactor->ends_with(v))
520 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700521 asyncResp->res.jsonValue[jsonPtr]["BaseModuleType"] = v;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200522 break;
523 }
524 }
525 }
526
527 if (allowedSpeedsMT != nullptr)
528 {
529 nlohmann::json& jValue =
Ed Tanousac106bf2023-06-07 09:24:59 -0700530 asyncResp->res.jsonValue[jsonPtr]["AllowedSpeedsMHz"];
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200531 jValue = nlohmann::json::array();
532 for (uint16_t subVal : *allowedSpeedsMT)
533 {
534 jValue.push_back(subVal);
535 }
536 }
537
538 if (memoryAttributes != nullptr)
539 {
George Liu6995c1c2023-06-15 08:53:11 +0800540 asyncResp->res.jsonValue[jsonPtr]["RankCount"] = *memoryAttributes;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200541 }
542
543 if (memoryConfiguredSpeedInMhz != nullptr)
544 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700545 asyncResp->res.jsonValue[jsonPtr]["OperatingSpeedMhz"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200546 *memoryConfiguredSpeedInMhz;
547 }
548
549 if (memoryType != nullptr)
550 {
551 std::string memoryDeviceType =
552 translateMemoryTypeToRedfish(*memoryType);
553 // Values like "Unknown" or "Other" will return empty
554 // so just leave off
555 if (!memoryDeviceType.empty())
556 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700557 asyncResp->res.jsonValue[jsonPtr]["MemoryDeviceType"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200558 memoryDeviceType;
559 }
560 if (memoryType->find("DDR") != std::string::npos)
561 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700562 asyncResp->res.jsonValue[jsonPtr]["MemoryType"] =
563 memory::MemoryType::DRAM;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200564 }
565 else if (memoryType->ends_with("Logical"))
566 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700567 asyncResp->res.jsonValue[jsonPtr]["MemoryType"] =
568 memory::MemoryType::IntelOptane;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200569 }
570 }
571
572 if (channel != nullptr)
573 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700574 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Channel"] =
575 *channel;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200576 }
577
578 if (memoryController != nullptr)
579 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400580 asyncResp->res
581 .jsonValue[jsonPtr]["MemoryLocation"]["MemoryController"] =
582 *memoryController;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200583 }
584
585 if (slot != nullptr)
586 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700587 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Slot"] = *slot;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200588 }
589
590 if (socket != nullptr)
591 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700592 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Socket"] = *socket;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200593 }
594
595 if (sparePartNumber != nullptr)
596 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700597 asyncResp->res.jsonValue[jsonPtr]["SparePartNumber"] = *sparePartNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200598 }
599
600 if (model != nullptr)
601 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700602 asyncResp->res.jsonValue[jsonPtr]["Model"] = *model;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200603 }
604
605 if (locationCode != nullptr)
606 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400607 asyncResp->res
608 .jsonValue[jsonPtr]["Location"]["PartLocation"]["ServiceLabel"] =
609 *locationCode;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200610 }
611
Ed Tanousac106bf2023-06-07 09:24:59 -0700612 getPersistentMemoryProperties(asyncResp, properties, jsonPtr);
Nan Zhou9a5acea2022-05-17 21:12:43 +0000613}
614
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400615inline void getDimmDataByService(
616 std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& dimmId,
617 const std::string& service, const std::string& objPath)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200618{
Ed Tanous62598e32023-07-17 17:06:25 -0700619 BMCWEB_LOG_DEBUG("Get available system components.");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800620 dbus::utility::getAllProperties(
621 service, objPath, "",
Ed Tanousac106bf2023-06-07 09:24:59 -0700622 [dimmId, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800623 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800624 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400625 if (ec)
626 {
627 BMCWEB_LOG_DEBUG("DBUS response error");
628 messages::internalError(asyncResp->res);
629 return;
630 }
631 assembleDimmProperties(dimmId, asyncResp, properties,
632 ""_json_pointer);
633 });
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200634}
635
Nan Zhouef00d7d2022-05-20 21:22:32 +0000636inline void assembleDimmPartitionData(
Ed Tanousac106bf2023-06-07 09:24:59 -0700637 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000638 const dbus::utility::DBusPropertiesMap& properties,
639 const nlohmann::json::json_pointer& regionPtr)
Nan Zhouef00d7d2022-05-20 21:22:32 +0000640{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200641 const std::string* memoryClassification = nullptr;
642 const uint64_t* offsetInKiB = nullptr;
643 const std::string* partitionId = nullptr;
644 const bool* passphraseState = nullptr;
645 const uint64_t* sizeInKiB = nullptr;
646
647 const bool success = sdbusplus::unpackPropertiesNoThrow(
648 dbus_utils::UnpackErrorPrinter(), properties, "MemoryClassification",
649 memoryClassification, "OffsetInKiB", offsetInKiB, "PartitionId",
650 partitionId, "PassphraseState", passphraseState, "SizeInKiB",
651 sizeInKiB);
652
653 if (!success)
Nan Zhouef00d7d2022-05-20 21:22:32 +0000654 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700655 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200656 return;
Nan Zhouef00d7d2022-05-20 21:22:32 +0000657 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200658
659 nlohmann::json::object_t partition;
660
661 if (memoryClassification != nullptr)
662 {
663 partition["MemoryClassification"] = *memoryClassification;
664 }
665
666 if (offsetInKiB != nullptr)
667 {
668 partition["OffsetMiB"] = (*offsetInKiB >> 10);
669 }
670
671 if (partitionId != nullptr)
672 {
673 partition["RegionId"] = *partitionId;
674 }
675
676 if (passphraseState != nullptr)
677 {
678 partition["PassphraseEnabled"] = *passphraseState;
679 }
680
681 if (sizeInKiB != nullptr)
682 {
683 partition["SizeMiB"] = (*sizeInKiB >> 10);
684 }
685
Ed Tanousac106bf2023-06-07 09:24:59 -0700686 asyncResp->res.jsonValue[regionPtr].emplace_back(std::move(partition));
Nan Zhouef00d7d2022-05-20 21:22:32 +0000687}
688
Ed Tanousac106bf2023-06-07 09:24:59 -0700689inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000690 const std::string& service,
691 const std::string& path)
James Feist45094ad2020-04-29 14:02:30 -0700692{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800693 dbus::utility::getAllProperties(
694 service, path,
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200695 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition",
Ed Tanousac106bf2023-06-07 09:24:59 -0700696 [asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800697 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800698 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400699 if (ec)
700 {
701 BMCWEB_LOG_DEBUG("DBUS response error");
702 messages::internalError(asyncResp->res);
James Feist45094ad2020-04-29 14:02:30 -0700703
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400704 return;
705 }
706 nlohmann::json::json_pointer regionPtr = "/Regions"_json_pointer;
707 assembleDimmPartitionData(asyncResp, properties, regionPtr);
Ed Tanous002d39b2022-05-31 08:59:27 -0700708 }
James Feist45094ad2020-04-29 14:02:30 -0700709
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200710 );
James Feist45094ad2020-04-29 14:02:30 -0700711}
712
Ed Tanousac106bf2023-06-07 09:24:59 -0700713inline void getDimmData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000714 const std::string& dimmId)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200715{
Ed Tanous62598e32023-07-17 17:06:25 -0700716 BMCWEB_LOG_DEBUG("Get available system dimm resources.");
George Liue99073f2022-12-09 11:06:16 +0800717 constexpr std::array<std::string_view, 2> dimmInterfaces = {
718 "xyz.openbmc_project.Inventory.Item.Dimm",
719 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition"};
720 dbus::utility::getSubTree(
721 "/xyz/openbmc_project/inventory", 0, dimmInterfaces,
Ed Tanousac106bf2023-06-07 09:24:59 -0700722 [dimmId, asyncResp{std::move(asyncResp)}](
George Liue99073f2022-12-09 11:06:16 +0800723 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800724 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400725 if (ec)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200726 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400727 BMCWEB_LOG_DEBUG("DBUS response error");
728 messages::internalError(asyncResp->res);
James Feist45094ad2020-04-29 14:02:30 -0700729
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400730 return;
731 }
732 bool found = false;
733 for (const auto& [rawPath, object] : subtree)
734 {
735 sdbusplus::message::object_path path(rawPath);
736 for (const auto& [service, interfaces] : object)
737 {
738 for (const auto& interface : interfaces)
Nan Zhou76686dc2022-06-17 23:01:51 +0000739 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400740 if (interface ==
741 "xyz.openbmc_project.Inventory.Item.Dimm" &&
742 path.filename() == dimmId)
743 {
744 getDimmDataByService(asyncResp, dimmId, service,
745 rawPath);
746 found = true;
747 }
748
749 // partitions are separate as there can be multiple
750 // per
751 // device, i.e.
752 // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition1
753 // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition2
754 if (interface ==
755 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition" &&
756 path.parent_path().filename() == dimmId)
757 {
758 getDimmPartitionData(asyncResp, service, rawPath);
759 }
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200760 }
761 }
762 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400763 // Object not found
764 if (!found)
765 {
766 messages::resourceNotFound(asyncResp->res, "Memory", dimmId);
767 return;
768 }
769 // Set @odata only if object is found
770 asyncResp->res.jsonValue["@odata.type"] = "#Memory.v1_11_0.Memory";
771 asyncResp->res.jsonValue["@odata.id"] =
772 boost::urls::format("/redfish/v1/Systems/{}/Memory/{}",
773 BMCWEB_REDFISH_SYSTEM_URI_NAME, dimmId);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200774 return;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400775 });
Ed Tanous271584a2019-07-09 16:24:22 -0700776}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200777
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700778inline void requestRoutesMemoryCollection(App& app)
Ed Tanous029573d2019-02-01 10:57:49 -0800779{
Ed Tanous029573d2019-02-01 10:57:49 -0800780 /**
781 * Functions triggers appropriate requests on DBus
782 */
Ed Tanous22d268c2022-05-19 09:39:07 -0700783 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/")
Ed Tanoused398212021-06-09 17:05:54 -0700784 .privileges(redfish::privileges::getMemoryCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700785 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700786 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -0700787 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
788 const std::string& systemName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400789 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
790 {
791 return;
792 }
793 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
794 {
795 // Option currently returns no systems. TBD
796 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
797 systemName);
798 return;
799 }
800 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
801 {
802 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
803 systemName);
804 return;
805 }
Ed Tanous22d268c2022-05-19 09:39:07 -0700806
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400807 asyncResp->res.jsonValue["@odata.type"] =
808 "#MemoryCollection.MemoryCollection";
809 asyncResp->res.jsonValue["Name"] = "Memory Module Collection";
810 asyncResp->res.jsonValue["@odata.id"] =
811 boost::urls::format("/redfish/v1/Systems/{}/Memory",
812 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200813
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400814 constexpr std::array<std::string_view, 1> interfaces{
815 "xyz.openbmc_project.Inventory.Item.Dimm"};
816 collection_util::getCollectionMembers(
817 asyncResp,
818 boost::urls::format("/redfish/v1/Systems/{}/Memory",
819 BMCWEB_REDFISH_SYSTEM_URI_NAME),
820 interfaces, "/xyz/openbmc_project/inventory");
821 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700822}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200823
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700824inline void requestRoutesMemory(App& app)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200825{
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200826 /**
827 * Functions triggers appropriate requests on DBus
828 */
Ed Tanous22d268c2022-05-19 09:39:07 -0700829 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700830 .privileges(redfish::privileges::getMemory)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700831 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700832 [&app](const crow::Request& req,
833 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -0700834 const std::string& systemName, const std::string& dimmId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400835 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
836 {
837 return;
838 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800839
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400840 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
841 {
842 // Option currently returns no systems. TBD
843 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
844 systemName);
845 return;
846 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800847
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400848 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
849 {
850 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
851 systemName);
852 return;
853 }
Ed Tanous22d268c2022-05-19 09:39:07 -0700854
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400855 getDimmData(asyncResp, dimmId);
856 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700857}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200858
859} // namespace redfish