blob: 9b2c5b673179715090270c87e93fa39b72d6cc8c [file] [log] [blame]
Patrick Venture1cde5f92018-11-07 08:26:47 -08001#pragma once
2
3#include "data_handler.hpp"
Patrick Venture8f6fb602019-04-30 16:43:18 -07004#include "internal/sys.hpp"
Patrick Venture1cde5f92018-11-07 08:26:47 -08005
6#include <cstdint>
Patrick Venturebc40c612019-04-30 16:48:19 -07007#include <string>
Patrick Venture1cde5f92018-11-07 08:26:47 -08008#include <vector>
9
Patrick Venture1d5a31c2019-05-20 11:38:22 -070010namespace ipmi_flash
Patrick Venture1cde5f92018-11-07 08:26:47 -080011{
12
Patrick Venture8c535332018-11-08 15:58:00 -080013/**
14 * Data handler for reading and writing data via the P2A bridge.
Patrick Venture8f6fb602019-04-30 16:43:18 -070015 *
16 * @note: Currently implemented to support only aspeed-p2a-ctrl.
Patrick Venture8c535332018-11-08 15:58:00 -080017 */
Patrick Venture1cde5f92018-11-07 08:26:47 -080018class PciDataHandler : public DataInterface
19{
Patrick Venture1cde5f92018-11-07 08:26:47 -080020 public:
Patrick Venture4289e712019-04-30 17:08:50 -070021 PciDataHandler(std::uint32_t regionAddress, std::size_t regionSize,
Patrick Venture8f6fb602019-04-30 16:43:18 -070022 const internal::Sys* sys = &internal::sys_impl) :
23 regionAddress(regionAddress),
Patrick Venture4289e712019-04-30 17:08:50 -070024 memoryRegionSize(regionSize), sys(sys){};
Patrick Venture1cde5f92018-11-07 08:26:47 -080025
Patrick Venture0d2a8132018-11-09 11:34:21 -080026 bool open() override;
Patrick Venture0fbabf22018-11-09 11:54:12 -080027 bool close() override;
Patrick Venture1cde5f92018-11-07 08:26:47 -080028 std::vector<std::uint8_t> copyFrom(std::uint32_t length) override;
Patrick Venture74304642019-01-17 09:31:04 -080029 bool writeMeta(const std::vector<std::uint8_t>& configuration) override;
30 std::vector<std::uint8_t> readMeta() override;
Patrick Ventureb0c84d02018-11-09 12:00:31 -080031
32 private:
33 std::uint32_t regionAddress;
Patrick Venture4289e712019-04-30 17:08:50 -070034 std::uint32_t memoryRegionSize;
Patrick Venture8f6fb602019-04-30 16:43:18 -070035 const internal::Sys* sys;
Patrick Venture4289e712019-04-30 17:08:50 -070036
37 int mappedFd = -1;
38 std::uint8_t* mapped = nullptr;
Patrick Venturebc40c612019-04-30 16:48:19 -070039 static const std::string p2aControlPath;
Patrick Venture1cde5f92018-11-07 08:26:47 -080040};
41
Patrick Venture1d5a31c2019-05-20 11:38:22 -070042} // namespace ipmi_flash