fix to allow usb modules to compile
[linux-2.4.21-pre4.git] / arch / ppc / platforms / apus_setup.c
1 /*
2  * BK Id: SCCS/s.apus_setup.c 1.42 10/09/02 10:47:02 paulus
3  */
4 /*
5  *  arch/ppc/platforms/apus_setup.c
6  *
7  *  Copyright (C) 1998, 1999  Jesper Skov
8  *
9  *  Basically what is needed to replace functionality found in
10  *  arch/m68k allowing Amiga drivers to work under APUS.
11  *  Bits of code and/or ideas from arch/m68k and arch/ppc files.
12  *
13  * TODO:
14  *  This file needs a *really* good cleanup. Restructure and optimize.
15  *  Make sure it can be compiled for non-APUS configs. Begin to move
16  *  Amiga specific stuff into mach/amiga.
17  */
18
19 #include <linux/config.h>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/init.h>
23 #include <linux/blk.h>
24 #include <linux/seq_file.h>
25
26 /* Needs INITSERIAL call in head.S! */
27 #undef APUS_DEBUG
28
29 #include <asm/bootinfo.h>
30 #include <asm/setup.h>
31 #include <asm/amigahw.h>
32 #include <asm/amigaints.h>
33 #include <asm/amigappc.h>
34 #include <asm/pgtable.h>
35 #include <asm/dma.h>
36 #include <asm/machdep.h>
37 #include <asm/hardirq.h>
38 #include <asm/keyboard.h>
39 #include <asm/time.h>
40
41 unsigned long m68k_machtype;
42 char debug_device[6] = "";
43
44 extern void amiga_init_IRQ(void);
45
46 extern int amiga_kbd_translate(unsigned char keycode, unsigned char *keycodep, char raw_mode);
47 extern char amiga_sysrq_xlate[128];
48
49 extern void apus_setup_pci_ptrs(void);
50
51 void (*mach_sched_init) (void (*handler)(int, void *, struct pt_regs *)) __initdata = NULL;
52 /* machine dependent keyboard functions */
53 int (*mach_keyb_init) (void) __initdata = NULL;
54 int (*mach_kbdrate) (struct kbd_repeat *) = NULL;
55 void (*mach_kbd_leds) (unsigned int) = NULL;
56 /* machine dependent irq functions */
57 void (*mach_init_IRQ) (void) __initdata = NULL;
58 void (*(*mach_default_handler)[]) (int, void *, struct pt_regs *) = NULL;
59 void (*mach_get_model) (char *model) = NULL;
60 int (*mach_get_hardware_list) (char *buffer) = NULL;
61 int (*mach_get_irq_list) (char *) = NULL;
62 void (*mach_process_int) (int, struct pt_regs *) = NULL;
63 /* machine dependent timer functions */
64 unsigned long (*mach_gettimeoffset) (void);
65 void (*mach_gettod) (int*, int*, int*, int*, int*, int*);
66 int (*mach_hwclk) (int, struct hwclk_time*) = NULL;
67 int (*mach_set_clock_mmss) (unsigned long) = NULL;
68 void (*mach_reset)( void );
69 long mach_max_dma_address = 0x00ffffff; /* default set to the lower 16MB */
70 #if defined(CONFIG_AMIGA_FLOPPY)
71 void (*mach_floppy_setup) (char *, int *) __initdata = NULL;
72 #endif
73 #ifdef CONFIG_HEARTBEAT
74 void (*mach_heartbeat) (int) = NULL;
75 extern void apus_heartbeat(void);
76 #endif
77
78 extern unsigned long amiga_model;
79 extern unsigned decrementer_count;/* count value for 1e6/HZ microseconds */
80 extern unsigned count_period_num; /* 1 decrementer count equals */
81 extern unsigned count_period_den; /* count_period_num / count_period_den us */
82
83 int num_memory = 0;
84 struct mem_info memory[NUM_MEMINFO];/* memory description */
85 /* FIXME: Duplicate memory data to avoid conflicts with m68k shared code. */
86 int m68k_realnum_memory = 0;
87 struct mem_info m68k_memory[NUM_MEMINFO];/* memory description */
88
89 struct mem_info ramdisk;
90
91 extern void amiga_floppy_setup(char *, int *);
92 extern void config_amiga(void);
93
94 static int __60nsram = 0;
95
96 /* for cpuinfo */
97 static int __bus_speed = 0;
98 static int __speed_test_failed = 0;
99
100 /********************************************** COMPILE PROTECTION */
101 /* Provide some stubs that links to Amiga specific functions.
102  * This allows CONFIG_APUS to be removed from generic PPC files while
103  * preventing link errors for other PPC targets.
104  */
105 unsigned long apus_get_rtc_time(void)
106 {
107 #ifdef CONFIG_APUS
108         extern unsigned long m68k_get_rtc_time(void);
109
110         return m68k_get_rtc_time ();
111 #else
112         return 0;
113 #endif
114 }
115
116 int apus_set_rtc_time(unsigned long nowtime)
117 {
118 #ifdef CONFIG_APUS
119         extern int m68k_set_rtc_time(unsigned long nowtime);
120
121         return m68k_set_rtc_time (nowtime);
122 #else
123         return 0;
124 #endif
125 }
126
127 /*********************************************************** SETUP */
128 /* From arch/m68k/kernel/setup.c. */
129 void __init apus_setup_arch(void)
130 {
131 #ifdef CONFIG_APUS
132         extern char cmd_line[];
133         int i;
134         char *p, *q;
135
136         /* Let m68k-shared code know it should do the Amiga thing. */
137         m68k_machtype = MACH_AMIGA;
138
139         /* Parse the command line for arch-specific options.
140          * For the m68k, this is currently only "debug=xxx" to enable printing
141          * certain kernel messages to some machine-specific device.  */
142         for( p = cmd_line; p && *p; ) {
143             i = 0;
144             if (!strncmp( p, "debug=", 6 )) {
145                     strncpy( debug_device, p+6, sizeof(debug_device)-1 );
146                     debug_device[sizeof(debug_device)-1] = 0;
147                     if ((q = strchr( debug_device, ' ' ))) *q = 0;
148                     i = 1;
149             } else if (!strncmp( p, "60nsram", 7 )) {
150                     APUS_WRITE (APUS_REG_WAITSTATE,
151                                 REGWAITSTATE_SETRESET
152                                 |REGWAITSTATE_PPCR
153                                 |REGWAITSTATE_PPCW);
154                     __60nsram = 1;
155                     i = 1;
156             }
157
158             if (i) {
159                 /* option processed, delete it */
160                 if ((q = strchr( p, ' ' )))
161                     strcpy( p, q+1 );
162                 else
163                     *p = 0;
164             } else {
165                 if ((p = strchr( p, ' ' ))) ++p;
166             }
167         }
168
169         config_amiga();
170
171 #if 0 /* Enable for logging - also include logging.o in Makefile rule */
172         {
173 #define LOG_SIZE 4096
174                 void* base;
175
176                 /* Throw away some memory - the P5 firmare stomps on top
177                  * of CHIP memory during bootup.
178                  */
179                 amiga_chip_alloc(0x1000);
180
181                 base = amiga_chip_alloc(LOG_SIZE+sizeof(klog_data_t));
182                 LOG_INIT(base, base+sizeof(klog_data_t), LOG_SIZE);
183         }
184 #endif
185 #endif
186 }
187
188 int
189 apus_show_cpuinfo(struct seq_file *m)
190 {
191         extern int __map_without_bats;
192         extern unsigned long powerup_PCI_present;
193
194         seq_printf(m, "machine\t\t: Amiga\n");
195         seq_printf(m, "bus speed\t: %d%s", __bus_speed,
196                    (__speed_test_failed) ? " [failed]\n" : "\n");
197         seq_printf(m, "using BATs\t: %s\n",
198                    (__map_without_bats) ? "No" : "Yes");
199         seq_printf(m, "ram speed\t: %dns\n", (__60nsram) ? 60 : 70);
200         seq_printf(m, "PCI bridge\t: %s\n",
201                    (powerup_PCI_present) ? "Yes" : "No");
202         return 0;
203 }
204
205 static void get_current_tb(unsigned long long *time)
206 {
207         __asm __volatile ("1:mftbu 4      \n\t"
208                           "  mftb  5      \n\t"
209                           "  mftbu 6      \n\t"
210                           "  cmpw  4,6    \n\t"
211                           "  bne   1b     \n\t"
212                           "  stw   4,0(%0)\n\t"
213                           "  stw   5,4(%0)\n\t"
214                           :
215                           : "r" (time)
216                           : "r4", "r5", "r6");
217 }
218
219
220 void apus_calibrate_decr(void)
221 {
222 #ifdef CONFIG_APUS
223         unsigned long freq;
224
225         /* This algorithm for determining the bus speed was
226            contributed by Ralph Schmidt. */
227         unsigned long long start, stop;
228         int bus_speed;
229         int speed_test_failed = 0;
230
231         {
232                 unsigned long loop = amiga_eclock / 10;
233
234                 get_current_tb (&start);
235                 while (loop--) {
236                         unsigned char tmp;
237
238                         tmp = ciaa.pra;
239                 }
240                 get_current_tb (&stop);
241         }
242
243         bus_speed = (((unsigned long)(stop-start))*10*4) / 1000000;
244         if (AMI_1200 == amiga_model)
245                 bus_speed /= 2;
246
247         if ((bus_speed >= 47) && (bus_speed < 53)) {
248                 bus_speed = 50;
249                 freq = 12500000;
250         } else if ((bus_speed >= 57) && (bus_speed < 63)) {
251                 bus_speed = 60;
252                 freq = 15000000;
253         } else if ((bus_speed >= 63) && (bus_speed < 69)) {
254                 bus_speed = 67;
255                 freq = 16666667;
256         } else {
257                 printk ("APUS: Unable to determine bus speed (%d). "
258                         "Defaulting to 50MHz", bus_speed);
259                 bus_speed = 50;
260                 freq = 12500000;
261                 speed_test_failed = 1;
262         }
263
264         /* Ease diagnostics... */
265         {
266                 extern int __map_without_bats;
267                 extern unsigned long powerup_PCI_present;
268
269                 printk ("APUS: BATs=%d, BUS=%dMHz",
270                         (__map_without_bats) ? 0 : 1,
271                         bus_speed);
272                 if (speed_test_failed)
273                         printk ("[FAILED - please report]");
274
275                 printk (", RAM=%dns, PCI bridge=%d\n",
276                         (__60nsram) ? 60 : 70,
277                         (powerup_PCI_present) ? 1 : 0);
278
279                 /* print a bit more if asked politely... */
280                 if (!(ciaa.pra & 0x40)){
281                         extern unsigned int bat_addrs[4][3];
282                         int b;
283                         for (b = 0; b < 4; ++b) {
284                                 printk ("APUS: BAT%d ", b);
285                                 printk ("%08x-%08x -> %08x\n",
286                                         bat_addrs[b][0],
287                                         bat_addrs[b][1],
288                                         bat_addrs[b][2]);
289                         }
290                 }
291
292         }
293
294         printk("time_init: decrementer frequency = %lu.%.6lu MHz\n",
295                freq/1000000, freq%1000000);
296         tb_ticks_per_jiffy = freq / HZ;
297         tb_to_us = mulhwu_scale_factor(freq, 1000000);
298
299         __bus_speed = bus_speed;
300         __speed_test_failed = speed_test_failed;
301 #endif
302 }
303
304 void arch_gettod(int *year, int *mon, int *day, int *hour,
305                  int *min, int *sec)
306 {
307 #ifdef CONFIG_APUS
308         if (mach_gettod)
309                 mach_gettod(year, mon, day, hour, min, sec);
310         else
311                 *year = *mon = *day = *hour = *min = *sec = 0;
312 #endif
313 }
314
315 /* for "kbd-reset" cmdline param */
316 __init
317 void kbd_reset_setup(char *str, int *ints)
318 {
319 }
320
321 /*********************************************************** FLOPPY */
322 #if defined(CONFIG_AMIGA_FLOPPY)
323 __init
324 void floppy_setup(char *str, int *ints)
325 {
326         if (mach_floppy_setup)
327                 mach_floppy_setup (str, ints);
328 }
329 #endif
330
331 /*********************************************************** MEMORY */
332 #define KMAP_MAX 32
333 unsigned long kmap_chunks[KMAP_MAX*3];
334 int kmap_chunk_count = 0;
335
336 /* From pgtable.h */
337 static __inline__ pte_t *my_find_pte(struct mm_struct *mm,unsigned long va)
338 {
339         pgd_t *dir = 0;
340         pmd_t *pmd = 0;
341         pte_t *pte = 0;
342
343         va &= PAGE_MASK;
344
345         dir = pgd_offset( mm, va );
346         if (dir)
347         {
348                 pmd = pmd_offset(dir, va & PAGE_MASK);
349                 if (pmd && pmd_present(*pmd))
350                 {
351                         pte = pte_offset(pmd, va);
352                 }
353         }
354         return pte;
355 }
356
357
358 /* Again simulating an m68k/mm/kmap.c function. */
359 void kernel_set_cachemode( unsigned long address, unsigned long size,
360                            unsigned int cmode )
361 {
362         unsigned long mask, flags;
363
364         switch (cmode)
365         {
366         case IOMAP_FULL_CACHING:
367                 mask = ~(_PAGE_NO_CACHE | _PAGE_GUARDED);
368                 flags = 0;
369                 break;
370         case IOMAP_NOCACHE_SER:
371                 mask = ~0;
372                 flags = (_PAGE_NO_CACHE | _PAGE_GUARDED);
373                 break;
374         default:
375                 panic ("kernel_set_cachemode() doesn't support mode %d\n",
376                        cmode);
377                 break;
378         }
379
380         size /= PAGE_SIZE;
381         address &= PAGE_MASK;
382         while (size--)
383         {
384                 pte_t *pte;
385
386                 pte = my_find_pte(&init_mm, address);
387                 if ( !pte )
388                 {
389                         printk("pte NULL in kernel_set_cachemode()\n");
390                         return;
391                 }
392
393                 pte_val (*pte) &= mask;
394                 pte_val (*pte) |= flags;
395                 flush_tlb_page(find_vma(&init_mm,address),address);
396
397                 address += PAGE_SIZE;
398         }
399 }
400
401 unsigned long mm_ptov (unsigned long paddr)
402 {
403         unsigned long ret;
404         if (paddr < 16*1024*1024)
405                 ret = ZTWO_VADDR(paddr);
406         else {
407                 int i;
408
409                 for (i = 0; i < kmap_chunk_count;){
410                         unsigned long phys = kmap_chunks[i++];
411                         unsigned long size = kmap_chunks[i++];
412                         unsigned long virt = kmap_chunks[i++];
413                         if (paddr >= phys
414                             && paddr < (phys + size)){
415                                 ret = virt + paddr - phys;
416                                 goto exit;
417                         }
418                 }
419
420                 ret = (unsigned long) __va(paddr);
421         }
422 exit:
423 #ifdef DEBUGPV
424         printk ("PTOV(%lx)=%lx\n", paddr, ret);
425 #endif
426         return ret;
427 }
428
429 int mm_end_of_chunk (unsigned long addr, int len)
430 {
431         if (memory[0].addr + memory[0].size == addr + len)
432                 return 1;
433         return 0;
434 }
435
436 /*********************************************************** CACHE */
437
438 #define L1_CACHE_BYTES 32
439 #define MAX_CACHE_SIZE 8192
440 void cache_push(__u32 addr, int length)
441 {
442         addr = mm_ptov(addr);
443
444         if (MAX_CACHE_SIZE < length)
445                 length = MAX_CACHE_SIZE;
446
447         while(length > 0){
448                 __asm ("dcbf 0,%0\n\t"
449                        : : "r" (addr));
450                 addr += L1_CACHE_BYTES;
451                 length -= L1_CACHE_BYTES;
452         }
453         /* Also flush trailing block */
454         __asm ("dcbf 0,%0\n\t"
455                "sync \n\t"
456                : : "r" (addr));
457 }
458
459 void cache_clear(__u32 addr, int length)
460 {
461         if (MAX_CACHE_SIZE < length)
462                 length = MAX_CACHE_SIZE;
463
464         addr = mm_ptov(addr);
465
466         __asm ("dcbf 0,%0\n\t"
467                "sync \n\t"
468                "icbi 0,%0 \n\t"
469                "isync \n\t"
470                : : "r" (addr));
471
472         addr += L1_CACHE_BYTES;
473         length -= L1_CACHE_BYTES;
474
475         while(length > 0){
476                 __asm ("dcbf 0,%0\n\t"
477                        "sync \n\t"
478                        "icbi 0,%0 \n\t"
479                        "isync \n\t"
480                        : : "r" (addr));
481                 addr += L1_CACHE_BYTES;
482                 length -= L1_CACHE_BYTES;
483         }
484
485         __asm ("dcbf 0,%0\n\t"
486                "sync \n\t"
487                "icbi 0,%0 \n\t"
488                "isync \n\t"
489                : : "r" (addr));
490 }
491
492 /****************************************************** from setup.c */
493 void
494 apus_restart(char *cmd)
495 {
496         cli();
497
498         APUS_WRITE(APUS_REG_LOCK,
499                    REGLOCK_BLACKMAGICK1|REGLOCK_BLACKMAGICK2);
500         APUS_WRITE(APUS_REG_LOCK,
501                    REGLOCK_BLACKMAGICK1|REGLOCK_BLACKMAGICK3);
502         APUS_WRITE(APUS_REG_LOCK,
503                    REGLOCK_BLACKMAGICK2|REGLOCK_BLACKMAGICK3);
504         APUS_WRITE(APUS_REG_SHADOW, REGSHADOW_SELFRESET);
505         APUS_WRITE(APUS_REG_RESET, REGRESET_AMIGARESET);
506         for(;;);
507 }
508
509 void
510 apus_power_off(void)
511 {
512         for (;;);
513 }
514
515 void
516 apus_halt(void)
517 {
518    apus_restart(NULL);
519 }
520
521 /****************************************************** IRQ stuff */
522
523 static unsigned char last_ipl[8];
524
525 int apus_get_irq(struct pt_regs* regs)
526 {
527         unsigned char ipl_emu, mask;
528         unsigned int level;
529
530         APUS_READ(APUS_IPL_EMU, ipl_emu);
531         level = (ipl_emu >> 3) & IPLEMU_IPLMASK;
532         mask = IPLEMU_SETRESET|IPLEMU_DISABLEINT|level;
533         level ^= 7;
534
535         /* Save previous IPL value */
536         if (last_ipl[level])
537                 return -2;
538         last_ipl[level] = ipl_emu;
539
540         /* Set to current IPL value */
541         APUS_WRITE(APUS_IPL_EMU, mask);
542         APUS_WRITE(APUS_IPL_EMU, IPLEMU_DISABLEINT|level);
543
544
545 #ifdef __INTERRUPT_DEBUG
546         printk("<%d:%d>", level, ~ipl_emu & IPLEMU_IPLMASK);
547 #endif
548         return level + IRQ_AMIGA_AUTO;
549 }
550
551 void apus_end_irq(unsigned int irq)
552 {
553         unsigned char ipl_emu;
554         unsigned int level = irq - IRQ_AMIGA_AUTO;
555 #ifdef __INTERRUPT_DEBUG
556         printk("{%d}", ~last_ipl[level] & IPLEMU_IPLMASK);
557 #endif
558         /* Restore IPL to the previous value */
559         ipl_emu = last_ipl[level] & IPLEMU_IPLMASK;
560         APUS_WRITE(APUS_IPL_EMU, IPLEMU_SETRESET|IPLEMU_DISABLEINT|ipl_emu);
561         last_ipl[level] = 0;
562         ipl_emu ^= 7;
563         APUS_WRITE(APUS_IPL_EMU, IPLEMU_DISABLEINT|ipl_emu);
564 }
565
566 /****************************************************** keyboard */
567 static int apus_kbd_setkeycode(unsigned int scancode, unsigned int keycode)
568 {
569         return -EOPNOTSUPP;
570 }
571
572 static int apus_kbd_getkeycode(unsigned int scancode)
573 {
574         return scancode > 127 ? -EINVAL : scancode;
575 }
576
577 static char apus_kbd_unexpected_up(unsigned char keycode)
578 {
579         return 0200;
580 }
581
582 static void apus_kbd_init_hw(void)
583 {
584 #ifdef CONFIG_APUS
585         extern int amiga_keyb_init(void);
586
587         amiga_keyb_init();
588 #endif
589 }
590
591
592 /****************************************************** debugging */
593
594 /* some serial hardware definitions */
595 #define SDR_OVRUN   (1<<15)
596 #define SDR_RBF     (1<<14)
597 #define SDR_TBE     (1<<13)
598 #define SDR_TSRE    (1<<12)
599
600 #define AC_SETCLR   (1<<15)
601 #define AC_UARTBRK  (1<<11)
602
603 #define SER_DTR     (1<<7)
604 #define SER_RTS     (1<<6)
605 #define SER_DCD     (1<<5)
606 #define SER_CTS     (1<<4)
607 #define SER_DSR     (1<<3)
608
609 static __inline__ void ser_RTSon(void)
610 {
611     ciab.pra &= ~SER_RTS; /* active low */
612 }
613
614 int __debug_ser_out( unsigned char c )
615 {
616         custom.serdat = c | 0x100;
617         mb();
618         while (!(custom.serdatr & 0x2000))
619                 barrier();
620         return 1;
621 }
622
623 unsigned char __debug_ser_in( void )
624 {
625         unsigned char c;
626
627         /* XXX: is that ok?? derived from amiga_ser.c... */
628         while( !(custom.intreqr & IF_RBF) )
629                 barrier();
630         c = custom.serdatr;
631         /* clear the interrupt, so that another character can be read */
632         custom.intreq = IF_RBF;
633         return c;
634 }
635
636 int __debug_serinit( void )
637 {
638         unsigned long flags;
639
640         save_flags (flags);
641         cli();
642
643         /* turn off Rx and Tx interrupts */
644         custom.intena = IF_RBF | IF_TBE;
645
646         /* clear any pending interrupt */
647         custom.intreq = IF_RBF | IF_TBE;
648
649         restore_flags (flags);
650
651         /*
652          * set the appropriate directions for the modem control flags,
653          * and clear RTS and DTR
654          */
655         ciab.ddra |= (SER_DTR | SER_RTS);   /* outputs */
656         ciab.ddra &= ~(SER_DCD | SER_CTS | SER_DSR);  /* inputs */
657
658 #ifdef CONFIG_KGDB
659         /* turn Rx interrupts on for GDB */
660         custom.intena = IF_SETCLR | IF_RBF;
661         ser_RTSon();
662 #endif
663
664         return 0;
665 }
666
667 void __debug_print_hex(unsigned long x)
668 {
669         int i;
670         char hexchars[] = "0123456789ABCDEF";
671
672         for (i = 0; i < 8; i++) {
673                 __debug_ser_out(hexchars[(x >> 28) & 15]);
674                 x <<= 4;
675         }
676         __debug_ser_out('\n');
677         __debug_ser_out('\r');
678 }
679
680 void __debug_print_string(char* s)
681 {
682         unsigned char c;
683         while((c = *s++))
684                 __debug_ser_out(c);
685         __debug_ser_out('\n');
686         __debug_ser_out('\r');
687 }
688
689 static void apus_progress(char *s, unsigned short value)
690 {
691         __debug_print_string(s);
692 }
693
694 /****************************************************** init */
695
696 /* The number of spurious interrupts */
697 volatile unsigned int num_spurious;
698
699 extern struct irqaction amiga_sys_irqaction[AUTO_IRQS];
700
701
702 extern void amiga_enable_irq(unsigned int irq);
703 extern void amiga_disable_irq(unsigned int irq);
704
705 struct hw_interrupt_type amiga_sys_irqctrl = {
706         typename: "Amiga IPL",
707         end: apus_end_irq,
708 };
709
710 struct hw_interrupt_type amiga_irqctrl = {
711         typename: "Amiga    ",
712         enable: amiga_enable_irq,
713         disable: amiga_disable_irq,
714 };
715
716 #define HARDWARE_MAPPED_SIZE (512*1024)
717 unsigned long __init apus_find_end_of_memory(void)
718 {
719         int shadow = 0;
720         unsigned long total;
721
722         /* The memory size reported by ADOS excludes the 512KB
723            reserved for PPC exception registers and possibly 512KB
724            containing a shadow of the ADOS ROM. */
725         {
726                 unsigned long size = memory[0].size;
727
728                 /* If 2MB aligned, size was probably user
729                    specified. We can't tell anything about shadowing
730                    in this case so skip shadow assignment. */
731                 if (0 != (size & 0x1fffff)){
732                         /* Align to 512KB to ensure correct handling
733                            of both memfile and system specified
734                            sizes. */
735                         size = ((size+0x0007ffff) & 0xfff80000);
736                         /* If memory is 1MB aligned, assume
737                            shadowing. */
738                         shadow = !(size & 0x80000);
739                 }
740
741                 /* Add the chunk that ADOS does not see. by aligning
742                    the size to the nearest 2MB limit upwards.  */
743                 memory[0].size = ((size+0x001fffff) & 0xffe00000);
744         }
745
746         ppc_memstart = memory[0].addr;
747         ppc_memoffset = PAGE_OFFSET - PPC_MEMSTART;
748         total = memory[0].size;
749
750         /* Remove the memory chunks that are controlled by special
751            Phase5 hardware. */
752
753         /* Remove the upper 512KB if it contains a shadow of
754            the ADOS ROM. FIXME: It might be possible to
755            disable this shadow HW. Check the booter
756            (ppc_boot.c) */
757         if (shadow)
758                 total -= HARDWARE_MAPPED_SIZE;
759
760         /* Remove the upper 512KB where the PPC exception
761            vectors are mapped. */
762         total -= HARDWARE_MAPPED_SIZE;
763
764         /* Linux/APUS only handles one block of memory -- the one on
765            the PowerUP board. Other system memory is horrible slow in
766            comparison. The user can use other memory for swapping
767            using the z2ram device. */
768         return total;
769 }
770
771 static void __init
772 apus_map_io(void)
773 {
774         /* Map PPC exception vectors. */
775         io_block_mapping(0xfff00000, 0xfff00000, 0x00020000, _PAGE_KERNEL);
776         /* Map chip and ZorroII memory */
777         io_block_mapping(zTwoBase,   0x00000000, 0x01000000, _PAGE_IO);
778 }
779
780 __init
781 void apus_init_IRQ(void)
782 {
783         struct irqaction *action;
784         int i;
785
786 #ifdef CONFIG_PCI
787         apus_setup_pci_ptrs();
788 #endif
789
790         for ( i = 0 ; i < AMI_IRQS; i++ ) {
791                 irq_desc[i].status = IRQ_LEVEL;
792                 if (i < IRQ_AMIGA_AUTO) {
793                         irq_desc[i].handler = &amiga_irqctrl;
794                 } else {
795                         irq_desc[i].handler = &amiga_sys_irqctrl;
796                         action = &amiga_sys_irqaction[i-IRQ_AMIGA_AUTO];
797                         if (action->name)
798                                 setup_irq(i, action);
799                 }
800         }
801
802         amiga_init_IRQ();
803
804 }
805
806 __init
807 void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
808                    unsigned long r6, unsigned long r7)
809 {
810         extern int parse_bootinfo(const struct bi_record *);
811         extern char _end[];
812
813         /* Parse bootinfo. The bootinfo is located right after
814            the kernel bss */
815         parse_bootinfo((const struct bi_record *)&_end);
816 #ifdef CONFIG_BLK_DEV_INITRD
817         /* Take care of initrd if we have one. Use data from
818            bootinfo to avoid the need to initialize PPC
819            registers when kernel is booted via a PPC reset. */
820         if ( ramdisk.addr ) {
821                 initrd_start = (unsigned long) __va(ramdisk.addr);
822                 initrd_end = (unsigned long)
823                         __va(ramdisk.size + ramdisk.addr);
824         }
825 #endif /* CONFIG_BLK_DEV_INITRD */
826
827         ISA_DMA_THRESHOLD = 0x00ffffff;
828
829         ppc_md.setup_arch     = apus_setup_arch;
830         ppc_md.show_cpuinfo   = apus_show_cpuinfo;
831         ppc_md.init_IRQ       = apus_init_IRQ;
832         ppc_md.get_irq        = apus_get_irq;
833
834 #ifdef CONFIG_HEARTBEAT
835         ppc_md.heartbeat      = apus_heartbeat;
836         heartbeat_reset(0)    = 1;              /* assume UP for now */
837         heartbeat_count(0)    = 1;
838 #endif
839 #ifdef APUS_DEBUG
840         __debug_serinit();
841         ppc_md.progress       = apus_progress;
842 #endif
843         ppc_md.init           = NULL;
844
845         ppc_md.restart        = apus_restart;
846         ppc_md.power_off      = apus_power_off;
847         ppc_md.halt           = apus_halt;
848
849         ppc_md.time_init      = NULL;
850         ppc_md.set_rtc_time   = apus_set_rtc_time;
851         ppc_md.get_rtc_time   = apus_get_rtc_time;
852         ppc_md.calibrate_decr = apus_calibrate_decr;
853
854         ppc_md.find_end_of_memory = apus_find_end_of_memory;
855         ppc_md.setup_io_mappings = apus_map_io;
856
857         /* These should not be used for the APUS yet, since it uses
858            the M68K keyboard now. */
859         ppc_md.kbd_setkeycode    = apus_kbd_setkeycode;
860         ppc_md.kbd_getkeycode    = apus_kbd_getkeycode;
861         ppc_md.kbd_translate     = amiga_kbd_translate;
862         ppc_md.kbd_unexpected_up = apus_kbd_unexpected_up;
863         ppc_md.kbd_init_hw       = apus_kbd_init_hw;
864 #ifdef CONFIG_SYSRQ
865         ppc_md.ppc_kbd_sysrq_xlate = amiga_sysrq_xlate;
866         SYSRQ_KEY                = 0xff;
867 #endif
868 }