Import 2.3.50pre1
[davej-history.git] / arch / ppc / kernel / pmac_setup.c
blobc2c4cbbf496f4bc0e333e5c1ae9877eeb28cfd83
1 /*
2 * linux/arch/ppc/kernel/setup.c
4 * PowerPC version
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 * Adapted for Power Macintosh by Paul Mackerras
8 * Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au)
10 * Derived from "arch/alpha/kernel/setup.c"
11 * Copyright (C) 1995 Linus Torvalds
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
21 * bootup setup stuff..
24 #include <linux/config.h>
25 #include <linux/init.h>
26 #include <linux/errno.h>
27 #include <linux/sched.h>
28 #include <linux/kernel.h>
29 #include <linux/mm.h>
30 #include <linux/stddef.h>
31 #include <linux/unistd.h>
32 #include <linux/ptrace.h>
33 #include <linux/malloc.h>
34 #include <linux/user.h>
35 #include <linux/a.out.h>
36 #include <linux/tty.h>
37 #include <linux/string.h>
38 #include <linux/delay.h>
39 #include <linux/ioport.h>
40 #include <linux/major.h>
41 #include <linux/blk.h>
42 #include <linux/vt_kern.h>
43 #include <linux/console.h>
44 #include <linux/ide.h>
45 #include <linux/pci.h>
46 #include <linux/adb.h>
47 #include <linux/cuda.h>
48 #include <linux/pmu.h>
50 #include <asm/init.h>
51 #include <asm/prom.h>
52 #include <asm/system.h>
53 #include <asm/pgtable.h>
54 #include <asm/bitops.h>
55 #include <asm/io.h>
56 #include <asm/pci-bridge.h>
57 #include <asm/ohare.h>
58 #include <asm/mediabay.h>
59 #include <asm/feature.h>
60 #include <asm/machdep.h>
61 #include <asm/keyboard.h>
62 #include <asm/dma.h>
63 #include <asm/bootx.h>
65 #include "time.h"
66 #include "local_irq.h"
67 #include "pmac_pic.h"
69 #undef SHOW_GATWICK_IRQS
71 unsigned long pmac_get_rtc_time(void);
72 int pmac_set_rtc_time(unsigned long nowtime);
73 void pmac_read_rtc_time(void);
74 void pmac_calibrate_decr(void);
75 void pmac_setup_pci_ptrs(void);
77 extern int mackbd_setkeycode(unsigned int scancode, unsigned int keycode);
78 extern int mackbd_getkeycode(unsigned int scancode);
79 extern int mackbd_translate(unsigned char scancode, unsigned char *keycode,
80 char raw_mode);
81 extern char mackbd_unexpected_up(unsigned char keycode);
82 extern void mackbd_leds(unsigned char leds);
83 extern void mackbd_init_hw(void);
84 #ifdef CONFIG_MAGIC_SYSRQ
85 unsigned char mackbd_sysrq_xlate[128];
86 #endif /* CONFIG_MAGIC_SYSRQ */
87 extern int pckbd_setkeycode(unsigned int scancode, unsigned int keycode);
88 extern int pckbd_getkeycode(unsigned int scancode);
89 extern int pckbd_translate(unsigned char scancode, unsigned char *keycode,
90 char raw_mode);
91 extern char pckbd_unexpected_up(unsigned char keycode);
92 extern void pckbd_leds(unsigned char leds);
93 extern void pckbd_init_hw(void);
95 unsigned char drive_info;
97 int ppc_override_l2cr = 0;
98 int ppc_override_l2cr_value;
99 int has_l2cache = 0;
101 extern char saved_command_line[];
103 #define DEFAULT_ROOT_DEVICE 0x0801 /* sda1 - slightly silly choice */
105 extern void zs_kgdb_hook(int tty_num);
106 static void ohare_init(void);
107 static void init_p2pbridge(void);
108 static void init_uninorth(void);
109 #ifdef CONFIG_BOOTX_TEXT
110 void pmac_progress(char *s, unsigned short hex);
111 #endif
113 __pmac
115 pmac_get_cpuinfo(char *buffer)
117 int len;
118 struct device_node *np;
119 char *pp;
120 int plen;
122 /* find motherboard type */
123 len = sprintf(buffer, "machine\t\t: ");
124 np = find_devices("device-tree");
125 if (np != NULL) {
126 pp = (char *) get_property(np, "model", NULL);
127 if (pp != NULL)
128 len += sprintf(buffer+len, "%s\n", pp);
129 else
130 len += sprintf(buffer+len, "PowerMac\n");
131 pp = (char *) get_property(np, "compatible", &plen);
132 if (pp != NULL) {
133 len += sprintf(buffer+len, "motherboard\t:");
134 while (plen > 0) {
135 int l = strlen(pp) + 1;
136 len += sprintf(buffer+len, " %s", pp);
137 plen -= l;
138 pp += l;
140 buffer[len++] = '\n';
142 } else
143 len += sprintf(buffer+len, "PowerMac\n");
145 /* find l2 cache info */
146 np = find_devices("l2-cache");
147 if (np == 0)
148 np = find_type_devices("cache");
149 if (np != 0) {
150 unsigned int *ic = (unsigned int *)
151 get_property(np, "i-cache-size", NULL);
152 unsigned int *dc = (unsigned int *)
153 get_property(np, "d-cache-size", NULL);
154 len += sprintf(buffer+len, "L2 cache\t:");
155 has_l2cache = 1;
156 if (get_property(np, "cache-unified", NULL) != 0 && dc) {
157 len += sprintf(buffer+len, " %dK unified", *dc / 1024);
158 } else {
159 if (ic)
160 len += sprintf(buffer+len, " %dK instruction",
161 *ic / 1024);
162 if (dc)
163 len += sprintf(buffer+len, "%s %dK data",
164 (ic? " +": ""), *dc / 1024);
166 pp = get_property(np, "ram-type", NULL);
167 if (pp)
168 len += sprintf(buffer+len, " %s", pp);
169 buffer[len++] = '\n';
172 /* find ram info */
173 np = find_devices("memory");
174 if (np != 0) {
175 int n;
176 struct reg_property *reg = (struct reg_property *)
177 get_property(np, "reg", &n);
179 if (reg != 0) {
180 unsigned long total = 0;
182 for (n /= sizeof(struct reg_property); n > 0; --n)
183 total += (reg++)->size;
184 len += sprintf(buffer+len, "memory\t\t: %luMB\n",
185 total >> 20);
189 /* Checks "l2cr-value" property in the registry */
190 np = find_devices("cpus");
191 if (np == 0)
192 np = find_type_devices("cpu");
193 if (np != 0) {
194 unsigned int *l2cr = (unsigned int *)
195 get_property(np, "l2cr-value", NULL);
196 if (l2cr != 0) {
197 len += sprintf(buffer+len, "l2cr override\t: 0x%x\n", *l2cr);
201 return len;
204 #ifdef CONFIG_SCSI
205 /* Find the device number for the disk (if any) at target tgt
206 on host adaptor host. We just need to get the prototype from
207 sd.h */
208 #include <linux/blkdev.h>
209 #include "../../../drivers/scsi/scsi.h"
210 #include "../../../drivers/scsi/sd.h"
212 #endif
215 * Dummy mksound function that does nothing.
216 * The real one is in the dmasound driver.
218 __pmac
219 static void
220 pmac_mksound(unsigned int hz, unsigned int ticks)
224 static volatile u32 *sysctrl_regs;
226 void __init
227 pmac_setup_arch(void)
229 struct device_node *cpu;
230 int *fp;
232 /* Set loops_per_sec to a half-way reasonable value,
233 for use until calibrate_delay gets called. */
234 cpu = find_type_devices("cpu");
235 if (cpu != 0) {
236 fp = (int *) get_property(cpu, "clock-frequency", NULL);
237 if (fp != 0) {
238 switch (_get_PVR() >> 16) {
239 case 4: /* 604 */
240 case 8: /* G3 */
241 case 9: /* 604e */
242 case 10: /* mach V (604ev5) */
243 case 12: /* G4 */
244 case 20: /* 620 */
245 loops_per_sec = *fp;
246 break;
247 default: /* 601, 603, etc. */
248 loops_per_sec = *fp / 2;
250 } else
251 loops_per_sec = 50000000;
254 /* this area has the CPU identification register
255 and some registers used by smp boards */
256 sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000);
257 __ioremap(0xffc00000, 0x400000, pgprot_val(PAGE_READONLY));
258 ohare_init();
260 pmac_find_bridges();
261 init_p2pbridge();
262 init_uninorth();
264 /* Checks "l2cr-value" property in the registry */
265 if ( (_get_PVR() >> 16) == 8 || (_get_PVR() >> 16) == 12 ) {
266 struct device_node *np = find_devices("cpus");
267 if (np == 0)
268 np = find_type_devices("cpu");
269 if (np != 0) {
270 unsigned int *l2cr = (unsigned int *)
271 get_property(np, "l2cr-value", NULL);
272 if (l2cr != 0) {
273 ppc_override_l2cr = 1;
274 ppc_override_l2cr_value = *l2cr;
275 _set_L2CR(0);
276 _set_L2CR(ppc_override_l2cr_value);
281 if (ppc_override_l2cr)
282 printk(KERN_INFO "L2CR overriden (0x%x), backside cache is %s\n",
283 ppc_override_l2cr_value, (ppc_override_l2cr_value & 0x80000000)
284 ? "enabled" : "disabled");
286 #ifdef CONFIG_KGDB
287 zs_kgdb_hook(0);
288 #endif
290 #ifdef CONFIG_ADB_CUDA
291 find_via_cuda();
292 #endif
293 #ifdef CONFIG_ADB_PMU
294 find_via_pmu();
295 #endif
297 #ifdef CONFIG_DUMMY_CONSOLE
298 conswitchp = &dummy_con;
299 #endif
301 kd_mksound = pmac_mksound;
303 #ifdef CONFIG_BLK_DEV_INITRD
304 if (initrd_start)
305 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
306 else
307 #endif
308 ROOT_DEV = to_kdev_t(DEFAULT_ROOT_DEVICE);
312 * Tweak the PCI-PCI bridge chip on the blue & white G3s.
314 static void __init init_p2pbridge(void)
316 struct device_node *p2pbridge;
317 unsigned char bus, devfn;
318 unsigned short val;
320 /* XXX it would be better here to identify the specific
321 PCI-PCI bridge chip we have. */
322 if ((p2pbridge = find_devices("pci-bridge")) == 0
323 || p2pbridge->parent == NULL
324 || strcmp(p2pbridge->parent->name, "pci") != 0)
325 return;
326 if (pci_device_loc(p2pbridge, &bus, &devfn) < 0)
327 return;
328 if (ppc_md.pcibios_read_config_word(bus, devfn, PCI_BRIDGE_CONTROL, &val) < 0) {
329 printk(KERN_ERR "init_p2pbridge: couldn't read bridge control\n");
330 return;
332 val &= ~PCI_BRIDGE_CTL_MASTER_ABORT;
333 ppc_md.pcibios_write_config_word(bus, devfn, PCI_BRIDGE_CONTROL, val);
334 ppc_md.pcibios_read_config_word(bus, devfn, PCI_BRIDGE_CONTROL, &val);
337 static void __init ohare_init(void)
340 * Turn on the L2 cache.
341 * We assume that we have a PSX memory controller iff
342 * we have an ohare I/O controller.
344 if (find_devices("ohare") != NULL) {
345 if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) {
346 if (sysctrl_regs[4] & 0x10)
347 sysctrl_regs[4] |= 0x04000020;
348 else
349 sysctrl_regs[4] |= 0x04000000;
350 if(has_l2cache)
351 printk(KERN_INFO "Level 2 cache enabled\n");
356 static void __init
357 init_uninorth(void)
360 * Turns on the gmac clock so that it responds to PCI cycles
361 * later, the driver may want to turn it off again to save
362 * power when interface is down
364 struct device_node* uni_n = find_devices("uni-n");
365 struct device_node* gmac = find_devices("ethernet");
366 unsigned long* addr;
368 if (!uni_n || uni_n->n_addrs < 1)
369 return;
370 addr = ioremap(uni_n->addrs[0].address, 0x300);
372 while(gmac) {
373 if (device_is_compatible(gmac, "gmac"))
374 break;
375 gmac = gmac->next;
377 if (gmac) {
378 *(addr + 8) |= 2;
379 eieio();
383 extern char *bootpath;
384 extern char *bootdevice;
385 void *boot_host;
386 int boot_target;
387 int boot_part;
388 kdev_t boot_dev;
390 extern void via_pmu_start(void);
392 void __init
393 pmac_init2(void)
395 #ifdef CONFIG_ADB_PMU
396 via_pmu_start();
397 #endif
398 #ifdef CONFIG_NVRAM
399 pmac_nvram_init();
400 #endif
401 #ifdef CONFIG_PMAC_PBOOK
402 media_bay_init();
403 #endif
406 #ifdef CONFIG_SCSI
407 void __init
408 note_scsi_host(struct device_node *node, void *host)
410 int l;
411 char *p;
413 l = strlen(node->full_name);
414 if (bootpath != NULL && bootdevice != NULL
415 && strncmp(node->full_name, bootdevice, l) == 0
416 && (bootdevice[l] == '/' || bootdevice[l] == 0)) {
417 boot_host = host;
419 * There's a bug in OF 1.0.5. (Why am I not surprised.)
420 * If you pass a path like scsi/sd@1:0 to canon, it returns
421 * something like /bandit@F2000000/gc@10/53c94@10000/sd@0,0
422 * That is, the scsi target number doesn't get preserved.
423 * So we pick the target number out of bootpath and use that.
425 p = strstr(bootpath, "/sd@");
426 if (p != NULL) {
427 p += 4;
428 boot_target = simple_strtoul(p, NULL, 10);
429 p = strchr(p, ':');
430 if (p != NULL)
431 boot_part = simple_strtoul(p + 1, NULL, 10);
435 #endif
437 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
439 kdev_t __init find_ide_boot(void)
441 char *p;
442 int n;
443 kdev_t __init pmac_find_ide_boot(char *bootdevice, int n);
445 if (bootdevice == NULL)
446 return 0;
447 p = strrchr(bootdevice, '/');
448 if (p == NULL)
449 return 0;
450 n = p - bootdevice;
452 return pmac_find_ide_boot(bootdevice, n);
454 #endif /* CONFIG_BLK_DEV_IDE && CONFIG_BLK_DEV_IDE_PMAC */
456 void __init find_boot_device(void)
458 #ifdef CONFIG_SCSI
459 if (boot_host != NULL) {
460 boot_dev = sd_find_target(boot_host, boot_target);
461 if (boot_dev != 0)
462 return;
464 #endif
465 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
466 boot_dev = find_ide_boot();
467 #endif
470 /* can't be __init - can be called whenever a disk is first accessed */
471 __pmac
472 void note_bootable_part(kdev_t dev, int part)
474 static int found_boot = 0;
475 char *p;
477 /* Do nothing if the root has been set already. */
478 if (ROOT_DEV != to_kdev_t(DEFAULT_ROOT_DEVICE))
479 return;
480 p = strstr(saved_command_line, "root=");
481 if (p != NULL && (p == saved_command_line || p[-1] == ' '))
482 return;
484 if (!found_boot) {
485 find_boot_device();
486 found_boot = 1;
488 if (boot_dev == 0 || dev == boot_dev) {
489 ROOT_DEV = MKDEV(MAJOR(dev), MINOR(dev) + part);
490 boot_dev = NODEV;
491 printk(" (root on %d)", part);
495 void
496 pmac_restart(char *cmd)
498 #ifdef CONFIG_ADB_CUDA
499 struct adb_request req;
500 #endif /* CONFIG_ADB_CUDA */
502 switch (sys_ctrler) {
503 #ifdef CONFIG_ADB_CUDA
504 case SYS_CTRLER_CUDA:
505 cuda_request(&req, NULL, 2, CUDA_PACKET,
506 CUDA_RESET_SYSTEM);
507 for (;;)
508 cuda_poll();
509 break;
510 #endif /* CONFIG_ADB_CUDA */
511 #ifdef CONFIG_ADB_PMU
512 case SYS_CTRLER_PMU:
513 pmu_restart();
514 break;
515 #endif /* CONFIG_ADB_PMU */
516 default:
520 void
521 pmac_power_off(void)
523 #ifdef CONFIG_ADB_CUDA
524 struct adb_request req;
525 #endif /* CONFIG_ADB_CUDA */
527 switch (sys_ctrler) {
528 #ifdef CONFIG_ADB_CUDA
529 case SYS_CTRLER_CUDA:
530 cuda_request(&req, NULL, 2, CUDA_PACKET,
531 CUDA_POWERDOWN);
532 for (;;)
533 cuda_poll();
534 break;
535 #endif /* CONFIG_ADB_CUDA */
536 #ifdef CONFIG_ADB_PMU
537 case SYS_CTRLER_PMU:
538 pmu_shutdown();
539 break;
540 #endif /* CONFIG_ADB_PMU */
541 default:
545 void
546 pmac_halt(void)
548 pmac_power_off();
552 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
554 * IDE stuff.
556 void
557 pmac_ide_insw(ide_ioreg_t port, void *buf, int ns)
559 _insw_ns((unsigned short *)(port+_IO_BASE), buf, ns);
562 void
563 pmac_ide_outsw(ide_ioreg_t port, void *buf, int ns)
565 _outsw_ns((unsigned short *)(port+_IO_BASE), buf, ns);
569 pmac_ide_default_irq(ide_ioreg_t base)
571 return 0;
574 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
575 extern ide_ioreg_t pmac_ide_get_base(int index);
576 #endif
578 ide_ioreg_t
579 pmac_ide_default_io_base(int index)
581 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
582 return pmac_ide_get_base(index);
583 #else
584 return 0;
585 #endif
589 pmac_ide_check_region(ide_ioreg_t from, unsigned int extent)
591 return 0;
594 void
595 pmac_ide_request_region(ide_ioreg_t from,
596 unsigned int extent,
597 const char *name)
601 void
602 pmac_ide_release_region(ide_ioreg_t from,
603 unsigned int extent)
607 /* Convert the shorts/longs in hd_driveid from little to big endian;
608 * chars are endian independant, of course, but strings need to be flipped.
609 * (Despite what it says in drivers/block/ide.h, they come up as little
610 * endian...)
612 * Changes to linux/hdreg.h may require changes here. */
613 void
614 pmac_ide_fix_driveid(struct hd_driveid *id)
616 ppc_generic_ide_fix_driveid(id);
619 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
620 /* This is declared in drivers/block/ide-pmac.c */
621 void pmac_ide_init_hwif_ports (hw_regs_t *hw, ide_ioreg_t data_port, ide_ioreg_t ctrl_port, int *irq);
622 #else
624 * This registers the standard ports for this architecture with the IDE
625 * driver.
627 void pmac_ide_init_hwif_ports(hw_regs_t *hw, ide_ioreg_t data_port, ide_ioreg_t ctrl_port, int *irq)
630 #endif
631 #endif
633 void __init
634 pmac_init(unsigned long r3, unsigned long r4, unsigned long r5,
635 unsigned long r6, unsigned long r7)
637 pmac_setup_pci_ptrs();
639 /* isa_io_base gets set in pmac_find_bridges */
640 isa_mem_base = PMAC_ISA_MEM_BASE;
641 pci_dram_offset = PMAC_PCI_DRAM_OFFSET;
642 ISA_DMA_THRESHOLD = ~0L;
643 DMA_MODE_READ = 1;
644 DMA_MODE_WRITE = 2;
646 ppc_md.setup_arch = pmac_setup_arch;
647 ppc_md.setup_residual = NULL;
648 ppc_md.get_cpuinfo = pmac_get_cpuinfo;
649 ppc_md.irq_cannonicalize = NULL;
650 ppc_md.init_IRQ = pmac_pic_init;
651 ppc_md.get_irq = pmac_get_irq;
652 ppc_md.init = pmac_init2;
654 ppc_md.restart = pmac_restart;
655 ppc_md.power_off = pmac_power_off;
656 ppc_md.halt = pmac_halt;
658 ppc_md.time_init = NULL;
659 ppc_md.set_rtc_time = pmac_set_rtc_time;
660 ppc_md.get_rtc_time = pmac_get_rtc_time;
661 ppc_md.calibrate_decr = pmac_calibrate_decr;
663 #if defined(CONFIG_VT) && defined(CONFIG_ADB_KEYBOARD)
664 ppc_md.kbd_setkeycode = mackbd_setkeycode;
665 ppc_md.kbd_getkeycode = mackbd_getkeycode;
666 ppc_md.kbd_translate = mackbd_translate;
667 ppc_md.kbd_unexpected_up = mackbd_unexpected_up;
668 ppc_md.kbd_leds = mackbd_leds;
669 ppc_md.kbd_init_hw = mackbd_init_hw;
670 #ifdef CONFIG_MAGIC_SYSRQ
671 ppc_md.ppc_kbd_sysrq_xlate = mackbd_sysrq_xlate;
672 SYSRQ_KEY = 0x69;
673 #endif
674 #endif
676 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
677 ppc_ide_md.insw = pmac_ide_insw;
678 ppc_ide_md.outsw = pmac_ide_outsw;
679 ppc_ide_md.default_irq = pmac_ide_default_irq;
680 ppc_ide_md.default_io_base = pmac_ide_default_io_base;
681 ppc_ide_md.ide_check_region = pmac_ide_check_region;
682 ppc_ide_md.ide_request_region = pmac_ide_request_region;
683 ppc_ide_md.ide_release_region = pmac_ide_release_region;
684 ppc_ide_md.fix_driveid = pmac_ide_fix_driveid;
685 ppc_ide_md.ide_init_hwif = pmac_ide_init_hwif_ports;
687 ppc_ide_md.io_base = _IO_BASE; /* actually too early for this :-( */
688 #endif
689 #ifdef CONFIG_BOOTX_TEXT
690 ppc_md.progress = pmac_progress;
691 #endif
692 if (ppc_md.progress) ppc_md.progress("pmac_init(): exit", 0);
696 #ifdef CONFIG_BOOTX_TEXT
697 extern void drawchar(char c);
698 extern void drawstring(const char *c);
699 extern boot_infos_t *disp_bi;
700 void
701 pmac_progress(char *s, unsigned short hex)
703 if (disp_bi == 0)
704 return;
705 prom_drawstring(s);
706 prom_drawchar('\n');
708 #endif CONFIG_BOOTX_TEXT