Move PPIN to UniqueIdentifier

The PPIN should be published in Redfish as the
ProtectedIdentificationNumber property rather than SerialNumber. So we
will publish the new UniqueIdentifier D-Bus interface from cpuinfoapp,
rather than modifying the Asset interface served by smbios-mdrv2.

Tested:
Wait for BIOS to finish and check D-Bus property:
$ busctl get-property xyz.openbmc_project.CPUInfo \
    /xyz/openbmc_project/inventory/system/chassis/motherboard/cpu0 \
    xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier \
    UniqueIdentifier
s "8a8b34a8abcd76a"

Signed-off-by: Jonathan Doman <jonathan.doman@intel.com>
Change-Id: Ib65f373f3b7a253a458701d9faf10cdb4cddbb07
diff --git a/include/cpuinfo.hpp b/include/cpuinfo.hpp
index f7dd21b..ac26c60 100644
--- a/include/cpuinfo.hpp
+++ b/include/cpuinfo.hpp
@@ -17,7 +17,9 @@
 #pragma once
 
 #include <sdbusplus/asio/object_server.hpp>
+#include <sdbusplus/server/object.hpp>
 #include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
+#include <xyz/openbmc_project/Inventory/Decorator/UniqueIdentifier/server.hpp>
 
 namespace cpu_info
 {
@@ -35,13 +37,21 @@
     sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu;
 */
 
-// This will be expanded to CPUInfo object_server in a future patch
-struct CPUInfo
+using UniqueIdentifierBase =
+    sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
+                                    Decorator::server::UniqueIdentifier>;
+
+struct CPUInfo : public UniqueIdentifierBase
 {
-    CPUInfo(const size_t cpuId, const uint8_t peciAddress,
-            const uint8_t i2cBusNum, const uint8_t i2cSlaveAddress) :
-        id(cpuId),
-        peciAddr(peciAddress), i2cBus(i2cBusNum), i2cDevice(i2cSlaveAddress)
+    CPUInfo(sdbusplus::bus::bus& bus, const size_t cpuId,
+            const uint8_t peciAddress, const uint8_t i2cBusNum,
+            const uint8_t i2cSlaveAddress) :
+        // use defer_emit for UniqueIdentifier iface so that ObjectMapper
+        // doesn't find it until we have a valid PPIN
+        UniqueIdentifierBase(bus, (cpuPath + std::to_string(cpuId - 1)).c_str(),
+                             action::defer_emit),
+        id(cpuId), peciAddr(peciAddress), i2cBus(i2cBusNum),
+        i2cDevice(i2cSlaveAddress)
     {}
 
     uint8_t id;
diff --git a/src/cpuinfo_main.cpp b/src/cpuinfo_main.cpp
index cc5e772..6e44d71 100644
--- a/src/cpuinfo_main.cpp
+++ b/src/cpuinfo_main.cpp
@@ -448,9 +448,10 @@
                 std::stringstream stream;
                 stream << std::hex << cpuPPIN;
                 std::string serialNumber(stream.str());
-                // cpuInfo->serialNumber(serialNumber);
-                setCpuProperty(conn, cpu, assetInterfaceName, "SerialNumber",
-                               serialNumber);
+                cpuInfo->uniqueIdentifier(serialNumber);
+                // Signal that the iface is added now so that ObjectMapper and
+                // others can find it.
+                cpuInfo->emit_added();
             }
 
             tryReadSSpec(conn, cpuInfo);
@@ -538,8 +539,8 @@
                     i2cDevice = defaultI2cSlaveAddr0 + cpu - 1;
                 }
                 cpuInfoMap.insert_or_assign(
-                    cpu, std::make_shared<CPUInfo>(cpu, peciAddress, i2cBus,
-                                                   i2cDevice));
+                    cpu, std::make_shared<CPUInfo>(*conn, cpu, peciAddress,
+                                                   i2cBus, i2cDevice));
 
                 getProcessorInfo(io, conn, cpu);
             }