blob: a105301e2b7fec6465daa9ac89c06a20b65cd59f [file] [log] [blame]
Michal Simek12e84142009-03-27 14:25:12 +01001/*
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>
Yinghai Lu95f72d12010-07-12 14:36:09 +100032#include <linux/memblock.h>
Michal Simek12e84142009-03-27 14:25:12 +010033
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>
Michal Simek12e84142009-03-27 14:25:12 +010042#include <asm/sections.h>
43#include <asm/pci-bridge.h>
44
Grant Likely51975db2010-02-01 21:34:14 -070045void __init early_init_dt_add_memory_arch(u64 base, u64 size)
Michal Simek12e84142009-03-27 14:25:12 +010046{
Yinghai Lu95f72d12010-07-12 14:36:09 +100047 memblock_add(base, size);
Michal Simek12e84142009-03-27 14:25:12 +010048}
49
Jeremy Kerr4ef7b372010-02-14 07:13:47 -070050u64 __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
51{
Yinghai Lu95f72d12010-07-12 14:36:09 +100052 return memblock_alloc(size, align);
Jeremy Kerr4ef7b372010-02-14 07:13:47 -070053}
54
Michal Simek12e84142009-03-27 14:25:12 +010055#ifdef CONFIG_EARLY_PRINTK
56/* MS this is Microblaze specifig function */
57static 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 int *addr;
63
64 pr_debug("search \"chosen\", 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 early_init_dt_check_for_initrd(node);
71
72/* find compatible node with uartlite */
73 p = of_get_flat_dt_prop(node, "compatible", &l);
74 if ((strncmp(p, "xlnx,xps-uartlite", 17) != 0) &&
Michal Simek02b08042010-09-28 16:04:14 +100075 (strncmp(p, "xlnx,opb-uartlite", 17) != 0) &&
76 (strncmp(p, "xlnx,axi-uartlite", 17) != 0))
Michal Simek12e84142009-03-27 14:25:12 +010077 return 0;
78
79 addr = of_get_flat_dt_prop(node, "reg", &l);
Michal Simek02b08042010-09-28 16:04:14 +100080 return be32_to_cpup(addr); /* return address */
Michal Simek12e84142009-03-27 14:25:12 +010081}
82
83/* this function is looking for early uartlite console - Microblaze specific */
84int __init early_uartlite_console(void)
85{
86 return of_scan_flat_dt(early_init_dt_scan_serial, NULL);
87}
Michal Simek67f4aaa2010-09-28 16:17:03 +100088
89/* MS this is Microblaze specifig function */
90static int __init early_init_dt_scan_serial_full(unsigned long node,
91 const char *uname, int depth, void *data)
92{
93 unsigned long l;
94 char *p;
95 unsigned int addr;
96
97 pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
98
99/* find all serial nodes */
100 if (strncmp(uname, "serial", 6) != 0)
101 return 0;
102
103 early_init_dt_check_for_initrd(node);
104
105/* find compatible node with uartlite */
106 p = of_get_flat_dt_prop(node, "compatible", &l);
107
108 if ((strncmp(p, "xlnx,xps-uart16550", 18) != 0) &&
109 (strncmp(p, "xlnx,axi-uart16550", 18) != 0))
110 return 0;
111
112 addr = *(u32 *)of_get_flat_dt_prop(node, "reg", &l);
113 addr += *(u32 *)of_get_flat_dt_prop(node, "reg-offset", &l);
Michal Simek02b08042010-09-28 16:04:14 +1000114 return be32_to_cpu(addr); /* return address */
Michal Simek67f4aaa2010-09-28 16:17:03 +1000115}
116
117/* this function is looking for early uartlite console - Microblaze specific */
118int __init early_uart16550_console(void)
119{
120 return of_scan_flat_dt(early_init_dt_scan_serial_full, NULL);
121}
Michal Simek12e84142009-03-27 14:25:12 +0100122#endif
123
124void __init early_init_devtree(void *params)
125{
126 pr_debug(" -> early_init_devtree(%p)\n", params);
127
128 /* Setup flat device-tree pointer */
129 initial_boot_params = params;
130
Michal Simek12e84142009-03-27 14:25:12 +0100131 /* Retrieve various informations from the /chosen node of the
132 * device-tree, including the platform type, initrd location and
133 * size, TCE reserve, and more ...
134 */
135 of_scan_flat_dt(early_init_dt_scan_chosen, NULL);
136
Yinghai Lu95f72d12010-07-12 14:36:09 +1000137 /* Scan memory nodes and rebuild MEMBLOCKs */
138 memblock_init();
Michal Simek12e84142009-03-27 14:25:12 +0100139 of_scan_flat_dt(early_init_dt_scan_root, NULL);
140 of_scan_flat_dt(early_init_dt_scan_memory, NULL);
141
142 /* Save command line for /proc/cmdline and then parse parameters */
143 strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
144 parse_early_param();
145
Yinghai Lu95f72d12010-07-12 14:36:09 +1000146 memblock_analyze();
Michal Simek12e84142009-03-27 14:25:12 +0100147
Yinghai Lu95f72d12010-07-12 14:36:09 +1000148 pr_debug("Phys. mem: %lx\n", (unsigned long) memblock_phys_mem_size());
Michal Simek12e84142009-03-27 14:25:12 +0100149
Michal Simek12e84142009-03-27 14:25:12 +0100150 pr_debug(" <- early_init_devtree()\n");
151}
152
Jeremy Kerr1406bc22010-01-30 01:31:21 -0700153#ifdef CONFIG_BLK_DEV_INITRD
154void __init early_init_dt_setup_initrd_arch(unsigned long start,
155 unsigned long end)
156{
157 initrd_start = (unsigned long)__va(start);
158 initrd_end = (unsigned long)__va(end);
159 initrd_below_start_ok = 1;
160}
161#endif
162
Michal Simek12e84142009-03-27 14:25:12 +0100163/*******
164 *
165 * New implementation of the OF "find" APIs, return a refcounted
166 * object, call of_node_put() when done. The device tree and list
167 * are protected by a rw_lock.
168 *
169 * Note that property management will need some locking as well,
170 * this isn't dealt with yet.
171 *
172 *******/
173
Michal Simek12e84142009-03-27 14:25:12 +0100174#if defined(CONFIG_DEBUG_FS) && defined(DEBUG)
175static struct debugfs_blob_wrapper flat_dt_blob;
176
177static int __init export_flat_device_tree(void)
178{
179 struct dentry *d;
180
181 flat_dt_blob.data = initial_boot_params;
182 flat_dt_blob.size = initial_boot_params->totalsize;
183
184 d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR,
185 of_debugfs_root, &flat_dt_blob);
186 if (!d)
187 return 1;
188
189 return 0;
190}
191device_initcall(export_flat_device_tree);
192#endif