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