blob: 848760cdd7dbb605186c470a532889a797304f0c [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) :
Patrick Williams42a44c22024-08-16 15:21:32 -040023 regionAddress(regionAddress), memoryRegionSize(regionSize), sys(sys) {};
Patrick Venture1cde5f92018-11-07 08:26:47 -080024
Patrick Venture0d2a8132018-11-09 11:34:21 -080025 bool open() override;
Patrick Venture0fbabf22018-11-09 11:54:12 -080026 bool close() override;
Patrick Venture1cde5f92018-11-07 08:26:47 -080027 std::vector<std::uint8_t> copyFrom(std::uint32_t length) override;
Patrick Venture74304642019-01-17 09:31:04 -080028 bool writeMeta(const std::vector<std::uint8_t>& configuration) override;
29 std::vector<std::uint8_t> readMeta() override;
Patrick Ventureb0c84d02018-11-09 12:00:31 -080030
31 private:
32 std::uint32_t regionAddress;
Patrick Venture4289e712019-04-30 17:08:50 -070033 std::uint32_t memoryRegionSize;
Patrick Venture8f6fb602019-04-30 16:43:18 -070034 const internal::Sys* sys;
Patrick Venture4289e712019-04-30 17:08:50 -070035
36 int mappedFd = -1;
37 std::uint8_t* mapped = nullptr;
Patrick Venturebc40c612019-04-30 16:48:19 -070038 static const std::string p2aControlPath;
Patrick Venture1cde5f92018-11-07 08:26:47 -080039};
40
Patrick Venture1d5a31c2019-05-20 11:38:22 -070041} // namespace ipmi_flash