From patchwork Fri Feb 12 08:13:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 61824 Delivered-To: patches@linaro.org Received: by 10.112.43.199 with SMTP id y7csp676695lbl; Fri, 12 Feb 2016 00:14:17 -0800 (PST) X-Received: by 10.28.54.159 with SMTP id y31mr3024894wmh.89.1455264857000; Fri, 12 Feb 2016 00:14:17 -0800 (PST) Return-Path: Received: from mail-wm0-x22c.google.com (mail-wm0-x22c.google.com. [2a00:1450:400c:c09::22c]) by mx.google.com with ESMTPS id n69si2318105wmd.25.2016.02.12.00.14.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Feb 2016 00:14:16 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22c as permitted sender) client-ip=2a00:1450:400c:c09::22c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22c as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dkim=pass header.i=@linaro.org Received: by mail-wm0-x22c.google.com with SMTP id p63so8868590wmp.1 for ; Fri, 12 Feb 2016 00:14:16 -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=6siQHza5Ilpi+kmOrXNUKU7Z35UkzV4yioJdbdD/DC4=; b=LO7I+0zF5e5/n0fkhDnmbCTWk6LLLSO8mMjra01Gh4JpifVyn4wXeCowhd/9hThxwm BpjHn0a8TCOuUnpSvedE0FxEznrhdzl+lxsGZewWet4dNwPF6m3+4oDQCbOJBWj1nGmd tm1cqbo0rHUjTiTWs2Zy+K9LQunozeOzC0/O8= 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=6siQHza5Ilpi+kmOrXNUKU7Z35UkzV4yioJdbdD/DC4=; b=G6cwhawXG7LhQGklxkHgcOXux2nMrSTXIDV7TlDW02B/L+usRvHK57nM3U9HUeAM5e jcuIVkRUxtE8OLWJkFS3yE4eP1TARlGwUnMoW2ztbWv+yPgAiG8fAT4aiTQiBnCGI2aB 7uq12wtt8Q8fG1DAbrqSS5U9ias1DdvYwyYSlGFzFWU8G+g8+MnJQBW2awQuQX/DT3AZ BFtN86fEdyQThXBp2AjirkZEBFp/uK9IfwRCjY2e5thWBCvZNn7rlp6t/Zv9wSD0wfkx BpVCUyKyLpjNNzNZ1pAmLCDrYsyh1bkk4wruq34kTlg6w5WKU3xibtaukXeHIlxwLsvl 5jfA== X-Gm-Message-State: AG10YOQWVqPqA2Eirqhol3HyrJP8SLqtMnRkXbLwNefRCrRrA9Hpo6CKK4Vog57cqr01u/go/Z4= X-Received: by 10.194.78.175 with SMTP id c15mr312201wjx.16.1455264856802; Fri, 12 Feb 2016 00:14:16 -0800 (PST) Return-Path: Received: from new-host-17.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id x66sm1243977wmb.20.2016.02.12.00.14.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Feb 2016 00:14:15 -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 v3 07/15] iommu: iommu_get/put_single_reserved Date: Fri, 12 Feb 2016 08:13:09 +0000 Message-Id: <1455264797-2334-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455264797-2334-1-git-send-email-eric.auger@linaro.org> References: <1455264797-2334-1-git-send-email-eric.auger@linaro.org> 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 --- v2 -> v3: - remove static implementation of iommu_get_single_reserved & iommu_put_single_reserved when CONFIG_IOMMU_API is not set v1 -> v2: - previously a VFIO API, named vfio_alloc_map/unmap_free_reserved_iova --- drivers/iommu/iommu.c | 21 +++++++++++++++++++++ include/linux/iommu.h | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) -- 1.9.1 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 2d1f155..1e00c1b 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);