From patchwork Thu Feb 11 14:34:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8281031 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4FD81BEEE5 for ; Thu, 11 Feb 2016 14:39:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5254B203AC for ; Thu, 11 Feb 2016 14:39:03 +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 5D5E02035D for ; Thu, 11 Feb 2016 14:39:02 +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 1aTsMt-000641-9c; Thu, 11 Feb 2016 14:37:15 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aTsLO-0004fB-EI for linux-arm-kernel@lists.infradead.org; Thu, 11 Feb 2016 14:35:47 +0000 Received: by mail-wm0-x234.google.com with SMTP id p63so75955222wmp.1 for ; Thu, 11 Feb 2016 06:35:22 -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=SccXANhJfhHVB1xx6dsF179JnD3/HIzWjjjfE9DWOfs=; b=CqTNsoQfuo6IymGT8i4jxcncn8XdE0jtMtIwvfnV8CjL28g2r61Z9yWg1aaGj/YJzC NJOqY8WPvBZZvo7pEjS/3W4euKyLFNyuqP0fOpjmd1nndw398MbywUdFDIXO0BEcabZJ 4uSS8/CtCFwRXut1U1MNUgH5IPaJbo9hbPBzE= 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=SccXANhJfhHVB1xx6dsF179JnD3/HIzWjjjfE9DWOfs=; b=h6/VqkaErEyMlW7ixoBPMXAD0Y7LIV+A+4mShnu89+eK9V3Ho+koIic3NgS87to4AM BHcp1wWerOkdWQ+KppDpskq+fGamrllMldG7pC2v10uBGvcVlJThxTu8oWFrt7O0tYPi 5Pl44AnhkEKSAnPBiZxSOrBV1zK6t3xIp0LYoPWCwONIs1dtS+mXcc+NRwq2bV9eG4b8 UBKyFoKUdYBmp7EgctXvwOefGuuuf7Idzt/pAs/aBezMayTYJniYOOY71lSAoILoTtqd wYO8aBtcDaGQ8mkuEoL3qJK9AfrNrtTeBVjlZGKHcrQTj3hjaVLNfkCAe9KSAxnDMgvI m3mw== X-Gm-Message-State: AG10YOQvOdyS93VyQMTsayqQ+0DanckVm/v8dmDwWkntWtmG1xS7fioagM1o430b+weG5rPM X-Received: by 10.194.52.37 with SMTP id q5mr46796995wjo.123.1455201321051; Thu, 11 Feb 2016 06:35:21 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Feb 2016 06:35:19 -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 07/15] iommu: iommu_get/put_single_reserved Date: Thu, 11 Feb 2016 14:34:14 +0000 Message-Id: <1455201262-5259-8-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_063543_055748_5CA45891 X-CRM114-Status: GOOD ( 14.92 ) X-Spam-Score: -2.7 (--) 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 This patch introduces iommu_get/put_single_reserved. iommu_get_single_reserved allows to allocate a new reserved iova page and map it onto the physical page that contains a given physical address. It returns the iova that is mapped onto the provided physical address. Hence the physical address passed in argument does not need to be aligned. In case a mapping already exists between both pages, the IOVA mapped to the PA is directly returned. Each time an iova is successfully returned a binding ref count is incremented. iommu_put_single_reserved decrements the ref count and when this latter is null, the mapping is destroyed and the iova is released. Signed-off-by: Eric Auger Signed-off-by: Ankit Jindal Signed-off-by: Pranavkumar Sawargaonkar Signed-off-by: Bharat Bhushan --- Currently the ref counting is does not really used. All bindings will be destroyed when the domain is killed. v1 -> v2: - previously a VFIO API, named vfio_alloc_map/unmap_free_reserved_iova --- drivers/iommu/iommu.c | 21 +++++++++++++++++++++ include/linux/iommu.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index a994f34..14ebde1 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1415,6 +1415,27 @@ size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size) return unmapped; } EXPORT_SYMBOL_GPL(iommu_unmap); +int iommu_get_single_reserved(struct iommu_domain *domain, + phys_addr_t addr, int prot, + dma_addr_t *iova) +{ + if (!domain->ops->get_single_reserved) + return -ENODEV; + + return domain->ops->get_single_reserved(domain, addr, prot, iova); + +} +EXPORT_SYMBOL_GPL(iommu_get_single_reserved); + +void iommu_put_single_reserved(struct iommu_domain *domain, + dma_addr_t iova) +{ + if (!domain->ops->put_single_reserved) + return; + + domain->ops->put_single_reserved(domain, iova); +} +EXPORT_SYMBOL_GPL(iommu_put_single_reserved); size_t default_iommu_map_sg(struct iommu_domain *domain, unsigned long iova, struct scatterlist *sg, unsigned int nents, int prot) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 32c1a4e..148465b8 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -201,6 +201,21 @@ struct iommu_ops { unsigned long order); /* frees the reserved iova domain */ void (*free_reserved_iova_domain)(struct iommu_domain *domain); + /** + * allocate a reserved iova page and bind it onto the page that + * contains a physical address (@addr), returns the @iova bound to + * @addr. In case the 2 pages already are bound simply return @iova + * and increment a ref count. + */ + int (*get_single_reserved)(struct iommu_domain *domain, + phys_addr_t addr, int prot, + dma_addr_t *iova); + /** + * decrement a ref count of the iova page. If null, unmap the iova page + * and release the iova + */ + void (*put_single_reserved)(struct iommu_domain *domain, + dma_addr_t iova); #ifdef CONFIG_OF_IOMMU int (*of_xlate)(struct device *dev, struct of_phandle_args *args); @@ -276,6 +291,11 @@ 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); +extern int iommu_get_single_reserved(struct iommu_domain *domain, + phys_addr_t paddr, int prot, + dma_addr_t *iova); +extern void iommu_put_single_reserved(struct iommu_domain *domain, + dma_addr_t iova); struct device *iommu_device_create(struct device *parent, void *drvdata, const struct attribute_group **groups, const char *fmt, ...) __printf(4, 5); @@ -562,6 +582,17 @@ static void iommu_free_reserved_iova_domain(struct iommu_domain *domain) { } +static int iommu_get_single_reserved(struct iommu_domain *domain, + phys_addr_t paddr, int prot, + dma_addr_t *iova) +{ + return -EINVAL; +} +static void iommu_put_single_reserved(struct iommu_domain *domain, + dma_addr_t iova) +{ +} + #endif /* CONFIG_IOMMU_API */ #endif /* __LINUX_IOMMU_H */