blob: f3ae7983281416dec94da8defaef1b0d60221304 [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
10namespace blobs
11{
12
Patrick Venture8c535332018-11-08 15:58:00 -080013/** P2A configuration response. */
14struct PciConfigResponse
15{
16 std::uint32_t address;
17} __attribute__((packed));
18
19/**
20 * Data handler for reading and writing data via the P2A bridge.
Patrick Venture8f6fb602019-04-30 16:43:18 -070021 *
22 * @note: Currently implemented to support only aspeed-p2a-ctrl.
Patrick Venture8c535332018-11-08 15:58:00 -080023 */
Patrick Venture1cde5f92018-11-07 08:26:47 -080024class PciDataHandler : public DataInterface
25{
Patrick Venture1cde5f92018-11-07 08:26:47 -080026 public:
Patrick Venture4289e712019-04-30 17:08:50 -070027 PciDataHandler(std::uint32_t regionAddress, std::size_t regionSize,
Patrick Venture8f6fb602019-04-30 16:43:18 -070028 const internal::Sys* sys = &internal::sys_impl) :
29 regionAddress(regionAddress),
Patrick Venture4289e712019-04-30 17:08:50 -070030 memoryRegionSize(regionSize), sys(sys){};
Patrick Venture1cde5f92018-11-07 08:26:47 -080031
Patrick Venture0d2a8132018-11-09 11:34:21 -080032 bool open() override;
Patrick Venture0fbabf22018-11-09 11:54:12 -080033 bool close() override;
Patrick Venture1cde5f92018-11-07 08:26:47 -080034 std::vector<std::uint8_t> copyFrom(std::uint32_t length) override;
Patrick Venture74304642019-01-17 09:31:04 -080035 bool writeMeta(const std::vector<std::uint8_t>& configuration) override;
36 std::vector<std::uint8_t> readMeta() override;
Patrick Ventureb0c84d02018-11-09 12:00:31 -080037
38 private:
39 std::uint32_t regionAddress;
Patrick Venture4289e712019-04-30 17:08:50 -070040 std::uint32_t memoryRegionSize;
Patrick Venture8f6fb602019-04-30 16:43:18 -070041 const internal::Sys* sys;
Patrick Venture4289e712019-04-30 17:08:50 -070042
43 int mappedFd = -1;
44 std::uint8_t* mapped = nullptr;
Patrick Venturebc40c612019-04-30 16:48:19 -070045 static const std::string p2aControlPath;
Patrick Venture1cde5f92018-11-07 08:26:47 -080046};
47
48} // namespace blobs