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