smbios-mdr: Associate with the motherboard

The change associates the objects such as processor, memory and PCIe
slots published by smbios-mdr with the motherboard inventory object.
Presently objects paths created by smbios-mdr have the motherboard path
as the prefix -- "/xyz/openbmc_project/inventory/chassis/motherboard".
For machine with entity-manager dynamic stack, that hardcoded
motherboard path would probably not be the object path of the
motherboard.

We have implemented a DBus method in EM that can return the inventory
object path of the root board in the system. Such associations can be
assembled in Redfish resources can indicate the machine topology.

Tested:
DBus call on the Association interface of a CPU object.

busctl get-property xyz.openbmc_project.Smbios.MDR_V2 \
/xyz/openbmc_project/inventory/system/chassis/motherboard/cpu0 \
xyz.openbmc_project.Association.Definitions Associations
a(sss) 1 "chassis" "processors" \
"/xyz/openbmc_project/inventory/system/board/GSZ"

Signed-off-by: Jie Yang <jjy@google.com>
Change-Id: Ia95159a87c2ce5e69e90e622cf341a68e7db13d4
diff --git a/include/cpu.hpp b/include/cpu.hpp
index 395d528..1f8fd9c 100644
--- a/include/cpu.hpp
+++ b/include/cpu.hpp
@@ -17,6 +17,7 @@
 #pragma once
 #include "smbios_mdrv2.hpp"
 
+#include <xyz/openbmc_project/Association/Definitions/server.hpp>
 #include <xyz/openbmc_project/Inventory/Connector/Slot/server.hpp>
 #include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
 #include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
@@ -40,6 +41,8 @@
     sdbusplus::xyz::openbmc_project::Inventory::Connector::server::Slot;
 using processor = sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu;
 using Item = sdbusplus::xyz::openbmc_project::Inventory::server::Item;
+using association =
+    sdbusplus::xyz::openbmc_project::Association::server::Definitions;
 
 // Definition follow smbios spec DSP0134 3.0.0
 static const std::map<uint8_t, const char*> familyTable = {
@@ -98,7 +101,7 @@
 
 class Cpu :
     sdbusplus::server::object_t<processor, asset, location, connector, rev,
-                                Item>
+                                Item, association>
 {
   public:
     Cpu() = delete;
@@ -109,10 +112,11 @@
     ~Cpu() = default;
 
     Cpu(sdbusplus::bus::bus& bus, const std::string& objPath,
-        const uint8_t& cpuId, uint8_t* smbiosTableStorage) :
+        const uint8_t& cpuId, uint8_t* smbiosTableStorage,
+        const std::string& motherboard) :
         sdbusplus::server::object_t<processor, asset, location, connector, rev,
-                                    Item>(bus, objPath.c_str()),
-        cpuNum(cpuId), storage(smbiosTableStorage)
+                                    Item, association>(bus, objPath.c_str()),
+        cpuNum(cpuId), storage(smbiosTableStorage), motherboardPath(motherboard)
     {
         infoUpdate();
     }
@@ -124,6 +128,8 @@
 
     uint8_t* storage;
 
+    std::string motherboardPath;
+
     struct ProcessorInfo
     {
         uint8_t type;