]> err.no Git - linux-2.6/blob - arch/ppc/platforms/chrp_setup.c
Merge branch 'for-linus' of master.kernel.org:/pub/scm/linux/kernel/git/roland/infiniband
[linux-2.6] / arch / ppc / platforms / chrp_setup.c
1 /*
2  *  arch/ppc/platforms/setup.c
3  *
4  *  Copyright (C) 1995  Linus Torvalds
5  *  Adapted from 'alpha' version by Gary Thomas
6  *  Modified by Cort Dougan (cort@cs.nmt.edu)
7  */
8
9 /*
10  * bootup setup stuff..
11  */
12
13 #include <linux/config.h>
14 #include <linux/errno.h>
15 #include <linux/sched.h>
16 #include <linux/kernel.h>
17 #include <linux/mm.h>
18 #include <linux/stddef.h>
19 #include <linux/unistd.h>
20 #include <linux/ptrace.h>
21 #include <linux/slab.h>
22 #include <linux/user.h>
23 #include <linux/a.out.h>
24 #include <linux/tty.h>
25 #include <linux/major.h>
26 #include <linux/interrupt.h>
27 #include <linux/reboot.h>
28 #include <linux/init.h>
29 #include <linux/pci.h>
30 #include <linux/version.h>
31 #include <linux/adb.h>
32 #include <linux/module.h>
33 #include <linux/delay.h>
34 #include <linux/ide.h>
35 #include <linux/console.h>
36 #include <linux/seq_file.h>
37 #include <linux/root_dev.h>
38 #include <linux/initrd.h>
39 #include <linux/module.h>
40
41 #include <asm/io.h>
42 #include <asm/pgtable.h>
43 #include <asm/prom.h>
44 #include <asm/gg2.h>
45 #include <asm/pci-bridge.h>
46 #include <asm/dma.h>
47 #include <asm/machdep.h>
48 #include <asm/irq.h>
49 #include <asm/hydra.h>
50 #include <asm/sections.h>
51 #include <asm/time.h>
52 #include <asm/btext.h>
53 #include <asm/i8259.h>
54 #include <asm/open_pic.h>
55 #include <asm/xmon.h>
56
57 unsigned long chrp_get_rtc_time(void);
58 int chrp_set_rtc_time(unsigned long nowtime);
59 void chrp_calibrate_decr(void);
60 long chrp_time_init(void);
61
62 void chrp_find_bridges(void);
63 void chrp_event_scan(void);
64 void rtas_display_progress(char *, unsigned short);
65 void rtas_indicator_progress(char *, unsigned short);
66 void btext_progress(char *, unsigned short);
67
68 extern unsigned long pmac_find_end_of_memory(void);
69 extern int of_show_percpuinfo(struct seq_file *, int);
70
71 int _chrp_type;
72 EXPORT_SYMBOL(_chrp_type);
73
74 /*
75  * XXX this should be in xmon.h, but putting it there means xmon.h
76  * has to include <linux/interrupt.h> (to get irqreturn_t), which
77  * causes all sorts of problems.  -- paulus
78  */
79 extern irqreturn_t xmon_irq(int, void *, struct pt_regs *);
80
81 extern dev_t boot_dev;
82
83 extern PTE *Hash, *Hash_end;
84 extern unsigned long Hash_size, Hash_mask;
85 extern int probingmem;
86 extern unsigned long loops_per_jiffy;
87 static int max_width;
88
89 #ifdef CONFIG_SMP
90 extern struct smp_ops_t chrp_smp_ops;
91 #endif
92
93 static const char *gg2_memtypes[4] = {
94         "FPM", "SDRAM", "EDO", "BEDO"
95 };
96 static const char *gg2_cachesizes[4] = {
97         "256 KB", "512 KB", "1 MB", "Reserved"
98 };
99 static const char *gg2_cachetypes[4] = {
100         "Asynchronous", "Reserved", "Flow-Through Synchronous",
101         "Pipelined Synchronous"
102 };
103 static const char *gg2_cachemodes[4] = {
104         "Disabled", "Write-Through", "Copy-Back", "Transparent Mode"
105 };
106
107 int __chrp
108 chrp_show_cpuinfo(struct seq_file *m)
109 {
110         int i, sdramen;
111         unsigned int t;
112         struct device_node *root;
113         const char *model = "";
114
115         root = find_path_device("/");
116         if (root)
117                 model = get_property(root, "model", NULL);
118         seq_printf(m, "machine\t\t: CHRP %s\n", model);
119
120         /* longtrail (goldengate) stuff */
121         if (!strncmp(model, "IBM,LongTrail", 13)) {
122                 /* VLSI VAS96011/12 `Golden Gate 2' */
123                 /* Memory banks */
124                 sdramen = (in_le32(gg2_pci_config_base + GG2_PCI_DRAM_CTRL)
125                            >>31) & 1;
126                 for (i = 0; i < (sdramen ? 4 : 6); i++) {
127                         t = in_le32(gg2_pci_config_base+
128                                                  GG2_PCI_DRAM_BANK0+
129                                                  i*4);
130                         if (!(t & 1))
131                                 continue;
132                         switch ((t>>8) & 0x1f) {
133                         case 0x1f:
134                                 model = "4 MB";
135                                 break;
136                         case 0x1e:
137                                 model = "8 MB";
138                                 break;
139                         case 0x1c:
140                                 model = "16 MB";
141                                 break;
142                         case 0x18:
143                                 model = "32 MB";
144                                 break;
145                         case 0x10:
146                                 model = "64 MB";
147                                 break;
148                         case 0x00:
149                                 model = "128 MB";
150                                 break;
151                         default:
152                                 model = "Reserved";
153                                 break;
154                         }
155                         seq_printf(m, "memory bank %d\t: %s %s\n", i, model,
156                                    gg2_memtypes[sdramen ? 1 : ((t>>1) & 3)]);
157                 }
158                 /* L2 cache */
159                 t = in_le32(gg2_pci_config_base+GG2_PCI_CC_CTRL);
160                 seq_printf(m, "board l2\t: %s %s (%s)\n",
161                            gg2_cachesizes[(t>>7) & 3],
162                            gg2_cachetypes[(t>>2) & 3],
163                            gg2_cachemodes[t & 3]);
164         }
165         return 0;
166 }
167
168 /*
169  *  Fixes for the National Semiconductor PC78308VUL SuperI/O
170  *
171  *  Some versions of Open Firmware incorrectly initialize the IRQ settings
172  *  for keyboard and mouse
173  */
174 static inline void __init sio_write(u8 val, u8 index)
175 {
176         outb(index, 0x15c);
177         outb(val, 0x15d);
178 }
179
180 static inline u8 __init sio_read(u8 index)
181 {
182         outb(index, 0x15c);
183         return inb(0x15d);
184 }
185
186 static void __init sio_fixup_irq(const char *name, u8 device, u8 level,
187                                      u8 type)
188 {
189         u8 level0, type0, active;
190
191         /* select logical device */
192         sio_write(device, 0x07);
193         active = sio_read(0x30);
194         level0 = sio_read(0x70);
195         type0 = sio_read(0x71);
196         if (level0 != level || type0 != type || !active) {
197                 printk(KERN_WARNING "sio: %s irq level %d, type %d, %sactive: "
198                        "remapping to level %d, type %d, active\n",
199                        name, level0, type0, !active ? "in" : "", level, type);
200                 sio_write(0x01, 0x30);
201                 sio_write(level, 0x70);
202                 sio_write(type, 0x71);
203         }
204 }
205
206 static void __init sio_init(void)
207 {
208         struct device_node *root;
209
210         if ((root = find_path_device("/")) &&
211             !strncmp(get_property(root, "model", NULL), "IBM,LongTrail", 13)) {
212                 /* logical device 0 (KBC/Keyboard) */
213                 sio_fixup_irq("keyboard", 0, 1, 2);
214                 /* select logical device 1 (KBC/Mouse) */
215                 sio_fixup_irq("mouse", 1, 12, 2);
216         }
217 }
218
219
220 static void __init pegasos_set_l2cr(void)
221 {
222         struct device_node *np;
223
224         /* On Pegasos, enable the l2 cache if needed, as the OF forgets it */
225         if (_chrp_type != _CHRP_Pegasos)
226                 return;
227
228         /* Enable L2 cache if needed */
229         np = find_type_devices("cpu");
230         if (np != NULL) {
231                 unsigned int *l2cr = (unsigned int *)
232                         get_property (np, "l2cr", NULL);
233                 if (l2cr == NULL) {
234                         printk ("Pegasos l2cr : no cpu l2cr property found\n");
235                         return;
236                 }
237                 if (!((*l2cr) & 0x80000000)) {
238                         printk ("Pegasos l2cr : L2 cache was not active, "
239                                 "activating\n");
240                         _set_L2CR(0);
241                         _set_L2CR((*l2cr) | 0x80000000);
242                 }
243         }
244 }
245
246 void __init chrp_setup_arch(void)
247 {
248         struct device_node *device;
249
250         /* init to some ~sane value until calibrate_delay() runs */
251         loops_per_jiffy = 50000000/HZ;
252
253 #ifdef CONFIG_BLK_DEV_INITRD
254         /* this is fine for chrp */
255         initrd_below_start_ok = 1;
256
257         if (initrd_start)
258                 ROOT_DEV = Root_RAM0;
259         else
260 #endif
261                 ROOT_DEV = Root_SDA2; /* sda2 (sda1 is for the kernel) */
262
263         /* On pegasos, enable the L2 cache if not already done by OF */
264         pegasos_set_l2cr();
265
266         /* Lookup PCI host bridges */
267         chrp_find_bridges();
268
269 #ifndef CONFIG_PPC64BRIDGE
270         /*
271          *  Temporary fixes for PCI devices.
272          *  -- Geert
273          */
274         hydra_init();           /* Mac I/O */
275
276 #endif /* CONFIG_PPC64BRIDGE */
277
278         /*
279          *  Fix the Super I/O configuration
280          */
281         sio_init();
282
283         /* Get the event scan rate for the rtas so we know how
284          * often it expects a heartbeat. -- Cort
285          */
286         if ( rtas_data ) {
287                 struct property *p;
288                 device = find_devices("rtas");
289                 for ( p = device->properties;
290                       p && strncmp(p->name, "rtas-event-scan-rate", 20);
291                       p = p->next )
292                         /* nothing */ ;
293                 if ( p && *(unsigned long *)p->value ) {
294                         ppc_md.heartbeat = chrp_event_scan;
295                         ppc_md.heartbeat_reset = (HZ/(*(unsigned long *)p->value)*30)-1;
296                         ppc_md.heartbeat_count = 1;
297                         printk("RTAS Event Scan Rate: %lu (%lu jiffies)\n",
298                                *(unsigned long *)p->value, ppc_md.heartbeat_reset );
299                 }
300         }
301
302         pci_create_OF_bus_map();
303 }
304
305 void __chrp
306 chrp_event_scan(void)
307 {
308         unsigned char log[1024];
309         unsigned long ret = 0;
310         /* XXX: we should loop until the hardware says no more error logs -- Cort */
311         call_rtas( "event-scan", 4, 1, &ret, 0xffffffff, 0,
312                    __pa(log), 1024 );
313         ppc_md.heartbeat_count = ppc_md.heartbeat_reset;
314 }
315
316 void __chrp
317 chrp_restart(char *cmd)
318 {
319         printk("RTAS system-reboot returned %d\n",
320                call_rtas("system-reboot", 0, 1, NULL));
321         for (;;);
322 }
323
324 void __chrp
325 chrp_power_off(void)
326 {
327         /* allow power on only with power button press */
328         printk("RTAS power-off returned %d\n",
329                call_rtas("power-off", 2, 1, NULL,0xffffffff,0xffffffff));
330         for (;;);
331 }
332
333 void __chrp
334 chrp_halt(void)
335 {
336         chrp_power_off();
337 }
338
339 u_int __chrp
340 chrp_irq_canonicalize(u_int irq)
341 {
342         if (irq == 2)
343                 return 9;
344         return irq;
345 }
346
347 /*
348  * Finds the open-pic node and sets OpenPIC_Addr based on its reg property.
349  * Then checks if it has an interrupt-ranges property.  If it does then
350  * we have a distributed open-pic, so call openpic_set_sources to tell
351  * the openpic code where to find the interrupt source registers.
352  */
353 static void __init chrp_find_openpic(void)
354 {
355         struct device_node *np;
356         int len, i;
357         unsigned int *iranges;
358         void __iomem *isu;
359
360         np = find_type_devices("open-pic");
361         if (np == NULL || np->n_addrs == 0)
362                 return;
363         printk(KERN_INFO "OpenPIC at %x (size %x)\n",
364                np->addrs[0].address, np->addrs[0].size);
365         OpenPIC_Addr = ioremap(np->addrs[0].address, 0x40000);
366         if (OpenPIC_Addr == NULL) {
367                 printk(KERN_ERR "Failed to map OpenPIC!\n");
368                 return;
369         }
370
371         iranges = (unsigned int *) get_property(np, "interrupt-ranges", &len);
372         if (iranges == NULL || len < 2 * sizeof(unsigned int))
373                 return;         /* not distributed */
374
375         /*
376          * The first pair of cells in interrupt-ranges refers to the
377          * IDU; subsequent pairs refer to the ISUs.
378          */
379         len /= 2 * sizeof(unsigned int);
380         if (np->n_addrs < len) {
381                 printk(KERN_ERR "Insufficient addresses for distributed"
382                        " OpenPIC (%d < %d)\n", np->n_addrs, len);
383                 return;
384         }
385         if (iranges[1] != 0) {
386                 printk(KERN_INFO "OpenPIC irqs %d..%d in IDU\n",
387                        iranges[0], iranges[0] + iranges[1] - 1);
388                 openpic_set_sources(iranges[0], iranges[1], NULL);
389         }
390         for (i = 1; i < len; ++i) {
391                 iranges += 2;
392                 printk(KERN_INFO "OpenPIC irqs %d..%d in ISU at %x (%x)\n",
393                        iranges[0], iranges[0] + iranges[1] - 1,
394                        np->addrs[i].address, np->addrs[i].size);
395                 isu = ioremap(np->addrs[i].address, np->addrs[i].size);
396                 if (isu != NULL)
397                         openpic_set_sources(iranges[0], iranges[1], isu);
398                 else
399                         printk(KERN_ERR "Failed to map OpenPIC ISU at %x!\n",
400                                np->addrs[i].address);
401         }
402 }
403
404 #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
405 static struct irqaction xmon_irqaction = {
406         .handler = xmon_irq,
407         .mask = CPU_MASK_NONE,
408         .name = "XMON break",
409 };
410 #endif
411
412 void __init chrp_init_IRQ(void)
413 {
414         struct device_node *np;
415         int i;
416         unsigned long chrp_int_ack = 0;
417         unsigned char init_senses[NR_IRQS - NUM_8259_INTERRUPTS];
418 #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
419         struct device_node *kbd;
420 #endif
421
422         for (np = find_devices("pci"); np != NULL; np = np->next) {
423                 unsigned int *addrp = (unsigned int *)
424                         get_property(np, "8259-interrupt-acknowledge", NULL);
425
426                 if (addrp == NULL)
427                         continue;
428                 chrp_int_ack = addrp[prom_n_addr_cells(np)-1];
429                 break;
430         }
431         if (np == NULL)
432                 printk(KERN_ERR "Cannot find PCI interrupt acknowledge address\n");
433
434         chrp_find_openpic();
435
436         if (OpenPIC_Addr) {
437                 prom_get_irq_senses(init_senses, NUM_8259_INTERRUPTS, NR_IRQS);
438                 OpenPIC_InitSenses = init_senses;
439                 OpenPIC_NumInitSenses = NR_IRQS - NUM_8259_INTERRUPTS;
440
441                 openpic_init(NUM_8259_INTERRUPTS);
442                 /* We have a cascade on OpenPIC IRQ 0, Linux IRQ 16 */
443                 openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
444                                        i8259_irq);
445
446         }
447         for (i = 0; i < NUM_8259_INTERRUPTS; i++)
448                 irq_desc[i].handler = &i8259_pic;
449         i8259_init(chrp_int_ack);
450
451 #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
452         /* see if there is a keyboard in the device tree
453            with a parent of type "adb" */
454         for (kbd = find_devices("keyboard"); kbd; kbd = kbd->next)
455                 if (kbd->parent && kbd->parent->type
456                     && strcmp(kbd->parent->type, "adb") == 0)
457                         break;
458         if (kbd)
459                 setup_irq(HYDRA_INT_ADB_NMI, &xmon_irqaction);
460 #endif
461 }
462
463 void __init
464 chrp_init2(void)
465 {
466 #ifdef CONFIG_NVRAM
467 // XX replace this in a more saner way
468 //      pmac_nvram_init();
469 #endif
470
471         request_region(0x20,0x20,"pic1");
472         request_region(0xa0,0x20,"pic2");
473         request_region(0x00,0x20,"dma1");
474         request_region(0x40,0x20,"timer");
475         request_region(0x80,0x10,"dma page reg");
476         request_region(0xc0,0x20,"dma2");
477
478         if (ppc_md.progress)
479                 ppc_md.progress("  Have fun!    ", 0x7777);
480 }
481
482 void __init
483 chrp_init(unsigned long r3, unsigned long r4, unsigned long r5,
484           unsigned long r6, unsigned long r7)
485 {
486         struct device_node *root = find_path_device ("/");
487         char *machine = NULL;
488
489 #ifdef CONFIG_BLK_DEV_INITRD
490         /* take care of initrd if we have one */
491         if ( r6 )
492         {
493                 initrd_start = r6 + KERNELBASE;
494                 initrd_end = r6 + r7 + KERNELBASE;
495         }
496 #endif /* CONFIG_BLK_DEV_INITRD */
497
498         ISA_DMA_THRESHOLD = ~0L;
499         DMA_MODE_READ = 0x44;
500         DMA_MODE_WRITE = 0x48;
501         isa_io_base = CHRP_ISA_IO_BASE;         /* default value */
502
503         if (root)
504                 machine = get_property(root, "model", NULL);
505         if (machine && strncmp(machine, "Pegasos", 7) == 0) {
506                 _chrp_type = _CHRP_Pegasos;
507         } else if (machine && strncmp(machine, "IBM", 3) == 0) {
508                 _chrp_type = _CHRP_IBM;
509         } else if (machine && strncmp(machine, "MOT", 3) == 0) {
510                 _chrp_type = _CHRP_Motorola;
511         } else {
512                 /* Let's assume it is an IBM chrp if all else fails */
513                 _chrp_type = _CHRP_IBM;
514         }
515
516         ppc_md.setup_arch     = chrp_setup_arch;
517         ppc_md.show_percpuinfo = of_show_percpuinfo;
518         ppc_md.show_cpuinfo   = chrp_show_cpuinfo;
519
520         ppc_md.irq_canonicalize = chrp_irq_canonicalize;
521         ppc_md.init_IRQ       = chrp_init_IRQ;
522         if (_chrp_type == _CHRP_Pegasos)
523                 ppc_md.get_irq        = i8259_irq;
524         else
525                 ppc_md.get_irq        = openpic_get_irq;
526
527         ppc_md.init           = chrp_init2;
528
529         ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
530
531         ppc_md.restart        = chrp_restart;
532         ppc_md.power_off      = chrp_power_off;
533         ppc_md.halt           = chrp_halt;
534
535         ppc_md.time_init      = chrp_time_init;
536         ppc_md.set_rtc_time   = chrp_set_rtc_time;
537         ppc_md.get_rtc_time   = chrp_get_rtc_time;
538         ppc_md.calibrate_decr = chrp_calibrate_decr;
539
540         ppc_md.find_end_of_memory = pmac_find_end_of_memory;
541
542         if (rtas_data) {
543                 struct device_node *rtas;
544                 unsigned int *p;
545
546                 rtas = find_devices("rtas");
547                 if (rtas != NULL) {
548                         if (get_property(rtas, "display-character", NULL)) {
549                                 ppc_md.progress = rtas_display_progress;
550                                 p = (unsigned int *) get_property
551                                        (rtas, "ibm,display-line-length", NULL);
552                                 if (p)
553                                         max_width = *p;
554                         } else if (get_property(rtas, "set-indicator", NULL))
555                                 ppc_md.progress = rtas_indicator_progress;
556                 }
557         }
558 #ifdef CONFIG_BOOTX_TEXT
559         if (ppc_md.progress == NULL && boot_text_mapped)
560                 ppc_md.progress = btext_progress;
561 #endif
562
563 #ifdef CONFIG_SMP
564         ppc_md.smp_ops = &chrp_smp_ops;
565 #endif /* CONFIG_SMP */
566
567         /*
568          * Print the banner, then scroll down so boot progress
569          * can be printed.  -- Cort
570          */
571         if (ppc_md.progress) ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0x0);
572 }
573
574 void __chrp
575 rtas_display_progress(char *s, unsigned short hex)
576 {
577         int width;
578         char *os = s;
579
580         if ( call_rtas( "display-character", 1, 1, NULL, '\r' ) )
581                 return;
582
583         width = max_width;
584         while ( *os )
585         {
586                 if ( (*os == '\n') || (*os == '\r') )
587                         width = max_width;
588                 else
589                         width--;
590                 call_rtas( "display-character", 1, 1, NULL, *os++ );
591                 /* if we overwrite the screen length */
592                 if ( width == 0 )
593                         while ( (*os != 0) && (*os != '\n') && (*os != '\r') )
594                                 os++;
595         }
596
597         /*while ( width-- > 0 )*/
598         call_rtas( "display-character", 1, 1, NULL, ' ' );
599 }
600
601 void __chrp
602 rtas_indicator_progress(char *s, unsigned short hex)
603 {
604         call_rtas("set-indicator", 3, 1, NULL, 6, 0, hex);
605 }
606
607 #ifdef CONFIG_BOOTX_TEXT
608 void
609 btext_progress(char *s, unsigned short hex)
610 {
611         prom_print(s);
612         prom_print("\n");
613 }
614 #endif /* CONFIG_BOOTX_TEXT */