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/console.h>
36 #include <linux/seq_file.h>
37 #include <linux/root_dev.h>
38 #include <linux/initrd.h>
39 #include <linux/module.h>
42 #include <asm/pgtable.h>
45 #include <asm/pci-bridge.h>
47 #include <asm/machdep.h>
49 #include <asm/hydra.h>
50 #include <asm/sections.h>
52 #include <asm/btext.h>
53 #include <asm/i8259.h>
54 #include <asm/open_pic.h>
57 unsigned long chrp_get_rtc_time(void);
58 int chrp_set_rtc_time(unsigned long nowtime);
59 void chrp_calibrate_decr(void);
60 long chrp_time_init(void);
62 void chrp_find_bridges(void);
63 void chrp_event_scan(void);
64 void rtas_display_progress(char *, unsigned short);
65 void rtas_indicator_progress(char *, unsigned short);
66 void btext_progress(char *, unsigned short);
68 extern unsigned long pmac_find_end_of_memory(void);
69 extern int of_show_percpuinfo(struct seq_file *, int);
72 EXPORT_SYMBOL(_chrp_type);
75 * XXX this should be in xmon.h, but putting it there means xmon.h
76 * has to include <linux/interrupt.h> (to get irqreturn_t), which
77 * causes all sorts of problems. -- paulus
79 extern irqreturn_t xmon_irq(int, void *, struct pt_regs *);
81 extern dev_t boot_dev;
83 extern PTE *Hash, *Hash_end;
84 extern unsigned long Hash_size, Hash_mask;
85 extern int probingmem;
86 extern unsigned long loops_per_jiffy;
90 extern struct smp_ops_t chrp_smp_ops;
93 static const char *gg2_memtypes[4] = {
94 "FPM", "SDRAM", "EDO", "BEDO"
96 static const char *gg2_cachesizes[4] = {
97 "256 KB", "512 KB", "1 MB", "Reserved"
99 static const char *gg2_cachetypes[4] = {
100 "Asynchronous", "Reserved", "Flow-Through Synchronous",
101 "Pipelined Synchronous"
103 static const char *gg2_cachemodes[4] = {
104 "Disabled", "Write-Through", "Copy-Back", "Transparent Mode"
108 chrp_show_cpuinfo(struct seq_file *m)
112 struct device_node *root;
113 const char *model = "";
115 root = find_path_device("/");
117 model = get_property(root, "model", NULL);
118 seq_printf(m, "machine\t\t: CHRP %s\n", model);
120 /* longtrail (goldengate) stuff */
121 if (!strncmp(model, "IBM,LongTrail", 13)) {
122 /* VLSI VAS96011/12 `Golden Gate 2' */
124 sdramen = (in_le32(gg2_pci_config_base + GG2_PCI_DRAM_CTRL)
126 for (i = 0; i < (sdramen ? 4 : 6); i++) {
127 t = in_le32(gg2_pci_config_base+
132 switch ((t>>8) & 0x1f) {
155 seq_printf(m, "memory bank %d\t: %s %s\n", i, model,
156 gg2_memtypes[sdramen ? 1 : ((t>>1) & 3)]);
159 t = in_le32(gg2_pci_config_base+GG2_PCI_CC_CTRL);
160 seq_printf(m, "board l2\t: %s %s (%s)\n",
161 gg2_cachesizes[(t>>7) & 3],
162 gg2_cachetypes[(t>>2) & 3],
163 gg2_cachemodes[t & 3]);
169 * Fixes for the National Semiconductor PC78308VUL SuperI/O
171 * Some versions of Open Firmware incorrectly initialize the IRQ settings
172 * for keyboard and mouse
174 static inline void __init sio_write(u8 val, u8 index)
180 static inline u8 __init sio_read(u8 index)
186 static void __init sio_fixup_irq(const char *name, u8 device, u8 level,
189 u8 level0, type0, active;
191 /* select logical device */
192 sio_write(device, 0x07);
193 active = sio_read(0x30);
194 level0 = sio_read(0x70);
195 type0 = sio_read(0x71);
196 if (level0 != level || type0 != type || !active) {
197 printk(KERN_WARNING "sio: %s irq level %d, type %d, %sactive: "
198 "remapping to level %d, type %d, active\n",
199 name, level0, type0, !active ? "in" : "", level, type);
200 sio_write(0x01, 0x30);
201 sio_write(level, 0x70);
202 sio_write(type, 0x71);
206 static void __init sio_init(void)
208 struct device_node *root;
210 if ((root = find_path_device("/")) &&
211 !strncmp(get_property(root, "model", NULL), "IBM,LongTrail", 13)) {
212 /* logical device 0 (KBC/Keyboard) */
213 sio_fixup_irq("keyboard", 0, 1, 2);
214 /* select logical device 1 (KBC/Mouse) */
215 sio_fixup_irq("mouse", 1, 12, 2);
220 static void __init pegasos_set_l2cr(void)
222 struct device_node *np;
224 /* On Pegasos, enable the l2 cache if needed, as the OF forgets it */
225 if (_chrp_type != _CHRP_Pegasos)
228 /* Enable L2 cache if needed */
229 np = find_type_devices("cpu");
231 unsigned int *l2cr = (unsigned int *)
232 get_property (np, "l2cr", NULL);
234 printk ("Pegasos l2cr : no cpu l2cr property found\n");
237 if (!((*l2cr) & 0x80000000)) {
238 printk ("Pegasos l2cr : L2 cache was not active, "
241 _set_L2CR((*l2cr) | 0x80000000);
246 void __init chrp_setup_arch(void)
248 struct device_node *device;
250 /* init to some ~sane value until calibrate_delay() runs */
251 loops_per_jiffy = 50000000/HZ;
253 #ifdef CONFIG_BLK_DEV_INITRD
254 /* this is fine for chrp */
255 initrd_below_start_ok = 1;
258 ROOT_DEV = Root_RAM0;
261 ROOT_DEV = Root_SDA2; /* sda2 (sda1 is for the kernel) */
263 /* On pegasos, enable the L2 cache if not already done by OF */
266 /* Lookup PCI host bridges */
269 #ifndef CONFIG_PPC64BRIDGE
271 * Temporary fixes for PCI devices.
274 hydra_init(); /* Mac I/O */
276 #endif /* CONFIG_PPC64BRIDGE */
279 * Fix the Super I/O configuration
283 /* Get the event scan rate for the rtas so we know how
284 * often it expects a heartbeat. -- Cort
288 device = find_devices("rtas");
289 for ( p = device->properties;
290 p && strncmp(p->name, "rtas-event-scan-rate", 20);
293 if ( p && *(unsigned long *)p->value ) {
294 ppc_md.heartbeat = chrp_event_scan;
295 ppc_md.heartbeat_reset = (HZ/(*(unsigned long *)p->value)*30)-1;
296 ppc_md.heartbeat_count = 1;
297 printk("RTAS Event Scan Rate: %lu (%lu jiffies)\n",
298 *(unsigned long *)p->value, ppc_md.heartbeat_reset );
302 pci_create_OF_bus_map();
306 chrp_event_scan(void)
308 unsigned char log[1024];
309 unsigned long ret = 0;
310 /* XXX: we should loop until the hardware says no more error logs -- Cort */
311 call_rtas( "event-scan", 4, 1, &ret, 0xffffffff, 0,
313 ppc_md.heartbeat_count = ppc_md.heartbeat_reset;
317 chrp_restart(char *cmd)
319 printk("RTAS system-reboot returned %d\n",
320 call_rtas("system-reboot", 0, 1, NULL));
327 /* allow power on only with power button press */
328 printk("RTAS power-off returned %d\n",
329 call_rtas("power-off", 2, 1, NULL,0xffffffff,0xffffffff));
340 * Finds the open-pic node and sets OpenPIC_Addr based on its reg property.
341 * Then checks if it has an interrupt-ranges property. If it does then
342 * we have a distributed open-pic, so call openpic_set_sources to tell
343 * the openpic code where to find the interrupt source registers.
345 static void __init chrp_find_openpic(void)
347 struct device_node *np;
349 unsigned int *iranges;
352 np = find_type_devices("open-pic");
353 if (np == NULL || np->n_addrs == 0)
355 printk(KERN_INFO "OpenPIC at %x (size %x)\n",
356 np->addrs[0].address, np->addrs[0].size);
357 OpenPIC_Addr = ioremap(np->addrs[0].address, 0x40000);
358 if (OpenPIC_Addr == NULL) {
359 printk(KERN_ERR "Failed to map OpenPIC!\n");
363 iranges = (unsigned int *) get_property(np, "interrupt-ranges", &len);
364 if (iranges == NULL || len < 2 * sizeof(unsigned int))
365 return; /* not distributed */
368 * The first pair of cells in interrupt-ranges refers to the
369 * IDU; subsequent pairs refer to the ISUs.
371 len /= 2 * sizeof(unsigned int);
372 if (np->n_addrs < len) {
373 printk(KERN_ERR "Insufficient addresses for distributed"
374 " OpenPIC (%d < %d)\n", np->n_addrs, len);
377 if (iranges[1] != 0) {
378 printk(KERN_INFO "OpenPIC irqs %d..%d in IDU\n",
379 iranges[0], iranges[0] + iranges[1] - 1);
380 openpic_set_sources(iranges[0], iranges[1], NULL);
382 for (i = 1; i < len; ++i) {
384 printk(KERN_INFO "OpenPIC irqs %d..%d in ISU at %x (%x)\n",
385 iranges[0], iranges[0] + iranges[1] - 1,
386 np->addrs[i].address, np->addrs[i].size);
387 isu = ioremap(np->addrs[i].address, np->addrs[i].size);
389 openpic_set_sources(iranges[0], iranges[1], isu);
391 printk(KERN_ERR "Failed to map OpenPIC ISU at %x!\n",
392 np->addrs[i].address);
396 #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
397 static struct irqaction xmon_irqaction = {
399 .mask = CPU_MASK_NONE,
400 .name = "XMON break",
404 void __init chrp_init_IRQ(void)
406 struct device_node *np;
408 unsigned long chrp_int_ack = 0;
409 unsigned char init_senses[NR_IRQS - NUM_8259_INTERRUPTS];
410 #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
411 struct device_node *kbd;
414 for (np = find_devices("pci"); np != NULL; np = np->next) {
415 unsigned int *addrp = (unsigned int *)
416 get_property(np, "8259-interrupt-acknowledge", NULL);
420 chrp_int_ack = addrp[prom_n_addr_cells(np)-1];
424 printk(KERN_ERR "Cannot find PCI interrupt acknowledge address\n");
429 prom_get_irq_senses(init_senses, NUM_8259_INTERRUPTS, NR_IRQS);
430 OpenPIC_InitSenses = init_senses;
431 OpenPIC_NumInitSenses = NR_IRQS - NUM_8259_INTERRUPTS;
433 openpic_init(NUM_8259_INTERRUPTS);
434 /* We have a cascade on OpenPIC IRQ 0, Linux IRQ 16 */
435 openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
439 i8259_init(chrp_int_ack, 0);
441 #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
442 /* see if there is a keyboard in the device tree
443 with a parent of type "adb" */
444 for (kbd = find_devices("keyboard"); kbd; kbd = kbd->next)
445 if (kbd->parent && kbd->parent->type
446 && strcmp(kbd->parent->type, "adb") == 0)
449 setup_irq(HYDRA_INT_ADB_NMI, &xmon_irqaction);
460 request_region(0x20,0x20,"pic1");
461 request_region(0xa0,0x20,"pic2");
462 request_region(0x00,0x20,"dma1");
463 request_region(0x40,0x20,"timer");
464 request_region(0x80,0x10,"dma page reg");
465 request_region(0xc0,0x20,"dma2");
468 ppc_md.progress(" Have fun! ", 0x7777);
472 chrp_init(unsigned long r3, unsigned long r4, unsigned long r5,
473 unsigned long r6, unsigned long r7)
475 struct device_node *root = find_path_device ("/");
476 char *machine = NULL;
478 #ifdef CONFIG_BLK_DEV_INITRD
479 /* take care of initrd if we have one */
482 initrd_start = r6 + KERNELBASE;
483 initrd_end = r6 + r7 + KERNELBASE;
485 #endif /* CONFIG_BLK_DEV_INITRD */
487 ISA_DMA_THRESHOLD = ~0L;
488 DMA_MODE_READ = 0x44;
489 DMA_MODE_WRITE = 0x48;
490 isa_io_base = CHRP_ISA_IO_BASE; /* default value */
491 ppc_do_canonicalize_irqs = 1;
494 machine = get_property(root, "model", NULL);
495 if (machine && strncmp(machine, "Pegasos", 7) == 0) {
496 _chrp_type = _CHRP_Pegasos;
497 } else if (machine && strncmp(machine, "IBM", 3) == 0) {
498 _chrp_type = _CHRP_IBM;
499 } else if (machine && strncmp(machine, "MOT", 3) == 0) {
500 _chrp_type = _CHRP_Motorola;
502 /* Let's assume it is an IBM chrp if all else fails */
503 _chrp_type = _CHRP_IBM;
506 ppc_md.setup_arch = chrp_setup_arch;
507 ppc_md.show_percpuinfo = of_show_percpuinfo;
508 ppc_md.show_cpuinfo = chrp_show_cpuinfo;
510 ppc_md.init_IRQ = chrp_init_IRQ;
511 if (_chrp_type == _CHRP_Pegasos)
512 ppc_md.get_irq = i8259_irq;
514 ppc_md.get_irq = openpic_get_irq;
516 ppc_md.init = chrp_init2;
518 ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
520 ppc_md.restart = chrp_restart;
521 ppc_md.power_off = chrp_power_off;
522 ppc_md.halt = chrp_halt;
524 ppc_md.time_init = chrp_time_init;
525 ppc_md.set_rtc_time = chrp_set_rtc_time;
526 ppc_md.get_rtc_time = chrp_get_rtc_time;
527 ppc_md.calibrate_decr = chrp_calibrate_decr;
529 ppc_md.find_end_of_memory = pmac_find_end_of_memory;
532 struct device_node *rtas;
535 rtas = find_devices("rtas");
537 if (get_property(rtas, "display-character", NULL)) {
538 ppc_md.progress = rtas_display_progress;
539 p = (unsigned int *) get_property
540 (rtas, "ibm,display-line-length", NULL);
543 } else if (get_property(rtas, "set-indicator", NULL))
544 ppc_md.progress = rtas_indicator_progress;
547 #ifdef CONFIG_BOOTX_TEXT
548 if (ppc_md.progress == NULL && boot_text_mapped)
549 ppc_md.progress = btext_progress;
553 smp_ops = &chrp_smp_ops;
554 #endif /* CONFIG_SMP */
557 * Print the banner, then scroll down so boot progress
558 * can be printed. -- Cort
560 if (ppc_md.progress) ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0x0);
564 rtas_display_progress(char *s, unsigned short hex)
569 if ( call_rtas( "display-character", 1, 1, NULL, '\r' ) )
575 if ( (*os == '\n') || (*os == '\r') )
579 call_rtas( "display-character", 1, 1, NULL, *os++ );
580 /* if we overwrite the screen length */
582 while ( (*os != 0) && (*os != '\n') && (*os != '\r') )
586 /*while ( width-- > 0 )*/
587 call_rtas( "display-character", 1, 1, NULL, ' ' );
591 rtas_indicator_progress(char *s, unsigned short hex)
593 call_rtas("set-indicator", 3, 1, NULL, 6, 0, hex);
596 #ifdef CONFIG_BOOTX_TEXT
598 btext_progress(char *s, unsigned short hex)
603 #endif /* CONFIG_BOOTX_TEXT */