xref: /openbmc/bios-bmc-smm-error-logger/include/pci_handler.hpp (revision 1d0c3566371925317c4b7fa84795d7c69db85279)
1  #pragma once
2  
3  #include "data_interface.hpp"
4  
5  #include <stdplus/fd/managed.hpp>
6  #include <stdplus/fd/mmap.hpp>
7  
8  #include <cstdint>
9  #include <memory>
10  #include <span>
11  #include <vector>
12  
13  namespace bios_bmc_smm_error_logger
14  {
15  
16  /**
17   * Data handler for reading and writing data via the PCI bridge.
18   *
19   */
20  class PciDataHandler : public DataInterface
21  {
22    public:
23      explicit PciDataHandler(uint32_t regionAddress, size_t regionSize,
24                              std::unique_ptr<stdplus::fd::Fd> fd);
25  
26      std::vector<uint8_t> read(uint32_t offset, uint32_t length) override;
27      uint32_t write(const uint32_t offset,
28                     const std::span<const uint8_t> bytes) override;
29      uint32_t getMemoryRegionSize() override;
30  
31    private:
32      uint32_t regionAddress;
33      uint32_t regionSize;
34  
35      std::unique_ptr<stdplus::fd::Fd> fd;
36      stdplus::fd::MMap mmap;
37  };
38  
39  } // namespace bios_bmc_smm_error_logger
40