xref: /openbmc/linux/arch/powerpc/platforms/powermac/setup.c (revision d8731527acee53b4d46d59ff0b5fc36931ad0451)
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;
155*d8731527SMathieu 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)) {
2461658ab66SStephen Rothwell 		struct device_node *np = of_find_node_by_name(NULL, "cpus");
247*d8731527SMathieu Malaterre 		if (!np)
2481658ab66SStephen Rothwell 			np = of_find_node_by_type(NULL, "cpu");
249*d8731527SMathieu Malaterre 		if (np) {
250018a3d1dSJeremy Kerr 			const unsigned int *l2cr =
251e2eb6392SStephen Rothwell 				of_get_property(np, "l2cr-value", NULL);
252*d8731527SMathieu Malaterre 			if (l2cr) {
253f6d57916SPaul Mackerras 				ppc_override_l2cr = 1;
254f6d57916SPaul Mackerras 				ppc_override_l2cr_value = *l2cr;
255f6d57916SPaul Mackerras 				_set_L2CR(0);
256f6d57916SPaul Mackerras 				_set_L2CR(ppc_override_l2cr_value);
257f6d57916SPaul Mackerras 			}
2581658ab66SStephen Rothwell 			of_node_put(np);
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;
28235499c01SPaul Mackerras 	cpu = of_find_node_by_type(NULL, "cpu");
28335499c01SPaul Mackerras 	if (cpu != NULL) {
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 		}
29635499c01SPaul Mackerras 		of_node_put(cpu);
29735499c01SPaul Mackerras 	}
29835499c01SPaul Mackerras 
299a575b807SPaul Mackerras 	/* See if newworld or oldworld */
30022059a90SMichael Ellerman 	ic = of_find_node_with_property(NULL, "interrupt-controller");
301d2515c80SOlaf Hering 	if (ic) {
302d2515c80SOlaf Hering 		pmac_newworld = 1;
303a575b807SPaul Mackerras 		of_node_put(ic);
304d2515c80SOlaf Hering 	}
305a575b807SPaul Mackerras 
30635499c01SPaul Mackerras 	/* Lookup PCI hosts */
30735499c01SPaul Mackerras 	pmac_pci_init();
30835499c01SPaul Mackerras 
30935499c01SPaul Mackerras #ifdef CONFIG_PPC32
31035499c01SPaul Mackerras 	ohare_init();
31135499c01SPaul Mackerras 	l2cr_init();
31235499c01SPaul Mackerras #endif /* CONFIG_PPC32 */
31335499c01SPaul Mackerras 
314f6d57916SPaul Mackerras 	find_via_cuda();
315f6d57916SPaul Mackerras 	find_via_pmu();
31635499c01SPaul Mackerras 	smu_init();
31735499c01SPaul Mackerras 
31821e38dfeSTony Breeds #if defined(CONFIG_NVRAM) || defined(CONFIG_NVRAM_MODULE) || \
31921e38dfeSTony Breeds     defined(CONFIG_PPC64)
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 
355d7418031SStephen Rothwell /*
356bd721ea7SFabian Frederick  * This is __ref because we check for "initializing" before
357d7418031SStephen Rothwell  * touching any of the __init sensitive things and "initializing"
358d7418031SStephen Rothwell  * will be false after __init time. This can't be __init because it
359d7418031SStephen Rothwell  * can be called whenever a disk is first accessed.
360d7418031SStephen Rothwell  */
361bd721ea7SFabian Frederick void __ref note_bootable_part(dev_t dev, int part, int goodness)
362f6d57916SPaul Mackerras {
363f6d57916SPaul Mackerras 	char *p;
364f6d57916SPaul Mackerras 
365f6d57916SPaul Mackerras 	if (!initializing)
366f6d57916SPaul Mackerras 		return;
367f6d57916SPaul Mackerras 	if ((goodness <= current_root_goodness) &&
368f6d57916SPaul Mackerras 	    ROOT_DEV != DEFAULT_ROOT_DEVICE)
369f6d57916SPaul Mackerras 		return;
370b8757b21SAlon Bar-Lev 	p = strstr(boot_command_line, "root=");
371b8757b21SAlon Bar-Lev 	if (p != NULL && (p == boot_command_line || p[-1] == ' '))
372f6d57916SPaul Mackerras 		return;
373f6d57916SPaul Mackerras 
374f6d57916SPaul Mackerras 	ROOT_DEV = dev + part;
375f6d57916SPaul Mackerras 	current_root_goodness = goodness;
376f6d57916SPaul Mackerras }
377f6d57916SPaul Mackerras 
37835499c01SPaul Mackerras #ifdef CONFIG_ADB_CUDA
37995ec77c0SDaniel Axtens static void __noreturn cuda_restart(void)
380f6d57916SPaul Mackerras {
381f6d57916SPaul Mackerras 	struct adb_request req;
382f6d57916SPaul Mackerras 
38335499c01SPaul Mackerras 	cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM);
384f6d57916SPaul Mackerras 	for (;;)
385f6d57916SPaul Mackerras 		cuda_poll();
38635499c01SPaul Mackerras }
38735499c01SPaul Mackerras 
38895ec77c0SDaniel Axtens static void __noreturn cuda_shutdown(void)
38935499c01SPaul Mackerras {
39035499c01SPaul Mackerras 	struct adb_request req;
39135499c01SPaul Mackerras 
39235499c01SPaul Mackerras 	cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN);
39335499c01SPaul Mackerras 	for (;;)
39435499c01SPaul Mackerras 		cuda_poll();
39535499c01SPaul Mackerras }
39635499c01SPaul Mackerras 
39735499c01SPaul Mackerras #else
39835499c01SPaul Mackerras #define cuda_restart()
39935499c01SPaul Mackerras #define cuda_shutdown()
40035499c01SPaul Mackerras #endif
40135499c01SPaul Mackerras 
40235499c01SPaul Mackerras #ifndef CONFIG_ADB_PMU
40335499c01SPaul Mackerras #define pmu_restart()
40435499c01SPaul Mackerras #define pmu_shutdown()
40535499c01SPaul Mackerras #endif
40635499c01SPaul Mackerras 
40735499c01SPaul Mackerras #ifndef CONFIG_PMAC_SMU
40835499c01SPaul Mackerras #define smu_restart()
40935499c01SPaul Mackerras #define smu_shutdown()
41035499c01SPaul Mackerras #endif
41135499c01SPaul Mackerras 
41295ec77c0SDaniel Axtens static void __noreturn pmac_restart(char *cmd)
41335499c01SPaul Mackerras {
41435499c01SPaul Mackerras 	switch (sys_ctrler) {
41535499c01SPaul Mackerras 	case SYS_CTRLER_CUDA:
41635499c01SPaul Mackerras 		cuda_restart();
417f6d57916SPaul Mackerras 		break;
418f6d57916SPaul Mackerras 	case SYS_CTRLER_PMU:
419f6d57916SPaul Mackerras 		pmu_restart();
420f6d57916SPaul Mackerras 		break;
42135499c01SPaul Mackerras 	case SYS_CTRLER_SMU:
42235499c01SPaul Mackerras 		smu_restart();
42335499c01SPaul Mackerras 		break;
424f6d57916SPaul Mackerras 	default: ;
425f6d57916SPaul Mackerras 	}
42695ec77c0SDaniel Axtens 	while (1) ;
427f6d57916SPaul Mackerras }
428f6d57916SPaul Mackerras 
42995ec77c0SDaniel Axtens static void __noreturn pmac_power_off(void)
430f6d57916SPaul Mackerras {
431f6d57916SPaul Mackerras 	switch (sys_ctrler) {
432f6d57916SPaul Mackerras 	case SYS_CTRLER_CUDA:
43335499c01SPaul Mackerras 		cuda_shutdown();
434f6d57916SPaul Mackerras 		break;
435f6d57916SPaul Mackerras 	case SYS_CTRLER_PMU:
436f6d57916SPaul Mackerras 		pmu_shutdown();
437f6d57916SPaul Mackerras 		break;
43835499c01SPaul Mackerras 	case SYS_CTRLER_SMU:
43935499c01SPaul Mackerras 		smu_shutdown();
44035499c01SPaul Mackerras 		break;
441f6d57916SPaul Mackerras 	default: ;
442f6d57916SPaul Mackerras 	}
44395ec77c0SDaniel Axtens 	while (1) ;
444f6d57916SPaul Mackerras }
445f6d57916SPaul Mackerras 
44695ec77c0SDaniel Axtens static void __noreturn
447f6d57916SPaul Mackerras pmac_halt(void)
448f6d57916SPaul Mackerras {
449f6d57916SPaul Mackerras 	pmac_power_off();
450f6d57916SPaul Mackerras }
451f6d57916SPaul Mackerras 
45235499c01SPaul Mackerras /*
45335499c01SPaul Mackerras  * Early initialization.
45435499c01SPaul Mackerras  */
455f2d57694SBenjamin Herrenschmidt static void __init pmac_init(void)
456f6d57916SPaul Mackerras {
45751d3082fSBenjamin Herrenschmidt 	/* Enable early btext debug if requested */
4583e47d147SAnton Blanchard 	if (strstr(boot_command_line, "btextdbg")) {
45951d3082fSBenjamin Herrenschmidt 		udbg_adb_init_early();
46051d3082fSBenjamin Herrenschmidt 		register_early_udbg_console();
46135499c01SPaul Mackerras 	}
46235499c01SPaul Mackerras 
46351d3082fSBenjamin Herrenschmidt 	/* Probe motherboard chipset */
46451d3082fSBenjamin Herrenschmidt 	pmac_feature_init();
46551d3082fSBenjamin Herrenschmidt 
46651d3082fSBenjamin Herrenschmidt 	/* Initialize debug stuff */
4673e47d147SAnton Blanchard 	udbg_scc_init(!!strstr(boot_command_line, "sccdbg"));
4683e47d147SAnton Blanchard 	udbg_adb_init(!!strstr(boot_command_line, "btextdbg"));
46951d3082fSBenjamin Herrenschmidt 
47051d3082fSBenjamin Herrenschmidt #ifdef CONFIG_PPC64
471e63f26d3SDaniel Axtens 	iommu_init_early_dart(&pmac_pci_controller_ops);
47235499c01SPaul Mackerras #endif
4737ccbe504SBenjamin Herrenschmidt 
4747ccbe504SBenjamin Herrenschmidt 	/* SMP Init has to be done early as we need to patch up
475828a6986SAnton Blanchard 	 * cpu_possible_mask before interrupt stacks are allocated
4767ccbe504SBenjamin Herrenschmidt 	 * or kaboom...
4777ccbe504SBenjamin Herrenschmidt 	 */
4787ccbe504SBenjamin Herrenschmidt #ifdef CONFIG_SMP
4797ccbe504SBenjamin Herrenschmidt 	pmac_setup_smp();
4807ccbe504SBenjamin Herrenschmidt #endif
48135499c01SPaul Mackerras }
48235499c01SPaul Mackerras 
48335499c01SPaul Mackerras static int __init pmac_declare_of_platform_devices(void)
484f6d57916SPaul Mackerras {
485a28d3af2SBenjamin Herrenschmidt 	struct device_node *np;
486f6d57916SPaul Mackerras 
487730745a5SBenjamin Herrenschmidt 	np = of_find_node_by_name(NULL, "valkyrie");
4883631cb83SJulia Lawall 	if (np) {
48935499c01SPaul Mackerras 		of_platform_device_create(np, "valkyrie", NULL);
4903631cb83SJulia Lawall 		of_node_put(np);
4913631cb83SJulia Lawall 	}
492730745a5SBenjamin Herrenschmidt 	np = of_find_node_by_name(NULL, "platinum");
4933631cb83SJulia Lawall 	if (np) {
49435499c01SPaul Mackerras 		of_platform_device_create(np, "platinum", NULL);
4953631cb83SJulia Lawall 		of_node_put(np);
4963631cb83SJulia Lawall 	}
49735499c01SPaul Mackerras         np = of_find_node_by_type(NULL, "smu");
49835499c01SPaul Mackerras         if (np) {
49935499c01SPaul Mackerras 		of_platform_device_create(np, "smu", NULL);
50035499c01SPaul Mackerras 		of_node_put(np);
50135499c01SPaul Mackerras 	}
50298b14d6bSMarc Zyngier 	np = of_find_node_by_type(NULL, "fcu");
50398b14d6bSMarc Zyngier 	if (np == NULL) {
50498b14d6bSMarc Zyngier 		/* Some machines have strangely broken device-tree */
50598b14d6bSMarc Zyngier 		np = of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/fan@15e");
50698b14d6bSMarc Zyngier 	}
50798b14d6bSMarc Zyngier 	if (np) {
50898b14d6bSMarc Zyngier 		of_platform_device_create(np, "temperature", NULL);
50998b14d6bSMarc Zyngier 		of_node_put(np);
51098b14d6bSMarc Zyngier 	}
511f6d57916SPaul Mackerras 
512f6d57916SPaul Mackerras 	return 0;
513f6d57916SPaul Mackerras }
514d518b717SGrant Likely machine_device_initcall(powermac, pmac_declare_of_platform_devices);
51535499c01SPaul Mackerras 
516025d7917SBenjamin Herrenschmidt #ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
517025d7917SBenjamin Herrenschmidt /*
518025d7917SBenjamin Herrenschmidt  * This is called very early, as part of console_init() (typically just after
519025d7917SBenjamin Herrenschmidt  * time_init()). This function is respondible for trying to find a good
520025d7917SBenjamin Herrenschmidt  * default console on serial ports. It tries to match the open firmware
521025d7917SBenjamin Herrenschmidt  * default output with one of the available serial console drivers.
522025d7917SBenjamin Herrenschmidt  */
523025d7917SBenjamin Herrenschmidt static int __init check_pmac_serial_console(void)
524025d7917SBenjamin Herrenschmidt {
525025d7917SBenjamin Herrenschmidt 	struct device_node *prom_stdout = NULL;
526025d7917SBenjamin Herrenschmidt 	int offset = 0;
527025d7917SBenjamin Herrenschmidt 	const char *name;
528025d7917SBenjamin Herrenschmidt #ifdef CONFIG_SERIAL_PMACZILOG_TTYS
529025d7917SBenjamin Herrenschmidt 	char *devname = "ttyS";
530025d7917SBenjamin Herrenschmidt #else
531025d7917SBenjamin Herrenschmidt 	char *devname = "ttyPZ";
532025d7917SBenjamin Herrenschmidt #endif
533025d7917SBenjamin Herrenschmidt 
534025d7917SBenjamin Herrenschmidt 	pr_debug(" -> check_pmac_serial_console()\n");
535025d7917SBenjamin Herrenschmidt 
536025d7917SBenjamin Herrenschmidt 	/* The user has requested a console so this is already set up. */
537025d7917SBenjamin Herrenschmidt 	if (strstr(boot_command_line, "console=")) {
538025d7917SBenjamin Herrenschmidt 		pr_debug(" console was specified !\n");
539025d7917SBenjamin Herrenschmidt 		return -EBUSY;
540025d7917SBenjamin Herrenschmidt 	}
541025d7917SBenjamin Herrenschmidt 
542025d7917SBenjamin Herrenschmidt 	if (!of_chosen) {
543025d7917SBenjamin Herrenschmidt 		pr_debug(" of_chosen is NULL !\n");
544025d7917SBenjamin Herrenschmidt 		return -ENODEV;
545025d7917SBenjamin Herrenschmidt 	}
546025d7917SBenjamin Herrenschmidt 
547025d7917SBenjamin Herrenschmidt 	/* We are getting a weird phandle from OF ... */
548025d7917SBenjamin Herrenschmidt 	/* ... So use the full path instead */
549025d7917SBenjamin Herrenschmidt 	name = of_get_property(of_chosen, "linux,stdout-path", NULL);
550025d7917SBenjamin Herrenschmidt 	if (name == NULL) {
551025d7917SBenjamin Herrenschmidt 		pr_debug(" no linux,stdout-path !\n");
552025d7917SBenjamin Herrenschmidt 		return -ENODEV;
553025d7917SBenjamin Herrenschmidt 	}
554025d7917SBenjamin Herrenschmidt 	prom_stdout = of_find_node_by_path(name);
555025d7917SBenjamin Herrenschmidt 	if (!prom_stdout) {
556025d7917SBenjamin Herrenschmidt 		pr_debug(" can't find stdout package %s !\n", name);
557025d7917SBenjamin Herrenschmidt 		return -ENODEV;
558025d7917SBenjamin Herrenschmidt 	}
559b7c670d6SRob Herring 	pr_debug("stdout is %pOF\n", prom_stdout);
560025d7917SBenjamin Herrenschmidt 
561025d7917SBenjamin Herrenschmidt 	name = of_get_property(prom_stdout, "name", NULL);
562025d7917SBenjamin Herrenschmidt 	if (!name) {
563025d7917SBenjamin Herrenschmidt 		pr_debug(" stdout package has no name !\n");
564025d7917SBenjamin Herrenschmidt 		goto not_found;
565025d7917SBenjamin Herrenschmidt 	}
566025d7917SBenjamin Herrenschmidt 
567025d7917SBenjamin Herrenschmidt 	if (strcmp(name, "ch-a") == 0)
568025d7917SBenjamin Herrenschmidt 		offset = 0;
569025d7917SBenjamin Herrenschmidt 	else if (strcmp(name, "ch-b") == 0)
570025d7917SBenjamin Herrenschmidt 		offset = 1;
571025d7917SBenjamin Herrenschmidt 	else
572025d7917SBenjamin Herrenschmidt 		goto not_found;
573025d7917SBenjamin Herrenschmidt 	of_node_put(prom_stdout);
574025d7917SBenjamin Herrenschmidt 
575025d7917SBenjamin Herrenschmidt 	pr_debug("Found serial console at %s%d\n", devname, offset);
576025d7917SBenjamin Herrenschmidt 
577025d7917SBenjamin Herrenschmidt 	return add_preferred_console(devname, offset, NULL);
578025d7917SBenjamin Herrenschmidt 
579025d7917SBenjamin Herrenschmidt  not_found:
580025d7917SBenjamin Herrenschmidt 	pr_debug("No preferred console found !\n");
581025d7917SBenjamin Herrenschmidt 	of_node_put(prom_stdout);
582025d7917SBenjamin Herrenschmidt 	return -ENODEV;
583025d7917SBenjamin Herrenschmidt }
584025d7917SBenjamin Herrenschmidt console_initcall(check_pmac_serial_console);
585025d7917SBenjamin Herrenschmidt 
586025d7917SBenjamin Herrenschmidt #endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */
587025d7917SBenjamin Herrenschmidt 
58835499c01SPaul Mackerras /*
58935499c01SPaul Mackerras  * Called very early, MMU is off, device-tree isn't unflattened
59035499c01SPaul Mackerras  */
591e8222502SBenjamin Herrenschmidt static int __init pmac_probe(void)
59235499c01SPaul Mackerras {
593406b0b6aSBenjamin Herrenschmidt 	if (!of_machine_is_compatible("Power Macintosh") &&
594406b0b6aSBenjamin Herrenschmidt 	    !of_machine_is_compatible("MacRISC"))
595406b0b6aSBenjamin Herrenschmidt 		return 0;
59635499c01SPaul Mackerras 
597e8222502SBenjamin Herrenschmidt #ifdef CONFIG_PPC32
598e8222502SBenjamin Herrenschmidt 	/* isa_io_base gets set in pmac_pci_init */
599e8222502SBenjamin Herrenschmidt 	ISA_DMA_THRESHOLD = ~0L;
600e8222502SBenjamin Herrenschmidt 	DMA_MODE_READ = 1;
601e8222502SBenjamin Herrenschmidt 	DMA_MODE_WRITE = 2;
602e8222502SBenjamin Herrenschmidt #endif /* CONFIG_PPC32 */
603e8222502SBenjamin Herrenschmidt 
6049178ba29SAlexander Graf 	pm_power_off = pmac_power_off;
6059178ba29SAlexander Graf 
606f2d57694SBenjamin Herrenschmidt 	pmac_init();
607f2d57694SBenjamin Herrenschmidt 
60835499c01SPaul Mackerras 	return 1;
60935499c01SPaul Mackerras }
61035499c01SPaul Mackerras 
611e8222502SBenjamin Herrenschmidt define_machine(powermac) {
612e8222502SBenjamin Herrenschmidt 	.name			= "PowerMac",
61335499c01SPaul Mackerras 	.probe			= pmac_probe,
61435499c01SPaul Mackerras 	.setup_arch		= pmac_setup_arch,
61535499c01SPaul Mackerras 	.show_cpuinfo		= pmac_show_cpuinfo,
61635499c01SPaul Mackerras 	.init_IRQ		= pmac_pic_init,
617cc5d0189SBenjamin Herrenschmidt 	.get_irq		= NULL,	/* changed later */
618f90bb153SBenjamin Herrenschmidt 	.pci_irq_fixup		= pmac_pci_irq_fixup,
61935499c01SPaul Mackerras 	.restart		= pmac_restart,
62035499c01SPaul Mackerras 	.halt			= pmac_halt,
62135499c01SPaul Mackerras 	.time_init		= pmac_time_init,
62235499c01SPaul Mackerras 	.get_boot_time		= pmac_get_boot_time,
62335499c01SPaul Mackerras 	.set_rtc_time		= pmac_set_rtc_time,
62435499c01SPaul Mackerras 	.get_rtc_time		= pmac_get_rtc_time,
62535499c01SPaul Mackerras 	.calibrate_decr		= pmac_calibrate_decr,
62635499c01SPaul Mackerras 	.feature_call		= pmac_do_feature_call,
627be6b8439SKumar Gala 	.progress		= udbg_progress,
62835499c01SPaul Mackerras #ifdef CONFIG_PPC64
629a0652fc9SPaul Mackerras 	.power_save		= power4_idle,
63035499c01SPaul Mackerras 	.enable_pmcs		= power4_enable_pmcs,
6313d1229d6SMichael Ellerman #endif /* CONFIG_PPC64 */
63235499c01SPaul Mackerras #ifdef CONFIG_PPC32
63335499c01SPaul Mackerras 	.pcibios_after_init	= pmac_pcibios_after_init,
63435499c01SPaul Mackerras 	.phys_mem_access_prot	= pci_phys_mem_access_prot,
63535499c01SPaul Mackerras #endif
63635499c01SPaul Mackerras };
637