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> 5595f72d1eSYinghai Lu #include <linux/memblock.h> 56f6d57916SPaul Mackerras 57f6d57916SPaul Mackerras #include <asm/reg.h> 58f6d57916SPaul Mackerras #include <asm/sections.h> 59f6d57916SPaul Mackerras #include <asm/prom.h> 60f6d57916SPaul Mackerras #include <asm/pgtable.h> 61f6d57916SPaul Mackerras #include <asm/io.h> 62f6d57916SPaul Mackerras #include <asm/pci-bridge.h> 63f6d57916SPaul Mackerras #include <asm/ohare.h> 64f6d57916SPaul Mackerras #include <asm/mediabay.h> 65f6d57916SPaul Mackerras #include <asm/machdep.h> 66f6d57916SPaul Mackerras #include <asm/dma.h> 67f6d57916SPaul Mackerras #include <asm/cputable.h> 68f6d57916SPaul Mackerras #include <asm/btext.h> 69f6d57916SPaul Mackerras #include <asm/pmac_feature.h> 70f6d57916SPaul Mackerras #include <asm/time.h> 71f6d57916SPaul Mackerras #include <asm/mmu_context.h> 7235499c01SPaul Mackerras #include <asm/iommu.h> 7335499c01SPaul Mackerras #include <asm/smu.h> 7435499c01SPaul Mackerras #include <asm/pmc.h> 7551d3082fSBenjamin Herrenschmidt #include <asm/udbg.h> 76f6d57916SPaul Mackerras 773c3f42d6SPaul Mackerras #include "pmac.h" 78f6d57916SPaul Mackerras 79f6d57916SPaul Mackerras #undef SHOW_GATWICK_IRQS 80f6d57916SPaul Mackerras 81f6d57916SPaul Mackerras int ppc_override_l2cr = 0; 82f6d57916SPaul Mackerras int ppc_override_l2cr_value; 83f6d57916SPaul Mackerras int has_l2cache = 0; 84f6d57916SPaul Mackerras 85d2515c80SOlaf Hering int pmac_newworld; 86f6d57916SPaul Mackerras 87f6d57916SPaul Mackerras static int current_root_goodness = -1; 88f6d57916SPaul Mackerras 8935499c01SPaul Mackerras extern struct machdep_calls pmac_md; 90f6d57916SPaul Mackerras 91f6d57916SPaul Mackerras #define DEFAULT_ROOT_DEVICE Root_SDA1 /* sda1 - slightly silly choice */ 92f6d57916SPaul Mackerras 9335499c01SPaul Mackerras #ifdef CONFIG_PPC64 9435499c01SPaul Mackerras int sccdbg; 95f6d57916SPaul Mackerras #endif 96f6d57916SPaul Mackerras 97f6d57916SPaul Mackerras sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN; 9835499c01SPaul Mackerras EXPORT_SYMBOL(sys_ctrler); 9935499c01SPaul Mackerras 10035499c01SPaul Mackerras #ifdef CONFIG_PMAC_SMU 10135499c01SPaul Mackerras unsigned long smu_cmdbuf_abs; 10235499c01SPaul Mackerras EXPORT_SYMBOL(smu_cmdbuf_abs); 10335499c01SPaul Mackerras #endif 104f6d57916SPaul Mackerras 1050dd194d0SPaul Mackerras static void pmac_show_cpuinfo(struct seq_file *m) 106f6d57916SPaul Mackerras { 107f6d57916SPaul Mackerras struct device_node *np; 108018a3d1dSJeremy Kerr const char *pp; 109f6d57916SPaul Mackerras int plen; 1100dd194d0SPaul Mackerras int mbmodel; 1110dd194d0SPaul Mackerras unsigned int mbflags; 112f6d57916SPaul Mackerras char* mbname; 113f6d57916SPaul Mackerras 1140dd194d0SPaul Mackerras mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, 1150dd194d0SPaul Mackerras PMAC_MB_INFO_MODEL, 0); 1160dd194d0SPaul Mackerras mbflags = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, 1170dd194d0SPaul Mackerras PMAC_MB_INFO_FLAGS, 0); 1180dd194d0SPaul Mackerras if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME, 1190dd194d0SPaul Mackerras (long) &mbname) != 0) 120f6d57916SPaul Mackerras mbname = "Unknown"; 121f6d57916SPaul Mackerras 122f6d57916SPaul Mackerras /* find motherboard type */ 123f6d57916SPaul Mackerras seq_printf(m, "machine\t\t: "); 1240dd194d0SPaul Mackerras np = of_find_node_by_path("/"); 125f6d57916SPaul Mackerras if (np != NULL) { 126e2eb6392SStephen Rothwell pp = of_get_property(np, "model", NULL); 127f6d57916SPaul Mackerras if (pp != NULL) 128f6d57916SPaul Mackerras seq_printf(m, "%s\n", pp); 129f6d57916SPaul Mackerras else 130f6d57916SPaul Mackerras seq_printf(m, "PowerMac\n"); 131e2eb6392SStephen Rothwell pp = of_get_property(np, "compatible", &plen); 132f6d57916SPaul Mackerras if (pp != NULL) { 133f6d57916SPaul Mackerras seq_printf(m, "motherboard\t:"); 134f6d57916SPaul Mackerras while (plen > 0) { 135f6d57916SPaul Mackerras int l = strlen(pp) + 1; 136f6d57916SPaul Mackerras seq_printf(m, " %s", pp); 137f6d57916SPaul Mackerras plen -= l; 138f6d57916SPaul Mackerras pp += l; 139f6d57916SPaul Mackerras } 140f6d57916SPaul Mackerras seq_printf(m, "\n"); 141f6d57916SPaul Mackerras } 1420dd194d0SPaul Mackerras of_node_put(np); 143f6d57916SPaul Mackerras } else 144f6d57916SPaul Mackerras seq_printf(m, "PowerMac\n"); 145f6d57916SPaul Mackerras 146f6d57916SPaul Mackerras /* print parsed model */ 147f6d57916SPaul Mackerras seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname); 148f6d57916SPaul Mackerras seq_printf(m, "pmac flags\t: %08x\n", mbflags); 149f6d57916SPaul Mackerras 150f6d57916SPaul Mackerras /* find l2 cache info */ 1510dd194d0SPaul Mackerras np = of_find_node_by_name(NULL, "l2-cache"); 1520dd194d0SPaul Mackerras if (np == NULL) 1530dd194d0SPaul Mackerras np = of_find_node_by_type(NULL, "cache"); 1540dd194d0SPaul Mackerras if (np != NULL) { 155e2eb6392SStephen Rothwell const unsigned int *ic = 156e2eb6392SStephen Rothwell of_get_property(np, "i-cache-size", NULL); 157e2eb6392SStephen Rothwell const unsigned int *dc = 158e2eb6392SStephen Rothwell of_get_property(np, "d-cache-size", NULL); 159f6d57916SPaul Mackerras seq_printf(m, "L2 cache\t:"); 160f6d57916SPaul Mackerras has_l2cache = 1; 161e2eb6392SStephen Rothwell if (of_get_property(np, "cache-unified", NULL) != 0 && dc) { 162f6d57916SPaul Mackerras seq_printf(m, " %dK unified", *dc / 1024); 163f6d57916SPaul Mackerras } else { 164f6d57916SPaul Mackerras if (ic) 165f6d57916SPaul Mackerras seq_printf(m, " %dK instruction", *ic / 1024); 166f6d57916SPaul Mackerras if (dc) 167f6d57916SPaul Mackerras seq_printf(m, "%s %dK data", 168f6d57916SPaul Mackerras (ic? " +": ""), *dc / 1024); 169f6d57916SPaul Mackerras } 170e2eb6392SStephen Rothwell pp = of_get_property(np, "ram-type", NULL); 171f6d57916SPaul Mackerras if (pp) 172f6d57916SPaul Mackerras seq_printf(m, " %s", pp); 173f6d57916SPaul Mackerras seq_printf(m, "\n"); 1740dd194d0SPaul Mackerras of_node_put(np); 175f6d57916SPaul Mackerras } 176f6d57916SPaul Mackerras 177f6d57916SPaul Mackerras /* Indicate newworld/oldworld */ 178f6d57916SPaul Mackerras seq_printf(m, "pmac-generation\t: %s\n", 179f6d57916SPaul Mackerras pmac_newworld ? "NewWorld" : "OldWorld"); 180f6d57916SPaul Mackerras } 181f6d57916SPaul Mackerras 18235499c01SPaul Mackerras #ifndef CONFIG_ADB_CUDA 18335499c01SPaul Mackerras int find_via_cuda(void) 18435499c01SPaul Mackerras { 18530686ba6SStephen Rothwell struct device_node *dn = of_find_node_by_name(NULL, "via-cuda"); 18630686ba6SStephen Rothwell 18730686ba6SStephen Rothwell if (!dn) 18835499c01SPaul Mackerras return 0; 18930686ba6SStephen Rothwell of_node_put(dn); 19035499c01SPaul Mackerras printk("WARNING ! Your machine is CUDA-based but your kernel\n"); 19135499c01SPaul Mackerras printk(" wasn't compiled with CONFIG_ADB_CUDA option !\n"); 19235499c01SPaul Mackerras return 0; 19335499c01SPaul Mackerras } 19435499c01SPaul Mackerras #endif 19535499c01SPaul Mackerras 19635499c01SPaul Mackerras #ifndef CONFIG_ADB_PMU 19735499c01SPaul Mackerras int find_via_pmu(void) 19835499c01SPaul Mackerras { 19930686ba6SStephen Rothwell struct device_node *dn = of_find_node_by_name(NULL, "via-pmu"); 20030686ba6SStephen Rothwell 20130686ba6SStephen Rothwell if (!dn) 20235499c01SPaul Mackerras return 0; 20330686ba6SStephen Rothwell of_node_put(dn); 20435499c01SPaul Mackerras printk("WARNING ! Your machine is PMU-based but your kernel\n"); 20535499c01SPaul Mackerras printk(" wasn't compiled with CONFIG_ADB_PMU option !\n"); 206a575b807SPaul Mackerras return 0; 20735499c01SPaul Mackerras } 20835499c01SPaul Mackerras #endif 20935499c01SPaul Mackerras 21035499c01SPaul Mackerras #ifndef CONFIG_PMAC_SMU 21135499c01SPaul Mackerras int smu_init(void) 21235499c01SPaul Mackerras { 21335499c01SPaul Mackerras /* should check and warn if SMU is present */ 21435499c01SPaul Mackerras return 0; 21535499c01SPaul Mackerras } 21635499c01SPaul Mackerras #endif 21735499c01SPaul Mackerras 21835499c01SPaul Mackerras #ifdef CONFIG_PPC32 219f6d57916SPaul Mackerras static volatile u32 *sysctrl_regs; 220f6d57916SPaul Mackerras 22135499c01SPaul Mackerras static void __init ohare_init(void) 222f6d57916SPaul Mackerras { 22330686ba6SStephen Rothwell struct device_node *dn; 22430686ba6SStephen Rothwell 225f6d57916SPaul Mackerras /* this area has the CPU identification register 226f6d57916SPaul Mackerras and some registers used by smp boards */ 227f6d57916SPaul Mackerras sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000); 228f6d57916SPaul Mackerras 22935499c01SPaul Mackerras /* 23035499c01SPaul Mackerras * Turn on the L2 cache. 23135499c01SPaul Mackerras * We assume that we have a PSX memory controller iff 23235499c01SPaul Mackerras * we have an ohare I/O controller. 23335499c01SPaul Mackerras */ 23430686ba6SStephen Rothwell dn = of_find_node_by_name(NULL, "ohare"); 23530686ba6SStephen Rothwell if (dn) { 23630686ba6SStephen Rothwell of_node_put(dn); 23735499c01SPaul Mackerras if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) { 23835499c01SPaul Mackerras if (sysctrl_regs[4] & 0x10) 23935499c01SPaul Mackerras sysctrl_regs[4] |= 0x04000020; 24035499c01SPaul Mackerras else 24135499c01SPaul Mackerras sysctrl_regs[4] |= 0x04000000; 24235499c01SPaul Mackerras if(has_l2cache) 24335499c01SPaul Mackerras printk(KERN_INFO "Level 2 cache enabled\n"); 24435499c01SPaul Mackerras } 24535499c01SPaul Mackerras } 24635499c01SPaul Mackerras } 247f6d57916SPaul Mackerras 24835499c01SPaul Mackerras static void __init l2cr_init(void) 24935499c01SPaul Mackerras { 250f6d57916SPaul Mackerras /* Checks "l2cr-value" property in the registry */ 251f6d57916SPaul Mackerras if (cpu_has_feature(CPU_FTR_L2CR)) { 2521658ab66SStephen Rothwell struct device_node *np = of_find_node_by_name(NULL, "cpus"); 253f6d57916SPaul Mackerras if (np == 0) 2541658ab66SStephen Rothwell np = of_find_node_by_type(NULL, "cpu"); 255f6d57916SPaul Mackerras if (np != 0) { 256018a3d1dSJeremy Kerr const unsigned int *l2cr = 257e2eb6392SStephen Rothwell of_get_property(np, "l2cr-value", NULL); 258f6d57916SPaul Mackerras if (l2cr != 0) { 259f6d57916SPaul Mackerras ppc_override_l2cr = 1; 260f6d57916SPaul Mackerras ppc_override_l2cr_value = *l2cr; 261f6d57916SPaul Mackerras _set_L2CR(0); 262f6d57916SPaul Mackerras _set_L2CR(ppc_override_l2cr_value); 263f6d57916SPaul Mackerras } 2641658ab66SStephen Rothwell of_node_put(np); 265f6d57916SPaul Mackerras } 266f6d57916SPaul Mackerras } 267f6d57916SPaul Mackerras 268f6d57916SPaul Mackerras if (ppc_override_l2cr) 26935499c01SPaul Mackerras printk(KERN_INFO "L2CR overridden (0x%x), " 27035499c01SPaul Mackerras "backside cache is %s\n", 27135499c01SPaul Mackerras ppc_override_l2cr_value, 27235499c01SPaul Mackerras (ppc_override_l2cr_value & 0x80000000) 273f6d57916SPaul Mackerras ? "enabled" : "disabled"); 27435499c01SPaul Mackerras } 27535499c01SPaul Mackerras #endif 27635499c01SPaul Mackerras 277ff38e7c8SArnd Bergmann static void __init pmac_setup_arch(void) 27835499c01SPaul Mackerras { 279a575b807SPaul Mackerras struct device_node *cpu, *ic; 280018a3d1dSJeremy Kerr const int *fp; 28135499c01SPaul Mackerras unsigned long pvr; 28235499c01SPaul Mackerras 28335499c01SPaul Mackerras pvr = PVR_VER(mfspr(SPRN_PVR)); 28435499c01SPaul Mackerras 28535499c01SPaul Mackerras /* Set loops_per_jiffy to a half-way reasonable value, 28635499c01SPaul Mackerras for use until calibrate_delay gets called. */ 28735499c01SPaul Mackerras loops_per_jiffy = 50000000 / HZ; 28835499c01SPaul Mackerras cpu = of_find_node_by_type(NULL, "cpu"); 28935499c01SPaul Mackerras if (cpu != NULL) { 290e2eb6392SStephen Rothwell fp = of_get_property(cpu, "clock-frequency", NULL); 29135499c01SPaul Mackerras if (fp != NULL) { 29235499c01SPaul Mackerras if (pvr >= 0x30 && pvr < 0x80) 29335499c01SPaul Mackerras /* PPC970 etc. */ 29435499c01SPaul Mackerras loops_per_jiffy = *fp / (3 * HZ); 29535499c01SPaul Mackerras else if (pvr == 4 || pvr >= 8) 29635499c01SPaul Mackerras /* 604, G3, G4 etc. */ 29735499c01SPaul Mackerras loops_per_jiffy = *fp / HZ; 29835499c01SPaul Mackerras else 29935499c01SPaul Mackerras /* 601, 603, etc. */ 30035499c01SPaul Mackerras loops_per_jiffy = *fp / (2 * HZ); 30135499c01SPaul Mackerras } 30235499c01SPaul Mackerras of_node_put(cpu); 30335499c01SPaul Mackerras } 30435499c01SPaul Mackerras 305a575b807SPaul Mackerras /* See if newworld or oldworld */ 30622059a90SMichael Ellerman ic = of_find_node_with_property(NULL, "interrupt-controller"); 307d2515c80SOlaf Hering if (ic) { 308d2515c80SOlaf Hering pmac_newworld = 1; 309a575b807SPaul Mackerras of_node_put(ic); 310d2515c80SOlaf Hering } 311a575b807SPaul Mackerras 31235499c01SPaul Mackerras /* Lookup PCI hosts */ 31335499c01SPaul Mackerras pmac_pci_init(); 31435499c01SPaul Mackerras 31535499c01SPaul Mackerras #ifdef CONFIG_PPC32 31635499c01SPaul Mackerras ohare_init(); 31735499c01SPaul Mackerras l2cr_init(); 31835499c01SPaul Mackerras #endif /* CONFIG_PPC32 */ 31935499c01SPaul Mackerras 320f6d57916SPaul Mackerras find_via_cuda(); 321f6d57916SPaul Mackerras find_via_pmu(); 32235499c01SPaul Mackerras smu_init(); 32335499c01SPaul Mackerras 32421e38dfeSTony Breeds #if defined(CONFIG_NVRAM) || defined(CONFIG_NVRAM_MODULE) || \ 32521e38dfeSTony Breeds defined(CONFIG_PPC64) 326f6d57916SPaul Mackerras pmac_nvram_init(); 327f6d57916SPaul Mackerras #endif 32835499c01SPaul Mackerras 32935499c01SPaul Mackerras #ifdef CONFIG_PPC32 330f6d57916SPaul Mackerras #ifdef CONFIG_BLK_DEV_INITRD 331f6d57916SPaul Mackerras if (initrd_start) 332f6d57916SPaul Mackerras ROOT_DEV = Root_RAM0; 333f6d57916SPaul Mackerras else 334f6d57916SPaul Mackerras #endif 335f6d57916SPaul Mackerras ROOT_DEV = DEFAULT_ROOT_DEVICE; 33635499c01SPaul Mackerras #endif 337f6d57916SPaul Mackerras 338e8222502SBenjamin Herrenschmidt #ifdef CONFIG_ADB 3393e47d147SAnton Blanchard if (strstr(boot_command_line, "adb_sync")) { 340e8222502SBenjamin Herrenschmidt extern int __adb_probe_sync; 341e8222502SBenjamin Herrenschmidt __adb_probe_sync = 1; 342e8222502SBenjamin Herrenschmidt } 343e8222502SBenjamin Herrenschmidt #endif /* CONFIG_ADB */ 344f6d57916SPaul Mackerras } 345f6d57916SPaul Mackerras 346f6d57916SPaul Mackerras #ifdef CONFIG_SCSI 347405861a0SLi Yang void note_scsi_host(struct device_node *node, void *host) 348f6d57916SPaul Mackerras { 349f6d57916SPaul Mackerras } 350f6d57916SPaul Mackerras EXPORT_SYMBOL(note_scsi_host); 351f6d57916SPaul Mackerras #endif 352f6d57916SPaul Mackerras 35335499c01SPaul Mackerras static int initializing = 1; 35435499c01SPaul Mackerras 355f6d57916SPaul Mackerras static int pmac_late_init(void) 356f6d57916SPaul Mackerras { 357f6d57916SPaul Mackerras initializing = 0; 358f6d57916SPaul Mackerras return 0; 359f6d57916SPaul Mackerras } 360d518b717SGrant Likely machine_late_initcall(powermac, pmac_late_init); 361f6d57916SPaul Mackerras 362d7418031SStephen Rothwell /* 363d7418031SStephen Rothwell * This is __init_refok because we check for "initializing" before 364d7418031SStephen Rothwell * touching any of the __init sensitive things and "initializing" 365d7418031SStephen Rothwell * will be false after __init time. This can't be __init because it 366d7418031SStephen Rothwell * can be called whenever a disk is first accessed. 367d7418031SStephen Rothwell */ 368d7418031SStephen Rothwell void __init_refok note_bootable_part(dev_t dev, int part, int goodness) 369f6d57916SPaul Mackerras { 370f6d57916SPaul Mackerras char *p; 371f6d57916SPaul Mackerras 372f6d57916SPaul Mackerras if (!initializing) 373f6d57916SPaul Mackerras return; 374f6d57916SPaul Mackerras if ((goodness <= current_root_goodness) && 375f6d57916SPaul Mackerras ROOT_DEV != DEFAULT_ROOT_DEVICE) 376f6d57916SPaul Mackerras return; 377b8757b21SAlon Bar-Lev p = strstr(boot_command_line, "root="); 378b8757b21SAlon Bar-Lev if (p != NULL && (p == boot_command_line || p[-1] == ' ')) 379f6d57916SPaul Mackerras return; 380f6d57916SPaul Mackerras 381f6d57916SPaul Mackerras ROOT_DEV = dev + part; 382f6d57916SPaul Mackerras current_root_goodness = goodness; 383f6d57916SPaul Mackerras } 384f6d57916SPaul Mackerras 38535499c01SPaul Mackerras #ifdef CONFIG_ADB_CUDA 38635499c01SPaul Mackerras static void cuda_restart(void) 387f6d57916SPaul Mackerras { 388f6d57916SPaul Mackerras struct adb_request req; 389f6d57916SPaul Mackerras 39035499c01SPaul Mackerras cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM); 391f6d57916SPaul Mackerras for (;;) 392f6d57916SPaul Mackerras cuda_poll(); 39335499c01SPaul Mackerras } 39435499c01SPaul Mackerras 39535499c01SPaul Mackerras static void cuda_shutdown(void) 39635499c01SPaul Mackerras { 39735499c01SPaul Mackerras struct adb_request req; 39835499c01SPaul Mackerras 39935499c01SPaul Mackerras cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN); 40035499c01SPaul Mackerras for (;;) 40135499c01SPaul Mackerras cuda_poll(); 40235499c01SPaul Mackerras } 40335499c01SPaul Mackerras 40435499c01SPaul Mackerras #else 40535499c01SPaul Mackerras #define cuda_restart() 40635499c01SPaul Mackerras #define cuda_shutdown() 40735499c01SPaul Mackerras #endif 40835499c01SPaul Mackerras 40935499c01SPaul Mackerras #ifndef CONFIG_ADB_PMU 41035499c01SPaul Mackerras #define pmu_restart() 41135499c01SPaul Mackerras #define pmu_shutdown() 41235499c01SPaul Mackerras #endif 41335499c01SPaul Mackerras 41435499c01SPaul Mackerras #ifndef CONFIG_PMAC_SMU 41535499c01SPaul Mackerras #define smu_restart() 41635499c01SPaul Mackerras #define smu_shutdown() 41735499c01SPaul Mackerras #endif 41835499c01SPaul Mackerras 41935499c01SPaul Mackerras static void pmac_restart(char *cmd) 42035499c01SPaul Mackerras { 42135499c01SPaul Mackerras switch (sys_ctrler) { 42235499c01SPaul Mackerras case SYS_CTRLER_CUDA: 42335499c01SPaul Mackerras cuda_restart(); 424f6d57916SPaul Mackerras break; 425f6d57916SPaul Mackerras case SYS_CTRLER_PMU: 426f6d57916SPaul Mackerras pmu_restart(); 427f6d57916SPaul Mackerras break; 42835499c01SPaul Mackerras case SYS_CTRLER_SMU: 42935499c01SPaul Mackerras smu_restart(); 43035499c01SPaul Mackerras break; 431f6d57916SPaul Mackerras default: ; 432f6d57916SPaul Mackerras } 433f6d57916SPaul Mackerras } 434f6d57916SPaul Mackerras 43535499c01SPaul Mackerras static void pmac_power_off(void) 436f6d57916SPaul Mackerras { 437f6d57916SPaul Mackerras switch (sys_ctrler) { 438f6d57916SPaul Mackerras case SYS_CTRLER_CUDA: 43935499c01SPaul Mackerras cuda_shutdown(); 440f6d57916SPaul Mackerras break; 441f6d57916SPaul Mackerras case SYS_CTRLER_PMU: 442f6d57916SPaul Mackerras pmu_shutdown(); 443f6d57916SPaul Mackerras break; 44435499c01SPaul Mackerras case SYS_CTRLER_SMU: 44535499c01SPaul Mackerras smu_shutdown(); 44635499c01SPaul Mackerras break; 447f6d57916SPaul Mackerras default: ; 448f6d57916SPaul Mackerras } 449f6d57916SPaul Mackerras } 450f6d57916SPaul Mackerras 451f6d57916SPaul Mackerras static void 452f6d57916SPaul Mackerras pmac_halt(void) 453f6d57916SPaul Mackerras { 454f6d57916SPaul Mackerras pmac_power_off(); 455f6d57916SPaul Mackerras } 456f6d57916SPaul Mackerras 45735499c01SPaul Mackerras /* 45835499c01SPaul Mackerras * Early initialization. 45935499c01SPaul Mackerras */ 46035499c01SPaul Mackerras static void __init pmac_init_early(void) 461f6d57916SPaul Mackerras { 46251d3082fSBenjamin Herrenschmidt /* Enable early btext debug if requested */ 4633e47d147SAnton Blanchard if (strstr(boot_command_line, "btextdbg")) { 46451d3082fSBenjamin Herrenschmidt udbg_adb_init_early(); 46551d3082fSBenjamin Herrenschmidt register_early_udbg_console(); 46635499c01SPaul Mackerras } 46735499c01SPaul Mackerras 46851d3082fSBenjamin Herrenschmidt /* Probe motherboard chipset */ 46951d3082fSBenjamin Herrenschmidt pmac_feature_init(); 47051d3082fSBenjamin Herrenschmidt 47151d3082fSBenjamin Herrenschmidt /* Initialize debug stuff */ 4723e47d147SAnton Blanchard udbg_scc_init(!!strstr(boot_command_line, "sccdbg")); 4733e47d147SAnton Blanchard udbg_adb_init(!!strstr(boot_command_line, "btextdbg")); 47451d3082fSBenjamin Herrenschmidt 47551d3082fSBenjamin Herrenschmidt #ifdef CONFIG_PPC64 476*e63f26d3SDaniel Axtens iommu_init_early_dart(&pmac_pci_controller_ops); 47735499c01SPaul Mackerras #endif 4787ccbe504SBenjamin Herrenschmidt 4797ccbe504SBenjamin Herrenschmidt /* SMP Init has to be done early as we need to patch up 480828a6986SAnton Blanchard * cpu_possible_mask before interrupt stacks are allocated 4817ccbe504SBenjamin Herrenschmidt * or kaboom... 4827ccbe504SBenjamin Herrenschmidt */ 4837ccbe504SBenjamin Herrenschmidt #ifdef CONFIG_SMP 4847ccbe504SBenjamin Herrenschmidt pmac_setup_smp(); 4857ccbe504SBenjamin Herrenschmidt #endif 48635499c01SPaul Mackerras } 48735499c01SPaul Mackerras 48835499c01SPaul Mackerras static int __init pmac_declare_of_platform_devices(void) 489f6d57916SPaul Mackerras { 490a28d3af2SBenjamin Herrenschmidt struct device_node *np; 491f6d57916SPaul Mackerras 492e8222502SBenjamin Herrenschmidt if (machine_is(chrp)) 493e8222502SBenjamin Herrenschmidt return -1; 494e8222502SBenjamin Herrenschmidt 495730745a5SBenjamin Herrenschmidt np = of_find_node_by_name(NULL, "valkyrie"); 4963631cb83SJulia Lawall if (np) { 49735499c01SPaul Mackerras of_platform_device_create(np, "valkyrie", NULL); 4983631cb83SJulia Lawall of_node_put(np); 4993631cb83SJulia Lawall } 500730745a5SBenjamin Herrenschmidt np = of_find_node_by_name(NULL, "platinum"); 5013631cb83SJulia Lawall if (np) { 50235499c01SPaul Mackerras of_platform_device_create(np, "platinum", NULL); 5033631cb83SJulia Lawall of_node_put(np); 5043631cb83SJulia Lawall } 50535499c01SPaul Mackerras np = of_find_node_by_type(NULL, "smu"); 50635499c01SPaul Mackerras if (np) { 50735499c01SPaul Mackerras of_platform_device_create(np, "smu", NULL); 50835499c01SPaul Mackerras of_node_put(np); 50935499c01SPaul Mackerras } 51098b14d6bSMarc Zyngier np = of_find_node_by_type(NULL, "fcu"); 51198b14d6bSMarc Zyngier if (np == NULL) { 51298b14d6bSMarc Zyngier /* Some machines have strangely broken device-tree */ 51398b14d6bSMarc Zyngier np = of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/fan@15e"); 51498b14d6bSMarc Zyngier } 51598b14d6bSMarc Zyngier if (np) { 51698b14d6bSMarc Zyngier of_platform_device_create(np, "temperature", NULL); 51798b14d6bSMarc Zyngier of_node_put(np); 51898b14d6bSMarc Zyngier } 519f6d57916SPaul Mackerras 520f6d57916SPaul Mackerras return 0; 521f6d57916SPaul Mackerras } 522d518b717SGrant Likely machine_device_initcall(powermac, pmac_declare_of_platform_devices); 52335499c01SPaul Mackerras 524025d7917SBenjamin Herrenschmidt #ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE 525025d7917SBenjamin Herrenschmidt /* 526025d7917SBenjamin Herrenschmidt * This is called very early, as part of console_init() (typically just after 527025d7917SBenjamin Herrenschmidt * time_init()). This function is respondible for trying to find a good 528025d7917SBenjamin Herrenschmidt * default console on serial ports. It tries to match the open firmware 529025d7917SBenjamin Herrenschmidt * default output with one of the available serial console drivers. 530025d7917SBenjamin Herrenschmidt */ 531025d7917SBenjamin Herrenschmidt static int __init check_pmac_serial_console(void) 532025d7917SBenjamin Herrenschmidt { 533025d7917SBenjamin Herrenschmidt struct device_node *prom_stdout = NULL; 534025d7917SBenjamin Herrenschmidt int offset = 0; 535025d7917SBenjamin Herrenschmidt const char *name; 536025d7917SBenjamin Herrenschmidt #ifdef CONFIG_SERIAL_PMACZILOG_TTYS 537025d7917SBenjamin Herrenschmidt char *devname = "ttyS"; 538025d7917SBenjamin Herrenschmidt #else 539025d7917SBenjamin Herrenschmidt char *devname = "ttyPZ"; 540025d7917SBenjamin Herrenschmidt #endif 541025d7917SBenjamin Herrenschmidt 542025d7917SBenjamin Herrenschmidt pr_debug(" -> check_pmac_serial_console()\n"); 543025d7917SBenjamin Herrenschmidt 544025d7917SBenjamin Herrenschmidt /* The user has requested a console so this is already set up. */ 545025d7917SBenjamin Herrenschmidt if (strstr(boot_command_line, "console=")) { 546025d7917SBenjamin Herrenschmidt pr_debug(" console was specified !\n"); 547025d7917SBenjamin Herrenschmidt return -EBUSY; 548025d7917SBenjamin Herrenschmidt } 549025d7917SBenjamin Herrenschmidt 550025d7917SBenjamin Herrenschmidt if (!of_chosen) { 551025d7917SBenjamin Herrenschmidt pr_debug(" of_chosen is NULL !\n"); 552025d7917SBenjamin Herrenschmidt return -ENODEV; 553025d7917SBenjamin Herrenschmidt } 554025d7917SBenjamin Herrenschmidt 555025d7917SBenjamin Herrenschmidt /* We are getting a weird phandle from OF ... */ 556025d7917SBenjamin Herrenschmidt /* ... So use the full path instead */ 557025d7917SBenjamin Herrenschmidt name = of_get_property(of_chosen, "linux,stdout-path", NULL); 558025d7917SBenjamin Herrenschmidt if (name == NULL) { 559025d7917SBenjamin Herrenschmidt pr_debug(" no linux,stdout-path !\n"); 560025d7917SBenjamin Herrenschmidt return -ENODEV; 561025d7917SBenjamin Herrenschmidt } 562025d7917SBenjamin Herrenschmidt prom_stdout = of_find_node_by_path(name); 563025d7917SBenjamin Herrenschmidt if (!prom_stdout) { 564025d7917SBenjamin Herrenschmidt pr_debug(" can't find stdout package %s !\n", name); 565025d7917SBenjamin Herrenschmidt return -ENODEV; 566025d7917SBenjamin Herrenschmidt } 567025d7917SBenjamin Herrenschmidt pr_debug("stdout is %s\n", prom_stdout->full_name); 568025d7917SBenjamin Herrenschmidt 569025d7917SBenjamin Herrenschmidt name = of_get_property(prom_stdout, "name", NULL); 570025d7917SBenjamin Herrenschmidt if (!name) { 571025d7917SBenjamin Herrenschmidt pr_debug(" stdout package has no name !\n"); 572025d7917SBenjamin Herrenschmidt goto not_found; 573025d7917SBenjamin Herrenschmidt } 574025d7917SBenjamin Herrenschmidt 575025d7917SBenjamin Herrenschmidt if (strcmp(name, "ch-a") == 0) 576025d7917SBenjamin Herrenschmidt offset = 0; 577025d7917SBenjamin Herrenschmidt else if (strcmp(name, "ch-b") == 0) 578025d7917SBenjamin Herrenschmidt offset = 1; 579025d7917SBenjamin Herrenschmidt else 580025d7917SBenjamin Herrenschmidt goto not_found; 581025d7917SBenjamin Herrenschmidt of_node_put(prom_stdout); 582025d7917SBenjamin Herrenschmidt 583025d7917SBenjamin Herrenschmidt pr_debug("Found serial console at %s%d\n", devname, offset); 584025d7917SBenjamin Herrenschmidt 585025d7917SBenjamin Herrenschmidt return add_preferred_console(devname, offset, NULL); 586025d7917SBenjamin Herrenschmidt 587025d7917SBenjamin Herrenschmidt not_found: 588025d7917SBenjamin Herrenschmidt pr_debug("No preferred console found !\n"); 589025d7917SBenjamin Herrenschmidt of_node_put(prom_stdout); 590025d7917SBenjamin Herrenschmidt return -ENODEV; 591025d7917SBenjamin Herrenschmidt } 592025d7917SBenjamin Herrenschmidt console_initcall(check_pmac_serial_console); 593025d7917SBenjamin Herrenschmidt 594025d7917SBenjamin Herrenschmidt #endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */ 595025d7917SBenjamin Herrenschmidt 59635499c01SPaul Mackerras /* 59735499c01SPaul Mackerras * Called very early, MMU is off, device-tree isn't unflattened 59835499c01SPaul Mackerras */ 599e8222502SBenjamin Herrenschmidt static int __init pmac_probe(void) 60035499c01SPaul Mackerras { 601e8222502SBenjamin Herrenschmidt unsigned long root = of_get_flat_dt_root(); 602e8222502SBenjamin Herrenschmidt 603e8222502SBenjamin Herrenschmidt if (!of_flat_dt_is_compatible(root, "Power Macintosh") && 604e8222502SBenjamin Herrenschmidt !of_flat_dt_is_compatible(root, "MacRISC")) 60535499c01SPaul Mackerras return 0; 60635499c01SPaul Mackerras 607e8222502SBenjamin Herrenschmidt #ifdef CONFIG_PPC64 60835499c01SPaul Mackerras /* 60935499c01SPaul Mackerras * On U3, the DART (iommu) must be allocated now since it 61035499c01SPaul Mackerras * has an impact on htab_initialize (due to the large page it 61135499c01SPaul Mackerras * occupies having to be broken up so the DART itself is not 61235499c01SPaul Mackerras * part of the cacheable linar mapping 61335499c01SPaul Mackerras */ 6141beb6a7dSBenjamin Herrenschmidt alloc_dart_table(); 6157d0daae4SMichael Ellerman 6167d0daae4SMichael Ellerman hpte_init_native(); 61735499c01SPaul Mackerras #endif 61835499c01SPaul Mackerras 619e8222502SBenjamin Herrenschmidt #ifdef CONFIG_PPC32 620e8222502SBenjamin Herrenschmidt /* isa_io_base gets set in pmac_pci_init */ 621e8222502SBenjamin Herrenschmidt ISA_DMA_THRESHOLD = ~0L; 622e8222502SBenjamin Herrenschmidt DMA_MODE_READ = 1; 623e8222502SBenjamin Herrenschmidt DMA_MODE_WRITE = 2; 624e8222502SBenjamin Herrenschmidt #endif /* CONFIG_PPC32 */ 625e8222502SBenjamin Herrenschmidt 62635499c01SPaul Mackerras #ifdef CONFIG_PMAC_SMU 62735499c01SPaul Mackerras /* 62835499c01SPaul Mackerras * SMU based G5s need some memory below 2Gb, at least the current 62935499c01SPaul Mackerras * driver needs that. We have to allocate it now. We allocate 4k 63035499c01SPaul Mackerras * (1 small page) for now. 63135499c01SPaul Mackerras */ 63295f72d1eSYinghai Lu smu_cmdbuf_abs = memblock_alloc_base(4096, 4096, 0x80000000UL); 63335499c01SPaul Mackerras #endif /* CONFIG_PMAC_SMU */ 63435499c01SPaul Mackerras 6359178ba29SAlexander Graf pm_power_off = pmac_power_off; 6369178ba29SAlexander Graf 63735499c01SPaul Mackerras return 1; 63835499c01SPaul Mackerras } 63935499c01SPaul Mackerras 640e8222502SBenjamin Herrenschmidt define_machine(powermac) { 641e8222502SBenjamin Herrenschmidt .name = "PowerMac", 64235499c01SPaul Mackerras .probe = pmac_probe, 64335499c01SPaul Mackerras .setup_arch = pmac_setup_arch, 64435499c01SPaul Mackerras .init_early = pmac_init_early, 64535499c01SPaul Mackerras .show_cpuinfo = pmac_show_cpuinfo, 64635499c01SPaul Mackerras .init_IRQ = pmac_pic_init, 647cc5d0189SBenjamin Herrenschmidt .get_irq = NULL, /* changed later */ 648f90bb153SBenjamin Herrenschmidt .pci_irq_fixup = pmac_pci_irq_fixup, 64935499c01SPaul Mackerras .restart = pmac_restart, 65035499c01SPaul Mackerras .halt = pmac_halt, 65135499c01SPaul Mackerras .time_init = pmac_time_init, 65235499c01SPaul Mackerras .get_boot_time = pmac_get_boot_time, 65335499c01SPaul Mackerras .set_rtc_time = pmac_set_rtc_time, 65435499c01SPaul Mackerras .get_rtc_time = pmac_get_rtc_time, 65535499c01SPaul Mackerras .calibrate_decr = pmac_calibrate_decr, 65635499c01SPaul Mackerras .feature_call = pmac_do_feature_call, 657be6b8439SKumar Gala .progress = udbg_progress, 65835499c01SPaul Mackerras #ifdef CONFIG_PPC64 659a0652fc9SPaul Mackerras .power_save = power4_idle, 66035499c01SPaul Mackerras .enable_pmcs = power4_enable_pmcs, 6613d1229d6SMichael Ellerman #endif /* CONFIG_PPC64 */ 66235499c01SPaul Mackerras #ifdef CONFIG_PPC32 66335499c01SPaul Mackerras .pcibios_after_init = pmac_pcibios_after_init, 66435499c01SPaul Mackerras .phys_mem_access_prot = pci_phys_mem_access_prot, 66535499c01SPaul Mackerras #endif 66635499c01SPaul Mackerras }; 667