Implement interfaces for read and write of SCOM registers
Changes include:
- Validation of input parameters
- Building the SBE command request as per the SBE specification
Change-Id: Iad0b075ea53842c0f0de123352b04096b52de9e5
Signed-off-by: Murulidhar Nataraju <murulidhar@in.ibm.com>
diff --git a/sbe_interfaces.cpp b/sbe_interfaces.cpp
new file mode 100755
index 0000000..8e63b53
--- /dev/null
+++ b/sbe_interfaces.cpp
@@ -0,0 +1,92 @@
+#include <iostream>
+#include <stdexcept>
+#include <array>
+#include "sbe_interfaces.hpp"
+
+namespace openpower
+{
+namespace sbe
+{
+
+//Helper interfaces
+static inline uint32_t upper(uint64_t value)
+{
+ return ((value & 0xFFFFFFFF00000000ull) >> 32);
+}
+
+static inline uint32_t lower(uint64_t value)
+{
+ return (value & 0xFFFFFFFF);
+}
+
+using sbe_word_t = uint32_t;
+
+namespace scom
+{
+
+//Constants specific to SCOM operations
+static constexpr sbe_word_t READ_OPCODE = 0x0000A201;
+static constexpr sbe_word_t WRITE_OPCODE = 0x0000A202;
+static constexpr size_t READ_CMD_LENGTH = 0x4;
+static constexpr size_t WRITE_CMD_LENGTH = 0x6;
+
+//Reading SCOM Registers
+uint64_t read(const char* devPath,
+ uint64_t address)
+{
+ uint64_t value = 0;
+
+ //Validate input device path
+ if (devPath == nullptr)
+ {
+ throw std::runtime_error("NULL FIFO device path");
+ }
+
+ //Build SCOM read request command
+ std::array<sbe_word_t, READ_CMD_LENGTH> command =
+ {
+ static_cast<sbe_word_t>(READ_CMD_LENGTH),
+ READ_OPCODE,
+ upper(address),
+ lower(address)
+ };
+
+ std::cout << "Size of read command buffer:" << command.size();
+
+ // TODO: Call an interface to read the command to the SBE FIFO and read the
+ // response from the SBE FIFO device
+
+ return value;
+}
+
+void write(const char* devPath,
+ uint64_t address,
+ uint64_t data)
+{
+ //Validate input device path
+ if (devPath == nullptr)
+ {
+ throw std::runtime_error("NULL FIFO device path");
+ }
+
+ //Build SCOM write request command
+ std::array<sbe_word_t, WRITE_CMD_LENGTH> command =
+ {
+ static_cast<sbe_word_t>(WRITE_CMD_LENGTH),
+ WRITE_OPCODE,
+ upper(address),
+ lower(address),
+ upper(data),
+ lower(data)
+ };
+
+ std::cout << "Size of write command buffer:" << command.size();
+
+ // TODO: Call an interface to write the command to the SBE FIFO and read the
+ // response from the SBE FIFO device
+
+}
+
+} // namespace scom
+} // namespace sbe
+} // namespace openpower