1 #pragma once 2 3 #include <stdplus/fd/managed.hpp> 4 #include <stdplus/fd/mmap.hpp> 5 6 #include <cstdint> 7 #include <memory> 8 #include <span> 9 #include <vector> 10 11 namespace bios_bmc_smm_error_logger 12 { 13 14 /** 15 * Each data transport mechanism must implement the DataInterface. 16 */ 17 class DataInterface 18 { 19 public: 20 virtual ~DataInterface() = default; 21 22 /** 23 * Read bytes from shared buffer (blocking call). 24 * 25 * @param[in] offset - offset to read from 26 * @param[in] length - number of bytes to read 27 * @return the bytes read 28 */ 29 virtual std::vector<uint8_t> read(const uint32_t offset, 30 const uint32_t length) = 0; 31 32 /** 33 * Write bytes to shared buffer. 34 * 35 * @param[in] offset - offset to write to 36 * @param[in] bytes - byte vector of data. 37 * @return return the byte length written 38 */ 39 virtual uint32_t write(const uint32_t offset, 40 const std::span<const uint8_t> bytes) = 0; 41 42 /** 43 * Getter for Memory Region Size 44 * 45 * @return return Memory Region size allocated 46 */ 47 virtual uint32_t getMemoryRegionSize() = 0; 48 }; 49 50 /** 51 * Data handler for reading and writing data via the PCI bridge. 52 * 53 */ 54 class PciDataHandler : public DataInterface 55 { 56 public: 57 explicit PciDataHandler(uint32_t regionAddress, size_t regionSize, 58 std::unique_ptr<stdplus::fd::Fd> fd); 59 60 std::vector<uint8_t> read(uint32_t offset, uint32_t length) override; 61 uint32_t write(const uint32_t offset, 62 const std::span<const uint8_t> bytes) override; 63 uint32_t getMemoryRegionSize() override; 64 65 private: 66 uint32_t regionAddress; 67 uint32_t regionSize; 68 69 std::unique_ptr<stdplus::fd::Fd> fd; 70 stdplus::fd::MMap mmap; 71 }; 72 73 } // namespace bios_bmc_smm_error_logger 74