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