blob: 2aaf4be91a6d7b14febce89bbfcbe01dee846fa5 [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 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +053041 lg2::error(
Prithvi A Paibc924d02021-12-29 04:54:43 +000042 "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 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530129 lg2::error("smbios is not ready for update");
Kuiying Wanga4c08702020-11-18 19:27:20 +0800130 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
131 UpdateInProgress();
Cheng C Yangeecaf822019-12-19 00:34:23 +0800132 }
133 return offer;
134}
135
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700136inline uint8_t MDRV2::smbiosValidFlag(uint8_t index)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800137{
138 FlagStatus ret = FlagStatus::flagIsInvalid;
139 MDR2SMBIOSStatusEnum stage = smbiosDir.dir[index].stage;
140 MDR2DirLockEnum lock = smbiosDir.dir[index].lock;
141
142 switch (stage)
143 {
144 case MDR2SMBIOSStatusEnum::mdr2Loaded:
145 case MDR2SMBIOSStatusEnum::mdr2Updated:
146 if (lock == MDR2DirLockEnum::mdr2DirLock)
147 {
148 ret = FlagStatus::flagIsLocked; // locked
149 }
150 else
151 {
152 ret = FlagStatus::flagIsValid; // valid
153 }
154 break;
155
156 case MDR2SMBIOSStatusEnum::mdr2Updating:
157 case MDR2SMBIOSStatusEnum::mdr2Init:
158 ret = FlagStatus::flagIsInvalid; // invalid
159 break;
160
161 default:
162 break;
163 }
164
165 return static_cast<uint8_t>(ret);
166}
167
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700168// If source variable size is 4 bytes (uint32_t) and destination is Vector type
169// is 1 byte (uint8_t), then by using this API can copy data byte by byte. For
170// Example copying data from smbiosDir.dir[idIndex].common.size and
171// smbiosDir.dir[idIndex].common.timestamp to vector variable responseInfo
172template <typename T>
173void appendReversed(std::vector<uint8_t>& vector, const T& value)
174{
175 auto data = reinterpret_cast<const uint8_t*>(&value);
176 std::reverse_copy(data, data + sizeof(value), std::back_inserter(vector));
177}
178
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700179std::vector<uint8_t> MDRV2::getDataInformation(uint8_t idIndex)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800180{
181 std::vector<uint8_t> responseInfo;
182 responseInfo.push_back(mdr2Version);
183
184 if (idIndex >= maxDirEntries)
185 {
Kuiying Wanga4c08702020-11-18 19:27:20 +0800186 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
187 InvalidParameter();
Cheng C Yangeecaf822019-12-19 00:34:23 +0800188 }
189
190 for (uint8_t index = 0; index < sizeof(DataIdStruct); index++)
191 {
192 responseInfo.push_back(
193 smbiosDir.dir[idIndex].common.id.dataInfo[index]);
194 }
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700195
Cheng C Yangeecaf822019-12-19 00:34:23 +0800196 responseInfo.push_back(smbiosValidFlag(idIndex));
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700197 appendReversed(responseInfo, smbiosDir.dir[idIndex].common.size);
Cheng C Yangeecaf822019-12-19 00:34:23 +0800198 responseInfo.push_back(smbiosDir.dir[idIndex].common.dataVersion);
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700199 appendReversed(responseInfo, smbiosDir.dir[idIndex].common.timestamp);
Cheng C Yangeecaf822019-12-19 00:34:23 +0800200
201 return responseInfo;
202}
203
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700204bool MDRV2::readDataFromFlash(MDRSMBIOSHeader* mdrHdr, uint8_t* data)
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700205{
206 if (mdrHdr == nullptr)
207 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530208 lg2::error("Read data from flash error - Invalid mdr header");
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700209 return false;
210 }
211 if (data == nullptr)
212 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530213 lg2::error("Read data from flash error - Invalid data point");
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700214 return false;
215 }
Josh Lehan027277a2023-09-11 05:28:19 -0700216 std::ifstream smbiosFile(smbiosFilePath, std::ios_base::binary);
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700217 if (!smbiosFile.good())
218 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530219 lg2::error(
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700220 "Read data from flash error - Open MDRV2 table file failure");
221 return false;
222 }
223 smbiosFile.clear();
224 smbiosFile.seekg(0, std::ios_base::end);
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700225 size_t fileLength = smbiosFile.tellg();
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700226 smbiosFile.seekg(0, std::ios_base::beg);
227 if (fileLength < sizeof(MDRSMBIOSHeader))
228 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530229 lg2::error("MDR V2 file size is smaller than mdr header");
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700230 return false;
231 }
232 smbiosFile.read(reinterpret_cast<char*>(mdrHdr), sizeof(MDRSMBIOSHeader));
233 if (mdrHdr->dataSize > smbiosTableStorageSize)
234 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530235 lg2::error("Data size out of limitation");
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700236 smbiosFile.close();
237 return false;
238 }
239 fileLength -= sizeof(MDRSMBIOSHeader);
240 if (fileLength < mdrHdr->dataSize)
241 {
242 smbiosFile.read(reinterpret_cast<char*>(data), fileLength);
243 }
244 else
245 {
246 smbiosFile.read(reinterpret_cast<char*>(data), mdrHdr->dataSize);
247 }
248 smbiosFile.close();
249 return true;
250}
251
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400252bool MDRV2::sendDirectoryInformation(
253 uint8_t dirVersion, uint8_t dirIndex, uint8_t returnedEntries,
254 uint8_t remainingEntries, std::vector<uint8_t> dirEntry)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800255{
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +0530256 bool terminate = false;
Cheng C Yang608e52d2019-12-19 00:39:50 +0800257 if ((dirIndex >= maxDirEntries) || (returnedEntries < 1))
258 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530259 lg2::error("Send Dir info failed - input parameter invalid");
Kuiying Wanga4c08702020-11-18 19:27:20 +0800260 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
261 InvalidParameter();
Cheng C Yang608e52d2019-12-19 00:39:50 +0800262 }
Mansi Joshiecbd71b2021-08-10 22:14:08 +0530263 if ((static_cast<size_t>(returnedEntries) * sizeof(DataIdStruct)) !=
264 dirEntry.size())
Cheng C Yang608e52d2019-12-19 00:39:50 +0800265 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530266 lg2::error("Directory size invalid");
Kuiying Wanga4c08702020-11-18 19:27:20 +0800267 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
268 InvalidParameter();
Cheng C Yang608e52d2019-12-19 00:39:50 +0800269 }
270 if (dirVersion == smbiosDir.dirVersion)
271 {
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +0530272 terminate = true;
Cheng C Yang608e52d2019-12-19 00:39:50 +0800273 }
274 else
275 {
276 if (remainingEntries > 0)
277 {
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +0530278 terminate = false;
Cheng C Yang608e52d2019-12-19 00:39:50 +0800279 }
280 else
281 {
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +0530282 terminate = true;
Cheng C Yang608e52d2019-12-19 00:39:50 +0800283 smbiosDir.dirVersion = dirVersion;
284 }
285 uint8_t idIndex = dirIndex;
Mansi Joshiecbd71b2021-08-10 22:14:08 +0530286 smbiosDir.dirEntries = returnedEntries;
Cheng C Yang608e52d2019-12-19 00:39:50 +0800287
288 uint8_t* pData = dirEntry.data();
289 if (pData == nullptr)
290 {
291 return false;
292 }
293 for (uint8_t index = 0; index < returnedEntries; index++)
294 {
Mansi Joshiecbd71b2021-08-10 22:14:08 +0530295 auto data = reinterpret_cast<const DataIdStruct*>(pData);
296 std::copy(data->dataInfo, data->dataInfo + sizeof(DataIdStruct),
Cheng C Yang608e52d2019-12-19 00:39:50 +0800297 smbiosDir.dir[idIndex + index].common.id.dataInfo);
Mansi Joshiecbd71b2021-08-10 22:14:08 +0530298 pData += sizeof(DataIdStruct);
Cheng C Yang608e52d2019-12-19 00:39:50 +0800299 }
300 }
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +0530301 return terminate;
Cheng C Yangeecaf822019-12-19 00:34:23 +0800302}
303
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700304bool MDRV2::sendDataInformation(uint8_t idIndex, uint8_t /* flag */,
305 uint32_t dataLen, uint32_t dataVer,
306 uint32_t timeStamp)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800307{
308 if (idIndex >= maxDirEntries)
309 {
Kuiying Wanga4c08702020-11-18 19:27:20 +0800310 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
311 InvalidParameter();
Cheng C Yangeecaf822019-12-19 00:34:23 +0800312 }
313 int entryChanged = 0;
314 if (smbiosDir.dir[idIndex].common.dataSetSize != dataLen)
315 {
316 entryChanged++;
317 smbiosDir.dir[idIndex].common.dataSetSize = dataLen;
318 }
319
320 if (smbiosDir.dir[idIndex].common.dataVersion != dataVer)
321 {
322 entryChanged++;
323 smbiosDir.dir[idIndex].common.dataVersion = dataVer;
324 }
325
326 if (smbiosDir.dir[idIndex].common.timestamp != timeStamp)
327 {
328 entryChanged++;
329 smbiosDir.dir[idIndex].common.timestamp = timeStamp;
330 }
331 if (entryChanged == 0)
332 {
333 return false;
334 }
335 return true;
336}
337
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700338int MDRV2::findIdIndex(std::vector<uint8_t> dataInfo)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800339{
340 if (dataInfo.size() != sizeof(DataIdStruct))
341 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530342 lg2::error("Length of dataInfo invalid");
Kuiying Wanga4c08702020-11-18 19:27:20 +0800343 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
344 InvalidId();
Cheng C Yangeecaf822019-12-19 00:34:23 +0800345 }
346 std::array<uint8_t, 16> arrayDataInfo;
347
348 std::copy(dataInfo.begin(), dataInfo.end(), arrayDataInfo.begin());
349
350 for (int index = 0; index < smbiosDir.dirEntries; index++)
351 {
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700352 size_t info = 0;
Cheng C Yangeecaf822019-12-19 00:34:23 +0800353 for (; info < arrayDataInfo.size(); info++)
354 {
355 if (arrayDataInfo[info] !=
356 smbiosDir.dir[index].common.id.dataInfo[info])
357 {
358 break;
359 }
360 }
361 if (info == arrayDataInfo.size())
362 {
363 return index;
364 }
365 }
Kuiying Wanga4c08702020-11-18 19:27:20 +0800366 throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::InvalidId();
Cheng C Yangeecaf822019-12-19 00:34:23 +0800367}
368
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700369uint8_t MDRV2::directoryEntries(uint8_t value)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800370{
Josh Lehan027277a2023-09-11 05:28:19 -0700371 std::ifstream smbiosFile(smbiosFilePath, std::ios_base::binary);
Prithvi A Paibc924d02021-12-29 04:54:43 +0000372 if (!smbiosFile.good())
373 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530374 lg2::error(
Prithvi A Paibc924d02021-12-29 04:54:43 +0000375 "Read data from flash error - Open MDRV2 table file failure");
376 value = 0;
377 }
378 else
379 {
380 value = smbiosDir.dirEntries;
381 }
Jason M. Bills33ae81f2023-04-26 09:06:08 -0700382 return sdbusplus::server::xyz::openbmc_project::smbios::MDRV2::
Cheng C Yangeecaf822019-12-19 00:34:23 +0800383 directoryEntries(value);
384}
385
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700386void MDRV2::systemInfoUpdate()
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800387{
Josh Lehan027277a2023-09-11 05:28:19 -0700388 // By default, look for System interface on any system/board/* object
389 std::string mapperAncestorPath = smbiosInventoryPath;
390 std::string matchParentPath = smbiosInventoryPath + "/board/";
391 bool requireExactMatch = false;
392
393 // If customized, look for System on only that custom object
394 if (smbiosInventoryPath != defaultInventoryPath)
395 {
396 std::filesystem::path path(smbiosInventoryPath);
397
398 // Search under parent to find exact match for self
399 mapperAncestorPath = path.parent_path().string();
400 matchParentPath = mapperAncestorPath;
401 requireExactMatch = true;
402 }
403
Jie Yange7cf3192021-08-20 11:21:43 -0700404 std::string motherboardPath;
Josh Lehan027277a2023-09-11 05:28:19 -0700405 auto method = bus->new_method_call(mapperBusName, mapperPath,
406 mapperInterface, "GetSubTreePaths");
407 method.append(mapperAncestorPath);
Gobinath Krishnamoorthybb9c6222022-11-03 20:08:01 +0000408 method.append(0);
Josh Lehanabdccd32024-01-26 15:49:50 -0800409
410 // If customized, also accept Board as anchor, not just System
411 std::vector<std::string> desiredInterfaces{systemInterface};
412 if (requireExactMatch)
413 {
414 desiredInterfaces.emplace_back(boardInterface);
415 }
416 method.append(desiredInterfaces);
Nikhil Namjoshidd1811c2023-03-14 22:51:48 +0000417
Jie Yange7cf3192021-08-20 11:21:43 -0700418 try
419 {
Gobinath Krishnamoorthybb9c6222022-11-03 20:08:01 +0000420 std::vector<std::string> paths;
Josh Lehan027277a2023-09-11 05:28:19 -0700421 sdbusplus::message_t reply = bus->call(method);
Gobinath Krishnamoorthybb9c6222022-11-03 20:08:01 +0000422 reply.read(paths);
Josh Lehan027277a2023-09-11 05:28:19 -0700423
424 size_t pathsCount = paths.size();
425 for (size_t i = 0; i < pathsCount; ++i)
426 {
427 if (requireExactMatch && (paths[i] != smbiosInventoryPath))
428 {
429 continue;
430 }
431
432 motherboardPath = std::move(paths[i]);
433 break;
434 }
Jie Yange7cf3192021-08-20 11:21:43 -0700435 }
436 catch (const sdbusplus::exception_t& e)
437 {
Josh Lehan027277a2023-09-11 05:28:19 -0700438 lg2::error(
439 "Exception while trying to find Inventory anchor object for SMBIOS content {I}: {E}",
440 "I", smbiosInventoryPath, "E", e.what());
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530441 lg2::error("Failed to query system motherboard: {ERROR}", "ERROR",
442 e.what());
Jie Yange7cf3192021-08-20 11:21:43 -0700443 }
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800444
Josh Lehanabdccd32024-01-26 15:49:50 -0800445 if (motherboardPath.empty())
446 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530447 lg2::error(
448 "Failed to get system motherboard dbus path. Setting up a match rule");
Josh Lehanabdccd32024-01-26 15:49:50 -0800449
450 if (motherboardConfigMatch)
451 {
452 lg2::info("Motherboard match rule already exists");
453 }
454 else
455 {
456 motherboardConfigMatch = std::make_unique<sdbusplus::bus::match_t>(
457 *bus,
458 sdbusplus::bus::match::rules::interfacesAdded() +
459 sdbusplus::bus::match::rules::argNpath(0, matchParentPath),
460 [this, requireExactMatch](sdbusplus::message_t& msg) {
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400461 sdbusplus::message::object_path objectName;
Josh Lehanabdccd32024-01-26 15:49:50 -0800462 boost::container::flat_map<
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400463 std::string,
464 boost::container::flat_map<
465 std::string, std::variant<std::string, uint64_t>>>
466 msgData;
467 msg.read(objectName, msgData);
468 bool gotMatch = false;
Josh Lehanabdccd32024-01-26 15:49:50 -0800469
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400470 if (msgData.contains(systemInterface))
471 {
472 lg2::info("Successful match on system interface");
473 gotMatch = true;
474 }
Josh Lehanabdccd32024-01-26 15:49:50 -0800475
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400476 // If customized, also accept Board as anchor, not just
477 // System
478 if (requireExactMatch && msgData.contains(boardInterface))
479 {
480 lg2::info("Successful match on board interface");
481 gotMatch = true;
482 }
Josh Lehanabdccd32024-01-26 15:49:50 -0800483
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400484 if (gotMatch)
485 {
486 // There is a race condition here: our desired interface
487 // has just been created, triggering the D-Bus callback,
488 // but Object Mapper has not been told of it yet. The
489 // mapper must also add it. Stall for time, so it can.
490 sleep(2);
491 systemInfoUpdate();
492 }
493 });
Josh Lehanabdccd32024-01-26 15:49:50 -0800494 }
495 }
496 else
497 {
498#ifdef ASSOC_TRIM_PATH
499 // When enabled, chop off last component of motherboardPath, to trim one
500 // layer, so that associations are built to the underlying chassis
501 // itself, not the system boards in the chassis. This is for
502 // compatibility with traditional systems which only have one
503 // motherboard per chassis.
504 std::filesystem::path foundPath(motherboardPath);
505 motherboardPath = foundPath.parent_path().string();
506#endif
507
508 lg2::info("Found Inventory anchor object for SMBIOS content {I}: {M}",
509 "I", smbiosInventoryPath, "M", motherboardPath);
510 }
511
512 lg2::info("Using Inventory anchor object for SMBIOS content {I}: {M}", "I",
513 smbiosInventoryPath, "M", motherboardPath);
514
Prithvi Pai26e04a82025-04-02 13:01:22 +0530515 std::optional<size_t> num = getTotalSmbiosEntries(processorsType);
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700516 if (!num)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800517 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530518 lg2::error("get cpu total slot failed");
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800519 return;
520 }
521
Brandon Kim5a122a62023-05-04 04:25:03 +0000522 // In case the new size is smaller than old, trim the vector
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700523 if (*num < cpus.size())
Brandon Kim5a122a62023-05-04 04:25:03 +0000524 {
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700525 cpus.resize(*num);
Brandon Kim5a122a62023-05-04 04:25:03 +0000526 }
527
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700528 for (unsigned int index = 0; index < *num; index++)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800529 {
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400530 std::string path =
531 smbiosInventoryPath + cpuSuffix + std::to_string(index);
Brandon Kim5a122a62023-05-04 04:25:03 +0000532 if (index + 1 > cpus.size())
533 {
534 cpus.emplace_back(std::make_unique<phosphor::smbios::Cpu>(
Josh Lehan027277a2023-09-11 05:28:19 -0700535 *bus, path, index, smbiosDir.dir[smbiosDirIndex].dataStorage,
Brandon Kim5a122a62023-05-04 04:25:03 +0000536 motherboardPath));
537 }
538 else
539 {
540 cpus[index]->infoUpdate(smbiosDir.dir[smbiosDirIndex].dataStorage,
541 motherboardPath);
542 }
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800543 }
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800544
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700545#ifdef DIMM_DBUS
546
Prithvi Pai26e04a82025-04-02 13:01:22 +0530547 num = getTotalSmbiosEntries(memoryDeviceType);
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700548 if (!num)
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800549 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530550 lg2::error("get dimm total slot failed");
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800551 return;
552 }
553
Brandon Kim5a122a62023-05-04 04:25:03 +0000554 // In case the new size is smaller than old, trim the vector
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700555 if (*num < dimms.size())
Brandon Kim5a122a62023-05-04 04:25:03 +0000556 {
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700557 dimms.resize(*num);
Brandon Kim5a122a62023-05-04 04:25:03 +0000558 }
559
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700560 for (unsigned int index = 0; index < *num; index++)
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800561 {
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400562 std::string path =
563 smbiosInventoryPath + dimmSuffix + std::to_string(index);
Brandon Kim5a122a62023-05-04 04:25:03 +0000564 if (index + 1 > dimms.size())
565 {
566 dimms.emplace_back(std::make_unique<phosphor::smbios::Dimm>(
Josh Lehan027277a2023-09-11 05:28:19 -0700567 *bus, path, index, smbiosDir.dir[smbiosDirIndex].dataStorage,
Brandon Kim5a122a62023-05-04 04:25:03 +0000568 motherboardPath));
569 }
570 else
571 {
572 dimms[index]->memoryInfoUpdate(
573 smbiosDir.dir[smbiosDirIndex].dataStorage, motherboardPath);
574 }
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800575 }
Cheng C Yangb4651b92019-12-19 00:59:01 +0800576
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700577#endif
578
Prithvi Pai26e04a82025-04-02 13:01:22 +0530579 num = getTotalSmbiosEntries(systemSlots);
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700580 if (!num)
Jie Yang08e4a6d2021-08-23 13:07:41 -0700581 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530582 lg2::error("get pcie total slot failed");
Jie Yang08e4a6d2021-08-23 13:07:41 -0700583 return;
584 }
585
Brandon Kim5a122a62023-05-04 04:25:03 +0000586 // In case the new size is smaller than old, trim the vector
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700587 if (*num < pcies.size())
Brandon Kim5a122a62023-05-04 04:25:03 +0000588 {
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700589 pcies.resize(*num);
Brandon Kim5a122a62023-05-04 04:25:03 +0000590 }
591
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700592 for (unsigned int index = 0; index < *num; index++)
Jie Yang08e4a6d2021-08-23 13:07:41 -0700593 {
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400594 std::string path =
595 smbiosInventoryPath + pcieSuffix + std::to_string(index);
Brandon Kim5a122a62023-05-04 04:25:03 +0000596 if (index + 1 > pcies.size())
597 {
598 pcies.emplace_back(std::make_unique<phosphor::smbios::Pcie>(
Josh Lehan027277a2023-09-11 05:28:19 -0700599 *bus, path, index, smbiosDir.dir[smbiosDirIndex].dataStorage,
Brandon Kim5a122a62023-05-04 04:25:03 +0000600 motherboardPath));
601 }
602 else
603 {
604 pcies[index]->pcieInfoUpdate(
605 smbiosDir.dir[smbiosDirIndex].dataStorage, motherboardPath);
606 }
Jie Yang08e4a6d2021-08-23 13:07:41 -0700607 }
608
Prithvi Pai5af42bb2025-02-11 17:59:07 +0530609#ifdef TPM_DBUS
610
Prithvi Pai26e04a82025-04-02 13:01:22 +0530611 num = getTotalSmbiosEntries(tpmDeviceType);
Prithvi Pai5af42bb2025-02-11 17:59:07 +0530612 if (!num)
613 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530614 lg2::error("get tpm failed");
Prithvi Pai5af42bb2025-02-11 17:59:07 +0530615 return;
616 }
617 // In case the new size is smaller than old, trim the vector
618 if (*num < tpms.size())
619 {
620 tpms.resize(*num);
621 }
622
623 for (unsigned int index = 0; index < *num; index++)
624 {
625 std::string path =
626 smbiosInventoryPath + tpmSuffix + std::to_string(index);
627 if (index + 1 > tpms.size())
628 {
629 tpms.emplace_back(std::make_unique<phosphor::smbios::Tpm>(
630 *bus, path, index, smbiosDir.dir[smbiosDirIndex].dataStorage,
631 motherboardPath));
632 }
633 else
634 {
635 tpms[index]->tpmInfoUpdate(
636 smbiosDir.dir[smbiosDirIndex].dataStorage, motherboardPath);
637 }
638 }
639#endif
640
Prithvi Pai6f9e7a72025-03-14 13:05:02 +0530641#ifdef FIRMWARE_INVENTORY_DBUS
642
643 auto existingVersionPaths = utils::getExistingVersionPaths(*bus);
Prithvi Pai26e04a82025-04-02 13:01:22 +0530644 num = getTotalSmbiosEntries(firmwareInventoryInformationType);
Prithvi Pai6f9e7a72025-03-14 13:05:02 +0530645 if (!num)
646 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530647 lg2::error("get firmware inventory failed");
Prithvi Pai6f9e7a72025-03-14 13:05:02 +0530648 existingVersionPaths.clear();
649 return;
650 }
651
652 // In case the new size is smaller than old, trim the vector
653 if (*num < firmwareCollection.size())
654 {
655 firmwareCollection.resize(*num);
656 }
657 for (unsigned int index = 0; index < *num; index++)
658 {
659 auto path = FirmwareInventory::checkAndCreateFirmwarePath(
660 smbiosDir.dir[smbiosDirIndex].dataStorage, index,
661 existingVersionPaths);
662 if (path.empty())
663 {
664 continue;
665 }
666 firmwareCollection.emplace_back(
667 std::make_unique<phosphor::smbios::FirmwareInventory>(
668 *bus, path, index, smbiosDir.dir[smbiosDirIndex].dataStorage));
669 }
670
671#endif
672
Cheng C Yangb4651b92019-12-19 00:59:01 +0800673 system.reset();
Josh Lehan027277a2023-09-11 05:28:19 -0700674 system = std::make_unique<System>(bus, smbiosInventoryPath + systemSuffix,
675 smbiosDir.dir[smbiosDirIndex].dataStorage,
676 smbiosFilePath);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800677}
678
Prithvi Pai26e04a82025-04-02 13:01:22 +0530679std::optional<size_t> MDRV2::getTotalSmbiosEntries(uint8_t smbiosType)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800680{
681 uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700682 size_t num = 0;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800683
684 if (dataIn == nullptr)
685 {
Prithvi Pai26e04a82025-04-02 13:01:22 +0530686 lg2::error("Failed to get SMBIOS entries for type {TYPE}", "TYPE",
687 smbiosType);
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700688 return std::nullopt;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800689 }
690
691 while (1)
692 {
Prithvi Pai26e04a82025-04-02 13:01:22 +0530693 dataIn = getSMBIOSTypePtr(dataIn, smbiosType);
Jie Yang08e4a6d2021-08-23 13:07:41 -0700694 if (dataIn == nullptr)
695 {
696 break;
697 }
698
Prithvi Pai26e04a82025-04-02 13:01:22 +0530699 // Special handling for PCIe slots
700 if (smbiosType == systemSlots)
701 {
702 if (pcieSmbiosType.find(*(dataIn + 5)) != pcieSmbiosType.end())
703 {
704 num++;
705 }
706 }
707 else
Jie Yang08e4a6d2021-08-23 13:07:41 -0700708 {
709 num++;
710 }
Prithvi Pai26e04a82025-04-02 13:01:22 +0530711 if (num >= limitEntryLen)
712 {
713 break;
714 }
Jie Yang08e4a6d2021-08-23 13:07:41 -0700715 dataIn = smbiosNextPtr(dataIn);
716 if (dataIn == nullptr)
717 {
718 break;
719 }
Jie Yang08e4a6d2021-08-23 13:07:41 -0700720 }
Prithvi Pai6f9e7a72025-03-14 13:05:02 +0530721 return num;
722}
723
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700724bool MDRV2::checkSMBIOSVersion(uint8_t* dataIn)
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530725{
Brandon Kime4ea3772022-02-23 20:21:10 -0800726 const std::string anchorString21 = "_SM_";
727 const std::string anchorString30 = "_SM3_";
Josh Lehanc6d87a52024-02-08 19:01:29 -0800728 std::string buffer(reinterpret_cast<const char*>(dataIn),
729 smbiosTableStorageSize);
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530730
731 auto it = std::search(std::begin(buffer), std::end(buffer),
Brandon Kime4ea3772022-02-23 20:21:10 -0800732 std::begin(anchorString21), std::end(anchorString21));
733 bool smbios21Found = it != std::end(buffer);
734 if (!smbios21Found)
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530735 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530736 lg2::info("SMBIOS 2.1 Anchor String not found. Looking for SMBIOS 3.0");
Brandon Kime4ea3772022-02-23 20:21:10 -0800737 it = std::search(std::begin(buffer), std::end(buffer),
738 std::begin(anchorString30), std::end(anchorString30));
739 if (it == std::end(buffer))
740 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530741 lg2::error("SMBIOS 2.1 and 3.0 Anchor Strings not found");
Brandon Kime4ea3772022-02-23 20:21:10 -0800742 return false;
743 }
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530744 }
745
746 auto pos = std::distance(std::begin(buffer), it);
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700747 size_t length = smbiosTableStorageSize - pos;
Brandon Kime4ea3772022-02-23 20:21:10 -0800748 uint8_t foundMajorVersion;
749 uint8_t foundMinorVersion;
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530750
Brandon Kime4ea3772022-02-23 20:21:10 -0800751 if (smbios21Found)
752 {
753 if (length < sizeof(EntryPointStructure21))
754 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530755 lg2::error("Invalid entry point structure for SMBIOS 2.1");
Brandon Kime4ea3772022-02-23 20:21:10 -0800756 return false;
757 }
758
759 auto epStructure =
760 reinterpret_cast<const EntryPointStructure21*>(&dataIn[pos]);
761 foundMajorVersion = epStructure->smbiosVersion.majorVersion;
762 foundMinorVersion = epStructure->smbiosVersion.minorVersion;
763 }
764 else
765 {
766 if (length < sizeof(EntryPointStructure30))
767 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530768 lg2::error("Invalid entry point structure for SMBIOS 3.0");
Brandon Kime4ea3772022-02-23 20:21:10 -0800769 return false;
770 }
771
772 auto epStructure =
773 reinterpret_cast<const EntryPointStructure30*>(&dataIn[pos]);
774 foundMajorVersion = epStructure->smbiosVersion.majorVersion;
775 foundMinorVersion = epStructure->smbiosVersion.minorVersion;
776 }
777 lg2::info("SMBIOS VERSION - {MAJOR}.{MINOR}", "MAJOR", foundMajorVersion,
778 "MINOR", foundMinorVersion);
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530779
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400780 auto itr = std::find_if(
781 std::begin(supportedSMBIOSVersions), std::end(supportedSMBIOSVersions),
782 [&](SMBIOSVersion versionItr) {
783 return versionItr.majorVersion == foundMajorVersion &&
784 versionItr.minorVersion == foundMinorVersion;
785 });
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530786 if (itr == std::end(supportedSMBIOSVersions))
787 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530788 lg2::error("Unsupported SMBIOS table version");
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530789 return false;
790 }
791 return true;
792}
793
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700794bool MDRV2::agentSynchronizeData()
Cheng C Yangeecaf822019-12-19 00:34:23 +0800795{
Cheng C Yangec634252019-12-19 00:42:36 +0800796 struct MDRSMBIOSHeader mdr2SMBIOS;
797 bool status = readDataFromFlash(&mdr2SMBIOS,
798 smbiosDir.dir[smbiosDirIndex].dataStorage);
799 if (!status)
800 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530801 lg2::error("agent data sync failed - read data from flash failed");
Cheng C Yangec634252019-12-19 00:42:36 +0800802 return false;
803 }
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530804
805 if (!checkSMBIOSVersion(smbiosDir.dir[smbiosDirIndex].dataStorage))
Cheng C Yangec634252019-12-19 00:42:36 +0800806 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530807 lg2::error("Unsupported SMBIOS table version");
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530808 return false;
Cheng C Yangec634252019-12-19 00:42:36 +0800809 }
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530810
Jayaprakash Mutyalab5cc6902025-02-13 07:00:15 +0000811 if (0 == static_cast<uint8_t>(sdbusplus::server::xyz::openbmc_project::
812 smbios::MDRV2::directoryEntries()))
813 {
814 directoryEntries(smbiosDir.dirEntries);
815 }
816
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530817 systemInfoUpdate();
818 smbiosDir.dir[smbiosDirIndex].common.dataVersion = mdr2SMBIOS.dirVer;
819 smbiosDir.dir[smbiosDirIndex].common.timestamp = mdr2SMBIOS.timestamp;
820 smbiosDir.dir[smbiosDirIndex].common.size = mdr2SMBIOS.dataSize;
821 smbiosDir.dir[smbiosDirIndex].stage = MDR2SMBIOSStatusEnum::mdr2Loaded;
822 smbiosDir.dir[smbiosDirIndex].lock = MDR2DirLockEnum::mdr2DirUnlock;
823
Cheng C Yangec634252019-12-19 00:42:36 +0800824 return true;
Cheng C Yangeecaf822019-12-19 00:34:23 +0800825}
826
Patrick Williams07a2c9a2025-02-01 08:23:10 -0500827std::vector<uint32_t> MDRV2::synchronizeDirectoryCommonData(uint8_t idIndex,
828 uint32_t size)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800829{
Cheng C Yangec634252019-12-19 00:42:36 +0800830 std::chrono::microseconds usec(
831 defaultTimeout); // default lock time out is 2s
832 std::vector<uint32_t> result;
833 smbiosDir.dir[idIndex].common.size = size;
834 result.push_back(smbiosDir.dir[idIndex].common.dataSetSize);
835 result.push_back(smbiosDir.dir[idIndex].common.dataVersion);
836 result.push_back(smbiosDir.dir[idIndex].common.timestamp);
837
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700838 timer.expires_after(usec);
839 timer.async_wait([this](boost::system::error_code ec) {
Josh Lehan027277a2023-09-11 05:28:19 -0700840 if (ec)
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700841 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530842 lg2::error("Timer Error!");
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700843 return;
844 }
845 agentSynchronizeData();
846 });
Cheng C Yangec634252019-12-19 00:42:36 +0800847 return result;
Cheng C Yangeecaf822019-12-19 00:34:23 +0800848}
849
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700850std::vector<boost::container::flat_map<std::string, RecordVariant>>
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700851 MDRV2::getRecordType(size_t type)
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700852{
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700853 std::vector<boost::container::flat_map<std::string, RecordVariant>> ret;
854 if (type == memoryDeviceType)
855 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700856 uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
857
858 if (dataIn == nullptr)
859 {
Kuiying Wanga4c08702020-11-18 19:27:20 +0800860 throw std::runtime_error("Data not populated");
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700861 }
862
863 do
864 {
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400865 dataIn =
866 getSMBIOSTypePtr(dataIn, memoryDeviceType, sizeof(MemoryInfo));
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700867 if (dataIn == nullptr)
868 {
869 break;
870 }
871 boost::container::flat_map<std::string, RecordVariant>& record =
872 ret.emplace_back();
873
874 auto memoryInfo = reinterpret_cast<MemoryInfo*>(dataIn);
875
876 record["Type"] = memoryInfo->type;
877 record["Length"] = memoryInfo->length;
878 record["Handle"] = uint16_t(memoryInfo->handle);
879 record["Physical Memory Array Handle"] =
880 uint16_t(memoryInfo->phyArrayHandle);
881 record["Memory Error Information Handle"] =
882 uint16_t(memoryInfo->errInfoHandle);
883 record["Total Width"] = uint16_t(memoryInfo->totalWidth);
884 record["Data Width"] = uint16_t(memoryInfo->dataWidth);
885 record["Size"] = uint16_t(memoryInfo->size);
886 record["Form Factor"] = memoryInfo->formFactor;
887 record["Device Set"] = memoryInfo->deviceSet;
888 record["Device Locator"] = positionToString(
889 memoryInfo->deviceLocator, memoryInfo->length, dataIn);
890 record["Bank Locator"] = positionToString(
891 memoryInfo->bankLocator, memoryInfo->length, dataIn);
892 record["Memory Type"] = memoryInfo->memoryType;
893 record["Type Detail"] = uint16_t(memoryInfo->typeDetail);
894 record["Speed"] = uint16_t(memoryInfo->speed);
895 record["Manufacturer"] = positionToString(
896 memoryInfo->manufacturer, memoryInfo->length, dataIn);
897 record["Serial Number"] = positionToString(
898 memoryInfo->serialNum, memoryInfo->length, dataIn);
899 record["Asset Tag"] = positionToString(memoryInfo->assetTag,
900 memoryInfo->length, dataIn);
901 record["Part Number"] = positionToString(
902 memoryInfo->partNum, memoryInfo->length, dataIn);
George Liu036374a2023-06-15 08:47:46 +0800903 record["Attributes"] = uint32_t(memoryInfo->attributes);
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700904 record["Extended Size"] = uint32_t(memoryInfo->extendedSize);
905 record["Configured Memory Speed"] =
906 uint32_t(memoryInfo->confClockSpeed);
907 record["Minimum voltage"] = uint16_t(memoryInfo->minimumVoltage);
908 record["Maximum voltage"] = uint16_t(memoryInfo->maximumVoltage);
909 record["Configured voltage"] =
910 uint16_t(memoryInfo->configuredVoltage);
911 record["Memory Technology"] = memoryInfo->memoryTechnology;
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +0530912 record["Memory Operating Mode Capability"] =
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700913 uint16_t(memoryInfo->memoryOperatingModeCap);
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +0530914 record["Firmware Version"] = memoryInfo->firwareVersion;
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700915 record["Module Manufacturer ID"] =
916 uint16_t(memoryInfo->modelManufId);
917 record["Module Product ID"] = uint16_t(memoryInfo->modelProdId);
918 record["Memory Subsystem Controller Manufacturer ID"] =
919 uint16_t(memoryInfo->memSubConManufId);
920 record["Memory Subsystem Controller Product Id"] =
921 uint16_t(memoryInfo->memSubConProdId);
922 record["Non-volatile Size"] = uint64_t(memoryInfo->nvSize);
923 record["Volatile Size"] = uint64_t(memoryInfo->volatileSize);
924 record["Cache Size"] = uint64_t(memoryInfo->cacheSize);
925 record["Logical Size"] = uint64_t(memoryInfo->logicalSize);
926 } while ((dataIn = smbiosNextPtr(dataIn)) != nullptr);
927
928 return ret;
929 }
930
Kuiying Wanga4c08702020-11-18 19:27:20 +0800931 throw std::invalid_argument("Invalid record type");
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700932 return ret;
933}
934
Cheng C Yangeecaf822019-12-19 00:34:23 +0800935} // namespace smbios
936} // namespace phosphor