1 /* 2 * Common boot and setup code for both 32-bit and 64-bit. 3 * Extracted from arch/powerpc/kernel/setup_64.c. 4 * 5 * Copyright (C) 2001 PPC64 Team, IBM Corp 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 10 * 2 of the License, or (at your option) any later version. 11 */ 12 13 #undef DEBUG 14 15 #include <linux/export.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/platform_device.h> 24 #include <linux/seq_file.h> 25 #include <linux/ioport.h> 26 #include <linux/console.h> 27 #include <linux/screen_info.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/percpu.h> 35 #include <linux/memblock.h> 36 #include <linux/bootmem.h> 37 #include <linux/of_platform.h> 38 #include <linux/hugetlb.h> 39 #include <asm/debugfs.h> 40 #include <asm/io.h> 41 #include <asm/paca.h> 42 #include <asm/prom.h> 43 #include <asm/processor.h> 44 #include <asm/vdso_datapage.h> 45 #include <asm/pgtable.h> 46 #include <asm/smp.h> 47 #include <asm/elf.h> 48 #include <asm/machdep.h> 49 #include <asm/time.h> 50 #include <asm/cputable.h> 51 #include <asm/sections.h> 52 #include <asm/firmware.h> 53 #include <asm/btext.h> 54 #include <asm/nvram.h> 55 #include <asm/setup.h> 56 #include <asm/rtas.h> 57 #include <asm/iommu.h> 58 #include <asm/serial.h> 59 #include <asm/cache.h> 60 #include <asm/page.h> 61 #include <asm/mmu.h> 62 #include <asm/xmon.h> 63 #include <asm/cputhreads.h> 64 #include <mm/mmu_decl.h> 65 #include <asm/fadump.h> 66 #include <asm/udbg.h> 67 #include <asm/hugetlb.h> 68 #include <asm/livepatch.h> 69 #include <asm/mmu_context.h> 70 #include <asm/cpu_has_feature.h> 71 72 #include "setup.h" 73 74 #ifdef DEBUG 75 #include <asm/udbg.h> 76 #define DBG(fmt...) udbg_printf(fmt) 77 #else 78 #define DBG(fmt...) 79 #endif 80 81 /* The main machine-dep calls structure 82 */ 83 struct machdep_calls ppc_md; 84 EXPORT_SYMBOL(ppc_md); 85 struct machdep_calls *machine_id; 86 EXPORT_SYMBOL(machine_id); 87 88 int boot_cpuid = -1; 89 EXPORT_SYMBOL_GPL(boot_cpuid); 90 91 /* 92 * These are used in binfmt_elf.c to put aux entries on the stack 93 * for each elf executable being started. 94 */ 95 int dcache_bsize; 96 int icache_bsize; 97 int ucache_bsize; 98 99 100 unsigned long klimit = (unsigned long) _end; 101 102 /* 103 * This still seems to be needed... -- paulus 104 */ 105 struct screen_info screen_info = { 106 .orig_x = 0, 107 .orig_y = 25, 108 .orig_video_cols = 80, 109 .orig_video_lines = 25, 110 .orig_video_isVGA = 1, 111 .orig_video_points = 16 112 }; 113 #if defined(CONFIG_FB_VGA16_MODULE) 114 EXPORT_SYMBOL(screen_info); 115 #endif 116 117 /* Variables required to store legacy IO irq routing */ 118 int of_i8042_kbd_irq; 119 EXPORT_SYMBOL_GPL(of_i8042_kbd_irq); 120 int of_i8042_aux_irq; 121 EXPORT_SYMBOL_GPL(of_i8042_aux_irq); 122 123 #ifdef __DO_IRQ_CANON 124 /* XXX should go elsewhere eventually */ 125 int ppc_do_canonicalize_irqs; 126 EXPORT_SYMBOL(ppc_do_canonicalize_irqs); 127 #endif 128 129 #ifdef CONFIG_CRASH_CORE 130 /* This keeps a track of which one is the crashing cpu. */ 131 int crashing_cpu = -1; 132 #endif 133 134 /* also used by kexec */ 135 void machine_shutdown(void) 136 { 137 #ifdef CONFIG_FA_DUMP 138 /* 139 * if fadump is active, cleanup the fadump registration before we 140 * shutdown. 141 */ 142 fadump_cleanup(); 143 #endif 144 145 if (ppc_md.machine_shutdown) 146 ppc_md.machine_shutdown(); 147 } 148 149 static void machine_hang(void) 150 { 151 pr_emerg("System Halted, OK to turn off power\n"); 152 local_irq_disable(); 153 while (1) 154 ; 155 } 156 157 void machine_restart(char *cmd) 158 { 159 machine_shutdown(); 160 if (ppc_md.restart) 161 ppc_md.restart(cmd); 162 163 smp_send_stop(); 164 165 do_kernel_restart(cmd); 166 mdelay(1000); 167 168 machine_hang(); 169 } 170 171 void machine_power_off(void) 172 { 173 machine_shutdown(); 174 if (pm_power_off) 175 pm_power_off(); 176 177 smp_send_stop(); 178 machine_hang(); 179 } 180 /* Used by the G5 thermal driver */ 181 EXPORT_SYMBOL_GPL(machine_power_off); 182 183 void (*pm_power_off)(void); 184 EXPORT_SYMBOL_GPL(pm_power_off); 185 186 void machine_halt(void) 187 { 188 machine_shutdown(); 189 if (ppc_md.halt) 190 ppc_md.halt(); 191 192 smp_send_stop(); 193 machine_hang(); 194 } 195 196 #ifdef CONFIG_SMP 197 DEFINE_PER_CPU(unsigned int, cpu_pvr); 198 #endif 199 200 static void show_cpuinfo_summary(struct seq_file *m) 201 { 202 struct device_node *root; 203 const char *model = NULL; 204 #if defined(CONFIG_SMP) && defined(CONFIG_PPC32) 205 unsigned long bogosum = 0; 206 int i; 207 for_each_online_cpu(i) 208 bogosum += loops_per_jiffy; 209 seq_printf(m, "total bogomips\t: %lu.%02lu\n", 210 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100); 211 #endif /* CONFIG_SMP && CONFIG_PPC32 */ 212 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq); 213 if (ppc_md.name) 214 seq_printf(m, "platform\t: %s\n", ppc_md.name); 215 root = of_find_node_by_path("/"); 216 if (root) 217 model = of_get_property(root, "model", NULL); 218 if (model) 219 seq_printf(m, "model\t\t: %s\n", model); 220 of_node_put(root); 221 222 if (ppc_md.show_cpuinfo != NULL) 223 ppc_md.show_cpuinfo(m); 224 225 #ifdef CONFIG_PPC32 226 /* Display the amount of memory */ 227 seq_printf(m, "Memory\t\t: %d MB\n", 228 (unsigned int)(total_memory / (1024 * 1024))); 229 #endif 230 } 231 232 static int show_cpuinfo(struct seq_file *m, void *v) 233 { 234 unsigned long cpu_id = (unsigned long)v - 1; 235 unsigned int pvr; 236 unsigned long proc_freq; 237 unsigned short maj; 238 unsigned short min; 239 240 #ifdef CONFIG_SMP 241 pvr = per_cpu(cpu_pvr, cpu_id); 242 #else 243 pvr = mfspr(SPRN_PVR); 244 #endif 245 maj = (pvr >> 8) & 0xFF; 246 min = pvr & 0xFF; 247 248 seq_printf(m, "processor\t: %lu\n", cpu_id); 249 seq_printf(m, "cpu\t\t: "); 250 251 if (cur_cpu_spec->pvr_mask && cur_cpu_spec->cpu_name) 252 seq_printf(m, "%s", cur_cpu_spec->cpu_name); 253 else 254 seq_printf(m, "unknown (%08x)", pvr); 255 256 #ifdef CONFIG_ALTIVEC 257 if (cpu_has_feature(CPU_FTR_ALTIVEC)) 258 seq_printf(m, ", altivec supported"); 259 #endif /* CONFIG_ALTIVEC */ 260 261 seq_printf(m, "\n"); 262 263 #ifdef CONFIG_TAU 264 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) { 265 #ifdef CONFIG_TAU_AVERAGE 266 /* more straightforward, but potentially misleading */ 267 seq_printf(m, "temperature \t: %u C (uncalibrated)\n", 268 cpu_temp(cpu_id)); 269 #else 270 /* show the actual temp sensor range */ 271 u32 temp; 272 temp = cpu_temp_both(cpu_id); 273 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n", 274 temp & 0xff, temp >> 16); 275 #endif 276 } 277 #endif /* CONFIG_TAU */ 278 279 /* 280 * Platforms that have variable clock rates, should implement 281 * the method ppc_md.get_proc_freq() that reports the clock 282 * rate of a given cpu. The rest can use ppc_proc_freq to 283 * report the clock rate that is same across all cpus. 284 */ 285 if (ppc_md.get_proc_freq) 286 proc_freq = ppc_md.get_proc_freq(cpu_id); 287 else 288 proc_freq = ppc_proc_freq; 289 290 if (proc_freq) 291 seq_printf(m, "clock\t\t: %lu.%06luMHz\n", 292 proc_freq / 1000000, proc_freq % 1000000); 293 294 if (ppc_md.show_percpuinfo != NULL) 295 ppc_md.show_percpuinfo(m, cpu_id); 296 297 /* If we are a Freescale core do a simple check so 298 * we dont have to keep adding cases in the future */ 299 if (PVR_VER(pvr) & 0x8000) { 300 switch (PVR_VER(pvr)) { 301 case 0x8000: /* 7441/7450/7451, Voyager */ 302 case 0x8001: /* 7445/7455, Apollo 6 */ 303 case 0x8002: /* 7447/7457, Apollo 7 */ 304 case 0x8003: /* 7447A, Apollo 7 PM */ 305 case 0x8004: /* 7448, Apollo 8 */ 306 case 0x800c: /* 7410, Nitro */ 307 maj = ((pvr >> 8) & 0xF); 308 min = PVR_MIN(pvr); 309 break; 310 default: /* e500/book-e */ 311 maj = PVR_MAJ(pvr); 312 min = PVR_MIN(pvr); 313 break; 314 } 315 } else { 316 switch (PVR_VER(pvr)) { 317 case 0x0020: /* 403 family */ 318 maj = PVR_MAJ(pvr) + 1; 319 min = PVR_MIN(pvr); 320 break; 321 case 0x1008: /* 740P/750P ?? */ 322 maj = ((pvr >> 8) & 0xFF) - 1; 323 min = pvr & 0xFF; 324 break; 325 case 0x004e: /* POWER9 bits 12-15 give chip type */ 326 maj = (pvr >> 8) & 0x0F; 327 min = pvr & 0xFF; 328 break; 329 default: 330 maj = (pvr >> 8) & 0xFF; 331 min = pvr & 0xFF; 332 break; 333 } 334 } 335 336 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n", 337 maj, min, PVR_VER(pvr), PVR_REV(pvr)); 338 339 #ifdef CONFIG_PPC32 340 seq_printf(m, "bogomips\t: %lu.%02lu\n", 341 loops_per_jiffy / (500000/HZ), 342 (loops_per_jiffy / (5000/HZ)) % 100); 343 #endif 344 seq_printf(m, "\n"); 345 346 /* If this is the last cpu, print the summary */ 347 if (cpumask_next(cpu_id, cpu_online_mask) >= nr_cpu_ids) 348 show_cpuinfo_summary(m); 349 350 return 0; 351 } 352 353 static void *c_start(struct seq_file *m, loff_t *pos) 354 { 355 if (*pos == 0) /* just in case, cpu 0 is not the first */ 356 *pos = cpumask_first(cpu_online_mask); 357 else 358 *pos = cpumask_next(*pos - 1, cpu_online_mask); 359 if ((*pos) < nr_cpu_ids) 360 return (void *)(unsigned long)(*pos + 1); 361 return NULL; 362 } 363 364 static void *c_next(struct seq_file *m, void *v, loff_t *pos) 365 { 366 (*pos)++; 367 return c_start(m, pos); 368 } 369 370 static void c_stop(struct seq_file *m, void *v) 371 { 372 } 373 374 const struct seq_operations cpuinfo_op = { 375 .start = c_start, 376 .next = c_next, 377 .stop = c_stop, 378 .show = show_cpuinfo, 379 }; 380 381 void __init check_for_initrd(void) 382 { 383 #ifdef CONFIG_BLK_DEV_INITRD 384 DBG(" -> check_for_initrd() initrd_start=0x%lx initrd_end=0x%lx\n", 385 initrd_start, initrd_end); 386 387 /* If we were passed an initrd, set the ROOT_DEV properly if the values 388 * look sensible. If not, clear initrd reference. 389 */ 390 if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) && 391 initrd_end > initrd_start) 392 ROOT_DEV = Root_RAM0; 393 else 394 initrd_start = initrd_end = 0; 395 396 if (initrd_start) 397 pr_info("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end); 398 399 DBG(" <- check_for_initrd()\n"); 400 #endif /* CONFIG_BLK_DEV_INITRD */ 401 } 402 403 #ifdef CONFIG_SMP 404 405 int threads_per_core, threads_per_subcore, threads_shift; 406 cpumask_t threads_core_mask; 407 EXPORT_SYMBOL_GPL(threads_per_core); 408 EXPORT_SYMBOL_GPL(threads_per_subcore); 409 EXPORT_SYMBOL_GPL(threads_shift); 410 EXPORT_SYMBOL_GPL(threads_core_mask); 411 412 static void __init cpu_init_thread_core_maps(int tpc) 413 { 414 int i; 415 416 threads_per_core = tpc; 417 threads_per_subcore = tpc; 418 cpumask_clear(&threads_core_mask); 419 420 /* This implementation only supports power of 2 number of threads 421 * for simplicity and performance 422 */ 423 threads_shift = ilog2(tpc); 424 BUG_ON(tpc != (1 << threads_shift)); 425 426 for (i = 0; i < tpc; i++) 427 cpumask_set_cpu(i, &threads_core_mask); 428 429 printk(KERN_INFO "CPU maps initialized for %d thread%s per core\n", 430 tpc, tpc > 1 ? "s" : ""); 431 printk(KERN_DEBUG " (thread shift is %d)\n", threads_shift); 432 } 433 434 435 u32 *cpu_to_phys_id = NULL; 436 437 /** 438 * setup_cpu_maps - initialize the following cpu maps: 439 * cpu_possible_mask 440 * cpu_present_mask 441 * 442 * Having the possible map set up early allows us to restrict allocations 443 * of things like irqstacks to nr_cpu_ids rather than NR_CPUS. 444 * 445 * We do not initialize the online map here; cpus set their own bits in 446 * cpu_online_mask as they come up. 447 * 448 * This function is valid only for Open Firmware systems. finish_device_tree 449 * must be called before using this. 450 * 451 * While we're here, we may as well set the "physical" cpu ids in the paca. 452 * 453 * NOTE: This must match the parsing done in early_init_dt_scan_cpus. 454 */ 455 void __init smp_setup_cpu_maps(void) 456 { 457 struct device_node *dn; 458 int cpu = 0; 459 int nthreads = 1; 460 461 DBG("smp_setup_cpu_maps()\n"); 462 463 cpu_to_phys_id = __va(memblock_alloc(nr_cpu_ids * sizeof(u32), 464 __alignof__(u32))); 465 memset(cpu_to_phys_id, 0, nr_cpu_ids * sizeof(u32)); 466 467 for_each_node_by_type(dn, "cpu") { 468 const __be32 *intserv; 469 __be32 cpu_be; 470 int j, len; 471 472 DBG(" * %pOF...\n", dn); 473 474 intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s", 475 &len); 476 if (intserv) { 477 DBG(" ibm,ppc-interrupt-server#s -> %d threads\n", 478 nthreads); 479 } else { 480 DBG(" no ibm,ppc-interrupt-server#s -> 1 thread\n"); 481 intserv = of_get_property(dn, "reg", &len); 482 if (!intserv) { 483 cpu_be = cpu_to_be32(cpu); 484 /* XXX: what is this? uninitialized?? */ 485 intserv = &cpu_be; /* assume logical == phys */ 486 len = 4; 487 } 488 } 489 490 nthreads = len / sizeof(int); 491 492 for (j = 0; j < nthreads && cpu < nr_cpu_ids; j++) { 493 bool avail; 494 495 DBG(" thread %d -> cpu %d (hard id %d)\n", 496 j, cpu, be32_to_cpu(intserv[j])); 497 498 avail = of_device_is_available(dn); 499 if (!avail) 500 avail = !of_property_match_string(dn, 501 "enable-method", "spin-table"); 502 503 set_cpu_present(cpu, avail); 504 set_cpu_possible(cpu, true); 505 cpu_to_phys_id[cpu] = be32_to_cpu(intserv[j]); 506 cpu++; 507 } 508 509 if (cpu >= nr_cpu_ids) { 510 of_node_put(dn); 511 break; 512 } 513 } 514 515 /* If no SMT supported, nthreads is forced to 1 */ 516 if (!cpu_has_feature(CPU_FTR_SMT)) { 517 DBG(" SMT disabled ! nthreads forced to 1\n"); 518 nthreads = 1; 519 } 520 521 #ifdef CONFIG_PPC64 522 /* 523 * On pSeries LPAR, we need to know how many cpus 524 * could possibly be added to this partition. 525 */ 526 if (firmware_has_feature(FW_FEATURE_LPAR) && 527 (dn = of_find_node_by_path("/rtas"))) { 528 int num_addr_cell, num_size_cell, maxcpus; 529 const __be32 *ireg; 530 531 num_addr_cell = of_n_addr_cells(dn); 532 num_size_cell = of_n_size_cells(dn); 533 534 ireg = of_get_property(dn, "ibm,lrdr-capacity", NULL); 535 536 if (!ireg) 537 goto out; 538 539 maxcpus = be32_to_cpup(ireg + num_addr_cell + num_size_cell); 540 541 /* Double maxcpus for processors which have SMT capability */ 542 if (cpu_has_feature(CPU_FTR_SMT)) 543 maxcpus *= nthreads; 544 545 if (maxcpus > nr_cpu_ids) { 546 printk(KERN_WARNING 547 "Partition configured for %d cpus, " 548 "operating system maximum is %u.\n", 549 maxcpus, nr_cpu_ids); 550 maxcpus = nr_cpu_ids; 551 } else 552 printk(KERN_INFO "Partition configured for %d cpus.\n", 553 maxcpus); 554 555 for (cpu = 0; cpu < maxcpus; cpu++) 556 set_cpu_possible(cpu, true); 557 out: 558 of_node_put(dn); 559 } 560 vdso_data->processorCount = num_present_cpus(); 561 #endif /* CONFIG_PPC64 */ 562 563 /* Initialize CPU <=> thread mapping/ 564 * 565 * WARNING: We assume that the number of threads is the same for 566 * every CPU in the system. If that is not the case, then some code 567 * here will have to be reworked 568 */ 569 cpu_init_thread_core_maps(nthreads); 570 571 /* Now that possible cpus are set, set nr_cpu_ids for later use */ 572 setup_nr_cpu_ids(); 573 574 free_unused_pacas(); 575 } 576 #endif /* CONFIG_SMP */ 577 578 #ifdef CONFIG_PCSPKR_PLATFORM 579 static __init int add_pcspkr(void) 580 { 581 struct device_node *np; 582 struct platform_device *pd; 583 int ret; 584 585 np = of_find_compatible_node(NULL, NULL, "pnpPNP,100"); 586 of_node_put(np); 587 if (!np) 588 return -ENODEV; 589 590 pd = platform_device_alloc("pcspkr", -1); 591 if (!pd) 592 return -ENOMEM; 593 594 ret = platform_device_add(pd); 595 if (ret) 596 platform_device_put(pd); 597 598 return ret; 599 } 600 device_initcall(add_pcspkr); 601 #endif /* CONFIG_PCSPKR_PLATFORM */ 602 603 void probe_machine(void) 604 { 605 extern struct machdep_calls __machine_desc_start; 606 extern struct machdep_calls __machine_desc_end; 607 unsigned int i; 608 609 /* 610 * Iterate all ppc_md structures until we find the proper 611 * one for the current machine type 612 */ 613 DBG("Probing machine type ...\n"); 614 615 /* 616 * Check ppc_md is empty, if not we have a bug, ie, we setup an 617 * entry before probe_machine() which will be overwritten 618 */ 619 for (i = 0; i < (sizeof(ppc_md) / sizeof(void *)); i++) { 620 if (((void **)&ppc_md)[i]) { 621 printk(KERN_ERR "Entry %d in ppc_md non empty before" 622 " machine probe !\n", i); 623 } 624 } 625 626 for (machine_id = &__machine_desc_start; 627 machine_id < &__machine_desc_end; 628 machine_id++) { 629 DBG(" %s ...", machine_id->name); 630 memcpy(&ppc_md, machine_id, sizeof(struct machdep_calls)); 631 if (ppc_md.probe()) { 632 DBG(" match !\n"); 633 break; 634 } 635 DBG("\n"); 636 } 637 /* What can we do if we didn't find ? */ 638 if (machine_id >= &__machine_desc_end) { 639 DBG("No suitable machine found !\n"); 640 for (;;); 641 } 642 643 printk(KERN_INFO "Using %s machine description\n", ppc_md.name); 644 } 645 646 /* Match a class of boards, not a specific device configuration. */ 647 int check_legacy_ioport(unsigned long base_port) 648 { 649 struct device_node *parent, *np = NULL; 650 int ret = -ENODEV; 651 652 switch(base_port) { 653 case I8042_DATA_REG: 654 if (!(np = of_find_compatible_node(NULL, NULL, "pnpPNP,303"))) 655 np = of_find_compatible_node(NULL, NULL, "pnpPNP,f03"); 656 if (np) { 657 parent = of_get_parent(np); 658 659 of_i8042_kbd_irq = irq_of_parse_and_map(parent, 0); 660 if (!of_i8042_kbd_irq) 661 of_i8042_kbd_irq = 1; 662 663 of_i8042_aux_irq = irq_of_parse_and_map(parent, 1); 664 if (!of_i8042_aux_irq) 665 of_i8042_aux_irq = 12; 666 667 of_node_put(np); 668 np = parent; 669 break; 670 } 671 np = of_find_node_by_type(NULL, "8042"); 672 /* Pegasos has no device_type on its 8042 node, look for the 673 * name instead */ 674 if (!np) 675 np = of_find_node_by_name(NULL, "8042"); 676 if (np) { 677 of_i8042_kbd_irq = 1; 678 of_i8042_aux_irq = 12; 679 } 680 break; 681 case FDC_BASE: /* FDC1 */ 682 np = of_find_node_by_type(NULL, "fdc"); 683 break; 684 default: 685 /* ipmi is supposed to fail here */ 686 break; 687 } 688 if (!np) 689 return ret; 690 parent = of_get_parent(np); 691 if (parent) { 692 if (strcmp(parent->type, "isa") == 0) 693 ret = 0; 694 of_node_put(parent); 695 } 696 of_node_put(np); 697 return ret; 698 } 699 EXPORT_SYMBOL(check_legacy_ioport); 700 701 static int ppc_panic_event(struct notifier_block *this, 702 unsigned long event, void *ptr) 703 { 704 /* 705 * panic does a local_irq_disable, but we really 706 * want interrupts to be hard disabled. 707 */ 708 hard_irq_disable(); 709 710 /* 711 * If firmware-assisted dump has been registered then trigger 712 * firmware-assisted dump and let firmware handle everything else. 713 */ 714 crash_fadump(NULL, ptr); 715 if (ppc_md.panic) 716 ppc_md.panic(ptr); /* May not return */ 717 return NOTIFY_DONE; 718 } 719 720 static struct notifier_block ppc_panic_block = { 721 .notifier_call = ppc_panic_event, 722 .priority = INT_MIN /* may not return; must be done last */ 723 }; 724 725 void __init setup_panic(void) 726 { 727 /* PPC64 always does a hard irq disable in its panic handler */ 728 if (!IS_ENABLED(CONFIG_PPC64) && !ppc_md.panic) 729 return; 730 atomic_notifier_chain_register(&panic_notifier_list, &ppc_panic_block); 731 } 732 733 #ifdef CONFIG_CHECK_CACHE_COHERENCY 734 /* 735 * For platforms that have configurable cache-coherency. This function 736 * checks that the cache coherency setting of the kernel matches the setting 737 * left by the firmware, as indicated in the device tree. Since a mismatch 738 * will eventually result in DMA failures, we print * and error and call 739 * BUG() in that case. 740 */ 741 742 #ifdef CONFIG_NOT_COHERENT_CACHE 743 #define KERNEL_COHERENCY 0 744 #else 745 #define KERNEL_COHERENCY 1 746 #endif 747 748 static int __init check_cache_coherency(void) 749 { 750 struct device_node *np; 751 const void *prop; 752 int devtree_coherency; 753 754 np = of_find_node_by_path("/"); 755 prop = of_get_property(np, "coherency-off", NULL); 756 of_node_put(np); 757 758 devtree_coherency = prop ? 0 : 1; 759 760 if (devtree_coherency != KERNEL_COHERENCY) { 761 printk(KERN_ERR 762 "kernel coherency:%s != device tree_coherency:%s\n", 763 KERNEL_COHERENCY ? "on" : "off", 764 devtree_coherency ? "on" : "off"); 765 BUG(); 766 } 767 768 return 0; 769 } 770 771 late_initcall(check_cache_coherency); 772 #endif /* CONFIG_CHECK_CACHE_COHERENCY */ 773 774 #ifdef CONFIG_DEBUG_FS 775 struct dentry *powerpc_debugfs_root; 776 EXPORT_SYMBOL(powerpc_debugfs_root); 777 778 static int powerpc_debugfs_init(void) 779 { 780 powerpc_debugfs_root = debugfs_create_dir("powerpc", NULL); 781 782 return powerpc_debugfs_root == NULL; 783 } 784 arch_initcall(powerpc_debugfs_init); 785 #endif 786 787 void ppc_printk_progress(char *s, unsigned short hex) 788 { 789 pr_info("%s\n", s); 790 } 791 792 void arch_setup_pdev_archdata(struct platform_device *pdev) 793 { 794 pdev->archdata.dma_mask = DMA_BIT_MASK(32); 795 pdev->dev.dma_mask = &pdev->archdata.dma_mask; 796 set_dma_ops(&pdev->dev, &dma_nommu_ops); 797 } 798 799 static __init void print_system_info(void) 800 { 801 pr_info("-----------------------------------------------------\n"); 802 #ifdef CONFIG_PPC_BOOK3S_64 803 pr_info("ppc64_pft_size = 0x%llx\n", ppc64_pft_size); 804 #endif 805 #ifdef CONFIG_PPC_STD_MMU_32 806 pr_info("Hash_size = 0x%lx\n", Hash_size); 807 #endif 808 pr_info("phys_mem_size = 0x%llx\n", 809 (unsigned long long)memblock_phys_mem_size()); 810 811 pr_info("dcache_bsize = 0x%x\n", dcache_bsize); 812 pr_info("icache_bsize = 0x%x\n", icache_bsize); 813 if (ucache_bsize != 0) 814 pr_info("ucache_bsize = 0x%x\n", ucache_bsize); 815 816 pr_info("cpu_features = 0x%016lx\n", cur_cpu_spec->cpu_features); 817 pr_info(" possible = 0x%016lx\n", 818 (unsigned long)CPU_FTRS_POSSIBLE); 819 pr_info(" always = 0x%016lx\n", 820 (unsigned long)CPU_FTRS_ALWAYS); 821 pr_info("cpu_user_features = 0x%08x 0x%08x\n", 822 cur_cpu_spec->cpu_user_features, 823 cur_cpu_spec->cpu_user_features2); 824 pr_info("mmu_features = 0x%08x\n", cur_cpu_spec->mmu_features); 825 #ifdef CONFIG_PPC64 826 pr_info("firmware_features = 0x%016lx\n", powerpc_firmware_features); 827 #endif 828 829 #ifdef CONFIG_PPC_BOOK3S_64 830 if (htab_address) 831 pr_info("htab_address = 0x%p\n", htab_address); 832 if (htab_hash_mask) 833 pr_info("htab_hash_mask = 0x%lx\n", htab_hash_mask); 834 #endif 835 #ifdef CONFIG_PPC_STD_MMU_32 836 if (Hash) 837 pr_info("Hash = 0x%p\n", Hash); 838 if (Hash_mask) 839 pr_info("Hash_mask = 0x%lx\n", Hash_mask); 840 #endif 841 842 if (PHYSICAL_START > 0) 843 pr_info("physical_start = 0x%llx\n", 844 (unsigned long long)PHYSICAL_START); 845 pr_info("-----------------------------------------------------\n"); 846 } 847 848 #ifdef CONFIG_SMP 849 static void smp_setup_pacas(void) 850 { 851 int cpu; 852 853 for_each_possible_cpu(cpu) { 854 if (cpu == smp_processor_id()) 855 continue; 856 allocate_paca(cpu); 857 set_hard_smp_processor_id(cpu, cpu_to_phys_id[cpu]); 858 } 859 860 memblock_free(__pa(cpu_to_phys_id), nr_cpu_ids * sizeof(u32)); 861 cpu_to_phys_id = NULL; 862 } 863 #endif 864 865 /* 866 * Called into from start_kernel this initializes memblock, which is used 867 * to manage page allocation until mem_init is called. 868 */ 869 void __init setup_arch(char **cmdline_p) 870 { 871 *cmdline_p = boot_command_line; 872 873 /* Set a half-reasonable default so udelay does something sensible */ 874 loops_per_jiffy = 500000000 / HZ; 875 876 /* Unflatten the device-tree passed by prom_init or kexec */ 877 unflatten_device_tree(); 878 879 /* 880 * Initialize cache line/block info from device-tree (on ppc64) or 881 * just cputable (on ppc32). 882 */ 883 initialize_cache_info(); 884 885 /* Initialize RTAS if available. */ 886 rtas_initialize(); 887 888 /* Check if we have an initrd provided via the device-tree. */ 889 check_for_initrd(); 890 891 /* Probe the machine type, establish ppc_md. */ 892 probe_machine(); 893 894 /* Setup panic notifier if requested by the platform. */ 895 setup_panic(); 896 897 /* 898 * Configure ppc_md.power_save (ppc32 only, 64-bit machines do 899 * it from their respective probe() function. 900 */ 901 setup_power_save(); 902 903 /* Discover standard serial ports. */ 904 find_legacy_serial_ports(); 905 906 /* Register early console with the printk subsystem. */ 907 register_early_udbg_console(); 908 909 /* Setup the various CPU maps based on the device-tree. */ 910 smp_setup_cpu_maps(); 911 912 /* Initialize xmon. */ 913 xmon_setup(); 914 915 /* Check the SMT related command line arguments (ppc64). */ 916 check_smt_enabled(); 917 918 /* Parse memory topology */ 919 mem_topology_setup(); 920 921 /* 922 * Release secondary cpus out of their spinloops at 0x60 now that 923 * we can map physical -> logical CPU ids. 924 * 925 * Freescale Book3e parts spin in a loop provided by firmware, 926 * so smp_release_cpus() does nothing for them. 927 */ 928 #ifdef CONFIG_SMP 929 smp_setup_pacas(); 930 931 /* On BookE, setup per-core TLB data structures. */ 932 setup_tlb_core_data(); 933 934 smp_release_cpus(); 935 #endif 936 937 /* Print various info about the machine that has been gathered so far. */ 938 print_system_info(); 939 940 /* Reserve large chunks of memory for use by CMA for KVM. */ 941 kvm_cma_reserve(); 942 943 klp_init_thread_info(&init_thread_info); 944 945 init_mm.start_code = (unsigned long)_stext; 946 init_mm.end_code = (unsigned long) _etext; 947 init_mm.end_data = (unsigned long) _edata; 948 init_mm.brk = klimit; 949 950 #ifdef CONFIG_PPC_MM_SLICES 951 #ifdef CONFIG_PPC64 952 if (!radix_enabled()) 953 init_mm.context.slb_addr_limit = DEFAULT_MAP_WINDOW_USER64; 954 #elif defined(CONFIG_PPC_8xx) 955 init_mm.context.slb_addr_limit = DEFAULT_MAP_WINDOW; 956 #else 957 #error "context.addr_limit not initialized." 958 #endif 959 #endif 960 961 #ifdef CONFIG_SPAPR_TCE_IOMMU 962 mm_iommu_init(&init_mm); 963 #endif 964 irqstack_early_init(); 965 exc_lvl_early_init(); 966 emergency_stack_init(); 967 968 initmem_init(); 969 970 early_memtest(min_low_pfn << PAGE_SHIFT, max_low_pfn << PAGE_SHIFT); 971 972 #ifdef CONFIG_DUMMY_CONSOLE 973 conswitchp = &dummy_con; 974 #endif 975 if (ppc_md.setup_arch) 976 ppc_md.setup_arch(); 977 978 setup_barrier_nospec(); 979 980 paging_init(); 981 982 /* Initialize the MMU context management stuff. */ 983 mmu_context_init(); 984 985 #ifdef CONFIG_PPC64 986 /* Interrupt code needs to be 64K-aligned. */ 987 if ((unsigned long)_stext & 0xffff) 988 panic("Kernelbase not 64K-aligned (0x%lx)!\n", 989 (unsigned long)_stext); 990 #endif 991 } 992