PEL: MTMS class to handle the type-model and SN
This class represents the (M)achine (T)ype-(M)odel (S)erial number
structure for the PEL, where it is used in both the ExtendedUserHeader
and FailingMTMS sections.
It consists of an 8 byte machine type+model field of the form TTT-MMMM,
followed by a 12 byte machine serial number field. Unused bytes are set
to 0.
Note that this is not a PEL section itself. It's just used by other PEL
sections.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I15f9858e951a913ab2353cf93b7f20cc2709c502
diff --git a/extensions/openpower-pels/mtms.hpp b/extensions/openpower-pels/mtms.hpp
new file mode 100644
index 0000000..fe8723d
--- /dev/null
+++ b/extensions/openpower-pels/mtms.hpp
@@ -0,0 +1,128 @@
+#pragma once
+
+#include "stream.hpp"
+
+#include <string>
+
+namespace openpower
+{
+namespace pels
+{
+
+/** @class MTMS
+ *
+ * (M)achine (T)ype-(M)odel (S)erialNumber
+ *
+ * Represents the PEL's Machine Type / Model / Serial Number
+ * structure, which shows up in multiple places in a PEL.
+ *
+ * It holds 8 bytes for the Type+Model, and 12 for the SN.
+ * Unused bytes are set to 0s.
+ *
+ * The type and model are combined into a single field.
+ */
+class MTMS
+{
+ public:
+ MTMS(const MTMS&) = default;
+ MTMS& operator=(const MTMS&) = default;
+ MTMS(MTMS&&) = default;
+ MTMS& operator=(MTMS&&) = default;
+ ~MTMS() = default;
+
+ enum
+ {
+ mtmSize = 8,
+ snSize = 12
+ };
+
+ /**
+ * @brief Constructor
+ */
+ MTMS();
+
+ /**
+ * @brief Constructor
+ *
+ * @param[in] typeModel - The machine type+model
+ * @param[in] serialNumber - The machine serial number
+ */
+ MTMS(const std::string& typeModel, const std::string& serialNumber);
+
+ /**
+ * @brief Constructor
+ *
+ * Fills in this class's data fields from the stream.
+ *
+ * @param[in] pel - the PEL data stream
+ */
+ explicit MTMS(Stream& stream);
+
+ /**
+ * @brief Returns the machine type/model value
+ *
+ * @return std::array<uint8_t, mtmSize>& - The TM value
+ */
+ std::array<uint8_t, mtmSize>& machineTypeAndModel()
+ {
+ return _machineTypeAndModel;
+ }
+
+ /**
+ * @brief Returns the machine serial number value
+ *
+ * @return std::array<uint8_t, snSize>& - The SN value
+ */
+ std::array<uint8_t, snSize>& machineSerialNumber()
+ {
+ return _serialNumber;
+ }
+
+ /**
+ * @brief Returns the size of the data when flattened
+ *
+ * @return size_t - The size of the data
+ */
+ static constexpr size_t flattenedSize()
+ {
+ return mtmSize + snSize;
+ }
+
+ private:
+ /**
+ * @brief The type+model value
+ *
+ * Of the form TTTT-MMM where:
+ * TTTT = machine type
+ * MMM = machine model
+ */
+ std::array<uint8_t, mtmSize> _machineTypeAndModel;
+
+ /**
+ * @brief Machine Serial Number
+ */
+ std::array<uint8_t, snSize> _serialNumber;
+};
+
+/**
+ * @brief Stream extraction operator for MTMS
+ *
+ * @param[in] s - the stream
+ * @param[out] mtms - the MTMS object
+ *
+ * @return Stream&
+ */
+Stream& operator>>(Stream& s, MTMS& mtms);
+
+/**
+ * @brief Stream insertion operator for MTMS
+ *
+ * @param[out] s - the stream
+ * @param[in] mtms - the MTMS object
+ *
+ * @return Stream&
+ */
+Stream& operator<<(Stream& s, MTMS& mtms);
+
+} // namespace pels
+} // namespace openpower