Add interfaces for PCI host and PCI device.

This commit is contained in:
Maxim Poliakovski 2019-08-23 23:30:33 +02:00
parent 2f06623c62
commit 78e8b06cf1
2 changed files with 49 additions and 0 deletions

34
devices/pcidevice.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef PCI_DEVICE_H
#define PCI_DEVICE_H
#include <cinttypes>
#include <string>
#include "mmiodevice.h"
#include "pcihost.h"
/* convert little-endian DWORD to big-endian DWORD */
#define LE2BE(x) (x >> 24) | ((x & 0x00FF0000) >> 8) | ((x & 0x0000FF00) << 8) | (x << 24)
enum {
CFG_REG_BAR0 = 0x10 // base address register 0
};
class PCIDevice : public MMIODevice {
public:
PCIDevice(std::string name) {this->name = name;};
virtual ~PCIDevice() = default;
/* configuration space access methods */
virtual uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size) = 0;
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) = 0;
virtual void set_host(PCIHost *host_instance) = 0;
protected:
std::string name; // human-readable device name
PCIHost *host_instance; // host bridge instance to call back
uint32_t base_addr; // base address register 0
};
#endif /* PCI_DEVICE_H */

15
devices/pcihost.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef PCI_HOST_H
#define PCI_HOST_H
#include <cinttypes>
class PCIDevice; // forward declaration to prevent errors
class PCIHost {
public:
virtual bool pci_register_device(int dev_num, PCIDevice *dev_instance) = 0;
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size,
PCIDevice *obj) = 0;
};
#endif /* PCI_HOST_H */