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 #include <linux/config.h> 13 #include <linux/module.h> 14 #include <linux/string.h> 15 #include <linux/sched.h> 16 #include <linux/init.h> 17 #include <linux/kernel.h> 18 #include <linux/reboot.h> 19 #include <linux/delay.h> 20 #include <linux/initrd.h> 21 #include <linux/platform_device.h> 22 #include <linux/ide.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 <asm/io.h> 35 #include <asm/prom.h> 36 #include <asm/processor.h> 37 #include <asm/vdso_datapage.h> 38 #include <asm/pgtable.h> 39 #include <asm/smp.h> 40 #include <asm/elf.h> 41 #include <asm/machdep.h> 42 #include <asm/time.h> 43 #include <asm/cputable.h> 44 #include <asm/sections.h> 45 #include <asm/btext.h> 46 #include <asm/nvram.h> 47 #include <asm/setup.h> 48 #include <asm/system.h> 49 #include <asm/rtas.h> 50 #include <asm/iommu.h> 51 #include <asm/serial.h> 52 #include <asm/cache.h> 53 #include <asm/page.h> 54 #include <asm/mmu.h> 55 #include <asm/lmb.h> 56 #include <asm/xmon.h> 57 58 #include "setup.h" 59 60 #undef DEBUG 61 62 #ifdef DEBUG 63 #include <asm/udbg.h> 64 #define DBG(fmt...) udbg_printf(fmt) 65 #else 66 #define DBG(fmt...) 67 #endif 68 69 #ifdef CONFIG_PPC_MULTIPLATFORM 70 int _machine = 0; 71 EXPORT_SYMBOL(_machine); 72 #endif 73 74 unsigned long klimit = (unsigned long) _end; 75 76 /* 77 * This still seems to be needed... -- paulus 78 */ 79 struct screen_info screen_info = { 80 .orig_x = 0, 81 .orig_y = 25, 82 .orig_video_cols = 80, 83 .orig_video_lines = 25, 84 .orig_video_isVGA = 1, 85 .orig_video_points = 16 86 }; 87 88 #ifdef __DO_IRQ_CANON 89 /* XXX should go elsewhere eventually */ 90 int ppc_do_canonicalize_irqs; 91 EXPORT_SYMBOL(ppc_do_canonicalize_irqs); 92 #endif 93 94 /* also used by kexec */ 95 void machine_shutdown(void) 96 { 97 if (ppc_md.machine_shutdown) 98 ppc_md.machine_shutdown(); 99 } 100 101 void machine_restart(char *cmd) 102 { 103 machine_shutdown(); 104 if (ppc_md.restart) 105 ppc_md.restart(cmd); 106 #ifdef CONFIG_SMP 107 smp_send_stop(); 108 #endif 109 printk(KERN_EMERG "System Halted, OK to turn off power\n"); 110 local_irq_disable(); 111 while (1) ; 112 } 113 114 void machine_power_off(void) 115 { 116 machine_shutdown(); 117 if (ppc_md.power_off) 118 ppc_md.power_off(); 119 #ifdef CONFIG_SMP 120 smp_send_stop(); 121 #endif 122 printk(KERN_EMERG "System Halted, OK to turn off power\n"); 123 local_irq_disable(); 124 while (1) ; 125 } 126 /* Used by the G5 thermal driver */ 127 EXPORT_SYMBOL_GPL(machine_power_off); 128 129 void (*pm_power_off)(void) = machine_power_off; 130 EXPORT_SYMBOL_GPL(pm_power_off); 131 132 void machine_halt(void) 133 { 134 machine_shutdown(); 135 if (ppc_md.halt) 136 ppc_md.halt(); 137 #ifdef CONFIG_SMP 138 smp_send_stop(); 139 #endif 140 printk(KERN_EMERG "System Halted, OK to turn off power\n"); 141 local_irq_disable(); 142 while (1) ; 143 } 144 145 146 #ifdef CONFIG_TAU 147 extern u32 cpu_temp(unsigned long cpu); 148 extern u32 cpu_temp_both(unsigned long cpu); 149 #endif /* CONFIG_TAU */ 150 151 #ifdef CONFIG_SMP 152 DEFINE_PER_CPU(unsigned int, pvr); 153 #endif 154 155 static int show_cpuinfo(struct seq_file *m, void *v) 156 { 157 unsigned long cpu_id = (unsigned long)v - 1; 158 unsigned int pvr; 159 unsigned short maj; 160 unsigned short min; 161 162 if (cpu_id == NR_CPUS) { 163 #if defined(CONFIG_SMP) && defined(CONFIG_PPC32) 164 unsigned long bogosum = 0; 165 int i; 166 for (i = 0; i < NR_CPUS; ++i) 167 if (cpu_online(i)) 168 bogosum += loops_per_jiffy; 169 seq_printf(m, "total bogomips\t: %lu.%02lu\n", 170 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100); 171 #endif /* CONFIG_SMP && CONFIG_PPC32 */ 172 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq); 173 174 if (ppc_md.show_cpuinfo != NULL) 175 ppc_md.show_cpuinfo(m); 176 177 return 0; 178 } 179 180 /* We only show online cpus: disable preempt (overzealous, I 181 * knew) to prevent cpu going down. */ 182 preempt_disable(); 183 if (!cpu_online(cpu_id)) { 184 preempt_enable(); 185 return 0; 186 } 187 188 #ifdef CONFIG_SMP 189 pvr = per_cpu(pvr, cpu_id); 190 #else 191 pvr = mfspr(SPRN_PVR); 192 #endif 193 maj = (pvr >> 8) & 0xFF; 194 min = pvr & 0xFF; 195 196 seq_printf(m, "processor\t: %lu\n", cpu_id); 197 seq_printf(m, "cpu\t\t: "); 198 199 if (cur_cpu_spec->pvr_mask) 200 seq_printf(m, "%s", cur_cpu_spec->cpu_name); 201 else 202 seq_printf(m, "unknown (%08x)", pvr); 203 204 #ifdef CONFIG_ALTIVEC 205 if (cpu_has_feature(CPU_FTR_ALTIVEC)) 206 seq_printf(m, ", altivec supported"); 207 #endif /* CONFIG_ALTIVEC */ 208 209 seq_printf(m, "\n"); 210 211 #ifdef CONFIG_TAU 212 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) { 213 #ifdef CONFIG_TAU_AVERAGE 214 /* more straightforward, but potentially misleading */ 215 seq_printf(m, "temperature \t: %u C (uncalibrated)\n", 216 cpu_temp(cpu_id)); 217 #else 218 /* show the actual temp sensor range */ 219 u32 temp; 220 temp = cpu_temp_both(cpu_id); 221 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n", 222 temp & 0xff, temp >> 16); 223 #endif 224 } 225 #endif /* CONFIG_TAU */ 226 227 /* 228 * Assume here that all clock rates are the same in a 229 * smp system. -- Cort 230 */ 231 if (ppc_proc_freq) 232 seq_printf(m, "clock\t\t: %lu.%06luMHz\n", 233 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000); 234 235 if (ppc_md.show_percpuinfo != NULL) 236 ppc_md.show_percpuinfo(m, cpu_id); 237 238 /* If we are a Freescale core do a simple check so 239 * we dont have to keep adding cases in the future */ 240 if (PVR_VER(pvr) & 0x8000) { 241 maj = PVR_MAJ(pvr); 242 min = PVR_MIN(pvr); 243 } else { 244 switch (PVR_VER(pvr)) { 245 case 0x0020: /* 403 family */ 246 maj = PVR_MAJ(pvr) + 1; 247 min = PVR_MIN(pvr); 248 break; 249 case 0x1008: /* 740P/750P ?? */ 250 maj = ((pvr >> 8) & 0xFF) - 1; 251 min = pvr & 0xFF; 252 break; 253 default: 254 maj = (pvr >> 8) & 0xFF; 255 min = pvr & 0xFF; 256 break; 257 } 258 } 259 260 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n", 261 maj, min, PVR_VER(pvr), PVR_REV(pvr)); 262 263 #ifdef CONFIG_PPC32 264 seq_printf(m, "bogomips\t: %lu.%02lu\n", 265 loops_per_jiffy / (500000/HZ), 266 (loops_per_jiffy / (5000/HZ)) % 100); 267 #endif 268 269 #ifdef CONFIG_SMP 270 seq_printf(m, "\n"); 271 #endif 272 273 preempt_enable(); 274 return 0; 275 } 276 277 static void *c_start(struct seq_file *m, loff_t *pos) 278 { 279 unsigned long i = *pos; 280 281 return i <= NR_CPUS ? (void *)(i + 1) : NULL; 282 } 283 284 static void *c_next(struct seq_file *m, void *v, loff_t *pos) 285 { 286 ++*pos; 287 return c_start(m, pos); 288 } 289 290 static void c_stop(struct seq_file *m, void *v) 291 { 292 } 293 294 struct seq_operations cpuinfo_op = { 295 .start =c_start, 296 .next = c_next, 297 .stop = c_stop, 298 .show = show_cpuinfo, 299 }; 300 301 void __init check_for_initrd(void) 302 { 303 #ifdef CONFIG_BLK_DEV_INITRD 304 unsigned long *prop; 305 306 DBG(" -> check_for_initrd()\n"); 307 308 if (of_chosen) { 309 prop = (unsigned long *)get_property(of_chosen, 310 "linux,initrd-start", NULL); 311 if (prop != NULL) { 312 initrd_start = (unsigned long)__va(*prop); 313 prop = (unsigned long *)get_property(of_chosen, 314 "linux,initrd-end", NULL); 315 if (prop != NULL) { 316 initrd_end = (unsigned long)__va(*prop); 317 initrd_below_start_ok = 1; 318 } else 319 initrd_start = 0; 320 } 321 } 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 /** 342 * setup_cpu_maps - initialize the following cpu maps: 343 * cpu_possible_map 344 * cpu_present_map 345 * cpu_sibling_map 346 * 347 * Having the possible map set up early allows us to restrict allocations 348 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS. 349 * 350 * We do not initialize the online map here; cpus set their own bits in 351 * cpu_online_map as they come up. 352 * 353 * This function is valid only for Open Firmware systems. finish_device_tree 354 * must be called before using this. 355 * 356 * While we're here, we may as well set the "physical" cpu ids in the paca. 357 */ 358 void __init smp_setup_cpu_maps(void) 359 { 360 struct device_node *dn = NULL; 361 int cpu = 0; 362 int swap_cpuid = 0; 363 364 while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) { 365 int *intserv; 366 int j, len = sizeof(u32), nthreads = 1; 367 368 intserv = (int *)get_property(dn, "ibm,ppc-interrupt-server#s", 369 &len); 370 if (intserv) 371 nthreads = len / sizeof(int); 372 else { 373 intserv = (int *) get_property(dn, "reg", NULL); 374 if (!intserv) 375 intserv = &cpu; /* assume logical == phys */ 376 } 377 378 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) { 379 cpu_set(cpu, cpu_present_map); 380 set_hard_smp_processor_id(cpu, intserv[j]); 381 382 if (intserv[j] == boot_cpuid_phys) 383 swap_cpuid = cpu; 384 cpu_set(cpu, cpu_possible_map); 385 cpu++; 386 } 387 } 388 389 /* Swap CPU id 0 with boot_cpuid_phys, so we can always assume that 390 * boot cpu is logical 0. 391 */ 392 if (boot_cpuid_phys != get_hard_smp_processor_id(0)) { 393 u32 tmp; 394 tmp = get_hard_smp_processor_id(0); 395 set_hard_smp_processor_id(0, boot_cpuid_phys); 396 set_hard_smp_processor_id(swap_cpuid, tmp); 397 } 398 399 #ifdef CONFIG_PPC64 400 /* 401 * On pSeries LPAR, we need to know how many cpus 402 * could possibly be added to this partition. 403 */ 404 if (_machine == PLATFORM_PSERIES_LPAR && 405 (dn = of_find_node_by_path("/rtas"))) { 406 int num_addr_cell, num_size_cell, maxcpus; 407 unsigned int *ireg; 408 409 num_addr_cell = prom_n_addr_cells(dn); 410 num_size_cell = prom_n_size_cells(dn); 411 412 ireg = (unsigned int *) 413 get_property(dn, "ibm,lrdr-capacity", NULL); 414 415 if (!ireg) 416 goto out; 417 418 maxcpus = ireg[num_addr_cell + num_size_cell]; 419 420 /* Double maxcpus for processors which have SMT capability */ 421 if (cpu_has_feature(CPU_FTR_SMT)) 422 maxcpus *= 2; 423 424 if (maxcpus > NR_CPUS) { 425 printk(KERN_WARNING 426 "Partition configured for %d cpus, " 427 "operating system maximum is %d.\n", 428 maxcpus, NR_CPUS); 429 maxcpus = NR_CPUS; 430 } else 431 printk(KERN_INFO "Partition configured for %d cpus.\n", 432 maxcpus); 433 434 for (cpu = 0; cpu < maxcpus; cpu++) 435 cpu_set(cpu, cpu_possible_map); 436 out: 437 of_node_put(dn); 438 } 439 440 /* 441 * Do the sibling map; assume only two threads per processor. 442 */ 443 for_each_cpu(cpu) { 444 cpu_set(cpu, cpu_sibling_map[cpu]); 445 if (cpu_has_feature(CPU_FTR_SMT)) 446 cpu_set(cpu ^ 0x1, cpu_sibling_map[cpu]); 447 } 448 449 vdso_data->processorCount = num_present_cpus(); 450 #endif /* CONFIG_PPC64 */ 451 } 452 #endif /* CONFIG_SMP */ 453 454 #ifdef CONFIG_XMON 455 static int __init early_xmon(char *p) 456 { 457 /* ensure xmon is enabled */ 458 if (p) { 459 if (strncmp(p, "on", 2) == 0) 460 xmon_init(1); 461 if (strncmp(p, "off", 3) == 0) 462 xmon_init(0); 463 if (strncmp(p, "early", 5) != 0) 464 return 0; 465 } 466 xmon_init(1); 467 debugger(NULL); 468 469 return 0; 470 } 471 early_param("xmon", early_xmon); 472 #endif 473 474 static __init int add_pcspkr(void) 475 { 476 struct device_node *np; 477 struct platform_device *pd; 478 int ret; 479 480 np = of_find_compatible_node(NULL, NULL, "pnpPNP,100"); 481 of_node_put(np); 482 if (!np) 483 return -ENODEV; 484 485 pd = platform_device_alloc("pcspkr", -1); 486 if (!pd) 487 return -ENOMEM; 488 489 ret = platform_device_add(pd); 490 if (ret) 491 platform_device_put(pd); 492 493 return ret; 494 } 495 device_initcall(add_pcspkr); 496