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 #if defined(CONFIG_AMIGA_FLOPPY)
59 void (*mach_floppy_setup
) (char *, int *) __initdata
= NULL
;
61 #ifdef CONFIG_HEARTBEAT
62 void (*mach_heartbeat
) (int) = NULL
;
63 extern void apus_heartbeat (void);
66 extern unsigned long amiga_model
;
67 extern unsigned decrementer_count
;/* count value for 1e6/HZ microseconds */
68 extern unsigned count_period_num
; /* 1 decrementer count equals */
69 extern unsigned count_period_den
; /* count_period_num / count_period_den us */
72 struct mem_info memory
[NUM_MEMINFO
];/* memory description */
73 /* FIXME: Duplicate memory data to avoid conflicts with m68k shared code. */
74 int m68k_realnum_memory
= 0;
75 struct mem_info m68k_memory
[NUM_MEMINFO
];/* memory description */
77 struct mem_info ramdisk
;
79 extern void amiga_floppy_setup(char *, int *);
80 extern void config_amiga(void);
82 static int __60nsram
= 0;
85 static int __bus_speed
= 0;
86 static int __speed_test_failed
= 0;
88 /********************************************** COMPILE PROTECTION */
89 /* Provide some stubs that links to Amiga specific functions.
90 * This allows CONFIG_APUS to be removed from generic PPC files while
91 * preventing link errors for other PPC targets.
93 unsigned long apus_get_rtc_time(void)
96 extern unsigned long m68k_get_rtc_time(void);
98 return m68k_get_rtc_time ();
104 int apus_set_rtc_time(unsigned long nowtime
)
107 extern int m68k_set_rtc_time(unsigned long nowtime
);
109 return m68k_set_rtc_time (nowtime
);
115 /*********************************************************** SETUP */
116 /* From arch/m68k/kernel/setup.c. */
117 void __init
apus_setup_arch(void)
120 extern char cmd_line
[];
124 /* Let m68k-shared code know it should do the Amiga thing. */
125 m68k_machtype
= MACH_AMIGA
;
127 /* Parse the command line for arch-specific options.
128 * For the m68k, this is currently only "debug=xxx" to enable printing
129 * certain kernel messages to some machine-specific device. */
130 for( p
= cmd_line
; p
&& *p
; ) {
132 if (!strncmp( p
, "debug=", 6 )) {
133 strlcpy( debug_device
, p
+6, sizeof(debug_device
) );
134 if ((q
= strchr( debug_device
, ' ' ))) *q
= 0;
136 } else if (!strncmp( p
, "60nsram", 7 )) {
137 APUS_WRITE (APUS_REG_WAITSTATE
,
138 REGWAITSTATE_SETRESET
146 /* option processed, delete it */
147 if ((q
= strchr( p
, ' ' )))
152 if ((p
= strchr( p
, ' ' ))) ++p
;
158 #if 0 /* Enable for logging - also include logging.o in Makefile rule */
160 #define LOG_SIZE 4096
163 /* Throw away some memory - the P5 firmare stomps on top
164 * of CHIP memory during bootup.
166 amiga_chip_alloc(0x1000);
168 base
= amiga_chip_alloc(LOG_SIZE
+sizeof(klog_data_t
));
169 LOG_INIT(base
, base
+sizeof(klog_data_t
), LOG_SIZE
);
176 apus_show_cpuinfo(struct seq_file
*m
)
178 extern int __map_without_bats
;
179 extern unsigned long powerup_PCI_present
;
181 seq_printf(m
, "machine\t\t: Amiga\n");
182 seq_printf(m
, "bus speed\t: %d%s", __bus_speed
,
183 (__speed_test_failed
) ? " [failed]\n" : "\n");
184 seq_printf(m
, "using BATs\t: %s\n",
185 (__map_without_bats
) ? "No" : "Yes");
186 seq_printf(m
, "ram speed\t: %dns\n", (__60nsram
) ? 60 : 70);
187 seq_printf(m
, "PCI bridge\t: %s\n",
188 (powerup_PCI_present
) ? "Yes" : "No");
192 static void get_current_tb(unsigned long long *time
)
194 __asm
__volatile ("1:mftbu 4 \n\t"
207 void apus_calibrate_decr(void)
212 /* This algorithm for determining the bus speed was
213 contributed by Ralph Schmidt. */
214 unsigned long long start
, stop
;
216 int speed_test_failed
= 0;
219 unsigned long loop
= amiga_eclock
/ 10;
221 get_current_tb (&start
);
227 get_current_tb (&stop
);
230 bus_speed
= (((unsigned long)(stop
-start
))*10*4) / 1000000;
231 if (AMI_1200
== amiga_model
)
234 if ((bus_speed
>= 47) && (bus_speed
< 53)) {
237 } else if ((bus_speed
>= 57) && (bus_speed
< 63)) {
240 } else if ((bus_speed
>= 63) && (bus_speed
< 69)) {
244 printk ("APUS: Unable to determine bus speed (%d). "
245 "Defaulting to 50MHz", bus_speed
);
248 speed_test_failed
= 1;
251 /* Ease diagnostics... */
253 extern int __map_without_bats
;
254 extern unsigned long powerup_PCI_present
;
256 printk ("APUS: BATs=%d, BUS=%dMHz",
257 (__map_without_bats
) ? 0 : 1,
259 if (speed_test_failed
)
260 printk ("[FAILED - please report]");
262 printk (", RAM=%dns, PCI bridge=%d\n",
263 (__60nsram
) ? 60 : 70,
264 (powerup_PCI_present
) ? 1 : 0);
266 /* print a bit more if asked politely... */
267 if (!(ciaa
.pra
& 0x40)){
268 extern unsigned int bat_addrs
[4][3];
270 for (b
= 0; b
< 4; ++b
) {
271 printk ("APUS: BAT%d ", b
);
272 printk ("%08x-%08x -> %08x\n",
281 printk("time_init: decrementer frequency = %lu.%.6lu MHz\n",
282 freq
/1000000, freq
%1000000);
283 tb_ticks_per_jiffy
= freq
/ HZ
;
284 tb_to_us
= mulhwu_scale_factor(freq
, 1000000);
286 __bus_speed
= bus_speed
;
287 __speed_test_failed
= speed_test_failed
;
291 void arch_gettod(int *year
, int *mon
, int *day
, int *hour
,
296 mach_gettod(year
, mon
, day
, hour
, min
, sec
);
298 *year
= *mon
= *day
= *hour
= *min
= *sec
= 0;
302 /* for "kbd-reset" cmdline param */
304 void kbd_reset_setup(char *str
, int *ints
)
308 /*********************************************************** FLOPPY */
309 #if defined(CONFIG_AMIGA_FLOPPY)
311 void floppy_setup(char *str
, int *ints
)
313 if (mach_floppy_setup
)
314 mach_floppy_setup (str
, ints
);
318 /*********************************************************** MEMORY */
320 unsigned long kmap_chunks
[KMAP_MAX
*3];
321 int kmap_chunk_count
= 0;
324 static __inline__ pte_t
*my_find_pte(struct mm_struct
*mm
,unsigned long va
)
332 dir
= pgd_offset( mm
, va
);
335 pmd
= pmd_offset(dir
, va
& PAGE_MASK
);
336 if (pmd
&& pmd_present(*pmd
))
338 pte
= pte_offset(pmd
, va
);
345 /* Again simulating an m68k/mm/kmap.c function. */
346 void kernel_set_cachemode( unsigned long address
, unsigned long size
,
349 unsigned long mask
, flags
;
353 case IOMAP_FULL_CACHING
:
354 mask
= ~(_PAGE_NO_CACHE
| _PAGE_GUARDED
);
357 case IOMAP_NOCACHE_SER
:
359 flags
= (_PAGE_NO_CACHE
| _PAGE_GUARDED
);
362 panic ("kernel_set_cachemode() doesn't support mode %d\n",
368 address
&= PAGE_MASK
;
373 pte
= my_find_pte(&init_mm
, address
);
376 printk("pte NULL in kernel_set_cachemode()\n");
380 pte_val (*pte
) &= mask
;
381 pte_val (*pte
) |= flags
;
382 flush_tlb_page(find_vma(&init_mm
,address
),address
);
384 address
+= PAGE_SIZE
;
388 unsigned long mm_ptov (unsigned long paddr
)
391 if (paddr
< 16*1024*1024)
392 ret
= ZTWO_VADDR(paddr
);
396 for (i
= 0; i
< kmap_chunk_count
;){
397 unsigned long phys
= kmap_chunks
[i
++];
398 unsigned long size
= kmap_chunks
[i
++];
399 unsigned long virt
= kmap_chunks
[i
++];
401 && paddr
< (phys
+ size
)){
402 ret
= virt
+ paddr
- phys
;
407 ret
= (unsigned long) __va(paddr
);
411 printk ("PTOV(%lx)=%lx\n", paddr
, ret
);
416 int mm_end_of_chunk (unsigned long addr
, int len
)
418 if (memory
[0].addr
+ memory
[0].size
== addr
+ len
)
423 /*********************************************************** CACHE */
425 #define L1_CACHE_BYTES 32
426 #define MAX_CACHE_SIZE 8192
427 void cache_push(__u32 addr
, int length
)
429 addr
= mm_ptov(addr
);
431 if (MAX_CACHE_SIZE
< length
)
432 length
= MAX_CACHE_SIZE
;
435 __asm ("dcbf 0,%0\n\t"
437 addr
+= L1_CACHE_BYTES
;
438 length
-= L1_CACHE_BYTES
;
440 /* Also flush trailing block */
441 __asm ("dcbf 0,%0\n\t"
446 void cache_clear(__u32 addr
, int length
)
448 if (MAX_CACHE_SIZE
< length
)
449 length
= MAX_CACHE_SIZE
;
451 addr
= mm_ptov(addr
);
453 __asm ("dcbf 0,%0\n\t"
459 addr
+= L1_CACHE_BYTES
;
460 length
-= L1_CACHE_BYTES
;
463 __asm ("dcbf 0,%0\n\t"
468 addr
+= L1_CACHE_BYTES
;
469 length
-= L1_CACHE_BYTES
;
472 __asm ("dcbf 0,%0\n\t"
479 /****************************************************** from setup.c */
481 apus_restart(char *cmd
)
485 APUS_WRITE(APUS_REG_LOCK
,
486 REGLOCK_BLACKMAGICK1
|REGLOCK_BLACKMAGICK2
);
487 APUS_WRITE(APUS_REG_LOCK
,
488 REGLOCK_BLACKMAGICK1
|REGLOCK_BLACKMAGICK3
);
489 APUS_WRITE(APUS_REG_LOCK
,
490 REGLOCK_BLACKMAGICK2
|REGLOCK_BLACKMAGICK3
);
491 APUS_WRITE(APUS_REG_SHADOW
, REGSHADOW_SELFRESET
);
492 APUS_WRITE(APUS_REG_RESET
, REGRESET_AMIGARESET
);
508 /****************************************************** IRQ stuff */
510 static unsigned char last_ipl
[8];
512 int apus_get_irq(struct pt_regs
* regs
)
514 unsigned char ipl_emu
, mask
;
517 APUS_READ(APUS_IPL_EMU
, ipl_emu
);
518 level
= (ipl_emu
>> 3) & IPLEMU_IPLMASK
;
519 mask
= IPLEMU_SETRESET
|IPLEMU_DISABLEINT
|level
;
522 /* Save previous IPL value */
525 last_ipl
[level
] = ipl_emu
;
527 /* Set to current IPL value */
528 APUS_WRITE(APUS_IPL_EMU
, mask
);
529 APUS_WRITE(APUS_IPL_EMU
, IPLEMU_DISABLEINT
|level
);
532 #ifdef __INTERRUPT_DEBUG
533 printk("<%d:%d>", level
, ~ipl_emu
& IPLEMU_IPLMASK
);
535 return level
+ IRQ_AMIGA_AUTO
;
538 void apus_end_irq(unsigned int irq
)
540 unsigned char ipl_emu
;
541 unsigned int level
= irq
- IRQ_AMIGA_AUTO
;
542 #ifdef __INTERRUPT_DEBUG
543 printk("{%d}", ~last_ipl
[level
] & IPLEMU_IPLMASK
);
545 /* Restore IPL to the previous value */
546 ipl_emu
= last_ipl
[level
] & IPLEMU_IPLMASK
;
547 APUS_WRITE(APUS_IPL_EMU
, IPLEMU_SETRESET
|IPLEMU_DISABLEINT
|ipl_emu
);
550 APUS_WRITE(APUS_IPL_EMU
, IPLEMU_DISABLEINT
|ipl_emu
);
553 /****************************************************** debugging */
555 /* some serial hardware definitions */
556 #define SDR_OVRUN (1<<15)
557 #define SDR_RBF (1<<14)
558 #define SDR_TBE (1<<13)
559 #define SDR_TSRE (1<<12)
561 #define AC_SETCLR (1<<15)
562 #define AC_UARTBRK (1<<11)
564 #define SER_DTR (1<<7)
565 #define SER_RTS (1<<6)
566 #define SER_DCD (1<<5)
567 #define SER_CTS (1<<4)
568 #define SER_DSR (1<<3)
570 static __inline__
void ser_RTSon(void)
572 ciab
.pra
&= ~SER_RTS
; /* active low */
575 int __debug_ser_out( unsigned char c
)
577 custom
.serdat
= c
| 0x100;
579 while (!(custom
.serdatr
& 0x2000))
584 unsigned char __debug_ser_in( void )
588 /* XXX: is that ok?? derived from amiga_ser.c... */
589 while( !(custom
.intreqr
& IF_RBF
) )
592 /* clear the interrupt, so that another character can be read */
593 custom
.intreq
= IF_RBF
;
597 int __debug_serinit( void )
601 local_irq_save(flags
);
603 /* turn off Rx and Tx interrupts */
604 custom
.intena
= IF_RBF
| IF_TBE
;
606 /* clear any pending interrupt */
607 custom
.intreq
= IF_RBF
| IF_TBE
;
609 local_irq_restore(flags
);
612 * set the appropriate directions for the modem control flags,
613 * and clear RTS and DTR
615 ciab
.ddra
|= (SER_DTR
| SER_RTS
); /* outputs */
616 ciab
.ddra
&= ~(SER_DCD
| SER_CTS
| SER_DSR
); /* inputs */
619 /* turn Rx interrupts on for GDB */
620 custom
.intena
= IF_SETCLR
| IF_RBF
;
627 void __debug_print_hex(unsigned long x
)
630 char hexchars
[] = "0123456789ABCDEF";
632 for (i
= 0; i
< 8; i
++) {
633 __debug_ser_out(hexchars
[(x
>> 28) & 15]);
636 __debug_ser_out('\n');
637 __debug_ser_out('\r');
640 void __debug_print_string(char* s
)
645 __debug_ser_out('\n');
646 __debug_ser_out('\r');
649 static void apus_progress(char *s
, unsigned short value
)
651 __debug_print_string(s
);
654 /****************************************************** init */
656 /* The number of spurious interrupts */
657 volatile unsigned int num_spurious
;
659 extern struct irqaction amiga_sys_irqaction
[AUTO_IRQS
];
662 extern void amiga_enable_irq(unsigned int irq
);
663 extern void amiga_disable_irq(unsigned int irq
);
665 struct hw_interrupt_type amiga_sys_irqctrl
= {
666 .typename
= "Amiga IPL",
670 struct hw_interrupt_type amiga_irqctrl
= {
671 .typename
= "Amiga ",
672 .enable
= amiga_enable_irq
,
673 .disable
= amiga_disable_irq
,
676 #define HARDWARE_MAPPED_SIZE (512*1024)
677 unsigned long __init
apus_find_end_of_memory(void)
682 /* The memory size reported by ADOS excludes the 512KB
683 reserved for PPC exception registers and possibly 512KB
684 containing a shadow of the ADOS ROM. */
686 unsigned long size
= memory
[0].size
;
688 /* If 2MB aligned, size was probably user
689 specified. We can't tell anything about shadowing
690 in this case so skip shadow assignment. */
691 if (0 != (size
& 0x1fffff)){
692 /* Align to 512KB to ensure correct handling
693 of both memfile and system specified
695 size
= ((size
+0x0007ffff) & 0xfff80000);
696 /* If memory is 1MB aligned, assume
698 shadow
= !(size
& 0x80000);
701 /* Add the chunk that ADOS does not see. by aligning
702 the size to the nearest 2MB limit upwards. */
703 memory
[0].size
= ((size
+0x001fffff) & 0xffe00000);
706 ppc_memstart
= memory
[0].addr
;
707 ppc_memoffset
= PAGE_OFFSET
- PPC_MEMSTART
;
708 total
= memory
[0].size
;
710 /* Remove the memory chunks that are controlled by special
713 /* Remove the upper 512KB if it contains a shadow of
714 the ADOS ROM. FIXME: It might be possible to
715 disable this shadow HW. Check the booter
718 total
-= HARDWARE_MAPPED_SIZE
;
720 /* Remove the upper 512KB where the PPC exception
721 vectors are mapped. */
722 total
-= HARDWARE_MAPPED_SIZE
;
724 /* Linux/APUS only handles one block of memory -- the one on
725 the PowerUP board. Other system memory is horrible slow in
726 comparison. The user can use other memory for swapping
727 using the z2ram device. */
734 /* Map PPC exception vectors. */
735 io_block_mapping(0xfff00000, 0xfff00000, 0x00020000, _PAGE_KERNEL
);
736 /* Map chip and ZorroII memory */
737 io_block_mapping(zTwoBase
, 0x00000000, 0x01000000, _PAGE_IO
);
741 void apus_init_IRQ(void)
743 struct irqaction
*action
;
747 apus_setup_pci_ptrs();
750 for ( i
= 0 ; i
< AMI_IRQS
; i
++ ) {
751 irq_desc
[i
].status
= IRQ_LEVEL
;
752 if (i
< IRQ_AMIGA_AUTO
) {
753 irq_desc
[i
].handler
= &amiga_irqctrl
;
755 irq_desc
[i
].handler
= &amiga_sys_irqctrl
;
756 action
= &amiga_sys_irqaction
[i
-IRQ_AMIGA_AUTO
];
758 setup_irq(i
, action
);
767 void platform_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
768 unsigned long r6
, unsigned long r7
)
770 extern int parse_bootinfo(const struct bi_record
*);
773 /* Parse bootinfo. The bootinfo is located right after
775 parse_bootinfo((const struct bi_record
*)&_end
);
776 #ifdef CONFIG_BLK_DEV_INITRD
777 /* Take care of initrd if we have one. Use data from
778 bootinfo to avoid the need to initialize PPC
779 registers when kernel is booted via a PPC reset. */
780 if ( ramdisk
.addr
) {
781 initrd_start
= (unsigned long) __va(ramdisk
.addr
);
782 initrd_end
= (unsigned long)
783 __va(ramdisk
.size
+ ramdisk
.addr
);
785 #endif /* CONFIG_BLK_DEV_INITRD */
787 ISA_DMA_THRESHOLD
= 0x00ffffff;
789 ppc_md
.setup_arch
= apus_setup_arch
;
790 ppc_md
.show_cpuinfo
= apus_show_cpuinfo
;
791 ppc_md
.init_IRQ
= apus_init_IRQ
;
792 ppc_md
.get_irq
= apus_get_irq
;
794 #ifdef CONFIG_HEARTBEAT
795 ppc_md
.heartbeat
= apus_heartbeat
;
796 ppc_md
.heartbeat_count
= 1;
800 ppc_md
.progress
= apus_progress
;
804 ppc_md
.restart
= apus_restart
;
805 ppc_md
.power_off
= apus_power_off
;
806 ppc_md
.halt
= apus_halt
;
808 ppc_md
.time_init
= NULL
;
809 ppc_md
.set_rtc_time
= apus_set_rtc_time
;
810 ppc_md
.get_rtc_time
= apus_get_rtc_time
;
811 ppc_md
.calibrate_decr
= apus_calibrate_decr
;
813 ppc_md
.find_end_of_memory
= apus_find_end_of_memory
;
814 ppc_md
.setup_io_mappings
= apus_map_io
;