summaryrefslogtreecommitdiffstats
path: root/bmc/pci_handler.hpp
blob: 9b2c5b673179715090270c87e93fa39b72d6cc8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include "data_handler.hpp"
#include "internal/sys.hpp"

#include <cstdint>
#include <string>
#include <vector>

namespace ipmi_flash
{

/**
 * Data handler for reading and writing data via the P2A bridge.
 *
 * @note: Currently implemented to support only aspeed-p2a-ctrl.
 */
class PciDataHandler : public DataInterface
{
  public:
    PciDataHandler(std::uint32_t regionAddress, std::size_t regionSize,
                   const internal::Sys* sys = &internal::sys_impl) :
        regionAddress(regionAddress),
        memoryRegionSize(regionSize), sys(sys){};

    bool open() override;
    bool close() override;
    std::vector<std::uint8_t> copyFrom(std::uint32_t length) override;
    bool writeMeta(const std::vector<std::uint8_t>& configuration) override;
    std::vector<std::uint8_t> readMeta() override;

  private:
    std::uint32_t regionAddress;
    std::uint32_t memoryRegionSize;
    const internal::Sys* sys;

    int mappedFd = -1;
    std::uint8_t* mapped = nullptr;
    static const std::string p2aControlPath;
};

} // namespace ipmi_flash
OpenPOWER on IntegriCloud