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