smbios-mdr: Add TPM Device Information
Type 43 of SMBIOS records defines the data structure to expose
TPM Device information. Add patch which displays the TPM Device
information on dbus.
Introduced `TPM_DBUS` meson option which will be disabled by default
When enabled, the TPM information is populated on DBUS.
Tested:
TPM information is available under dbus tree of smbios-mdr
```
:~# busctl tree xyz.openbmc_project.Smbios.MDR_V2
`- /xyz
`- /xyz/openbmc_project
|- /xyz/openbmc_project/Smbios
| `- /xyz/openbmc_project/Smbios/MDR_V2
|- /xyz/openbmc_project/inventory
| `- /xyz/openbmc_project/inventory/system
| `- /xyz/openbmc_project/inventory/system/chassis
| |- /xyz/openbmc_project/inventory/system/chassis/motherboard/bios
| `- /xyz/openbmc_project/inventory/system/chassis/motherboard/tpm
```
Change-Id: Icd42f4f043bf5a970f4829e5d318568360fe4b59
Signed-off-by: Prithvi Pai <ppai@nvidia.com>
diff --git a/include/tpm.hpp b/include/tpm.hpp
new file mode 100644
index 0000000..efa14f0
--- /dev/null
+++ b/include/tpm.hpp
@@ -0,0 +1,95 @@
+#pragma once
+#include "smbios_mdrv2.hpp"
+
+#include <sdbusplus/asio/connection.hpp>
+#include <xyz/openbmc_project/Association/Definitions/server.hpp>
+#include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
+#include <xyz/openbmc_project/Inventory/Item/Tpm/server.hpp>
+#include <xyz/openbmc_project/Inventory/Item/server.hpp>
+#include <xyz/openbmc_project/Software/Version/server.hpp>
+
+namespace phosphor
+{
+
+namespace smbios
+{
+
+using tpm = sdbusplus::server::xyz::openbmc_project::inventory::item::Tpm;
+using asset =
+ sdbusplus::server::xyz::openbmc_project::inventory::decorator::Asset;
+using Item = sdbusplus::server::xyz::openbmc_project::inventory::Item;
+using softwareversion =
+ sdbusplus::server::xyz::openbmc_project::software::Version;
+using association =
+ sdbusplus::server::xyz::openbmc_project::association::Definitions;
+
+constexpr uint8_t tpmMajorVerion1 = 0x01;
+constexpr uint8_t tpmMajorVerion2 = 0x02;
+
+class Tpm :
+ sdbusplus::server::object_t<tpm, asset, Item, association, softwareversion>
+{
+ public:
+ Tpm() = delete;
+ ~Tpm() = default;
+ Tpm(const Tpm&) = delete;
+ Tpm& operator=(const Tpm&) = delete;
+ Tpm(Tpm&&) = default;
+ Tpm& operator=(Tpm&&) = default;
+
+ Tpm(sdbusplus::bus_t& bus, const std::string& objPath, const uint8_t tpmID,
+ uint8_t* smbiosTableStorage, const std::string& motherboard) :
+ sdbusplus::server::object_t<tpm, asset, Item, association,
+ softwareversion>(bus, objPath.c_str()),
+ tpmId(tpmID), storage(smbiosTableStorage), motherboardPath(motherboard)
+ {
+ tpmInfoUpdate(smbiosTableStorage, motherboard);
+ }
+
+ void tpmInfoUpdate(uint8_t* smbiosTableStorage,
+ const std::string& motherboard);
+
+ private:
+ uint8_t tpmId;
+
+ uint8_t* storage;
+
+ std::string motherboardPath;
+ struct TPMInfo
+ {
+ uint8_t type;
+ uint8_t length;
+ uint16_t handle;
+ char vendor[4];
+ uint8_t specMajor;
+ uint8_t specMinor;
+ uint32_t firmwareVersion1;
+ uint32_t firmwareVersion2;
+ uint8_t description;
+ uint64_t characteristics;
+ uint32_t oem;
+ } __attribute__((packed));
+
+ struct TPMVersionSpec1
+ {
+ uint8_t specMajor;
+ uint8_t specMinor;
+ uint8_t revMajor;
+ uint8_t revMinor;
+ } __attribute__((packed));
+
+ struct TPMVersionSpec2
+ {
+ uint16_t revMinor;
+ uint16_t revMajor;
+ } __attribute__((packed));
+
+ void tpmVendor(const struct TPMInfo* tpmInfo);
+ void tpmFirmwareVersion(const struct TPMInfo* tpmInfo);
+ void tpmDescription(const uint8_t positionNum, const uint8_t structLen,
+ uint8_t* dataIn);
+};
+
+} // namespace smbios
+
+} // namespace phosphor