blob: f3ae7983281416dec94da8defaef1b0d60221304 [file] [log] [blame]
#pragma once
#include "data_handler.hpp"
#include "internal/sys.hpp"
#include <cstdint>
#include <string>
#include <vector>
namespace blobs
{
/** P2A configuration response. */
struct PciConfigResponse
{
std::uint32_t address;
} __attribute__((packed));
/**
* 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 blobs