xref: /linux/arch/powerpc/platforms/powernv/setup.c (revision 3fafe9c202321a3edc47386d2071af89555c9f45)
155190f88SBenjamin Herrenschmidt /*
255190f88SBenjamin Herrenschmidt  * PowerNV setup code.
355190f88SBenjamin Herrenschmidt  *
455190f88SBenjamin Herrenschmidt  * Copyright 2011 IBM Corp.
555190f88SBenjamin Herrenschmidt  *
655190f88SBenjamin Herrenschmidt  * This program is free software; you can redistribute it and/or
755190f88SBenjamin Herrenschmidt  * modify it under the terms of the GNU General Public License
855190f88SBenjamin Herrenschmidt  * as published by the Free Software Foundation; either version
955190f88SBenjamin Herrenschmidt  * 2 of the License, or (at your option) any later version.
1055190f88SBenjamin Herrenschmidt  */
1155190f88SBenjamin Herrenschmidt 
1255190f88SBenjamin Herrenschmidt #undef DEBUG
1355190f88SBenjamin Herrenschmidt 
1455190f88SBenjamin Herrenschmidt #include <linux/cpu.h>
1555190f88SBenjamin Herrenschmidt #include <linux/errno.h>
1655190f88SBenjamin Herrenschmidt #include <linux/sched.h>
1755190f88SBenjamin Herrenschmidt #include <linux/kernel.h>
1855190f88SBenjamin Herrenschmidt #include <linux/tty.h>
1955190f88SBenjamin Herrenschmidt #include <linux/reboot.h>
2055190f88SBenjamin Herrenschmidt #include <linux/init.h>
2155190f88SBenjamin Herrenschmidt #include <linux/console.h>
2255190f88SBenjamin Herrenschmidt #include <linux/delay.h>
2355190f88SBenjamin Herrenschmidt #include <linux/irq.h>
2455190f88SBenjamin Herrenschmidt #include <linux/seq_file.h>
2555190f88SBenjamin Herrenschmidt #include <linux/of.h>
2655190f88SBenjamin Herrenschmidt #include <linux/interrupt.h>
2755190f88SBenjamin Herrenschmidt #include <linux/bug.h>
2855190f88SBenjamin Herrenschmidt 
2955190f88SBenjamin Herrenschmidt #include <asm/machdep.h>
3055190f88SBenjamin Herrenschmidt #include <asm/firmware.h>
3155190f88SBenjamin Herrenschmidt #include <asm/xics.h>
32628daa8dSBenjamin Herrenschmidt #include <asm/rtas.h>
33daea1175SBenjamin Herrenschmidt #include <asm/opal.h>
3455190f88SBenjamin Herrenschmidt 
3555190f88SBenjamin Herrenschmidt #include "powernv.h"
3655190f88SBenjamin Herrenschmidt 
3755190f88SBenjamin Herrenschmidt static void __init pnv_setup_arch(void)
3855190f88SBenjamin Herrenschmidt {
3955190f88SBenjamin Herrenschmidt 	/* Initialize SMP */
4055190f88SBenjamin Herrenschmidt 	pnv_smp_init();
4155190f88SBenjamin Herrenschmidt 
4261305a96SBenjamin Herrenschmidt 	/* Setup PCI */
4361305a96SBenjamin Herrenschmidt 	pnv_pci_init();
4455190f88SBenjamin Herrenschmidt 
45628daa8dSBenjamin Herrenschmidt 	/* Setup RTC and NVRAM callbacks */
46628daa8dSBenjamin Herrenschmidt 	if (firmware_has_feature(FW_FEATURE_OPAL))
47628daa8dSBenjamin Herrenschmidt 		opal_nvram_init();
4855190f88SBenjamin Herrenschmidt 
4955190f88SBenjamin Herrenschmidt 	/* Enable NAP mode */
5055190f88SBenjamin Herrenschmidt 	powersave_nap = 1;
5155190f88SBenjamin Herrenschmidt 
5255190f88SBenjamin Herrenschmidt 	/* XXX PMCS */
5355190f88SBenjamin Herrenschmidt }
5455190f88SBenjamin Herrenschmidt 
5555190f88SBenjamin Herrenschmidt static void __init pnv_init_early(void)
5655190f88SBenjamin Herrenschmidt {
57*3fafe9c2SBenjamin Herrenschmidt 	/*
58*3fafe9c2SBenjamin Herrenschmidt 	 * Initialize the LPC bus now so that legacy serial
59*3fafe9c2SBenjamin Herrenschmidt 	 * ports can be found on it
60*3fafe9c2SBenjamin Herrenschmidt 	 */
61*3fafe9c2SBenjamin Herrenschmidt 	opal_lpc_init();
62*3fafe9c2SBenjamin Herrenschmidt 
63daea1175SBenjamin Herrenschmidt #ifdef CONFIG_HVC_OPAL
64daea1175SBenjamin Herrenschmidt 	if (firmware_has_feature(FW_FEATURE_OPAL))
65daea1175SBenjamin Herrenschmidt 		hvc_opal_init_early();
66daea1175SBenjamin Herrenschmidt 	else
67daea1175SBenjamin Herrenschmidt #endif
68daea1175SBenjamin Herrenschmidt 		add_preferred_console("hvc", 0, NULL);
6955190f88SBenjamin Herrenschmidt }
7055190f88SBenjamin Herrenschmidt 
7155190f88SBenjamin Herrenschmidt static void __init pnv_init_IRQ(void)
7255190f88SBenjamin Herrenschmidt {
7355190f88SBenjamin Herrenschmidt 	xics_init();
7455190f88SBenjamin Herrenschmidt 
7555190f88SBenjamin Herrenschmidt 	WARN_ON(!ppc_md.get_irq);
7655190f88SBenjamin Herrenschmidt }
7755190f88SBenjamin Herrenschmidt 
7855190f88SBenjamin Herrenschmidt static void pnv_show_cpuinfo(struct seq_file *m)
7955190f88SBenjamin Herrenschmidt {
8055190f88SBenjamin Herrenschmidt 	struct device_node *root;
8155190f88SBenjamin Herrenschmidt 	const char *model = "";
8255190f88SBenjamin Herrenschmidt 
8355190f88SBenjamin Herrenschmidt 	root = of_find_node_by_path("/");
8455190f88SBenjamin Herrenschmidt 	if (root)
8555190f88SBenjamin Herrenschmidt 		model = of_get_property(root, "model", NULL);
8655190f88SBenjamin Herrenschmidt 	seq_printf(m, "machine\t\t: PowerNV %s\n", model);
8775b93da4SBenjamin Herrenschmidt 	if (firmware_has_feature(FW_FEATURE_OPALv3))
8875b93da4SBenjamin Herrenschmidt 		seq_printf(m, "firmware\t: OPAL v3\n");
8975b93da4SBenjamin Herrenschmidt 	else if (firmware_has_feature(FW_FEATURE_OPALv2))
9014a43e69SBenjamin Herrenschmidt 		seq_printf(m, "firmware\t: OPAL v2\n");
9114a43e69SBenjamin Herrenschmidt 	else if (firmware_has_feature(FW_FEATURE_OPAL))
9214a43e69SBenjamin Herrenschmidt 		seq_printf(m, "firmware\t: OPAL v1\n");
9314a43e69SBenjamin Herrenschmidt 	else
9414a43e69SBenjamin Herrenschmidt 		seq_printf(m, "firmware\t: BML\n");
9555190f88SBenjamin Herrenschmidt 	of_node_put(root);
9655190f88SBenjamin Herrenschmidt }
9755190f88SBenjamin Herrenschmidt 
98ec27329fSBenjamin Herrenschmidt static void  __noreturn pnv_restart(char *cmd)
9955190f88SBenjamin Herrenschmidt {
100ec27329fSBenjamin Herrenschmidt 	long rc = OPAL_BUSY;
101ec27329fSBenjamin Herrenschmidt 
102e8e71fa4SGavin Shan 	opal_notifier_disable();
103e8e71fa4SGavin Shan 
104ec27329fSBenjamin Herrenschmidt 	while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
105ec27329fSBenjamin Herrenschmidt 		rc = opal_cec_reboot();
106ec27329fSBenjamin Herrenschmidt 		if (rc == OPAL_BUSY_EVENT)
107ec27329fSBenjamin Herrenschmidt 			opal_poll_events(NULL);
108ec27329fSBenjamin Herrenschmidt 		else
109ec27329fSBenjamin Herrenschmidt 			mdelay(10);
110ec27329fSBenjamin Herrenschmidt 	}
111ec27329fSBenjamin Herrenschmidt 	for (;;)
112ec27329fSBenjamin Herrenschmidt 		opal_poll_events(NULL);
11355190f88SBenjamin Herrenschmidt }
11455190f88SBenjamin Herrenschmidt 
115ec27329fSBenjamin Herrenschmidt static void __noreturn pnv_power_off(void)
11655190f88SBenjamin Herrenschmidt {
117ec27329fSBenjamin Herrenschmidt 	long rc = OPAL_BUSY;
118ec27329fSBenjamin Herrenschmidt 
119e8e71fa4SGavin Shan 	opal_notifier_disable();
120e8e71fa4SGavin Shan 
121ec27329fSBenjamin Herrenschmidt 	while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
122ec27329fSBenjamin Herrenschmidt 		rc = opal_cec_power_down(0);
123ec27329fSBenjamin Herrenschmidt 		if (rc == OPAL_BUSY_EVENT)
124ec27329fSBenjamin Herrenschmidt 			opal_poll_events(NULL);
125ec27329fSBenjamin Herrenschmidt 		else
126ec27329fSBenjamin Herrenschmidt 			mdelay(10);
127ec27329fSBenjamin Herrenschmidt 	}
128ec27329fSBenjamin Herrenschmidt 	for (;;)
129ec27329fSBenjamin Herrenschmidt 		opal_poll_events(NULL);
13055190f88SBenjamin Herrenschmidt }
13155190f88SBenjamin Herrenschmidt 
132ec27329fSBenjamin Herrenschmidt static void __noreturn pnv_halt(void)
13355190f88SBenjamin Herrenschmidt {
134ec27329fSBenjamin Herrenschmidt 	pnv_power_off();
13555190f88SBenjamin Herrenschmidt }
13655190f88SBenjamin Herrenschmidt 
13755190f88SBenjamin Herrenschmidt static void pnv_progress(char *s, unsigned short hex)
13855190f88SBenjamin Herrenschmidt {
13955190f88SBenjamin Herrenschmidt }
14055190f88SBenjamin Herrenschmidt 
14173ed148aSBenjamin Herrenschmidt static void pnv_shutdown(void)
14273ed148aSBenjamin Herrenschmidt {
14373ed148aSBenjamin Herrenschmidt 	/* Let the PCI code clear up IODA tables */
14473ed148aSBenjamin Herrenschmidt 	pnv_pci_shutdown();
14573ed148aSBenjamin Herrenschmidt 
14673ed148aSBenjamin Herrenschmidt 	/* And unregister all OPAL interrupts so they don't fire
14773ed148aSBenjamin Herrenschmidt 	 * up while we kexec
14873ed148aSBenjamin Herrenschmidt 	 */
14973ed148aSBenjamin Herrenschmidt 	opal_shutdown();
15073ed148aSBenjamin Herrenschmidt }
15173ed148aSBenjamin Herrenschmidt 
15255190f88SBenjamin Herrenschmidt #ifdef CONFIG_KEXEC
15355190f88SBenjamin Herrenschmidt static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)
15455190f88SBenjamin Herrenschmidt {
15555190f88SBenjamin Herrenschmidt 	xics_kexec_teardown_cpu(secondary);
15655190f88SBenjamin Herrenschmidt }
15755190f88SBenjamin Herrenschmidt #endif /* CONFIG_KEXEC */
15855190f88SBenjamin Herrenschmidt 
159628daa8dSBenjamin Herrenschmidt static void __init pnv_setup_machdep_opal(void)
160628daa8dSBenjamin Herrenschmidt {
161628daa8dSBenjamin Herrenschmidt 	ppc_md.get_boot_time = opal_get_boot_time;
162628daa8dSBenjamin Herrenschmidt 	ppc_md.get_rtc_time = opal_get_rtc_time;
163628daa8dSBenjamin Herrenschmidt 	ppc_md.set_rtc_time = opal_set_rtc_time;
164628daa8dSBenjamin Herrenschmidt 	ppc_md.restart = pnv_restart;
165628daa8dSBenjamin Herrenschmidt 	ppc_md.power_off = pnv_power_off;
166628daa8dSBenjamin Herrenschmidt 	ppc_md.halt = pnv_halt;
167ed79ba9eSBenjamin Herrenschmidt 	ppc_md.machine_check_exception = opal_machine_check;
168628daa8dSBenjamin Herrenschmidt }
169628daa8dSBenjamin Herrenschmidt 
170628daa8dSBenjamin Herrenschmidt #ifdef CONFIG_PPC_POWERNV_RTAS
171628daa8dSBenjamin Herrenschmidt static void __init pnv_setup_machdep_rtas(void)
172628daa8dSBenjamin Herrenschmidt {
173628daa8dSBenjamin Herrenschmidt 	if (rtas_token("get-time-of-day") != RTAS_UNKNOWN_SERVICE) {
174628daa8dSBenjamin Herrenschmidt 		ppc_md.get_boot_time = rtas_get_boot_time;
175628daa8dSBenjamin Herrenschmidt 		ppc_md.get_rtc_time = rtas_get_rtc_time;
176628daa8dSBenjamin Herrenschmidt 		ppc_md.set_rtc_time = rtas_set_rtc_time;
177628daa8dSBenjamin Herrenschmidt 	}
178628daa8dSBenjamin Herrenschmidt 	ppc_md.restart = rtas_restart;
179628daa8dSBenjamin Herrenschmidt 	ppc_md.power_off = rtas_power_off;
180628daa8dSBenjamin Herrenschmidt 	ppc_md.halt = rtas_halt;
181628daa8dSBenjamin Herrenschmidt }
182628daa8dSBenjamin Herrenschmidt #endif /* CONFIG_PPC_POWERNV_RTAS */
183628daa8dSBenjamin Herrenschmidt 
18455190f88SBenjamin Herrenschmidt static int __init pnv_probe(void)
18555190f88SBenjamin Herrenschmidt {
18655190f88SBenjamin Herrenschmidt 	unsigned long root = of_get_flat_dt_root();
18755190f88SBenjamin Herrenschmidt 
18855190f88SBenjamin Herrenschmidt 	if (!of_flat_dt_is_compatible(root, "ibm,powernv"))
18955190f88SBenjamin Herrenschmidt 		return 0;
19055190f88SBenjamin Herrenschmidt 
19155190f88SBenjamin Herrenschmidt 	hpte_init_native();
19255190f88SBenjamin Herrenschmidt 
193628daa8dSBenjamin Herrenschmidt 	if (firmware_has_feature(FW_FEATURE_OPAL))
194628daa8dSBenjamin Herrenschmidt 		pnv_setup_machdep_opal();
195628daa8dSBenjamin Herrenschmidt #ifdef CONFIG_PPC_POWERNV_RTAS
196628daa8dSBenjamin Herrenschmidt 	else if (rtas.base)
197628daa8dSBenjamin Herrenschmidt 		pnv_setup_machdep_rtas();
198628daa8dSBenjamin Herrenschmidt #endif /* CONFIG_PPC_POWERNV_RTAS */
199628daa8dSBenjamin Herrenschmidt 
20055190f88SBenjamin Herrenschmidt 	pr_debug("PowerNV detected !\n");
20155190f88SBenjamin Herrenschmidt 
20255190f88SBenjamin Herrenschmidt 	return 1;
20355190f88SBenjamin Herrenschmidt }
20455190f88SBenjamin Herrenschmidt 
20555190f88SBenjamin Herrenschmidt define_machine(powernv) {
20655190f88SBenjamin Herrenschmidt 	.name			= "PowerNV",
20755190f88SBenjamin Herrenschmidt 	.probe			= pnv_probe,
20855190f88SBenjamin Herrenschmidt 	.init_early		= pnv_init_early,
209628daa8dSBenjamin Herrenschmidt 	.setup_arch		= pnv_setup_arch,
21055190f88SBenjamin Herrenschmidt 	.init_IRQ		= pnv_init_IRQ,
21155190f88SBenjamin Herrenschmidt 	.show_cpuinfo		= pnv_show_cpuinfo,
21255190f88SBenjamin Herrenschmidt 	.progress		= pnv_progress,
21373ed148aSBenjamin Herrenschmidt 	.machine_shutdown	= pnv_shutdown,
21455190f88SBenjamin Herrenschmidt 	.power_save             = power7_idle,
21555190f88SBenjamin Herrenschmidt 	.calibrate_decr		= generic_calibrate_decr,
21655190f88SBenjamin Herrenschmidt #ifdef CONFIG_KEXEC
21755190f88SBenjamin Herrenschmidt 	.kexec_cpu_down		= pnv_kexec_cpu_down,
21855190f88SBenjamin Herrenschmidt #endif
21955190f88SBenjamin Herrenschmidt };
220