2 * BK Id: SCCS/s.apus_setup.c 1.42 10/09/02 10:47:02 paulus
5 * arch/ppc/platforms/apus_setup.c
7 * Copyright (C) 1998, 1999 Jesper Skov
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.
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.
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>
26 /* Needs INITSERIAL call in head.S! */
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>
36 #include <asm/machdep.h>
37 #include <asm/hardirq.h>
38 #include <asm/keyboard.h>
41 unsigned long m68k_machtype;
42 char debug_device[6] = "";
44 extern void amiga_init_IRQ(void);
46 extern int amiga_kbd_translate(unsigned char keycode, unsigned char *keycodep, char raw_mode);
47 extern char amiga_sysrq_xlate[128];
49 extern void apus_setup_pci_ptrs(void);
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;
73 #ifdef CONFIG_HEARTBEAT
74 void (*mach_heartbeat) (int) = NULL;
75 extern void apus_heartbeat(void);
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 */
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 */
89 struct mem_info ramdisk;
91 extern void amiga_floppy_setup(char *, int *);
92 extern void config_amiga(void);
94 static int __60nsram = 0;
97 static int __bus_speed = 0;
98 static int __speed_test_failed = 0;
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.
105 unsigned long apus_get_rtc_time(void)
108 extern unsigned long m68k_get_rtc_time(void);
110 return m68k_get_rtc_time ();
116 int apus_set_rtc_time(unsigned long nowtime)
119 extern int m68k_set_rtc_time(unsigned long nowtime);
121 return m68k_set_rtc_time (nowtime);
127 /*********************************************************** SETUP */
128 /* From arch/m68k/kernel/setup.c. */
129 void __init apus_setup_arch(void)
132 extern char cmd_line[];
136 /* Let m68k-shared code know it should do the Amiga thing. */
137 m68k_machtype = MACH_AMIGA;
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; ) {
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;
149 } else if (!strncmp( p, "60nsram", 7 )) {
150 APUS_WRITE (APUS_REG_WAITSTATE,
151 REGWAITSTATE_SETRESET
159 /* option processed, delete it */
160 if ((q = strchr( p, ' ' )))
165 if ((p = strchr( p, ' ' ))) ++p;
171 #if 0 /* Enable for logging - also include logging.o in Makefile rule */
173 #define LOG_SIZE 4096
176 /* Throw away some memory - the P5 firmare stomps on top
177 * of CHIP memory during bootup.
179 amiga_chip_alloc(0x1000);
181 base = amiga_chip_alloc(LOG_SIZE+sizeof(klog_data_t));
182 LOG_INIT(base, base+sizeof(klog_data_t), LOG_SIZE);
189 apus_show_cpuinfo(struct seq_file *m)
191 extern int __map_without_bats;
192 extern unsigned long powerup_PCI_present;
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");
205 static void get_current_tb(unsigned long long *time)
207 __asm __volatile ("1:mftbu 4 \n\t"
220 void apus_calibrate_decr(void)
225 /* This algorithm for determining the bus speed was
226 contributed by Ralph Schmidt. */
227 unsigned long long start, stop;
229 int speed_test_failed = 0;
232 unsigned long loop = amiga_eclock / 10;
234 get_current_tb (&start);
240 get_current_tb (&stop);
243 bus_speed = (((unsigned long)(stop-start))*10*4) / 1000000;
244 if (AMI_1200 == amiga_model)
247 if ((bus_speed >= 47) && (bus_speed < 53)) {
250 } else if ((bus_speed >= 57) && (bus_speed < 63)) {
253 } else if ((bus_speed >= 63) && (bus_speed < 69)) {
257 printk ("APUS: Unable to determine bus speed (%d). "
258 "Defaulting to 50MHz", bus_speed);
261 speed_test_failed = 1;
264 /* Ease diagnostics... */
266 extern int __map_without_bats;
267 extern unsigned long powerup_PCI_present;
269 printk ("APUS: BATs=%d, BUS=%dMHz",
270 (__map_without_bats) ? 0 : 1,
272 if (speed_test_failed)
273 printk ("[FAILED - please report]");
275 printk (", RAM=%dns, PCI bridge=%d\n",
276 (__60nsram) ? 60 : 70,
277 (powerup_PCI_present) ? 1 : 0);
279 /* print a bit more if asked politely... */
280 if (!(ciaa.pra & 0x40)){
281 extern unsigned int bat_addrs[4][3];
283 for (b = 0; b < 4; ++b) {
284 printk ("APUS: BAT%d ", b);
285 printk ("%08x-%08x -> %08x\n",
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);
299 __bus_speed = bus_speed;
300 __speed_test_failed = speed_test_failed;
304 void arch_gettod(int *year, int *mon, int *day, int *hour,
309 mach_gettod(year, mon, day, hour, min, sec);
311 *year = *mon = *day = *hour = *min = *sec = 0;
315 /* for "kbd-reset" cmdline param */
317 void kbd_reset_setup(char *str, int *ints)
321 /*********************************************************** FLOPPY */
322 #if defined(CONFIG_AMIGA_FLOPPY)
324 void floppy_setup(char *str, int *ints)
326 if (mach_floppy_setup)
327 mach_floppy_setup (str, ints);
331 /*********************************************************** MEMORY */
333 unsigned long kmap_chunks[KMAP_MAX*3];
334 int kmap_chunk_count = 0;
337 static __inline__ pte_t *my_find_pte(struct mm_struct *mm,unsigned long va)
345 dir = pgd_offset( mm, va );
348 pmd = pmd_offset(dir, va & PAGE_MASK);
349 if (pmd && pmd_present(*pmd))
351 pte = pte_offset(pmd, va);
358 /* Again simulating an m68k/mm/kmap.c function. */
359 void kernel_set_cachemode( unsigned long address, unsigned long size,
362 unsigned long mask, flags;
366 case IOMAP_FULL_CACHING:
367 mask = ~(_PAGE_NO_CACHE | _PAGE_GUARDED);
370 case IOMAP_NOCACHE_SER:
372 flags = (_PAGE_NO_CACHE | _PAGE_GUARDED);
375 panic ("kernel_set_cachemode() doesn't support mode %d\n",
381 address &= PAGE_MASK;
386 pte = my_find_pte(&init_mm, address);
389 printk("pte NULL in kernel_set_cachemode()\n");
393 pte_val (*pte) &= mask;
394 pte_val (*pte) |= flags;
395 flush_tlb_page(find_vma(&init_mm,address),address);
397 address += PAGE_SIZE;
401 unsigned long mm_ptov (unsigned long paddr)
404 if (paddr < 16*1024*1024)
405 ret = ZTWO_VADDR(paddr);
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++];
414 && paddr < (phys + size)){
415 ret = virt + paddr - phys;
420 ret = (unsigned long) __va(paddr);
424 printk ("PTOV(%lx)=%lx\n", paddr, ret);
429 int mm_end_of_chunk (unsigned long addr, int len)
431 if (memory[0].addr + memory[0].size == addr + len)
436 /*********************************************************** CACHE */
438 #define L1_CACHE_BYTES 32
439 #define MAX_CACHE_SIZE 8192
440 void cache_push(__u32 addr, int length)
442 addr = mm_ptov(addr);
444 if (MAX_CACHE_SIZE < length)
445 length = MAX_CACHE_SIZE;
448 __asm ("dcbf 0,%0\n\t"
450 addr += L1_CACHE_BYTES;
451 length -= L1_CACHE_BYTES;
453 /* Also flush trailing block */
454 __asm ("dcbf 0,%0\n\t"
459 void cache_clear(__u32 addr, int length)
461 if (MAX_CACHE_SIZE < length)
462 length = MAX_CACHE_SIZE;
464 addr = mm_ptov(addr);
466 __asm ("dcbf 0,%0\n\t"
472 addr += L1_CACHE_BYTES;
473 length -= L1_CACHE_BYTES;
476 __asm ("dcbf 0,%0\n\t"
481 addr += L1_CACHE_BYTES;
482 length -= L1_CACHE_BYTES;
485 __asm ("dcbf 0,%0\n\t"
492 /****************************************************** from setup.c */
494 apus_restart(char *cmd)
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);
521 /****************************************************** IRQ stuff */
523 static unsigned char last_ipl[8];
525 int apus_get_irq(struct pt_regs* regs)
527 unsigned char ipl_emu, mask;
530 APUS_READ(APUS_IPL_EMU, ipl_emu);
531 level = (ipl_emu >> 3) & IPLEMU_IPLMASK;
532 mask = IPLEMU_SETRESET|IPLEMU_DISABLEINT|level;
535 /* Save previous IPL value */
538 last_ipl[level] = ipl_emu;
540 /* Set to current IPL value */
541 APUS_WRITE(APUS_IPL_EMU, mask);
542 APUS_WRITE(APUS_IPL_EMU, IPLEMU_DISABLEINT|level);
545 #ifdef __INTERRUPT_DEBUG
546 printk("<%d:%d>", level, ~ipl_emu & IPLEMU_IPLMASK);
548 return level + IRQ_AMIGA_AUTO;
551 void apus_end_irq(unsigned int irq)
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);
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);
563 APUS_WRITE(APUS_IPL_EMU, IPLEMU_DISABLEINT|ipl_emu);
566 /****************************************************** keyboard */
567 static int apus_kbd_setkeycode(unsigned int scancode, unsigned int keycode)
572 static int apus_kbd_getkeycode(unsigned int scancode)
574 return scancode > 127 ? -EINVAL : scancode;
577 static char apus_kbd_unexpected_up(unsigned char keycode)
582 static void apus_kbd_init_hw(void)
585 extern int amiga_keyb_init(void);
592 /****************************************************** debugging */
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)
600 #define AC_SETCLR (1<<15)
601 #define AC_UARTBRK (1<<11)
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)
609 static __inline__ void ser_RTSon(void)
611 ciab.pra &= ~SER_RTS; /* active low */
614 int __debug_ser_out( unsigned char c )
616 custom.serdat = c | 0x100;
618 while (!(custom.serdatr & 0x2000))
623 unsigned char __debug_ser_in( void )
627 /* XXX: is that ok?? derived from amiga_ser.c... */
628 while( !(custom.intreqr & IF_RBF) )
631 /* clear the interrupt, so that another character can be read */
632 custom.intreq = IF_RBF;
636 int __debug_serinit( void )
643 /* turn off Rx and Tx interrupts */
644 custom.intena = IF_RBF | IF_TBE;
646 /* clear any pending interrupt */
647 custom.intreq = IF_RBF | IF_TBE;
649 restore_flags (flags);
652 * set the appropriate directions for the modem control flags,
653 * and clear RTS and DTR
655 ciab.ddra |= (SER_DTR | SER_RTS); /* outputs */
656 ciab.ddra &= ~(SER_DCD | SER_CTS | SER_DSR); /* inputs */
659 /* turn Rx interrupts on for GDB */
660 custom.intena = IF_SETCLR | IF_RBF;
667 void __debug_print_hex(unsigned long x)
670 char hexchars[] = "0123456789ABCDEF";
672 for (i = 0; i < 8; i++) {
673 __debug_ser_out(hexchars[(x >> 28) & 15]);
676 __debug_ser_out('\n');
677 __debug_ser_out('\r');
680 void __debug_print_string(char* s)
685 __debug_ser_out('\n');
686 __debug_ser_out('\r');
689 static void apus_progress(char *s, unsigned short value)
691 __debug_print_string(s);
694 /****************************************************** init */
696 /* The number of spurious interrupts */
697 volatile unsigned int num_spurious;
699 extern struct irqaction amiga_sys_irqaction[AUTO_IRQS];
702 extern void amiga_enable_irq(unsigned int irq);
703 extern void amiga_disable_irq(unsigned int irq);
705 struct hw_interrupt_type amiga_sys_irqctrl = {
706 typename: "Amiga IPL",
710 struct hw_interrupt_type amiga_irqctrl = {
712 enable: amiga_enable_irq,
713 disable: amiga_disable_irq,
716 #define HARDWARE_MAPPED_SIZE (512*1024)
717 unsigned long __init apus_find_end_of_memory(void)
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. */
726 unsigned long size = memory[0].size;
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
735 size = ((size+0x0007ffff) & 0xfff80000);
736 /* If memory is 1MB aligned, assume
738 shadow = !(size & 0x80000);
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);
746 ppc_memstart = memory[0].addr;
747 ppc_memoffset = PAGE_OFFSET - PPC_MEMSTART;
748 total = memory[0].size;
750 /* Remove the memory chunks that are controlled by special
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
758 total -= HARDWARE_MAPPED_SIZE;
760 /* Remove the upper 512KB where the PPC exception
761 vectors are mapped. */
762 total -= HARDWARE_MAPPED_SIZE;
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. */
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);
781 void apus_init_IRQ(void)
783 struct irqaction *action;
787 apus_setup_pci_ptrs();
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;
795 irq_desc[i].handler = &amiga_sys_irqctrl;
796 action = &amiga_sys_irqaction[i-IRQ_AMIGA_AUTO];
798 setup_irq(i, action);
807 void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
808 unsigned long r6, unsigned long r7)
810 extern int parse_bootinfo(const struct bi_record *);
813 /* Parse bootinfo. The bootinfo is located right after
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);
825 #endif /* CONFIG_BLK_DEV_INITRD */
827 ISA_DMA_THRESHOLD = 0x00ffffff;
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;
834 #ifdef CONFIG_HEARTBEAT
835 ppc_md.heartbeat = apus_heartbeat;
836 heartbeat_reset(0) = 1; /* assume UP for now */
837 heartbeat_count(0) = 1;
841 ppc_md.progress = apus_progress;
845 ppc_md.restart = apus_restart;
846 ppc_md.power_off = apus_power_off;
847 ppc_md.halt = apus_halt;
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;
854 ppc_md.find_end_of_memory = apus_find_end_of_memory;
855 ppc_md.setup_io_mappings = apus_map_io;
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;
865 ppc_md.ppc_kbd_sysrq_xlate = amiga_sysrq_xlate;