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