From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eduard - Gabriel Munteanu Subject: [RFC PATCH 3/7] pci: call IOMMU hooks Date: Wed, 14 Jul 2010 08:45:03 +0300 Message-ID: <1279086307-9596-4-git-send-email-eduard.munteanu@linux360.ro> References: <1279086307-9596-1-git-send-email-eduard.munteanu@linux360.ro> Cc: avi@redhat.com, paul@codesourcery.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, Eduard - Gabriel Munteanu To: joro@8bytes.org Return-path: Received: from mail-bw0-f46.google.com ([209.85.214.46]:46395 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751565Ab0GNFqf (ORCPT ); Wed, 14 Jul 2010 01:46:35 -0400 Received: by mail-bw0-f46.google.com with SMTP id 1so678994bwz.19 for ; Tue, 13 Jul 2010 22:46:34 -0700 (PDT) In-Reply-To: <1279086307-9596-1-git-send-email-eduard.munteanu@linux360.ro> Sender: kvm-owner@vger.kernel.org List-ID: Memory accesses must go through the IOMMU layer. Signed-off-by: Eduard - Gabriel Munteanu --- hw/pci.c | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 6871728..9c5d706 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -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; } -- 1.7.1