1 #pragma once
2 
3 #include "data_handler.hpp"
4 #include "internal/sys.hpp"
5 
6 #include <cstdint>
7 #include <string>
8 #include <vector>
9 
10 namespace ipmi_flash
11 {
12 
13 /**
14  * Data handler for reading and writing data via the P2A bridge.
15  *
16  * @note: Currently implemented to support only aspeed-p2a-ctrl.
17  */
18 class PciDataHandler : public DataInterface
19 {
20   public:
21     PciDataHandler(std::uint32_t regionAddress, std::size_t regionSize,
22                    const internal::Sys* sys = &internal::sys_impl) :
23         regionAddress(regionAddress),
24         memoryRegionSize(regionSize), sys(sys){};
25 
26     bool open() override;
27     bool close() override;
28     std::vector<std::uint8_t> copyFrom(std::uint32_t length) override;
29     bool writeMeta(const std::vector<std::uint8_t>& configuration) override;
30     std::vector<std::uint8_t> readMeta() override;
31 
32   private:
33     std::uint32_t regionAddress;
34     std::uint32_t memoryRegionSize;
35     const internal::Sys* sys;
36 
37     int mappedFd = -1;
38     std::uint8_t* mapped = nullptr;
39     static const std::string p2aControlPath;
40 };
41 
42 } // namespace ipmi_flash
43