blob: c77a5346a6d2b6f9caabeb57e4294208cb624c93 [file] [log] [blame]
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +02001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
Willy 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 Tanous3ccb3ad2023-01-13 17:40:03 -080022#include "query.hpp"
23#include "registries/privilege_registry.hpp"
24#include "utils/collection.hpp"
25#include "utils/dbus_utils.hpp"
26#include "utils/hex_utils.hpp"
27#include "utils/json_utils.hpp"
James Feist35e257a2020-06-05 13:30:51 -070028
George Liue99073f2022-12-09 11:06:16 +080029#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070030#include <boost/url/format.hpp>
Nan Zhoud7f04fd2022-05-01 01:11:07 +000031#include <nlohmann/json.hpp>
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +020032#include <sdbusplus/asio/property.hpp>
33#include <sdbusplus/unpack_properties.hpp>
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020034
George Liu7a1dbc42022-12-07 16:03:22 +080035#include <array>
36#include <string_view>
37
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 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700371 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
372 ["DataLockCapable"] = *dataLockCapable;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200373 }
374
375 if (passphraseCapable != nullptr)
376 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700377 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
378 ["PassphraseCapable"] = *passphraseCapable;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200379 }
380
381 if (maxPassphraseCount != nullptr)
382 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700383 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
384 ["MaxPassphraseCount"] = *maxPassphraseCount;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200385 }
386
387 if (passphraseLockLimit != nullptr)
388 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700389 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
390 ["PassphraseLockLimit"] = *passphraseLockLimit;
James Feistc50e7c62020-07-27 15:39:36 -0700391 }
392}
393
Nan Zhou9a5acea2022-05-17 21:12:43 +0000394inline void
395 assembleDimmProperties(std::string_view dimmId,
Ed Tanousac106bf2023-06-07 09:24:59 -0700396 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000397 const dbus::utility::DBusPropertiesMap& properties,
398 const nlohmann::json::json_pointer& jsonPtr)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000399{
Ed Tanousac106bf2023-06-07 09:24:59 -0700400 asyncResp->res.jsonValue[jsonPtr]["Id"] = dimmId;
401 asyncResp->res.jsonValue[jsonPtr]["Name"] = "DIMM Slot";
402 asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] = "Enabled";
403 asyncResp->res.jsonValue[jsonPtr]["Status"]["Health"] = "OK";
Nan Zhou9a5acea2022-05-17 21:12:43 +0000404
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200405 const uint16_t* memoryDataWidth = nullptr;
406 const size_t* memorySizeInKB = nullptr;
407 const std::string* partNumber = nullptr;
408 const std::string* serialNumber = nullptr;
409 const std::string* manufacturer = nullptr;
410 const uint16_t* revisionCode = nullptr;
411 const bool* present = nullptr;
412 const uint16_t* memoryTotalWidth = nullptr;
413 const std::string* ecc = nullptr;
414 const std::string* formFactor = nullptr;
415 const std::vector<uint16_t>* allowedSpeedsMT = nullptr;
George Liu6995c1c2023-06-15 08:53:11 +0800416 const size_t* memoryAttributes = nullptr;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200417 const uint16_t* memoryConfiguredSpeedInMhz = nullptr;
418 const std::string* memoryType = nullptr;
Jayaprakash Mutyala6fde5972023-06-15 07:56:58 +0000419 const std::uint8_t* channel = nullptr;
420 const std::uint8_t* memoryController = nullptr;
421 const std::uint8_t* slot = nullptr;
422 const std::uint8_t* socket = nullptr;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200423 const std::string* sparePartNumber = nullptr;
424 const std::string* model = nullptr;
425 const std::string* locationCode = nullptr;
426
427 const bool success = sdbusplus::unpackPropertiesNoThrow(
428 dbus_utils::UnpackErrorPrinter(), properties, "MemoryDataWidth",
429 memoryDataWidth, "MemorySizeInKB", memorySizeInKB, "PartNumber",
Nikhil Namjoshi656472d2022-09-13 20:54:44 +0000430 partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer,
431 "RevisionCode", revisionCode, "Present", present, "MemoryTotalWidth",
432 memoryTotalWidth, "ECC", ecc, "FormFactor", formFactor,
433 "AllowedSpeedsMT", allowedSpeedsMT, "MemoryAttributes",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200434 memoryAttributes, "MemoryConfiguredSpeedInMhz",
435 memoryConfiguredSpeedInMhz, "MemoryType", memoryType, "Channel",
436 channel, "MemoryController", memoryController, "Slot", slot, "Socket",
437 socket, "SparePartNumber", sparePartNumber, "Model", model,
438 "LocationCode", locationCode);
439
440 if (!success)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000441 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700442 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200443 return;
444 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000445
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200446 if (memoryDataWidth != nullptr)
447 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700448 asyncResp->res.jsonValue[jsonPtr]["DataWidthBits"] = *memoryDataWidth;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200449 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000450
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200451 if (memorySizeInKB != nullptr)
452 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700453 asyncResp->res.jsonValue[jsonPtr]["CapacityMiB"] =
454 (*memorySizeInKB >> 10);
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 (partNumber != nullptr)
458 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700459 asyncResp->res.jsonValue[jsonPtr]["PartNumber"] = *partNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200460 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000461
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200462 if (serialNumber != nullptr)
463 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700464 asyncResp->res.jsonValue[jsonPtr]["SerialNumber"] = *serialNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200465 }
466
467 if (manufacturer != nullptr)
468 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700469 asyncResp->res.jsonValue[jsonPtr]["Manufacturer"] = *manufacturer;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200470 }
471
472 if (revisionCode != nullptr)
473 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700474 asyncResp->res.jsonValue[jsonPtr]["FirmwareRevision"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200475 std::to_string(*revisionCode);
476 }
477
478 if (present != nullptr && !*present)
479 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700480 asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] = "Absent";
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200481 }
482
483 if (memoryTotalWidth != nullptr)
484 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700485 asyncResp->res.jsonValue[jsonPtr]["BusWidthBits"] = *memoryTotalWidth;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200486 }
487
488 if (ecc != nullptr)
489 {
490 constexpr const std::array<const char*, 4> values{
491 "NoECC", "SingleBitECC", "MultiBitECC", "AddressParity"};
492
493 for (const char* v : values)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000494 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200495 if (ecc->ends_with(v))
Nan Zhou9a5acea2022-05-17 21:12:43 +0000496 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700497 asyncResp->res.jsonValue[jsonPtr]["ErrorCorrection"] = v;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200498 break;
Nan Zhou9a5acea2022-05-17 21:12:43 +0000499 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000500 }
501 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200502
503 if (formFactor != nullptr)
504 {
505 constexpr const std::array<const char*, 11> values{
506 "RDIMM", "UDIMM", "SO_DIMM", "LRDIMM",
507 "Mini_RDIMM", "Mini_UDIMM", "SO_RDIMM_72b", "SO_UDIMM_72b",
508 "SO_DIMM_16b", "SO_DIMM_32b", "Die"};
509
510 for (const char* v : values)
511 {
512 if (formFactor->ends_with(v))
513 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700514 asyncResp->res.jsonValue[jsonPtr]["BaseModuleType"] = v;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200515 break;
516 }
517 }
518 }
519
520 if (allowedSpeedsMT != nullptr)
521 {
522 nlohmann::json& jValue =
Ed Tanousac106bf2023-06-07 09:24:59 -0700523 asyncResp->res.jsonValue[jsonPtr]["AllowedSpeedsMHz"];
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200524 jValue = nlohmann::json::array();
525 for (uint16_t subVal : *allowedSpeedsMT)
526 {
527 jValue.push_back(subVal);
528 }
529 }
530
531 if (memoryAttributes != nullptr)
532 {
George Liu6995c1c2023-06-15 08:53:11 +0800533 asyncResp->res.jsonValue[jsonPtr]["RankCount"] = *memoryAttributes;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200534 }
535
536 if (memoryConfiguredSpeedInMhz != nullptr)
537 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700538 asyncResp->res.jsonValue[jsonPtr]["OperatingSpeedMhz"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200539 *memoryConfiguredSpeedInMhz;
540 }
541
542 if (memoryType != nullptr)
543 {
544 std::string memoryDeviceType =
545 translateMemoryTypeToRedfish(*memoryType);
546 // Values like "Unknown" or "Other" will return empty
547 // so just leave off
548 if (!memoryDeviceType.empty())
549 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700550 asyncResp->res.jsonValue[jsonPtr]["MemoryDeviceType"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200551 memoryDeviceType;
552 }
553 if (memoryType->find("DDR") != std::string::npos)
554 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700555 asyncResp->res.jsonValue[jsonPtr]["MemoryType"] = "DRAM";
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200556 }
557 else if (memoryType->ends_with("Logical"))
558 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700559 asyncResp->res.jsonValue[jsonPtr]["MemoryType"] = "IntelOptane";
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200560 }
561 }
562
563 if (channel != nullptr)
564 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700565 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Channel"] =
566 *channel;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200567 }
568
569 if (memoryController != nullptr)
570 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700571 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]
572 ["MemoryController"] = *memoryController;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200573 }
574
575 if (slot != nullptr)
576 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700577 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Slot"] = *slot;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200578 }
579
580 if (socket != nullptr)
581 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700582 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Socket"] = *socket;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200583 }
584
585 if (sparePartNumber != nullptr)
586 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700587 asyncResp->res.jsonValue[jsonPtr]["SparePartNumber"] = *sparePartNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200588 }
589
590 if (model != nullptr)
591 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700592 asyncResp->res.jsonValue[jsonPtr]["Model"] = *model;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200593 }
594
595 if (locationCode != nullptr)
596 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700597 asyncResp->res.jsonValue[jsonPtr]["Location"]["PartLocation"]
598 ["ServiceLabel"] = *locationCode;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200599 }
600
Ed Tanousac106bf2023-06-07 09:24:59 -0700601 getPersistentMemoryProperties(asyncResp, properties, jsonPtr);
Nan Zhou9a5acea2022-05-17 21:12:43 +0000602}
603
Ed Tanousac106bf2023-06-07 09:24:59 -0700604inline void getDimmDataByService(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous80789c82020-08-19 09:19:09 -0700605 const std::string& dimmId,
606 const std::string& service,
607 const std::string& objPath)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200608{
Ed Tanous62598e32023-07-17 17:06:25 -0700609 BMCWEB_LOG_DEBUG("Get available system components.");
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200610 sdbusplus::asio::getAllProperties(
611 *crow::connections::systemBus, service, objPath, "",
Ed Tanousac106bf2023-06-07 09:24:59 -0700612 [dimmId, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800613 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800614 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700615 if (ec)
616 {
Ed Tanous62598e32023-07-17 17:06:25 -0700617 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -0700618 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700619 return;
620 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700621 assembleDimmProperties(dimmId, asyncResp, properties, ""_json_pointer);
Patrick Williams5a39f772023-10-20 11:20:21 -0500622 });
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200623}
624
Nan Zhouef00d7d2022-05-20 21:22:32 +0000625inline void assembleDimmPartitionData(
Ed Tanousac106bf2023-06-07 09:24:59 -0700626 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000627 const dbus::utility::DBusPropertiesMap& properties,
628 const nlohmann::json::json_pointer& regionPtr)
Nan Zhouef00d7d2022-05-20 21:22:32 +0000629{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200630 const std::string* memoryClassification = nullptr;
631 const uint64_t* offsetInKiB = nullptr;
632 const std::string* partitionId = nullptr;
633 const bool* passphraseState = nullptr;
634 const uint64_t* sizeInKiB = nullptr;
635
636 const bool success = sdbusplus::unpackPropertiesNoThrow(
637 dbus_utils::UnpackErrorPrinter(), properties, "MemoryClassification",
638 memoryClassification, "OffsetInKiB", offsetInKiB, "PartitionId",
639 partitionId, "PassphraseState", passphraseState, "SizeInKiB",
640 sizeInKiB);
641
642 if (!success)
Nan Zhouef00d7d2022-05-20 21:22:32 +0000643 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700644 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200645 return;
Nan Zhouef00d7d2022-05-20 21:22:32 +0000646 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200647
648 nlohmann::json::object_t partition;
649
650 if (memoryClassification != nullptr)
651 {
652 partition["MemoryClassification"] = *memoryClassification;
653 }
654
655 if (offsetInKiB != nullptr)
656 {
657 partition["OffsetMiB"] = (*offsetInKiB >> 10);
658 }
659
660 if (partitionId != nullptr)
661 {
662 partition["RegionId"] = *partitionId;
663 }
664
665 if (passphraseState != nullptr)
666 {
667 partition["PassphraseEnabled"] = *passphraseState;
668 }
669
670 if (sizeInKiB != nullptr)
671 {
672 partition["SizeMiB"] = (*sizeInKiB >> 10);
673 }
674
Ed Tanousac106bf2023-06-07 09:24:59 -0700675 asyncResp->res.jsonValue[regionPtr].emplace_back(std::move(partition));
Nan Zhouef00d7d2022-05-20 21:22:32 +0000676}
677
Ed Tanousac106bf2023-06-07 09:24:59 -0700678inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000679 const std::string& service,
680 const std::string& path)
James Feist45094ad2020-04-29 14:02:30 -0700681{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200682 sdbusplus::asio::getAllProperties(
683 *crow::connections::systemBus, service, path,
684 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition",
Ed Tanousac106bf2023-06-07 09:24:59 -0700685 [asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800686 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800687 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700688 if (ec)
689 {
Ed Tanous62598e32023-07-17 17:06:25 -0700690 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -0700691 messages::internalError(asyncResp->res);
James Feist45094ad2020-04-29 14:02:30 -0700692
Ed Tanous002d39b2022-05-31 08:59:27 -0700693 return;
694 }
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000695 nlohmann::json::json_pointer regionPtr = "/Regions"_json_pointer;
Ed Tanousac106bf2023-06-07 09:24:59 -0700696 assembleDimmPartitionData(asyncResp, properties, regionPtr);
Patrick Williams5a39f772023-10-20 11:20:21 -0500697 }
James Feist45094ad2020-04-29 14:02:30 -0700698
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200699 );
James Feist45094ad2020-04-29 14:02:30 -0700700}
701
Ed Tanousac106bf2023-06-07 09:24:59 -0700702inline void getDimmData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000703 const std::string& dimmId)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200704{
Ed Tanous62598e32023-07-17 17:06:25 -0700705 BMCWEB_LOG_DEBUG("Get available system dimm resources.");
George Liue99073f2022-12-09 11:06:16 +0800706 constexpr std::array<std::string_view, 2> dimmInterfaces = {
707 "xyz.openbmc_project.Inventory.Item.Dimm",
708 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition"};
709 dbus::utility::getSubTree(
710 "/xyz/openbmc_project/inventory", 0, dimmInterfaces,
Ed Tanousac106bf2023-06-07 09:24:59 -0700711 [dimmId, asyncResp{std::move(asyncResp)}](
George Liue99073f2022-12-09 11:06:16 +0800712 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800713 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700714 if (ec)
715 {
Ed Tanous62598e32023-07-17 17:06:25 -0700716 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -0700717 messages::internalError(asyncResp->res);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200718
Ed Tanous002d39b2022-05-31 08:59:27 -0700719 return;
720 }
721 bool found = false;
Nan Zhou76686dc2022-06-17 23:01:51 +0000722 for (const auto& [rawPath, object] : subtree)
Ed Tanous002d39b2022-05-31 08:59:27 -0700723 {
Nan Zhou76686dc2022-06-17 23:01:51 +0000724 sdbusplus::message::object_path path(rawPath);
725 for (const auto& [service, interfaces] : object)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200726 {
Nan Zhou76686dc2022-06-17 23:01:51 +0000727 for (const auto& interface : interfaces)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200728 {
Nan Zhou76686dc2022-06-17 23:01:51 +0000729 if (interface ==
730 "xyz.openbmc_project.Inventory.Item.Dimm" &&
731 path.filename() == dimmId)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200732 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700733 getDimmDataByService(asyncResp, dimmId, service,
734 rawPath);
Nan Zhou76686dc2022-06-17 23:01:51 +0000735 found = true;
736 }
James Feist45094ad2020-04-29 14:02:30 -0700737
Nan Zhou76686dc2022-06-17 23:01:51 +0000738 // partitions are separate as there can be multiple
739 // per
740 // device, i.e.
741 // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition1
742 // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition2
743 if (interface ==
744 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition" &&
745 path.parent_path().filename() == dimmId)
746 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700747 getDimmPartitionData(asyncResp, service, rawPath);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200748 }
749 }
750 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700751 }
752 // Object not found
753 if (!found)
754 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700755 messages::resourceNotFound(asyncResp->res, "Memory", dimmId);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200756 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700757 }
758 // Set @odata only if object is found
Ed Tanousac106bf2023-06-07 09:24:59 -0700759 asyncResp->res.jsonValue["@odata.type"] = "#Memory.v1_11_0.Memory";
760 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -0700761 boost::urls::format("/redfish/v1/Systems/{}/Memory/{}",
762 BMCWEB_REDFISH_SYSTEM_URI_NAME, dimmId);
Ed Tanous002d39b2022-05-31 08:59:27 -0700763 return;
Patrick Williams5a39f772023-10-20 11:20:21 -0500764 });
Ed Tanous271584a2019-07-09 16:24:22 -0700765}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200766
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700767inline void requestRoutesMemoryCollection(App& app)
Ed Tanous029573d2019-02-01 10:57:49 -0800768{
Ed Tanous029573d2019-02-01 10:57:49 -0800769 /**
770 * Functions triggers appropriate requests on DBus
771 */
Ed Tanous22d268c2022-05-19 09:39:07 -0700772 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/")
Ed Tanoused398212021-06-09 17:05:54 -0700773 .privileges(redfish::privileges::getMemoryCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700774 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700775 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -0700776 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
777 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000778 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700779 {
780 return;
781 }
Ed Tanous25b54db2024-04-17 15:40:31 -0700782 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800783 {
784 // Option currently returns no systems. TBD
785 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
786 systemName);
787 return;
788 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700789 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -0700790 {
791 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
792 systemName);
793 return;
794 }
795
Ed Tanous002d39b2022-05-31 08:59:27 -0700796 asyncResp->res.jsonValue["@odata.type"] =
797 "#MemoryCollection.MemoryCollection";
798 asyncResp->res.jsonValue["Name"] = "Memory Module Collection";
Ed Tanous253f11b2024-05-16 09:38:31 -0700799 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
800 "/redfish/v1/Systems/{}/Memory", BMCWEB_REDFISH_SYSTEM_URI_NAME);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200801
George Liu7a1dbc42022-12-07 16:03:22 +0800802 constexpr std::array<std::string_view, 1> interfaces{
803 "xyz.openbmc_project.Inventory.Item.Dimm"};
Ed Tanous002d39b2022-05-31 08:59:27 -0700804 collection_util::getCollectionMembers(
Ed Tanous253f11b2024-05-16 09:38:31 -0700805 asyncResp,
806 boost::urls::format("/redfish/v1/Systems/{}/Memory",
807 BMCWEB_REDFISH_SYSTEM_URI_NAME),
Lakshmi Yadlapati36b5f1e2023-09-26 23:53:28 -0500808 interfaces, "/xyz/openbmc_project/inventory");
Patrick Williams5a39f772023-10-20 11:20:21 -0500809 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700810}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200811
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700812inline void requestRoutesMemory(App& app)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200813{
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200814 /**
815 * Functions triggers appropriate requests on DBus
816 */
Ed Tanous22d268c2022-05-19 09:39:07 -0700817 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700818 .privileges(redfish::privileges::getMemory)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700819 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700820 [&app](const crow::Request& req,
821 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -0700822 const std::string& systemName, const std::string& dimmId) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000823 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700824 {
825 return;
826 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800827
Ed Tanous25b54db2024-04-17 15:40:31 -0700828 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800829 {
830 // Option currently returns no systems. TBD
831 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
832 systemName);
833 return;
834 }
835
Ed Tanous253f11b2024-05-16 09:38:31 -0700836 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -0700837 {
838 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
839 systemName);
840 return;
841 }
842
Ed Tanous002d39b2022-05-31 08:59:27 -0700843 getDimmData(asyncResp, dimmId);
Patrick Williams5a39f772023-10-20 11:20:21 -0500844 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700845}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200846
847} // namespace redfish