Commit | Line | Data |
---|---|---|
12e84142 MS |
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> | |
95f72d1e | 32 | #include <linux/memblock.h> |
12e84142 MS |
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> | |
12e84142 MS |
39 | #include <asm/mmu.h> |
40 | #include <asm/pgtable.h> | |
12e84142 MS |
41 | #include <asm/sections.h> |
42 | #include <asm/pci-bridge.h> | |
43 | ||
51975db0 | 44 | void __init early_init_dt_add_memory_arch(u64 base, u64 size) |
12e84142 | 45 | { |
95f72d1e | 46 | memblock_add(base, size); |
12e84142 MS |
47 | } |
48 | ||
672c5446 | 49 | void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align) |
4ef7b373 | 50 | { |
672c5446 | 51 | return __va(memblock_alloc(size, align)); |
4ef7b373 JK |
52 | } |
53 | ||
12e84142 | 54 | #ifdef CONFIG_EARLY_PRINTK |
2aa8e375 | 55 | char *stdout; |
12e84142 | 56 | |
2aa8e375 | 57 | int __init early_init_dt_scan_chosen_serial(unsigned long node, |
67f4aaa2 MS |
58 | const char *uname, int depth, void *data) |
59 | { | |
60 | unsigned long l; | |
61 | char *p; | |
67f4aaa2 | 62 | |
2aa8e375 MS |
63 | pr_debug("%s: depth: %d, uname: %s\n", __func__, depth, uname); |
64 | ||
65 | if (depth == 1 && (strcmp(uname, "chosen") == 0 || | |
66 | strcmp(uname, "chosen@0") == 0)) { | |
67 | p = of_get_flat_dt_prop(node, "linux,stdout-path", &l); | |
68 | if (p != NULL && l > 0) | |
69 | stdout = p; /* store pointer to stdout-path */ | |
70 | } | |
71 | ||
72 | if (stdout && strstr(stdout, uname)) { | |
73 | p = of_get_flat_dt_prop(node, "compatible", &l); | |
74 | pr_debug("Compatible string: %s\n", p); | |
75 | ||
76 | if ((strncmp(p, "xlnx,xps-uart16550", 18) == 0) || | |
77 | (strncmp(p, "xlnx,axi-uart16550", 18) == 0)) { | |
78 | unsigned int addr; | |
79 | ||
80 | *(u32 *)data = UART16550; | |
81 | ||
82 | addr = *(u32 *)of_get_flat_dt_prop(node, "reg", &l); | |
83 | addr += *(u32 *)of_get_flat_dt_prop(node, | |
84 | "reg-offset", &l); | |
85 | /* clear register offset */ | |
86 | return be32_to_cpu(addr) & ~3; | |
87 | } | |
88 | if ((strncmp(p, "xlnx,xps-uartlite", 17) == 0) || | |
89 | (strncmp(p, "xlnx,opb-uartlite", 17) == 0) || | |
ca12adc8 MS |
90 | (strncmp(p, "xlnx,axi-uartlite", 17) == 0) || |
91 | (strncmp(p, "xlnx,mdm", 8) == 0)) { | |
2aa8e375 MS |
92 | unsigned int *addrp; |
93 | ||
94 | *(u32 *)data = UARTLITE; | |
95 | ||
96 | addrp = of_get_flat_dt_prop(node, "reg", &l); | |
97 | return be32_to_cpup(addrp); /* return address */ | |
98 | } | |
99 | } | |
100 | return 0; | |
67f4aaa2 MS |
101 | } |
102 | ||
2aa8e375 MS |
103 | /* this function is looking for early console - Microblaze specific */ |
104 | int __init of_early_console(void *version) | |
67f4aaa2 | 105 | { |
2aa8e375 | 106 | return of_scan_flat_dt(early_init_dt_scan_chosen_serial, version); |
67f4aaa2 | 107 | } |
12e84142 MS |
108 | #endif |
109 | ||
110 | void __init early_init_devtree(void *params) | |
111 | { | |
112 | pr_debug(" -> early_init_devtree(%p)\n", params); | |
113 | ||
114 | /* Setup flat device-tree pointer */ | |
115 | initial_boot_params = params; | |
116 | ||
12e84142 MS |
117 | /* Retrieve various informations from the /chosen node of the |
118 | * device-tree, including the platform type, initrd location and | |
119 | * size, TCE reserve, and more ... | |
120 | */ | |
85f60ae4 | 121 | of_scan_flat_dt(early_init_dt_scan_chosen, cmd_line); |
12e84142 | 122 | |
95f72d1e | 123 | /* Scan memory nodes and rebuild MEMBLOCKs */ |
12e84142 MS |
124 | of_scan_flat_dt(early_init_dt_scan_root, NULL); |
125 | of_scan_flat_dt(early_init_dt_scan_memory, NULL); | |
126 | ||
127 | /* Save command line for /proc/cmdline and then parse parameters */ | |
128 | strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE); | |
129 | parse_early_param(); | |
130 | ||
1aadc056 | 131 | memblock_allow_resize(); |
12e84142 | 132 | |
95f72d1e | 133 | pr_debug("Phys. mem: %lx\n", (unsigned long) memblock_phys_mem_size()); |
12e84142 | 134 | |
12e84142 MS |
135 | pr_debug(" <- early_init_devtree()\n"); |
136 | } | |
137 | ||
1406bc2f JK |
138 | #ifdef CONFIG_BLK_DEV_INITRD |
139 | void __init early_init_dt_setup_initrd_arch(unsigned long start, | |
140 | unsigned long end) | |
141 | { | |
142 | initrd_start = (unsigned long)__va(start); | |
143 | initrd_end = (unsigned long)__va(end); | |
144 | initrd_below_start_ok = 1; | |
145 | } | |
146 | #endif | |
147 | ||
12e84142 MS |
148 | /******* |
149 | * | |
150 | * New implementation of the OF "find" APIs, return a refcounted | |
151 | * object, call of_node_put() when done. The device tree and list | |
152 | * are protected by a rw_lock. | |
153 | * | |
154 | * Note that property management will need some locking as well, | |
155 | * this isn't dealt with yet. | |
156 | * | |
157 | *******/ | |
158 | ||
12e84142 MS |
159 | #if defined(CONFIG_DEBUG_FS) && defined(DEBUG) |
160 | static struct debugfs_blob_wrapper flat_dt_blob; | |
161 | ||
162 | static int __init export_flat_device_tree(void) | |
163 | { | |
164 | struct dentry *d; | |
165 | ||
166 | flat_dt_blob.data = initial_boot_params; | |
167 | flat_dt_blob.size = initial_boot_params->totalsize; | |
168 | ||
169 | d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR, | |
170 | of_debugfs_root, &flat_dt_blob); | |
171 | if (!d) | |
172 | return 1; | |
173 | ||
174 | return 0; | |
175 | } | |
176 | device_initcall(export_flat_device_tree); | |
177 | #endif |