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 chrp_irq_canonicalize(u_int irq)
348 * Finds the open-pic node and sets OpenPIC_Addr based on its reg property.
349 * Then checks if it has an interrupt-ranges property. If it does then
350 * we have a distributed open-pic, so call openpic_set_sources to tell
351 * the openpic code where to find the interrupt source registers.
353 static void __init chrp_find_openpic(void)
355 struct device_node *np;
357 unsigned int *iranges;
360 np = find_type_devices("open-pic");
361 if (np == NULL || np->n_addrs == 0)
363 printk(KERN_INFO "OpenPIC at %x (size %x)\n",
364 np->addrs[0].address, np->addrs[0].size);
365 OpenPIC_Addr = ioremap(np->addrs[0].address, 0x40000);
366 if (OpenPIC_Addr == NULL) {
367 printk(KERN_ERR "Failed to map OpenPIC!\n");
371 iranges = (unsigned int *) get_property(np, "interrupt-ranges", &len);
372 if (iranges == NULL || len < 2 * sizeof(unsigned int))
373 return; /* not distributed */
376 * The first pair of cells in interrupt-ranges refers to the
377 * IDU; subsequent pairs refer to the ISUs.
379 len /= 2 * sizeof(unsigned int);
380 if (np->n_addrs < len) {
381 printk(KERN_ERR "Insufficient addresses for distributed"
382 " OpenPIC (%d < %d)\n", np->n_addrs, len);
385 if (iranges[1] != 0) {
386 printk(KERN_INFO "OpenPIC irqs %d..%d in IDU\n",
387 iranges[0], iranges[0] + iranges[1] - 1);
388 openpic_set_sources(iranges[0], iranges[1], NULL);
390 for (i = 1; i < len; ++i) {
392 printk(KERN_INFO "OpenPIC irqs %d..%d in ISU at %x (%x)\n",
393 iranges[0], iranges[0] + iranges[1] - 1,
394 np->addrs[i].address, np->addrs[i].size);
395 isu = ioremap(np->addrs[i].address, np->addrs[i].size);
397 openpic_set_sources(iranges[0], iranges[1], isu);
399 printk(KERN_ERR "Failed to map OpenPIC ISU at %x!\n",
400 np->addrs[i].address);
404 #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
405 static struct irqaction xmon_irqaction = {
407 .mask = CPU_MASK_NONE,
408 .name = "XMON break",
412 void __init chrp_init_IRQ(void)
414 struct device_node *np;
416 unsigned long chrp_int_ack = 0;
417 unsigned char init_senses[NR_IRQS - NUM_8259_INTERRUPTS];
418 #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
419 struct device_node *kbd;
422 for (np = find_devices("pci"); np != NULL; np = np->next) {
423 unsigned int *addrp = (unsigned int *)
424 get_property(np, "8259-interrupt-acknowledge", NULL);
428 chrp_int_ack = addrp[prom_n_addr_cells(np)-1];
432 printk(KERN_ERR "Cannot find PCI interrupt acknowledge address\n");
437 prom_get_irq_senses(init_senses, NUM_8259_INTERRUPTS, NR_IRQS);
438 OpenPIC_InitSenses = init_senses;
439 OpenPIC_NumInitSenses = NR_IRQS - NUM_8259_INTERRUPTS;
441 openpic_init(NUM_8259_INTERRUPTS);
442 /* We have a cascade on OpenPIC IRQ 0, Linux IRQ 16 */
443 openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
447 for (i = 0; i < NUM_8259_INTERRUPTS; i++)
448 irq_desc[i].handler = &i8259_pic;
449 i8259_init(chrp_int_ack);
451 #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
452 /* see if there is a keyboard in the device tree
453 with a parent of type "adb" */
454 for (kbd = find_devices("keyboard"); kbd; kbd = kbd->next)
455 if (kbd->parent && kbd->parent->type
456 && strcmp(kbd->parent->type, "adb") == 0)
459 setup_irq(HYDRA_INT_ADB_NMI, &xmon_irqaction);
467 // XX replace this in a more saner way
468 // pmac_nvram_init();
471 request_region(0x20,0x20,"pic1");
472 request_region(0xa0,0x20,"pic2");
473 request_region(0x00,0x20,"dma1");
474 request_region(0x40,0x20,"timer");
475 request_region(0x80,0x10,"dma page reg");
476 request_region(0xc0,0x20,"dma2");
479 ppc_md.progress(" Have fun! ", 0x7777);
483 chrp_init(unsigned long r3, unsigned long r4, unsigned long r5,
484 unsigned long r6, unsigned long r7)
486 struct device_node *root = find_path_device ("/");
487 char *machine = NULL;
489 #ifdef CONFIG_BLK_DEV_INITRD
490 /* take care of initrd if we have one */
493 initrd_start = r6 + KERNELBASE;
494 initrd_end = r6 + r7 + KERNELBASE;
496 #endif /* CONFIG_BLK_DEV_INITRD */
498 ISA_DMA_THRESHOLD = ~0L;
499 DMA_MODE_READ = 0x44;
500 DMA_MODE_WRITE = 0x48;
501 isa_io_base = CHRP_ISA_IO_BASE; /* default value */
504 machine = get_property(root, "model", NULL);
505 if (machine && strncmp(machine, "Pegasos", 7) == 0) {
506 _chrp_type = _CHRP_Pegasos;
507 } else if (machine && strncmp(machine, "IBM", 3) == 0) {
508 _chrp_type = _CHRP_IBM;
509 } else if (machine && strncmp(machine, "MOT", 3) == 0) {
510 _chrp_type = _CHRP_Motorola;
512 /* Let's assume it is an IBM chrp if all else fails */
513 _chrp_type = _CHRP_IBM;
516 ppc_md.setup_arch = chrp_setup_arch;
517 ppc_md.show_percpuinfo = of_show_percpuinfo;
518 ppc_md.show_cpuinfo = chrp_show_cpuinfo;
520 ppc_md.irq_canonicalize = chrp_irq_canonicalize;
521 ppc_md.init_IRQ = chrp_init_IRQ;
522 if (_chrp_type == _CHRP_Pegasos)
523 ppc_md.get_irq = i8259_irq;
525 ppc_md.get_irq = openpic_get_irq;
527 ppc_md.init = chrp_init2;
529 ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
531 ppc_md.restart = chrp_restart;
532 ppc_md.power_off = chrp_power_off;
533 ppc_md.halt = chrp_halt;
535 ppc_md.time_init = chrp_time_init;
536 ppc_md.set_rtc_time = chrp_set_rtc_time;
537 ppc_md.get_rtc_time = chrp_get_rtc_time;
538 ppc_md.calibrate_decr = chrp_calibrate_decr;
540 ppc_md.find_end_of_memory = pmac_find_end_of_memory;
543 struct device_node *rtas;
546 rtas = find_devices("rtas");
548 if (get_property(rtas, "display-character", NULL)) {
549 ppc_md.progress = rtas_display_progress;
550 p = (unsigned int *) get_property
551 (rtas, "ibm,display-line-length", NULL);
554 } else if (get_property(rtas, "set-indicator", NULL))
555 ppc_md.progress = rtas_indicator_progress;
558 #ifdef CONFIG_BOOTX_TEXT
559 if (ppc_md.progress == NULL && boot_text_mapped)
560 ppc_md.progress = btext_progress;
564 ppc_md.smp_ops = &chrp_smp_ops;
565 #endif /* CONFIG_SMP */
568 * Print the banner, then scroll down so boot progress
569 * can be printed. -- Cort
571 if (ppc_md.progress) ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0x0);
575 rtas_display_progress(char *s, unsigned short hex)
580 if ( call_rtas( "display-character", 1, 1, NULL, '\r' ) )
586 if ( (*os == '\n') || (*os == '\r') )
590 call_rtas( "display-character", 1, 1, NULL, *os++ );
591 /* if we overwrite the screen length */
593 while ( (*os != 0) && (*os != '\n') && (*os != '\r') )
597 /*while ( width-- > 0 )*/
598 call_rtas( "display-character", 1, 1, NULL, ' ' );
602 rtas_indicator_progress(char *s, unsigned short hex)
604 call_rtas("set-indicator", 3, 1, NULL, 6, 0, hex);
607 #ifdef CONFIG_BOOTX_TEXT
609 btext_progress(char *s, unsigned short hex)
614 #endif /* CONFIG_BOOTX_TEXT */