From 78e8b06cf125bfbcab1a3b8c35ab7177d9c4c399 Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Fri, 23 Aug 2019 23:30:33 +0200 Subject: [PATCH] Add interfaces for PCI host and PCI device. --- devices/pcidevice.h | 34 ++++++++++++++++++++++++++++++++++ devices/pcihost.h | 15 +++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 devices/pcidevice.h create mode 100644 devices/pcihost.h diff --git a/devices/pcidevice.h b/devices/pcidevice.h new file mode 100644 index 0000000..e1985a6 --- /dev/null +++ b/devices/pcidevice.h @@ -0,0 +1,34 @@ +#ifndef PCI_DEVICE_H +#define PCI_DEVICE_H + +#include +#include +#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 */ diff --git a/devices/pcihost.h b/devices/pcihost.h new file mode 100644 index 0000000..acd3d1f --- /dev/null +++ b/devices/pcihost.h @@ -0,0 +1,15 @@ +#ifndef PCI_HOST_H +#define PCI_HOST_H + +#include + +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 */