Remove duplicate functions to get smbios slot counts
Currently there are duplicate functions to get CPU count,
dimm count, pcie slot count, tpm count and firmware inventory
record counts. The current patch refactors the same and removes
the duplicate.
Tested:
1) DBus tree with this changes looks as before
`- /xyz/openbmc_project
|- /xyz/openbmc_project/Smbios
| `- /xyz/openbmc_project/Smbios/MDR_V2
|- /xyz/openbmc_project/inventory
|`- /xyz/openbmc_project/inventory/system
|`- /xyz/openbmc_project/inventory/system/chassis
|`- /xyz/openbmc_project/inventory/system/chassis/motherboard
|`- /xyz/openbmc_project/inventory/system/chassis/motherboard/bios
`- /xyz/openbmc_project/software
`- /xyz/openbmc_project/software/UEFI
Change-Id: Ie77be54ac240819df785f93272cc2b8398b6c2d0
Signed-off-by: Prithvi Pai <ppai@nvidia.com>
diff --git a/include/mdrv2.hpp b/include/mdrv2.hpp
index c60633c..9776523 100644
--- a/include/mdrv2.hpp
+++ b/include/mdrv2.hpp
@@ -189,11 +189,7 @@
inline uint8_t smbiosValidFlag(uint8_t index);
void systemInfoUpdate(void);
- std::optional<size_t> getTotalCpuSlot(void);
- std::optional<size_t> getTotalDimmSlot(void);
- std::optional<size_t> getTotalPcieSlot(void);
- std::optional<size_t> getTotalTpm(void);
- std::optional<size_t> getTotalFirmwareInventory(void);
+ std::optional<size_t> getTotalSmbiosEntries(uint8_t smbiosType);
std::vector<std::unique_ptr<Cpu>> cpus;
std::vector<std::unique_ptr<Dimm>> dimms;
std::vector<std::unique_ptr<Pcie>> pcies;
diff --git a/src/mdrv2.cpp b/src/mdrv2.cpp
index 357fb02..2aaf4be 100644
--- a/src/mdrv2.cpp
+++ b/src/mdrv2.cpp
@@ -512,7 +512,7 @@
lg2::info("Using Inventory anchor object for SMBIOS content {I}: {M}", "I",
smbiosInventoryPath, "M", motherboardPath);
- std::optional<size_t> num = getTotalCpuSlot();
+ std::optional<size_t> num = getTotalSmbiosEntries(processorsType);
if (!num)
{
lg2::error("get cpu total slot failed");
@@ -544,7 +544,7 @@
#ifdef DIMM_DBUS
- num = getTotalDimmSlot();
+ num = getTotalSmbiosEntries(memoryDeviceType);
if (!num)
{
lg2::error("get dimm total slot failed");
@@ -576,7 +576,7 @@
#endif
- num = getTotalPcieSlot();
+ num = getTotalSmbiosEntries(systemSlots);
if (!num)
{
lg2::error("get pcie total slot failed");
@@ -608,7 +608,7 @@
#ifdef TPM_DBUS
- num = getTotalTpm();
+ num = getTotalSmbiosEntries(tpmDeviceType);
if (!num)
{
lg2::error("get tpm failed");
@@ -641,7 +641,7 @@
#ifdef FIRMWARE_INVENTORY_DBUS
auto existingVersionPaths = utils::getExistingVersionPaths(*bus);
- num = getTotalFirmwareInventory();
+ num = getTotalSmbiosEntries(firmwareInventoryInformationType);
if (!num)
{
lg2::error("get firmware inventory failed");
@@ -676,175 +676,48 @@
smbiosFilePath);
}
-std::optional<size_t> MDRV2::getTotalCpuSlot()
+std::optional<size_t> MDRV2::getTotalSmbiosEntries(uint8_t smbiosType)
{
uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
size_t num = 0;
if (dataIn == nullptr)
{
- lg2::error("get cpu total slot failed - no storage data");
+ lg2::error("Failed to get SMBIOS entries for type {TYPE}", "TYPE",
+ smbiosType);
return std::nullopt;
}
while (1)
{
- dataIn = getSMBIOSTypePtr(dataIn, processorsType);
- if (dataIn == nullptr)
- {
- break;
- }
- num++;
- dataIn = smbiosNextPtr(dataIn);
- if (dataIn == nullptr)
- {
- break;
- }
- if (num >= limitEntryLen)
- {
- break;
- }
- }
-
- return num;
-}
-
-std::optional<size_t> MDRV2::getTotalDimmSlot()
-{
- uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
- size_t num = 0;
-
- if (dataIn == nullptr)
- {
- lg2::error("Fail to get dimm total slot - no storage data");
- return std::nullopt;
- }
-
- while (1)
- {
- dataIn = getSMBIOSTypePtr(dataIn, memoryDeviceType);
- if (dataIn == nullptr)
- {
- break;
- }
- num++;
- dataIn = smbiosNextPtr(dataIn);
- if (dataIn == nullptr)
- {
- break;
- }
- if (num >= limitEntryLen)
- {
- break;
- }
- }
-
- return num;
-}
-
-std::optional<size_t> MDRV2::getTotalPcieSlot()
-{
- uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
- size_t num = 0;
-
- if (dataIn == nullptr)
- {
- lg2::error("Fail to get total system slot - no storage data");
- return std::nullopt;
- }
-
- while (1)
- {
- dataIn = getSMBIOSTypePtr(dataIn, systemSlots);
+ dataIn = getSMBIOSTypePtr(dataIn, smbiosType);
if (dataIn == nullptr)
{
break;
}
- /* System slot type offset. Check if the slot is a PCIE slots. All
- * PCIE slot type are hardcoded in a table.
- */
- if (pcieSmbiosType.find(*(dataIn + 5)) != pcieSmbiosType.end())
+ // Special handling for PCIe slots
+ if (smbiosType == systemSlots)
+ {
+ if (pcieSmbiosType.find(*(dataIn + 5)) != pcieSmbiosType.end())
+ {
+ num++;
+ }
+ }
+ else
{
num++;
}
+ if (num >= limitEntryLen)
+ {
+ break;
+ }
dataIn = smbiosNextPtr(dataIn);
if (dataIn == nullptr)
{
break;
}
- if (num >= limitEntryLen)
- {
- break;
- }
}
-
- return num;
-}
-
-std::optional<size_t> MDRV2::getTotalTpm()
-{
- uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
- size_t num = 0;
-
- if (dataIn == nullptr)
- {
- lg2::error("Fail to get tpm total slot - no storage data");
- return std::nullopt;
- }
-
- while (1)
- {
- dataIn = getSMBIOSTypePtr(dataIn, tpmDeviceType);
- if (dataIn == nullptr)
- {
- break;
- }
- num++;
- dataIn = smbiosNextPtr(dataIn);
- if (dataIn == nullptr)
- {
- break;
- }
- if (num >= limitEntryLen)
- {
- break;
- }
- }
-
- return num;
-}
-
-std::optional<size_t> MDRV2::getTotalFirmwareInventory()
-{
- uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
- size_t num = 0;
-
- if (dataIn == nullptr)
- {
- lg2::error("Fail to get firmware inventory - no storage data");
- return std::nullopt;
- }
-
- while (1)
- {
- dataIn = getSMBIOSTypePtr(dataIn, firmwareInventoryInformationType);
- if (dataIn == nullptr)
- {
- break;
- }
- num++;
- dataIn = smbiosNextPtr(dataIn);
- if (dataIn == nullptr)
- {
- break;
- }
- if (num >= limitEntryLen)
- {
- break;
- }
- }
-
return num;
}