1 /*
2 * Procedures for creating, accessing and interpreting the device tree.
3 *
4 * Paul Mackerras August 1996.
5 * Copyright (C) 1996-2005 Paul Mackerras.
6 *
7 * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
8 * {engebret|bergner}@us.ibm.com
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 */
15
16 #include <stdarg.h>
17 #include <linux/kernel.h>
18 #include <linux/string.h>
19 #include <linux/init.h>
20 #include <linux/threads.h>
21 #include <linux/spinlock.h>
22 #include <linux/types.h>
23 #include <linux/pci.h>
24 #include <linux/stringify.h>
25 #include <linux/delay.h>
26 #include <linux/initrd.h>
27 #include <linux/bitops.h>
28 #include <linux/module.h>
29 #include <linux/kexec.h>
30 #include <linux/debugfs.h>
31 #include <linux/irq.h>
32 #include <linux/memblock.h>
33
34 #include <asm/prom.h>
35 #include <asm/page.h>
36 #include <asm/processor.h>
37 #include <asm/irq.h>
38 #include <linux/io.h>
39 #include <asm/system.h>
40 #include <asm/mmu.h>
41 #include <asm/pgtable.h>
42 #include <asm/sections.h>
43 #include <asm/pci-bridge.h>
44
early_init_dt_add_memory_arch(u64 base,u64 size)45 void __init early_init_dt_add_memory_arch(u64 base, u64 size)
46 {
47 memblock_add(base, size);
48 }
49
early_init_dt_alloc_memory_arch(u64 size,u64 align)50 void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
51 {
52 return __va(memblock_alloc(size, align));
53 }
54
55 #ifdef CONFIG_EARLY_PRINTK
56 /* MS this is Microblaze specifig function */
early_init_dt_scan_serial(unsigned long node,const char * uname,int depth,void * data)57 static int __init early_init_dt_scan_serial(unsigned long node,
58 const char *uname, int depth, void *data)
59 {
60 unsigned long l;
61 char *p;
62 const __be32 *addr;
63
64 pr_debug("search \"serial\", depth: %d, uname: %s\n", depth, uname);
65
66 /* find all serial nodes */
67 if (strncmp(uname, "serial", 6) != 0)
68 return 0;
69
70 /* find compatible node with uartlite */
71 p = of_get_flat_dt_prop(node, "compatible", &l);
72 if ((strncmp(p, "xlnx,xps-uartlite", 17) != 0) &&
73 (strncmp(p, "xlnx,opb-uartlite", 17) != 0) &&
74 (strncmp(p, "xlnx,axi-uartlite", 17) != 0))
75 return 0;
76
77 addr = of_get_flat_dt_prop(node, "reg", &l);
78 return be32_to_cpup(addr); /* return address */
79 }
80
81 /* this function is looking for early uartlite console - Microblaze specific */
early_uartlite_console(void)82 int __init early_uartlite_console(void)
83 {
84 return of_scan_flat_dt(early_init_dt_scan_serial, NULL);
85 }
86
87 /* MS this is Microblaze specifig function */
early_init_dt_scan_serial_full(unsigned long node,const char * uname,int depth,void * data)88 static int __init early_init_dt_scan_serial_full(unsigned long node,
89 const char *uname, int depth, void *data)
90 {
91 unsigned long l;
92 char *p;
93 unsigned int addr;
94
95 pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
96
97 /* find all serial nodes */
98 if (strncmp(uname, "serial", 6) != 0)
99 return 0;
100
101 early_init_dt_check_for_initrd(node);
102
103 /* find compatible node with uartlite */
104 p = of_get_flat_dt_prop(node, "compatible", &l);
105
106 if ((strncmp(p, "xlnx,xps-uart16550", 18) != 0) &&
107 (strncmp(p, "xlnx,axi-uart16550", 18) != 0))
108 return 0;
109
110 addr = *(u32 *)of_get_flat_dt_prop(node, "reg", &l);
111 addr += *(u32 *)of_get_flat_dt_prop(node, "reg-offset", &l);
112 return be32_to_cpu(addr); /* return address */
113 }
114
115 /* this function is looking for early uartlite console - Microblaze specific */
early_uart16550_console(void)116 int __init early_uart16550_console(void)
117 {
118 return of_scan_flat_dt(early_init_dt_scan_serial_full, NULL);
119 }
120 #endif
121
early_init_devtree(void * params)122 void __init early_init_devtree(void *params)
123 {
124 pr_debug(" -> early_init_devtree(%p)\n", params);
125
126 /* Setup flat device-tree pointer */
127 initial_boot_params = params;
128
129 /* Retrieve various informations from the /chosen node of the
130 * device-tree, including the platform type, initrd location and
131 * size, TCE reserve, and more ...
132 */
133 of_scan_flat_dt(early_init_dt_scan_chosen, NULL);
134
135 /* Scan memory nodes and rebuild MEMBLOCKs */
136 memblock_init();
137 of_scan_flat_dt(early_init_dt_scan_root, NULL);
138 of_scan_flat_dt(early_init_dt_scan_memory, NULL);
139
140 /* Save command line for /proc/cmdline and then parse parameters */
141 strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
142 parse_early_param();
143
144 memblock_analyze();
145
146 pr_debug("Phys. mem: %lx\n", (unsigned long) memblock_phys_mem_size());
147
148 pr_debug(" <- early_init_devtree()\n");
149 }
150
151 #ifdef CONFIG_BLK_DEV_INITRD
early_init_dt_setup_initrd_arch(unsigned long start,unsigned long end)152 void __init early_init_dt_setup_initrd_arch(unsigned long start,
153 unsigned long end)
154 {
155 initrd_start = (unsigned long)__va(start);
156 initrd_end = (unsigned long)__va(end);
157 initrd_below_start_ok = 1;
158 }
159 #endif
160
161 /*******
162 *
163 * New implementation of the OF "find" APIs, return a refcounted
164 * object, call of_node_put() when done. The device tree and list
165 * are protected by a rw_lock.
166 *
167 * Note that property management will need some locking as well,
168 * this isn't dealt with yet.
169 *
170 *******/
171
172 #if defined(CONFIG_DEBUG_FS) && defined(DEBUG)
173 static struct debugfs_blob_wrapper flat_dt_blob;
174
export_flat_device_tree(void)175 static int __init export_flat_device_tree(void)
176 {
177 struct dentry *d;
178
179 flat_dt_blob.data = initial_boot_params;
180 flat_dt_blob.size = initial_boot_params->totalsize;
181
182 d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR,
183 of_debugfs_root, &flat_dt_blob);
184 if (!d)
185 return 1;
186
187 return 0;
188 }
189 device_initcall(export_flat_device_tree);
190 #endif
191