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 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
;
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
);
115 pmac_get_cpuinfo(char *buffer
)
118 struct device_node
*np
;
122 /* find motherboard type */
123 len
= sprintf(buffer
, "machine\t\t: ");
124 np
= find_devices("device-tree");
126 pp
= (char *) get_property(np
, "model", NULL
);
128 len
+= sprintf(buffer
+len
, "%s\n", pp
);
130 len
+= sprintf(buffer
+len
, "PowerMac\n");
131 pp
= (char *) get_property(np
, "compatible", &plen
);
133 len
+= sprintf(buffer
+len
, "motherboard\t:");
135 int l
= strlen(pp
) + 1;
136 len
+= sprintf(buffer
+len
, " %s", pp
);
140 buffer
[len
++] = '\n';
143 len
+= sprintf(buffer
+len
, "PowerMac\n");
145 /* find l2 cache info */
146 np
= find_devices("l2-cache");
148 np
= find_type_devices("cache");
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:");
156 if (get_property(np
, "cache-unified", NULL
) != 0 && dc
) {
157 len
+= sprintf(buffer
+len
, " %dK unified", *dc
/ 1024);
160 len
+= sprintf(buffer
+len
, " %dK instruction",
163 len
+= sprintf(buffer
+len
, "%s %dK data",
164 (ic
? " +": ""), *dc
/ 1024);
166 pp
= get_property(np
, "ram-type", NULL
);
168 len
+= sprintf(buffer
+len
, " %s", pp
);
169 buffer
[len
++] = '\n';
173 np
= find_devices("memory");
176 struct reg_property
*reg
= (struct reg_property
*)
177 get_property(np
, "reg", &n
);
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",
189 /* Checks "l2cr-value" property in the registry */
190 np
= find_devices("cpus");
192 np
= find_type_devices("cpu");
194 unsigned int *l2cr
= (unsigned int *)
195 get_property(np
, "l2cr-value", NULL
);
197 len
+= sprintf(buffer
+len
, "l2cr override\t: 0x%x\n", *l2cr
);
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
208 #include <linux/blkdev.h>
209 #include "../../../drivers/scsi/scsi.h"
210 #include "../../../drivers/scsi/sd.h"
215 * Dummy mksound function that does nothing.
216 * The real one is in the dmasound driver.
220 pmac_mksound(unsigned int hz
, unsigned int ticks
)
224 static volatile u32
*sysctrl_regs
;
227 pmac_setup_arch(void)
229 struct device_node
*cpu
;
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");
236 fp
= (int *) get_property(cpu
, "clock-frequency", NULL
);
238 switch (_get_PVR() >> 16) {
242 case 10: /* mach V (604ev5) */
247 default: /* 601, 603, etc. */
248 loops_per_sec
= *fp
/ 2;
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
));
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");
268 np
= find_type_devices("cpu");
270 unsigned int *l2cr
= (unsigned int *)
271 get_property(np
, "l2cr-value", NULL
);
273 ppc_override_l2cr
= 1;
274 ppc_override_l2cr_value
= *l2cr
;
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");
290 #ifdef CONFIG_ADB_CUDA
293 #ifdef CONFIG_ADB_PMU
297 #ifdef CONFIG_DUMMY_CONSOLE
298 conswitchp
= &dummy_con
;
301 kd_mksound
= pmac_mksound
;
303 #ifdef CONFIG_BLK_DEV_INITRD
305 ROOT_DEV
= MKDEV(RAMDISK_MAJOR
, 0);
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
;
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)
326 if (pci_device_loc(p2pbridge
, &bus
, &devfn
) < 0)
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");
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;
349 sysctrl_regs
[4] |= 0x04000000;
351 printk(KERN_INFO
"Level 2 cache enabled\n");
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");
368 if (!uni_n
|| uni_n
->n_addrs
< 1)
370 addr
= ioremap(uni_n
->addrs
[0].address
, 0x300);
373 if (device_is_compatible(gmac
, "gmac"))
383 extern char *bootpath
;
384 extern char *bootdevice
;
390 extern void via_pmu_start(void);
395 #ifdef CONFIG_ADB_PMU
401 #ifdef CONFIG_PMAC_PBOOK
408 note_scsi_host(struct device_node
*node
, void *host
)
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)) {
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@");
428 boot_target
= simple_strtoul(p
, NULL
, 10);
431 boot_part
= simple_strtoul(p
+ 1, NULL
, 10);
437 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
439 kdev_t __init
find_ide_boot(void)
443 kdev_t __init
pmac_find_ide_boot(char *bootdevice
, int n
);
445 if (bootdevice
== NULL
)
447 p
= strrchr(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)
459 if (boot_host
!= NULL
) {
460 boot_dev
= sd_find_target(boot_host
, boot_target
);
465 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
466 boot_dev
= find_ide_boot();
470 /* can't be __init - can be called whenever a disk is first accessed */
472 void note_bootable_part(kdev_t dev
, int part
)
474 static int found_boot
= 0;
477 /* Do nothing if the root has been set already. */
478 if (ROOT_DEV
!= to_kdev_t(DEFAULT_ROOT_DEVICE
))
480 p
= strstr(saved_command_line
, "root=");
481 if (p
!= NULL
&& (p
== saved_command_line
|| p
[-1] == ' '))
488 if (boot_dev
== 0 || dev
== boot_dev
) {
489 ROOT_DEV
= MKDEV(MAJOR(dev
), MINOR(dev
) + part
);
491 printk(" (root on %d)", part
);
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
,
510 #endif /* CONFIG_ADB_CUDA */
511 #ifdef CONFIG_ADB_PMU
515 #endif /* CONFIG_ADB_PMU */
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
,
535 #endif /* CONFIG_ADB_CUDA */
536 #ifdef CONFIG_ADB_PMU
540 #endif /* CONFIG_ADB_PMU */
552 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
557 pmac_ide_insw(ide_ioreg_t port
, void *buf
, int ns
)
559 _insw_ns((unsigned short *)(port
+_IO_BASE
), buf
, ns
);
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
)
574 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
575 extern ide_ioreg_t
pmac_ide_get_base(int index
);
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
);
589 pmac_ide_check_region(ide_ioreg_t from
, unsigned int extent
)
595 pmac_ide_request_region(ide_ioreg_t from
,
602 pmac_ide_release_region(ide_ioreg_t from
,
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
612 * Changes to linux/hdreg.h may require changes here. */
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
);
624 * This registers the standard ports for this architecture with the IDE
627 void pmac_ide_init_hwif_ports(hw_regs_t
*hw
, ide_ioreg_t data_port
, ide_ioreg_t ctrl_port
, int *irq
)
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;
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
;
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 :-( */
689 #ifdef CONFIG_BOOTX_TEXT
690 ppc_md
.progress
= pmac_progress
;
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
;
701 pmac_progress(char *s
, unsigned short hex
)
708 #endif CONFIG_BOOTX_TEXT