blob: f33fbc12443a7f835d2a07ee5e0e4e263e8ec0c9 [file] [log] [blame]
Cheng C Yangeecaf822019-12-19 00:34:23 +08001/*
Zhikui Ren18a5ab92020-09-01 21:35:20 -07002// Copyright (c) 2018 Intel Corporation
Cheng C Yangeecaf822019-12-19 00:34:23 +08003//
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
17#include "mdrv2.hpp"
18
Jie Yang08e4a6d2021-08-23 13:07:41 -070019#include "pcieslot.hpp"
20
Cheng C Yangeecaf822019-12-19 00:34:23 +080021#include <sys/mman.h>
22
Cheng C Yangeecaf822019-12-19 00:34:23 +080023#include <phosphor-logging/elog-errors.hpp>
24#include <sdbusplus/exception.hpp>
25#include <xyz/openbmc_project/Smbios/MDR_V2/error.hpp>
26
Zhikui Ren18a5ab92020-09-01 21:35:20 -070027#include <fstream>
28
Cheng C Yangeecaf822019-12-19 00:34:23 +080029namespace phosphor
30{
31namespace smbios
32{
33
Jason M. Billsa3f5b382023-04-26 08:17:28 -070034std::vector<uint8_t> MDRV2::getDirectoryInformation(uint8_t dirIndex)
Cheng C Yangeecaf822019-12-19 00:34:23 +080035{
Cheng C Yang608e52d2019-12-19 00:39:50 +080036 std::vector<uint8_t> responseDir;
Prithvi A Paibc924d02021-12-29 04:54:43 +000037
Josh Lehan027277a2023-09-11 05:28:19 -070038 std::ifstream smbiosFile(smbiosFilePath, std::ios_base::binary);
Prithvi A Paibc924d02021-12-29 04:54:43 +000039 if (!smbiosFile.good())
40 {
41 phosphor::logging::log<phosphor::logging::level::ERR>(
42 "Read data from flash error - Open MDRV2 table file failure");
43 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
44 InvalidParameter();
45 }
Cheng C Yang608e52d2019-12-19 00:39:50 +080046 if (dirIndex > smbiosDir.dirEntries)
47 {
48 responseDir.push_back(0);
Kuiying Wanga4c08702020-11-18 19:27:20 +080049 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
50 InvalidParameter();
Cheng C Yang608e52d2019-12-19 00:39:50 +080051 }
52 responseDir.push_back(mdr2Version);
53 responseDir.push_back(smbiosDir.dirVersion);
54 uint8_t returnedEntries = smbiosDir.dirEntries - dirIndex;
55 responseDir.push_back(returnedEntries);
56 if ((dirIndex + returnedEntries) >= smbiosDir.dirEntries)
57 {
58 responseDir.push_back(0);
59 }
60 else
61 {
Patrick Williams1d73dcc2024-08-16 15:21:42 -040062 responseDir.push_back(
63 smbiosDir.dirEntries - dirIndex - returnedEntries);
Cheng C Yang608e52d2019-12-19 00:39:50 +080064 }
65 for (uint8_t index = dirIndex; index < smbiosDir.dirEntries; index++)
66 {
67 for (uint8_t indexId = 0; indexId < sizeof(DataIdStruct); indexId++)
68 {
69 responseDir.push_back(
70 smbiosDir.dir[index].common.id.dataInfo[indexId]);
71 }
72 }
73
74 return responseDir;
Cheng C Yangeecaf822019-12-19 00:34:23 +080075}
76
Jason M. Billsa3f5b382023-04-26 08:17:28 -070077bool MDRV2::smbiosIsAvailForUpdate(uint8_t index)
Cheng C Yangeecaf822019-12-19 00:34:23 +080078{
79 bool ret = false;
Chen Yugangad0e7652020-12-01 14:49:54 +080080 if (index >= maxDirEntries)
Cheng C Yangeecaf822019-12-19 00:34:23 +080081 {
82 return ret;
83 }
84
85 switch (smbiosDir.dir[index].stage)
86 {
87 case MDR2SMBIOSStatusEnum::mdr2Updating:
88 ret = false;
89 break;
90
91 case MDR2SMBIOSStatusEnum::mdr2Init:
92 // This *looks* like there should be a break statement here,
93 // as the effects of the previous statement are a noop given
94 // the following code that this falls through to.
95 // We've elected not to change it, though, since it's been
96 // this way since the old generation, and it would affect
97 // the way the code functions.
98 // If it ain't broke, don't fix it.
99
100 case MDR2SMBIOSStatusEnum::mdr2Loaded:
101 case MDR2SMBIOSStatusEnum::mdr2Updated:
102 if (smbiosDir.dir[index].lock == MDR2DirLockEnum::mdr2DirLock)
103 {
104 ret = false;
105 }
106 else
107 {
108 ret = true;
109 }
110 break;
111
112 default:
113 break;
114 }
115
116 return ret;
117}
118
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700119std::vector<uint8_t> MDRV2::getDataOffer()
Cheng C Yangeecaf822019-12-19 00:34:23 +0800120{
121 std::vector<uint8_t> offer(sizeof(DataIdStruct));
122 if (smbiosIsAvailForUpdate(0))
123 {
124 std::copy(smbiosDir.dir[0].common.id.dataInfo,
125 &smbiosDir.dir[0].common.id.dataInfo[16], offer.data());
126 }
127 else
128 {
129 phosphor::logging::log<phosphor::logging::level::ERR>(
130 "smbios is not ready for update");
Kuiying Wanga4c08702020-11-18 19:27:20 +0800131 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
132 UpdateInProgress();
Cheng C Yangeecaf822019-12-19 00:34:23 +0800133 }
134 return offer;
135}
136
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700137inline uint8_t MDRV2::smbiosValidFlag(uint8_t index)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800138{
139 FlagStatus ret = FlagStatus::flagIsInvalid;
140 MDR2SMBIOSStatusEnum stage = smbiosDir.dir[index].stage;
141 MDR2DirLockEnum lock = smbiosDir.dir[index].lock;
142
143 switch (stage)
144 {
145 case MDR2SMBIOSStatusEnum::mdr2Loaded:
146 case MDR2SMBIOSStatusEnum::mdr2Updated:
147 if (lock == MDR2DirLockEnum::mdr2DirLock)
148 {
149 ret = FlagStatus::flagIsLocked; // locked
150 }
151 else
152 {
153 ret = FlagStatus::flagIsValid; // valid
154 }
155 break;
156
157 case MDR2SMBIOSStatusEnum::mdr2Updating:
158 case MDR2SMBIOSStatusEnum::mdr2Init:
159 ret = FlagStatus::flagIsInvalid; // invalid
160 break;
161
162 default:
163 break;
164 }
165
166 return static_cast<uint8_t>(ret);
167}
168
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700169// If source variable size is 4 bytes (uint32_t) and destination is Vector type
170// is 1 byte (uint8_t), then by using this API can copy data byte by byte. For
171// Example copying data from smbiosDir.dir[idIndex].common.size and
172// smbiosDir.dir[idIndex].common.timestamp to vector variable responseInfo
173template <typename T>
174void appendReversed(std::vector<uint8_t>& vector, const T& value)
175{
176 auto data = reinterpret_cast<const uint8_t*>(&value);
177 std::reverse_copy(data, data + sizeof(value), std::back_inserter(vector));
178}
179
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700180std::vector<uint8_t> MDRV2::getDataInformation(uint8_t idIndex)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800181{
182 std::vector<uint8_t> responseInfo;
183 responseInfo.push_back(mdr2Version);
184
185 if (idIndex >= maxDirEntries)
186 {
Kuiying Wanga4c08702020-11-18 19:27:20 +0800187 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
188 InvalidParameter();
Cheng C Yangeecaf822019-12-19 00:34:23 +0800189 }
190
191 for (uint8_t index = 0; index < sizeof(DataIdStruct); index++)
192 {
193 responseInfo.push_back(
194 smbiosDir.dir[idIndex].common.id.dataInfo[index]);
195 }
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700196
Cheng C Yangeecaf822019-12-19 00:34:23 +0800197 responseInfo.push_back(smbiosValidFlag(idIndex));
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700198 appendReversed(responseInfo, smbiosDir.dir[idIndex].common.size);
Cheng C Yangeecaf822019-12-19 00:34:23 +0800199 responseInfo.push_back(smbiosDir.dir[idIndex].common.dataVersion);
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700200 appendReversed(responseInfo, smbiosDir.dir[idIndex].common.timestamp);
Cheng C Yangeecaf822019-12-19 00:34:23 +0800201
202 return responseInfo;
203}
204
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700205bool MDRV2::readDataFromFlash(MDRSMBIOSHeader* mdrHdr, uint8_t* data)
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700206{
207 if (mdrHdr == nullptr)
208 {
209 phosphor::logging::log<phosphor::logging::level::ERR>(
210 "Read data from flash error - Invalid mdr header");
211 return false;
212 }
213 if (data == nullptr)
214 {
215 phosphor::logging::log<phosphor::logging::level::ERR>(
216 "Read data from flash error - Invalid data point");
217 return false;
218 }
Josh Lehan027277a2023-09-11 05:28:19 -0700219 std::ifstream smbiosFile(smbiosFilePath, std::ios_base::binary);
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700220 if (!smbiosFile.good())
221 {
222 phosphor::logging::log<phosphor::logging::level::ERR>(
223 "Read data from flash error - Open MDRV2 table file failure");
224 return false;
225 }
226 smbiosFile.clear();
227 smbiosFile.seekg(0, std::ios_base::end);
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700228 size_t fileLength = smbiosFile.tellg();
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700229 smbiosFile.seekg(0, std::ios_base::beg);
230 if (fileLength < sizeof(MDRSMBIOSHeader))
231 {
232 phosphor::logging::log<phosphor::logging::level::ERR>(
233 "MDR V2 file size is smaller than mdr header");
234 return false;
235 }
236 smbiosFile.read(reinterpret_cast<char*>(mdrHdr), sizeof(MDRSMBIOSHeader));
237 if (mdrHdr->dataSize > smbiosTableStorageSize)
238 {
239 phosphor::logging::log<phosphor::logging::level::ERR>(
240 "Data size out of limitation");
241 smbiosFile.close();
242 return false;
243 }
244 fileLength -= sizeof(MDRSMBIOSHeader);
245 if (fileLength < mdrHdr->dataSize)
246 {
247 smbiosFile.read(reinterpret_cast<char*>(data), fileLength);
248 }
249 else
250 {
251 smbiosFile.read(reinterpret_cast<char*>(data), mdrHdr->dataSize);
252 }
253 smbiosFile.close();
254 return true;
255}
256
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400257bool MDRV2::sendDirectoryInformation(
258 uint8_t dirVersion, uint8_t dirIndex, uint8_t returnedEntries,
259 uint8_t remainingEntries, std::vector<uint8_t> dirEntry)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800260{
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +0530261 bool terminate = false;
Cheng C Yang608e52d2019-12-19 00:39:50 +0800262 if ((dirIndex >= maxDirEntries) || (returnedEntries < 1))
263 {
264 phosphor::logging::log<phosphor::logging::level::ERR>(
265 "Send Dir info failed - input parameter invalid");
Kuiying Wanga4c08702020-11-18 19:27:20 +0800266 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
267 InvalidParameter();
Cheng C Yang608e52d2019-12-19 00:39:50 +0800268 }
Mansi Joshiecbd71b2021-08-10 22:14:08 +0530269 if ((static_cast<size_t>(returnedEntries) * sizeof(DataIdStruct)) !=
270 dirEntry.size())
Cheng C Yang608e52d2019-12-19 00:39:50 +0800271 {
272 phosphor::logging::log<phosphor::logging::level::ERR>(
273 "Directory size invalid");
Kuiying Wanga4c08702020-11-18 19:27:20 +0800274 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
275 InvalidParameter();
Cheng C Yang608e52d2019-12-19 00:39:50 +0800276 }
277 if (dirVersion == smbiosDir.dirVersion)
278 {
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +0530279 terminate = true;
Cheng C Yang608e52d2019-12-19 00:39:50 +0800280 }
281 else
282 {
283 if (remainingEntries > 0)
284 {
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +0530285 terminate = false;
Cheng C Yang608e52d2019-12-19 00:39:50 +0800286 }
287 else
288 {
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +0530289 terminate = true;
Cheng C Yang608e52d2019-12-19 00:39:50 +0800290 smbiosDir.dirVersion = dirVersion;
291 }
292 uint8_t idIndex = dirIndex;
Mansi Joshiecbd71b2021-08-10 22:14:08 +0530293 smbiosDir.dirEntries = returnedEntries;
Cheng C Yang608e52d2019-12-19 00:39:50 +0800294
295 uint8_t* pData = dirEntry.data();
296 if (pData == nullptr)
297 {
298 return false;
299 }
300 for (uint8_t index = 0; index < returnedEntries; index++)
301 {
Mansi Joshiecbd71b2021-08-10 22:14:08 +0530302 auto data = reinterpret_cast<const DataIdStruct*>(pData);
303 std::copy(data->dataInfo, data->dataInfo + sizeof(DataIdStruct),
Cheng C Yang608e52d2019-12-19 00:39:50 +0800304 smbiosDir.dir[idIndex + index].common.id.dataInfo);
Mansi Joshiecbd71b2021-08-10 22:14:08 +0530305 pData += sizeof(DataIdStruct);
Cheng C Yang608e52d2019-12-19 00:39:50 +0800306 }
307 }
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +0530308 return terminate;
Cheng C Yangeecaf822019-12-19 00:34:23 +0800309}
310
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700311bool MDRV2::sendDataInformation(uint8_t idIndex, uint8_t /* flag */,
312 uint32_t dataLen, uint32_t dataVer,
313 uint32_t timeStamp)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800314{
315 if (idIndex >= maxDirEntries)
316 {
Kuiying Wanga4c08702020-11-18 19:27:20 +0800317 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
318 InvalidParameter();
Cheng C Yangeecaf822019-12-19 00:34:23 +0800319 }
320 int entryChanged = 0;
321 if (smbiosDir.dir[idIndex].common.dataSetSize != dataLen)
322 {
323 entryChanged++;
324 smbiosDir.dir[idIndex].common.dataSetSize = dataLen;
325 }
326
327 if (smbiosDir.dir[idIndex].common.dataVersion != dataVer)
328 {
329 entryChanged++;
330 smbiosDir.dir[idIndex].common.dataVersion = dataVer;
331 }
332
333 if (smbiosDir.dir[idIndex].common.timestamp != timeStamp)
334 {
335 entryChanged++;
336 smbiosDir.dir[idIndex].common.timestamp = timeStamp;
337 }
338 if (entryChanged == 0)
339 {
340 return false;
341 }
342 return true;
343}
344
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700345int MDRV2::findIdIndex(std::vector<uint8_t> dataInfo)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800346{
347 if (dataInfo.size() != sizeof(DataIdStruct))
348 {
349 phosphor::logging::log<phosphor::logging::level::ERR>(
350 "Length of dataInfo invalid");
Kuiying Wanga4c08702020-11-18 19:27:20 +0800351 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
352 InvalidId();
Cheng C Yangeecaf822019-12-19 00:34:23 +0800353 }
354 std::array<uint8_t, 16> arrayDataInfo;
355
356 std::copy(dataInfo.begin(), dataInfo.end(), arrayDataInfo.begin());
357
358 for (int index = 0; index < smbiosDir.dirEntries; index++)
359 {
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700360 size_t info = 0;
Cheng C Yangeecaf822019-12-19 00:34:23 +0800361 for (; info < arrayDataInfo.size(); info++)
362 {
363 if (arrayDataInfo[info] !=
364 smbiosDir.dir[index].common.id.dataInfo[info])
365 {
366 break;
367 }
368 }
369 if (info == arrayDataInfo.size())
370 {
371 return index;
372 }
373 }
Kuiying Wanga4c08702020-11-18 19:27:20 +0800374 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::InvalidId();
Cheng C Yangeecaf822019-12-19 00:34:23 +0800375}
376
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700377uint8_t MDRV2::directoryEntries(uint8_t value)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800378{
Josh Lehan027277a2023-09-11 05:28:19 -0700379 std::ifstream smbiosFile(smbiosFilePath, std::ios_base::binary);
Prithvi A Paibc924d02021-12-29 04:54:43 +0000380 if (!smbiosFile.good())
381 {
382 phosphor::logging::log<phosphor::logging::level::ERR>(
383 "Read data from flash error - Open MDRV2 table file failure");
384 value = 0;
385 }
386 else
387 {
388 value = smbiosDir.dirEntries;
389 }
Jason M. Bills33ae81f2023-04-26 09:06:08 -0700390 return sdbusplus::server::xyz::openbmc_project::smbios::MDRV2::
Cheng C Yangeecaf822019-12-19 00:34:23 +0800391 directoryEntries(value);
392}
393
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700394void MDRV2::systemInfoUpdate()
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800395{
Josh Lehan027277a2023-09-11 05:28:19 -0700396 // By default, look for System interface on any system/board/* object
397 std::string mapperAncestorPath = smbiosInventoryPath;
398 std::string matchParentPath = smbiosInventoryPath + "/board/";
399 bool requireExactMatch = false;
400
401 // If customized, look for System on only that custom object
402 if (smbiosInventoryPath != defaultInventoryPath)
403 {
404 std::filesystem::path path(smbiosInventoryPath);
405
406 // Search under parent to find exact match for self
407 mapperAncestorPath = path.parent_path().string();
408 matchParentPath = mapperAncestorPath;
409 requireExactMatch = true;
410 }
411
Jie Yange7cf3192021-08-20 11:21:43 -0700412 std::string motherboardPath;
Josh Lehan027277a2023-09-11 05:28:19 -0700413 auto method = bus->new_method_call(mapperBusName, mapperPath,
414 mapperInterface, "GetSubTreePaths");
415 method.append(mapperAncestorPath);
Gobinath Krishnamoorthybb9c6222022-11-03 20:08:01 +0000416 method.append(0);
Josh Lehanabdccd32024-01-26 15:49:50 -0800417
418 // If customized, also accept Board as anchor, not just System
419 std::vector<std::string> desiredInterfaces{systemInterface};
420 if (requireExactMatch)
421 {
422 desiredInterfaces.emplace_back(boardInterface);
423 }
424 method.append(desiredInterfaces);
Nikhil Namjoshidd1811c2023-03-14 22:51:48 +0000425
Jie Yange7cf3192021-08-20 11:21:43 -0700426 try
427 {
Gobinath Krishnamoorthybb9c6222022-11-03 20:08:01 +0000428 std::vector<std::string> paths;
Josh Lehan027277a2023-09-11 05:28:19 -0700429 sdbusplus::message_t reply = bus->call(method);
Gobinath Krishnamoorthybb9c6222022-11-03 20:08:01 +0000430 reply.read(paths);
Josh Lehan027277a2023-09-11 05:28:19 -0700431
432 size_t pathsCount = paths.size();
433 for (size_t i = 0; i < pathsCount; ++i)
434 {
435 if (requireExactMatch && (paths[i] != smbiosInventoryPath))
436 {
437 continue;
438 }
439
440 motherboardPath = std::move(paths[i]);
441 break;
442 }
Jie Yange7cf3192021-08-20 11:21:43 -0700443 }
444 catch (const sdbusplus::exception_t& e)
445 {
Josh Lehan027277a2023-09-11 05:28:19 -0700446 lg2::error(
447 "Exception while trying to find Inventory anchor object for SMBIOS content {I}: {E}",
448 "I", smbiosInventoryPath, "E", e.what());
Jie Yange7cf3192021-08-20 11:21:43 -0700449 phosphor::logging::log<phosphor::logging::level::ERR>(
450 "Failed to query system motherboard",
451 phosphor::logging::entry("ERROR=%s", e.what()));
452 }
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800453
Josh Lehanabdccd32024-01-26 15:49:50 -0800454 if (motherboardPath.empty())
455 {
456 phosphor::logging::log<phosphor::logging::level::ERR>(
457 "Failed to get system motherboard dbus path. Setting up a "
458 "match rule");
459
460 if (motherboardConfigMatch)
461 {
462 lg2::info("Motherboard match rule already exists");
463 }
464 else
465 {
466 motherboardConfigMatch = std::make_unique<sdbusplus::bus::match_t>(
467 *bus,
468 sdbusplus::bus::match::rules::interfacesAdded() +
469 sdbusplus::bus::match::rules::argNpath(0, matchParentPath),
470 [this, requireExactMatch](sdbusplus::message_t& msg) {
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400471 sdbusplus::message::object_path objectName;
Josh Lehanabdccd32024-01-26 15:49:50 -0800472 boost::container::flat_map<
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400473 std::string,
474 boost::container::flat_map<
475 std::string, std::variant<std::string, uint64_t>>>
476 msgData;
477 msg.read(objectName, msgData);
478 bool gotMatch = false;
Josh Lehanabdccd32024-01-26 15:49:50 -0800479
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400480 if (msgData.contains(systemInterface))
481 {
482 lg2::info("Successful match on system interface");
483 gotMatch = true;
484 }
Josh Lehanabdccd32024-01-26 15:49:50 -0800485
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400486 // If customized, also accept Board as anchor, not just
487 // System
488 if (requireExactMatch && msgData.contains(boardInterface))
489 {
490 lg2::info("Successful match on board interface");
491 gotMatch = true;
492 }
Josh Lehanabdccd32024-01-26 15:49:50 -0800493
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400494 if (gotMatch)
495 {
496 // There is a race condition here: our desired interface
497 // has just been created, triggering the D-Bus callback,
498 // but Object Mapper has not been told of it yet. The
499 // mapper must also add it. Stall for time, so it can.
500 sleep(2);
501 systemInfoUpdate();
502 }
503 });
Josh Lehanabdccd32024-01-26 15:49:50 -0800504 }
505 }
506 else
507 {
508#ifdef ASSOC_TRIM_PATH
509 // When enabled, chop off last component of motherboardPath, to trim one
510 // layer, so that associations are built to the underlying chassis
511 // itself, not the system boards in the chassis. This is for
512 // compatibility with traditional systems which only have one
513 // motherboard per chassis.
514 std::filesystem::path foundPath(motherboardPath);
515 motherboardPath = foundPath.parent_path().string();
516#endif
517
518 lg2::info("Found Inventory anchor object for SMBIOS content {I}: {M}",
519 "I", smbiosInventoryPath, "M", motherboardPath);
520 }
521
522 lg2::info("Using Inventory anchor object for SMBIOS content {I}: {M}", "I",
523 smbiosInventoryPath, "M", motherboardPath);
524
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700525 std::optional<size_t> num = getTotalCpuSlot();
526 if (!num)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800527 {
528 phosphor::logging::log<phosphor::logging::level::ERR>(
529 "get cpu total slot failed");
530 return;
531 }
532
Brandon Kim5a122a62023-05-04 04:25:03 +0000533 // In case the new size is smaller than old, trim the vector
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700534 if (*num < cpus.size())
Brandon Kim5a122a62023-05-04 04:25:03 +0000535 {
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700536 cpus.resize(*num);
Brandon Kim5a122a62023-05-04 04:25:03 +0000537 }
538
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700539 for (unsigned int index = 0; index < *num; index++)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800540 {
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400541 std::string path =
542 smbiosInventoryPath + cpuSuffix + std::to_string(index);
Brandon Kim5a122a62023-05-04 04:25:03 +0000543 if (index + 1 > cpus.size())
544 {
545 cpus.emplace_back(std::make_unique<phosphor::smbios::Cpu>(
Josh Lehan027277a2023-09-11 05:28:19 -0700546 *bus, path, index, smbiosDir.dir[smbiosDirIndex].dataStorage,
Brandon Kim5a122a62023-05-04 04:25:03 +0000547 motherboardPath));
548 }
549 else
550 {
551 cpus[index]->infoUpdate(smbiosDir.dir[smbiosDirIndex].dataStorage,
552 motherboardPath);
553 }
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800554 }
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800555
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700556#ifdef DIMM_DBUS
557
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800558 num = getTotalDimmSlot();
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700559 if (!num)
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800560 {
561 phosphor::logging::log<phosphor::logging::level::ERR>(
562 "get dimm total slot failed");
563 return;
564 }
565
Brandon Kim5a122a62023-05-04 04:25:03 +0000566 // In case the new size is smaller than old, trim the vector
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700567 if (*num < dimms.size())
Brandon Kim5a122a62023-05-04 04:25:03 +0000568 {
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700569 dimms.resize(*num);
Brandon Kim5a122a62023-05-04 04:25:03 +0000570 }
571
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700572 for (unsigned int index = 0; index < *num; index++)
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800573 {
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400574 std::string path =
575 smbiosInventoryPath + dimmSuffix + std::to_string(index);
Brandon Kim5a122a62023-05-04 04:25:03 +0000576 if (index + 1 > dimms.size())
577 {
578 dimms.emplace_back(std::make_unique<phosphor::smbios::Dimm>(
Josh Lehan027277a2023-09-11 05:28:19 -0700579 *bus, path, index, smbiosDir.dir[smbiosDirIndex].dataStorage,
Brandon Kim5a122a62023-05-04 04:25:03 +0000580 motherboardPath));
581 }
582 else
583 {
584 dimms[index]->memoryInfoUpdate(
585 smbiosDir.dir[smbiosDirIndex].dataStorage, motherboardPath);
586 }
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800587 }
Cheng C Yangb4651b92019-12-19 00:59:01 +0800588
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700589#endif
590
Jie Yang08e4a6d2021-08-23 13:07:41 -0700591 num = getTotalPcieSlot();
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700592 if (!num)
Jie Yang08e4a6d2021-08-23 13:07:41 -0700593 {
594 phosphor::logging::log<phosphor::logging::level::ERR>(
595 "get pcie total slot failed");
596 return;
597 }
598
Brandon Kim5a122a62023-05-04 04:25:03 +0000599 // In case the new size is smaller than old, trim the vector
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700600 if (*num < pcies.size())
Brandon Kim5a122a62023-05-04 04:25:03 +0000601 {
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700602 pcies.resize(*num);
Brandon Kim5a122a62023-05-04 04:25:03 +0000603 }
604
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700605 for (unsigned int index = 0; index < *num; index++)
Jie Yang08e4a6d2021-08-23 13:07:41 -0700606 {
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400607 std::string path =
608 smbiosInventoryPath + pcieSuffix + std::to_string(index);
Brandon Kim5a122a62023-05-04 04:25:03 +0000609 if (index + 1 > pcies.size())
610 {
611 pcies.emplace_back(std::make_unique<phosphor::smbios::Pcie>(
Josh Lehan027277a2023-09-11 05:28:19 -0700612 *bus, path, index, smbiosDir.dir[smbiosDirIndex].dataStorage,
Brandon Kim5a122a62023-05-04 04:25:03 +0000613 motherboardPath));
614 }
615 else
616 {
617 pcies[index]->pcieInfoUpdate(
618 smbiosDir.dir[smbiosDirIndex].dataStorage, motherboardPath);
619 }
Jie Yang08e4a6d2021-08-23 13:07:41 -0700620 }
621
Prithvi Pai5af42bb2025-02-11 17:59:07 +0530622#ifdef TPM_DBUS
623
624 num = getTotalTpm();
625 if (!num)
626 {
627 phosphor::logging::log<phosphor::logging::level::ERR>("get tpm failed");
628 return;
629 }
630 // In case the new size is smaller than old, trim the vector
631 if (*num < tpms.size())
632 {
633 tpms.resize(*num);
634 }
635
636 for (unsigned int index = 0; index < *num; index++)
637 {
638 std::string path =
639 smbiosInventoryPath + tpmSuffix + std::to_string(index);
640 if (index + 1 > tpms.size())
641 {
642 tpms.emplace_back(std::make_unique<phosphor::smbios::Tpm>(
643 *bus, path, index, smbiosDir.dir[smbiosDirIndex].dataStorage,
644 motherboardPath));
645 }
646 else
647 {
648 tpms[index]->tpmInfoUpdate(
649 smbiosDir.dir[smbiosDirIndex].dataStorage, motherboardPath);
650 }
651 }
652#endif
653
Cheng C Yangb4651b92019-12-19 00:59:01 +0800654 system.reset();
Josh Lehan027277a2023-09-11 05:28:19 -0700655 system = std::make_unique<System>(bus, smbiosInventoryPath + systemSuffix,
656 smbiosDir.dir[smbiosDirIndex].dataStorage,
657 smbiosFilePath);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800658}
659
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700660std::optional<size_t> MDRV2::getTotalCpuSlot()
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800661{
662 uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700663 size_t num = 0;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800664
665 if (dataIn == nullptr)
666 {
667 phosphor::logging::log<phosphor::logging::level::ERR>(
668 "get cpu total slot failed - no storage data");
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700669 return std::nullopt;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800670 }
671
672 while (1)
673 {
674 dataIn = getSMBIOSTypePtr(dataIn, processorsType);
675 if (dataIn == nullptr)
676 {
677 break;
678 }
679 num++;
680 dataIn = smbiosNextPtr(dataIn);
681 if (dataIn == nullptr)
682 {
683 break;
684 }
685 if (num >= limitEntryLen)
686 {
687 break;
688 }
689 }
690
691 return num;
692}
693
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700694std::optional<size_t> MDRV2::getTotalDimmSlot()
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800695{
696 uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700697 size_t num = 0;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800698
699 if (dataIn == nullptr)
700 {
701 phosphor::logging::log<phosphor::logging::level::ERR>(
702 "Fail to get dimm total slot - no storage data");
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700703 return std::nullopt;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800704 }
705
706 while (1)
707 {
708 dataIn = getSMBIOSTypePtr(dataIn, memoryDeviceType);
709 if (dataIn == nullptr)
710 {
711 break;
712 }
713 num++;
714 dataIn = smbiosNextPtr(dataIn);
715 if (dataIn == nullptr)
716 {
717 break;
718 }
719 if (num >= limitEntryLen)
720 {
721 break;
722 }
723 }
724
725 return num;
726}
727
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700728std::optional<size_t> MDRV2::getTotalPcieSlot()
Jie Yang08e4a6d2021-08-23 13:07:41 -0700729{
730 uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700731 size_t num = 0;
Jie Yang08e4a6d2021-08-23 13:07:41 -0700732
733 if (dataIn == nullptr)
734 {
735 phosphor::logging::log<phosphor::logging::level::ERR>(
736 "Fail to get total system slot - no storage data");
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700737 return std::nullopt;
Jie Yang08e4a6d2021-08-23 13:07:41 -0700738 }
739
740 while (1)
741 {
742 dataIn = getSMBIOSTypePtr(dataIn, systemSlots);
743 if (dataIn == nullptr)
744 {
745 break;
746 }
747
748 /* System slot type offset. Check if the slot is a PCIE slots. All
749 * PCIE slot type are hardcoded in a table.
750 */
751 if (pcieSmbiosType.find(*(dataIn + 5)) != pcieSmbiosType.end())
752 {
753 num++;
754 }
755 dataIn = smbiosNextPtr(dataIn);
756 if (dataIn == nullptr)
757 {
758 break;
759 }
760 if (num >= limitEntryLen)
761 {
762 break;
763 }
764 }
765
766 return num;
767}
768
Prithvi Pai5af42bb2025-02-11 17:59:07 +0530769std::optional<size_t> MDRV2::getTotalTpm()
770{
771 uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
772 size_t num = 0;
773
774 if (dataIn == nullptr)
775 {
776 phosphor::logging::log<phosphor::logging::level::ERR>(
777 "Fail to get tpm total slot - no storage data");
778 return std::nullopt;
779 }
780
781 while (1)
782 {
783 dataIn = getSMBIOSTypePtr(dataIn, tpmDeviceType);
784 if (dataIn == nullptr)
785 {
786 break;
787 }
788 num++;
789 dataIn = smbiosNextPtr(dataIn);
790 if (dataIn == nullptr)
791 {
792 break;
793 }
794 if (num >= limitEntryLen)
795 {
796 break;
797 }
798 }
799
800 return num;
801}
802
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700803bool MDRV2::checkSMBIOSVersion(uint8_t* dataIn)
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530804{
Brandon Kime4ea3772022-02-23 20:21:10 -0800805 const std::string anchorString21 = "_SM_";
806 const std::string anchorString30 = "_SM3_";
Josh Lehanc6d87a52024-02-08 19:01:29 -0800807 std::string buffer(reinterpret_cast<const char*>(dataIn),
808 smbiosTableStorageSize);
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530809
810 auto it = std::search(std::begin(buffer), std::end(buffer),
Brandon Kime4ea3772022-02-23 20:21:10 -0800811 std::begin(anchorString21), std::end(anchorString21));
812 bool smbios21Found = it != std::end(buffer);
813 if (!smbios21Found)
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530814 {
Brandon Kime4ea3772022-02-23 20:21:10 -0800815 phosphor::logging::log<phosphor::logging::level::INFO>(
816 "SMBIOS 2.1 Anchor String not found. Looking for SMBIOS 3.0");
817 it = std::search(std::begin(buffer), std::end(buffer),
818 std::begin(anchorString30), std::end(anchorString30));
819 if (it == std::end(buffer))
820 {
821 phosphor::logging::log<phosphor::logging::level::ERR>(
822 "SMBIOS 2.1 and 3.0 Anchor Strings not found");
823 return false;
824 }
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530825 }
826
827 auto pos = std::distance(std::begin(buffer), it);
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700828 size_t length = smbiosTableStorageSize - pos;
Brandon Kime4ea3772022-02-23 20:21:10 -0800829 uint8_t foundMajorVersion;
830 uint8_t foundMinorVersion;
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530831
Brandon Kime4ea3772022-02-23 20:21:10 -0800832 if (smbios21Found)
833 {
834 if (length < sizeof(EntryPointStructure21))
835 {
836 phosphor::logging::log<phosphor::logging::level::ERR>(
837 "Invalid entry point structure for SMBIOS 2.1");
838 return false;
839 }
840
841 auto epStructure =
842 reinterpret_cast<const EntryPointStructure21*>(&dataIn[pos]);
843 foundMajorVersion = epStructure->smbiosVersion.majorVersion;
844 foundMinorVersion = epStructure->smbiosVersion.minorVersion;
845 }
846 else
847 {
848 if (length < sizeof(EntryPointStructure30))
849 {
850 phosphor::logging::log<phosphor::logging::level::ERR>(
851 "Invalid entry point structure for SMBIOS 3.0");
852 return false;
853 }
854
855 auto epStructure =
856 reinterpret_cast<const EntryPointStructure30*>(&dataIn[pos]);
857 foundMajorVersion = epStructure->smbiosVersion.majorVersion;
858 foundMinorVersion = epStructure->smbiosVersion.minorVersion;
859 }
860 lg2::info("SMBIOS VERSION - {MAJOR}.{MINOR}", "MAJOR", foundMajorVersion,
861 "MINOR", foundMinorVersion);
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530862
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400863 auto itr = std::find_if(
864 std::begin(supportedSMBIOSVersions), std::end(supportedSMBIOSVersions),
865 [&](SMBIOSVersion versionItr) {
866 return versionItr.majorVersion == foundMajorVersion &&
867 versionItr.minorVersion == foundMinorVersion;
868 });
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530869 if (itr == std::end(supportedSMBIOSVersions))
870 {
871 return false;
872 }
873 return true;
874}
875
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700876bool MDRV2::agentSynchronizeData()
Cheng C Yangeecaf822019-12-19 00:34:23 +0800877{
Cheng C Yangec634252019-12-19 00:42:36 +0800878 struct MDRSMBIOSHeader mdr2SMBIOS;
879 bool status = readDataFromFlash(&mdr2SMBIOS,
880 smbiosDir.dir[smbiosDirIndex].dataStorage);
881 if (!status)
882 {
883 phosphor::logging::log<phosphor::logging::level::ERR>(
884 "agent data sync failed - read data from flash failed");
885 return false;
886 }
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530887
888 if (!checkSMBIOSVersion(smbiosDir.dir[smbiosDirIndex].dataStorage))
Cheng C Yangec634252019-12-19 00:42:36 +0800889 {
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530890 phosphor::logging::log<phosphor::logging::level::ERR>(
891 "Unsupported SMBIOS table version");
892 return false;
Cheng C Yangec634252019-12-19 00:42:36 +0800893 }
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530894
Jayaprakash Mutyalab5cc6902025-02-13 07:00:15 +0000895 if (0 == static_cast<uint8_t>(sdbusplus::server::xyz::openbmc_project::
896 smbios::MDRV2::directoryEntries()))
897 {
898 directoryEntries(smbiosDir.dirEntries);
899 }
900
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530901 systemInfoUpdate();
902 smbiosDir.dir[smbiosDirIndex].common.dataVersion = mdr2SMBIOS.dirVer;
903 smbiosDir.dir[smbiosDirIndex].common.timestamp = mdr2SMBIOS.timestamp;
904 smbiosDir.dir[smbiosDirIndex].common.size = mdr2SMBIOS.dataSize;
905 smbiosDir.dir[smbiosDirIndex].stage = MDR2SMBIOSStatusEnum::mdr2Loaded;
906 smbiosDir.dir[smbiosDirIndex].lock = MDR2DirLockEnum::mdr2DirUnlock;
907
Cheng C Yangec634252019-12-19 00:42:36 +0800908 return true;
Cheng C Yangeecaf822019-12-19 00:34:23 +0800909}
910
Patrick Williams07a2c9a2025-02-01 08:23:10 -0500911std::vector<uint32_t> MDRV2::synchronizeDirectoryCommonData(uint8_t idIndex,
912 uint32_t size)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800913{
Cheng C Yangec634252019-12-19 00:42:36 +0800914 std::chrono::microseconds usec(
915 defaultTimeout); // default lock time out is 2s
916 std::vector<uint32_t> result;
917 smbiosDir.dir[idIndex].common.size = size;
918 result.push_back(smbiosDir.dir[idIndex].common.dataSetSize);
919 result.push_back(smbiosDir.dir[idIndex].common.dataVersion);
920 result.push_back(smbiosDir.dir[idIndex].common.timestamp);
921
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700922 timer.expires_after(usec);
923 timer.async_wait([this](boost::system::error_code ec) {
Josh Lehan027277a2023-09-11 05:28:19 -0700924 if (ec)
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700925 {
926 phosphor::logging::log<phosphor::logging::level::ERR>(
927 "Timer Error!");
928 return;
929 }
930 agentSynchronizeData();
931 });
Cheng C Yangec634252019-12-19 00:42:36 +0800932 return result;
Cheng C Yangeecaf822019-12-19 00:34:23 +0800933}
934
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700935std::vector<boost::container::flat_map<std::string, RecordVariant>>
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700936 MDRV2::getRecordType(size_t type)
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700937{
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700938 std::vector<boost::container::flat_map<std::string, RecordVariant>> ret;
939 if (type == memoryDeviceType)
940 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700941 uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
942
943 if (dataIn == nullptr)
944 {
Kuiying Wanga4c08702020-11-18 19:27:20 +0800945 throw std::runtime_error("Data not populated");
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700946 }
947
948 do
949 {
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400950 dataIn =
951 getSMBIOSTypePtr(dataIn, memoryDeviceType, sizeof(MemoryInfo));
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700952 if (dataIn == nullptr)
953 {
954 break;
955 }
956 boost::container::flat_map<std::string, RecordVariant>& record =
957 ret.emplace_back();
958
959 auto memoryInfo = reinterpret_cast<MemoryInfo*>(dataIn);
960
961 record["Type"] = memoryInfo->type;
962 record["Length"] = memoryInfo->length;
963 record["Handle"] = uint16_t(memoryInfo->handle);
964 record["Physical Memory Array Handle"] =
965 uint16_t(memoryInfo->phyArrayHandle);
966 record["Memory Error Information Handle"] =
967 uint16_t(memoryInfo->errInfoHandle);
968 record["Total Width"] = uint16_t(memoryInfo->totalWidth);
969 record["Data Width"] = uint16_t(memoryInfo->dataWidth);
970 record["Size"] = uint16_t(memoryInfo->size);
971 record["Form Factor"] = memoryInfo->formFactor;
972 record["Device Set"] = memoryInfo->deviceSet;
973 record["Device Locator"] = positionToString(
974 memoryInfo->deviceLocator, memoryInfo->length, dataIn);
975 record["Bank Locator"] = positionToString(
976 memoryInfo->bankLocator, memoryInfo->length, dataIn);
977 record["Memory Type"] = memoryInfo->memoryType;
978 record["Type Detail"] = uint16_t(memoryInfo->typeDetail);
979 record["Speed"] = uint16_t(memoryInfo->speed);
980 record["Manufacturer"] = positionToString(
981 memoryInfo->manufacturer, memoryInfo->length, dataIn);
982 record["Serial Number"] = positionToString(
983 memoryInfo->serialNum, memoryInfo->length, dataIn);
984 record["Asset Tag"] = positionToString(memoryInfo->assetTag,
985 memoryInfo->length, dataIn);
986 record["Part Number"] = positionToString(
987 memoryInfo->partNum, memoryInfo->length, dataIn);
George Liu036374a2023-06-15 08:47:46 +0800988 record["Attributes"] = uint32_t(memoryInfo->attributes);
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700989 record["Extended Size"] = uint32_t(memoryInfo->extendedSize);
990 record["Configured Memory Speed"] =
991 uint32_t(memoryInfo->confClockSpeed);
992 record["Minimum voltage"] = uint16_t(memoryInfo->minimumVoltage);
993 record["Maximum voltage"] = uint16_t(memoryInfo->maximumVoltage);
994 record["Configured voltage"] =
995 uint16_t(memoryInfo->configuredVoltage);
996 record["Memory Technology"] = memoryInfo->memoryTechnology;
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +0530997 record["Memory Operating Mode Capability"] =
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700998 uint16_t(memoryInfo->memoryOperatingModeCap);
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +0530999 record["Firmware Version"] = memoryInfo->firwareVersion;
Zhikui Ren18a5ab92020-09-01 21:35:20 -07001000 record["Module Manufacturer ID"] =
1001 uint16_t(memoryInfo->modelManufId);
1002 record["Module Product ID"] = uint16_t(memoryInfo->modelProdId);
1003 record["Memory Subsystem Controller Manufacturer ID"] =
1004 uint16_t(memoryInfo->memSubConManufId);
1005 record["Memory Subsystem Controller Product Id"] =
1006 uint16_t(memoryInfo->memSubConProdId);
1007 record["Non-volatile Size"] = uint64_t(memoryInfo->nvSize);
1008 record["Volatile Size"] = uint64_t(memoryInfo->volatileSize);
1009 record["Cache Size"] = uint64_t(memoryInfo->cacheSize);
1010 record["Logical Size"] = uint64_t(memoryInfo->logicalSize);
1011 } while ((dataIn = smbiosNextPtr(dataIn)) != nullptr);
1012
1013 return ret;
1014 }
1015
Kuiying Wanga4c08702020-11-18 19:27:20 +08001016 throw std::invalid_argument("Invalid record type");
Zhikui Ren18a5ab92020-09-01 21:35:20 -07001017 return ret;
1018}
1019
Cheng C Yangeecaf822019-12-19 00:34:23 +08001020} // namespace smbios
1021} // namespace phosphor