Add DIMM dbus service for MDR V2

Add all DIMM information in smbios table and provide dbus
interface for redfish to get DIMM information.

Tested:
DC cycle the system and waiting for BIOS entring setup page.
Correct DIMM information should show in Redfish.

Signed-off-by: Cheng C Yang <cheng.c.yang@linux.intel.com>
Change-Id: I8c2678c5d40f4d1fde81292b21aa94e80b0ab586
diff --git a/src/mdrv2.cpp b/src/mdrv2.cpp
index 8452741..c392127 100644
--- a/src/mdrv2.cpp
+++ b/src/mdrv2.cpp
@@ -379,6 +379,23 @@
         cpus.emplace_back(std::make_unique<phosphor::smbios::Cpu>(
             bus, path, index, smbiosDir.dir[smbiosDirIndex].dataStorage));
     }
+
+    dimms.clear();
+
+    num = getTotalDimmSlot();
+    if (num == -1)
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "get dimm total slot failed");
+        return;
+    }
+
+    for (int index = 0; index < num; index++)
+    {
+        std::string path = dimmPath + std::to_string(index);
+        dimms.emplace_back(std::make_unique<phosphor::smbios::Dimm>(
+            bus, path, index, smbiosDir.dir[smbiosDirIndex].dataStorage));
+    }
 }
 
 int MDR_V2::getTotalCpuSlot()
@@ -415,6 +432,40 @@
     return num;
 }
 
+int MDR_V2::getTotalDimmSlot()
+{
+    uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
+    uint8_t num = 0;
+
+    if (dataIn == nullptr)
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "Fail to get dimm total slot - no storage data");
+        return -1;
+    }
+
+    while (1)
+    {
+        dataIn = getSMBIOSTypePtr(dataIn, memoryDeviceType);
+        if (dataIn == nullptr)
+        {
+            break;
+        }
+        num++;
+        dataIn = smbiosNextPtr(dataIn);
+        if (dataIn == nullptr)
+        {
+            break;
+        }
+        if (num >= limitEntryLen)
+        {
+            break;
+        }
+    }
+
+    return num;
+}
+
 bool MDR_V2::agentSynchronizeData()
 {
     struct MDRSMBIOSHeader mdr2SMBIOS;