1
2
3
4
5
6
7
8
9
10
11
12
13#undef DEBUG
14
15#include <linux/module.h>
16#include <linux/string.h>
17#include <linux/sched.h>
18#include <linux/init.h>
19#include <linux/kernel.h>
20#include <linux/reboot.h>
21#include <linux/delay.h>
22#include <linux/initrd.h>
23#include <linux/seq_file.h>
24#include <linux/ioport.h>
25#include <linux/console.h>
26#include <linux/utsname.h>
27#include <linux/tty.h>
28#include <linux/root_dev.h>
29#include <linux/notifier.h>
30#include <linux/cpu.h>
31#include <linux/unistd.h>
32#include <linux/serial.h>
33#include <linux/serial_8250.h>
34#include <linux/bootmem.h>
35#include <linux/pci.h>
36#include <asm/io.h>
37#include <asm/kdump.h>
38#include <asm/prom.h>
39#include <asm/processor.h>
40#include <asm/pgtable.h>
41#include <asm/smp.h>
42#include <asm/elf.h>
43#include <asm/machdep.h>
44#include <asm/paca.h>
45#include <asm/time.h>
46#include <asm/cputable.h>
47#include <asm/sections.h>
48#include <asm/btext.h>
49#include <asm/nvram.h>
50#include <asm/setup.h>
51#include <asm/system.h>
52#include <asm/rtas.h>
53#include <asm/iommu.h>
54#include <asm/serial.h>
55#include <asm/cache.h>
56#include <asm/page.h>
57#include <asm/mmu.h>
58#include <asm/lmb.h>
59#include <asm/firmware.h>
60#include <asm/xmon.h>
61#include <asm/udbg.h>
62#include <asm/kexec.h>
63
64#include "setup.h"
65
66#ifdef DEBUG
67#define DBG(fmt...) udbg_printf(fmt)
68#else
69#define DBG(fmt...)
70#endif
71
72int have_of = 1;
73int boot_cpuid = 0;
74u64 ppc64_pft_size;
75
76
77
78
79struct ppc64_caches ppc64_caches = {
80 .dline_size = 0x40,
81 .log_dline_size = 6,
82 .iline_size = 0x40,
83 .log_iline_size = 6
84};
85EXPORT_SYMBOL_GPL(ppc64_caches);
86
87
88
89
90
91int dcache_bsize;
92int icache_bsize;
93int ucache_bsize;
94
95#ifdef CONFIG_SMP
96
97static int smt_enabled_cmdline;
98
99
100static void check_smt_enabled(void)
101{
102 struct device_node *dn;
103 const char *smt_option;
104
105
106 if (smt_enabled_cmdline)
107 return;
108
109 dn = of_find_node_by_path("/options");
110
111 if (dn) {
112 smt_option = of_get_property(dn, "ibm,smt-enabled", NULL);
113
114 if (smt_option) {
115 if (!strcmp(smt_option, "on"))
116 smt_enabled_at_boot = 1;
117 else if (!strcmp(smt_option, "off"))
118 smt_enabled_at_boot = 0;
119 }
120 }
121}
122
123
124static int __init early_smt_enabled(char *p)
125{
126 smt_enabled_cmdline = 1;
127
128 if (!p)
129 return 0;
130
131 if (!strcmp(p, "on") || !strcmp(p, "1"))
132 smt_enabled_at_boot = 1;
133 else if (!strcmp(p, "off") || !strcmp(p, "0"))
134 smt_enabled_at_boot = 0;
135
136 return 0;
137}
138early_param("smt-enabled", early_smt_enabled);
139
140#else
141#define check_smt_enabled()
142#endif
143
144
145void __init setup_paca(int cpu)
146{
147 local_paca = &paca[cpu];
148 mtspr(SPRN_SPRG3, local_paca);
149}
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170void __init early_setup(unsigned long dt_ptr)
171{
172
173 identify_cpu(0, mfspr(SPRN_PVR));
174
175
176 setup_paca(0);
177
178
179 udbg_early_init();
180
181 DBG(" -> early_setup(), dt_ptr: 0x%lx\n", dt_ptr);
182
183
184
185
186
187
188 early_init_devtree(__va(dt_ptr));
189
190
191 setup_paca(boot_cpuid);
192
193
194 get_paca()->cpu_start = 1;
195 get_paca()->stab_real = __pa((u64)&initial_stab);
196 get_paca()->stab_addr = (u64)&initial_stab;
197
198
199 probe_machine();
200
201 setup_kdump_trampoline();
202
203 DBG("Found, Initializing memory management...\n");
204
205
206
207
208
209
210 htab_initialize();
211
212
213
214
215 if (cpu_has_feature(CPU_FTR_SLB))
216 slb_initialize();
217 else if (!firmware_has_feature(FW_FEATURE_ISERIES))
218 stab_initialize(get_paca()->stab_real);
219
220 DBG(" <- early_setup()\n");
221}
222
223#ifdef CONFIG_SMP
224void early_setup_secondary(void)
225{
226 struct paca_struct *lpaca = get_paca();
227
228
229 lpaca->soft_enabled = 0;
230
231
232 htab_initialize_secondary();
233
234
235
236
237
238 if (cpu_has_feature(CPU_FTR_SLB))
239 slb_initialize();
240 else
241 stab_initialize(lpaca->stab_addr);
242}
243
244#endif
245
246#if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
247void smp_release_cpus(void)
248{
249 extern unsigned long __secondary_hold_spinloop;
250 unsigned long *ptr;
251
252 DBG(" -> smp_release_cpus()\n");
253
254
255
256
257
258
259
260
261 ptr = (unsigned long *)((unsigned long)&__secondary_hold_spinloop
262 - PHYSICAL_START);
263 *ptr = 1;
264 mb();
265
266 DBG(" <- smp_release_cpus()\n");
267}
268#endif
269
270
271
272
273
274
275
276
277static void __init initialize_cache_info(void)
278{
279 struct device_node *np;
280 unsigned long num_cpus = 0;
281
282 DBG(" -> initialize_cache_info()\n");
283
284 for (np = NULL; (np = of_find_node_by_type(np, "cpu"));) {
285 num_cpus += 1;
286
287
288
289
290
291 if ( num_cpus == 1 ) {
292 const u32 *sizep, *lsizep;
293 u32 size, lsize;
294
295 size = 0;
296 lsize = cur_cpu_spec->dcache_bsize;
297 sizep = of_get_property(np, "d-cache-size", NULL);
298 if (sizep != NULL)
299 size = *sizep;
300 lsizep = of_get_property(np, "d-cache-block-size", NULL);
301
302 if (lsizep == NULL)
303 lsizep = of_get_property(np, "d-cache-line-size", NULL);
304 if (lsizep != NULL)
305 lsize = *lsizep;
306 if (sizep == 0 || lsizep == 0)
307 DBG("Argh, can't find dcache properties ! "
308 "sizep: %p, lsizep: %p\n", sizep, lsizep);
309
310 ppc64_caches.dsize = size;
311 ppc64_caches.dline_size = lsize;
312 ppc64_caches.log_dline_size = __ilog2(lsize);
313 ppc64_caches.dlines_per_page = PAGE_SIZE / lsize;
314
315 size = 0;
316 lsize = cur_cpu_spec->icache_bsize;
317 sizep = of_get_property(np, "i-cache-size", NULL);
318 if (sizep != NULL)
319 size = *sizep;
320 lsizep = of_get_property(np, "i-cache-block-size", NULL);
321 if (lsizep == NULL)
322 lsizep = of_get_property(np, "i-cache-line-size", NULL);
323 if (lsizep != NULL)
324 lsize = *lsizep;
325 if (sizep == 0 || lsizep == 0)
326 DBG("Argh, can't find icache properties ! "
327 "sizep: %p, lsizep: %p\n", sizep, lsizep);
328
329 ppc64_caches.isize = size;
330 ppc64_caches.iline_size = lsize;
331 ppc64_caches.log_iline_size = __ilog2(lsize);
332 ppc64_caches.ilines_per_page = PAGE_SIZE / lsize;
333 }
334 }
335
336 DBG(" <- initialize_cache_info()\n");
337}
338
339
340
341
342
343
344void __init setup_system(void)
345{
346 DBG(" -> setup_system()\n");
347
348
349
350
351 do_feature_fixups(cur_cpu_spec->cpu_features,
352 &__start___ftr_fixup, &__stop___ftr_fixup);
353 do_feature_fixups(powerpc_firmware_features,
354 &__start___fw_ftr_fixup, &__stop___fw_ftr_fixup);
355
356
357
358
359 unflatten_device_tree();
360
361
362
363
364
365 initialize_cache_info();
366
367
368
369
370 irq_early_init();
371
372#ifdef CONFIG_PPC_RTAS
373
374
375
376 rtas_initialize();
377#endif
378
379
380
381
382 check_for_initrd();
383
384
385
386
387
388
389 if (ppc_md.init_early)
390 ppc_md.init_early();
391
392
393
394
395
396
397 find_legacy_serial_ports();
398
399
400
401
402 register_early_udbg_console();
403
404
405
406
407 xmon_setup();
408
409 check_smt_enabled();
410 smp_setup_cpu_maps();
411
412#ifdef CONFIG_SMP
413
414
415
416 smp_release_cpus();
417#endif
418
419 printk("Starting Linux PPC64 %s\n", init_utsname()->version);
420
421 printk("-----------------------------------------------------\n");
422 printk("ppc64_pft_size = 0x%lx\n", ppc64_pft_size);
423 printk("physicalMemorySize = 0x%lx\n", lmb_phys_mem_size());
424 if (ppc64_caches.dline_size != 0x80)
425 printk("ppc64_caches.dcache_line_size = 0x%x\n",
426 ppc64_caches.dline_size);
427 if (ppc64_caches.iline_size != 0x80)
428 printk("ppc64_caches.icache_line_size = 0x%x\n",
429 ppc64_caches.iline_size);
430 if (htab_address)
431 printk("htab_address = 0x%p\n", htab_address);
432 printk("htab_hash_mask = 0x%lx\n", htab_hash_mask);
433#if PHYSICAL_START > 0
434 printk("physical_start = 0x%x\n", PHYSICAL_START);
435#endif
436 printk("-----------------------------------------------------\n");
437
438 DBG(" <- setup_system()\n");
439}
440
441#ifdef CONFIG_IRQSTACKS
442static void __init irqstack_early_init(void)
443{
444 unsigned int i;
445
446
447
448
449
450 for_each_possible_cpu(i) {
451 softirq_ctx[i] = (struct thread_info *)
452 __va(lmb_alloc_base(THREAD_SIZE,
453 THREAD_SIZE, 0x10000000));
454 hardirq_ctx[i] = (struct thread_info *)
455 __va(lmb_alloc_base(THREAD_SIZE,
456 THREAD_SIZE, 0x10000000));
457 }
458}
459#else
460#define irqstack_early_init()
461#endif
462
463
464
465
466
467static void __init emergency_stack_init(void)
468{
469 unsigned long limit;
470 unsigned int i;
471
472
473
474
475
476
477
478
479
480
481 limit = min(0x10000000UL, lmb.rmo_size);
482
483 for_each_possible_cpu(i)
484 paca[i].emergency_sp =
485 __va(lmb_alloc_base(HW_PAGE_SIZE, 128, limit)) + HW_PAGE_SIZE;
486}
487
488
489
490
491
492
493void __init setup_arch(char **cmdline_p)
494{
495 ppc64_boot_msg(0x12, "Setup Arch");
496
497 *cmdline_p = cmd_line;
498
499
500
501
502
503
504 dcache_bsize = ppc64_caches.dline_size;
505 icache_bsize = ppc64_caches.iline_size;
506
507
508 panic_timeout = 180;
509
510 if (ppc_md.panic)
511 setup_panic();
512
513 init_mm.start_code = PAGE_OFFSET;
514 init_mm.end_code = (unsigned long) _etext;
515 init_mm.end_data = (unsigned long) _edata;
516 init_mm.brk = klimit;
517
518 irqstack_early_init();
519 emergency_stack_init();
520
521 stabs_alloc();
522
523
524 do_init_bootmem();
525 sparse_init();
526
527#ifdef CONFIG_DUMMY_CONSOLE
528 conswitchp = &dummy_con;
529#endif
530
531 if (ppc_md.setup_arch)
532 ppc_md.setup_arch();
533
534 paging_init();
535 ppc64_boot_msg(0x15, "Setup Done");
536}
537
538
539
540#define PPC64_LINUX_FUNCTION 0x0f000000
541#define PPC64_IPL_MESSAGE 0xc0000000
542#define PPC64_TERM_MESSAGE 0xb0000000
543
544static void ppc64_do_msg(unsigned int src, const char *msg)
545{
546 if (ppc_md.progress) {
547 char buf[128];
548
549 sprintf(buf, "%08X\n", src);
550 ppc_md.progress(buf, 0);
551 snprintf(buf, 128, "%s", msg);
552 ppc_md.progress(buf, 0);
553 }
554}
555
556
557void ppc64_boot_msg(unsigned int src, const char *msg)
558{
559 ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_IPL_MESSAGE|src, msg);
560 printk("[boot]%04x %s\n", src, msg);
561}
562
563
564void ppc64_terminate_msg(unsigned int src, const char *msg)
565{
566 ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_TERM_MESSAGE|src, msg);
567 printk("[terminate]%04x %s\n", src, msg);
568}
569
570void cpu_die(void)
571{
572 if (ppc_md.cpu_die)
573 ppc_md.cpu_die();
574}
575
576#ifdef CONFIG_SMP
577void __init setup_per_cpu_areas(void)
578{
579 int i;
580 unsigned long size;
581 char *ptr;
582
583
584 size = ALIGN(__per_cpu_end - __per_cpu_start, PAGE_SIZE);
585#ifdef CONFIG_MODULES
586 if (size < PERCPU_ENOUGH_ROOM)
587 size = PERCPU_ENOUGH_ROOM;
588#endif
589
590 for_each_possible_cpu(i) {
591 ptr = alloc_bootmem_pages_node(NODE_DATA(cpu_to_node(i)), size);
592 if (!ptr)
593 panic("Cannot allocate cpu data for CPU %d\n", i);
594
595 paca[i].data_offset = ptr - __per_cpu_start;
596 memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
597 }
598
599
600 smp_setup_cpu_sibling_map();
601}
602#endif
603
604
605#ifdef CONFIG_PPC_INDIRECT_IO
606struct ppc_pci_io ppc_pci_io;
607EXPORT_SYMBOL(ppc_pci_io);
608#endif
609
610