2 * Copyright (C) 2012 Synopsys, Inc. (www.synopsys.com)
4 * Based on reduced version of METAG
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
12 #include <linux/init.h>
13 #include <linux/reboot.h>
14 #include <linux/memblock.h>
16 #include <linux/of_fdt.h>
19 #include <asm/mach_desc.h>
21 /* called from unflatten_device_tree() to bootstrap devicetree itself */
22 void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
24 return __va(memblock_alloc(size, align));
28 * setup_machine_fdt - Machine setup when an dtb was passed to the kernel
29 * @dt: virtual address pointer to dt blob
31 * If a dtb was passed to the kernel, then use it to choose the correct
32 * machine_desc and to setup the system.
34 struct machine_desc * __init setup_machine_fdt(void *dt)
36 struct boot_param_header *devtree = dt;
37 struct machine_desc *mdesc = NULL, *mdesc_best = NULL;
38 unsigned int score, mdesc_score = ~1;
39 unsigned long dt_root;
40 const char *model, *compat;
42 char manufacturer[16];
45 /* check device tree validity */
46 if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
49 initial_boot_params = devtree;
50 dt_root = of_get_flat_dt_root();
53 * The kernel could be multi-platform enabled, thus could have many
54 * "baked-in" machine descriptors. Search thru all for the best
55 * "compatible" string match.
57 for_each_machine_desc(mdesc) {
58 score = of_flat_dt_match(dt_root, mdesc->dt_compat);
59 if (score > 0 && score < mdesc_score) {
68 pr_err("\n unrecognized device tree list:\n[ ");
70 prop = of_get_flat_dt_prop(dt_root, "compatible", &size);
73 printk("'%s' ", prop);
74 size -= strlen(prop) + 1;
75 prop += strlen(prop) + 1;
83 /* compat = "<manufacturer>,<model>" */
84 compat = mdesc_best->dt_compat[0];
86 model = strchr(compat, ',');
90 strlcpy(manufacturer, compat, model ? model - compat : strlen(compat));
92 pr_info("Board \"%s\" from %s (Manufacturer)\n", model, manufacturer);
94 /* Retrieve various information from the /chosen node */
95 of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
97 /* Initialize {size,address}-cells info */
98 of_scan_flat_dt(early_init_dt_scan_root, NULL);
100 /* Setup memory, calling early_init_dt_add_memory_arch */
101 of_scan_flat_dt(early_init_dt_scan_memory, NULL);
103 clk = of_get_flat_dt_prop(dt_root, "clock-frequency", &len);
105 arc_set_core_freq(of_read_ulong(clk, len/4));
111 * Copy the flattened DT out of .init since unflattening doesn't copy strings
112 * and the normal DT APIs refs them from orig flat DT
114 void __init copy_devtree(void)
116 void *alloc = early_init_dt_alloc_memory_arch(
117 be32_to_cpu(initial_boot_params->totalsize), 64);
119 memcpy(alloc, initial_boot_params,
120 be32_to_cpu(initial_boot_params->totalsize));
121 initial_boot_params = alloc;