diff options
Diffstat (limited to 'arch/powerpc/kernel/setup-common.c')
| -rw-r--r-- | arch/powerpc/kernel/setup-common.c | 410 |
1 files changed, 410 insertions, 0 deletions
diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c new file mode 100644 index 000000000000..1292460fcde2 --- /dev/null +++ b/arch/powerpc/kernel/setup-common.c | |||
| @@ -0,0 +1,410 @@ | |||
| 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/ide.h> | ||
| 22 | #include <linux/seq_file.h> | ||
| 23 | #include <linux/ioport.h> | ||
| 24 | #include <linux/console.h> | ||
| 25 | #include <linux/utsname.h> | ||
| 26 | #include <linux/tty.h> | ||
| 27 | #include <linux/root_dev.h> | ||
| 28 | #include <linux/notifier.h> | ||
| 29 | #include <linux/cpu.h> | ||
| 30 | #include <linux/unistd.h> | ||
| 31 | #include <linux/serial.h> | ||
| 32 | #include <linux/serial_8250.h> | ||
| 33 | #include <asm/io.h> | ||
| 34 | #include <asm/prom.h> | ||
| 35 | #include <asm/processor.h> | ||
| 36 | #include <asm/pgtable.h> | ||
| 37 | #include <asm/smp.h> | ||
| 38 | #include <asm/elf.h> | ||
| 39 | #include <asm/machdep.h> | ||
| 40 | #include <asm/time.h> | ||
| 41 | #include <asm/cputable.h> | ||
| 42 | #include <asm/sections.h> | ||
| 43 | #include <asm/btext.h> | ||
| 44 | #include <asm/nvram.h> | ||
| 45 | #include <asm/setup.h> | ||
| 46 | #include <asm/system.h> | ||
| 47 | #include <asm/rtas.h> | ||
| 48 | #include <asm/iommu.h> | ||
| 49 | #include <asm/serial.h> | ||
| 50 | #include <asm/cache.h> | ||
| 51 | #include <asm/page.h> | ||
| 52 | #include <asm/mmu.h> | ||
| 53 | #include <asm/lmb.h> | ||
| 54 | |||
| 55 | #undef DEBUG | ||
| 56 | |||
| 57 | #ifdef DEBUG | ||
| 58 | #define DBG(fmt...) udbg_printf(fmt) | ||
| 59 | #else | ||
| 60 | #define DBG(fmt...) | ||
| 61 | #endif | ||
| 62 | |||
| 63 | /* | ||
| 64 | * This still seems to be needed... -- paulus | ||
| 65 | */ | ||
| 66 | struct screen_info screen_info = { | ||
| 67 | .orig_x = 0, | ||
| 68 | .orig_y = 25, | ||
| 69 | .orig_video_cols = 80, | ||
| 70 | .orig_video_lines = 25, | ||
| 71 | .orig_video_isVGA = 1, | ||
| 72 | .orig_video_points = 16 | ||
| 73 | }; | ||
| 74 | |||
| 75 | #ifdef __DO_IRQ_CANON | ||
| 76 | /* XXX should go elsewhere eventually */ | ||
| 77 | int ppc_do_canonicalize_irqs; | ||
| 78 | EXPORT_SYMBOL(ppc_do_canonicalize_irqs); | ||
| 79 | #endif | ||
| 80 | |||
| 81 | /* also used by kexec */ | ||
| 82 | void machine_shutdown(void) | ||
| 83 | { | ||
| 84 | if (ppc_md.nvram_sync) | ||
| 85 | ppc_md.nvram_sync(); | ||
| 86 | } | ||
| 87 | |||
| 88 | void machine_restart(char *cmd) | ||
| 89 | { | ||
| 90 | machine_shutdown(); | ||
| 91 | ppc_md.restart(cmd); | ||
| 92 | #ifdef CONFIG_SMP | ||
| 93 | smp_send_stop(); | ||
| 94 | #endif | ||
| 95 | printk(KERN_EMERG "System Halted, OK to turn off power\n"); | ||
| 96 | local_irq_disable(); | ||
| 97 | while (1) ; | ||
| 98 | } | ||
| 99 | |||
| 100 | void machine_power_off(void) | ||
| 101 | { | ||
| 102 | machine_shutdown(); | ||
| 103 | ppc_md.power_off(); | ||
| 104 | #ifdef CONFIG_SMP | ||
| 105 | smp_send_stop(); | ||
| 106 | #endif | ||
| 107 | printk(KERN_EMERG "System Halted, OK to turn off power\n"); | ||
| 108 | local_irq_disable(); | ||
| 109 | while (1) ; | ||
| 110 | } | ||
| 111 | /* Used by the G5 thermal driver */ | ||
| 112 | EXPORT_SYMBOL_GPL(machine_power_off); | ||
| 113 | |||
| 114 | void (*pm_power_off)(void) = machine_power_off; | ||
| 115 | EXPORT_SYMBOL_GPL(pm_power_off); | ||
| 116 | |||
| 117 | void machine_halt(void) | ||
| 118 | { | ||
| 119 | machine_shutdown(); | ||
| 120 | ppc_md.halt(); | ||
| 121 | #ifdef CONFIG_SMP | ||
| 122 | smp_send_stop(); | ||
| 123 | #endif | ||
| 124 | printk(KERN_EMERG "System Halted, OK to turn off power\n"); | ||
| 125 | local_irq_disable(); | ||
| 126 | while (1) ; | ||
| 127 | } | ||
| 128 | |||
| 129 | |||
| 130 | #ifdef CONFIG_TAU | ||
| 131 | extern u32 cpu_temp(unsigned long cpu); | ||
| 132 | extern u32 cpu_temp_both(unsigned long cpu); | ||
| 133 | #endif /* CONFIG_TAU */ | ||
| 134 | |||
| 135 | #ifdef CONFIG_SMP | ||
| 136 | DEFINE_PER_CPU(unsigned int, pvr); | ||
| 137 | #endif | ||
| 138 | |||
| 139 | static int show_cpuinfo(struct seq_file *m, void *v) | ||
| 140 | { | ||
| 141 | unsigned long cpu_id = (unsigned long)v - 1; | ||
| 142 | unsigned int pvr; | ||
| 143 | unsigned short maj; | ||
| 144 | unsigned short min; | ||
| 145 | |||
| 146 | if (cpu_id == NR_CPUS) { | ||
| 147 | #if defined(CONFIG_SMP) && defined(CONFIG_PPC32) | ||
| 148 | unsigned long bogosum = 0; | ||
| 149 | int i; | ||
| 150 | for (i = 0; i < NR_CPUS; ++i) | ||
| 151 | if (cpu_online(i)) | ||
| 152 | bogosum += loops_per_jiffy; | ||
| 153 | seq_printf(m, "total bogomips\t: %lu.%02lu\n", | ||
| 154 | bogosum/(500000/HZ), bogosum/(5000/HZ) % 100); | ||
| 155 | #endif /* CONFIG_SMP && CONFIG_PPC32 */ | ||
| 156 | seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq); | ||
| 157 | |||
| 158 | if (ppc_md.show_cpuinfo != NULL) | ||
| 159 | ppc_md.show_cpuinfo(m); | ||
| 160 | |||
| 161 | return 0; | ||
| 162 | } | ||
| 163 | |||
| 164 | /* We only show online cpus: disable preempt (overzealous, I | ||
| 165 | * knew) to prevent cpu going down. */ | ||
| 166 | preempt_disable(); | ||
| 167 | if (!cpu_online(cpu_id)) { | ||
| 168 | preempt_enable(); | ||
| 169 | return 0; | ||
| 170 | } | ||
| 171 | |||
| 172 | #ifdef CONFIG_SMP | ||
| 173 | #ifdef CONFIG_PPC64 /* XXX for now */ | ||
| 174 | pvr = per_cpu(pvr, cpu_id); | ||
| 175 | #else | ||
| 176 | pvr = cpu_data[cpu_id].pvr; | ||
| 177 | #endif | ||
| 178 | #else | ||
| 179 | pvr = mfspr(SPRN_PVR); | ||
| 180 | #endif | ||
| 181 | maj = (pvr >> 8) & 0xFF; | ||
| 182 | min = pvr & 0xFF; | ||
| 183 | |||
| 184 | seq_printf(m, "processor\t: %lu\n", cpu_id); | ||
| 185 | seq_printf(m, "cpu\t\t: "); | ||
| 186 | |||
| 187 | if (cur_cpu_spec->pvr_mask) | ||
| 188 | seq_printf(m, "%s", cur_cpu_spec->cpu_name); | ||
| 189 | else | ||
| 190 | seq_printf(m, "unknown (%08x)", pvr); | ||
| 191 | |||
| 192 | #ifdef CONFIG_ALTIVEC | ||
| 193 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) | ||
| 194 | seq_printf(m, ", altivec supported"); | ||
| 195 | #endif /* CONFIG_ALTIVEC */ | ||
| 196 | |||
| 197 | seq_printf(m, "\n"); | ||
| 198 | |||
| 199 | #ifdef CONFIG_TAU | ||
| 200 | if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) { | ||
| 201 | #ifdef CONFIG_TAU_AVERAGE | ||
| 202 | /* more straightforward, but potentially misleading */ | ||
| 203 | seq_printf(m, "temperature \t: %u C (uncalibrated)\n", | ||
| 204 | cpu_temp(i)); | ||
| 205 | #else | ||
| 206 | /* show the actual temp sensor range */ | ||
| 207 | u32 temp; | ||
| 208 | temp = cpu_temp_both(i); | ||
| 209 | seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n", | ||
| 210 | temp & 0xff, temp >> 16); | ||
| 211 | #endif | ||
| 212 | } | ||
| 213 | #endif /* CONFIG_TAU */ | ||
| 214 | |||
| 215 | /* | ||
| 216 | * Assume here that all clock rates are the same in a | ||
| 217 | * smp system. -- Cort | ||
| 218 | */ | ||
| 219 | if (ppc_proc_freq) | ||
| 220 | seq_printf(m, "clock\t\t: %lu.%06luMHz\n", | ||
| 221 | ppc_proc_freq / 1000000, ppc_proc_freq % 1000000); | ||
| 222 | |||
| 223 | if (ppc_md.show_percpuinfo != NULL) | ||
| 224 | ppc_md.show_percpuinfo(m, cpu_id); | ||
| 225 | |||
| 226 | /* If we are a Freescale core do a simple check so | ||
| 227 | * we dont have to keep adding cases in the future */ | ||
| 228 | if (PVR_VER(pvr) & 0x8000) { | ||
| 229 | maj = PVR_MAJ(pvr); | ||
| 230 | min = PVR_MIN(pvr); | ||
| 231 | } else { | ||
| 232 | switch (PVR_VER(pvr)) { | ||
| 233 | case 0x0020: /* 403 family */ | ||
| 234 | maj = PVR_MAJ(pvr) + 1; | ||
| 235 | min = PVR_MIN(pvr); | ||
| 236 | break; | ||
| 237 | case 0x1008: /* 740P/750P ?? */ | ||
| 238 | maj = ((pvr >> 8) & 0xFF) - 1; | ||
| 239 | min = pvr & 0xFF; | ||
| 240 | break; | ||
| 241 | default: | ||
| 242 | maj = (pvr >> 8) & 0xFF; | ||
| 243 | min = pvr & 0xFF; | ||
| 244 | break; | ||
| 245 | } | ||
| 246 | } | ||
| 247 | |||
| 248 | seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n", | ||
| 249 | maj, min, PVR_VER(pvr), PVR_REV(pvr)); | ||
| 250 | |||
| 251 | #ifdef CONFIG_PPC32 | ||
| 252 | seq_printf(m, "bogomips\t: %lu.%02lu\n", | ||
| 253 | loops_per_jiffy / (500000/HZ), | ||
| 254 | (loops_per_jiffy / (5000/HZ)) % 100); | ||
| 255 | #endif | ||
| 256 | |||
| 257 | #ifdef CONFIG_SMP | ||
| 258 | seq_printf(m, "\n"); | ||
| 259 | #endif | ||
| 260 | |||
| 261 | preempt_enable(); | ||
| 262 | return 0; | ||
| 263 | } | ||
| 264 | |||
| 265 | static void *c_start(struct seq_file *m, loff_t *pos) | ||
| 266 | { | ||
| 267 | unsigned long i = *pos; | ||
| 268 | |||
| 269 | return i <= NR_CPUS ? (void *)(i + 1) : NULL; | ||
| 270 | } | ||
| 271 | |||
| 272 | static void *c_next(struct seq_file *m, void *v, loff_t *pos) | ||
| 273 | { | ||
| 274 | ++*pos; | ||
| 275 | return c_start(m, pos); | ||
| 276 | } | ||
| 277 | |||
| 278 | static void c_stop(struct seq_file *m, void *v) | ||
| 279 | { | ||
| 280 | } | ||
| 281 | |||
| 282 | struct seq_operations cpuinfo_op = { | ||
| 283 | .start =c_start, | ||
| 284 | .next = c_next, | ||
| 285 | .stop = c_stop, | ||
| 286 | .show = show_cpuinfo, | ||
| 287 | }; | ||
| 288 | |||
| 289 | #ifdef CONFIG_PPC_MULTIPLATFORM | ||
| 290 | static int __init set_preferred_console(void) | ||
| 291 | { | ||
| 292 | struct device_node *prom_stdout = NULL; | ||
| 293 | char *name; | ||
| 294 | u32 *spd; | ||
| 295 | int offset = 0; | ||
| 296 | |||
| 297 | DBG(" -> set_preferred_console()\n"); | ||
| 298 | |||
| 299 | /* The user has requested a console so this is already set up. */ | ||
| 300 | if (strstr(saved_command_line, "console=")) { | ||
| 301 | DBG(" console was specified !\n"); | ||
| 302 | return -EBUSY; | ||
| 303 | } | ||
| 304 | |||
| 305 | if (!of_chosen) { | ||
| 306 | DBG(" of_chosen is NULL !\n"); | ||
| 307 | return -ENODEV; | ||
| 308 | } | ||
| 309 | /* We are getting a weird phandle from OF ... */ | ||
| 310 | /* ... So use the full path instead */ | ||
| 311 | name = (char *)get_property(of_chosen, "linux,stdout-path", NULL); | ||
| 312 | if (name == NULL) { | ||
| 313 | DBG(" no linux,stdout-path !\n"); | ||
| 314 | return -ENODEV; | ||
| 315 | } | ||
| 316 | prom_stdout = of_find_node_by_path(name); | ||
| 317 | if (!prom_stdout) { | ||
| 318 | DBG(" can't find stdout package %s !\n", name); | ||
| 319 | return -ENODEV; | ||
| 320 | } | ||
| 321 | DBG("stdout is %s\n", prom_stdout->full_name); | ||
| 322 | |||
| 323 | name = (char *)get_property(prom_stdout, "name", NULL); | ||
| 324 | if (!name) { | ||
| 325 | DBG(" stdout package has no name !\n"); | ||
| 326 | goto not_found; | ||
| 327 | } | ||
| 328 | spd = (u32 *)get_property(prom_stdout, "current-speed", NULL); | ||
| 329 | |||
| 330 | if (0) | ||
| 331 | ; | ||
| 332 | #ifdef CONFIG_SERIAL_8250_CONSOLE | ||
| 333 | else if (strcmp(name, "serial") == 0) { | ||
| 334 | int i; | ||
| 335 | u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i); | ||
| 336 | if (i > 8) { | ||
| 337 | switch (reg[1]) { | ||
| 338 | case 0x3f8: | ||
| 339 | offset = 0; | ||
| 340 | break; | ||
| 341 | case 0x2f8: | ||
| 342 | offset = 1; | ||
| 343 | break; | ||
| 344 | case 0x898: | ||
| 345 | offset = 2; | ||
| 346 | break; | ||
| 347 | case 0x890: | ||
| 348 | offset = 3; | ||
| 349 | break; | ||
| 350 | default: | ||
| 351 | /* We dont recognise the serial port */ | ||
| 352 | goto not_found; | ||
| 353 | } | ||
| 354 | } | ||
| 355 | } | ||
| 356 | #endif /* CONFIG_SERIAL_8250_CONSOLE */ | ||
| 357 | #ifdef CONFIG_PPC_PSERIES | ||
| 358 | else if (strcmp(name, "vty") == 0) { | ||
| 359 | u32 *reg = (u32 *)get_property(prom_stdout, "reg", NULL); | ||
| 360 | char *compat = (char *)get_property(prom_stdout, "compatible", NULL); | ||
| 361 | |||
| 362 | if (reg && compat && (strcmp(compat, "hvterm-protocol") == 0)) { | ||
| 363 | /* Host Virtual Serial Interface */ | ||
| 364 | switch (reg[0]) { | ||
| 365 | case 0x30000000: | ||
| 366 | offset = 0; | ||
| 367 | break; | ||
| 368 | case 0x30000001: | ||
| 369 | offset = 1; | ||
| 370 | break; | ||
| 371 | default: | ||
| 372 | goto not_found; | ||
| 373 | } | ||
| 374 | of_node_put(prom_stdout); | ||
| 375 | DBG("Found hvsi console at offset %d\n", offset); | ||
| 376 | return add_preferred_console("hvsi", offset, NULL); | ||
| 377 | } else { | ||
| 378 | /* pSeries LPAR virtual console */ | ||
| 379 | of_node_put(prom_stdout); | ||
| 380 | DBG("Found hvc console\n"); | ||
| 381 | return add_preferred_console("hvc", 0, NULL); | ||
| 382 | } | ||
| 383 | } | ||
| 384 | #endif /* CONFIG_PPC_PSERIES */ | ||
| 385 | #ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE | ||
| 386 | else if (strcmp(name, "ch-a") == 0) | ||
| 387 | offset = 0; | ||
| 388 | else if (strcmp(name, "ch-b") == 0) | ||
| 389 | offset = 1; | ||
| 390 | #endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */ | ||
| 391 | else | ||
| 392 | goto not_found; | ||
| 393 | of_node_put(prom_stdout); | ||
| 394 | |||
| 395 | DBG("Found serial console at ttyS%d\n", offset); | ||
| 396 | |||
| 397 | if (spd) { | ||
| 398 | static char __initdata opt[16]; | ||
| 399 | sprintf(opt, "%d", *spd); | ||
| 400 | return add_preferred_console("ttyS", offset, opt); | ||
| 401 | } else | ||
| 402 | return add_preferred_console("ttyS", offset, NULL); | ||
| 403 | |||
| 404 | not_found: | ||
| 405 | DBG("No preferred console found !\n"); | ||
| 406 | of_node_put(prom_stdout); | ||
| 407 | return -ENODEV; | ||
| 408 | } | ||
| 409 | console_initcall(set_preferred_console); | ||
| 410 | #endif /* CONFIG_PPC_MULTIPLATFORM */ | ||
