2013-09-16 23:09:37

by Rob Herring

[permalink] [raw]
Subject: [PATCH 00/28] Early flattened DT init consolidation

From: Rob Herring <[email protected]>

This is the first of 2 series to do some consolidation of per
architecture Device Tree code. We now have 12 architectures with DT
support. As new architectures have been added, much of the DT related
code for the early flattened DT scanning has been duplicated. Yet little
of this code is architecture specific. This series has 4 main parts:

- Create a common function to copy built-in dtb's out of init section
- Create a single, common function to scan the FDT
- Removal of early_init_dt_setup_initrd_arch
- Create common functions for machine matching with DT

The entire series is available here:
git://sources.calxeda.com/kernel/linux.git dt-cleanup

Compiled on arm, arm64, microblaze, mips, openrisc, powerpc, sparc,
xtensa.

Rob

Rob Herring (28):
c6x: use boot_command_line instead of private c6x_command_line
openrisc: use boot_command_line instead of private cmd_line
of: create unflatten_and_copy_device_tree
arc: use unflatten_and_copy_device_tree
openrisc: use unflatten_and_copy_device_tree
x86: use unflatten_and_copy_device_tree
xtensa: use unflatten_and_copy_device_tree
metag: use unflatten_and_copy_device_tree
of: Introduce common early_init_dt_scan
arc: use early_init_dt_scan
arm: use early_init_dt_scan
arm64: use early_init_dt_scan
c6x: use early_init_dt_scan
microblaze: use early_init_dt_scan
mips: use early_init_dt_scan
openrisc: use early_init_dt_scan
xtensa: use early_init_dt_scan
of: create default early_init_dt_add_memory_arch
arm: set initrd_start/initrd_end for fdt scan
arm64: set initrd_start/initrd_end for fdt scan
of: remove early_init_dt_setup_initrd_arch
openrisc: remove unnecessary prom.c includes
of: introduce common FDT machine related functions
arc: use common of_flat_dt_match_machine
arm: use common of_flat_dt_match_machine
arm64: use common of_flat_dt_get_machine_name
metag: use common of_flat_dt_match_machine
mips: use common of_flat_dt_get_machine_name

arch/arc/include/asm/mach_desc.h | 1 -
arch/arc/kernel/devtree.c | 94 +++++++--------------------------
arch/arc/kernel/setup.c | 3 +-
arch/arc/mm/init.c | 7 ---
arch/arm/kernel/devtree.c | 57 ++++++++------------
arch/arm/mm/init.c | 13 ++---
arch/arm64/kernel/setup.c | 60 ++-------------------
arch/arm64/mm/init.c | 24 +++------
arch/c6x/include/asm/setup.h | 2 -
arch/c6x/kernel/devicetree.c | 29 ----------
arch/c6x/kernel/setup.c | 13 +----
arch/metag/kernel/devtree.c | 87 ++++++------------------------
arch/metag/kernel/setup.c | 4 +-
arch/metag/mm/init.c | 9 ----
arch/microblaze/kernel/prom.c | 31 ++---------
arch/microblaze/kernel/setup.c | 2 +-
arch/mips/include/asm/prom.h | 3 --
arch/mips/kernel/prom.c | 60 +--------------------
arch/openrisc/kernel/prom.c | 70 +-----------------------
arch/openrisc/kernel/setup.c | 6 +--
arch/powerpc/kernel/prom.c | 9 ----
arch/x86/kernel/devicetree.c | 42 +++------------
arch/xtensa/kernel/setup.c | 55 +++++--------------
drivers/of/fdt.c | 111 +++++++++++++++++++++++++++++++++++++--
include/linux/of_fdt.h | 18 +++----
25 files changed, 223 insertions(+), 587 deletions(-)

--
1.8.1.2


2013-09-16 23:09:45

by Rob Herring

[permalink] [raw]
Subject: [PATCH 05/28] openrisc: use unflatten_and_copy_device_tree

From: Rob Herring <[email protected]>

Use the common unflatten_and_copy_device_tree to copy the built-in FDT
out of init section. This moves the copy later in the boot, but there
do not appear to be any references to strings in the FDT before the copy.

Signed-off-by: Rob Herring <[email protected]>
Cc: Jonas Bonn <[email protected]>
Cc: [email protected]
---
arch/openrisc/kernel/prom.c | 13 -------------
arch/openrisc/kernel/setup.c | 2 +-
2 files changed, 1 insertion(+), 14 deletions(-)

diff --git a/arch/openrisc/kernel/prom.c b/arch/openrisc/kernel/prom.c
index bf3fd05..3b94972 100644
--- a/arch/openrisc/kernel/prom.c
+++ b/arch/openrisc/kernel/prom.c
@@ -55,8 +55,6 @@ void __init early_init_dt_add_memory_arch(u64 base, u64 size)

void __init early_init_devtree(void *params)
{
- void *alloc;
-
/* Setup flat device-tree pointer */
initial_boot_params = params;

@@ -72,17 +70,6 @@ void __init early_init_devtree(void *params)
of_scan_flat_dt(early_init_dt_scan_memory, NULL);

memblock_allow_resize();
-
- /* We must copy the flattend device tree from init memory to regular
- * memory because the device tree references the strings in it
- * directly.
- */
-
- alloc = __va(memblock_alloc(initial_boot_params->totalsize, PAGE_SIZE));
-
- memcpy(alloc, initial_boot_params, initial_boot_params->totalsize);
-
- initial_boot_params = alloc;
}

#ifdef CONFIG_BLK_DEV_INITRD
diff --git a/arch/openrisc/kernel/setup.c b/arch/openrisc/kernel/setup.c
index 719c5c8..09a769b 100644
--- a/arch/openrisc/kernel/setup.c
+++ b/arch/openrisc/kernel/setup.c
@@ -283,7 +283,7 @@ void __init setup_arch(char **cmdline_p)
{
unsigned long max_low_pfn;

- unflatten_device_tree();
+ unflatten_and_copy_device_tree();

setup_cpuinfo();

--
1.8.1.2

2013-09-16 23:09:50

by Rob Herring

[permalink] [raw]
Subject: [PATCH 15/28] mips: use early_init_dt_scan

From: Rob Herring <[email protected]>

Convert mips to use new early_init_dt_scan function.

Remove early_init_dt_scan_memory_arch

Signed-off-by: Rob Herring <[email protected]>
Cc: Ralf Baechle <[email protected]>
Cc: [email protected]
---
arch/mips/include/asm/prom.h | 3 ---
arch/mips/kernel/prom.c | 39 +++------------------------------------
2 files changed, 3 insertions(+), 39 deletions(-)

diff --git a/arch/mips/include/asm/prom.h b/arch/mips/include/asm/prom.h
index 1e7e096..e3dbd0e 100644
--- a/arch/mips/include/asm/prom.h
+++ b/arch/mips/include/asm/prom.h
@@ -17,9 +17,6 @@
#include <linux/types.h>
#include <asm/bootinfo.h>

-extern int early_init_dt_scan_memory_arch(unsigned long node,
- const char *uname, int depth, void *data);
-
extern void device_tree_init(void);

static inline unsigned long pci_address_to_pio(phys_addr_t address)
diff --git a/arch/mips/kernel/prom.c b/arch/mips/kernel/prom.c
index 0fa0b69..67a4c53 100644
--- a/arch/mips/kernel/prom.c
+++ b/arch/mips/kernel/prom.c
@@ -17,8 +17,6 @@
#include <linux/debugfs.h>
#include <linux/of.h>
#include <linux/of_fdt.h>
-#include <linux/of_irq.h>
-#include <linux/of_platform.h>

#include <asm/page.h>
#include <asm/prom.h>
@@ -40,13 +38,6 @@ char *mips_get_machine_name(void)
}

#ifdef CONFIG_OF
-int __init early_init_dt_scan_memory_arch(unsigned long node,
- const char *uname, int depth,
- void *data)
-{
- return early_init_dt_scan_memory(node, uname, depth, data);
-}
-
void __init early_init_dt_add_memory_arch(u64 base, u64 size)
{
return add_memory_region(base, size, BOOT_MEM_RAM);
@@ -78,36 +69,12 @@ int __init early_init_dt_scan_model(unsigned long node, const char *uname,
return 0;
}

-void __init early_init_devtree(void *params)
-{
- /* Setup flat device-tree pointer */
- initial_boot_params = params;
-
- /* Retrieve various informations from the /chosen node of the
- * device-tree, including the platform type, initrd location and
- * size, and more ...
- */
- of_scan_flat_dt(early_init_dt_scan_chosen, arcs_cmdline);
-
-
- /* Scan memory nodes */
- of_scan_flat_dt(early_init_dt_scan_root, NULL);
- of_scan_flat_dt(early_init_dt_scan_memory_arch, NULL);
-
- /* try to load the mips machine name */
- of_scan_flat_dt(early_init_dt_scan_model, NULL);
-}
-
void __init __dt_setup_arch(struct boot_param_header *bph)
{
- if (be32_to_cpu(bph->magic) != OF_DT_HEADER) {
- pr_err("DTB has bad magic, ignoring builtin OF DTB\n");
-
+ if (!early_init_dt_scan(bph))
return;
- }
-
- initial_boot_params = bph;

- early_init_devtree(initial_boot_params);
+ /* try to load the mips machine name */
+ of_scan_flat_dt(early_init_dt_scan_model, NULL);
}
#endif
--
1.8.1.2

2013-09-16 23:09:56

by Rob Herring

[permalink] [raw]
Subject: [PATCH 21/28] of: remove early_init_dt_setup_initrd_arch

From: Rob Herring <[email protected]>

All arches do essentially the same thing now for
early_init_dt_setup_initrd_arch, so it can now be removed.

Signed-off-by: Rob Herring <[email protected]>
Cc: Vineet Gupta <[email protected]>
Cc: Russell King <[email protected]>
Cc: Mark Salter <[email protected]>
Cc: Aurelien Jacquiot <[email protected]>
Cc: James Hogan <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Ralf Baechle <[email protected]>
Cc: Jonas Bonn <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]
Cc: Chris Zankel <[email protected]>
Cc: Max Filippov <[email protected]>
Cc: Grant Likely <[email protected]>
---
arch/arc/mm/init.c | 7 -------
arch/arm/mm/init.c | 8 --------
arch/c6x/kernel/devicetree.c | 10 ----------
arch/metag/mm/init.c | 9 ---------
arch/microblaze/kernel/prom.c | 9 ---------
arch/mips/kernel/prom.c | 10 ----------
arch/openrisc/kernel/prom.c | 9 ---------
arch/powerpc/kernel/prom.c | 9 ---------
arch/x86/kernel/devicetree.c | 9 ---------
arch/xtensa/kernel/setup.c | 15 ++++-----------
drivers/of/fdt.c | 9 ++++++---
include/linux/of_fdt.h | 10 ----------
12 files changed, 10 insertions(+), 104 deletions(-)

diff --git a/arch/arc/mm/init.c b/arch/arc/mm/init.c
index 81279ec..55e0a85 100644
--- a/arch/arc/mm/init.c
+++ b/arch/arc/mm/init.c
@@ -125,10 +125,3 @@ void __init free_initrd_mem(unsigned long start, unsigned long end)
free_reserved_area((void *)start, (void *)end, -1, "initrd");
}
#endif
-
-#ifdef CONFIG_OF_FLATTREE
-void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
-{
- pr_err("%s(%llx, %llx)\n", __func__, start, end);
-}
-#endif /* CONFIG_OF_FLATTREE */
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 9eeb1cd..9d0b91d 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -77,14 +77,6 @@ static int __init parse_tag_initrd2(const struct tag *tag)

__tagtable(ATAG_INITRD2, parse_tag_initrd2);

-#if defined(CONFIG_OF_FLATTREE) && defined(CONFIG_BLK_DEV_INITRD)
-void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
-{
- initrd_start = (unsigned long)__va(start);
- initrd_end = (unsigned long)__va(end);
-}
-#endif /* CONFIG_OF_FLATTREE */
-
/*
* This keeps memory configuration data used by a couple memory
* initialization functions, as well as show_mem() for the skipping
diff --git a/arch/c6x/kernel/devicetree.c b/arch/c6x/kernel/devicetree.c
index d28a92f..fa3e574 100644
--- a/arch/c6x/kernel/devicetree.c
+++ b/arch/c6x/kernel/devicetree.c
@@ -10,18 +10,8 @@
*
*/
#include <linux/init.h>
-#include <linux/initrd.h>
#include <linux/memblock.h>

-#ifdef CONFIG_BLK_DEV_INITRD
-void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
-{
- initrd_start = (unsigned long)__va(start);
- initrd_end = (unsigned long)__va(end);
- initrd_below_start_ok = 1;
-}
-#endif
-
void __init early_init_dt_add_memory_arch(u64 base, u64 size)
{
c6x_add_memory(base, size);
diff --git a/arch/metag/mm/init.c b/arch/metag/mm/init.c
index 1239195..249fff6 100644
--- a/arch/metag/mm/init.c
+++ b/arch/metag/mm/init.c
@@ -12,7 +12,6 @@
#include <linux/percpu.h>
#include <linux/memblock.h>
#include <linux/initrd.h>
-#include <linux/of_fdt.h>

#include <asm/setup.h>
#include <asm/page.h>
@@ -405,11 +404,3 @@ void free_initrd_mem(unsigned long start, unsigned long end)
"initrd");
}
#endif
-
-#ifdef CONFIG_OF_FLATTREE
-void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
-{
- pr_err("%s(%llx, %llx)\n",
- __func__, start, end);
-}
-#endif /* CONFIG_OF_FLATTREE */
diff --git a/arch/microblaze/kernel/prom.c b/arch/microblaze/kernel/prom.c
index 951e4d6..cab6dc3 100644
--- a/arch/microblaze/kernel/prom.c
+++ b/arch/microblaze/kernel/prom.c
@@ -114,15 +114,6 @@ void __init early_init_devtree(void *params)
pr_debug(" <- early_init_devtree()\n");
}

-#ifdef CONFIG_BLK_DEV_INITRD
-void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
-{
- initrd_start = (unsigned long)__va(start);
- initrd_end = (unsigned long)__va(end);
- initrd_below_start_ok = 1;
-}
-#endif
-
/*******
*
* New implementation of the OF "find" APIs, return a refcounted
diff --git a/arch/mips/kernel/prom.c b/arch/mips/kernel/prom.c
index 67a4c53..0b2485f 100644
--- a/arch/mips/kernel/prom.c
+++ b/arch/mips/kernel/prom.c
@@ -13,7 +13,6 @@
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/bootmem.h>
-#include <linux/initrd.h>
#include <linux/debugfs.h>
#include <linux/of.h>
#include <linux/of_fdt.h>
@@ -48,15 +47,6 @@ void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
return __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS));
}

-#ifdef CONFIG_BLK_DEV_INITRD
-void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
-{
- initrd_start = (unsigned long)__va(start);
- initrd_end = (unsigned long)__va(end);
- initrd_below_start_ok = 1;
-}
-#endif
-
int __init early_init_dt_scan_model(unsigned long node, const char *uname,
int depth, void *data)
{
diff --git a/arch/openrisc/kernel/prom.c b/arch/openrisc/kernel/prom.c
index 6dbcaa8..2aae474 100644
--- a/arch/openrisc/kernel/prom.c
+++ b/arch/openrisc/kernel/prom.c
@@ -52,12 +52,3 @@ void __init early_init_devtree(void *params)
early_init_dt_scan(params);
memblock_allow_resize();
}
-
-#ifdef CONFIG_BLK_DEV_INITRD
-void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
-{
- initrd_start = (unsigned long)__va(start);
- initrd_end = (unsigned long)__va(end);
- initrd_below_start_ok = 1;
-}
-#endif
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index b7634ce..a089468 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -546,15 +546,6 @@ void __init early_init_dt_add_memory_arch(u64 base, u64 size)
memblock_add(base, size);
}

-#ifdef CONFIG_BLK_DEV_INITRD
-void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
-{
- initrd_start = (unsigned long)__va(start);
- initrd_end = (unsigned long)__va(end);
- initrd_below_start_ok = 1;
-}
-#endif
-
static void __init early_reserve_mem_dt(void)
{
unsigned long i, len, dt_root;
diff --git a/arch/x86/kernel/devicetree.c b/arch/x86/kernel/devicetree.c
index 2f5cb37..ec2d011 100644
--- a/arch/x86/kernel/devicetree.c
+++ b/arch/x86/kernel/devicetree.c
@@ -41,15 +41,6 @@ void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
return __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS));
}

-#ifdef CONFIG_BLK_DEV_INITRD
-void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
-{
- initrd_start = (unsigned long)__va(start);
- initrd_end = (unsigned long)__va(end);
- initrd_below_start_ok = 1;
-}
-#endif
-
void __init add_dtb(u64 data)
{
initial_dtb = data + offsetof(struct setup_data, data);
diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c
index 65974a8..6e2b663 100644
--- a/arch/xtensa/kernel/setup.c
+++ b/arch/xtensa/kernel/setup.c
@@ -61,8 +61,8 @@ extern struct rtc_ops no_rtc_ops;
struct rtc_ops *rtc_ops;

#ifdef CONFIG_BLK_DEV_INITRD
-extern void *initrd_start;
-extern void *initrd_end;
+extern unsigned long initrd_start;
+extern unsigned long initrd_end;
int initrd_is_mapped = 0;
extern int initrd_below_start_ok;
#endif
@@ -149,8 +149,8 @@ static int __init parse_tag_initrd(const bp_tag_t* tag)
{
meminfo_t* mi;
mi = (meminfo_t*)(tag->data);
- initrd_start = __va(mi->start);
- initrd_end = __va(mi->end);
+ initrd_start = (unsigned long)__va(mi->start);
+ initrd_end = (unsigned long)__va(mi->end);

return 0;
}
@@ -167,13 +167,6 @@ static int __init parse_tag_fdt(const bp_tag_t *tag)

__tagtable(BP_TAG_FDT, parse_tag_fdt);

-void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
-{
- initrd_start = (void *)__va(start);
- initrd_end = (void *)__va(end);
- initrd_below_start_ok = 1;
-}
-
#endif /* CONFIG_OF */

#endif /* CONFIG_BLK_DEV_INITRD */
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a9dce7a..83cdeb5 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -624,7 +624,7 @@ int __init of_scan_flat_dt_by_path(const char *path,
* early_init_dt_check_for_initrd - Decode initrd location from flat tree
* @node: reference to node containing initrd location ('chosen')
*/
-void __init early_init_dt_check_for_initrd(unsigned long node)
+static void __init early_init_dt_check_for_initrd(unsigned long node)
{
u64 start, end;
unsigned long len;
@@ -642,12 +642,15 @@ void __init early_init_dt_check_for_initrd(unsigned long node)
return;
end = of_read_number(prop, len/4);

- early_init_dt_setup_initrd_arch(start, end);
+ initrd_start = (unsigned long)__va(start);
+ initrd_end = (unsigned long)__va(end);
+ initrd_below_start_ok = 1;
+
pr_debug("initrd_start=0x%llx initrd_end=0x%llx\n",
(unsigned long long)start, (unsigned long long)end);
}
#else
-inline void early_init_dt_check_for_initrd(unsigned long node)
+static inline void early_init_dt_check_for_initrd(unsigned long node)
{
}
#endif /* CONFIG_BLK_DEV_INITRD */
diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
index 73e1651..b365f5a 100644
--- a/include/linux/of_fdt.h
+++ b/include/linux/of_fdt.h
@@ -96,22 +96,12 @@ extern int of_scan_flat_dt_by_path(const char *path,

extern int early_init_dt_scan_chosen(unsigned long node, const char *uname,
int depth, void *data);
-extern void early_init_dt_check_for_initrd(unsigned long node);
extern int early_init_dt_scan_memory(unsigned long node, const char *uname,
int depth, void *data);
extern void early_init_dt_add_memory_arch(u64 base, u64 size);
extern void * early_init_dt_alloc_memory_arch(u64 size, u64 align);
extern u64 dt_mem_next_cell(int s, __be32 **cellp);

-/*
- * If BLK_DEV_INITRD, the fdt early init code will call this function,
- * to be provided by the arch code. start and end are specified as
- * physical addresses.
- */
-#ifdef CONFIG_BLK_DEV_INITRD
-extern void early_init_dt_setup_initrd_arch(u64 start, u64 end);
-#endif
-
/* Early flat tree scan hooks */
extern int early_init_dt_scan_root(unsigned long node, const char *uname,
int depth, void *data);
--
1.8.1.2

2013-09-16 23:10:06

by Rob Herring

[permalink] [raw]
Subject: [PATCH 27/28] metag: use common of_flat_dt_match_machine

From: Rob Herring <[email protected]>

Convert metag to use the common of_flat_dt_get_machine_name function.

Signed-off-by: Rob Herring <[email protected]>
Cc: James Hogan <[email protected]>
---
arch/metag/kernel/devtree.c | 67 ++++++++++++---------------------------------
1 file changed, 18 insertions(+), 49 deletions(-)

diff --git a/arch/metag/kernel/devtree.c b/arch/metag/kernel/devtree.c
index 2c6ee6d..b26bcb4 100644
--- a/arch/metag/kernel/devtree.c
+++ b/arch/metag/kernel/devtree.c
@@ -28,6 +28,19 @@ void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
return alloc_bootmem_align(size, align);
}

+static void * __init arch_get_next_mach(const char *const **match)
+{
+ static struct machine_desc *mdesc = __arch_info_begin;
+ struct machine_desc *m = mdesc;
+
+ if (m >= __arch_info_end)
+ return NULL;
+
+ mdesc++;
+ *match = m->dt_compat;
+ return m;
+}
+
/**
* setup_machine_fdt - Machine setup when an dtb was passed to the kernel
* @dt: virtual address pointer to dt blob
@@ -37,56 +50,12 @@ void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
*/
struct machine_desc * __init setup_machine_fdt(void *dt)
{
- struct boot_param_header *devtree = dt;
- struct machine_desc *mdesc, *mdesc_best = NULL;
- unsigned int score, mdesc_score = ~1;
- unsigned long dt_root;
- const char *model;
-
- /* check device tree validity */
- if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
- return NULL;
-
- /* Search the mdescs for the 'best' compatible value match */
- initial_boot_params = devtree;
- dt_root = of_get_flat_dt_root();
-
- for_each_machine_desc(mdesc) {
- score = of_flat_dt_match(dt_root, mdesc->dt_compat);
- if (score > 0 && score < mdesc_score) {
- mdesc_best = mdesc;
- mdesc_score = score;
- }
- }
- if (!mdesc_best) {
- const char *prop;
- long size;
-
- pr_err("\nError: unrecognized/unsupported device tree compatible list:\n[ ");
-
- prop = of_get_flat_dt_prop(dt_root, "compatible", &size);
- if (prop) {
- while (size > 0) {
- printk("'%s' ", prop);
- size -= strlen(prop) + 1;
- prop += strlen(prop) + 1;
- }
- }
- printk("]\n\n");
+ struct machine_desc *mdesc;

+ early_init_dt_scan(dt);
+ mdesc = of_flat_dt_match_machine(NULL, arch_get_next_mach);
+ if (!mdesc)
dump_machine_table(); /* does not return */
- }
-
- model = of_get_flat_dt_prop(dt_root, "model", NULL);
- if (!model)
- model = of_get_flat_dt_prop(dt_root, "compatible", NULL);
- if (!model)
- model = "<unknown>";
- pr_info("Machine: %s, model: %s\n", mdesc_best->name, model);
-
- /* Retrieve various information from the /chosen node */
- of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
-
- return mdesc_best;

+ return mdesc;
}
--
1.8.1.2

2013-09-16 23:10:00

by Rob Herring

[permalink] [raw]
Subject: [PATCH 20/28] arm64: set initrd_start/initrd_end for fdt scan

From: Rob Herring <[email protected]>

In order to unify the initrd scanning for DT across architectures, make
arm64 use initrd_start and initrd_end instead of the physical addresses.

Signed-off-by: Rob Herring <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: [email protected]
---
arch/arm64/mm/init.c | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index de2de5d..8261f4e 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -39,17 +39,9 @@

#include "mm.h"

-static unsigned long phys_initrd_start __initdata = 0;
-static unsigned long phys_initrd_size __initdata = 0;
-
phys_addr_t memstart_addr __read_mostly = 0;

-void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
-{
- phys_initrd_start = start;
- phys_initrd_size = end - start;
-}
-
+#ifdef CONFIG_BLK_DEV_INITRD
static int __init early_initrd(char *p)
{
unsigned long start, size;
@@ -59,12 +51,13 @@ static int __init early_initrd(char *p)
if (*endp == ',') {
size = memparse(endp + 1, NULL);

- phys_initrd_start = start;
- phys_initrd_size = size;
+ initrd_start = (unsigned long)__va(start);
+ initrd_end = (unsigned long)__va(start + size);
}
return 0;
}
early_param("initrd", early_initrd);
+#endif

#define MAX_DMA32_PFN ((4UL * 1024 * 1024 * 1024) >> PAGE_SHIFT)

@@ -137,13 +130,8 @@ void __init arm64_memblock_init(void)
/* Register the kernel text, kernel data and initrd with memblock */
memblock_reserve(__pa(_text), _end - _text);
#ifdef CONFIG_BLK_DEV_INITRD
- if (phys_initrd_size) {
- memblock_reserve(phys_initrd_start, phys_initrd_size);
-
- /* Now convert initrd to virtual addresses */
- initrd_start = __phys_to_virt(phys_initrd_start);
- initrd_end = initrd_start + phys_initrd_size;
- }
+ if (initrd_start)
+ memblock_reserve(__virt_to_phys(initrd_start), initrd_end - initrd_start);
#endif

/*
--
1.8.1.2

2013-09-16 23:10:03

by Rob Herring

[permalink] [raw]
Subject: [PATCH 19/28] arm: set initrd_start/initrd_end for fdt scan

From: Rob Herring <[email protected]>

In order to unify the initrd scanning for DT across architectures, make
arm set initrd_start and initrd_end instead of the physical addresses.
This is aligned with all other architectures.

Signed-off-by: Rob Herring <[email protected]>
Cc: Russell King <[email protected]>
Cc: [email protected]
---
arch/arm/mm/init.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index febaee7..9eeb1cd 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -77,11 +77,11 @@ static int __init parse_tag_initrd2(const struct tag *tag)

__tagtable(ATAG_INITRD2, parse_tag_initrd2);

-#ifdef CONFIG_OF_FLATTREE
+#if defined(CONFIG_OF_FLATTREE) && defined(CONFIG_BLK_DEV_INITRD)
void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
{
- phys_initrd_start = start;
- phys_initrd_size = end - start;
+ initrd_start = (unsigned long)__va(start);
+ initrd_end = (unsigned long)__va(end);
}
#endif /* CONFIG_OF_FLATTREE */

@@ -351,6 +351,11 @@ void __init arm_memblock_init(struct meminfo *mi,
memblock_reserve(__pa(_stext), _end - _stext);
#endif
#ifdef CONFIG_BLK_DEV_INITRD
+ /* FDT scan will populate initrd_start */
+ if (initrd_start) {
+ phys_initrd_start = __virt_to_phys(initrd_start);
+ phys_initrd_size = initrd_end - initrd_start;
+ }
if (phys_initrd_size &&
!memblock_is_region_memory(phys_initrd_start, phys_initrd_size)) {
pr_err("INITRD: 0x%08llx+0x%08lx is not a memory region - disabling initrd\n",
--
1.8.1.2

2013-09-16 23:10:45

by Rob Herring

[permalink] [raw]
Subject: [PATCH 28/28] mips: use common of_flat_dt_get_machine_name

From: Rob Herring <[email protected]>

Convert mips to use the common of_flat_dt_get_machine_name function.

Signed-off-by: Rob Herring <[email protected]>
Cc: Ralf Baechle <[email protected]>
Cc: [email protected]
---
arch/mips/kernel/prom.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/arch/mips/kernel/prom.c b/arch/mips/kernel/prom.c
index 0b2485f..3c3b0df 100644
--- a/arch/mips/kernel/prom.c
+++ b/arch/mips/kernel/prom.c
@@ -47,24 +47,11 @@ void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
return __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS));
}

-int __init early_init_dt_scan_model(unsigned long node, const char *uname,
- int depth, void *data)
-{
- if (!depth) {
- char *model = of_get_flat_dt_prop(node, "model", NULL);
-
- if (model)
- mips_set_machine_name(model);
- }
- return 0;
-}
-
void __init __dt_setup_arch(struct boot_param_header *bph)
{
if (!early_init_dt_scan(bph))
return;

- /* try to load the mips machine name */
- of_scan_flat_dt(early_init_dt_scan_model, NULL);
+ mips_set_machine_name(of_flat_dt_get_machine_name());
}
#endif
--
1.8.1.2

2013-09-16 23:11:06

by Rob Herring

[permalink] [raw]
Subject: [PATCH 26/28] arm64: use common of_flat_dt_get_machine_name

From: Rob Herring <[email protected]>

Convert arm64 to use the common of_flat_dt_get_machine_name function.

Signed-off-by: Rob Herring <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: [email protected]
---
arch/arm64/kernel/setup.c | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 3790004..4504f28 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -124,8 +124,6 @@ static void __init setup_processor(void)

static void __init setup_machine_fdt(phys_addr_t dt_phys)
{
- unsigned long dt_root;
-
if (!dt_phys || !early_init_dt_scan(phys_to_virt(dt_phys))) {
early_print("\n"
"Error: invalid device tree blob at physical address 0x%p (virtual address 0x%p)\n"
@@ -137,14 +135,7 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)
cpu_relax();
}

- dt_root = of_get_flat_dt_root();
-
- machine_name = of_get_flat_dt_prop(dt_root, "model", NULL);
- if (!machine_name)
- machine_name = of_get_flat_dt_prop(dt_root, "compatible", NULL);
- if (!machine_name)
- machine_name = "<unknown>";
- pr_info("Machine: %s\n", machine_name);
+ machine_name = of_flat_dt_get_machine_name();
}

/*
--
1.8.1.2

2013-09-16 23:11:10

by Rob Herring

[permalink] [raw]
Subject: [PATCH 25/28] arm: use common of_flat_dt_match_machine

From: Rob Herring <[email protected]>

Convert arm to use the common of_flat_dt_match_machine function.

Signed-off-by: Rob Herring <[email protected]>
Cc: Russell King <[email protected]>
Cc: [email protected]
---
arch/arm/kernel/devtree.c | 42 ++++++++++++++++++++----------------------
1 file changed, 20 insertions(+), 22 deletions(-)

diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
index 04050f7..cb918f6 100644
--- a/arch/arm/kernel/devtree.c
+++ b/arch/arm/kernel/devtree.c
@@ -174,6 +174,19 @@ bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
return (phys_id & MPIDR_HWID_BITMASK) == cpu_logical_map(cpu);
}

+static void * __init arch_get_next_mach(const char *const **match)
+{
+ static struct machine_desc *mdesc = __arch_info_begin;
+ struct machine_desc *m = mdesc;
+
+ if (m >= __arch_info_end)
+ return NULL;
+
+ mdesc++;
+ *match = m->dt_compat;
+ return m;
+}
+
/**
* setup_machine_fdt - Machine setup when an dtb was passed to the kernel
* @dt_phys: physical address of dt blob
@@ -184,9 +197,6 @@ bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
{
const struct machine_desc *mdesc, *mdesc_best = NULL;
- unsigned int score, mdesc_score = ~1;
- unsigned long dt_root;
- const char *model;

#ifdef CONFIG_ARCH_MULTIPLATFORM
DT_MACHINE_START(GENERIC_DT, "Generic DT based system")
@@ -199,23 +209,17 @@ const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
return NULL;

early_init_dt_scan(phys_to_virt(dt_phys));
+ mdesc = of_flat_dt_match_machine(mdesc_best, arch_get_next_mach);

- /* Search the mdescs for the 'best' compatible value match */
- dt_root = of_get_flat_dt_root();
- for_each_machine_desc(mdesc) {
- score = of_flat_dt_match(dt_root, mdesc->dt_compat);
- if (score > 0 && score < mdesc_score) {
- mdesc_best = mdesc;
- mdesc_score = score;
- }
- }
- if (!mdesc_best) {
+ if (!mdesc) {
const char *prop;
long size;
+ unsigned long dt_root;

early_print("\nError: unrecognized/unsupported "
"device tree compatible list:\n[ ");

+ dt_root = of_get_flat_dt_root();
prop = of_get_flat_dt_prop(dt_root, "compatible", &size);
while (size > 0) {
early_print("'%s' ", prop);
@@ -226,16 +230,10 @@ const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)

dump_machine_table(); /* does not return */
}
-
- model = of_get_flat_dt_prop(dt_root, "model", NULL);
- if (!model)
- model = of_get_flat_dt_prop(dt_root, "compatible", NULL);
- if (!model)
- model = "<unknown>";
- pr_info("Machine: %s, model: %s\n", mdesc_best->name, model);
+ early_print("matched mach %s\n", mdesc->name);

/* Change machine number to match the mdesc we're using */
- __machine_arch_type = mdesc_best->nr;
+ __machine_arch_type = mdesc->nr;

- return mdesc_best;
+ return mdesc;
}
--
1.8.1.2

2013-09-16 23:11:37

by Rob Herring

[permalink] [raw]
Subject: [PATCH 24/28] arc: use common of_flat_dt_match_machine

From: Rob Herring <[email protected]>

Convert arc to use the common of_flat_dt_match_machine function.

Signed-off-by: Rob Herring <[email protected]>
Cc: Vineet Gupta <[email protected]>
---
arch/arc/kernel/devtree.c | 65 +++++++++++++----------------------------------
1 file changed, 18 insertions(+), 47 deletions(-)

diff --git a/arch/arc/kernel/devtree.c b/arch/arc/kernel/devtree.c
index 1ab6f35..b45aa5a 100644
--- a/arch/arc/kernel/devtree.c
+++ b/arch/arc/kernel/devtree.c
@@ -18,6 +18,19 @@
#include <asm/clk.h>
#include <asm/mach_desc.h>

+static void * __init arch_get_next_mach(const char *const **match)
+{
+ static struct machine_desc *mdesc = __arch_info_begin;
+ struct machine_desc *m = mdesc;
+
+ if (m >= __arch_info_end)
+ return NULL;
+
+ mdesc++;
+ *match = m->dt_compat;
+ return m;
+}
+
/**
* setup_machine_fdt - Machine setup when an dtb was passed to the kernel
* @dt: virtual address pointer to dt blob
@@ -27,64 +40,22 @@
*/
struct machine_desc * __init setup_machine_fdt(void *dt)
{
- struct machine_desc *mdesc = NULL, *mdesc_best = NULL;
- unsigned int score, mdesc_score = ~1;
+ struct machine_desc *mdesc;
unsigned long dt_root;
- const char *model, *compat;
void *clk;
- char manufacturer[16];
unsigned long len;

if (!early_init_dt_scan(dt))
return NULL;

- dt_root = of_get_flat_dt_root();
-
- /*
- * The kernel could be multi-platform enabled, thus could have many
- * "baked-in" machine descriptors. Search thru all for the best
- * "compatible" string match.
- */
- for_each_machine_desc(mdesc) {
- score = of_flat_dt_match(dt_root, mdesc->dt_compat);
- if (score > 0 && score < mdesc_score) {
- mdesc_best = mdesc;
- mdesc_score = score;
- }
- }
- if (!mdesc_best) {
- const char *prop;
- long size;
-
- pr_err("\n unrecognized device tree list:\n[ ");
-
- prop = of_get_flat_dt_prop(dt_root, "compatible", &size);
- if (prop) {
- while (size > 0) {
- printk("'%s' ", prop);
- size -= strlen(prop) + 1;
- prop += strlen(prop) + 1;
- }
- }
- printk("]\n\n");
-
+ mdesc = of_flat_dt_match_machine(NULL, arch_get_next_mach);
+ if (!mdesc)
machine_halt();
- }
-
- /* compat = "<manufacturer>,<model>" */
- compat = mdesc_best->dt_compat[0];
-
- model = strchr(compat, ',');
- if (model)
- model++;
-
- strlcpy(manufacturer, compat, model ? model - compat : strlen(compat));
-
- pr_info("Board \"%s\" from %s (Manufacturer)\n", model, manufacturer);

+ dt_root = of_get_flat_dt_root();
clk = of_get_flat_dt_prop(dt_root, "clock-frequency", &len);
if (clk)
arc_set_core_freq(of_read_ulong(clk, len/4));

- return mdesc_best;
+ return mdesc;
}
--
1.8.1.2

2013-09-16 23:11:56

by Rob Herring

[permalink] [raw]
Subject: [PATCH 22/28] openrisc: remove unnecessary prom.c includes

From: Rob Herring <[email protected]>

It appears openrisc prom.c was just copied from another arch with a
bunch of unnecessary includes. Remove all the unecessary ones.

Signed-off-by: Rob Herring <[email protected]>
Cc: Jonas Bonn <[email protected]>
Cc: [email protected]
---
arch/openrisc/kernel/prom.c | 22 ----------------------
1 file changed, 22 deletions(-)

diff --git a/arch/openrisc/kernel/prom.c b/arch/openrisc/kernel/prom.c
index 2aae474..6a44340 100644
--- a/arch/openrisc/kernel/prom.c
+++ b/arch/openrisc/kernel/prom.c
@@ -18,34 +18,12 @@
*
*/

-#include <stdarg.h>
-#include <linux/kernel.h>
-#include <linux/string.h>
#include <linux/init.h>
-#include <linux/threads.h>
-#include <linux/spinlock.h>
#include <linux/types.h>
-#include <linux/pci.h>
-#include <linux/stringify.h>
-#include <linux/delay.h>
-#include <linux/initrd.h>
-#include <linux/bitops.h>
-#include <linux/module.h>
-#include <linux/kexec.h>
-#include <linux/debugfs.h>
-#include <linux/irq.h>
#include <linux/memblock.h>
#include <linux/of_fdt.h>

-#include <asm/prom.h>
#include <asm/page.h>
-#include <asm/processor.h>
-#include <asm/irq.h>
-#include <linux/io.h>
-#include <asm/mmu.h>
-#include <asm/pgtable.h>
-#include <asm/sections.h>
-#include <asm/setup.h>

void __init early_init_devtree(void *params)
{
--
1.8.1.2

2013-09-16 23:11:54

by Rob Herring

[permalink] [raw]
Subject: [PATCH 23/28] of: introduce common FDT machine related functions

From: Rob Herring <[email protected]>

Introduce common of_flat_dt_match_machine and
of_flat_dt_get_machine_name functions to unify architectures' handling
of machine level model and compatible properties.

Several architectures match the root compatible string with an arch
specific list of machine descriptors duplicating the same search
algorithm. Create a common implementation with a simple architecture
specific hook to iterate over each machine's match table.

Signed-off-by: Rob Herring <[email protected]>
Cc: Grant Likely <[email protected]>
---
drivers/of/fdt.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/of_fdt.h | 4 ++++
2 files changed, 64 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 83cdeb5..e21d1dc 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -619,6 +619,66 @@ int __init of_scan_flat_dt_by_path(const char *path,
return ret;
}

+const char *of_flat_dt_get_machine_name(void)
+{
+ const char *name;
+ unsigned long dt_root = of_get_flat_dt_root();
+
+ name = of_get_flat_dt_prop(dt_root, "model", NULL);
+ if (!name)
+ name = of_get_flat_dt_prop(dt_root, "compatible", NULL);
+ return name;
+}
+
+/**
+ * of_flat_dt_match_machine - Iterate match tables to find matching machine.
+ *
+ * @default_match: A machine specific ptr to return in case of no match.
+ * @get_next_compat: callback function to return next compatible match table.
+ *
+ * Iterate through machine match tables to find the best match for the machine
+ * compatible string in the FDT.
+ */
+void * __init of_flat_dt_match_machine(void *default_match,
+ void * (*get_next_compat)(const char * const**))
+{
+ void *data = NULL;
+ void *best_data = default_match;
+ const char *const *compat;
+ unsigned long dt_root;
+ unsigned int best_score = ~1, score = 0;
+
+ dt_root = of_get_flat_dt_root();
+ while ((data = get_next_compat(&compat))) {
+ score = of_flat_dt_match(dt_root, compat);
+ if (score > 0 && score < best_score) {
+ best_data = data;
+ best_score = score;
+ }
+ }
+ if (!best_data) {
+ const char *prop;
+ long size;
+
+ pr_err("\n unrecognized device tree list:\n[ ");
+
+ prop = of_get_flat_dt_prop(dt_root, "compatible", &size);
+ if (prop) {
+ while (size > 0) {
+ printk("'%s' ", prop);
+ size -= strlen(prop) + 1;
+ prop += strlen(prop) + 1;
+ }
+ }
+ printk("]\n\n");
+ return NULL;
+ }
+
+ pr_info("Machine model: %s\n", of_flat_dt_get_machine_name());
+
+ return best_data;
+}
+
#ifdef CONFIG_BLK_DEV_INITRD
/**
* early_init_dt_check_for_initrd - Decode initrd location from flat tree
diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
index b365f5a..985a744 100644
--- a/include/linux/of_fdt.h
+++ b/include/linux/of_fdt.h
@@ -108,6 +108,10 @@ extern int early_init_dt_scan_root(unsigned long node, const char *uname,

extern bool early_init_dt_scan(void *params);

+const char *of_flat_dt_get_machine_name(void);
+extern void *of_flat_dt_match_machine(void *default_match,
+ void * (*get_next_compat)(const char * const**));
+
/* Other Prototypes */
extern void unflatten_device_tree(void);
extern void unflatten_and_copy_device_tree(void);
--
1.8.1.2

2013-09-16 23:12:24

by Rob Herring

[permalink] [raw]
Subject: [PATCH 18/28] of: create default early_init_dt_add_memory_arch

From: Rob Herring <[email protected]>

Create a weak version of early_init_dt_add_memory_arch which uses
memblock or is an empty function when memblock is not enabled. This
will unify all architectures except ones with custom memory bank
structs.

Signed-off-by: Rob Herring <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: James Hogan <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Jonas Bonn <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]
Cc: Grant Likely <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
arch/arm64/kernel/setup.c | 18 ------------------
arch/metag/kernel/devtree.c | 6 ------
arch/microblaze/kernel/prom.c | 5 -----
arch/openrisc/kernel/prom.c | 6 ------
arch/x86/kernel/devicetree.c | 10 ----------
drivers/of/fdt.c | 11 +++++++++++
6 files changed, 11 insertions(+), 45 deletions(-)

diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index b4461e1..3790004 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -147,24 +147,6 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)
pr_info("Machine: %s\n", machine_name);
}

-void __init early_init_dt_add_memory_arch(u64 base, u64 size)
-{
- base &= PAGE_MASK;
- size &= PAGE_MASK;
- if (base + size < PHYS_OFFSET) {
- pr_warning("Ignoring memory block 0x%llx - 0x%llx\n",
- base, base + size);
- return;
- }
- if (base < PHYS_OFFSET) {
- pr_warning("Ignoring memory range 0x%llx - 0x%llx\n",
- base, PHYS_OFFSET);
- size -= PHYS_OFFSET - base;
- base = PHYS_OFFSET;
- }
- memblock_add(base, size);
-}
-
/*
* Limit the memory size that was specified via FDT.
*/
diff --git a/arch/metag/kernel/devtree.c b/arch/metag/kernel/devtree.c
index 049af56..2c6ee6d 100644
--- a/arch/metag/kernel/devtree.c
+++ b/arch/metag/kernel/devtree.c
@@ -23,12 +23,6 @@
#include <asm/page.h>
#include <asm/mach/arch.h>

-void __init early_init_dt_add_memory_arch(u64 base, u64 size)
-{
- pr_err("%s(%llx, %llx)\n",
- __func__, base, size);
-}
-
void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
{
return alloc_bootmem_align(size, align);
diff --git a/arch/microblaze/kernel/prom.c b/arch/microblaze/kernel/prom.c
index e13686e..951e4d6 100644
--- a/arch/microblaze/kernel/prom.c
+++ b/arch/microblaze/kernel/prom.c
@@ -41,11 +41,6 @@
#include <asm/sections.h>
#include <asm/pci-bridge.h>

-void __init early_init_dt_add_memory_arch(u64 base, u64 size)
-{
- memblock_add(base, size);
-}
-
#ifdef CONFIG_EARLY_PRINTK
static char *stdout;

diff --git a/arch/openrisc/kernel/prom.c b/arch/openrisc/kernel/prom.c
index fbed459..6dbcaa8 100644
--- a/arch/openrisc/kernel/prom.c
+++ b/arch/openrisc/kernel/prom.c
@@ -47,12 +47,6 @@
#include <asm/sections.h>
#include <asm/setup.h>

-void __init early_init_dt_add_memory_arch(u64 base, u64 size)
-{
- size &= PAGE_MASK;
- memblock_add(base, size);
-}
-
void __init early_init_devtree(void *params)
{
early_init_dt_scan(params);
diff --git a/arch/x86/kernel/devicetree.c b/arch/x86/kernel/devicetree.c
index 0db805c..2f5cb37 100644
--- a/arch/x86/kernel/devicetree.c
+++ b/arch/x86/kernel/devicetree.c
@@ -36,16 +36,6 @@ unsigned long pci_address_to_pio(phys_addr_t address)
}
EXPORT_SYMBOL_GPL(pci_address_to_pio);

-void __init early_init_dt_scan_chosen_arch(unsigned long node)
-{
- BUG();
-}
-
-void __init early_init_dt_add_memory_arch(u64 base, u64 size)
-{
- BUG();
-}
-
void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
{
return __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS));
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 0714dd4..a9dce7a 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -688,6 +688,17 @@ u64 __init dt_mem_next_cell(int s, __be32 **cellp)
return of_read_number(p, s);
}

+void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
+{
+#ifdef CONFIG_HAVE_MEMBLOCK
+ base &= PAGE_MASK;
+ size &= PAGE_MASK;
+ memblock_add(base, size);
+#else
+ pr_err("%s: ignoring memory (%llx, %llx)\n", __func__, base, size);
+#endif
+}
+
/**
* early_init_dt_scan_memory - Look for an parse memory nodes
*/
--
1.8.1.2

2013-09-16 23:09:47

by Rob Herring

[permalink] [raw]
Subject: [PATCH 08/28] metag: use unflatten_and_copy_device_tree

From: Rob Herring <[email protected]>

Use the common unflatten_and_copy_device_tree to copy the built-in FDT
out of init section.

Signed-off-by: Rob Herring <[email protected]>
Cc: James Hogan <[email protected]>
---
arch/metag/kernel/devtree.c | 16 ----------------
arch/metag/kernel/setup.c | 4 +---
2 files changed, 1 insertion(+), 19 deletions(-)

diff --git a/arch/metag/kernel/devtree.c b/arch/metag/kernel/devtree.c
index 7cd0252..049af56 100644
--- a/arch/metag/kernel/devtree.c
+++ b/arch/metag/kernel/devtree.c
@@ -94,21 +94,5 @@ struct machine_desc * __init setup_machine_fdt(void *dt)
of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);

return mdesc_best;
-}

-/**
- * copy_fdt - Copy device tree into non-init memory.
- *
- * We must copy the flattened device tree blob into non-init memory because the
- * unflattened device tree will reference the strings in it directly.
- */
-void __init copy_fdt(void)
-{
- void *alloc = early_init_dt_alloc_memory_arch(
- be32_to_cpu(initial_boot_params->totalsize), 0x40);
- if (alloc) {
- memcpy(alloc, initial_boot_params,
- be32_to_cpu(initial_boot_params->totalsize));
- initial_boot_params = alloc;
- }
}
diff --git a/arch/metag/kernel/setup.c b/arch/metag/kernel/setup.c
index c396cd0..2c697d3 100644
--- a/arch/metag/kernel/setup.c
+++ b/arch/metag/kernel/setup.c
@@ -408,9 +408,7 @@ void __init setup_arch(char **cmdline_p)
cpu_2_hwthread_id[smp_processor_id()] = hard_processor_id();
hwthread_id_2_cpu[hard_processor_id()] = smp_processor_id();

- /* Copy device tree blob into non-init memory before unflattening */
- copy_fdt();
- unflatten_device_tree();
+ unflatten_and_copy_device_tree();

#ifdef CONFIG_SMP
smp_init_cpus();
--
1.8.1.2

2013-09-16 23:12:45

by Rob Herring

[permalink] [raw]
Subject: [PATCH 17/28] xtensa: use early_init_dt_scan

From: Rob Herring <[email protected]>

Convert xtensa to use new early_init_dt_scan function.

Signed-off-by: Rob Herring <[email protected]>
Cc: Chris Zankel <[email protected]>
Cc: Max Filippov <[email protected]>
Cc: [email protected]
---
arch/xtensa/kernel/setup.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c
index fc31ec1..65974a8 100644
--- a/arch/xtensa/kernel/setup.c
+++ b/arch/xtensa/kernel/setup.c
@@ -219,9 +219,13 @@ static int __init parse_bootparam(const bp_tag_t* tag)
}

#ifdef CONFIG_OF
+bool __initdata dt_memory_scan = false;

void __init early_init_dt_add_memory_arch(u64 base, u64 size)
{
+ if (!dt_memory_scan)
+ return;
+
size &= PAGE_MASK;
add_sysmem_bank(MEMORY_TYPE_CONVENTIONAL, base, base + size);
}
@@ -233,20 +237,13 @@ void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)

void __init early_init_devtree(void *params)
{
- /* Setup flat device-tree pointer */
- initial_boot_params = params;
+ if (sysmem.nr_banks == 0)
+ dt_memory_scan = true;

- /* Retrieve various informations from the /chosen node of the
- * device-tree, including the platform type, initrd location and
- * size, TCE reserve, and more ...
- */
- if (!command_line[0])
- of_scan_flat_dt(early_init_dt_scan_chosen, command_line);
+ early_init_dt_scan(params);

- /* Scan memory nodes and rebuild MEMBLOCKs */
- of_scan_flat_dt(early_init_dt_scan_root, NULL);
- if (sysmem.nr_banks == 0)
- of_scan_flat_dt(early_init_dt_scan_memory, NULL);
+ if (!command_line[0])
+ strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
}

static int __init xtensa_device_probe(void)
--
1.8.1.2

2013-09-16 23:13:04

by Rob Herring

[permalink] [raw]
Subject: [PATCH 16/28] openrisc: use early_init_dt_scan

From: Rob Herring <[email protected]>

Convert openrisc to use new early_init_dt_scan function.

Signed-off-by: Rob Herring <[email protected]>
Cc: Jonas Bonn <[email protected]>
Cc: [email protected]
---
arch/openrisc/kernel/prom.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/arch/openrisc/kernel/prom.c b/arch/openrisc/kernel/prom.c
index 3b94972..fbed459 100644
--- a/arch/openrisc/kernel/prom.c
+++ b/arch/openrisc/kernel/prom.c
@@ -55,20 +55,7 @@ void __init early_init_dt_add_memory_arch(u64 base, u64 size)

void __init early_init_devtree(void *params)
{
- /* Setup flat device-tree pointer */
- initial_boot_params = params;
-
-
- /* Retrieve various informations from the /chosen node of the
- * device-tree, including the platform type, initrd location and
- * size, TCE reserve, and more ...
- */
- of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
-
- /* Scan memory nodes and rebuild MEMBLOCKs */
- of_scan_flat_dt(early_init_dt_scan_root, NULL);
- of_scan_flat_dt(early_init_dt_scan_memory, NULL);
-
+ early_init_dt_scan(params);
memblock_allow_resize();
}

--
1.8.1.2

2013-09-16 23:13:27

by Rob Herring

[permalink] [raw]
Subject: [PATCH 14/28] microblaze: use early_init_dt_scan

From: Rob Herring <[email protected]>

Convert microblaze to use new early_init_dt_scan function.

Signed-off-by: Rob Herring <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: [email protected]
---
arch/microblaze/kernel/prom.c | 17 +++--------------
arch/microblaze/kernel/setup.c | 2 +-
2 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/arch/microblaze/kernel/prom.c b/arch/microblaze/kernel/prom.c
index 0c4453f..e13686e 100644
--- a/arch/microblaze/kernel/prom.c
+++ b/arch/microblaze/kernel/prom.c
@@ -106,21 +106,10 @@ void __init early_init_devtree(void *params)
{
pr_debug(" -> early_init_devtree(%p)\n", params);

- /* Setup flat device-tree pointer */
- initial_boot_params = params;
+ early_init_dt_scan(params);
+ if (!strlen(boot_command_line))
+ strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);

- /* Retrieve various informations from the /chosen node of the
- * device-tree, including the platform type, initrd location and
- * size, TCE reserve, and more ...
- */
- of_scan_flat_dt(early_init_dt_scan_chosen, cmd_line);
-
- /* Scan memory nodes and rebuild MEMBLOCKs */
- of_scan_flat_dt(early_init_dt_scan_root, NULL);
- of_scan_flat_dt(early_init_dt_scan_memory, NULL);
-
- /* Save command line for /proc/cmdline and then parse parameters */
- strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
parse_early_param();

memblock_allow_resize();
diff --git a/arch/microblaze/kernel/setup.c b/arch/microblaze/kernel/setup.c
index 0775e03..6c4efba 100644
--- a/arch/microblaze/kernel/setup.c
+++ b/arch/microblaze/kernel/setup.c
@@ -50,7 +50,7 @@ char cmd_line[COMMAND_LINE_SIZE] __attribute__ ((section(".data")));

void __init setup_arch(char **cmdline_p)
{
- *cmdline_p = cmd_line;
+ *cmdline_p = boot_command_line;

console_verbose();

--
1.8.1.2

2013-09-16 23:13:48

by Rob Herring

[permalink] [raw]
Subject: [PATCH 13/28] c6x: use early_init_dt_scan

From: Rob Herring <[email protected]>

Convert c6x to use new early_init_dt_scan function.

Signed-off-by: Rob Herring <[email protected]>
Cc: Mark Salter <[email protected]>
Cc: Aurelien Jacquiot <[email protected]>
Cc: [email protected]
---
arch/c6x/kernel/devicetree.c | 19 -------------------
arch/c6x/kernel/setup.c | 2 +-
2 files changed, 1 insertion(+), 20 deletions(-)

diff --git a/arch/c6x/kernel/devicetree.c b/arch/c6x/kernel/devicetree.c
index 5e8c838..d28a92f 100644
--- a/arch/c6x/kernel/devicetree.c
+++ b/arch/c6x/kernel/devicetree.c
@@ -10,28 +10,9 @@
*
*/
#include <linux/init.h>
-#include <linux/of.h>
-#include <linux/of_fdt.h>
#include <linux/initrd.h>
#include <linux/memblock.h>

-void __init early_init_devtree(void *params)
-{
- /* Setup flat device-tree pointer */
- initial_boot_params = params;
-
- /* Retrieve various informations from the /chosen node of the
- * device-tree, including the platform type, initrd location and
- * size and more ...
- */
- of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
-
- /* Scan memory nodes and rebuild MEMBLOCKs */
- of_scan_flat_dt(early_init_dt_scan_root, NULL);
- of_scan_flat_dt(early_init_dt_scan_memory, NULL);
-}
-
-
#ifdef CONFIG_BLK_DEV_INITRD
void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
{
diff --git a/arch/c6x/kernel/setup.c b/arch/c6x/kernel/setup.c
index 0e5a812..731db4b 100644
--- a/arch/c6x/kernel/setup.c
+++ b/arch/c6x/kernel/setup.c
@@ -287,7 +287,7 @@ notrace void __init machine_init(unsigned long dt_ptr)
fdt = dtb;

/* Do some early initialization based on the flat device tree */
- early_init_devtree(fdt);
+ early_init_dt_scan(fdt);

parse_early_param();
}
--
1.8.1.2

2013-09-16 23:14:03

by Rob Herring

[permalink] [raw]
Subject: [PATCH 12/28] arm64: use early_init_dt_scan

From: Rob Herring <[email protected]>

Convert arm64 to use new early_init_dt_scan function.

Signed-off-by: Rob Herring <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: [email protected]
---
arch/arm64/kernel/setup.c | 31 +++----------------------------
1 file changed, 3 insertions(+), 28 deletions(-)

diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 12ad8f3..b4461e1 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -124,37 +124,19 @@ static void __init setup_processor(void)

static void __init setup_machine_fdt(phys_addr_t dt_phys)
{
- struct boot_param_header *devtree;
unsigned long dt_root;

- /* Check we have a non-NULL DT pointer */
- if (!dt_phys) {
- early_print("\n"
- "Error: NULL or invalid device tree blob\n"
- "The dtb must be 8-byte aligned and passed in the first 512MB of memory\n"
- "\nPlease check your bootloader.\n");
-
- while (true)
- cpu_relax();
-
- }
-
- devtree = phys_to_virt(dt_phys);
-
- /* Check device tree validity */
- if (be32_to_cpu(devtree->magic) != OF_DT_HEADER) {
+ if (!dt_phys || !early_init_dt_scan(phys_to_virt(dt_phys))) {
early_print("\n"
"Error: invalid device tree blob at physical address 0x%p (virtual address 0x%p)\n"
- "Expected 0x%x, found 0x%x\n"
+ "The dtb must be 8-byte aligned and passed in the first 512MB of memory\n"
"\nPlease check your bootloader.\n",
- dt_phys, devtree, OF_DT_HEADER,
- be32_to_cpu(devtree->magic));
+ dt_phys, phys_to_virt(dt_phys));

while (true)
cpu_relax();
}

- initial_boot_params = devtree;
dt_root = of_get_flat_dt_root();

machine_name = of_get_flat_dt_prop(dt_root, "model", NULL);
@@ -163,13 +145,6 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)
if (!machine_name)
machine_name = "<unknown>";
pr_info("Machine: %s\n", machine_name);
-
- /* Retrieve various information from the /chosen node */
- of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
- /* Initialize {size,address}-cells info */
- of_scan_flat_dt(early_init_dt_scan_root, NULL);
- /* Setup memory, calling early_init_dt_add_memory_arch */
- of_scan_flat_dt(early_init_dt_scan_memory, NULL);
}

void __init early_init_dt_add_memory_arch(u64 base, u64 size)
--
1.8.1.2

2013-09-16 23:09:42

by Rob Herring

[permalink] [raw]
Subject: [PATCH 04/28] arc: use unflatten_and_copy_device_tree

From: Rob Herring <[email protected]>

Use the common unflatten_and_copy_device_tree to copy the built-in FDT
out of init section.

Signed-off-by: Rob Herring <[email protected]>
Cc: Vineet Gupta <[email protected]>
---
arch/arc/include/asm/mach_desc.h | 1 -
arch/arc/kernel/devtree.c | 15 ---------------
arch/arc/kernel/setup.c | 3 +--
3 files changed, 1 insertion(+), 18 deletions(-)

diff --git a/arch/arc/include/asm/mach_desc.h b/arch/arc/include/asm/mach_desc.h
index 9998dc8..d3e9c0a 100644
--- a/arch/arc/include/asm/mach_desc.h
+++ b/arch/arc/include/asm/mach_desc.h
@@ -82,6 +82,5 @@ __attribute__((__section__(".arch.info.init"))) = { \
};

extern struct machine_desc *setup_machine_fdt(void *dt);
-extern void __init copy_devtree(void);

#endif
diff --git a/arch/arc/kernel/devtree.c b/arch/arc/kernel/devtree.c
index 2340af0..eeb613a 100644
--- a/arch/arc/kernel/devtree.c
+++ b/arch/arc/kernel/devtree.c
@@ -100,18 +100,3 @@ struct machine_desc * __init setup_machine_fdt(void *dt)

return mdesc_best;
}
-
-/*
- * Copy the flattened DT out of .init since unflattening doesn't copy strings
- * and the normal DT APIs refs them from orig flat DT
- */
-void __init copy_devtree(void)
-{
- void *alloc = early_init_dt_alloc_memory_arch(
- be32_to_cpu(initial_boot_params->totalsize), 64);
- if (alloc) {
- memcpy(alloc, initial_boot_params,
- be32_to_cpu(initial_boot_params->totalsize));
- initial_boot_params = alloc;
- }
-}
diff --git a/arch/arc/kernel/setup.c b/arch/arc/kernel/setup.c
index 2c68bc7e..710bf89 100644
--- a/arch/arc/kernel/setup.c
+++ b/arch/arc/kernel/setup.c
@@ -346,8 +346,7 @@ void __init setup_arch(char **cmdline_p)
setup_arch_memory();

/* copy flat DT out of .init and then unflatten it */
- copy_devtree();
- unflatten_device_tree();
+ unflatten_and_copy_device_tree();

/* Can be issue if someone passes cmd line arg "ro"
* But that is unlikely so keeping it as it is
--
1.8.1.2

2013-09-16 23:14:30

by Rob Herring

[permalink] [raw]
Subject: [PATCH 10/28] arc: use early_init_dt_scan

From: Rob Herring <[email protected]>

Convert arc to use new early_init_dt_scan function.

Signed-off-by: Rob Herring <[email protected]>
Cc: Vineet Gupta <[email protected]>
---
arch/arc/kernel/devtree.c | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/arch/arc/kernel/devtree.c b/arch/arc/kernel/devtree.c
index eeb613a..1ab6f35 100644
--- a/arch/arc/kernel/devtree.c
+++ b/arch/arc/kernel/devtree.c
@@ -27,7 +27,6 @@
*/
struct machine_desc * __init setup_machine_fdt(void *dt)
{
- struct boot_param_header *devtree = dt;
struct machine_desc *mdesc = NULL, *mdesc_best = NULL;
unsigned int score, mdesc_score = ~1;
unsigned long dt_root;
@@ -36,11 +35,9 @@ struct machine_desc * __init setup_machine_fdt(void *dt)
char manufacturer[16];
unsigned long len;

- /* check device tree validity */
- if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
+ if (!early_init_dt_scan(dt))
return NULL;

- initial_boot_params = devtree;
dt_root = of_get_flat_dt_root();

/*
@@ -85,15 +82,6 @@ struct machine_desc * __init setup_machine_fdt(void *dt)

pr_info("Board \"%s\" from %s (Manufacturer)\n", model, manufacturer);

- /* Retrieve various information from the /chosen node */
- of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
-
- /* Initialize {size,address}-cells info */
- of_scan_flat_dt(early_init_dt_scan_root, NULL);
-
- /* Setup memory, calling early_init_dt_add_memory_arch */
- of_scan_flat_dt(early_init_dt_scan_memory, NULL);
-
clk = of_get_flat_dt_prop(dt_root, "clock-frequency", &len);
if (clk)
arc_set_core_freq(of_read_ulong(clk, len/4));
--
1.8.1.2

2013-09-16 23:14:27

by Rob Herring

[permalink] [raw]
Subject: [PATCH 11/28] arm: use early_init_dt_scan

From: Rob Herring <[email protected]>

Convert arm to use new early_init_dt_scan function.

Signed-off-by: Rob Herring <[email protected]>
Cc: Russell King <[email protected]>
Cc: [email protected]
---
arch/arm/kernel/devtree.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
index f35906b..04050f7 100644
--- a/arch/arm/kernel/devtree.c
+++ b/arch/arm/kernel/devtree.c
@@ -183,7 +183,6 @@ bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
*/
const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
{
- struct boot_param_header *devtree;
const struct machine_desc *mdesc, *mdesc_best = NULL;
unsigned int score, mdesc_score = ~1;
unsigned long dt_root;
@@ -199,14 +198,9 @@ const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
if (!dt_phys)
return NULL;

- devtree = phys_to_virt(dt_phys);
-
- /* check device tree validity */
- if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
- return NULL;
+ early_init_dt_scan(phys_to_virt(dt_phys));

/* Search the mdescs for the 'best' compatible value match */
- initial_boot_params = devtree;
dt_root = of_get_flat_dt_root();
for_each_machine_desc(mdesc) {
score = of_flat_dt_match(dt_root, mdesc->dt_compat);
@@ -240,13 +234,6 @@ const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
model = "<unknown>";
pr_info("Machine: %s, model: %s\n", mdesc_best->name, model);

- /* Retrieve various information from the /chosen node */
- of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
- /* Initialize {size,address}-cells info */
- of_scan_flat_dt(early_init_dt_scan_root, NULL);
- /* Setup memory, calling early_init_dt_add_memory_arch */
- of_scan_flat_dt(early_init_dt_scan_memory, NULL);
-
/* Change machine number to match the mdesc we're using */
__machine_arch_type = mdesc_best->nr;

--
1.8.1.2

2013-09-16 23:14:57

by Rob Herring

[permalink] [raw]
Subject: [PATCH 09/28] of: Introduce common early_init_dt_scan

From: Rob Herring <[email protected]>

Most architectures scan the all the same items early in the FDT and none
are really architecture specific. Create a common early_init_dt_scan to
unify the early scan of root, memory, and chosen nodes in the flattened
DT.

Signed-off-by: Rob Herring <[email protected]>
Cc: Grant Likely <[email protected]>
---
drivers/of/fdt.c | 18 ++++++++++++++++++
include/linux/of_fdt.h | 2 ++
2 files changed, 20 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index eca1810..0714dd4 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -785,6 +785,24 @@ void * __init __weak early_init_dt_alloc_memory_arch(u64 size, u64 align)
}
#endif

+bool __init early_init_dt_scan(void *params)
+{
+ /* Setup flat device-tree pointer */
+ initial_boot_params = params;
+
+ /* check device tree validity */
+ if (be32_to_cpu(initial_boot_params->magic) != OF_DT_HEADER)
+ return false;
+
+ /* Retrieve various information from the /chosen node */
+ of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
+ /* Initialize {size,address}-cells info */
+ of_scan_flat_dt(early_init_dt_scan_root, NULL);
+ /* Setup memory, calling early_init_dt_add_memory_arch */
+ of_scan_flat_dt(early_init_dt_scan_memory, NULL);
+ return true;
+}
+
/**
* unflatten_device_tree - create tree of device_nodes from flat blob
*
diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
index 58c28a8..73e1651 100644
--- a/include/linux/of_fdt.h
+++ b/include/linux/of_fdt.h
@@ -116,6 +116,8 @@ extern void early_init_dt_setup_initrd_arch(u64 start, u64 end);
extern int early_init_dt_scan_root(unsigned long node, const char *uname,
int depth, void *data);

+extern bool early_init_dt_scan(void *params);
+
/* Other Prototypes */
extern void unflatten_device_tree(void);
extern void unflatten_and_copy_device_tree(void);
--
1.8.1.2

2013-09-16 23:15:23

by Rob Herring

[permalink] [raw]
Subject: [PATCH 06/28] x86: use unflatten_and_copy_device_tree

From: Rob Herring <[email protected]>

Use the common unflatten_and_copy_device_tree to copy the built-in FDT
out of init section.

Signed-off-by: Rob Herring <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]
---
arch/x86/kernel/devicetree.c | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/arch/x86/kernel/devicetree.c b/arch/x86/kernel/devicetree.c
index 376dc78..0db805c 100644
--- a/arch/x86/kernel/devicetree.c
+++ b/arch/x86/kernel/devicetree.c
@@ -230,7 +230,7 @@ static void __init dtb_apic_setup(void)
static void __init x86_flattree_get_config(void)
{
u32 size, map_len;
- void *new_dtb;
+ struct boot_param_header *dt;

if (!initial_dtb)
return;
@@ -238,24 +238,17 @@ static void __init x86_flattree_get_config(void)
map_len = max(PAGE_SIZE - (initial_dtb & ~PAGE_MASK),
(u64)sizeof(struct boot_param_header));

- initial_boot_params = early_memremap(initial_dtb, map_len);
- size = be32_to_cpu(initial_boot_params->totalsize);
+ dt = early_memremap(initial_dtb, map_len);
+ size = be32_to_cpu(dt->totalsize);
if (map_len < size) {
- early_iounmap(initial_boot_params, map_len);
- initial_boot_params = early_memremap(initial_dtb, size);
+ early_iounmap(dt, map_len);
+ dt = early_memremap(initial_dtb, size);
map_len = size;
}

- new_dtb = alloc_bootmem(size);
- memcpy(new_dtb, initial_boot_params, size);
- early_iounmap(initial_boot_params, map_len);
-
- initial_boot_params = new_dtb;
-
- /* root level address cells */
- of_scan_flat_dt(early_init_dt_scan_root, NULL);
-
- unflatten_device_tree();
+ initial_boot_params = dt;
+ unflatten_and_copy_device_tree();
+ early_iounmap(dt, map_len);
}
#else
static inline void x86_flattree_get_config(void) { }
--
1.8.1.2

2013-09-16 23:15:20

by Rob Herring

[permalink] [raw]
Subject: [PATCH 07/28] xtensa: use unflatten_and_copy_device_tree

From: Rob Herring <[email protected]>

Use the common unflatten_and_copy_device_tree to copy the built-in FDT
out of init section.

Signed-off-by: Rob Herring <[email protected]>
Cc: Chris Zankel <[email protected]>
Cc: Max Filippov <[email protected]>
Cc: [email protected]
---
arch/xtensa/kernel/setup.c | 19 +------------------
1 file changed, 1 insertion(+), 18 deletions(-)

diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c
index 946fb8d..fc31ec1 100644
--- a/arch/xtensa/kernel/setup.c
+++ b/arch/xtensa/kernel/setup.c
@@ -21,11 +21,8 @@
#include <linux/screen_info.h>
#include <linux/bootmem.h>
#include <linux/kernel.h>
-
-#ifdef CONFIG_OF
#include <linux/of_fdt.h>
#include <linux/of_platform.h>
-#endif

#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
# include <linux/console.h>
@@ -252,17 +249,6 @@ void __init early_init_devtree(void *params)
of_scan_flat_dt(early_init_dt_scan_memory, NULL);
}

-static void __init copy_devtree(void)
-{
- void *alloc = early_init_dt_alloc_memory_arch(
- be32_to_cpu(initial_boot_params->totalsize), 8);
- if (alloc) {
- memcpy(alloc, initial_boot_params,
- be32_to_cpu(initial_boot_params->totalsize));
- initial_boot_params = alloc;
- }
-}
-
static int __init xtensa_device_probe(void)
{
of_platform_populate(NULL, NULL, NULL, NULL);
@@ -525,10 +511,7 @@ void __init setup_arch(char **cmdline_p)

bootmem_init();

-#ifdef CONFIG_OF
- copy_devtree();
- unflatten_device_tree();
-#endif
+ unflatten_and_copy_device_tree();

platform_setup(cmdline_p);

--
1.8.1.2

2013-09-16 23:15:58

by Rob Herring

[permalink] [raw]
Subject: [PATCH 03/28] of: create unflatten_and_copy_device_tree

From: Rob Herring <[email protected]>

Several architectures using DT support built-in dtb's in the init
section. These platforms need to copy the dtb from init since the
strings are referenced after unflattening. Every arch has their own
copying routine which do the same thing. Create a common function,
unflatten_and_copy_device_tree, to copy the dtb when unflattening the
dtb.

Signed-off-by: Rob Herring <[email protected]>
Cc: Grant Likely <[email protected]>
---
drivers/of/fdt.c | 13 +++++++++++++
include/linux/of_fdt.h | 2 ++
2 files changed, 15 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 229dd9d..eca1810 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -802,6 +802,19 @@ void __init unflatten_device_tree(void)
of_alias_scan(early_init_dt_alloc_memory_arch);
}

+void __init unflatten_and_copy_device_tree(void)
+{
+ int size = __be32_to_cpu(initial_boot_params->totalsize);
+ void *dt = early_init_dt_alloc_memory_arch(size,
+ __alignof__(struct boot_param_header));
+
+ if (dt) {
+ memcpy(dt, initial_boot_params, size);
+ initial_boot_params = dt;
+ }
+ unflatten_device_tree();
+}
+
#endif /* CONFIG_OF_EARLY_FLATTREE */

/* Feed entire flattened device tree into the random pool */
diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
index a478c62..58c28a8 100644
--- a/include/linux/of_fdt.h
+++ b/include/linux/of_fdt.h
@@ -118,9 +118,11 @@ extern int early_init_dt_scan_root(unsigned long node, const char *uname,

/* Other Prototypes */
extern void unflatten_device_tree(void);
+extern void unflatten_and_copy_device_tree(void);
extern void early_init_devtree(void *);
#else /* CONFIG_OF_FLATTREE */
static inline void unflatten_device_tree(void) {}
+static inline void unflatten_and_copy_device_tree(void) {}
#endif /* CONFIG_OF_FLATTREE */

#endif /* __ASSEMBLY__ */
--
1.8.1.2

2013-09-16 23:16:17

by Rob Herring

[permalink] [raw]
Subject: [PATCH 02/28] openrisc: use boot_command_line instead of private cmd_line

From: Rob Herring <[email protected]>

Save some pointless copying of the kernel command line and just use
boot_command_line instead. The DT code already handles CONFIG_CMDLINE,
so a separate copy is not needed.

Signed-off-by: Rob Herring <[email protected]>
Cc: Jonas Bonn <[email protected]>
Cc: [email protected]
---
arch/openrisc/kernel/prom.c | 7 +------
arch/openrisc/kernel/setup.c | 4 +---
2 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/arch/openrisc/kernel/prom.c b/arch/openrisc/kernel/prom.c
index a63e768..bf3fd05 100644
--- a/arch/openrisc/kernel/prom.c
+++ b/arch/openrisc/kernel/prom.c
@@ -47,8 +47,6 @@
#include <asm/sections.h>
#include <asm/setup.h>

-extern char cmd_line[COMMAND_LINE_SIZE];
-
void __init early_init_dt_add_memory_arch(u64 base, u64 size)
{
size &= PAGE_MASK;
@@ -67,15 +65,12 @@ void __init early_init_devtree(void *params)
* device-tree, including the platform type, initrd location and
* size, TCE reserve, and more ...
*/
- of_scan_flat_dt(early_init_dt_scan_chosen, cmd_line);
+ of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);

/* Scan memory nodes and rebuild MEMBLOCKs */
of_scan_flat_dt(early_init_dt_scan_root, NULL);
of_scan_flat_dt(early_init_dt_scan_memory, NULL);

- /* Save command line for /proc/cmdline and then parse parameters */
- strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
-
memblock_allow_resize();

/* We must copy the flattend device tree from init memory to regular
diff --git a/arch/openrisc/kernel/setup.c b/arch/openrisc/kernel/setup.c
index d7359ff..719c5c8 100644
--- a/arch/openrisc/kernel/setup.c
+++ b/arch/openrisc/kernel/setup.c
@@ -50,8 +50,6 @@

#include "vmlinux.h"

-char __initdata cmd_line[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
-
static unsigned long __init setup_memory(void)
{
unsigned long bootmap_size;
@@ -316,7 +314,7 @@ void __init setup_arch(char **cmdline_p)
conswitchp = &dummy_con;
#endif

- *cmdline_p = cmd_line;
+ *cmdline_p = boot_command_line;

printk(KERN_INFO "OpenRISC Linux -- http://openrisc.net\n");
}
--
1.8.1.2

2013-09-16 23:16:22

by Rob Herring

[permalink] [raw]
Subject: [PATCH 01/28] c6x: use boot_command_line instead of private c6x_command_line

From: Rob Herring <[email protected]>

Save some pointless copying of the kernel command line and just use
boot_command_line instead.

Also remove default_command_line as it is not referenced anywhere, and
the DT code already handles the default command line.

Signed-off-by: Rob Herring <[email protected]>
Cc: Mark Salter <[email protected]>
Cc: Aurelien Jacquiot <[email protected]>
Cc: [email protected]
---
arch/c6x/include/asm/setup.h | 2 --
arch/c6x/kernel/devicetree.c | 2 +-
arch/c6x/kernel/setup.c | 11 +----------
3 files changed, 2 insertions(+), 13 deletions(-)

diff --git a/arch/c6x/include/asm/setup.h b/arch/c6x/include/asm/setup.h
index ecead15..6968044 100644
--- a/arch/c6x/include/asm/setup.h
+++ b/arch/c6x/include/asm/setup.h
@@ -14,8 +14,6 @@
#include <uapi/asm/setup.h>

#ifndef __ASSEMBLY__
-extern char c6x_command_line[COMMAND_LINE_SIZE];
-
extern int c6x_add_memory(phys_addr_t start, unsigned long size);

extern unsigned long ram_start;
diff --git a/arch/c6x/kernel/devicetree.c b/arch/c6x/kernel/devicetree.c
index 9e15ab9..5e8c838 100644
--- a/arch/c6x/kernel/devicetree.c
+++ b/arch/c6x/kernel/devicetree.c
@@ -24,7 +24,7 @@ void __init early_init_devtree(void *params)
* device-tree, including the platform type, initrd location and
* size and more ...
*/
- of_scan_flat_dt(early_init_dt_scan_chosen, c6x_command_line);
+ of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);

/* Scan memory nodes and rebuild MEMBLOCKs */
of_scan_flat_dt(early_init_dt_scan_root, NULL);
diff --git a/arch/c6x/kernel/setup.c b/arch/c6x/kernel/setup.c
index f4e72bd..0e5a812 100644
--- a/arch/c6x/kernel/setup.c
+++ b/arch/c6x/kernel/setup.c
@@ -68,13 +68,6 @@ unsigned long ram_end;
static unsigned long dma_start __initdata;
static unsigned long dma_size __initdata;

-char c6x_command_line[COMMAND_LINE_SIZE];
-
-#if defined(CONFIG_CMDLINE_BOOL)
-static const char default_command_line[COMMAND_LINE_SIZE] __section(.cmdline) =
- CONFIG_CMDLINE;
-#endif
-
struct cpuinfo_c6x {
const char *cpu_name;
const char *cpu_voltage;
@@ -296,8 +289,6 @@ notrace void __init machine_init(unsigned long dt_ptr)
/* Do some early initialization based on the flat device tree */
early_init_devtree(fdt);

- /* parse_early_param needs a boot_command_line */
- strlcpy(boot_command_line, c6x_command_line, COMMAND_LINE_SIZE);
parse_early_param();
}

@@ -309,7 +300,7 @@ void __init setup_arch(char **cmdline_p)
printk(KERN_INFO "Initializing kernel\n");

/* Initialize command line */
- *cmdline_p = c6x_command_line;
+ *cmdline_p = boot_command_line;

memory_end = ram_end;
memory_end &= ~(PAGE_SIZE - 1);
--
1.8.1.2

2013-09-17 04:32:53

by John Crispin

[permalink] [raw]
Subject: Re: [PATCH 28/28] mips: use common of_flat_dt_get_machine_name

On 17/09/13 01:09, Rob Herring wrote:
> From: Rob Herring<[email protected]>
>
> Convert mips to use the common of_flat_dt_get_machine_name function.
>
> Signed-off-by: Rob Herring<[email protected]>
> Cc: Ralf Baechle<[email protected]>
> Cc: [email protected]
> ---


Acked-by: John Crispin <[email protected]>


Thanks for this series ...



> arch/mips/kernel/prom.c | 15 +--------------
> 1 file changed, 1 insertion(+), 14 deletions(-)
>
> diff --git a/arch/mips/kernel/prom.c b/arch/mips/kernel/prom.c
> index 0b2485f..3c3b0df 100644
> --- a/arch/mips/kernel/prom.c
> +++ b/arch/mips/kernel/prom.c
> @@ -47,24 +47,11 @@ void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
> return __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS));
> }
>
> -int __init early_init_dt_scan_model(unsigned long node, const char *uname,
> - int depth, void *data)
> -{
> - if (!depth) {
> - char *model = of_get_flat_dt_prop(node, "model", NULL);
> -
> - if (model)
> - mips_set_machine_name(model);
> - }
> - return 0;
> -}
> -
> void __init __dt_setup_arch(struct boot_param_header *bph)
> {
> if (!early_init_dt_scan(bph))
> return;
>
> - /* try to load the mips machine name */
> - of_scan_flat_dt(early_init_dt_scan_model, NULL);
> + mips_set_machine_name(of_flat_dt_get_machine_name());
> }
> #endif

2013-09-17 04:33:20

by John Crispin

[permalink] [raw]
Subject: Re: [PATCH 15/28] mips: use early_init_dt_scan

On 17/09/13 01:09, Rob Herring wrote:
> From: Rob Herring<[email protected]>
>
> Convert mips to use new early_init_dt_scan function.
>
> Remove early_init_dt_scan_memory_arch
>
> Signed-off-by: Rob Herring<[email protected]>
> Cc: Ralf Baechle<[email protected]>
> Cc: [email protected]
> ---

Acked-by: John Crispin <[email protected]>


Thanks for this series ...







> arch/mips/include/asm/prom.h | 3 ---
> arch/mips/kernel/prom.c | 39 +++------------------------------------
> 2 files changed, 3 insertions(+), 39 deletions(-)
>
> diff --git a/arch/mips/include/asm/prom.h b/arch/mips/include/asm/prom.h
> index 1e7e096..e3dbd0e 100644
> --- a/arch/mips/include/asm/prom.h
> +++ b/arch/mips/include/asm/prom.h
> @@ -17,9 +17,6 @@
> #include<linux/types.h>
> #include<asm/bootinfo.h>
>
> -extern int early_init_dt_scan_memory_arch(unsigned long node,
> - const char *uname, int depth, void *data);
> -
> extern void device_tree_init(void);
>
> static inline unsigned long pci_address_to_pio(phys_addr_t address)
> diff --git a/arch/mips/kernel/prom.c b/arch/mips/kernel/prom.c
> index 0fa0b69..67a4c53 100644
> --- a/arch/mips/kernel/prom.c
> +++ b/arch/mips/kernel/prom.c
> @@ -17,8 +17,6 @@
> #include<linux/debugfs.h>
> #include<linux/of.h>
> #include<linux/of_fdt.h>
> -#include<linux/of_irq.h>
> -#include<linux/of_platform.h>
>
> #include<asm/page.h>
> #include<asm/prom.h>
> @@ -40,13 +38,6 @@ char *mips_get_machine_name(void)
> }
>
> #ifdef CONFIG_OF
> -int __init early_init_dt_scan_memory_arch(unsigned long node,
> - const char *uname, int depth,
> - void *data)
> -{
> - return early_init_dt_scan_memory(node, uname, depth, data);
> -}
> -
> void __init early_init_dt_add_memory_arch(u64 base, u64 size)
> {
> return add_memory_region(base, size, BOOT_MEM_RAM);
> @@ -78,36 +69,12 @@ int __init early_init_dt_scan_model(unsigned long node, const char *uname,
> return 0;
> }
>
> -void __init early_init_devtree(void *params)
> -{
> - /* Setup flat device-tree pointer */
> - initial_boot_params = params;
> -
> - /* Retrieve various informations from the /chosen node of the
> - * device-tree, including the platform type, initrd location and
> - * size, and more ...
> - */
> - of_scan_flat_dt(early_init_dt_scan_chosen, arcs_cmdline);
> -
> -
> - /* Scan memory nodes */
> - of_scan_flat_dt(early_init_dt_scan_root, NULL);
> - of_scan_flat_dt(early_init_dt_scan_memory_arch, NULL);
> -
> - /* try to load the mips machine name */
> - of_scan_flat_dt(early_init_dt_scan_model, NULL);
> -}
> -
> void __init __dt_setup_arch(struct boot_param_header *bph)
> {
> - if (be32_to_cpu(bph->magic) != OF_DT_HEADER) {
> - pr_err("DTB has bad magic, ignoring builtin OF DTB\n");
> -
> + if (!early_init_dt_scan(bph))
> return;
> - }
> -
> - initial_boot_params = bph;
>
> - early_init_devtree(initial_boot_params);
> + /* try to load the mips machine name */
> + of_scan_flat_dt(early_init_dt_scan_model, NULL);
> }
> #endif

2013-09-17 05:25:17

by Vineet Gupta

[permalink] [raw]
Subject: Re: [PATCH 03/28] of: create unflatten_and_copy_device_tree

On 09/17/2013 04:38 AM, Rob Herring wrote:
> From: Rob Herring <rob.herring-bsGFqQB8/[email protected]>
>
> Several architectures using DT support built-in dtb's in the init
> section. These platforms need to copy the dtb from init since the
> strings are referenced after unflattening. Every arch has their own
> copying routine which do the same thing. Create a common function,
> unflatten_and_copy_device_tree, to copy the dtb when unflattening the
> dtb.
>
> Signed-off-by: Rob Herring <rob.herring-bsGFqQB8/[email protected]>
> Cc: Grant Likely <[email protected]>
> ---
> drivers/of/fdt.c | 13 +++++++++++++
> include/linux/of_fdt.h | 2 ++
> 2 files changed, 15 insertions(+)
>
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index 229dd9d..eca1810 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -802,6 +802,19 @@ void __init unflatten_device_tree(void)
> of_alias_scan(early_init_dt_alloc_memory_arch);
> }
>
> +void __init unflatten_and_copy_device_tree(void)
> +{

Can we add a comment here why exactly is the copy needed (unflattening doesn't
copy strings which are referenced to by the DT APIs). Will help first time readers.


> + int size = __be32_to_cpu(initial_boot_params->totalsize);
> + void *dt = early_init_dt_alloc_memory_arch(size,
> + __alignof__(struct boot_param_header));
> +
> + if (dt) {
> + memcpy(dt, initial_boot_params, size);
> + initial_boot_params = dt;
> + }
> + unflatten_device_tree();
> +}
> +
> #endif /* CONFIG_OF_EARLY_FLATTREE */
>

2013-09-17 05:27:09

by Vineet Gupta

[permalink] [raw]
Subject: Re: [PATCH 04/28] arc: use unflatten_and_copy_device_tree

On 09/17/2013 04:39 AM, Rob Herring wrote:
> From: Rob Herring <[email protected]>
>
> Use the common unflatten_and_copy_device_tree to copy the built-in FDT
> out of init section.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Vineet Gupta <[email protected]>

I tested the series - works great !

Acked by: Vineet Gupta <[email protected]>

Thx,
-Vineet

2013-09-17 05:46:38

by Vineet Gupta

[permalink] [raw]
Subject: Re: [PATCH 09/28] of: Introduce common early_init_dt_scan

On 09/17/2013 04:39 AM, Rob Herring wrote:
> From: Rob Herring <[email protected]>
>
> Most architectures scan the all the same items early in the FDT and none
> are really architecture specific. Create a common early_init_dt_scan to
> unify the early scan of root, memory, and chosen nodes in the flattened
> DT.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Grant Likely <[email protected]>
> ---
> drivers/of/fdt.c | 18 ++++++++++++++++++
> include/linux/of_fdt.h | 2 ++
> 2 files changed, 20 insertions(+)
>
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index eca1810..0714dd4 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -785,6 +785,24 @@ void * __init __weak early_init_dt_alloc_memory_arch(u64 size, u64 align)
> }
> #endif
>
> +bool __init early_init_dt_scan(void *params)
> +{
> + /* Setup flat device-tree pointer */
> + initial_boot_params = params;
> +
> + /* check device tree validity */
> + if (be32_to_cpu(initial_boot_params->magic) != OF_DT_HEADER)
> + return false;
> +
> + /* Retrieve various information from the /chosen node */
> + of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
> + /* Initialize {size,address}-cells info */
> + of_scan_flat_dt(early_init_dt_scan_root, NULL);
> + /* Setup memory, calling early_init_dt_add_memory_arch */
> + of_scan_flat_dt(early_init_dt_scan_memory, NULL);
> + return true;
> +}

You probably need empty lines here.

-Vineet

> +
> /**
> * unflatten_device_tree - create tree of device_nodes from flat blob
> *
> diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
> index 58c28a8..73e1651 100644
> --- a/include/linux/of_fdt.h
> +++ b/include/linux/of_fdt.h
> @@ -116,6 +116,8 @@ extern void early_init_dt_setup_initrd_arch(u64 start, u64 end);
> extern int early_init_dt_scan_root(unsigned long node, const char *uname,
> int depth, void *data);
>
> +extern bool early_init_dt_scan(void *params);
> +
> /* Other Prototypes */
> extern void unflatten_device_tree(void);
> extern void unflatten_and_copy_device_tree(void);
>

2013-09-17 06:37:25

by Vineet Gupta

[permalink] [raw]
Subject: Re: [PATCH 10/28] arc: use early_init_dt_scan

On 09/17/2013 04:39 AM, Rob Herring wrote:
> From: Rob Herring <[email protected]>
>
> Convert arc to use new early_init_dt_scan function.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Vineet Gupta <[email protected]>

Acked-by: Vineet Gupta <[email protected]>

-Vineet

2013-09-17 06:45:30

by Vineet Gupta

[permalink] [raw]
Subject: Re: [PATCH 21/28] of: remove early_init_dt_setup_initrd_arch

On 09/17/2013 04:39 AM, Rob Herring wrote:
> From: Rob Herring <[email protected]>
>
> All arches do essentially the same thing now for
> early_init_dt_setup_initrd_arch, so it can now be removed.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Vineet Gupta <[email protected]>

Acked-by: Vineet Gupta <[email protected]>

-Vineet

2013-09-17 06:50:53

by Vineet Gupta

[permalink] [raw]
Subject: Re: [PATCH 24/28] arc: use common of_flat_dt_match_machine

On 09/17/2013 04:40 AM, Rob Herring wrote:
> From: Rob Herring <[email protected]>
>
> Convert arc to use the common of_flat_dt_match_machine function.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Vineet Gupta <[email protected]>

Acked-by: Vineet Gupta <[email protected]>

Thx for the series.
-Vineet

2013-09-17 08:43:10

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH 12/28] arm64: use early_init_dt_scan

On 17 Sep 2013, at 00:09, Rob Herring <[email protected]> wrote:
> From: Rob Herring <[email protected]>
>
> Convert arm64 to use new early_init_dt_scan function.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Catalin Marinas <[email protected]>
> Cc: Will Deacon <[email protected]>
> Cc: [email protected]

Acked-by: Catalin Marinas <[email protected]>

2013-09-17 08:47:00

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH 18/28] of: create default early_init_dt_add_memory_arch

On 17 Sep 2013, at 00:09, Rob Herring <[email protected]> wrote:
> --- a/arch/arm64/kernel/setup.c
> +++ b/arch/arm64/kernel/setup.c
> @@ -147,24 +147,6 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)
> pr_info("Machine: %s\n", machine_name);
> }
>
> -void __init early_init_dt_add_memory_arch(u64 base, u64 size)
> -{
> - base &= PAGE_MASK;
> - size &= PAGE_MASK;
> - if (base + size < PHYS_OFFSET) {
> - pr_warning("Ignoring memory block 0x%llx - 0x%llx\n",
> - base, base + size);
> - return;
> - }
> - if (base < PHYS_OFFSET) {
> - pr_warning("Ignoring memory range 0x%llx - 0x%llx\n",
> - base, PHYS_OFFSET);
> - size -= PHYS_OFFSET - base;
> - base = PHYS_OFFSET;
> - }
> - memblock_add(base, size);
> -}
> -
> /*
> * Limit the memory size that was specified via FDT.
> */

...

> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -688,6 +688,17 @@ u64 __init dt_mem_next_cell(int s, __be32 **cellp)
> return of_read_number(p, s);
> }
>
> +void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> +{
> +#ifdef CONFIG_HAVE_MEMBLOCK
> + base &= PAGE_MASK;
> + size &= PAGE_MASK;
> + memblock_add(base, size);
> +#else
> + pr_err("%s: ignoring memory (%llx, %llx)\n", __func__, base, size);
> +#endif
> +}

Are the arm64 changes equivalent here? There are some safety checks to
cope with the kernel being loaded at a higher offset than the
recommended one (PHYS_OFFSET calculated automatically).

Catalin-

2013-09-17 08:50:12

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH 20/28] arm64: set initrd_start/initrd_end for fdt scan

On 17 Sep 2013, at 00:09, Rob Herring <[email protected]> wrote:
> From: Rob Herring <[email protected]>
>
> In order to unify the initrd scanning for DT across architectures, make
> arm64 use initrd_start and initrd_end instead of the physical addresses.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Catalin Marinas <[email protected]>
> Cc: Will Deacon <[email protected]>
> Cc: [email protected]

Acked-by: Catalin Marinas <[email protected]>

2013-09-17 08:53:15

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH 26/28] arm64: use common of_flat_dt_get_machine_name

On 17 Sep 2013, at 00:09, Rob Herring <[email protected]> wrote:
> From: Rob Herring <[email protected]>
>
> Convert arm64 to use the common of_flat_dt_get_machine_name function.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Catalin Marinas <[email protected]>
> Cc: Will Deacon <[email protected]>
> Cc: [email protected]

Acked-by: Catalin Marinas <[email protected]>

2013-09-17 12:21:05

by Mark Salter

[permalink] [raw]
Subject: Re: [PATCH 13/28] c6x: use early_init_dt_scan

On Mon, 2013-09-16 at 18:09 -0500, Rob Herring wrote:
> From: Rob Herring <[email protected]>
>
> Convert c6x to use new early_init_dt_scan function.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Mark Salter <[email protected]>
> Cc: Aurelien Jacquiot <[email protected]>
> Cc: [email protected]
> ---
> arch/c6x/kernel/devicetree.c | 19 -------------------
> arch/c6x/kernel/setup.c | 2 +-
> 2 files changed, 1 insertion(+), 20 deletions(-)

Acked-by: Mark Salter <[email protected]>

2013-09-17 13:01:38

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH 18/28] of: create default early_init_dt_add_memory_arch

On Tue, Sep 17, 2013 at 3:46 AM, Catalin Marinas
<[email protected]> wrote:
> On 17 Sep 2013, at 00:09, Rob Herring <[email protected]> wrote:
>> --- a/arch/arm64/kernel/setup.c
>> +++ b/arch/arm64/kernel/setup.c
>> @@ -147,24 +147,6 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)
>> pr_info("Machine: %s\n", machine_name);
>> }
>>
>> -void __init early_init_dt_add_memory_arch(u64 base, u64 size)
>> -{
>> - base &= PAGE_MASK;
>> - size &= PAGE_MASK;
>> - if (base + size < PHYS_OFFSET) {
>> - pr_warning("Ignoring memory block 0x%llx - 0x%llx\n",
>> - base, base + size);
>> - return;
>> - }
>> - if (base < PHYS_OFFSET) {
>> - pr_warning("Ignoring memory range 0x%llx - 0x%llx\n",
>> - base, PHYS_OFFSET);
>> - size -= PHYS_OFFSET - base;
>> - base = PHYS_OFFSET;
>> - }
>> - memblock_add(base, size);
>> -}
>> -
>> /*
>> * Limit the memory size that was specified via FDT.
>> */
>
> ...
>
>> --- a/drivers/of/fdt.c
>> +++ b/drivers/of/fdt.c
>> @@ -688,6 +688,17 @@ u64 __init dt_mem_next_cell(int s, __be32 **cellp)
>> return of_read_number(p, s);
>> }
>>
>> +void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
>> +{
>> +#ifdef CONFIG_HAVE_MEMBLOCK
>> + base &= PAGE_MASK;
>> + size &= PAGE_MASK;
>> + memblock_add(base, size);
>> +#else
>> + pr_err("%s: ignoring memory (%llx, %llx)\n", __func__, base, size);
>> +#endif
>> +}
>
> Are the arm64 changes equivalent here? There are some safety checks to
> cope with the kernel being loaded at a higher offset than the
> recommended one (PHYS_OFFSET calculated automatically).

I tried to keep that, but PHYS_OFFSET is not universally defined. My
reasoning is this range checking is hardly specific to an
architecture. Perhaps if memory always starts at 0 you don't need it.
If arm64 really needs these checks, then all architectures do.

Perhaps "__virt_to_phys(PAGE_OFFSET)" instead of PHYS_OFFSET would work for all?

Rob

2013-09-17 13:05:54

by Michal Simek

[permalink] [raw]
Subject: Re: [PATCH 14/28] microblaze: use early_init_dt_scan

On 09/17/2013 01:09 AM, Rob Herring wrote:
> From: Rob Herring <[email protected]>
>
> Convert microblaze to use new early_init_dt_scan function.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Michal Simek <[email protected]>
> Cc: [email protected]
> ---
> arch/microblaze/kernel/prom.c | 17 +++--------------
> arch/microblaze/kernel/setup.c | 2 +-
> 2 files changed, 4 insertions(+), 15 deletions(-)

No problem on Microblaze with this change.
Tested-by: Michal Simek <[email protected]>

Thanks,
Michal

--
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: http://www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/
Maintainer of Linux kernel - Xilinx Zynq ARM architecture
Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform



Attachments:
signature.asc (263.00 B)
OpenPGP digital signature

2013-09-17 15:29:50

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH 18/28] of: create default early_init_dt_add_memory_arch

On Tue, Sep 17, 2013 at 02:01:36PM +0100, Rob Herring wrote:
> On Tue, Sep 17, 2013 at 3:46 AM, Catalin Marinas
> <[email protected]> wrote:
> > On 17 Sep 2013, at 00:09, Rob Herring <[email protected]> wrote:
> >> --- a/arch/arm64/kernel/setup.c
> >> +++ b/arch/arm64/kernel/setup.c
> >> @@ -147,24 +147,6 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)
> >> pr_info("Machine: %s\n", machine_name);
> >> }
> >>
> >> -void __init early_init_dt_add_memory_arch(u64 base, u64 size)
> >> -{
> >> - base &= PAGE_MASK;
> >> - size &= PAGE_MASK;
> >> - if (base + size < PHYS_OFFSET) {
> >> - pr_warning("Ignoring memory block 0x%llx - 0x%llx\n",
> >> - base, base + size);
> >> - return;
> >> - }
> >> - if (base < PHYS_OFFSET) {
> >> - pr_warning("Ignoring memory range 0x%llx - 0x%llx\n",
> >> - base, PHYS_OFFSET);
> >> - size -= PHYS_OFFSET - base;
> >> - base = PHYS_OFFSET;
> >> - }
> >> - memblock_add(base, size);
> >> -}
> >> -
> >> /*
> >> * Limit the memory size that was specified via FDT.
> >> */
> >
> > ...
> >
> >> --- a/drivers/of/fdt.c
> >> +++ b/drivers/of/fdt.c
> >> @@ -688,6 +688,17 @@ u64 __init dt_mem_next_cell(int s, __be32 **cellp)
> >> return of_read_number(p, s);
> >> }
> >>
> >> +void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> >> +{
> >> +#ifdef CONFIG_HAVE_MEMBLOCK
> >> + base &= PAGE_MASK;
> >> + size &= PAGE_MASK;
> >> + memblock_add(base, size);
> >> +#else
> >> + pr_err("%s: ignoring memory (%llx, %llx)\n", __func__, base, size);
> >> +#endif
> >> +}
> >
> > Are the arm64 changes equivalent here? There are some safety checks to
> > cope with the kernel being loaded at a higher offset than the
> > recommended one (PHYS_OFFSET calculated automatically).
>
> I tried to keep that, but PHYS_OFFSET is not universally defined. My
> reasoning is this range checking is hardly specific to an
> architecture. Perhaps if memory always starts at 0 you don't need it.
> If arm64 really needs these checks, then all architectures do.
>
> Perhaps "__virt_to_phys(PAGE_OFFSET)" instead of PHYS_OFFSET would work for all?

I think virt_to_phys() or __pa() should work, the __virt_to_phys() is
only defined by a few architectures.

--
Catalin

2013-09-18 06:13:40

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH 18/28] of: create default early_init_dt_add_memory_arch

On Mon, 16 Sep 2013 18:09:14 -0500, Rob Herring <[email protected]> wrote:
> From: Rob Herring <[email protected]>
>
> Create a weak version of early_init_dt_add_memory_arch which uses
> memblock or is an empty function when memblock is not enabled. This
> will unify all architectures except ones with custom memory bank
> structs.

Two comments below, but otherwise:

Acked-by: Grant Likely <[email protected]>

> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index 0714dd4..a9dce7a 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -688,6 +688,17 @@ u64 __init dt_mem_next_cell(int s, __be32 **cellp)
> return of_read_number(p, s);
> }
>
> +void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> +{
> +#ifdef CONFIG_HAVE_MEMBLOCK
> + base &= PAGE_MASK;
> + size &= PAGE_MASK;
> + memblock_add(base, size);
> +#else
> + pr_err("%s: ignoring memory (%llx, %llx)\n", __func__, base, size);
> +#endif
> +}
> +

Can you do it this way instead:

#ifdef CONFIG_HAVE_MEMBLOCK
void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
{
base &= PAGE_MASK;
size &= PAGE_MASK;
memblock_add(base, size);
}
#endif

If the platform doesn't provide an early_init_dt_add_memory_arch()
function and it doesn't have a memblock implementation, then the build
should outright fail. I don't see a scenario where we would want to
successfully build the kernel without a working add memory function.

Also, can you group this function with the common __weak
early_init_dt_alloc_memory_arch() implementation? It would be good to
group all the memblock specific functions together.

g.

2013-09-18 06:13:36

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH 19/28] arm: set initrd_start/initrd_end for fdt scan

On Mon, 16 Sep 2013 18:09:15 -0500, Rob Herring <[email protected]> wrote:
> From: Rob Herring <[email protected]>
>
> In order to unify the initrd scanning for DT across architectures, make
> arm set initrd_start and initrd_end instead of the physical addresses.
> This is aligned with all other architectures.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Russell King <[email protected]>
> Cc: [email protected]

Acked-by: Grant Likely <[email protected]>

> ---
> arch/arm/mm/init.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
> index febaee7..9eeb1cd 100644
> --- a/arch/arm/mm/init.c
> +++ b/arch/arm/mm/init.c
> @@ -77,11 +77,11 @@ static int __init parse_tag_initrd2(const struct tag *tag)
>
> __tagtable(ATAG_INITRD2, parse_tag_initrd2);
>
> -#ifdef CONFIG_OF_FLATTREE
> +#if defined(CONFIG_OF_FLATTREE) && defined(CONFIG_BLK_DEV_INITRD)
> void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
> {
> - phys_initrd_start = start;
> - phys_initrd_size = end - start;
> + initrd_start = (unsigned long)__va(start);
> + initrd_end = (unsigned long)__va(end);
> }
> #endif /* CONFIG_OF_FLATTREE */
>
> @@ -351,6 +351,11 @@ void __init arm_memblock_init(struct meminfo *mi,
> memblock_reserve(__pa(_stext), _end - _stext);
> #endif
> #ifdef CONFIG_BLK_DEV_INITRD
> + /* FDT scan will populate initrd_start */
> + if (initrd_start) {
> + phys_initrd_start = __virt_to_phys(initrd_start);
> + phys_initrd_size = initrd_end - initrd_start;
> + }
> if (phys_initrd_size &&
> !memblock_is_region_memory(phys_initrd_start, phys_initrd_size)) {
> pr_err("INITRD: 0x%08llx+0x%08lx is not a memory region - disabling initrd\n",
> --
> 1.8.1.2
>

2013-09-18 06:14:35

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH 21/28] of: remove early_init_dt_setup_initrd_arch

On Mon, 16 Sep 2013 18:09:17 -0500, Rob Herring <[email protected]> wrote:
> From: Rob Herring <[email protected]>
>
> All arches do essentially the same thing now for
> early_init_dt_setup_initrd_arch, so it can now be removed.
>
> Signed-off-by: Rob Herring <[email protected]>

Acked-by: Grant Likely <[email protected]>

2013-09-18 06:14:33

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH 09/28] of: Introduce common early_init_dt_scan

On Mon, 16 Sep 2013 18:09:05 -0500, Rob Herring <[email protected]> wrote:
> From: Rob Herring <[email protected]>
>
> Most architectures scan the all the same items early in the FDT and none
> are really architecture specific. Create a common early_init_dt_scan to
> unify the early scan of root, memory, and chosen nodes in the flattened
> DT.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Grant Likely <[email protected]>

One caveat below, but otherwise:
Acked-by: Grant Likely <[email protected]>

> ---
> drivers/of/fdt.c | 18 ++++++++++++++++++
> include/linux/of_fdt.h | 2 ++
> 2 files changed, 20 insertions(+)
>
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index eca1810..0714dd4 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -785,6 +785,24 @@ void * __init __weak early_init_dt_alloc_memory_arch(u64 size, u64 align)
> }
> #endif
>
> +bool __init early_init_dt_scan(void *params)
> +{
> + /* Setup flat device-tree pointer */
> + initial_boot_params = params;
> +
> + /* check device tree validity */
> + if (be32_to_cpu(initial_boot_params->magic) != OF_DT_HEADER)
> + return false;

If the test fails, then clear initial_boot_params to NULL. Similarly, if
params is NULL, then bail before dereferencing it.

> +
> + /* Retrieve various information from the /chosen node */
> + of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
> + /* Initialize {size,address}-cells info */
> + of_scan_flat_dt(early_init_dt_scan_root, NULL);
> + /* Setup memory, calling early_init_dt_add_memory_arch */
> + of_scan_flat_dt(early_init_dt_scan_memory, NULL);
> + return true;
> +}
> +
> /**
> * unflatten_device_tree - create tree of device_nodes from flat blob
> *
> diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
> index 58c28a8..73e1651 100644
> --- a/include/linux/of_fdt.h
> +++ b/include/linux/of_fdt.h
> @@ -116,6 +116,8 @@ extern void early_init_dt_setup_initrd_arch(u64 start, u64 end);
> extern int early_init_dt_scan_root(unsigned long node, const char *uname,
> int depth, void *data);
>
> +extern bool early_init_dt_scan(void *params);
> +
> /* Other Prototypes */
> extern void unflatten_device_tree(void);
> extern void unflatten_and_copy_device_tree(void);
> --
> 1.8.1.2
>

2013-09-18 06:13:35

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH 23/28] of: introduce common FDT machine related functions

On Mon, 16 Sep 2013 18:09:19 -0500, Rob Herring <[email protected]> wrote:
> From: Rob Herring <[email protected]>
>
> Introduce common of_flat_dt_match_machine and
> of_flat_dt_get_machine_name functions to unify architectures' handling
> of machine level model and compatible properties.
>
> Several architectures match the root compatible string with an arch
> specific list of machine descriptors duplicating the same search
> algorithm. Create a common implementation with a simple architecture
> specific hook to iterate over each machine's match table.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Grant Likely <[email protected]>

Nice!

Acked-by: Grant Likely <[email protected]>

Thanks for doing this whole series. It's some really good improvements.

g.

2013-09-18 06:15:03

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH 01/28] c6x: use boot_command_line instead of private c6x_command_line

On Mon, 16 Sep 2013 18:08:57 -0500, Rob Herring <[email protected]> wrote:
> From: Rob Herring <[email protected]>
>
> Save some pointless copying of the kernel command line and just use
> boot_command_line instead.
>
> Also remove default_command_line as it is not referenced anywhere, and
> the DT code already handles the default command line.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Mark Salter <[email protected]>
> Cc: Aurelien Jacquiot <[email protected]>
> Cc: [email protected]

This and the next patch look good to me.

Reviewed-by: Grant Likely <[email protected]>

> ---
> arch/c6x/include/asm/setup.h | 2 --
> arch/c6x/kernel/devicetree.c | 2 +-
> arch/c6x/kernel/setup.c | 11 +----------
> 3 files changed, 2 insertions(+), 13 deletions(-)
>
> diff --git a/arch/c6x/include/asm/setup.h b/arch/c6x/include/asm/setup.h
> index ecead15..6968044 100644
> --- a/arch/c6x/include/asm/setup.h
> +++ b/arch/c6x/include/asm/setup.h
> @@ -14,8 +14,6 @@
> #include <uapi/asm/setup.h>
>
> #ifndef __ASSEMBLY__
> -extern char c6x_command_line[COMMAND_LINE_SIZE];
> -
> extern int c6x_add_memory(phys_addr_t start, unsigned long size);
>
> extern unsigned long ram_start;
> diff --git a/arch/c6x/kernel/devicetree.c b/arch/c6x/kernel/devicetree.c
> index 9e15ab9..5e8c838 100644
> --- a/arch/c6x/kernel/devicetree.c
> +++ b/arch/c6x/kernel/devicetree.c
> @@ -24,7 +24,7 @@ void __init early_init_devtree(void *params)
> * device-tree, including the platform type, initrd location and
> * size and more ...
> */
> - of_scan_flat_dt(early_init_dt_scan_chosen, c6x_command_line);
> + of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
>
> /* Scan memory nodes and rebuild MEMBLOCKs */
> of_scan_flat_dt(early_init_dt_scan_root, NULL);
> diff --git a/arch/c6x/kernel/setup.c b/arch/c6x/kernel/setup.c
> index f4e72bd..0e5a812 100644
> --- a/arch/c6x/kernel/setup.c
> +++ b/arch/c6x/kernel/setup.c
> @@ -68,13 +68,6 @@ unsigned long ram_end;
> static unsigned long dma_start __initdata;
> static unsigned long dma_size __initdata;
>
> -char c6x_command_line[COMMAND_LINE_SIZE];
> -
> -#if defined(CONFIG_CMDLINE_BOOL)
> -static const char default_command_line[COMMAND_LINE_SIZE] __section(.cmdline) =
> - CONFIG_CMDLINE;
> -#endif
> -
> struct cpuinfo_c6x {
> const char *cpu_name;
> const char *cpu_voltage;
> @@ -296,8 +289,6 @@ notrace void __init machine_init(unsigned long dt_ptr)
> /* Do some early initialization based on the flat device tree */
> early_init_devtree(fdt);
>
> - /* parse_early_param needs a boot_command_line */
> - strlcpy(boot_command_line, c6x_command_line, COMMAND_LINE_SIZE);
> parse_early_param();
> }
>
> @@ -309,7 +300,7 @@ void __init setup_arch(char **cmdline_p)
> printk(KERN_INFO "Initializing kernel\n");
>
> /* Initialize command line */
> - *cmdline_p = c6x_command_line;
> + *cmdline_p = boot_command_line;
>
> memory_end = ram_end;
> memory_end &= ~(PAGE_SIZE - 1);
> --
> 1.8.1.2
>

2013-09-18 06:15:58

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH 20/28] arm64: set initrd_start/initrd_end for fdt scan

On Tue, 17 Sep 2013 09:50:04 +0100, Catalin Marinas <[email protected]> wrote:
> On 17 Sep 2013, at 00:09, Rob Herring <[email protected]> wrote:
> > From: Rob Herring <[email protected]>
> >
> > In order to unify the initrd scanning for DT across architectures, make
> > arm64 use initrd_start and initrd_end instead of the physical addresses.
> >
> > Signed-off-by: Rob Herring <[email protected]>
> > Cc: Catalin Marinas <[email protected]>
> > Cc: Will Deacon <[email protected]>
> > Cc: [email protected]
>
> Acked-by: Catalin Marinas <[email protected]>
Acked-by: Grant Likely <[email protected]>

2013-09-18 06:15:57

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH 03/28] of: create unflatten_and_copy_device_tree

On Mon, 16 Sep 2013 18:08:59 -0500, Rob Herring <[email protected]> wrote:
> From: Rob Herring <[email protected]>
>
> Several architectures using DT support built-in dtb's in the init
> section. These platforms need to copy the dtb from init since the
> strings are referenced after unflattening. Every arch has their own
> copying routine which do the same thing. Create a common function,
> unflatten_and_copy_device_tree, to copy the dtb when unflattening the
> dtb.

This set of changes looks fine by me, but it does raise a question:
For the platforms using memblock; would it work to use memblock_reserve
on the region containing the device tree? That would avoid an
unnecessary copy of the data. Can anyone tell me if it is legal to do a
memblock_reserve on an __init section?

Also, I think the patch needs to add documentation for the function that
states when it is appropriate to use the function, and that it shouldn't
be used when DT memory has been reserved.

Acked-by: Grant Likely <[email protected]>

>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Grant Likely <[email protected]>
> ---
> drivers/of/fdt.c | 13 +++++++++++++
> include/linux/of_fdt.h | 2 ++
> 2 files changed, 15 insertions(+)
>
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index 229dd9d..eca1810 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -802,6 +802,19 @@ void __init unflatten_device_tree(void)
> of_alias_scan(early_init_dt_alloc_memory_arch);
> }
>
> +void __init unflatten_and_copy_device_tree(void)
> +{
> + int size = __be32_to_cpu(initial_boot_params->totalsize);
> + void *dt = early_init_dt_alloc_memory_arch(size,
> + __alignof__(struct boot_param_header));
> +
> + if (dt) {
> + memcpy(dt, initial_boot_params, size);
> + initial_boot_params = dt;
> + }
> + unflatten_device_tree();
> +}
> +
> #endif /* CONFIG_OF_EARLY_FLATTREE */
>
> /* Feed entire flattened device tree into the random pool */
> diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
> index a478c62..58c28a8 100644
> --- a/include/linux/of_fdt.h
> +++ b/include/linux/of_fdt.h
> @@ -118,9 +118,11 @@ extern int early_init_dt_scan_root(unsigned long node, const char *uname,
>
> /* Other Prototypes */
> extern void unflatten_device_tree(void);
> +extern void unflatten_and_copy_device_tree(void);
> extern void early_init_devtree(void *);
> #else /* CONFIG_OF_FLATTREE */
> static inline void unflatten_device_tree(void) {}
> +static inline void unflatten_and_copy_device_tree(void) {}
> #endif /* CONFIG_OF_FLATTREE */
>
> #endif /* __ASSEMBLY__ */
> --
> 1.8.1.2
>

2013-09-18 13:35:41

by Mark Salter

[permalink] [raw]
Subject: Re: [PATCH 01/28] c6x: use boot_command_line instead of private c6x_command_line

On Mon, 2013-09-16 at 18:08 -0500, Rob Herring wrote:
> From: Rob Herring <[email protected]>
>
> Save some pointless copying of the kernel command line and just use
> boot_command_line instead.
>
> Also remove default_command_line as it is not referenced anywhere, and
> the DT code already handles the default command line.
>

The default_command_line is leftover cruft from the kernel before it was
upstreamed. It was a mechanism to place the commandline at a known fixed
offset in the Image. It was needed for simple (serial eeprom based)
loaders which didn't know about DT. Anyway, bits of that support are
missing, so I don't see a reason to keep it around. If anyone complains
we can add it back in as a completely functional patch. There is also
a fragment of arch/c6x/kernel/vmlinux.lds.S which should also be
removed:

diff --git a/arch/c6x/kernel/vmlinux.lds.S b/arch/c6x/kernel/vmlinux.lds.S
index 279d807..5a6e141 100644
--- a/arch/c6x/kernel/vmlinux.lds.S
+++ b/arch/c6x/kernel/vmlinux.lds.S
@@ -37,12 +37,6 @@ SECTIONS
_vectors_end = .;
}

- . = ALIGN(0x1000);
- .cmdline :
- {
- *(.cmdline)
- }
-
/*
* This section contains data which may be shared with other
* cores. It needs to be a fixed offset from PAGE_OFFSET

2013-09-18 15:09:43

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH 18/28] of: create default early_init_dt_add_memory_arch

On Tue, Sep 17, 2013 at 10:33 PM, Grant Likely <[email protected]> wrote:
> On Mon, 16 Sep 2013 18:09:14 -0500, Rob Herring <[email protected]> wrote:
>> From: Rob Herring <[email protected]>
>>
>> Create a weak version of early_init_dt_add_memory_arch which uses
>> memblock or is an empty function when memblock is not enabled. This
>> will unify all architectures except ones with custom memory bank
>> structs.
>
> Two comments below, but otherwise:
>
> Acked-by: Grant Likely <[email protected]>
>
>> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
>> index 0714dd4..a9dce7a 100644
>> --- a/drivers/of/fdt.c
>> +++ b/drivers/of/fdt.c
>> @@ -688,6 +688,17 @@ u64 __init dt_mem_next_cell(int s, __be32 **cellp)
>> return of_read_number(p, s);
>> }
>>
>> +void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
>> +{
>> +#ifdef CONFIG_HAVE_MEMBLOCK
>> + base &= PAGE_MASK;
>> + size &= PAGE_MASK;
>> + memblock_add(base, size);
>> +#else
>> + pr_err("%s: ignoring memory (%llx, %llx)\n", __func__, base, size);
>> +#endif
>> +}
>> +
>
> Can you do it this way instead:
>
> #ifdef CONFIG_HAVE_MEMBLOCK
> void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> {
> base &= PAGE_MASK;
> size &= PAGE_MASK;
> memblock_add(base, size);
> }
> #endif
>
> If the platform doesn't provide an early_init_dt_add_memory_arch()
> function and it doesn't have a memblock implementation, then the build
> should outright fail. I don't see a scenario where we would want to
> successfully build the kernel without a working add memory function.

metag and x86 both have empty functions. I guess they get memory from
a different boot interface.

Rob

>
> Also, can you group this function with the common __weak
> early_init_dt_alloc_memory_arch() implementation? It would be good to
> group all the memblock specific functions together.
>
> g.
>

2013-09-22 13:29:03

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH 18/28] of: create default early_init_dt_add_memory_arch

On Wed, 18 Sep 2013 10:09:40 -0500, Rob Herring <[email protected]> wrote:
> On Tue, Sep 17, 2013 at 10:33 PM, Grant Likely <[email protected]> wrote:
> > On Mon, 16 Sep 2013 18:09:14 -0500, Rob Herring <[email protected]> wrote:
> >> From: Rob Herring <[email protected]>
> >>
> >> Create a weak version of early_init_dt_add_memory_arch which uses
> >> memblock or is an empty function when memblock is not enabled. This
> >> will unify all architectures except ones with custom memory bank
> >> structs.
> >
> > Two comments below, but otherwise:
> >
> > Acked-by: Grant Likely <[email protected]>
> >
> >> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> >> index 0714dd4..a9dce7a 100644
> >> --- a/drivers/of/fdt.c
> >> +++ b/drivers/of/fdt.c
> >> @@ -688,6 +688,17 @@ u64 __init dt_mem_next_cell(int s, __be32 **cellp)
> >> return of_read_number(p, s);
> >> }
> >>
> >> +void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> >> +{
> >> +#ifdef CONFIG_HAVE_MEMBLOCK
> >> + base &= PAGE_MASK;
> >> + size &= PAGE_MASK;
> >> + memblock_add(base, size);
> >> +#else
> >> + pr_err("%s: ignoring memory (%llx, %llx)\n", __func__, base, size);
> >> +#endif
> >> +}
> >> +
> >
> > Can you do it this way instead:
> >
> > #ifdef CONFIG_HAVE_MEMBLOCK
> > void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> > {
> > base &= PAGE_MASK;
> > size &= PAGE_MASK;
> > memblock_add(base, size);
> > }
> > #endif
> >
> > If the platform doesn't provide an early_init_dt_add_memory_arch()
> > function and it doesn't have a memblock implementation, then the build
> > should outright fail. I don't see a scenario where we would want to
> > successfully build the kernel without a working add memory function.
>
> metag and x86 both have empty functions. I guess they get memory from
> a different boot interface.

I would put the exceptions into arch/x86 and arch/metag then. The
default answer should be that early_init_dt_add_memory_arch() works, and
the build will fail if they aren't implemented. If it really is valid to
have an empty implementation, then the architecture should have to do
something special to get that.

g.

2013-09-23 09:59:07

by James Hogan

[permalink] [raw]
Subject: Re: [PATCH 00/28] Early flattened DT init consolidation

On 17/09/13 00:08, Rob Herring wrote:
> From: Rob Herring <[email protected]>
>
> This is the first of 2 series to do some consolidation of per
> architecture Device Tree code. We now have 12 architectures with DT
> support. As new architectures have been added, much of the DT related
> code for the early flattened DT scanning has been duplicated. Yet little
> of this code is architecture specific. This series has 4 main parts:
>
> - Create a common function to copy built-in dtb's out of init section
> - Create a single, common function to scan the FDT
> - Removal of early_init_dt_setup_initrd_arch
> - Create common functions for machine matching with DT
>
> The entire series is available here:
> git://sources.calxeda.com/kernel/linux.git dt-cleanup

Hi Rob,

I gave this branch a try on metag.

The following patches break the build:
e09b397e of: only include prom.h on sparc
740de19c of: remove empty arch prom.h headers

because metag's prom.h has a setup_machine_fdt function declaration
which is used in arch/metag/kernel/setup.c (and defined in
arch/metag/kernel/devtree.c). Please move that declaration elsewhere
(asm/setup.h would seem appropriate) if you're going to remove prom.h.


Also I appear to hit the BUG_ON at
drivers/of/fdt.c:511/of_get_flat_dt_root().

This is because on metag we try interpreting the command line argument
as a device tree and only use the built-in DT if that fails. Previously
we relied on the be32_to_cpu(devtree->magic) != OF_DT_HEADER check in
setup_machine_fdt. The following seems to fix it:

diff --git a/arch/metag/kernel/devtree.c b/arch/metag/kernel/devtree.c
index abe607e..550dd91 100644
--- a/arch/metag/kernel/devtree.c
+++ b/arch/metag/kernel/devtree.c
@@ -52,7 +52,10 @@ struct machine_desc * __init setup_machine_fdt(void *dt)
{
struct machine_desc *mdesc;

- early_init_dt_scan(dt);
+ /* check device tree validity */
+ if (!early_init_dt_scan(dt))
+ return NULL;
+
mdesc = of_flat_dt_match_machine(NULL, arch_get_next_mach);
if (!mdesc)
dump_machine_table(); /* does not return */

Cheers
James

>
> Compiled on arm, arm64, microblaze, mips, openrisc, powerpc, sparc,
> xtensa.
>
> Rob
>
> Rob Herring (28):
> c6x: use boot_command_line instead of private c6x_command_line
> openrisc: use boot_command_line instead of private cmd_line
> of: create unflatten_and_copy_device_tree
> arc: use unflatten_and_copy_device_tree
> openrisc: use unflatten_and_copy_device_tree
> x86: use unflatten_and_copy_device_tree
> xtensa: use unflatten_and_copy_device_tree
> metag: use unflatten_and_copy_device_tree
> of: Introduce common early_init_dt_scan
> arc: use early_init_dt_scan
> arm: use early_init_dt_scan
> arm64: use early_init_dt_scan
> c6x: use early_init_dt_scan
> microblaze: use early_init_dt_scan
> mips: use early_init_dt_scan
> openrisc: use early_init_dt_scan
> xtensa: use early_init_dt_scan
> of: create default early_init_dt_add_memory_arch
> arm: set initrd_start/initrd_end for fdt scan
> arm64: set initrd_start/initrd_end for fdt scan
> of: remove early_init_dt_setup_initrd_arch
> openrisc: remove unnecessary prom.c includes
> of: introduce common FDT machine related functions
> arc: use common of_flat_dt_match_machine
> arm: use common of_flat_dt_match_machine
> arm64: use common of_flat_dt_get_machine_name
> metag: use common of_flat_dt_match_machine
> mips: use common of_flat_dt_get_machine_name
>
> arch/arc/include/asm/mach_desc.h | 1 -
> arch/arc/kernel/devtree.c | 94 +++++++--------------------------
> arch/arc/kernel/setup.c | 3 +-
> arch/arc/mm/init.c | 7 ---
> arch/arm/kernel/devtree.c | 57 ++++++++------------
> arch/arm/mm/init.c | 13 ++---
> arch/arm64/kernel/setup.c | 60 ++-------------------
> arch/arm64/mm/init.c | 24 +++------
> arch/c6x/include/asm/setup.h | 2 -
> arch/c6x/kernel/devicetree.c | 29 ----------
> arch/c6x/kernel/setup.c | 13 +----
> arch/metag/kernel/devtree.c | 87 ++++++------------------------
> arch/metag/kernel/setup.c | 4 +-
> arch/metag/mm/init.c | 9 ----
> arch/microblaze/kernel/prom.c | 31 ++---------
> arch/microblaze/kernel/setup.c | 2 +-
> arch/mips/include/asm/prom.h | 3 --
> arch/mips/kernel/prom.c | 60 +--------------------
> arch/openrisc/kernel/prom.c | 70 +-----------------------
> arch/openrisc/kernel/setup.c | 6 +--
> arch/powerpc/kernel/prom.c | 9 ----
> arch/x86/kernel/devicetree.c | 42 +++------------
> arch/xtensa/kernel/setup.c | 55 +++++--------------
> drivers/of/fdt.c | 111 +++++++++++++++++++++++++++++++++++++--
> include/linux/of_fdt.h | 18 +++----
> 25 files changed, 223 insertions(+), 587 deletions(-)
>


Attachments:
signature.asc (836.00 B)
OpenPGP digital signature

2013-09-23 10:53:00

by Max Filippov

[permalink] [raw]
Subject: Re: [PATCH 07/28] xtensa: use unflatten_and_copy_device_tree

On Tue, Sep 17, 2013 at 3:09 AM, Rob Herring <[email protected]> wrote:
> From: Rob Herring <[email protected]>
>
> Use the common unflatten_and_copy_device_tree to copy the built-in FDT
> out of init section.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Chris Zankel <[email protected]>
> Cc: Max Filippov <[email protected]>
> Cc: [email protected]
> ---
> arch/xtensa/kernel/setup.c | 19 +------------------
> 1 file changed, 1 insertion(+), 18 deletions(-)

Acked-by: Max Filippov <[email protected]>

--
Thanks.
-- Max

2013-09-23 10:53:18

by Max Filippov

[permalink] [raw]
Subject: Re: [PATCH 17/28] xtensa: use early_init_dt_scan

On Tue, Sep 17, 2013 at 3:09 AM, Rob Herring <[email protected]> wrote:
> From: Rob Herring <[email protected]>
>
> Convert xtensa to use new early_init_dt_scan function.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Chris Zankel <[email protected]>
> Cc: Max Filippov <[email protected]>
> Cc: [email protected]
> ---
> arch/xtensa/kernel/setup.c | 21 +++++++++------------
> 1 file changed, 9 insertions(+), 12 deletions(-)

Acked-by: Max Filippov <[email protected]>

--
Thanks.
-- Max

2013-10-07 12:02:54

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH 23/28] of: introduce common FDT machine related functions

On Mon, 16 Sep 2013 18:09:19 -0500, Rob Herring <[email protected]> wrote:
> From: Rob Herring <[email protected]>
>
> Introduce common of_flat_dt_match_machine and
> of_flat_dt_get_machine_name functions to unify architectures' handling
> of machine level model and compatible properties.
>
> Several architectures match the root compatible string with an arch
> specific list of machine descriptors duplicating the same search
> algorithm. Create a common implementation with a simple architecture
> specific hook to iterate over each machine's match table.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Grant Likely <[email protected]>
> ---
> drivers/of/fdt.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/of_fdt.h | 4 ++++
> 2 files changed, 64 insertions(+)
>
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index 83cdeb5..e21d1dc 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -619,6 +619,66 @@ int __init of_scan_flat_dt_by_path(const char *path,
> return ret;
> }
>
> +const char *of_flat_dt_get_machine_name(void)

Just discovered that this needs to be __init.

g.