2 * arch/ppc/platforms/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 * Maintained by Benjamin Herrenschmidt (benh@kernel.crashing.org)
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
23 * bootup setup stuff..
26 #include <linux/config.h>
27 #include <linux/init.h>
28 #include <linux/errno.h>
29 #include <linux/sched.h>
30 #include <linux/kernel.h>
32 #include <linux/stddef.h>
33 #include <linux/unistd.h>
34 #include <linux/ptrace.h>
35 #include <linux/slab.h>
36 #include <linux/user.h>
37 #include <linux/a.out.h>
38 #include <linux/tty.h>
39 #include <linux/string.h>
40 #include <linux/delay.h>
41 #include <linux/ioport.h>
42 #include <linux/major.h>
43 #include <linux/initrd.h>
44 #include <linux/vt_kern.h>
45 #include <linux/console.h>
46 #include <linux/ide.h>
47 #include <linux/pci.h>
48 #include <linux/adb.h>
49 #include <linux/cuda.h>
50 #include <linux/pmu.h>
51 #include <linux/seq_file.h>
52 #include <linux/root_dev.h>
53 #include <linux/bitops.h>
54 #include <linux/suspend.h>
57 #include <asm/sections.h>
59 #include <asm/system.h>
60 #include <asm/pgtable.h>
62 #include <asm/pci-bridge.h>
63 #include <asm/ohare.h>
64 #include <asm/mediabay.h>
65 #include <asm/machdep.h>
67 #include <asm/bootx.h>
68 #include <asm/cputable.h>
69 #include <asm/btext.h>
70 #include <asm/pmac_feature.h>
72 #include <asm/of_device.h>
73 #include <asm/mmu_context.h>
76 #include "mem_pieces.h"
78 #undef SHOW_GATWICK_IRQS
80 extern long pmac_time_init(void);
81 extern unsigned long pmac_get_rtc_time(void);
82 extern int pmac_set_rtc_time(unsigned long nowtime
);
83 extern void pmac_read_rtc_time(void);
84 extern void pmac_calibrate_decr(void);
85 extern void pmac_pcibios_fixup(void);
86 extern void pmac_find_bridges(void);
87 extern unsigned long pmac_ide_get_base(int index
);
88 extern void pmac_ide_init_hwif_ports(hw_regs_t
*hw
,
89 unsigned long data_port
, unsigned long ctrl_port
, int *irq
);
91 extern void pmac_nvram_update(void);
92 extern unsigned char pmac_nvram_read_byte(int addr
);
93 extern void pmac_nvram_write_byte(int addr
, unsigned char val
);
94 extern int pmac_pci_enable_device_hook(struct pci_dev
*dev
, int initial
);
95 extern void pmac_pcibios_after_init(void);
96 extern int of_show_percpuinfo(struct seq_file
*m
, int i
);
98 struct device_node
*memory_node
;
100 unsigned char drive_info
;
102 int ppc_override_l2cr
= 0;
103 int ppc_override_l2cr_value
;
106 static int current_root_goodness
= -1;
108 extern int pmac_newworld
;
110 #define DEFAULT_ROOT_DEVICE Root_SDA1 /* sda1 - slightly silly choice */
112 extern void zs_kgdb_hook(int tty_num
);
113 static void ohare_init(void);
114 #ifdef CONFIG_BOOTX_TEXT
115 static void pmac_progress(char *s
, unsigned short hex
);
118 sys_ctrler_t sys_ctrler
= SYS_CTRLER_UNKNOWN
;
121 extern struct smp_ops_t psurge_smp_ops
;
122 extern struct smp_ops_t core99_smp_ops
;
123 #endif /* CONFIG_SMP */
126 pmac_show_cpuinfo(struct seq_file
*m
)
128 struct device_node
*np
;
131 int mbmodel
= pmac_call_feature(PMAC_FTR_GET_MB_INFO
,
132 NULL
, PMAC_MB_INFO_MODEL
, 0);
133 unsigned int mbflags
= (unsigned int)pmac_call_feature(PMAC_FTR_GET_MB_INFO
,
134 NULL
, PMAC_MB_INFO_FLAGS
, 0);
137 if (pmac_call_feature(PMAC_FTR_GET_MB_INFO
, NULL
, PMAC_MB_INFO_NAME
, (int)&mbname
) != 0)
140 /* find motherboard type */
141 seq_printf(m
, "machine\t\t: ");
142 np
= find_devices("device-tree");
144 pp
= (char *) get_property(np
, "model", NULL
);
146 seq_printf(m
, "%s\n", pp
);
148 seq_printf(m
, "PowerMac\n");
149 pp
= (char *) get_property(np
, "compatible", &plen
);
151 seq_printf(m
, "motherboard\t:");
153 int l
= strlen(pp
) + 1;
154 seq_printf(m
, " %s", pp
);
161 seq_printf(m
, "PowerMac\n");
163 /* print parsed model */
164 seq_printf(m
, "detected as\t: %d (%s)\n", mbmodel
, mbname
);
165 seq_printf(m
, "pmac flags\t: %08x\n", mbflags
);
167 /* find l2 cache info */
168 np
= find_devices("l2-cache");
170 np
= find_type_devices("cache");
172 unsigned int *ic
= (unsigned int *)
173 get_property(np
, "i-cache-size", NULL
);
174 unsigned int *dc
= (unsigned int *)
175 get_property(np
, "d-cache-size", NULL
);
176 seq_printf(m
, "L2 cache\t:");
178 if (get_property(np
, "cache-unified", NULL
) != 0 && dc
) {
179 seq_printf(m
, " %dK unified", *dc
/ 1024);
182 seq_printf(m
, " %dK instruction", *ic
/ 1024);
184 seq_printf(m
, "%s %dK data",
185 (ic
? " +": ""), *dc
/ 1024);
187 pp
= get_property(np
, "ram-type", NULL
);
189 seq_printf(m
, " %s", pp
);
194 np
= find_devices("memory");
197 struct reg_property
*reg
= (struct reg_property
*)
198 get_property(np
, "reg", &n
);
201 unsigned long total
= 0;
203 for (n
/= sizeof(struct reg_property
); n
> 0; --n
)
204 total
+= (reg
++)->size
;
205 seq_printf(m
, "memory\t\t: %luMB\n", total
>> 20);
209 /* Checks "l2cr-value" property in the registry */
210 np
= find_devices("cpus");
212 np
= find_type_devices("cpu");
214 unsigned int *l2cr
= (unsigned int *)
215 get_property(np
, "l2cr-value", NULL
);
217 seq_printf(m
, "l2cr override\t: 0x%x\n", *l2cr
);
221 /* Indicate newworld/oldworld */
222 seq_printf(m
, "pmac-generation\t: %s\n",
223 pmac_newworld
? "NewWorld" : "OldWorld");
230 pmac_show_percpuinfo(struct seq_file
*m
, int i
)
232 #ifdef CONFIG_CPU_FREQ_PMAC
233 extern unsigned int pmac_get_one_cpufreq(int i
);
234 unsigned int freq
= pmac_get_one_cpufreq(i
);
236 seq_printf(m
, "clock\t\t: %dMHz\n", freq
/1000);
239 #endif /* CONFIG_CPU_FREQ_PMAC */
240 return of_show_percpuinfo(m
, i
);
243 static volatile u32
*sysctrl_regs
;
246 pmac_setup_arch(void)
248 struct device_node
*cpu
;
252 pvr
= PVR_VER(mfspr(SPRN_PVR
));
254 /* Set loops_per_jiffy to a half-way reasonable value,
255 for use until calibrate_delay gets called. */
256 cpu
= find_type_devices("cpu");
258 fp
= (int *) get_property(cpu
, "clock-frequency", NULL
);
260 if (pvr
== 4 || pvr
>= 8)
261 /* 604, G3, G4 etc. */
262 loops_per_jiffy
= *fp
/ HZ
;
265 loops_per_jiffy
= *fp
/ (2*HZ
);
267 loops_per_jiffy
= 50000000 / HZ
;
270 /* this area has the CPU identification register
271 and some registers used by smp boards */
272 sysctrl_regs
= (volatile u32
*) ioremap(0xf8000000, 0x1000);
275 /* Lookup PCI hosts */
278 /* Checks "l2cr-value" property in the registry */
279 if (cpu_has_feature(CPU_FTR_L2CR
)) {
280 struct device_node
*np
= find_devices("cpus");
282 np
= find_type_devices("cpu");
284 unsigned int *l2cr
= (unsigned int *)
285 get_property(np
, "l2cr-value", NULL
);
287 ppc_override_l2cr
= 1;
288 ppc_override_l2cr_value
= *l2cr
;
290 _set_L2CR(ppc_override_l2cr_value
);
295 if (ppc_override_l2cr
)
296 printk(KERN_INFO
"L2CR overriden (0x%x), backside cache is %s\n",
297 ppc_override_l2cr_value
, (ppc_override_l2cr_value
& 0x80000000)
298 ? "enabled" : "disabled");
304 #ifdef CONFIG_ADB_CUDA
307 if (find_devices("via-cuda")) {
308 printk("WARNING ! Your machine is Cuda based but your kernel\n");
309 printk(" wasn't compiled with CONFIG_ADB_CUDA option !\n");
312 #ifdef CONFIG_ADB_PMU
315 if (find_devices("via-pmu")) {
316 printk("WARNING ! Your machine is PMU based but your kernel\n");
317 printk(" wasn't compiled with CONFIG_ADB_PMU option !\n");
323 #ifdef CONFIG_BLK_DEV_INITRD
325 ROOT_DEV
= Root_RAM0
;
328 ROOT_DEV
= DEFAULT_ROOT_DEVICE
;
331 /* Check for Core99 */
332 if (find_devices("uni-n") || find_devices("u3"))
333 smp_ops
= &core99_smp_ops
;
335 smp_ops
= &psurge_smp_ops
;
336 #endif /* CONFIG_SMP */
338 pci_create_OF_bus_map();
341 static void __init
ohare_init(void)
344 * Turn on the L2 cache.
345 * We assume that we have a PSX memory controller iff
346 * we have an ohare I/O controller.
348 if (find_devices("ohare") != NULL
) {
349 if (((sysctrl_regs
[2] >> 24) & 0xf) >= 3) {
350 if (sysctrl_regs
[4] & 0x10)
351 sysctrl_regs
[4] |= 0x04000020;
353 sysctrl_regs
[4] |= 0x04000000;
355 printk(KERN_INFO
"Level 2 cache enabled\n");
360 extern char *bootpath
;
361 extern char *bootdevice
;
365 extern dev_t boot_dev
;
369 note_scsi_host(struct device_node
*node
, void *host
)
374 l
= strlen(node
->full_name
);
375 if (bootpath
!= NULL
&& bootdevice
!= NULL
376 && strncmp(node
->full_name
, bootdevice
, l
) == 0
377 && (bootdevice
[l
] == '/' || bootdevice
[l
] == 0)) {
380 * There's a bug in OF 1.0.5. (Why am I not surprised.)
381 * If you pass a path like scsi/sd@1:0 to canon, it returns
382 * something like /bandit@F2000000/gc@10/53c94@10000/sd@0,0
383 * That is, the scsi target number doesn't get preserved.
384 * So we pick the target number out of bootpath and use that.
386 p
= strstr(bootpath
, "/sd@");
389 boot_target
= simple_strtoul(p
, NULL
, 10);
392 boot_part
= simple_strtoul(p
+ 1, NULL
, 10);
398 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
404 dev_t __init
pmac_find_ide_boot(char *bootdevice
, int n
);
406 if (bootdevice
== NULL
)
408 p
= strrchr(bootdevice
, '/');
413 return pmac_find_ide_boot(bootdevice
, n
);
415 #endif /* CONFIG_BLK_DEV_IDE && CONFIG_BLK_DEV_IDE_PMAC */
418 find_boot_device(void)
420 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
421 boot_dev
= find_ide_boot();
425 static int initializing
= 1;
426 /* TODO: Merge the suspend-to-ram with the common code !!!
427 * currently, this is a stub implementation for suspend-to-disk
431 #ifdef CONFIG_SOFTWARE_SUSPEND
433 static int pmac_pm_prepare(suspend_state_t state
)
435 printk(KERN_DEBUG
"%s(%d)\n", __FUNCTION__
, state
);
440 static int pmac_pm_enter(suspend_state_t state
)
442 printk(KERN_DEBUG
"%s(%d)\n", __FUNCTION__
, state
);
444 /* Giveup the lazy FPU & vec so we don't have to back them
445 * up from the low level code
449 #ifdef CONFIG_ALTIVEC
450 if (cur_cpu_spec
->cpu_features
& CPU_FTR_ALTIVEC
)
451 enable_kernel_altivec();
452 #endif /* CONFIG_ALTIVEC */
457 static int pmac_pm_finish(suspend_state_t state
)
459 printk(KERN_DEBUG
"%s(%d)\n", __FUNCTION__
, state
);
461 /* Restore userland MMU context */
462 set_context(current
->active_mm
->context
, current
->active_mm
->pgd
);
467 static struct pm_ops pmac_pm_ops
= {
468 .pm_disk_mode
= PM_DISK_SHUTDOWN
,
469 .prepare
= pmac_pm_prepare
,
470 .enter
= pmac_pm_enter
,
471 .finish
= pmac_pm_finish
,
474 #endif /* CONFIG_SOFTWARE_SUSPEND */
476 static int pmac_late_init(void)
479 #ifdef CONFIG_SOFTWARE_SUSPEND
480 pm_set_ops(&pmac_pm_ops
);
481 #endif /* CONFIG_SOFTWARE_SUSPEND */
485 late_initcall(pmac_late_init
);
487 /* can't be __init - can be called whenever a disk is first accessed */
489 note_bootable_part(dev_t dev
, int part
, int goodness
)
491 static int found_boot
= 0;
496 if ((goodness
<= current_root_goodness
) &&
497 ROOT_DEV
!= DEFAULT_ROOT_DEVICE
)
499 p
= strstr(saved_command_line
, "root=");
500 if (p
!= NULL
&& (p
== saved_command_line
|| p
[-1] == ' '))
507 if (!boot_dev
|| dev
== boot_dev
) {
508 ROOT_DEV
= dev
+ part
;
510 current_root_goodness
= goodness
;
515 pmac_restart(char *cmd
)
517 #ifdef CONFIG_ADB_CUDA
518 struct adb_request req
;
519 #endif /* CONFIG_ADB_CUDA */
521 switch (sys_ctrler
) {
522 #ifdef CONFIG_ADB_CUDA
523 case SYS_CTRLER_CUDA
:
524 cuda_request(&req
, NULL
, 2, CUDA_PACKET
,
529 #endif /* CONFIG_ADB_CUDA */
530 #ifdef CONFIG_ADB_PMU
534 #endif /* CONFIG_ADB_PMU */
542 #ifdef CONFIG_ADB_CUDA
543 struct adb_request req
;
544 #endif /* CONFIG_ADB_CUDA */
546 switch (sys_ctrler
) {
547 #ifdef CONFIG_ADB_CUDA
548 case SYS_CTRLER_CUDA
:
549 cuda_request(&req
, NULL
, 2, CUDA_PACKET
,
554 #endif /* CONFIG_ADB_CUDA */
555 #ifdef CONFIG_ADB_PMU
559 #endif /* CONFIG_ADB_PMU */
571 * Read in a property describing some pieces of memory.
575 get_mem_prop(char *name
, struct mem_pieces
*mp
)
577 struct reg_property
*rp
;
580 int nac
= prom_n_addr_cells(memory_node
);
581 int nsc
= prom_n_size_cells(memory_node
);
583 ip
= (unsigned int *) get_property(memory_node
, name
, &s
);
585 printk(KERN_ERR
"error: couldn't get %s property on /memory\n",
589 s
/= (nsc
+ nac
) * 4;
591 for (i
= 0; i
< s
; ++i
, ip
+= nac
+nsc
) {
592 if (nac
>= 2 && ip
[nac
-2] != 0)
594 rp
->address
= ip
[nac
-1];
595 if (nsc
>= 2 && ip
[nac
+nsc
-2] != 0)
598 rp
->size
= ip
[nac
+nsc
-1];
601 mp
->n_regions
= rp
- mp
->regions
;
603 /* Make sure the pieces are sorted. */
605 mem_pieces_coalesce(mp
);
610 * On systems with Open Firmware, collect information about
611 * physical RAM and which pieces are already in use.
612 * At this point, we have (at least) the first 8MB mapped with a BAT.
613 * Our text, data, bss use something over 1MB, starting at 0.
614 * Open Firmware may be using 1MB at the 4MB point.
617 pmac_find_end_of_memory(void)
619 unsigned long a
, total
;
620 struct mem_pieces phys_mem
;
623 * Find out where physical memory is, and check that it
624 * starts at 0 and is contiguous. It seems that RAM is
625 * always physically contiguous on Power Macintoshes.
627 * Supporting discontiguous physical memory isn't hard,
628 * it just makes the virtual <-> physical mapping functions
629 * more complicated (or else you end up wasting space
632 memory_node
= find_devices("memory");
633 if (memory_node
== NULL
|| !get_mem_prop("reg", &phys_mem
)
634 || phys_mem
.n_regions
== 0)
636 a
= phys_mem
.regions
[0].address
;
638 panic("RAM doesn't start at physical address 0");
639 total
= phys_mem
.regions
[0].size
;
641 if (phys_mem
.n_regions
> 1) {
642 printk("RAM starting at 0x%x is not contiguous\n",
643 phys_mem
.regions
[1].address
);
644 printk("Using RAM from 0 to 0x%lx\n", total
-1);
651 pmac_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
652 unsigned long r6
, unsigned long r7
)
654 /* isa_io_base gets set in pmac_find_bridges */
655 isa_mem_base
= PMAC_ISA_MEM_BASE
;
656 pci_dram_offset
= PMAC_PCI_DRAM_OFFSET
;
657 ISA_DMA_THRESHOLD
= ~0L;
661 ppc_md
.setup_arch
= pmac_setup_arch
;
662 ppc_md
.show_cpuinfo
= pmac_show_cpuinfo
;
663 ppc_md
.show_percpuinfo
= pmac_show_percpuinfo
;
664 ppc_md
.init_IRQ
= pmac_pic_init
;
665 ppc_md
.get_irq
= pmac_get_irq
; /* Changed later on ... */
667 ppc_md
.pcibios_fixup
= pmac_pcibios_fixup
;
668 ppc_md
.pcibios_enable_device_hook
= pmac_pci_enable_device_hook
;
669 ppc_md
.pcibios_after_init
= pmac_pcibios_after_init
;
670 ppc_md
.phys_mem_access_prot
= pci_phys_mem_access_prot
;
672 ppc_md
.restart
= pmac_restart
;
673 ppc_md
.power_off
= pmac_power_off
;
674 ppc_md
.halt
= pmac_halt
;
676 ppc_md
.time_init
= pmac_time_init
;
677 ppc_md
.set_rtc_time
= pmac_set_rtc_time
;
678 ppc_md
.get_rtc_time
= pmac_get_rtc_time
;
679 ppc_md
.calibrate_decr
= pmac_calibrate_decr
;
681 ppc_md
.find_end_of_memory
= pmac_find_end_of_memory
;
683 ppc_md
.feature_call
= pmac_do_feature_call
;
685 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
686 #ifdef CONFIG_BLK_DEV_IDE_PMAC
687 ppc_ide_md
.ide_init_hwif
= pmac_ide_init_hwif_ports
;
688 ppc_ide_md
.default_io_base
= pmac_ide_get_base
;
689 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
690 #endif /* defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE) */
692 #ifdef CONFIG_BOOTX_TEXT
693 ppc_md
.progress
= pmac_progress
;
694 #endif /* CONFIG_BOOTX_TEXT */
696 if (ppc_md
.progress
) ppc_md
.progress("pmac_init(): exit", 0);
700 #ifdef CONFIG_BOOTX_TEXT
702 pmac_progress(char *s
, unsigned short hex
)
704 if (boot_text_mapped
) {
706 btext_drawchar('\n');
709 #endif /* CONFIG_BOOTX_TEXT */
712 pmac_declare_of_platform_devices(void)
714 struct device_node
*np
;
716 np
= find_devices("uni-n");
718 for (np
= np
->child
; np
!= NULL
; np
= np
->sibling
)
719 if (strncmp(np
->name
, "i2c", 3) == 0) {
720 of_platform_device_create(np
, "uni-n-i2c",
725 np
= find_devices("u3");
727 for (np
= np
->child
; np
!= NULL
; np
= np
->sibling
)
728 if (strncmp(np
->name
, "i2c", 3) == 0) {
729 of_platform_device_create(np
, "u3-i2c",
735 np
= find_devices("valkyrie");
737 of_platform_device_create(np
, "valkyrie", NULL
);
738 np
= find_devices("platinum");
740 of_platform_device_create(np
, "platinum", NULL
);
745 device_initcall(pmac_declare_of_platform_devices
);