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..
26 #include <linux/config.h>
27 #include <linux/init.h>
28 #include <linux/errno.h>
29 #include <linux/sched.h>
30 #include <linux/kernel.h>
32 #include <linux/stddef.h>
33 #include <linux/unistd.h>
34 #include <linux/ptrace.h>
35 #include <linux/slab.h>
36 #include <linux/user.h>
37 #include <linux/a.out.h>
38 #include <linux/tty.h>
39 #include <linux/string.h>
40 #include <linux/delay.h>
41 #include <linux/ioport.h>
42 #include <linux/major.h>
43 #include <linux/initrd.h>
44 #include <linux/vt_kern.h>
45 #include <linux/console.h>
46 #include <linux/ide.h>
47 #include <linux/pci.h>
48 #include <linux/adb.h>
49 #include <linux/cuda.h>
50 #include <linux/pmu.h>
51 #include <linux/irq.h>
52 #include <linux/seq_file.h>
53 #include <linux/root_dev.h>
55 #include <asm/processor.h>
56 #include <asm/sections.h>
58 #include <asm/system.h>
59 #include <asm/pgtable.h>
60 #include <asm/bitops.h>
62 #include <asm/pci-bridge.h>
63 #include <asm/iommu.h>
64 #include <asm/machdep.h>
66 #include <asm/bootx.h>
67 #include <asm/btext.h>
68 #include <asm/cputable.h>
69 #include <asm/pmac_feature.h>
71 #include <asm/of_device.h>
76 static int current_root_goodness = -1;
77 #define DEFAULT_ROOT_DEVICE Root_SDA1 /* sda1 - slightly silly choice */
79 extern int powersave_nap;
82 extern void udbg_init_scc(struct device_node *np);
84 #ifdef CONFIG_BOOTX_TEXT
85 void pmac_progress(char *s, unsigned short hex);
88 void __pmac pmac_show_cpuinfo(struct seq_file *m)
90 struct device_node *np;
94 int mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
95 PMAC_MB_INFO_MODEL, 0);
96 unsigned int mbflags = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
97 PMAC_MB_INFO_FLAGS, 0);
99 if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME,
103 /* find motherboard type */
104 seq_printf(m, "machine\t\t: ");
105 np = find_devices("device-tree");
107 pp = (char *) get_property(np, "model", NULL);
109 seq_printf(m, "%s\n", pp);
111 seq_printf(m, "PowerMac\n");
112 pp = (char *) get_property(np, "compatible", &plen);
114 seq_printf(m, "motherboard\t:");
116 int l = strlen(pp) + 1;
117 seq_printf(m, " %s", pp);
124 seq_printf(m, "PowerMac\n");
126 /* print parsed model */
127 seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname);
128 seq_printf(m, "pmac flags\t: %08x\n", mbflags);
130 /* Indicate newworld */
131 seq_printf(m, "pmac-generation\t: NewWorld\n");
135 void __init pmac_setup_arch(void)
137 struct device_node *cpu;
141 pvr = PVR_VER(mfspr(PVR));
143 /* Set loops_per_jiffy to a half-way reasonable value,
144 for use until calibrate_delay gets called. */
145 cpu = find_type_devices("cpu");
147 fp = (int *) get_property(cpu, "clock-frequency", NULL);
149 if (pvr == 4 || pvr >= 8)
150 /* 604, G3, G4 etc. */
151 loops_per_jiffy = *fp / HZ;
154 loops_per_jiffy = *fp / (2*HZ);
156 loops_per_jiffy = 50000000 / HZ;
162 /* Initialize the PMU */
165 /* Init NVRAM access */
168 /* Setup SMP callback */
173 /* Setup the PCI DMA to "direct" by default. May be overriden
176 pci_dma_init_direct();
178 /* Lookup PCI hosts */
181 #ifdef CONFIG_DUMMY_CONSOLE
182 conswitchp = &dummy_con;
186 extern char *bootpath;
187 extern char *bootdevice;
191 extern dev_t boot_dev;
194 void __init note_scsi_host(struct device_node *node, void *host)
199 l = strlen(node->full_name);
200 if (bootpath != NULL && bootdevice != NULL
201 && strncmp(node->full_name, bootdevice, l) == 0
202 && (bootdevice[l] == '/' || bootdevice[l] == 0)) {
205 * There's a bug in OF 1.0.5. (Why am I not surprised.)
206 * If you pass a path like scsi/sd@1:0 to canon, it returns
207 * something like /bandit@F2000000/gc@10/53c94@10000/sd@0,0
208 * That is, the scsi target number doesn't get preserved.
209 * So we pick the target number out of bootpath and use that.
211 p = strstr(bootpath, "/sd@");
214 boot_target = simple_strtoul(p, NULL, 10);
217 boot_part = simple_strtoul(p + 1, NULL, 10);
223 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
224 static dev_t __init find_ide_boot(void)
228 dev_t __init pmac_find_ide_boot(char *bootdevice, int n);
230 if (bootdevice == NULL)
232 p = strrchr(bootdevice, '/');
237 return pmac_find_ide_boot(bootdevice, n);
239 #endif /* CONFIG_BLK_DEV_IDE && CONFIG_BLK_DEV_IDE_PMAC */
241 void __init find_boot_device(void)
243 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
244 boot_dev = find_ide_boot();
248 static int initializing = 1;
250 static int pmac_late_init(void)
256 late_initcall(pmac_late_init);
258 /* can't be __init - can be called whenever a disk is first accessed */
259 void __pmac note_bootable_part(dev_t dev, int part, int goodness)
261 static int found_boot = 0;
266 if ((goodness <= current_root_goodness) &&
267 ROOT_DEV != DEFAULT_ROOT_DEVICE)
269 p = strstr(saved_command_line, "root=");
270 if (p != NULL && (p == saved_command_line || p[-1] == ' '))
277 if (!boot_dev || dev == boot_dev) {
278 ROOT_DEV = dev + part;
280 current_root_goodness = goodness;
284 void __pmac pmac_restart(char *cmd)
289 void __pmac pmac_power_off(void)
294 void __pmac pmac_halt(void)
299 #ifdef CONFIG_BOOTX_TEXT
300 static int dummy_getc_poll(void)
305 static unsigned char dummy_getc(void)
310 static void btext_putc(unsigned char c)
314 #endif /* CONFIG_BOOTX_TEXT */
317 * Early initialization.
318 * Relocation is on but do not reference unbolted pages
319 * Also, device-tree hasn't been "finished", so don't muck with
322 void __init pmac_init_early(void)
326 #ifdef CONFIG_BOOTX_TEXT
327 ppc_md.udbg_putc = btext_putc;
328 ppc_md.udbg_getc = dummy_getc;
329 ppc_md.udbg_getc_poll = dummy_getc_poll;
330 #endif /* CONFIG_BOOTX_TEXT */
333 extern void* OpenPIC_Addr;
334 extern void* OpenPIC2_Addr;
335 extern u_int OpenPIC_NumInitSenses;
336 extern u_char *OpenPIC_InitSenses;
337 extern void openpic_init(int main_pic, int offset, unsigned char* chrp_ack,
338 int programmer_switch_irq);
339 extern void openpic2_init(int offset);
340 extern int openpic_get_irq(struct pt_regs *regs);
341 extern int openpic2_get_irq(struct pt_regs *regs);
343 static int pmac_cascade_irq = -1;
345 static irqreturn_t pmac_u3_do_cascade(int cpl, void *dev_id, struct pt_regs *regs)
350 irq = openpic2_get_irq(regs);
353 ppc_irq_dispatch_handler(regs, irq);
358 static __init void pmac_init_IRQ(void)
360 struct device_node *irqctrler = NULL;
361 struct device_node *irqctrler2 = NULL;
362 struct device_node *np = NULL;
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 OpenPIC_InitSenses = senses;
383 OpenPIC_NumInitSenses = 128;
384 OpenPIC_Addr = ioremap(irqctrler->addrs[0].address,
385 irqctrler->addrs[0].size);
386 openpic_init(1, 0, NULL, -1);
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);
393 pmac_call_feature(PMAC_FTR_ENABLE_MPIC, irqctrler2, 0, 0);
394 OpenPIC2_Addr = ioremap(irqctrler2->addrs[0].address,
395 irqctrler2->addrs[0].size);
396 prom_get_irq_senses(senses, 128, 128 + 128);
397 OpenPIC_InitSenses = senses;
398 OpenPIC_NumInitSenses = 128;
400 pmac_cascade_irq = irqctrler2->intrs[0].line;
403 of_node_put(irqctrler);
404 of_node_put(irqctrler2);
407 /* We cannot do request_irq too early ... Right now, we get the
408 * cascade as a core_initcall, which should be fine for our needs
410 static int __init pmac_irq_cascade_init(void)
412 if (request_irq(pmac_cascade_irq, pmac_u3_do_cascade, 0,
413 "U3->K2 Cascade", NULL))
414 printk(KERN_ERR "Unable to get OpenPIC IRQ for cascade\n");
418 core_initcall(pmac_irq_cascade_init);
420 void __init pmac_init(unsigned long r3, unsigned long r4, unsigned long r5,
421 unsigned long r6, unsigned long r7)
423 /* Probe motherboard chipset */
427 if (strstr(cmd_line, "sccdbg")) {
432 /* Fill up the machine description */
433 ppc_md.setup_arch = pmac_setup_arch;
434 ppc_md.get_cpuinfo = pmac_show_cpuinfo;
436 ppc_md.init_IRQ = pmac_init_IRQ;
437 ppc_md.get_irq = openpic_get_irq;
439 ppc_md.pcibios_fixup = pmac_pcibios_fixup;
441 ppc_md.restart = pmac_restart;
442 ppc_md.power_off = pmac_power_off;
443 ppc_md.halt = pmac_halt;
445 ppc_md.get_boot_time = pmac_get_boot_time;
446 ppc_md.set_rtc_time = pmac_set_rtc_time;
447 ppc_md.get_rtc_time = pmac_get_rtc_time;
448 ppc_md.calibrate_decr = pmac_calibrate_decr;
450 ppc_md.feature_call = pmac_do_feature_call;
453 #ifdef CONFIG_BOOTX_TEXT
454 ppc_md.progress = pmac_progress;
455 #endif /* CONFIG_BOOTX_TEXT */
457 if (ppc_md.progress) ppc_md.progress("pmac_init(): exit", 0);
461 #ifdef CONFIG_BOOTX_TEXT
462 void __init pmac_progress(char *s, unsigned short hex)
468 else if (boot_text_mapped) {
470 btext_drawchar('\n');
473 #endif /* CONFIG_BOOTX_TEXT */
475 static int __init pmac_declare_of_platform_devices(void)
477 struct device_node *np;
479 np = find_devices("u3");
481 for (np = np->child; np != NULL; np = np->sibling)
482 if (strncmp(np->name, "i2c", 3) == 0) {
483 of_platform_device_create(np, "u3-i2c");
491 device_initcall(pmac_declare_of_platform_devices);