From patchwork Wed Sep 7 15:41:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 1127622 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p87GcMRG032043 for ; Wed, 7 Sep 2011 16:38:22 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751923Ab1IGQ3P (ORCPT ); Wed, 7 Sep 2011 12:29:15 -0400 Received: from va3ehsobe004.messaging.microsoft.com ([216.32.180.14]:52632 "EHLO VA3EHSOBE004.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751765Ab1IGQ3K (ORCPT ); Wed, 7 Sep 2011 12:29:10 -0400 Received: from mail62-va3-R.bigfish.com (10.7.14.240) by VA3EHSOBE004.bigfish.com (10.7.40.24) with Microsoft SMTP Server id 14.1.225.22; Wed, 7 Sep 2011 15:42:10 +0000 Received: from mail62-va3 (localhost.localdomain [127.0.0.1]) by mail62-va3-R.bigfish.com (Postfix) with ESMTP id 559531B0812D; Wed, 7 Sep 2011 15:42:10 +0000 (UTC) X-SpamScore: 1 X-BigFish: VPS1(zzzz1202hzz8275bhz32i668h839h61h) X-Spam-TCS-SCL: 0:0 X-Forefront-Antispam-Report: CIP:163.181.249.108; KIP:(null); UIP:(null); IPVD:NLI; H:ausb3twp01.amd.com; RD:none; EFVD:NLI Received: from mail62-va3 (localhost.localdomain [127.0.0.1]) by mail62-va3 (MessageSwitch) id 131541013019881_11796; Wed, 7 Sep 2011 15:42:10 +0000 (UTC) Received: from VA3EHSMHS019.bigfish.com (unknown [10.7.14.235]) by mail62-va3.bigfish.com (Postfix) with ESMTP id EB90E1408055; Wed, 7 Sep 2011 15:42:09 +0000 (UTC) Received: from ausb3twp01.amd.com (163.181.249.108) by VA3EHSMHS019.bigfish.com (10.7.99.29) with Microsoft SMTP Server id 14.1.225.22; Wed, 7 Sep 2011 15:42:04 +0000 X-WSS-ID: 0LR5SY1-01-4FL-02 X-M-MSG: Received: from sausexedgep02.amd.com (sausexedgep02-ext.amd.com [163.181.249.73]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ausb3twp01.amd.com (Axway MailGate 3.8.1) with ESMTP id 2BA40102808D; Wed, 7 Sep 2011 10:42:00 -0500 (CDT) Received: from sausexhtp02.amd.com (163.181.3.152) by sausexedgep02.amd.com (163.181.36.59) with Microsoft SMTP Server (TLS) id 8.3.106.1; Wed, 7 Sep 2011 10:43:00 -0500 Received: from storexhtp01.amd.com (172.24.4.3) by sausexhtp02.amd.com (163.181.3.152) with Microsoft SMTP Server (TLS) id 8.3.83.0; Wed, 7 Sep 2011 10:42:01 -0500 Received: from gwo.osrc.amd.com (165.204.16.204) by storexhtp01.amd.com (172.24.4.3) with Microsoft SMTP Server id 8.3.83.0; Wed, 7 Sep 2011 11:41:57 -0400 Received: from lemmy.osrc.amd.com (lemmy.osrc.amd.com [165.204.15.93]) by gwo.osrc.amd.com (Postfix) with ESMTP id DCDD049C627; Wed, 7 Sep 2011 16:41:55 +0100 (BST) Received: by lemmy.osrc.amd.com (Postfix, from userid 1000) id CF3C6FF9CE; Wed, 7 Sep 2011 17:41:55 +0200 (CEST) From: Joerg Roedel To: CC: Greg Kroah-Hartman , Alex Williamson , Ohad Ben-Cohen , David Woodhouse , David Brown , , , , Joerg Roedel Subject: [PATCH 05/10] iommu/core: Use bus->iommu_ops in the iommu-api Date: Wed, 7 Sep 2011 17:41:48 +0200 Message-ID: <1315410113-26608-6-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1315410113-26608-1-git-send-email-joerg.roedel@amd.com> References: <1315410113-26608-1-git-send-email-joerg.roedel@amd.com> MIME-Version: 1.0 X-OriginatorOrg: amd.com Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 07 Sep 2011 16:38:22 +0000 (UTC) Use the per-bus iommu-ops in the functions of the iommu-api instead of the global iommu_ops. Signed-off-by: Joerg Roedel --- drivers/iommu/iommu.c | 34 +++++++++++++++++++++++++++------- 1 files changed, 27 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 2270127..f2ced4c 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -83,34 +83,48 @@ EXPORT_SYMBOL_GPL(iommu_domain_alloc); void iommu_domain_free(struct iommu_domain *domain) { - iommu_ops->domain_destroy(domain); + if (likely(domain->ops->domain_destroy != NULL)) + domain->ops->domain_destroy(domain); + kfree(domain); } EXPORT_SYMBOL_GPL(iommu_domain_free); int iommu_attach_device(struct iommu_domain *domain, struct device *dev) { - return iommu_ops->attach_dev(domain, dev); + if (unlikely(domain->ops->attach_dev == NULL)) + return -ENODEV; + + return domain->ops->attach_dev(domain, dev); } EXPORT_SYMBOL_GPL(iommu_attach_device); void iommu_detach_device(struct iommu_domain *domain, struct device *dev) { - iommu_ops->detach_dev(domain, dev); + if (unlikely(domain->ops->detach_dev == NULL)) + return; + + domain->ops->detach_dev(domain, dev); } EXPORT_SYMBOL_GPL(iommu_detach_device); phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, unsigned long iova) { - return iommu_ops->iova_to_phys(domain, iova); + if (unlikely(domain->ops->iova_to_phys == NULL)) + return 0; + + return domain->ops->iova_to_phys(domain, iova); } EXPORT_SYMBOL_GPL(iommu_iova_to_phys); int iommu_domain_has_cap(struct iommu_domain *domain, unsigned long cap) { - return iommu_ops->domain_has_cap(domain, cap); + if (unlikely(domain->ops->domain_has_cap == NULL)) + return 0; + + return domain->ops->domain_has_cap(domain, cap); } EXPORT_SYMBOL_GPL(iommu_domain_has_cap); @@ -119,11 +133,14 @@ int iommu_map(struct iommu_domain *domain, unsigned long iova, { size_t size; + if (unlikely(domain->ops->map == NULL)) + return -ENODEV; + size = PAGE_SIZE << gfp_order; BUG_ON(!IS_ALIGNED(iova | paddr, size)); - return iommu_ops->map(domain, iova, paddr, gfp_order, prot); + return domain->ops->map(domain, iova, paddr, gfp_order, prot); } EXPORT_SYMBOL_GPL(iommu_map); @@ -131,10 +148,13 @@ int iommu_unmap(struct iommu_domain *domain, unsigned long iova, int gfp_order) { size_t size; + if (unlikely(domain->ops->unmap == NULL)) + return -ENODEV; + size = PAGE_SIZE << gfp_order; BUG_ON(!IS_ALIGNED(iova, size)); - return iommu_ops->unmap(domain, iova, gfp_order); + return domain->ops->unmap(domain, iova, gfp_order); } EXPORT_SYMBOL_GPL(iommu_unmap);