2 * Copyright (C) 1998, 1999 Jesper Skov
4 * Basically what is needed to replace functionality found in
5 * arch/m68k allowing Amiga drivers to work under APUS.
6 * Bits of code and/or ideas from arch/m68k and arch/ppc files.
9 * This file needs a *really* good cleanup. Restructure and optimize.
10 * Make sure it can be compiled for non-APUS configs. Begin to move
11 * Amiga specific stuff into mach/amiga.
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/init.h>
17 #include <linux/initrd.h>
18 #include <linux/seq_file.h>
20 /* Needs INITSERIAL call in head.S! */
23 #include <asm/bootinfo.h>
24 #include <asm/setup.h>
25 #include <asm/amigahw.h>
26 #include <asm/amigaints.h>
27 #include <asm/amigappc.h>
28 #include <asm/pgtable.h>
30 #include <asm/machdep.h>
33 unsigned long m68k_machtype
;
34 char debug_device
[6] = "";
36 extern void amiga_init_IRQ(void);
38 extern void apus_setup_pci_ptrs(void);
40 void (*mach_sched_init
) (void (*handler
)(int, void *, struct pt_regs
*)) __initdata
= NULL
;
41 /* machine dependent irq functions */
42 void (*mach_init_IRQ
) (void) __initdata
= NULL
;
43 void (*(*mach_default_handler
)[]) (int, void *, struct pt_regs
*) = NULL
;
44 void (*mach_get_model
) (char *model
) = NULL
;
45 int (*mach_get_hardware_list
) (char *buffer
) = NULL
;
46 int (*mach_get_irq_list
) (struct seq_file
*, void *) = NULL
;
47 void (*mach_process_int
) (int, struct pt_regs
*) = NULL
;
48 /* machine dependent timer functions */
49 unsigned long (*mach_gettimeoffset
) (void);
50 void (*mach_gettod
) (int*, int*, int*, int*, int*, int*);
51 int (*mach_hwclk
) (int, struct hwclk_time
*) = NULL
;
52 int (*mach_set_clock_mmss
) (unsigned long) = NULL
;
53 void (*mach_reset
)( void );
54 long mach_max_dma_address
= 0x00ffffff; /* default set to the lower 16MB */
55 #ifdef CONFIG_HEARTBEAT
56 void (*mach_heartbeat
) (int) = NULL
;
57 extern void apus_heartbeat (void);
60 extern unsigned long amiga_model
;
61 extern unsigned decrementer_count
;/* count value for 1e6/HZ microseconds */
62 extern unsigned count_period_num
; /* 1 decrementer count equals */
63 extern unsigned count_period_den
; /* count_period_num / count_period_den us */
66 struct mem_info memory
[NUM_MEMINFO
];/* memory description */
67 /* FIXME: Duplicate memory data to avoid conflicts with m68k shared code. */
68 int m68k_realnum_memory
= 0;
69 struct mem_info m68k_memory
[NUM_MEMINFO
];/* memory description */
71 struct mem_info ramdisk
;
73 extern void config_amiga(void);
75 static int __60nsram
= 0;
78 static int __bus_speed
= 0;
79 static int __speed_test_failed
= 0;
81 /********************************************** COMPILE PROTECTION */
82 /* Provide some stubs that links to Amiga specific functions.
83 * This allows CONFIG_APUS to be removed from generic PPC files while
84 * preventing link errors for other PPC targets.
86 unsigned long apus_get_rtc_time(void)
89 extern unsigned long m68k_get_rtc_time(void);
91 return m68k_get_rtc_time ();
97 int apus_set_rtc_time(unsigned long nowtime
)
100 extern int m68k_set_rtc_time(unsigned long nowtime
);
102 return m68k_set_rtc_time (nowtime
);
108 /*********************************************************** SETUP */
109 /* From arch/m68k/kernel/setup.c. */
110 void __init
apus_setup_arch(void)
113 extern char cmd_line
[];
117 /* Let m68k-shared code know it should do the Amiga thing. */
118 m68k_machtype
= MACH_AMIGA
;
120 /* Parse the command line for arch-specific options.
121 * For the m68k, this is currently only "debug=xxx" to enable printing
122 * certain kernel messages to some machine-specific device. */
123 for( p
= cmd_line
; p
&& *p
; ) {
125 if (!strncmp( p
, "debug=", 6 )) {
126 strlcpy( debug_device
, p
+6, sizeof(debug_device
) );
127 if ((q
= strchr( debug_device
, ' ' ))) *q
= 0;
129 } else if (!strncmp( p
, "60nsram", 7 )) {
130 APUS_WRITE (APUS_REG_WAITSTATE
,
131 REGWAITSTATE_SETRESET
139 /* option processed, delete it */
140 if ((q
= strchr( p
, ' ' )))
145 if ((p
= strchr( p
, ' ' ))) ++p
;
151 #if 0 /* Enable for logging - also include logging.o in Makefile rule */
153 #define LOG_SIZE 4096
156 /* Throw away some memory - the P5 firmare stomps on top
157 * of CHIP memory during bootup.
159 amiga_chip_alloc(0x1000);
161 base
= amiga_chip_alloc(LOG_SIZE
+sizeof(klog_data_t
));
162 LOG_INIT(base
, base
+sizeof(klog_data_t
), LOG_SIZE
);
169 apus_show_cpuinfo(struct seq_file
*m
)
171 extern int __map_without_bats
;
172 extern unsigned long powerup_PCI_present
;
174 seq_printf(m
, "machine\t\t: Amiga\n");
175 seq_printf(m
, "bus speed\t: %d%s", __bus_speed
,
176 (__speed_test_failed
) ? " [failed]\n" : "\n");
177 seq_printf(m
, "using BATs\t: %s\n",
178 (__map_without_bats
) ? "No" : "Yes");
179 seq_printf(m
, "ram speed\t: %dns\n", (__60nsram
) ? 60 : 70);
180 seq_printf(m
, "PCI bridge\t: %s\n",
181 (powerup_PCI_present
) ? "Yes" : "No");
185 static void get_current_tb(unsigned long long *time
)
187 __asm
__volatile ("1:mftbu 4 \n\t"
200 void apus_calibrate_decr(void)
205 /* This algorithm for determining the bus speed was
206 contributed by Ralph Schmidt. */
207 unsigned long long start
, stop
;
209 int speed_test_failed
= 0;
212 unsigned long loop
= amiga_eclock
/ 10;
214 get_current_tb (&start
);
220 get_current_tb (&stop
);
223 bus_speed
= (((unsigned long)(stop
-start
))*10*4) / 1000000;
224 if (AMI_1200
== amiga_model
)
227 if ((bus_speed
>= 47) && (bus_speed
< 53)) {
230 } else if ((bus_speed
>= 57) && (bus_speed
< 63)) {
233 } else if ((bus_speed
>= 63) && (bus_speed
< 69)) {
237 printk ("APUS: Unable to determine bus speed (%d). "
238 "Defaulting to 50MHz", bus_speed
);
241 speed_test_failed
= 1;
244 /* Ease diagnostics... */
246 extern int __map_without_bats
;
247 extern unsigned long powerup_PCI_present
;
249 printk ("APUS: BATs=%d, BUS=%dMHz",
250 (__map_without_bats
) ? 0 : 1,
252 if (speed_test_failed
)
253 printk ("[FAILED - please report]");
255 printk (", RAM=%dns, PCI bridge=%d\n",
256 (__60nsram
) ? 60 : 70,
257 (powerup_PCI_present
) ? 1 : 0);
259 /* print a bit more if asked politely... */
260 if (!(ciaa
.pra
& 0x40)){
261 extern unsigned int bat_addrs
[4][3];
263 for (b
= 0; b
< 4; ++b
) {
264 printk ("APUS: BAT%d ", b
);
265 printk ("%08x-%08x -> %08x\n",
274 printk("time_init: decrementer frequency = %lu.%.6lu MHz\n",
275 freq
/1000000, freq
%1000000);
276 tb_ticks_per_jiffy
= freq
/ HZ
;
277 tb_to_us
= mulhwu_scale_factor(freq
, 1000000);
279 __bus_speed
= bus_speed
;
280 __speed_test_failed
= speed_test_failed
;
284 void arch_gettod(int *year
, int *mon
, int *day
, int *hour
,
289 mach_gettod(year
, mon
, day
, hour
, min
, sec
);
291 *year
= *mon
= *day
= *hour
= *min
= *sec
= 0;
295 /* for "kbd-reset" cmdline param */
297 void kbd_reset_setup(char *str
, int *ints
)
301 /*********************************************************** MEMORY */
303 unsigned long kmap_chunks
[KMAP_MAX
*3];
304 int kmap_chunk_count
= 0;
307 static __inline__ pte_t
*my_find_pte(struct mm_struct
*mm
,unsigned long va
)
315 dir
= pgd_offset( mm
, va
);
318 pmd
= pmd_offset(dir
, va
& PAGE_MASK
);
319 if (pmd
&& pmd_present(*pmd
))
321 pte
= pte_offset(pmd
, va
);
328 /* Again simulating an m68k/mm/kmap.c function. */
329 void kernel_set_cachemode( unsigned long address
, unsigned long size
,
332 unsigned long mask
, flags
;
336 case IOMAP_FULL_CACHING
:
337 mask
= ~(_PAGE_NO_CACHE
| _PAGE_GUARDED
);
340 case IOMAP_NOCACHE_SER
:
342 flags
= (_PAGE_NO_CACHE
| _PAGE_GUARDED
);
345 panic ("kernel_set_cachemode() doesn't support mode %d\n",
351 address
&= PAGE_MASK
;
356 pte
= my_find_pte(&init_mm
, address
);
359 printk("pte NULL in kernel_set_cachemode()\n");
363 pte_val (*pte
) &= mask
;
364 pte_val (*pte
) |= flags
;
365 flush_tlb_page(find_vma(&init_mm
,address
),address
);
367 address
+= PAGE_SIZE
;
371 unsigned long mm_ptov (unsigned long paddr
)
374 if (paddr
< 16*1024*1024)
375 ret
= ZTWO_VADDR(paddr
);
379 for (i
= 0; i
< kmap_chunk_count
;){
380 unsigned long phys
= kmap_chunks
[i
++];
381 unsigned long size
= kmap_chunks
[i
++];
382 unsigned long virt
= kmap_chunks
[i
++];
384 && paddr
< (phys
+ size
)){
385 ret
= virt
+ paddr
- phys
;
390 ret
= (unsigned long) __va(paddr
);
394 printk ("PTOV(%lx)=%lx\n", paddr
, ret
);
399 int mm_end_of_chunk (unsigned long addr
, int len
)
401 if (memory
[0].addr
+ memory
[0].size
== addr
+ len
)
406 /*********************************************************** CACHE */
408 #define L1_CACHE_BYTES 32
409 #define MAX_CACHE_SIZE 8192
410 void cache_push(__u32 addr
, int length
)
412 addr
= mm_ptov(addr
);
414 if (MAX_CACHE_SIZE
< length
)
415 length
= MAX_CACHE_SIZE
;
418 __asm ("dcbf 0,%0\n\t"
420 addr
+= L1_CACHE_BYTES
;
421 length
-= L1_CACHE_BYTES
;
423 /* Also flush trailing block */
424 __asm ("dcbf 0,%0\n\t"
429 void cache_clear(__u32 addr
, int length
)
431 if (MAX_CACHE_SIZE
< length
)
432 length
= MAX_CACHE_SIZE
;
434 addr
= mm_ptov(addr
);
436 __asm ("dcbf 0,%0\n\t"
442 addr
+= L1_CACHE_BYTES
;
443 length
-= L1_CACHE_BYTES
;
446 __asm ("dcbf 0,%0\n\t"
451 addr
+= L1_CACHE_BYTES
;
452 length
-= L1_CACHE_BYTES
;
455 __asm ("dcbf 0,%0\n\t"
462 /****************************************************** from setup.c */
464 apus_restart(char *cmd
)
468 APUS_WRITE(APUS_REG_LOCK
,
469 REGLOCK_BLACKMAGICK1
|REGLOCK_BLACKMAGICK2
);
470 APUS_WRITE(APUS_REG_LOCK
,
471 REGLOCK_BLACKMAGICK1
|REGLOCK_BLACKMAGICK3
);
472 APUS_WRITE(APUS_REG_LOCK
,
473 REGLOCK_BLACKMAGICK2
|REGLOCK_BLACKMAGICK3
);
474 APUS_WRITE(APUS_REG_SHADOW
, REGSHADOW_SELFRESET
);
475 APUS_WRITE(APUS_REG_RESET
, REGRESET_AMIGARESET
);
491 /****************************************************** IRQ stuff */
493 static unsigned char last_ipl
[8];
495 int apus_get_irq(struct pt_regs
* regs
)
497 unsigned char ipl_emu
, mask
;
500 APUS_READ(APUS_IPL_EMU
, ipl_emu
);
501 level
= (ipl_emu
>> 3) & IPLEMU_IPLMASK
;
502 mask
= IPLEMU_SETRESET
|IPLEMU_DISABLEINT
|level
;
505 /* Save previous IPL value */
508 last_ipl
[level
] = ipl_emu
;
510 /* Set to current IPL value */
511 APUS_WRITE(APUS_IPL_EMU
, mask
);
512 APUS_WRITE(APUS_IPL_EMU
, IPLEMU_DISABLEINT
|level
);
515 #ifdef __INTERRUPT_DEBUG
516 printk("<%d:%d>", level
, ~ipl_emu
& IPLEMU_IPLMASK
);
518 return level
+ IRQ_AMIGA_AUTO
;
521 void apus_end_irq(unsigned int irq
)
523 unsigned char ipl_emu
;
524 unsigned int level
= irq
- IRQ_AMIGA_AUTO
;
525 #ifdef __INTERRUPT_DEBUG
526 printk("{%d}", ~last_ipl
[level
] & IPLEMU_IPLMASK
);
528 /* Restore IPL to the previous value */
529 ipl_emu
= last_ipl
[level
] & IPLEMU_IPLMASK
;
530 APUS_WRITE(APUS_IPL_EMU
, IPLEMU_SETRESET
|IPLEMU_DISABLEINT
|ipl_emu
);
533 APUS_WRITE(APUS_IPL_EMU
, IPLEMU_DISABLEINT
|ipl_emu
);
536 /****************************************************** debugging */
538 /* some serial hardware definitions */
539 #define SDR_OVRUN (1<<15)
540 #define SDR_RBF (1<<14)
541 #define SDR_TBE (1<<13)
542 #define SDR_TSRE (1<<12)
544 #define AC_SETCLR (1<<15)
545 #define AC_UARTBRK (1<<11)
547 #define SER_DTR (1<<7)
548 #define SER_RTS (1<<6)
549 #define SER_DCD (1<<5)
550 #define SER_CTS (1<<4)
551 #define SER_DSR (1<<3)
553 static __inline__
void ser_RTSon(void)
555 ciab
.pra
&= ~SER_RTS
; /* active low */
558 int __debug_ser_out( unsigned char c
)
560 amiga_custom
.serdat
= c
| 0x100;
562 while (!(amiga_custom
.serdatr
& 0x2000))
567 unsigned char __debug_ser_in( void )
571 /* XXX: is that ok?? derived from amiga_ser.c... */
572 while( !(amiga_custom
.intreqr
& IF_RBF
) )
574 c
= amiga_custom
.serdatr
;
575 /* clear the interrupt, so that another character can be read */
576 amiga_custom
.intreq
= IF_RBF
;
580 int __debug_serinit( void )
584 local_irq_save(flags
);
586 /* turn off Rx and Tx interrupts */
587 amiga_custom
.intena
= IF_RBF
| IF_TBE
;
589 /* clear any pending interrupt */
590 amiga_custom
.intreq
= IF_RBF
| IF_TBE
;
592 local_irq_restore(flags
);
595 * set the appropriate directions for the modem control flags,
596 * and clear RTS and DTR
598 ciab
.ddra
|= (SER_DTR
| SER_RTS
); /* outputs */
599 ciab
.ddra
&= ~(SER_DCD
| SER_CTS
| SER_DSR
); /* inputs */
602 /* turn Rx interrupts on for GDB */
603 amiga_custom
.intena
= IF_SETCLR
| IF_RBF
;
610 void __debug_print_hex(unsigned long x
)
613 char hexchars
[] = "0123456789ABCDEF";
615 for (i
= 0; i
< 8; i
++) {
616 __debug_ser_out(hexchars
[(x
>> 28) & 15]);
619 __debug_ser_out('\n');
620 __debug_ser_out('\r');
623 void __debug_print_string(char* s
)
628 __debug_ser_out('\n');
629 __debug_ser_out('\r');
632 static void apus_progress(char *s
, unsigned short value
)
634 __debug_print_string(s
);
637 /****************************************************** init */
639 /* The number of spurious interrupts */
640 volatile unsigned int num_spurious
;
642 extern struct irqaction amiga_sys_irqaction
[AUTO_IRQS
];
645 extern void amiga_enable_irq(unsigned int irq
);
646 extern void amiga_disable_irq(unsigned int irq
);
648 struct hw_interrupt_type amiga_sys_irqctrl
= {
649 .typename
= "Amiga IPL",
653 struct hw_interrupt_type amiga_irqctrl
= {
654 .typename
= "Amiga ",
655 .enable
= amiga_enable_irq
,
656 .disable
= amiga_disable_irq
,
659 #define HARDWARE_MAPPED_SIZE (512*1024)
660 unsigned long __init
apus_find_end_of_memory(void)
665 /* The memory size reported by ADOS excludes the 512KB
666 reserved for PPC exception registers and possibly 512KB
667 containing a shadow of the ADOS ROM. */
669 unsigned long size
= memory
[0].size
;
671 /* If 2MB aligned, size was probably user
672 specified. We can't tell anything about shadowing
673 in this case so skip shadow assignment. */
674 if (0 != (size
& 0x1fffff)){
675 /* Align to 512KB to ensure correct handling
676 of both memfile and system specified
678 size
= ((size
+0x0007ffff) & 0xfff80000);
679 /* If memory is 1MB aligned, assume
681 shadow
= !(size
& 0x80000);
684 /* Add the chunk that ADOS does not see. by aligning
685 the size to the nearest 2MB limit upwards. */
686 memory
[0].size
= ((size
+0x001fffff) & 0xffe00000);
689 ppc_memstart
= memory
[0].addr
;
690 ppc_memoffset
= PAGE_OFFSET
- PPC_MEMSTART
;
691 total
= memory
[0].size
;
693 /* Remove the memory chunks that are controlled by special
696 /* Remove the upper 512KB if it contains a shadow of
697 the ADOS ROM. FIXME: It might be possible to
698 disable this shadow HW. Check the booter
701 total
-= HARDWARE_MAPPED_SIZE
;
703 /* Remove the upper 512KB where the PPC exception
704 vectors are mapped. */
705 total
-= HARDWARE_MAPPED_SIZE
;
707 /* Linux/APUS only handles one block of memory -- the one on
708 the PowerUP board. Other system memory is horrible slow in
709 comparison. The user can use other memory for swapping
710 using the z2ram device. */
717 /* Map PPC exception vectors. */
718 io_block_mapping(0xfff00000, 0xfff00000, 0x00020000, _PAGE_KERNEL
);
719 /* Map chip and ZorroII memory */
720 io_block_mapping(zTwoBase
, 0x00000000, 0x01000000, _PAGE_IO
);
724 void apus_init_IRQ(void)
726 struct irqaction
*action
;
730 apus_setup_pci_ptrs();
733 for ( i
= 0 ; i
< AMI_IRQS
; i
++ ) {
734 irq_desc
[i
].status
= IRQ_LEVEL
;
735 if (i
< IRQ_AMIGA_AUTO
) {
736 irq_desc
[i
].chip
= &amiga_irqctrl
;
738 irq_desc
[i
].chip
= &amiga_sys_irqctrl
;
739 action
= &amiga_sys_irqaction
[i
-IRQ_AMIGA_AUTO
];
741 setup_irq(i
, action
);
750 void platform_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
751 unsigned long r6
, unsigned long r7
)
753 extern int parse_bootinfo(const struct bi_record
*);
756 /* Parse bootinfo. The bootinfo is located right after
758 parse_bootinfo((const struct bi_record
*)&_end
);
759 #ifdef CONFIG_BLK_DEV_INITRD
760 /* Take care of initrd if we have one. Use data from
761 bootinfo to avoid the need to initialize PPC
762 registers when kernel is booted via a PPC reset. */
763 if ( ramdisk
.addr
) {
764 initrd_start
= (unsigned long) __va(ramdisk
.addr
);
765 initrd_end
= (unsigned long)
766 __va(ramdisk
.size
+ ramdisk
.addr
);
768 #endif /* CONFIG_BLK_DEV_INITRD */
770 ISA_DMA_THRESHOLD
= 0x00ffffff;
772 ppc_md
.setup_arch
= apus_setup_arch
;
773 ppc_md
.show_cpuinfo
= apus_show_cpuinfo
;
774 ppc_md
.init_IRQ
= apus_init_IRQ
;
775 ppc_md
.get_irq
= apus_get_irq
;
777 #ifdef CONFIG_HEARTBEAT
778 ppc_md
.heartbeat
= apus_heartbeat
;
779 ppc_md
.heartbeat_count
= 1;
783 ppc_md
.progress
= apus_progress
;
787 ppc_md
.restart
= apus_restart
;
788 ppc_md
.power_off
= apus_power_off
;
789 ppc_md
.halt
= apus_halt
;
791 ppc_md
.time_init
= NULL
;
792 ppc_md
.set_rtc_time
= apus_set_rtc_time
;
793 ppc_md
.get_rtc_time
= apus_get_rtc_time
;
794 ppc_md
.calibrate_decr
= apus_calibrate_decr
;
796 ppc_md
.find_end_of_memory
= apus_find_end_of_memory
;
797 ppc_md
.setup_io_mappings
= apus_map_io
;