blob: 357fb02ce04a5a46b57540071d1a129d93d7999b [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
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700515 std::optional<size_t> num = getTotalCpuSlot();
516 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
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800547 num = getTotalDimmSlot();
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
Jie Yang08e4a6d2021-08-23 13:07:41 -0700579 num = getTotalPcieSlot();
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
611 num = getTotalTpm();
612 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);
644 num = getTotalFirmwareInventory();
645 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
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700679std::optional<size_t> MDRV2::getTotalCpuSlot()
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 Pai6981b7f2025-04-02 10:33:29 +0530686 lg2::error("get cpu total slot failed - no storage data");
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700687 return std::nullopt;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800688 }
689
690 while (1)
691 {
692 dataIn = getSMBIOSTypePtr(dataIn, processorsType);
693 if (dataIn == nullptr)
694 {
695 break;
696 }
697 num++;
698 dataIn = smbiosNextPtr(dataIn);
699 if (dataIn == nullptr)
700 {
701 break;
702 }
703 if (num >= limitEntryLen)
704 {
705 break;
706 }
707 }
708
709 return num;
710}
711
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700712std::optional<size_t> MDRV2::getTotalDimmSlot()
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800713{
714 uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700715 size_t num = 0;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800716
717 if (dataIn == nullptr)
718 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530719 lg2::error("Fail to get dimm total slot - no storage data");
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700720 return std::nullopt;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800721 }
722
723 while (1)
724 {
725 dataIn = getSMBIOSTypePtr(dataIn, memoryDeviceType);
726 if (dataIn == nullptr)
727 {
728 break;
729 }
730 num++;
731 dataIn = smbiosNextPtr(dataIn);
732 if (dataIn == nullptr)
733 {
734 break;
735 }
736 if (num >= limitEntryLen)
737 {
738 break;
739 }
740 }
741
742 return num;
743}
744
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700745std::optional<size_t> MDRV2::getTotalPcieSlot()
Jie Yang08e4a6d2021-08-23 13:07:41 -0700746{
747 uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700748 size_t num = 0;
Jie Yang08e4a6d2021-08-23 13:07:41 -0700749
750 if (dataIn == nullptr)
751 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530752 lg2::error("Fail to get total system slot - no storage data");
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700753 return std::nullopt;
Jie Yang08e4a6d2021-08-23 13:07:41 -0700754 }
755
756 while (1)
757 {
758 dataIn = getSMBIOSTypePtr(dataIn, systemSlots);
759 if (dataIn == nullptr)
760 {
761 break;
762 }
763
764 /* System slot type offset. Check if the slot is a PCIE slots. All
765 * PCIE slot type are hardcoded in a table.
766 */
767 if (pcieSmbiosType.find(*(dataIn + 5)) != pcieSmbiosType.end())
768 {
769 num++;
770 }
771 dataIn = smbiosNextPtr(dataIn);
772 if (dataIn == nullptr)
773 {
774 break;
775 }
776 if (num >= limitEntryLen)
777 {
778 break;
779 }
780 }
781
782 return num;
783}
784
Prithvi Pai5af42bb2025-02-11 17:59:07 +0530785std::optional<size_t> MDRV2::getTotalTpm()
786{
787 uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
788 size_t num = 0;
789
790 if (dataIn == nullptr)
791 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530792 lg2::error("Fail to get tpm total slot - no storage data");
Prithvi Pai5af42bb2025-02-11 17:59:07 +0530793 return std::nullopt;
794 }
795
796 while (1)
797 {
798 dataIn = getSMBIOSTypePtr(dataIn, tpmDeviceType);
799 if (dataIn == nullptr)
800 {
801 break;
802 }
803 num++;
804 dataIn = smbiosNextPtr(dataIn);
805 if (dataIn == nullptr)
806 {
807 break;
808 }
809 if (num >= limitEntryLen)
810 {
811 break;
812 }
813 }
814
815 return num;
816}
817
Prithvi Pai6f9e7a72025-03-14 13:05:02 +0530818std::optional<size_t> MDRV2::getTotalFirmwareInventory()
819{
820 uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
821 size_t num = 0;
822
823 if (dataIn == nullptr)
824 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530825 lg2::error("Fail to get firmware inventory - no storage data");
Prithvi Pai6f9e7a72025-03-14 13:05:02 +0530826 return std::nullopt;
827 }
828
829 while (1)
830 {
831 dataIn = getSMBIOSTypePtr(dataIn, firmwareInventoryInformationType);
832 if (dataIn == nullptr)
833 {
834 break;
835 }
836 num++;
837 dataIn = smbiosNextPtr(dataIn);
838 if (dataIn == nullptr)
839 {
840 break;
841 }
842 if (num >= limitEntryLen)
843 {
844 break;
845 }
846 }
847
848 return num;
849}
850
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700851bool MDRV2::checkSMBIOSVersion(uint8_t* dataIn)
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530852{
Brandon Kime4ea3772022-02-23 20:21:10 -0800853 const std::string anchorString21 = "_SM_";
854 const std::string anchorString30 = "_SM3_";
Josh Lehanc6d87a52024-02-08 19:01:29 -0800855 std::string buffer(reinterpret_cast<const char*>(dataIn),
856 smbiosTableStorageSize);
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530857
858 auto it = std::search(std::begin(buffer), std::end(buffer),
Brandon Kime4ea3772022-02-23 20:21:10 -0800859 std::begin(anchorString21), std::end(anchorString21));
860 bool smbios21Found = it != std::end(buffer);
861 if (!smbios21Found)
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530862 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530863 lg2::info("SMBIOS 2.1 Anchor String not found. Looking for SMBIOS 3.0");
Brandon Kime4ea3772022-02-23 20:21:10 -0800864 it = std::search(std::begin(buffer), std::end(buffer),
865 std::begin(anchorString30), std::end(anchorString30));
866 if (it == std::end(buffer))
867 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530868 lg2::error("SMBIOS 2.1 and 3.0 Anchor Strings not found");
Brandon Kime4ea3772022-02-23 20:21:10 -0800869 return false;
870 }
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530871 }
872
873 auto pos = std::distance(std::begin(buffer), it);
Jonathan Domanf2d8bb42023-07-26 10:13:34 -0700874 size_t length = smbiosTableStorageSize - pos;
Brandon Kime4ea3772022-02-23 20:21:10 -0800875 uint8_t foundMajorVersion;
876 uint8_t foundMinorVersion;
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530877
Brandon Kime4ea3772022-02-23 20:21:10 -0800878 if (smbios21Found)
879 {
880 if (length < sizeof(EntryPointStructure21))
881 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530882 lg2::error("Invalid entry point structure for SMBIOS 2.1");
Brandon Kime4ea3772022-02-23 20:21:10 -0800883 return false;
884 }
885
886 auto epStructure =
887 reinterpret_cast<const EntryPointStructure21*>(&dataIn[pos]);
888 foundMajorVersion = epStructure->smbiosVersion.majorVersion;
889 foundMinorVersion = epStructure->smbiosVersion.minorVersion;
890 }
891 else
892 {
893 if (length < sizeof(EntryPointStructure30))
894 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530895 lg2::error("Invalid entry point structure for SMBIOS 3.0");
Brandon Kime4ea3772022-02-23 20:21:10 -0800896 return false;
897 }
898
899 auto epStructure =
900 reinterpret_cast<const EntryPointStructure30*>(&dataIn[pos]);
901 foundMajorVersion = epStructure->smbiosVersion.majorVersion;
902 foundMinorVersion = epStructure->smbiosVersion.minorVersion;
903 }
904 lg2::info("SMBIOS VERSION - {MAJOR}.{MINOR}", "MAJOR", foundMajorVersion,
905 "MINOR", foundMinorVersion);
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530906
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400907 auto itr = std::find_if(
908 std::begin(supportedSMBIOSVersions), std::end(supportedSMBIOSVersions),
909 [&](SMBIOSVersion versionItr) {
910 return versionItr.majorVersion == foundMajorVersion &&
911 versionItr.minorVersion == foundMinorVersion;
912 });
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530913 if (itr == std::end(supportedSMBIOSVersions))
914 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530915 lg2::error("Unsupported SMBIOS table version");
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530916 return false;
917 }
918 return true;
919}
920
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700921bool MDRV2::agentSynchronizeData()
Cheng C Yangeecaf822019-12-19 00:34:23 +0800922{
Cheng C Yangec634252019-12-19 00:42:36 +0800923 struct MDRSMBIOSHeader mdr2SMBIOS;
924 bool status = readDataFromFlash(&mdr2SMBIOS,
925 smbiosDir.dir[smbiosDirIndex].dataStorage);
926 if (!status)
927 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530928 lg2::error("agent data sync failed - read data from flash failed");
Cheng C Yangec634252019-12-19 00:42:36 +0800929 return false;
930 }
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530931
932 if (!checkSMBIOSVersion(smbiosDir.dir[smbiosDirIndex].dataStorage))
Cheng C Yangec634252019-12-19 00:42:36 +0800933 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530934 lg2::error("Unsupported SMBIOS table version");
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530935 return false;
Cheng C Yangec634252019-12-19 00:42:36 +0800936 }
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530937
Jayaprakash Mutyalab5cc6902025-02-13 07:00:15 +0000938 if (0 == static_cast<uint8_t>(sdbusplus::server::xyz::openbmc_project::
939 smbios::MDRV2::directoryEntries()))
940 {
941 directoryEntries(smbiosDir.dirEntries);
942 }
943
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530944 systemInfoUpdate();
945 smbiosDir.dir[smbiosDirIndex].common.dataVersion = mdr2SMBIOS.dirVer;
946 smbiosDir.dir[smbiosDirIndex].common.timestamp = mdr2SMBIOS.timestamp;
947 smbiosDir.dir[smbiosDirIndex].common.size = mdr2SMBIOS.dataSize;
948 smbiosDir.dir[smbiosDirIndex].stage = MDR2SMBIOSStatusEnum::mdr2Loaded;
949 smbiosDir.dir[smbiosDirIndex].lock = MDR2DirLockEnum::mdr2DirUnlock;
950
Cheng C Yangec634252019-12-19 00:42:36 +0800951 return true;
Cheng C Yangeecaf822019-12-19 00:34:23 +0800952}
953
Patrick Williams07a2c9a2025-02-01 08:23:10 -0500954std::vector<uint32_t> MDRV2::synchronizeDirectoryCommonData(uint8_t idIndex,
955 uint32_t size)
Cheng C Yangeecaf822019-12-19 00:34:23 +0800956{
Cheng C Yangec634252019-12-19 00:42:36 +0800957 std::chrono::microseconds usec(
958 defaultTimeout); // default lock time out is 2s
959 std::vector<uint32_t> result;
960 smbiosDir.dir[idIndex].common.size = size;
961 result.push_back(smbiosDir.dir[idIndex].common.dataSetSize);
962 result.push_back(smbiosDir.dir[idIndex].common.dataVersion);
963 result.push_back(smbiosDir.dir[idIndex].common.timestamp);
964
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700965 timer.expires_after(usec);
966 timer.async_wait([this](boost::system::error_code ec) {
Josh Lehan027277a2023-09-11 05:28:19 -0700967 if (ec)
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700968 {
Prithvi Pai6981b7f2025-04-02 10:33:29 +0530969 lg2::error("Timer Error!");
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700970 return;
971 }
972 agentSynchronizeData();
973 });
Cheng C Yangec634252019-12-19 00:42:36 +0800974 return result;
Cheng C Yangeecaf822019-12-19 00:34:23 +0800975}
976
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700977std::vector<boost::container::flat_map<std::string, RecordVariant>>
Jason M. Billsa3f5b382023-04-26 08:17:28 -0700978 MDRV2::getRecordType(size_t type)
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700979{
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700980 std::vector<boost::container::flat_map<std::string, RecordVariant>> ret;
981 if (type == memoryDeviceType)
982 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700983 uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
984
985 if (dataIn == nullptr)
986 {
Kuiying Wanga4c08702020-11-18 19:27:20 +0800987 throw std::runtime_error("Data not populated");
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700988 }
989
990 do
991 {
Patrick Williams1d73dcc2024-08-16 15:21:42 -0400992 dataIn =
993 getSMBIOSTypePtr(dataIn, memoryDeviceType, sizeof(MemoryInfo));
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700994 if (dataIn == nullptr)
995 {
996 break;
997 }
998 boost::container::flat_map<std::string, RecordVariant>& record =
999 ret.emplace_back();
1000
1001 auto memoryInfo = reinterpret_cast<MemoryInfo*>(dataIn);
1002
1003 record["Type"] = memoryInfo->type;
1004 record["Length"] = memoryInfo->length;
1005 record["Handle"] = uint16_t(memoryInfo->handle);
1006 record["Physical Memory Array Handle"] =
1007 uint16_t(memoryInfo->phyArrayHandle);
1008 record["Memory Error Information Handle"] =
1009 uint16_t(memoryInfo->errInfoHandle);
1010 record["Total Width"] = uint16_t(memoryInfo->totalWidth);
1011 record["Data Width"] = uint16_t(memoryInfo->dataWidth);
1012 record["Size"] = uint16_t(memoryInfo->size);
1013 record["Form Factor"] = memoryInfo->formFactor;
1014 record["Device Set"] = memoryInfo->deviceSet;
1015 record["Device Locator"] = positionToString(
1016 memoryInfo->deviceLocator, memoryInfo->length, dataIn);
1017 record["Bank Locator"] = positionToString(
1018 memoryInfo->bankLocator, memoryInfo->length, dataIn);
1019 record["Memory Type"] = memoryInfo->memoryType;
1020 record["Type Detail"] = uint16_t(memoryInfo->typeDetail);
1021 record["Speed"] = uint16_t(memoryInfo->speed);
1022 record["Manufacturer"] = positionToString(
1023 memoryInfo->manufacturer, memoryInfo->length, dataIn);
1024 record["Serial Number"] = positionToString(
1025 memoryInfo->serialNum, memoryInfo->length, dataIn);
1026 record["Asset Tag"] = positionToString(memoryInfo->assetTag,
1027 memoryInfo->length, dataIn);
1028 record["Part Number"] = positionToString(
1029 memoryInfo->partNum, memoryInfo->length, dataIn);
George Liu036374a2023-06-15 08:47:46 +08001030 record["Attributes"] = uint32_t(memoryInfo->attributes);
Zhikui Ren18a5ab92020-09-01 21:35:20 -07001031 record["Extended Size"] = uint32_t(memoryInfo->extendedSize);
1032 record["Configured Memory Speed"] =
1033 uint32_t(memoryInfo->confClockSpeed);
1034 record["Minimum voltage"] = uint16_t(memoryInfo->minimumVoltage);
1035 record["Maximum voltage"] = uint16_t(memoryInfo->maximumVoltage);
1036 record["Configured voltage"] =
1037 uint16_t(memoryInfo->configuredVoltage);
1038 record["Memory Technology"] = memoryInfo->memoryTechnology;
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +05301039 record["Memory Operating Mode Capability"] =
Zhikui Ren18a5ab92020-09-01 21:35:20 -07001040 uint16_t(memoryInfo->memoryOperatingModeCap);
Manojkiran Eda0fe13ab2024-06-17 14:55:10 +05301041 record["Firmware Version"] = memoryInfo->firwareVersion;
Zhikui Ren18a5ab92020-09-01 21:35:20 -07001042 record["Module Manufacturer ID"] =
1043 uint16_t(memoryInfo->modelManufId);
1044 record["Module Product ID"] = uint16_t(memoryInfo->modelProdId);
1045 record["Memory Subsystem Controller Manufacturer ID"] =
1046 uint16_t(memoryInfo->memSubConManufId);
1047 record["Memory Subsystem Controller Product Id"] =
1048 uint16_t(memoryInfo->memSubConProdId);
1049 record["Non-volatile Size"] = uint64_t(memoryInfo->nvSize);
1050 record["Volatile Size"] = uint64_t(memoryInfo->volatileSize);
1051 record["Cache Size"] = uint64_t(memoryInfo->cacheSize);
1052 record["Logical Size"] = uint64_t(memoryInfo->logicalSize);
1053 } while ((dataIn = smbiosNextPtr(dataIn)) != nullptr);
1054
1055 return ret;
1056 }
1057
Kuiying Wanga4c08702020-11-18 19:27:20 +08001058 throw std::invalid_argument("Invalid record type");
Zhikui Ren18a5ab92020-09-01 21:35:20 -07001059 return ret;
1060}
1061
Cheng C Yangeecaf822019-12-19 00:34:23 +08001062} // namespace smbios
1063} // namespace phosphor