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>
38 #include <linux/root_dev.h>
39 #include <linux/initrd.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 * XXX this should be in xmon.h, but putting it there means xmon.h
73 * has to include <linux/interrupt.h> (to get irqreturn_t), which
74 * causes all sorts of problems. -- paulus
76 extern irqreturn_t xmon_irq(int, void *, struct pt_regs *);
78 extern dev_t boot_dev;
80 extern PTE *Hash, *Hash_end;
81 extern unsigned long Hash_size, Hash_mask;
82 extern int probingmem;
83 extern unsigned long loops_per_jiffy;
87 extern struct smp_ops_t chrp_smp_ops;
90 static const char *gg2_memtypes[4] = {
91 "FPM", "SDRAM", "EDO", "BEDO"
93 static const char *gg2_cachesizes[4] = {
94 "256 KB", "512 KB", "1 MB", "Reserved"
96 static const char *gg2_cachetypes[4] = {
97 "Asynchronous", "Reserved", "Flow-Through Synchronous",
98 "Pipelined Synchronous"
100 static const char *gg2_cachemodes[4] = {
101 "Disabled", "Write-Through", "Copy-Back", "Transparent Mode"
105 chrp_show_cpuinfo(struct seq_file *m)
109 struct device_node *root;
110 const char *model = "";
112 root = find_path_device("/");
114 model = get_property(root, "model", NULL);
115 seq_printf(m, "machine\t\t: CHRP %s\n", model);
117 /* longtrail (goldengate) stuff */
118 if (!strncmp(model, "IBM,LongTrail", 13)) {
119 /* VLSI VAS96011/12 `Golden Gate 2' */
121 sdramen = (in_le32((unsigned *)(gg2_pci_config_base+
124 for (i = 0; i < (sdramen ? 4 : 6); i++) {
125 t = in_le32((unsigned *)(gg2_pci_config_base+
130 switch ((t>>8) & 0x1f) {
153 seq_printf(m, "memory bank %d\t: %s %s\n", i, model,
154 gg2_memtypes[sdramen ? 1 : ((t>>1) & 3)]);
157 t = in_le32((unsigned *)(gg2_pci_config_base+GG2_PCI_CC_CTRL));
158 seq_printf(m, "board l2\t: %s %s (%s)\n",
159 gg2_cachesizes[(t>>7) & 3],
160 gg2_cachetypes[(t>>2) & 3],
161 gg2_cachemodes[t & 3]);
167 * Fixes for the National Semiconductor PC78308VUL SuperI/O
169 * Some versions of Open Firmware incorrectly initialize the IRQ settings
170 * for keyboard and mouse
172 static inline void __init sio_write(u8 val, u8 index)
178 static inline u8 __init sio_read(u8 index)
184 static void __init sio_fixup_irq(const char *name, u8 device, u8 level,
187 u8 level0, type0, active;
189 /* select logical device */
190 sio_write(device, 0x07);
191 active = sio_read(0x30);
192 level0 = sio_read(0x70);
193 type0 = sio_read(0x71);
194 if (level0 != level || type0 != type || !active) {
195 printk(KERN_WARNING "sio: %s irq level %d, type %d, %sactive: "
196 "remapping to level %d, type %d, active\n",
197 name, level0, type0, !active ? "in" : "", level, type);
198 sio_write(0x01, 0x30);
199 sio_write(level, 0x70);
200 sio_write(type, 0x71);
204 static void __init sio_init(void)
206 struct device_node *root;
208 if ((root = find_path_device("/")) &&
209 !strncmp(get_property(root, "model", NULL), "IBM,LongTrail", 13)) {
210 /* logical device 0 (KBC/Keyboard) */
211 sio_fixup_irq("keyboard", 0, 1, 2);
212 /* select logical device 1 (KBC/Mouse) */
213 sio_fixup_irq("mouse", 1, 12, 2);
219 chrp_setup_arch(void)
221 struct device_node *device;
223 /* init to some ~sane value until calibrate_delay() runs */
224 loops_per_jiffy = 50000000/HZ;
226 #ifdef CONFIG_BLK_DEV_INITRD
227 /* this is fine for chrp */
228 initrd_below_start_ok = 1;
231 ROOT_DEV = Root_RAM0;
234 ROOT_DEV = Root_SDA2; /* sda2 (sda1 is for the kernel) */
236 /* Lookup PCI host bridges */
239 #ifndef CONFIG_PPC64BRIDGE
241 * Temporary fixes for PCI devices.
244 hydra_init(); /* Mac I/O */
246 #endif /* CONFIG_PPC64BRIDGE */
249 * Fix the Super I/O configuration
254 * Setup the console operations
256 #ifdef CONFIG_DUMMY_CONSOLE
257 conswitchp = &dummy_con;
260 /* Get the event scan rate for the rtas so we know how
261 * often it expects a heartbeat. -- Cort
265 device = find_devices("rtas");
266 for ( p = device->properties;
267 p && strncmp(p->name, "rtas-event-scan-rate", 20);
270 if ( p && *(unsigned long *)p->value ) {
271 ppc_md.heartbeat = chrp_event_scan;
272 ppc_md.heartbeat_reset = (HZ/(*(unsigned long *)p->value)*30)-1;
273 ppc_md.heartbeat_count = 1;
274 printk("RTAS Event Scan Rate: %lu (%lu jiffies)\n",
275 *(unsigned long *)p->value, ppc_md.heartbeat_reset );
279 pci_create_OF_bus_map();
283 chrp_event_scan(void)
285 unsigned char log[1024];
286 unsigned long ret = 0;
287 /* XXX: we should loop until the hardware says no more error logs -- Cort */
288 call_rtas( "event-scan", 4, 1, &ret, 0xffffffff, 0,
290 ppc_md.heartbeat_count = ppc_md.heartbeat_reset;
294 chrp_restart(char *cmd)
296 printk("RTAS system-reboot returned %d\n",
297 call_rtas("system-reboot", 0, 1, NULL));
304 /* allow power on only with power button press */
305 printk("RTAS power-off returned %d\n",
306 call_rtas("power-off", 2, 1, NULL,0xffffffff,0xffffffff));
317 chrp_irq_canonicalize(u_int irq)
325 * Finds the open-pic node and sets OpenPIC_Addr based on its reg property.
326 * Then checks if it has an interrupt-ranges property. If it does then
327 * we have a distributed open-pic, so call openpic_set_sources to tell
328 * the openpic code where to find the interrupt source registers.
330 static void __init chrp_find_openpic(void)
332 struct device_node *np;
334 unsigned int *iranges;
337 np = find_type_devices("open-pic");
338 if (np == NULL || np->n_addrs == 0)
340 printk(KERN_INFO "OpenPIC at %x (size %x)\n",
341 np->addrs[0].address, np->addrs[0].size);
342 OpenPIC_Addr = ioremap(np->addrs[0].address, 0x40000);
343 if (OpenPIC_Addr == NULL) {
344 printk(KERN_ERR "Failed to map OpenPIC!\n");
348 iranges = (unsigned int *) get_property(np, "interrupt-ranges", &len);
349 if (iranges == NULL || len < 2 * sizeof(unsigned int))
350 return; /* not distributed */
353 * The first pair of cells in interrupt-ranges refers to the
354 * IDU; subsequent pairs refer to the ISUs.
356 len /= 2 * sizeof(unsigned int);
357 if (np->n_addrs < len) {
358 printk(KERN_ERR "Insufficient addresses for distributed"
359 " OpenPIC (%d < %d)\n", np->n_addrs, len);
362 if (iranges[1] != 0) {
363 printk(KERN_INFO "OpenPIC irqs %d..%d in IDU\n",
364 iranges[0], iranges[0] + iranges[1] - 1);
365 openpic_set_sources(iranges[0], iranges[1], NULL);
367 for (i = 1; i < len; ++i) {
369 printk(KERN_INFO "OpenPIC irqs %d..%d in ISU at %x (%x)\n",
370 iranges[0], iranges[0] + iranges[1] - 1,
371 np->addrs[i].address, np->addrs[i].size);
372 isu = ioremap(np->addrs[i].address, np->addrs[i].size);
374 openpic_set_sources(iranges[0], iranges[1], isu);
376 printk(KERN_ERR "Failed to map OpenPIC ISU at %x!\n",
377 np->addrs[i].address);
381 void __init chrp_init_IRQ(void)
383 struct device_node *np;
385 unsigned long chrp_int_ack;
386 unsigned char init_senses[NR_IRQS - NUM_8259_INTERRUPTS];
387 #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
388 struct device_node *kbd;
391 for (np = find_devices("pci"); np != NULL; np = np->next) {
392 unsigned int *addrp = (unsigned int *)
393 get_property(np, "8259-interrupt-acknowledge", NULL);
397 chrp_int_ack = addrp[prom_n_addr_cells(np)-1];
401 printk(KERN_ERR "Cannot find PCI interrupt acknowledge address\n");
405 prom_get_irq_senses(init_senses, NUM_8259_INTERRUPTS, NR_IRQS);
406 OpenPIC_InitSenses = init_senses;
407 OpenPIC_NumInitSenses = NR_IRQS - NUM_8259_INTERRUPTS;
409 openpic_init(NUM_8259_INTERRUPTS);
410 /* We have a cascade on OpenPIC IRQ 0, Linux IRQ 16 */
411 openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
414 for (i = 0; i < NUM_8259_INTERRUPTS; i++)
415 irq_desc[i].handler = &i8259_pic;
416 i8259_init(chrp_int_ack);
418 #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
419 /* see if there is a keyboard in the device tree
420 with a parent of type "adb" */
421 for (kbd = find_devices("keyboard"); kbd; kbd = kbd->next)
422 if (kbd->parent && kbd->parent->type
423 && strcmp(kbd->parent->type, "adb") == 0)
426 request_irq(HYDRA_INT_ADB_NMI, xmon_irq, 0, "XMON break", 0);
434 // XX replace this in a more saner way
435 // pmac_nvram_init();
438 request_region(0x20,0x20,"pic1");
439 request_region(0xa0,0x20,"pic2");
440 request_region(0x00,0x20,"dma1");
441 request_region(0x40,0x20,"timer");
442 request_region(0x80,0x10,"dma page reg");
443 request_region(0xc0,0x20,"dma2");
446 ppc_md.progress(" Have fun! ", 0x7777);
450 chrp_init(unsigned long r3, unsigned long r4, unsigned long r5,
451 unsigned long r6, unsigned long r7)
453 #ifdef CONFIG_BLK_DEV_INITRD
454 /* take care of initrd if we have one */
457 initrd_start = r6 + KERNELBASE;
458 initrd_end = r6 + r7 + KERNELBASE;
460 #endif /* CONFIG_BLK_DEV_INITRD */
462 ISA_DMA_THRESHOLD = ~0L;
463 DMA_MODE_READ = 0x44;
464 DMA_MODE_WRITE = 0x48;
465 isa_io_base = CHRP_ISA_IO_BASE; /* default value */
467 ppc_md.setup_arch = chrp_setup_arch;
468 ppc_md.show_percpuinfo = of_show_percpuinfo;
469 ppc_md.show_cpuinfo = chrp_show_cpuinfo;
470 ppc_md.irq_canonicalize = chrp_irq_canonicalize;
471 ppc_md.init_IRQ = chrp_init_IRQ;
472 ppc_md.get_irq = openpic_get_irq;
474 ppc_md.init = chrp_init2;
476 ppc_md.restart = chrp_restart;
477 ppc_md.power_off = chrp_power_off;
478 ppc_md.halt = chrp_halt;
480 ppc_md.time_init = chrp_time_init;
481 ppc_md.set_rtc_time = chrp_set_rtc_time;
482 ppc_md.get_rtc_time = chrp_get_rtc_time;
483 ppc_md.calibrate_decr = chrp_calibrate_decr;
485 ppc_md.find_end_of_memory = pmac_find_end_of_memory;
488 struct device_node *rtas;
491 rtas = find_devices("rtas");
493 if (get_property(rtas, "display-character", NULL)) {
494 ppc_md.progress = rtas_display_progress;
495 p = (unsigned int *) get_property
496 (rtas, "ibm,display-line-length", NULL);
499 } else if (get_property(rtas, "set-indicator", NULL))
500 ppc_md.progress = rtas_indicator_progress;
503 #ifdef CONFIG_BOOTX_TEXT
504 if (ppc_md.progress == NULL && boot_text_mapped)
505 ppc_md.progress = btext_progress;
509 ppc_md.smp_ops = &chrp_smp_ops;
510 #endif /* CONFIG_SMP */
513 * Print the banner, then scroll down so boot progress
514 * can be printed. -- Cort
516 if (ppc_md.progress) ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0x0);
520 rtas_display_progress(char *s, unsigned short hex)
525 if ( call_rtas( "display-character", 1, 1, NULL, '\r' ) )
531 if ( (*os == '\n') || (*os == '\r') )
535 call_rtas( "display-character", 1, 1, NULL, *os++ );
536 /* if we overwrite the screen length */
538 while ( (*os != 0) && (*os != '\n') && (*os != '\r') )
542 /*while ( width-- > 0 )*/
543 call_rtas( "display-character", 1, 1, NULL, ' ' );
547 rtas_indicator_progress(char *s, unsigned short hex)
549 call_rtas("set-indicator", 3, 1, NULL, 6, 0, hex);
552 #ifdef CONFIG_BOOTX_TEXT
554 btext_progress(char *s, unsigned short hex)
559 #endif /* CONFIG_BOOTX_TEXT */