blob: 974d4b49867b5a91251bc2bedd747624f29e73fd [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Paul Mackerras14cf11a2005-09-26 16:04:21 +10002/*
Paul Mackerras35499c02005-10-22 16:02:39 +10003 * Powermac setup and early boot code plus other random bits.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10004 *
5 * PowerPC version
6 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 *
8 * Adapted for Power Macintosh by Paul Mackerras
Paul Mackerras35499c02005-10-22 16:02:39 +10009 * Copyright (C) 1996 Paul Mackerras (paulus@samba.org)
Paul Mackerras14cf11a2005-09-26 16:04:21 +100010 *
11 * Derived from "arch/alpha/kernel/setup.c"
12 * Copyright (C) 1995 Linus Torvalds
13 *
14 * Maintained by Benjamin Herrenschmidt (benh@kernel.crashing.org)
Paul Mackerras14cf11a2005-09-26 16:04:21 +100015 */
16
17/*
18 * bootup setup stuff..
19 */
20
Paul Mackerras14cf11a2005-09-26 16:04:21 +100021#include <linux/init.h>
22#include <linux/errno.h>
23#include <linux/sched.h>
24#include <linux/kernel.h>
25#include <linux/mm.h>
26#include <linux/stddef.h>
27#include <linux/unistd.h>
28#include <linux/ptrace.h>
Paul Gortmaker66b15db2011-05-27 10:46:24 -040029#include <linux/export.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100030#include <linux/user.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100031#include <linux/tty.h>
32#include <linux/string.h>
33#include <linux/delay.h>
34#include <linux/ioport.h>
35#include <linux/major.h>
36#include <linux/initrd.h>
37#include <linux/vt_kern.h>
38#include <linux/console.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100039#include <linux/pci.h>
40#include <linux/adb.h>
41#include <linux/cuda.h>
42#include <linux/pmu.h>
43#include <linux/irq.h>
44#include <linux/seq_file.h>
45#include <linux/root_dev.h>
46#include <linux/bitops.h>
47#include <linux/suspend.h>
Jon Loeliger5f867dc2007-11-14 04:13:03 +110048#include <linux/of_device.h>
49#include <linux/of_platform.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100050
51#include <asm/reg.h>
52#include <asm/sections.h>
53#include <asm/prom.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100054#include <asm/io.h>
55#include <asm/pci-bridge.h>
56#include <asm/ohare.h>
57#include <asm/mediabay.h>
58#include <asm/machdep.h>
59#include <asm/dma.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100060#include <asm/cputable.h>
61#include <asm/btext.h>
62#include <asm/pmac_feature.h>
63#include <asm/time.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100064#include <asm/mmu_context.h>
Paul Mackerras35499c02005-10-22 16:02:39 +100065#include <asm/iommu.h>
66#include <asm/smu.h>
67#include <asm/pmc.h>
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +110068#include <asm/udbg.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100069
Paul Mackerras3c3f42d2005-10-10 22:58:41 +100070#include "pmac.h"
Paul Mackerras14cf11a2005-09-26 16:04:21 +100071
72#undef SHOW_GATWICK_IRQS
73
Paul Mackerras14cf11a2005-09-26 16:04:21 +100074int ppc_override_l2cr = 0;
75int ppc_override_l2cr_value;
76int has_l2cache = 0;
77
Olaf Heringd2515c82006-01-22 22:19:02 +010078int pmac_newworld;
Paul Mackerras9b6b5632005-10-06 12:06:20 +100079
Paul Mackerras14cf11a2005-09-26 16:04:21 +100080static int current_root_goodness = -1;
81
Paul Mackerras14cf11a2005-09-26 16:04:21 +100082#define DEFAULT_ROOT_DEVICE Root_SDA1 /* sda1 - slightly silly choice */
83
Paul Mackerras35499c02005-10-22 16:02:39 +100084#ifdef CONFIG_PPC64
Paul Mackerras35499c02005-10-22 16:02:39 +100085int sccdbg;
Paul Mackerras14cf11a2005-09-26 16:04:21 +100086#endif
87
88sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN;
Paul Mackerras35499c02005-10-22 16:02:39 +100089EXPORT_SYMBOL(sys_ctrler);
90
Paul Mackerras0dd194d2005-10-20 20:48:19 +100091static void pmac_show_cpuinfo(struct seq_file *m)
Paul Mackerras14cf11a2005-09-26 16:04:21 +100092{
93 struct device_node *np;
Jeremy Kerr018a3d12006-07-12 15:40:29 +100094 const char *pp;
Paul Mackerras14cf11a2005-09-26 16:04:21 +100095 int plen;
Paul Mackerras0dd194d2005-10-20 20:48:19 +100096 int mbmodel;
97 unsigned int mbflags;
Paul Mackerras14cf11a2005-09-26 16:04:21 +100098 char* mbname;
99
Paul Mackerras0dd194d2005-10-20 20:48:19 +1000100 mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
101 PMAC_MB_INFO_MODEL, 0);
102 mbflags = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
103 PMAC_MB_INFO_FLAGS, 0);
104 if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME,
105 (long) &mbname) != 0)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000106 mbname = "Unknown";
107
108 /* find motherboard type */
109 seq_printf(m, "machine\t\t: ");
Paul Mackerras0dd194d2005-10-20 20:48:19 +1000110 np = of_find_node_by_path("/");
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000111 if (np != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000112 pp = of_get_property(np, "model", NULL);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000113 if (pp != NULL)
114 seq_printf(m, "%s\n", pp);
115 else
116 seq_printf(m, "PowerMac\n");
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000117 pp = of_get_property(np, "compatible", &plen);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000118 if (pp != NULL) {
119 seq_printf(m, "motherboard\t:");
120 while (plen > 0) {
121 int l = strlen(pp) + 1;
122 seq_printf(m, " %s", pp);
123 plen -= l;
124 pp += l;
125 }
126 seq_printf(m, "\n");
127 }
Paul Mackerras0dd194d2005-10-20 20:48:19 +1000128 of_node_put(np);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000129 } else
130 seq_printf(m, "PowerMac\n");
131
132 /* print parsed model */
133 seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname);
134 seq_printf(m, "pmac flags\t: %08x\n", mbflags);
135
136 /* find l2 cache info */
Paul Mackerras0dd194d2005-10-20 20:48:19 +1000137 np = of_find_node_by_name(NULL, "l2-cache");
138 if (np == NULL)
139 np = of_find_node_by_type(NULL, "cache");
140 if (np != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000141 const unsigned int *ic =
142 of_get_property(np, "i-cache-size", NULL);
143 const unsigned int *dc =
144 of_get_property(np, "d-cache-size", NULL);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000145 seq_printf(m, "L2 cache\t:");
146 has_l2cache = 1;
Mathieu Malaterred8731522018-04-13 20:41:43 +0200147 if (of_get_property(np, "cache-unified", NULL) && dc) {
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000148 seq_printf(m, " %dK unified", *dc / 1024);
149 } else {
150 if (ic)
151 seq_printf(m, " %dK instruction", *ic / 1024);
152 if (dc)
153 seq_printf(m, "%s %dK data",
154 (ic? " +": ""), *dc / 1024);
155 }
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000156 pp = of_get_property(np, "ram-type", NULL);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000157 if (pp)
158 seq_printf(m, " %s", pp);
159 seq_printf(m, "\n");
Paul Mackerras0dd194d2005-10-20 20:48:19 +1000160 of_node_put(np);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000161 }
162
163 /* Indicate newworld/oldworld */
164 seq_printf(m, "pmac-generation\t: %s\n",
165 pmac_newworld ? "NewWorld" : "OldWorld");
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000166}
167
Paul Mackerras35499c02005-10-22 16:02:39 +1000168#ifndef CONFIG_ADB_CUDA
Nick Child7da1d1d2021-12-16 17:00:35 -0500169int __init find_via_cuda(void)
Paul Mackerras35499c02005-10-22 16:02:39 +1000170{
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000171 struct device_node *dn = of_find_node_by_name(NULL, "via-cuda");
172
173 if (!dn)
Paul Mackerras35499c02005-10-22 16:02:39 +1000174 return 0;
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000175 of_node_put(dn);
Paul Mackerras35499c02005-10-22 16:02:39 +1000176 printk("WARNING ! Your machine is CUDA-based but your kernel\n");
177 printk(" wasn't compiled with CONFIG_ADB_CUDA option !\n");
178 return 0;
179}
180#endif
181
182#ifndef CONFIG_ADB_PMU
Nick Child7da1d1d2021-12-16 17:00:35 -0500183int __init find_via_pmu(void)
Paul Mackerras35499c02005-10-22 16:02:39 +1000184{
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000185 struct device_node *dn = of_find_node_by_name(NULL, "via-pmu");
186
187 if (!dn)
Paul Mackerras35499c02005-10-22 16:02:39 +1000188 return 0;
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000189 of_node_put(dn);
Paul Mackerras35499c02005-10-22 16:02:39 +1000190 printk("WARNING ! Your machine is PMU-based but your kernel\n");
191 printk(" wasn't compiled with CONFIG_ADB_PMU option !\n");
Paul Mackerrasa575b802005-10-23 17:23:21 +1000192 return 0;
Paul Mackerras35499c02005-10-22 16:02:39 +1000193}
194#endif
195
196#ifndef CONFIG_PMAC_SMU
Nick Childb346f572021-12-16 17:00:25 -0500197int __init smu_init(void)
Paul Mackerras35499c02005-10-22 16:02:39 +1000198{
199 /* should check and warn if SMU is present */
200 return 0;
201}
202#endif
203
204#ifdef CONFIG_PPC32
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000205static volatile u32 *sysctrl_regs;
206
Paul Mackerras35499c02005-10-22 16:02:39 +1000207static void __init ohare_init(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000208{
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000209 struct device_node *dn;
210
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000211 /* this area has the CPU identification register
212 and some registers used by smp boards */
213 sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000214
Paul Mackerras35499c02005-10-22 16:02:39 +1000215 /*
216 * Turn on the L2 cache.
217 * We assume that we have a PSX memory controller iff
218 * we have an ohare I/O controller.
219 */
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000220 dn = of_find_node_by_name(NULL, "ohare");
221 if (dn) {
222 of_node_put(dn);
Paul Mackerras35499c02005-10-22 16:02:39 +1000223 if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) {
224 if (sysctrl_regs[4] & 0x10)
225 sysctrl_regs[4] |= 0x04000020;
226 else
227 sysctrl_regs[4] |= 0x04000000;
228 if(has_l2cache)
229 printk(KERN_INFO "Level 2 cache enabled\n");
230 }
231 }
232}
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000233
Paul Mackerras35499c02005-10-22 16:02:39 +1000234static void __init l2cr_init(void)
235{
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000236 /* Checks "l2cr-value" property in the registry */
237 if (cpu_has_feature(CPU_FTR_L2CR)) {
Rob Herringa94fe362018-08-27 12:24:09 -0500238 struct device_node *np;
239
240 for_each_of_cpu_node(np) {
Jeremy Kerr018a3d12006-07-12 15:40:29 +1000241 const unsigned int *l2cr =
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000242 of_get_property(np, "l2cr-value", NULL);
Mathieu Malaterred8731522018-04-13 20:41:43 +0200243 if (l2cr) {
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000244 ppc_override_l2cr = 1;
245 ppc_override_l2cr_value = *l2cr;
246 _set_L2CR(0);
247 _set_L2CR(ppc_override_l2cr_value);
248 }
Stephen Rothwell1658ab62007-04-24 13:51:59 +1000249 of_node_put(np);
Rob Herringa94fe362018-08-27 12:24:09 -0500250 break;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000251 }
252 }
253
254 if (ppc_override_l2cr)
Paul Mackerras35499c02005-10-22 16:02:39 +1000255 printk(KERN_INFO "L2CR overridden (0x%x), "
256 "backside cache is %s\n",
257 ppc_override_l2cr_value,
258 (ppc_override_l2cr_value & 0x80000000)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000259 ? "enabled" : "disabled");
Paul Mackerras35499c02005-10-22 16:02:39 +1000260}
261#endif
262
Arnd Bergmannff38e7c2006-01-11 00:00:03 +0000263static void __init pmac_setup_arch(void)
Paul Mackerras35499c02005-10-22 16:02:39 +1000264{
Paul Mackerrasa575b802005-10-23 17:23:21 +1000265 struct device_node *cpu, *ic;
Jeremy Kerr018a3d12006-07-12 15:40:29 +1000266 const int *fp;
Paul Mackerras35499c02005-10-22 16:02:39 +1000267 unsigned long pvr;
268
269 pvr = PVR_VER(mfspr(SPRN_PVR));
270
271 /* Set loops_per_jiffy to a half-way reasonable value,
272 for use until calibrate_delay gets called. */
273 loops_per_jiffy = 50000000 / HZ;
Rob Herringa94fe362018-08-27 12:24:09 -0500274
275 for_each_of_cpu_node(cpu) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000276 fp = of_get_property(cpu, "clock-frequency", NULL);
Paul Mackerras35499c02005-10-22 16:02:39 +1000277 if (fp != NULL) {
278 if (pvr >= 0x30 && pvr < 0x80)
279 /* PPC970 etc. */
280 loops_per_jiffy = *fp / (3 * HZ);
281 else if (pvr == 4 || pvr >= 8)
282 /* 604, G3, G4 etc. */
283 loops_per_jiffy = *fp / HZ;
284 else
Christophe Leroy8b14e1d2020-09-29 06:48:36 +0000285 /* 603, etc. */
Paul Mackerras35499c02005-10-22 16:02:39 +1000286 loops_per_jiffy = *fp / (2 * HZ);
Rob Herringa94fe362018-08-27 12:24:09 -0500287 of_node_put(cpu);
288 break;
Paul Mackerras35499c02005-10-22 16:02:39 +1000289 }
Paul Mackerras35499c02005-10-22 16:02:39 +1000290 }
291
Paul Mackerrasa575b802005-10-23 17:23:21 +1000292 /* See if newworld or oldworld */
Michael Ellerman22059a92008-11-12 18:20:43 +0000293 ic = of_find_node_with_property(NULL, "interrupt-controller");
Olaf Heringd2515c82006-01-22 22:19:02 +0100294 if (ic) {
295 pmac_newworld = 1;
Paul Mackerrasa575b802005-10-23 17:23:21 +1000296 of_node_put(ic);
Olaf Heringd2515c82006-01-22 22:19:02 +0100297 }
Paul Mackerrasa575b802005-10-23 17:23:21 +1000298
Paul Mackerras35499c02005-10-22 16:02:39 +1000299#ifdef CONFIG_PPC32
300 ohare_init();
301 l2cr_init();
302#endif /* CONFIG_PPC32 */
303
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000304 find_via_cuda();
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000305 find_via_pmu();
Paul Mackerras35499c02005-10-22 16:02:39 +1000306 smu_init();
307
Finn Thain20e07af2019-01-15 15:18:56 +1100308#if IS_ENABLED(CONFIG_NVRAM)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000309 pmac_nvram_init();
310#endif
Paul Mackerras35499c02005-10-22 16:02:39 +1000311#ifdef CONFIG_PPC32
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000312#ifdef CONFIG_BLK_DEV_INITRD
313 if (initrd_start)
314 ROOT_DEV = Root_RAM0;
315 else
316#endif
317 ROOT_DEV = DEFAULT_ROOT_DEVICE;
Paul Mackerras35499c02005-10-22 16:02:39 +1000318#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000319
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100320#ifdef CONFIG_ADB
Anton Blanchard3e47d142014-09-17 14:39:36 +1000321 if (strstr(boot_command_line, "adb_sync")) {
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100322 extern int __adb_probe_sync;
323 __adb_probe_sync = 1;
324 }
325#endif /* CONFIG_ADB */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000326}
327
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000328#ifdef CONFIG_SCSI
Li Yang405861a2007-05-23 11:28:03 +0800329void note_scsi_host(struct device_node *node, void *host)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000330{
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000331}
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000332EXPORT_SYMBOL(note_scsi_host);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000333#endif
334
Paul Mackerras35499c02005-10-22 16:02:39 +1000335static int initializing = 1;
336
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000337static int pmac_late_init(void)
338{
339 initializing = 0;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000340 return 0;
341}
Grant Likelyd518b712008-01-03 06:14:28 +1100342machine_late_initcall(powermac, pmac_late_init);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000343
Mathieu Malaterref72cf3f2018-04-04 22:13:05 +0200344void note_bootable_part(dev_t dev, int part, int goodness);
Stephen Rothwelld7418032007-10-04 12:00:28 +1000345/*
Fabian Frederickbd721ea2016-08-02 14:03:33 -0700346 * This is __ref because we check for "initializing" before
Stephen Rothwelld7418032007-10-04 12:00:28 +1000347 * touching any of the __init sensitive things and "initializing"
348 * will be false after __init time. This can't be __init because it
349 * can be called whenever a disk is first accessed.
350 */
Fabian Frederickbd721ea2016-08-02 14:03:33 -0700351void __ref note_bootable_part(dev_t dev, int part, int goodness)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000352{
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000353 char *p;
354
355 if (!initializing)
356 return;
357 if ((goodness <= current_root_goodness) &&
358 ROOT_DEV != DEFAULT_ROOT_DEVICE)
359 return;
Alon Bar-Levb8757b22007-02-12 00:54:17 -0800360 p = strstr(boot_command_line, "root=");
361 if (p != NULL && (p == boot_command_line || p[-1] == ' '))
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000362 return;
363
Paul Mackerras6ee0d9f2007-10-04 13:47:06 +1000364 ROOT_DEV = dev + part;
365 current_root_goodness = goodness;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000366}
367
Paul Mackerras35499c02005-10-22 16:02:39 +1000368#ifdef CONFIG_ADB_CUDA
Daniel Axtens95ec77c2016-07-12 10:54:52 +1000369static void __noreturn cuda_restart(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000370{
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000371 struct adb_request req;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000372
Paul Mackerras35499c02005-10-22 16:02:39 +1000373 cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM);
374 for (;;)
375 cuda_poll();
376}
377
Daniel Axtens95ec77c2016-07-12 10:54:52 +1000378static void __noreturn cuda_shutdown(void)
Paul Mackerras35499c02005-10-22 16:02:39 +1000379{
380 struct adb_request req;
381
382 cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN);
383 for (;;)
384 cuda_poll();
385}
386
387#else
388#define cuda_restart()
389#define cuda_shutdown()
390#endif
391
392#ifndef CONFIG_ADB_PMU
393#define pmu_restart()
394#define pmu_shutdown()
395#endif
396
397#ifndef CONFIG_PMAC_SMU
398#define smu_restart()
399#define smu_shutdown()
400#endif
401
Daniel Axtens95ec77c2016-07-12 10:54:52 +1000402static void __noreturn pmac_restart(char *cmd)
Paul Mackerras35499c02005-10-22 16:02:39 +1000403{
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000404 switch (sys_ctrler) {
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000405 case SYS_CTRLER_CUDA:
Paul Mackerras35499c02005-10-22 16:02:39 +1000406 cuda_restart();
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000407 break;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000408 case SYS_CTRLER_PMU:
409 pmu_restart();
410 break;
Paul Mackerras35499c02005-10-22 16:02:39 +1000411 case SYS_CTRLER_SMU:
412 smu_restart();
413 break;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000414 default: ;
415 }
Daniel Axtens95ec77c2016-07-12 10:54:52 +1000416 while (1) ;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000417}
418
Daniel Axtens95ec77c2016-07-12 10:54:52 +1000419static void __noreturn pmac_power_off(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000420{
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000421 switch (sys_ctrler) {
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000422 case SYS_CTRLER_CUDA:
Paul Mackerras35499c02005-10-22 16:02:39 +1000423 cuda_shutdown();
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000424 break;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000425 case SYS_CTRLER_PMU:
426 pmu_shutdown();
427 break;
Paul Mackerras35499c02005-10-22 16:02:39 +1000428 case SYS_CTRLER_SMU:
429 smu_shutdown();
430 break;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000431 default: ;
432 }
Daniel Axtens95ec77c2016-07-12 10:54:52 +1000433 while (1) ;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000434}
435
Daniel Axtens95ec77c2016-07-12 10:54:52 +1000436static void __noreturn
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000437pmac_halt(void)
438{
439 pmac_power_off();
440}
441
Paul Mackerras35499c02005-10-22 16:02:39 +1000442/*
443 * Early initialization.
444 */
Benjamin Herrenschmidtf2d57692016-07-05 15:04:06 +1000445static void __init pmac_init(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000446{
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100447 /* Enable early btext debug if requested */
Anton Blanchard3e47d142014-09-17 14:39:36 +1000448 if (strstr(boot_command_line, "btextdbg")) {
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100449 udbg_adb_init_early();
450 register_early_udbg_console();
Paul Mackerras35499c02005-10-22 16:02:39 +1000451 }
452
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100453 /* Probe motherboard chipset */
454 pmac_feature_init();
455
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100456 /* Initialize debug stuff */
Anton Blanchard3e47d142014-09-17 14:39:36 +1000457 udbg_scc_init(!!strstr(boot_command_line, "sccdbg"));
458 udbg_adb_init(!!strstr(boot_command_line, "btextdbg"));
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100459
460#ifdef CONFIG_PPC64
Daniel Axtense63f26d2015-03-31 16:00:49 +1100461 iommu_init_early_dart(&pmac_pci_controller_ops);
Paul Mackerras35499c02005-10-22 16:02:39 +1000462#endif
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000463
464 /* SMP Init has to be done early as we need to patch up
Anton Blanchard828a6982010-04-26 15:32:44 +0000465 * cpu_possible_mask before interrupt stacks are allocated
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000466 * or kaboom...
467 */
468#ifdef CONFIG_SMP
469 pmac_setup_smp();
470#endif
Paul Mackerras35499c02005-10-22 16:02:39 +1000471}
472
Paul Mackerras35499c02005-10-22 16:02:39 +1000473static int __init pmac_declare_of_platform_devices(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000474{
Benjamin Herrenschmidta28d3af2006-01-07 11:35:26 +1100475 struct device_node *np;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000476
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100477 np = of_find_node_by_name(NULL, "valkyrie");
Julia Lawall3631cb82011-08-21 06:10:01 +0000478 if (np) {
Paul Mackerras35499c02005-10-22 16:02:39 +1000479 of_platform_device_create(np, "valkyrie", NULL);
Julia Lawall3631cb82011-08-21 06:10:01 +0000480 of_node_put(np);
481 }
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100482 np = of_find_node_by_name(NULL, "platinum");
Julia Lawall3631cb82011-08-21 06:10:01 +0000483 if (np) {
Paul Mackerras35499c02005-10-22 16:02:39 +1000484 of_platform_device_create(np, "platinum", NULL);
Julia Lawall3631cb82011-08-21 06:10:01 +0000485 of_node_put(np);
486 }
Paul Mackerras35499c02005-10-22 16:02:39 +1000487 np = of_find_node_by_type(NULL, "smu");
488 if (np) {
489 of_platform_device_create(np, "smu", NULL);
490 of_node_put(np);
491 }
Marc Zyngier98b14d62010-12-05 05:05:37 +0000492 np = of_find_node_by_type(NULL, "fcu");
493 if (np == NULL) {
494 /* Some machines have strangely broken device-tree */
495 np = of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/fan@15e");
496 }
497 if (np) {
498 of_platform_device_create(np, "temperature", NULL);
499 of_node_put(np);
500 }
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000501
502 return 0;
503}
Grant Likelyd518b712008-01-03 06:14:28 +1100504machine_device_initcall(powermac, pmac_declare_of_platform_devices);
Paul Mackerras35499c02005-10-22 16:02:39 +1000505
Benjamin Herrenschmidt025d7912008-07-28 13:49:15 +1000506#ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
507/*
508 * This is called very early, as part of console_init() (typically just after
509 * time_init()). This function is respondible for trying to find a good
510 * default console on serial ports. It tries to match the open firmware
511 * default output with one of the available serial console drivers.
512 */
513static int __init check_pmac_serial_console(void)
514{
515 struct device_node *prom_stdout = NULL;
516 int offset = 0;
517 const char *name;
518#ifdef CONFIG_SERIAL_PMACZILOG_TTYS
519 char *devname = "ttyS";
520#else
521 char *devname = "ttyPZ";
522#endif
523
524 pr_debug(" -> check_pmac_serial_console()\n");
525
526 /* The user has requested a console so this is already set up. */
527 if (strstr(boot_command_line, "console=")) {
528 pr_debug(" console was specified !\n");
529 return -EBUSY;
530 }
531
532 if (!of_chosen) {
533 pr_debug(" of_chosen is NULL !\n");
534 return -ENODEV;
535 }
536
537 /* We are getting a weird phandle from OF ... */
538 /* ... So use the full path instead */
539 name = of_get_property(of_chosen, "linux,stdout-path", NULL);
540 if (name == NULL) {
541 pr_debug(" no linux,stdout-path !\n");
542 return -ENODEV;
543 }
544 prom_stdout = of_find_node_by_path(name);
545 if (!prom_stdout) {
546 pr_debug(" can't find stdout package %s !\n", name);
547 return -ENODEV;
548 }
Rob Herringb7c670d2017-08-21 10:16:47 -0500549 pr_debug("stdout is %pOF\n", prom_stdout);
Benjamin Herrenschmidt025d7912008-07-28 13:49:15 +1000550
Rob Herring2c8e65b2018-12-05 13:50:18 -0600551 if (of_node_name_eq(prom_stdout, "ch-a"))
Benjamin Herrenschmidt025d7912008-07-28 13:49:15 +1000552 offset = 0;
Rob Herring2c8e65b2018-12-05 13:50:18 -0600553 else if (of_node_name_eq(prom_stdout, "ch-b"))
Benjamin Herrenschmidt025d7912008-07-28 13:49:15 +1000554 offset = 1;
555 else
556 goto not_found;
557 of_node_put(prom_stdout);
558
559 pr_debug("Found serial console at %s%d\n", devname, offset);
560
561 return add_preferred_console(devname, offset, NULL);
562
563 not_found:
564 pr_debug("No preferred console found !\n");
565 of_node_put(prom_stdout);
566 return -ENODEV;
567}
568console_initcall(check_pmac_serial_console);
569
570#endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */
571
Paul Mackerras35499c02005-10-22 16:02:39 +1000572/*
573 * Called very early, MMU is off, device-tree isn't unflattened
574 */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100575static int __init pmac_probe(void)
Paul Mackerras35499c02005-10-22 16:02:39 +1000576{
Benjamin Herrenschmidt406b0b62016-07-05 15:04:00 +1000577 if (!of_machine_is_compatible("Power Macintosh") &&
578 !of_machine_is_compatible("MacRISC"))
579 return 0;
Paul Mackerras35499c02005-10-22 16:02:39 +1000580
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100581#ifdef CONFIG_PPC32
582 /* isa_io_base gets set in pmac_pci_init */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100583 DMA_MODE_READ = 1;
584 DMA_MODE_WRITE = 2;
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100585#endif /* CONFIG_PPC32 */
586
Alexander Graf9178ba22014-10-13 16:01:09 +0200587 pm_power_off = pmac_power_off;
588
Benjamin Herrenschmidtf2d57692016-07-05 15:04:06 +1000589 pmac_init();
590
Paul Mackerras35499c02005-10-22 16:02:39 +1000591 return 1;
592}
593
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100594define_machine(powermac) {
595 .name = "PowerMac",
Paul Mackerras35499c02005-10-22 16:02:39 +1000596 .probe = pmac_probe,
597 .setup_arch = pmac_setup_arch,
Oliver O'Halloranfbbefb322020-11-03 15:35:07 +1100598 .discover_phbs = pmac_pci_init,
Paul Mackerras35499c02005-10-22 16:02:39 +1000599 .show_cpuinfo = pmac_show_cpuinfo,
Paul Mackerras35499c02005-10-22 16:02:39 +1000600 .init_IRQ = pmac_pic_init,
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100601 .get_irq = NULL, /* changed later */
Benjamin Herrenschmidtf90bb152006-11-11 17:24:51 +1100602 .pci_irq_fixup = pmac_pci_irq_fixup,
Paul Mackerras35499c02005-10-22 16:02:39 +1000603 .restart = pmac_restart,
Paul Mackerras35499c02005-10-22 16:02:39 +1000604 .halt = pmac_halt,
605 .time_init = pmac_time_init,
606 .get_boot_time = pmac_get_boot_time,
607 .set_rtc_time = pmac_set_rtc_time,
608 .get_rtc_time = pmac_get_rtc_time,
609 .calibrate_decr = pmac_calibrate_decr,
610 .feature_call = pmac_do_feature_call,
Kumar Galabe6b8432005-12-20 16:37:07 -0600611 .progress = udbg_progress,
Paul Mackerras35499c02005-10-22 16:02:39 +1000612#ifdef CONFIG_PPC64
Paul Mackerrasa0652fc2006-03-27 15:03:03 +1100613 .power_save = power4_idle,
Paul Mackerras35499c02005-10-22 16:02:39 +1000614 .enable_pmcs = power4_enable_pmcs,
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100615#endif /* CONFIG_PPC64 */
Paul Mackerras35499c02005-10-22 16:02:39 +1000616#ifdef CONFIG_PPC32
Paul Mackerras35499c02005-10-22 16:02:39 +1000617 .pcibios_after_init = pmac_pcibios_after_init,
618 .phys_mem_access_prot = pci_phys_mem_access_prot,
619#endif
620};