From patchwork Wed Jul 14 05:45:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard - Gabriel Munteanu X-Patchwork-Id: 58847 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C84681007D1 for ; Wed, 14 Jul 2010 15:55:57 +1000 (EST) Received: from localhost ([127.0.0.1]:41517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OYuwk-0003uN-Rm for incoming@patchwork.ozlabs.org; Wed, 14 Jul 2010 01:55:54 -0400 Received: from [140.186.70.92] (port=39886 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OYunv-00089Q-BN for qemu-devel@nongnu.org; Wed, 14 Jul 2010 01:46:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OYunt-0008OL-49 for qemu-devel@nongnu.org; Wed, 14 Jul 2010 01:46:47 -0400 Received: from mail-bw0-f45.google.com ([209.85.214.45]:39612) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OYuns-0008Nv-Pz for qemu-devel@nongnu.org; Wed, 14 Jul 2010 01:46:45 -0400 Received: by bwz19 with SMTP id 19so541031bwz.4 for ; Tue, 13 Jul 2010 22:46:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:cc:subject :date:message-id:x-mailer:in-reply-to:references; bh=qa5Q6S5Y6aPgr3qKInk0G36jQF+IBYScTfoGOcTHDGE=; b=lanCsoWHohbwU9vQa6jRzwAlXF8rQsbIUIM72znnpD1xN5wwG0aqlRrMoWNTnuFgTl hKGnv/oxmYnvIykFSX2MmYWG0Sk/aM32T8ftYMmOsqTOf9bLAJasfJn4ZX3hUhoNVvrb JByKQEetpH/Pe+aYq0eupF7Jr6r4Ufj+zmUEM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=EKD4PkhHwAwfZgWMqDn1k3STnrXeVnTI4qxnoS54GsuB8EweDRibgY+r4N3p8Y79o9 F8XxlaIikBWfI7Fu1LgEITLBr8EuIRGJwahS7UvJmL2qDlKH/ynph4oqHYJa3EJ7DEr4 IltXj4J4hE3LsRivlVjUXQgHq2HTDuw/RdWPo= Received: by 10.204.163.17 with SMTP id y17mr12794146bkx.64.1279086394206; Tue, 13 Jul 2010 22:46:34 -0700 (PDT) Received: from localhost ([188.25.93.67]) by mx.google.com with ESMTPS id g11sm29670898bkw.22.2010.07.13.22.46.33 (version=SSLv3 cipher=RC4-MD5); Tue, 13 Jul 2010 22:46:33 -0700 (PDT) From: Eduard - Gabriel Munteanu To: joro@8bytes.org Date: Wed, 14 Jul 2010 08:45:03 +0300 Message-Id: <1279086307-9596-4-git-send-email-eduard.munteanu@linux360.ro> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1279086307-9596-1-git-send-email-eduard.munteanu@linux360.ro> References: <1279086307-9596-1-git-send-email-eduard.munteanu@linux360.ro> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: qemu-devel@nongnu.org, Eduard - Gabriel Munteanu , avi@redhat.com, kvm@vger.kernel.org, paul@codesourcery.com Subject: [Qemu-devel] [RFC PATCH 3/7] pci: call IOMMU hooks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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; }