2 * arch/ppc/platforms/setup.c
4 * Copyright (C) 1995 Linus Torvalds
5 * Adapted from 'alpha' version by Gary Thomas
6 * Modified by Cort Dougan (cort@cs.nmt.edu)
10 * bootup setup stuff..
13 #include <linux/config.h>
14 #include <linux/errno.h>
15 #include <linux/sched.h>
16 #include <linux/kernel.h>
18 #include <linux/stddef.h>
19 #include <linux/unistd.h>
20 #include <linux/ptrace.h>
21 #include <linux/slab.h>
22 #include <linux/user.h>
23 #include <linux/a.out.h>
24 #include <linux/tty.h>
25 #include <linux/major.h>
26 #include <linux/interrupt.h>
27 #include <linux/reboot.h>
28 #include <linux/init.h>
29 #include <linux/pci.h>
30 #include <linux/version.h>
31 #include <linux/adb.h>
32 #include <linux/module.h>
33 #include <linux/delay.h>
34 #include <linux/ide.h>
35 #include <linux/irq.h>
36 #include <linux/console.h>
37 #include <linux/seq_file.h>
39 #include <asm/processor.h>
41 #include <asm/pgtable.h>
44 #include <asm/pci-bridge.h>
46 #include <asm/machdep.h>
48 #include <asm/hydra.h>
49 #include <asm/keyboard.h>
50 #include <asm/sections.h>
52 #include <asm/btext.h>
53 #include <asm/i8259.h>
54 #include <asm/open_pic.h>
57 #include <linux/serial.h>
58 #include <linux/serialP.h>
61 unsigned long chrp_get_rtc_time(void);
62 int chrp_set_rtc_time(unsigned long nowtime);
63 void chrp_calibrate_decr(void);
64 long chrp_time_init(void);
66 void chrp_find_bridges(void);
67 void chrp_event_scan(void);
68 void rtas_display_progress(char *, unsigned short);
69 void rtas_indicator_progress(char *, unsigned short);
70 void btext_progress(char *, unsigned short);
72 extern unsigned long pmac_find_end_of_memory(void);
73 extern int pckbd_setkeycode(unsigned int scancode, unsigned int keycode);
74 extern int pckbd_getkeycode(unsigned int scancode);
75 extern int pckbd_translate(unsigned char scancode, unsigned char *keycode,
77 extern char pckbd_unexpected_up(unsigned char keycode);
78 extern void pckbd_leds(unsigned char leds);
79 extern void pckbd_init_hw(void);
80 extern unsigned char pckbd_sysrq_xlate[128];
81 extern void select_adb_keyboard(void);
82 extern int of_show_percpuinfo(struct seq_file *, int);
84 extern kdev_t boot_dev;
86 extern unsigned long loops_per_jiffy;
88 static int max_width __chrpdata;
89 int chrp_is_briq __chrpdata;
90 unsigned int* briq_SPOR __chrpdata; /* To be replaced by RTAS when available */
93 extern struct smp_ops_t chrp_smp_ops;
96 static const char *gg2_memtypes[4] = {
97 "FPM", "SDRAM", "EDO", "BEDO"
99 static const char *gg2_cachesizes[4] = {
100 "256 KB", "512 KB", "1 MB", "Reserved"
102 static const char *gg2_cachetypes[4] = {
103 "Asynchronous", "Reserved", "Flow-Through Synchronous",
104 "Pipelined Synchronous"
106 static const char *gg2_cachemodes[4] = {
107 "Disabled", "Write-Through", "Copy-Back", "Transparent Mode"
111 chrp_show_cpuinfo(struct seq_file *m)
115 struct device_node *root;
116 const char *model = "";
118 root = find_path_device("/");
120 model = get_property(root, "model", NULL);
121 seq_printf(m, "machine\t\t: CHRP %s\n", model);
123 /* longtrail (goldengate) stuff */
124 if (!strncmp(model, "IBM,LongTrail", 13)) {
125 /* VLSI VAS96011/12 `Golden Gate 2' */
127 sdramen = (in_le32((unsigned *)(gg2_pci_config_base+
130 for (i = 0; i < (sdramen ? 4 : 6); i++) {
131 t = in_le32((unsigned *)(gg2_pci_config_base+
136 switch ((t>>8) & 0x1f) {
159 seq_printf(m, "memory bank %d\t: %s %s\n", i, model,
160 gg2_memtypes[sdramen ? 1 : ((t>>1) & 3)]);
163 t = in_le32((unsigned *)(gg2_pci_config_base+GG2_PCI_CC_CTRL));
164 seq_printf(m, "board l2\t: %s %s (%s)\n",
165 gg2_cachesizes[(t>>7) & 3],
166 gg2_cachetypes[(t>>2) & 3],
167 gg2_cachemodes[t & 3]);
173 * Fixes for the National Semiconductor PC78308VUL SuperI/O
175 * Some versions of Open Firmware incorrectly initialize the IRQ settings
176 * for keyboard and mouse
178 static inline void __init sio_write(u8 val, u8 index)
184 static inline u8 __init sio_read(u8 index)
190 static void __init sio_fixup_irq(const char *name, u8 device, u8 level,
193 u8 level0, type0, active;
195 /* select logical device */
196 sio_write(device, 0x07);
197 active = sio_read(0x30);
198 level0 = sio_read(0x70);
199 type0 = sio_read(0x71);
200 if (level0 != level || type0 != type || !active) {
201 printk(KERN_WARNING "sio: %s irq level %d, type %d, %sactive: "
202 "remapping to level %d, type %d, active\n",
203 name, level0, type0, !active ? "in" : "", level, type);
204 sio_write(0x01, 0x30);
205 sio_write(level, 0x70);
206 sio_write(type, 0x71);
210 static void __init sio_init(void)
212 struct device_node *root;
214 if ((root = find_path_device("/")) &&
215 !strncmp(get_property(root, "model", NULL), "IBM,LongTrail", 13)) {
216 /* logical device 0 (KBC/Keyboard) */
217 sio_fixup_irq("keyboard", 0, 1, 2);
218 /* select logical device 1 (KBC/Mouse) */
219 sio_fixup_irq("mouse", 1, 12, 2);
225 chrp_setup_arch(void)
227 struct device_node *device;
229 /* init to some ~sane value until calibrate_delay() runs */
230 loops_per_jiffy = 50000000/HZ;
232 #ifdef CONFIG_BLK_DEV_INITRD
233 /* this is fine for chrp */
234 initrd_below_start_ok = 1;
237 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
240 ROOT_DEV = to_kdev_t(0x0802); /* sda2 (sda1 is for the kernel) */
242 /* Lookup PCI host bridges */
245 #ifndef CONFIG_PPC64BRIDGE
247 * Temporary fixes for PCI devices.
250 hydra_init(); /* Mac I/O */
252 #endif /* CONFIG_PPC64BRIDGE */
255 * Fix the Super I/O configuration
260 * Setup the console operations
262 #ifdef CONFIG_DUMMY_CONSOLE
263 conswitchp = &dummy_con;
266 /* Get the event scan rate for the rtas so we know how
267 * often it expects a heartbeat. -- Cort
271 unsigned long rate, count;
272 device = find_devices("rtas");
273 for ( p = device->properties;
274 p && strncmp(p->name, "rtas-event-scan-rate", 20);
277 if (p && (rate = *(unsigned long *)p->value) > 0) {
279 * The value is the number of times per minute.
280 * For now assign the full workload here to cpu 0.
282 * We now split the rate and spread the heartbeats
283 * when we kick secondary cpus so we can spread
286 ppc_md.heartbeat = chrp_event_scan;
288 count = (60*HZ) / rate;
289 if (!count) /* XXX insane */
292 heartbeat_reset(0) = count;
293 heartbeat_count(0) = 1;
295 printk("RTAS Event Scan Rate: %lu calls/minute "
296 "(every %lu jiffies)\n", rate, count );
300 pci_create_OF_bus_map();
304 chrp_event_scan(void)
306 unsigned char log[1024];
307 unsigned long ret = 0;
308 /* XXX: we should loop until the hardware says no more error logs -- Cort */
309 call_rtas( "event-scan", 4, 1, &ret, 0xffffffff, 0,
314 chrp_restart(char *cmd)
316 printk("RTAS system-reboot returned %d\n",
317 call_rtas("system-reboot", 0, 1, NULL));
324 /* allow power on only with power button press */
325 printk("RTAS power-off returned %d\n",
326 call_rtas("power-off", 2, 1, NULL,0xffffffff,0xffffffff));
337 chrp_irq_cannonicalize(u_int irq)
345 briq_restart(char *cmd)
349 out_be32(briq_SPOR, 0);
354 * Finds the open-pic node and sets OpenPIC_Addr based on its reg property.
355 * Then checks if it has an interrupt-ranges property. If it does then
356 * we have a distributed open-pic, so call openpic_set_sources to tell
357 * the openpic code where to find the interrupt source registers.
359 static void __init chrp_find_openpic(void)
361 struct device_node *np;
363 unsigned int *iranges;
366 np = find_type_devices("open-pic");
367 if (np == NULL || np->n_addrs == 0)
369 printk(KERN_INFO "OpenPIC at %x (size %x)\n",
370 np->addrs[0].address, np->addrs[0].size);
371 OpenPIC_Addr = ioremap(np->addrs[0].address, 0x40000);
372 if (OpenPIC_Addr == NULL) {
373 printk(KERN_ERR "Failed to map OpenPIC!\n");
377 iranges = (unsigned int *) get_property(np, "interrupt-ranges", &len);
378 if (iranges == NULL || len < 2 * sizeof(unsigned int))
379 return; /* not distributed */
382 * The first pair of cells in interrupt-ranges refers to the
383 * IDU; subsequent pairs refer to the ISUs.
385 len /= 2 * sizeof(unsigned int);
386 if (np->n_addrs < len) {
387 printk(KERN_ERR "Insufficient addresses for distributed"
388 " OpenPIC (%d < %d)\n", np->n_addrs, len);
391 if (iranges[1] != 0) {
392 printk(KERN_INFO "OpenPIC irqs %d..%d in IDU\n",
393 iranges[0], iranges[0] + iranges[1] - 1);
394 openpic_set_sources(iranges[0], iranges[1], NULL);
396 for (i = 1; i < len; ++i) {
398 printk(KERN_INFO "OpenPIC irqs %d..%d in ISU at %x (%x)\n",
399 iranges[0], iranges[0] + iranges[1] - 1,
400 np->addrs[i].address, np->addrs[i].size);
401 isu = ioremap(np->addrs[i].address, np->addrs[i].size);
403 openpic_set_sources(iranges[0], iranges[1], isu);
405 printk(KERN_ERR "Failed to map OpenPIC ISU at %x!\n",
406 np->addrs[i].address);
411 chrp_init_irq_openpic(unsigned long intack)
414 unsigned char init_senses[NR_IRQS - NUM_8259_INTERRUPTS];
418 prom_get_irq_senses(init_senses, NUM_8259_INTERRUPTS, NR_IRQS);
419 OpenPIC_InitSenses = init_senses;
420 OpenPIC_NumInitSenses = NR_IRQS - NUM_8259_INTERRUPTS;
422 openpic_init(NUM_8259_INTERRUPTS);
423 /* We have a cascade on OpenPIC IRQ 0, Linux IRQ 16 */
424 openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
427 for (i = 0; i < NUM_8259_INTERRUPTS; i++)
428 irq_desc[i].handler = &i8259_pic;
433 chrp_init_irq_8259(unsigned long intack)
437 ppc_md.get_irq = i8259_irq;
438 for (i = 0; i < NUM_8259_INTERRUPTS; i++)
439 irq_desc[i].handler = &i8259_pic;
443 void __init chrp_init_IRQ(void)
445 struct device_node *np;
446 unsigned long intack = 0;
447 struct device_node *main_irq_ctrler = NULL;
448 #if defined(CONFIG_VT) && defined(CONFIG_ADB_KEYBOARD) && defined(XMON)
449 struct device_node *kbd;
452 for (np = find_devices("pci"); np != NULL; np = np->next) {
453 unsigned int *addrp = (unsigned int *)
454 get_property(np, "8259-interrupt-acknowledge", NULL);
457 intack = addrp[prom_n_addr_cells(np)-1];
461 printk("Cannot find pci to get ack address\n");
463 /* Look for the node of the toplevel interrupt controller.
464 * If we don't find it, we assume openpic
466 np = find_path_device("/chosen");
468 phandle *irq_ctrler_ph =
469 (phandle *)get_property(np, "interrupt-controller", NULL);
471 main_irq_ctrler = find_phandle(*irq_ctrler_ph);
474 if (main_irq_ctrler && device_is_compatible(main_irq_ctrler, "8259"))
475 chrp_init_irq_8259(intack);
477 chrp_init_irq_openpic(intack);
479 #if defined(CONFIG_VT) && defined(CONFIG_ADB_KEYBOARD) && defined(XMON)
480 /* see if there is a keyboard in the device tree
481 with a parent of type "adb" */
482 for (kbd = find_devices("keyboard"); kbd; kbd = kbd->next)
483 if (kbd->parent && kbd->parent->type
484 && strcmp(kbd->parent->type, "adb") == 0)
487 request_irq(HYDRA_INT_ADB_NMI, xmon_irq, 0, "XMON break", 0);
496 briq_SPOR = (unsigned int *)ioremap(0xff0000e8, 4);
498 /* Fix me: currently, a lot of pmac_nvram routines are marked __pmac, and
499 * blindly calling pmac_nvram_init() on chrp cause bad results.
500 * Among others, it cracks on briQ.
501 * Please implement a CHRP specific version. --BenH
506 /* This is to be replaced by RTAS when available */
508 request_region(0x20,0x20,"pic1");
509 request_region(0xa0,0x20,"pic2");
510 request_region(0x00,0x20,"dma1");
511 request_region(0x40,0x20,"timer");
512 request_region(0x80,0x10,"dma page reg");
513 request_region(0xc0,0x20,"dma2");
516 ppc_md.progress(" Have fun! ", 0x7777);
518 #if defined(CONFIG_VT) && (defined(CONFIG_ADB_KEYBOARD) || defined(CONFIG_INPUT))
519 /* see if there is a keyboard in the device tree
520 with a parent of type "adb" */
522 struct device_node *kbd;
524 for (kbd = find_devices("keyboard"); kbd; kbd = kbd->next) {
525 if (kbd->parent && kbd->parent->type
526 && strcmp(kbd->parent->type, "adb") == 0) {
527 select_adb_keyboard();
532 #endif /* CONFIG_VT && (CONFIG_ADB_KEYBOARD || CONFIG_INPUT) */
536 chrp_init(unsigned long r3, unsigned long r4, unsigned long r5,
537 unsigned long r6, unsigned long r7)
539 struct device_node *root = find_path_device("/");
542 #ifdef CONFIG_BLK_DEV_INITRD
543 /* take care of initrd if we have one */
546 initrd_start = r6 + KERNELBASE;
547 initrd_end = r6 + r7 + KERNELBASE;
549 #endif /* CONFIG_BLK_DEV_INITRD */
551 ISA_DMA_THRESHOLD = ~0L;
552 DMA_MODE_READ = 0x44;
553 DMA_MODE_WRITE = 0x48;
554 isa_io_base = CHRP_ISA_IO_BASE; /* default value */
556 /* Check if it's a briq */
557 machine = get_property(root, "model", NULL);
558 chrp_is_briq = machine && strncmp(machine, "TotalImpact,BRIQ-1", 18) == 0;
561 /* briQ has a different serial clock */
562 extern struct serial_state rs_table[];
563 rs_table[0].baud_base = (7372800 / 16);
564 rs_table[1].baud_base = (7372800 / 16);
566 #endif /* CONFIG_SERIAL */
568 ppc_md.setup_arch = chrp_setup_arch;
569 ppc_md.show_percpuinfo = of_show_percpuinfo;
570 ppc_md.show_cpuinfo = chrp_show_cpuinfo;
571 ppc_md.irq_cannonicalize = chrp_irq_cannonicalize;
572 ppc_md.init_IRQ = chrp_init_IRQ;
573 ppc_md.get_irq = openpic_get_irq;
575 ppc_md.init = chrp_init2;
577 ppc_md.restart = chrp_is_briq ? briq_restart : chrp_restart;
578 ppc_md.power_off = chrp_power_off;
579 ppc_md.halt = chrp_halt;
581 ppc_md.time_init = chrp_time_init;
582 ppc_md.set_rtc_time = chrp_set_rtc_time;
583 ppc_md.get_rtc_time = chrp_get_rtc_time;
584 ppc_md.calibrate_decr = chrp_calibrate_decr;
586 ppc_md.find_end_of_memory = pmac_find_end_of_memory;
589 /* these are adjusted in chrp_init2 if we have an ADB keyboard */
590 ppc_md.kbd_setkeycode = pckbd_setkeycode;
591 ppc_md.kbd_getkeycode = pckbd_getkeycode;
592 ppc_md.kbd_translate = pckbd_translate;
593 ppc_md.kbd_unexpected_up = pckbd_unexpected_up;
595 ppc_md.kbd_leds = pckbd_leds;
596 ppc_md.kbd_init_hw = pckbd_init_hw;
598 #ifdef CONFIG_MAGIC_SYSRQ
599 ppc_md.ppc_kbd_sysrq_xlate = pckbd_sysrq_xlate;
601 #endif /* CONFIG_MAGIC_SYSRQ */
602 #endif /* CONFIG_VT */
605 struct device_node *rtas;
608 rtas = find_devices("rtas");
610 if (get_property(rtas, "display-character", NULL)) {
611 ppc_md.progress = rtas_display_progress;
612 p = (unsigned int *) get_property
613 (rtas, "ibm,display-line-length", NULL);
616 } else if (get_property(rtas, "set-indicator", NULL))
617 ppc_md.progress = rtas_indicator_progress;
620 #ifdef CONFIG_BOOTX_TEXT
621 if (ppc_md.progress == NULL && boot_text_mapped)
622 ppc_md.progress = btext_progress;
626 ppc_md.smp_ops = &chrp_smp_ops;
627 #endif /* CONFIG_SMP */
629 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
633 * Print the banner, then scroll down so boot progress
634 * can be printed. -- Cort
636 if ( ppc_md.progress ) ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0x0);
640 rtas_display_progress(char *s, unsigned short hex)
645 if ( call_rtas( "display-character", 1, 1, NULL, '\r' ) )
651 if ( (*os == '\n') || (*os == '\r') )
655 call_rtas( "display-character", 1, 1, NULL, *os++ );
656 /* if we overwrite the screen length */
658 while ( (*os != 0) && (*os != '\n') && (*os != '\r') )
662 /*while ( width-- > 0 )*/
663 call_rtas( "display-character", 1, 1, NULL, ' ' );
667 rtas_indicator_progress(char *s, unsigned short hex)
669 call_rtas("set-indicator", 3, 1, NULL, 6, 0, hex);
672 #ifdef CONFIG_BOOTX_TEXT
674 btext_progress(char *s, unsigned short hex)
679 #endif /* CONFIG_BOOTX_TEXT */