xref: /openbmc/linux/arch/powerpc/platforms/powermac/setup.c (revision 0dd194d02d2584c34e06ddd26c7a7896a5fa1974)
1f6d57916SPaul Mackerras /*
2f6d57916SPaul Mackerras  *  arch/ppc/platforms/setup.c
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
8f6d57916SPaul Mackerras  *    Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au)
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/config.h>
27f6d57916SPaul Mackerras #include <linux/init.h>
28f6d57916SPaul Mackerras #include <linux/errno.h>
29f6d57916SPaul Mackerras #include <linux/sched.h>
30f6d57916SPaul Mackerras #include <linux/kernel.h>
31f6d57916SPaul Mackerras #include <linux/mm.h>
32f6d57916SPaul Mackerras #include <linux/stddef.h>
33f6d57916SPaul Mackerras #include <linux/unistd.h>
34f6d57916SPaul Mackerras #include <linux/ptrace.h>
35f6d57916SPaul Mackerras #include <linux/slab.h>
36f6d57916SPaul Mackerras #include <linux/user.h>
37f6d57916SPaul Mackerras #include <linux/a.out.h>
38f6d57916SPaul Mackerras #include <linux/tty.h>
39f6d57916SPaul Mackerras #include <linux/string.h>
40f6d57916SPaul Mackerras #include <linux/delay.h>
41f6d57916SPaul Mackerras #include <linux/ioport.h>
42f6d57916SPaul Mackerras #include <linux/major.h>
43f6d57916SPaul Mackerras #include <linux/initrd.h>
44f6d57916SPaul Mackerras #include <linux/vt_kern.h>
45f6d57916SPaul Mackerras #include <linux/console.h>
46f6d57916SPaul Mackerras #include <linux/ide.h>
47f6d57916SPaul Mackerras #include <linux/pci.h>
48f6d57916SPaul Mackerras #include <linux/adb.h>
49f6d57916SPaul Mackerras #include <linux/cuda.h>
50f6d57916SPaul Mackerras #include <linux/pmu.h>
51f6d57916SPaul Mackerras #include <linux/irq.h>
52f6d57916SPaul Mackerras #include <linux/seq_file.h>
53f6d57916SPaul Mackerras #include <linux/root_dev.h>
54f6d57916SPaul Mackerras #include <linux/bitops.h>
55f6d57916SPaul Mackerras #include <linux/suspend.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/system.h>
61f6d57916SPaul Mackerras #include <asm/pgtable.h>
62f6d57916SPaul Mackerras #include <asm/io.h>
63f6d57916SPaul Mackerras #include <asm/pci-bridge.h>
64f6d57916SPaul Mackerras #include <asm/ohare.h>
65f6d57916SPaul Mackerras #include <asm/mediabay.h>
66f6d57916SPaul Mackerras #include <asm/machdep.h>
67f6d57916SPaul Mackerras #include <asm/dma.h>
68f6d57916SPaul Mackerras #include <asm/bootx.h>
69f6d57916SPaul Mackerras #include <asm/cputable.h>
70f6d57916SPaul Mackerras #include <asm/btext.h>
71f6d57916SPaul Mackerras #include <asm/pmac_feature.h>
72f6d57916SPaul Mackerras #include <asm/time.h>
73f6d57916SPaul Mackerras #include <asm/of_device.h>
74f6d57916SPaul Mackerras #include <asm/mmu_context.h>
75f6d57916SPaul Mackerras 
763c3f42d6SPaul Mackerras #include "pmac.h"
77f6d57916SPaul Mackerras 
78f6d57916SPaul Mackerras #undef SHOW_GATWICK_IRQS
79f6d57916SPaul Mackerras 
80f6d57916SPaul Mackerras unsigned char drive_info;
81f6d57916SPaul Mackerras 
82f6d57916SPaul Mackerras int ppc_override_l2cr = 0;
83f6d57916SPaul Mackerras int ppc_override_l2cr_value;
84f6d57916SPaul Mackerras int has_l2cache = 0;
85f6d57916SPaul Mackerras 
86f6d57916SPaul Mackerras int pmac_newworld = 1;
87f6d57916SPaul Mackerras 
88f6d57916SPaul Mackerras static int current_root_goodness = -1;
89f6d57916SPaul Mackerras 
90f6d57916SPaul Mackerras extern int pmac_newworld;
91f6d57916SPaul Mackerras 
92f6d57916SPaul Mackerras #define DEFAULT_ROOT_DEVICE Root_SDA1	/* sda1 - slightly silly choice */
93f6d57916SPaul Mackerras 
94f6d57916SPaul Mackerras extern void zs_kgdb_hook(int tty_num);
95f6d57916SPaul Mackerras static void ohare_init(void);
96f6d57916SPaul Mackerras #ifdef CONFIG_BOOTX_TEXT
97f6d57916SPaul Mackerras static void pmac_progress(char *s, unsigned short hex);
98f6d57916SPaul Mackerras #endif
99f6d57916SPaul Mackerras 
100f6d57916SPaul Mackerras sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN;
101f6d57916SPaul Mackerras 
102f6d57916SPaul Mackerras #ifdef CONFIG_SMP
103f6d57916SPaul Mackerras extern struct smp_ops_t psurge_smp_ops;
104f6d57916SPaul Mackerras extern struct smp_ops_t core99_smp_ops;
105f6d57916SPaul Mackerras #endif /* CONFIG_SMP */
106f6d57916SPaul Mackerras 
107*0dd194d0SPaul Mackerras static void pmac_show_cpuinfo(struct seq_file *m)
108f6d57916SPaul Mackerras {
109f6d57916SPaul Mackerras 	struct device_node *np;
110f6d57916SPaul Mackerras 	char *pp;
111f6d57916SPaul Mackerras 	int plen;
112*0dd194d0SPaul Mackerras 	int mbmodel;
113*0dd194d0SPaul Mackerras 	unsigned int mbflags;
114f6d57916SPaul Mackerras 	char* mbname;
115f6d57916SPaul Mackerras 
116*0dd194d0SPaul Mackerras 	mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
117*0dd194d0SPaul Mackerras 				    PMAC_MB_INFO_MODEL, 0);
118*0dd194d0SPaul Mackerras 	mbflags = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
119*0dd194d0SPaul Mackerras 				    PMAC_MB_INFO_FLAGS, 0);
120*0dd194d0SPaul Mackerras 	if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME,
121*0dd194d0SPaul Mackerras 			      (long) &mbname) != 0)
122f6d57916SPaul Mackerras 		mbname = "Unknown";
123f6d57916SPaul Mackerras 
124f6d57916SPaul Mackerras 	/* find motherboard type */
125f6d57916SPaul Mackerras 	seq_printf(m, "machine\t\t: ");
126*0dd194d0SPaul Mackerras 	np = of_find_node_by_path("/");
127f6d57916SPaul Mackerras 	if (np != NULL) {
128f6d57916SPaul Mackerras 		pp = (char *) get_property(np, "model", NULL);
129f6d57916SPaul Mackerras 		if (pp != NULL)
130f6d57916SPaul Mackerras 			seq_printf(m, "%s\n", pp);
131f6d57916SPaul Mackerras 		else
132f6d57916SPaul Mackerras 			seq_printf(m, "PowerMac\n");
133f6d57916SPaul Mackerras 		pp = (char *) get_property(np, "compatible", &plen);
134f6d57916SPaul Mackerras 		if (pp != NULL) {
135f6d57916SPaul Mackerras 			seq_printf(m, "motherboard\t:");
136f6d57916SPaul Mackerras 			while (plen > 0) {
137f6d57916SPaul Mackerras 				int l = strlen(pp) + 1;
138f6d57916SPaul Mackerras 				seq_printf(m, " %s", pp);
139f6d57916SPaul Mackerras 				plen -= l;
140f6d57916SPaul Mackerras 				pp += l;
141f6d57916SPaul Mackerras 			}
142f6d57916SPaul Mackerras 			seq_printf(m, "\n");
143f6d57916SPaul Mackerras 		}
144*0dd194d0SPaul Mackerras 		of_node_put(np);
145f6d57916SPaul Mackerras 	} else
146f6d57916SPaul Mackerras 		seq_printf(m, "PowerMac\n");
147f6d57916SPaul Mackerras 
148f6d57916SPaul Mackerras 	/* print parsed model */
149f6d57916SPaul Mackerras 	seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname);
150f6d57916SPaul Mackerras 	seq_printf(m, "pmac flags\t: %08x\n", mbflags);
151f6d57916SPaul Mackerras 
152f6d57916SPaul Mackerras 	/* find l2 cache info */
153*0dd194d0SPaul Mackerras 	np = of_find_node_by_name(NULL, "l2-cache");
154*0dd194d0SPaul Mackerras 	if (np == NULL)
155*0dd194d0SPaul Mackerras 		np = of_find_node_by_type(NULL, "cache");
156*0dd194d0SPaul Mackerras 	if (np != NULL) {
157f6d57916SPaul Mackerras 		unsigned int *ic = (unsigned int *)
158f6d57916SPaul Mackerras 			get_property(np, "i-cache-size", NULL);
159f6d57916SPaul Mackerras 		unsigned int *dc = (unsigned int *)
160f6d57916SPaul Mackerras 			get_property(np, "d-cache-size", NULL);
161f6d57916SPaul Mackerras 		seq_printf(m, "L2 cache\t:");
162f6d57916SPaul Mackerras 		has_l2cache = 1;
163f6d57916SPaul Mackerras 		if (get_property(np, "cache-unified", NULL) != 0 && dc) {
164f6d57916SPaul Mackerras 			seq_printf(m, " %dK unified", *dc / 1024);
165f6d57916SPaul Mackerras 		} else {
166f6d57916SPaul Mackerras 			if (ic)
167f6d57916SPaul Mackerras 				seq_printf(m, " %dK instruction", *ic / 1024);
168f6d57916SPaul Mackerras 			if (dc)
169f6d57916SPaul Mackerras 				seq_printf(m, "%s %dK data",
170f6d57916SPaul Mackerras 					   (ic? " +": ""), *dc / 1024);
171f6d57916SPaul Mackerras 		}
172f6d57916SPaul Mackerras 		pp = get_property(np, "ram-type", NULL);
173f6d57916SPaul Mackerras 		if (pp)
174f6d57916SPaul Mackerras 			seq_printf(m, " %s", pp);
175f6d57916SPaul Mackerras 		seq_printf(m, "\n");
176*0dd194d0SPaul Mackerras 		of_node_put(np);
177f6d57916SPaul Mackerras 	}
178f6d57916SPaul Mackerras 
179f6d57916SPaul Mackerras 	/* Indicate newworld/oldworld */
180f6d57916SPaul Mackerras 	seq_printf(m, "pmac-generation\t: %s\n",
181f6d57916SPaul Mackerras 		   pmac_newworld ? "NewWorld" : "OldWorld");
182f6d57916SPaul Mackerras }
183f6d57916SPaul Mackerras 
184*0dd194d0SPaul Mackerras static void pmac_show_percpuinfo(struct seq_file *m, int i)
185f6d57916SPaul Mackerras {
186f6d57916SPaul Mackerras #ifdef CONFIG_CPU_FREQ_PMAC
187f6d57916SPaul Mackerras 	extern unsigned int pmac_get_one_cpufreq(int i);
188f6d57916SPaul Mackerras 	unsigned int freq = pmac_get_one_cpufreq(i);
189f6d57916SPaul Mackerras 	if (freq != 0) {
190f6d57916SPaul Mackerras 		seq_printf(m, "clock\t\t: %dMHz\n", freq/1000);
191*0dd194d0SPaul Mackerras 		return;
192f6d57916SPaul Mackerras 	}
193f6d57916SPaul Mackerras #endif /* CONFIG_CPU_FREQ_PMAC */
194*0dd194d0SPaul Mackerras 	of_show_percpuinfo(m, i);
195f6d57916SPaul Mackerras }
196f6d57916SPaul Mackerras 
197f6d57916SPaul Mackerras static volatile u32 *sysctrl_regs;
198f6d57916SPaul Mackerras 
199f6d57916SPaul Mackerras void __init
200f6d57916SPaul Mackerras pmac_setup_arch(void)
201f6d57916SPaul Mackerras {
202f6d57916SPaul Mackerras 	struct device_node *cpu;
203f6d57916SPaul Mackerras 	int *fp;
204f6d57916SPaul Mackerras 	unsigned long pvr;
205f6d57916SPaul Mackerras 
206f6d57916SPaul Mackerras 	pvr = PVR_VER(mfspr(SPRN_PVR));
207f6d57916SPaul Mackerras 
208f6d57916SPaul Mackerras 	/* Set loops_per_jiffy to a half-way reasonable value,
209f6d57916SPaul Mackerras 	   for use until calibrate_delay gets called. */
210f6d57916SPaul Mackerras 	cpu = find_type_devices("cpu");
211f6d57916SPaul Mackerras 	if (cpu != 0) {
212f6d57916SPaul Mackerras 		fp = (int *) get_property(cpu, "clock-frequency", NULL);
213f6d57916SPaul Mackerras 		if (fp != 0) {
214f6d57916SPaul Mackerras 			if (pvr == 4 || pvr >= 8)
215f6d57916SPaul Mackerras 				/* 604, G3, G4 etc. */
216f6d57916SPaul Mackerras 				loops_per_jiffy = *fp / HZ;
217f6d57916SPaul Mackerras 			else
218f6d57916SPaul Mackerras 				/* 601, 603, etc. */
219f6d57916SPaul Mackerras 				loops_per_jiffy = *fp / (2*HZ);
220f6d57916SPaul Mackerras 		} else
221f6d57916SPaul Mackerras 			loops_per_jiffy = 50000000 / HZ;
222f6d57916SPaul Mackerras 	}
223f6d57916SPaul Mackerras 
224f6d57916SPaul Mackerras 	/* this area has the CPU identification register
225f6d57916SPaul Mackerras 	   and some registers used by smp boards */
226f6d57916SPaul Mackerras 	sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000);
227f6d57916SPaul Mackerras 	ohare_init();
228f6d57916SPaul Mackerras 
229f6d57916SPaul Mackerras 	/* Lookup PCI hosts */
230f6d57916SPaul Mackerras 	pmac_find_bridges();
231f6d57916SPaul Mackerras 
232f6d57916SPaul Mackerras 	/* Checks "l2cr-value" property in the registry */
233f6d57916SPaul Mackerras 	if (cpu_has_feature(CPU_FTR_L2CR)) {
234f6d57916SPaul Mackerras 		struct device_node *np = find_devices("cpus");
235f6d57916SPaul Mackerras 		if (np == 0)
236f6d57916SPaul Mackerras 			np = find_type_devices("cpu");
237f6d57916SPaul Mackerras 		if (np != 0) {
238f6d57916SPaul Mackerras 			unsigned int *l2cr = (unsigned int *)
239f6d57916SPaul Mackerras 				get_property(np, "l2cr-value", NULL);
240f6d57916SPaul Mackerras 			if (l2cr != 0) {
241f6d57916SPaul Mackerras 				ppc_override_l2cr = 1;
242f6d57916SPaul Mackerras 				ppc_override_l2cr_value = *l2cr;
243f6d57916SPaul Mackerras 				_set_L2CR(0);
244f6d57916SPaul Mackerras 				_set_L2CR(ppc_override_l2cr_value);
245f6d57916SPaul Mackerras 			}
246f6d57916SPaul Mackerras 		}
247f6d57916SPaul Mackerras 	}
248f6d57916SPaul Mackerras 
249f6d57916SPaul Mackerras 	if (ppc_override_l2cr)
250f6d57916SPaul Mackerras 		printk(KERN_INFO "L2CR overriden (0x%x), backside cache is %s\n",
251f6d57916SPaul Mackerras 			ppc_override_l2cr_value, (ppc_override_l2cr_value & 0x80000000)
252f6d57916SPaul Mackerras 				? "enabled" : "disabled");
253f6d57916SPaul Mackerras 
254f6d57916SPaul Mackerras #ifdef CONFIG_KGDB
255f6d57916SPaul Mackerras 	zs_kgdb_hook(0);
256f6d57916SPaul Mackerras #endif
257f6d57916SPaul Mackerras 
258f6d57916SPaul Mackerras #ifdef CONFIG_ADB_CUDA
259f6d57916SPaul Mackerras 	find_via_cuda();
260f6d57916SPaul Mackerras #else
261f6d57916SPaul Mackerras 	if (find_devices("via-cuda")) {
262f6d57916SPaul Mackerras 		printk("WARNING ! Your machine is Cuda based but your kernel\n");
263f6d57916SPaul Mackerras 		printk("          wasn't compiled with CONFIG_ADB_CUDA option !\n");
264f6d57916SPaul Mackerras 	}
265f6d57916SPaul Mackerras #endif
266f6d57916SPaul Mackerras #ifdef CONFIG_ADB_PMU
267f6d57916SPaul Mackerras 	find_via_pmu();
268f6d57916SPaul Mackerras #else
269f6d57916SPaul Mackerras 	if (find_devices("via-pmu")) {
270f6d57916SPaul Mackerras 		printk("WARNING ! Your machine is PMU based but your kernel\n");
271f6d57916SPaul Mackerras 		printk("          wasn't compiled with CONFIG_ADB_PMU option !\n");
272f6d57916SPaul Mackerras 	}
273f6d57916SPaul Mackerras #endif
274f6d57916SPaul Mackerras #ifdef CONFIG_NVRAM
275f6d57916SPaul Mackerras 	pmac_nvram_init();
276f6d57916SPaul Mackerras #endif
277f6d57916SPaul Mackerras #ifdef CONFIG_BLK_DEV_INITRD
278f6d57916SPaul Mackerras 	if (initrd_start)
279f6d57916SPaul Mackerras 		ROOT_DEV = Root_RAM0;
280f6d57916SPaul Mackerras 	else
281f6d57916SPaul Mackerras #endif
282f6d57916SPaul Mackerras 		ROOT_DEV = DEFAULT_ROOT_DEVICE;
283f6d57916SPaul Mackerras 
284f6d57916SPaul Mackerras #ifdef CONFIG_SMP
285f6d57916SPaul Mackerras 	/* Check for Core99 */
286f6d57916SPaul Mackerras 	if (find_devices("uni-n") || find_devices("u3"))
2877ed476d1SPaul Mackerras 		smp_ops = &core99_smp_ops;
288f6d57916SPaul Mackerras 	else
2897ed476d1SPaul Mackerras 		smp_ops = &psurge_smp_ops;
290f6d57916SPaul Mackerras #endif /* CONFIG_SMP */
291f6d57916SPaul Mackerras 
292f6d57916SPaul Mackerras 	pci_create_OF_bus_map();
293f6d57916SPaul Mackerras }
294f6d57916SPaul Mackerras 
295f6d57916SPaul Mackerras static void __init ohare_init(void)
296f6d57916SPaul Mackerras {
297f6d57916SPaul Mackerras 	/*
298f6d57916SPaul Mackerras 	 * Turn on the L2 cache.
299f6d57916SPaul Mackerras 	 * We assume that we have a PSX memory controller iff
300f6d57916SPaul Mackerras 	 * we have an ohare I/O controller.
301f6d57916SPaul Mackerras 	 */
302f6d57916SPaul Mackerras 	if (find_devices("ohare") != NULL) {
303f6d57916SPaul Mackerras 		if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) {
304f6d57916SPaul Mackerras 			if (sysctrl_regs[4] & 0x10)
305f6d57916SPaul Mackerras 				sysctrl_regs[4] |= 0x04000020;
306f6d57916SPaul Mackerras 			else
307f6d57916SPaul Mackerras 				sysctrl_regs[4] |= 0x04000000;
308f6d57916SPaul Mackerras 			if(has_l2cache)
309f6d57916SPaul Mackerras 				printk(KERN_INFO "Level 2 cache enabled\n");
310f6d57916SPaul Mackerras 		}
311f6d57916SPaul Mackerras 	}
312f6d57916SPaul Mackerras }
313f6d57916SPaul Mackerras 
314f6d57916SPaul Mackerras char *bootpath;
315f6d57916SPaul Mackerras char *bootdevice;
316f6d57916SPaul Mackerras void *boot_host;
317f6d57916SPaul Mackerras int boot_target;
318f6d57916SPaul Mackerras int boot_part;
319f6d57916SPaul Mackerras extern dev_t boot_dev;
320f6d57916SPaul Mackerras 
321f6d57916SPaul Mackerras #ifdef CONFIG_SCSI
322f6d57916SPaul Mackerras void __init
323f6d57916SPaul Mackerras note_scsi_host(struct device_node *node, void *host)
324f6d57916SPaul Mackerras {
325f6d57916SPaul Mackerras 	int l;
326f6d57916SPaul Mackerras 	char *p;
327f6d57916SPaul Mackerras 
328f6d57916SPaul Mackerras 	l = strlen(node->full_name);
329f6d57916SPaul Mackerras 	if (bootpath != NULL && bootdevice != NULL
330f6d57916SPaul Mackerras 	    && strncmp(node->full_name, bootdevice, l) == 0
331f6d57916SPaul Mackerras 	    && (bootdevice[l] == '/' || bootdevice[l] == 0)) {
332f6d57916SPaul Mackerras 		boot_host = host;
333f6d57916SPaul Mackerras 		/*
334f6d57916SPaul Mackerras 		 * There's a bug in OF 1.0.5.  (Why am I not surprised.)
335f6d57916SPaul Mackerras 		 * If you pass a path like scsi/sd@1:0 to canon, it returns
336f6d57916SPaul Mackerras 		 * something like /bandit@F2000000/gc@10/53c94@10000/sd@0,0
337f6d57916SPaul Mackerras 		 * That is, the scsi target number doesn't get preserved.
338f6d57916SPaul Mackerras 		 * So we pick the target number out of bootpath and use that.
339f6d57916SPaul Mackerras 		 */
340f6d57916SPaul Mackerras 		p = strstr(bootpath, "/sd@");
341f6d57916SPaul Mackerras 		if (p != NULL) {
342f6d57916SPaul Mackerras 			p += 4;
343f6d57916SPaul Mackerras 			boot_target = simple_strtoul(p, NULL, 10);
344f6d57916SPaul Mackerras 			p = strchr(p, ':');
345f6d57916SPaul Mackerras 			if (p != NULL)
346f6d57916SPaul Mackerras 				boot_part = simple_strtoul(p + 1, NULL, 10);
347f6d57916SPaul Mackerras 		}
348f6d57916SPaul Mackerras 	}
349f6d57916SPaul Mackerras }
350f6d57916SPaul Mackerras EXPORT_SYMBOL(note_scsi_host);
351f6d57916SPaul Mackerras #endif
352f6d57916SPaul Mackerras 
353f6d57916SPaul Mackerras #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
354f6d57916SPaul Mackerras static dev_t __init
355f6d57916SPaul Mackerras find_ide_boot(void)
356f6d57916SPaul Mackerras {
357f6d57916SPaul Mackerras 	char *p;
358f6d57916SPaul Mackerras 	int n;
359f6d57916SPaul Mackerras 	dev_t __init pmac_find_ide_boot(char *bootdevice, int n);
360f6d57916SPaul Mackerras 
361f6d57916SPaul Mackerras 	if (bootdevice == NULL)
362f6d57916SPaul Mackerras 		return 0;
363f6d57916SPaul Mackerras 	p = strrchr(bootdevice, '/');
364f6d57916SPaul Mackerras 	if (p == NULL)
365f6d57916SPaul Mackerras 		return 0;
366f6d57916SPaul Mackerras 	n = p - bootdevice;
367f6d57916SPaul Mackerras 
368f6d57916SPaul Mackerras 	return pmac_find_ide_boot(bootdevice, n);
369f6d57916SPaul Mackerras }
370f6d57916SPaul Mackerras #endif /* CONFIG_BLK_DEV_IDE && CONFIG_BLK_DEV_IDE_PMAC */
371f6d57916SPaul Mackerras 
372f6d57916SPaul Mackerras static void __init
373f6d57916SPaul Mackerras find_boot_device(void)
374f6d57916SPaul Mackerras {
375f6d57916SPaul Mackerras #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
376f6d57916SPaul Mackerras 	boot_dev = find_ide_boot();
377f6d57916SPaul Mackerras #endif
378f6d57916SPaul Mackerras }
379f6d57916SPaul Mackerras 
380f6d57916SPaul Mackerras static int initializing = 1;
381f6d57916SPaul Mackerras /* TODO: Merge the suspend-to-ram with the common code !!!
382f6d57916SPaul Mackerras  * currently, this is a stub implementation for suspend-to-disk
383f6d57916SPaul Mackerras  * only
384f6d57916SPaul Mackerras  */
385f6d57916SPaul Mackerras 
386f6d57916SPaul Mackerras #ifdef CONFIG_SOFTWARE_SUSPEND
387f6d57916SPaul Mackerras 
388f6d57916SPaul Mackerras static int pmac_pm_prepare(suspend_state_t state)
389f6d57916SPaul Mackerras {
390f6d57916SPaul Mackerras 	printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
391f6d57916SPaul Mackerras 
392f6d57916SPaul Mackerras 	return 0;
393f6d57916SPaul Mackerras }
394f6d57916SPaul Mackerras 
395f6d57916SPaul Mackerras static int pmac_pm_enter(suspend_state_t state)
396f6d57916SPaul Mackerras {
397f6d57916SPaul Mackerras 	printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
398f6d57916SPaul Mackerras 
399f6d57916SPaul Mackerras 	/* Giveup the lazy FPU & vec so we don't have to back them
400f6d57916SPaul Mackerras 	 * up from the low level code
401f6d57916SPaul Mackerras 	 */
402f6d57916SPaul Mackerras 	enable_kernel_fp();
403f6d57916SPaul Mackerras 
404f6d57916SPaul Mackerras #ifdef CONFIG_ALTIVEC
405f6d57916SPaul Mackerras 	if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
406f6d57916SPaul Mackerras 		enable_kernel_altivec();
407f6d57916SPaul Mackerras #endif /* CONFIG_ALTIVEC */
408f6d57916SPaul Mackerras 
409f6d57916SPaul Mackerras 	return 0;
410f6d57916SPaul Mackerras }
411f6d57916SPaul Mackerras 
412f6d57916SPaul Mackerras static int pmac_pm_finish(suspend_state_t state)
413f6d57916SPaul Mackerras {
414f6d57916SPaul Mackerras 	printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
415f6d57916SPaul Mackerras 
416f6d57916SPaul Mackerras 	/* Restore userland MMU context */
417f6d57916SPaul Mackerras 	set_context(current->active_mm->context, current->active_mm->pgd);
418f6d57916SPaul Mackerras 
419f6d57916SPaul Mackerras 	return 0;
420f6d57916SPaul Mackerras }
421f6d57916SPaul Mackerras 
422f6d57916SPaul Mackerras static struct pm_ops pmac_pm_ops = {
423f6d57916SPaul Mackerras 	.pm_disk_mode	= PM_DISK_SHUTDOWN,
424f6d57916SPaul Mackerras 	.prepare	= pmac_pm_prepare,
425f6d57916SPaul Mackerras 	.enter		= pmac_pm_enter,
426f6d57916SPaul Mackerras 	.finish		= pmac_pm_finish,
427f6d57916SPaul Mackerras };
428f6d57916SPaul Mackerras 
429f6d57916SPaul Mackerras #endif /* CONFIG_SOFTWARE_SUSPEND */
430f6d57916SPaul Mackerras 
431f6d57916SPaul Mackerras static int pmac_late_init(void)
432f6d57916SPaul Mackerras {
433f6d57916SPaul Mackerras 	initializing = 0;
434f6d57916SPaul Mackerras #ifdef CONFIG_SOFTWARE_SUSPEND
435f6d57916SPaul Mackerras 	pm_set_ops(&pmac_pm_ops);
436f6d57916SPaul Mackerras #endif /* CONFIG_SOFTWARE_SUSPEND */
437f6d57916SPaul Mackerras 	return 0;
438f6d57916SPaul Mackerras }
439f6d57916SPaul Mackerras 
440f6d57916SPaul Mackerras late_initcall(pmac_late_init);
441f6d57916SPaul Mackerras 
442f6d57916SPaul Mackerras /* can't be __init - can be called whenever a disk is first accessed */
443f6d57916SPaul Mackerras void
444f6d57916SPaul Mackerras note_bootable_part(dev_t dev, int part, int goodness)
445f6d57916SPaul Mackerras {
446f6d57916SPaul Mackerras 	static int found_boot = 0;
447f6d57916SPaul Mackerras 	char *p;
448f6d57916SPaul Mackerras 
449f6d57916SPaul Mackerras 	if (!initializing)
450f6d57916SPaul Mackerras 		return;
451f6d57916SPaul Mackerras 	if ((goodness <= current_root_goodness) &&
452f6d57916SPaul Mackerras 	    ROOT_DEV != DEFAULT_ROOT_DEVICE)
453f6d57916SPaul Mackerras 		return;
454f6d57916SPaul Mackerras 	p = strstr(saved_command_line, "root=");
455f6d57916SPaul Mackerras 	if (p != NULL && (p == saved_command_line || p[-1] == ' '))
456f6d57916SPaul Mackerras 		return;
457f6d57916SPaul Mackerras 
458f6d57916SPaul Mackerras 	if (!found_boot) {
459f6d57916SPaul Mackerras 		find_boot_device();
460f6d57916SPaul Mackerras 		found_boot = 1;
461f6d57916SPaul Mackerras 	}
462f6d57916SPaul Mackerras 	if (!boot_dev || dev == boot_dev) {
463f6d57916SPaul Mackerras 		ROOT_DEV = dev + part;
464f6d57916SPaul Mackerras 		boot_dev = 0;
465f6d57916SPaul Mackerras 		current_root_goodness = goodness;
466f6d57916SPaul Mackerras 	}
467f6d57916SPaul Mackerras }
468f6d57916SPaul Mackerras 
469f6d57916SPaul Mackerras static void
470f6d57916SPaul Mackerras pmac_restart(char *cmd)
471f6d57916SPaul Mackerras {
472f6d57916SPaul Mackerras #ifdef CONFIG_ADB_CUDA
473f6d57916SPaul Mackerras 	struct adb_request req;
474f6d57916SPaul Mackerras #endif /* CONFIG_ADB_CUDA */
475f6d57916SPaul Mackerras 
476f6d57916SPaul Mackerras 	switch (sys_ctrler) {
477f6d57916SPaul Mackerras #ifdef CONFIG_ADB_CUDA
478f6d57916SPaul Mackerras 	case SYS_CTRLER_CUDA:
479f6d57916SPaul Mackerras 		cuda_request(&req, NULL, 2, CUDA_PACKET,
480f6d57916SPaul Mackerras 			     CUDA_RESET_SYSTEM);
481f6d57916SPaul Mackerras 		for (;;)
482f6d57916SPaul Mackerras 			cuda_poll();
483f6d57916SPaul Mackerras 		break;
484f6d57916SPaul Mackerras #endif /* CONFIG_ADB_CUDA */
485f6d57916SPaul Mackerras #ifdef CONFIG_ADB_PMU
486f6d57916SPaul Mackerras 	case SYS_CTRLER_PMU:
487f6d57916SPaul Mackerras 		pmu_restart();
488f6d57916SPaul Mackerras 		break;
489f6d57916SPaul Mackerras #endif /* CONFIG_ADB_PMU */
490f6d57916SPaul Mackerras 	default: ;
491f6d57916SPaul Mackerras 	}
492f6d57916SPaul Mackerras }
493f6d57916SPaul Mackerras 
494f6d57916SPaul Mackerras static void
495f6d57916SPaul Mackerras pmac_power_off(void)
496f6d57916SPaul Mackerras {
497f6d57916SPaul Mackerras #ifdef CONFIG_ADB_CUDA
498f6d57916SPaul Mackerras 	struct adb_request req;
499f6d57916SPaul Mackerras #endif /* CONFIG_ADB_CUDA */
500f6d57916SPaul Mackerras 
501f6d57916SPaul Mackerras 	switch (sys_ctrler) {
502f6d57916SPaul Mackerras #ifdef CONFIG_ADB_CUDA
503f6d57916SPaul Mackerras 	case SYS_CTRLER_CUDA:
504f6d57916SPaul Mackerras 		cuda_request(&req, NULL, 2, CUDA_PACKET,
505f6d57916SPaul Mackerras 			     CUDA_POWERDOWN);
506f6d57916SPaul Mackerras 		for (;;)
507f6d57916SPaul Mackerras 			cuda_poll();
508f6d57916SPaul Mackerras 		break;
509f6d57916SPaul Mackerras #endif /* CONFIG_ADB_CUDA */
510f6d57916SPaul Mackerras #ifdef CONFIG_ADB_PMU
511f6d57916SPaul Mackerras 	case SYS_CTRLER_PMU:
512f6d57916SPaul Mackerras 		pmu_shutdown();
513f6d57916SPaul Mackerras 		break;
514f6d57916SPaul Mackerras #endif /* CONFIG_ADB_PMU */
515f6d57916SPaul Mackerras 	default: ;
516f6d57916SPaul Mackerras 	}
517f6d57916SPaul Mackerras }
518f6d57916SPaul Mackerras 
519f6d57916SPaul Mackerras static void
520f6d57916SPaul Mackerras pmac_halt(void)
521f6d57916SPaul Mackerras {
522f6d57916SPaul Mackerras 	pmac_power_off();
523f6d57916SPaul Mackerras }
524f6d57916SPaul Mackerras 
525f6d57916SPaul Mackerras void __init pmac_init(void)
526f6d57916SPaul Mackerras {
527f6d57916SPaul Mackerras 	/* isa_io_base gets set in pmac_find_bridges */
528f6d57916SPaul Mackerras 	isa_mem_base = PMAC_ISA_MEM_BASE;
529f6d57916SPaul Mackerras 	pci_dram_offset = PMAC_PCI_DRAM_OFFSET;
530f6d57916SPaul Mackerras 	ISA_DMA_THRESHOLD = ~0L;
531f6d57916SPaul Mackerras 	DMA_MODE_READ = 1;
532f6d57916SPaul Mackerras 	DMA_MODE_WRITE = 2;
533f6d57916SPaul Mackerras 
534f6d57916SPaul Mackerras 	ppc_md.setup_arch     = pmac_setup_arch;
535f6d57916SPaul Mackerras 	ppc_md.show_cpuinfo   = pmac_show_cpuinfo;
536f6d57916SPaul Mackerras 	ppc_md.show_percpuinfo = pmac_show_percpuinfo;
537f6d57916SPaul Mackerras 	ppc_md.init_IRQ       = pmac_pic_init;
538f6d57916SPaul Mackerras 	ppc_md.get_irq        = pmac_get_irq; /* Changed later on ... */
539f6d57916SPaul Mackerras 
540f6d57916SPaul Mackerras 	ppc_md.pcibios_fixup  = pmac_pcibios_fixup;
541f6d57916SPaul Mackerras 	ppc_md.pcibios_enable_device_hook = pmac_pci_enable_device_hook;
542f6d57916SPaul Mackerras 	ppc_md.pcibios_after_init = pmac_pcibios_after_init;
543f6d57916SPaul Mackerras 	ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
544f6d57916SPaul Mackerras 
545f6d57916SPaul Mackerras 	ppc_md.restart        = pmac_restart;
546f6d57916SPaul Mackerras 	ppc_md.power_off      = pmac_power_off;
547f6d57916SPaul Mackerras 	ppc_md.halt           = pmac_halt;
548f6d57916SPaul Mackerras 
549f6d57916SPaul Mackerras 	ppc_md.time_init      = pmac_time_init;
550f6d57916SPaul Mackerras 	ppc_md.set_rtc_time   = pmac_set_rtc_time;
551f6d57916SPaul Mackerras 	ppc_md.get_rtc_time   = pmac_get_rtc_time;
552143a1decSPaul Mackerras 	ppc_md.get_boot_time  = pmac_get_boot_time;
553f6d57916SPaul Mackerras 	ppc_md.calibrate_decr = pmac_calibrate_decr;
554f6d57916SPaul Mackerras 
555f6d57916SPaul Mackerras 	ppc_md.feature_call   = pmac_do_feature_call;
556f6d57916SPaul Mackerras 
557f6d57916SPaul Mackerras #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
558f6d57916SPaul Mackerras #ifdef CONFIG_BLK_DEV_IDE_PMAC
559f6d57916SPaul Mackerras         ppc_ide_md.ide_init_hwif	= pmac_ide_init_hwif_ports;
560f6d57916SPaul Mackerras         ppc_ide_md.default_io_base	= pmac_ide_get_base;
561f6d57916SPaul Mackerras #endif /* CONFIG_BLK_DEV_IDE_PMAC */
562f6d57916SPaul Mackerras #endif /* defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE) */
563f6d57916SPaul Mackerras 
564f6d57916SPaul Mackerras #ifdef CONFIG_BOOTX_TEXT
565f6d57916SPaul Mackerras 	ppc_md.progress = pmac_progress;
566f6d57916SPaul Mackerras #endif /* CONFIG_BOOTX_TEXT */
567f6d57916SPaul Mackerras 
568f6d57916SPaul Mackerras 	if (ppc_md.progress) ppc_md.progress("pmac_init(): exit", 0);
569f6d57916SPaul Mackerras 
570f6d57916SPaul Mackerras }
571f6d57916SPaul Mackerras 
572f6d57916SPaul Mackerras #ifdef CONFIG_BOOTX_TEXT
573f6d57916SPaul Mackerras static void __init
574f6d57916SPaul Mackerras pmac_progress(char *s, unsigned short hex)
575f6d57916SPaul Mackerras {
576f6d57916SPaul Mackerras 	if (boot_text_mapped) {
577f6d57916SPaul Mackerras 		btext_drawstring(s);
578f6d57916SPaul Mackerras 		btext_drawchar('\n');
579f6d57916SPaul Mackerras 	}
580f6d57916SPaul Mackerras }
581f6d57916SPaul Mackerras #endif /* CONFIG_BOOTX_TEXT */
582f6d57916SPaul Mackerras 
583f6d57916SPaul Mackerras static int __init
584f6d57916SPaul Mackerras pmac_declare_of_platform_devices(void)
585f6d57916SPaul Mackerras {
586f6d57916SPaul Mackerras 	struct device_node *np;
587f6d57916SPaul Mackerras 
588f6d57916SPaul Mackerras 	np = find_devices("uni-n");
589f6d57916SPaul Mackerras 	if (np) {
590f6d57916SPaul Mackerras 		for (np = np->child; np != NULL; np = np->sibling)
591f6d57916SPaul Mackerras 			if (strncmp(np->name, "i2c", 3) == 0) {
592f6d57916SPaul Mackerras 				of_platform_device_create(np, "uni-n-i2c",
593f6d57916SPaul Mackerras 							  NULL);
594f6d57916SPaul Mackerras 				break;
595f6d57916SPaul Mackerras 			}
596f6d57916SPaul Mackerras 	}
597f6d57916SPaul Mackerras 	np = find_devices("u3");
598f6d57916SPaul Mackerras 	if (np) {
599f6d57916SPaul Mackerras 		for (np = np->child; np != NULL; np = np->sibling)
600f6d57916SPaul Mackerras 			if (strncmp(np->name, "i2c", 3) == 0) {
601f6d57916SPaul Mackerras 				of_platform_device_create(np, "u3-i2c",
602f6d57916SPaul Mackerras 							  NULL);
603f6d57916SPaul Mackerras 				break;
604f6d57916SPaul Mackerras 			}
605f6d57916SPaul Mackerras 	}
606f6d57916SPaul Mackerras 
607f6d57916SPaul Mackerras 	np = find_devices("valkyrie");
608f6d57916SPaul Mackerras 	if (np)
609f6d57916SPaul Mackerras 		of_platform_device_create(np, "valkyrie", NULL);
610f6d57916SPaul Mackerras 	np = find_devices("platinum");
611f6d57916SPaul Mackerras 	if (np)
612f6d57916SPaul Mackerras 		of_platform_device_create(np, "platinum", NULL);
613f6d57916SPaul Mackerras 
614f6d57916SPaul Mackerras 	return 0;
615f6d57916SPaul Mackerras }
616f6d57916SPaul Mackerras 
617f6d57916SPaul Mackerras device_initcall(pmac_declare_of_platform_devices);
618