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>
56 #include "mem_pieces.h"
58 unsigned long chrp_get_rtc_time(void);
59 int chrp_set_rtc_time(unsigned long nowtime);
60 void chrp_calibrate_decr(void);
61 long chrp_time_init(void);
63 void chrp_find_bridges(void);
64 void chrp_event_scan(void);
65 void rtas_display_progress(char *, unsigned short);
66 void rtas_indicator_progress(char *, unsigned short);
67 void btext_progress(char *, unsigned short);
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;
407 unsigned long chrp_int_ack = 0;
408 unsigned char init_senses[NR_IRQS - NUM_8259_INTERRUPTS];
409 #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
410 struct device_node *kbd;
413 for (np = find_devices("pci"); np != NULL; np = np->next) {
414 unsigned int *addrp = (unsigned int *)
415 get_property(np, "8259-interrupt-acknowledge", NULL);
419 chrp_int_ack = addrp[prom_n_addr_cells(np)-1];
423 printk(KERN_ERR "Cannot find PCI interrupt acknowledge address\n");
428 prom_get_irq_senses(init_senses, NUM_8259_INTERRUPTS, NR_IRQS);
429 OpenPIC_InitSenses = init_senses;
430 OpenPIC_NumInitSenses = NR_IRQS - NUM_8259_INTERRUPTS;
432 openpic_init(NUM_8259_INTERRUPTS);
433 /* We have a cascade on OpenPIC IRQ 0, Linux IRQ 16 */
434 openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
438 i8259_init(chrp_int_ack, 0);
440 #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
441 /* see if there is a keyboard in the device tree
442 with a parent of type "adb" */
443 for (kbd = find_devices("keyboard"); kbd; kbd = kbd->next)
444 if (kbd->parent && kbd->parent->type
445 && strcmp(kbd->parent->type, "adb") == 0)
448 setup_irq(HYDRA_INT_ADB_NMI, &xmon_irqaction);
459 request_region(0x20,0x20,"pic1");
460 request_region(0xa0,0x20,"pic2");
461 request_region(0x00,0x20,"dma1");
462 request_region(0x40,0x20,"timer");
463 request_region(0x80,0x10,"dma page reg");
464 request_region(0xc0,0x20,"dma2");
467 ppc_md.progress(" Have fun! ", 0x7777);
470 static struct device_node *memory_node;
472 static int __init get_mem_prop(char *name, struct mem_pieces *mp)
474 struct reg_property *rp;
477 int nac = prom_n_addr_cells(memory_node);
478 int nsc = prom_n_size_cells(memory_node);
480 ip = (unsigned int *) get_property(memory_node, name, &s);
482 printk(KERN_ERR "error: couldn't get %s property on /memory\n",
486 s /= (nsc + nac) * 4;
488 for (i = 0; i < s; ++i, ip += nac+nsc) {
489 if (nac >= 2 && ip[nac-2] != 0)
491 rp->address = ip[nac-1];
492 if (nsc >= 2 && ip[nac+nsc-2] != 0)
495 rp->size = ip[nac+nsc-1];
498 mp->n_regions = rp - mp->regions;
500 /* Make sure the pieces are sorted. */
502 mem_pieces_coalesce(mp);
506 static unsigned long __init chrp_find_end_of_memory(void)
508 unsigned long a, total;
509 struct mem_pieces phys_mem;
512 * Find out where physical memory is, and check that it
513 * starts at 0 and is contiguous. It seems that RAM is
514 * always physically contiguous on Power Macintoshes.
516 * Supporting discontiguous physical memory isn't hard,
517 * it just makes the virtual <-> physical mapping functions
518 * more complicated (or else you end up wasting space
521 memory_node = find_devices("memory");
522 if (memory_node == NULL || !get_mem_prop("reg", &phys_mem)
523 || phys_mem.n_regions == 0)
525 a = phys_mem.regions[0].address;
527 panic("RAM doesn't start at physical address 0");
528 total = phys_mem.regions[0].size;
530 if (phys_mem.n_regions > 1) {
531 printk("RAM starting at 0x%x is not contiguous\n",
532 phys_mem.regions[1].address);
533 printk("Using RAM from 0 to 0x%lx\n", total-1);
540 chrp_init(unsigned long r3, unsigned long r4, unsigned long r5,
541 unsigned long r6, unsigned long r7)
543 struct device_node *root = find_path_device ("/");
544 char *machine = NULL;
546 #ifdef CONFIG_BLK_DEV_INITRD
547 /* take care of initrd if we have one */
550 initrd_start = r6 + KERNELBASE;
551 initrd_end = r6 + r7 + KERNELBASE;
553 #endif /* CONFIG_BLK_DEV_INITRD */
555 ISA_DMA_THRESHOLD = ~0L;
556 DMA_MODE_READ = 0x44;
557 DMA_MODE_WRITE = 0x48;
558 isa_io_base = CHRP_ISA_IO_BASE; /* default value */
559 ppc_do_canonicalize_irqs = 1;
562 machine = get_property(root, "model", NULL);
563 if (machine && strncmp(machine, "Pegasos", 7) == 0) {
564 _chrp_type = _CHRP_Pegasos;
565 } else if (machine && strncmp(machine, "IBM", 3) == 0) {
566 _chrp_type = _CHRP_IBM;
567 } else if (machine && strncmp(machine, "MOT", 3) == 0) {
568 _chrp_type = _CHRP_Motorola;
570 /* Let's assume it is an IBM chrp if all else fails */
571 _chrp_type = _CHRP_IBM;
574 ppc_md.setup_arch = chrp_setup_arch;
575 ppc_md.show_percpuinfo = of_show_percpuinfo;
576 ppc_md.show_cpuinfo = chrp_show_cpuinfo;
578 ppc_md.init_IRQ = chrp_init_IRQ;
579 if (_chrp_type == _CHRP_Pegasos)
580 ppc_md.get_irq = i8259_irq;
582 ppc_md.get_irq = openpic_get_irq;
584 ppc_md.init = chrp_init2;
586 ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
588 ppc_md.restart = chrp_restart;
589 ppc_md.power_off = chrp_power_off;
590 ppc_md.halt = chrp_halt;
592 ppc_md.time_init = chrp_time_init;
593 ppc_md.set_rtc_time = chrp_set_rtc_time;
594 ppc_md.get_rtc_time = chrp_get_rtc_time;
595 ppc_md.calibrate_decr = chrp_calibrate_decr;
597 ppc_md.find_end_of_memory = chrp_find_end_of_memory;
600 struct device_node *rtas;
603 rtas = find_devices("rtas");
605 if (get_property(rtas, "display-character", NULL)) {
606 ppc_md.progress = rtas_display_progress;
607 p = (unsigned int *) get_property
608 (rtas, "ibm,display-line-length", NULL);
611 } else if (get_property(rtas, "set-indicator", NULL))
612 ppc_md.progress = rtas_indicator_progress;
615 #ifdef CONFIG_BOOTX_TEXT
616 if (ppc_md.progress == NULL && boot_text_mapped)
617 ppc_md.progress = btext_progress;
621 smp_ops = &chrp_smp_ops;
622 #endif /* CONFIG_SMP */
625 * Print the banner, then scroll down so boot progress
626 * can be printed. -- Cort
628 if (ppc_md.progress) ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0x0);
632 rtas_display_progress(char *s, unsigned short hex)
637 if ( call_rtas( "display-character", 1, 1, NULL, '\r' ) )
643 if ( (*os == '\n') || (*os == '\r') )
647 call_rtas( "display-character", 1, 1, NULL, *os++ );
648 /* if we overwrite the screen length */
650 while ( (*os != 0) && (*os != '\n') && (*os != '\r') )
654 /*while ( width-- > 0 )*/
655 call_rtas( "display-character", 1, 1, NULL, ' ' );
659 rtas_indicator_progress(char *s, unsigned short hex)
661 call_rtas("set-indicator", 3, 1, NULL, 6, 0, hex);
664 #ifdef CONFIG_BOOTX_TEXT
666 btext_progress(char *s, unsigned short hex)
671 #endif /* CONFIG_BOOTX_TEXT */