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/irq.h>
52 #include <linux/seq_file.h>
53 #include <linux/root_dev.h>
56 #include <asm/sections.h>
58 #include <asm/system.h>
59 #include <asm/pgtable.h>
60 #include <asm/bitops.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>
74 #include "mem_pieces.h"
76 #undef SHOW_GATWICK_IRQS
78 extern long pmac_time_init(void);
79 extern unsigned long pmac_get_rtc_time(void);
80 extern int pmac_set_rtc_time(unsigned long nowtime
);
81 extern void pmac_read_rtc_time(void);
82 extern void pmac_calibrate_decr(void);
83 extern void pmac_pcibios_fixup(void);
84 extern void pmac_find_bridges(void);
85 extern unsigned long pmac_ide_get_base(int index
);
86 extern void pmac_ide_init_hwif_ports(hw_regs_t
*hw
,
87 unsigned long data_port
, unsigned long ctrl_port
, int *irq
);
89 extern void pmac_nvram_update(void);
90 extern unsigned char pmac_nvram_read_byte(int addr
);
91 extern void pmac_nvram_write_byte(int addr
, unsigned char val
);
92 extern int pmac_pci_enable_device_hook(struct pci_dev
*dev
, int initial
);
93 extern void pmac_pcibios_after_init(void);
94 extern int of_show_percpuinfo(struct seq_file
*m
, int i
);
96 struct device_node
*memory_node
;
98 unsigned char drive_info
;
100 int ppc_override_l2cr
= 0;
101 int ppc_override_l2cr_value
;
104 static int current_root_goodness
= -1;
106 extern int pmac_newworld
;
108 #define DEFAULT_ROOT_DEVICE Root_SDA1 /* sda1 - slightly silly choice */
110 extern void zs_kgdb_hook(int tty_num
);
111 static void ohare_init(void);
112 #ifdef CONFIG_BOOTX_TEXT
113 void pmac_progress(char *s
, unsigned short hex
);
116 sys_ctrler_t sys_ctrler
= SYS_CTRLER_UNKNOWN
;
119 extern struct smp_ops_t psurge_smp_ops
;
120 extern struct smp_ops_t core99_smp_ops
;
121 #endif /* CONFIG_SMP */
124 pmac_show_cpuinfo(struct seq_file
*m
)
126 struct device_node
*np
;
129 int mbmodel
= pmac_call_feature(PMAC_FTR_GET_MB_INFO
,
130 NULL
, PMAC_MB_INFO_MODEL
, 0);
131 unsigned int mbflags
= (unsigned int)pmac_call_feature(PMAC_FTR_GET_MB_INFO
,
132 NULL
, PMAC_MB_INFO_FLAGS
, 0);
135 if (pmac_call_feature(PMAC_FTR_GET_MB_INFO
, NULL
, PMAC_MB_INFO_NAME
, (int)&mbname
) != 0)
138 /* find motherboard type */
139 seq_printf(m
, "machine\t\t: ");
140 np
= find_devices("device-tree");
142 pp
= (char *) get_property(np
, "model", NULL
);
144 seq_printf(m
, "%s\n", pp
);
146 seq_printf(m
, "PowerMac\n");
147 pp
= (char *) get_property(np
, "compatible", &plen
);
149 seq_printf(m
, "motherboard\t:");
151 int l
= strlen(pp
) + 1;
152 seq_printf(m
, " %s", pp
);
159 seq_printf(m
, "PowerMac\n");
161 /* print parsed model */
162 seq_printf(m
, "detected as\t: %d (%s)\n", mbmodel
, mbname
);
163 seq_printf(m
, "pmac flags\t: %08x\n", mbflags
);
165 /* find l2 cache info */
166 np
= find_devices("l2-cache");
168 np
= find_type_devices("cache");
170 unsigned int *ic
= (unsigned int *)
171 get_property(np
, "i-cache-size", NULL
);
172 unsigned int *dc
= (unsigned int *)
173 get_property(np
, "d-cache-size", NULL
);
174 seq_printf(m
, "L2 cache\t:");
176 if (get_property(np
, "cache-unified", NULL
) != 0 && dc
) {
177 seq_printf(m
, " %dK unified", *dc
/ 1024);
180 seq_printf(m
, " %dK instruction", *ic
/ 1024);
182 seq_printf(m
, "%s %dK data",
183 (ic
? " +": ""), *dc
/ 1024);
185 pp
= get_property(np
, "ram-type", NULL
);
187 seq_printf(m
, " %s", pp
);
192 np
= find_devices("memory");
195 struct reg_property
*reg
= (struct reg_property
*)
196 get_property(np
, "reg", &n
);
199 unsigned long total
= 0;
201 for (n
/= sizeof(struct reg_property
); n
> 0; --n
)
202 total
+= (reg
++)->size
;
203 seq_printf(m
, "memory\t\t: %luMB\n", total
>> 20);
207 /* Checks "l2cr-value" property in the registry */
208 np
= find_devices("cpus");
210 np
= find_type_devices("cpu");
212 unsigned int *l2cr
= (unsigned int *)
213 get_property(np
, "l2cr-value", NULL
);
215 seq_printf(m
, "l2cr override\t: 0x%x\n", *l2cr
);
219 /* Indicate newworld/oldworld */
220 seq_printf(m
, "pmac-generation\t: %s\n",
221 pmac_newworld
? "NewWorld" : "OldWorld");
228 pmac_show_percpuinfo(struct seq_file
*m
, int i
)
230 #ifdef CONFIG_CPU_FREQ_PMAC
231 extern unsigned int pmac_get_one_cpufreq(int i
);
232 unsigned int freq
= pmac_get_one_cpufreq(i
);
234 seq_printf(m
, "clock\t\t: %dMHz\n", freq
/1000);
237 #endif /* CONFIG_CPU_FREQ_PMAC */
238 return of_show_percpuinfo(m
, i
);
241 static volatile u32
*sysctrl_regs
;
244 pmac_setup_arch(void)
246 struct device_node
*cpu
;
250 pvr
= PVR_VER(mfspr(PVR
));
252 /* Set loops_per_jiffy to a half-way reasonable value,
253 for use until calibrate_delay gets called. */
254 cpu
= find_type_devices("cpu");
256 fp
= (int *) get_property(cpu
, "clock-frequency", NULL
);
258 if (pvr
== 4 || pvr
>= 8)
259 /* 604, G3, G4 etc. */
260 loops_per_jiffy
= *fp
/ HZ
;
263 loops_per_jiffy
= *fp
/ (2*HZ
);
265 loops_per_jiffy
= 50000000 / HZ
;
268 /* this area has the CPU identification register
269 and some registers used by smp boards */
270 sysctrl_regs
= (volatile u32
*) ioremap(0xf8000000, 0x1000);
273 /* Lookup PCI hosts */
276 /* Checks "l2cr-value" property in the registry */
277 if (cur_cpu_spec
[0]->cpu_features
& CPU_FTR_L2CR
) {
278 struct device_node
*np
= find_devices("cpus");
280 np
= find_type_devices("cpu");
282 unsigned int *l2cr
= (unsigned int *)
283 get_property(np
, "l2cr-value", NULL
);
285 ppc_override_l2cr
= 1;
286 ppc_override_l2cr_value
= *l2cr
;
288 _set_L2CR(ppc_override_l2cr_value
);
293 if (ppc_override_l2cr
)
294 printk(KERN_INFO
"L2CR overriden (0x%x), backside cache is %s\n",
295 ppc_override_l2cr_value
, (ppc_override_l2cr_value
& 0x80000000)
296 ? "enabled" : "disabled");
302 #ifdef CONFIG_ADB_CUDA
305 if (find_devices("via-cuda")) {
306 printk("WARNING ! Your machine is Cuda based but your kernel\n");
307 printk(" wasn't compiled with CONFIG_ADB_CUDA option !\n");
310 #ifdef CONFIG_ADB_PMU
313 if (find_devices("via-pmu")) {
314 printk("WARNING ! Your machine is PMU based but your kernel\n");
315 printk(" wasn't compiled with CONFIG_ADB_PMU option !\n");
321 #ifdef CONFIG_BLK_DEV_INITRD
323 ROOT_DEV
= Root_RAM0
;
326 ROOT_DEV
= DEFAULT_ROOT_DEVICE
;
329 /* Check for Core99 */
330 if (find_devices("uni-n") || find_devices("u3"))
331 ppc_md
.smp_ops
= &core99_smp_ops
;
333 ppc_md
.smp_ops
= &psurge_smp_ops
;
334 #endif /* CONFIG_SMP */
336 pci_create_OF_bus_map();
339 static void __init
ohare_init(void)
342 * Turn on the L2 cache.
343 * We assume that we have a PSX memory controller iff
344 * we have an ohare I/O controller.
346 if (find_devices("ohare") != NULL
) {
347 if (((sysctrl_regs
[2] >> 24) & 0xf) >= 3) {
348 if (sysctrl_regs
[4] & 0x10)
349 sysctrl_regs
[4] |= 0x04000020;
351 sysctrl_regs
[4] |= 0x04000000;
353 printk(KERN_INFO
"Level 2 cache enabled\n");
358 extern char *bootpath
;
359 extern char *bootdevice
;
363 extern dev_t boot_dev
;
367 note_scsi_host(struct device_node
*node
, void *host
)
372 l
= strlen(node
->full_name
);
373 if (bootpath
!= NULL
&& bootdevice
!= NULL
374 && strncmp(node
->full_name
, bootdevice
, l
) == 0
375 && (bootdevice
[l
] == '/' || bootdevice
[l
] == 0)) {
378 * There's a bug in OF 1.0.5. (Why am I not surprised.)
379 * If you pass a path like scsi/sd@1:0 to canon, it returns
380 * something like /bandit@F2000000/gc@10/53c94@10000/sd@0,0
381 * That is, the scsi target number doesn't get preserved.
382 * So we pick the target number out of bootpath and use that.
384 p
= strstr(bootpath
, "/sd@");
387 boot_target
= simple_strtoul(p
, NULL
, 10);
390 boot_part
= simple_strtoul(p
+ 1, NULL
, 10);
396 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
402 dev_t __init
pmac_find_ide_boot(char *bootdevice
, int n
);
404 if (bootdevice
== NULL
)
406 p
= strrchr(bootdevice
, '/');
411 return pmac_find_ide_boot(bootdevice
, n
);
413 #endif /* CONFIG_BLK_DEV_IDE && CONFIG_BLK_DEV_IDE_PMAC */
416 find_boot_device(void)
418 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
419 boot_dev
= find_ide_boot();
423 static int initializing
= 1;
425 static int pmac_late_init(void)
431 late_initcall(pmac_late_init
);
433 /* can't be __init - can be called whenever a disk is first accessed */
435 note_bootable_part(dev_t dev
, int part
, int goodness
)
437 static int found_boot
= 0;
442 if ((goodness
<= current_root_goodness
) &&
443 ROOT_DEV
!= DEFAULT_ROOT_DEVICE
)
445 p
= strstr(saved_command_line
, "root=");
446 if (p
!= NULL
&& (p
== saved_command_line
|| p
[-1] == ' '))
453 if (!boot_dev
|| dev
== boot_dev
) {
454 ROOT_DEV
= dev
+ part
;
456 current_root_goodness
= goodness
;
461 pmac_restart(char *cmd
)
463 #ifdef CONFIG_ADB_CUDA
464 struct adb_request req
;
465 #endif /* CONFIG_ADB_CUDA */
467 switch (sys_ctrler
) {
468 #ifdef CONFIG_ADB_CUDA
469 case SYS_CTRLER_CUDA
:
470 cuda_request(&req
, NULL
, 2, CUDA_PACKET
,
475 #endif /* CONFIG_ADB_CUDA */
476 #ifdef CONFIG_ADB_PMU
480 #endif /* CONFIG_ADB_PMU */
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 */
517 * Read in a property describing some pieces of memory.
521 get_mem_prop(char *name
, struct mem_pieces
*mp
)
523 struct reg_property
*rp
;
526 int nac
= prom_n_addr_cells(memory_node
);
527 int nsc
= prom_n_size_cells(memory_node
);
529 ip
= (unsigned int *) get_property(memory_node
, name
, &s
);
531 printk(KERN_ERR
"error: couldn't get %s property on /memory\n",
535 s
/= (nsc
+ nac
) * 4;
537 for (i
= 0; i
< s
; ++i
, ip
+= nac
+nsc
) {
538 if (nac
>= 2 && ip
[nac
-2] != 0)
540 rp
->address
= ip
[nac
-1];
541 if (nsc
>= 2 && ip
[nac
+nsc
-2] != 0)
544 rp
->size
= ip
[nac
+nsc
-1];
547 mp
->n_regions
= rp
- mp
->regions
;
549 /* Make sure the pieces are sorted. */
551 mem_pieces_coalesce(mp
);
556 * On systems with Open Firmware, collect information about
557 * physical RAM and which pieces are already in use.
558 * At this point, we have (at least) the first 8MB mapped with a BAT.
559 * Our text, data, bss use something over 1MB, starting at 0.
560 * Open Firmware may be using 1MB at the 4MB point.
563 pmac_find_end_of_memory(void)
565 unsigned long a
, total
;
566 struct mem_pieces phys_mem
;
569 * Find out where physical memory is, and check that it
570 * starts at 0 and is contiguous. It seems that RAM is
571 * always physically contiguous on Power Macintoshes.
573 * Supporting discontiguous physical memory isn't hard,
574 * it just makes the virtual <-> physical mapping functions
575 * more complicated (or else you end up wasting space
578 memory_node
= find_devices("memory");
579 if (memory_node
== NULL
|| !get_mem_prop("reg", &phys_mem
)
580 || phys_mem
.n_regions
== 0)
582 a
= phys_mem
.regions
[0].address
;
584 panic("RAM doesn't start at physical address 0");
585 total
= phys_mem
.regions
[0].size
;
587 if (phys_mem
.n_regions
> 1) {
588 printk("RAM starting at 0x%x is not contiguous\n",
589 phys_mem
.regions
[1].address
);
590 printk("Using RAM from 0 to 0x%lx\n", total
-1);
597 pmac_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
598 unsigned long r6
, unsigned long r7
)
600 /* isa_io_base gets set in pmac_find_bridges */
601 isa_mem_base
= PMAC_ISA_MEM_BASE
;
602 pci_dram_offset
= PMAC_PCI_DRAM_OFFSET
;
603 ISA_DMA_THRESHOLD
= ~0L;
607 ppc_md
.setup_arch
= pmac_setup_arch
;
608 ppc_md
.show_cpuinfo
= pmac_show_cpuinfo
;
609 ppc_md
.show_percpuinfo
= pmac_show_percpuinfo
;
610 ppc_md
.irq_canonicalize
= NULL
;
611 ppc_md
.init_IRQ
= pmac_pic_init
;
612 ppc_md
.get_irq
= pmac_get_irq
; /* Changed later on ... */
614 ppc_md
.pcibios_fixup
= pmac_pcibios_fixup
;
615 ppc_md
.pcibios_enable_device_hook
= pmac_pci_enable_device_hook
;
616 ppc_md
.pcibios_after_init
= pmac_pcibios_after_init
;
618 ppc_md
.restart
= pmac_restart
;
619 ppc_md
.power_off
= pmac_power_off
;
620 ppc_md
.halt
= pmac_halt
;
622 ppc_md
.time_init
= pmac_time_init
;
623 ppc_md
.set_rtc_time
= pmac_set_rtc_time
;
624 ppc_md
.get_rtc_time
= pmac_get_rtc_time
;
625 ppc_md
.calibrate_decr
= pmac_calibrate_decr
;
627 ppc_md
.find_end_of_memory
= pmac_find_end_of_memory
;
629 ppc_md
.feature_call
= pmac_do_feature_call
;
631 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
632 #ifdef CONFIG_BLK_DEV_IDE_PMAC
633 ppc_ide_md
.ide_init_hwif
= pmac_ide_init_hwif_ports
;
634 ppc_ide_md
.default_io_base
= pmac_ide_get_base
;
635 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
636 #endif /* defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE) */
638 #ifdef CONFIG_BOOTX_TEXT
639 ppc_md
.progress
= pmac_progress
;
640 #endif /* CONFIG_BOOTX_TEXT */
642 if (ppc_md
.progress
) ppc_md
.progress("pmac_init(): exit", 0);
646 #ifdef CONFIG_BOOTX_TEXT
648 pmac_progress(char *s
, unsigned short hex
)
650 if (boot_text_mapped
) {
652 btext_drawchar('\n');
655 #endif /* CONFIG_BOOTX_TEXT */
658 pmac_declare_of_platform_devices(void)
660 struct device_node
*np
;
662 np
= find_devices("uni-n");
664 for (np
= np
->child
; np
!= NULL
; np
= np
->sibling
)
665 if (strncmp(np
->name
, "i2c", 3) == 0) {
666 of_platform_device_create(np
, "uni-n-i2c");
670 np
= find_devices("u3");
672 for (np
= np
->child
; np
!= NULL
; np
= np
->sibling
)
673 if (strncmp(np
->name
, "i2c", 3) == 0) {
674 of_platform_device_create(np
, "u3-i2c");
679 np
= find_devices("valkyrie");
681 of_platform_device_create(np
, "valkyrie");
682 np
= find_devices("platinum");
684 of_platform_device_create(np
, "platinum");
689 device_initcall(pmac_declare_of_platform_devices
);