2 * linux/arch/metag/kernel/devtree.c
4 * Copyright (C) 2012 Imagination Technologies Ltd.
6 * Based on ARM version:
7 * Copyright (C) 2009 Canonical Ltd. <jeremy.kerr@canonical.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/init.h>
15 #include <linux/export.h>
16 #include <linux/types.h>
17 #include <linux/bootmem.h>
18 #include <linux/memblock.h>
20 #include <linux/of_fdt.h>
22 #include <asm/setup.h>
24 #include <asm/mach/arch.h>
26 void __init
early_init_dt_add_memory_arch(u64 base
, u64 size
)
28 pr_err("%s(%llx, %llx)\n",
29 __func__
, base
, size
);
32 void * __init
early_init_dt_alloc_memory_arch(u64 size
, u64 align
)
34 return alloc_bootmem_align(size
, align
);
38 * setup_machine_fdt - Machine setup when an dtb was passed to the kernel
39 * @dt: virtual address pointer to dt blob
41 * If a dtb was passed to the kernel, then use it to choose the correct
42 * machine_desc and to setup the system.
44 struct machine_desc
* __init
setup_machine_fdt(void *dt
)
46 struct boot_param_header
*devtree
= dt
;
47 struct machine_desc
*mdesc
, *mdesc_best
= NULL
;
48 unsigned int score
, mdesc_score
= ~1;
49 unsigned long dt_root
;
52 /* check device tree validity */
53 if (be32_to_cpu(devtree
->magic
) != OF_DT_HEADER
)
56 /* Search the mdescs for the 'best' compatible value match */
57 initial_boot_params
= devtree
;
58 dt_root
= of_get_flat_dt_root();
60 for_each_machine_desc(mdesc
) {
61 score
= of_flat_dt_match(dt_root
, mdesc
->dt_compat
);
62 if (score
> 0 && score
< mdesc_score
) {
71 pr_err("\nError: unrecognized/unsupported device tree compatible list:\n[ ");
73 prop
= of_get_flat_dt_prop(dt_root
, "compatible", &size
);
76 printk("'%s' ", prop
);
77 size
-= strlen(prop
) + 1;
78 prop
+= strlen(prop
) + 1;
83 dump_machine_table(); /* does not return */
86 model
= of_get_flat_dt_prop(dt_root
, "model", NULL
);
88 model
= of_get_flat_dt_prop(dt_root
, "compatible", NULL
);
91 pr_info("Machine: %s, model: %s\n", mdesc_best
->name
, model
);
93 /* Retrieve various information from the /chosen node */
94 of_scan_flat_dt(early_init_dt_scan_chosen
, boot_command_line
);
100 * copy_fdt - Copy device tree into non-init memory.
102 * We must copy the flattened device tree blob into non-init memory because the
103 * unflattened device tree will reference the strings in it directly.
105 void __init
copy_fdt(void)
107 void *alloc
= early_init_dt_alloc_memory_arch(
108 be32_to_cpu(initial_boot_params
->totalsize
), 0x40);
110 memcpy(alloc
, initial_boot_params
,
111 be32_to_cpu(initial_boot_params
->totalsize
));
112 initial_boot_params
= alloc
;