Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/ppc/platforms/setup.c |
| 3 | * |
| 4 | * PowerPC version |
| 5 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 6 | * |
| 7 | * Adapted for Power Macintosh by Paul Mackerras |
| 8 | * Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au) |
| 9 | * |
| 10 | * Derived from "arch/alpha/kernel/setup.c" |
| 11 | * Copyright (C) 1995 Linus Torvalds |
| 12 | * |
| 13 | * Maintained by Benjamin Herrenschmidt (benh@kernel.crashing.org) |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * as published by the Free Software Foundation; either version |
| 18 | * 2 of the License, or (at your option) any later version. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * bootup setup stuff.. |
| 24 | */ |
| 25 | |
| 26 | #include <linux/config.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/errno.h> |
| 29 | #include <linux/sched.h> |
| 30 | #include <linux/kernel.h> |
| 31 | #include <linux/mm.h> |
| 32 | #include <linux/stddef.h> |
| 33 | #include <linux/unistd.h> |
| 34 | #include <linux/ptrace.h> |
| 35 | #include <linux/slab.h> |
| 36 | #include <linux/user.h> |
| 37 | #include <linux/a.out.h> |
| 38 | #include <linux/tty.h> |
| 39 | #include <linux/string.h> |
| 40 | #include <linux/delay.h> |
| 41 | #include <linux/ioport.h> |
| 42 | #include <linux/major.h> |
| 43 | #include <linux/initrd.h> |
| 44 | #include <linux/vt_kern.h> |
| 45 | #include <linux/console.h> |
| 46 | #include <linux/ide.h> |
| 47 | #include <linux/pci.h> |
| 48 | #include <linux/adb.h> |
| 49 | #include <linux/cuda.h> |
| 50 | #include <linux/pmu.h> |
| 51 | #include <linux/irq.h> |
| 52 | #include <linux/seq_file.h> |
| 53 | #include <linux/root_dev.h> |
| 54 | #include <linux/bitops.h> |
| 55 | #include <linux/suspend.h> |
| 56 | |
| 57 | #include <asm/reg.h> |
| 58 | #include <asm/sections.h> |
| 59 | #include <asm/prom.h> |
| 60 | #include <asm/system.h> |
| 61 | #include <asm/pgtable.h> |
| 62 | #include <asm/io.h> |
| 63 | #include <asm/pci-bridge.h> |
| 64 | #include <asm/ohare.h> |
| 65 | #include <asm/mediabay.h> |
| 66 | #include <asm/machdep.h> |
| 67 | #include <asm/dma.h> |
| 68 | #include <asm/bootx.h> |
| 69 | #include <asm/cputable.h> |
| 70 | #include <asm/btext.h> |
| 71 | #include <asm/pmac_feature.h> |
| 72 | #include <asm/time.h> |
| 73 | #include <asm/of_device.h> |
| 74 | #include <asm/mmu_context.h> |
| 75 | |
| 76 | #include "pmac_pic.h" |
| 77 | #include "mem_pieces.h" |
| 78 | |
| 79 | #undef SHOW_GATWICK_IRQS |
| 80 | |
| 81 | extern long pmac_time_init(void); |
| 82 | extern unsigned long pmac_get_rtc_time(void); |
| 83 | extern int pmac_set_rtc_time(unsigned long nowtime); |
| 84 | extern void pmac_read_rtc_time(void); |
| 85 | extern void pmac_calibrate_decr(void); |
| 86 | extern void pmac_pcibios_fixup(void); |
| 87 | extern void pmac_find_bridges(void); |
| 88 | extern unsigned long pmac_ide_get_base(int index); |
| 89 | extern void pmac_ide_init_hwif_ports(hw_regs_t *hw, |
| 90 | unsigned long data_port, unsigned long ctrl_port, int *irq); |
| 91 | |
| 92 | extern void pmac_nvram_update(void); |
| 93 | extern unsigned char pmac_nvram_read_byte(int addr); |
| 94 | extern void pmac_nvram_write_byte(int addr, unsigned char val); |
| 95 | extern int pmac_pci_enable_device_hook(struct pci_dev *dev, int initial); |
| 96 | extern void pmac_pcibios_after_init(void); |
| 97 | extern int of_show_percpuinfo(struct seq_file *m, int i); |
| 98 | |
| 99 | struct device_node *memory_node; |
| 100 | |
| 101 | unsigned char drive_info; |
| 102 | |
| 103 | int ppc_override_l2cr = 0; |
| 104 | int ppc_override_l2cr_value; |
| 105 | int has_l2cache = 0; |
| 106 | |
| 107 | static int current_root_goodness = -1; |
| 108 | |
| 109 | extern int pmac_newworld; |
| 110 | |
| 111 | #define DEFAULT_ROOT_DEVICE Root_SDA1 /* sda1 - slightly silly choice */ |
| 112 | |
| 113 | extern void zs_kgdb_hook(int tty_num); |
| 114 | static void ohare_init(void); |
| 115 | #ifdef CONFIG_BOOTX_TEXT |
| 116 | void pmac_progress(char *s, unsigned short hex); |
| 117 | #endif |
| 118 | |
| 119 | sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN; |
| 120 | |
| 121 | #ifdef CONFIG_SMP |
| 122 | extern struct smp_ops_t psurge_smp_ops; |
| 123 | extern struct smp_ops_t core99_smp_ops; |
| 124 | #endif /* CONFIG_SMP */ |
| 125 | |
| 126 | int __pmac |
| 127 | pmac_show_cpuinfo(struct seq_file *m) |
| 128 | { |
| 129 | struct device_node *np; |
| 130 | char *pp; |
| 131 | int plen; |
| 132 | int mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, |
| 133 | NULL, PMAC_MB_INFO_MODEL, 0); |
| 134 | unsigned int mbflags = (unsigned int)pmac_call_feature(PMAC_FTR_GET_MB_INFO, |
| 135 | NULL, PMAC_MB_INFO_FLAGS, 0); |
| 136 | char* mbname; |
| 137 | |
| 138 | if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME, (int)&mbname) != 0) |
| 139 | mbname = "Unknown"; |
| 140 | |
| 141 | /* find motherboard type */ |
| 142 | seq_printf(m, "machine\t\t: "); |
| 143 | np = find_devices("device-tree"); |
| 144 | if (np != NULL) { |
| 145 | pp = (char *) get_property(np, "model", NULL); |
| 146 | if (pp != NULL) |
| 147 | seq_printf(m, "%s\n", pp); |
| 148 | else |
| 149 | seq_printf(m, "PowerMac\n"); |
| 150 | pp = (char *) get_property(np, "compatible", &plen); |
| 151 | if (pp != NULL) { |
| 152 | seq_printf(m, "motherboard\t:"); |
| 153 | while (plen > 0) { |
| 154 | int l = strlen(pp) + 1; |
| 155 | seq_printf(m, " %s", pp); |
| 156 | plen -= l; |
| 157 | pp += l; |
| 158 | } |
| 159 | seq_printf(m, "\n"); |
| 160 | } |
| 161 | } else |
| 162 | seq_printf(m, "PowerMac\n"); |
| 163 | |
| 164 | /* print parsed model */ |
| 165 | seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname); |
| 166 | seq_printf(m, "pmac flags\t: %08x\n", mbflags); |
| 167 | |
| 168 | /* find l2 cache info */ |
| 169 | np = find_devices("l2-cache"); |
| 170 | if (np == 0) |
| 171 | np = find_type_devices("cache"); |
| 172 | if (np != 0) { |
| 173 | unsigned int *ic = (unsigned int *) |
| 174 | get_property(np, "i-cache-size", NULL); |
| 175 | unsigned int *dc = (unsigned int *) |
| 176 | get_property(np, "d-cache-size", NULL); |
| 177 | seq_printf(m, "L2 cache\t:"); |
| 178 | has_l2cache = 1; |
| 179 | if (get_property(np, "cache-unified", NULL) != 0 && dc) { |
| 180 | seq_printf(m, " %dK unified", *dc / 1024); |
| 181 | } else { |
| 182 | if (ic) |
| 183 | seq_printf(m, " %dK instruction", *ic / 1024); |
| 184 | if (dc) |
| 185 | seq_printf(m, "%s %dK data", |
| 186 | (ic? " +": ""), *dc / 1024); |
| 187 | } |
| 188 | pp = get_property(np, "ram-type", NULL); |
| 189 | if (pp) |
| 190 | seq_printf(m, " %s", pp); |
| 191 | seq_printf(m, "\n"); |
| 192 | } |
| 193 | |
| 194 | /* find ram info */ |
| 195 | np = find_devices("memory"); |
| 196 | if (np != 0) { |
| 197 | int n; |
| 198 | struct reg_property *reg = (struct reg_property *) |
| 199 | get_property(np, "reg", &n); |
| 200 | |
| 201 | if (reg != 0) { |
| 202 | unsigned long total = 0; |
| 203 | |
| 204 | for (n /= sizeof(struct reg_property); n > 0; --n) |
| 205 | total += (reg++)->size; |
| 206 | seq_printf(m, "memory\t\t: %luMB\n", total >> 20); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | /* Checks "l2cr-value" property in the registry */ |
| 211 | np = find_devices("cpus"); |
| 212 | if (np == 0) |
| 213 | np = find_type_devices("cpu"); |
| 214 | if (np != 0) { |
| 215 | unsigned int *l2cr = (unsigned int *) |
| 216 | get_property(np, "l2cr-value", NULL); |
| 217 | if (l2cr != 0) { |
| 218 | seq_printf(m, "l2cr override\t: 0x%x\n", *l2cr); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /* Indicate newworld/oldworld */ |
| 223 | seq_printf(m, "pmac-generation\t: %s\n", |
| 224 | pmac_newworld ? "NewWorld" : "OldWorld"); |
| 225 | |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | int __openfirmware |
| 231 | pmac_show_percpuinfo(struct seq_file *m, int i) |
| 232 | { |
| 233 | #ifdef CONFIG_CPU_FREQ_PMAC |
| 234 | extern unsigned int pmac_get_one_cpufreq(int i); |
| 235 | unsigned int freq = pmac_get_one_cpufreq(i); |
| 236 | if (freq != 0) { |
| 237 | seq_printf(m, "clock\t\t: %dMHz\n", freq/1000); |
| 238 | return 0; |
| 239 | } |
| 240 | #endif /* CONFIG_CPU_FREQ_PMAC */ |
| 241 | return of_show_percpuinfo(m, i); |
| 242 | } |
| 243 | |
| 244 | static volatile u32 *sysctrl_regs; |
| 245 | |
| 246 | void __init |
| 247 | pmac_setup_arch(void) |
| 248 | { |
| 249 | struct device_node *cpu; |
| 250 | int *fp; |
| 251 | unsigned long pvr; |
| 252 | |
| 253 | pvr = PVR_VER(mfspr(SPRN_PVR)); |
| 254 | |
| 255 | /* Set loops_per_jiffy to a half-way reasonable value, |
| 256 | for use until calibrate_delay gets called. */ |
| 257 | cpu = find_type_devices("cpu"); |
| 258 | if (cpu != 0) { |
| 259 | fp = (int *) get_property(cpu, "clock-frequency", NULL); |
| 260 | if (fp != 0) { |
| 261 | if (pvr == 4 || pvr >= 8) |
| 262 | /* 604, G3, G4 etc. */ |
| 263 | loops_per_jiffy = *fp / HZ; |
| 264 | else |
| 265 | /* 601, 603, etc. */ |
| 266 | loops_per_jiffy = *fp / (2*HZ); |
| 267 | } else |
| 268 | loops_per_jiffy = 50000000 / HZ; |
| 269 | } |
| 270 | |
| 271 | /* this area has the CPU identification register |
| 272 | and some registers used by smp boards */ |
| 273 | sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000); |
| 274 | ohare_init(); |
| 275 | |
| 276 | /* Lookup PCI hosts */ |
| 277 | pmac_find_bridges(); |
| 278 | |
| 279 | /* Checks "l2cr-value" property in the registry */ |
| 280 | if (cpu_has_feature(CPU_FTR_L2CR)) { |
| 281 | struct device_node *np = find_devices("cpus"); |
| 282 | if (np == 0) |
| 283 | np = find_type_devices("cpu"); |
| 284 | if (np != 0) { |
| 285 | unsigned int *l2cr = (unsigned int *) |
| 286 | get_property(np, "l2cr-value", NULL); |
| 287 | if (l2cr != 0) { |
| 288 | ppc_override_l2cr = 1; |
| 289 | ppc_override_l2cr_value = *l2cr; |
| 290 | _set_L2CR(0); |
| 291 | _set_L2CR(ppc_override_l2cr_value); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | if (ppc_override_l2cr) |
| 297 | printk(KERN_INFO "L2CR overriden (0x%x), backside cache is %s\n", |
| 298 | ppc_override_l2cr_value, (ppc_override_l2cr_value & 0x80000000) |
| 299 | ? "enabled" : "disabled"); |
| 300 | |
| 301 | #ifdef CONFIG_KGDB |
| 302 | zs_kgdb_hook(0); |
| 303 | #endif |
| 304 | |
| 305 | #ifdef CONFIG_ADB_CUDA |
| 306 | find_via_cuda(); |
| 307 | #else |
| 308 | if (find_devices("via-cuda")) { |
| 309 | printk("WARNING ! Your machine is Cuda based but your kernel\n"); |
| 310 | printk(" wasn't compiled with CONFIG_ADB_CUDA option !\n"); |
| 311 | } |
| 312 | #endif |
| 313 | #ifdef CONFIG_ADB_PMU |
| 314 | find_via_pmu(); |
| 315 | #else |
| 316 | if (find_devices("via-pmu")) { |
| 317 | printk("WARNING ! Your machine is PMU based but your kernel\n"); |
| 318 | printk(" wasn't compiled with CONFIG_ADB_PMU option !\n"); |
| 319 | } |
| 320 | #endif |
| 321 | #ifdef CONFIG_NVRAM |
| 322 | pmac_nvram_init(); |
| 323 | #endif |
| 324 | #ifdef CONFIG_BLK_DEV_INITRD |
| 325 | if (initrd_start) |
| 326 | ROOT_DEV = Root_RAM0; |
| 327 | else |
| 328 | #endif |
| 329 | ROOT_DEV = DEFAULT_ROOT_DEVICE; |
| 330 | |
| 331 | #ifdef CONFIG_SMP |
| 332 | /* Check for Core99 */ |
| 333 | if (find_devices("uni-n") || find_devices("u3")) |
| 334 | ppc_md.smp_ops = &core99_smp_ops; |
| 335 | else |
| 336 | ppc_md.smp_ops = &psurge_smp_ops; |
| 337 | #endif /* CONFIG_SMP */ |
| 338 | |
| 339 | pci_create_OF_bus_map(); |
| 340 | } |
| 341 | |
| 342 | static void __init ohare_init(void) |
| 343 | { |
| 344 | /* |
| 345 | * Turn on the L2 cache. |
| 346 | * We assume that we have a PSX memory controller iff |
| 347 | * we have an ohare I/O controller. |
| 348 | */ |
| 349 | if (find_devices("ohare") != NULL) { |
| 350 | if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) { |
| 351 | if (sysctrl_regs[4] & 0x10) |
| 352 | sysctrl_regs[4] |= 0x04000020; |
| 353 | else |
| 354 | sysctrl_regs[4] |= 0x04000000; |
| 355 | if(has_l2cache) |
| 356 | printk(KERN_INFO "Level 2 cache enabled\n"); |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | extern char *bootpath; |
| 362 | extern char *bootdevice; |
| 363 | void *boot_host; |
| 364 | int boot_target; |
| 365 | int boot_part; |
| 366 | extern dev_t boot_dev; |
| 367 | |
| 368 | #ifdef CONFIG_SCSI |
| 369 | void __init |
| 370 | note_scsi_host(struct device_node *node, void *host) |
| 371 | { |
| 372 | int l; |
| 373 | char *p; |
| 374 | |
| 375 | l = strlen(node->full_name); |
| 376 | if (bootpath != NULL && bootdevice != NULL |
| 377 | && strncmp(node->full_name, bootdevice, l) == 0 |
| 378 | && (bootdevice[l] == '/' || bootdevice[l] == 0)) { |
| 379 | boot_host = host; |
| 380 | /* |
| 381 | * There's a bug in OF 1.0.5. (Why am I not surprised.) |
| 382 | * If you pass a path like scsi/sd@1:0 to canon, it returns |
| 383 | * something like /bandit@F2000000/gc@10/53c94@10000/sd@0,0 |
| 384 | * That is, the scsi target number doesn't get preserved. |
| 385 | * So we pick the target number out of bootpath and use that. |
| 386 | */ |
| 387 | p = strstr(bootpath, "/sd@"); |
| 388 | if (p != NULL) { |
| 389 | p += 4; |
| 390 | boot_target = simple_strtoul(p, NULL, 10); |
| 391 | p = strchr(p, ':'); |
| 392 | if (p != NULL) |
| 393 | boot_part = simple_strtoul(p + 1, NULL, 10); |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | #endif |
| 398 | |
| 399 | #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC) |
| 400 | static dev_t __init |
| 401 | find_ide_boot(void) |
| 402 | { |
| 403 | char *p; |
| 404 | int n; |
| 405 | dev_t __init pmac_find_ide_boot(char *bootdevice, int n); |
| 406 | |
| 407 | if (bootdevice == NULL) |
| 408 | return 0; |
| 409 | p = strrchr(bootdevice, '/'); |
| 410 | if (p == NULL) |
| 411 | return 0; |
| 412 | n = p - bootdevice; |
| 413 | |
| 414 | return pmac_find_ide_boot(bootdevice, n); |
| 415 | } |
| 416 | #endif /* CONFIG_BLK_DEV_IDE && CONFIG_BLK_DEV_IDE_PMAC */ |
| 417 | |
| 418 | void __init |
| 419 | find_boot_device(void) |
| 420 | { |
| 421 | #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC) |
| 422 | boot_dev = find_ide_boot(); |
| 423 | #endif |
| 424 | } |
| 425 | |
| 426 | static int initializing = 1; |
| 427 | /* TODO: Merge the suspend-to-ram with the common code !!! |
| 428 | * currently, this is a stub implementation for suspend-to-disk |
| 429 | * only |
| 430 | */ |
| 431 | |
| 432 | #ifdef CONFIG_SOFTWARE_SUSPEND |
| 433 | |
| 434 | static int pmac_pm_prepare(suspend_state_t state) |
| 435 | { |
| 436 | printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state); |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | static int pmac_pm_enter(suspend_state_t state) |
| 442 | { |
| 443 | printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state); |
| 444 | |
| 445 | /* Giveup the lazy FPU & vec so we don't have to back them |
| 446 | * up from the low level code |
| 447 | */ |
| 448 | enable_kernel_fp(); |
| 449 | |
| 450 | #ifdef CONFIG_ALTIVEC |
| 451 | if (cur_cpu_spec[0]->cpu_features & CPU_FTR_ALTIVEC) |
| 452 | enable_kernel_altivec(); |
| 453 | #endif /* CONFIG_ALTIVEC */ |
| 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static int pmac_pm_finish(suspend_state_t state) |
| 459 | { |
| 460 | printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state); |
| 461 | |
| 462 | /* Restore userland MMU context */ |
| 463 | set_context(current->active_mm->context, current->active_mm->pgd); |
| 464 | |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | static struct pm_ops pmac_pm_ops = { |
| 469 | .pm_disk_mode = PM_DISK_SHUTDOWN, |
| 470 | .prepare = pmac_pm_prepare, |
| 471 | .enter = pmac_pm_enter, |
| 472 | .finish = pmac_pm_finish, |
| 473 | }; |
| 474 | |
| 475 | #endif /* CONFIG_SOFTWARE_SUSPEND */ |
| 476 | |
| 477 | static int pmac_late_init(void) |
| 478 | { |
| 479 | initializing = 0; |
| 480 | #ifdef CONFIG_SOFTWARE_SUSPEND |
| 481 | pm_set_ops(&pmac_pm_ops); |
| 482 | #endif /* CONFIG_SOFTWARE_SUSPEND */ |
| 483 | return 0; |
| 484 | } |
| 485 | |
| 486 | late_initcall(pmac_late_init); |
| 487 | |
| 488 | /* can't be __init - can be called whenever a disk is first accessed */ |
| 489 | void __pmac |
| 490 | note_bootable_part(dev_t dev, int part, int goodness) |
| 491 | { |
| 492 | static int found_boot = 0; |
| 493 | char *p; |
| 494 | |
| 495 | if (!initializing) |
| 496 | return; |
| 497 | if ((goodness <= current_root_goodness) && |
| 498 | ROOT_DEV != DEFAULT_ROOT_DEVICE) |
| 499 | return; |
| 500 | p = strstr(saved_command_line, "root="); |
| 501 | if (p != NULL && (p == saved_command_line || p[-1] == ' ')) |
| 502 | return; |
| 503 | |
| 504 | if (!found_boot) { |
| 505 | find_boot_device(); |
| 506 | found_boot = 1; |
| 507 | } |
| 508 | if (!boot_dev || dev == boot_dev) { |
| 509 | ROOT_DEV = dev + part; |
| 510 | boot_dev = 0; |
| 511 | current_root_goodness = goodness; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | void __pmac |
| 516 | pmac_restart(char *cmd) |
| 517 | { |
| 518 | #ifdef CONFIG_ADB_CUDA |
| 519 | struct adb_request req; |
| 520 | #endif /* CONFIG_ADB_CUDA */ |
| 521 | |
| 522 | switch (sys_ctrler) { |
| 523 | #ifdef CONFIG_ADB_CUDA |
| 524 | case SYS_CTRLER_CUDA: |
| 525 | cuda_request(&req, NULL, 2, CUDA_PACKET, |
| 526 | CUDA_RESET_SYSTEM); |
| 527 | for (;;) |
| 528 | cuda_poll(); |
| 529 | break; |
| 530 | #endif /* CONFIG_ADB_CUDA */ |
| 531 | #ifdef CONFIG_ADB_PMU |
| 532 | case SYS_CTRLER_PMU: |
| 533 | pmu_restart(); |
| 534 | break; |
| 535 | #endif /* CONFIG_ADB_PMU */ |
| 536 | default: ; |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | void __pmac |
| 541 | pmac_power_off(void) |
| 542 | { |
| 543 | #ifdef CONFIG_ADB_CUDA |
| 544 | struct adb_request req; |
| 545 | #endif /* CONFIG_ADB_CUDA */ |
| 546 | |
| 547 | switch (sys_ctrler) { |
| 548 | #ifdef CONFIG_ADB_CUDA |
| 549 | case SYS_CTRLER_CUDA: |
| 550 | cuda_request(&req, NULL, 2, CUDA_PACKET, |
| 551 | CUDA_POWERDOWN); |
| 552 | for (;;) |
| 553 | cuda_poll(); |
| 554 | break; |
| 555 | #endif /* CONFIG_ADB_CUDA */ |
| 556 | #ifdef CONFIG_ADB_PMU |
| 557 | case SYS_CTRLER_PMU: |
| 558 | pmu_shutdown(); |
| 559 | break; |
| 560 | #endif /* CONFIG_ADB_PMU */ |
| 561 | default: ; |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | void __pmac |
| 566 | pmac_halt(void) |
| 567 | { |
| 568 | pmac_power_off(); |
| 569 | } |
| 570 | |
| 571 | /* |
| 572 | * Read in a property describing some pieces of memory. |
| 573 | */ |
| 574 | |
| 575 | static int __init |
| 576 | get_mem_prop(char *name, struct mem_pieces *mp) |
| 577 | { |
| 578 | struct reg_property *rp; |
| 579 | int i, s; |
| 580 | unsigned int *ip; |
| 581 | int nac = prom_n_addr_cells(memory_node); |
| 582 | int nsc = prom_n_size_cells(memory_node); |
| 583 | |
| 584 | ip = (unsigned int *) get_property(memory_node, name, &s); |
| 585 | if (ip == NULL) { |
| 586 | printk(KERN_ERR "error: couldn't get %s property on /memory\n", |
| 587 | name); |
| 588 | return 0; |
| 589 | } |
| 590 | s /= (nsc + nac) * 4; |
| 591 | rp = mp->regions; |
| 592 | for (i = 0; i < s; ++i, ip += nac+nsc) { |
| 593 | if (nac >= 2 && ip[nac-2] != 0) |
| 594 | continue; |
| 595 | rp->address = ip[nac-1]; |
| 596 | if (nsc >= 2 && ip[nac+nsc-2] != 0) |
| 597 | rp->size = ~0U; |
| 598 | else |
| 599 | rp->size = ip[nac+nsc-1]; |
| 600 | ++rp; |
| 601 | } |
| 602 | mp->n_regions = rp - mp->regions; |
| 603 | |
| 604 | /* Make sure the pieces are sorted. */ |
| 605 | mem_pieces_sort(mp); |
| 606 | mem_pieces_coalesce(mp); |
| 607 | return 1; |
| 608 | } |
| 609 | |
| 610 | /* |
| 611 | * On systems with Open Firmware, collect information about |
| 612 | * physical RAM and which pieces are already in use. |
| 613 | * At this point, we have (at least) the first 8MB mapped with a BAT. |
| 614 | * Our text, data, bss use something over 1MB, starting at 0. |
| 615 | * Open Firmware may be using 1MB at the 4MB point. |
| 616 | */ |
| 617 | unsigned long __init |
| 618 | pmac_find_end_of_memory(void) |
| 619 | { |
| 620 | unsigned long a, total; |
| 621 | struct mem_pieces phys_mem; |
| 622 | |
| 623 | /* |
| 624 | * Find out where physical memory is, and check that it |
| 625 | * starts at 0 and is contiguous. It seems that RAM is |
| 626 | * always physically contiguous on Power Macintoshes. |
| 627 | * |
| 628 | * Supporting discontiguous physical memory isn't hard, |
| 629 | * it just makes the virtual <-> physical mapping functions |
| 630 | * more complicated (or else you end up wasting space |
| 631 | * in mem_map). |
| 632 | */ |
| 633 | memory_node = find_devices("memory"); |
| 634 | if (memory_node == NULL || !get_mem_prop("reg", &phys_mem) |
| 635 | || phys_mem.n_regions == 0) |
| 636 | panic("No RAM??"); |
| 637 | a = phys_mem.regions[0].address; |
| 638 | if (a != 0) |
| 639 | panic("RAM doesn't start at physical address 0"); |
| 640 | total = phys_mem.regions[0].size; |
| 641 | |
| 642 | if (phys_mem.n_regions > 1) { |
| 643 | printk("RAM starting at 0x%x is not contiguous\n", |
| 644 | phys_mem.regions[1].address); |
| 645 | printk("Using RAM from 0 to 0x%lx\n", total-1); |
| 646 | } |
| 647 | |
| 648 | return total; |
| 649 | } |
| 650 | |
| 651 | void __init |
| 652 | pmac_init(unsigned long r3, unsigned long r4, unsigned long r5, |
| 653 | unsigned long r6, unsigned long r7) |
| 654 | { |
| 655 | /* isa_io_base gets set in pmac_find_bridges */ |
| 656 | isa_mem_base = PMAC_ISA_MEM_BASE; |
| 657 | pci_dram_offset = PMAC_PCI_DRAM_OFFSET; |
| 658 | ISA_DMA_THRESHOLD = ~0L; |
| 659 | DMA_MODE_READ = 1; |
| 660 | DMA_MODE_WRITE = 2; |
| 661 | |
| 662 | ppc_md.setup_arch = pmac_setup_arch; |
| 663 | ppc_md.show_cpuinfo = pmac_show_cpuinfo; |
| 664 | ppc_md.show_percpuinfo = pmac_show_percpuinfo; |
| 665 | ppc_md.irq_canonicalize = NULL; |
| 666 | ppc_md.init_IRQ = pmac_pic_init; |
| 667 | ppc_md.get_irq = pmac_get_irq; /* Changed later on ... */ |
| 668 | |
| 669 | ppc_md.pcibios_fixup = pmac_pcibios_fixup; |
| 670 | ppc_md.pcibios_enable_device_hook = pmac_pci_enable_device_hook; |
| 671 | ppc_md.pcibios_after_init = pmac_pcibios_after_init; |
| 672 | ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot; |
| 673 | |
| 674 | ppc_md.restart = pmac_restart; |
| 675 | ppc_md.power_off = pmac_power_off; |
| 676 | ppc_md.halt = pmac_halt; |
| 677 | |
| 678 | ppc_md.time_init = pmac_time_init; |
| 679 | ppc_md.set_rtc_time = pmac_set_rtc_time; |
| 680 | ppc_md.get_rtc_time = pmac_get_rtc_time; |
| 681 | ppc_md.calibrate_decr = pmac_calibrate_decr; |
| 682 | |
| 683 | ppc_md.find_end_of_memory = pmac_find_end_of_memory; |
| 684 | |
| 685 | ppc_md.feature_call = pmac_do_feature_call; |
| 686 | |
| 687 | #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE) |
| 688 | #ifdef CONFIG_BLK_DEV_IDE_PMAC |
| 689 | ppc_ide_md.ide_init_hwif = pmac_ide_init_hwif_ports; |
| 690 | ppc_ide_md.default_io_base = pmac_ide_get_base; |
| 691 | #endif /* CONFIG_BLK_DEV_IDE_PMAC */ |
| 692 | #endif /* defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE) */ |
| 693 | |
| 694 | #ifdef CONFIG_BOOTX_TEXT |
| 695 | ppc_md.progress = pmac_progress; |
| 696 | #endif /* CONFIG_BOOTX_TEXT */ |
| 697 | |
| 698 | if (ppc_md.progress) ppc_md.progress("pmac_init(): exit", 0); |
| 699 | |
| 700 | } |
| 701 | |
| 702 | #ifdef CONFIG_BOOTX_TEXT |
| 703 | void __init |
| 704 | pmac_progress(char *s, unsigned short hex) |
| 705 | { |
| 706 | if (boot_text_mapped) { |
| 707 | btext_drawstring(s); |
| 708 | btext_drawchar('\n'); |
| 709 | } |
| 710 | } |
| 711 | #endif /* CONFIG_BOOTX_TEXT */ |
| 712 | |
| 713 | static int __init |
| 714 | pmac_declare_of_platform_devices(void) |
| 715 | { |
| 716 | struct device_node *np; |
| 717 | |
| 718 | np = find_devices("uni-n"); |
| 719 | if (np) { |
| 720 | for (np = np->child; np != NULL; np = np->sibling) |
| 721 | if (strncmp(np->name, "i2c", 3) == 0) { |
| 722 | of_platform_device_create(np, "uni-n-i2c"); |
| 723 | break; |
| 724 | } |
| 725 | } |
| 726 | np = find_devices("u3"); |
| 727 | if (np) { |
| 728 | for (np = np->child; np != NULL; np = np->sibling) |
| 729 | if (strncmp(np->name, "i2c", 3) == 0) { |
| 730 | of_platform_device_create(np, "u3-i2c"); |
| 731 | break; |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | np = find_devices("valkyrie"); |
| 736 | if (np) |
| 737 | of_platform_device_create(np, "valkyrie"); |
| 738 | np = find_devices("platinum"); |
| 739 | if (np) |
| 740 | of_platform_device_create(np, "platinum"); |
| 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | |
| 745 | device_initcall(pmac_declare_of_platform_devices); |