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/initrd.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>
36 unsigned long m68k_machtype;
37 char debug_device[6] = "";
39 extern void amiga_init_IRQ(void);
41 extern void apus_setup_pci_ptrs(void);
43 void (*mach_sched_init) (void (*handler)(int, void *, struct pt_regs *)) __initdata = NULL;
44 /* machine dependent irq functions */
45 void (*mach_init_IRQ) (void) __initdata = NULL;
46 void (*(*mach_default_handler)[]) (int, void *, struct pt_regs *) = NULL;
47 void (*mach_get_model) (char *model) = NULL;
48 int (*mach_get_hardware_list) (char *buffer) = NULL;
49 int (*mach_get_irq_list) (struct seq_file *, void *) = NULL;
50 void (*mach_process_int) (int, struct pt_regs *) = NULL;
51 /* machine dependent timer functions */
52 unsigned long (*mach_gettimeoffset) (void);
53 void (*mach_gettod) (int*, int*, int*, int*, int*, int*);
54 int (*mach_hwclk) (int, struct hwclk_time*) = NULL;
55 int (*mach_set_clock_mmss) (unsigned long) = NULL;
56 void (*mach_reset)( void );
57 long mach_max_dma_address = 0x00ffffff; /* default set to the lower 16MB */
58 #ifdef CONFIG_HEARTBEAT
59 void (*mach_heartbeat) (int) = NULL;
60 extern void apus_heartbeat (void);
63 extern unsigned long amiga_model;
64 extern unsigned decrementer_count;/* count value for 1e6/HZ microseconds */
65 extern unsigned count_period_num; /* 1 decrementer count equals */
66 extern unsigned count_period_den; /* count_period_num / count_period_den us */
69 struct mem_info memory[NUM_MEMINFO];/* memory description */
70 /* FIXME: Duplicate memory data to avoid conflicts with m68k shared code. */
71 int m68k_realnum_memory = 0;
72 struct mem_info m68k_memory[NUM_MEMINFO];/* memory description */
74 struct mem_info ramdisk;
76 extern void config_amiga(void);
78 static int __60nsram = 0;
81 static int __bus_speed = 0;
82 static int __speed_test_failed = 0;
84 /********************************************** COMPILE PROTECTION */
85 /* Provide some stubs that links to Amiga specific functions.
86 * This allows CONFIG_APUS to be removed from generic PPC files while
87 * preventing link errors for other PPC targets.
89 unsigned long apus_get_rtc_time(void)
92 extern unsigned long m68k_get_rtc_time(void);
94 return m68k_get_rtc_time ();
100 int apus_set_rtc_time(unsigned long nowtime)
103 extern int m68k_set_rtc_time(unsigned long nowtime);
105 return m68k_set_rtc_time (nowtime);
111 /*********************************************************** SETUP */
112 /* From arch/m68k/kernel/setup.c. */
113 void __init apus_setup_arch(void)
116 extern char cmd_line[];
120 /* Let m68k-shared code know it should do the Amiga thing. */
121 m68k_machtype = MACH_AMIGA;
123 /* Parse the command line for arch-specific options.
124 * For the m68k, this is currently only "debug=xxx" to enable printing
125 * certain kernel messages to some machine-specific device. */
126 for( p = cmd_line; p && *p; ) {
128 if (!strncmp( p, "debug=", 6 )) {
129 strlcpy( debug_device, p+6, sizeof(debug_device) );
130 if ((q = strchr( debug_device, ' ' ))) *q = 0;
132 } else if (!strncmp( p, "60nsram", 7 )) {
133 APUS_WRITE (APUS_REG_WAITSTATE,
134 REGWAITSTATE_SETRESET
142 /* option processed, delete it */
143 if ((q = strchr( p, ' ' )))
148 if ((p = strchr( p, ' ' ))) ++p;
154 #if 0 /* Enable for logging - also include logging.o in Makefile rule */
156 #define LOG_SIZE 4096
159 /* Throw away some memory - the P5 firmare stomps on top
160 * of CHIP memory during bootup.
162 amiga_chip_alloc(0x1000);
164 base = amiga_chip_alloc(LOG_SIZE+sizeof(klog_data_t));
165 LOG_INIT(base, base+sizeof(klog_data_t), LOG_SIZE);
172 apus_show_cpuinfo(struct seq_file *m)
174 extern int __map_without_bats;
175 extern unsigned long powerup_PCI_present;
177 seq_printf(m, "machine\t\t: Amiga\n");
178 seq_printf(m, "bus speed\t: %d%s", __bus_speed,
179 (__speed_test_failed) ? " [failed]\n" : "\n");
180 seq_printf(m, "using BATs\t: %s\n",
181 (__map_without_bats) ? "No" : "Yes");
182 seq_printf(m, "ram speed\t: %dns\n", (__60nsram) ? 60 : 70);
183 seq_printf(m, "PCI bridge\t: %s\n",
184 (powerup_PCI_present) ? "Yes" : "No");
188 static void get_current_tb(unsigned long long *time)
190 __asm __volatile ("1:mftbu 4 \n\t"
203 void apus_calibrate_decr(void)
208 /* This algorithm for determining the bus speed was
209 contributed by Ralph Schmidt. */
210 unsigned long long start, stop;
212 int speed_test_failed = 0;
215 unsigned long loop = amiga_eclock / 10;
217 get_current_tb (&start);
223 get_current_tb (&stop);
226 bus_speed = (((unsigned long)(stop-start))*10*4) / 1000000;
227 if (AMI_1200 == amiga_model)
230 if ((bus_speed >= 47) && (bus_speed < 53)) {
233 } else if ((bus_speed >= 57) && (bus_speed < 63)) {
236 } else if ((bus_speed >= 63) && (bus_speed < 69)) {
240 printk ("APUS: Unable to determine bus speed (%d). "
241 "Defaulting to 50MHz", bus_speed);
244 speed_test_failed = 1;
247 /* Ease diagnostics... */
249 extern int __map_without_bats;
250 extern unsigned long powerup_PCI_present;
252 printk ("APUS: BATs=%d, BUS=%dMHz",
253 (__map_without_bats) ? 0 : 1,
255 if (speed_test_failed)
256 printk ("[FAILED - please report]");
258 printk (", RAM=%dns, PCI bridge=%d\n",
259 (__60nsram) ? 60 : 70,
260 (powerup_PCI_present) ? 1 : 0);
262 /* print a bit more if asked politely... */
263 if (!(ciaa.pra & 0x40)){
264 extern unsigned int bat_addrs[4][3];
266 for (b = 0; b < 4; ++b) {
267 printk ("APUS: BAT%d ", b);
268 printk ("%08x-%08x -> %08x\n",
277 printk("time_init: decrementer frequency = %lu.%.6lu MHz\n",
278 freq/1000000, freq%1000000);
279 tb_ticks_per_jiffy = freq / HZ;
280 tb_to_us = mulhwu_scale_factor(freq, 1000000);
282 __bus_speed = bus_speed;
283 __speed_test_failed = speed_test_failed;
287 void arch_gettod(int *year, int *mon, int *day, int *hour,
292 mach_gettod(year, mon, day, hour, min, sec);
294 *year = *mon = *day = *hour = *min = *sec = 0;
298 /* for "kbd-reset" cmdline param */
300 void kbd_reset_setup(char *str, int *ints)
304 /*********************************************************** MEMORY */
306 unsigned long kmap_chunks[KMAP_MAX*3];
307 int kmap_chunk_count = 0;
310 static __inline__ pte_t *my_find_pte(struct mm_struct *mm,unsigned long va)
318 dir = pgd_offset( mm, va );
321 pmd = pmd_offset(dir, va & PAGE_MASK);
322 if (pmd && pmd_present(*pmd))
324 pte = pte_offset(pmd, va);
331 /* Again simulating an m68k/mm/kmap.c function. */
332 void kernel_set_cachemode( unsigned long address, unsigned long size,
335 unsigned long mask, flags;
339 case IOMAP_FULL_CACHING:
340 mask = ~(_PAGE_NO_CACHE | _PAGE_GUARDED);
343 case IOMAP_NOCACHE_SER:
345 flags = (_PAGE_NO_CACHE | _PAGE_GUARDED);
348 panic ("kernel_set_cachemode() doesn't support mode %d\n",
354 address &= PAGE_MASK;
359 pte = my_find_pte(&init_mm, address);
362 printk("pte NULL in kernel_set_cachemode()\n");
366 pte_val (*pte) &= mask;
367 pte_val (*pte) |= flags;
368 flush_tlb_page(find_vma(&init_mm,address),address);
370 address += PAGE_SIZE;
374 unsigned long mm_ptov (unsigned long paddr)
377 if (paddr < 16*1024*1024)
378 ret = ZTWO_VADDR(paddr);
382 for (i = 0; i < kmap_chunk_count;){
383 unsigned long phys = kmap_chunks[i++];
384 unsigned long size = kmap_chunks[i++];
385 unsigned long virt = kmap_chunks[i++];
387 && paddr < (phys + size)){
388 ret = virt + paddr - phys;
393 ret = (unsigned long) __va(paddr);
397 printk ("PTOV(%lx)=%lx\n", paddr, ret);
402 int mm_end_of_chunk (unsigned long addr, int len)
404 if (memory[0].addr + memory[0].size == addr + len)
409 /*********************************************************** CACHE */
411 #define L1_CACHE_BYTES 32
412 #define MAX_CACHE_SIZE 8192
413 void cache_push(__u32 addr, int length)
415 addr = mm_ptov(addr);
417 if (MAX_CACHE_SIZE < length)
418 length = MAX_CACHE_SIZE;
421 __asm ("dcbf 0,%0\n\t"
423 addr += L1_CACHE_BYTES;
424 length -= L1_CACHE_BYTES;
426 /* Also flush trailing block */
427 __asm ("dcbf 0,%0\n\t"
432 void cache_clear(__u32 addr, int length)
434 if (MAX_CACHE_SIZE < length)
435 length = MAX_CACHE_SIZE;
437 addr = mm_ptov(addr);
439 __asm ("dcbf 0,%0\n\t"
445 addr += L1_CACHE_BYTES;
446 length -= L1_CACHE_BYTES;
449 __asm ("dcbf 0,%0\n\t"
454 addr += L1_CACHE_BYTES;
455 length -= L1_CACHE_BYTES;
458 __asm ("dcbf 0,%0\n\t"
465 /****************************************************** from setup.c */
467 apus_restart(char *cmd)
471 APUS_WRITE(APUS_REG_LOCK,
472 REGLOCK_BLACKMAGICK1|REGLOCK_BLACKMAGICK2);
473 APUS_WRITE(APUS_REG_LOCK,
474 REGLOCK_BLACKMAGICK1|REGLOCK_BLACKMAGICK3);
475 APUS_WRITE(APUS_REG_LOCK,
476 REGLOCK_BLACKMAGICK2|REGLOCK_BLACKMAGICK3);
477 APUS_WRITE(APUS_REG_SHADOW, REGSHADOW_SELFRESET);
478 APUS_WRITE(APUS_REG_RESET, REGRESET_AMIGARESET);
494 /****************************************************** IRQ stuff */
496 static unsigned char last_ipl[8];
498 int apus_get_irq(struct pt_regs* regs)
500 unsigned char ipl_emu, mask;
503 APUS_READ(APUS_IPL_EMU, ipl_emu);
504 level = (ipl_emu >> 3) & IPLEMU_IPLMASK;
505 mask = IPLEMU_SETRESET|IPLEMU_DISABLEINT|level;
508 /* Save previous IPL value */
511 last_ipl[level] = ipl_emu;
513 /* Set to current IPL value */
514 APUS_WRITE(APUS_IPL_EMU, mask);
515 APUS_WRITE(APUS_IPL_EMU, IPLEMU_DISABLEINT|level);
518 #ifdef __INTERRUPT_DEBUG
519 printk("<%d:%d>", level, ~ipl_emu & IPLEMU_IPLMASK);
521 return level + IRQ_AMIGA_AUTO;
524 void apus_end_irq(unsigned int irq)
526 unsigned char ipl_emu;
527 unsigned int level = irq - IRQ_AMIGA_AUTO;
528 #ifdef __INTERRUPT_DEBUG
529 printk("{%d}", ~last_ipl[level] & IPLEMU_IPLMASK);
531 /* Restore IPL to the previous value */
532 ipl_emu = last_ipl[level] & IPLEMU_IPLMASK;
533 APUS_WRITE(APUS_IPL_EMU, IPLEMU_SETRESET|IPLEMU_DISABLEINT|ipl_emu);
536 APUS_WRITE(APUS_IPL_EMU, IPLEMU_DISABLEINT|ipl_emu);
539 /****************************************************** debugging */
541 /* some serial hardware definitions */
542 #define SDR_OVRUN (1<<15)
543 #define SDR_RBF (1<<14)
544 #define SDR_TBE (1<<13)
545 #define SDR_TSRE (1<<12)
547 #define AC_SETCLR (1<<15)
548 #define AC_UARTBRK (1<<11)
550 #define SER_DTR (1<<7)
551 #define SER_RTS (1<<6)
552 #define SER_DCD (1<<5)
553 #define SER_CTS (1<<4)
554 #define SER_DSR (1<<3)
556 static __inline__ void ser_RTSon(void)
558 ciab.pra &= ~SER_RTS; /* active low */
561 int __debug_ser_out( unsigned char c )
563 amiga_custom.serdat = c | 0x100;
565 while (!(amiga_custom.serdatr & 0x2000))
570 unsigned char __debug_ser_in( void )
574 /* XXX: is that ok?? derived from amiga_ser.c... */
575 while( !(amiga_custom.intreqr & IF_RBF) )
577 c = amiga_custom.serdatr;
578 /* clear the interrupt, so that another character can be read */
579 amiga_custom.intreq = IF_RBF;
583 int __debug_serinit( void )
587 local_irq_save(flags);
589 /* turn off Rx and Tx interrupts */
590 amiga_custom.intena = IF_RBF | IF_TBE;
592 /* clear any pending interrupt */
593 amiga_custom.intreq = IF_RBF | IF_TBE;
595 local_irq_restore(flags);
598 * set the appropriate directions for the modem control flags,
599 * and clear RTS and DTR
601 ciab.ddra |= (SER_DTR | SER_RTS); /* outputs */
602 ciab.ddra &= ~(SER_DCD | SER_CTS | SER_DSR); /* inputs */
605 /* turn Rx interrupts on for GDB */
606 amiga_custom.intena = IF_SETCLR | IF_RBF;
613 void __debug_print_hex(unsigned long x)
616 char hexchars[] = "0123456789ABCDEF";
618 for (i = 0; i < 8; i++) {
619 __debug_ser_out(hexchars[(x >> 28) & 15]);
622 __debug_ser_out('\n');
623 __debug_ser_out('\r');
626 void __debug_print_string(char* s)
631 __debug_ser_out('\n');
632 __debug_ser_out('\r');
635 static void apus_progress(char *s, unsigned short value)
637 __debug_print_string(s);
640 /****************************************************** init */
642 /* The number of spurious interrupts */
643 volatile unsigned int num_spurious;
645 extern struct irqaction amiga_sys_irqaction[AUTO_IRQS];
648 extern void amiga_enable_irq(unsigned int irq);
649 extern void amiga_disable_irq(unsigned int irq);
651 struct hw_interrupt_type amiga_sys_irqctrl = {
652 .typename = "Amiga IPL",
656 struct hw_interrupt_type amiga_irqctrl = {
657 .typename = "Amiga ",
658 .enable = amiga_enable_irq,
659 .disable = amiga_disable_irq,
662 #define HARDWARE_MAPPED_SIZE (512*1024)
663 unsigned long __init apus_find_end_of_memory(void)
668 /* The memory size reported by ADOS excludes the 512KB
669 reserved for PPC exception registers and possibly 512KB
670 containing a shadow of the ADOS ROM. */
672 unsigned long size = memory[0].size;
674 /* If 2MB aligned, size was probably user
675 specified. We can't tell anything about shadowing
676 in this case so skip shadow assignment. */
677 if (0 != (size & 0x1fffff)){
678 /* Align to 512KB to ensure correct handling
679 of both memfile and system specified
681 size = ((size+0x0007ffff) & 0xfff80000);
682 /* If memory is 1MB aligned, assume
684 shadow = !(size & 0x80000);
687 /* Add the chunk that ADOS does not see. by aligning
688 the size to the nearest 2MB limit upwards. */
689 memory[0].size = ((size+0x001fffff) & 0xffe00000);
692 ppc_memstart = memory[0].addr;
693 ppc_memoffset = PAGE_OFFSET - PPC_MEMSTART;
694 total = memory[0].size;
696 /* Remove the memory chunks that are controlled by special
699 /* Remove the upper 512KB if it contains a shadow of
700 the ADOS ROM. FIXME: It might be possible to
701 disable this shadow HW. Check the booter
704 total -= HARDWARE_MAPPED_SIZE;
706 /* Remove the upper 512KB where the PPC exception
707 vectors are mapped. */
708 total -= HARDWARE_MAPPED_SIZE;
710 /* Linux/APUS only handles one block of memory -- the one on
711 the PowerUP board. Other system memory is horrible slow in
712 comparison. The user can use other memory for swapping
713 using the z2ram device. */
720 /* Map PPC exception vectors. */
721 io_block_mapping(0xfff00000, 0xfff00000, 0x00020000, _PAGE_KERNEL);
722 /* Map chip and ZorroII memory */
723 io_block_mapping(zTwoBase, 0x00000000, 0x01000000, _PAGE_IO);
727 void apus_init_IRQ(void)
729 struct irqaction *action;
733 apus_setup_pci_ptrs();
736 for ( i = 0 ; i < AMI_IRQS; i++ ) {
737 irq_desc[i].status = IRQ_LEVEL;
738 if (i < IRQ_AMIGA_AUTO) {
739 irq_desc[i].handler = &amiga_irqctrl;
741 irq_desc[i].handler = &amiga_sys_irqctrl;
742 action = &amiga_sys_irqaction[i-IRQ_AMIGA_AUTO];
744 setup_irq(i, action);
753 void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
754 unsigned long r6, unsigned long r7)
756 extern int parse_bootinfo(const struct bi_record *);
759 /* Parse bootinfo. The bootinfo is located right after
761 parse_bootinfo((const struct bi_record *)&_end);
762 #ifdef CONFIG_BLK_DEV_INITRD
763 /* Take care of initrd if we have one. Use data from
764 bootinfo to avoid the need to initialize PPC
765 registers when kernel is booted via a PPC reset. */
766 if ( ramdisk.addr ) {
767 initrd_start = (unsigned long) __va(ramdisk.addr);
768 initrd_end = (unsigned long)
769 __va(ramdisk.size + ramdisk.addr);
771 #endif /* CONFIG_BLK_DEV_INITRD */
773 ISA_DMA_THRESHOLD = 0x00ffffff;
775 ppc_md.setup_arch = apus_setup_arch;
776 ppc_md.show_cpuinfo = apus_show_cpuinfo;
777 ppc_md.init_IRQ = apus_init_IRQ;
778 ppc_md.get_irq = apus_get_irq;
780 #ifdef CONFIG_HEARTBEAT
781 ppc_md.heartbeat = apus_heartbeat;
782 ppc_md.heartbeat_count = 1;
786 ppc_md.progress = apus_progress;
790 ppc_md.restart = apus_restart;
791 ppc_md.power_off = apus_power_off;
792 ppc_md.halt = apus_halt;
794 ppc_md.time_init = NULL;
795 ppc_md.set_rtc_time = apus_set_rtc_time;
796 ppc_md.get_rtc_time = apus_get_rtc_time;
797 ppc_md.calibrate_decr = apus_calibrate_decr;
799 ppc_md.find_end_of_memory = apus_find_end_of_memory;
800 ppc_md.setup_io_mappings = apus_map_io;