vserver 1.9.5.x5
[linux-2.6.git] / arch / ppc64 / kernel / pmac_setup.c
1 /*
2  *  arch/ppc/platforms/setup.c
3  *
4  *  PowerPC version
5  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6  *
7  *  Adapted for Power Macintosh by Paul Mackerras
8  *    Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au)
9  *
10  *  Derived from "arch/alpha/kernel/setup.c"
11  *    Copyright (C) 1995 Linus Torvalds
12  *
13  *  Maintained by Benjamin Herrenschmidt (benh@kernel.crashing.org)
14  *
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.
19  *
20  */
21
22 /*
23  * bootup setup stuff..
24  */
25
26 #undef DEBUG
27
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>
56 #include <linux/bitops.h>
57
58 #include <asm/processor.h>
59 #include <asm/sections.h>
60 #include <asm/prom.h>
61 #include <asm/system.h>
62 #include <asm/io.h>
63 #include <asm/pci-bridge.h>
64 #include <asm/iommu.h>
65 #include <asm/machdep.h>
66 #include <asm/dma.h>
67 #include <asm/btext.h>
68 #include <asm/cputable.h>
69 #include <asm/pmac_feature.h>
70 #include <asm/time.h>
71 #include <asm/of_device.h>
72 #include <asm/lmb.h>
73
74 #include "pmac.h"
75 #include "mpic.h"
76
77 #ifdef DEBUG
78 #define DBG(fmt...) udbg_printf(fmt)
79 #else
80 #define DBG(fmt...)
81 #endif
82
83
84 static int current_root_goodness = -1;
85 #define DEFAULT_ROOT_DEVICE Root_SDA1   /* sda1 - slightly silly choice */
86
87 extern  int powersave_nap;
88 int sccdbg;
89
90 extern void udbg_init_scc(struct device_node *np);
91
92 void __pmac pmac_show_cpuinfo(struct seq_file *m)
93 {
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);
102
103         if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME,
104                               (long)&mbname) != 0)
105                 mbname = "Unknown";
106         
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;
124                         }
125                         seq_printf(m, "\n");
126                 }
127         } else
128                 seq_printf(m, "PowerMac\n");
129
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);
133
134         /* Indicate newworld */
135         seq_printf(m, "pmac-generation\t: NewWorld\n");
136 }
137
138
139 void __init pmac_setup_arch(void)
140 {
141         /* init to some ~sane value until calibrate_delay() runs */
142         loops_per_jiffy = 50000000;
143
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);
153         }
154 #endif
155         /* We can NAP */
156         powersave_nap = 1;
157
158         /* Initialize the PMU */
159         find_via_pmu();
160
161         /* Init NVRAM access */
162         pmac_nvram_init();
163
164         /* Setup SMP callback */
165 #ifdef CONFIG_SMP
166         pmac_setup_smp();
167 #endif
168
169         /* Lookup PCI hosts */
170         pmac_pci_init();
171
172 #ifdef CONFIG_DUMMY_CONSOLE
173         conswitchp = &dummy_con;
174 #endif
175 }
176
177 #ifdef CONFIG_SCSI
178 void note_scsi_host(struct device_node *node, void *host)
179 {
180         /* Obsolete */
181 }
182 #endif
183
184
185 static int initializing = 1;
186
187 static int pmac_late_init(void)
188 {
189         initializing = 0;
190         return 0;
191 }
192
193 late_initcall(pmac_late_init);
194
195 /* can't be __init - can be called whenever a disk is first accessed */
196 void __pmac note_bootable_part(dev_t dev, int part, int goodness)
197 {
198         extern dev_t boot_dev;
199         char *p;
200
201         if (!initializing)
202                 return;
203         if ((goodness <= current_root_goodness) &&
204             ROOT_DEV != DEFAULT_ROOT_DEVICE)
205                 return;
206         p = strstr(saved_command_line, "root=");
207         if (p != NULL && (p == saved_command_line || p[-1] == ' '))
208                 return;
209
210         if (!boot_dev || dev == boot_dev) {
211                 ROOT_DEV = dev + part;
212                 boot_dev = 0;
213                 current_root_goodness = goodness;
214         }
215 }
216
217 void __pmac pmac_restart(char *cmd)
218 {
219         pmu_restart();
220 }
221
222 void __pmac pmac_power_off(void)
223 {
224         pmu_shutdown();
225 }
226
227 void __pmac pmac_halt(void)
228 {
229         pmac_power_off();
230 }
231
232 #ifdef CONFIG_BOOTX_TEXT
233 static int dummy_getc_poll(void)
234 {
235         return -1;
236 }
237
238 static unsigned char dummy_getc(void)
239 {
240         return 0;
241 }
242
243 static void btext_putc(unsigned char c)
244 {
245         btext_drawchar(c);
246 }
247 #endif /* CONFIG_BOOTX_TEXT */
248
249 static void __init init_boot_display(void)
250 {
251         char *name;
252         struct device_node *np = NULL; 
253         int rc = -ENODEV;
254
255         printk("trying to initialize btext ...\n");
256
257         name = (char *)get_property(of_chosen, "linux,stdout-path", NULL);
258         if (name != NULL) {
259                 np = of_find_node_by_path(name);
260                 if (np != NULL) {
261                         if (strcmp(np->type, "display") != 0) {
262                                 printk("boot stdout isn't a display !\n");
263                                 of_node_put(np);
264                                 np = NULL;
265                         }
266                 }
267         }
268         if (np)
269                 rc = btext_initialize(np);
270         if (rc == 0)
271                 return;
272
273         for (np = NULL; (np = of_find_node_by_type(np, "display"));) {
274                 if (get_property(np, "linux,opened", NULL)) {
275                         printk("trying %s ...\n", np->full_name);
276                         rc = btext_initialize(np);
277                         printk("result: %d\n", rc);
278                 }
279                 if (rc == 0)
280                         return;
281         }
282 }
283
284 /* 
285  * Early initialization.
286  */
287 void __init pmac_init_early(void)
288 {
289         DBG(" -> pmac_init_early\n");
290
291         /* Initialize hash table, from now on, we can take hash faults
292          * and call ioremap
293          */
294         hpte_init_native();
295
296         /* Init SCC */
297         if (strstr(cmd_line, "sccdbg")) {
298                 sccdbg = 1;
299                 udbg_init_scc(NULL);
300         }
301
302         else {
303 #ifdef CONFIG_BOOTX_TEXT
304                 init_boot_display();
305
306                 ppc_md.udbg_putc = btext_putc;
307                 ppc_md.udbg_getc = dummy_getc;
308                 ppc_md.udbg_getc_poll = dummy_getc_poll;
309 #endif /* CONFIG_BOOTX_TEXT */
310         }
311
312         /* Setup interrupt mapping options */
313         ppc64_interrupt_controller = IC_OPEN_PIC;
314
315         iommu_init_early_u3();
316
317         DBG(" <- pmac_init_early\n");
318 }
319
320 static int pmac_u3_cascade(struct pt_regs *regs, void *data)
321 {
322         return mpic_get_one_irq((struct mpic *)data, regs);
323 }
324
325 static __init void pmac_init_IRQ(void)
326 {
327         struct device_node *irqctrler  = NULL;
328         struct device_node *irqctrler2 = NULL;
329         struct device_node *np = NULL;
330         struct mpic *mpic1, *mpic2;
331
332         /* We first try to detect Apple's new Core99 chipset, since mac-io
333          * is quite different on those machines and contains an IBM MPIC2.
334          */
335         while ((np = of_find_node_by_type(np, "open-pic")) != NULL) {
336                 struct device_node *parent = of_get_parent(np);
337                 if (parent && !strcmp(parent->name, "u3"))
338                         irqctrler2 = of_node_get(np);
339                 else
340                         irqctrler = of_node_get(np);
341                 of_node_put(parent);
342         }
343         if (irqctrler != NULL && irqctrler->n_addrs > 0) {
344                 unsigned char senses[128];
345
346                 printk(KERN_INFO "PowerMac using OpenPIC irq controller at 0x%08x\n",
347                        (unsigned int)irqctrler->addrs[0].address);
348
349                 prom_get_irq_senses(senses, 0, 128);
350                 mpic1 = mpic_alloc(irqctrler->addrs[0].address,
351                                    MPIC_PRIMARY | MPIC_WANTS_RESET,
352                                    0, 0, 128, 256, senses, 128, " K2-MPIC  ");
353                 BUG_ON(mpic1 == NULL);
354                 mpic_init(mpic1);               
355
356                 if (irqctrler2 != NULL && irqctrler2->n_intrs > 0 &&
357                     irqctrler2->n_addrs > 0) {
358                         printk(KERN_INFO "Slave OpenPIC at 0x%08x hooked on IRQ %d\n",
359                                (u32)irqctrler2->addrs[0].address,
360                                irqctrler2->intrs[0].line);
361
362                         pmac_call_feature(PMAC_FTR_ENABLE_MPIC, irqctrler2, 0, 0);
363                         prom_get_irq_senses(senses, 128, 128 + 128);
364
365                         /* We don't need to set MPIC_BROKEN_U3 here since we don't have
366                          * hypertransport interrupts routed to it
367                          */
368                         mpic2 = mpic_alloc(irqctrler2->addrs[0].address,
369                                            MPIC_BIG_ENDIAN | MPIC_WANTS_RESET,
370                                            0, 128, 128, 0, senses, 128, " U3-MPIC  ");
371                         BUG_ON(mpic2 == NULL);
372                         mpic_init(mpic2);
373                         mpic_setup_cascade(irqctrler2->intrs[0].line,
374                                            pmac_u3_cascade, mpic2);
375                 }
376         }
377         of_node_put(irqctrler);
378         of_node_put(irqctrler2);
379 }
380
381 static void __init pmac_progress(char *s, unsigned short hex)
382 {
383         if (sccdbg) {
384                 udbg_puts(s);
385                 udbg_puts("\n");
386         }
387 #ifdef CONFIG_BOOTX_TEXT
388         else if (boot_text_mapped) {
389                 btext_drawstring(s);
390                 btext_drawstring("\n");
391         }
392 #endif /* CONFIG_BOOTX_TEXT */
393 }
394
395 /*
396  * pmac has no legacy IO, anything calling this function has to
397  * fail or bad things will happen
398  */
399 static int pmac_check_legacy_ioport(unsigned int baseport)
400 {
401         return -ENODEV;
402 }
403
404 static int __init pmac_declare_of_platform_devices(void)
405 {
406         struct device_node *np;
407
408         np = find_devices("u3");
409         if (np) {
410                 for (np = np->child; np != NULL; np = np->sibling)
411                         if (strncmp(np->name, "i2c", 3) == 0) {
412                                 of_platform_device_create(np, "u3-i2c");
413                                 break;
414                         }
415         }
416
417         return 0;
418 }
419
420 device_initcall(pmac_declare_of_platform_devices);
421
422 /*
423  * Called very early, MMU is off, device-tree isn't unflattened
424  */
425 static int __init pmac_probe(int platform)
426 {
427         if (platform != PLATFORM_POWERMAC)
428                 return 0;
429
430         /*
431          * On U3, the DART (iommu) must be allocated now since it
432          * has an impact on htab_initialize (due to the large page it
433          * occupies having to be broken up so the DART itself is not
434          * part of the cacheable linar mapping
435          */
436         alloc_u3_dart_table();
437
438         return 1;
439 }
440
441 struct machdep_calls __initdata pmac_md = {
442         .probe                  = pmac_probe,
443         .setup_arch             = pmac_setup_arch,
444         .init_early             = pmac_init_early,
445         .get_cpuinfo            = pmac_show_cpuinfo,
446         .init_IRQ               = pmac_init_IRQ,
447         .get_irq                = mpic_get_irq,
448         .pcibios_fixup          = pmac_pcibios_fixup,
449         .restart                = pmac_restart,
450         .power_off              = pmac_power_off,
451         .halt                   = pmac_halt,
452         .get_boot_time          = pmac_get_boot_time,
453         .set_rtc_time           = pmac_set_rtc_time,
454         .get_rtc_time           = pmac_get_rtc_time,
455         .calibrate_decr         = pmac_calibrate_decr,
456         .feature_call           = pmac_do_feature_call,
457         .progress               = pmac_progress,
458         .check_legacy_ioport    = pmac_check_legacy_ioport
459 };