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: Auger Eric X-Patchwork-Id: 61771 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp228967lbl; Thu, 11 Feb 2016 06:35:43 -0800 (PST) X-Received: by 10.98.76.80 with SMTP id z77mr67158427pfa.121.1455201320492; Thu, 11 Feb 2016 06:35:20 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g12si12967381pfj.135.2016.02.11.06.35.19; Thu, 11 Feb 2016 06:35:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751565AbcBKOfO (ORCPT + 30 others); Thu, 11 Feb 2016 09:35:14 -0500 Received: from mail-wm0-f49.google.com ([74.125.82.49]:35277 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752214AbcBKOfJ (ORCPT ); Thu, 11 Feb 2016 09:35:09 -0500 Received: by mail-wm0-f49.google.com with SMTP id c200so76066214wme.0 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=bIaQ+ApsbwpyrMhrjG5EeNlfIwt+uoPwhfN0us+CfHoJ4mIGb/Xfsaomdck3bAsiIi E+VTyujRrzXtWGQQ4HTGkW1S8cBibszdp5yfcxxfv0TsBZrq8OtNA/ncXfTAuejv2mif izONGBC6d6APhOutlxPS5mhUx+qyyGg0waViNxzaJB74XlSbmGouO/GoyRmmFZcDfBZN 2Z1g19gxf6JByIK98nTC3EQTB0m2RXzJSe/pa68+ttaD1TJpgqJSMQE9kxRxVZ+dG53X z/1MFSOTvLBaf9Fp/17D4rLbgV5NTRr0J7Nj5iXGtYNbX63I73AciI34AT3rVuGzQEIf +vKQ== X-Gm-Message-State: AG10YOSJ5peJsv5U9yHyHcNWQ3l4Dn+XOfeyHbRFOjAKMlhzdyoSsMiB9yweyZATHMZva7hj 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(+) -- 1.9.1 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 */