From patchwork Thu Jan 28 11:37:53 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 75576 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o0SBf0Wl008791 for ; Thu, 28 Jan 2010 11:41:01 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755905Ab0A1Ljy (ORCPT ); Thu, 28 Jan 2010 06:39:54 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755703Ab0A1LjS (ORCPT ); Thu, 28 Jan 2010 06:39:18 -0500 Received: from va3ehsobe003.messaging.microsoft.com ([216.32.180.13]:47666 "EHLO VA3EHSOBE003.bigfish.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932264Ab0A1LjN (ORCPT ); Thu, 28 Jan 2010 06:39:13 -0500 Received: from mail117-va3-R.bigfish.com (10.7.14.246) by VA3EHSOBE003.bigfish.com (10.7.40.23) with Microsoft SMTP Server id 8.1.240.5; Thu, 28 Jan 2010 11:39:12 +0000 Received: from mail117-va3 (localhost [127.0.0.1]) by mail117-va3-R.bigfish.com (Postfix) with ESMTP id 32EC21390893; Thu, 28 Jan 2010 11:39:12 +0000 (UTC) X-SpamScore: -2 X-BigFish: VPS-2(zzab9bh936eMzz1202hzzz32i6bh87h43j61h) X-Spam-TCS-SCL: 0:0 X-FB-DOMAIN-IP-MATCH: fail Received: from mail117-va3 (localhost.localdomain [127.0.0.1]) by mail117-va3 (MessageSwitch) id 1264678751574071_20011; Thu, 28 Jan 2010 11:39:11 +0000 (UTC) Received: from VA3EHSMHS003.bigfish.com (unknown [10.7.14.247]) by mail117-va3.bigfish.com (Postfix) with ESMTP id 3F8F411501AE; Thu, 28 Jan 2010 11:38:31 +0000 (UTC) Received: from ausb3extmailp01.amd.com (163.181.251.8) by VA3EHSMHS003.bigfish.com (10.7.99.13) with Microsoft SMTP Server (TLS) id 14.0.482.39; Thu, 28 Jan 2010 11:38:30 +0000 Received: from ausb3twp02.amd.com ([163.181.250.38]) by ausb3extmailp01.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id o0SBdpg7020439; Thu, 28 Jan 2010 05:39:54 -0600 X-WSS-ID: 0KWYGBW-02-6ZX-02 X-M-MSG: Received: from sausexbh2.amd.com (SAUSEXBH2.amd.com [163.181.22.102]) by ausb3twp02.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 21B2DC84D6; Thu, 28 Jan 2010 05:38:20 -0600 (CST) Received: from sausexmb4.amd.com ([163.181.3.15]) by sausexbh2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 28 Jan 2010 05:38:24 -0600 Received: from seurexmb1.amd.com ([165.204.9.130]) by sausexmb4.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 28 Jan 2010 05:38:23 -0600 Received: from lemmy.osrc.amd.com ([165.204.15.93]) by seurexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 28 Jan 2010 12:38:20 +0100 Received: by lemmy.osrc.amd.com (Postfix, from userid 41430) id 8E0A4C9AF7; Thu, 28 Jan 2010 12:38:20 +0100 (CET) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti , David Woodhouse CC: kvm@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Joerg Roedel Subject: [PATCH 02/11] iommu-api: Add iommu_map and iommu_unmap functions Date: Thu, 28 Jan 2010 12:37:53 +0100 Message-ID: <1264678682-30655-3-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.6.6 In-Reply-To: <1264678682-30655-1-git-send-email-joerg.roedel@amd.com> References: <1264678682-30655-1-git-send-email-joerg.roedel@amd.com> X-OriginalArrivalTime: 28 Jan 2010 11:38:20.0727 (UTC) FILETIME=[645CCC70:01CAA00E] MIME-Version: 1.0 X-Reverse-DNS: unknown 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.3 (demeter.kernel.org [140.211.167.41]); Thu, 28 Jan 2010 11:41:01 +0000 (UTC) difference to the iommu_(un)map_range() is that the new functions take a gfp_order parameter instead of a size. This allows the IOMMU backend implementations to detect easier if a given range can be mapped by larger page sizes. These new functions should replace the old ones in the long term. Signed-off-by: Joerg Roedel --- drivers/base/iommu.c | 31 +++++++++++++++++++++++++++++++ include/linux/iommu.h | 16 ++++++++++++++++ 2 files changed, 47 insertions(+), 0 deletions(-) diff --git a/drivers/base/iommu.c b/drivers/base/iommu.c index f4c86c4..cf7cbec 100644 --- a/drivers/base/iommu.c +++ b/drivers/base/iommu.c @@ -107,3 +107,34 @@ int iommu_domain_has_cap(struct iommu_domain *domain, return iommu_ops->domain_has_cap(domain, cap); } EXPORT_SYMBOL_GPL(iommu_domain_has_cap); + +int iommu_map(struct iommu_domain *domain, unsigned long iova, + phys_addr_t paddr, int gfp_order, int prot) +{ + unsigned long invalid_mask; + size_t size; + + size = 0x1000UL << gfp_order; + invalid_mask = size - 1; + + BUG_ON((iova | paddr) & invalid_mask); + + return iommu_ops->map_range(domain, iova, paddr, size, prot); +} +EXPORT_SYMBOL_GPL(iommu_map); + +int iommu_unmap(struct iommu_domain *domain, unsigned long iova, int gfp_order) +{ + unsigned long invalid_mask; + size_t size; + + size = 0x1000UL << gfp_order; + invalid_mask = size - 1; + + BUG_ON(iova & invalid_mask); + + iommu_ops->unmap_range(domain, iova, size); + + return gfp_order; +} +EXPORT_SYMBOL_GPL(iommu_unmap); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 0f18f37..6d0035b 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -60,6 +60,10 @@ extern int iommu_map_range(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot); extern void iommu_unmap_range(struct iommu_domain *domain, unsigned long iova, size_t size); +extern int iommu_map(struct iommu_domain *domain, unsigned long iova, + phys_addr_t paddr, int gfp_order, int prot); +extern int iommu_unmap(struct iommu_domain *domain, unsigned long iova, + int gfp_order); extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, unsigned long iova); extern int iommu_domain_has_cap(struct iommu_domain *domain, @@ -108,6 +112,18 @@ static inline void iommu_unmap_range(struct iommu_domain *domain, { } +static inline int iommu_map(struct iommu_domain *domain, unsigned long iova, + phys_addr_t paddr, int gfp_order, int prot) +{ + return -ENODEV; +} + +static inline int iommu_unmap(struct iommu_domain *domain, unsigned long iova, + int gfp_order) +{ + return -ENODEV; +} + static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, unsigned long iova) {