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/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/platform_device.h> 24 #include <linux/seq_file.h> 25 #include <linux/ioport.h> 26 #include <linux/console.h> 27 #include <linux/utsname.h> 28 #include <linux/screen_info.h> 29 #include <linux/root_dev.h> 30 #include <linux/notifier.h> 31 #include <linux/cpu.h> 32 #include <linux/unistd.h> 33 #include <linux/serial.h> 34 #include <linux/serial_8250.h> 35 #include <linux/debugfs.h> 36 #include <linux/percpu.h> 37 #include <linux/lmb.h> 38 #include <asm/io.h> 39 #include <asm/prom.h> 40 #include <asm/processor.h> 41 #include <asm/vdso_datapage.h> 42 #include <asm/pgtable.h> 43 #include <asm/smp.h> 44 #include <asm/elf.h> 45 #include <asm/machdep.h> 46 #include <asm/time.h> 47 #include <asm/cputable.h> 48 #include <asm/sections.h> 49 #include <asm/firmware.h> 50 #include <asm/btext.h> 51 #include <asm/nvram.h> 52 #include <asm/setup.h> 53 #include <asm/system.h> 54 #include <asm/rtas.h> 55 #include <asm/iommu.h> 56 #include <asm/serial.h> 57 #include <asm/cache.h> 58 #include <asm/page.h> 59 #include <asm/mmu.h> 60 #include <asm/xmon.h> 61 #include <asm/cputhreads.h> 62 63 #include "setup.h" 64 65 #ifdef DEBUG 66 #include <asm/udbg.h> 67 #define DBG(fmt...) udbg_printf(fmt) 68 #else 69 #define DBG(fmt...) 70 #endif 71 72 /* The main machine-dep calls structure 73 */ 74 struct machdep_calls ppc_md; 75 EXPORT_SYMBOL(ppc_md); 76 struct machdep_calls *machine_id; 77 EXPORT_SYMBOL(machine_id); 78 79 unsigned long klimit = (unsigned long) _end; 80 81 char cmd_line[COMMAND_LINE_SIZE]; 82 83 /* 84 * This still seems to be needed... -- paulus 85 */ 86 struct screen_info screen_info = { 87 .orig_x = 0, 88 .orig_y = 25, 89 .orig_video_cols = 80, 90 .orig_video_lines = 25, 91 .orig_video_isVGA = 1, 92 .orig_video_points = 16 93 }; 94 95 #ifdef __DO_IRQ_CANON 96 /* XXX should go elsewhere eventually */ 97 int ppc_do_canonicalize_irqs; 98 EXPORT_SYMBOL(ppc_do_canonicalize_irqs); 99 #endif 100 101 /* also used by kexec */ 102 void machine_shutdown(void) 103 { 104 if (ppc_md.machine_shutdown) 105 ppc_md.machine_shutdown(); 106 } 107 108 void machine_restart(char *cmd) 109 { 110 machine_shutdown(); 111 if (ppc_md.restart) 112 ppc_md.restart(cmd); 113 #ifdef CONFIG_SMP 114 smp_send_stop(); 115 #endif 116 printk(KERN_EMERG "System Halted, OK to turn off power\n"); 117 local_irq_disable(); 118 while (1) ; 119 } 120 121 void machine_power_off(void) 122 { 123 machine_shutdown(); 124 if (ppc_md.power_off) 125 ppc_md.power_off(); 126 #ifdef CONFIG_SMP 127 smp_send_stop(); 128 #endif 129 printk(KERN_EMERG "System Halted, OK to turn off power\n"); 130 local_irq_disable(); 131 while (1) ; 132 } 133 /* Used by the G5 thermal driver */ 134 EXPORT_SYMBOL_GPL(machine_power_off); 135 136 void (*pm_power_off)(void) = machine_power_off; 137 EXPORT_SYMBOL_GPL(pm_power_off); 138 139 void machine_halt(void) 140 { 141 machine_shutdown(); 142 if (ppc_md.halt) 143 ppc_md.halt(); 144 #ifdef CONFIG_SMP 145 smp_send_stop(); 146 #endif 147 printk(KERN_EMERG "System Halted, OK to turn off power\n"); 148 local_irq_disable(); 149 while (1) ; 150 } 151 152 153 #ifdef CONFIG_TAU 154 extern u32 cpu_temp(unsigned long cpu); 155 extern u32 cpu_temp_both(unsigned long cpu); 156 #endif /* CONFIG_TAU */ 157 158 #ifdef CONFIG_SMP 159 DEFINE_PER_CPU(unsigned int, pvr); 160 #endif 161 162 static int show_cpuinfo(struct seq_file *m, void *v) 163 { 164 unsigned long cpu_id = (unsigned long)v - 1; 165 unsigned int pvr; 166 unsigned short maj; 167 unsigned short min; 168 169 if (cpu_id == NR_CPUS) { 170 struct device_node *root; 171 const char *model = NULL; 172 #if defined(CONFIG_SMP) && defined(CONFIG_PPC32) 173 unsigned long bogosum = 0; 174 int i; 175 for_each_online_cpu(i) 176 bogosum += loops_per_jiffy; 177 seq_printf(m, "total bogomips\t: %lu.%02lu\n", 178 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100); 179 #endif /* CONFIG_SMP && CONFIG_PPC32 */ 180 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq); 181 if (ppc_md.name) 182 seq_printf(m, "platform\t: %s\n", ppc_md.name); 183 root = of_find_node_by_path("/"); 184 if (root) 185 model = of_get_property(root, "model", NULL); 186 if (model) 187 seq_printf(m, "model\t\t: %s\n", model); 188 of_node_put(root); 189 190 if (ppc_md.show_cpuinfo != NULL) 191 ppc_md.show_cpuinfo(m); 192 193 return 0; 194 } 195 196 /* We only show online cpus: disable preempt (overzealous, I 197 * knew) to prevent cpu going down. */ 198 preempt_disable(); 199 if (!cpu_online(cpu_id)) { 200 preempt_enable(); 201 return 0; 202 } 203 204 #ifdef CONFIG_SMP 205 pvr = per_cpu(pvr, cpu_id); 206 #else 207 pvr = mfspr(SPRN_PVR); 208 #endif 209 maj = (pvr >> 8) & 0xFF; 210 min = pvr & 0xFF; 211 212 seq_printf(m, "processor\t: %lu\n", cpu_id); 213 seq_printf(m, "cpu\t\t: "); 214 215 if (cur_cpu_spec->pvr_mask) 216 seq_printf(m, "%s", cur_cpu_spec->cpu_name); 217 else 218 seq_printf(m, "unknown (%08x)", pvr); 219 220 #ifdef CONFIG_ALTIVEC 221 if (cpu_has_feature(CPU_FTR_ALTIVEC)) 222 seq_printf(m, ", altivec supported"); 223 #endif /* CONFIG_ALTIVEC */ 224 225 seq_printf(m, "\n"); 226 227 #ifdef CONFIG_TAU 228 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) { 229 #ifdef CONFIG_TAU_AVERAGE 230 /* more straightforward, but potentially misleading */ 231 seq_printf(m, "temperature \t: %u C (uncalibrated)\n", 232 cpu_temp(cpu_id)); 233 #else 234 /* show the actual temp sensor range */ 235 u32 temp; 236 temp = cpu_temp_both(cpu_id); 237 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n", 238 temp & 0xff, temp >> 16); 239 #endif 240 } 241 #endif /* CONFIG_TAU */ 242 243 /* 244 * Assume here that all clock rates are the same in a 245 * smp system. -- Cort 246 */ 247 if (ppc_proc_freq) 248 seq_printf(m, "clock\t\t: %lu.%06luMHz\n", 249 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000); 250 251 if (ppc_md.show_percpuinfo != NULL) 252 ppc_md.show_percpuinfo(m, cpu_id); 253 254 /* If we are a Freescale core do a simple check so 255 * we dont have to keep adding cases in the future */ 256 if (PVR_VER(pvr) & 0x8000) { 257 maj = PVR_MAJ(pvr); 258 min = PVR_MIN(pvr); 259 } else { 260 switch (PVR_VER(pvr)) { 261 case 0x0020: /* 403 family */ 262 maj = PVR_MAJ(pvr) + 1; 263 min = PVR_MIN(pvr); 264 break; 265 case 0x1008: /* 740P/750P ?? */ 266 maj = ((pvr >> 8) & 0xFF) - 1; 267 min = pvr & 0xFF; 268 break; 269 default: 270 maj = (pvr >> 8) & 0xFF; 271 min = pvr & 0xFF; 272 break; 273 } 274 } 275 276 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n", 277 maj, min, PVR_VER(pvr), PVR_REV(pvr)); 278 279 #ifdef CONFIG_PPC32 280 seq_printf(m, "bogomips\t: %lu.%02lu\n", 281 loops_per_jiffy / (500000/HZ), 282 (loops_per_jiffy / (5000/HZ)) % 100); 283 #endif 284 285 #ifdef CONFIG_SMP 286 seq_printf(m, "\n"); 287 #endif 288 289 preempt_enable(); 290 return 0; 291 } 292 293 static void *c_start(struct seq_file *m, loff_t *pos) 294 { 295 unsigned long i = *pos; 296 297 return i <= NR_CPUS ? (void *)(i + 1) : NULL; 298 } 299 300 static void *c_next(struct seq_file *m, void *v, loff_t *pos) 301 { 302 ++*pos; 303 return c_start(m, pos); 304 } 305 306 static void c_stop(struct seq_file *m, void *v) 307 { 308 } 309 310 struct seq_operations cpuinfo_op = { 311 .start =c_start, 312 .next = c_next, 313 .stop = c_stop, 314 .show = show_cpuinfo, 315 }; 316 317 void __init check_for_initrd(void) 318 { 319 #ifdef CONFIG_BLK_DEV_INITRD 320 DBG(" -> check_for_initrd() initrd_start=0x%lx initrd_end=0x%lx\n", 321 initrd_start, initrd_end); 322 323 /* If we were passed an initrd, set the ROOT_DEV properly if the values 324 * look sensible. If not, clear initrd reference. 325 */ 326 if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) && 327 initrd_end > initrd_start) 328 ROOT_DEV = Root_RAM0; 329 else 330 initrd_start = initrd_end = 0; 331 332 if (initrd_start) 333 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end); 334 335 DBG(" <- check_for_initrd()\n"); 336 #endif /* CONFIG_BLK_DEV_INITRD */ 337 } 338 339 #ifdef CONFIG_SMP 340 341 int threads_per_core, threads_shift; 342 cpumask_t threads_core_mask; 343 344 static void __init cpu_init_thread_core_maps(int tpc) 345 { 346 int i; 347 348 threads_per_core = tpc; 349 threads_core_mask = CPU_MASK_NONE; 350 351 /* This implementation only supports power of 2 number of threads 352 * for simplicity and performance 353 */ 354 threads_shift = ilog2(tpc); 355 BUG_ON(tpc != (1 << threads_shift)); 356 357 for (i = 0; i < tpc; i++) 358 cpu_set(i, threads_core_mask); 359 360 printk(KERN_INFO "CPU maps initialized for %d thread%s per core\n", 361 tpc, tpc > 1 ? "s" : ""); 362 printk(KERN_DEBUG " (thread shift is %d)\n", threads_shift); 363 } 364 365 366 /** 367 * setup_cpu_maps - initialize the following cpu maps: 368 * cpu_possible_map 369 * cpu_present_map 370 * 371 * Having the possible map set up early allows us to restrict allocations 372 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS. 373 * 374 * We do not initialize the online map here; cpus set their own bits in 375 * cpu_online_map as they come up. 376 * 377 * This function is valid only for Open Firmware systems. finish_device_tree 378 * must be called before using this. 379 * 380 * While we're here, we may as well set the "physical" cpu ids in the paca. 381 * 382 * NOTE: This must match the parsing done in early_init_dt_scan_cpus. 383 */ 384 void __init smp_setup_cpu_maps(void) 385 { 386 struct device_node *dn = NULL; 387 int cpu = 0; 388 int nthreads = 1; 389 390 DBG("smp_setup_cpu_maps()\n"); 391 392 while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) { 393 const int *intserv; 394 int j, len; 395 396 DBG(" * %s...\n", dn->full_name); 397 398 intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s", 399 &len); 400 if (intserv) { 401 nthreads = len / sizeof(int); 402 DBG(" ibm,ppc-interrupt-server#s -> %d threads\n", 403 nthreads); 404 } else { 405 DBG(" no ibm,ppc-interrupt-server#s -> 1 thread\n"); 406 intserv = of_get_property(dn, "reg", NULL); 407 if (!intserv) 408 intserv = &cpu; /* assume logical == phys */ 409 } 410 411 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) { 412 DBG(" thread %d -> cpu %d (hard id %d)\n", 413 j, cpu, intserv[j]); 414 cpu_set(cpu, cpu_present_map); 415 set_hard_smp_processor_id(cpu, intserv[j]); 416 cpu_set(cpu, cpu_possible_map); 417 cpu++; 418 } 419 } 420 421 /* If no SMT supported, nthreads is forced to 1 */ 422 if (!cpu_has_feature(CPU_FTR_SMT)) { 423 DBG(" SMT disabled ! nthreads forced to 1\n"); 424 nthreads = 1; 425 } 426 427 #ifdef CONFIG_PPC64 428 /* 429 * On pSeries LPAR, we need to know how many cpus 430 * could possibly be added to this partition. 431 */ 432 if (machine_is(pseries) && firmware_has_feature(FW_FEATURE_LPAR) && 433 (dn = of_find_node_by_path("/rtas"))) { 434 int num_addr_cell, num_size_cell, maxcpus; 435 const unsigned int *ireg; 436 437 num_addr_cell = of_n_addr_cells(dn); 438 num_size_cell = of_n_size_cells(dn); 439 440 ireg = of_get_property(dn, "ibm,lrdr-capacity", NULL); 441 442 if (!ireg) 443 goto out; 444 445 maxcpus = ireg[num_addr_cell + num_size_cell]; 446 447 /* Double maxcpus for processors which have SMT capability */ 448 if (cpu_has_feature(CPU_FTR_SMT)) 449 maxcpus *= nthreads; 450 451 if (maxcpus > NR_CPUS) { 452 printk(KERN_WARNING 453 "Partition configured for %d cpus, " 454 "operating system maximum is %d.\n", 455 maxcpus, NR_CPUS); 456 maxcpus = NR_CPUS; 457 } else 458 printk(KERN_INFO "Partition configured for %d cpus.\n", 459 maxcpus); 460 461 for (cpu = 0; cpu < maxcpus; cpu++) 462 cpu_set(cpu, cpu_possible_map); 463 out: 464 of_node_put(dn); 465 } 466 vdso_data->processorCount = num_present_cpus(); 467 #endif /* CONFIG_PPC64 */ 468 469 /* Initialize CPU <=> thread mapping/ 470 * 471 * WARNING: We assume that the number of threads is the same for 472 * every CPU in the system. If that is not the case, then some code 473 * here will have to be reworked 474 */ 475 cpu_init_thread_core_maps(nthreads); 476 } 477 #endif /* CONFIG_SMP */ 478 479 #ifdef CONFIG_PCSPKR_PLATFORM 480 static __init int add_pcspkr(void) 481 { 482 struct device_node *np; 483 struct platform_device *pd; 484 int ret; 485 486 np = of_find_compatible_node(NULL, NULL, "pnpPNP,100"); 487 of_node_put(np); 488 if (!np) 489 return -ENODEV; 490 491 pd = platform_device_alloc("pcspkr", -1); 492 if (!pd) 493 return -ENOMEM; 494 495 ret = platform_device_add(pd); 496 if (ret) 497 platform_device_put(pd); 498 499 return ret; 500 } 501 device_initcall(add_pcspkr); 502 #endif /* CONFIG_PCSPKR_PLATFORM */ 503 504 void probe_machine(void) 505 { 506 extern struct machdep_calls __machine_desc_start; 507 extern struct machdep_calls __machine_desc_end; 508 509 /* 510 * Iterate all ppc_md structures until we find the proper 511 * one for the current machine type 512 */ 513 DBG("Probing machine type ...\n"); 514 515 for (machine_id = &__machine_desc_start; 516 machine_id < &__machine_desc_end; 517 machine_id++) { 518 DBG(" %s ...", machine_id->name); 519 memcpy(&ppc_md, machine_id, sizeof(struct machdep_calls)); 520 if (ppc_md.probe()) { 521 DBG(" match !\n"); 522 break; 523 } 524 DBG("\n"); 525 } 526 /* What can we do if we didn't find ? */ 527 if (machine_id >= &__machine_desc_end) { 528 DBG("No suitable machine found !\n"); 529 for (;;); 530 } 531 532 printk(KERN_INFO "Using %s machine description\n", ppc_md.name); 533 } 534 535 /* Match a class of boards, not a specific device configuration. */ 536 int check_legacy_ioport(unsigned long base_port) 537 { 538 struct device_node *parent, *np = NULL; 539 int ret = -ENODEV; 540 541 switch(base_port) { 542 case I8042_DATA_REG: 543 if (!(np = of_find_compatible_node(NULL, NULL, "pnpPNP,303"))) 544 np = of_find_compatible_node(NULL, NULL, "pnpPNP,f03"); 545 if (np) { 546 parent = of_get_parent(np); 547 of_node_put(np); 548 np = parent; 549 break; 550 } 551 np = of_find_node_by_type(NULL, "8042"); 552 /* Pegasos has no device_type on its 8042 node, look for the 553 * name instead */ 554 if (!np) 555 np = of_find_node_by_name(NULL, "8042"); 556 break; 557 case FDC_BASE: /* FDC1 */ 558 np = of_find_node_by_type(NULL, "fdc"); 559 break; 560 #ifdef CONFIG_PPC_PREP 561 case _PIDXR: 562 case _PNPWRP: 563 case PNPBIOS_BASE: 564 /* implement me */ 565 #endif 566 default: 567 /* ipmi is supposed to fail here */ 568 break; 569 } 570 if (!np) 571 return ret; 572 parent = of_get_parent(np); 573 if (parent) { 574 if (strcmp(parent->type, "isa") == 0) 575 ret = 0; 576 of_node_put(parent); 577 } 578 of_node_put(np); 579 return ret; 580 } 581 EXPORT_SYMBOL(check_legacy_ioport); 582 583 static int ppc_panic_event(struct notifier_block *this, 584 unsigned long event, void *ptr) 585 { 586 ppc_md.panic(ptr); /* May not return */ 587 return NOTIFY_DONE; 588 } 589 590 static struct notifier_block ppc_panic_block = { 591 .notifier_call = ppc_panic_event, 592 .priority = INT_MIN /* may not return; must be done last */ 593 }; 594 595 void __init setup_panic(void) 596 { 597 atomic_notifier_chain_register(&panic_notifier_list, &ppc_panic_block); 598 } 599 600 #ifdef CONFIG_CHECK_CACHE_COHERENCY 601 /* 602 * For platforms that have configurable cache-coherency. This function 603 * checks that the cache coherency setting of the kernel matches the setting 604 * left by the firmware, as indicated in the device tree. Since a mismatch 605 * will eventually result in DMA failures, we print * and error and call 606 * BUG() in that case. 607 */ 608 609 #ifdef CONFIG_NOT_COHERENT_CACHE 610 #define KERNEL_COHERENCY 0 611 #else 612 #define KERNEL_COHERENCY 1 613 #endif 614 615 static int __init check_cache_coherency(void) 616 { 617 struct device_node *np; 618 const void *prop; 619 int devtree_coherency; 620 621 np = of_find_node_by_path("/"); 622 prop = of_get_property(np, "coherency-off", NULL); 623 of_node_put(np); 624 625 devtree_coherency = prop ? 0 : 1; 626 627 if (devtree_coherency != KERNEL_COHERENCY) { 628 printk(KERN_ERR 629 "kernel coherency:%s != device tree_coherency:%s\n", 630 KERNEL_COHERENCY ? "on" : "off", 631 devtree_coherency ? "on" : "off"); 632 BUG(); 633 } 634 635 return 0; 636 } 637 638 late_initcall(check_cache_coherency); 639 #endif /* CONFIG_CHECK_CACHE_COHERENCY */ 640 641 #ifdef CONFIG_DEBUG_FS 642 struct dentry *powerpc_debugfs_root; 643 644 static int powerpc_debugfs_init(void) 645 { 646 powerpc_debugfs_root = debugfs_create_dir("powerpc", NULL); 647 648 return powerpc_debugfs_root == NULL; 649 } 650 arch_initcall(powerpc_debugfs_init); 651 #endif 652