* better
[mascara-docs.git] / i386 / linux-2.3.21 / arch / ppc / kernel / pmac_setup.c
blob6de8e50360e40f4f67eb9157dbf4e9430aef36f4
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/ide.h>
61 #include <asm/machdep.h>
62 #include <asm/keyboard.h>
63 #include <asm/dma.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;
100 extern char saved_command_line[];
102 #define DEFAULT_ROOT_DEVICE 0x0801 /* sda1 - slightly silly choice */
104 extern void zs_kgdb_hook(int tty_num);
105 static void ohare_init(void);
106 static void init_p2pbridge(void);
108 __pmac
110 pmac_get_cpuinfo(char *buffer)
112 int len;
113 struct device_node *np;
114 char *pp;
115 int plen;
117 /* find motherboard type */
118 len = sprintf(buffer, "machine\t\t: ");
119 np = find_devices("device-tree");
120 if (np != NULL) {
121 pp = (char *) get_property(np, "model", NULL);
122 if (pp != NULL)
123 len += sprintf(buffer+len, "%s\n", pp);
124 else
125 len += sprintf(buffer+len, "PowerMac\n");
126 pp = (char *) get_property(np, "compatible", &plen);
127 if (pp != NULL) {
128 len += sprintf(buffer+len, "motherboard\t:");
129 while (plen > 0) {
130 int l = strlen(pp) + 1;
131 len += sprintf(buffer+len, " %s", pp);
132 plen -= l;
133 pp += l;
135 buffer[len++] = '\n';
137 } else
138 len += sprintf(buffer+len, "PowerMac\n");
140 /* find l2 cache info */
141 np = find_devices("l2-cache");
142 if (np == 0)
143 np = find_type_devices("cache");
144 if (np != 0) {
145 unsigned int *ic = (unsigned int *)
146 get_property(np, "i-cache-size", NULL);
147 unsigned int *dc = (unsigned int *)
148 get_property(np, "d-cache-size", NULL);
149 len += sprintf(buffer+len, "L2 cache\t:");
150 if (get_property(np, "cache-unified", NULL) != 0 && dc) {
151 len += sprintf(buffer+len, " %dK unified", *dc / 1024);
152 } else {
153 if (ic)
154 len += sprintf(buffer+len, " %dK instruction",
155 *ic / 1024);
156 if (dc)
157 len += sprintf(buffer+len, "%s %dK data",
158 (ic? " +": ""), *dc / 1024);
160 pp = get_property(np, "ram-type", NULL);
161 if (pp)
162 len += sprintf(buffer+len, " %s", pp);
163 buffer[len++] = '\n';
166 /* find ram info */
167 np = find_devices("memory");
168 if (np != 0) {
169 int n;
170 struct reg_property *reg = (struct reg_property *)
171 get_property(np, "reg", &n);
173 if (reg != 0) {
174 unsigned long total = 0;
176 for (n /= sizeof(struct reg_property); n > 0; --n)
177 total += (reg++)->size;
178 len += sprintf(buffer+len, "memory\t\t: %luMB\n",
179 total >> 20);
183 /* Checks "l2cr-value" property in the registry */
184 np = find_devices("cpus");
185 if (np == 0)
186 np = find_type_devices("cpu");
187 if (np != 0) {
188 unsigned int *l2cr = (unsigned int *)
189 get_property(np, "l2cr-value", NULL);
190 if (l2cr != 0) {
191 len += sprintf(buffer+len, "l2cr override\t: 0x%x\n", *l2cr);
195 return len;
198 #ifdef CONFIG_SCSI
199 /* Find the device number for the disk (if any) at target tgt
200 on host adaptor host.
201 XXX this really really should be in drivers/scsi/sd.c. */
202 #include <linux/blkdev.h>
203 #include "../../../drivers/scsi/scsi.h"
204 #include "../../../drivers/scsi/sd.h"
205 #include "../../../drivers/scsi/hosts.h"
207 #define SD_MAJOR(i) (!(i) ? SCSI_DISK0_MAJOR : SCSI_DISK1_MAJOR-1+(i))
208 #define SD_MAJOR_NUMBER(i) SD_MAJOR((i) >> 8)
209 #define SD_MINOR_NUMBER(i) ((i) & 255)
210 #define MKDEV_SD_PARTITION(i) MKDEV(SD_MAJOR_NUMBER(i), SD_MINOR_NUMBER(i))
211 #define MKDEV_SD(index) MKDEV_SD_PARTITION((index) << 4)
213 __init
214 kdev_t sd_find_target(void *host, int tgt)
216 Scsi_Disk *dp;
217 int i;
218 #ifdef CONFIG_BLK_DEV_SD
219 for (dp = rscsi_disks, i = 0; i < sd_template.dev_max; ++i, ++dp)
220 if (dp->device != NULL && dp->device->host == host
221 && dp->device->id == tgt)
222 return MKDEV_SD(i);
223 #endif /* CONFIG_BLK_DEV_SD */
224 return 0;
226 #endif
229 * Dummy mksound function that does nothing.
230 * The real one is in the dmasound driver.
232 __pmac
233 static void
234 pmac_mksound(unsigned int hz, unsigned int ticks)
238 static volatile u32 *sysctrl_regs;
240 void __init
241 pmac_setup_arch(unsigned long *memory_start_p, unsigned long *memory_end_p)
243 struct device_node *cpu;
244 int *fp;
246 /* Set loops_per_sec to a half-way reasonable value,
247 for use until calibrate_delay gets called. */
248 cpu = find_type_devices("cpu");
249 if (cpu != 0) {
250 fp = (int *) get_property(cpu, "clock-frequency", NULL);
251 if (fp != 0) {
252 switch (_get_PVR() >> 16) {
253 case 4: /* 604 */
254 case 9: /* 604e */
255 case 10: /* mach V (604ev5) */
256 case 20: /* 620 */
257 loops_per_sec = *fp;
258 break;
259 default: /* 601, 603, etc. */
260 loops_per_sec = *fp / 2;
262 } else
263 loops_per_sec = 50000000;
266 /* this area has the CPU identification register
267 and some registers used by smp boards */
268 sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000);
269 __ioremap(0xffc00000, 0x400000, pgprot_val(PAGE_READONLY));
270 ohare_init();
272 *memory_start_p = pmac_find_bridges(*memory_start_p, *memory_end_p);
273 init_p2pbridge();
275 /* Checks "l2cr-value" property in the registry */
276 if ( (_get_PVR() >> 16) == 8) {
277 struct device_node *np = find_devices("cpus");
278 if (np == 0)
279 np = find_type_devices("cpu");
280 if (np != 0) {
281 unsigned int *l2cr = (unsigned int *)
282 get_property(np, "l2cr-value", NULL);
283 if (l2cr != 0) {
284 ppc_override_l2cr = 1;
285 ppc_override_l2cr_value = *l2cr;
286 _set_L2CR(0);
287 _set_L2CR(ppc_override_l2cr_value);
292 if (ppc_override_l2cr)
293 printk(KERN_INFO "L2CR overriden (0x%x), backside cache is %s\n",
294 ppc_override_l2cr_value, (ppc_override_l2cr_value & 0x80000000)
295 ? "enabled" : "disabled");
297 feature_init();
299 #ifdef CONFIG_KGDB
300 zs_kgdb_hook(0);
301 #endif
303 #ifdef CONFIG_ADB_CUDA
304 find_via_cuda();
305 #endif
306 #ifdef CONFIG_ADB_PMU
307 find_via_pmu();
308 #endif
310 #ifdef CONFIG_DUMMY_CONSOLE
311 conswitchp = &dummy_con;
312 #endif
314 kd_mksound = pmac_mksound;
316 #ifdef CONFIG_BLK_DEV_INITRD
317 if (initrd_start)
318 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
319 else
320 #endif
321 ROOT_DEV = to_kdev_t(DEFAULT_ROOT_DEVICE);
325 * Tweak the PCI-PCI bridge chip on the blue & white G3s.
327 static void __init init_p2pbridge(void)
329 struct device_node *p2pbridge;
330 unsigned char bus, devfn;
331 unsigned short val;
333 /* XXX it would be better here to identify the specific
334 PCI-PCI bridge chip we have. */
335 if ((p2pbridge = find_devices("pci-bridge")) == 0
336 || p2pbridge->parent == NULL
337 || strcmp(p2pbridge->parent->name, "pci") != 0)
338 return;
340 if (pci_device_loc(p2pbridge, &bus, &devfn) < 0)
341 return;
343 pcibios_read_config_word(bus, devfn, PCI_BRIDGE_CONTROL, &val);
344 val &= ~PCI_BRIDGE_CTL_MASTER_ABORT;
345 pcibios_write_config_word(bus, devfn, PCI_BRIDGE_CONTROL, val);
346 pcibios_read_config_word(bus, devfn, PCI_BRIDGE_CONTROL, &val);
349 static void __init ohare_init(void)
352 * Turn on the L2 cache.
353 * We assume that we have a PSX memory controller iff
354 * we have an ohare I/O controller.
356 if (find_devices("ohare") != NULL) {
357 if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) {
358 if (sysctrl_regs[4] & 0x10)
359 sysctrl_regs[4] |= 0x04000020;
360 else
361 sysctrl_regs[4] |= 0x04000000;
362 printk(KERN_INFO "Level 2 cache enabled\n");
367 extern char *bootpath;
368 extern char *bootdevice;
369 void *boot_host;
370 int boot_target;
371 int boot_part;
372 kdev_t boot_dev;
374 void __init
375 pmac_init2(void)
377 pmac_nvram_init();
378 #ifdef CONFIG_PMAC_PBOOK
379 media_bay_init();
380 #endif
383 #ifdef CONFIG_SCSI
384 void __init
385 note_scsi_host(struct device_node *node, void *host)
387 int l;
388 char *p;
390 l = strlen(node->full_name);
391 if (bootpath != NULL && bootdevice != NULL
392 && strncmp(node->full_name, bootdevice, l) == 0
393 && (bootdevice[l] == '/' || bootdevice[l] == 0)) {
394 boot_host = host;
396 * There's a bug in OF 1.0.5. (Why am I not surprised.)
397 * If you pass a path like scsi/sd@1:0 to canon, it returns
398 * something like /bandit@F2000000/gc@10/53c94@10000/sd@0,0
399 * That is, the scsi target number doesn't get preserved.
400 * So we pick the target number out of bootpath and use that.
402 p = strstr(bootpath, "/sd@");
403 if (p != NULL) {
404 p += 4;
405 boot_target = simple_strtoul(p, NULL, 10);
406 p = strchr(p, ':');
407 if (p != NULL)
408 boot_part = simple_strtoul(p + 1, NULL, 10);
412 #endif
414 #ifdef CONFIG_BLK_DEV_IDE_PMAC
415 extern int pmac_ide_count;
416 extern struct device_node *pmac_ide_node[];
417 static int ide_majors[] = { 3, 22, 33, 34, 56, 57, 88, 89 };
419 kdev_t __init find_ide_boot(void)
421 char *p;
422 int i, n;
424 if (bootdevice == NULL)
425 return 0;
426 p = strrchr(bootdevice, '/');
427 if (p == NULL)
428 return 0;
429 n = p - bootdevice;
432 * Look through the list of IDE interfaces for this one.
434 for (i = 0; i < pmac_ide_count; ++i) {
435 char *name = pmac_ide_node[i]->full_name;
436 if (memcmp(name, bootdevice, n) == 0 && name[n] == 0) {
437 /* XXX should cope with the 2nd drive as well... */
438 return MKDEV(ide_majors[i], 0);
442 return 0;
444 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
446 void __init find_boot_device(void)
448 #ifdef CONFIG_SCSI
449 if (boot_host != NULL) {
450 boot_dev = sd_find_target(boot_host, boot_target);
451 if (boot_dev != 0)
452 return;
454 #endif
455 #ifdef CONFIG_BLK_DEV_IDE_PMAC
456 boot_dev = find_ide_boot();
457 #endif
460 /* can't be __init - can be called whenever a disk is first accessed */
461 __pmac
462 void note_bootable_part(kdev_t dev, int part)
464 static int found_boot = 0;
465 char *p;
467 /* Do nothing if the root has been set already. */
468 if (ROOT_DEV != to_kdev_t(DEFAULT_ROOT_DEVICE))
469 return;
470 p = strstr(saved_command_line, "root=");
471 if (p != NULL && (p == saved_command_line || p[-1] == ' '))
472 return;
474 if (!found_boot) {
475 find_boot_device();
476 found_boot = 1;
478 if (dev == boot_dev) {
479 ROOT_DEV = MKDEV(MAJOR(dev), MINOR(dev) + part);
480 boot_dev = NODEV;
481 printk(" (root)");
485 void
486 pmac_restart(char *cmd)
488 #ifdef CONFIG_ADB_CUDA
489 struct adb_request req;
490 #endif /* CONFIG_ADB_CUDA */
492 switch (sys_ctrler) {
493 #ifdef CONFIG_ADB_CUDA
494 case SYS_CTRLER_CUDA:
495 cuda_request(&req, NULL, 2, CUDA_PACKET,
496 CUDA_RESET_SYSTEM);
497 for (;;)
498 cuda_poll();
499 break;
500 #endif /* CONFIG_ADB_CUDA */
501 #ifdef CONFIG_ADB_PMU
502 case SYS_CTRLER_PMU:
503 pmu_restart();
504 break;
505 #endif /* CONFIG_ADB_PMU */
506 default:
510 void
511 pmac_power_off(void)
513 #ifdef CONFIG_ADB_CUDA
514 struct adb_request req;
515 #endif /* CONFIG_ADB_CUDA */
517 switch (sys_ctrler) {
518 #ifdef CONFIG_ADB_CUDA
519 case SYS_CTRLER_CUDA:
520 cuda_request(&req, NULL, 2, CUDA_PACKET,
521 CUDA_POWERDOWN);
522 for (;;)
523 cuda_poll();
524 break;
525 #endif /* CONFIG_ADB_CUDA */
526 #ifdef CONFIG_ADB_PMU
527 case SYS_CTRLER_PMU:
528 pmu_shutdown();
529 break;
530 #endif /* CONFIG_ADB_PMU */
531 default:
535 void
536 pmac_halt(void)
538 pmac_power_off();
542 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
544 * IDE stuff.
546 void
547 pmac_ide_insw(ide_ioreg_t port, void *buf, int ns)
549 _insw_ns((unsigned short *)(port+_IO_BASE), buf, ns);
552 void
553 pmac_ide_outsw(ide_ioreg_t port, void *buf, int ns)
555 _outsw_ns((unsigned short *)(port+_IO_BASE), buf, ns);
559 pmac_ide_default_irq(ide_ioreg_t base)
561 return 0;
564 ide_ioreg_t
565 pmac_ide_default_io_base(int index)
567 #if defined(CONFIG_BLK_DEV_IDE_PMAC)
568 return pmac_ide_regbase[index];
569 #else
570 return 0;
571 #endif
575 pmac_ide_check_region(ide_ioreg_t from, unsigned int extent)
577 return 0;
580 void
581 pmac_ide_request_region(ide_ioreg_t from,
582 unsigned int extent,
583 const char *name)
587 void
588 pmac_ide_release_region(ide_ioreg_t from,
589 unsigned int extent)
593 /* Convert the shorts/longs in hd_driveid from little to big endian;
594 * chars are endian independant, of course, but strings need to be flipped.
595 * (Despite what it says in drivers/block/ide.h, they come up as little
596 * endian...)
598 * Changes to linux/hdreg.h may require changes here. */
599 void
600 pmac_ide_fix_driveid(struct hd_driveid *id)
602 ppc_generic_ide_fix_driveid(id);
605 #if defined(CONFIG_BLK_DEV_IDE_PMAC)
606 /* This is declared in drivers/block/ide-pmac.c */
607 void pmac_ide_init_hwif_ports (hw_regs_t *hw, ide_ioreg_t data_port, ide_ioreg_t ctrl_port, int *irq);
608 #else
610 * This registers the standard ports for this architecture with the IDE
611 * driver.
613 void pmac_ide_init_hwif_ports(hw_regs_t *hw, ide_ioreg_t data_port, ide_ioreg_t ctrl_port, int *irq)
616 #endif
617 #endif
619 void __init
620 pmac_init(unsigned long r3, unsigned long r4, unsigned long r5,
621 unsigned long r6, unsigned long r7)
623 pmac_setup_pci_ptrs();
625 /* isa_io_base gets set in pmac_find_bridges */
626 isa_mem_base = PMAC_ISA_MEM_BASE;
627 pci_dram_offset = PMAC_PCI_DRAM_OFFSET;
628 ISA_DMA_THRESHOLD = ~0L;
629 DMA_MODE_READ = 1;
630 DMA_MODE_WRITE = 2;
632 ppc_md.setup_arch = pmac_setup_arch;
633 ppc_md.setup_residual = NULL;
634 ppc_md.get_cpuinfo = pmac_get_cpuinfo;
635 ppc_md.irq_cannonicalize = NULL;
636 ppc_md.init_IRQ = pmac_pic_init;
637 ppc_md.get_irq = pmac_get_irq;
638 ppc_md.init = pmac_init2;
640 ppc_md.restart = pmac_restart;
641 ppc_md.power_off = pmac_power_off;
642 ppc_md.halt = pmac_halt;
644 ppc_md.time_init = NULL;
645 ppc_md.set_rtc_time = pmac_set_rtc_time;
646 ppc_md.get_rtc_time = pmac_get_rtc_time;
647 ppc_md.calibrate_decr = pmac_calibrate_decr;
649 #if defined(CONFIG_VT) && defined(CONFIG_ADB_KEYBOARD)
650 ppc_md.kbd_setkeycode = mackbd_setkeycode;
651 ppc_md.kbd_getkeycode = mackbd_getkeycode;
652 ppc_md.kbd_translate = mackbd_translate;
653 ppc_md.kbd_unexpected_up = mackbd_unexpected_up;
654 ppc_md.kbd_leds = mackbd_leds;
655 ppc_md.kbd_init_hw = mackbd_init_hw;
656 #ifdef CONFIG_MAGIC_SYSRQ
657 ppc_md.ppc_kbd_sysrq_xlate = mackbd_sysrq_xlate;
658 SYSRQ_KEY = 0x69;
659 #endif
660 #endif
662 #if defined(CONFIG_BLK_DEV_IDE_PMAC)
663 ppc_ide_md.insw = pmac_ide_insw;
664 ppc_ide_md.outsw = pmac_ide_outsw;
665 ppc_ide_md.default_irq = pmac_ide_default_irq;
666 ppc_ide_md.default_io_base = pmac_ide_default_io_base;
667 ppc_ide_md.ide_check_region = pmac_ide_check_region;
668 ppc_ide_md.ide_request_region = pmac_ide_request_region;
669 ppc_ide_md.ide_release_region = pmac_ide_release_region;
670 ppc_ide_md.fix_driveid = pmac_ide_fix_driveid;
671 ppc_ide_md.ide_init_hwif = pmac_ide_init_hwif_ports;
673 ppc_ide_md.io_base = _IO_BASE; /* actually too early for this :-( */
674 #endif