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>
54 #include <linux/bitops.h>
55 #include <linux/suspend.h>
58 #include <asm/sections.h>
60 #include <asm/system.h>
61 #include <asm/pgtable.h>
63 #include <asm/pci-bridge.h>
64 #include <asm/ohare.h>
65 #include <asm/mediabay.h>
66 #include <asm/machdep.h>
68 #include <asm/bootx.h>
69 #include <asm/cputable.h>
70 #include <asm/btext.h>
71 #include <asm/pmac_feature.h>
73 #include <asm/of_device.h>
74 #include <asm/mmu_context.h>
78 #undef SHOW_GATWICK_IRQS
80 unsigned char drive_info;
82 int ppc_override_l2cr = 0;
83 int ppc_override_l2cr_value;
86 int pmac_newworld = 1;
88 static int current_root_goodness = -1;
90 extern int pmac_newworld;
92 #define DEFAULT_ROOT_DEVICE Root_SDA1 /* sda1 - slightly silly choice */
94 extern void zs_kgdb_hook(int tty_num);
95 static void ohare_init(void);
96 #ifdef CONFIG_BOOTX_TEXT
97 static void pmac_progress(char *s, unsigned short hex);
100 sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN;
103 extern struct smp_ops_t psurge_smp_ops;
104 extern struct smp_ops_t core99_smp_ops;
105 #endif /* CONFIG_SMP */
107 static void pmac_show_cpuinfo(struct seq_file *m)
109 struct device_node *np;
113 unsigned int mbflags;
116 mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
117 PMAC_MB_INFO_MODEL, 0);
118 mbflags = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
119 PMAC_MB_INFO_FLAGS, 0);
120 if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME,
121 (long) &mbname) != 0)
124 /* find motherboard type */
125 seq_printf(m, "machine\t\t: ");
126 np = of_find_node_by_path("/");
128 pp = (char *) get_property(np, "model", NULL);
130 seq_printf(m, "%s\n", pp);
132 seq_printf(m, "PowerMac\n");
133 pp = (char *) get_property(np, "compatible", &plen);
135 seq_printf(m, "motherboard\t:");
137 int l = strlen(pp) + 1;
138 seq_printf(m, " %s", pp);
146 seq_printf(m, "PowerMac\n");
148 /* print parsed model */
149 seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname);
150 seq_printf(m, "pmac flags\t: %08x\n", mbflags);
152 /* find l2 cache info */
153 np = of_find_node_by_name(NULL, "l2-cache");
155 np = of_find_node_by_type(NULL, "cache");
157 unsigned int *ic = (unsigned int *)
158 get_property(np, "i-cache-size", NULL);
159 unsigned int *dc = (unsigned int *)
160 get_property(np, "d-cache-size", NULL);
161 seq_printf(m, "L2 cache\t:");
163 if (get_property(np, "cache-unified", NULL) != 0 && dc) {
164 seq_printf(m, " %dK unified", *dc / 1024);
167 seq_printf(m, " %dK instruction", *ic / 1024);
169 seq_printf(m, "%s %dK data",
170 (ic? " +": ""), *dc / 1024);
172 pp = get_property(np, "ram-type", NULL);
174 seq_printf(m, " %s", pp);
179 /* Indicate newworld/oldworld */
180 seq_printf(m, "pmac-generation\t: %s\n",
181 pmac_newworld ? "NewWorld" : "OldWorld");
184 static void pmac_show_percpuinfo(struct seq_file *m, int i)
186 #ifdef CONFIG_CPU_FREQ_PMAC
187 extern unsigned int pmac_get_one_cpufreq(int i);
188 unsigned int freq = pmac_get_one_cpufreq(i);
190 seq_printf(m, "clock\t\t: %dMHz\n", freq/1000);
193 #endif /* CONFIG_CPU_FREQ_PMAC */
194 of_show_percpuinfo(m, i);
197 static volatile u32 *sysctrl_regs;
200 pmac_setup_arch(void)
202 struct device_node *cpu;
206 pvr = PVR_VER(mfspr(SPRN_PVR));
208 /* Set loops_per_jiffy to a half-way reasonable value,
209 for use until calibrate_delay gets called. */
210 cpu = find_type_devices("cpu");
212 fp = (int *) get_property(cpu, "clock-frequency", NULL);
214 if (pvr == 4 || pvr >= 8)
215 /* 604, G3, G4 etc. */
216 loops_per_jiffy = *fp / HZ;
219 loops_per_jiffy = *fp / (2*HZ);
221 loops_per_jiffy = 50000000 / HZ;
224 /* this area has the CPU identification register
225 and some registers used by smp boards */
226 sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000);
229 /* Lookup PCI hosts */
232 /* Checks "l2cr-value" property in the registry */
233 if (cpu_has_feature(CPU_FTR_L2CR)) {
234 struct device_node *np = find_devices("cpus");
236 np = find_type_devices("cpu");
238 unsigned int *l2cr = (unsigned int *)
239 get_property(np, "l2cr-value", NULL);
241 ppc_override_l2cr = 1;
242 ppc_override_l2cr_value = *l2cr;
244 _set_L2CR(ppc_override_l2cr_value);
249 if (ppc_override_l2cr)
250 printk(KERN_INFO "L2CR overriden (0x%x), backside cache is %s\n",
251 ppc_override_l2cr_value, (ppc_override_l2cr_value & 0x80000000)
252 ? "enabled" : "disabled");
258 #ifdef CONFIG_ADB_CUDA
261 if (find_devices("via-cuda")) {
262 printk("WARNING ! Your machine is Cuda based but your kernel\n");
263 printk(" wasn't compiled with CONFIG_ADB_CUDA option !\n");
266 #ifdef CONFIG_ADB_PMU
269 if (find_devices("via-pmu")) {
270 printk("WARNING ! Your machine is PMU based but your kernel\n");
271 printk(" wasn't compiled with CONFIG_ADB_PMU option !\n");
277 #ifdef CONFIG_BLK_DEV_INITRD
279 ROOT_DEV = Root_RAM0;
282 ROOT_DEV = DEFAULT_ROOT_DEVICE;
285 /* Check for Core99 */
286 if (find_devices("uni-n") || find_devices("u3"))
287 smp_ops = &core99_smp_ops;
289 smp_ops = &psurge_smp_ops;
290 #endif /* CONFIG_SMP */
292 pci_create_OF_bus_map();
295 static void __init ohare_init(void)
298 * Turn on the L2 cache.
299 * We assume that we have a PSX memory controller iff
300 * we have an ohare I/O controller.
302 if (find_devices("ohare") != NULL) {
303 if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) {
304 if (sysctrl_regs[4] & 0x10)
305 sysctrl_regs[4] |= 0x04000020;
307 sysctrl_regs[4] |= 0x04000000;
309 printk(KERN_INFO "Level 2 cache enabled\n");
319 extern dev_t boot_dev;
323 note_scsi_host(struct device_node *node, void *host)
328 l = strlen(node->full_name);
329 if (bootpath != NULL && bootdevice != NULL
330 && strncmp(node->full_name, bootdevice, l) == 0
331 && (bootdevice[l] == '/' || bootdevice[l] == 0)) {
334 * There's a bug in OF 1.0.5. (Why am I not surprised.)
335 * If you pass a path like scsi/sd@1:0 to canon, it returns
336 * something like /bandit@F2000000/gc@10/53c94@10000/sd@0,0
337 * That is, the scsi target number doesn't get preserved.
338 * So we pick the target number out of bootpath and use that.
340 p = strstr(bootpath, "/sd@");
343 boot_target = simple_strtoul(p, NULL, 10);
346 boot_part = simple_strtoul(p + 1, NULL, 10);
350 EXPORT_SYMBOL(note_scsi_host);
353 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
359 dev_t __init pmac_find_ide_boot(char *bootdevice, int n);
361 if (bootdevice == NULL)
363 p = strrchr(bootdevice, '/');
368 return pmac_find_ide_boot(bootdevice, n);
370 #endif /* CONFIG_BLK_DEV_IDE && CONFIG_BLK_DEV_IDE_PMAC */
373 find_boot_device(void)
375 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
376 boot_dev = find_ide_boot();
380 static int initializing = 1;
381 /* TODO: Merge the suspend-to-ram with the common code !!!
382 * currently, this is a stub implementation for suspend-to-disk
386 #ifdef CONFIG_SOFTWARE_SUSPEND
388 static int pmac_pm_prepare(suspend_state_t state)
390 printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
395 static int pmac_pm_enter(suspend_state_t state)
397 printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
399 /* Giveup the lazy FPU & vec so we don't have to back them
400 * up from the low level code
404 #ifdef CONFIG_ALTIVEC
405 if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
406 enable_kernel_altivec();
407 #endif /* CONFIG_ALTIVEC */
412 static int pmac_pm_finish(suspend_state_t state)
414 printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
416 /* Restore userland MMU context */
417 set_context(current->active_mm->context, current->active_mm->pgd);
422 static struct pm_ops pmac_pm_ops = {
423 .pm_disk_mode = PM_DISK_SHUTDOWN,
424 .prepare = pmac_pm_prepare,
425 .enter = pmac_pm_enter,
426 .finish = pmac_pm_finish,
429 #endif /* CONFIG_SOFTWARE_SUSPEND */
431 static int pmac_late_init(void)
434 #ifdef CONFIG_SOFTWARE_SUSPEND
435 pm_set_ops(&pmac_pm_ops);
436 #endif /* CONFIG_SOFTWARE_SUSPEND */
440 late_initcall(pmac_late_init);
442 /* can't be __init - can be called whenever a disk is first accessed */
444 note_bootable_part(dev_t dev, int part, int goodness)
446 static int found_boot = 0;
451 if ((goodness <= current_root_goodness) &&
452 ROOT_DEV != DEFAULT_ROOT_DEVICE)
454 p = strstr(saved_command_line, "root=");
455 if (p != NULL && (p == saved_command_line || p[-1] == ' '))
462 if (!boot_dev || dev == boot_dev) {
463 ROOT_DEV = dev + part;
465 current_root_goodness = goodness;
470 pmac_restart(char *cmd)
472 #ifdef CONFIG_ADB_CUDA
473 struct adb_request req;
474 #endif /* CONFIG_ADB_CUDA */
476 switch (sys_ctrler) {
477 #ifdef CONFIG_ADB_CUDA
478 case SYS_CTRLER_CUDA:
479 cuda_request(&req, NULL, 2, CUDA_PACKET,
484 #endif /* CONFIG_ADB_CUDA */
485 #ifdef CONFIG_ADB_PMU
489 #endif /* CONFIG_ADB_PMU */
497 #ifdef CONFIG_ADB_CUDA
498 struct adb_request req;
499 #endif /* CONFIG_ADB_CUDA */
501 switch (sys_ctrler) {
502 #ifdef CONFIG_ADB_CUDA
503 case SYS_CTRLER_CUDA:
504 cuda_request(&req, NULL, 2, CUDA_PACKET,
509 #endif /* CONFIG_ADB_CUDA */
510 #ifdef CONFIG_ADB_PMU
514 #endif /* CONFIG_ADB_PMU */
525 void __init pmac_init(void)
527 /* isa_io_base gets set in pmac_find_bridges */
528 isa_mem_base = PMAC_ISA_MEM_BASE;
529 pci_dram_offset = PMAC_PCI_DRAM_OFFSET;
530 ISA_DMA_THRESHOLD = ~0L;
534 ppc_md.setup_arch = pmac_setup_arch;
535 ppc_md.show_cpuinfo = pmac_show_cpuinfo;
536 ppc_md.show_percpuinfo = pmac_show_percpuinfo;
537 ppc_md.init_IRQ = pmac_pic_init;
538 ppc_md.get_irq = pmac_get_irq; /* Changed later on ... */
540 ppc_md.pcibios_fixup = pmac_pcibios_fixup;
541 ppc_md.pcibios_enable_device_hook = pmac_pci_enable_device_hook;
542 ppc_md.pcibios_after_init = pmac_pcibios_after_init;
543 ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
545 ppc_md.restart = pmac_restart;
546 ppc_md.power_off = pmac_power_off;
547 ppc_md.halt = pmac_halt;
549 ppc_md.time_init = pmac_time_init;
550 ppc_md.set_rtc_time = pmac_set_rtc_time;
551 ppc_md.get_rtc_time = pmac_get_rtc_time;
552 ppc_md.get_boot_time = pmac_get_boot_time;
553 ppc_md.calibrate_decr = pmac_calibrate_decr;
555 ppc_md.feature_call = pmac_do_feature_call;
557 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
558 #ifdef CONFIG_BLK_DEV_IDE_PMAC
559 ppc_ide_md.ide_init_hwif = pmac_ide_init_hwif_ports;
560 ppc_ide_md.default_io_base = pmac_ide_get_base;
561 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
562 #endif /* defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE) */
564 #ifdef CONFIG_BOOTX_TEXT
565 ppc_md.progress = pmac_progress;
566 #endif /* CONFIG_BOOTX_TEXT */
568 if (ppc_md.progress) ppc_md.progress("pmac_init(): exit", 0);
572 #ifdef CONFIG_BOOTX_TEXT
574 pmac_progress(char *s, unsigned short hex)
576 if (boot_text_mapped) {
578 btext_drawchar('\n');
581 #endif /* CONFIG_BOOTX_TEXT */
584 pmac_declare_of_platform_devices(void)
586 struct device_node *np;
588 np = find_devices("uni-n");
590 for (np = np->child; np != NULL; np = np->sibling)
591 if (strncmp(np->name, "i2c", 3) == 0) {
592 of_platform_device_create(np, "uni-n-i2c",
597 np = find_devices("u3");
599 for (np = np->child; np != NULL; np = np->sibling)
600 if (strncmp(np->name, "i2c", 3) == 0) {
601 of_platform_device_create(np, "u3-i2c",
607 np = find_devices("valkyrie");
609 of_platform_device_create(np, "valkyrie", NULL);
610 np = find_devices("platinum");
612 of_platform_device_create(np, "platinum", NULL);
617 device_initcall(pmac_declare_of_platform_devices);