initial commit with v2.6.9
[linux-2.6.9-moxart.git] / arch / ppc64 / kernel / pmac_setup.c
blob3d1de0f9bf83b51e7b1d0c564b8781a54ba6b9e0
1 /*
2 * arch/ppc/platforms/setup.c
4 * PowerPC version
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 #undef DEBUG
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>
33 #include <linux/mm.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>
57 #include <asm/processor.h>
58 #include <asm/sections.h>
59 #include <asm/prom.h>
60 #include <asm/system.h>
61 #include <asm/pgtable.h>
62 #include <asm/bitops.h>
63 #include <asm/io.h>
64 #include <asm/pci-bridge.h>
65 #include <asm/iommu.h>
66 #include <asm/machdep.h>
67 #include <asm/dma.h>
68 #include <asm/btext.h>
69 #include <asm/cputable.h>
70 #include <asm/pmac_feature.h>
71 #include <asm/time.h>
72 #include <asm/of_device.h>
73 #include <asm/lmb.h>
75 #include "pmac.h"
77 #ifdef DEBUG
78 #define DBG(fmt...) udbg_printf(fmt)
79 #else
80 #define DBG(fmt...)
81 #endif
84 static int current_root_goodness = -1;
85 #define DEFAULT_ROOT_DEVICE Root_SDA1 /* sda1 - slightly silly choice */
87 extern int powersave_nap;
88 int sccdbg;
90 extern void udbg_init_scc(struct device_node *np);
92 void __pmac pmac_show_cpuinfo(struct seq_file *m)
94 struct device_node *np;
95 char *pp;
96 int plen;
97 char* mbname;
98 int mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
99 PMAC_MB_INFO_MODEL, 0);
100 unsigned int mbflags = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
101 PMAC_MB_INFO_FLAGS, 0);
103 if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME,
104 (long)&mbname) != 0)
105 mbname = "Unknown";
107 /* find motherboard type */
108 seq_printf(m, "machine\t\t: ");
109 np = find_devices("device-tree");
110 if (np != NULL) {
111 pp = (char *) get_property(np, "model", NULL);
112 if (pp != NULL)
113 seq_printf(m, "%s\n", pp);
114 else
115 seq_printf(m, "PowerMac\n");
116 pp = (char *) get_property(np, "compatible", &plen);
117 if (pp != NULL) {
118 seq_printf(m, "motherboard\t:");
119 while (plen > 0) {
120 int l = strlen(pp) + 1;
121 seq_printf(m, " %s", pp);
122 plen -= l;
123 pp += l;
125 seq_printf(m, "\n");
127 } else
128 seq_printf(m, "PowerMac\n");
130 /* print parsed model */
131 seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname);
132 seq_printf(m, "pmac flags\t: %08x\n", mbflags);
134 /* Indicate newworld */
135 seq_printf(m, "pmac-generation\t: NewWorld\n");
139 void __init pmac_setup_arch(void)
141 /* init to some ~sane value until calibrate_delay() runs */
142 loops_per_jiffy = 50000000;
144 /* Probe motherboard chipset */
145 pmac_feature_init();
146 #if 0
147 /* Lock-enable the SCC channel used for debug */
148 if (sccdbg) {
149 np = of_find_node_by_name(NULL, "escc");
150 if (np)
151 pmac_call_feature(PMAC_FTR_SCC_ENABLE, np,
152 PMAC_SCC_ASYNC | PMAC_SCC_FLAG_XMON, 1);
154 #endif
155 /* We can NAP */
156 powersave_nap = 1;
158 /* Initialize the PMU */
159 find_via_pmu();
161 /* Init NVRAM access */
162 pmac_nvram_init();
164 /* Setup SMP callback */
165 #ifdef CONFIG_SMP
166 pmac_setup_smp();
167 #endif
169 /* Setup the PCI DMA to "direct" by default. May be overriden
170 * by iommu later on
172 pci_dma_init_direct();
174 /* Lookup PCI hosts */
175 pmac_pci_init();
177 #ifdef CONFIG_DUMMY_CONSOLE
178 conswitchp = &dummy_con;
179 #endif
182 #ifdef CONFIG_SCSI
183 void note_scsi_host(struct device_node *node, void *host)
185 /* Obsolete */
187 #endif
190 static int initializing = 1;
192 static int pmac_late_init(void)
194 initializing = 0;
195 return 0;
198 late_initcall(pmac_late_init);
200 /* can't be __init - can be called whenever a disk is first accessed */
201 void __pmac note_bootable_part(dev_t dev, int part, int goodness)
203 extern dev_t boot_dev;
204 char *p;
206 if (!initializing)
207 return;
208 if ((goodness <= current_root_goodness) &&
209 ROOT_DEV != DEFAULT_ROOT_DEVICE)
210 return;
211 p = strstr(saved_command_line, "root=");
212 if (p != NULL && (p == saved_command_line || p[-1] == ' '))
213 return;
215 if (!boot_dev || dev == boot_dev) {
216 ROOT_DEV = dev + part;
217 boot_dev = 0;
218 current_root_goodness = goodness;
222 void __pmac pmac_restart(char *cmd)
224 pmu_restart();
227 void __pmac pmac_power_off(void)
229 pmu_shutdown();
232 void __pmac pmac_halt(void)
234 pmac_power_off();
237 #ifdef CONFIG_BOOTX_TEXT
238 static int dummy_getc_poll(void)
240 return -1;
243 static unsigned char dummy_getc(void)
245 return 0;
248 static void btext_putc(unsigned char c)
250 btext_drawchar(c);
252 #endif /* CONFIG_BOOTX_TEXT */
254 static void __init init_boot_display(void)
256 char *name;
257 struct device_node *np = NULL;
258 int rc = -ENODEV;
260 printk("trying to initialize btext ...\n");
262 name = (char *)get_property(of_chosen, "linux,stdout-path", NULL);
263 if (name != NULL) {
264 np = of_find_node_by_path(name);
265 if (np != NULL) {
266 if (strcmp(np->type, "display") != 0) {
267 printk("boot stdout isn't a display !\n");
268 of_node_put(np);
269 np = NULL;
273 if (np)
274 rc = btext_initialize(np);
275 if (rc == 0)
276 return;
278 for (np = NULL; (np = of_find_node_by_type(np, "display"));) {
279 if (get_property(np, "linux,opened", NULL)) {
280 printk("trying %s ...\n", np->full_name);
281 rc = btext_initialize(np);
282 printk("result: %d\n", rc);
284 if (rc == 0)
285 return;
290 * Early initialization.
292 void __init pmac_init_early(void)
294 DBG(" -> pmac_init_early\n");
296 /* Initialize hash table, from now on, we can take hash faults
297 * and call ioremap
299 hpte_init_native();
301 /* Init SCC */
302 if (strstr(cmd_line, "sccdbg")) {
303 sccdbg = 1;
304 udbg_init_scc(NULL);
307 else {
308 #ifdef CONFIG_BOOTX_TEXT
309 init_boot_display();
311 ppc_md.udbg_putc = btext_putc;
312 ppc_md.udbg_getc = dummy_getc;
313 ppc_md.udbg_getc_poll = dummy_getc_poll;
314 #endif /* CONFIG_BOOTX_TEXT */
317 /* Setup interrupt mapping options */
318 naca->interrupt_controller = IC_OPEN_PIC;
320 DBG(" <- pmac_init_early\n");
323 extern void* OpenPIC_Addr;
324 extern void* OpenPIC2_Addr;
325 extern u_int OpenPIC_NumInitSenses;
326 extern u_char *OpenPIC_InitSenses;
327 extern void openpic_init(int main_pic, int offset, unsigned char* chrp_ack,
328 int programmer_switch_irq);
329 extern void openpic2_init(int offset);
330 extern int openpic_get_irq(struct pt_regs *regs);
331 extern int openpic2_get_irq(struct pt_regs *regs);
333 static int pmac_cascade_irq = -1;
335 static irqreturn_t pmac_u3_do_cascade(int cpl, void *dev_id, struct pt_regs *regs)
337 int irq;
339 for (;;) {
340 irq = openpic2_get_irq(regs);
341 if (irq == -1)
342 break;
343 ppc_irq_dispatch_handler(regs, irq);
345 return IRQ_HANDLED;
348 static __init void pmac_init_IRQ(void)
350 struct device_node *irqctrler = NULL;
351 struct device_node *irqctrler2 = NULL;
352 struct device_node *np = NULL;
354 /* We first try to detect Apple's new Core99 chipset, since mac-io
355 * is quite different on those machines and contains an IBM MPIC2.
357 while ((np = of_find_node_by_type(np, "open-pic")) != NULL) {
358 struct device_node *parent = of_get_parent(np);
359 if (parent && !strcmp(parent->name, "u3"))
360 irqctrler2 = of_node_get(np);
361 else
362 irqctrler = of_node_get(np);
363 of_node_put(parent);
365 if (irqctrler != NULL && irqctrler->n_addrs > 0) {
366 unsigned char senses[128];
368 printk(KERN_INFO "PowerMac using OpenPIC irq controller at 0x%08x\n",
369 (unsigned int)irqctrler->addrs[0].address);
371 prom_get_irq_senses(senses, 0, 128);
372 OpenPIC_InitSenses = senses;
373 OpenPIC_NumInitSenses = 128;
374 OpenPIC_Addr = ioremap(irqctrler->addrs[0].address,
375 irqctrler->addrs[0].size);
376 openpic_init(1, 0, NULL, -1);
378 if (irqctrler2 != NULL && irqctrler2->n_intrs > 0 &&
379 irqctrler2->n_addrs > 0) {
380 printk(KERN_INFO "Slave OpenPIC at 0x%08x hooked on IRQ %d\n",
381 (u32)irqctrler2->addrs[0].address,
382 irqctrler2->intrs[0].line);
383 pmac_call_feature(PMAC_FTR_ENABLE_MPIC, irqctrler2, 0, 0);
384 OpenPIC2_Addr = ioremap(irqctrler2->addrs[0].address,
385 irqctrler2->addrs[0].size);
386 prom_get_irq_senses(senses, 128, 128 + 128);
387 OpenPIC_InitSenses = senses;
388 OpenPIC_NumInitSenses = 128;
389 openpic2_init(128);
390 pmac_cascade_irq = irqctrler2->intrs[0].line;
393 of_node_put(irqctrler);
394 of_node_put(irqctrler2);
397 /* We cannot do request_irq too early ... Right now, we get the
398 * cascade as a core_initcall, which should be fine for our needs
400 static int __init pmac_irq_cascade_init(void)
402 if (request_irq(pmac_cascade_irq, pmac_u3_do_cascade, 0,
403 "U3->K2 Cascade", NULL))
404 printk(KERN_ERR "Unable to get OpenPIC IRQ for cascade\n");
405 return 0;
408 core_initcall(pmac_irq_cascade_init);
410 static void __init pmac_progress(char *s, unsigned short hex)
412 if (sccdbg) {
413 udbg_puts(s);
414 udbg_puts("\n");
416 #ifdef CONFIG_BOOTX_TEXT
417 else if (boot_text_mapped) {
418 btext_drawstring(s);
419 btext_drawstring("\n");
421 #endif /* CONFIG_BOOTX_TEXT */
424 static int __init pmac_declare_of_platform_devices(void)
426 struct device_node *np;
428 np = find_devices("u3");
429 if (np) {
430 for (np = np->child; np != NULL; np = np->sibling)
431 if (strncmp(np->name, "i2c", 3) == 0) {
432 of_platform_device_create(np, "u3-i2c");
433 break;
437 return 0;
440 device_initcall(pmac_declare_of_platform_devices);
443 * Called very early, MMU is off, device-tree isn't unflattened
445 static int __init pmac_probe(int platform)
447 if (platform != PLATFORM_POWERMAC)
448 return 0;
451 * On U3, the DART (iommu) must be allocated now since it
452 * has an impact on htab_initialize (due to the large page it
453 * occupies having to be broken up so the DART itself is not
454 * part of the cacheable linar mapping
456 alloc_u3_dart_table();
458 return 1;
461 struct machdep_calls __initdata pmac_md = {
462 .probe = pmac_probe,
463 .setup_arch = pmac_setup_arch,
464 .init_early = pmac_init_early,
465 .get_cpuinfo = pmac_show_cpuinfo,
466 .init_IRQ = pmac_init_IRQ,
467 .get_irq = openpic_get_irq,
468 .pcibios_fixup = pmac_pcibios_fixup,
469 .restart = pmac_restart,
470 .power_off = pmac_power_off,
471 .halt = pmac_halt,
472 .get_boot_time = pmac_get_boot_time,
473 .set_rtc_time = pmac_set_rtc_time,
474 .get_rtc_time = pmac_get_rtc_time,
475 .calibrate_decr = pmac_calibrate_decr,
476 .feature_call = pmac_do_feature_call,
477 .progress = pmac_progress,