From: Grant Likely <grant.likely@linaro.org>
To: Marek Szyprowski <m.szyprowski@samsung.com>,
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>,
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: Re: [PATCH v6 02/11] drivers: of: add initialization code for static reserved memory
Date: Sun, 02 Mar 2014 13:28:42 +0800 [thread overview]
Message-ID: <20140302052842.EB26FC40E0C@trevor.secretlab.ca> (raw)
In-Reply-To: <1393594976-16728-3-git-send-email-m.szyprowski@samsung.com>
On Fri, 28 Feb 2014 14:42:47 +0100, Marek Szyprowski <m.szyprowski@samsung.com> wrote:
> This patch adds support for static (defined by 'reg' property) reserved
> memory regions declared in device tree.
>
> Memory blocks can be reliably reserved only during early boot. This must
> happen before the whole memory management subsystem is initialized,
> because we need to ensure that the given contiguous blocks are not yet
> allocated by kernel. Also it must happen before kernel mappings for the
> whole low memory are created, to ensure that there will be no mappings
> (for reserved blocks). Typically, all this happens before device tree
> structures are unflattened, so we need to get reserved memory layout
> directly from fdt.
>
> Based on previous code provided by Josh Cartwright <joshc@codeaurora.org>
>
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Acked-by: Grant Likely <grant.likely@linaro.org>
Applied, thanks.
g.
> ---
> drivers/of/fdt.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/of_fdt.h | 3 ++
> 2 files changed, 134 insertions(+)
>
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index 758b4f8b30b7..819e11209718 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -15,6 +15,7 @@
> #include <linux/module.h>
> #include <linux/of.h>
> #include <linux/of_fdt.h>
> +#include <linux/sizes.h>
> #include <linux/string.h>
> #include <linux/errno.h>
> #include <linux/slab.h>
> @@ -440,6 +441,118 @@ struct boot_param_header *initial_boot_params;
> #ifdef CONFIG_OF_EARLY_FLATTREE
>
> /**
> + * res_mem_reserve_reg() - reserve all memory described in 'reg' property
> + */
> +static int __init __reserved_mem_reserve_reg(unsigned long node,
> + const char *uname)
> +{
> + int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
> + phys_addr_t base, size;
> + unsigned long len;
> + __be32 *prop;
> + int nomap;
> +
> + prop = of_get_flat_dt_prop(node, "reg", &len);
> + if (!prop)
> + return -ENOENT;
> +
> + if (len && len % t_len != 0) {
> + pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n",
> + uname);
> + return -EINVAL;
> + }
> +
> + nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL;
> +
> + while (len >= t_len) {
> + base = dt_mem_next_cell(dt_root_addr_cells, &prop);
> + size = dt_mem_next_cell(dt_root_size_cells, &prop);
> +
> + if (base && size &&
> + early_init_dt_reserve_memory_arch(base, size, nomap) == 0)
> + pr_debug("Reserved memory: reserved region for node '%s': base %pa, size %ld MiB\n",
> + uname, &base, (unsigned long)size / SZ_1M);
> + else
> + pr_info("Reserved memory: failed to reserve memory for node '%s': base %pa, size %ld MiB\n",
> + uname, &base, (unsigned long)size / SZ_1M);
> +
> + len -= t_len;
> + }
> + return 0;
> +}
> +
> +/**
> + * __reserved_mem_check_root() - check if #size-cells, #address-cells provided
> + * in /reserved-memory matches the values supported by the current implementation,
> + * also check if ranges property has been provided
> + */
> +static int __reserved_mem_check_root(unsigned long node)
> +{
> + __be32 *prop;
> +
> + prop = of_get_flat_dt_prop(node, "#size-cells", NULL);
> + if (!prop || be32_to_cpup(prop) != dt_root_size_cells)
> + return -EINVAL;
> +
> + prop = of_get_flat_dt_prop(node, "#address-cells", NULL);
> + if (!prop || be32_to_cpup(prop) != dt_root_addr_cells)
> + return -EINVAL;
> +
> + prop = of_get_flat_dt_prop(node, "ranges", NULL);
> + if (!prop)
> + return -EINVAL;
> + return 0;
> +}
> +
> +/**
> + * fdt_scan_reserved_mem() - scan a single FDT node for reserved memory
> + */
> +static int __init __fdt_scan_reserved_mem(unsigned long node, const char *uname,
> + int depth, void *data)
> +{
> + static int found;
> + const char *status;
> +
> + if (!found && depth == 1 && strcmp(uname, "reserved-memory") == 0) {
> + if (__reserved_mem_check_root(node) != 0) {
> + pr_err("Reserved memory: unsupported node format, ignoring\n");
> + /* break scan */
> + return 1;
> + }
> + found = 1;
> + /* scan next node */
> + return 0;
> + } else if (!found) {
> + /* scan next node */
> + return 0;
> + } else if (found && depth < 2) {
> + /* scanning of /reserved-memory has been finished */
> + return 1;
> + }
> +
> + status = of_get_flat_dt_prop(node, "status", NULL);
> + if (status && strcmp(status, "okay") != 0 && strcmp(status, "ok") != 0)
> + return 0;
> +
> + __reserved_mem_reserve_reg(node, uname);
> +
> + /* scan next node */
> + return 0;
> +}
> +
> +/**
> + * early_init_fdt_scan_reserved_mem() - create reserved memory regions
> + *
> + * This function grabs memory from early allocator for device exclusive use
> + * defined in device tree structures. It should be called by arch specific code
> + * once the early allocator (i.e. memblock) has been fully activated.
> + */
> +void __init early_init_fdt_scan_reserved_mem(void)
> +{
> + of_scan_flat_dt(__fdt_scan_reserved_mem, NULL);
> +}
> +
> +/**
> * of_scan_flat_dt - scan flattened tree blob and call callback on each.
> * @it: callback function
> * @data: context data pointer
> @@ -856,6 +969,16 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> memblock_add(base, size);
> }
>
> +int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
> + phys_addr_t size, bool nomap)
> +{
> + if (memblock_is_region_reserved(base, size))
> + return -EBUSY;
> + if (nomap)
> + return memblock_remove(base, size);
> + return memblock_reserve(base, size);
> +}
> +
> /*
> * called from unflatten_device_tree() to bootstrap devicetree itself
> * Architectures can override this definition if memblock isn't used
> @@ -864,6 +987,14 @@ void * __init __weak early_init_dt_alloc_memory_arch(u64 size, u64 align)
> {
> return __va(memblock_alloc(size, align));
> }
> +#else
> +int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
> + phys_addr_t size, bool nomap)
> +{
> + pr_err("Reserved memory not supported, ignoring range 0x%llx - 0x%llx%s\n",
> + base, size, nomap ? " (nomap)" : "");
> + return -ENOSYS;
> +}
> #endif
>
> bool __init early_init_dt_scan(void *params)
> diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
> index 2b77058a7335..8610ad8d77d2 100644
> --- a/include/linux/of_fdt.h
> +++ b/include/linux/of_fdt.h
> @@ -98,7 +98,10 @@ extern int early_init_dt_scan_chosen(unsigned long node, const char *uname,
> int depth, void *data);
> extern int early_init_dt_scan_memory(unsigned long node, const char *uname,
> int depth, void *data);
> +extern void early_init_fdt_scan_reserved_mem(void);
> extern void early_init_dt_add_memory_arch(u64 base, u64 size);
> +extern int early_init_dt_reserve_memory_arch(phys_addr_t base, phys_addr_t size,
> + bool no_map);
> extern void * early_init_dt_alloc_memory_arch(u64 size, u64 align);
> extern u64 dt_mem_next_cell(int s, __be32 **cellp);
>
> --
> 1.7.9.5
>
next prev parent reply other threads:[~2014-03-02 9:09 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 [this message]
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 ` [PATCH v6 08/11] drivers: dma-contiguous: " Marek Szyprowski
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=20140302052842.EB26FC40E0C@trevor.secretlab.ca \
--to=grant.likely@linaro.org \
--cc=arnd@arndb.de \
--cc=benh@kernel.crashing.org \
--cc=catalin.marinas@arm.com \
--cc=devicetree@vger.kernel.org \
--cc=galak@codeaurora.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=m.szyprowski@samsung.com \
--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®