#define PCI_HDR_SIZE 256
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 43)
+#define IOMMU_FOUND() iommu_present(&pci_bus_type)
+#define IOMMU_DOMAIN_ALLOC() iommu_domain_alloc(&pci_bus_type)
+#else
+#define IOMMU_FOUND() iommu_found()
+#define IOMMU_DOMAIN_ALLOC() iommu_domain_alloc()
+#endif
+
+
static int setup_hw_pci_dev(struct host_pci_device * host_dev) {
int ret = 0;
if (flags & IORESOURCE_IO) {
bar->type = PT_BAR_IO;
} else if (flags & IORESOURCE_MEM) {
- if (flags & IORESOURCE_MEM_64) {
- struct v3_host_pci_bar * hi_bar = &(v3_dev->bars[i + 1]);
+ if ((flags & IORESOURCE_MEM_64)) {
+ // this should never happen with i==5, but it
+ // is technically an OOB access without the modulo
+ struct v3_host_pci_bar * hi_bar = &(v3_dev->bars[(i + 1) % 6]);
bar->type = PT_BAR_MEM64_LO;
/* HARDCODED for now but this will need to depend on IOMMU support detection */
- if (iommu_found()) {
+ if (IOMMU_FOUND()) {
printk("Setting host PCI device (%s) as IOMMU\n", host_dev->name);
v3_dev->iface = IOMMU;
} else {
int flags = 0;
uintptr_t gpa = 0;
- host_dev->hw_dev.iommu_domain = iommu_domain_alloc();
+ host_dev->hw_dev.iommu_domain = IOMMU_DOMAIN_ALLOC();
while (V3_get_guest_mem_region(v3_ctx, ®ion, gpa)) {