2013-10-07 16:29:57

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 00/29] 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 with prom.h clean-up series is available here:
git://sources.calxeda.com/kernel/linux.git dt-cleanup

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

Version 1 of this series is here:
http://www.spinics.net/lists/devicetree/msg04865.html

The prom.h clean-up series is here:
http://www.spinics.net/lists/devicetree/msg06175.html

Changes in v2:
- Rebase to v3.12-rc3
- add arm64 sanity checks to default early_init_dt_add_memory_arch
- drop x86 and metag from common early_init_dt_add_memory_arch
- move metag early_init_dt_scan support to separate patch
- metag fixes from James Hogan
- Add NULL checks in early_init_dt_scan
- Document proper use of unflatten_and_copy_device_tree
- fix section mismatches with of_flat_dt_get_machine_name
- fix non-DT boot on ARM

Rob


Rob Herring (29):
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
metag: 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 | 58 ++++++----------
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/c6x/kernel/vmlinux.lds.S | 6 --
arch/metag/include/asm/mach/arch.h | 2 +-
arch/metag/include/asm/prom.h | 2 +-
arch/metag/kernel/devtree.c | 83 ++++++----------------
arch/metag/kernel/setup.c | 6 +-
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 | 32 +++------
arch/xtensa/kernel/setup.c | 55 ++++-----------
drivers/of/fdt.c | 138 ++++++++++++++++++++++++++++++++++++-
include/linux/of_fdt.h | 18 +++--
28 files changed, 256 insertions(+), 580 deletions(-)

--
1.8.1.2


2013-10-07 16:30:15

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 10/29] 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]>
Acked-by: 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-10-07 16:30:20

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 12/29] 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]>
Acked-by: 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 055cfb8..4a5f624 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-10-07 16:30:28

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 13/29] 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]>
Acked-by: 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-10-07 16:30:24

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 14/29] metag: use early_init_dt_scan

From: Rob Herring <[email protected]>

Convert metag to use new early_init_dt_scan function.

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

diff --git a/arch/metag/kernel/devtree.c b/arch/metag/kernel/devtree.c
index 049af56..68c2fee 100644
--- a/arch/metag/kernel/devtree.c
+++ b/arch/metag/kernel/devtree.c
@@ -43,18 +43,16 @@ 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)
+ if (!early_init_dt_scan(dt))
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) {
@@ -90,9 +88,6 @@ struct machine_desc * __init setup_machine_fdt(void *dt)
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;

}
--
1.8.1.2

2013-10-07 16:30:35

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 21/29] 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]>
Acked-by: 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-10-07 16:30:50

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 29/29] 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]
Acked-by: John Crispin <[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-10-07 16:30:41

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 24/29] 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]>
Acked-by: 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 5f4cc88..5c47910 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 * __init 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.
+ */
+const void * __init of_flat_dt_match_machine(const void *default_match,
+ const void * (*get_next_compat)(const char * const**))
+{
+ const void *data = NULL;
+ const 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..dfaa1de 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);

+extern const char *of_flat_dt_get_machine_name(void);
+extern const void *of_flat_dt_match_machine(const void *default_match,
+ const 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-10-07 16:31:49

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 26/29] 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 e7ce175..0541f36 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 const void * __init arch_get_next_mach(const char *const **match)
+{
+ static const struct machine_desc *mdesc = __arch_info_begin;
+ const 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")
@@ -198,23 +208,17 @@ const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
if (!dt_phys || !early_init_dt_scan(phys_to_virt(dt_phys)))
return NULL;

+ 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);
@@ -225,16 +229,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-10-07 16:32:23

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 22/29] 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]>
Acked-by: 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]>
Acked-by: 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 0db805c..0e1f95b 100644
--- a/arch/x86/kernel/devicetree.c
+++ b/arch/x86/kernel/devicetree.c
@@ -51,15 +51,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 5bc55b6..5f4cc88 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-10-07 16:32:48

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 19/29] 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. 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: Michal Simek <[email protected]>
Cc: Jonas Bonn <[email protected]>
Acked-by: Grant Likely <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
arch/arm64/kernel/setup.c | 18 ------------------
arch/microblaze/kernel/prom.c | 5 -----
arch/openrisc/kernel/prom.c | 6 ------
drivers/of/fdt.c | 19 +++++++++++++++++++
4 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 4a5f624..7feb0c9 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/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/drivers/of/fdt.c b/drivers/of/fdt.c
index bfbfda5..5bc55b6 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -775,6 +775,25 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
}

#ifdef CONFIG_HAVE_MEMBLOCK
+void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
+{
+ const u64 phys_offset = __pa(PAGE_OFFSET);
+ 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);
+}
+
/*
* called from unflatten_device_tree() to bootstrap devicetree itself
* Architectures can override this definition if memblock isn't used
--
1.8.1.2

2013-10-07 16:33:33

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH v2 19/29] of: create default early_init_dt_add_memory_arch

On Mon, Oct 07, 2013 at 05:29:27PM +0100, Rob Herring wrote:
> From: Rob Herring <[email protected]>
>
> Create a weak version of early_init_dt_add_memory_arch which uses
> memblock. 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: Michal Simek <[email protected]>
> Cc: Jonas Bonn <[email protected]>
> Acked-by: Grant Likely <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]

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

2013-10-07 16:30:11

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 08/29] 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-10-07 16:34:13

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 11/29] 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 | 16 +---------------
1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
index f35906b..e7ce175 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;
@@ -196,17 +195,11 @@ const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
mdesc_best = &__mach_desc_GENERIC_DT;
#endif

- if (!dt_phys)
+ if (!dt_phys || !early_init_dt_scan(phys_to_virt(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;

/* 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 +233,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-10-07 16:30:06

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 06/29] 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-10-07 16:34:52

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 07/29] 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]>
Acked-by: Max Filippov <[email protected]>
Cc: [email protected]
Acked-by: Grant Likely <[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-10-07 16:35:15

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 03/29] 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]>
Acked-by: Grant Likely <[email protected]>
---
drivers/of/fdt.c | 24 ++++++++++++++++++++++++
include/linux/of_fdt.h | 2 ++
2 files changed, 26 insertions(+)

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

+/**
+ * unflatten_and_copy_device_tree - copy and create tree of device_nodes from flat blob
+ *
+ * Copies and unflattens the device-tree passed by the firmware, creating the
+ * tree of struct device_node. It also fills the "name" and "type"
+ * pointers of the nodes so the normal device-tree walking functions
+ * can be used. This should only be used when the FDT memory has not been
+ * reserved such is the case when the FDT is built-in to the kernel init
+ * section. If the FDT memory is reserved already then unflatten_device_tree
+ * should be used instead.
+ */
+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-10-07 16:35:30

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 01/29] 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]
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 +----------
arch/c6x/kernel/vmlinux.lds.S | 6 ------
4 files changed, 2 insertions(+), 19 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);
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
--
1.8.1.2

2013-10-07 16:35:44

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 17/29] 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-10-07 16:36:04

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 02/29] 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]
Reviewed-by: Grant Likely <[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-10-07 16:36:16

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 20/29] 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]
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-10-07 16:36:37

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 09/29] 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]>
Acked-by: Grant Likely <[email protected]>
---
drivers/of/fdt.c | 26 ++++++++++++++++++++++++++
include/linux/of_fdt.h | 2 ++
2 files changed, 28 insertions(+)

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

+bool __init early_init_dt_scan(void *params)
+{
+ if (!params)
+ return false;
+
+ /* Setup flat device-tree pointer */
+ initial_boot_params = params;
+
+ /* check device tree validity */
+ if (be32_to_cpu(initial_boot_params->magic) != OF_DT_HEADER) {
+ initial_boot_params = NULL;
+ 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-10-07 16:36:48

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 16/29] 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]
Acked-by: John Crispin <[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-10-07 16:36:51

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 28/29] 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]>
[james.hogan: fix missing arch_get_next_mach and const mismatch]
Reported-by: Guenter Roeck <[email protected]>
Signed-off-by: James Hogan <[email protected]>
---
arch/metag/include/asm/mach/arch.h | 2 +-
arch/metag/include/asm/prom.h | 2 +-
arch/metag/kernel/devtree.c | 60 ++++++++++++--------------------------
arch/metag/kernel/setup.c | 2 +-
4 files changed, 22 insertions(+), 44 deletions(-)

diff --git a/arch/metag/include/asm/mach/arch.h b/arch/metag/include/asm/mach/arch.h
index 12c5664..433f946 100644
--- a/arch/metag/include/asm/mach/arch.h
+++ b/arch/metag/include/asm/mach/arch.h
@@ -53,7 +53,7 @@ struct machine_desc {
/*
* Current machine - only accessible during boot.
*/
-extern struct machine_desc *machine_desc;
+extern const struct machine_desc *machine_desc;

/*
* Machine type table - also only accessible during boot
diff --git a/arch/metag/include/asm/prom.h b/arch/metag/include/asm/prom.h
index d2aa35d..9f67cbf 100644
--- a/arch/metag/include/asm/prom.h
+++ b/arch/metag/include/asm/prom.h
@@ -17,7 +17,7 @@
#include <asm/setup.h>
#define HAVE_ARCH_DEVTREE_FIXUPS

-extern struct machine_desc *setup_machine_fdt(void *dt);
+extern const struct machine_desc *setup_machine_fdt(void *dt);
extern void copy_fdt(void);

#endif /* __ASM_METAG_PROM_H */
diff --git a/arch/metag/kernel/devtree.c b/arch/metag/kernel/devtree.c
index 68c2fee..18dd7ae 100644
--- a/arch/metag/kernel/devtree.c
+++ b/arch/metag/kernel/devtree.c
@@ -34,6 +34,19 @@ void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
return alloc_bootmem_align(size, align);
}

+static const void * __init arch_get_next_mach(const char *const **match)
+{
+ static const struct machine_desc *mdesc = __arch_info_begin;
+ const 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
@@ -41,53 +54,18 @@ void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
* If a dtb was passed to the kernel, then use it to choose the correct
* machine_desc and to setup the system.
*/
-struct machine_desc * __init setup_machine_fdt(void *dt)
+const struct machine_desc * __init setup_machine_fdt(void *dt)
{
- struct machine_desc *mdesc, *mdesc_best = NULL;
- unsigned int score, mdesc_score = ~1;
- unsigned long dt_root;
- const char *model;
+ const struct machine_desc *mdesc;

/* check device tree validity */
if (!early_init_dt_scan(dt))
return NULL;

- /* 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) {
- 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");
-
+ 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);
-
- return mdesc_best;
+ pr_info("Machine name: %s\n", mdesc->name);

+ return mdesc;
}
diff --git a/arch/metag/kernel/setup.c b/arch/metag/kernel/setup.c
index 2c697d3..92cc119 100644
--- a/arch/metag/kernel/setup.c
+++ b/arch/metag/kernel/setup.c
@@ -115,7 +115,7 @@ extern u32 __dtb_start[];
extern struct console dash_console;
#endif

-struct machine_desc *machine_desc __initdata;
+const struct machine_desc *machine_desc __initdata;

/*
* Map a Linux CPU number to a hardware thread ID
--
1.8.1.2

2013-10-07 16:37:04

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 05/29] 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-10-07 16:37:12

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 27/29] 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]>
Acked-by: 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 7feb0c9..a4ed2d3 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-10-07 16:37:26

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 23/29] 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-10-07 16:37:40

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 18/29] 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]>
Acked-by: Max Filippov <[email protected]>
Cc: Chris Zankel <[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-10-07 16:38:30

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 15/29] 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]>
Tested-by: 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-10-07 16:38:28

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 25/29] 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]>
Acked-by: 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..12de555 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 const void * __init arch_get_next_mach(const char *const **match)
+{
+ static const struct machine_desc *mdesc = __arch_info_begin;
+ const 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-10-07 16:57:29

by Rob Herring

[permalink] [raw]
Subject: [PATCH v2 04/29] 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]>
Acked-by: Vineet Gupta <[email protected]>
Acked-by: Grant Likely <[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-10-07 20:12:49

by Mark Salter

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

On Mon, 2013-10-07 at 11:29 -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.
>
> Signed-off-by: Rob Herring <[email protected]>
> Cc: Mark Salter <[email protected]>
> Cc: Aurelien Jacquiot <[email protected]>
> Cc: [email protected]
> Reviewed-by: Grant Likely <[email protected]>
> ---
Tested and
Acked-by: Mark Salter <[email protected]>

2013-10-08 05:43:04

by Vineet Gupta

[permalink] [raw]
Subject: Re: [PATCH v2 25/29] arc: use common of_flat_dt_match_machine

Hi Rob,

On 10/07/2013 09:59 PM, Rob Herring wrote:
> From: Rob Herring <rob.herring-bsGFqQB8/[email protected]>
>
> Convert arc to use the common of_flat_dt_match_machine function.
>
> Signed-off-by: Rob Herring <rob.herring-bsGFqQB8/[email protected]>
> Acked-by: Vineet Gupta <vgupta-HKixBCOQz3hWk0Htik3J/[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..12de555 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 const void * __init arch_get_next_mach(const char *const **match)
> +{
> + static const struct machine_desc *mdesc = __arch_info_begin;
> + const 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;
> }
>

Can you please fold the following into this patch. This removes the const warning
and also gets rid of some dead code.

Thx,
-Vineet

------------------->
>From 3cd48b4955e9763248e306fff7ddf420b126ebab Mon Sep 17 00:00:00 2001
From: Vineet Gupta <[email protected]>
Date: Tue, 8 Oct 2013 09:53:17 +0530
Subject: [PATCH] ARC: Addendum to "use common of_flat_dt_match_machine"

Signed-off-by: Vineet Gupta <[email protected]>
---
arch/arc/include/asm/mach_desc.h | 14 ++------------
arch/arc/kernel/devtree.c | 4 ++--
arch/arc/kernel/setup.c | 2 +-
3 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/arch/arc/include/asm/mach_desc.h b/arch/arc/include/asm/mach_desc.h
index d3e9c0a05be8..c88c59c4183c 100644
--- a/arch/arc/include/asm/mach_desc.h
+++ b/arch/arc/include/asm/mach_desc.h
@@ -51,22 +51,12 @@ struct machine_desc {
/*
* Current machine - only accessible during boot.
*/
-extern struct machine_desc *machine_desc;
+extern const struct machine_desc *machine_desc;

/*
* Machine type table - also only accessible during boot
*/
extern struct machine_desc __arch_info_begin[], __arch_info_end[];
-#define for_each_machine_desc(p) \
- for (p = __arch_info_begin; p < __arch_info_end; p++)
-
-static inline struct machine_desc *default_machine_desc(void)
-{
- /* the default machine is the last one linked in */
- if (__arch_info_end - 1 < __arch_info_begin)
- return NULL;
- return __arch_info_end - 1;
-}

/*
* Set of macros to define architecture features.
@@ -81,6 +71,6 @@ __attribute__((__section__(".arch.info.init"))) = { \
#define MACHINE_END \
};

-extern struct machine_desc *setup_machine_fdt(void *dt);
+extern const struct machine_desc *setup_machine_fdt(void *dt);

#endif
diff --git a/arch/arc/kernel/devtree.c b/arch/arc/kernel/devtree.c
index 336396300e53..b6dc4e21fd32 100644
--- a/arch/arc/kernel/devtree.c
+++ b/arch/arc/kernel/devtree.c
@@ -37,9 +37,9 @@ static const void * __init arch_get_next_mach(const char *const
**match)
* If a dtb was passed to the kernel, then use it to choose the correct
* machine_desc and to setup the system.
*/
-struct machine_desc * __init setup_machine_fdt(void *dt)
+const struct machine_desc * __init setup_machine_fdt(void *dt)
{
- struct machine_desc *mdesc;
+ const struct machine_desc *mdesc;
unsigned long dt_root;
void *clk;
unsigned long len;
diff --git a/arch/arc/kernel/setup.c b/arch/arc/kernel/setup.c
index 5ae542454bed..f7d4a41d0629 100644
--- a/arch/arc/kernel/setup.c
+++ b/arch/arc/kernel/setup.c
@@ -30,7 +30,7 @@
int running_on_hw = 1; /* vs. on ISS */

char __initdata command_line[COMMAND_LINE_SIZE];
-struct machine_desc *machine_desc;
+const struct machine_desc *machine_desc;

struct task_struct *_current_task[NR_CPUS]; /* For stack switching */

-- 1.8.1.2

2013-10-09 17:04:54

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH v2 25/29] arc: use common of_flat_dt_match_machine

On Tue, Oct 8, 2013 at 12:42 AM, Vineet Gupta
<[email protected]> wrote:
> Hi Rob,
>
> On 10/07/2013 09:59 PM, Rob Herring wrote:
>> From: Rob Herring <rob.herring-bsGFqQB8/[email protected]>
>>
>> Convert arc to use the common of_flat_dt_match_machine function.
>>
>> Signed-off-by: Rob Herring <rob.herring-bsGFqQB8/[email protected]>
>> Acked-by: Vineet Gupta <vgupta-HKixBCOQz3hWk0Htik3J/[email protected]>

>
> Can you please fold the following into this patch. This removes the const warning
> and also gets rid of some dead code.

Thanks. I've added this in and updated my branch. Please double check
it when you have a chance. I also made __arch_info_begin[] and
__arch_info_end[] const.

Rob

2013-10-10 05:05:42

by Vineet Gupta

[permalink] [raw]
Subject: Re: [PATCH v2 25/29] arc: use common of_flat_dt_match_machine

On 10/09/2013 10:35 PM, Rob Herring wrote:
> Thanks. I've added this in and updated my branch. Please double check
> it when you have a chance. I also made __arch_info_begin[] and
> __arch_info_end[] const.

Works great !

Thx,
-Vineet