blob: cd87d42c7e952140414a292e8ac557facc80085a [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 Tanous539d8c62024-06-19 14:38:27 -070022#include "generated/enums/memory.hpp"
23#include "generated/enums/resource.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080024#include "query.hpp"
25#include "registries/privilege_registry.hpp"
26#include "utils/collection.hpp"
27#include "utils/dbus_utils.hpp"
28#include "utils/hex_utils.hpp"
29#include "utils/json_utils.hpp"
James Feist35e257a2020-06-05 13:30:51 -070030
George Liue99073f2022-12-09 11:06:16 +080031#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070032#include <boost/url/format.hpp>
Nan Zhoud7f04fd2022-05-01 01:11:07 +000033#include <nlohmann/json.hpp>
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +020034#include <sdbusplus/asio/property.hpp>
35#include <sdbusplus/unpack_properties.hpp>
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020036
George Liu7a1dbc42022-12-07 16:03:22 +080037#include <array>
38#include <string_view>
39
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020040namespace redfish
41{
42
Gunnar Mills313efb12020-10-26 16:05:08 -050043inline std::string translateMemoryTypeToRedfish(const std::string& memoryType)
44{
45 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR")
46 {
47 return "DDR";
48 }
49 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2")
50 {
51 return "DDR2";
52 }
53 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR3")
54 {
55 return "DDR3";
56 }
57 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4")
58 {
59 return "DDR4";
60 }
61 if (memoryType ==
62 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4E_SDRAM")
63 {
64 return "DDR4E_SDRAM";
65 }
Mansi Joshi11a2f0f2021-07-19 14:33:27 +053066 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR5")
67 {
68 return "DDR5";
69 }
Gunnar Mills313efb12020-10-26 16:05:08 -050070 if (memoryType ==
71 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR4_SDRAM")
72 {
73 return "LPDDR4_SDRAM";
74 }
75 if (memoryType ==
76 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR3_SDRAM")
77 {
78 return "LPDDR3_SDRAM";
79 }
80 if (memoryType ==
81 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM")
82 {
83 return "DDR2_SDRAM_FB_DIMM";
84 }
George Liu0fda0f12021-11-16 10:06:17 +080085 if (memoryType ==
86 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM_PROB")
Gunnar Mills313efb12020-10-26 16:05:08 -050087 {
88 return "DDR2_SDRAM_FB_DIMM_PROBE";
89 }
90 if (memoryType ==
91 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR_SGRAM")
92 {
93 return "DDR_SGRAM";
94 }
95 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.ROM")
96 {
97 return "ROM";
98 }
99 if (memoryType ==
100 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.SDRAM")
101 {
102 return "SDRAM";
103 }
104 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.EDO")
105 {
106 return "EDO";
107 }
108 if (memoryType ==
109 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.FastPageMode")
110 {
111 return "FastPageMode";
112 }
113 if (memoryType ==
114 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.PipelinedNibble")
115 {
116 return "PipelinedNibble";
117 }
118 if (memoryType ==
119 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.Logical")
120 {
121 return "Logical";
122 }
123 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM")
124 {
125 return "HBM";
126 }
127 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM2")
128 {
129 return "HBM2";
130 }
Tyson Tuckerbearce34d512022-09-13 16:26:15 -0700131 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM3")
132 {
133 return "HBM3";
134 }
Gunnar Mills313efb12020-10-26 16:05:08 -0500135 // This is values like Other or Unknown
136 // Also D-Bus values:
137 // DRAM
138 // EDRAM
139 // VRAM
140 // SRAM
141 // RAM
142 // FLASH
143 // EEPROM
144 // FEPROM
145 // EPROM
146 // CDRAM
147 // ThreeDRAM
148 // RDRAM
149 // FBD2
150 // LPDDR_SDRAM
151 // LPDDR2_SDRAM
Mansi Joshi11a2f0f2021-07-19 14:33:27 +0530152 // LPDDR5_SDRAM
Gunnar Mills313efb12020-10-26 16:05:08 -0500153 return "";
154}
155
Ed Tanousac106bf2023-06-07 09:24:59 -0700156inline void dimmPropToHex(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200157 const char* key, const uint16_t* value,
158 const nlohmann::json::json_pointer& jsonPtr)
James Feistc50e7c62020-07-27 15:39:36 -0700159{
James Feistc50e7c62020-07-27 15:39:36 -0700160 if (value == nullptr)
161 {
James Feistc50e7c62020-07-27 15:39:36 -0700162 return;
163 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700164 asyncResp->res.jsonValue[jsonPtr][key] = "0x" + intToHexString(*value, 4);
James Feistc50e7c62020-07-27 15:39:36 -0700165}
166
zhanghch058d1b46d2021-04-01 11:18:24 +0800167inline void getPersistentMemoryProperties(
Ed Tanousac106bf2023-06-07 09:24:59 -0700168 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200169 const dbus::utility::DBusPropertiesMap& properties,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000170 const nlohmann::json::json_pointer& jsonPtr)
James Feistc50e7c62020-07-27 15:39:36 -0700171{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200172 const uint16_t* moduleManufacturerID = nullptr;
173 const uint16_t* moduleProductID = nullptr;
174 const uint16_t* subsystemVendorID = nullptr;
175 const uint16_t* subsystemDeviceID = nullptr;
176 const uint64_t* volatileRegionSizeLimitInKiB = nullptr;
177 const uint64_t* pmRegionSizeLimitInKiB = nullptr;
178 const uint64_t* volatileSizeInKiB = nullptr;
179 const uint64_t* pmSizeInKiB = nullptr;
180 const uint64_t* cacheSizeInKB = nullptr;
181 const uint64_t* voltaileRegionMaxSizeInKib = nullptr;
182 const uint64_t* pmRegionMaxSizeInKiB = nullptr;
183 const uint64_t* allocationIncrementInKiB = nullptr;
184 const uint64_t* allocationAlignmentInKiB = nullptr;
185 const uint64_t* volatileRegionNumberLimit = nullptr;
186 const uint64_t* pmRegionNumberLimit = nullptr;
187 const uint64_t* spareDeviceCount = nullptr;
188 const bool* isSpareDeviceInUse = nullptr;
189 const bool* isRankSpareEnabled = nullptr;
190 const std::vector<uint32_t>* maxAveragePowerLimitmW = nullptr;
191 const bool* configurationLocked = nullptr;
192 const std::string* allowedMemoryModes = nullptr;
193 const std::string* memoryMedia = nullptr;
194 const bool* configurationLockCapable = nullptr;
195 const bool* dataLockCapable = nullptr;
196 const bool* passphraseCapable = nullptr;
197 const uint64_t* maxPassphraseCount = nullptr;
198 const uint64_t* passphraseLockLimit = nullptr;
James Feistc50e7c62020-07-27 15:39:36 -0700199
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200200 const bool success = sdbusplus::unpackPropertiesNoThrow(
201 dbus_utils::UnpackErrorPrinter(), properties, "ModuleManufacturerID",
202 moduleManufacturerID, "ModuleProductID", moduleProductID,
203 "SubsystemVendorID", subsystemVendorID, "SubsystemDeviceID",
204 subsystemDeviceID, "VolatileRegionSizeLimitInKiB",
205 volatileRegionSizeLimitInKiB, "PmRegionSizeLimitInKiB",
206 pmRegionSizeLimitInKiB, "VolatileSizeInKiB", volatileSizeInKiB,
207 "PmSizeInKiB", pmSizeInKiB, "CacheSizeInKB", cacheSizeInKB,
208 "VoltaileRegionMaxSizeInKib", voltaileRegionMaxSizeInKib,
209 "PmRegionMaxSizeInKiB", pmRegionMaxSizeInKiB,
210 "AllocationIncrementInKiB", allocationIncrementInKiB,
211 "AllocationAlignmentInKiB", allocationAlignmentInKiB,
212 "VolatileRegionNumberLimit", volatileRegionNumberLimit,
213 "PmRegionNumberLimit", pmRegionNumberLimit, "SpareDeviceCount",
214 spareDeviceCount, "IsSpareDeviceInUse", isSpareDeviceInUse,
215 "IsRankSpareEnabled", isRankSpareEnabled, "MaxAveragePowerLimitmW",
216 maxAveragePowerLimitmW, "ConfigurationLocked", configurationLocked,
217 "AllowedMemoryModes", allowedMemoryModes, "MemoryMedia", memoryMedia,
218 "ConfigurationLockCapable", configurationLockCapable, "DataLockCapable",
219 dataLockCapable, "PassphraseCapable", passphraseCapable,
220 "MaxPassphraseCount", maxPassphraseCount, "PassphraseLockLimit",
221 passphraseLockLimit);
222
223 if (!success)
224 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700225 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200226 return;
227 }
228
Ed Tanousac106bf2023-06-07 09:24:59 -0700229 dimmPropToHex(asyncResp, "ModuleManufacturerID", moduleManufacturerID,
230 jsonPtr);
231 dimmPropToHex(asyncResp, "ModuleProductID", moduleProductID, jsonPtr);
232 dimmPropToHex(asyncResp, "MemorySubsystemControllerManufacturerID",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200233 subsystemVendorID, jsonPtr);
Ed Tanousac106bf2023-06-07 09:24:59 -0700234 dimmPropToHex(asyncResp, "MemorySubsystemControllerProductID",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200235 subsystemDeviceID, jsonPtr);
236
237 if (volatileRegionSizeLimitInKiB != nullptr)
238 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700239 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionSizeLimitMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200240 (*volatileRegionSizeLimitInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800241 }
James Feistc50e7c62020-07-27 15:39:36 -0700242
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200243 if (pmRegionSizeLimitInKiB != nullptr)
244 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700245 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionSizeLimitMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200246 (*pmRegionSizeLimitInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800247 }
James Feistc50e7c62020-07-27 15:39:36 -0700248
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200249 if (volatileSizeInKiB != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800250 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700251 asyncResp->res.jsonValue[jsonPtr]["VolatileSizeMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200252 (*volatileSizeInKiB) >> 10;
253 }
254
255 if (pmSizeInKiB != nullptr)
256 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700257 asyncResp->res.jsonValue[jsonPtr]["NonVolatileSizeMiB"] =
258 (*pmSizeInKiB) >> 10;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200259 }
260
261 if (cacheSizeInKB != nullptr)
262 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700263 asyncResp->res.jsonValue[jsonPtr]["CacheSizeMiB"] =
264 (*cacheSizeInKB >> 10);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200265 }
266
267 if (voltaileRegionMaxSizeInKib != nullptr)
268 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700269 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionSizeMaxMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200270 (*voltaileRegionMaxSizeInKib) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800271 }
James Feistc50e7c62020-07-27 15:39:36 -0700272
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200273 if (pmRegionMaxSizeInKiB != nullptr)
274 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700275 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionSizeMaxMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200276 (*pmRegionMaxSizeInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800277 }
James Feistc50e7c62020-07-27 15:39:36 -0700278
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200279 if (allocationIncrementInKiB != nullptr)
280 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700281 asyncResp->res.jsonValue[jsonPtr]["AllocationIncrementMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200282 (*allocationIncrementInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800283 }
James Feistc50e7c62020-07-27 15:39:36 -0700284
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200285 if (allocationAlignmentInKiB != nullptr)
286 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700287 asyncResp->res.jsonValue[jsonPtr]["AllocationAlignmentMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200288 (*allocationAlignmentInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800289 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200290
291 if (volatileRegionNumberLimit != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800292 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700293 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionNumberLimit"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200294 *volatileRegionNumberLimit;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800295 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200296
297 if (pmRegionNumberLimit != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800298 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700299 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionNumberLimit"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200300 *pmRegionNumberLimit;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800301 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200302
303 if (spareDeviceCount != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800304 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700305 asyncResp->res.jsonValue[jsonPtr]["SpareDeviceCount"] =
306 *spareDeviceCount;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800307 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200308
309 if (isSpareDeviceInUse != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800310 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700311 asyncResp->res.jsonValue[jsonPtr]["IsSpareDeviceEnabled"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200312 *isSpareDeviceInUse;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800313 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200314
315 if (isRankSpareEnabled != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800316 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700317 asyncResp->res.jsonValue[jsonPtr]["IsRankSpareEnabled"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200318 *isRankSpareEnabled;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800319 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200320
321 if (maxAveragePowerLimitmW != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800322 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700323 asyncResp->res.jsonValue[jsonPtr]["MaxTDPMilliWatts"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200324 *maxAveragePowerLimitmW;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800325 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200326
327 if (configurationLocked != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800328 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700329 asyncResp->res.jsonValue[jsonPtr]["ConfigurationLocked"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200330 *configurationLocked;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800331 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200332
333 if (allowedMemoryModes != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800334 {
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800335 constexpr const std::array<const char*, 3> values{"Volatile", "PMEM",
336 "Block"};
James Feistc50e7c62020-07-27 15:39:36 -0700337
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800338 for (const char* v : values)
339 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200340 if (allowedMemoryModes->ends_with(v))
James Feistc50e7c62020-07-27 15:39:36 -0700341 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700342 asyncResp->res.jsonValue[jsonPtr]["OperatingMemoryModes"]
343 .push_back(v);
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800344 break;
James Feistc50e7c62020-07-27 15:39:36 -0700345 }
346 }
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800347 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200348
349 if (memoryMedia != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800350 {
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800351 constexpr const std::array<const char*, 3> values{"DRAM", "NAND",
352 "Intel3DXPoint"};
James Feistc50e7c62020-07-27 15:39:36 -0700353
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800354 for (const char* v : values)
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700355 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200356 if (memoryMedia->ends_with(v))
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700357 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700358 asyncResp->res.jsonValue[jsonPtr]["MemoryMedia"].push_back(v);
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800359 break;
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700360 }
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700361 }
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800362 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200363
364 if (configurationLockCapable != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800365 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700366 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
367 ["ConfigurationLockCapable"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200368 *configurationLockCapable;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800369 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200370
371 if (dataLockCapable != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800372 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700373 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
374 ["DataLockCapable"] = *dataLockCapable;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200375 }
376
377 if (passphraseCapable != nullptr)
378 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700379 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
380 ["PassphraseCapable"] = *passphraseCapable;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200381 }
382
383 if (maxPassphraseCount != nullptr)
384 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700385 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
386 ["MaxPassphraseCount"] = *maxPassphraseCount;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200387 }
388
389 if (passphraseLockLimit != nullptr)
390 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700391 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
392 ["PassphraseLockLimit"] = *passphraseLockLimit;
James Feistc50e7c62020-07-27 15:39:36 -0700393 }
394}
395
Nan Zhou9a5acea2022-05-17 21:12:43 +0000396inline void
397 assembleDimmProperties(std::string_view dimmId,
Ed Tanousac106bf2023-06-07 09:24:59 -0700398 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000399 const dbus::utility::DBusPropertiesMap& properties,
400 const nlohmann::json::json_pointer& jsonPtr)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000401{
Ed Tanousac106bf2023-06-07 09:24:59 -0700402 asyncResp->res.jsonValue[jsonPtr]["Id"] = dimmId;
403 asyncResp->res.jsonValue[jsonPtr]["Name"] = "DIMM Slot";
Ed Tanous539d8c62024-06-19 14:38:27 -0700404 asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] =
405 resource::State::Enabled;
406 asyncResp->res.jsonValue[jsonPtr]["Status"]["Health"] =
407 resource::Health::OK;
Nan Zhou9a5acea2022-05-17 21:12:43 +0000408
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200409 const uint16_t* memoryDataWidth = nullptr;
410 const size_t* memorySizeInKB = nullptr;
411 const std::string* partNumber = nullptr;
412 const std::string* serialNumber = nullptr;
413 const std::string* manufacturer = nullptr;
414 const uint16_t* revisionCode = nullptr;
415 const bool* present = nullptr;
416 const uint16_t* memoryTotalWidth = nullptr;
417 const std::string* ecc = nullptr;
418 const std::string* formFactor = nullptr;
419 const std::vector<uint16_t>* allowedSpeedsMT = nullptr;
George Liu6995c1c2023-06-15 08:53:11 +0800420 const size_t* memoryAttributes = nullptr;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200421 const uint16_t* memoryConfiguredSpeedInMhz = nullptr;
422 const std::string* memoryType = nullptr;
Jayaprakash Mutyala6fde5972023-06-15 07:56:58 +0000423 const std::uint8_t* channel = nullptr;
424 const std::uint8_t* memoryController = nullptr;
425 const std::uint8_t* slot = nullptr;
426 const std::uint8_t* socket = nullptr;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200427 const std::string* sparePartNumber = nullptr;
428 const std::string* model = nullptr;
429 const std::string* locationCode = nullptr;
430
431 const bool success = sdbusplus::unpackPropertiesNoThrow(
432 dbus_utils::UnpackErrorPrinter(), properties, "MemoryDataWidth",
433 memoryDataWidth, "MemorySizeInKB", memorySizeInKB, "PartNumber",
Nikhil Namjoshi656472d2022-09-13 20:54:44 +0000434 partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer,
435 "RevisionCode", revisionCode, "Present", present, "MemoryTotalWidth",
436 memoryTotalWidth, "ECC", ecc, "FormFactor", formFactor,
437 "AllowedSpeedsMT", allowedSpeedsMT, "MemoryAttributes",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200438 memoryAttributes, "MemoryConfiguredSpeedInMhz",
439 memoryConfiguredSpeedInMhz, "MemoryType", memoryType, "Channel",
440 channel, "MemoryController", memoryController, "Slot", slot, "Socket",
441 socket, "SparePartNumber", sparePartNumber, "Model", model,
442 "LocationCode", locationCode);
443
444 if (!success)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000445 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700446 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200447 return;
448 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000449
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200450 if (memoryDataWidth != nullptr)
451 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700452 asyncResp->res.jsonValue[jsonPtr]["DataWidthBits"] = *memoryDataWidth;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200453 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000454
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200455 if (memorySizeInKB != nullptr)
456 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700457 asyncResp->res.jsonValue[jsonPtr]["CapacityMiB"] =
458 (*memorySizeInKB >> 10);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200459 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000460
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200461 if (partNumber != nullptr)
462 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700463 asyncResp->res.jsonValue[jsonPtr]["PartNumber"] = *partNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200464 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000465
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200466 if (serialNumber != nullptr)
467 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700468 asyncResp->res.jsonValue[jsonPtr]["SerialNumber"] = *serialNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200469 }
470
471 if (manufacturer != nullptr)
472 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700473 asyncResp->res.jsonValue[jsonPtr]["Manufacturer"] = *manufacturer;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200474 }
475
476 if (revisionCode != nullptr)
477 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700478 asyncResp->res.jsonValue[jsonPtr]["FirmwareRevision"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200479 std::to_string(*revisionCode);
480 }
481
482 if (present != nullptr && !*present)
483 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700484 asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] =
485 resource::State::Absent;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200486 }
487
488 if (memoryTotalWidth != nullptr)
489 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700490 asyncResp->res.jsonValue[jsonPtr]["BusWidthBits"] = *memoryTotalWidth;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200491 }
492
493 if (ecc != nullptr)
494 {
495 constexpr const std::array<const char*, 4> values{
496 "NoECC", "SingleBitECC", "MultiBitECC", "AddressParity"};
497
498 for (const char* v : values)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000499 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200500 if (ecc->ends_with(v))
Nan Zhou9a5acea2022-05-17 21:12:43 +0000501 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700502 asyncResp->res.jsonValue[jsonPtr]["ErrorCorrection"] = v;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200503 break;
Nan Zhou9a5acea2022-05-17 21:12:43 +0000504 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000505 }
506 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200507
508 if (formFactor != nullptr)
509 {
510 constexpr const std::array<const char*, 11> values{
511 "RDIMM", "UDIMM", "SO_DIMM", "LRDIMM",
512 "Mini_RDIMM", "Mini_UDIMM", "SO_RDIMM_72b", "SO_UDIMM_72b",
513 "SO_DIMM_16b", "SO_DIMM_32b", "Die"};
514
515 for (const char* v : values)
516 {
517 if (formFactor->ends_with(v))
518 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700519 asyncResp->res.jsonValue[jsonPtr]["BaseModuleType"] = v;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200520 break;
521 }
522 }
523 }
524
525 if (allowedSpeedsMT != nullptr)
526 {
527 nlohmann::json& jValue =
Ed Tanousac106bf2023-06-07 09:24:59 -0700528 asyncResp->res.jsonValue[jsonPtr]["AllowedSpeedsMHz"];
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200529 jValue = nlohmann::json::array();
530 for (uint16_t subVal : *allowedSpeedsMT)
531 {
532 jValue.push_back(subVal);
533 }
534 }
535
536 if (memoryAttributes != nullptr)
537 {
George Liu6995c1c2023-06-15 08:53:11 +0800538 asyncResp->res.jsonValue[jsonPtr]["RankCount"] = *memoryAttributes;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200539 }
540
541 if (memoryConfiguredSpeedInMhz != nullptr)
542 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700543 asyncResp->res.jsonValue[jsonPtr]["OperatingSpeedMhz"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200544 *memoryConfiguredSpeedInMhz;
545 }
546
547 if (memoryType != nullptr)
548 {
549 std::string memoryDeviceType =
550 translateMemoryTypeToRedfish(*memoryType);
551 // Values like "Unknown" or "Other" will return empty
552 // so just leave off
553 if (!memoryDeviceType.empty())
554 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700555 asyncResp->res.jsonValue[jsonPtr]["MemoryDeviceType"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200556 memoryDeviceType;
557 }
558 if (memoryType->find("DDR") != std::string::npos)
559 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700560 asyncResp->res.jsonValue[jsonPtr]["MemoryType"] =
561 memory::MemoryType::DRAM;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200562 }
563 else if (memoryType->ends_with("Logical"))
564 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700565 asyncResp->res.jsonValue[jsonPtr]["MemoryType"] =
566 memory::MemoryType::IntelOptane;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200567 }
568 }
569
570 if (channel != nullptr)
571 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700572 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Channel"] =
573 *channel;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200574 }
575
576 if (memoryController != nullptr)
577 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700578 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]
579 ["MemoryController"] = *memoryController;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200580 }
581
582 if (slot != nullptr)
583 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700584 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Slot"] = *slot;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200585 }
586
587 if (socket != nullptr)
588 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700589 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Socket"] = *socket;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200590 }
591
592 if (sparePartNumber != nullptr)
593 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700594 asyncResp->res.jsonValue[jsonPtr]["SparePartNumber"] = *sparePartNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200595 }
596
597 if (model != nullptr)
598 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700599 asyncResp->res.jsonValue[jsonPtr]["Model"] = *model;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200600 }
601
602 if (locationCode != nullptr)
603 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700604 asyncResp->res.jsonValue[jsonPtr]["Location"]["PartLocation"]
605 ["ServiceLabel"] = *locationCode;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200606 }
607
Ed Tanousac106bf2023-06-07 09:24:59 -0700608 getPersistentMemoryProperties(asyncResp, properties, jsonPtr);
Nan Zhou9a5acea2022-05-17 21:12:43 +0000609}
610
Ed Tanousac106bf2023-06-07 09:24:59 -0700611inline void getDimmDataByService(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous80789c82020-08-19 09:19:09 -0700612 const std::string& dimmId,
613 const std::string& service,
614 const std::string& objPath)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200615{
Ed Tanous62598e32023-07-17 17:06:25 -0700616 BMCWEB_LOG_DEBUG("Get available system components.");
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200617 sdbusplus::asio::getAllProperties(
618 *crow::connections::systemBus, service, objPath, "",
Ed Tanousac106bf2023-06-07 09:24:59 -0700619 [dimmId, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800620 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800621 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700622 if (ec)
623 {
Ed Tanous62598e32023-07-17 17:06:25 -0700624 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -0700625 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700626 return;
627 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700628 assembleDimmProperties(dimmId, asyncResp, properties, ""_json_pointer);
Patrick Williams5a39f772023-10-20 11:20:21 -0500629 });
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200630}
631
Nan Zhouef00d7d2022-05-20 21:22:32 +0000632inline void assembleDimmPartitionData(
Ed Tanousac106bf2023-06-07 09:24:59 -0700633 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000634 const dbus::utility::DBusPropertiesMap& properties,
635 const nlohmann::json::json_pointer& regionPtr)
Nan Zhouef00d7d2022-05-20 21:22:32 +0000636{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200637 const std::string* memoryClassification = nullptr;
638 const uint64_t* offsetInKiB = nullptr;
639 const std::string* partitionId = nullptr;
640 const bool* passphraseState = nullptr;
641 const uint64_t* sizeInKiB = nullptr;
642
643 const bool success = sdbusplus::unpackPropertiesNoThrow(
644 dbus_utils::UnpackErrorPrinter(), properties, "MemoryClassification",
645 memoryClassification, "OffsetInKiB", offsetInKiB, "PartitionId",
646 partitionId, "PassphraseState", passphraseState, "SizeInKiB",
647 sizeInKiB);
648
649 if (!success)
Nan Zhouef00d7d2022-05-20 21:22:32 +0000650 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700651 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200652 return;
Nan Zhouef00d7d2022-05-20 21:22:32 +0000653 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200654
655 nlohmann::json::object_t partition;
656
657 if (memoryClassification != nullptr)
658 {
659 partition["MemoryClassification"] = *memoryClassification;
660 }
661
662 if (offsetInKiB != nullptr)
663 {
664 partition["OffsetMiB"] = (*offsetInKiB >> 10);
665 }
666
667 if (partitionId != nullptr)
668 {
669 partition["RegionId"] = *partitionId;
670 }
671
672 if (passphraseState != nullptr)
673 {
674 partition["PassphraseEnabled"] = *passphraseState;
675 }
676
677 if (sizeInKiB != nullptr)
678 {
679 partition["SizeMiB"] = (*sizeInKiB >> 10);
680 }
681
Ed Tanousac106bf2023-06-07 09:24:59 -0700682 asyncResp->res.jsonValue[regionPtr].emplace_back(std::move(partition));
Nan Zhouef00d7d2022-05-20 21:22:32 +0000683}
684
Ed Tanousac106bf2023-06-07 09:24:59 -0700685inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000686 const std::string& service,
687 const std::string& path)
James Feist45094ad2020-04-29 14:02:30 -0700688{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200689 sdbusplus::asio::getAllProperties(
690 *crow::connections::systemBus, service, path,
691 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition",
Ed Tanousac106bf2023-06-07 09:24:59 -0700692 [asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800693 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800694 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700695 if (ec)
696 {
Ed Tanous62598e32023-07-17 17:06:25 -0700697 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -0700698 messages::internalError(asyncResp->res);
James Feist45094ad2020-04-29 14:02:30 -0700699
Ed Tanous002d39b2022-05-31 08:59:27 -0700700 return;
701 }
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000702 nlohmann::json::json_pointer regionPtr = "/Regions"_json_pointer;
Ed Tanousac106bf2023-06-07 09:24:59 -0700703 assembleDimmPartitionData(asyncResp, properties, regionPtr);
Patrick Williams5a39f772023-10-20 11:20:21 -0500704 }
James Feist45094ad2020-04-29 14:02:30 -0700705
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200706 );
James Feist45094ad2020-04-29 14:02:30 -0700707}
708
Ed Tanousac106bf2023-06-07 09:24:59 -0700709inline void getDimmData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000710 const std::string& dimmId)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200711{
Ed Tanous62598e32023-07-17 17:06:25 -0700712 BMCWEB_LOG_DEBUG("Get available system dimm resources.");
George Liue99073f2022-12-09 11:06:16 +0800713 constexpr std::array<std::string_view, 2> dimmInterfaces = {
714 "xyz.openbmc_project.Inventory.Item.Dimm",
715 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition"};
716 dbus::utility::getSubTree(
717 "/xyz/openbmc_project/inventory", 0, dimmInterfaces,
Ed Tanousac106bf2023-06-07 09:24:59 -0700718 [dimmId, asyncResp{std::move(asyncResp)}](
George Liue99073f2022-12-09 11:06:16 +0800719 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800720 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700721 if (ec)
722 {
Ed Tanous62598e32023-07-17 17:06:25 -0700723 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -0700724 messages::internalError(asyncResp->res);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200725
Ed Tanous002d39b2022-05-31 08:59:27 -0700726 return;
727 }
728 bool found = false;
Nan Zhou76686dc2022-06-17 23:01:51 +0000729 for (const auto& [rawPath, object] : subtree)
Ed Tanous002d39b2022-05-31 08:59:27 -0700730 {
Nan Zhou76686dc2022-06-17 23:01:51 +0000731 sdbusplus::message::object_path path(rawPath);
732 for (const auto& [service, interfaces] : object)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200733 {
Nan Zhou76686dc2022-06-17 23:01:51 +0000734 for (const auto& interface : interfaces)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200735 {
Nan Zhou76686dc2022-06-17 23:01:51 +0000736 if (interface ==
737 "xyz.openbmc_project.Inventory.Item.Dimm" &&
738 path.filename() == dimmId)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200739 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700740 getDimmDataByService(asyncResp, dimmId, service,
741 rawPath);
Nan Zhou76686dc2022-06-17 23:01:51 +0000742 found = true;
743 }
James Feist45094ad2020-04-29 14:02:30 -0700744
Nan Zhou76686dc2022-06-17 23:01:51 +0000745 // partitions are separate as there can be multiple
746 // per
747 // device, i.e.
748 // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition1
749 // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition2
750 if (interface ==
751 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition" &&
752 path.parent_path().filename() == dimmId)
753 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700754 getDimmPartitionData(asyncResp, service, rawPath);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200755 }
756 }
757 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700758 }
759 // Object not found
760 if (!found)
761 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700762 messages::resourceNotFound(asyncResp->res, "Memory", dimmId);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200763 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700764 }
765 // Set @odata only if object is found
Ed Tanousac106bf2023-06-07 09:24:59 -0700766 asyncResp->res.jsonValue["@odata.type"] = "#Memory.v1_11_0.Memory";
767 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -0700768 boost::urls::format("/redfish/v1/Systems/{}/Memory/{}",
769 BMCWEB_REDFISH_SYSTEM_URI_NAME, dimmId);
Ed Tanous002d39b2022-05-31 08:59:27 -0700770 return;
Patrick Williams5a39f772023-10-20 11:20:21 -0500771 });
Ed Tanous271584a2019-07-09 16:24:22 -0700772}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200773
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700774inline void requestRoutesMemoryCollection(App& app)
Ed Tanous029573d2019-02-01 10:57:49 -0800775{
Ed Tanous029573d2019-02-01 10:57:49 -0800776 /**
777 * Functions triggers appropriate requests on DBus
778 */
Ed Tanous22d268c2022-05-19 09:39:07 -0700779 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/")
Ed Tanoused398212021-06-09 17:05:54 -0700780 .privileges(redfish::privileges::getMemoryCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700781 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700782 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -0700783 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
784 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000785 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700786 {
787 return;
788 }
Ed Tanous25b54db2024-04-17 15:40:31 -0700789 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800790 {
791 // Option currently returns no systems. TBD
792 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
793 systemName);
794 return;
795 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700796 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -0700797 {
798 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
799 systemName);
800 return;
801 }
802
Ed Tanous002d39b2022-05-31 08:59:27 -0700803 asyncResp->res.jsonValue["@odata.type"] =
804 "#MemoryCollection.MemoryCollection";
805 asyncResp->res.jsonValue["Name"] = "Memory Module Collection";
Ed Tanous253f11b2024-05-16 09:38:31 -0700806 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
807 "/redfish/v1/Systems/{}/Memory", BMCWEB_REDFISH_SYSTEM_URI_NAME);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200808
George Liu7a1dbc42022-12-07 16:03:22 +0800809 constexpr std::array<std::string_view, 1> interfaces{
810 "xyz.openbmc_project.Inventory.Item.Dimm"};
Ed Tanous002d39b2022-05-31 08:59:27 -0700811 collection_util::getCollectionMembers(
Ed Tanous253f11b2024-05-16 09:38:31 -0700812 asyncResp,
813 boost::urls::format("/redfish/v1/Systems/{}/Memory",
814 BMCWEB_REDFISH_SYSTEM_URI_NAME),
Lakshmi Yadlapati36b5f1e2023-09-26 23:53:28 -0500815 interfaces, "/xyz/openbmc_project/inventory");
Patrick Williams5a39f772023-10-20 11:20:21 -0500816 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700817}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200818
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700819inline void requestRoutesMemory(App& app)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200820{
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200821 /**
822 * Functions triggers appropriate requests on DBus
823 */
Ed Tanous22d268c2022-05-19 09:39:07 -0700824 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700825 .privileges(redfish::privileges::getMemory)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700826 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700827 [&app](const crow::Request& req,
828 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -0700829 const std::string& systemName, const std::string& dimmId) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000830 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700831 {
832 return;
833 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800834
Ed Tanous25b54db2024-04-17 15:40:31 -0700835 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800836 {
837 // Option currently returns no systems. TBD
838 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
839 systemName);
840 return;
841 }
842
Ed Tanous253f11b2024-05-16 09:38:31 -0700843 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -0700844 {
845 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
846 systemName);
847 return;
848 }
849
Ed Tanous002d39b2022-05-31 08:59:27 -0700850 getDimmData(asyncResp, dimmId);
Patrick Williams5a39f772023-10-20 11:20:21 -0500851 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700852}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200853
854} // namespace redfish