LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: iommu@lists.linux-foundation.org,
	Russell King <linux@armlinux.org.uk>,
	Brian Cain <bcain@codeaurora.org>
Cc: Dillon Min <dillon.minfei@gmail.com>,
	Vladimir Murzin <vladimir.murzin@arm.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-hexagon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 5/7] dma-mapping: add a dma_init_global_coherent helper
Date: Mon, 12 Jul 2021 08:17:02 +0200	[thread overview]
Message-ID: <20210712061704.4162464-6-hch@lst.de> (raw)
In-Reply-To: <20210712061704.4162464-1-hch@lst.de>

Add a new helper to initialize the global coherent pool.  This both
cleans up the existing initialization which indirects through the
reserved_mem_ops that are normally only used for struct device, and
also allows using the global pool for non-devicetree architectures.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Tested-by: Dillon Min <dillon.minfei@gmail.com>
---
 include/linux/dma-map-ops.h |  2 +-
 kernel/dma/coherent.c       | 32 ++++++++++++++------------------
 2 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
index 0d53a96a3d64..7e49bb86a0c0 100644
--- a/include/linux/dma-map-ops.h
+++ b/include/linux/dma-map-ops.h
@@ -176,7 +176,7 @@ void *dma_alloc_from_global_coherent(struct device *dev, ssize_t size,
 int dma_release_from_global_coherent(int order, void *vaddr);
 int dma_mmap_from_global_coherent(struct vm_area_struct *vma, void *cpu_addr,
 		size_t size, int *ret);
-
+int dma_init_global_coherent(phys_addr_t phys_addr, size_t size);
 #else
 static inline int dma_declare_coherent_memory(struct device *dev,
 		phys_addr_t phys_addr, dma_addr_t device_addr, size_t size)
diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c
index ab397ebfd5ad..160d4e246ecb 100644
--- a/kernel/dma/coherent.c
+++ b/kernel/dma/coherent.c
@@ -300,6 +300,18 @@ int dma_mmap_from_global_coherent(struct vm_area_struct *vma, void *vaddr,
 					vaddr, size, ret);
 }
 
+int dma_init_global_coherent(phys_addr_t phys_addr, size_t size)
+{
+	struct dma_coherent_mem *mem;
+
+	mem = dma_init_coherent_memory(phys_addr, phys_addr, size, true);
+	if (IS_ERR(mem))
+		return PTR_ERR(mem);
+	dma_coherent_default_memory = mem;
+	pr_info("DMA: default coherent area is set\n");
+	return 0;
+}
+
 /*
  * Support for reserved memory regions defined in device tree
  */
@@ -367,26 +379,10 @@ static int __init rmem_dma_setup(struct reserved_mem *rmem)
 
 static int __init dma_init_reserved_memory(void)
 {
-	const struct reserved_mem_ops *ops;
-	int ret;
-
 	if (!dma_reserved_default_memory)
 		return -ENOMEM;
-
-	ops = dma_reserved_default_memory->ops;
-
-	/*
-	 * We rely on rmem_dma_device_init() does not propagate error of
-	 * dma_assign_coherent_memory() for "NULL" device.
-	 */
-	ret = ops->device_init(dma_reserved_default_memory, NULL);
-
-	if (!ret) {
-		dma_coherent_default_memory = dma_reserved_default_memory->priv;
-		pr_info("DMA: default coherent area is set\n");
-	}
-
-	return ret;
+	return dma_init_global_coherent(dma_reserved_default_memory->base,
+					dma_reserved_default_memory->size);
 }
 
 core_initcall(dma_init_reserved_memory);
-- 
2.30.2


  parent reply	other threads:[~2021-07-12  6:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-12  6:16 add support for the global coherent pool to the dma core Christoph Hellwig
2021-07-12  6:16 ` [PATCH 1/7] dma-direct: add support for dma_coherent_default_memory Christoph Hellwig
2021-07-12  6:16 ` [PATCH 2/7] ARM/nommu: use the generic dma-direct code for non-coherent devices Christoph Hellwig
2021-07-12  6:17 ` [PATCH 3/7] dma-mapping: allow using the global coherent pool for !ARM Christoph Hellwig
2021-07-12  6:17 ` [PATCH 4/7] dma-mapping: simplify dma_init_coherent_memory Christoph Hellwig
2021-07-12  6:17 ` Christoph Hellwig [this message]
2021-07-12  6:17 ` [PATCH 6/7] dma-mapping: make the global coherent pool conditional Christoph Hellwig
2021-07-23 21:41   ` Atish Patra
2021-07-12  6:17 ` [PATCH 7/7] hexagon: use the generic global coherent pool Christoph Hellwig
2021-08-14  1:57   ` Brian Cain
2021-08-18 14:27     ` 'Christoph Hellwig'
2021-07-28 15:20 ` add support for the global coherent pool to the dma core Brian Cain
2021-08-12 13:09   ` 'Christoph Hellwig'
2021-08-14  7:03 ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210712061704.4162464-6-hch@lst.de \
    --to=hch@lst.de \
    --cc=bcain@codeaurora.org \
    --cc=dillon.minfei@gmail.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-hexagon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=vladimir.murzin@arm.com \
    --subject='Re: [PATCH 5/7] dma-mapping: add a dma_init_global_coherent helper' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).