Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Common prep/pmac/chrp boot and setup code. |
| 3 | */ |
| 4 | |
| 5 | #include <linux/config.h> |
| 6 | #include <linux/module.h> |
| 7 | #include <linux/string.h> |
| 8 | #include <linux/sched.h> |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/reboot.h> |
| 12 | #include <linux/delay.h> |
| 13 | #include <linux/initrd.h> |
| 14 | #include <linux/ide.h> |
| 15 | #include <linux/tty.h> |
| 16 | #include <linux/bootmem.h> |
| 17 | #include <linux/seq_file.h> |
| 18 | #include <linux/root_dev.h> |
| 19 | #include <linux/cpu.h> |
| 20 | #include <linux/console.h> |
| 21 | |
| 22 | #include <asm/residual.h> |
| 23 | #include <asm/io.h> |
| 24 | #include <asm/prom.h> |
| 25 | #include <asm/processor.h> |
| 26 | #include <asm/pgtable.h> |
| 27 | #include <asm/bootinfo.h> |
| 28 | #include <asm/setup.h> |
| 29 | #include <asm/amigappc.h> |
| 30 | #include <asm/smp.h> |
| 31 | #include <asm/elf.h> |
| 32 | #include <asm/cputable.h> |
| 33 | #include <asm/bootx.h> |
| 34 | #include <asm/btext.h> |
| 35 | #include <asm/machdep.h> |
| 36 | #include <asm/uaccess.h> |
| 37 | #include <asm/system.h> |
| 38 | #include <asm/pmac_feature.h> |
| 39 | #include <asm/sections.h> |
| 40 | #include <asm/nvram.h> |
| 41 | #include <asm/xmon.h> |
| 42 | #include <asm/ocp.h> |
| 43 | |
Kumar Gala | 8e8fff0 | 2005-09-03 15:55:34 -0700 | [diff] [blame] | 44 | #define USES_PPC_SYS (defined(CONFIG_85xx) || defined(CONFIG_83xx) || \ |
| 45 | defined(CONFIG_MPC10X_BRIDGE) || defined(CONFIG_8260) || \ |
| 46 | defined(CONFIG_PPC_MPC52xx)) |
| 47 | |
| 48 | #if USES_PPC_SYS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <asm/ppc_sys.h> |
| 50 | #endif |
| 51 | |
| 52 | #if defined CONFIG_KGDB |
| 53 | #include <asm/kgdb.h> |
| 54 | #endif |
| 55 | |
| 56 | extern void platform_init(unsigned long r3, unsigned long r4, |
| 57 | unsigned long r5, unsigned long r6, unsigned long r7); |
| 58 | extern void bootx_init(unsigned long r4, unsigned long phys); |
| 59 | extern void identify_cpu(unsigned long offset, unsigned long cpu); |
| 60 | extern void do_cpu_ftr_fixups(unsigned long offset); |
| 61 | extern void reloc_got2(unsigned long offset); |
| 62 | |
| 63 | extern void ppc6xx_idle(void); |
| 64 | extern void power4_idle(void); |
| 65 | |
| 66 | extern boot_infos_t *boot_infos; |
| 67 | struct ide_machdep_calls ppc_ide_md; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | /* Used with the BI_MEMSIZE bootinfo parameter to store the memory |
| 70 | size value reported by the boot loader. */ |
| 71 | unsigned long boot_mem_size; |
| 72 | |
| 73 | unsigned long ISA_DMA_THRESHOLD; |
Jon Loeliger | b8f114d | 2005-09-21 14:54:51 -0500 | [diff] [blame] | 74 | unsigned int DMA_MODE_READ; |
| 75 | unsigned int DMA_MODE_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | #ifdef CONFIG_PPC_MULTIPLATFORM |
| 78 | int _machine = 0; |
| 79 | |
| 80 | extern void prep_init(unsigned long r3, unsigned long r4, |
| 81 | unsigned long r5, unsigned long r6, unsigned long r7); |
| 82 | extern void pmac_init(unsigned long r3, unsigned long r4, |
| 83 | unsigned long r5, unsigned long r6, unsigned long r7); |
| 84 | extern void chrp_init(unsigned long r3, unsigned long r4, |
| 85 | unsigned long r5, unsigned long r6, unsigned long r7); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 86 | |
| 87 | dev_t boot_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #endif /* CONFIG_PPC_MULTIPLATFORM */ |
| 89 | |
Paul Mackerras | fd582ec | 2005-10-11 22:08:12 +1000 | [diff] [blame^] | 90 | int have_of; |
| 91 | EXPORT_SYMBOL(have_of); |
| 92 | |
Paul Mackerras | 35d81a4 | 2005-10-11 22:03:09 +1000 | [diff] [blame] | 93 | #ifdef __DO_IRQ_CANON |
| 94 | int ppc_do_canonicalize_irqs; |
| 95 | EXPORT_SYMBOL(ppc_do_canonicalize_irqs); |
| 96 | #endif |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | #ifdef CONFIG_MAGIC_SYSRQ |
| 99 | unsigned long SYSRQ_KEY = 0x54; |
| 100 | #endif /* CONFIG_MAGIC_SYSRQ */ |
| 101 | |
| 102 | #ifdef CONFIG_VGA_CONSOLE |
| 103 | unsigned long vgacon_remap_base; |
| 104 | #endif |
| 105 | |
| 106 | struct machdep_calls ppc_md; |
| 107 | |
| 108 | /* |
| 109 | * These are used in binfmt_elf.c to put aux entries on the stack |
| 110 | * for each elf executable being started. |
| 111 | */ |
| 112 | int dcache_bsize; |
| 113 | int icache_bsize; |
| 114 | int ucache_bsize; |
| 115 | |
| 116 | #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \ |
| 117 | defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA) |
| 118 | struct screen_info screen_info = { |
| 119 | 0, 25, /* orig-x, orig-y */ |
| 120 | 0, /* unused */ |
| 121 | 0, /* orig-video-page */ |
| 122 | 0, /* orig-video-mode */ |
| 123 | 80, /* orig-video-cols */ |
| 124 | 0,0,0, /* ega_ax, ega_bx, ega_cx */ |
| 125 | 25, /* orig-video-lines */ |
| 126 | 1, /* orig-video-isVGA */ |
| 127 | 16 /* orig-video-points */ |
| 128 | }; |
| 129 | #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */ |
| 130 | |
| 131 | void machine_restart(char *cmd) |
| 132 | { |
| 133 | #ifdef CONFIG_NVRAM |
| 134 | nvram_sync(); |
| 135 | #endif |
| 136 | ppc_md.restart(cmd); |
| 137 | } |
| 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | void machine_power_off(void) |
| 140 | { |
| 141 | #ifdef CONFIG_NVRAM |
| 142 | nvram_sync(); |
| 143 | #endif |
| 144 | ppc_md.power_off(); |
| 145 | } |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | void machine_halt(void) |
| 148 | { |
| 149 | #ifdef CONFIG_NVRAM |
| 150 | nvram_sync(); |
| 151 | #endif |
| 152 | ppc_md.halt(); |
| 153 | } |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | void (*pm_power_off)(void) = machine_power_off; |
| 156 | |
| 157 | #ifdef CONFIG_TAU |
| 158 | extern u32 cpu_temp(unsigned long cpu); |
| 159 | extern u32 cpu_temp_both(unsigned long cpu); |
| 160 | #endif /* CONFIG_TAU */ |
| 161 | |
| 162 | int show_cpuinfo(struct seq_file *m, void *v) |
| 163 | { |
| 164 | int i = (int) v - 1; |
| 165 | int err = 0; |
| 166 | unsigned int pvr; |
| 167 | unsigned short maj, min; |
| 168 | unsigned long lpj; |
| 169 | |
| 170 | if (i >= NR_CPUS) { |
| 171 | /* Show summary information */ |
| 172 | #ifdef CONFIG_SMP |
| 173 | unsigned long bogosum = 0; |
| 174 | for (i = 0; i < NR_CPUS; ++i) |
| 175 | if (cpu_online(i)) |
| 176 | bogosum += cpu_data[i].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 */ |
| 180 | |
| 181 | if (ppc_md.show_cpuinfo != NULL) |
| 182 | err = ppc_md.show_cpuinfo(m); |
| 183 | return err; |
| 184 | } |
| 185 | |
| 186 | #ifdef CONFIG_SMP |
| 187 | if (!cpu_online(i)) |
| 188 | return 0; |
| 189 | pvr = cpu_data[i].pvr; |
| 190 | lpj = cpu_data[i].loops_per_jiffy; |
| 191 | #else |
| 192 | pvr = mfspr(SPRN_PVR); |
| 193 | lpj = loops_per_jiffy; |
| 194 | #endif |
| 195 | |
| 196 | seq_printf(m, "processor\t: %d\n", i); |
| 197 | seq_printf(m, "cpu\t\t: "); |
| 198 | |
Kumar Gala | 400d221 | 2005-09-27 15:13:12 -0500 | [diff] [blame] | 199 | if (cur_cpu_spec->pvr_mask) |
| 200 | seq_printf(m, "%s", cur_cpu_spec->cpu_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | else |
| 202 | seq_printf(m, "unknown (%08x)", pvr); |
| 203 | #ifdef CONFIG_ALTIVEC |
Kumar Gala | 400d221 | 2005-09-27 15:13:12 -0500 | [diff] [blame] | 204 | if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | seq_printf(m, ", altivec supported"); |
| 206 | #endif |
| 207 | seq_printf(m, "\n"); |
| 208 | |
| 209 | #ifdef CONFIG_TAU |
Kumar Gala | 400d221 | 2005-09-27 15:13:12 -0500 | [diff] [blame] | 210 | if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | #ifdef CONFIG_TAU_AVERAGE |
| 212 | /* more straightforward, but potentially misleading */ |
| 213 | seq_printf(m, "temperature \t: %u C (uncalibrated)\n", |
| 214 | cpu_temp(i)); |
| 215 | #else |
| 216 | /* show the actual temp sensor range */ |
| 217 | u32 temp; |
| 218 | temp = cpu_temp_both(i); |
| 219 | seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n", |
| 220 | temp & 0xff, temp >> 16); |
| 221 | #endif |
| 222 | } |
| 223 | #endif /* CONFIG_TAU */ |
| 224 | |
| 225 | if (ppc_md.show_percpuinfo != NULL) { |
| 226 | err = ppc_md.show_percpuinfo(m, i); |
| 227 | if (err) |
| 228 | return err; |
| 229 | } |
| 230 | |
Kumar Gala | 696c2b9 | 2005-05-05 16:15:10 -0700 | [diff] [blame] | 231 | /* If we are a Freescale core do a simple check so |
| 232 | * we dont have to keep adding cases in the future */ |
| 233 | if ((PVR_VER(pvr) & 0x8000) == 0x8000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | maj = PVR_MAJ(pvr); |
| 235 | min = PVR_MIN(pvr); |
Kumar Gala | 696c2b9 | 2005-05-05 16:15:10 -0700 | [diff] [blame] | 236 | } else { |
| 237 | switch (PVR_VER(pvr)) { |
| 238 | case 0x0020: /* 403 family */ |
| 239 | maj = PVR_MAJ(pvr) + 1; |
| 240 | min = PVR_MIN(pvr); |
| 241 | break; |
| 242 | case 0x1008: /* 740P/750P ?? */ |
| 243 | maj = ((pvr >> 8) & 0xFF) - 1; |
| 244 | min = pvr & 0xFF; |
| 245 | break; |
| 246 | default: |
| 247 | maj = (pvr >> 8) & 0xFF; |
| 248 | min = pvr & 0xFF; |
| 249 | break; |
| 250 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n", |
| 254 | maj, min, PVR_VER(pvr), PVR_REV(pvr)); |
| 255 | |
| 256 | seq_printf(m, "bogomips\t: %lu.%02lu\n", |
| 257 | lpj / (500000/HZ), (lpj / (5000/HZ)) % 100); |
| 258 | |
Kumar Gala | 8e8fff0 | 2005-09-03 15:55:34 -0700 | [diff] [blame] | 259 | #if USES_PPC_SYS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if (cur_ppc_sys_spec->ppc_sys_name) |
| 261 | seq_printf(m, "chipset\t\t: %s\n", |
| 262 | cur_ppc_sys_spec->ppc_sys_name); |
| 263 | #endif |
| 264 | |
| 265 | #ifdef CONFIG_SMP |
| 266 | seq_printf(m, "\n"); |
| 267 | #endif |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | static void *c_start(struct seq_file *m, loff_t *pos) |
| 273 | { |
| 274 | int i = *pos; |
| 275 | |
| 276 | return i <= NR_CPUS? (void *) (i + 1): NULL; |
| 277 | } |
| 278 | |
| 279 | static void *c_next(struct seq_file *m, void *v, loff_t *pos) |
| 280 | { |
| 281 | ++*pos; |
| 282 | return c_start(m, pos); |
| 283 | } |
| 284 | |
| 285 | static void c_stop(struct seq_file *m, void *v) |
| 286 | { |
| 287 | } |
| 288 | |
| 289 | struct seq_operations cpuinfo_op = { |
| 290 | .start =c_start, |
| 291 | .next = c_next, |
| 292 | .stop = c_stop, |
| 293 | .show = show_cpuinfo, |
| 294 | }; |
| 295 | |
| 296 | /* |
| 297 | * We're called here very early in the boot. We determine the machine |
| 298 | * type and call the appropriate low-level setup functions. |
| 299 | * -- Cort <cort@fsmlabs.com> |
| 300 | * |
| 301 | * Note that the kernel may be running at an address which is different |
| 302 | * from the address that it was linked at, so we must use RELOC/PTRRELOC |
| 303 | * to access static data (including strings). -- paulus |
| 304 | */ |
| 305 | __init |
| 306 | unsigned long |
| 307 | early_init(int r3, int r4, int r5) |
| 308 | { |
| 309 | unsigned long phys; |
| 310 | unsigned long offset = reloc_offset(); |
| 311 | |
| 312 | /* Default */ |
| 313 | phys = offset + KERNELBASE; |
| 314 | |
| 315 | /* First zero the BSS -- use memset, some arches don't have |
| 316 | * caches on yet */ |
| 317 | memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start); |
| 318 | |
| 319 | /* |
| 320 | * Identify the CPU type and fix up code sections |
| 321 | * that depend on which cpu we have. |
| 322 | */ |
| 323 | identify_cpu(offset, 0); |
| 324 | do_cpu_ftr_fixups(offset); |
| 325 | |
| 326 | #if defined(CONFIG_PPC_MULTIPLATFORM) |
| 327 | reloc_got2(offset); |
| 328 | |
| 329 | /* If we came here from BootX, clear the screen, |
| 330 | * set up some pointers and return. */ |
| 331 | if ((r3 == 0x426f6f58) && (r5 == 0)) |
| 332 | bootx_init(r4, phys); |
| 333 | |
| 334 | /* |
| 335 | * don't do anything on prep |
| 336 | * for now, don't use bootinfo because it breaks yaboot 0.5 |
| 337 | * and assume that if we didn't find a magic number, we have OF |
| 338 | */ |
| 339 | else if (*(unsigned long *)(0) != 0xdeadc0de) |
| 340 | phys = prom_init(r3, r4, (prom_entry)r5); |
| 341 | |
| 342 | reloc_got2(-offset); |
| 343 | #endif |
| 344 | |
| 345 | return phys; |
| 346 | } |
| 347 | |
| 348 | #ifdef CONFIG_PPC_OF |
| 349 | /* |
| 350 | * Assume here that all clock rates are the same in a |
| 351 | * smp system. -- Cort |
| 352 | */ |
Jon Loeliger | f495a8b | 2005-09-17 10:35:08 -0500 | [diff] [blame] | 353 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | of_show_percpuinfo(struct seq_file *m, int i) |
| 355 | { |
| 356 | struct device_node *cpu_node; |
| 357 | u32 *fp; |
| 358 | int s; |
| 359 | |
| 360 | cpu_node = find_type_devices("cpu"); |
| 361 | if (!cpu_node) |
| 362 | return 0; |
| 363 | for (s = 0; s < i && cpu_node->next; s++) |
| 364 | cpu_node = cpu_node->next; |
| 365 | fp = (u32 *)get_property(cpu_node, "clock-frequency", NULL); |
| 366 | if (fp) |
| 367 | seq_printf(m, "clock\t\t: %dMHz\n", *fp / 1000000); |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | void __init |
| 372 | intuit_machine_type(void) |
| 373 | { |
| 374 | char *model; |
| 375 | struct device_node *root; |
| 376 | |
| 377 | /* ask the OF info if we're a chrp or pmac */ |
| 378 | root = find_path_device("/"); |
| 379 | if (root != 0) { |
| 380 | /* assume pmac unless proven to be chrp -- Cort */ |
| 381 | _machine = _MACH_Pmac; |
| 382 | model = get_property(root, "device_type", NULL); |
| 383 | if (model && !strncmp("chrp", model, 4)) |
| 384 | _machine = _MACH_chrp; |
| 385 | else { |
| 386 | model = get_property(root, "model", NULL); |
| 387 | if (model && !strncmp(model, "IBM", 3)) |
| 388 | _machine = _MACH_chrp; |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | #endif |
| 393 | |
| 394 | #ifdef CONFIG_PPC_MULTIPLATFORM |
| 395 | /* |
| 396 | * The PPC_MULTIPLATFORM version of platform_init... |
| 397 | */ |
| 398 | void __init |
| 399 | platform_init(unsigned long r3, unsigned long r4, unsigned long r5, |
| 400 | unsigned long r6, unsigned long r7) |
| 401 | { |
| 402 | #ifdef CONFIG_BOOTX_TEXT |
| 403 | if (boot_text_mapped) { |
| 404 | btext_clearscreen(); |
| 405 | btext_welcome(); |
| 406 | } |
| 407 | #endif |
| 408 | |
| 409 | parse_bootinfo(find_bootinfo()); |
| 410 | |
| 411 | /* if we didn't get any bootinfo telling us what we are... */ |
| 412 | if (_machine == 0) { |
| 413 | /* prep boot loader tells us if we're prep or not */ |
| 414 | if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) ) |
| 415 | _machine = _MACH_prep; |
| 416 | } |
| 417 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 418 | #ifdef CONFIG_PPC_PREP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | /* not much more to do here, if prep */ |
| 420 | if (_machine == _MACH_prep) { |
| 421 | prep_init(r3, r4, r5, r6, r7); |
| 422 | return; |
| 423 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 424 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
Paul Mackerras | fd582ec | 2005-10-11 22:08:12 +1000 | [diff] [blame^] | 426 | have_of = 1; |
| 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | /* prom_init has already been called from __start */ |
| 429 | if (boot_infos) |
| 430 | relocate_nodes(); |
| 431 | |
| 432 | /* If we aren't PReP, we can find out if we're Pmac |
| 433 | * or CHRP with this. */ |
| 434 | if (_machine == 0) |
| 435 | intuit_machine_type(); |
| 436 | |
| 437 | /* finish_device_tree may need _machine defined. */ |
| 438 | finish_device_tree(); |
| 439 | |
| 440 | /* |
| 441 | * If we were booted via quik, r3 points to the physical |
| 442 | * address of the command-line parameters. |
| 443 | * If we were booted from an xcoff image (i.e. netbooted or |
| 444 | * booted from floppy), we get the command line from the |
| 445 | * bootargs property of the /chosen node. |
| 446 | * If an initial ramdisk is present, r3 and r4 |
| 447 | * are used for initrd_start and initrd_size, |
| 448 | * otherwise they contain 0xdeadbeef. |
| 449 | */ |
| 450 | if (r3 >= 0x4000 && r3 < 0x800000 && r4 == 0) { |
| 451 | strlcpy(cmd_line, (char *)r3 + KERNELBASE, |
| 452 | sizeof(cmd_line)); |
| 453 | } else if (boot_infos != 0) { |
| 454 | /* booted by BootX - check for ramdisk */ |
| 455 | if (boot_infos->kernelParamsOffset != 0) |
| 456 | strlcpy(cmd_line, (char *) boot_infos |
| 457 | + boot_infos->kernelParamsOffset, |
| 458 | sizeof(cmd_line)); |
| 459 | #ifdef CONFIG_BLK_DEV_INITRD |
| 460 | if (boot_infos->ramDisk) { |
| 461 | initrd_start = (unsigned long) boot_infos |
| 462 | + boot_infos->ramDisk; |
| 463 | initrd_end = initrd_start + boot_infos->ramDiskSize; |
| 464 | initrd_below_start_ok = 1; |
| 465 | } |
| 466 | #endif |
| 467 | } else { |
| 468 | struct device_node *chosen; |
| 469 | char *p; |
| 470 | |
| 471 | #ifdef CONFIG_BLK_DEV_INITRD |
| 472 | if (r3 && r4 && r4 != 0xdeadbeef) { |
| 473 | if (r3 < KERNELBASE) |
| 474 | r3 += KERNELBASE; |
| 475 | initrd_start = r3; |
| 476 | initrd_end = r3 + r4; |
| 477 | ROOT_DEV = Root_RAM0; |
| 478 | initrd_below_start_ok = 1; |
| 479 | } |
| 480 | #endif |
| 481 | chosen = find_devices("chosen"); |
| 482 | if (chosen != NULL) { |
| 483 | p = get_property(chosen, "bootargs", NULL); |
| 484 | if (p && *p) { |
| 485 | strlcpy(cmd_line, p, sizeof(cmd_line)); |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | #ifdef CONFIG_ADB |
| 490 | if (strstr(cmd_line, "adb_sync")) { |
| 491 | extern int __adb_probe_sync; |
| 492 | __adb_probe_sync = 1; |
| 493 | } |
| 494 | #endif /* CONFIG_ADB */ |
| 495 | |
| 496 | switch (_machine) { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 497 | #ifdef CONFIG_PPC_PMAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | case _MACH_Pmac: |
| 499 | pmac_init(r3, r4, r5, r6, r7); |
| 500 | break; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 501 | #endif |
| 502 | #ifdef CONFIG_PPC_CHRP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | case _MACH_chrp: |
| 504 | chrp_init(r3, r4, r5, r6, r7); |
| 505 | break; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 506 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } |
| 508 | } |
| 509 | |
| 510 | #ifdef CONFIG_SERIAL_CORE_CONSOLE |
| 511 | extern char *of_stdout_device; |
| 512 | |
| 513 | static int __init set_preferred_console(void) |
| 514 | { |
| 515 | struct device_node *prom_stdout; |
| 516 | char *name; |
Paul Mackerras | 45fed46 | 2005-05-20 16:45:58 +1000 | [diff] [blame] | 517 | int offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
| 519 | if (of_stdout_device == NULL) |
| 520 | return -ENODEV; |
| 521 | |
| 522 | /* The user has requested a console so this is already set up. */ |
| 523 | if (strstr(saved_command_line, "console=")) |
| 524 | return -EBUSY; |
| 525 | |
| 526 | prom_stdout = find_path_device(of_stdout_device); |
| 527 | if (!prom_stdout) |
| 528 | return -ENODEV; |
| 529 | |
| 530 | name = (char *)get_property(prom_stdout, "name", NULL); |
| 531 | if (!name) |
| 532 | return -ENODEV; |
| 533 | |
| 534 | if (strcmp(name, "serial") == 0) { |
| 535 | int i; |
| 536 | u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i); |
| 537 | if (i > 8) { |
| 538 | switch (reg[1]) { |
| 539 | case 0x3f8: |
| 540 | offset = 0; |
| 541 | break; |
| 542 | case 0x2f8: |
| 543 | offset = 1; |
| 544 | break; |
| 545 | case 0x898: |
| 546 | offset = 2; |
| 547 | break; |
| 548 | case 0x890: |
| 549 | offset = 3; |
| 550 | break; |
| 551 | default: |
| 552 | /* We dont recognise the serial port */ |
| 553 | return -ENODEV; |
| 554 | } |
| 555 | } |
| 556 | } else if (strcmp(name, "ch-a") == 0) |
| 557 | offset = 0; |
| 558 | else if (strcmp(name, "ch-b") == 0) |
| 559 | offset = 1; |
| 560 | else |
| 561 | return -ENODEV; |
| 562 | return add_preferred_console("ttyS", offset, NULL); |
| 563 | } |
| 564 | console_initcall(set_preferred_console); |
| 565 | #endif /* CONFIG_SERIAL_CORE_CONSOLE */ |
| 566 | #endif /* CONFIG_PPC_MULTIPLATFORM */ |
| 567 | |
| 568 | struct bi_record *find_bootinfo(void) |
| 569 | { |
| 570 | struct bi_record *rec; |
| 571 | |
| 572 | rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20)); |
| 573 | if ( rec->tag != BI_FIRST ) { |
| 574 | /* |
| 575 | * This 0x10000 offset is a terrible hack but it will go away when |
| 576 | * we have the bootloader handle all the relocation and |
| 577 | * prom calls -- Cort |
| 578 | */ |
| 579 | rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20)); |
| 580 | if ( rec->tag != BI_FIRST ) |
| 581 | return NULL; |
| 582 | } |
| 583 | return rec; |
| 584 | } |
| 585 | |
| 586 | void parse_bootinfo(struct bi_record *rec) |
| 587 | { |
| 588 | if (rec == NULL || rec->tag != BI_FIRST) |
| 589 | return; |
| 590 | while (rec->tag != BI_LAST) { |
| 591 | ulong *data = rec->data; |
| 592 | switch (rec->tag) { |
| 593 | case BI_CMD_LINE: |
| 594 | strlcpy(cmd_line, (void *)data, sizeof(cmd_line)); |
| 595 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | #ifdef CONFIG_BLK_DEV_INITRD |
| 597 | case BI_INITRD: |
| 598 | initrd_start = data[0] + KERNELBASE; |
| 599 | initrd_end = data[0] + data[1] + KERNELBASE; |
| 600 | break; |
| 601 | #endif /* CONFIG_BLK_DEV_INITRD */ |
| 602 | #ifdef CONFIG_PPC_MULTIPLATFORM |
| 603 | case BI_MACHTYPE: |
| 604 | _machine = data[0]; |
| 605 | break; |
| 606 | #endif |
| 607 | case BI_MEMSIZE: |
| 608 | boot_mem_size = data[0]; |
| 609 | break; |
| 610 | } |
| 611 | rec = (struct bi_record *)((ulong)rec + rec->size); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | /* |
| 616 | * Find out what kind of machine we're on and save any data we need |
| 617 | * from the early boot process (devtree is copied on pmac by prom_init()). |
| 618 | * This is called very early on the boot process, after a minimal |
| 619 | * MMU environment has been set up but before MMU_init is called. |
| 620 | */ |
| 621 | void __init |
| 622 | machine_init(unsigned long r3, unsigned long r4, unsigned long r5, |
| 623 | unsigned long r6, unsigned long r7) |
| 624 | { |
| 625 | #ifdef CONFIG_CMDLINE |
| 626 | strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line)); |
| 627 | #endif /* CONFIG_CMDLINE */ |
| 628 | |
| 629 | #ifdef CONFIG_6xx |
| 630 | ppc_md.power_save = ppc6xx_idle; |
| 631 | #endif |
| 632 | #ifdef CONFIG_POWER4 |
| 633 | ppc_md.power_save = power4_idle; |
| 634 | #endif |
| 635 | |
| 636 | platform_init(r3, r4, r5, r6, r7); |
| 637 | |
| 638 | if (ppc_md.progress) |
| 639 | ppc_md.progress("id mach(): done", 0x200); |
| 640 | } |
Kumar Gala | a2f40cc | 2005-09-03 15:55:33 -0700 | [diff] [blame] | 641 | #ifdef CONFIG_BOOKE_WDT |
| 642 | /* Checks wdt=x and wdt_period=xx command-line option */ |
| 643 | int __init early_parse_wdt(char *p) |
| 644 | { |
Kumar Gala | a2f40cc | 2005-09-03 15:55:33 -0700 | [diff] [blame] | 645 | if (p && strncmp(p, "0", 1) != 0) |
Kumar Gala | 39cdc4b | 2005-09-03 15:55:39 -0700 | [diff] [blame] | 646 | booke_wdt_enabled = 1; |
Kumar Gala | a2f40cc | 2005-09-03 15:55:33 -0700 | [diff] [blame] | 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | early_param("wdt", early_parse_wdt); |
| 651 | |
| 652 | int __init early_parse_wdt_period (char *p) |
| 653 | { |
Kumar Gala | a2f40cc | 2005-09-03 15:55:33 -0700 | [diff] [blame] | 654 | if (p) |
Kumar Gala | 39cdc4b | 2005-09-03 15:55:39 -0700 | [diff] [blame] | 655 | booke_wdt_period = simple_strtoul(p, NULL, 0); |
Kumar Gala | a2f40cc | 2005-09-03 15:55:33 -0700 | [diff] [blame] | 656 | |
| 657 | return 0; |
| 658 | } |
| 659 | early_param("wdt_period", early_parse_wdt_period); |
| 660 | #endif /* CONFIG_BOOKE_WDT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | |
| 662 | /* Checks "l2cr=xxxx" command-line option */ |
| 663 | int __init ppc_setup_l2cr(char *str) |
| 664 | { |
| 665 | if (cpu_has_feature(CPU_FTR_L2CR)) { |
| 666 | unsigned long val = simple_strtoul(str, NULL, 0); |
| 667 | printk(KERN_INFO "l2cr set to %lx\n", val); |
| 668 | _set_L2CR(0); /* force invalidate by disable cache */ |
| 669 | _set_L2CR(val); /* and enable it */ |
| 670 | } |
| 671 | return 1; |
| 672 | } |
| 673 | __setup("l2cr=", ppc_setup_l2cr); |
| 674 | |
| 675 | #ifdef CONFIG_GENERIC_NVRAM |
| 676 | |
| 677 | /* Generic nvram hooks used by drivers/char/gen_nvram.c */ |
| 678 | unsigned char nvram_read_byte(int addr) |
| 679 | { |
| 680 | if (ppc_md.nvram_read_val) |
| 681 | return ppc_md.nvram_read_val(addr); |
| 682 | return 0xff; |
| 683 | } |
| 684 | EXPORT_SYMBOL(nvram_read_byte); |
| 685 | |
| 686 | void nvram_write_byte(unsigned char val, int addr) |
| 687 | { |
| 688 | if (ppc_md.nvram_write_val) |
| 689 | ppc_md.nvram_write_val(addr, val); |
| 690 | } |
| 691 | EXPORT_SYMBOL(nvram_write_byte); |
| 692 | |
| 693 | void nvram_sync(void) |
| 694 | { |
| 695 | if (ppc_md.nvram_sync) |
| 696 | ppc_md.nvram_sync(); |
| 697 | } |
| 698 | EXPORT_SYMBOL(nvram_sync); |
| 699 | |
| 700 | #endif /* CONFIG_NVRAM */ |
| 701 | |
| 702 | static struct cpu cpu_devices[NR_CPUS]; |
| 703 | |
| 704 | int __init ppc_init(void) |
| 705 | { |
| 706 | int i; |
| 707 | |
| 708 | /* clear the progress line */ |
| 709 | if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff); |
| 710 | |
| 711 | /* register CPU devices */ |
| 712 | for (i = 0; i < NR_CPUS; i++) |
| 713 | if (cpu_possible(i)) |
| 714 | register_cpu(&cpu_devices[i], i, NULL); |
| 715 | |
| 716 | /* call platform init */ |
| 717 | if (ppc_md.init != NULL) { |
| 718 | ppc_md.init(); |
| 719 | } |
| 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | arch_initcall(ppc_init); |
| 724 | |
| 725 | /* Warning, IO base is not yet inited */ |
| 726 | void __init setup_arch(char **cmdline_p) |
| 727 | { |
| 728 | extern char *klimit; |
| 729 | extern void do_init_bootmem(void); |
| 730 | |
| 731 | /* so udelay does something sensible, assume <= 1000 bogomips */ |
| 732 | loops_per_jiffy = 500000000 / HZ; |
| 733 | |
| 734 | #ifdef CONFIG_PPC_MULTIPLATFORM |
| 735 | /* This could be called "early setup arch", it must be done |
| 736 | * now because xmon need it |
| 737 | */ |
| 738 | if (_machine == _MACH_Pmac) |
| 739 | pmac_feature_init(); /* New cool way */ |
| 740 | #endif |
| 741 | |
| 742 | #ifdef CONFIG_XMON |
Paul Mackerras | fd582ec | 2005-10-11 22:08:12 +1000 | [diff] [blame^] | 743 | xmon_init(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | if (strstr(cmd_line, "xmon")) |
| 745 | xmon(NULL); |
| 746 | #endif /* CONFIG_XMON */ |
| 747 | if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab); |
| 748 | |
| 749 | #if defined(CONFIG_KGDB) |
| 750 | if (ppc_md.kgdb_map_scc) |
| 751 | ppc_md.kgdb_map_scc(); |
| 752 | set_debug_traps(); |
| 753 | if (strstr(cmd_line, "gdb")) { |
| 754 | if (ppc_md.progress) |
| 755 | ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000); |
| 756 | printk("kgdb breakpoint activated\n"); |
| 757 | breakpoint(); |
| 758 | } |
| 759 | #endif |
| 760 | |
| 761 | /* |
| 762 | * Set cache line size based on type of cpu as a default. |
| 763 | * Systems with OF can look in the properties on the cpu node(s) |
| 764 | * for a possibly more accurate value. |
| 765 | */ |
| 766 | if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) { |
Kumar Gala | 400d221 | 2005-09-27 15:13:12 -0500 | [diff] [blame] | 767 | dcache_bsize = cur_cpu_spec->dcache_bsize; |
| 768 | icache_bsize = cur_cpu_spec->icache_bsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | ucache_bsize = 0; |
| 770 | } else |
| 771 | ucache_bsize = dcache_bsize = icache_bsize |
Kumar Gala | 400d221 | 2005-09-27 15:13:12 -0500 | [diff] [blame] | 772 | = cur_cpu_spec->dcache_bsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
| 774 | /* reboot on panic */ |
| 775 | panic_timeout = 180; |
| 776 | |
| 777 | init_mm.start_code = PAGE_OFFSET; |
| 778 | init_mm.end_code = (unsigned long) _etext; |
| 779 | init_mm.end_data = (unsigned long) _edata; |
| 780 | init_mm.brk = (unsigned long) klimit; |
| 781 | |
| 782 | /* Save unparsed command line copy for /proc/cmdline */ |
| 783 | strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE); |
| 784 | *cmdline_p = cmd_line; |
| 785 | |
Paul Mackerras | 19bbdf0 | 2005-05-17 16:48:39 +1000 | [diff] [blame] | 786 | parse_early_param(); |
| 787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | /* set up the bootmem stuff with available memory */ |
| 789 | do_init_bootmem(); |
| 790 | if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab); |
| 791 | |
| 792 | #ifdef CONFIG_PPC_OCP |
| 793 | /* Initialize OCP device list */ |
| 794 | ocp_early_init(); |
| 795 | if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab); |
| 796 | #endif |
| 797 | |
| 798 | #ifdef CONFIG_DUMMY_CONSOLE |
| 799 | conswitchp = &dummy_con; |
| 800 | #endif |
| 801 | |
| 802 | ppc_md.setup_arch(); |
| 803 | if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab); |
| 804 | |
| 805 | paging_init(); |
| 806 | |
| 807 | /* this is for modules since _machine can be a define -- Cort */ |
| 808 | ppc_md.ppc_machine = _machine; |
| 809 | } |