2 * arch/ppc/platforms/apus_setup.c
4 * Copyright (C) 1998, 1999 Jesper Skov
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.
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.
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>
23 /* Needs INITSERIAL call in head.S! */
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>
33 #include <asm/machdep.h>
34 #include <asm/hardirq.h>
35 #include <asm/keyboard.h>
38 unsigned long m68k_machtype;
39 char debug_device[6] = "";
41 extern void amiga_init_IRQ(void);
43 extern int amiga_kbd_translate(unsigned char keycode, unsigned char *keycodep, char raw_mode);
44 extern char amiga_sysrq_xlate[128];
46 extern void apus_setup_pci_ptrs(void);
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;
70 #ifdef CONFIG_HEARTBEAT
71 void (*mach_heartbeat) (int) = NULL;
72 extern void apus_heartbeat(void);
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 */
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 */
86 struct mem_info ramdisk;
88 extern void amiga_floppy_setup(char *, int *);
89 extern void config_amiga(void);
91 static int __60nsram = 0;
94 static int __bus_speed = 0;
95 static int __speed_test_failed = 0;
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.
102 unsigned long apus_get_rtc_time(void)
105 extern unsigned long m68k_get_rtc_time(void);
107 return m68k_get_rtc_time ();
113 int apus_set_rtc_time(unsigned long nowtime)
116 extern int m68k_set_rtc_time(unsigned long nowtime);
118 return m68k_set_rtc_time (nowtime);
124 /*********************************************************** SETUP */
125 /* From arch/m68k/kernel/setup.c. */
126 void __init apus_setup_arch(void)
129 extern char cmd_line[];
133 /* Let m68k-shared code know it should do the Amiga thing. */
134 m68k_machtype = MACH_AMIGA;
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; ) {
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;
146 } else if (!strncmp( p, "60nsram", 7 )) {
147 APUS_WRITE (APUS_REG_WAITSTATE,
148 REGWAITSTATE_SETRESET
156 /* option processed, delete it */
157 if ((q = strchr( p, ' ' )))
162 if ((p = strchr( p, ' ' ))) ++p;
168 #if 0 /* Enable for logging - also include logging.o in Makefile rule */
170 #define LOG_SIZE 4096
173 /* Throw away some memory - the P5 firmare stomps on top
174 * of CHIP memory during bootup.
176 amiga_chip_alloc(0x1000);
178 base = amiga_chip_alloc(LOG_SIZE+sizeof(klog_data_t));
179 LOG_INIT(base, base+sizeof(klog_data_t), LOG_SIZE);
186 apus_show_cpuinfo(struct seq_file *m)
188 extern int __map_without_bats;
189 extern unsigned long powerup_PCI_present;
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");
202 static void get_current_tb(unsigned long long *time)
204 __asm __volatile ("1:mftbu 4 \n\t"
217 void apus_calibrate_decr(void)
222 /* This algorithm for determining the bus speed was
223 contributed by Ralph Schmidt. */
224 unsigned long long start, stop;
226 int speed_test_failed = 0;
229 unsigned long loop = amiga_eclock / 10;
231 get_current_tb (&start);
237 get_current_tb (&stop);
240 bus_speed = (((unsigned long)(stop-start))*10*4) / 1000000;
241 if (AMI_1200 == amiga_model)
244 if ((bus_speed >= 47) && (bus_speed < 53)) {
247 } else if ((bus_speed >= 57) && (bus_speed < 63)) {
250 } else if ((bus_speed >= 63) && (bus_speed < 69)) {
254 printk ("APUS: Unable to determine bus speed (%d). "
255 "Defaulting to 50MHz", bus_speed);
258 speed_test_failed = 1;
261 /* Ease diagnostics... */
263 extern int __map_without_bats;
264 extern unsigned long powerup_PCI_present;
266 printk ("APUS: BATs=%d, BUS=%dMHz",
267 (__map_without_bats) ? 0 : 1,
269 if (speed_test_failed)
270 printk ("[FAILED - please report]");
272 printk (", RAM=%dns, PCI bridge=%d\n",
273 (__60nsram) ? 60 : 70,
274 (powerup_PCI_present) ? 1 : 0);
276 /* print a bit more if asked politely... */
277 if (!(ciaa.pra & 0x40)){
278 extern unsigned int bat_addrs[4][3];
280 for (b = 0; b < 4; ++b) {
281 printk ("APUS: BAT%d ", b);
282 printk ("%08x-%08x -> %08x\n",
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);
296 __bus_speed = bus_speed;
297 __speed_test_failed = speed_test_failed;
301 void arch_gettod(int *year, int *mon, int *day, int *hour,
306 mach_gettod(year, mon, day, hour, min, sec);
308 *year = *mon = *day = *hour = *min = *sec = 0;
312 /* for "kbd-reset" cmdline param */
314 void kbd_reset_setup(char *str, int *ints)
318 /*********************************************************** FLOPPY */
319 #if defined(CONFIG_AMIGA_FLOPPY)
321 void floppy_setup(char *str, int *ints)
323 if (mach_floppy_setup)
324 mach_floppy_setup (str, ints);
328 /*********************************************************** MEMORY */
330 unsigned long kmap_chunks[KMAP_MAX*3];
331 int kmap_chunk_count = 0;
334 static __inline__ pte_t *my_find_pte(struct mm_struct *mm,unsigned long va)
342 dir = pgd_offset( mm, va );
345 pmd = pmd_offset(dir, va & PAGE_MASK);
346 if (pmd && pmd_present(*pmd))
348 pte = pte_offset(pmd, va);
355 /* Again simulating an m68k/mm/kmap.c function. */
356 void kernel_set_cachemode( unsigned long address, unsigned long size,
359 unsigned long mask, flags;
363 case IOMAP_FULL_CACHING:
364 mask = ~(_PAGE_NO_CACHE | _PAGE_GUARDED);
367 case IOMAP_NOCACHE_SER:
369 flags = (_PAGE_NO_CACHE | _PAGE_GUARDED);
372 panic ("kernel_set_cachemode() doesn't support mode %d\n",
378 address &= PAGE_MASK;
383 pte = my_find_pte(&init_mm, address);
386 printk("pte NULL in kernel_set_cachemode()\n");
390 pte_val (*pte) &= mask;
391 pte_val (*pte) |= flags;
392 flush_tlb_page(find_vma(&init_mm,address),address);
394 address += PAGE_SIZE;
398 unsigned long mm_ptov (unsigned long paddr)
401 if (paddr < 16*1024*1024)
402 ret = ZTWO_VADDR(paddr);
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++];
411 && paddr < (phys + size)){
412 ret = virt + paddr - phys;
417 ret = (unsigned long) __va(paddr);
421 printk ("PTOV(%lx)=%lx\n", paddr, ret);
426 int mm_end_of_chunk (unsigned long addr, int len)
428 if (memory[0].addr + memory[0].size == addr + len)
433 /*********************************************************** CACHE */
435 #define L1_CACHE_BYTES 32
436 #define MAX_CACHE_SIZE 8192
437 void cache_push(__u32 addr, int length)
439 addr = mm_ptov(addr);
441 if (MAX_CACHE_SIZE < length)
442 length = MAX_CACHE_SIZE;
445 __asm ("dcbf 0,%0\n\t"
447 addr += L1_CACHE_BYTES;
448 length -= L1_CACHE_BYTES;
450 /* Also flush trailing block */
451 __asm ("dcbf 0,%0\n\t"
456 void cache_clear(__u32 addr, int length)
458 if (MAX_CACHE_SIZE < length)
459 length = MAX_CACHE_SIZE;
461 addr = mm_ptov(addr);
463 __asm ("dcbf 0,%0\n\t"
469 addr += L1_CACHE_BYTES;
470 length -= L1_CACHE_BYTES;
473 __asm ("dcbf 0,%0\n\t"
478 addr += L1_CACHE_BYTES;
479 length -= L1_CACHE_BYTES;
482 __asm ("dcbf 0,%0\n\t"
489 /****************************************************** from setup.c */
491 apus_restart(char *cmd)
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);
518 /****************************************************** IRQ stuff */
520 static unsigned char last_ipl[8];
522 int apus_get_irq(struct pt_regs* regs)
524 unsigned char ipl_emu, mask;
527 APUS_READ(APUS_IPL_EMU, ipl_emu);
528 level = (ipl_emu >> 3) & IPLEMU_IPLMASK;
529 mask = IPLEMU_SETRESET|IPLEMU_DISABLEINT|level;
532 /* Save previous IPL value */
535 last_ipl[level] = ipl_emu;
537 /* Set to current IPL value */
538 APUS_WRITE(APUS_IPL_EMU, mask);
539 APUS_WRITE(APUS_IPL_EMU, IPLEMU_DISABLEINT|level);
542 #ifdef __INTERRUPT_DEBUG
543 printk("<%d:%d>", level, ~ipl_emu & IPLEMU_IPLMASK);
545 return level + IRQ_AMIGA_AUTO;
548 void apus_end_irq(unsigned int irq)
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);
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);
560 APUS_WRITE(APUS_IPL_EMU, IPLEMU_DISABLEINT|ipl_emu);
563 /****************************************************** keyboard */
564 static int apus_kbd_setkeycode(unsigned int scancode, unsigned int keycode)
569 static int apus_kbd_getkeycode(unsigned int scancode)
571 return scancode > 127 ? -EINVAL : scancode;
574 static char apus_kbd_unexpected_up(unsigned char keycode)
579 static void apus_kbd_init_hw(void)
582 extern int amiga_keyb_init(void);
589 /****************************************************** debugging */
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)
597 #define AC_SETCLR (1<<15)
598 #define AC_UARTBRK (1<<11)
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)
606 static __inline__ void ser_RTSon(void)
608 ciab.pra &= ~SER_RTS; /* active low */
611 int __debug_ser_out( unsigned char c )
613 custom.serdat = c | 0x100;
615 while (!(custom.serdatr & 0x2000))
620 unsigned char __debug_ser_in( void )
624 /* XXX: is that ok?? derived from amiga_ser.c... */
625 while( !(custom.intreqr & IF_RBF) )
628 /* clear the interrupt, so that another character can be read */
629 custom.intreq = IF_RBF;
633 int __debug_serinit( void )
640 /* turn off Rx and Tx interrupts */
641 custom.intena = IF_RBF | IF_TBE;
643 /* clear any pending interrupt */
644 custom.intreq = IF_RBF | IF_TBE;
646 restore_flags (flags);
649 * set the appropriate directions for the modem control flags,
650 * and clear RTS and DTR
652 ciab.ddra |= (SER_DTR | SER_RTS); /* outputs */
653 ciab.ddra &= ~(SER_DCD | SER_CTS | SER_DSR); /* inputs */
656 /* turn Rx interrupts on for GDB */
657 custom.intena = IF_SETCLR | IF_RBF;
664 void __debug_print_hex(unsigned long x)
667 char hexchars[] = "0123456789ABCDEF";
669 for (i = 0; i < 8; i++) {
670 __debug_ser_out(hexchars[(x >> 28) & 15]);
673 __debug_ser_out('\n');
674 __debug_ser_out('\r');
677 void __debug_print_string(char* s)
682 __debug_ser_out('\n');
683 __debug_ser_out('\r');
686 static void apus_progress(char *s, unsigned short value)
688 __debug_print_string(s);
691 /****************************************************** init */
693 /* The number of spurious interrupts */
694 volatile unsigned int num_spurious;
696 extern struct irqaction amiga_sys_irqaction[AUTO_IRQS];
699 extern void amiga_enable_irq(unsigned int irq);
700 extern void amiga_disable_irq(unsigned int irq);
702 struct hw_interrupt_type amiga_sys_irqctrl = {
703 typename: "Amiga IPL",
707 struct hw_interrupt_type amiga_irqctrl = {
709 enable: amiga_enable_irq,
710 disable: amiga_disable_irq,
713 #define HARDWARE_MAPPED_SIZE (512*1024)
714 unsigned long __init apus_find_end_of_memory(void)
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. */
723 unsigned long size = memory[0].size;
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
732 size = ((size+0x0007ffff) & 0xfff80000);
733 /* If memory is 1MB aligned, assume
735 shadow = !(size & 0x80000);
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);
743 total = memory[0].size;
745 /* Remove the memory chunks that are controlled by special
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
753 total -= HARDWARE_MAPPED_SIZE;
755 /* Remove the upper 512KB where the PPC exception
756 vectors are mapped. */
757 total -= HARDWARE_MAPPED_SIZE;
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;
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);
777 void apus_init_IRQ(void)
779 struct irqaction *action;
783 apus_setup_pci_ptrs();
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;
791 irq_desc[i].handler = &amiga_sys_irqctrl;
792 action = &amiga_sys_irqaction[i-IRQ_AMIGA_AUTO];
794 setup_irq(i, action);
803 void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
804 unsigned long r6, unsigned long r7)
806 extern int parse_bootinfo(const struct bi_record *);
809 /* Parse bootinfo. The bootinfo is located right after
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);
821 #endif /* CONFIG_BLK_DEV_INITRD */
823 ISA_DMA_THRESHOLD = 0x00ffffff;
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;
830 #ifdef CONFIG_HEARTBEAT
831 ppc_md.heartbeat = apus_heartbeat;
832 heartbeat_reset(0) = 1; /* assume UP for now */
833 heartbeat_count(0) = 1;
837 ppc_md.progress = apus_progress;
841 ppc_md.restart = apus_restart;
842 ppc_md.power_off = apus_power_off;
843 ppc_md.halt = apus_halt;
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;
850 ppc_md.find_end_of_memory = apus_find_end_of_memory;
851 ppc_md.setup_io_mappings = apus_map_io;
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;
861 ppc_md.ppc_kbd_sysrq_xlate = amiga_sysrq_xlate;