blob: 551a5790a101e10dc456be7f892011f83ea84ae1 [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"
James Feist35e257a2020-06-05 13:30:51 -070022#include "health.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080023#include "query.hpp"
24#include "registries/privilege_registry.hpp"
25#include "utils/collection.hpp"
26#include "utils/dbus_utils.hpp"
27#include "utils/hex_utils.hpp"
28#include "utils/json_utils.hpp"
James Feist35e257a2020-06-05 13:30:51 -070029
George Liue99073f2022-12-09 11:06:16 +080030#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070031#include <boost/url/format.hpp>
Nan Zhoud7f04fd2022-05-01 01:11:07 +000032#include <nlohmann/json.hpp>
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +020033#include <sdbusplus/asio/property.hpp>
34#include <sdbusplus/unpack_properties.hpp>
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020035
George Liu7a1dbc42022-12-07 16:03:22 +080036#include <array>
37#include <string_view>
38
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020039namespace redfish
40{
41
Gunnar Mills313efb12020-10-26 16:05:08 -050042inline std::string translateMemoryTypeToRedfish(const std::string& memoryType)
43{
44 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR")
45 {
46 return "DDR";
47 }
48 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2")
49 {
50 return "DDR2";
51 }
52 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR3")
53 {
54 return "DDR3";
55 }
56 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4")
57 {
58 return "DDR4";
59 }
60 if (memoryType ==
61 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4E_SDRAM")
62 {
63 return "DDR4E_SDRAM";
64 }
Mansi Joshi11a2f0f2021-07-19 14:33:27 +053065 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR5")
66 {
67 return "DDR5";
68 }
Gunnar Mills313efb12020-10-26 16:05:08 -050069 if (memoryType ==
70 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR4_SDRAM")
71 {
72 return "LPDDR4_SDRAM";
73 }
74 if (memoryType ==
75 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR3_SDRAM")
76 {
77 return "LPDDR3_SDRAM";
78 }
79 if (memoryType ==
80 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM")
81 {
82 return "DDR2_SDRAM_FB_DIMM";
83 }
George Liu0fda0f12021-11-16 10:06:17 +080084 if (memoryType ==
85 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM_PROB")
Gunnar Mills313efb12020-10-26 16:05:08 -050086 {
87 return "DDR2_SDRAM_FB_DIMM_PROBE";
88 }
89 if (memoryType ==
90 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR_SGRAM")
91 {
92 return "DDR_SGRAM";
93 }
94 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.ROM")
95 {
96 return "ROM";
97 }
98 if (memoryType ==
99 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.SDRAM")
100 {
101 return "SDRAM";
102 }
103 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.EDO")
104 {
105 return "EDO";
106 }
107 if (memoryType ==
108 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.FastPageMode")
109 {
110 return "FastPageMode";
111 }
112 if (memoryType ==
113 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.PipelinedNibble")
114 {
115 return "PipelinedNibble";
116 }
117 if (memoryType ==
118 "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.Logical")
119 {
120 return "Logical";
121 }
122 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM")
123 {
124 return "HBM";
125 }
126 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM2")
127 {
128 return "HBM2";
129 }
Tyson Tuckerbearce34d512022-09-13 16:26:15 -0700130 if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM3")
131 {
132 return "HBM3";
133 }
Gunnar Mills313efb12020-10-26 16:05:08 -0500134 // This is values like Other or Unknown
135 // Also D-Bus values:
136 // DRAM
137 // EDRAM
138 // VRAM
139 // SRAM
140 // RAM
141 // FLASH
142 // EEPROM
143 // FEPROM
144 // EPROM
145 // CDRAM
146 // ThreeDRAM
147 // RDRAM
148 // FBD2
149 // LPDDR_SDRAM
150 // LPDDR2_SDRAM
Mansi Joshi11a2f0f2021-07-19 14:33:27 +0530151 // LPDDR5_SDRAM
Gunnar Mills313efb12020-10-26 16:05:08 -0500152 return "";
153}
154
Ed Tanousac106bf2023-06-07 09:24:59 -0700155inline void dimmPropToHex(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200156 const char* key, const uint16_t* value,
157 const nlohmann::json::json_pointer& jsonPtr)
James Feistc50e7c62020-07-27 15:39:36 -0700158{
James Feistc50e7c62020-07-27 15:39:36 -0700159 if (value == nullptr)
160 {
James Feistc50e7c62020-07-27 15:39:36 -0700161 return;
162 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700163 asyncResp->res.jsonValue[jsonPtr][key] = "0x" + intToHexString(*value, 4);
James Feistc50e7c62020-07-27 15:39:36 -0700164}
165
zhanghch058d1b46d2021-04-01 11:18:24 +0800166inline void getPersistentMemoryProperties(
Ed Tanousac106bf2023-06-07 09:24:59 -0700167 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200168 const dbus::utility::DBusPropertiesMap& properties,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000169 const nlohmann::json::json_pointer& jsonPtr)
James Feistc50e7c62020-07-27 15:39:36 -0700170{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200171 const uint16_t* moduleManufacturerID = nullptr;
172 const uint16_t* moduleProductID = nullptr;
173 const uint16_t* subsystemVendorID = nullptr;
174 const uint16_t* subsystemDeviceID = nullptr;
175 const uint64_t* volatileRegionSizeLimitInKiB = nullptr;
176 const uint64_t* pmRegionSizeLimitInKiB = nullptr;
177 const uint64_t* volatileSizeInKiB = nullptr;
178 const uint64_t* pmSizeInKiB = nullptr;
179 const uint64_t* cacheSizeInKB = nullptr;
180 const uint64_t* voltaileRegionMaxSizeInKib = nullptr;
181 const uint64_t* pmRegionMaxSizeInKiB = nullptr;
182 const uint64_t* allocationIncrementInKiB = nullptr;
183 const uint64_t* allocationAlignmentInKiB = nullptr;
184 const uint64_t* volatileRegionNumberLimit = nullptr;
185 const uint64_t* pmRegionNumberLimit = nullptr;
186 const uint64_t* spareDeviceCount = nullptr;
187 const bool* isSpareDeviceInUse = nullptr;
188 const bool* isRankSpareEnabled = nullptr;
189 const std::vector<uint32_t>* maxAveragePowerLimitmW = nullptr;
190 const bool* configurationLocked = nullptr;
191 const std::string* allowedMemoryModes = nullptr;
192 const std::string* memoryMedia = nullptr;
193 const bool* configurationLockCapable = nullptr;
194 const bool* dataLockCapable = nullptr;
195 const bool* passphraseCapable = nullptr;
196 const uint64_t* maxPassphraseCount = nullptr;
197 const uint64_t* passphraseLockLimit = nullptr;
James Feistc50e7c62020-07-27 15:39:36 -0700198
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200199 const bool success = sdbusplus::unpackPropertiesNoThrow(
200 dbus_utils::UnpackErrorPrinter(), properties, "ModuleManufacturerID",
201 moduleManufacturerID, "ModuleProductID", moduleProductID,
202 "SubsystemVendorID", subsystemVendorID, "SubsystemDeviceID",
203 subsystemDeviceID, "VolatileRegionSizeLimitInKiB",
204 volatileRegionSizeLimitInKiB, "PmRegionSizeLimitInKiB",
205 pmRegionSizeLimitInKiB, "VolatileSizeInKiB", volatileSizeInKiB,
206 "PmSizeInKiB", pmSizeInKiB, "CacheSizeInKB", cacheSizeInKB,
207 "VoltaileRegionMaxSizeInKib", voltaileRegionMaxSizeInKib,
208 "PmRegionMaxSizeInKiB", pmRegionMaxSizeInKiB,
209 "AllocationIncrementInKiB", allocationIncrementInKiB,
210 "AllocationAlignmentInKiB", allocationAlignmentInKiB,
211 "VolatileRegionNumberLimit", volatileRegionNumberLimit,
212 "PmRegionNumberLimit", pmRegionNumberLimit, "SpareDeviceCount",
213 spareDeviceCount, "IsSpareDeviceInUse", isSpareDeviceInUse,
214 "IsRankSpareEnabled", isRankSpareEnabled, "MaxAveragePowerLimitmW",
215 maxAveragePowerLimitmW, "ConfigurationLocked", configurationLocked,
216 "AllowedMemoryModes", allowedMemoryModes, "MemoryMedia", memoryMedia,
217 "ConfigurationLockCapable", configurationLockCapable, "DataLockCapable",
218 dataLockCapable, "PassphraseCapable", passphraseCapable,
219 "MaxPassphraseCount", maxPassphraseCount, "PassphraseLockLimit",
220 passphraseLockLimit);
221
222 if (!success)
223 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700224 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200225 return;
226 }
227
Ed Tanousac106bf2023-06-07 09:24:59 -0700228 dimmPropToHex(asyncResp, "ModuleManufacturerID", moduleManufacturerID,
229 jsonPtr);
230 dimmPropToHex(asyncResp, "ModuleProductID", moduleProductID, jsonPtr);
231 dimmPropToHex(asyncResp, "MemorySubsystemControllerManufacturerID",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200232 subsystemVendorID, jsonPtr);
Ed Tanousac106bf2023-06-07 09:24:59 -0700233 dimmPropToHex(asyncResp, "MemorySubsystemControllerProductID",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200234 subsystemDeviceID, jsonPtr);
235
236 if (volatileRegionSizeLimitInKiB != nullptr)
237 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700238 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionSizeLimitMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200239 (*volatileRegionSizeLimitInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800240 }
James Feistc50e7c62020-07-27 15:39:36 -0700241
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200242 if (pmRegionSizeLimitInKiB != nullptr)
243 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700244 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionSizeLimitMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200245 (*pmRegionSizeLimitInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800246 }
James Feistc50e7c62020-07-27 15:39:36 -0700247
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200248 if (volatileSizeInKiB != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800249 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700250 asyncResp->res.jsonValue[jsonPtr]["VolatileSizeMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200251 (*volatileSizeInKiB) >> 10;
252 }
253
254 if (pmSizeInKiB != nullptr)
255 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700256 asyncResp->res.jsonValue[jsonPtr]["NonVolatileSizeMiB"] =
257 (*pmSizeInKiB) >> 10;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200258 }
259
260 if (cacheSizeInKB != nullptr)
261 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700262 asyncResp->res.jsonValue[jsonPtr]["CacheSizeMiB"] =
263 (*cacheSizeInKB >> 10);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200264 }
265
266 if (voltaileRegionMaxSizeInKib != nullptr)
267 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700268 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionSizeMaxMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200269 (*voltaileRegionMaxSizeInKib) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800270 }
James Feistc50e7c62020-07-27 15:39:36 -0700271
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200272 if (pmRegionMaxSizeInKiB != nullptr)
273 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700274 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionSizeMaxMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200275 (*pmRegionMaxSizeInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800276 }
James Feistc50e7c62020-07-27 15:39:36 -0700277
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200278 if (allocationIncrementInKiB != nullptr)
279 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700280 asyncResp->res.jsonValue[jsonPtr]["AllocationIncrementMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200281 (*allocationIncrementInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800282 }
James Feistc50e7c62020-07-27 15:39:36 -0700283
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200284 if (allocationAlignmentInKiB != nullptr)
285 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700286 asyncResp->res.jsonValue[jsonPtr]["AllocationAlignmentMiB"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200287 (*allocationAlignmentInKiB) >> 10;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800288 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200289
290 if (volatileRegionNumberLimit != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800291 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700292 asyncResp->res.jsonValue[jsonPtr]["VolatileRegionNumberLimit"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200293 *volatileRegionNumberLimit;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800294 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200295
296 if (pmRegionNumberLimit != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800297 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700298 asyncResp->res.jsonValue[jsonPtr]["PersistentRegionNumberLimit"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200299 *pmRegionNumberLimit;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800300 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200301
302 if (spareDeviceCount != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800303 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700304 asyncResp->res.jsonValue[jsonPtr]["SpareDeviceCount"] =
305 *spareDeviceCount;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800306 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200307
308 if (isSpareDeviceInUse != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800309 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700310 asyncResp->res.jsonValue[jsonPtr]["IsSpareDeviceEnabled"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200311 *isSpareDeviceInUse;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800312 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200313
314 if (isRankSpareEnabled != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800315 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700316 asyncResp->res.jsonValue[jsonPtr]["IsRankSpareEnabled"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200317 *isRankSpareEnabled;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800318 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200319
320 if (maxAveragePowerLimitmW != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800321 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700322 asyncResp->res.jsonValue[jsonPtr]["MaxTDPMilliWatts"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200323 *maxAveragePowerLimitmW;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800324 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200325
326 if (configurationLocked != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800327 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700328 asyncResp->res.jsonValue[jsonPtr]["ConfigurationLocked"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200329 *configurationLocked;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800330 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200331
332 if (allowedMemoryModes != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800333 {
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800334 constexpr const std::array<const char*, 3> values{"Volatile", "PMEM",
335 "Block"};
James Feistc50e7c62020-07-27 15:39:36 -0700336
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800337 for (const char* v : values)
338 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200339 if (allowedMemoryModes->ends_with(v))
James Feistc50e7c62020-07-27 15:39:36 -0700340 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700341 asyncResp->res.jsonValue[jsonPtr]["OperatingMemoryModes"]
342 .push_back(v);
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800343 break;
James Feistc50e7c62020-07-27 15:39:36 -0700344 }
345 }
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800346 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200347
348 if (memoryMedia != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800349 {
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800350 constexpr const std::array<const char*, 3> values{"DRAM", "NAND",
351 "Intel3DXPoint"};
James Feistc50e7c62020-07-27 15:39:36 -0700352
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800353 for (const char* v : values)
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700354 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200355 if (memoryMedia->ends_with(v))
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700356 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700357 asyncResp->res.jsonValue[jsonPtr]["MemoryMedia"].push_back(v);
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800358 break;
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700359 }
Ed Tanous5fb91ba2020-09-28 15:41:28 -0700360 }
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800361 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200362
363 if (configurationLockCapable != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800364 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700365 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
366 ["ConfigurationLockCapable"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200367 *configurationLockCapable;
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800368 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200369
370 if (dataLockCapable != nullptr)
Jiaqing Zhao80badf72022-03-18 17:48:53 +0800371 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700372 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
373 ["DataLockCapable"] = *dataLockCapable;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200374 }
375
376 if (passphraseCapable != nullptr)
377 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700378 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
379 ["PassphraseCapable"] = *passphraseCapable;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200380 }
381
382 if (maxPassphraseCount != nullptr)
383 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700384 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
385 ["MaxPassphraseCount"] = *maxPassphraseCount;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200386 }
387
388 if (passphraseLockLimit != nullptr)
389 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700390 asyncResp->res.jsonValue[jsonPtr]["SecurityCapabilities"]
391 ["PassphraseLockLimit"] = *passphraseLockLimit;
James Feistc50e7c62020-07-27 15:39:36 -0700392 }
393}
394
Nan Zhou9a5acea2022-05-17 21:12:43 +0000395inline void
396 assembleDimmProperties(std::string_view dimmId,
Ed Tanousac106bf2023-06-07 09:24:59 -0700397 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000398 const dbus::utility::DBusPropertiesMap& properties,
399 const nlohmann::json::json_pointer& jsonPtr)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000400{
Ed Tanousac106bf2023-06-07 09:24:59 -0700401 asyncResp->res.jsonValue[jsonPtr]["Id"] = dimmId;
402 asyncResp->res.jsonValue[jsonPtr]["Name"] = "DIMM Slot";
403 asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] = "Enabled";
404 asyncResp->res.jsonValue[jsonPtr]["Status"]["Health"] = "OK";
Nan Zhou9a5acea2022-05-17 21:12:43 +0000405
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200406 const uint16_t* memoryDataWidth = nullptr;
407 const size_t* memorySizeInKB = nullptr;
408 const std::string* partNumber = nullptr;
409 const std::string* serialNumber = nullptr;
410 const std::string* manufacturer = nullptr;
411 const uint16_t* revisionCode = nullptr;
412 const bool* present = nullptr;
413 const uint16_t* memoryTotalWidth = nullptr;
414 const std::string* ecc = nullptr;
415 const std::string* formFactor = nullptr;
416 const std::vector<uint16_t>* allowedSpeedsMT = nullptr;
George Liu6995c1c2023-06-15 08:53:11 +0800417 const size_t* memoryAttributes = nullptr;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200418 const uint16_t* memoryConfiguredSpeedInMhz = nullptr;
419 const std::string* memoryType = nullptr;
Jayaprakash Mutyala6fde5972023-06-15 07:56:58 +0000420 const std::uint8_t* channel = nullptr;
421 const std::uint8_t* memoryController = nullptr;
422 const std::uint8_t* slot = nullptr;
423 const std::uint8_t* socket = nullptr;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200424 const std::string* sparePartNumber = nullptr;
425 const std::string* model = nullptr;
426 const std::string* locationCode = nullptr;
427
428 const bool success = sdbusplus::unpackPropertiesNoThrow(
429 dbus_utils::UnpackErrorPrinter(), properties, "MemoryDataWidth",
430 memoryDataWidth, "MemorySizeInKB", memorySizeInKB, "PartNumber",
Nikhil Namjoshi656472d2022-09-13 20:54:44 +0000431 partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer,
432 "RevisionCode", revisionCode, "Present", present, "MemoryTotalWidth",
433 memoryTotalWidth, "ECC", ecc, "FormFactor", formFactor,
434 "AllowedSpeedsMT", allowedSpeedsMT, "MemoryAttributes",
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200435 memoryAttributes, "MemoryConfiguredSpeedInMhz",
436 memoryConfiguredSpeedInMhz, "MemoryType", memoryType, "Channel",
437 channel, "MemoryController", memoryController, "Slot", slot, "Socket",
438 socket, "SparePartNumber", sparePartNumber, "Model", model,
439 "LocationCode", locationCode);
440
441 if (!success)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000442 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700443 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200444 return;
445 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000446
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200447 if (memoryDataWidth != nullptr)
448 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700449 asyncResp->res.jsonValue[jsonPtr]["DataWidthBits"] = *memoryDataWidth;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200450 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000451
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200452 if (memorySizeInKB != nullptr)
453 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700454 asyncResp->res.jsonValue[jsonPtr]["CapacityMiB"] =
455 (*memorySizeInKB >> 10);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200456 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000457
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200458 if (partNumber != nullptr)
459 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700460 asyncResp->res.jsonValue[jsonPtr]["PartNumber"] = *partNumber;
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 (serialNumber != nullptr)
464 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700465 asyncResp->res.jsonValue[jsonPtr]["SerialNumber"] = *serialNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200466 }
467
468 if (manufacturer != nullptr)
469 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700470 asyncResp->res.jsonValue[jsonPtr]["Manufacturer"] = *manufacturer;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200471 }
472
473 if (revisionCode != nullptr)
474 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700475 asyncResp->res.jsonValue[jsonPtr]["FirmwareRevision"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200476 std::to_string(*revisionCode);
477 }
478
479 if (present != nullptr && !*present)
480 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700481 asyncResp->res.jsonValue[jsonPtr]["Status"]["State"] = "Absent";
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200482 }
483
484 if (memoryTotalWidth != nullptr)
485 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700486 asyncResp->res.jsonValue[jsonPtr]["BusWidthBits"] = *memoryTotalWidth;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200487 }
488
489 if (ecc != nullptr)
490 {
491 constexpr const std::array<const char*, 4> values{
492 "NoECC", "SingleBitECC", "MultiBitECC", "AddressParity"};
493
494 for (const char* v : values)
Nan Zhou9a5acea2022-05-17 21:12:43 +0000495 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200496 if (ecc->ends_with(v))
Nan Zhou9a5acea2022-05-17 21:12:43 +0000497 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700498 asyncResp->res.jsonValue[jsonPtr]["ErrorCorrection"] = v;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200499 break;
Nan Zhou9a5acea2022-05-17 21:12:43 +0000500 }
Nan Zhou9a5acea2022-05-17 21:12:43 +0000501 }
502 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200503
504 if (formFactor != nullptr)
505 {
506 constexpr const std::array<const char*, 11> values{
507 "RDIMM", "UDIMM", "SO_DIMM", "LRDIMM",
508 "Mini_RDIMM", "Mini_UDIMM", "SO_RDIMM_72b", "SO_UDIMM_72b",
509 "SO_DIMM_16b", "SO_DIMM_32b", "Die"};
510
511 for (const char* v : values)
512 {
513 if (formFactor->ends_with(v))
514 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700515 asyncResp->res.jsonValue[jsonPtr]["BaseModuleType"] = v;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200516 break;
517 }
518 }
519 }
520
521 if (allowedSpeedsMT != nullptr)
522 {
523 nlohmann::json& jValue =
Ed Tanousac106bf2023-06-07 09:24:59 -0700524 asyncResp->res.jsonValue[jsonPtr]["AllowedSpeedsMHz"];
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200525 jValue = nlohmann::json::array();
526 for (uint16_t subVal : *allowedSpeedsMT)
527 {
528 jValue.push_back(subVal);
529 }
530 }
531
532 if (memoryAttributes != nullptr)
533 {
George Liu6995c1c2023-06-15 08:53:11 +0800534 asyncResp->res.jsonValue[jsonPtr]["RankCount"] = *memoryAttributes;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200535 }
536
537 if (memoryConfiguredSpeedInMhz != nullptr)
538 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700539 asyncResp->res.jsonValue[jsonPtr]["OperatingSpeedMhz"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200540 *memoryConfiguredSpeedInMhz;
541 }
542
543 if (memoryType != nullptr)
544 {
545 std::string memoryDeviceType =
546 translateMemoryTypeToRedfish(*memoryType);
547 // Values like "Unknown" or "Other" will return empty
548 // so just leave off
549 if (!memoryDeviceType.empty())
550 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700551 asyncResp->res.jsonValue[jsonPtr]["MemoryDeviceType"] =
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200552 memoryDeviceType;
553 }
554 if (memoryType->find("DDR") != std::string::npos)
555 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700556 asyncResp->res.jsonValue[jsonPtr]["MemoryType"] = "DRAM";
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200557 }
558 else if (memoryType->ends_with("Logical"))
559 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700560 asyncResp->res.jsonValue[jsonPtr]["MemoryType"] = "IntelOptane";
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200561 }
562 }
563
564 if (channel != nullptr)
565 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700566 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Channel"] =
567 *channel;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200568 }
569
570 if (memoryController != nullptr)
571 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700572 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]
573 ["MemoryController"] = *memoryController;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200574 }
575
576 if (slot != nullptr)
577 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700578 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Slot"] = *slot;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200579 }
580
581 if (socket != nullptr)
582 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700583 asyncResp->res.jsonValue[jsonPtr]["MemoryLocation"]["Socket"] = *socket;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200584 }
585
586 if (sparePartNumber != nullptr)
587 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700588 asyncResp->res.jsonValue[jsonPtr]["SparePartNumber"] = *sparePartNumber;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200589 }
590
591 if (model != nullptr)
592 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700593 asyncResp->res.jsonValue[jsonPtr]["Model"] = *model;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200594 }
595
596 if (locationCode != nullptr)
597 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700598 asyncResp->res.jsonValue[jsonPtr]["Location"]["PartLocation"]
599 ["ServiceLabel"] = *locationCode;
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200600 }
601
Ed Tanousac106bf2023-06-07 09:24:59 -0700602 getPersistentMemoryProperties(asyncResp, properties, jsonPtr);
Nan Zhou9a5acea2022-05-17 21:12:43 +0000603}
604
Ed Tanousac106bf2023-06-07 09:24:59 -0700605inline void getDimmDataByService(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous80789c82020-08-19 09:19:09 -0700606 const std::string& dimmId,
607 const std::string& service,
608 const std::string& objPath)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200609{
Willy Tu13451e32023-05-24 16:08:18 -0700610 if constexpr (bmcwebEnableHealthPopulate)
611 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700612 auto health = std::make_shared<HealthPopulate>(asyncResp);
Willy Tu13451e32023-05-24 16:08:18 -0700613 health->selfPath = objPath;
614 health->populate();
615 }
James Feist35e257a2020-06-05 13:30:51 -0700616
Ed Tanous62598e32023-07-17 17:06:25 -0700617 BMCWEB_LOG_DEBUG("Get available system components.");
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200618 sdbusplus::asio::getAllProperties(
619 *crow::connections::systemBus, service, objPath, "",
Ed Tanousac106bf2023-06-07 09:24:59 -0700620 [dimmId, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800621 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800622 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700623 if (ec)
624 {
Ed Tanous62598e32023-07-17 17:06:25 -0700625 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -0700626 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700627 return;
628 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700629 assembleDimmProperties(dimmId, asyncResp, properties, ""_json_pointer);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200630 });
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200631}
632
Nan Zhouef00d7d2022-05-20 21:22:32 +0000633inline void assembleDimmPartitionData(
Ed Tanousac106bf2023-06-07 09:24:59 -0700634 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000635 const dbus::utility::DBusPropertiesMap& properties,
636 const nlohmann::json::json_pointer& regionPtr)
Nan Zhouef00d7d2022-05-20 21:22:32 +0000637{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200638 const std::string* memoryClassification = nullptr;
639 const uint64_t* offsetInKiB = nullptr;
640 const std::string* partitionId = nullptr;
641 const bool* passphraseState = nullptr;
642 const uint64_t* sizeInKiB = nullptr;
643
644 const bool success = sdbusplus::unpackPropertiesNoThrow(
645 dbus_utils::UnpackErrorPrinter(), properties, "MemoryClassification",
646 memoryClassification, "OffsetInKiB", offsetInKiB, "PartitionId",
647 partitionId, "PassphraseState", passphraseState, "SizeInKiB",
648 sizeInKiB);
649
650 if (!success)
Nan Zhouef00d7d2022-05-20 21:22:32 +0000651 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700652 messages::internalError(asyncResp->res);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200653 return;
Nan Zhouef00d7d2022-05-20 21:22:32 +0000654 }
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200655
656 nlohmann::json::object_t partition;
657
658 if (memoryClassification != nullptr)
659 {
660 partition["MemoryClassification"] = *memoryClassification;
661 }
662
663 if (offsetInKiB != nullptr)
664 {
665 partition["OffsetMiB"] = (*offsetInKiB >> 10);
666 }
667
668 if (partitionId != nullptr)
669 {
670 partition["RegionId"] = *partitionId;
671 }
672
673 if (passphraseState != nullptr)
674 {
675 partition["PassphraseEnabled"] = *passphraseState;
676 }
677
678 if (sizeInKiB != nullptr)
679 {
680 partition["SizeMiB"] = (*sizeInKiB >> 10);
681 }
682
Ed Tanousac106bf2023-06-07 09:24:59 -0700683 asyncResp->res.jsonValue[regionPtr].emplace_back(std::move(partition));
Nan Zhouef00d7d2022-05-20 21:22:32 +0000684}
685
Ed Tanousac106bf2023-06-07 09:24:59 -0700686inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000687 const std::string& service,
688 const std::string& path)
James Feist45094ad2020-04-29 14:02:30 -0700689{
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200690 sdbusplus::asio::getAllProperties(
691 *crow::connections::systemBus, service, path,
692 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition",
Ed Tanousac106bf2023-06-07 09:24:59 -0700693 [asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800694 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800695 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700696 if (ec)
697 {
Ed Tanous62598e32023-07-17 17:06:25 -0700698 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -0700699 messages::internalError(asyncResp->res);
James Feist45094ad2020-04-29 14:02:30 -0700700
Ed Tanous002d39b2022-05-31 08:59:27 -0700701 return;
702 }
Nan Zhoud7f04fd2022-05-01 01:11:07 +0000703 nlohmann::json::json_pointer regionPtr = "/Regions"_json_pointer;
Ed Tanousac106bf2023-06-07 09:24:59 -0700704 assembleDimmPartitionData(asyncResp, properties, regionPtr);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200705 }
James Feist45094ad2020-04-29 14:02:30 -0700706
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200707 );
James Feist45094ad2020-04-29 14:02:30 -0700708}
709
Ed Tanousac106bf2023-06-07 09:24:59 -0700710inline void getDimmData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000711 const std::string& dimmId)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200712{
Ed Tanous62598e32023-07-17 17:06:25 -0700713 BMCWEB_LOG_DEBUG("Get available system dimm resources.");
George Liue99073f2022-12-09 11:06:16 +0800714 constexpr std::array<std::string_view, 2> dimmInterfaces = {
715 "xyz.openbmc_project.Inventory.Item.Dimm",
716 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition"};
717 dbus::utility::getSubTree(
718 "/xyz/openbmc_project/inventory", 0, dimmInterfaces,
Ed Tanousac106bf2023-06-07 09:24:59 -0700719 [dimmId, asyncResp{std::move(asyncResp)}](
George Liue99073f2022-12-09 11:06:16 +0800720 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800721 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700722 if (ec)
723 {
Ed Tanous62598e32023-07-17 17:06:25 -0700724 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -0700725 messages::internalError(asyncResp->res);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200726
Ed Tanous002d39b2022-05-31 08:59:27 -0700727 return;
728 }
729 bool found = false;
Nan Zhou76686dc2022-06-17 23:01:51 +0000730 for (const auto& [rawPath, object] : subtree)
Ed Tanous002d39b2022-05-31 08:59:27 -0700731 {
Nan Zhou76686dc2022-06-17 23:01:51 +0000732 sdbusplus::message::object_path path(rawPath);
733 for (const auto& [service, interfaces] : object)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200734 {
Nan Zhou76686dc2022-06-17 23:01:51 +0000735 for (const auto& interface : interfaces)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200736 {
Nan Zhou76686dc2022-06-17 23:01:51 +0000737 if (interface ==
738 "xyz.openbmc_project.Inventory.Item.Dimm" &&
739 path.filename() == dimmId)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200740 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700741 getDimmDataByService(asyncResp, dimmId, service,
742 rawPath);
Nan Zhou76686dc2022-06-17 23:01:51 +0000743 found = true;
744 }
James Feist45094ad2020-04-29 14:02:30 -0700745
Nan Zhou76686dc2022-06-17 23:01:51 +0000746 // partitions are separate as there can be multiple
747 // per
748 // device, i.e.
749 // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition1
750 // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition2
751 if (interface ==
752 "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition" &&
753 path.parent_path().filename() == dimmId)
754 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700755 getDimmPartitionData(asyncResp, service, rawPath);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200756 }
757 }
758 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700759 }
760 // Object not found
761 if (!found)
762 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700763 messages::resourceNotFound(asyncResp->res, "Memory", dimmId);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200764 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700765 }
766 // Set @odata only if object is found
Ed Tanousac106bf2023-06-07 09:24:59 -0700767 asyncResp->res.jsonValue["@odata.type"] = "#Memory.v1_11_0.Memory";
768 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700769 boost::urls::format("/redfish/v1/Systems/system/Memory/{}", dimmId);
Ed Tanous002d39b2022-05-31 08:59:27 -0700770 return;
George Liue99073f2022-12-09 11:06:16 +0800771 });
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 Tanous7f3e84a2022-12-28 16:22:54 -0800789 if constexpr (bmcwebEnableMultiHost)
790 {
791 // Option currently returns no systems. TBD
792 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
793 systemName);
794 return;
795 }
Ed Tanous22d268c2022-05-19 09:39:07 -0700796 if (systemName != "system")
797 {
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";
806 asyncResp->res.jsonValue["@odata.id"] =
807 "/redfish/v1/Systems/system/Memory";
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(
Willy Tuae9031f2022-09-27 05:48:07 +0000812 asyncResp, boost::urls::url("/redfish/v1/Systems/system/Memory"),
George Liu7a1dbc42022-12-07 16:03:22 +0800813 interfaces);
Ed Tanous002d39b2022-05-31 08:59:27 -0700814 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700815}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200816
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700817inline void requestRoutesMemory(App& app)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200818{
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200819 /**
820 * Functions triggers appropriate requests on DBus
821 */
Ed Tanous22d268c2022-05-19 09:39:07 -0700822 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700823 .privileges(redfish::privileges::getMemory)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700824 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700825 [&app](const crow::Request& req,
826 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -0700827 const std::string& systemName, const std::string& dimmId) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000828 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700829 {
830 return;
831 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800832
833 if constexpr (bmcwebEnableMultiHost)
834 {
835 // Option currently returns no systems. TBD
836 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
837 systemName);
838 return;
839 }
840
Ed Tanous22d268c2022-05-19 09:39:07 -0700841 if (systemName != "system")
842 {
843 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
844 systemName);
845 return;
846 }
847
Ed Tanous002d39b2022-05-31 08:59:27 -0700848 getDimmData(asyncResp, dimmId);
849 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700850}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200851
852} // namespace redfish