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: 8281001 Return-Path: X-Original-To: patchwork-linux-arm@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 C9AAB9F3CD for ; Thu, 11 Feb 2016 14:38:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DE55C203AC for ; Thu, 11 Feb 2016 14:38:28 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 54D072039E for ; Thu, 11 Feb 2016 14:38:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aTsM9-0005QI-6c; Thu, 11 Feb 2016 14:36:29 +0000 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aTsLC-0004Tv-0v for linux-arm-kernel@lists.infradead.org; Thu, 11 Feb 2016 14:35:32 +0000 Received: by mail-wm0-x229.google.com with SMTP id 128so23794843wmz.1 for ; Thu, 11 Feb 2016 06:35:09 -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=XWQHaUjVXVtgo7AC6wjOkpr/Ie5919Qs3EF/BrhwZwHFv4qAW6KNIQ78p14cOB5Xog 59fXGljYPJGjXarKZ/uFJxytwzVfXezBYKWnVub8fN4ptG7V2/MgBxwkqa2bA9kCB+NA jvxZ85TSKIM/xN8XxffNzjP7WhiqUO0gqkvjRpCXL3ByhgDxdL0J+wO7hocsywz8f9O1 quN+MpQbh9Oe1J0WIyBPdn+2gFnjDFopLwN/WSgeEMLsBeBW0TVPWqKi+3u9X+kNaX7h w3m1yO39/+1VDZk/Y+U9/qSBv7O0Ei+gZ9mX8M5FH43uKINI8XsXqm+bwuKznqiGmRMm veKg== X-Gm-Message-State: AG10YOQ8hvjyR7ghxd7iWk5XlaTWC5EZ8toA1Lp+x3zkdQoXho9yxxoZ40rIKkeCDOlalDCS 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160211_063530_358792_1AAA5308 X-CRM114-Status: GOOD ( 13.07 ) X-Spam-Score: -2.0 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas.Lendacky@amd.com, brijesh.singh@amd.com, patches@linaro.org, Manish.Jaggi@caviumnetworks.com, p.fedin@samsung.com, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, iommu@lists.linux-foundation.org, pranav.sawargaonkar@gmail.com, leo.duran@amd.com, suravee.suthikulpanit@amd.com, sherry.hurwitz@amd.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,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 */