Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 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 | */ |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 12 | |
| 13 | #undef DEBUG |
| 14 | |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 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> |
Michael Neuling | e5c6c8e | 2006-03-14 00:11:50 -0500 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 24 | #include <linux/seq_file.h> |
| 25 | #include <linux/ioport.h> |
| 26 | #include <linux/console.h> |
| 27 | #include <linux/utsname.h> |
Jon Smirl | 894673e | 2006-07-10 04:44:13 -0700 | [diff] [blame] | 28 | #include <linux/screen_info.h> |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 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> |
Michael Ellerman | 94a3807 | 2007-06-20 10:54:19 +1000 | [diff] [blame] | 35 | #include <linux/debugfs.h> |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 36 | #include <linux/percpu.h> |
David S. Miller | d9b2b2a | 2008-02-13 16:56:49 -0800 | [diff] [blame] | 37 | #include <linux/lmb.h> |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 38 | #include <asm/io.h> |
| 39 | #include <asm/prom.h> |
| 40 | #include <asm/processor.h> |
Benjamin Herrenschmidt | a7f290d | 2005-11-11 21:15:21 +1100 | [diff] [blame] | 41 | #include <asm/vdso_datapage.h> |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 42 | #include <asm/pgtable.h> |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 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> |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 49 | #include <asm/firmware.h> |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 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> |
Paul Mackerras | fca5dcd | 2005-11-08 22:55:08 +1100 | [diff] [blame] | 60 | #include <asm/xmon.h> |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 61 | #include <asm/cputhreads.h> |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 62 | |
Stephen Rothwell | 66ba135 | 2005-11-09 11:01:06 +1100 | [diff] [blame] | 63 | #include "setup.h" |
| 64 | |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 65 | #ifdef DEBUG |
Michael Ellerman | f9e4ec5 | 2005-11-15 15:16:38 +1100 | [diff] [blame] | 66 | #include <asm/udbg.h> |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 67 | #define DBG(fmt...) udbg_printf(fmt) |
| 68 | #else |
| 69 | #define DBG(fmt...) |
| 70 | #endif |
| 71 | |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 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); |
Paul Mackerras | 799d604 | 2005-11-10 13:37:51 +1100 | [diff] [blame] | 78 | |
Paul Mackerras | 49b0985 | 2005-11-10 15:53:40 +1100 | [diff] [blame] | 79 | unsigned long klimit = (unsigned long) _end; |
| 80 | |
Stephen Rothwell | 19a8d97 | 2007-09-17 14:41:38 +1000 | [diff] [blame] | 81 | char cmd_line[COMMAND_LINE_SIZE]; |
| 82 | |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 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 | { |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 104 | if (ppc_md.machine_shutdown) |
| 105 | ppc_md.machine_shutdown(); |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void machine_restart(char *cmd) |
| 109 | { |
| 110 | machine_shutdown(); |
Kumar Gala | b8e383d | 2006-01-13 10:15:17 -0600 | [diff] [blame] | 111 | if (ppc_md.restart) |
| 112 | ppc_md.restart(cmd); |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 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(); |
Kumar Gala | b8e383d | 2006-01-13 10:15:17 -0600 | [diff] [blame] | 124 | if (ppc_md.power_off) |
| 125 | ppc_md.power_off(); |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 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(); |
Kumar Gala | b8e383d | 2006-01-13 10:15:17 -0600 | [diff] [blame] | 142 | if (ppc_md.halt) |
| 143 | ppc_md.halt(); |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 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) { |
Marian Balakowicz | 0276c13 | 2007-11-10 04:11:43 +1100 | [diff] [blame] | 170 | struct device_node *root; |
| 171 | const char *model = NULL; |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 172 | #if defined(CONFIG_SMP) && defined(CONFIG_PPC32) |
| 173 | unsigned long bogosum = 0; |
| 174 | int i; |
Andrew Morton | 394e390 | 2006-03-23 03:01:05 -0800 | [diff] [blame] | 175 | for_each_online_cpu(i) |
| 176 | bogosum += loops_per_jiffy; |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 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); |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 181 | if (ppc_md.name) |
| 182 | seq_printf(m, "platform\t: %s\n", ppc_md.name); |
Marian Balakowicz | 0276c13 | 2007-11-10 04:11:43 +1100 | [diff] [blame] | 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 | |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 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 |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 205 | pvr = per_cpu(pvr, cpu_id); |
| 206 | #else |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 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", |
Paul Mackerras | bccfd58 | 2005-11-02 15:06:22 +1100 | [diff] [blame] | 232 | cpu_temp(cpu_id)); |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 233 | #else |
| 234 | /* show the actual temp sensor range */ |
| 235 | u32 temp; |
Paul Mackerras | bccfd58 | 2005-11-02 15:06:22 +1100 | [diff] [blame] | 236 | temp = cpu_temp_both(cpu_id); |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 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) { |
Martin Langer | a501d8f | 2008-09-07 17:51:32 +1000 | [diff] [blame^] | 257 | switch (PVR_VER(pvr)) { |
| 258 | case 0x8000: /* 7441/7450/7451, Voyager */ |
| 259 | case 0x8001: /* 7445/7455, Apollo 6 */ |
| 260 | case 0x8002: /* 7447/7457, Apollo 7 */ |
| 261 | case 0x8003: /* 7447A, Apollo 7 PM */ |
| 262 | case 0x8004: /* 7448, Apollo 8 */ |
| 263 | case 0x800c: /* 7410, Nitro */ |
| 264 | maj = ((pvr >> 8) & 0xF); |
| 265 | min = PVR_MIN(pvr); |
| 266 | break; |
| 267 | default: /* e500/book-e */ |
| 268 | maj = PVR_MAJ(pvr); |
| 269 | min = PVR_MIN(pvr); |
| 270 | break; |
| 271 | } |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 272 | } else { |
| 273 | switch (PVR_VER(pvr)) { |
| 274 | case 0x0020: /* 403 family */ |
| 275 | maj = PVR_MAJ(pvr) + 1; |
| 276 | min = PVR_MIN(pvr); |
| 277 | break; |
| 278 | case 0x1008: /* 740P/750P ?? */ |
| 279 | maj = ((pvr >> 8) & 0xFF) - 1; |
| 280 | min = pvr & 0xFF; |
| 281 | break; |
| 282 | default: |
| 283 | maj = (pvr >> 8) & 0xFF; |
| 284 | min = pvr & 0xFF; |
| 285 | break; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n", |
| 290 | maj, min, PVR_VER(pvr), PVR_REV(pvr)); |
| 291 | |
| 292 | #ifdef CONFIG_PPC32 |
| 293 | seq_printf(m, "bogomips\t: %lu.%02lu\n", |
| 294 | loops_per_jiffy / (500000/HZ), |
| 295 | (loops_per_jiffy / (5000/HZ)) % 100); |
| 296 | #endif |
| 297 | |
| 298 | #ifdef CONFIG_SMP |
| 299 | seq_printf(m, "\n"); |
| 300 | #endif |
| 301 | |
| 302 | preempt_enable(); |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | static void *c_start(struct seq_file *m, loff_t *pos) |
| 307 | { |
| 308 | unsigned long i = *pos; |
| 309 | |
| 310 | return i <= NR_CPUS ? (void *)(i + 1) : NULL; |
| 311 | } |
| 312 | |
| 313 | static void *c_next(struct seq_file *m, void *v, loff_t *pos) |
| 314 | { |
| 315 | ++*pos; |
| 316 | return c_start(m, pos); |
| 317 | } |
| 318 | |
| 319 | static void c_stop(struct seq_file *m, void *v) |
| 320 | { |
| 321 | } |
| 322 | |
| 323 | struct seq_operations cpuinfo_op = { |
| 324 | .start =c_start, |
| 325 | .next = c_next, |
| 326 | .stop = c_stop, |
| 327 | .show = show_cpuinfo, |
| 328 | }; |
| 329 | |
David Woodhouse | a82765b | 2005-11-02 22:34:20 +0000 | [diff] [blame] | 330 | void __init check_for_initrd(void) |
| 331 | { |
| 332 | #ifdef CONFIG_BLK_DEV_INITRD |
David Gibson | 30437b3 | 2007-02-28 14:12:29 +1100 | [diff] [blame] | 333 | DBG(" -> check_for_initrd() initrd_start=0x%lx initrd_end=0x%lx\n", |
| 334 | initrd_start, initrd_end); |
David Woodhouse | a82765b | 2005-11-02 22:34:20 +0000 | [diff] [blame] | 335 | |
| 336 | /* If we were passed an initrd, set the ROOT_DEV properly if the values |
| 337 | * look sensible. If not, clear initrd reference. |
| 338 | */ |
Michael Ellerman | 51fae6de | 2005-12-04 18:39:15 +1100 | [diff] [blame] | 339 | if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) && |
David Woodhouse | a82765b | 2005-11-02 22:34:20 +0000 | [diff] [blame] | 340 | initrd_end > initrd_start) |
| 341 | ROOT_DEV = Root_RAM0; |
David Woodhouse | 6761c4a | 2005-11-11 08:07:11 +0000 | [diff] [blame] | 342 | else |
David Woodhouse | a82765b | 2005-11-02 22:34:20 +0000 | [diff] [blame] | 343 | initrd_start = initrd_end = 0; |
David Woodhouse | a82765b | 2005-11-02 22:34:20 +0000 | [diff] [blame] | 344 | |
| 345 | if (initrd_start) |
| 346 | printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end); |
| 347 | |
| 348 | DBG(" <- check_for_initrd()\n"); |
| 349 | #endif /* CONFIG_BLK_DEV_INITRD */ |
| 350 | } |
| 351 | |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 352 | #ifdef CONFIG_SMP |
| 353 | |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 354 | int threads_per_core, threads_shift; |
| 355 | cpumask_t threads_core_mask; |
| 356 | |
| 357 | static void __init cpu_init_thread_core_maps(int tpc) |
| 358 | { |
| 359 | int i; |
| 360 | |
| 361 | threads_per_core = tpc; |
| 362 | threads_core_mask = CPU_MASK_NONE; |
| 363 | |
| 364 | /* This implementation only supports power of 2 number of threads |
| 365 | * for simplicity and performance |
| 366 | */ |
| 367 | threads_shift = ilog2(tpc); |
| 368 | BUG_ON(tpc != (1 << threads_shift)); |
| 369 | |
| 370 | for (i = 0; i < tpc; i++) |
| 371 | cpu_set(i, threads_core_mask); |
| 372 | |
| 373 | printk(KERN_INFO "CPU maps initialized for %d thread%s per core\n", |
| 374 | tpc, tpc > 1 ? "s" : ""); |
| 375 | printk(KERN_DEBUG " (thread shift is %d)\n", threads_shift); |
| 376 | } |
| 377 | |
| 378 | |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 379 | /** |
| 380 | * setup_cpu_maps - initialize the following cpu maps: |
| 381 | * cpu_possible_map |
| 382 | * cpu_present_map |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 383 | * |
| 384 | * Having the possible map set up early allows us to restrict allocations |
| 385 | * of things like irqstacks to num_possible_cpus() rather than NR_CPUS. |
| 386 | * |
| 387 | * We do not initialize the online map here; cpus set their own bits in |
| 388 | * cpu_online_map as they come up. |
| 389 | * |
| 390 | * This function is valid only for Open Firmware systems. finish_device_tree |
| 391 | * must be called before using this. |
| 392 | * |
| 393 | * While we're here, we may as well set the "physical" cpu ids in the paca. |
Anton Blanchard | 4df2046 | 2006-03-25 17:25:17 +1100 | [diff] [blame] | 394 | * |
| 395 | * NOTE: This must match the parsing done in early_init_dt_scan_cpus. |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 396 | */ |
| 397 | void __init smp_setup_cpu_maps(void) |
| 398 | { |
| 399 | struct device_node *dn = NULL; |
| 400 | int cpu = 0; |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 401 | int nthreads = 1; |
| 402 | |
| 403 | DBG("smp_setup_cpu_maps()\n"); |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 404 | |
| 405 | while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) { |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 406 | const int *intserv; |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 407 | int j, len; |
| 408 | |
| 409 | DBG(" * %s...\n", dn->full_name); |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 410 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 411 | intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s", |
| 412 | &len); |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 413 | if (intserv) { |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 414 | nthreads = len / sizeof(int); |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 415 | DBG(" ibm,ppc-interrupt-server#s -> %d threads\n", |
| 416 | nthreads); |
| 417 | } else { |
| 418 | DBG(" no ibm,ppc-interrupt-server#s -> 1 thread\n"); |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 419 | intserv = of_get_property(dn, "reg", NULL); |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 420 | if (!intserv) |
| 421 | intserv = &cpu; /* assume logical == phys */ |
| 422 | } |
| 423 | |
| 424 | for (j = 0; j < nthreads && cpu < NR_CPUS; j++) { |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 425 | DBG(" thread %d -> cpu %d (hard id %d)\n", |
| 426 | j, cpu, intserv[j]); |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 427 | cpu_set(cpu, cpu_present_map); |
| 428 | set_hard_smp_processor_id(cpu, intserv[j]); |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 429 | cpu_set(cpu, cpu_possible_map); |
| 430 | cpu++; |
| 431 | } |
| 432 | } |
| 433 | |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 434 | /* If no SMT supported, nthreads is forced to 1 */ |
| 435 | if (!cpu_has_feature(CPU_FTR_SMT)) { |
| 436 | DBG(" SMT disabled ! nthreads forced to 1\n"); |
| 437 | nthreads = 1; |
| 438 | } |
| 439 | |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 440 | #ifdef CONFIG_PPC64 |
| 441 | /* |
| 442 | * On pSeries LPAR, we need to know how many cpus |
| 443 | * could possibly be added to this partition. |
| 444 | */ |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 445 | if (machine_is(pseries) && firmware_has_feature(FW_FEATURE_LPAR) && |
Paul Mackerras | 799d604 | 2005-11-10 13:37:51 +1100 | [diff] [blame] | 446 | (dn = of_find_node_by_path("/rtas"))) { |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 447 | int num_addr_cell, num_size_cell, maxcpus; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 448 | const unsigned int *ireg; |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 449 | |
Stephen Rothwell | a8bda5d | 2007-04-03 10:56:50 +1000 | [diff] [blame] | 450 | num_addr_cell = of_n_addr_cells(dn); |
Stephen Rothwell | 9213fee | 2007-04-03 10:57:48 +1000 | [diff] [blame] | 451 | num_size_cell = of_n_size_cells(dn); |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 452 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 453 | ireg = of_get_property(dn, "ibm,lrdr-capacity", NULL); |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 454 | |
| 455 | if (!ireg) |
| 456 | goto out; |
| 457 | |
| 458 | maxcpus = ireg[num_addr_cell + num_size_cell]; |
| 459 | |
| 460 | /* Double maxcpus for processors which have SMT capability */ |
| 461 | if (cpu_has_feature(CPU_FTR_SMT)) |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 462 | maxcpus *= nthreads; |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 463 | |
| 464 | if (maxcpus > NR_CPUS) { |
| 465 | printk(KERN_WARNING |
| 466 | "Partition configured for %d cpus, " |
| 467 | "operating system maximum is %d.\n", |
| 468 | maxcpus, NR_CPUS); |
| 469 | maxcpus = NR_CPUS; |
| 470 | } else |
| 471 | printk(KERN_INFO "Partition configured for %d cpus.\n", |
| 472 | maxcpus); |
| 473 | |
| 474 | for (cpu = 0; cpu < maxcpus; cpu++) |
| 475 | cpu_set(cpu, cpu_possible_map); |
| 476 | out: |
| 477 | of_node_put(dn); |
| 478 | } |
Mike Travis | d5a7430 | 2007-10-16 01:24:05 -0700 | [diff] [blame] | 479 | vdso_data->processorCount = num_present_cpus(); |
| 480 | #endif /* CONFIG_PPC64 */ |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 481 | |
| 482 | /* Initialize CPU <=> thread mapping/ |
| 483 | * |
| 484 | * WARNING: We assume that the number of threads is the same for |
| 485 | * every CPU in the system. If that is not the case, then some code |
| 486 | * here will have to be reworked |
| 487 | */ |
| 488 | cpu_init_thread_core_maps(nthreads); |
Mike Travis | d5a7430 | 2007-10-16 01:24:05 -0700 | [diff] [blame] | 489 | } |
Paul Mackerras | 5ad5707 | 2005-11-05 10:33:55 +1100 | [diff] [blame] | 490 | #endif /* CONFIG_SMP */ |
Paul Mackerras | fca5dcd | 2005-11-08 22:55:08 +1100 | [diff] [blame] | 491 | |
Emil Medve | d33b78d | 2008-05-23 08:40:16 +1000 | [diff] [blame] | 492 | #ifdef CONFIG_PCSPKR_PLATFORM |
Michael Neuling | e5c6c8e | 2006-03-14 00:11:50 -0500 | [diff] [blame] | 493 | static __init int add_pcspkr(void) |
| 494 | { |
| 495 | struct device_node *np; |
| 496 | struct platform_device *pd; |
| 497 | int ret; |
| 498 | |
| 499 | np = of_find_compatible_node(NULL, NULL, "pnpPNP,100"); |
| 500 | of_node_put(np); |
| 501 | if (!np) |
| 502 | return -ENODEV; |
| 503 | |
| 504 | pd = platform_device_alloc("pcspkr", -1); |
| 505 | if (!pd) |
| 506 | return -ENOMEM; |
| 507 | |
| 508 | ret = platform_device_add(pd); |
| 509 | if (ret) |
| 510 | platform_device_put(pd); |
| 511 | |
| 512 | return ret; |
| 513 | } |
| 514 | device_initcall(add_pcspkr); |
Emil Medve | d33b78d | 2008-05-23 08:40:16 +1000 | [diff] [blame] | 515 | #endif /* CONFIG_PCSPKR_PLATFORM */ |
Dmitry Torokhov | 95d465f | 2006-04-02 00:08:05 -0500 | [diff] [blame] | 516 | |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 517 | void probe_machine(void) |
| 518 | { |
| 519 | extern struct machdep_calls __machine_desc_start; |
| 520 | extern struct machdep_calls __machine_desc_end; |
| 521 | |
| 522 | /* |
| 523 | * Iterate all ppc_md structures until we find the proper |
| 524 | * one for the current machine type |
| 525 | */ |
| 526 | DBG("Probing machine type ...\n"); |
| 527 | |
| 528 | for (machine_id = &__machine_desc_start; |
| 529 | machine_id < &__machine_desc_end; |
| 530 | machine_id++) { |
| 531 | DBG(" %s ...", machine_id->name); |
| 532 | memcpy(&ppc_md, machine_id, sizeof(struct machdep_calls)); |
| 533 | if (ppc_md.probe()) { |
| 534 | DBG(" match !\n"); |
| 535 | break; |
| 536 | } |
| 537 | DBG("\n"); |
| 538 | } |
| 539 | /* What can we do if we didn't find ? */ |
| 540 | if (machine_id >= &__machine_desc_end) { |
| 541 | DBG("No suitable machine found !\n"); |
| 542 | for (;;); |
| 543 | } |
| 544 | |
| 545 | printk(KERN_INFO "Using %s machine description\n", ppc_md.name); |
| 546 | } |
David Woodhouse | 1269277a | 2006-04-24 23:22:17 +0100 | [diff] [blame] | 547 | |
Olaf Hering | 8d8a024 | 2007-04-26 06:36:56 +1000 | [diff] [blame] | 548 | /* Match a class of boards, not a specific device configuration. */ |
David Woodhouse | 1269277a | 2006-04-24 23:22:17 +0100 | [diff] [blame] | 549 | int check_legacy_ioport(unsigned long base_port) |
| 550 | { |
Olaf Hering | 8d8a024 | 2007-04-26 06:36:56 +1000 | [diff] [blame] | 551 | struct device_node *parent, *np = NULL; |
| 552 | int ret = -ENODEV; |
| 553 | |
| 554 | switch(base_port) { |
| 555 | case I8042_DATA_REG: |
Wade Farnsworth | db0dbae | 2007-06-20 10:15:10 +1000 | [diff] [blame] | 556 | if (!(np = of_find_compatible_node(NULL, NULL, "pnpPNP,303"))) |
| 557 | np = of_find_compatible_node(NULL, NULL, "pnpPNP,f03"); |
| 558 | if (np) { |
| 559 | parent = of_get_parent(np); |
| 560 | of_node_put(np); |
| 561 | np = parent; |
| 562 | break; |
| 563 | } |
Olaf Hering | 8d8a024 | 2007-04-26 06:36:56 +1000 | [diff] [blame] | 564 | np = of_find_node_by_type(NULL, "8042"); |
Alan Curry | f5d834f | 2007-07-25 11:28:32 +1000 | [diff] [blame] | 565 | /* Pegasos has no device_type on its 8042 node, look for the |
| 566 | * name instead */ |
| 567 | if (!np) |
| 568 | np = of_find_node_by_name(NULL, "8042"); |
Olaf Hering | 8d8a024 | 2007-04-26 06:36:56 +1000 | [diff] [blame] | 569 | break; |
| 570 | case FDC_BASE: /* FDC1 */ |
| 571 | np = of_find_node_by_type(NULL, "fdc"); |
| 572 | break; |
| 573 | #ifdef CONFIG_PPC_PREP |
| 574 | case _PIDXR: |
| 575 | case _PNPWRP: |
| 576 | case PNPBIOS_BASE: |
| 577 | /* implement me */ |
| 578 | #endif |
| 579 | default: |
| 580 | /* ipmi is supposed to fail here */ |
| 581 | break; |
| 582 | } |
| 583 | if (!np) |
| 584 | return ret; |
| 585 | parent = of_get_parent(np); |
| 586 | if (parent) { |
| 587 | if (strcmp(parent->type, "isa") == 0) |
| 588 | ret = 0; |
| 589 | of_node_put(parent); |
| 590 | } |
| 591 | of_node_put(np); |
| 592 | return ret; |
David Woodhouse | 1269277a | 2006-04-24 23:22:17 +0100 | [diff] [blame] | 593 | } |
| 594 | EXPORT_SYMBOL(check_legacy_ioport); |
Kumar Gala | 7e99026 | 2006-05-05 00:02:08 -0500 | [diff] [blame] | 595 | |
| 596 | static int ppc_panic_event(struct notifier_block *this, |
| 597 | unsigned long event, void *ptr) |
| 598 | { |
| 599 | ppc_md.panic(ptr); /* May not return */ |
| 600 | return NOTIFY_DONE; |
| 601 | } |
| 602 | |
| 603 | static struct notifier_block ppc_panic_block = { |
| 604 | .notifier_call = ppc_panic_event, |
| 605 | .priority = INT_MIN /* may not return; must be done last */ |
| 606 | }; |
| 607 | |
| 608 | void __init setup_panic(void) |
| 609 | { |
| 610 | atomic_notifier_chain_register(&panic_notifier_list, &ppc_panic_block); |
| 611 | } |
Dale Farnsworth | 06cce43 | 2007-05-12 10:57:35 +1000 | [diff] [blame] | 612 | |
| 613 | #ifdef CONFIG_CHECK_CACHE_COHERENCY |
| 614 | /* |
| 615 | * For platforms that have configurable cache-coherency. This function |
| 616 | * checks that the cache coherency setting of the kernel matches the setting |
| 617 | * left by the firmware, as indicated in the device tree. Since a mismatch |
| 618 | * will eventually result in DMA failures, we print * and error and call |
| 619 | * BUG() in that case. |
| 620 | */ |
| 621 | |
| 622 | #ifdef CONFIG_NOT_COHERENT_CACHE |
| 623 | #define KERNEL_COHERENCY 0 |
| 624 | #else |
| 625 | #define KERNEL_COHERENCY 1 |
| 626 | #endif |
| 627 | |
| 628 | static int __init check_cache_coherency(void) |
| 629 | { |
| 630 | struct device_node *np; |
| 631 | const void *prop; |
| 632 | int devtree_coherency; |
| 633 | |
| 634 | np = of_find_node_by_path("/"); |
| 635 | prop = of_get_property(np, "coherency-off", NULL); |
| 636 | of_node_put(np); |
| 637 | |
| 638 | devtree_coherency = prop ? 0 : 1; |
| 639 | |
| 640 | if (devtree_coherency != KERNEL_COHERENCY) { |
| 641 | printk(KERN_ERR |
| 642 | "kernel coherency:%s != device tree_coherency:%s\n", |
| 643 | KERNEL_COHERENCY ? "on" : "off", |
| 644 | devtree_coherency ? "on" : "off"); |
| 645 | BUG(); |
| 646 | } |
| 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | late_initcall(check_cache_coherency); |
| 652 | #endif /* CONFIG_CHECK_CACHE_COHERENCY */ |
Michael Ellerman | 94a3807 | 2007-06-20 10:54:19 +1000 | [diff] [blame] | 653 | |
| 654 | #ifdef CONFIG_DEBUG_FS |
| 655 | struct dentry *powerpc_debugfs_root; |
| 656 | |
| 657 | static int powerpc_debugfs_init(void) |
| 658 | { |
| 659 | powerpc_debugfs_root = debugfs_create_dir("powerpc", NULL); |
| 660 | |
| 661 | return powerpc_debugfs_root == NULL; |
| 662 | } |
| 663 | arch_initcall(powerpc_debugfs_init); |
| 664 | #endif |