2 * linux/arch/ppc/kernel/setup.c
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>
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>
52 #include <asm/system.h>
53 #include <asm/pgtable.h>
54 #include <asm/bitops.h>
56 #include <asm/pci-bridge.h>
57 #include <asm/ohare.h>
58 #include <asm/mediabay.h>
59 #include <asm/feature.h>
61 #include <asm/machdep.h>
62 #include <asm/keyboard.h>
66 #include "local_irq.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
,
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
,
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);
110 pmac_get_cpuinfo(char *buffer
)
113 struct device_node
*np
;
117 /* find motherboard type */
118 len
= sprintf(buffer
, "machine\t\t: ");
119 np
= find_devices("device-tree");
121 pp
= (char *) get_property(np
, "model", NULL
);
123 len
+= sprintf(buffer
+len
, "%s\n", pp
);
125 len
+= sprintf(buffer
+len
, "PowerMac\n");
126 pp
= (char *) get_property(np
, "compatible", &plen
);
128 len
+= sprintf(buffer
+len
, "motherboard\t:");
130 int l
= strlen(pp
) + 1;
131 len
+= sprintf(buffer
+len
, " %s", pp
);
135 buffer
[len
++] = '\n';
138 len
+= sprintf(buffer
+len
, "PowerMac\n");
140 /* find l2 cache info */
141 np
= find_devices("l2-cache");
143 np
= find_type_devices("cache");
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);
154 len
+= sprintf(buffer
+len
, " %dK instruction",
157 len
+= sprintf(buffer
+len
, "%s %dK data",
158 (ic
? " +": ""), *dc
/ 1024);
160 pp
= get_property(np
, "ram-type", NULL
);
162 len
+= sprintf(buffer
+len
, " %s", pp
);
163 buffer
[len
++] = '\n';
167 np
= find_devices("memory");
170 struct reg_property
*reg
= (struct reg_property
*)
171 get_property(np
, "reg", &n
);
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",
183 /* Checks "l2cr-value" property in the registry */
184 np
= find_devices("cpus");
186 np
= find_type_devices("cpu");
188 unsigned int *l2cr
= (unsigned int *)
189 get_property(np
, "l2cr-value", NULL
);
191 len
+= sprintf(buffer
+len
, "l2cr override\t: 0x%x\n", *l2cr
);
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)
214 kdev_t
sd_find_target(void *host
, int tgt
)
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
)
223 #endif /* CONFIG_BLK_DEV_SD */
229 * Dummy mksound function that does nothing.
230 * The real one is in the dmasound driver.
234 pmac_mksound(unsigned int hz
, unsigned int ticks
)
238 static volatile u32
*sysctrl_regs
;
241 pmac_setup_arch(unsigned long *memory_start_p
, unsigned long *memory_end_p
)
243 struct device_node
*cpu
;
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");
250 fp
= (int *) get_property(cpu
, "clock-frequency", NULL
);
252 switch (_get_PVR() >> 16) {
255 case 10: /* mach V (604ev5) */
259 default: /* 601, 603, etc. */
260 loops_per_sec
= *fp
/ 2;
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
));
272 *memory_start_p
= pmac_find_bridges(*memory_start_p
, *memory_end_p
);
275 /* Checks "l2cr-value" property in the registry */
276 if ( (_get_PVR() >> 16) == 8) {
277 struct device_node
*np
= find_devices("cpus");
279 np
= find_type_devices("cpu");
281 unsigned int *l2cr
= (unsigned int *)
282 get_property(np
, "l2cr-value", NULL
);
284 ppc_override_l2cr
= 1;
285 ppc_override_l2cr_value
= *l2cr
;
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");
303 #ifdef CONFIG_ADB_CUDA
306 #ifdef CONFIG_ADB_PMU
310 #ifdef CONFIG_DUMMY_CONSOLE
311 conswitchp
= &dummy_con
;
314 kd_mksound
= pmac_mksound
;
316 #ifdef CONFIG_BLK_DEV_INITRD
318 ROOT_DEV
= MKDEV(RAMDISK_MAJOR
, 0);
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
;
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)
340 if (pci_device_loc(p2pbridge
, &bus
, &devfn
) < 0)
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;
361 sysctrl_regs
[4] |= 0x04000000;
362 printk(KERN_INFO
"Level 2 cache enabled\n");
367 extern char *bootpath
;
368 extern char *bootdevice
;
378 #ifdef CONFIG_PMAC_PBOOK
385 note_scsi_host(struct device_node
*node
, void *host
)
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)) {
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@");
405 boot_target
= simple_strtoul(p
, NULL
, 10);
408 boot_part
= simple_strtoul(p
+ 1, NULL
, 10);
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)
424 if (bootdevice
== NULL
)
426 p
= strrchr(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);
444 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
446 void __init
find_boot_device(void)
449 if (boot_host
!= NULL
) {
450 boot_dev
= sd_find_target(boot_host
, boot_target
);
455 #ifdef CONFIG_BLK_DEV_IDE_PMAC
456 boot_dev
= find_ide_boot();
460 /* can't be __init - can be called whenever a disk is first accessed */
462 void note_bootable_part(kdev_t dev
, int part
)
464 static int found_boot
= 0;
467 /* Do nothing if the root has been set already. */
468 if (ROOT_DEV
!= to_kdev_t(DEFAULT_ROOT_DEVICE
))
470 p
= strstr(saved_command_line
, "root=");
471 if (p
!= NULL
&& (p
== saved_command_line
|| p
[-1] == ' '))
478 if (dev
== boot_dev
) {
479 ROOT_DEV
= MKDEV(MAJOR(dev
), MINOR(dev
) + part
);
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
,
500 #endif /* CONFIG_ADB_CUDA */
501 #ifdef CONFIG_ADB_PMU
505 #endif /* CONFIG_ADB_PMU */
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
,
525 #endif /* CONFIG_ADB_CUDA */
526 #ifdef CONFIG_ADB_PMU
530 #endif /* CONFIG_ADB_PMU */
542 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
547 pmac_ide_insw(ide_ioreg_t port
, void *buf
, int ns
)
549 _insw_ns((unsigned short *)(port
+_IO_BASE
), buf
, ns
);
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
)
565 pmac_ide_default_io_base(int index
)
567 #if defined(CONFIG_BLK_DEV_IDE_PMAC)
568 return pmac_ide_regbase
[index
];
575 pmac_ide_check_region(ide_ioreg_t from
, unsigned int extent
)
581 pmac_ide_request_region(ide_ioreg_t from
,
588 pmac_ide_release_region(ide_ioreg_t from
,
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
598 * Changes to linux/hdreg.h may require changes here. */
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
);
610 * This registers the standard ports for this architecture with the IDE
613 void pmac_ide_init_hwif_ports(hw_regs_t
*hw
, ide_ioreg_t data_port
, ide_ioreg_t ctrl_port
, int *irq
)
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;
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
;
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 :-( */