@@ -22,6 +22,7 @@
* THE SOFTWARE.
*/
#include "hw.h"
+#include "iommu.h"
#include "pci.h"
#include "monitor.h"
#include "net.h"
@@ -733,12 +734,25 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)
pci_config_free(pci_dev);
}
+#ifdef CONFIG_IOMMU
+static inline int pci_iommu_register_device(PCIBus *bus, PCIDevice *dev)
+{
+ return iommu_register_device(bus->qbus.iommu, &dev->qdev);
+}
+#else
+static inline int pci_iommu_register_device(PCIBus *bus, PCIDevice *dev)
+{
+ return 0;
+}
+#endif
+
PCIDevice *pci_register_device(PCIBus *bus, const char *name,
int instance_size, int devfn,
PCIConfigReadFunc *config_read,
PCIConfigWriteFunc *config_write)
{
PCIDevice *pci_dev;
+ int err;
pci_dev = qemu_mallocz(instance_size);
pci_dev = do_pci_register_device(pci_dev, bus, name, devfn,
@@ -747,6 +761,13 @@ PCIDevice *pci_register_device(PCIBus *bus, const char *name,
if (pci_dev == NULL) {
hw_error("PCI: can't register device\n");
}
+
+ err = pci_iommu_register_device(bus, pci_dev);
+ if (err) {
+ hw_error("PCI: can't register device with IOMMU\n");
+ return NULL;
+ }
+
return pci_dev;
}