x86/xen: resume timer irqs early
[linux/fpc-iii.git] / arch / arc / kernel / devtree.c
blob2340af0e1d6f8c00b57b35a127bf73f673a244e2
1 /*
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.
9 */
12 #include <linux/init.h>
13 #include <linux/reboot.h>
14 #include <linux/memblock.h>
15 #include <linux/of.h>
16 #include <linux/of_fdt.h>
17 #include <asm/prom.h>
18 #include <asm/clk.h>
19 #include <asm/mach_desc.h>
21 /**
22 * setup_machine_fdt - Machine setup when an dtb was passed to the kernel
23 * @dt: virtual address pointer to dt blob
25 * If a dtb was passed to the kernel, then use it to choose the correct
26 * machine_desc and to setup the system.
28 struct machine_desc * __init setup_machine_fdt(void *dt)
30 struct boot_param_header *devtree = dt;
31 struct machine_desc *mdesc = NULL, *mdesc_best = NULL;
32 unsigned int score, mdesc_score = ~1;
33 unsigned long dt_root;
34 const char *model, *compat;
35 void *clk;
36 char manufacturer[16];
37 unsigned long len;
39 /* check device tree validity */
40 if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
41 return NULL;
43 initial_boot_params = devtree;
44 dt_root = of_get_flat_dt_root();
47 * The kernel could be multi-platform enabled, thus could have many
48 * "baked-in" machine descriptors. Search thru all for the best
49 * "compatible" string match.
51 for_each_machine_desc(mdesc) {
52 score = of_flat_dt_match(dt_root, mdesc->dt_compat);
53 if (score > 0 && score < mdesc_score) {
54 mdesc_best = mdesc;
55 mdesc_score = score;
58 if (!mdesc_best) {
59 const char *prop;
60 long size;
62 pr_err("\n unrecognized device tree list:\n[ ");
64 prop = of_get_flat_dt_prop(dt_root, "compatible", &size);
65 if (prop) {
66 while (size > 0) {
67 printk("'%s' ", prop);
68 size -= strlen(prop) + 1;
69 prop += strlen(prop) + 1;
72 printk("]\n\n");
74 machine_halt();
77 /* compat = "<manufacturer>,<model>" */
78 compat = mdesc_best->dt_compat[0];
80 model = strchr(compat, ',');
81 if (model)
82 model++;
84 strlcpy(manufacturer, compat, model ? model - compat : strlen(compat));
86 pr_info("Board \"%s\" from %s (Manufacturer)\n", model, manufacturer);
88 /* Retrieve various information from the /chosen node */
89 of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
91 /* Initialize {size,address}-cells info */
92 of_scan_flat_dt(early_init_dt_scan_root, NULL);
94 /* Setup memory, calling early_init_dt_add_memory_arch */
95 of_scan_flat_dt(early_init_dt_scan_memory, NULL);
97 clk = of_get_flat_dt_prop(dt_root, "clock-frequency", &len);
98 if (clk)
99 arc_set_core_freq(of_read_ulong(clk, len/4));
101 return mdesc_best;
105 * Copy the flattened DT out of .init since unflattening doesn't copy strings
106 * and the normal DT APIs refs them from orig flat DT
108 void __init copy_devtree(void)
110 void *alloc = early_init_dt_alloc_memory_arch(
111 be32_to_cpu(initial_boot_params->totalsize), 64);
112 if (alloc) {
113 memcpy(alloc, initial_boot_params,
114 be32_to_cpu(initial_boot_params->totalsize));
115 initial_boot_params = alloc;