109 lines
2.5 KiB
C++
109 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
#include "Device.h"
|
|
|
|
class PCIEDevice: public Device {
|
|
|
|
public:
|
|
|
|
class VitalProductData{
|
|
public:
|
|
class ResourceType {
|
|
public:
|
|
enum class TypeName : uint8_t{
|
|
StringTag = 0x02,
|
|
VPD_R = 0x10,
|
|
VPD_W = 0x11,
|
|
End = 0x0f,
|
|
};
|
|
|
|
explicit ResourceType(const std::vector<uint8_t>& s, size_t& offset);
|
|
|
|
TypeName getName() const{
|
|
return m_name;
|
|
}
|
|
|
|
const auto& getData() const{
|
|
return m_data;
|
|
}
|
|
|
|
protected:
|
|
TypeName m_name;
|
|
std::vector<uint8_t> m_data;
|
|
};
|
|
|
|
explicit VitalProductData(const std::vector<uint8_t>& s);
|
|
|
|
private:
|
|
void fillFromEntry(const std::vector<uint8_t>& v, size_t& offset);
|
|
|
|
std::unordered_map<std::string, std::vector<uint8_t>> m_vpd;
|
|
};
|
|
|
|
class DeviceEntry{
|
|
|
|
public:
|
|
DeviceEntry(std::string path, uint16_t vendor, uint16_t _class, const std::vector<uint8_t>& vpd) : m_path(std::move(path)), m_class(_class), m_vendor(vendor), m_vpd(vpd){
|
|
|
|
}
|
|
DeviceEntry(const DeviceEntry& a) =default;
|
|
|
|
static std::vector<DeviceEntry> find();
|
|
|
|
const auto& getPath() const{
|
|
return m_path;
|
|
}
|
|
|
|
const auto& getVPD() const{
|
|
return m_vpd;
|
|
}
|
|
|
|
uint16_t getVendor() const{
|
|
return m_vendor;
|
|
}
|
|
|
|
uint16_t getClass() const{
|
|
return m_class;
|
|
}
|
|
private:
|
|
std::string m_path;
|
|
uint16_t m_vendor;
|
|
uint16_t m_class;
|
|
VitalProductData m_vpd;
|
|
};
|
|
|
|
explicit PCIEDevice(const PCIEDevice::DeviceEntry& device);
|
|
|
|
uint32_t get32(uint32_t address) const override;
|
|
volatile uint32_t* map32(uint32_t address) const override;
|
|
void set32(uint32_t address, uint32_t value) const override;
|
|
|
|
uint64_t get64(uint32_t address) const override;
|
|
void set64(uint32_t address, uint64_t value) const override;
|
|
|
|
const PCIEDevice::DeviceEntry& getDeviceEntry() const{
|
|
return m_device;
|
|
}
|
|
|
|
bool valid() const override{
|
|
return m_bar4mmap != nullptr && m_bar4Resource > 0;
|
|
}
|
|
|
|
~PCIEDevice() override;
|
|
|
|
|
|
private:
|
|
volatile uint32_t* getaddress(uint32_t address) const {
|
|
return m_bar4mmap + address;
|
|
}
|
|
int m_bar4Resource = 0;
|
|
uint32_t* m_bar4mmap = nullptr;
|
|
PCIEDevice::DeviceEntry m_device;
|
|
};
|
|
|
|
|