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>
60 #include <asm/machdep.h>
61 #include <asm/keyboard.h>
63 #include <asm/bootx.h>
66 #include "local_irq.h"
69 #undef SHOW_GATWICK_IRQS
71 extern long pmac_time_init(void);
72 extern unsigned long pmac_get_rtc_time(void);
73 extern int pmac_set_rtc_time(unsigned long nowtime
);
74 extern void pmac_read_rtc_time(void);
75 extern void pmac_calibrate_decr(void);
76 extern void pmac_setup_pci_ptrs(void);
78 extern int mackbd_setkeycode(unsigned int scancode
, unsigned int keycode
);
79 extern int mackbd_getkeycode(unsigned int scancode
);
80 extern int mackbd_translate(unsigned char keycode
, unsigned char *keycodep
,
82 extern int mackbd_unexpected_up(unsigned char keycode
);
83 extern void mackbd_leds(unsigned char leds
);
84 extern void __init
mackbd_init_hw(void);
85 extern int mac_hid_kbd_translate(unsigned char scancode
, unsigned char *keycode
,
87 extern char mac_hid_kbd_unexpected_up(unsigned char keycode
);
88 extern void mac_hid_init_hw(void);
89 #ifdef CONFIG_MAGIC_SYSRQ
90 extern unsigned char mac_hid_kbd_sysrq_xlate
[128];
91 extern unsigned char pckbd_sysrq_xlate
[128];
92 extern unsigned char mackbd_sysrq_xlate
[128];
93 #endif /* CONFIG_MAGIC_SYSRQ */
94 extern int pckbd_setkeycode(unsigned int scancode
, unsigned int keycode
);
95 extern int pckbd_getkeycode(unsigned int scancode
);
96 extern int pckbd_translate(unsigned char scancode
, unsigned char *keycode
,
98 extern char pckbd_unexpected_up(unsigned char keycode
);
99 extern int keyboard_sends_linux_keycodes
;
100 extern void pmac_nvram_update(void);
102 extern void *pmac_pci_dev_io_base(unsigned char bus
, unsigned char devfn
, int physical
);
103 extern void *pmac_pci_dev_mem_base(unsigned char bus
, unsigned char devfn
);
104 extern int pmac_pci_dev_root_bridge(unsigned char bus
, unsigned char devfn
);
106 unsigned char drive_info
;
108 int ppc_override_l2cr
= 0;
109 int ppc_override_l2cr_value
;
112 static int current_root_goodness
= -1;
114 extern char saved_command_line
[];
116 extern int pmac_newworld
;
118 #define DEFAULT_ROOT_DEVICE 0x0801 /* sda1 - slightly silly choice */
120 extern void zs_kgdb_hook(int tty_num
);
121 static void ohare_init(void);
122 static void init_p2pbridge(void);
123 #ifdef CONFIG_BOOTX_TEXT
124 void pmac_progress(char *s
, unsigned short hex
);
127 sys_ctrler_t sys_ctrler
= SYS_CTRLER_UNKNOWN
;
131 pmac_get_cpuinfo(char *buffer
)
134 struct device_node
*np
;
138 /* find motherboard type */
139 len
= sprintf(buffer
, "machine\t\t: ");
140 np
= find_devices("device-tree");
142 pp
= (char *) get_property(np
, "model", NULL
);
144 len
+= sprintf(buffer
+len
, "%s\n", pp
);
146 len
+= sprintf(buffer
+len
, "PowerMac\n");
147 pp
= (char *) get_property(np
, "compatible", &plen
);
149 len
+= sprintf(buffer
+len
, "motherboard\t:");
151 int l
= strlen(pp
) + 1;
152 len
+= sprintf(buffer
+len
, " %s", pp
);
156 buffer
[len
++] = '\n';
159 len
+= sprintf(buffer
+len
, "PowerMac\n");
161 /* find l2 cache info */
162 np
= find_devices("l2-cache");
164 np
= find_type_devices("cache");
166 unsigned int *ic
= (unsigned int *)
167 get_property(np
, "i-cache-size", NULL
);
168 unsigned int *dc
= (unsigned int *)
169 get_property(np
, "d-cache-size", NULL
);
170 len
+= sprintf(buffer
+len
, "L2 cache\t:");
172 if (get_property(np
, "cache-unified", NULL
) != 0 && dc
) {
173 len
+= sprintf(buffer
+len
, " %dK unified", *dc
/ 1024);
176 len
+= sprintf(buffer
+len
, " %dK instruction",
179 len
+= sprintf(buffer
+len
, "%s %dK data",
180 (ic
? " +": ""), *dc
/ 1024);
182 pp
= get_property(np
, "ram-type", NULL
);
184 len
+= sprintf(buffer
+len
, " %s", pp
);
185 buffer
[len
++] = '\n';
189 np
= find_devices("memory");
192 struct reg_property
*reg
= (struct reg_property
*)
193 get_property(np
, "reg", &n
);
196 unsigned long total
= 0;
198 for (n
/= sizeof(struct reg_property
); n
> 0; --n
)
199 total
+= (reg
++)->size
;
200 len
+= sprintf(buffer
+len
, "memory\t\t: %luMB\n",
205 /* Checks "l2cr-value" property in the registry */
206 np
= find_devices("cpus");
208 np
= find_type_devices("cpu");
210 unsigned int *l2cr
= (unsigned int *)
211 get_property(np
, "l2cr-value", NULL
);
213 len
+= sprintf(buffer
+len
, "l2cr override\t: 0x%x\n", *l2cr
);
217 /* Indicate newworld/oldworld */
218 len
+= sprintf(buffer
+len
, "pmac-generation\t: %s\n",
219 pmac_newworld
? "NewWorld" : "OldWorld");
226 /* Find the device number for the disk (if any) at target tgt
227 on host adaptor host. We just need to get the prototype from
229 #include <linux/blkdev.h>
230 #include "../../../drivers/scsi/scsi.h"
231 #include "../../../drivers/scsi/sd.h"
236 * Dummy mksound function that does nothing.
237 * The real one is in the dmasound driver.
241 pmac_mksound(unsigned int hz
, unsigned int ticks
)
245 static volatile u32
*sysctrl_regs
;
248 pmac_setup_arch(void)
250 struct device_node
*cpu
;
253 /* Set loops_per_sec to a half-way reasonable value,
254 for use until calibrate_delay gets called. */
255 cpu
= find_type_devices("cpu");
257 fp
= (int *) get_property(cpu
, "clock-frequency", NULL
);
259 switch (_get_PVR() >> 16) {
263 case 10: /* mach V (604ev5) */
268 default: /* 601, 603, etc. */
269 loops_per_sec
= *fp
/ 2;
272 loops_per_sec
= 50000000;
275 /* this area has the CPU identification register
276 and some registers used by smp boards */
277 sysctrl_regs
= (volatile u32
*) ioremap(0xf8000000, 0x1000);
278 __ioremap(0xffc00000, 0x400000, pgprot_val(PAGE_READONLY
));
284 /* Checks "l2cr-value" property in the registry */
285 if ( (_get_PVR() >> 16) == 8 || (_get_PVR() >> 16) == 12 ) {
286 struct device_node
*np
= find_devices("cpus");
288 np
= find_type_devices("cpu");
290 unsigned int *l2cr
= (unsigned int *)
291 get_property(np
, "l2cr-value", NULL
);
293 ppc_override_l2cr
= 1;
294 ppc_override_l2cr_value
= *l2cr
;
296 _set_L2CR(ppc_override_l2cr_value
);
301 if (ppc_override_l2cr
)
302 printk(KERN_INFO
"L2CR overriden (0x%x), backside cache is %s\n",
303 ppc_override_l2cr_value
, (ppc_override_l2cr_value
& 0x80000000)
304 ? "enabled" : "disabled");
310 #ifdef CONFIG_ADB_CUDA
313 #ifdef CONFIG_ADB_PMU
319 #ifdef CONFIG_DUMMY_CONSOLE
320 conswitchp
= &dummy_con
;
323 kd_mksound
= pmac_mksound
;
325 #ifdef CONFIG_BLK_DEV_INITRD
327 ROOT_DEV
= MKDEV(RAMDISK_MAJOR
, 0);
330 ROOT_DEV
= to_kdev_t(DEFAULT_ROOT_DEVICE
);
334 * Tweak the PCI-PCI bridge chip on the blue & white G3s.
336 static void __init
init_p2pbridge(void)
338 struct device_node
*p2pbridge
;
339 unsigned char bus
, devfn
;
342 /* XXX it would be better here to identify the specific
343 PCI-PCI bridge chip we have. */
344 if ((p2pbridge
= find_devices("pci-bridge")) == 0
345 || p2pbridge
->parent
== NULL
346 || strcmp(p2pbridge
->parent
->name
, "pci") != 0)
348 if (pci_device_loc(p2pbridge
, &bus
, &devfn
) < 0)
350 if (ppc_md
.pcibios_read_config_word(bus
, devfn
, PCI_BRIDGE_CONTROL
, &val
) < 0) {
351 printk(KERN_ERR
"init_p2pbridge: couldn't read bridge control\n");
354 val
&= ~PCI_BRIDGE_CTL_MASTER_ABORT
;
355 ppc_md
.pcibios_write_config_word(bus
, devfn
, PCI_BRIDGE_CONTROL
, val
);
356 ppc_md
.pcibios_read_config_word(bus
, devfn
, PCI_BRIDGE_CONTROL
, &val
);
359 static void __init
ohare_init(void)
362 * Turn on the L2 cache.
363 * We assume that we have a PSX memory controller iff
364 * we have an ohare I/O controller.
366 if (find_devices("ohare") != NULL
) {
367 if (((sysctrl_regs
[2] >> 24) & 0xf) >= 3) {
368 if (sysctrl_regs
[4] & 0x10)
369 sysctrl_regs
[4] |= 0x04000020;
371 sysctrl_regs
[4] |= 0x04000000;
373 printk(KERN_INFO
"Level 2 cache enabled\n");
378 extern char *bootpath
;
379 extern char *bootdevice
;
388 #ifdef CONFIG_ADB_PMU
391 #ifdef CONFIG_ADB_CUDA
394 #ifdef CONFIG_PMAC_PBOOK
401 note_scsi_host(struct device_node
*node
, void *host
)
406 l
= strlen(node
->full_name
);
407 if (bootpath
!= NULL
&& bootdevice
!= NULL
408 && strncmp(node
->full_name
, bootdevice
, l
) == 0
409 && (bootdevice
[l
] == '/' || bootdevice
[l
] == 0)) {
412 * There's a bug in OF 1.0.5. (Why am I not surprised.)
413 * If you pass a path like scsi/sd@1:0 to canon, it returns
414 * something like /bandit@F2000000/gc@10/53c94@10000/sd@0,0
415 * That is, the scsi target number doesn't get preserved.
416 * So we pick the target number out of bootpath and use that.
418 p
= strstr(bootpath
, "/sd@");
421 boot_target
= simple_strtoul(p
, NULL
, 10);
424 boot_part
= simple_strtoul(p
+ 1, NULL
, 10);
430 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
432 kdev_t __init
find_ide_boot(void)
436 kdev_t __init
pmac_find_ide_boot(char *bootdevice
, int n
);
438 if (bootdevice
== NULL
)
440 p
= strrchr(bootdevice
, '/');
445 return pmac_find_ide_boot(bootdevice
, n
);
447 #endif /* CONFIG_BLK_DEV_IDE && CONFIG_BLK_DEV_IDE_PMAC */
449 void __init
find_boot_device(void)
452 if (boot_host
!= NULL
) {
453 boot_dev
= sd_find_target(boot_host
, boot_target
);
458 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
459 boot_dev
= find_ide_boot();
463 /* can't be __init - can be called whenever a disk is first accessed */
465 void note_bootable_part(kdev_t dev
, int part
, int goodness
)
467 static int found_boot
= 0;
470 /* Do nothing if the root has been set already. */
471 if ((goodness
< current_root_goodness
) &&
472 (ROOT_DEV
!= to_kdev_t(DEFAULT_ROOT_DEVICE
)))
474 p
= strstr(saved_command_line
, "root=");
475 if (p
!= NULL
&& (p
== saved_command_line
|| p
[-1] == ' '))
482 if (boot_dev
== 0 || dev
== boot_dev
) {
483 ROOT_DEV
= MKDEV(MAJOR(dev
), MINOR(dev
) + part
);
485 current_root_goodness
= goodness
;
490 pmac_restart(char *cmd
)
492 #ifdef CONFIG_ADB_CUDA
493 struct adb_request req
;
494 #endif /* CONFIG_ADB_CUDA */
498 switch (sys_ctrler
) {
499 #ifdef CONFIG_ADB_CUDA
500 case SYS_CTRLER_CUDA
:
501 cuda_request(&req
, NULL
, 2, CUDA_PACKET
,
506 #endif /* CONFIG_ADB_CUDA */
507 #ifdef CONFIG_ADB_PMU
511 #endif /* CONFIG_ADB_PMU */
519 #ifdef CONFIG_ADB_CUDA
520 struct adb_request req
;
521 #endif /* CONFIG_ADB_CUDA */
525 switch (sys_ctrler
) {
526 #ifdef CONFIG_ADB_CUDA
527 case SYS_CTRLER_CUDA
:
528 cuda_request(&req
, NULL
, 2, CUDA_PACKET
,
533 #endif /* CONFIG_ADB_CUDA */
534 #ifdef CONFIG_ADB_PMU
538 #endif /* CONFIG_ADB_PMU */
550 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
555 pmac_ide_insw(ide_ioreg_t port
, void *buf
, int ns
)
557 _insw_ns((unsigned short *)(port
+_IO_BASE
), buf
, ns
);
561 pmac_ide_outsw(ide_ioreg_t port
, void *buf
, int ns
)
563 _outsw_ns((unsigned short *)(port
+_IO_BASE
), buf
, ns
);
567 pmac_ide_default_irq(ide_ioreg_t base
)
572 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
573 extern ide_ioreg_t
pmac_ide_get_base(int index
);
577 pmac_ide_default_io_base(int index
)
579 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
580 return pmac_ide_get_base(index
);
587 pmac_ide_check_region(ide_ioreg_t from
, unsigned int extent
)
593 pmac_ide_request_region(ide_ioreg_t from
,
600 pmac_ide_release_region(ide_ioreg_t from
,
605 /* Convert the shorts/longs in hd_driveid from little to big endian;
606 * chars are endian independant, of course, but strings need to be flipped.
607 * (Despite what it says in drivers/block/ide.h, they come up as little
610 * Changes to linux/hdreg.h may require changes here. */
612 pmac_ide_fix_driveid(struct hd_driveid
*id
)
614 ppc_generic_ide_fix_driveid(id
);
617 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
618 /* This is declared in drivers/block/ide-pmac.c */
619 void pmac_ide_init_hwif_ports (hw_regs_t
*hw
, ide_ioreg_t data_port
, ide_ioreg_t ctrl_port
, int *irq
);
622 * This registers the standard ports for this architecture with the IDE
625 void pmac_ide_init_hwif_ports(hw_regs_t
*hw
, ide_ioreg_t data_port
, ide_ioreg_t ctrl_port
, int *irq
)
632 pmac_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
633 unsigned long r6
, unsigned long r7
)
635 pmac_setup_pci_ptrs();
637 /* isa_io_base gets set in pmac_find_bridges */
638 isa_mem_base
= PMAC_ISA_MEM_BASE
;
639 pci_dram_offset
= PMAC_PCI_DRAM_OFFSET
;
640 ISA_DMA_THRESHOLD
= ~0L;
644 ppc_md
.setup_arch
= pmac_setup_arch
;
645 ppc_md
.setup_residual
= NULL
;
646 ppc_md
.get_cpuinfo
= pmac_get_cpuinfo
;
647 ppc_md
.irq_cannonicalize
= NULL
;
648 ppc_md
.init_IRQ
= pmac_pic_init
;
649 ppc_md
.get_irq
= pmac_get_irq
;
650 ppc_md
.init
= pmac_init2
;
652 ppc_md
.restart
= pmac_restart
;
653 ppc_md
.power_off
= pmac_power_off
;
654 ppc_md
.halt
= pmac_halt
;
656 ppc_md
.time_init
= pmac_time_init
;
657 ppc_md
.set_rtc_time
= pmac_set_rtc_time
;
658 ppc_md
.get_rtc_time
= pmac_get_rtc_time
;
659 ppc_md
.calibrate_decr
= pmac_calibrate_decr
;
661 ppc_md
.pci_dev_io_base
= pmac_pci_dev_io_base
;
662 ppc_md
.pci_dev_mem_base
= pmac_pci_dev_mem_base
;
663 ppc_md
.pci_dev_root_bridge
= pmac_pci_dev_root_bridge
;
666 #ifdef CONFIG_INPUT_ADBHID
667 ppc_md
.kbd_init_hw
= mac_hid_init_hw
;
668 ppc_md
.kbd_translate
= mac_hid_kbd_translate
;
669 ppc_md
.kbd_unexpected_up
= mac_hid_kbd_unexpected_up
;
670 ppc_md
.kbd_setkeycode
= 0;
671 ppc_md
.kbd_getkeycode
= 0;
672 #ifdef CONFIG_MAGIC_SYSRQ
673 #ifdef CONFIG_MAC_ADBKEYCODES
674 if (!keyboard_sends_linux_keycodes
) {
675 ppc_md
.ppc_kbd_sysrq_xlate
= mac_hid_kbd_sysrq_xlate
;
678 #endif /* CONFIG_MAC_ADBKEYCODES */
680 ppc_md
.ppc_kbd_sysrq_xlate
= pckbd_sysrq_xlate
;
683 #endif /* CONFIG_MAGIC_SYSRQ */
684 #elif defined(CONFIG_ADB_KEYBOARD)
685 ppc_md
.kbd_setkeycode
= mackbd_setkeycode
;
686 ppc_md
.kbd_getkeycode
= mackbd_getkeycode
;
687 ppc_md
.kbd_translate
= mackbd_translate
;
688 ppc_md
.kbd_unexpected_up
= mackbd_unexpected_up
;
689 ppc_md
.kbd_leds
= mackbd_leds
;
690 ppc_md
.kbd_init_hw
= mackbd_init_hw
;
691 #ifdef CONFIG_MAGIC_SYSRQ
692 ppc_md
.ppc_kbd_sysrq_xlate
= mackbd_sysrq_xlate
;
694 #endif /* CONFIG_MAGIC_SYSRQ */
695 #endif /* CONFIG_INPUT_ADBHID/CONFIG_ADB_KEYBOARD */
696 #endif /* CONFIG_VT */
698 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
699 ppc_ide_md
.insw
= pmac_ide_insw
;
700 ppc_ide_md
.outsw
= pmac_ide_outsw
;
701 ppc_ide_md
.default_irq
= pmac_ide_default_irq
;
702 ppc_ide_md
.default_io_base
= pmac_ide_default_io_base
;
703 ppc_ide_md
.ide_check_region
= pmac_ide_check_region
;
704 ppc_ide_md
.ide_request_region
= pmac_ide_request_region
;
705 ppc_ide_md
.ide_release_region
= pmac_ide_release_region
;
706 ppc_ide_md
.fix_driveid
= pmac_ide_fix_driveid
;
707 ppc_ide_md
.ide_init_hwif
= pmac_ide_init_hwif_ports
;
709 ppc_ide_md
.io_base
= _IO_BASE
; /* actually too early for this :-( */
711 #ifdef CONFIG_BOOTX_TEXT
712 ppc_md
.progress
= pmac_progress
;
714 if (ppc_md
.progress
) ppc_md
.progress("pmac_init(): exit", 0);
718 #ifdef CONFIG_BOOTX_TEXT
719 extern void drawchar(char c
);
720 extern void drawstring(const char *c
);
721 extern boot_infos_t
*disp_bi
;
723 pmac_progress(char *s
, unsigned short hex
)
730 #endif CONFIG_BOOTX_TEXT