1 #include <iostream> 2 #include <stdexcept> 3 #include <array> 4 #include "sbe_interfaces.hpp" 5 6 namespace openpower 7 { 8 namespace sbe 9 { 10 11 //Helper interfaces 12 static inline uint32_t upper(uint64_t value) 13 { 14 return ((value & 0xFFFFFFFF00000000ull) >> 32); 15 } 16 17 static inline uint32_t lower(uint64_t value) 18 { 19 return (value & 0xFFFFFFFF); 20 } 21 22 using sbe_word_t = uint32_t; 23 24 namespace scom 25 { 26 27 //Constants specific to SCOM operations 28 static constexpr sbe_word_t READ_OPCODE = 0x0000A201; 29 static constexpr sbe_word_t WRITE_OPCODE = 0x0000A202; 30 static constexpr size_t READ_CMD_LENGTH = 0x4; 31 static constexpr size_t WRITE_CMD_LENGTH = 0x6; 32 33 //Reading SCOM Registers 34 uint64_t read(const char* devPath, 35 uint64_t address) 36 { 37 uint64_t value = 0; 38 39 //Validate input device path 40 if (devPath == nullptr) 41 { 42 throw std::runtime_error("NULL FIFO device path"); 43 } 44 45 //Build SCOM read request command 46 std::array<sbe_word_t, READ_CMD_LENGTH> command = 47 { 48 static_cast<sbe_word_t>(READ_CMD_LENGTH), 49 READ_OPCODE, 50 upper(address), 51 lower(address) 52 }; 53 54 std::cout << "Size of read command buffer:" << command.size(); 55 56 // TODO: Call an interface to read the command to the SBE FIFO and read the 57 // response from the SBE FIFO device 58 59 return value; 60 } 61 62 void write(const char* devPath, 63 uint64_t address, 64 uint64_t data) 65 { 66 //Validate input device path 67 if (devPath == nullptr) 68 { 69 throw std::runtime_error("NULL FIFO device path"); 70 } 71 72 //Build SCOM write request command 73 std::array<sbe_word_t, WRITE_CMD_LENGTH> command = 74 { 75 static_cast<sbe_word_t>(WRITE_CMD_LENGTH), 76 WRITE_OPCODE, 77 upper(address), 78 lower(address), 79 upper(data), 80 lower(data) 81 }; 82 83 std::cout << "Size of write command buffer:" << command.size(); 84 85 // TODO: Call an interface to write the command to the SBE FIFO and read the 86 // response from the SBE FIFO device 87 88 } 89 90 } // namespace scom 91 } // namespace sbe 92 } // namespace openpower 93