initial commit of source materials
Initial commit of source materials packaged into separate repository.
Change-Id: I94f416202b1f45813d3f3984c3b8dc81410b59ff
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/i2c.hpp b/i2c.hpp
new file mode 100644
index 0000000..105dfbe
--- /dev/null
+++ b/i2c.hpp
@@ -0,0 +1,74 @@
+#pragma once
+
+#include <host-ipmid/ipmid-api.h>
+
+#include <cstdint>
+#include <host-ipmid/oemrouter.hpp>
+
+using std::uint8_t;
+
+namespace oem
+{
+namespace i2c
+{
+/*
+ * Request header
+ */
+constexpr size_t requestHeaderBus = 0;
+constexpr size_t requestHeaderFlags = 1;
+constexpr size_t requestHeaderLen = 2;
+
+typedef uint8_t BusId;
+typedef uint8_t ReqFlags;
+
+constexpr ReqFlags requestFlagsUsePec = (1 << 7);
+
+/*
+ * Request step.
+ */
+constexpr size_t stepHeaderDevAndDir = 0;
+constexpr size_t stepHeaderFlags = 1;
+constexpr size_t stepHeaderParm = 2;
+constexpr size_t stepHeaderLen = 3;
+
+typedef uint8_t DevAddr;
+typedef uint8_t StepFlags;
+constexpr StepFlags stepFlagsRecvLen = (1 << 7);
+constexpr StepFlags stepFlagsNoStart = (1 << 6);
+
+// So far 2 steps suffics, so 4 should be safe.
+constexpr size_t maxSteps = 4;
+
+// Currently we specify 32 byte payload limit;
+// but for block read with PEC that entails 34 total bytes.
+constexpr size_t largestReply = 34;
+
+} // namespace i2c
+
+/**
+ * I2c is a global i2c-via-ipmi manager and IPMI handler.
+ */
+class I2c
+{
+ public:
+ /**
+ * Allows specification of the mechanism to register OEM IPMI handler.
+ *
+ * @param[in] oemRouter - A pointer to a router instance.
+ */
+ void registerWith(Router* oemRouter);
+
+ /**
+ * The i2c-via-ipmi commands go through this method.
+ *
+ * @param[in] cmd - the IPMI command.
+ * @param[in] reqBuf - the IPMI command buffer.
+ * @param[in,out] replyBuf - the IPMI response buffer.
+ * @param[in,out] dataLen - pointer to request length, set to reply length.
+ * @return IPMI return code.
+ */
+ ipmi_ret_t transfer(ipmi_cmd_t cmd, const uint8_t* reqBuf,
+ uint8_t* replyBuf, size_t* dataLen);
+};
+
+} // namespace oem