blob: f1b70ab3c6fd892a34ef182427e32e63e0c52c2b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/ppc/platforms/setup.c
3 *
4 * Copyright (C) 1995 Linus Torvalds
5 * Adapted from 'alpha' version by Gary Thomas
6 * Modified by Cort Dougan (cort@cs.nmt.edu)
7 */
8
9/*
10 * bootup setup stuff..
11 */
12
13#include <linux/config.h>
14#include <linux/errno.h>
15#include <linux/sched.h>
16#include <linux/kernel.h>
17#include <linux/mm.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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#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>
40
41#include <asm/io.h>
42#include <asm/pgtable.h>
43#include <asm/prom.h>
44#include <asm/gg2.h>
45#include <asm/pci-bridge.h>
46#include <asm/dma.h>
47#include <asm/machdep.h>
48#include <asm/irq.h>
49#include <asm/hydra.h>
50#include <asm/sections.h>
51#include <asm/time.h>
52#include <asm/btext.h>
53#include <asm/i8259.h>
54#include <asm/open_pic.h>
55#include <asm/xmon.h>
56
57unsigned long chrp_get_rtc_time(void);
58int chrp_set_rtc_time(unsigned long nowtime);
59void chrp_calibrate_decr(void);
60long chrp_time_init(void);
61
62void chrp_find_bridges(void);
63void chrp_event_scan(void);
64void rtas_display_progress(char *, unsigned short);
65void rtas_indicator_progress(char *, unsigned short);
66void btext_progress(char *, unsigned short);
67
68extern unsigned long pmac_find_end_of_memory(void);
69extern int of_show_percpuinfo(struct seq_file *, int);
70
71int _chrp_type;
72EXPORT_SYMBOL(_chrp_type);
73
74/*
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
78 */
79extern irqreturn_t xmon_irq(int, void *, struct pt_regs *);
80
81extern dev_t boot_dev;
82
83extern PTE *Hash, *Hash_end;
84extern unsigned long Hash_size, Hash_mask;
85extern int probingmem;
86extern unsigned long loops_per_jiffy;
87static int max_width;
88
89#ifdef CONFIG_SMP
90extern struct smp_ops_t chrp_smp_ops;
91#endif
92
93static const char *gg2_memtypes[4] = {
94 "FPM", "SDRAM", "EDO", "BEDO"
95};
96static const char *gg2_cachesizes[4] = {
97 "256 KB", "512 KB", "1 MB", "Reserved"
98};
99static const char *gg2_cachetypes[4] = {
100 "Asynchronous", "Reserved", "Flow-Through Synchronous",
101 "Pipelined Synchronous"
102};
103static const char *gg2_cachemodes[4] = {
104 "Disabled", "Write-Through", "Copy-Back", "Transparent Mode"
105};
106
Jon Loeligerf495a8b2005-09-17 10:35:08 -0500107int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108chrp_show_cpuinfo(struct seq_file *m)
109{
110 int i, sdramen;
111 unsigned int t;
112 struct device_node *root;
113 const char *model = "";
114
115 root = find_path_device("/");
116 if (root)
117 model = get_property(root, "model", NULL);
118 seq_printf(m, "machine\t\t: CHRP %s\n", model);
119
120 /* longtrail (goldengate) stuff */
121 if (!strncmp(model, "IBM,LongTrail", 13)) {
122 /* VLSI VAS96011/12 `Golden Gate 2' */
123 /* Memory banks */
124 sdramen = (in_le32(gg2_pci_config_base + GG2_PCI_DRAM_CTRL)
125 >>31) & 1;
126 for (i = 0; i < (sdramen ? 4 : 6); i++) {
127 t = in_le32(gg2_pci_config_base+
128 GG2_PCI_DRAM_BANK0+
129 i*4);
130 if (!(t & 1))
131 continue;
132 switch ((t>>8) & 0x1f) {
133 case 0x1f:
134 model = "4 MB";
135 break;
136 case 0x1e:
137 model = "8 MB";
138 break;
139 case 0x1c:
140 model = "16 MB";
141 break;
142 case 0x18:
143 model = "32 MB";
144 break;
145 case 0x10:
146 model = "64 MB";
147 break;
148 case 0x00:
149 model = "128 MB";
150 break;
151 default:
152 model = "Reserved";
153 break;
154 }
155 seq_printf(m, "memory bank %d\t: %s %s\n", i, model,
156 gg2_memtypes[sdramen ? 1 : ((t>>1) & 3)]);
157 }
158 /* L2 cache */
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]);
164 }
165 return 0;
166}
167
168/*
169 * Fixes for the National Semiconductor PC78308VUL SuperI/O
170 *
171 * Some versions of Open Firmware incorrectly initialize the IRQ settings
172 * for keyboard and mouse
173 */
174static inline void __init sio_write(u8 val, u8 index)
175{
176 outb(index, 0x15c);
177 outb(val, 0x15d);
178}
179
180static inline u8 __init sio_read(u8 index)
181{
182 outb(index, 0x15c);
183 return inb(0x15d);
184}
185
186static void __init sio_fixup_irq(const char *name, u8 device, u8 level,
187 u8 type)
188{
189 u8 level0, type0, active;
190
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);
203 }
204}
205
206static void __init sio_init(void)
207{
208 struct device_node *root;
209
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);
216 }
217}
218
219
220static void __init pegasos_set_l2cr(void)
221{
222 struct device_node *np;
223
224 /* On Pegasos, enable the l2 cache if needed, as the OF forgets it */
225 if (_chrp_type != _CHRP_Pegasos)
226 return;
227
228 /* Enable L2 cache if needed */
229 np = find_type_devices("cpu");
230 if (np != NULL) {
231 unsigned int *l2cr = (unsigned int *)
232 get_property (np, "l2cr", NULL);
233 if (l2cr == NULL) {
234 printk ("Pegasos l2cr : no cpu l2cr property found\n");
235 return;
236 }
237 if (!((*l2cr) & 0x80000000)) {
238 printk ("Pegasos l2cr : L2 cache was not active, "
239 "activating\n");
240 _set_L2CR(0);
241 _set_L2CR((*l2cr) | 0x80000000);
242 }
243 }
244}
245
246void __init chrp_setup_arch(void)
247{
248 struct device_node *device;
249
250 /* init to some ~sane value until calibrate_delay() runs */
251 loops_per_jiffy = 50000000/HZ;
252
253#ifdef CONFIG_BLK_DEV_INITRD
254 /* this is fine for chrp */
255 initrd_below_start_ok = 1;
256
257 if (initrd_start)
258 ROOT_DEV = Root_RAM0;
259 else
260#endif
261 ROOT_DEV = Root_SDA2; /* sda2 (sda1 is for the kernel) */
262
263 /* On pegasos, enable the L2 cache if not already done by OF */
264 pegasos_set_l2cr();
265
266 /* Lookup PCI host bridges */
267 chrp_find_bridges();
268
269#ifndef CONFIG_PPC64BRIDGE
270 /*
271 * Temporary fixes for PCI devices.
272 * -- Geert
273 */
274 hydra_init(); /* Mac I/O */
275
276#endif /* CONFIG_PPC64BRIDGE */
277
278 /*
279 * Fix the Super I/O configuration
280 */
281 sio_init();
282
283 /* Get the event scan rate for the rtas so we know how
284 * often it expects a heartbeat. -- Cort
285 */
286 if ( rtas_data ) {
287 struct property *p;
288 device = find_devices("rtas");
289 for ( p = device->properties;
290 p && strncmp(p->name, "rtas-event-scan-rate", 20);
291 p = p->next )
292 /* nothing */ ;
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 );
299 }
300 }
301
302 pci_create_OF_bus_map();
303}
304
Jon Loeligerf495a8b2005-09-17 10:35:08 -0500305void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306chrp_event_scan(void)
307{
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,
312 __pa(log), 1024 );
313 ppc_md.heartbeat_count = ppc_md.heartbeat_reset;
314}
315
Jon Loeligerf495a8b2005-09-17 10:35:08 -0500316void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317chrp_restart(char *cmd)
318{
319 printk("RTAS system-reboot returned %d\n",
320 call_rtas("system-reboot", 0, 1, NULL));
321 for (;;);
322}
323
Jon Loeligerf495a8b2005-09-17 10:35:08 -0500324void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325chrp_power_off(void)
326{
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));
330 for (;;);
331}
332
Jon Loeligerf495a8b2005-09-17 10:35:08 -0500333void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334chrp_halt(void)
335{
336 chrp_power_off();
337}
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339/*
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.
344 */
345static void __init chrp_find_openpic(void)
346{
347 struct device_node *np;
348 int len, i;
349 unsigned int *iranges;
Al Viroe2178f12005-04-24 14:58:08 -0700350 void __iomem *isu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352 np = find_type_devices("open-pic");
353 if (np == NULL || np->n_addrs == 0)
354 return;
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");
360 return;
361 }
362
363 iranges = (unsigned int *) get_property(np, "interrupt-ranges", &len);
364 if (iranges == NULL || len < 2 * sizeof(unsigned int))
365 return; /* not distributed */
366
367 /*
368 * The first pair of cells in interrupt-ranges refers to the
369 * IDU; subsequent pairs refer to the ISUs.
370 */
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);
375 return;
376 }
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);
381 }
382 for (i = 1; i < len; ++i) {
383 iranges += 2;
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);
388 if (isu != NULL)
389 openpic_set_sources(iranges[0], iranges[1], isu);
390 else
391 printk(KERN_ERR "Failed to map OpenPIC ISU at %x!\n",
392 np->addrs[i].address);
393 }
394}
395
396#if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
397static struct irqaction xmon_irqaction = {
398 .handler = xmon_irq,
399 .mask = CPU_MASK_NONE,
400 .name = "XMON break",
401};
402#endif
403
404void __init chrp_init_IRQ(void)
405{
406 struct device_node *np;
407 int i;
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;
412#endif
413
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);
417
418 if (addrp == NULL)
419 continue;
420 chrp_int_ack = addrp[prom_n_addr_cells(np)-1];
421 break;
422 }
423 if (np == NULL)
424 printk(KERN_ERR "Cannot find PCI interrupt acknowledge address\n");
425
426 chrp_find_openpic();
427
428 if (OpenPIC_Addr) {
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;
432
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",
436 i8259_irq);
437
438 }
Paul Mackerrasf9bd1702005-10-26 16:47:42 +1000439 i8259_init(chrp_int_ack, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
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)
447 break;
448 if (kbd)
449 setup_irq(HYDRA_INT_ADB_NMI, &xmon_irqaction);
450#endif
451}
452
453void __init
454chrp_init2(void)
455{
456#ifdef CONFIG_NVRAM
Olaf Hering35e95e62005-10-28 17:46:19 -0700457 chrp_nvram_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#endif
459
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");
466
467 if (ppc_md.progress)
468 ppc_md.progress(" Have fun! ", 0x7777);
469}
470
471void __init
472chrp_init(unsigned long r3, unsigned long r4, unsigned long r5,
473 unsigned long r6, unsigned long r7)
474{
475 struct device_node *root = find_path_device ("/");
476 char *machine = NULL;
477
478#ifdef CONFIG_BLK_DEV_INITRD
479 /* take care of initrd if we have one */
480 if ( r6 )
481 {
482 initrd_start = r6 + KERNELBASE;
483 initrd_end = r6 + r7 + KERNELBASE;
484 }
485#endif /* CONFIG_BLK_DEV_INITRD */
486
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 */
Paul Mackerras35d81a4b2005-10-11 22:03:09 +1000491 ppc_do_canonicalize_irqs = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 if (root)
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;
501 } else {
502 /* Let's assume it is an IBM chrp if all else fails */
503 _chrp_type = _CHRP_IBM;
504 }
505
506 ppc_md.setup_arch = chrp_setup_arch;
507 ppc_md.show_percpuinfo = of_show_percpuinfo;
508 ppc_md.show_cpuinfo = chrp_show_cpuinfo;
509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 ppc_md.init_IRQ = chrp_init_IRQ;
511 if (_chrp_type == _CHRP_Pegasos)
512 ppc_md.get_irq = i8259_irq;
513 else
514 ppc_md.get_irq = openpic_get_irq;
515
516 ppc_md.init = chrp_init2;
517
518 ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
519
520 ppc_md.restart = chrp_restart;
521 ppc_md.power_off = chrp_power_off;
522 ppc_md.halt = chrp_halt;
523
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;
528
529 ppc_md.find_end_of_memory = pmac_find_end_of_memory;
530
531 if (rtas_data) {
532 struct device_node *rtas;
533 unsigned int *p;
534
535 rtas = find_devices("rtas");
536 if (rtas != NULL) {
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);
541 if (p)
542 max_width = *p;
543 } else if (get_property(rtas, "set-indicator", NULL))
544 ppc_md.progress = rtas_indicator_progress;
545 }
546 }
547#ifdef CONFIG_BOOTX_TEXT
548 if (ppc_md.progress == NULL && boot_text_mapped)
549 ppc_md.progress = btext_progress;
550#endif
551
552#ifdef CONFIG_SMP
Paul Mackerras7ed476d2005-10-19 21:44:51 +1000553 smp_ops = &chrp_smp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554#endif /* CONFIG_SMP */
555
556 /*
557 * Print the banner, then scroll down so boot progress
558 * can be printed. -- Cort
559 */
560 if (ppc_md.progress) ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0x0);
561}
562
Jon Loeligerf495a8b2005-09-17 10:35:08 -0500563void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564rtas_display_progress(char *s, unsigned short hex)
565{
566 int width;
567 char *os = s;
568
569 if ( call_rtas( "display-character", 1, 1, NULL, '\r' ) )
570 return;
571
572 width = max_width;
573 while ( *os )
574 {
575 if ( (*os == '\n') || (*os == '\r') )
576 width = max_width;
577 else
578 width--;
579 call_rtas( "display-character", 1, 1, NULL, *os++ );
580 /* if we overwrite the screen length */
581 if ( width == 0 )
582 while ( (*os != 0) && (*os != '\n') && (*os != '\r') )
583 os++;
584 }
585
586 /*while ( width-- > 0 )*/
587 call_rtas( "display-character", 1, 1, NULL, ' ' );
588}
589
Jon Loeligerf495a8b2005-09-17 10:35:08 -0500590void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591rtas_indicator_progress(char *s, unsigned short hex)
592{
593 call_rtas("set-indicator", 3, 1, NULL, 6, 0, hex);
594}
595
596#ifdef CONFIG_BOOTX_TEXT
597void
598btext_progress(char *s, unsigned short hex)
599{
600 prom_print(s);
601 prom_print("\n");
602}
603#endif /* CONFIG_BOOTX_TEXT */