Add pfr postcode feature

Add PfrPostcode object to read platformState mailbox register.
Add dbus object to PFR manager service so current platform state
value can be read by interested application like Redfish.
PfrPostcode object is added only when system is pfr provisioned.

Tested:
Manually verified dbus object properties as below -

busctl introspect xyz.openbmc_project.PFR.Manager /xyz/openbmc_project/pfr
NAME                                    TYPE      SIGNATURE  RESULT/VALUE  FLAGS
xyz.openbmc_project.State.Boot.Platform interface -          -                  -
.Data                                   property  y          14                 emits-change writable
.PlatformState                          property  s          "T0 boot complete" emits-change

Signed-off-by: Zhikui Ren <zhikui.ren@intel.com>
Change-Id: I3f3581af23c2656523ee975b2aab9ba15078c934
diff --git a/service/src/pfr_mgr.cpp b/service/src/pfr_mgr.cpp
index 2fc73fd..fc69fea 100644
--- a/service/src/pfr_mgr.cpp
+++ b/service/src/pfr_mgr.cpp
@@ -213,4 +213,83 @@
     return;
 }
 
+static constexpr const char* postcodeStrProp = "PlatformState";
+static constexpr const char* postcodeStrDefault = "Unknown";
+static constexpr const char* postcodeDataProp = "Data";
+static constexpr const char* postcodeIface =
+    "xyz.openbmc_project.State.Boot.Platform";
+
+PfrPostcode::PfrPostcode(sdbusplus::asio::object_server& srv_,
+                         std::shared_ptr<sdbusplus::asio::connection>& conn_) :
+    server(srv_),
+    conn(conn_)
+{
+    if (getPlatformState(postcode) < 0)
+    {
+        postcode = 0;
+    }
+
+    pfrPostcodeIface =
+        server.add_interface("/xyz/openbmc_project/pfr", postcodeIface);
+
+    if (pfrPostcodeIface != nullptr)
+    {
+        pfrPostcodeIface->register_property(
+            postcodeDataProp, postcode,
+            // Override set
+            [this](const uint8_t req, uint8_t& propertyValue) {
+                if (internalSet)
+                {
+                    if (req != propertyValue)
+                    {
+                        postcode = req;
+                        propertyValue = req;
+                        return 1;
+                    }
+                }
+                return 0;
+            },
+            [this](uint8_t& propertyValue) {
+                updatePostcode();
+                propertyValue = postcode;
+                return propertyValue;
+            });
+
+        pfrPostcodeIface->register_property(postcodeStrProp,
+                                            std::string(postcodeStrDefault));
+
+        pfrPostcodeIface->initialize();
+        auto it = postcodeMap.find(postcode);
+        if (it != postcodeMap.end())
+        {
+            pfrPostcodeIface->set_property(postcodeStrProp, it->second);
+        }
+    }
+}
+
+void PfrPostcode::updatePostcode()
+{
+    if (pfrPostcodeIface && pfrPostcodeIface->is_initialized())
+    {
+        if (getPlatformState(postcode) < 0)
+        {
+            postcode = 0;
+        }
+
+        internalSet = true;
+        pfrPostcodeIface->set_property(postcodeDataProp, postcode);
+        auto it = postcodeMap.find(postcode);
+        if (it == postcodeMap.end())
+        {
+            pfrPostcodeIface->set_property(postcodeStrProp, postcodeStrDefault);
+        }
+        else
+        {
+            pfrPostcodeIface->set_property(postcodeStrProp, it->second);
+        }
+        internalSet = false;
+    }
+    return;
+}
+
 } // namespace pfr