VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / arch / ppc / platforms / prep_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  * Support for PReP (Motorola MTX/MVME)
9  * by Troy Benjegerdes (hozer@drgw.net)
10  */
11
12 /*
13  * bootup setup stuff..
14  */
15
16 #include <linux/config.h>
17 #include <linux/delay.h>
18 #include <linux/module.h>
19 #include <linux/errno.h>
20 #include <linux/sched.h>
21 #include <linux/kernel.h>
22 #include <linux/mm.h>
23 #include <linux/stddef.h>
24 #include <linux/unistd.h>
25 #include <linux/ptrace.h>
26 #include <linux/slab.h>
27 #include <linux/user.h>
28 #include <linux/a.out.h>
29 #include <linux/tty.h>
30 #include <linux/major.h>
31 #include <linux/interrupt.h>
32 #include <linux/reboot.h>
33 #include <linux/init.h>
34 #include <linux/initrd.h>
35 #include <linux/ioport.h>
36 #include <linux/console.h>
37 #include <linux/timex.h>
38 #include <linux/pci.h>
39 #include <linux/ide.h>
40 #include <linux/seq_file.h>
41 #include <linux/root_dev.h>
42
43 #include <asm/sections.h>
44 #include <asm/mmu.h>
45 #include <asm/processor.h>
46 #include <asm/residual.h>
47 #include <asm/io.h>
48 #include <asm/pgtable.h>
49 #include <asm/cache.h>
50 #include <asm/dma.h>
51 #include <asm/machdep.h>
52 #include <asm/mc146818rtc.h>
53 #include <asm/mk48t59.h>
54 #include <asm/prep_nvram.h>
55 #include <asm/raven.h>
56 #include <asm/vga.h>
57 #include <asm/time.h>
58 #include <asm/mpc10x.h>
59 #include <asm/i8259.h>
60 #include <asm/open_pic.h>
61 #include <asm/pci-bridge.h>
62 #include <asm/todc.h>
63
64 TODC_ALLOC();
65
66 unsigned char ucSystemType;
67 unsigned char ucBoardRev;
68 unsigned char ucBoardRevMaj, ucBoardRevMin;
69
70 extern unsigned char prep_nvram_read_val(int addr);
71 extern void prep_nvram_write_val(int addr,
72                                  unsigned char val);
73 extern unsigned char rs_nvram_read_val(int addr);
74 extern void rs_nvram_write_val(int addr,
75                                  unsigned char val);
76 extern void ibm_prep_init(void);
77
78 extern void prep_find_bridges(void);
79
80 int _prep_type;
81
82 extern void prep_sandalfoot_setup_pci(char *irq_edge_mask_lo, char *irq_edge_mask_hi);
83 extern void prep_thinkpad_setup_pci(char *irq_edge_mask_lo, char *irq_edge_mask_hi);
84 extern void prep_carolina_setup_pci(char *irq_edge_mask_lo, char *irq_edge_mask_hi);
85 extern void prep_tiger1_setup_pci(char *irq_edge_mask_lo, char *irq_edge_mask_hi);
86
87
88 #define cached_21       (((char *)(ppc_cached_irq_mask))[3])
89 #define cached_A1       (((char *)(ppc_cached_irq_mask))[2])
90
91 /* for the mac fs */
92 dev_t boot_dev;
93
94 #ifdef CONFIG_SOUND_CS4232
95 long ppc_cs4232_dma, ppc_cs4232_dma2;
96 #endif
97
98 extern PTE *Hash, *Hash_end;
99 extern unsigned long Hash_size, Hash_mask;
100 extern int probingmem;
101 extern unsigned long loops_per_jiffy;
102
103 #ifdef CONFIG_SOUND_CS4232
104 EXPORT_SYMBOL(ppc_cs4232_dma);
105 EXPORT_SYMBOL(ppc_cs4232_dma2);
106 #endif
107
108 /* useful ISA ports */
109 #define PREP_SYSCTL     0x81c
110 /* present in the IBM reference design; possibly identical in Mot boxes: */
111 #define PREP_IBM_SIMM_ID        0x803   /* SIMM size: 32 or 8 MiB */
112 #define PREP_IBM_SIMM_PRESENCE  0x804
113 #define PREP_IBM_EQUIPMENT      0x80c
114 #define PREP_IBM_L2INFO 0x80d
115 #define PREP_IBM_PM1    0x82a   /* power management register 1 */
116 #define PREP_IBM_PLANAR 0x852   /* planar ID - identifies the motherboard */
117 #define PREP_IBM_DISP   0x8c0   /* 4-digit LED display */
118
119 /* Equipment Present Register masks: */
120 #define PREP_IBM_EQUIPMENT_RESERVED     0x80
121 #define PREP_IBM_EQUIPMENT_SCSIFUSE     0x40
122 #define PREP_IBM_EQUIPMENT_L2_COPYBACK  0x08
123 #define PREP_IBM_EQUIPMENT_L2_256       0x04
124 #define PREP_IBM_EQUIPMENT_CPU  0x02
125 #define PREP_IBM_EQUIPMENT_L2   0x01
126
127 /* planar ID values: */
128 /* Sandalfoot/Sandalbow (6015/7020) */
129 #define PREP_IBM_SANDALFOOT     0xfc
130 /* Woodfield, Thinkpad 850/860 (6042/7249) */
131 #define PREP_IBM_THINKPAD       0xff /* planar ID unimplemented */
132 /* PowerSeries 830/850 (6050/6070) */
133 #define PREP_IBM_CAROLINA_IDE_0 0xf0
134 #define PREP_IBM_CAROLINA_IDE_1 0xf1
135 #define PREP_IBM_CAROLINA_IDE_2 0xf2
136 #define PREP_IBM_CAROLINA_IDE_3 0xf3
137 /* 7248-43P */
138 #define PREP_IBM_CAROLINA_SCSI_0        0xf4
139 #define PREP_IBM_CAROLINA_SCSI_1        0xf5
140 #define PREP_IBM_CAROLINA_SCSI_2        0xf6
141 #define PREP_IBM_CAROLINA_SCSI_3        0xf7 /* missing from Carolina Tech Spec */
142 /* Tiger1 (7043-140) */
143 #define PREP_IBM_TIGER1_133             0xd1
144 #define PREP_IBM_TIGER1_166             0xd2
145 #define PREP_IBM_TIGER1_180             0xd3
146 #define PREP_IBM_TIGER1_xxx             0xd4 /* unknown, but probably exists */
147 #define PREP_IBM_TIGER1_333             0xd5 /* missing from Tiger Tech Spec */
148
149 /* setup_ibm_pci:
150  *      set Motherboard_map_name, Motherboard_map, Motherboard_routes.
151  *      return 8259 edge/level masks.
152  */
153 void (*setup_ibm_pci)(char *irq_lo, char *irq_hi);
154
155 extern char *Motherboard_map_name; /* for use in *_cpuinfo */
156
157 /*
158  * As found in the PReP reference implementation.
159  * Used by Thinkpad, Sandalfoot (6015/7020), and all Motorola PReP.
160  */
161 static void __init
162 prep_gen_enable_l2(void)
163 {
164         outb(inb(PREP_SYSCTL) | 0x3, PREP_SYSCTL);
165 }
166
167 /* Used by Carolina and Tiger1 */
168 static void __init
169 prep_carolina_enable_l2(void)
170 {
171         outb(inb(PREP_SYSCTL) | 0xc0, PREP_SYSCTL);
172 }
173
174 /* cpuinfo code common to all IBM PReP */
175 static void __prep
176 prep_ibm_cpuinfo(struct seq_file *m)
177 {
178         unsigned int equip_reg = inb(PREP_IBM_EQUIPMENT);
179
180         seq_printf(m, "machine\t\t: PReP %s\n", Motherboard_map_name);
181
182         seq_printf(m, "upgrade cpu\t: ");
183         if (equip_reg & PREP_IBM_EQUIPMENT_CPU) {
184                 seq_printf(m, "not ");
185         }
186         seq_printf(m, "present\n");
187
188         /* print info about the SCSI fuse */
189         seq_printf(m, "scsi fuse\t: ");
190         if (equip_reg & PREP_IBM_EQUIPMENT_SCSIFUSE)
191                 seq_printf(m, "ok");
192         else
193                 seq_printf(m, "bad");
194         seq_printf(m, "\n");
195
196 #ifdef CONFIG_PREP_RESIDUAL
197         /* print info about SIMMs */
198         if (res->ResidualLength != 0) {
199                 int i;
200                 seq_printf(m, "simms\t\t: ");
201                 for (i = 0; (res->ActualNumMemories) && (i < MAX_MEMS); i++) {
202                         if (res->Memories[i].SIMMSize != 0)
203                                 seq_printf(m, "%d:%ldMiB ", i,
204                                         (res->Memories[i].SIMMSize > 1024) ?
205                                         res->Memories[i].SIMMSize>>20 :
206                                         res->Memories[i].SIMMSize);
207                 }
208                 seq_printf(m, "\n");
209         }
210 #endif
211 }
212
213 static int __prep
214 prep_sandalfoot_cpuinfo(struct seq_file *m)
215 {
216         unsigned int equip_reg = inb(PREP_IBM_EQUIPMENT);
217
218         prep_ibm_cpuinfo(m);
219
220         /* report amount and type of L2 cache present */
221         seq_printf(m, "L2 cache\t: ");
222         if (equip_reg & PREP_IBM_EQUIPMENT_L2) {
223                 seq_printf(m, "not present");
224         } else {
225                 if (equip_reg & PREP_IBM_EQUIPMENT_L2_256)
226                         seq_printf(m, "256KiB");
227                 else
228                         seq_printf(m, "unknown size");
229
230                 if (equip_reg & PREP_IBM_EQUIPMENT_L2_COPYBACK)
231                         seq_printf(m, ", copy-back");
232                 else
233                         seq_printf(m, ", write-through");
234         }
235         seq_printf(m, "\n");
236
237         return 0;
238 }
239
240 static int __prep
241 prep_thinkpad_cpuinfo(struct seq_file *m)
242 {
243         unsigned int equip_reg = inb(PREP_IBM_EQUIPMENT);
244         char *cpubus_speed, *pci_speed;
245
246         prep_ibm_cpuinfo(m);
247
248         /* report amount and type of L2 cache present */
249         seq_printf(m, "l2 cache\t: ");
250         if ((equip_reg & 0x1) == 0) {
251                 switch ((equip_reg & 0xc) >> 2) {
252                         case 0x0:
253                                 seq_printf(m, "128KiB look-aside 2-way write-through\n");
254                                 break;
255                         case 0x1:
256                                 seq_printf(m, "512KiB look-aside direct-mapped write-back\n");
257                                 break;
258                         case 0x2:
259                                 seq_printf(m, "256KiB look-aside 2-way write-through\n");
260                                 break;
261                         case 0x3:
262                                 seq_printf(m, "256KiB look-aside direct-mapped write-back\n");
263                                 break;
264                 }
265         } else {
266                 seq_printf(m, "not present\n");
267         }
268
269         /* report bus speeds because we can */
270         if ((equip_reg & 0x80) == 0) {
271                 switch ((equip_reg & 0x30) >> 4) {
272                         case 0x1:
273                                 cpubus_speed = "50";
274                                 pci_speed = "25";
275                                 break;
276                         case 0x3:
277                                 cpubus_speed = "66";
278                                 pci_speed = "33";
279                                 break;
280                         default:
281                                 cpubus_speed = "unknown";
282                                 pci_speed = "unknown";
283                                 break;
284                 }
285         } else {
286                 switch ((equip_reg & 0x30) >> 4) {
287                         case 0x1:
288                                 cpubus_speed = "25";
289                                 pci_speed = "25";
290                                 break;
291                         case 0x2:
292                                 cpubus_speed = "60";
293                                 pci_speed = "30";
294                                 break;
295                         case 0x3:
296                                 cpubus_speed = "33";
297                                 pci_speed = "33";
298                                 break;
299                         default:
300                                 cpubus_speed = "unknown";
301                                 pci_speed = "unknown";
302                                 break;
303                 }
304         }
305         seq_printf(m, "60x bus\t\t: %sMHz\n", cpubus_speed);
306         seq_printf(m, "pci bus\t\t: %sMHz\n", pci_speed);
307
308         return 0;
309 }
310
311 static int __prep
312 prep_carolina_cpuinfo(struct seq_file *m)
313 {
314         unsigned int equip_reg = inb(PREP_IBM_EQUIPMENT);
315
316         prep_ibm_cpuinfo(m);
317
318         /* report amount and type of L2 cache present */
319         seq_printf(m, "l2 cache\t: ");
320         if ((equip_reg & 0x1) == 0) {
321                 unsigned int l2_reg = inb(PREP_IBM_L2INFO);
322
323                 /* L2 size */
324                 if ((l2_reg & 0x60) == 0)
325                         seq_printf(m, "256KiB");
326                 else if ((l2_reg & 0x60) == 0x20)
327                         seq_printf(m, "512KiB");
328                 else
329                         seq_printf(m, "unknown size");
330
331                 /* L2 type */
332                 if ((l2_reg & 0x3) == 0)
333                         seq_printf(m, ", async");
334                 else if ((l2_reg & 0x3) == 1)
335                         seq_printf(m, ", sync");
336                 else
337                         seq_printf(m, ", unknown type");
338
339                 seq_printf(m, "\n");
340         } else {
341                 seq_printf(m, "not present\n");
342         }
343
344         return 0;
345 }
346
347 static int __prep
348 prep_tiger1_cpuinfo(struct seq_file *m)
349 {
350         unsigned int l2_reg = inb(PREP_IBM_L2INFO);
351
352         prep_ibm_cpuinfo(m);
353
354         /* report amount and type of L2 cache present */
355         seq_printf(m, "l2 cache\t: ");
356         if ((l2_reg & 0xf) == 0xf) {
357                 seq_printf(m, "not present\n");
358         } else {
359                 if (l2_reg & 0x8)
360                         seq_printf(m, "async, ");
361                 else
362                         seq_printf(m, "sync burst, ");
363         
364                 if (l2_reg & 0x4)
365                         seq_printf(m, "parity, ");
366                 else
367                         seq_printf(m, "no parity, ");
368         
369                 switch (l2_reg & 0x3) {
370                         case 0x0:
371                                 seq_printf(m, "256KiB\n");
372                                 break;
373                         case 0x1:
374                                 seq_printf(m, "512KiB\n");
375                                 break;
376                         case 0x2:
377                                 seq_printf(m, "1MiB\n");
378                                 break;
379                         default:
380                                 seq_printf(m, "unknown size\n");
381                                 break;
382                 }
383         }
384
385         return 0;
386 }
387
388
389 /* Used by all Motorola PReP */
390 static int __prep
391 prep_mot_cpuinfo(struct seq_file *m)
392 {
393         unsigned int cachew = *((unsigned char *)CACHECRBA);
394
395         seq_printf(m, "machine\t\t: PReP %s\n", Motherboard_map_name);
396
397         /* report amount and type of L2 cache present */
398         seq_printf(m, "l2 cache\t: ");
399         switch (cachew & L2CACHE_MASK) {
400                 case L2CACHE_512KB:
401                         seq_printf(m, "512KiB");
402                         break;
403                 case L2CACHE_256KB:
404                         seq_printf(m, "256KiB");
405                         break;
406                 case L2CACHE_1MB:
407                         seq_printf(m, "1MiB");
408                         break;
409                 case L2CACHE_NONE:
410                         seq_printf(m, "none\n");
411                         goto no_l2;
412                         break;
413                 default:
414                         seq_printf(m, "%x\n", cachew);
415         }
416
417         seq_printf(m, ", parity %s",
418                         (cachew & L2CACHE_PARITY)? "enabled" : "disabled");
419
420         seq_printf(m, " SRAM:");
421
422         switch ( ((cachew & 0xf0) >> 4) & ~(0x3) ) {
423                 case 1: seq_printf(m, "synchronous, parity, flow-through\n");
424                                 break;
425                 case 2: seq_printf(m, "asynchronous, no parity\n");
426                                 break;
427                 case 3: seq_printf(m, "asynchronous, parity\n");
428                                 break;
429                 default:seq_printf(m, "synchronous, pipelined, no parity\n");
430                                 break;
431         }
432
433 no_l2:
434 #ifdef CONFIG_PREP_RESIDUAL
435         /* print info about SIMMs */
436         if (res->ResidualLength != 0) {
437                 int i;
438                 seq_printf(m, "simms\t\t: ");
439                 for (i = 0; (res->ActualNumMemories) && (i < MAX_MEMS); i++) {
440                         if (res->Memories[i].SIMMSize != 0)
441                                 seq_printf(m, "%d:%ldM ", i,
442                                         (res->Memories[i].SIMMSize > 1024) ?
443                                         res->Memories[i].SIMMSize>>20 :
444                                         res->Memories[i].SIMMSize);
445                 }
446                 seq_printf(m, "\n");
447         }
448 #endif
449
450         return 0;
451 }
452
453 static void __prep
454 prep_tiger1_progress(char *msg, unsigned short code)
455 {
456         outw(code, PREP_IBM_DISP);
457 }
458
459 static void __prep
460 prep_restart(char *cmd)
461 {
462 #define PREP_SP92       0x92    /* Special Port 92 */
463         local_irq_disable(); /* no interrupts */
464
465         /* set exception prefix high - to the prom */
466         _nmask_and_or_msr(0, MSR_IP);
467
468         /* make sure bit 0 (reset) is a 0 */
469         outb( inb(PREP_SP92) & ~1L , PREP_SP92);
470         /* signal a reset to system control port A - soft reset */
471         outb( inb(PREP_SP92) | 1 , PREP_SP92);
472
473         while ( 1 ) ;
474         /* not reached */
475 #undef PREP_SP92
476 }
477
478 static void __prep
479 prep_halt(void)
480 {
481         local_irq_disable(); /* no interrupts */
482
483         /* set exception prefix high - to the prom */
484         _nmask_and_or_msr(0, MSR_IP);
485
486         while ( 1 ) ;
487         /* not reached */
488 }
489
490 /* Carrera is the power manager in the Thinkpads. Unfortunately not much is
491  * known about it, so we can't power down.
492  */
493 static void __prep
494 prep_carrera_poweroff(void)
495 {
496         prep_halt();
497 }
498
499 /*
500  * On most IBM PReP's, power management is handled by a Signetics 87c750
501  * behind the Utah component on the ISA bus. To access the 750 you must write
502  * a series of nibbles to port 0x82a (decoded by the Utah). This is described
503  * somewhat in the IBM Carolina Technical Specification.
504  * -Hollis
505  */
506 static void __prep
507 utah_sig87c750_setbit(unsigned int bytenum, unsigned int bitnum, int value)
508 {
509         /*
510          * byte1: 0 0 0 1 0  d  a5 a4
511          * byte2: 0 0 0 1 a3 a2 a1 a0
512          *
513          * d = the bit's value, enabled or disabled
514          * (a5 a4 a3) = the byte number, minus 20
515          * (a2 a1 a0) = the bit number
516          *
517          * example: set the 5th bit of byte 21 (21.5)
518          *     a5 a4 a3 = 001 (byte 1)
519          *     a2 a1 a0 = 101 (bit 5)
520          *
521          *     byte1 = 0001 0100 (0x14)
522          *     byte2 = 0001 1101 (0x1d)
523          */
524         unsigned char byte1=0x10, byte2=0x10;
525
526         /* the 750's '20.0' is accessed as '0.0' through Utah (which adds 20) */
527         bytenum -= 20;
528
529         byte1 |= (!!value) << 2;                /* set d */
530         byte1 |= (bytenum >> 1) & 0x3;  /* set a5, a4 */
531
532         byte2 |= (bytenum & 0x1) << 3;  /* set a3 */
533         byte2 |= bitnum & 0x7;                  /* set a2, a1, a0 */
534
535         outb(byte1, PREP_IBM_PM1);      /* first nibble */
536         mb();
537         udelay(100);                            /* important: let controller recover */
538
539         outb(byte2, PREP_IBM_PM1);      /* second nibble */
540         mb();
541         udelay(100);                            /* important: let controller recover */
542 }
543
544 static void __prep
545 prep_sig750_poweroff(void)
546 {
547         /* tweak the power manager found in most IBM PRePs (except Thinkpads) */
548
549         local_irq_disable();
550         /* set exception prefix high - to the prom */
551         _nmask_and_or_msr(0, MSR_IP);
552
553         utah_sig87c750_setbit(21, 5, 1); /* set bit 21.5, "PMEXEC_OFF" */
554
555         while (1) ;
556         /* not reached */
557 }
558
559 static int __prep
560 prep_show_percpuinfo(struct seq_file *m, int i)
561 {
562         /* PREP's without residual data will give incorrect values here */
563         seq_printf(m, "clock\t\t: ");
564 #ifdef CONFIG_PREP_RESIDUAL
565         if (res->ResidualLength)
566                 seq_printf(m, "%ldMHz\n",
567                            (res->VitalProductData.ProcessorHz > 1024) ?
568                            res->VitalProductData.ProcessorHz / 1000000 :
569                            res->VitalProductData.ProcessorHz);
570         else
571 #endif /* CONFIG_PREP_RESIDUAL */
572                 seq_printf(m, "???\n");
573
574         return 0;
575 }
576
577 #ifdef CONFIG_SOUND_CS4232
578 static long __init masktoint(unsigned int i)
579 {
580         int t = -1;
581         while (i >> ++t)
582                 ;
583         return (t-1);
584 }
585
586 /*
587  * ppc_cs4232_dma and ppc_cs4232_dma2 are used in include/asm/dma.h
588  * to distinguish sound dma-channels from others. This is because
589  * blocksize on 16 bit dma-channels 5,6,7 is 128k, but
590  * the cs4232.c uses 64k like on 8 bit dma-channels 0,1,2,3
591  */
592
593 static void __init prep_init_sound(void)
594 {
595         PPC_DEVICE *audiodevice = NULL;
596
597         /*
598          * Get the needed resource informations from residual data.
599          *
600          */
601 #ifdef CONFIG_PREP_RESIDUAL
602         audiodevice = residual_find_device(~0, NULL, MultimediaController,
603                         AudioController, -1, 0);
604         if (audiodevice != NULL) {
605                 PnP_TAG_PACKET *pkt;
606
607                 pkt = PnP_find_packet((unsigned char *)&res->DevicePnPHeap[audiodevice->AllocatedOffset],
608                                 S5_Packet, 0);
609                 if (pkt != NULL)
610                         ppc_cs4232_dma = masktoint(pkt->S5_Pack.DMAMask);
611                 pkt = PnP_find_packet((unsigned char*)&res->DevicePnPHeap[audiodevice->AllocatedOffset],
612                                 S5_Packet, 1);
613                 if (pkt != NULL)
614                         ppc_cs4232_dma2 = masktoint(pkt->S5_Pack.DMAMask);
615         }
616 #endif
617
618         /*
619          * These are the PReP specs' defaults for the cs4231.  We use these
620          * as fallback incase we don't have residual data.
621          * At least the IBM Thinkpad 850 with IDE DMA Channels at 6 and 7
622          * will use the other values.
623          */
624         if (audiodevice == NULL) {
625                 switch (_prep_type) {
626                 case _PREP_IBM:
627                         ppc_cs4232_dma = 1;
628                         ppc_cs4232_dma2 = -1;
629                         break;
630                 default:
631                         ppc_cs4232_dma = 6;
632                         ppc_cs4232_dma2 = 7;
633                 }
634         }
635
636         /*
637          * Find a way to push these informations to the cs4232 driver
638          * Give it out with printk, when not in cmd_line?
639          * Append it to  cmd_line and saved_command_line?
640          * Format is cs4232=io,irq,dma,dma2
641          */
642 }
643 #endif /* CONFIG_SOUND_CS4232 */
644
645 /*
646  * Fill out screen_info according to the residual data. This allows us to use
647  * at least vesafb.
648  */
649 static void __init
650 prep_init_vesa(void)
651 {
652 #if defined(CONFIG_PREP_RESIDUAL) && \
653         (defined(CONFIG_FB_VGA16) || defined(CONFIG_FB_VGA_16_MODULE) || \
654          defined(CONFIG_FB_VESA))
655         PPC_DEVICE *vgadev;
656
657         vgadev = residual_find_device(~0, NULL, DisplayController, SVGAController,
658                                                                         -1, 0);
659         if (vgadev != NULL) {
660                 PnP_TAG_PACKET *pkt;
661
662                 pkt = PnP_find_large_vendor_packet(
663                                 (unsigned char *)&res->DevicePnPHeap[vgadev->AllocatedOffset],
664                                 0x04, 0); /* 0x04 = Display Tag */
665                 if (pkt != NULL) {
666                         unsigned char *ptr = (unsigned char *)pkt;
667
668                         if (ptr[4]) {
669                                 /* graphics mode */
670                                 screen_info.orig_video_isVGA = VIDEO_TYPE_VLFB;
671
672                                 screen_info.lfb_depth = ptr[4] * 8;
673
674                                 screen_info.lfb_width = swab16(*(short *)(ptr+6));
675                                 screen_info.lfb_height = swab16(*(short *)(ptr+8));
676                                 screen_info.lfb_linelength = swab16(*(short *)(ptr+10));
677
678                                 screen_info.lfb_base = swab32(*(long *)(ptr+12));
679                                 screen_info.lfb_size = swab32(*(long *)(ptr+20)) / 65536;
680                         }
681                 }
682         }
683 #endif /* CONFIG_PREP_RESIDUAL */
684 }
685
686 static void __init
687 prep_setup_arch(void)
688 {
689         unsigned char reg;
690         int is_ide=0;
691
692         /* init to some ~sane value until calibrate_delay() runs */
693         loops_per_jiffy = 50000000;
694
695         /* Lookup PCI host bridges */
696         prep_find_bridges();
697
698         /* Set up floppy in PS/2 mode */
699         outb(0x09, SIO_CONFIG_RA);
700         reg = inb(SIO_CONFIG_RD);
701         reg = (reg & 0x3F) | 0x40;
702         outb(reg, SIO_CONFIG_RD);
703         outb(reg, SIO_CONFIG_RD);       /* Have to write twice to change! */
704
705         switch ( _prep_type )
706         {
707         case _PREP_IBM:
708                 reg = inb(PREP_IBM_PLANAR);
709                 printk(KERN_INFO "IBM planar ID: %08x", reg);
710                 switch (reg) {
711                         case PREP_IBM_SANDALFOOT:
712                                 prep_gen_enable_l2();
713                                 setup_ibm_pci = prep_sandalfoot_setup_pci;
714                                 ppc_md.power_off = prep_sig750_poweroff;
715                                 ppc_md.show_cpuinfo = prep_sandalfoot_cpuinfo;
716                                 break;
717                         case PREP_IBM_THINKPAD:
718                                 prep_gen_enable_l2();
719                                 setup_ibm_pci = prep_thinkpad_setup_pci;
720                                 ppc_md.power_off = prep_carrera_poweroff;
721                                 ppc_md.show_cpuinfo = prep_thinkpad_cpuinfo;
722                                 break;
723                         default:
724                                 printk(" -- unknown! Assuming Carolina");
725                         case PREP_IBM_CAROLINA_IDE_0:
726                         case PREP_IBM_CAROLINA_IDE_1:
727                         case PREP_IBM_CAROLINA_IDE_2:
728                         case PREP_IBM_CAROLINA_IDE_3:
729                                 is_ide = 1;
730                         case PREP_IBM_CAROLINA_SCSI_0:
731                         case PREP_IBM_CAROLINA_SCSI_1:
732                         case PREP_IBM_CAROLINA_SCSI_2:
733                         case PREP_IBM_CAROLINA_SCSI_3:
734                                 prep_carolina_enable_l2();
735                                 setup_ibm_pci = prep_carolina_setup_pci;
736                                 ppc_md.power_off = prep_sig750_poweroff;
737                                 ppc_md.show_cpuinfo = prep_carolina_cpuinfo;
738                                 break;
739                         case PREP_IBM_TIGER1_133:
740                         case PREP_IBM_TIGER1_166:
741                         case PREP_IBM_TIGER1_180:
742                         case PREP_IBM_TIGER1_xxx:
743                         case PREP_IBM_TIGER1_333:
744                                 prep_carolina_enable_l2();
745                                 setup_ibm_pci = prep_tiger1_setup_pci;
746                                 ppc_md.power_off = prep_sig750_poweroff;
747                                 ppc_md.show_cpuinfo = prep_tiger1_cpuinfo;
748                                 ppc_md.progress = prep_tiger1_progress;
749                                 break;
750                 }
751                 printk("\n");
752
753                 /* default root device */
754                 if (is_ide)
755                         ROOT_DEV = MKDEV(IDE0_MAJOR, 3);
756                 else
757                         ROOT_DEV = MKDEV(SCSI_DISK0_MAJOR, 3);
758
759                 break;
760         case _PREP_Motorola:
761                 prep_gen_enable_l2();
762                 ppc_md.power_off = prep_halt;
763                 ppc_md.show_cpuinfo = prep_mot_cpuinfo;
764
765 #ifdef CONFIG_BLK_DEV_INITRD
766                 if (initrd_start)
767                         ROOT_DEV = Root_RAM0;
768                 else
769 #endif
770 #ifdef CONFIG_ROOT_NFS
771                         ROOT_DEV = Root_NFS;
772 #else
773                         ROOT_DEV = Root_SDA2;
774 #endif
775                 break;
776         }
777
778         /* Read in NVRAM data */
779         init_prep_nvram();
780
781         /* if no bootargs, look in NVRAM */
782         if ( cmd_line[0] == '\0' ) {
783                 char *bootargs;
784                  bootargs = prep_nvram_get_var("bootargs");
785                  if (bootargs != NULL) {
786                          strcpy(cmd_line, bootargs);
787                          /* again.. */
788                          strcpy(saved_command_line, cmd_line);
789                 }
790         }
791
792 #ifdef CONFIG_SOUND_CS4232
793         prep_init_sound();
794 #endif /* CONFIG_SOUND_CS4232 */
795
796         prep_init_vesa();
797
798         switch (_prep_type) {
799         case _PREP_Motorola:
800                 raven_init();
801                 break;
802         case _PREP_IBM:
803                 ibm_prep_init();
804                 break;
805         }
806
807 #ifdef CONFIG_VGA_CONSOLE
808         /* vgacon.c needs to know where we mapped IO memory in io_block_mapping() */
809         vgacon_remap_base = 0xf0000000;
810         conswitchp = &vga_con;
811 #elif defined(CONFIG_DUMMY_CONSOLE)
812         conswitchp = &dummy_con;
813 #endif
814 }
815
816 /*
817  * First, see if we can get this information from the residual data.
818  * This is important on some IBM PReP systems.  If we cannot, we let the
819  * TODC code handle doing this.
820  */
821 static void __init
822 prep_calibrate_decr(void)
823 {
824 #ifdef CONFIG_PREP_RESIDUAL
825         unsigned long freq, divisor = 4;
826
827         if ( res->VitalProductData.ProcessorBusHz ) {
828                 freq = res->VitalProductData.ProcessorBusHz;
829                 printk("time_init: decrementer frequency = %lu.%.6lu MHz\n",
830                                 (freq/divisor)/1000000,
831                                 (freq/divisor)%1000000);
832                 tb_to_us = mulhwu_scale_factor(freq/divisor, 1000000);
833                 tb_ticks_per_jiffy = freq / HZ / divisor;
834         } else
835 #endif
836                 todc_calibrate_decr();
837 }
838
839 static unsigned int __prep
840 prep_irq_canonicalize(u_int irq)
841 {
842         if (irq == 2)
843         {
844                 return 9;
845         }
846         else
847         {
848                 return irq;
849         }
850 }
851
852 static void __init
853 prep_init_IRQ(void)
854 {
855         int i;
856         unsigned int pci_viddid, pci_did;
857
858         if (OpenPIC_Addr != NULL) {
859                 openpic_init(NUM_8259_INTERRUPTS);
860                 /* We have a cascade on OpenPIC IRQ 0, Linux IRQ 16 */
861                 openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
862                                        i8259_irq);
863         }
864         for ( i = 0 ; i < NUM_8259_INTERRUPTS ; i++ )
865                 irq_desc[i].handler = &i8259_pic;
866         /* If we have a Raven PCI bridge or a Hawk PCI bridge / Memory
867          * controller, we poll (as they have a different int-ack address). */
868         early_read_config_dword(NULL, 0, 0, PCI_VENDOR_ID, &pci_viddid);
869         pci_did = (pci_viddid & 0xffff0000) >> 16;
870         if (((pci_viddid & 0xffff) == PCI_VENDOR_ID_MOTOROLA)
871                         && ((pci_did == PCI_DEVICE_ID_MOTOROLA_RAVEN)
872                                 || (pci_did == PCI_DEVICE_ID_MOTOROLA_HAWK)))
873                 i8259_init(0);
874         else
875                 /* PCI interrupt ack address given in section 6.1.8 of the
876                  * PReP specification. */
877                 i8259_init(MPC10X_MAPA_PCI_INTACK_ADDR);
878 }
879
880 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
881 /*
882  * IDE stuff.
883  */
884 static int __prep
885 prep_ide_default_irq(unsigned long base)
886 {
887         switch (base) {
888                 case 0x1f0: return 13;
889                 case 0x170: return 13;
890                 case 0x1e8: return 11;
891                 case 0x168: return 10;
892                 case 0xfff0: return 14;         /* MCP(N)750 ide0 */
893                 case 0xffe0: return 15;         /* MCP(N)750 ide1 */
894                 default: return 0;
895         }
896 }
897
898 static unsigned long __prep
899 prep_ide_default_io_base(int index)
900 {
901         switch (index) {
902                 case 0: return 0x1f0;
903                 case 1: return 0x170;
904                 case 2: return 0x1e8;
905                 case 3: return 0x168;
906                 default:
907                         return 0;
908         }
909 }
910 #endif
911
912 #ifdef CONFIG_SMP
913 /* PReP (MTX) support */
914 static int __init
915 smp_prep_probe(void)
916 {
917         extern int mot_multi;
918
919         if (mot_multi) {
920                 openpic_request_IPIs();
921                 smp_hw_index[1] = 1;
922                 return 2;
923         }
924
925         return 1;
926 }
927
928 static void __init
929 smp_prep_kick_cpu(int nr)
930 {
931         *(unsigned long *)KERNELBASE = nr;
932         asm volatile("dcbf 0,%0"::"r"(KERNELBASE):"memory");
933         printk("CPU1 released, waiting\n");
934 }
935
936 static void __init
937 smp_prep_setup_cpu(int cpu_nr)
938 {
939         if (OpenPIC_Addr)
940                 do_openpic_setup_cpu();
941 }
942
943 static struct smp_ops_t prep_smp_ops __prepdata = {
944         smp_openpic_message_pass,
945         smp_prep_probe,
946         smp_prep_kick_cpu,
947         smp_prep_setup_cpu,
948         .give_timebase = smp_generic_give_timebase,
949         .take_timebase = smp_generic_take_timebase,
950 };
951 #endif /* CONFIG_SMP */
952
953 /*
954  * Setup the bat mappings we're going to load that cover
955  * the io areas.  RAM was mapped by mapin_ram().
956  * -- Cort
957  */
958 static void __init
959 prep_map_io(void)
960 {
961         io_block_mapping(0x80000000, PREP_ISA_IO_BASE, 0x10000000, _PAGE_IO);
962         io_block_mapping(0xf0000000, PREP_ISA_MEM_BASE, 0x08000000, _PAGE_IO);
963 }
964
965 static int __init
966 prep_request_io(void)
967 {
968         if (_machine == _MACH_prep) {
969 #ifdef CONFIG_NVRAM
970                 request_region(PREP_NVRAM_AS0, 0x8, "nvram");
971 #endif
972                 request_region(0x00,0x20,"dma1");
973                 request_region(0x40,0x20,"timer");
974                 request_region(0x80,0x10,"dma page reg");
975                 request_region(0xc0,0x20,"dma2");
976         }
977
978         return 0;
979 }
980
981 device_initcall(prep_request_io);
982
983 void __init
984 prep_init(unsigned long r3, unsigned long r4, unsigned long r5,
985                 unsigned long r6, unsigned long r7)
986 {
987 #ifdef CONFIG_PREP_RESIDUAL
988         /* make a copy of residual data */
989         if ( r3 ) {
990                 memcpy((void *)res,(void *)(r3+KERNELBASE),
991                          sizeof(RESIDUAL));
992         }
993 #endif
994
995         isa_io_base = PREP_ISA_IO_BASE;
996         isa_mem_base = PREP_ISA_MEM_BASE;
997         pci_dram_offset = PREP_PCI_DRAM_OFFSET;
998         ISA_DMA_THRESHOLD = 0x00ffffff;
999         DMA_MODE_READ = 0x44;
1000         DMA_MODE_WRITE = 0x48;
1001
1002         /* figure out what kind of prep workstation we are */
1003 #ifdef CONFIG_PREP_RESIDUAL
1004         if ( res->ResidualLength != 0 ) {
1005                 if ( !strncmp(res->VitalProductData.PrintableModel,"IBM",3) )
1006                         _prep_type = _PREP_IBM;
1007                 else
1008                         _prep_type = _PREP_Motorola;
1009         } else /* assume motorola if no residual (netboot?) */
1010 #endif
1011         {
1012                 _prep_type = _PREP_Motorola;
1013         }
1014
1015         ppc_md.setup_arch     = prep_setup_arch;
1016         ppc_md.show_percpuinfo = prep_show_percpuinfo;
1017         ppc_md.show_cpuinfo   = NULL; /* set in prep_setup_arch() */
1018         ppc_md.irq_canonicalize = prep_irq_canonicalize;
1019         ppc_md.init_IRQ       = prep_init_IRQ;
1020         /* this gets changed later on if we have an OpenPIC -- Cort */
1021         ppc_md.get_irq        = i8259_irq;
1022
1023         ppc_md.restart        = prep_restart;
1024         ppc_md.power_off      = NULL; /* set in prep_setup_arch() */
1025         ppc_md.halt           = prep_halt;
1026
1027         ppc_md.nvram_read_val = prep_nvram_read_val;
1028         ppc_md.nvram_write_val = prep_nvram_write_val;
1029
1030         ppc_md.time_init      = todc_time_init;
1031         if (_prep_type == _PREP_IBM) {
1032                 ppc_md.rtc_read_val = todc_mc146818_read_val;
1033                 ppc_md.rtc_write_val = todc_mc146818_write_val;
1034                 TODC_INIT(TODC_TYPE_MC146818, RTC_PORT(0), NULL, RTC_PORT(1),
1035                                 8);
1036         } else {
1037                 TODC_INIT(TODC_TYPE_MK48T59, PREP_NVRAM_AS0, PREP_NVRAM_AS1,
1038                                 PREP_NVRAM_DATA, 8);
1039         }
1040
1041         ppc_md.calibrate_decr = prep_calibrate_decr;
1042         ppc_md.set_rtc_time   = todc_set_rtc_time;
1043         ppc_md.get_rtc_time   = todc_get_rtc_time;
1044
1045         ppc_md.setup_io_mappings = prep_map_io;
1046
1047 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
1048         ppc_ide_md.default_irq = prep_ide_default_irq;
1049         ppc_ide_md.default_io_base = prep_ide_default_io_base;
1050 #endif
1051
1052 #ifdef CONFIG_SMP
1053         ppc_md.smp_ops           = &prep_smp_ops;
1054 #endif /* CONFIG_SMP */
1055 }