1
2
3
4
5#include <linux/module.h>
6#include <linux/string.h>
7#include <linux/sched.h>
8#include <linux/init.h>
9#include <linux/kernel.h>
10#include <linux/reboot.h>
11#include <linux/delay.h>
12#include <linux/initrd.h>
13#include <linux/tty.h>
14#include <linux/bootmem.h>
15#include <linux/seq_file.h>
16#include <linux/root_dev.h>
17#include <linux/cpu.h>
18#include <linux/console.h>
19#include <linux/memblock.h>
20
21#include <asm/io.h>
22#include <asm/prom.h>
23#include <asm/processor.h>
24#include <asm/pgtable.h>
25#include <asm/setup.h>
26#include <asm/smp.h>
27#include <asm/elf.h>
28#include <asm/cputable.h>
29#include <asm/bootx.h>
30#include <asm/btext.h>
31#include <asm/machdep.h>
32#include <asm/uaccess.h>
33#include <asm/pmac_feature.h>
34#include <asm/sections.h>
35#include <asm/nvram.h>
36#include <asm/xmon.h>
37#include <asm/time.h>
38#include <asm/serial.h>
39#include <asm/udbg.h>
40#include <asm/mmu_context.h>
41
42#define DBG(fmt...)
43
44extern void bootx_init(unsigned long r4, unsigned long phys);
45
46int boot_cpuid_phys;
47EXPORT_SYMBOL_GPL(boot_cpuid_phys);
48
49int smp_hw_index[NR_CPUS];
50
51unsigned long ISA_DMA_THRESHOLD;
52unsigned int DMA_MODE_READ;
53unsigned int DMA_MODE_WRITE;
54
55#ifdef CONFIG_VGA_CONSOLE
56unsigned long vgacon_remap_base;
57EXPORT_SYMBOL(vgacon_remap_base);
58#endif
59
60
61
62
63
64int dcache_bsize;
65int icache_bsize;
66int ucache_bsize;
67
68
69
70
71
72
73
74
75
76
77notrace unsigned long __init early_init(unsigned long dt_ptr)
78{
79 unsigned long offset = reloc_offset();
80 struct cpu_spec *spec;
81
82
83
84 memset_io((void __iomem *)PTRRELOC(&__bss_start), 0,
85 __bss_stop - __bss_start);
86
87
88
89
90
91 spec = identify_cpu(offset, mfspr(SPRN_PVR));
92
93 do_feature_fixups(spec->cpu_features,
94 PTRRELOC(&__start___ftr_fixup),
95 PTRRELOC(&__stop___ftr_fixup));
96
97 do_feature_fixups(spec->mmu_features,
98 PTRRELOC(&__start___mmu_ftr_fixup),
99 PTRRELOC(&__stop___mmu_ftr_fixup));
100
101 do_lwsync_fixups(spec->cpu_features,
102 PTRRELOC(&__start___lwsync_fixup),
103 PTRRELOC(&__stop___lwsync_fixup));
104
105 do_final_fixups();
106
107 return KERNELBASE + offset;
108}
109
110
111
112
113
114
115
116
117notrace void __init machine_init(u64 dt_ptr)
118{
119 lockdep_init();
120
121
122 udbg_early_init();
123
124
125 early_init_devtree(__va(dt_ptr));
126
127 early_init_mmu();
128
129 probe_machine();
130
131 setup_kdump_trampoline();
132
133#ifdef CONFIG_6xx
134 if (cpu_has_feature(CPU_FTR_CAN_DOZE) ||
135 cpu_has_feature(CPU_FTR_CAN_NAP))
136 ppc_md.power_save = ppc6xx_idle;
137#endif
138
139#ifdef CONFIG_E500
140 if (cpu_has_feature(CPU_FTR_CAN_DOZE) ||
141 cpu_has_feature(CPU_FTR_CAN_NAP))
142 ppc_md.power_save = e500_idle;
143#endif
144 if (ppc_md.progress)
145 ppc_md.progress("id mach(): done", 0x200);
146}
147
148
149int __init ppc_setup_l2cr(char *str)
150{
151 if (cpu_has_feature(CPU_FTR_L2CR)) {
152 unsigned long val = simple_strtoul(str, NULL, 0);
153 printk(KERN_INFO "l2cr set to %lx\n", val);
154 _set_L2CR(0);
155 _set_L2CR(val);
156 }
157 return 1;
158}
159__setup("l2cr=", ppc_setup_l2cr);
160
161
162int __init ppc_setup_l3cr(char *str)
163{
164 if (cpu_has_feature(CPU_FTR_L3CR)) {
165 unsigned long val = simple_strtoul(str, NULL, 0);
166 printk(KERN_INFO "l3cr set to %lx\n", val);
167 _set_L3CR(val);
168 }
169 return 1;
170}
171__setup("l3cr=", ppc_setup_l3cr);
172
173#ifdef CONFIG_GENERIC_NVRAM
174
175
176unsigned char nvram_read_byte(int addr)
177{
178 if (ppc_md.nvram_read_val)
179 return ppc_md.nvram_read_val(addr);
180 return 0xff;
181}
182EXPORT_SYMBOL(nvram_read_byte);
183
184void nvram_write_byte(unsigned char val, int addr)
185{
186 if (ppc_md.nvram_write_val)
187 ppc_md.nvram_write_val(addr, val);
188}
189EXPORT_SYMBOL(nvram_write_byte);
190
191ssize_t nvram_get_size(void)
192{
193 if (ppc_md.nvram_size)
194 return ppc_md.nvram_size();
195 return -1;
196}
197EXPORT_SYMBOL(nvram_get_size);
198
199void nvram_sync(void)
200{
201 if (ppc_md.nvram_sync)
202 ppc_md.nvram_sync();
203}
204EXPORT_SYMBOL(nvram_sync);
205
206#endif
207
208int __init ppc_init(void)
209{
210
211 if (ppc_md.progress)
212 ppc_md.progress(" ", 0xffff);
213
214
215 if (ppc_md.init != NULL) {
216 ppc_md.init();
217 }
218 return 0;
219}
220
221arch_initcall(ppc_init);
222
223static void __init irqstack_early_init(void)
224{
225 unsigned int i;
226
227
228
229 for_each_possible_cpu(i) {
230 softirq_ctx[i] = (struct thread_info *)
231 __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
232 hardirq_ctx[i] = (struct thread_info *)
233 __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
234 }
235}
236
237#if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
238static void __init exc_lvl_early_init(void)
239{
240 unsigned int i, hw_cpu;
241
242
243
244 for_each_possible_cpu(i) {
245 hw_cpu = get_hard_smp_processor_id(i);
246 critirq_ctx[hw_cpu] = (struct thread_info *)
247 __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
248#ifdef CONFIG_BOOKE
249 dbgirq_ctx[hw_cpu] = (struct thread_info *)
250 __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
251 mcheckirq_ctx[hw_cpu] = (struct thread_info *)
252 __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
253#endif
254 }
255}
256#else
257#define exc_lvl_early_init()
258#endif
259
260
261void __init setup_arch(char **cmdline_p)
262{
263 *cmdline_p = cmd_line;
264
265
266 loops_per_jiffy = 500000000 / HZ;
267
268 unflatten_device_tree();
269 check_for_initrd();
270
271 if (ppc_md.init_early)
272 ppc_md.init_early();
273
274 find_legacy_serial_ports();
275
276 smp_setup_cpu_maps();
277
278
279 register_early_udbg_console();
280
281 xmon_setup();
282
283
284
285
286
287
288 dcache_bsize = cur_cpu_spec->dcache_bsize;
289 icache_bsize = cur_cpu_spec->icache_bsize;
290 ucache_bsize = 0;
291 if (cpu_has_feature(CPU_FTR_UNIFIED_ID_CACHE))
292 ucache_bsize = icache_bsize = dcache_bsize;
293
294 if (ppc_md.panic)
295 setup_panic();
296
297 init_mm.start_code = (unsigned long)_stext;
298 init_mm.end_code = (unsigned long) _etext;
299 init_mm.end_data = (unsigned long) _edata;
300 init_mm.brk = klimit;
301
302 exc_lvl_early_init();
303
304 irqstack_early_init();
305
306
307 do_init_bootmem();
308 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
309
310#ifdef CONFIG_DUMMY_CONSOLE
311 conswitchp = &dummy_con;
312#endif
313
314 if (ppc_md.setup_arch)
315 ppc_md.setup_arch();
316 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
317
318 paging_init();
319
320
321 mmu_context_init();
322
323}
324