1 /* Copyright 2013-2014 IBM Corp.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * 	http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <skiboot.h>
18 #include <console.h>
19 #include <device.h>
20 #include <ipmi.h>
21 
22 #include <platforms/astbmc/astbmc.h>
23 
24 static bool bt_device_present;
25 
qemu_probe_common(const char * compat)26 static bool qemu_probe_common(const char *compat)
27 {
28 	struct dt_node *n;
29 
30 	if (!dt_node_is_compatible(dt_root, compat))
31 		return false;
32 
33         astbmc_early_init();
34 
35 	/* check if the BT device was defined by QEMU */
36 	dt_for_each_compatible(dt_root, n, "bt") {
37 		bt_device_present = true;
38 	}
39 
40 	return true;
41 }
42 
qemu_probe(void)43 static bool qemu_probe(void)
44 {
45 	return qemu_probe_common("qemu,powernv");
46 }
47 
qemu_probe_powernv8(void)48 static bool qemu_probe_powernv8(void)
49 {
50 	return qemu_probe_common("qemu,powernv8");
51 }
52 
qemu_probe_powernv9(void)53 static bool qemu_probe_powernv9(void)
54 {
55 	return qemu_probe_common("qemu,powernv9");
56 }
57 
qemu_init(void)58 static void qemu_init(void)
59 {
60 	if (!bt_device_present) {
61 		set_opal_console(&uart_opal_con);
62 	} else {
63 		astbmc_init();
64 	}
65 }
66 
67 DECLARE_PLATFORM(qemu) = {
68 	.name		= "QEMU",
69 	.probe		= qemu_probe,
70 	.init		= qemu_init,
71 	.external_irq   = astbmc_ext_irq_serirq_cpld,
72 	.cec_power_down = astbmc_ipmi_power_down,
73 	.cec_reboot     = astbmc_ipmi_reboot,
74 	.start_preload_resource	= flash_start_preload_resource,
75 	.resource_loaded	= flash_resource_loaded,
76 	.terminate	= ipmi_terminate,
77 };
78 
79 /*
80  * For a QEMU PowerNV machine using POWER8 CPUs (Palmetto)
81  */
82 DECLARE_PLATFORM(qemu_powernv8) = {
83 	.name		= "QEMU POWER8",
84 	.probe		= qemu_probe_powernv8,
85 	.bmc		= &bmc_plat_ast2400_ami,
86 	.init		= qemu_init,
87 	.external_irq   = astbmc_ext_irq_serirq_cpld,
88 	.cec_power_down = astbmc_ipmi_power_down,
89 	.cec_reboot     = astbmc_ipmi_reboot,
90 	.start_preload_resource	= flash_start_preload_resource,
91 	.resource_loaded	= flash_resource_loaded,
92 	.exit			= astbmc_exit,
93 	.terminate	= ipmi_terminate,
94 };
95 
96 /*
97  * For a QEMU PowerNV machine using POWER9 CPUs (Witherspoon)
98  */
99 DECLARE_PLATFORM(qemu_powernv9) = {
100 	.name		= "QEMU POWER9",
101 	.probe		= qemu_probe_powernv9,
102 	.bmc		= &bmc_plat_ast2500_openbmc,
103 	.init		= qemu_init,
104 	.external_irq   = astbmc_ext_irq_serirq_cpld,
105 	.cec_power_down = astbmc_ipmi_power_down,
106 	.cec_reboot     = astbmc_ipmi_reboot,
107 	.start_preload_resource	= flash_start_preload_resource,
108 	.resource_loaded	= flash_resource_loaded,
109 	.exit			= astbmc_exit,
110 	.terminate	= ipmi_terminate,
111 };
112