blob: 88ccf3a08a9c387ef13ac373d3f08e2368460350 [file] [log] [blame]
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001/*
Paul Mackerras35499c02005-10-22 16:02:39 +10002 * Powermac setup and early boot code plus other random bits.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10003 *
4 * PowerPC version
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6 *
7 * Adapted for Power Macintosh by Paul Mackerras
Paul Mackerras35499c02005-10-22 16:02:39 +10008 * Copyright (C) 1996 Paul Mackerras (paulus@samba.org)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10009 *
10 * Derived from "arch/alpha/kernel/setup.c"
11 * Copyright (C) 1995 Linus Torvalds
12 *
13 * Maintained by Benjamin Herrenschmidt (benh@kernel.crashing.org)
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
19 *
20 */
21
22/*
23 * bootup setup stuff..
24 */
25
Paul Mackerras14cf11a2005-09-26 16:04:21 +100026#include <linux/init.h>
27#include <linux/errno.h>
28#include <linux/sched.h>
29#include <linux/kernel.h>
30#include <linux/mm.h>
31#include <linux/stddef.h>
32#include <linux/unistd.h>
33#include <linux/ptrace.h>
34#include <linux/slab.h>
35#include <linux/user.h>
36#include <linux/a.out.h>
37#include <linux/tty.h>
38#include <linux/string.h>
39#include <linux/delay.h>
40#include <linux/ioport.h>
41#include <linux/major.h>
42#include <linux/initrd.h>
43#include <linux/vt_kern.h>
44#include <linux/console.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100045#include <linux/pci.h>
46#include <linux/adb.h>
47#include <linux/cuda.h>
48#include <linux/pmu.h>
49#include <linux/irq.h>
50#include <linux/seq_file.h>
51#include <linux/root_dev.h>
52#include <linux/bitops.h>
53#include <linux/suspend.h>
Jon Loeliger5f867dc2007-11-14 04:13:03 +110054#include <linux/of_device.h>
55#include <linux/of_platform.h>
David S. Millerd9b2b2a2008-02-13 16:56:49 -080056#include <linux/lmb.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100057
58#include <asm/reg.h>
59#include <asm/sections.h>
60#include <asm/prom.h>
61#include <asm/system.h>
62#include <asm/pgtable.h>
63#include <asm/io.h>
Michael Ellerman3d1229d2005-11-14 23:35:00 +110064#include <asm/kexec.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100065#include <asm/pci-bridge.h>
66#include <asm/ohare.h>
67#include <asm/mediabay.h>
68#include <asm/machdep.h>
69#include <asm/dma.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100070#include <asm/cputable.h>
71#include <asm/btext.h>
72#include <asm/pmac_feature.h>
73#include <asm/time.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100074#include <asm/mmu_context.h>
Paul Mackerras35499c02005-10-22 16:02:39 +100075#include <asm/iommu.h>
76#include <asm/smu.h>
77#include <asm/pmc.h>
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +110078#include <asm/udbg.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100079
Paul Mackerras3c3f42d2005-10-10 22:58:41 +100080#include "pmac.h"
Paul Mackerras14cf11a2005-09-26 16:04:21 +100081
82#undef SHOW_GATWICK_IRQS
83
Paul Mackerras14cf11a2005-09-26 16:04:21 +100084int ppc_override_l2cr = 0;
85int ppc_override_l2cr_value;
86int has_l2cache = 0;
87
Olaf Heringd2515c82006-01-22 22:19:02 +010088int pmac_newworld;
Paul Mackerras9b6b5632005-10-06 12:06:20 +100089
Paul Mackerras14cf11a2005-09-26 16:04:21 +100090static int current_root_goodness = -1;
91
Paul Mackerras35499c02005-10-22 16:02:39 +100092extern struct machdep_calls pmac_md;
Paul Mackerras14cf11a2005-09-26 16:04:21 +100093
94#define DEFAULT_ROOT_DEVICE Root_SDA1 /* sda1 - slightly silly choice */
95
Paul Mackerras35499c02005-10-22 16:02:39 +100096#ifdef CONFIG_PPC64
Paul Mackerras35499c02005-10-22 16:02:39 +100097int sccdbg;
Paul Mackerras14cf11a2005-09-26 16:04:21 +100098#endif
99
100sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN;
Paul Mackerras35499c02005-10-22 16:02:39 +1000101EXPORT_SYMBOL(sys_ctrler);
102
103#ifdef CONFIG_PMAC_SMU
104unsigned long smu_cmdbuf_abs;
105EXPORT_SYMBOL(smu_cmdbuf_abs);
106#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000107
108#ifdef CONFIG_SMP
109extern struct smp_ops_t psurge_smp_ops;
110extern struct smp_ops_t core99_smp_ops;
111#endif /* CONFIG_SMP */
112
Paul Mackerras0dd194d2005-10-20 20:48:19 +1000113static void pmac_show_cpuinfo(struct seq_file *m)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000114{
115 struct device_node *np;
Jeremy Kerr018a3d12006-07-12 15:40:29 +1000116 const char *pp;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000117 int plen;
Paul Mackerras0dd194d2005-10-20 20:48:19 +1000118 int mbmodel;
119 unsigned int mbflags;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000120 char* mbname;
121
Paul Mackerras0dd194d2005-10-20 20:48:19 +1000122 mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
123 PMAC_MB_INFO_MODEL, 0);
124 mbflags = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
125 PMAC_MB_INFO_FLAGS, 0);
126 if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME,
127 (long) &mbname) != 0)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000128 mbname = "Unknown";
129
130 /* find motherboard type */
131 seq_printf(m, "machine\t\t: ");
Paul Mackerras0dd194d2005-10-20 20:48:19 +1000132 np = of_find_node_by_path("/");
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000133 if (np != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000134 pp = of_get_property(np, "model", NULL);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000135 if (pp != NULL)
136 seq_printf(m, "%s\n", pp);
137 else
138 seq_printf(m, "PowerMac\n");
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000139 pp = of_get_property(np, "compatible", &plen);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000140 if (pp != NULL) {
141 seq_printf(m, "motherboard\t:");
142 while (plen > 0) {
143 int l = strlen(pp) + 1;
144 seq_printf(m, " %s", pp);
145 plen -= l;
146 pp += l;
147 }
148 seq_printf(m, "\n");
149 }
Paul Mackerras0dd194d2005-10-20 20:48:19 +1000150 of_node_put(np);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000151 } else
152 seq_printf(m, "PowerMac\n");
153
154 /* print parsed model */
155 seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname);
156 seq_printf(m, "pmac flags\t: %08x\n", mbflags);
157
158 /* find l2 cache info */
Paul Mackerras0dd194d2005-10-20 20:48:19 +1000159 np = of_find_node_by_name(NULL, "l2-cache");
160 if (np == NULL)
161 np = of_find_node_by_type(NULL, "cache");
162 if (np != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000163 const unsigned int *ic =
164 of_get_property(np, "i-cache-size", NULL);
165 const unsigned int *dc =
166 of_get_property(np, "d-cache-size", NULL);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000167 seq_printf(m, "L2 cache\t:");
168 has_l2cache = 1;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000169 if (of_get_property(np, "cache-unified", NULL) != 0 && dc) {
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000170 seq_printf(m, " %dK unified", *dc / 1024);
171 } else {
172 if (ic)
173 seq_printf(m, " %dK instruction", *ic / 1024);
174 if (dc)
175 seq_printf(m, "%s %dK data",
176 (ic? " +": ""), *dc / 1024);
177 }
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000178 pp = of_get_property(np, "ram-type", NULL);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000179 if (pp)
180 seq_printf(m, " %s", pp);
181 seq_printf(m, "\n");
Paul Mackerras0dd194d2005-10-20 20:48:19 +1000182 of_node_put(np);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000183 }
184
185 /* Indicate newworld/oldworld */
186 seq_printf(m, "pmac-generation\t: %s\n",
187 pmac_newworld ? "NewWorld" : "OldWorld");
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000188}
189
Paul Mackerras35499c02005-10-22 16:02:39 +1000190#ifndef CONFIG_ADB_CUDA
191int find_via_cuda(void)
192{
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000193 struct device_node *dn = of_find_node_by_name(NULL, "via-cuda");
194
195 if (!dn)
Paul Mackerras35499c02005-10-22 16:02:39 +1000196 return 0;
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000197 of_node_put(dn);
Paul Mackerras35499c02005-10-22 16:02:39 +1000198 printk("WARNING ! Your machine is CUDA-based but your kernel\n");
199 printk(" wasn't compiled with CONFIG_ADB_CUDA option !\n");
200 return 0;
201}
202#endif
203
204#ifndef CONFIG_ADB_PMU
205int find_via_pmu(void)
206{
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000207 struct device_node *dn = of_find_node_by_name(NULL, "via-pmu");
208
209 if (!dn)
Paul Mackerras35499c02005-10-22 16:02:39 +1000210 return 0;
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000211 of_node_put(dn);
Paul Mackerras35499c02005-10-22 16:02:39 +1000212 printk("WARNING ! Your machine is PMU-based but your kernel\n");
213 printk(" wasn't compiled with CONFIG_ADB_PMU option !\n");
Paul Mackerrasa575b802005-10-23 17:23:21 +1000214 return 0;
Paul Mackerras35499c02005-10-22 16:02:39 +1000215}
216#endif
217
218#ifndef CONFIG_PMAC_SMU
219int smu_init(void)
220{
221 /* should check and warn if SMU is present */
222 return 0;
223}
224#endif
225
226#ifdef CONFIG_PPC32
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000227static volatile u32 *sysctrl_regs;
228
Paul Mackerras35499c02005-10-22 16:02:39 +1000229static void __init ohare_init(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000230{
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000231 struct device_node *dn;
232
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000233 /* this area has the CPU identification register
234 and some registers used by smp boards */
235 sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000236
Paul Mackerras35499c02005-10-22 16:02:39 +1000237 /*
238 * Turn on the L2 cache.
239 * We assume that we have a PSX memory controller iff
240 * we have an ohare I/O controller.
241 */
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000242 dn = of_find_node_by_name(NULL, "ohare");
243 if (dn) {
244 of_node_put(dn);
Paul Mackerras35499c02005-10-22 16:02:39 +1000245 if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) {
246 if (sysctrl_regs[4] & 0x10)
247 sysctrl_regs[4] |= 0x04000020;
248 else
249 sysctrl_regs[4] |= 0x04000000;
250 if(has_l2cache)
251 printk(KERN_INFO "Level 2 cache enabled\n");
252 }
253 }
254}
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000255
Paul Mackerras35499c02005-10-22 16:02:39 +1000256static void __init l2cr_init(void)
257{
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000258 /* Checks "l2cr-value" property in the registry */
259 if (cpu_has_feature(CPU_FTR_L2CR)) {
Stephen Rothwell1658ab62007-04-24 13:51:59 +1000260 struct device_node *np = of_find_node_by_name(NULL, "cpus");
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000261 if (np == 0)
Stephen Rothwell1658ab62007-04-24 13:51:59 +1000262 np = of_find_node_by_type(NULL, "cpu");
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000263 if (np != 0) {
Jeremy Kerr018a3d12006-07-12 15:40:29 +1000264 const unsigned int *l2cr =
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000265 of_get_property(np, "l2cr-value", NULL);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000266 if (l2cr != 0) {
267 ppc_override_l2cr = 1;
268 ppc_override_l2cr_value = *l2cr;
269 _set_L2CR(0);
270 _set_L2CR(ppc_override_l2cr_value);
271 }
Stephen Rothwell1658ab62007-04-24 13:51:59 +1000272 of_node_put(np);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000273 }
274 }
275
276 if (ppc_override_l2cr)
Paul Mackerras35499c02005-10-22 16:02:39 +1000277 printk(KERN_INFO "L2CR overridden (0x%x), "
278 "backside cache is %s\n",
279 ppc_override_l2cr_value,
280 (ppc_override_l2cr_value & 0x80000000)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000281 ? "enabled" : "disabled");
Paul Mackerras35499c02005-10-22 16:02:39 +1000282}
283#endif
284
Arnd Bergmannff38e7c2006-01-11 00:00:03 +0000285static void __init pmac_setup_arch(void)
Paul Mackerras35499c02005-10-22 16:02:39 +1000286{
Paul Mackerrasa575b802005-10-23 17:23:21 +1000287 struct device_node *cpu, *ic;
Jeremy Kerr018a3d12006-07-12 15:40:29 +1000288 const int *fp;
Paul Mackerras35499c02005-10-22 16:02:39 +1000289 unsigned long pvr;
290
291 pvr = PVR_VER(mfspr(SPRN_PVR));
292
293 /* Set loops_per_jiffy to a half-way reasonable value,
294 for use until calibrate_delay gets called. */
295 loops_per_jiffy = 50000000 / HZ;
296 cpu = of_find_node_by_type(NULL, "cpu");
297 if (cpu != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000298 fp = of_get_property(cpu, "clock-frequency", NULL);
Paul Mackerras35499c02005-10-22 16:02:39 +1000299 if (fp != NULL) {
300 if (pvr >= 0x30 && pvr < 0x80)
301 /* PPC970 etc. */
302 loops_per_jiffy = *fp / (3 * HZ);
303 else if (pvr == 4 || pvr >= 8)
304 /* 604, G3, G4 etc. */
305 loops_per_jiffy = *fp / HZ;
306 else
307 /* 601, 603, etc. */
308 loops_per_jiffy = *fp / (2 * HZ);
309 }
310 of_node_put(cpu);
311 }
312
Paul Mackerrasa575b802005-10-23 17:23:21 +1000313 /* See if newworld or oldworld */
Paul Mackerrasbfab1012005-10-27 22:45:33 +1000314 for (ic = NULL; (ic = of_find_all_nodes(ic)) != NULL; )
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000315 if (of_get_property(ic, "interrupt-controller", NULL))
Paul Mackerrasbfab1012005-10-27 22:45:33 +1000316 break;
Olaf Heringd2515c82006-01-22 22:19:02 +0100317 if (ic) {
318 pmac_newworld = 1;
Paul Mackerrasa575b802005-10-23 17:23:21 +1000319 of_node_put(ic);
Olaf Heringd2515c82006-01-22 22:19:02 +0100320 }
Paul Mackerrasa575b802005-10-23 17:23:21 +1000321
Paul Mackerras35499c02005-10-22 16:02:39 +1000322 /* Lookup PCI hosts */
323 pmac_pci_init();
324
325#ifdef CONFIG_PPC32
326 ohare_init();
327 l2cr_init();
328#endif /* CONFIG_PPC32 */
329
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000330 find_via_cuda();
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000331 find_via_pmu();
Paul Mackerras35499c02005-10-22 16:02:39 +1000332 smu_init();
333
Tony Breeds21e38df2008-04-29 11:42:32 +1000334#if defined(CONFIG_NVRAM) || defined(CONFIG_NVRAM_MODULE) || \
335 defined(CONFIG_PPC64)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000336 pmac_nvram_init();
337#endif
Paul Mackerras35499c02005-10-22 16:02:39 +1000338
339#ifdef CONFIG_PPC32
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000340#ifdef CONFIG_BLK_DEV_INITRD
341 if (initrd_start)
342 ROOT_DEV = Root_RAM0;
343 else
344#endif
345 ROOT_DEV = DEFAULT_ROOT_DEVICE;
Paul Mackerras35499c02005-10-22 16:02:39 +1000346#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000347
348#ifdef CONFIG_SMP
349 /* Check for Core99 */
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000350 ic = of_find_node_by_name(NULL, "uni-n");
351 if (!ic)
352 ic = of_find_node_by_name(NULL, "u3");
353 if (!ic)
354 ic = of_find_node_by_name(NULL, "u4");
355 if (ic) {
356 of_node_put(ic);
Paul Mackerras7ed476d2005-10-19 21:44:51 +1000357 smp_ops = &core99_smp_ops;
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000358 }
Paul Mackerras35499c02005-10-22 16:02:39 +1000359#ifdef CONFIG_PPC32
Paul Mackerrasc63c4fa2007-06-07 22:42:19 +1000360 else {
361 /*
362 * We have to set bits in cpu_possible_map here since the
363 * secondary CPU(s) aren't in the device tree, and
364 * setup_per_cpu_areas only allocates per-cpu data for
365 * CPUs in the cpu_possible_map.
366 */
367 int cpu;
368
369 for (cpu = 1; cpu < 4 && cpu < NR_CPUS; ++cpu)
370 cpu_set(cpu, cpu_possible_map);
Paul Mackerras7ed476d2005-10-19 21:44:51 +1000371 smp_ops = &psurge_smp_ops;
Paul Mackerrasc63c4fa2007-06-07 22:42:19 +1000372 }
Paul Mackerras35499c02005-10-22 16:02:39 +1000373#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000374#endif /* CONFIG_SMP */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100375
376#ifdef CONFIG_ADB
377 if (strstr(cmd_line, "adb_sync")) {
378 extern int __adb_probe_sync;
379 __adb_probe_sync = 1;
380 }
381#endif /* CONFIG_ADB */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000382}
383
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000384#ifdef CONFIG_SCSI
Li Yang405861a2007-05-23 11:28:03 +0800385void note_scsi_host(struct device_node *node, void *host)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000386{
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000387}
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000388EXPORT_SYMBOL(note_scsi_host);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000389#endif
390
Paul Mackerras35499c02005-10-22 16:02:39 +1000391static int initializing = 1;
392
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000393static int pmac_late_init(void)
394{
395 initializing = 0;
Johannes Bergd9333af2007-05-03 06:33:51 +1000396 /* this is udbg (which is __init) and we can later use it during
397 * cpu hotplug (in smp_core99_kick_cpu) */
398 ppc_md.progress = NULL;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000399 return 0;
400}
Grant Likelyd518b712008-01-03 06:14:28 +1100401machine_late_initcall(powermac, pmac_late_init);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000402
Stephen Rothwelld7418032007-10-04 12:00:28 +1000403/*
404 * This is __init_refok because we check for "initializing" before
405 * touching any of the __init sensitive things and "initializing"
406 * will be false after __init time. This can't be __init because it
407 * can be called whenever a disk is first accessed.
408 */
409void __init_refok note_bootable_part(dev_t dev, int part, int goodness)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000410{
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000411 char *p;
412
413 if (!initializing)
414 return;
415 if ((goodness <= current_root_goodness) &&
416 ROOT_DEV != DEFAULT_ROOT_DEVICE)
417 return;
Alon Bar-Levb8757b22007-02-12 00:54:17 -0800418 p = strstr(boot_command_line, "root=");
419 if (p != NULL && (p == boot_command_line || p[-1] == ' '))
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000420 return;
421
Paul Mackerras6ee0d9f2007-10-04 13:47:06 +1000422 ROOT_DEV = dev + part;
423 current_root_goodness = goodness;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000424}
425
Paul Mackerras35499c02005-10-22 16:02:39 +1000426#ifdef CONFIG_ADB_CUDA
427static void cuda_restart(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000428{
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000429 struct adb_request req;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000430
Paul Mackerras35499c02005-10-22 16:02:39 +1000431 cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM);
432 for (;;)
433 cuda_poll();
434}
435
436static void cuda_shutdown(void)
437{
438 struct adb_request req;
439
440 cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN);
441 for (;;)
442 cuda_poll();
443}
444
445#else
446#define cuda_restart()
447#define cuda_shutdown()
448#endif
449
450#ifndef CONFIG_ADB_PMU
451#define pmu_restart()
452#define pmu_shutdown()
453#endif
454
455#ifndef CONFIG_PMAC_SMU
456#define smu_restart()
457#define smu_shutdown()
458#endif
459
460static void pmac_restart(char *cmd)
461{
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000462 switch (sys_ctrler) {
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000463 case SYS_CTRLER_CUDA:
Paul Mackerras35499c02005-10-22 16:02:39 +1000464 cuda_restart();
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000465 break;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000466 case SYS_CTRLER_PMU:
467 pmu_restart();
468 break;
Paul Mackerras35499c02005-10-22 16:02:39 +1000469 case SYS_CTRLER_SMU:
470 smu_restart();
471 break;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000472 default: ;
473 }
474}
475
Paul Mackerras35499c02005-10-22 16:02:39 +1000476static void pmac_power_off(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000477{
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000478 switch (sys_ctrler) {
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000479 case SYS_CTRLER_CUDA:
Paul Mackerras35499c02005-10-22 16:02:39 +1000480 cuda_shutdown();
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000481 break;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000482 case SYS_CTRLER_PMU:
483 pmu_shutdown();
484 break;
Paul Mackerras35499c02005-10-22 16:02:39 +1000485 case SYS_CTRLER_SMU:
486 smu_shutdown();
487 break;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000488 default: ;
489 }
490}
491
492static void
493pmac_halt(void)
494{
495 pmac_power_off();
496}
497
Paul Mackerras35499c02005-10-22 16:02:39 +1000498/*
499 * Early initialization.
500 */
501static void __init pmac_init_early(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000502{
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100503 /* Enable early btext debug if requested */
504 if (strstr(cmd_line, "btextdbg")) {
505 udbg_adb_init_early();
506 register_early_udbg_console();
Paul Mackerras35499c02005-10-22 16:02:39 +1000507 }
508
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100509 /* Probe motherboard chipset */
510 pmac_feature_init();
511
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100512 /* Initialize debug stuff */
513 udbg_scc_init(!!strstr(cmd_line, "sccdbg"));
514 udbg_adb_init(!!strstr(cmd_line, "btextdbg"));
515
516#ifdef CONFIG_PPC64
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100517 iommu_init_early_dart();
Paul Mackerras35499c02005-10-22 16:02:39 +1000518#endif
519}
520
Paul Mackerras35499c02005-10-22 16:02:39 +1000521static int __init pmac_declare_of_platform_devices(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000522{
Benjamin Herrenschmidta28d3af2006-01-07 11:35:26 +1100523 struct device_node *np;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000524
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100525 if (machine_is(chrp))
526 return -1;
527
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100528 np = of_find_node_by_name(NULL, "valkyrie");
Paul Mackerras35499c02005-10-22 16:02:39 +1000529 if (np)
530 of_platform_device_create(np, "valkyrie", NULL);
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100531 np = of_find_node_by_name(NULL, "platinum");
Paul Mackerras35499c02005-10-22 16:02:39 +1000532 if (np)
533 of_platform_device_create(np, "platinum", NULL);
Paul Mackerras35499c02005-10-22 16:02:39 +1000534 np = of_find_node_by_type(NULL, "smu");
535 if (np) {
536 of_platform_device_create(np, "smu", NULL);
537 of_node_put(np);
538 }
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000539
540 return 0;
541}
Grant Likelyd518b712008-01-03 06:14:28 +1100542machine_device_initcall(powermac, pmac_declare_of_platform_devices);
Paul Mackerras35499c02005-10-22 16:02:39 +1000543
Benjamin Herrenschmidt025d7912008-07-28 13:49:15 +1000544#ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
545/*
546 * This is called very early, as part of console_init() (typically just after
547 * time_init()). This function is respondible for trying to find a good
548 * default console on serial ports. It tries to match the open firmware
549 * default output with one of the available serial console drivers.
550 */
551static int __init check_pmac_serial_console(void)
552{
553 struct device_node *prom_stdout = NULL;
554 int offset = 0;
555 const char *name;
556#ifdef CONFIG_SERIAL_PMACZILOG_TTYS
557 char *devname = "ttyS";
558#else
559 char *devname = "ttyPZ";
560#endif
561
562 pr_debug(" -> check_pmac_serial_console()\n");
563
564 /* The user has requested a console so this is already set up. */
565 if (strstr(boot_command_line, "console=")) {
566 pr_debug(" console was specified !\n");
567 return -EBUSY;
568 }
569
570 if (!of_chosen) {
571 pr_debug(" of_chosen is NULL !\n");
572 return -ENODEV;
573 }
574
575 /* We are getting a weird phandle from OF ... */
576 /* ... So use the full path instead */
577 name = of_get_property(of_chosen, "linux,stdout-path", NULL);
578 if (name == NULL) {
579 pr_debug(" no linux,stdout-path !\n");
580 return -ENODEV;
581 }
582 prom_stdout = of_find_node_by_path(name);
583 if (!prom_stdout) {
584 pr_debug(" can't find stdout package %s !\n", name);
585 return -ENODEV;
586 }
587 pr_debug("stdout is %s\n", prom_stdout->full_name);
588
589 name = of_get_property(prom_stdout, "name", NULL);
590 if (!name) {
591 pr_debug(" stdout package has no name !\n");
592 goto not_found;
593 }
594
595 if (strcmp(name, "ch-a") == 0)
596 offset = 0;
597 else if (strcmp(name, "ch-b") == 0)
598 offset = 1;
599 else
600 goto not_found;
601 of_node_put(prom_stdout);
602
603 pr_debug("Found serial console at %s%d\n", devname, offset);
604
605 return add_preferred_console(devname, offset, NULL);
606
607 not_found:
608 pr_debug("No preferred console found !\n");
609 of_node_put(prom_stdout);
610 return -ENODEV;
611}
612console_initcall(check_pmac_serial_console);
613
614#endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */
615
Paul Mackerras35499c02005-10-22 16:02:39 +1000616/*
617 * Called very early, MMU is off, device-tree isn't unflattened
618 */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100619static int __init pmac_probe(void)
Paul Mackerras35499c02005-10-22 16:02:39 +1000620{
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100621 unsigned long root = of_get_flat_dt_root();
622
623 if (!of_flat_dt_is_compatible(root, "Power Macintosh") &&
624 !of_flat_dt_is_compatible(root, "MacRISC"))
Paul Mackerras35499c02005-10-22 16:02:39 +1000625 return 0;
626
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100627#ifdef CONFIG_PPC64
Paul Mackerras35499c02005-10-22 16:02:39 +1000628 /*
629 * On U3, the DART (iommu) must be allocated now since it
630 * has an impact on htab_initialize (due to the large page it
631 * occupies having to be broken up so the DART itself is not
632 * part of the cacheable linar mapping
633 */
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100634 alloc_dart_table();
Michael Ellerman7d0daae2006-06-23 18:16:38 +1000635
636 hpte_init_native();
Paul Mackerras35499c02005-10-22 16:02:39 +1000637#endif
638
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100639#ifdef CONFIG_PPC32
640 /* isa_io_base gets set in pmac_pci_init */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100641 ISA_DMA_THRESHOLD = ~0L;
642 DMA_MODE_READ = 1;
643 DMA_MODE_WRITE = 2;
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100644#endif /* CONFIG_PPC32 */
645
Paul Mackerras35499c02005-10-22 16:02:39 +1000646#ifdef CONFIG_PMAC_SMU
647 /*
648 * SMU based G5s need some memory below 2Gb, at least the current
649 * driver needs that. We have to allocate it now. We allocate 4k
650 * (1 small page) for now.
651 */
652 smu_cmdbuf_abs = lmb_alloc_base(4096, 4096, 0x80000000UL);
653#endif /* CONFIG_PMAC_SMU */
654
655 return 1;
656}
657
658#ifdef CONFIG_PPC64
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100659/* Move that to pci.c */
660static int pmac_pci_probe_mode(struct pci_bus *bus)
Paul Mackerras35499c02005-10-22 16:02:39 +1000661{
662 struct device_node *node = bus->sysdata;
663
664 /* We need to use normal PCI probing for the AGP bus,
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100665 * since the device for the AGP bridge isn't in the tree.
Benjamin Herrenschmidt444532d2007-12-20 14:55:01 +1100666 * Same for the PCIe host on U4 and the HT host bridge.
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100667 */
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000668 if (bus->self == NULL && (of_device_is_compatible(node, "u3-agp") ||
Benjamin Herrenschmidt444532d2007-12-20 14:55:01 +1100669 of_device_is_compatible(node, "u4-pcie") ||
670 of_device_is_compatible(node, "u3-ht")))
Paul Mackerras35499c02005-10-22 16:02:39 +1000671 return PCI_PROBE_NORMAL;
Paul Mackerras35499c02005-10-22 16:02:39 +1000672 return PCI_PROBE_DEVTREE;
673}
Johannes Bergd9333af2007-05-03 06:33:51 +1000674
675#ifdef CONFIG_HOTPLUG_CPU
676/* access per cpu vars from generic smp.c */
677DECLARE_PER_CPU(int, cpu_state);
678
679static void pmac_cpu_die(void)
680{
681 /*
682 * turn off as much as possible, we'll be
683 * kicked out as this will only be invoked
684 * on core99 platforms for now ...
685 */
686
687 printk(KERN_INFO "CPU#%d offline\n", smp_processor_id());
688 __get_cpu_var(cpu_state) = CPU_DEAD;
689 smp_wmb();
690
691 /*
692 * during the path that leads here preemption is disabled,
693 * reenable it now so that when coming up preempt count is
694 * zero correctly
695 */
696 preempt_enable();
697
698 /*
699 * hard-disable interrupts for the non-NAP case, the NAP code
700 * needs to re-enable interrupts (but soft-disables them)
701 */
702 hard_irq_disable();
703
704 while (1) {
705 /* let's not take timer interrupts too often ... */
706 set_dec(0x7fffffff);
707
708 /* should always be true at this point */
709 if (cpu_has_feature(CPU_FTR_CAN_NAP))
710 power4_cpu_offline_powersave();
711 else {
712 HMT_low();
713 HMT_very_low();
714 }
715 }
716}
717#endif /* CONFIG_HOTPLUG_CPU */
718
719#endif /* CONFIG_PPC64 */
Paul Mackerras35499c02005-10-22 16:02:39 +1000720
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100721define_machine(powermac) {
722 .name = "PowerMac",
Paul Mackerras35499c02005-10-22 16:02:39 +1000723 .probe = pmac_probe,
724 .setup_arch = pmac_setup_arch,
725 .init_early = pmac_init_early,
726 .show_cpuinfo = pmac_show_cpuinfo,
Paul Mackerras35499c02005-10-22 16:02:39 +1000727 .init_IRQ = pmac_pic_init,
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100728 .get_irq = NULL, /* changed later */
Benjamin Herrenschmidtf90bb152006-11-11 17:24:51 +1100729 .pci_irq_fixup = pmac_pci_irq_fixup,
Paul Mackerras35499c02005-10-22 16:02:39 +1000730 .restart = pmac_restart,
731 .power_off = pmac_power_off,
732 .halt = pmac_halt,
733 .time_init = pmac_time_init,
734 .get_boot_time = pmac_get_boot_time,
735 .set_rtc_time = pmac_set_rtc_time,
736 .get_rtc_time = pmac_get_rtc_time,
737 .calibrate_decr = pmac_calibrate_decr,
738 .feature_call = pmac_do_feature_call,
Kumar Galabe6b8432005-12-20 16:37:07 -0600739 .progress = udbg_progress,
Paul Mackerras35499c02005-10-22 16:02:39 +1000740#ifdef CONFIG_PPC64
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100741 .pci_probe_mode = pmac_pci_probe_mode,
Paul Mackerrasa0652fc2006-03-27 15:03:03 +1100742 .power_save = power4_idle,
Paul Mackerras35499c02005-10-22 16:02:39 +1000743 .enable_pmcs = power4_enable_pmcs,
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100744#ifdef CONFIG_KEXEC
745 .machine_kexec = default_machine_kexec,
746 .machine_kexec_prepare = default_machine_kexec_prepare,
Michael Ellermancc532912005-12-04 18:39:43 +1100747 .machine_crash_shutdown = default_machine_crash_shutdown,
Paul Mackerras35499c02005-10-22 16:02:39 +1000748#endif
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100749#endif /* CONFIG_PPC64 */
Paul Mackerras35499c02005-10-22 16:02:39 +1000750#ifdef CONFIG_PPC32
751 .pcibios_enable_device_hook = pmac_pci_enable_device_hook,
752 .pcibios_after_init = pmac_pcibios_after_init,
753 .phys_mem_access_prot = pci_phys_mem_access_prot,
754#endif
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100755#if defined(CONFIG_HOTPLUG_CPU) && defined(CONFIG_PPC64)
Johannes Bergd9333af2007-05-03 06:33:51 +1000756 .cpu_die = pmac_cpu_die,
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100757#endif
Paul Mackerras35499c02005-10-22 16:02:39 +1000758};