2 * arch/ppc/platforms/setup.c
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 * Adapted for Power Macintosh by Paul Mackerras
8 * Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au)
10 * Derived from "arch/alpha/kernel/setup.c"
11 * Copyright (C) 1995 Linus Torvalds
13 * Maintained by Benjamin Herrenschmidt (benh@kernel.crashing.org)
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.
23 * bootup setup stuff..
28 #include <linux/config.h>
29 #include <linux/init.h>
30 #include <linux/errno.h>
31 #include <linux/sched.h>
32 #include <linux/kernel.h>
34 #include <linux/stddef.h>
35 #include <linux/unistd.h>
36 #include <linux/ptrace.h>
37 #include <linux/slab.h>
38 #include <linux/user.h>
39 #include <linux/a.out.h>
40 #include <linux/tty.h>
41 #include <linux/string.h>
42 #include <linux/delay.h>
43 #include <linux/ioport.h>
44 #include <linux/major.h>
45 #include <linux/initrd.h>
46 #include <linux/vt_kern.h>
47 #include <linux/console.h>
48 #include <linux/ide.h>
49 #include <linux/pci.h>
50 #include <linux/adb.h>
51 #include <linux/cuda.h>
52 #include <linux/pmu.h>
53 #include <linux/irq.h>
54 #include <linux/seq_file.h>
55 #include <linux/root_dev.h>
56 #include <linux/bitops.h>
58 #include <asm/processor.h>
59 #include <asm/sections.h>
61 #include <asm/system.h>
63 #include <asm/pci-bridge.h>
64 #include <asm/iommu.h>
65 #include <asm/machdep.h>
67 #include <asm/btext.h>
68 #include <asm/cputable.h>
69 #include <asm/pmac_feature.h>
71 #include <asm/of_device.h>
80 #define DBG(fmt...) udbg_printf(fmt)
85 static int current_root_goodness = -1;
86 #define DEFAULT_ROOT_DEVICE Root_SDA1 /* sda1 - slightly silly choice */
88 extern int powersave_nap;
91 sys_ctrler_t sys_ctrler;
92 EXPORT_SYMBOL(sys_ctrler);
94 #ifdef CONFIG_PMAC_SMU
95 unsigned long smu_cmdbuf_abs;
96 EXPORT_SYMBOL(smu_cmdbuf_abs);
99 extern void udbg_init_scc(struct device_node *np);
101 static void __pmac pmac_show_cpuinfo(struct seq_file *m)
103 struct device_node *np;
107 int mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
108 PMAC_MB_INFO_MODEL, 0);
109 unsigned int mbflags = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
110 PMAC_MB_INFO_FLAGS, 0);
112 if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME,
116 /* find motherboard type */
117 seq_printf(m, "machine\t\t: ");
118 np = of_find_node_by_path("/");
120 pp = (char *) get_property(np, "model", NULL);
122 seq_printf(m, "%s\n", pp);
124 seq_printf(m, "PowerMac\n");
125 pp = (char *) get_property(np, "compatible", &plen);
127 seq_printf(m, "motherboard\t:");
129 int l = strlen(pp) + 1;
130 seq_printf(m, " %s", pp);
138 seq_printf(m, "PowerMac\n");
140 /* print parsed model */
141 seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname);
142 seq_printf(m, "pmac flags\t: %08x\n", mbflags);
144 /* Indicate newworld */
145 seq_printf(m, "pmac-generation\t: NewWorld\n");
149 static void __init pmac_setup_arch(void)
151 /* init to some ~sane value until calibrate_delay() runs */
152 loops_per_jiffy = 50000000;
154 /* Probe motherboard chipset */
157 /* Lock-enable the SCC channel used for debug */
159 np = of_find_node_by_name(NULL, "escc");
161 pmac_call_feature(PMAC_FTR_SCC_ENABLE, np,
162 PMAC_SCC_ASYNC | PMAC_SCC_FLAG_XMON, 1);
168 #ifdef CONFIG_ADB_PMU
169 /* Initialize the PMU if any */
172 #ifdef CONFIG_PMAC_SMU
173 /* Initialize the SMU if any */
177 /* Init NVRAM access */
180 /* Setup SMP callback */
185 /* Lookup PCI hosts */
188 #ifdef CONFIG_DUMMY_CONSOLE
189 conswitchp = &dummy_con;
192 printk(KERN_INFO "Using native/NAP idle loop\n");
196 void note_scsi_host(struct device_node *node, void *host)
203 static int initializing = 1;
205 static int pmac_late_init(void)
211 late_initcall(pmac_late_init);
213 /* can't be __init - can be called whenever a disk is first accessed */
214 void __pmac note_bootable_part(dev_t dev, int part, int goodness)
216 extern dev_t boot_dev;
221 if ((goodness <= current_root_goodness) &&
222 ROOT_DEV != DEFAULT_ROOT_DEVICE)
224 p = strstr(saved_command_line, "root=");
225 if (p != NULL && (p == saved_command_line || p[-1] == ' '))
228 if (!boot_dev || dev == boot_dev) {
229 ROOT_DEV = dev + part;
231 current_root_goodness = goodness;
235 static void __pmac pmac_restart(char *cmd)
238 #ifdef CONFIG_ADB_PMU
244 #ifdef CONFIG_PMAC_SMU
254 static void __pmac pmac_power_off(void)
257 #ifdef CONFIG_ADB_PMU
262 #ifdef CONFIG_PMAC_SMU
272 static void __pmac pmac_halt(void)
277 #ifdef CONFIG_BOOTX_TEXT
278 static void btext_putc(unsigned char c)
283 static void __init init_boot_display(void)
286 struct device_node *np = NULL;
289 printk("trying to initialize btext ...\n");
291 name = (char *)get_property(of_chosen, "linux,stdout-path", NULL);
293 np = of_find_node_by_path(name);
295 if (strcmp(np->type, "display") != 0) {
296 printk("boot stdout isn't a display !\n");
303 rc = btext_initialize(np);
307 for (np = NULL; (np = of_find_node_by_type(np, "display"));) {
308 if (get_property(np, "linux,opened", NULL)) {
309 printk("trying %s ...\n", np->full_name);
310 rc = btext_initialize(np);
311 printk("result: %d\n", rc);
317 #endif /* CONFIG_BOOTX_TEXT */
320 * Early initialization.
322 static void __init pmac_init_early(void)
324 DBG(" -> pmac_init_early\n");
326 /* Initialize hash table, from now on, we can take hash faults
332 if (strstr(cmd_line, "sccdbg")) {
336 #ifdef CONFIG_BOOTX_TEXT
340 udbg_putc = btext_putc;
342 #endif /* CONFIG_BOOTX_TEXT */
344 /* Setup interrupt mapping options */
345 ppc64_interrupt_controller = IC_OPEN_PIC;
347 iommu_init_early_u3();
349 DBG(" <- pmac_init_early\n");
352 static int pmac_u3_cascade(struct pt_regs *regs, void *data)
354 return mpic_get_one_irq((struct mpic *)data, regs);
357 static __init void pmac_init_IRQ(void)
359 struct device_node *irqctrler = NULL;
360 struct device_node *irqctrler2 = NULL;
361 struct device_node *np = NULL;
362 struct mpic *mpic1, *mpic2;
364 /* We first try to detect Apple's new Core99 chipset, since mac-io
365 * is quite different on those machines and contains an IBM MPIC2.
367 while ((np = of_find_node_by_type(np, "open-pic")) != NULL) {
368 struct device_node *parent = of_get_parent(np);
369 if (parent && !strcmp(parent->name, "u3"))
370 irqctrler2 = of_node_get(np);
372 irqctrler = of_node_get(np);
375 if (irqctrler != NULL && irqctrler->n_addrs > 0) {
376 unsigned char senses[128];
378 printk(KERN_INFO "PowerMac using OpenPIC irq controller at 0x%08x\n",
379 (unsigned int)irqctrler->addrs[0].address);
381 prom_get_irq_senses(senses, 0, 128);
382 mpic1 = mpic_alloc(irqctrler->addrs[0].address,
383 MPIC_PRIMARY | MPIC_WANTS_RESET,
384 0, 0, 128, 256, senses, 128, " K2-MPIC ");
385 BUG_ON(mpic1 == NULL);
388 if (irqctrler2 != NULL && irqctrler2->n_intrs > 0 &&
389 irqctrler2->n_addrs > 0) {
390 printk(KERN_INFO "Slave OpenPIC at 0x%08x hooked on IRQ %d\n",
391 (u32)irqctrler2->addrs[0].address,
392 irqctrler2->intrs[0].line);
394 pmac_call_feature(PMAC_FTR_ENABLE_MPIC, irqctrler2, 0, 0);
395 prom_get_irq_senses(senses, 128, 128 + 128);
397 /* We don't need to set MPIC_BROKEN_U3 here since we don't have
398 * hypertransport interrupts routed to it
400 mpic2 = mpic_alloc(irqctrler2->addrs[0].address,
401 MPIC_BIG_ENDIAN | MPIC_WANTS_RESET,
402 0, 128, 128, 0, senses, 128, " U3-MPIC ");
403 BUG_ON(mpic2 == NULL);
405 mpic_setup_cascade(irqctrler2->intrs[0].line,
406 pmac_u3_cascade, mpic2);
409 of_node_put(irqctrler);
410 of_node_put(irqctrler2);
413 static void __init pmac_progress(char *s, unsigned short hex)
419 #ifdef CONFIG_BOOTX_TEXT
420 else if (boot_text_mapped) {
422 btext_drawstring("\n");
424 #endif /* CONFIG_BOOTX_TEXT */
428 * pmac has no legacy IO, anything calling this function has to
429 * fail or bad things will happen
431 static int pmac_check_legacy_ioport(unsigned int baseport)
436 static int __init pmac_declare_of_platform_devices(void)
438 struct device_node *np, *npp;
440 npp = of_find_node_by_name(NULL, "u3");
442 for (np = NULL; (np = of_get_next_child(npp, np)) != NULL;) {
443 if (strncmp(np->name, "i2c", 3) == 0) {
444 of_platform_device_create(np, "u3-i2c", NULL);
451 npp = of_find_node_by_type(NULL, "smu");
453 of_platform_device_create(npp, "smu", NULL);
460 device_initcall(pmac_declare_of_platform_devices);
463 * Called very early, MMU is off, device-tree isn't unflattened
465 static int __init pmac_probe(int platform)
467 if (platform != PLATFORM_POWERMAC)
470 * On U3, the DART (iommu) must be allocated now since it
471 * has an impact on htab_initialize (due to the large page it
472 * occupies having to be broken up so the DART itself is not
473 * part of the cacheable linar mapping
475 alloc_u3_dart_table();
477 #ifdef CONFIG_PMAC_SMU
479 * SMU based G5s need some memory below 2Gb, at least the current
480 * driver needs that. We have to allocate it now. We allocate 4k
481 * (1 small page) for now.
483 smu_cmdbuf_abs = lmb_alloc_base(4096, 4096, 0x80000000UL);
484 #endif /* CONFIG_PMAC_SMU */
489 static int pmac_probe_mode(struct pci_bus *bus)
491 struct device_node *node = bus->sysdata;
493 /* We need to use normal PCI probing for the AGP bus,
494 since the device for the AGP bridge isn't in the tree. */
495 if (bus->self == NULL && device_is_compatible(node, "u3-agp"))
496 return PCI_PROBE_NORMAL;
498 return PCI_PROBE_DEVTREE;
501 struct machdep_calls __initdata pmac_md = {
502 #ifdef CONFIG_HOTPLUG_CPU
503 .cpu_die = generic_mach_cpu_die,
506 .setup_arch = pmac_setup_arch,
507 .init_early = pmac_init_early,
508 .get_cpuinfo = pmac_show_cpuinfo,
509 .init_IRQ = pmac_init_IRQ,
510 .get_irq = mpic_get_irq,
511 .pcibios_fixup = pmac_pcibios_fixup,
512 .pci_probe_mode = pmac_probe_mode,
513 .restart = pmac_restart,
514 .power_off = pmac_power_off,
516 .get_boot_time = pmac_get_boot_time,
517 .set_rtc_time = pmac_set_rtc_time,
518 .get_rtc_time = pmac_get_rtc_time,
519 .calibrate_decr = pmac_calibrate_decr,
520 .feature_call = pmac_do_feature_call,
521 .progress = pmac_progress,
522 .check_legacy_ioport = pmac_check_legacy_ioport,
523 .idle_loop = native_idle,
524 .enable_pmcs = power4_enable_pmcs,