diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/ppc/platforms/apus_setup.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/ppc/platforms/apus_setup.c')
-rw-r--r-- | arch/ppc/platforms/apus_setup.c | 815 |
1 files changed, 815 insertions, 0 deletions
diff --git a/arch/ppc/platforms/apus_setup.c b/arch/ppc/platforms/apus_setup.c new file mode 100644 index 000000000000..2f74fde98ebc --- /dev/null +++ b/arch/ppc/platforms/apus_setup.c | |||
@@ -0,0 +1,815 @@ | |||
1 | /* | ||
2 | * arch/ppc/platforms/apus_setup.c | ||
3 | * | ||
4 | * Copyright (C) 1998, 1999 Jesper Skov | ||
5 | * | ||
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. | ||
9 | * | ||
10 | * TODO: | ||
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. | ||
14 | */ | ||
15 | |||
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> | ||
22 | |||
23 | /* Needs INITSERIAL call in head.S! */ | ||
24 | #undef APUS_DEBUG | ||
25 | |||
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> | ||
32 | #include <asm/dma.h> | ||
33 | #include <asm/machdep.h> | ||
34 | #include <asm/time.h> | ||
35 | |||
36 | unsigned long m68k_machtype; | ||
37 | char debug_device[6] = ""; | ||
38 | |||
39 | extern void amiga_init_IRQ(void); | ||
40 | |||
41 | extern void apus_setup_pci_ptrs(void); | ||
42 | |||
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; | ||
60 | #endif | ||
61 | #ifdef CONFIG_HEARTBEAT | ||
62 | void (*mach_heartbeat) (int) = NULL; | ||
63 | extern void apus_heartbeat (void); | ||
64 | #endif | ||
65 | |||
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 */ | ||
70 | |||
71 | int num_memory = 0; | ||
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 */ | ||
76 | |||
77 | struct mem_info ramdisk; | ||
78 | |||
79 | extern void amiga_floppy_setup(char *, int *); | ||
80 | extern void config_amiga(void); | ||
81 | |||
82 | static int __60nsram = 0; | ||
83 | |||
84 | /* for cpuinfo */ | ||
85 | static int __bus_speed = 0; | ||
86 | static int __speed_test_failed = 0; | ||
87 | |||
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. | ||
92 | */ | ||
93 | unsigned long apus_get_rtc_time(void) | ||
94 | { | ||
95 | #ifdef CONFIG_APUS | ||
96 | extern unsigned long m68k_get_rtc_time(void); | ||
97 | |||
98 | return m68k_get_rtc_time (); | ||
99 | #else | ||
100 | return 0; | ||
101 | #endif | ||
102 | } | ||
103 | |||
104 | int apus_set_rtc_time(unsigned long nowtime) | ||
105 | { | ||
106 | #ifdef CONFIG_APUS | ||
107 | extern int m68k_set_rtc_time(unsigned long nowtime); | ||
108 | |||
109 | return m68k_set_rtc_time (nowtime); | ||
110 | #else | ||
111 | return 0; | ||
112 | #endif | ||
113 | } | ||
114 | |||
115 | /*********************************************************** SETUP */ | ||
116 | /* From arch/m68k/kernel/setup.c. */ | ||
117 | void __init apus_setup_arch(void) | ||
118 | { | ||
119 | #ifdef CONFIG_APUS | ||
120 | extern char cmd_line[]; | ||
121 | int i; | ||
122 | char *p, *q; | ||
123 | |||
124 | /* Let m68k-shared code know it should do the Amiga thing. */ | ||
125 | m68k_machtype = MACH_AMIGA; | ||
126 | |||
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; ) { | ||
131 | i = 0; | ||
132 | if (!strncmp( p, "debug=", 6 )) { | ||
133 | strlcpy( debug_device, p+6, sizeof(debug_device) ); | ||
134 | if ((q = strchr( debug_device, ' ' ))) *q = 0; | ||
135 | i = 1; | ||
136 | } else if (!strncmp( p, "60nsram", 7 )) { | ||
137 | APUS_WRITE (APUS_REG_WAITSTATE, | ||
138 | REGWAITSTATE_SETRESET | ||
139 | |REGWAITSTATE_PPCR | ||
140 | |REGWAITSTATE_PPCW); | ||
141 | __60nsram = 1; | ||
142 | i = 1; | ||
143 | } | ||
144 | |||
145 | if (i) { | ||
146 | /* option processed, delete it */ | ||
147 | if ((q = strchr( p, ' ' ))) | ||
148 | strcpy( p, q+1 ); | ||
149 | else | ||
150 | *p = 0; | ||
151 | } else { | ||
152 | if ((p = strchr( p, ' ' ))) ++p; | ||
153 | } | ||
154 | } | ||
155 | |||
156 | config_amiga(); | ||
157 | |||
158 | #if 0 /* Enable for logging - also include logging.o in Makefile rule */ | ||
159 | { | ||
160 | #define LOG_SIZE 4096 | ||
161 | void* base; | ||
162 | |||
163 | /* Throw away some memory - the P5 firmare stomps on top | ||
164 | * of CHIP memory during bootup. | ||
165 | */ | ||
166 | amiga_chip_alloc(0x1000); | ||
167 | |||
168 | base = amiga_chip_alloc(LOG_SIZE+sizeof(klog_data_t)); | ||
169 | LOG_INIT(base, base+sizeof(klog_data_t), LOG_SIZE); | ||
170 | } | ||
171 | #endif | ||
172 | #endif | ||
173 | } | ||
174 | |||
175 | int | ||
176 | apus_show_cpuinfo(struct seq_file *m) | ||
177 | { | ||
178 | extern int __map_without_bats; | ||
179 | extern unsigned long powerup_PCI_present; | ||
180 | |||
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"); | ||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | static void get_current_tb(unsigned long long *time) | ||
193 | { | ||
194 | __asm __volatile ("1:mftbu 4 \n\t" | ||
195 | " mftb 5 \n\t" | ||
196 | " mftbu 6 \n\t" | ||
197 | " cmpw 4,6 \n\t" | ||
198 | " bne 1b \n\t" | ||
199 | " stw 4,0(%0)\n\t" | ||
200 | " stw 5,4(%0)\n\t" | ||
201 | : | ||
202 | : "r" (time) | ||
203 | : "r4", "r5", "r6"); | ||
204 | } | ||
205 | |||
206 | |||
207 | void apus_calibrate_decr(void) | ||
208 | { | ||
209 | #ifdef CONFIG_APUS | ||
210 | unsigned long freq; | ||
211 | |||
212 | /* This algorithm for determining the bus speed was | ||
213 | contributed by Ralph Schmidt. */ | ||
214 | unsigned long long start, stop; | ||
215 | int bus_speed; | ||
216 | int speed_test_failed = 0; | ||
217 | |||
218 | { | ||
219 | unsigned long loop = amiga_eclock / 10; | ||
220 | |||
221 | get_current_tb (&start); | ||
222 | while (loop--) { | ||
223 | unsigned char tmp; | ||
224 | |||
225 | tmp = ciaa.pra; | ||
226 | } | ||
227 | get_current_tb (&stop); | ||
228 | } | ||
229 | |||
230 | bus_speed = (((unsigned long)(stop-start))*10*4) / 1000000; | ||
231 | if (AMI_1200 == amiga_model) | ||
232 | bus_speed /= 2; | ||
233 | |||
234 | if ((bus_speed >= 47) && (bus_speed < 53)) { | ||
235 | bus_speed = 50; | ||
236 | freq = 12500000; | ||
237 | } else if ((bus_speed >= 57) && (bus_speed < 63)) { | ||
238 | bus_speed = 60; | ||
239 | freq = 15000000; | ||
240 | } else if ((bus_speed >= 63) && (bus_speed < 69)) { | ||
241 | bus_speed = 67; | ||
242 | freq = 16666667; | ||
243 | } else { | ||
244 | printk ("APUS: Unable to determine bus speed (%d). " | ||
245 | "Defaulting to 50MHz", bus_speed); | ||
246 | bus_speed = 50; | ||
247 | freq = 12500000; | ||
248 | speed_test_failed = 1; | ||
249 | } | ||
250 | |||
251 | /* Ease diagnostics... */ | ||
252 | { | ||
253 | extern int __map_without_bats; | ||
254 | extern unsigned long powerup_PCI_present; | ||
255 | |||
256 | printk ("APUS: BATs=%d, BUS=%dMHz", | ||
257 | (__map_without_bats) ? 0 : 1, | ||
258 | bus_speed); | ||
259 | if (speed_test_failed) | ||
260 | printk ("[FAILED - please report]"); | ||
261 | |||
262 | printk (", RAM=%dns, PCI bridge=%d\n", | ||
263 | (__60nsram) ? 60 : 70, | ||
264 | (powerup_PCI_present) ? 1 : 0); | ||
265 | |||
266 | /* print a bit more if asked politely... */ | ||
267 | if (!(ciaa.pra & 0x40)){ | ||
268 | extern unsigned int bat_addrs[4][3]; | ||
269 | int b; | ||
270 | for (b = 0; b < 4; ++b) { | ||
271 | printk ("APUS: BAT%d ", b); | ||
272 | printk ("%08x-%08x -> %08x\n", | ||
273 | bat_addrs[b][0], | ||
274 | bat_addrs[b][1], | ||
275 | bat_addrs[b][2]); | ||
276 | } | ||
277 | } | ||
278 | |||
279 | } | ||
280 | |||
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); | ||
285 | |||
286 | __bus_speed = bus_speed; | ||
287 | __speed_test_failed = speed_test_failed; | ||
288 | #endif | ||
289 | } | ||
290 | |||
291 | void arch_gettod(int *year, int *mon, int *day, int *hour, | ||
292 | int *min, int *sec) | ||
293 | { | ||
294 | #ifdef CONFIG_APUS | ||
295 | if (mach_gettod) | ||
296 | mach_gettod(year, mon, day, hour, min, sec); | ||
297 | else | ||
298 | *year = *mon = *day = *hour = *min = *sec = 0; | ||
299 | #endif | ||
300 | } | ||
301 | |||
302 | /* for "kbd-reset" cmdline param */ | ||
303 | __init | ||
304 | void kbd_reset_setup(char *str, int *ints) | ||
305 | { | ||
306 | } | ||
307 | |||
308 | /*********************************************************** FLOPPY */ | ||
309 | #if defined(CONFIG_AMIGA_FLOPPY) | ||
310 | __init | ||
311 | void floppy_setup(char *str, int *ints) | ||
312 | { | ||
313 | if (mach_floppy_setup) | ||
314 | mach_floppy_setup (str, ints); | ||
315 | } | ||
316 | #endif | ||
317 | |||
318 | /*********************************************************** MEMORY */ | ||
319 | #define KMAP_MAX 32 | ||
320 | unsigned long kmap_chunks[KMAP_MAX*3]; | ||
321 | int kmap_chunk_count = 0; | ||
322 | |||
323 | /* From pgtable.h */ | ||
324 | static __inline__ pte_t *my_find_pte(struct mm_struct *mm,unsigned long va) | ||
325 | { | ||
326 | pgd_t *dir = 0; | ||
327 | pmd_t *pmd = 0; | ||
328 | pte_t *pte = 0; | ||
329 | |||
330 | va &= PAGE_MASK; | ||
331 | |||
332 | dir = pgd_offset( mm, va ); | ||
333 | if (dir) | ||
334 | { | ||
335 | pmd = pmd_offset(dir, va & PAGE_MASK); | ||
336 | if (pmd && pmd_present(*pmd)) | ||
337 | { | ||
338 | pte = pte_offset(pmd, va); | ||
339 | } | ||
340 | } | ||
341 | return pte; | ||
342 | } | ||
343 | |||
344 | |||
345 | /* Again simulating an m68k/mm/kmap.c function. */ | ||
346 | void kernel_set_cachemode( unsigned long address, unsigned long size, | ||
347 | unsigned int cmode ) | ||
348 | { | ||
349 | unsigned long mask, flags; | ||
350 | |||
351 | switch (cmode) | ||
352 | { | ||
353 | case IOMAP_FULL_CACHING: | ||
354 | mask = ~(_PAGE_NO_CACHE | _PAGE_GUARDED); | ||
355 | flags = 0; | ||
356 | break; | ||
357 | case IOMAP_NOCACHE_SER: | ||
358 | mask = ~0; | ||
359 | flags = (_PAGE_NO_CACHE | _PAGE_GUARDED); | ||
360 | break; | ||
361 | default: | ||
362 | panic ("kernel_set_cachemode() doesn't support mode %d\n", | ||
363 | cmode); | ||
364 | break; | ||
365 | } | ||
366 | |||
367 | size /= PAGE_SIZE; | ||
368 | address &= PAGE_MASK; | ||
369 | while (size--) | ||
370 | { | ||
371 | pte_t *pte; | ||
372 | |||
373 | pte = my_find_pte(&init_mm, address); | ||
374 | if ( !pte ) | ||
375 | { | ||
376 | printk("pte NULL in kernel_set_cachemode()\n"); | ||
377 | return; | ||
378 | } | ||
379 | |||
380 | pte_val (*pte) &= mask; | ||
381 | pte_val (*pte) |= flags; | ||
382 | flush_tlb_page(find_vma(&init_mm,address),address); | ||
383 | |||
384 | address += PAGE_SIZE; | ||
385 | } | ||
386 | } | ||
387 | |||
388 | unsigned long mm_ptov (unsigned long paddr) | ||
389 | { | ||
390 | unsigned long ret; | ||
391 | if (paddr < 16*1024*1024) | ||
392 | ret = ZTWO_VADDR(paddr); | ||
393 | else { | ||
394 | int i; | ||
395 | |||
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++]; | ||
400 | if (paddr >= phys | ||
401 | && paddr < (phys + size)){ | ||
402 | ret = virt + paddr - phys; | ||
403 | goto exit; | ||
404 | } | ||
405 | } | ||
406 | |||
407 | ret = (unsigned long) __va(paddr); | ||
408 | } | ||
409 | exit: | ||
410 | #ifdef DEBUGPV | ||
411 | printk ("PTOV(%lx)=%lx\n", paddr, ret); | ||
412 | #endif | ||
413 | return ret; | ||
414 | } | ||
415 | |||
416 | int mm_end_of_chunk (unsigned long addr, int len) | ||
417 | { | ||
418 | if (memory[0].addr + memory[0].size == addr + len) | ||
419 | return 1; | ||
420 | return 0; | ||
421 | } | ||
422 | |||
423 | /*********************************************************** CACHE */ | ||
424 | |||
425 | #define L1_CACHE_BYTES 32 | ||
426 | #define MAX_CACHE_SIZE 8192 | ||
427 | void cache_push(__u32 addr, int length) | ||
428 | { | ||
429 | addr = mm_ptov(addr); | ||
430 | |||
431 | if (MAX_CACHE_SIZE < length) | ||
432 | length = MAX_CACHE_SIZE; | ||
433 | |||
434 | while(length > 0){ | ||
435 | __asm ("dcbf 0,%0\n\t" | ||
436 | : : "r" (addr)); | ||
437 | addr += L1_CACHE_BYTES; | ||
438 | length -= L1_CACHE_BYTES; | ||
439 | } | ||
440 | /* Also flush trailing block */ | ||
441 | __asm ("dcbf 0,%0\n\t" | ||
442 | "sync \n\t" | ||
443 | : : "r" (addr)); | ||
444 | } | ||
445 | |||
446 | void cache_clear(__u32 addr, int length) | ||
447 | { | ||
448 | if (MAX_CACHE_SIZE < length) | ||
449 | length = MAX_CACHE_SIZE; | ||
450 | |||
451 | addr = mm_ptov(addr); | ||
452 | |||
453 | __asm ("dcbf 0,%0\n\t" | ||
454 | "sync \n\t" | ||
455 | "icbi 0,%0 \n\t" | ||
456 | "isync \n\t" | ||
457 | : : "r" (addr)); | ||
458 | |||
459 | addr += L1_CACHE_BYTES; | ||
460 | length -= L1_CACHE_BYTES; | ||
461 | |||
462 | while(length > 0){ | ||
463 | __asm ("dcbf 0,%0\n\t" | ||
464 | "sync \n\t" | ||
465 | "icbi 0,%0 \n\t" | ||
466 | "isync \n\t" | ||
467 | : : "r" (addr)); | ||
468 | addr += L1_CACHE_BYTES; | ||
469 | length -= L1_CACHE_BYTES; | ||
470 | } | ||
471 | |||
472 | __asm ("dcbf 0,%0\n\t" | ||
473 | "sync \n\t" | ||
474 | "icbi 0,%0 \n\t" | ||
475 | "isync \n\t" | ||
476 | : : "r" (addr)); | ||
477 | } | ||
478 | |||
479 | /****************************************************** from setup.c */ | ||
480 | void | ||
481 | apus_restart(char *cmd) | ||
482 | { | ||
483 | local_irq_disable(); | ||
484 | |||
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); | ||
493 | for(;;); | ||
494 | } | ||
495 | |||
496 | void | ||
497 | apus_power_off(void) | ||
498 | { | ||
499 | for (;;); | ||
500 | } | ||
501 | |||
502 | void | ||
503 | apus_halt(void) | ||
504 | { | ||
505 | apus_restart(NULL); | ||
506 | } | ||
507 | |||
508 | /****************************************************** IRQ stuff */ | ||
509 | |||
510 | static unsigned char last_ipl[8]; | ||
511 | |||
512 | int apus_get_irq(struct pt_regs* regs) | ||
513 | { | ||
514 | unsigned char ipl_emu, mask; | ||
515 | unsigned int level; | ||
516 | |||
517 | APUS_READ(APUS_IPL_EMU, ipl_emu); | ||
518 | level = (ipl_emu >> 3) & IPLEMU_IPLMASK; | ||
519 | mask = IPLEMU_SETRESET|IPLEMU_DISABLEINT|level; | ||
520 | level ^= 7; | ||
521 | |||
522 | /* Save previous IPL value */ | ||
523 | if (last_ipl[level]) | ||
524 | return -2; | ||
525 | last_ipl[level] = ipl_emu; | ||
526 | |||
527 | /* Set to current IPL value */ | ||
528 | APUS_WRITE(APUS_IPL_EMU, mask); | ||
529 | APUS_WRITE(APUS_IPL_EMU, IPLEMU_DISABLEINT|level); | ||
530 | |||
531 | |||
532 | #ifdef __INTERRUPT_DEBUG | ||
533 | printk("<%d:%d>", level, ~ipl_emu & IPLEMU_IPLMASK); | ||
534 | #endif | ||
535 | return level + IRQ_AMIGA_AUTO; | ||
536 | } | ||
537 | |||
538 | void apus_end_irq(unsigned int irq) | ||
539 | { | ||
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); | ||
544 | #endif | ||
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); | ||
548 | last_ipl[level] = 0; | ||
549 | ipl_emu ^= 7; | ||
550 | APUS_WRITE(APUS_IPL_EMU, IPLEMU_DISABLEINT|ipl_emu); | ||
551 | } | ||
552 | |||
553 | /****************************************************** debugging */ | ||
554 | |||
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) | ||
560 | |||
561 | #define AC_SETCLR (1<<15) | ||
562 | #define AC_UARTBRK (1<<11) | ||
563 | |||
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) | ||
569 | |||
570 | static __inline__ void ser_RTSon(void) | ||
571 | { | ||
572 | ciab.pra &= ~SER_RTS; /* active low */ | ||
573 | } | ||
574 | |||
575 | int __debug_ser_out( unsigned char c ) | ||
576 | { | ||
577 | custom.serdat = c | 0x100; | ||
578 | mb(); | ||
579 | while (!(custom.serdatr & 0x2000)) | ||
580 | barrier(); | ||
581 | return 1; | ||
582 | } | ||
583 | |||
584 | unsigned char __debug_ser_in( void ) | ||
585 | { | ||
586 | unsigned char c; | ||
587 | |||
588 | /* XXX: is that ok?? derived from amiga_ser.c... */ | ||
589 | while( !(custom.intreqr & IF_RBF) ) | ||
590 | barrier(); | ||
591 | c = custom.serdatr; | ||
592 | /* clear the interrupt, so that another character can be read */ | ||
593 | custom.intreq = IF_RBF; | ||
594 | return c; | ||
595 | } | ||
596 | |||
597 | int __debug_serinit( void ) | ||
598 | { | ||
599 | unsigned long flags; | ||
600 | |||
601 | local_irq_save(flags); | ||
602 | |||
603 | /* turn off Rx and Tx interrupts */ | ||
604 | custom.intena = IF_RBF | IF_TBE; | ||
605 | |||
606 | /* clear any pending interrupt */ | ||
607 | custom.intreq = IF_RBF | IF_TBE; | ||
608 | |||
609 | local_irq_restore(flags); | ||
610 | |||
611 | /* | ||
612 | * set the appropriate directions for the modem control flags, | ||
613 | * and clear RTS and DTR | ||
614 | */ | ||
615 | ciab.ddra |= (SER_DTR | SER_RTS); /* outputs */ | ||
616 | ciab.ddra &= ~(SER_DCD | SER_CTS | SER_DSR); /* inputs */ | ||
617 | |||
618 | #ifdef CONFIG_KGDB | ||
619 | /* turn Rx interrupts on for GDB */ | ||
620 | custom.intena = IF_SETCLR | IF_RBF; | ||
621 | ser_RTSon(); | ||
622 | #endif | ||
623 | |||
624 | return 0; | ||
625 | } | ||
626 | |||
627 | void __debug_print_hex(unsigned long x) | ||
628 | { | ||
629 | int i; | ||
630 | char hexchars[] = "0123456789ABCDEF"; | ||
631 | |||
632 | for (i = 0; i < 8; i++) { | ||
633 | __debug_ser_out(hexchars[(x >> 28) & 15]); | ||
634 | x <<= 4; | ||
635 | } | ||
636 | __debug_ser_out('\n'); | ||
637 | __debug_ser_out('\r'); | ||
638 | } | ||
639 | |||
640 | void __debug_print_string(char* s) | ||
641 | { | ||
642 | unsigned char c; | ||
643 | while((c = *s++)) | ||
644 | __debug_ser_out(c); | ||
645 | __debug_ser_out('\n'); | ||
646 | __debug_ser_out('\r'); | ||
647 | } | ||
648 | |||
649 | static void apus_progress(char *s, unsigned short value) | ||
650 | { | ||
651 | __debug_print_string(s); | ||
652 | } | ||
653 | |||
654 | /****************************************************** init */ | ||
655 | |||
656 | /* The number of spurious interrupts */ | ||
657 | volatile unsigned int num_spurious; | ||
658 | |||
659 | extern struct irqaction amiga_sys_irqaction[AUTO_IRQS]; | ||
660 | |||
661 | |||
662 | extern void amiga_enable_irq(unsigned int irq); | ||
663 | extern void amiga_disable_irq(unsigned int irq); | ||
664 | |||
665 | struct hw_interrupt_type amiga_sys_irqctrl = { | ||
666 | .typename = "Amiga IPL", | ||
667 | .end = apus_end_irq, | ||
668 | }; | ||
669 | |||
670 | struct hw_interrupt_type amiga_irqctrl = { | ||
671 | .typename = "Amiga ", | ||
672 | .enable = amiga_enable_irq, | ||
673 | .disable = amiga_disable_irq, | ||
674 | }; | ||
675 | |||
676 | #define HARDWARE_MAPPED_SIZE (512*1024) | ||
677 | unsigned long __init apus_find_end_of_memory(void) | ||
678 | { | ||
679 | int shadow = 0; | ||
680 | unsigned long total; | ||
681 | |||
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. */ | ||
685 | { | ||
686 | unsigned long size = memory[0].size; | ||
687 | |||
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 | ||
694 | sizes. */ | ||
695 | size = ((size+0x0007ffff) & 0xfff80000); | ||
696 | /* If memory is 1MB aligned, assume | ||
697 | shadowing. */ | ||
698 | shadow = !(size & 0x80000); | ||
699 | } | ||
700 | |||
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); | ||
704 | } | ||
705 | |||
706 | ppc_memstart = memory[0].addr; | ||
707 | ppc_memoffset = PAGE_OFFSET - PPC_MEMSTART; | ||
708 | total = memory[0].size; | ||
709 | |||
710 | /* Remove the memory chunks that are controlled by special | ||
711 | Phase5 hardware. */ | ||
712 | |||
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 | ||
716 | (ppc_boot.c) */ | ||
717 | if (shadow) | ||
718 | total -= HARDWARE_MAPPED_SIZE; | ||
719 | |||
720 | /* Remove the upper 512KB where the PPC exception | ||
721 | vectors are mapped. */ | ||
722 | total -= HARDWARE_MAPPED_SIZE; | ||
723 | |||
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. */ | ||
728 | return total; | ||
729 | } | ||
730 | |||
731 | static void __init | ||
732 | apus_map_io(void) | ||
733 | { | ||
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); | ||
738 | } | ||
739 | |||
740 | __init | ||
741 | void apus_init_IRQ(void) | ||
742 | { | ||
743 | struct irqaction *action; | ||
744 | int i; | ||
745 | |||
746 | #ifdef CONFIG_PCI | ||
747 | apus_setup_pci_ptrs(); | ||
748 | #endif | ||
749 | |||
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; | ||
754 | } else { | ||
755 | irq_desc[i].handler = &amiga_sys_irqctrl; | ||
756 | action = &amiga_sys_irqaction[i-IRQ_AMIGA_AUTO]; | ||
757 | if (action->name) | ||
758 | setup_irq(i, action); | ||
759 | } | ||
760 | } | ||
761 | |||
762 | amiga_init_IRQ(); | ||
763 | |||
764 | } | ||
765 | |||
766 | __init | ||
767 | void platform_init(unsigned long r3, unsigned long r4, unsigned long r5, | ||
768 | unsigned long r6, unsigned long r7) | ||
769 | { | ||
770 | extern int parse_bootinfo(const struct bi_record *); | ||
771 | extern char _end[]; | ||
772 | |||
773 | /* Parse bootinfo. The bootinfo is located right after | ||
774 | the kernel bss */ | ||
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); | ||
784 | } | ||
785 | #endif /* CONFIG_BLK_DEV_INITRD */ | ||
786 | |||
787 | ISA_DMA_THRESHOLD = 0x00ffffff; | ||
788 | |||
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; | ||
793 | |||
794 | #ifdef CONFIG_HEARTBEAT | ||
795 | ppc_md.heartbeat = apus_heartbeat; | ||
796 | ppc_md.heartbeat_count = 1; | ||
797 | #endif | ||
798 | #ifdef APUS_DEBUG | ||
799 | __debug_serinit(); | ||
800 | ppc_md.progress = apus_progress; | ||
801 | #endif | ||
802 | ppc_md.init = NULL; | ||
803 | |||
804 | ppc_md.restart = apus_restart; | ||
805 | ppc_md.power_off = apus_power_off; | ||
806 | ppc_md.halt = apus_halt; | ||
807 | |||
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; | ||
812 | |||
813 | ppc_md.find_end_of_memory = apus_find_end_of_memory; | ||
814 | ppc_md.setup_io_mappings = apus_map_io; | ||
815 | } | ||