Adding CPUCore interface support
This commit introduces essential D-Bus infrastructure support for
hosting the `Item.CPUCore` D-Bus object. Additionally, it includes
getter and setter functions to enable get/set properties within the
`CPUCore` interface, such as core count and microcode.
Testing:
Unit test passed
Change-Id: I728522b34e96ee7d6609efb5746b40cf923812e8
Signed-off-by: Kamalkumar Patel <kamalkumar.patel@ibm.com>
diff --git a/host-bmc/dbus/cpu_core.cpp b/host-bmc/dbus/cpu_core.cpp
new file mode 100644
index 0000000..91531ed
--- /dev/null
+++ b/host-bmc/dbus/cpu_core.cpp
@@ -0,0 +1,21 @@
+#include "cpu_core.hpp"
+
+namespace pldm
+{
+namespace dbus
+{
+
+uint32_t CPUCore::microcode() const
+{
+ return sdbusplus::xyz::openbmc_project::Inventory::Item::server::CpuCore::
+ microcode();
+}
+
+uint32_t CPUCore::microcode(uint32_t value)
+{
+ return sdbusplus::xyz::openbmc_project::Inventory::Item::server::CpuCore::
+ microcode(value);
+}
+
+} // namespace dbus
+} // namespace pldm
diff --git a/host-bmc/dbus/cpu_core.hpp b/host-bmc/dbus/cpu_core.hpp
new file mode 100644
index 0000000..3a58529
--- /dev/null
+++ b/host-bmc/dbus/cpu_core.hpp
@@ -0,0 +1,39 @@
+#pragma once
+
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/server.hpp>
+#include <sdbusplus/server/object.hpp>
+#include <xyz/openbmc_project/Inventory/Item/CpuCore/server.hpp>
+
+#include <string>
+
+namespace pldm
+{
+namespace dbus
+{
+using CoreIntf = sdbusplus::server::object_t<
+ sdbusplus::xyz::openbmc_project::Inventory::Item::server::CpuCore>;
+
+class CPUCore : public CoreIntf
+{
+ public:
+ CPUCore() = delete;
+ ~CPUCore() = default;
+ CPUCore(const CPUCore&) = delete;
+ CPUCore& operator=(const CPUCore&) = delete;
+ CPUCore(CPUCore&&) = default;
+ CPUCore& operator=(CPUCore&&) = default;
+
+ CPUCore(sdbusplus::bus_t& bus, const std::string& objPath) :
+ CoreIntf(bus, objPath.c_str())
+ {}
+
+ /** Get value of Microcode */
+ uint32_t microcode() const override;
+
+ /** Set value of Microcode */
+ uint32_t microcode(uint32_t value) override;
+};
+
+} // namespace dbus
+} // namespace pldm
diff --git a/host-bmc/dbus/custom_dbus.cpp b/host-bmc/dbus/custom_dbus.cpp
index 6427a93..435d574 100644
--- a/host-bmc/dbus/custom_dbus.cpp
+++ b/host-bmc/dbus/custom_dbus.cpp
@@ -27,5 +27,33 @@
return std::nullopt;
}
+void CustomDBus::implementCpuCoreInterface(const std::string& path)
+{
+ if (!cpuCore.contains(path))
+ {
+ cpuCore.emplace(path, std::make_unique<CPUCore>(
+ pldm::utils::DBusHandler::getBus(), path));
+ }
+}
+
+void CustomDBus::setMicroCode(const std::string& path, uint32_t value)
+{
+ if (!cpuCore.contains(path))
+ {
+ cpuCore.emplace(path, std::make_unique<CPUCore>(
+ pldm::utils::DBusHandler::getBus(), path));
+ }
+ cpuCore.at(path)->microcode(value);
+}
+
+std::optional<uint32_t> CustomDBus::getMicroCode(const std::string& path) const
+{
+ if (cpuCore.contains(path))
+ {
+ return cpuCore.at(path)->microcode();
+ }
+
+ return std::nullopt;
+}
} // namespace dbus
} // namespace pldm
diff --git a/host-bmc/dbus/custom_dbus.hpp b/host-bmc/dbus/custom_dbus.hpp
index a320641..c8307c6 100644
--- a/host-bmc/dbus/custom_dbus.hpp
+++ b/host-bmc/dbus/custom_dbus.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "common/utils.hpp"
+#include "cpu_core.hpp"
#include <sdbusplus/server.hpp>
#include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
@@ -53,15 +54,37 @@
/** @brief Get the LocationCode property
*
- * @param[in] path - The object path
+ * @param[in] path - The object path
*
* @return std::optional<std::string> - The value of the LocationCode
* property
*/
std::optional<std::string> getLocationCode(const std::string& path) const;
+ /** @brief Implement CpuCore Interface
+ *
+ * @param[in] path - The object path
+ *
+ */
+ void implementCpuCoreInterface(const std::string& path);
+ /** @brief Set the microcode property
+ *
+ * @param[in] path - The object path
+ *
+ * @param[in] value - microcode value
+ */
+ void setMicroCode(const std::string& path, uint32_t value);
+
+ /** @brief Get the microcode property
+ *
+ * @param[in] path - The object path
+ *
+ * @return std::optional<uint32_t> - The value of the microcode value
+ */
+ std::optional<uint32_t> getMicroCode(const std::string& path) const;
private:
std::unordered_map<ObjectPath, std::unique_ptr<LocationIntf>> location;
+ std::unordered_map<ObjectPath, std::unique_ptr<CPUCore>> cpuCore;
};
} // namespace dbus
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index 955736c..1580956 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -1118,7 +1118,17 @@
void HostPDRHandler::createDbusObjects(const PDRList& fruRecordSetPDRs)
{
// TODO: Creating and Refreshing dbus hosted by remote PLDM entity Fru PDRs
-
+ for (const auto& entity : objPathMap)
+ {
+ pldm_entity node = pldm_entity_extract(entity.second);
+ switch (node.entity_type)
+ {
+ case PLDM_ENTITY_PROC | 0x8000:
+ CustomDBus::getCustomDBus().implementCpuCoreInterface(
+ entity.first);
+ break;
+ }
+ }
getFRURecordTableMetadataByRemote(fruRecordSetPDRs);
}
diff --git a/host-bmc/test/custom_dbus_test.cpp b/host-bmc/test/custom_dbus_test.cpp
index be23924..cce0a92 100644
--- a/host-bmc/test/custom_dbus_test.cpp
+++ b/host-bmc/test/custom_dbus_test.cpp
@@ -14,3 +14,15 @@
EXPECT_NE(retLocationCode, std::nullopt);
EXPECT_EQ(locationCode, retLocationCode);
}
+
+TEST(CustomDBus, MicroCode)
+{
+ std::string tmpPath = "/abc/def";
+ uint32_t value = 32;
+
+ CustomDBus::getCustomDBus().setMicroCode(tmpPath, value);
+ auto retMicroCode = CustomDBus::getCustomDBus().getMicroCode(tmpPath);
+
+ EXPECT_NE(retMicroCode, std::nullopt);
+ EXPECT_EQ(value, retMicroCode);
+}
diff --git a/host-bmc/test/meson.build b/host-bmc/test/meson.build
index d102ff7..f994552 100644
--- a/host-bmc/test/meson.build
+++ b/host-bmc/test/meson.build
@@ -6,6 +6,7 @@
'../../common/utils.cpp',
'../utils.cpp',
'../dbus/custom_dbus.cpp',
+ '../dbus/cpu_core.cpp',
]
tests = [