1f6d57916SPaul Mackerras /* 235499c01SPaul Mackerras * Powermac setup and early boot code plus other random bits. 3f6d57916SPaul Mackerras * 4f6d57916SPaul Mackerras * PowerPC version 5f6d57916SPaul Mackerras * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 6f6d57916SPaul Mackerras * 7f6d57916SPaul Mackerras * Adapted for Power Macintosh by Paul Mackerras 835499c01SPaul Mackerras * Copyright (C) 1996 Paul Mackerras (paulus@samba.org) 9f6d57916SPaul Mackerras * 10f6d57916SPaul Mackerras * Derived from "arch/alpha/kernel/setup.c" 11f6d57916SPaul Mackerras * Copyright (C) 1995 Linus Torvalds 12f6d57916SPaul Mackerras * 13f6d57916SPaul Mackerras * Maintained by Benjamin Herrenschmidt (benh@kernel.crashing.org) 14f6d57916SPaul Mackerras * 15f6d57916SPaul Mackerras * This program is free software; you can redistribute it and/or 16f6d57916SPaul Mackerras * modify it under the terms of the GNU General Public License 17f6d57916SPaul Mackerras * as published by the Free Software Foundation; either version 18f6d57916SPaul Mackerras * 2 of the License, or (at your option) any later version. 19f6d57916SPaul Mackerras * 20f6d57916SPaul Mackerras */ 21f6d57916SPaul Mackerras 22f6d57916SPaul Mackerras /* 23f6d57916SPaul Mackerras * bootup setup stuff.. 24f6d57916SPaul Mackerras */ 25f6d57916SPaul Mackerras 26f6d57916SPaul Mackerras #include <linux/init.h> 27f6d57916SPaul Mackerras #include <linux/errno.h> 28f6d57916SPaul Mackerras #include <linux/sched.h> 29f6d57916SPaul Mackerras #include <linux/kernel.h> 30f6d57916SPaul Mackerras #include <linux/mm.h> 31f6d57916SPaul Mackerras #include <linux/stddef.h> 32f6d57916SPaul Mackerras #include <linux/unistd.h> 33f6d57916SPaul Mackerras #include <linux/ptrace.h> 3466b15db6SPaul Gortmaker #include <linux/export.h> 35f6d57916SPaul Mackerras #include <linux/user.h> 36f6d57916SPaul Mackerras #include <linux/tty.h> 37f6d57916SPaul Mackerras #include <linux/string.h> 38f6d57916SPaul Mackerras #include <linux/delay.h> 39f6d57916SPaul Mackerras #include <linux/ioport.h> 40f6d57916SPaul Mackerras #include <linux/major.h> 41f6d57916SPaul Mackerras #include <linux/initrd.h> 42f6d57916SPaul Mackerras #include <linux/vt_kern.h> 43f6d57916SPaul Mackerras #include <linux/console.h> 44f6d57916SPaul Mackerras #include <linux/pci.h> 45f6d57916SPaul Mackerras #include <linux/adb.h> 46f6d57916SPaul Mackerras #include <linux/cuda.h> 47f6d57916SPaul Mackerras #include <linux/pmu.h> 48f6d57916SPaul Mackerras #include <linux/irq.h> 49f6d57916SPaul Mackerras #include <linux/seq_file.h> 50f6d57916SPaul Mackerras #include <linux/root_dev.h> 51f6d57916SPaul Mackerras #include <linux/bitops.h> 52f6d57916SPaul Mackerras #include <linux/suspend.h> 535f867dc7SJon Loeliger #include <linux/of_device.h> 545f867dc7SJon Loeliger #include <linux/of_platform.h> 55f6d57916SPaul Mackerras 56f6d57916SPaul Mackerras #include <asm/reg.h> 57f6d57916SPaul Mackerras #include <asm/sections.h> 58f6d57916SPaul Mackerras #include <asm/prom.h> 59f6d57916SPaul Mackerras #include <asm/pgtable.h> 60f6d57916SPaul Mackerras #include <asm/io.h> 61f6d57916SPaul Mackerras #include <asm/pci-bridge.h> 62f6d57916SPaul Mackerras #include <asm/ohare.h> 63f6d57916SPaul Mackerras #include <asm/mediabay.h> 64f6d57916SPaul Mackerras #include <asm/machdep.h> 65f6d57916SPaul Mackerras #include <asm/dma.h> 66f6d57916SPaul Mackerras #include <asm/cputable.h> 67f6d57916SPaul Mackerras #include <asm/btext.h> 68f6d57916SPaul Mackerras #include <asm/pmac_feature.h> 69f6d57916SPaul Mackerras #include <asm/time.h> 70f6d57916SPaul Mackerras #include <asm/mmu_context.h> 7135499c01SPaul Mackerras #include <asm/iommu.h> 7235499c01SPaul Mackerras #include <asm/smu.h> 7335499c01SPaul Mackerras #include <asm/pmc.h> 7451d3082fSBenjamin Herrenschmidt #include <asm/udbg.h> 75f6d57916SPaul Mackerras 763c3f42d6SPaul Mackerras #include "pmac.h" 77f6d57916SPaul Mackerras 78f6d57916SPaul Mackerras #undef SHOW_GATWICK_IRQS 79f6d57916SPaul Mackerras 80f6d57916SPaul Mackerras int ppc_override_l2cr = 0; 81f6d57916SPaul Mackerras int ppc_override_l2cr_value; 82f6d57916SPaul Mackerras int has_l2cache = 0; 83f6d57916SPaul Mackerras 84d2515c80SOlaf Hering int pmac_newworld; 85f6d57916SPaul Mackerras 86f6d57916SPaul Mackerras static int current_root_goodness = -1; 87f6d57916SPaul Mackerras 8835499c01SPaul Mackerras extern struct machdep_calls pmac_md; 89f6d57916SPaul Mackerras 90f6d57916SPaul Mackerras #define DEFAULT_ROOT_DEVICE Root_SDA1 /* sda1 - slightly silly choice */ 91f6d57916SPaul Mackerras 9235499c01SPaul Mackerras #ifdef CONFIG_PPC64 9335499c01SPaul Mackerras int sccdbg; 94f6d57916SPaul Mackerras #endif 95f6d57916SPaul Mackerras 96f6d57916SPaul Mackerras sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN; 9735499c01SPaul Mackerras EXPORT_SYMBOL(sys_ctrler); 9835499c01SPaul Mackerras 990dd194d0SPaul Mackerras static void pmac_show_cpuinfo(struct seq_file *m) 100f6d57916SPaul Mackerras { 101f6d57916SPaul Mackerras struct device_node *np; 102018a3d1dSJeremy Kerr const char *pp; 103f6d57916SPaul Mackerras int plen; 1040dd194d0SPaul Mackerras int mbmodel; 1050dd194d0SPaul Mackerras unsigned int mbflags; 106f6d57916SPaul Mackerras char* mbname; 107f6d57916SPaul Mackerras 1080dd194d0SPaul Mackerras mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, 1090dd194d0SPaul Mackerras PMAC_MB_INFO_MODEL, 0); 1100dd194d0SPaul Mackerras mbflags = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, 1110dd194d0SPaul Mackerras PMAC_MB_INFO_FLAGS, 0); 1120dd194d0SPaul Mackerras if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME, 1130dd194d0SPaul Mackerras (long) &mbname) != 0) 114f6d57916SPaul Mackerras mbname = "Unknown"; 115f6d57916SPaul Mackerras 116f6d57916SPaul Mackerras /* find motherboard type */ 117f6d57916SPaul Mackerras seq_printf(m, "machine\t\t: "); 1180dd194d0SPaul Mackerras np = of_find_node_by_path("/"); 119f6d57916SPaul Mackerras if (np != NULL) { 120e2eb6392SStephen Rothwell pp = of_get_property(np, "model", NULL); 121f6d57916SPaul Mackerras if (pp != NULL) 122f6d57916SPaul Mackerras seq_printf(m, "%s\n", pp); 123f6d57916SPaul Mackerras else 124f6d57916SPaul Mackerras seq_printf(m, "PowerMac\n"); 125e2eb6392SStephen Rothwell pp = of_get_property(np, "compatible", &plen); 126f6d57916SPaul Mackerras if (pp != NULL) { 127f6d57916SPaul Mackerras seq_printf(m, "motherboard\t:"); 128f6d57916SPaul Mackerras while (plen > 0) { 129f6d57916SPaul Mackerras int l = strlen(pp) + 1; 130f6d57916SPaul Mackerras seq_printf(m, " %s", pp); 131f6d57916SPaul Mackerras plen -= l; 132f6d57916SPaul Mackerras pp += l; 133f6d57916SPaul Mackerras } 134f6d57916SPaul Mackerras seq_printf(m, "\n"); 135f6d57916SPaul Mackerras } 1360dd194d0SPaul Mackerras of_node_put(np); 137f6d57916SPaul Mackerras } else 138f6d57916SPaul Mackerras seq_printf(m, "PowerMac\n"); 139f6d57916SPaul Mackerras 140f6d57916SPaul Mackerras /* print parsed model */ 141f6d57916SPaul Mackerras seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname); 142f6d57916SPaul Mackerras seq_printf(m, "pmac flags\t: %08x\n", mbflags); 143f6d57916SPaul Mackerras 144f6d57916SPaul Mackerras /* find l2 cache info */ 1450dd194d0SPaul Mackerras np = of_find_node_by_name(NULL, "l2-cache"); 1460dd194d0SPaul Mackerras if (np == NULL) 1470dd194d0SPaul Mackerras np = of_find_node_by_type(NULL, "cache"); 1480dd194d0SPaul Mackerras if (np != NULL) { 149e2eb6392SStephen Rothwell const unsigned int *ic = 150e2eb6392SStephen Rothwell of_get_property(np, "i-cache-size", NULL); 151e2eb6392SStephen Rothwell const unsigned int *dc = 152e2eb6392SStephen Rothwell of_get_property(np, "d-cache-size", NULL); 153f6d57916SPaul Mackerras seq_printf(m, "L2 cache\t:"); 154f6d57916SPaul Mackerras has_l2cache = 1; 155d8731527SMathieu Malaterre if (of_get_property(np, "cache-unified", NULL) && dc) { 156f6d57916SPaul Mackerras seq_printf(m, " %dK unified", *dc / 1024); 157f6d57916SPaul Mackerras } else { 158f6d57916SPaul Mackerras if (ic) 159f6d57916SPaul Mackerras seq_printf(m, " %dK instruction", *ic / 1024); 160f6d57916SPaul Mackerras if (dc) 161f6d57916SPaul Mackerras seq_printf(m, "%s %dK data", 162f6d57916SPaul Mackerras (ic? " +": ""), *dc / 1024); 163f6d57916SPaul Mackerras } 164e2eb6392SStephen Rothwell pp = of_get_property(np, "ram-type", NULL); 165f6d57916SPaul Mackerras if (pp) 166f6d57916SPaul Mackerras seq_printf(m, " %s", pp); 167f6d57916SPaul Mackerras seq_printf(m, "\n"); 1680dd194d0SPaul Mackerras of_node_put(np); 169f6d57916SPaul Mackerras } 170f6d57916SPaul Mackerras 171f6d57916SPaul Mackerras /* Indicate newworld/oldworld */ 172f6d57916SPaul Mackerras seq_printf(m, "pmac-generation\t: %s\n", 173f6d57916SPaul Mackerras pmac_newworld ? "NewWorld" : "OldWorld"); 174f6d57916SPaul Mackerras } 175f6d57916SPaul Mackerras 17635499c01SPaul Mackerras #ifndef CONFIG_ADB_CUDA 17735499c01SPaul Mackerras int find_via_cuda(void) 17835499c01SPaul Mackerras { 17930686ba6SStephen Rothwell struct device_node *dn = of_find_node_by_name(NULL, "via-cuda"); 18030686ba6SStephen Rothwell 18130686ba6SStephen Rothwell if (!dn) 18235499c01SPaul Mackerras return 0; 18330686ba6SStephen Rothwell of_node_put(dn); 18435499c01SPaul Mackerras printk("WARNING ! Your machine is CUDA-based but your kernel\n"); 18535499c01SPaul Mackerras printk(" wasn't compiled with CONFIG_ADB_CUDA option !\n"); 18635499c01SPaul Mackerras return 0; 18735499c01SPaul Mackerras } 18835499c01SPaul Mackerras #endif 18935499c01SPaul Mackerras 19035499c01SPaul Mackerras #ifndef CONFIG_ADB_PMU 19135499c01SPaul Mackerras int find_via_pmu(void) 19235499c01SPaul Mackerras { 19330686ba6SStephen Rothwell struct device_node *dn = of_find_node_by_name(NULL, "via-pmu"); 19430686ba6SStephen Rothwell 19530686ba6SStephen Rothwell if (!dn) 19635499c01SPaul Mackerras return 0; 19730686ba6SStephen Rothwell of_node_put(dn); 19835499c01SPaul Mackerras printk("WARNING ! Your machine is PMU-based but your kernel\n"); 19935499c01SPaul Mackerras printk(" wasn't compiled with CONFIG_ADB_PMU option !\n"); 200a575b807SPaul Mackerras return 0; 20135499c01SPaul Mackerras } 20235499c01SPaul Mackerras #endif 20335499c01SPaul Mackerras 20435499c01SPaul Mackerras #ifndef CONFIG_PMAC_SMU 20535499c01SPaul Mackerras int smu_init(void) 20635499c01SPaul Mackerras { 20735499c01SPaul Mackerras /* should check and warn if SMU is present */ 20835499c01SPaul Mackerras return 0; 20935499c01SPaul Mackerras } 21035499c01SPaul Mackerras #endif 21135499c01SPaul Mackerras 21235499c01SPaul Mackerras #ifdef CONFIG_PPC32 213f6d57916SPaul Mackerras static volatile u32 *sysctrl_regs; 214f6d57916SPaul Mackerras 21535499c01SPaul Mackerras static void __init ohare_init(void) 216f6d57916SPaul Mackerras { 21730686ba6SStephen Rothwell struct device_node *dn; 21830686ba6SStephen Rothwell 219f6d57916SPaul Mackerras /* this area has the CPU identification register 220f6d57916SPaul Mackerras and some registers used by smp boards */ 221f6d57916SPaul Mackerras sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000); 222f6d57916SPaul Mackerras 22335499c01SPaul Mackerras /* 22435499c01SPaul Mackerras * Turn on the L2 cache. 22535499c01SPaul Mackerras * We assume that we have a PSX memory controller iff 22635499c01SPaul Mackerras * we have an ohare I/O controller. 22735499c01SPaul Mackerras */ 22830686ba6SStephen Rothwell dn = of_find_node_by_name(NULL, "ohare"); 22930686ba6SStephen Rothwell if (dn) { 23030686ba6SStephen Rothwell of_node_put(dn); 23135499c01SPaul Mackerras if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) { 23235499c01SPaul Mackerras if (sysctrl_regs[4] & 0x10) 23335499c01SPaul Mackerras sysctrl_regs[4] |= 0x04000020; 23435499c01SPaul Mackerras else 23535499c01SPaul Mackerras sysctrl_regs[4] |= 0x04000000; 23635499c01SPaul Mackerras if(has_l2cache) 23735499c01SPaul Mackerras printk(KERN_INFO "Level 2 cache enabled\n"); 23835499c01SPaul Mackerras } 23935499c01SPaul Mackerras } 24035499c01SPaul Mackerras } 241f6d57916SPaul Mackerras 24235499c01SPaul Mackerras static void __init l2cr_init(void) 24335499c01SPaul Mackerras { 244f6d57916SPaul Mackerras /* Checks "l2cr-value" property in the registry */ 245f6d57916SPaul Mackerras if (cpu_has_feature(CPU_FTR_L2CR)) { 246a94fe366SRob Herring struct device_node *np; 247a94fe366SRob Herring 248a94fe366SRob Herring for_each_of_cpu_node(np) { 249018a3d1dSJeremy Kerr const unsigned int *l2cr = 250e2eb6392SStephen Rothwell of_get_property(np, "l2cr-value", NULL); 251d8731527SMathieu Malaterre if (l2cr) { 252f6d57916SPaul Mackerras ppc_override_l2cr = 1; 253f6d57916SPaul Mackerras ppc_override_l2cr_value = *l2cr; 254f6d57916SPaul Mackerras _set_L2CR(0); 255f6d57916SPaul Mackerras _set_L2CR(ppc_override_l2cr_value); 256f6d57916SPaul Mackerras } 2571658ab66SStephen Rothwell of_node_put(np); 258a94fe366SRob Herring break; 259f6d57916SPaul Mackerras } 260f6d57916SPaul Mackerras } 261f6d57916SPaul Mackerras 262f6d57916SPaul Mackerras if (ppc_override_l2cr) 26335499c01SPaul Mackerras printk(KERN_INFO "L2CR overridden (0x%x), " 26435499c01SPaul Mackerras "backside cache is %s\n", 26535499c01SPaul Mackerras ppc_override_l2cr_value, 26635499c01SPaul Mackerras (ppc_override_l2cr_value & 0x80000000) 267f6d57916SPaul Mackerras ? "enabled" : "disabled"); 26835499c01SPaul Mackerras } 26935499c01SPaul Mackerras #endif 27035499c01SPaul Mackerras 271ff38e7c8SArnd Bergmann static void __init pmac_setup_arch(void) 27235499c01SPaul Mackerras { 273a575b807SPaul Mackerras struct device_node *cpu, *ic; 274018a3d1dSJeremy Kerr const int *fp; 27535499c01SPaul Mackerras unsigned long pvr; 27635499c01SPaul Mackerras 27735499c01SPaul Mackerras pvr = PVR_VER(mfspr(SPRN_PVR)); 27835499c01SPaul Mackerras 27935499c01SPaul Mackerras /* Set loops_per_jiffy to a half-way reasonable value, 28035499c01SPaul Mackerras for use until calibrate_delay gets called. */ 28135499c01SPaul Mackerras loops_per_jiffy = 50000000 / HZ; 282a94fe366SRob Herring 283a94fe366SRob Herring for_each_of_cpu_node(cpu) { 284e2eb6392SStephen Rothwell fp = of_get_property(cpu, "clock-frequency", NULL); 28535499c01SPaul Mackerras if (fp != NULL) { 28635499c01SPaul Mackerras if (pvr >= 0x30 && pvr < 0x80) 28735499c01SPaul Mackerras /* PPC970 etc. */ 28835499c01SPaul Mackerras loops_per_jiffy = *fp / (3 * HZ); 28935499c01SPaul Mackerras else if (pvr == 4 || pvr >= 8) 29035499c01SPaul Mackerras /* 604, G3, G4 etc. */ 29135499c01SPaul Mackerras loops_per_jiffy = *fp / HZ; 29235499c01SPaul Mackerras else 29335499c01SPaul Mackerras /* 601, 603, etc. */ 29435499c01SPaul Mackerras loops_per_jiffy = *fp / (2 * HZ); 29535499c01SPaul Mackerras of_node_put(cpu); 296a94fe366SRob Herring break; 297a94fe366SRob Herring } 29835499c01SPaul Mackerras } 29935499c01SPaul Mackerras 300a575b807SPaul Mackerras /* See if newworld or oldworld */ 30122059a90SMichael Ellerman ic = of_find_node_with_property(NULL, "interrupt-controller"); 302d2515c80SOlaf Hering if (ic) { 303d2515c80SOlaf Hering pmac_newworld = 1; 304a575b807SPaul Mackerras of_node_put(ic); 305d2515c80SOlaf Hering } 306a575b807SPaul Mackerras 30735499c01SPaul Mackerras /* Lookup PCI hosts */ 30835499c01SPaul Mackerras pmac_pci_init(); 30935499c01SPaul Mackerras 31035499c01SPaul Mackerras #ifdef CONFIG_PPC32 31135499c01SPaul Mackerras ohare_init(); 31235499c01SPaul Mackerras l2cr_init(); 31335499c01SPaul Mackerras #endif /* CONFIG_PPC32 */ 31435499c01SPaul Mackerras 315f6d57916SPaul Mackerras find_via_cuda(); 316f6d57916SPaul Mackerras find_via_pmu(); 31735499c01SPaul Mackerras smu_init(); 31835499c01SPaul Mackerras 319*20e07af7SFinn Thain #if IS_ENABLED(CONFIG_NVRAM) 320f6d57916SPaul Mackerras pmac_nvram_init(); 321f6d57916SPaul Mackerras #endif 32235499c01SPaul Mackerras #ifdef CONFIG_PPC32 323f6d57916SPaul Mackerras #ifdef CONFIG_BLK_DEV_INITRD 324f6d57916SPaul Mackerras if (initrd_start) 325f6d57916SPaul Mackerras ROOT_DEV = Root_RAM0; 326f6d57916SPaul Mackerras else 327f6d57916SPaul Mackerras #endif 328f6d57916SPaul Mackerras ROOT_DEV = DEFAULT_ROOT_DEVICE; 32935499c01SPaul Mackerras #endif 330f6d57916SPaul Mackerras 331e8222502SBenjamin Herrenschmidt #ifdef CONFIG_ADB 3323e47d147SAnton Blanchard if (strstr(boot_command_line, "adb_sync")) { 333e8222502SBenjamin Herrenschmidt extern int __adb_probe_sync; 334e8222502SBenjamin Herrenschmidt __adb_probe_sync = 1; 335e8222502SBenjamin Herrenschmidt } 336e8222502SBenjamin Herrenschmidt #endif /* CONFIG_ADB */ 337f6d57916SPaul Mackerras } 338f6d57916SPaul Mackerras 339f6d57916SPaul Mackerras #ifdef CONFIG_SCSI 340405861a0SLi Yang void note_scsi_host(struct device_node *node, void *host) 341f6d57916SPaul Mackerras { 342f6d57916SPaul Mackerras } 343f6d57916SPaul Mackerras EXPORT_SYMBOL(note_scsi_host); 344f6d57916SPaul Mackerras #endif 345f6d57916SPaul Mackerras 34635499c01SPaul Mackerras static int initializing = 1; 34735499c01SPaul Mackerras 348f6d57916SPaul Mackerras static int pmac_late_init(void) 349f6d57916SPaul Mackerras { 350f6d57916SPaul Mackerras initializing = 0; 351f6d57916SPaul Mackerras return 0; 352f6d57916SPaul Mackerras } 353d518b717SGrant Likely machine_late_initcall(powermac, pmac_late_init); 354f6d57916SPaul Mackerras 355f72cf3f1SMathieu Malaterre void note_bootable_part(dev_t dev, int part, int goodness); 356d7418031SStephen Rothwell /* 357bd721ea7SFabian Frederick * This is __ref because we check for "initializing" before 358d7418031SStephen Rothwell * touching any of the __init sensitive things and "initializing" 359d7418031SStephen Rothwell * will be false after __init time. This can't be __init because it 360d7418031SStephen Rothwell * can be called whenever a disk is first accessed. 361d7418031SStephen Rothwell */ 362bd721ea7SFabian Frederick void __ref note_bootable_part(dev_t dev, int part, int goodness) 363f6d57916SPaul Mackerras { 364f6d57916SPaul Mackerras char *p; 365f6d57916SPaul Mackerras 366f6d57916SPaul Mackerras if (!initializing) 367f6d57916SPaul Mackerras return; 368f6d57916SPaul Mackerras if ((goodness <= current_root_goodness) && 369f6d57916SPaul Mackerras ROOT_DEV != DEFAULT_ROOT_DEVICE) 370f6d57916SPaul Mackerras return; 371b8757b21SAlon Bar-Lev p = strstr(boot_command_line, "root="); 372b8757b21SAlon Bar-Lev if (p != NULL && (p == boot_command_line || p[-1] == ' ')) 373f6d57916SPaul Mackerras return; 374f6d57916SPaul Mackerras 375f6d57916SPaul Mackerras ROOT_DEV = dev + part; 376f6d57916SPaul Mackerras current_root_goodness = goodness; 377f6d57916SPaul Mackerras } 378f6d57916SPaul Mackerras 37935499c01SPaul Mackerras #ifdef CONFIG_ADB_CUDA 38095ec77c0SDaniel Axtens static void __noreturn cuda_restart(void) 381f6d57916SPaul Mackerras { 382f6d57916SPaul Mackerras struct adb_request req; 383f6d57916SPaul Mackerras 38435499c01SPaul Mackerras cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM); 385f6d57916SPaul Mackerras for (;;) 386f6d57916SPaul Mackerras cuda_poll(); 38735499c01SPaul Mackerras } 38835499c01SPaul Mackerras 38995ec77c0SDaniel Axtens static void __noreturn cuda_shutdown(void) 39035499c01SPaul Mackerras { 39135499c01SPaul Mackerras struct adb_request req; 39235499c01SPaul Mackerras 39335499c01SPaul Mackerras cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN); 39435499c01SPaul Mackerras for (;;) 39535499c01SPaul Mackerras cuda_poll(); 39635499c01SPaul Mackerras } 39735499c01SPaul Mackerras 39835499c01SPaul Mackerras #else 39935499c01SPaul Mackerras #define cuda_restart() 40035499c01SPaul Mackerras #define cuda_shutdown() 40135499c01SPaul Mackerras #endif 40235499c01SPaul Mackerras 40335499c01SPaul Mackerras #ifndef CONFIG_ADB_PMU 40435499c01SPaul Mackerras #define pmu_restart() 40535499c01SPaul Mackerras #define pmu_shutdown() 40635499c01SPaul Mackerras #endif 40735499c01SPaul Mackerras 40835499c01SPaul Mackerras #ifndef CONFIG_PMAC_SMU 40935499c01SPaul Mackerras #define smu_restart() 41035499c01SPaul Mackerras #define smu_shutdown() 41135499c01SPaul Mackerras #endif 41235499c01SPaul Mackerras 41395ec77c0SDaniel Axtens static void __noreturn pmac_restart(char *cmd) 41435499c01SPaul Mackerras { 41535499c01SPaul Mackerras switch (sys_ctrler) { 41635499c01SPaul Mackerras case SYS_CTRLER_CUDA: 41735499c01SPaul Mackerras cuda_restart(); 418f6d57916SPaul Mackerras break; 419f6d57916SPaul Mackerras case SYS_CTRLER_PMU: 420f6d57916SPaul Mackerras pmu_restart(); 421f6d57916SPaul Mackerras break; 42235499c01SPaul Mackerras case SYS_CTRLER_SMU: 42335499c01SPaul Mackerras smu_restart(); 42435499c01SPaul Mackerras break; 425f6d57916SPaul Mackerras default: ; 426f6d57916SPaul Mackerras } 42795ec77c0SDaniel Axtens while (1) ; 428f6d57916SPaul Mackerras } 429f6d57916SPaul Mackerras 43095ec77c0SDaniel Axtens static void __noreturn pmac_power_off(void) 431f6d57916SPaul Mackerras { 432f6d57916SPaul Mackerras switch (sys_ctrler) { 433f6d57916SPaul Mackerras case SYS_CTRLER_CUDA: 43435499c01SPaul Mackerras cuda_shutdown(); 435f6d57916SPaul Mackerras break; 436f6d57916SPaul Mackerras case SYS_CTRLER_PMU: 437f6d57916SPaul Mackerras pmu_shutdown(); 438f6d57916SPaul Mackerras break; 43935499c01SPaul Mackerras case SYS_CTRLER_SMU: 44035499c01SPaul Mackerras smu_shutdown(); 44135499c01SPaul Mackerras break; 442f6d57916SPaul Mackerras default: ; 443f6d57916SPaul Mackerras } 44495ec77c0SDaniel Axtens while (1) ; 445f6d57916SPaul Mackerras } 446f6d57916SPaul Mackerras 44795ec77c0SDaniel Axtens static void __noreturn 448f6d57916SPaul Mackerras pmac_halt(void) 449f6d57916SPaul Mackerras { 450f6d57916SPaul Mackerras pmac_power_off(); 451f6d57916SPaul Mackerras } 452f6d57916SPaul Mackerras 45335499c01SPaul Mackerras /* 45435499c01SPaul Mackerras * Early initialization. 45535499c01SPaul Mackerras */ 456f2d57694SBenjamin Herrenschmidt static void __init pmac_init(void) 457f6d57916SPaul Mackerras { 45851d3082fSBenjamin Herrenschmidt /* Enable early btext debug if requested */ 4593e47d147SAnton Blanchard if (strstr(boot_command_line, "btextdbg")) { 46051d3082fSBenjamin Herrenschmidt udbg_adb_init_early(); 46151d3082fSBenjamin Herrenschmidt register_early_udbg_console(); 46235499c01SPaul Mackerras } 46335499c01SPaul Mackerras 46451d3082fSBenjamin Herrenschmidt /* Probe motherboard chipset */ 46551d3082fSBenjamin Herrenschmidt pmac_feature_init(); 46651d3082fSBenjamin Herrenschmidt 46751d3082fSBenjamin Herrenschmidt /* Initialize debug stuff */ 4683e47d147SAnton Blanchard udbg_scc_init(!!strstr(boot_command_line, "sccdbg")); 4693e47d147SAnton Blanchard udbg_adb_init(!!strstr(boot_command_line, "btextdbg")); 47051d3082fSBenjamin Herrenschmidt 47151d3082fSBenjamin Herrenschmidt #ifdef CONFIG_PPC64 472e63f26d3SDaniel Axtens iommu_init_early_dart(&pmac_pci_controller_ops); 47335499c01SPaul Mackerras #endif 4747ccbe504SBenjamin Herrenschmidt 4757ccbe504SBenjamin Herrenschmidt /* SMP Init has to be done early as we need to patch up 476828a6986SAnton Blanchard * cpu_possible_mask before interrupt stacks are allocated 4777ccbe504SBenjamin Herrenschmidt * or kaboom... 4787ccbe504SBenjamin Herrenschmidt */ 4797ccbe504SBenjamin Herrenschmidt #ifdef CONFIG_SMP 4807ccbe504SBenjamin Herrenschmidt pmac_setup_smp(); 4817ccbe504SBenjamin Herrenschmidt #endif 48235499c01SPaul Mackerras } 48335499c01SPaul Mackerras 48435499c01SPaul Mackerras static int __init pmac_declare_of_platform_devices(void) 485f6d57916SPaul Mackerras { 486a28d3af2SBenjamin Herrenschmidt struct device_node *np; 487f6d57916SPaul Mackerras 488730745a5SBenjamin Herrenschmidt np = of_find_node_by_name(NULL, "valkyrie"); 4893631cb83SJulia Lawall if (np) { 49035499c01SPaul Mackerras of_platform_device_create(np, "valkyrie", NULL); 4913631cb83SJulia Lawall of_node_put(np); 4923631cb83SJulia Lawall } 493730745a5SBenjamin Herrenschmidt np = of_find_node_by_name(NULL, "platinum"); 4943631cb83SJulia Lawall if (np) { 49535499c01SPaul Mackerras of_platform_device_create(np, "platinum", NULL); 4963631cb83SJulia Lawall of_node_put(np); 4973631cb83SJulia Lawall } 49835499c01SPaul Mackerras np = of_find_node_by_type(NULL, "smu"); 49935499c01SPaul Mackerras if (np) { 50035499c01SPaul Mackerras of_platform_device_create(np, "smu", NULL); 50135499c01SPaul Mackerras of_node_put(np); 50235499c01SPaul Mackerras } 50398b14d6bSMarc Zyngier np = of_find_node_by_type(NULL, "fcu"); 50498b14d6bSMarc Zyngier if (np == NULL) { 50598b14d6bSMarc Zyngier /* Some machines have strangely broken device-tree */ 50698b14d6bSMarc Zyngier np = of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/fan@15e"); 50798b14d6bSMarc Zyngier } 50898b14d6bSMarc Zyngier if (np) { 50998b14d6bSMarc Zyngier of_platform_device_create(np, "temperature", NULL); 51098b14d6bSMarc Zyngier of_node_put(np); 51198b14d6bSMarc Zyngier } 512f6d57916SPaul Mackerras 513f6d57916SPaul Mackerras return 0; 514f6d57916SPaul Mackerras } 515d518b717SGrant Likely machine_device_initcall(powermac, pmac_declare_of_platform_devices); 51635499c01SPaul Mackerras 517025d7917SBenjamin Herrenschmidt #ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE 518025d7917SBenjamin Herrenschmidt /* 519025d7917SBenjamin Herrenschmidt * This is called very early, as part of console_init() (typically just after 520025d7917SBenjamin Herrenschmidt * time_init()). This function is respondible for trying to find a good 521025d7917SBenjamin Herrenschmidt * default console on serial ports. It tries to match the open firmware 522025d7917SBenjamin Herrenschmidt * default output with one of the available serial console drivers. 523025d7917SBenjamin Herrenschmidt */ 524025d7917SBenjamin Herrenschmidt static int __init check_pmac_serial_console(void) 525025d7917SBenjamin Herrenschmidt { 526025d7917SBenjamin Herrenschmidt struct device_node *prom_stdout = NULL; 527025d7917SBenjamin Herrenschmidt int offset = 0; 528025d7917SBenjamin Herrenschmidt const char *name; 529025d7917SBenjamin Herrenschmidt #ifdef CONFIG_SERIAL_PMACZILOG_TTYS 530025d7917SBenjamin Herrenschmidt char *devname = "ttyS"; 531025d7917SBenjamin Herrenschmidt #else 532025d7917SBenjamin Herrenschmidt char *devname = "ttyPZ"; 533025d7917SBenjamin Herrenschmidt #endif 534025d7917SBenjamin Herrenschmidt 535025d7917SBenjamin Herrenschmidt pr_debug(" -> check_pmac_serial_console()\n"); 536025d7917SBenjamin Herrenschmidt 537025d7917SBenjamin Herrenschmidt /* The user has requested a console so this is already set up. */ 538025d7917SBenjamin Herrenschmidt if (strstr(boot_command_line, "console=")) { 539025d7917SBenjamin Herrenschmidt pr_debug(" console was specified !\n"); 540025d7917SBenjamin Herrenschmidt return -EBUSY; 541025d7917SBenjamin Herrenschmidt } 542025d7917SBenjamin Herrenschmidt 543025d7917SBenjamin Herrenschmidt if (!of_chosen) { 544025d7917SBenjamin Herrenschmidt pr_debug(" of_chosen is NULL !\n"); 545025d7917SBenjamin Herrenschmidt return -ENODEV; 546025d7917SBenjamin Herrenschmidt } 547025d7917SBenjamin Herrenschmidt 548025d7917SBenjamin Herrenschmidt /* We are getting a weird phandle from OF ... */ 549025d7917SBenjamin Herrenschmidt /* ... So use the full path instead */ 550025d7917SBenjamin Herrenschmidt name = of_get_property(of_chosen, "linux,stdout-path", NULL); 551025d7917SBenjamin Herrenschmidt if (name == NULL) { 552025d7917SBenjamin Herrenschmidt pr_debug(" no linux,stdout-path !\n"); 553025d7917SBenjamin Herrenschmidt return -ENODEV; 554025d7917SBenjamin Herrenschmidt } 555025d7917SBenjamin Herrenschmidt prom_stdout = of_find_node_by_path(name); 556025d7917SBenjamin Herrenschmidt if (!prom_stdout) { 557025d7917SBenjamin Herrenschmidt pr_debug(" can't find stdout package %s !\n", name); 558025d7917SBenjamin Herrenschmidt return -ENODEV; 559025d7917SBenjamin Herrenschmidt } 560b7c670d6SRob Herring pr_debug("stdout is %pOF\n", prom_stdout); 561025d7917SBenjamin Herrenschmidt 5622c8e65b5SRob Herring if (of_node_name_eq(prom_stdout, "ch-a")) 563025d7917SBenjamin Herrenschmidt offset = 0; 5642c8e65b5SRob Herring else if (of_node_name_eq(prom_stdout, "ch-b")) 565025d7917SBenjamin Herrenschmidt offset = 1; 566025d7917SBenjamin Herrenschmidt else 567025d7917SBenjamin Herrenschmidt goto not_found; 568025d7917SBenjamin Herrenschmidt of_node_put(prom_stdout); 569025d7917SBenjamin Herrenschmidt 570025d7917SBenjamin Herrenschmidt pr_debug("Found serial console at %s%d\n", devname, offset); 571025d7917SBenjamin Herrenschmidt 572025d7917SBenjamin Herrenschmidt return add_preferred_console(devname, offset, NULL); 573025d7917SBenjamin Herrenschmidt 574025d7917SBenjamin Herrenschmidt not_found: 575025d7917SBenjamin Herrenschmidt pr_debug("No preferred console found !\n"); 576025d7917SBenjamin Herrenschmidt of_node_put(prom_stdout); 577025d7917SBenjamin Herrenschmidt return -ENODEV; 578025d7917SBenjamin Herrenschmidt } 579025d7917SBenjamin Herrenschmidt console_initcall(check_pmac_serial_console); 580025d7917SBenjamin Herrenschmidt 581025d7917SBenjamin Herrenschmidt #endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */ 582025d7917SBenjamin Herrenschmidt 58335499c01SPaul Mackerras /* 58435499c01SPaul Mackerras * Called very early, MMU is off, device-tree isn't unflattened 58535499c01SPaul Mackerras */ 586e8222502SBenjamin Herrenschmidt static int __init pmac_probe(void) 58735499c01SPaul Mackerras { 588406b0b6aSBenjamin Herrenschmidt if (!of_machine_is_compatible("Power Macintosh") && 589406b0b6aSBenjamin Herrenschmidt !of_machine_is_compatible("MacRISC")) 590406b0b6aSBenjamin Herrenschmidt return 0; 59135499c01SPaul Mackerras 592e8222502SBenjamin Herrenschmidt #ifdef CONFIG_PPC32 593e8222502SBenjamin Herrenschmidt /* isa_io_base gets set in pmac_pci_init */ 594e8222502SBenjamin Herrenschmidt ISA_DMA_THRESHOLD = ~0L; 595e8222502SBenjamin Herrenschmidt DMA_MODE_READ = 1; 596e8222502SBenjamin Herrenschmidt DMA_MODE_WRITE = 2; 597e8222502SBenjamin Herrenschmidt #endif /* CONFIG_PPC32 */ 598e8222502SBenjamin Herrenschmidt 5999178ba29SAlexander Graf pm_power_off = pmac_power_off; 6009178ba29SAlexander Graf 601f2d57694SBenjamin Herrenschmidt pmac_init(); 602f2d57694SBenjamin Herrenschmidt 60335499c01SPaul Mackerras return 1; 60435499c01SPaul Mackerras } 60535499c01SPaul Mackerras 606e8222502SBenjamin Herrenschmidt define_machine(powermac) { 607e8222502SBenjamin Herrenschmidt .name = "PowerMac", 60835499c01SPaul Mackerras .probe = pmac_probe, 60935499c01SPaul Mackerras .setup_arch = pmac_setup_arch, 61035499c01SPaul Mackerras .show_cpuinfo = pmac_show_cpuinfo, 61135499c01SPaul Mackerras .init_IRQ = pmac_pic_init, 612cc5d0189SBenjamin Herrenschmidt .get_irq = NULL, /* changed later */ 613f90bb153SBenjamin Herrenschmidt .pci_irq_fixup = pmac_pci_irq_fixup, 61435499c01SPaul Mackerras .restart = pmac_restart, 61535499c01SPaul Mackerras .halt = pmac_halt, 61635499c01SPaul Mackerras .time_init = pmac_time_init, 61735499c01SPaul Mackerras .get_boot_time = pmac_get_boot_time, 61835499c01SPaul Mackerras .set_rtc_time = pmac_set_rtc_time, 61935499c01SPaul Mackerras .get_rtc_time = pmac_get_rtc_time, 62035499c01SPaul Mackerras .calibrate_decr = pmac_calibrate_decr, 62135499c01SPaul Mackerras .feature_call = pmac_do_feature_call, 622be6b8439SKumar Gala .progress = udbg_progress, 62335499c01SPaul Mackerras #ifdef CONFIG_PPC64 624a0652fc9SPaul Mackerras .power_save = power4_idle, 62535499c01SPaul Mackerras .enable_pmcs = power4_enable_pmcs, 6263d1229d6SMichael Ellerman #endif /* CONFIG_PPC64 */ 62735499c01SPaul Mackerras #ifdef CONFIG_PPC32 62835499c01SPaul Mackerras .pcibios_after_init = pmac_pcibios_after_init, 62935499c01SPaul Mackerras .phys_mem_access_prot = pci_phys_mem_access_prot, 63035499c01SPaul Mackerras #endif 63135499c01SPaul Mackerras }; 632