1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Maple (970 eval board) setup code
5 * (c) Copyright 2004 Benjamin Herrenschmidt (benh@kernel.crashing.org),
11 #include <linux/init.h>
12 #include <linux/errno.h>
13 #include <linux/sched.h>
14 #include <linux/kernel.h>
15 #include <linux/export.h>
17 #include <linux/stddef.h>
18 #include <linux/unistd.h>
19 #include <linux/ptrace.h>
20 #include <linux/user.h>
21 #include <linux/tty.h>
22 #include <linux/string.h>
23 #include <linux/delay.h>
24 #include <linux/ioport.h>
25 #include <linux/major.h>
26 #include <linux/initrd.h>
27 #include <linux/vt_kern.h>
28 #include <linux/console.h>
29 #include <linux/pci.h>
30 #include <linux/adb.h>
31 #include <linux/cuda.h>
32 #include <linux/pmu.h>
33 #include <linux/irq.h>
34 #include <linux/seq_file.h>
35 #include <linux/root_dev.h>
36 #include <linux/serial.h>
37 #include <linux/smp.h>
38 #include <linux/bitops.h>
39 #include <linux/of_device.h>
40 #include <linux/memblock.h>
42 #include <asm/processor.h>
43 #include <asm/sections.h>
45 #include <asm/pgtable.h>
47 #include <asm/pci-bridge.h>
48 #include <asm/iommu.h>
49 #include <asm/machdep.h>
51 #include <asm/cputable.h>
56 #include <asm/nvram.h>
61 #define DBG(fmt...) udbg_printf(fmt)
66 static unsigned long maple_find_nvram_base(void)
68 struct device_node *rtcs;
69 unsigned long result = 0;
71 /* find NVRAM device */
72 rtcs = of_find_compatible_node(NULL, "nvram", "AMD8111");
75 if (of_address_to_resource(rtcs, 0, &r)) {
76 printk(KERN_EMERG "Maple: Unable to translate NVRAM"
80 if (!(r.flags & IORESOURCE_IO)) {
81 printk(KERN_EMERG "Maple: NVRAM address isn't PIO!\n");
86 printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
92 static void __noreturn maple_restart(char *cmd)
94 unsigned int maple_nvram_base;
95 const unsigned int *maple_nvram_offset, *maple_nvram_command;
96 struct device_node *sp;
98 maple_nvram_base = maple_find_nvram_base();
99 if (maple_nvram_base == 0)
102 /* find service processor device */
103 sp = of_find_node_by_name(NULL, "service-processor");
105 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
108 maple_nvram_offset = of_get_property(sp, "restart-addr", NULL);
109 maple_nvram_command = of_get_property(sp, "restart-value", NULL);
113 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
116 printk(KERN_EMERG "Maple: Manual Restart Required\n");
120 static void __noreturn maple_power_off(void)
122 unsigned int maple_nvram_base;
123 const unsigned int *maple_nvram_offset, *maple_nvram_command;
124 struct device_node *sp;
126 maple_nvram_base = maple_find_nvram_base();
127 if (maple_nvram_base == 0)
130 /* find service processor device */
131 sp = of_find_node_by_name(NULL, "service-processor");
133 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
136 maple_nvram_offset = of_get_property(sp, "power-off-addr", NULL);
137 maple_nvram_command = of_get_property(sp, "power-off-value", NULL);
141 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
144 printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
148 static void __noreturn maple_halt(void)
154 static struct smp_ops_t maple_smp_ops = {
155 .probe = smp_mpic_probe,
156 .message_pass = smp_mpic_message_pass,
157 .kick_cpu = smp_generic_kick_cpu,
158 .setup_cpu = smp_mpic_setup_cpu,
159 .give_timebase = smp_generic_give_timebase,
160 .take_timebase = smp_generic_take_timebase,
162 #endif /* CONFIG_SMP */
164 static void __init maple_use_rtas_reboot_and_halt_if_present(void)
166 if (rtas_service_present("system-reboot") &&
167 rtas_service_present("power-off")) {
168 ppc_md.restart = rtas_restart;
169 pm_power_off = rtas_power_off;
170 ppc_md.halt = rtas_halt;
174 static void __init maple_setup_arch(void)
176 /* init to some ~sane value until calibrate_delay() runs */
177 loops_per_jiffy = 50000000;
179 /* Setup SMP callback */
181 smp_ops = &maple_smp_ops;
183 /* Lookup PCI hosts */
186 #ifdef CONFIG_DUMMY_CONSOLE
187 conswitchp = &dummy_con;
189 maple_use_rtas_reboot_and_halt_if_present();
191 printk(KERN_DEBUG "Using native/NAP idle loop\n");
197 * This is almost identical to pSeries and CHRP. We need to make that
198 * code generic at one point, with appropriate bits in the device-tree to
199 * identify the presence of an HT APIC
201 static void __init maple_init_IRQ(void)
203 struct device_node *root, *np, *mpic_node = NULL;
204 const unsigned int *opprop;
205 unsigned long openpic_addr = 0;
206 int naddr, n, i, opplen, has_isus = 0;
208 unsigned int flags = 0;
210 /* Locate MPIC in the device-tree. Note that there is a bug
211 * in Maple device-tree where the type of the controller is
212 * open-pic and not interrupt-controller
215 for_each_node_by_type(np, "interrupt-controller")
216 if (of_device_is_compatible(np, "open-pic")) {
220 if (mpic_node == NULL)
221 for_each_node_by_type(np, "open-pic") {
225 if (mpic_node == NULL) {
227 "Failed to locate the MPIC interrupt controller\n");
231 /* Find address list in /platform-open-pic */
232 root = of_find_node_by_path("/");
233 naddr = of_n_addr_cells(root);
234 opprop = of_get_property(root, "platform-open-pic", &opplen);
236 openpic_addr = of_read_number(opprop, naddr);
237 has_isus = (opplen > naddr);
238 printk(KERN_DEBUG "OpenPIC addr: %lx, has ISUs: %d\n",
239 openpic_addr, has_isus);
242 BUG_ON(openpic_addr == 0);
244 /* Check for a big endian MPIC */
245 if (of_get_property(np, "big-endian", NULL) != NULL)
246 flags |= MPIC_BIG_ENDIAN;
248 /* XXX Maple specific bits */
249 flags |= MPIC_U3_HT_IRQS;
250 /* All U3/U4 are big-endian, older SLOF firmware doesn't encode this */
251 flags |= MPIC_BIG_ENDIAN;
253 /* Setup the openpic driver. More device-tree junks, we hard code no
254 * ISUs for now. I'll have to revisit some stuffs with the folks doing
255 * the firmware for those
257 mpic = mpic_alloc(mpic_node, openpic_addr, flags,
258 /*has_isus ? 16 :*/ 0, 0, " MPIC ");
259 BUG_ON(mpic == NULL);
262 opplen /= sizeof(u32);
263 for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
264 unsigned long isuaddr = of_read_number(opprop + i, naddr);
265 mpic_assign_isu(mpic, n, isuaddr);
268 /* All ISUs are setup, complete initialization */
270 ppc_md.get_irq = mpic_get_irq;
271 of_node_put(mpic_node);
275 static void __init maple_progress(char *s, unsigned short hex)
277 printk("*** %04x : %s\n", hex, s ? s : "");
282 * Called very early, MMU is off, device-tree isn't unflattened
284 static int __init maple_probe(void)
286 if (!of_machine_is_compatible("Momentum,Maple") &&
287 !of_machine_is_compatible("Momentum,Apache"))
290 pm_power_off = maple_power_off;
292 iommu_init_early_dart(&maple_pci_controller_ops);
297 define_machine(maple) {
299 .probe = maple_probe,
300 .setup_arch = maple_setup_arch,
301 .init_IRQ = maple_init_IRQ,
302 .pci_irq_fixup = maple_pci_irq_fixup,
303 .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
304 .restart = maple_restart,
306 .get_boot_time = maple_get_boot_time,
307 .set_rtc_time = maple_set_rtc_time,
308 .get_rtc_time = maple_get_rtc_time,
309 .calibrate_decr = generic_calibrate_decr,
310 .progress = maple_progress,
311 .power_save = power4_idle,
316 * Register a platform device for CPC925 memory controller on
317 * all boards with U3H (CPC925) bridge.
319 static int __init maple_cpc925_edac_setup(void)
321 struct platform_device *pdev;
322 struct device_node *np = NULL;
325 volatile void __iomem *mem;
328 np = of_find_node_by_type(NULL, "memory-controller");
330 printk(KERN_ERR "%s: Unable to find memory-controller node\n",
335 ret = of_address_to_resource(np, 0, &r);
339 printk(KERN_ERR "%s: Unable to get memory-controller reg\n",
344 mem = ioremap(r.start, resource_size(&r));
346 printk(KERN_ERR "%s: Unable to map memory-controller memory\n",
351 rev = __raw_readl(mem);
354 if (rev < 0x34 || rev > 0x3f) { /* U3H */
355 printk(KERN_ERR "%s: Non-CPC925(U3H) bridge revision: %02x\n",
360 pdev = platform_device_register_simple("cpc925_edac", 0, &r, 1);
362 return PTR_ERR(pdev);
364 printk(KERN_INFO "%s: CPC925 platform device created\n", __func__);
368 machine_device_initcall(maple, maple_cpc925_edac_setup);