File: /usr/src/linux/arch/ppc/kernel/chrp_setup.c
1 /*
2 * BK Id: SCCS/s.chrp_setup.c 1.36 09/08/01 15:47:42 paulus
3 */
4 /*
5 * linux/arch/ppc/kernel/setup.c
6 *
7 * Copyright (C) 1995 Linus Torvalds
8 * Adapted from 'alpha' version by Gary Thomas
9 * Modified by Cort Dougan (cort@cs.nmt.edu)
10 */
11
12 /*
13 * bootup setup stuff..
14 */
15
16 #include <linux/config.h>
17 #include <linux/errno.h>
18 #include <linux/sched.h>
19 #include <linux/kernel.h>
20 #include <linux/mm.h>
21 #include <linux/stddef.h>
22 #include <linux/unistd.h>
23 #include <linux/ptrace.h>
24 #include <linux/slab.h>
25 #include <linux/user.h>
26 #include <linux/a.out.h>
27 #include <linux/tty.h>
28 #include <linux/major.h>
29 #include <linux/interrupt.h>
30 #include <linux/reboot.h>
31 #include <linux/init.h>
32 #include <linux/blk.h>
33 #include <linux/ioport.h>
34 #include <linux/console.h>
35 #include <linux/pci.h>
36 #include <linux/version.h>
37 #include <linux/adb.h>
38 #include <linux/module.h>
39 #include <linux/delay.h>
40 #include <linux/ide.h>
41
42 #include <asm/mmu.h>
43 #include <asm/processor.h>
44 #include <asm/io.h>
45 #include <asm/pgtable.h>
46 #include <asm/prom.h>
47 #include <asm/gg2.h>
48 #include <asm/pci-bridge.h>
49 #include <asm/dma.h>
50 #include <asm/machdep.h>
51 #include <asm/irq.h>
52 #include <asm/hydra.h>
53 #include <asm/keyboard.h>
54 #include <asm/sections.h>
55 #include <asm/time.h>
56 #include <asm/btext.h>
57
58 #include "local_irq.h"
59 #include "i8259.h"
60 #include "open_pic.h"
61 #include "xics.h"
62
63 unsigned long chrp_get_rtc_time(void);
64 int chrp_set_rtc_time(unsigned long nowtime);
65 void chrp_calibrate_decr(void);
66 long chrp_time_init(void);
67
68 void chrp_find_bridges(void);
69 void chrp_event_scan(void);
70 void rtas_display_progress(char *, unsigned short);
71 void rtas_indicator_progress(char *, unsigned short);
72 void btext_progress(char *, unsigned short);
73
74 extern unsigned long pmac_find_end_of_memory(void);
75 extern int pckbd_setkeycode(unsigned int scancode, unsigned int keycode);
76 extern int pckbd_getkeycode(unsigned int scancode);
77 extern int pckbd_translate(unsigned char scancode, unsigned char *keycode,
78 char raw_mode);
79 extern char pckbd_unexpected_up(unsigned char keycode);
80 extern void pckbd_leds(unsigned char leds);
81 extern void pckbd_init_hw(void);
82 extern unsigned char pckbd_sysrq_xlate[128];
83 extern void select_adb_keyboard(void);
84
85 extern kdev_t boot_dev;
86
87 extern PTE *Hash, *Hash_end;
88 extern unsigned long Hash_size, Hash_mask;
89 extern int probingmem;
90 extern unsigned long loops_per_jiffy;
91 static int max_width;
92
93 #ifdef CONFIG_SMP
94 extern struct smp_ops_t chrp_smp_ops;
95 extern struct smp_ops_t xics_smp_ops;
96 #endif
97
98 static const char *gg2_memtypes[4] = {
99 "FPM", "SDRAM", "EDO", "BEDO"
100 };
101 static const char *gg2_cachesizes[4] = {
102 "256 KB", "512 KB", "1 MB", "Reserved"
103 };
104 static const char *gg2_cachetypes[4] = {
105 "Asynchronous", "Reserved", "Flow-Through Synchronous",
106 "Pipelined Synchronous"
107 };
108 static const char *gg2_cachemodes[4] = {
109 "Disabled", "Write-Through", "Copy-Back", "Transparent Mode"
110 };
111
112 int __chrp
113 chrp_get_cpuinfo(char *buffer)
114 {
115 int i, len, sdramen;
116 unsigned int t;
117 struct device_node *root;
118 const char *model = "";
119
120 root = find_path_device("/");
121 if (root)
122 model = get_property(root, "model", NULL);
123 len = sprintf(buffer,"machine\t\t: CHRP %s\n", model);
124
125 /* longtrail (goldengate) stuff */
126 if ( !strncmp( model, "IBM,LongTrail", 13 ) )
127 {
128 /* VLSI VAS96011/12 `Golden Gate 2' */
129 /* Memory banks */
130 sdramen = (in_le32((unsigned *)(GG2_PCI_CONFIG_BASE+
131 GG2_PCI_DRAM_CTRL))
132 >>31) & 1;
133 for (i = 0; i < (sdramen ? 4 : 6); i++) {
134 t = in_le32((unsigned *)(GG2_PCI_CONFIG_BASE+
135 GG2_PCI_DRAM_BANK0+
136 i*4));
137 if (!(t & 1))
138 continue;
139 switch ((t>>8) & 0x1f) {
140 case 0x1f:
141 model = "4 MB";
142 break;
143 case 0x1e:
144 model = "8 MB";
145 break;
146 case 0x1c:
147 model = "16 MB";
148 break;
149 case 0x18:
150 model = "32 MB";
151 break;
152 case 0x10:
153 model = "64 MB";
154 break;
155 case 0x00:
156 model = "128 MB";
157 break;
158 default:
159 model = "Reserved";
160 break;
161 }
162 len += sprintf(buffer+len, "memory bank %d\t: %s %s\n", i, model,
163 gg2_memtypes[sdramen ? 1 : ((t>>1) & 3)]);
164 }
165 /* L2 cache */
166 t = in_le32((unsigned *)(GG2_PCI_CONFIG_BASE+GG2_PCI_CC_CTRL));
167 len += sprintf(buffer+len, "board l2\t: %s %s (%s)\n",
168 gg2_cachesizes[(t>>7) & 3],
169 gg2_cachetypes[(t>>2) & 3],
170 gg2_cachemodes[t & 3]);
171 }
172 return len;
173 }
174
175 /*
176 * Fixes for the National Semiconductor PC78308VUL SuperI/O
177 *
178 * Some versions of Open Firmware incorrectly initialize the IRQ settings
179 * for keyboard and mouse
180 */
181 static inline void __init sio_write(u8 val, u8 index)
182 {
183 outb(index, 0x15c);
184 outb(val, 0x15d);
185 }
186
187 static inline u8 __init sio_read(u8 index)
188 {
189 outb(index, 0x15c);
190 return inb(0x15d);
191 }
192
193 static void __init sio_fixup_irq(const char *name, u8 device, u8 level,
194 u8 type)
195 {
196 u8 level0, type0, active;
197
198 /* select logical device */
199 sio_write(device, 0x07);
200 active = sio_read(0x30);
201 level0 = sio_read(0x70);
202 type0 = sio_read(0x71);
203 if (level0 != level || type0 != type || !active) {
204 printk(KERN_WARNING "sio: %s irq level %d, type %d, %sactive: "
205 "remapping to level %d, type %d, active\n",
206 name, level0, type0, !active ? "in" : "", level, type);
207 sio_write(0x01, 0x30);
208 sio_write(level, 0x70);
209 sio_write(type, 0x71);
210 }
211 }
212
213 static void __init sio_init(void)
214 {
215 struct device_node *root;
216
217 if ((root = find_path_device("/")) &&
218 !strncmp(get_property(root, "model", NULL), "IBM,LongTrail", 13)) {
219 /* logical device 0 (KBC/Keyboard) */
220 sio_fixup_irq("keyboard", 0, 1, 2);
221 /* select logical device 1 (KBC/Mouse) */
222 sio_fixup_irq("mouse", 1, 12, 2);
223 }
224 }
225
226
227 void __init
228 chrp_setup_arch(void)
229 {
230 struct device_node *device;
231
232 /* init to some ~sane value until calibrate_delay() runs */
233 loops_per_jiffy = 50000000/HZ;
234
235 #ifdef CONFIG_BLK_DEV_INITRD
236 /* this is fine for chrp */
237 initrd_below_start_ok = 1;
238
239 if (initrd_start)
240 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
241 else
242 #endif
243 ROOT_DEV = to_kdev_t(0x0802); /* sda2 (sda1 is for the kernel) */
244
245 /* Lookup PCI host bridges */
246 chrp_find_bridges();
247
248 #ifndef CONFIG_PPC64BRIDGE
249 /*
250 * Temporary fixes for PCI devices.
251 * -- Geert
252 */
253 hydra_init(); /* Mac I/O */
254
255 #endif /* CONFIG_PPC64BRIDGE */
256
257 /* Some IBM machines don't have the hydra -- Cort */
258 if (!OpenPIC_Addr) {
259 struct device_node *root;
260 unsigned long *opprop;
261 int n;
262
263 root = find_path_device("/");
264 opprop = (unsigned long *) get_property
265 (root, "platform-open-pic", NULL);
266 n = prom_n_addr_cells(root);
267 if (opprop != 0) {
268 printk("OpenPIC addrs: %lx %lx %lx\n",
269 opprop[n-1], opprop[2*n-1], opprop[3*n-1]);
270 OpenPIC_Addr = ioremap(opprop[n-1], 0x40000);
271 }
272 }
273
274 /*
275 * Fix the Super I/O configuration
276 */
277 sio_init();
278
279 /*
280 * Setup the console operations
281 */
282 #ifdef CONFIG_DUMMY_CONSOLE
283 conswitchp = &dummy_con;
284 #endif
285
286 /* Get the event scan rate for the rtas so we know how
287 * often it expects a heartbeat. -- Cort
288 */
289 if ( rtas_data ) {
290 struct property *p;
291 device = find_devices("rtas");
292 for ( p = device->properties;
293 p && strncmp(p->name, "rtas-event-scan-rate", 20);
294 p = p->next )
295 /* nothing */ ;
296 if ( p && *(unsigned long *)p->value ) {
297 ppc_md.heartbeat = chrp_event_scan;
298 ppc_md.heartbeat_reset = (HZ/(*(unsigned long *)p->value)*30)-1;
299 ppc_md.heartbeat_count = 1;
300 printk("RTAS Event Scan Rate: %lu (%lu jiffies)\n",
301 *(unsigned long *)p->value, ppc_md.heartbeat_reset );
302 }
303 }
304 }
305
306 void __chrp
307 chrp_event_scan(void)
308 {
309 unsigned char log[1024];
310 unsigned long ret = 0;
311 /* XXX: we should loop until the hardware says no more error logs -- Cort */
312 call_rtas( "event-scan", 4, 1, &ret, 0xffffffff, 0,
313 __pa(log), 1024 );
314 ppc_md.heartbeat_count = ppc_md.heartbeat_reset;
315 }
316
317 void __chrp
318 chrp_restart(char *cmd)
319 {
320 printk("RTAS system-reboot returned %d\n",
321 call_rtas("system-reboot", 0, 1, NULL));
322 for (;;);
323 }
324
325 void __chrp
326 chrp_power_off(void)
327 {
328 /* allow power on only with power button press */
329 printk("RTAS power-off returned %d\n",
330 call_rtas("power-off", 2, 1, NULL,0xffffffff,0xffffffff));
331 for (;;);
332 }
333
334 void __chrp
335 chrp_halt(void)
336 {
337 chrp_power_off();
338 }
339
340 u_int __chrp
341 chrp_irq_cannonicalize(u_int irq)
342 {
343 if (irq == 2)
344 {
345 return 9;
346 }
347 else
348 {
349 return irq;
350 }
351 }
352
353 void __init chrp_init_IRQ(void)
354 {
355 struct device_node *np;
356 int i;
357 unsigned int *addrp;
358 unsigned char* chrp_int_ack_special = 0;
359 unsigned char init_senses[NR_IRQS - NUM_8259_INTERRUPTS];
360 int nmi_irq = -1;
361 #if defined(CONFIG_VT) && defined(CONFIG_ADB_KEYBOARD) && defined(XMON)
362 struct device_node *kbd;
363 #endif
364
365 if (!(np = find_devices("pci"))
366 || !(addrp = (unsigned int *)
367 get_property(np, "8259-interrupt-acknowledge", NULL)))
368 printk("Cannot find pci to get ack address\n");
369 else
370 chrp_int_ack_special = (unsigned char *)
371 ioremap(addrp[prom_n_addr_cells(np)-1], 1);
372 /* hydra still sets OpenPIC_InitSenses to a static set of values */
373 if (OpenPIC_InitSenses == NULL) {
374 prom_get_irq_senses(init_senses, NUM_8259_INTERRUPTS, NR_IRQS);
375 OpenPIC_InitSenses = init_senses;
376 OpenPIC_NumInitSenses = NR_IRQS - NUM_8259_INTERRUPTS;
377 }
378 openpic_init(1, NUM_8259_INTERRUPTS, chrp_int_ack_special, nmi_irq);
379 for ( i = 0 ; i < NUM_8259_INTERRUPTS ; i++ )
380 irq_desc[i].handler = &i8259_pic;
381 i8259_init();
382 #if defined(CONFIG_VT) && defined(CONFIG_ADB_KEYBOARD) && defined(XMON)
383 /* see if there is a keyboard in the device tree
384 with a parent of type "adb" */
385 for (kbd = find_devices("keyboard"); kbd; kbd = kbd->next)
386 if (kbd->parent && kbd->parent->type
387 && strcmp(kbd->parent->type, "adb") == 0)
388 break;
389 if (kbd)
390 request_irq( HYDRA_INT_ADB_NMI, xmon_irq, 0, "XMON break", 0);
391 #endif
392 }
393
394 void __init
395 chrp_init2(void)
396 {
397 #ifdef CONFIG_NVRAM
398 pmac_nvram_init();
399 #endif
400
401 request_region(0x20,0x20,"pic1");
402 request_region(0xa0,0x20,"pic2");
403 request_region(0x00,0x20,"dma1");
404 request_region(0x40,0x20,"timer");
405 request_region(0x80,0x10,"dma page reg");
406 request_region(0xc0,0x20,"dma2");
407
408 if (ppc_md.progress)
409 ppc_md.progress(" Have fun! ", 0x7777);
410
411 #if defined(CONFIG_VT) && (defined(CONFIG_ADB_KEYBOARD) || defined(CONFIG_INPUT))
412 /* see if there is a keyboard in the device tree
413 with a parent of type "adb" */
414 {
415 struct device_node *kbd;
416
417 for (kbd = find_devices("keyboard"); kbd; kbd = kbd->next) {
418 if (kbd->parent && kbd->parent->type
419 && strcmp(kbd->parent->type, "adb") == 0) {
420 select_adb_keyboard();
421 break;
422 }
423 }
424 }
425 #endif /* CONFIG_VT && (CONFIG_ADB_KEYBOARD || CONFIG_INPUT) */
426 }
427
428 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
429 /*
430 * IDE stuff.
431 */
432
433 static int __chrp
434 chrp_ide_check_region(ide_ioreg_t from, unsigned int extent)
435 {
436 return check_region(from, extent);
437 }
438
439 static void __chrp
440 chrp_ide_request_region(ide_ioreg_t from,
441 unsigned int extent,
442 const char *name)
443 {
444 request_region(from, extent, name);
445 }
446
447 static void __chrp
448 chrp_ide_release_region(ide_ioreg_t from,
449 unsigned int extent)
450 {
451 release_region(from, extent);
452 }
453
454 static void __chrp
455 chrp_ide_init_hwif_ports(hw_regs_t *hw, ide_ioreg_t data_port, ide_ioreg_t ctrl_port, int *irq)
456 {
457 ide_ioreg_t reg = data_port;
458 int i;
459
460 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
461 hw->io_ports[i] = reg;
462 reg += 1;
463 }
464 hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
465 }
466 #endif
467
468 /*
469 * One of the main thing these mappings are needed for is so that
470 * xmon can get to the serial port early on. We probably should
471 * handle the machines with the mpc106 as well as the python (F50)
472 * and the GG2 (longtrail). Actually we should look in the device
473 * tree and do the right thing.
474 */
475 static void __init
476 chrp_map_io(void)
477 {
478 char *name;
479
480 /*
481 * The code below tends to get removed, please don't take it out.
482 * The F50 needs this mapping and it you take it out I'll track you
483 * down and slap your hands. If it causes problems please email me.
484 * -- Cort <cort@fsmlabs.com>
485 */
486 name = get_property(find_path_device("/"), "name", NULL);
487 if (name && strncmp(name, "IBM-70", 6) == 0
488 && strstr(name, "-F50")) {
489 io_block_mapping(0x80000000, 0x80000000, 0x10000000, _PAGE_IO);
490 io_block_mapping(0x90000000, 0x90000000, 0x10000000, _PAGE_IO);
491 return;
492 } else {
493 io_block_mapping(0xf8000000, 0xf8000000, 0x04000000, _PAGE_IO);
494 }
495 }
496
497 void __init
498 chrp_init(unsigned long r3, unsigned long r4, unsigned long r5,
499 unsigned long r6, unsigned long r7)
500 {
501 #ifdef CONFIG_BLK_DEV_INITRD
502 /* take care of initrd if we have one */
503 if ( r6 )
504 {
505 initrd_start = r6 + KERNELBASE;
506 initrd_end = r6 + r7 + KERNELBASE;
507 }
508 #endif /* CONFIG_BLK_DEV_INITRD */
509
510 ISA_DMA_THRESHOLD = ~0L;
511 DMA_MODE_READ = 0x44;
512 DMA_MODE_WRITE = 0x48;
513 isa_io_base = CHRP_ISA_IO_BASE; /* default value */
514
515 ppc_md.setup_arch = chrp_setup_arch;
516 ppc_md.setup_residual = NULL;
517 ppc_md.get_cpuinfo = chrp_get_cpuinfo;
518 ppc_md.irq_cannonicalize = chrp_irq_cannonicalize;
519 #ifndef CONFIG_POWER4
520 ppc_md.init_IRQ = chrp_init_IRQ;
521 ppc_md.get_irq = openpic_get_irq;
522 #else
523 ppc_md.init_IRQ = xics_init_IRQ;
524 ppc_md.get_irq = xics_get_irq;
525 #endif /* CONFIG_POWER4 */
526
527 ppc_md.init = chrp_init2;
528
529 ppc_md.restart = chrp_restart;
530 ppc_md.power_off = chrp_power_off;
531 ppc_md.halt = chrp_halt;
532
533 ppc_md.time_init = chrp_time_init;
534 ppc_md.set_rtc_time = chrp_set_rtc_time;
535 ppc_md.get_rtc_time = chrp_get_rtc_time;
536 ppc_md.calibrate_decr = chrp_calibrate_decr;
537
538 ppc_md.find_end_of_memory = pmac_find_end_of_memory;
539 ppc_md.setup_io_mappings = chrp_map_io;
540
541 #ifdef CONFIG_VT
542 /* these are adjusted in chrp_init2 if we have an ADB keyboard */
543 ppc_md.kbd_setkeycode = pckbd_setkeycode;
544 ppc_md.kbd_getkeycode = pckbd_getkeycode;
545 ppc_md.kbd_translate = pckbd_translate;
546 ppc_md.kbd_unexpected_up = pckbd_unexpected_up;
547 ppc_md.kbd_leds = pckbd_leds;
548 ppc_md.kbd_init_hw = pckbd_init_hw;
549 #ifdef CONFIG_MAGIC_SYSRQ
550 ppc_md.ppc_kbd_sysrq_xlate = pckbd_sysrq_xlate;
551 SYSRQ_KEY = 0x54;
552 #endif /* CONFIG_MAGIC_SYSRQ */
553 #endif /* CONFIG_VT */
554
555 if (rtas_data) {
556 struct device_node *rtas;
557 unsigned int *p;
558
559 rtas = find_devices("rtas");
560 if (rtas != NULL) {
561 if (get_property(rtas, "display-character", NULL)) {
562 ppc_md.progress = rtas_display_progress;
563 p = (unsigned int *) get_property
564 (rtas, "ibm,display-line-length", NULL);
565 if (p)
566 max_width = *p;
567 } else if (get_property(rtas, "set-indicator", NULL))
568 ppc_md.progress = rtas_indicator_progress;
569 }
570 }
571 #ifdef CONFIG_BOOTX_TEXT
572 if (ppc_md.progress == NULL && boot_text_mapped)
573 ppc_md.progress = btext_progress;
574 #endif
575
576 #ifdef CONFIG_SMP
577 #ifndef CONFIG_POWER4
578 ppc_md.smp_ops = &chrp_smp_ops;
579 #else
580 ppc_md.smp_ops = &xics_smp_ops;
581 #endif /* CONFIG_POWER4 */
582 #endif /* CONFIG_SMP */
583
584 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
585 ppc_ide_md.ide_check_region = chrp_ide_check_region;
586 ppc_ide_md.ide_request_region = chrp_ide_request_region;
587 ppc_ide_md.ide_release_region = chrp_ide_release_region;
588 ppc_ide_md.ide_init_hwif = chrp_ide_init_hwif_ports;
589 #endif
590
591 /*
592 * Print the banner, then scroll down so boot progress
593 * can be printed. -- Cort
594 */
595 if ( ppc_md.progress ) ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0x0);
596 }
597
598 void __chrp
599 rtas_display_progress(char *s, unsigned short hex)
600 {
601 int width;
602 char *os = s;
603
604 if ( call_rtas( "display-character", 1, 1, NULL, '\r' ) )
605 return;
606
607 width = max_width;
608 while ( *os )
609 {
610 if ( (*os == '\n') || (*os == '\r') )
611 width = max_width;
612 else
613 width--;
614 call_rtas( "display-character", 1, 1, NULL, *os++ );
615 /* if we overwrite the screen length */
616 if ( width == 0 )
617 while ( (*os != 0) && (*os != '\n') && (*os != '\r') )
618 os++;
619 }
620
621 /*while ( width-- > 0 )*/
622 call_rtas( "display-character", 1, 1, NULL, ' ' );
623 }
624
625 void __chrp
626 rtas_indicator_progress(char *s, unsigned short hex)
627 {
628 call_rtas("set-indicator", 3, 1, NULL, 6, 0, hex);
629 }
630
631 #ifdef CONFIG_BOOTX_TEXT
632 void
633 btext_progress(char *s, unsigned short hex)
634 {
635 prom_print(s);
636 prom_print("\n");
637 }
638 #endif /* CONFIG_BOOTX_TEXT */
639