From: Marek Szyprowski <m.szyprowski@samsung.com>
To: linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linaro-mm-sig@lists.linaro.org, devicetree@vger.kernel.org,
linux-doc@vger.kernel.org
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Arnd Bergmann <arnd@arndb.de>,
Michal Nazarewicz <mina86@mina86.com>,
Grant Likely <grant.likely@linaro.org>,
Tomasz Figa <t.figa@samsung.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Laura Abbott <lauraa@codeaurora.org>,
Rob Herring <robh+dt@kernel.org>, Olof Johansson <olof@lixom.net>,
Pawel Moll <pawel.moll@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Stephen Warren <swarren@wwwdotorg.org>,
Ian Campbell <ian.campbell@citrix.com>,
Tomasz Figa <tomasz.figa@gmail.com>,
Kumar Gala <galak@codeaurora.org>,
Nishanth Peethambaran <nishanth.p@gmail.com>,
Marc <marc.ceeeee@gmail.com>,
Josh Cartwright <joshc@codeaurora.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will.deacon@arm.com>,
Paul Mackerras <paulus@samba.org>
Subject: [PATCH v6 08/11] drivers: dma-contiguous: add initialization from device tree
Date: Fri, 28 Feb 2014 14:42:53 +0100 [thread overview]
Message-ID: <1393594976-16728-9-git-send-email-m.szyprowski@samsung.com> (raw)
In-Reply-To: <1393594976-16728-1-git-send-email-m.szyprowski@samsung.com>
Refactor internal dma_contiguous_init_reserved_mem() function, which
creates CMA area from previously reserved memory region and add support
for handling 'shared-dma-pool' reserved-memory device tree nodes.
Based on previous code provided by Josh Cartwright <joshc@codeaurora.org>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
drivers/base/dma-contiguous.c | 129 ++++++++++++++++++++++++++++++++++-------
1 file changed, 107 insertions(+), 22 deletions(-)
diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index 165c2c299e57..0efdf1986990 100644
--- a/drivers/base/dma-contiguous.c
+++ b/drivers/base/dma-contiguous.c
@@ -182,6 +182,49 @@ static int __init cma_init_reserved_areas(void)
core_initcall(cma_init_reserved_areas);
/**
+ * dma_contiguous_init_reserved_mem() - reserve custom contiguous area
+ * @size: Size of the reserved area (in bytes),
+ * @base: Base address of the reserved area optional, use 0 for any
+ * @limit: End address of the reserved memory (optional, 0 for any).
+ * @res_cma: Pointer to store the created cma region.
+ *
+ * This function reserves memory from early allocator. It should be
+ * called by arch specific code once the early allocator (memblock or bootmem)
+ * has been activated and all other subsystems have already allocated/reserved
+ * memory. This function allows to create custom reserved areas for specific
+ * devices.
+ */
+static int __init dma_contiguous_init_reserved_mem(phys_addr_t size,
+ phys_addr_t base, struct cma **res_cma)
+{
+ struct cma *cma = &cma_areas[cma_area_count];
+ phys_addr_t alignment;
+
+ /* Sanity checks */
+ if (cma_area_count == ARRAY_SIZE(cma_areas)) {
+ pr_err("Not enough slots for CMA reserved regions!\n");
+ return -ENOSPC;
+ }
+
+ if (!size || !memblock_is_region_reserved(base, size))
+ return -EINVAL;
+
+ /* Sanitise input arguments */
+ alignment = PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order);
+ if (ALIGN(base, alignment) != base || ALIGN(size, alignment) != size)
+ return -EINVAL;
+
+ cma->base_pfn = PFN_DOWN(base);
+ cma->count = size >> PAGE_SHIFT;
+ *res_cma = cma;
+ cma_area_count++;
+
+ /* Architecture specific contiguous memory fixup. */
+ dma_contiguous_early_fixup(base, size);
+ return 0;
+}
+
+/**
* dma_contiguous_reserve_area() - reserve custom contiguous area
* @size: Size of the reserved area (in bytes),
* @base: Base address of the reserved area optional, use 0 for any
@@ -197,7 +240,6 @@ core_initcall(cma_init_reserved_areas);
int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
phys_addr_t limit, struct cma **res_cma)
{
- struct cma *cma = &cma_areas[cma_area_count];
phys_addr_t alignment;
int ret = 0;
@@ -205,12 +247,6 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
(unsigned long)size, (unsigned long)base,
(unsigned long)limit);
- /* Sanity checks */
- if (cma_area_count == ARRAY_SIZE(cma_areas)) {
- pr_err("Not enough slots for CMA reserved regions!\n");
- return -ENOSPC;
- }
-
if (!size)
return -EINVAL;
@@ -241,21 +277,12 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
}
}
- /*
- * Each reserved area must be initialised later, when more kernel
- * subsystems (like slab allocator) are available.
- */
- cma->base_pfn = PFN_DOWN(base);
- cma->count = size >> PAGE_SHIFT;
- *res_cma = cma;
- cma_area_count++;
-
- pr_info("CMA: reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M,
- (unsigned long)base);
-
- /* Architecture specific contiguous memory fixup. */
- dma_contiguous_early_fixup(base, size);
- return 0;
+ ret = dma_contiguous_init_reserved_mem(size, base, res_cma);
+ if (ret == 0) {
+ pr_info("CMA: reserved %ld MiB at %08lx\n",
+ (unsigned long)size / SZ_1M, (unsigned long)base);
+ return 0;
+ }
err:
pr_err("CMA: failed to reserve %ld MiB\n", (unsigned long)size / SZ_1M);
return ret;
@@ -357,3 +384,61 @@ bool dma_release_from_contiguous(struct device *dev, struct page *pages,
return true;
}
+
+/*
+ * Support for reserved memory regions defined in device tree
+ */
+#ifdef CONFIG_OF_RESERVED_MEM
+#include <linux/of.h>
+#include <linux/of_fdt.h>
+#include <linux/of_reserved_mem.h>
+
+#undef pr_fmt
+#define pr_fmt(fmt) fmt
+
+static void rmem_cma_device_init(struct reserved_mem *rmem, struct device *dev)
+{
+ struct cma *cma = rmem->priv;
+ dev_set_cma_area(dev, cma);
+}
+
+static const struct reserved_mem_ops rmem_cma_ops = {
+ .device_init = rmem_cma_device_init,
+};
+
+static int __init rmem_cma_setup(struct reserved_mem *rmem,
+ unsigned long node,
+ const char *uname)
+{
+ phys_addr_t align = PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order);
+ phys_addr_t mask = align - 1;
+ struct cma *cma;
+ int err;
+
+ if (!of_get_flat_dt_prop(node, "reusable", NULL))
+ return -EINVAL;
+
+ if ((rmem->base & mask) || (rmem->size & mask)) {
+ pr_err("Reserved memory: incorrect alignment of CMA region\n");
+ return -EINVAL;
+ }
+
+ err = dma_contiguous_init_reserved_mem(rmem->size, rmem->base, &cma);
+ if (err) {
+ pr_err("Reserved memory: unable to setup CMA region\n");
+ return err;
+ }
+
+ if (of_get_flat_dt_prop(node, "linux,cma-default", NULL))
+ dma_contiguous_set_default(cma);
+
+ rmem->ops = &rmem_cma_ops;
+ rmem->priv = cma;
+
+ pr_info("Reserved memory: created CMA memory pool at %pa, size %ld MiB\n",
+ &rmem->base, (unsigned long)rmem->size / SZ_1M);
+
+ return 0;
+}
+RESERVEDMEM_OF_DECLARE(cma, "shared-dma-pool", rmem_cma_setup);
+#endif
--
1.7.9.5
next prev parent reply other threads:[~2014-02-28 13:45 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-28 13:42 [PATCH v6 00/11] reserved-memory regions/CMA in devicetree, again Marek Szyprowski
2014-02-28 13:42 ` [PATCH v6 01/11] of: document bindings for reserved-memory nodes Marek Szyprowski
2014-03-02 5:00 ` Grant Likely
2014-02-28 13:42 ` [PATCH v6 02/11] drivers: of: add initialization code for static reserved memory Marek Szyprowski
2014-03-02 5:28 ` Grant Likely
2014-02-28 13:42 ` [PATCH v6 03/11] drivers: of: add initialization code for dynamic " Marek Szyprowski
2014-03-02 5:30 ` Grant Likely
2014-02-28 13:42 ` [PATCH v6 04/11] drivers: of: add support for custom reserved memory drivers Marek Szyprowski
2014-03-02 5:35 ` Grant Likely
2014-02-28 13:42 ` [PATCH v6 05/11] drivers: of: add automated assignment of reserved regions to client devices Marek Szyprowski
2014-03-02 5:40 ` Grant Likely
2014-05-14 9:15 ` Jon Medhurst (Tixy)
2014-05-14 11:16 ` Grant Likely
2014-02-28 13:42 ` [PATCH v6 06/11] drivers: of: initialize and assign reserved memory to newly created devices Marek Szyprowski
2014-02-28 13:42 ` [PATCH v6 07/11] drivers: dma-coherent: add initialization from device tree Marek Szyprowski
2014-02-28 13:42 ` Marek Szyprowski [this message]
2014-02-28 13:42 ` [PATCH v6 09/11] arm: add support for reserved memory defined by " Marek Szyprowski
2014-02-28 13:42 ` [PATCH v6 10/11] arm64: " Marek Szyprowski
2014-02-28 13:42 ` [PATCH v6 11/11] powerpc: " Marek Szyprowski
2014-03-11 17:37 ` [PATCH v6 00/11] reserved-memory regions/CMA in devicetree, again Grant Likely
2014-03-31 13:52 ` Grant Likely
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=1393594976-16728-9-git-send-email-m.szyprowski@samsung.com \
--to=m.szyprowski@samsung.com \
--cc=arnd@arndb.de \
--cc=benh@kernel.crashing.org \
--cc=catalin.marinas@arm.com \
--cc=devicetree@vger.kernel.org \
--cc=galak@codeaurora.org \
--cc=grant.likely@linaro.org \
--cc=ian.campbell@citrix.com \
--cc=joshc@codeaurora.org \
--cc=lauraa@codeaurora.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.ceeeee@gmail.com \
--cc=mark.rutland@arm.com \
--cc=mina86@mina86.com \
--cc=nishanth.p@gmail.com \
--cc=olof@lixom.net \
--cc=paulus@samba.org \
--cc=pawel.moll@arm.com \
--cc=robh+dt@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=swarren@wwwdotorg.org \
--cc=t.figa@samsung.com \
--cc=tomasz.figa@gmail.com \
--cc=will.deacon@arm.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®