Nvidia-gpu: Create GPU Inventory device
GPU device class implements Item.accelerator interface to get identified
as as GPU device. This will be used in Redfish to populate the GPU
processor schema.
Tested -
```
root@gb200nvl-obmc:~# busctl introspect xyz.openbmc_project.GpuSensor /xyz/openbmc_project/inventory/NVIDIA_GB200_GPU_0
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
org.freedesktop.DBus.Introspectable interface - - -
.Introspect method - s -
org.freedesktop.DBus.Peer interface - - -
.GetMachineId method - s -
.Ping method - - -
org.freedesktop.DBus.Properties interface - - -
.Get method ss v -
.GetAll method s a{sv} -
.Set method ssv - -
.PropertiesChanged signal sa{sv}as - -
xyz.openbmc_project.Inventory.Item.Accelerator interface - - -
.Type property s "GPU" emits-change
```
Change-Id: I20434529860cb37889e63651bbcd97cadfa9d54e
Signed-off-by: Rohit PAI <ropai@nvidia.com>
diff --git a/src/nvidia-gpu/Inventory.cpp b/src/nvidia-gpu/Inventory.cpp
new file mode 100644
index 0000000..901eca1
--- /dev/null
+++ b/src/nvidia-gpu/Inventory.cpp
@@ -0,0 +1,42 @@
+#include "Inventory.hpp"
+
+#include "Utils.hpp"
+
+#include <NvidiaGpuMctpVdm.hpp>
+#include <phosphor-logging/lg2.hpp>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+
+#include <exception>
+#include <memory>
+#include <string>
+
+constexpr const char* inventoryPrefix = "/xyz/openbmc_project/inventory/";
+constexpr const char* acceleratorIfaceName =
+ "xyz.openbmc_project.Inventory.Item.Accelerator";
+
+Inventory::Inventory(
+ const std::shared_ptr<sdbusplus::asio::connection>& /*conn*/,
+ sdbusplus::asio::object_server& objectServer,
+ const std::string& inventoryName,
+ const gpu::DeviceIdentification deviceType) :
+ name(escapeName(inventoryName))
+{
+ if (deviceType == gpu::DeviceIdentification::DEVICE_GPU)
+ {
+ std::string path = inventoryPrefix + name;
+ try
+ {
+ acceleratorInterface =
+ objectServer.add_interface(path, acceleratorIfaceName);
+ acceleratorInterface->register_property("Type", std::string("GPU"));
+ acceleratorInterface->initialize();
+ }
+ catch (const std::exception& e)
+ {
+ lg2::error(
+ "Failed to add accelerator interface. path='{PATH}', error='{ERROR}'",
+ "PATH", path, "ERROR", e.what());
+ }
+ }
+}