From patchwork Thu Feb 11 14:34:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8281121 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C6B889F3CD for ; Thu, 11 Feb 2016 14:41:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D93182039E for ; Thu, 11 Feb 2016 14:41:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D6C182035D for ; Thu, 11 Feb 2016 14:41:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752284AbcBKOfM (ORCPT ); Thu, 11 Feb 2016 09:35:12 -0500 Received: from mail-wm0-f53.google.com ([74.125.82.53]:38624 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752219AbcBKOfJ (ORCPT ); Thu, 11 Feb 2016 09:35:09 -0500 Received: by mail-wm0-f53.google.com with SMTP id p63so70992266wmp.1 for ; Thu, 11 Feb 2016 06:35:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hPvJkA5Sp7FoIzxc1xnFOb8HayFISDbDXP6IFX39C0I=; b=A0bAuPWonuo6TuciDLEz2l5qJASqh63BOiQJ7gyaevybmd0mb13rSEinIGrnbtuj/w 3PsNZlMPeRLICW/LgHcRnxR3iLm7+kwYlK3WQXr/8syB7RnAPZnfGn2kXf5uPH4zrZS/ YXIDfAoHmYizeELG1CUlhLBkwiEDIf4NANzsM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hPvJkA5Sp7FoIzxc1xnFOb8HayFISDbDXP6IFX39C0I=; b=Q5F39D1d2EeHmmrXisPcwjRoQktqGxSRoQg51m3013iwwLM2amALLiCinfUPiaV6u3 KCTkdDwR2o+jESflwJx4uLETydEjRywbKyhzmCGGRnVdj0nJbQ3zztQablxLbKZRsCEy CHMHDHTE1wWWgBewFRGlBV0AnJOmkdnv1sXz9yJ7SeRlikCQYnRd1wPY4MZyWXm+V0NF +ezupdaFGZXpSyL36sEhx3XWbGcYYOXg+84VLKcoGl0CNSWCTJ0rHOqpX4ENTS6aL5Y4 RQyEe6iy4/8mtcxlNiItCtBs07xvoql9Riq7kCfTHAUZeLNwvYRJNotCR+G5RSukNfna A/UA== X-Gm-Message-State: AG10YOTncTiYaZdtNfGc58z4KbFtj84cH+nn2qTnONBN11is4Wz5yJgjgwv3zW0FN+ijBg8M X-Received: by 10.28.188.138 with SMTP id m132mr18314456wmf.29.1455201308373; Thu, 11 Feb 2016 06:35:08 -0800 (PST) Received: from new-host-12.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id t205sm8290751wmt.23.2016.02.11.06.35.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Feb 2016 06:35:06 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, alex.williamson@redhat.com, will.deacon@arm.com, joro@8bytes.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com, christoffer.dall@linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: suravee.suthikulpanit@amd.com, patches@linaro.org, linux-kernel@vger.kernel.org, Manish.Jaggi@caviumnetworks.com, Bharat.Bhushan@freescale.com, pranav.sawargaonkar@gmail.com, p.fedin@samsung.com, iommu@lists.linux-foundation.org, sherry.hurwitz@amd.com, brijesh.singh@amd.com, leo.duran@amd.com, Thomas.Lendacky@amd.com Subject: [RFC v2 04/15] iommu: add alloc/free_reserved_iova_domain Date: Thu, 11 Feb 2016 14:34:11 +0000 Message-Id: <1455201262-5259-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455201262-5259-1-git-send-email-eric.auger@linaro.org> References: <1455201262-5259-1-git-send-email-eric.auger@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce alloc/free_reserved_iova_domain in the IOMMU API. alloc_reserved_iova_domain initializes an iova domain at a given iova base address and with a given size. This iova domain will be used to allocate iova within that window. Those IOVAs will be reserved for special purpose, typically MSI frame binding. Allocation function within the reserved iova domain will be introduced in subsequent patches. This is the responsability of the API user to make sure any IOVA belonging to that domain are allocated with those allocation functions. Signed-off-by: Eric Auger --- v1 -> v2: - moved from vfio API to IOMMU API --- drivers/iommu/iommu.c | 22 ++++++++++++++++++++++ include/linux/iommu.h | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 0e3b009..a994f34 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1557,6 +1557,28 @@ int iommu_domain_set_attr(struct iommu_domain *domain, } EXPORT_SYMBOL_GPL(iommu_domain_set_attr); +int iommu_alloc_reserved_iova_domain(struct iommu_domain *domain, + dma_addr_t iova, size_t size, + unsigned long order) +{ + int ret; + + if (!domain->ops->alloc_reserved_iova_domain) + return -EINVAL; + ret = domain->ops->alloc_reserved_iova_domain(domain, iova, + size, order); + return ret; +} +EXPORT_SYMBOL_GPL(iommu_alloc_reserved_iova_domain); + +void iommu_free_reserved_iova_domain(struct iommu_domain *domain) +{ + if (!domain->ops->free_reserved_iova_domain) + return; + domain->ops->free_reserved_iova_domain(domain); +} +EXPORT_SYMBOL_GPL(iommu_free_reserved_iova_domain); + void iommu_get_dm_regions(struct device *dev, struct list_head *list) { const struct iommu_ops *ops = dev->bus->iommu_ops; diff --git a/include/linux/iommu.h b/include/linux/iommu.h index a4fe04a..32c1a4e 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -195,6 +195,12 @@ struct iommu_ops { int (*domain_set_windows)(struct iommu_domain *domain, u32 w_count); /* Get the number of windows per domain */ u32 (*domain_get_windows)(struct iommu_domain *domain); + /* allocates the reserved iova domain */ + int (*alloc_reserved_iova_domain)(struct iommu_domain *domain, + dma_addr_t iova, size_t size, + unsigned long order); + /* frees the reserved iova domain */ + void (*free_reserved_iova_domain)(struct iommu_domain *domain); #ifdef CONFIG_OF_IOMMU int (*of_xlate)(struct device *dev, struct of_phandle_args *args); @@ -266,6 +272,10 @@ extern int iommu_domain_get_attr(struct iommu_domain *domain, enum iommu_attr, void *data); extern int iommu_domain_set_attr(struct iommu_domain *domain, enum iommu_attr, void *data); +extern int iommu_alloc_reserved_iova_domain(struct iommu_domain *domain, + dma_addr_t iova, size_t size, + unsigned long order); +extern void iommu_free_reserved_iova_domain(struct iommu_domain *domain); struct device *iommu_device_create(struct device *parent, void *drvdata, const struct attribute_group **groups, const char *fmt, ...) __printf(4, 5); @@ -541,6 +551,17 @@ static inline void iommu_device_unlink(struct device *dev, struct device *link) { } +static int iommu_alloc_reserved_iova_domain(struct iommu_domain *domain, + dma_addr_t iova, size_t size, + unsigned long order) +{ + return -EINVAL; +} + +static void iommu_free_reserved_iova_domain(struct iommu_domain *domain) +{ +} + #endif /* CONFIG_IOMMU_API */ #endif /* __LINUX_IOMMU_H */