blob: 8e63b5322055b8a9637775cd31f023cc31814f27 [file] [log] [blame]
Murulidhar Nataraju207bed42017-03-31 07:38:55 -05001#include <iostream>
2#include <stdexcept>
3#include <array>
4#include "sbe_interfaces.hpp"
5
6namespace openpower
7{
8namespace sbe
9{
10
11//Helper interfaces
12static inline uint32_t upper(uint64_t value)
13{
14 return ((value & 0xFFFFFFFF00000000ull) >> 32);
15}
16
17static inline uint32_t lower(uint64_t value)
18{
19 return (value & 0xFFFFFFFF);
20}
21
22using sbe_word_t = uint32_t;
23
24namespace scom
25{
26
27//Constants specific to SCOM operations
28static constexpr sbe_word_t READ_OPCODE = 0x0000A201;
29static constexpr sbe_word_t WRITE_OPCODE = 0x0000A202;
30static constexpr size_t READ_CMD_LENGTH = 0x4;
31static constexpr size_t WRITE_CMD_LENGTH = 0x6;
32
33//Reading SCOM Registers
34uint64_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
62void 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