powerpc: Fix places where ppc_md.show_[per]cpuinfo was treated as int
[linux-3.10.git] / arch / powerpc / platforms / powermac / setup.c
1 /*
2  *  arch/ppc/platforms/setup.c
3  *
4  *  PowerPC version
5  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6  *
7  *  Adapted for Power Macintosh by Paul Mackerras
8  *    Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au)
9  *
10  *  Derived from "arch/alpha/kernel/setup.c"
11  *    Copyright (C) 1995 Linus Torvalds
12  *
13  *  Maintained by Benjamin Herrenschmidt (benh@kernel.crashing.org)
14  *
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.
19  *
20  */
21
22 /*
23  * bootup setup stuff..
24  */
25
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>
31 #include <linux/mm.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>
56
57 #include <asm/reg.h>
58 #include <asm/sections.h>
59 #include <asm/prom.h>
60 #include <asm/system.h>
61 #include <asm/pgtable.h>
62 #include <asm/io.h>
63 #include <asm/pci-bridge.h>
64 #include <asm/ohare.h>
65 #include <asm/mediabay.h>
66 #include <asm/machdep.h>
67 #include <asm/dma.h>
68 #include <asm/bootx.h>
69 #include <asm/cputable.h>
70 #include <asm/btext.h>
71 #include <asm/pmac_feature.h>
72 #include <asm/time.h>
73 #include <asm/of_device.h>
74 #include <asm/mmu_context.h>
75
76 #include "pmac.h"
77
78 #undef SHOW_GATWICK_IRQS
79
80 unsigned char drive_info;
81
82 int ppc_override_l2cr = 0;
83 int ppc_override_l2cr_value;
84 int has_l2cache = 0;
85
86 int pmac_newworld = 1;
87
88 static int current_root_goodness = -1;
89
90 extern int pmac_newworld;
91
92 #define DEFAULT_ROOT_DEVICE Root_SDA1   /* sda1 - slightly silly choice */
93
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);
98 #endif
99
100 sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN;
101
102 #ifdef CONFIG_SMP
103 extern struct smp_ops_t psurge_smp_ops;
104 extern struct smp_ops_t core99_smp_ops;
105 #endif /* CONFIG_SMP */
106
107 static void pmac_show_cpuinfo(struct seq_file *m)
108 {
109         struct device_node *np;
110         char *pp;
111         int plen;
112         int mbmodel;
113         unsigned int mbflags;
114         char* mbname;
115
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)
122                 mbname = "Unknown";
123
124         /* find motherboard type */
125         seq_printf(m, "machine\t\t: ");
126         np = of_find_node_by_path("/");
127         if (np != NULL) {
128                 pp = (char *) get_property(np, "model", NULL);
129                 if (pp != NULL)
130                         seq_printf(m, "%s\n", pp);
131                 else
132                         seq_printf(m, "PowerMac\n");
133                 pp = (char *) get_property(np, "compatible", &plen);
134                 if (pp != NULL) {
135                         seq_printf(m, "motherboard\t:");
136                         while (plen > 0) {
137                                 int l = strlen(pp) + 1;
138                                 seq_printf(m, " %s", pp);
139                                 plen -= l;
140                                 pp += l;
141                         }
142                         seq_printf(m, "\n");
143                 }
144                 of_node_put(np);
145         } else
146                 seq_printf(m, "PowerMac\n");
147
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);
151
152         /* find l2 cache info */
153         np = of_find_node_by_name(NULL, "l2-cache");
154         if (np == NULL)
155                 np = of_find_node_by_type(NULL, "cache");
156         if (np != NULL) {
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:");
162                 has_l2cache = 1;
163                 if (get_property(np, "cache-unified", NULL) != 0 && dc) {
164                         seq_printf(m, " %dK unified", *dc / 1024);
165                 } else {
166                         if (ic)
167                                 seq_printf(m, " %dK instruction", *ic / 1024);
168                         if (dc)
169                                 seq_printf(m, "%s %dK data",
170                                            (ic? " +": ""), *dc / 1024);
171                 }
172                 pp = get_property(np, "ram-type", NULL);
173                 if (pp)
174                         seq_printf(m, " %s", pp);
175                 seq_printf(m, "\n");
176                 of_node_put(np);
177         }
178
179         /* Indicate newworld/oldworld */
180         seq_printf(m, "pmac-generation\t: %s\n",
181                    pmac_newworld ? "NewWorld" : "OldWorld");
182 }
183
184 static void pmac_show_percpuinfo(struct seq_file *m, int i)
185 {
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);
189         if (freq != 0) {
190                 seq_printf(m, "clock\t\t: %dMHz\n", freq/1000);
191                 return;
192         }
193 #endif /* CONFIG_CPU_FREQ_PMAC */
194         of_show_percpuinfo(m, i);
195 }
196
197 static volatile u32 *sysctrl_regs;
198
199 void __init
200 pmac_setup_arch(void)
201 {
202         struct device_node *cpu;
203         int *fp;
204         unsigned long pvr;
205
206         pvr = PVR_VER(mfspr(SPRN_PVR));
207
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");
211         if (cpu != 0) {
212                 fp = (int *) get_property(cpu, "clock-frequency", NULL);
213                 if (fp != 0) {
214                         if (pvr == 4 || pvr >= 8)
215                                 /* 604, G3, G4 etc. */
216                                 loops_per_jiffy = *fp / HZ;
217                         else
218                                 /* 601, 603, etc. */
219                                 loops_per_jiffy = *fp / (2*HZ);
220                 } else
221                         loops_per_jiffy = 50000000 / HZ;
222         }
223
224         /* this area has the CPU identification register
225            and some registers used by smp boards */
226         sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000);
227         ohare_init();
228
229         /* Lookup PCI hosts */
230         pmac_find_bridges();
231
232         /* Checks "l2cr-value" property in the registry */
233         if (cpu_has_feature(CPU_FTR_L2CR)) {
234                 struct device_node *np = find_devices("cpus");
235                 if (np == 0)
236                         np = find_type_devices("cpu");
237                 if (np != 0) {
238                         unsigned int *l2cr = (unsigned int *)
239                                 get_property(np, "l2cr-value", NULL);
240                         if (l2cr != 0) {
241                                 ppc_override_l2cr = 1;
242                                 ppc_override_l2cr_value = *l2cr;
243                                 _set_L2CR(0);
244                                 _set_L2CR(ppc_override_l2cr_value);
245                         }
246                 }
247         }
248
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");
253
254 #ifdef CONFIG_KGDB
255         zs_kgdb_hook(0);
256 #endif
257
258 #ifdef CONFIG_ADB_CUDA
259         find_via_cuda();
260 #else
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");
264         }
265 #endif
266 #ifdef CONFIG_ADB_PMU
267         find_via_pmu();
268 #else
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");
272         }
273 #endif
274 #ifdef CONFIG_NVRAM
275         pmac_nvram_init();
276 #endif
277 #ifdef CONFIG_BLK_DEV_INITRD
278         if (initrd_start)
279                 ROOT_DEV = Root_RAM0;
280         else
281 #endif
282                 ROOT_DEV = DEFAULT_ROOT_DEVICE;
283
284 #ifdef CONFIG_SMP
285         /* Check for Core99 */
286         if (find_devices("uni-n") || find_devices("u3"))
287                 smp_ops = &core99_smp_ops;
288         else
289                 smp_ops = &psurge_smp_ops;
290 #endif /* CONFIG_SMP */
291
292         pci_create_OF_bus_map();
293 }
294
295 static void __init ohare_init(void)
296 {
297         /*
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.
301          */
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;
306                         else
307                                 sysctrl_regs[4] |= 0x04000000;
308                         if(has_l2cache)
309                                 printk(KERN_INFO "Level 2 cache enabled\n");
310                 }
311         }
312 }
313
314 char *bootpath;
315 char *bootdevice;
316 void *boot_host;
317 int boot_target;
318 int boot_part;
319 extern dev_t boot_dev;
320
321 #ifdef CONFIG_SCSI
322 void __init
323 note_scsi_host(struct device_node *node, void *host)
324 {
325         int l;
326         char *p;
327
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)) {
332                 boot_host = host;
333                 /*
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.
339                  */
340                 p = strstr(bootpath, "/sd@");
341                 if (p != NULL) {
342                         p += 4;
343                         boot_target = simple_strtoul(p, NULL, 10);
344                         p = strchr(p, ':');
345                         if (p != NULL)
346                                 boot_part = simple_strtoul(p + 1, NULL, 10);
347                 }
348         }
349 }
350 EXPORT_SYMBOL(note_scsi_host);
351 #endif
352
353 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
354 static dev_t __init
355 find_ide_boot(void)
356 {
357         char *p;
358         int n;
359         dev_t __init pmac_find_ide_boot(char *bootdevice, int n);
360
361         if (bootdevice == NULL)
362                 return 0;
363         p = strrchr(bootdevice, '/');
364         if (p == NULL)
365                 return 0;
366         n = p - bootdevice;
367
368         return pmac_find_ide_boot(bootdevice, n);
369 }
370 #endif /* CONFIG_BLK_DEV_IDE && CONFIG_BLK_DEV_IDE_PMAC */
371
372 static void __init
373 find_boot_device(void)
374 {
375 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
376         boot_dev = find_ide_boot();
377 #endif
378 }
379
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
383  * only
384  */
385
386 #ifdef CONFIG_SOFTWARE_SUSPEND
387
388 static int pmac_pm_prepare(suspend_state_t state)
389 {
390         printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
391
392         return 0;
393 }
394
395 static int pmac_pm_enter(suspend_state_t state)
396 {
397         printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
398
399         /* Giveup the lazy FPU & vec so we don't have to back them
400          * up from the low level code
401          */
402         enable_kernel_fp();
403
404 #ifdef CONFIG_ALTIVEC
405         if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
406                 enable_kernel_altivec();
407 #endif /* CONFIG_ALTIVEC */
408
409         return 0;
410 }
411
412 static int pmac_pm_finish(suspend_state_t state)
413 {
414         printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
415
416         /* Restore userland MMU context */
417         set_context(current->active_mm->context, current->active_mm->pgd);
418
419         return 0;
420 }
421
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,
427 };
428
429 #endif /* CONFIG_SOFTWARE_SUSPEND */
430
431 static int pmac_late_init(void)
432 {
433         initializing = 0;
434 #ifdef CONFIG_SOFTWARE_SUSPEND
435         pm_set_ops(&pmac_pm_ops);
436 #endif /* CONFIG_SOFTWARE_SUSPEND */
437         return 0;
438 }
439
440 late_initcall(pmac_late_init);
441
442 /* can't be __init - can be called whenever a disk is first accessed */
443 void
444 note_bootable_part(dev_t dev, int part, int goodness)
445 {
446         static int found_boot = 0;
447         char *p;
448
449         if (!initializing)
450                 return;
451         if ((goodness <= current_root_goodness) &&
452             ROOT_DEV != DEFAULT_ROOT_DEVICE)
453                 return;
454         p = strstr(saved_command_line, "root=");
455         if (p != NULL && (p == saved_command_line || p[-1] == ' '))
456                 return;
457
458         if (!found_boot) {
459                 find_boot_device();
460                 found_boot = 1;
461         }
462         if (!boot_dev || dev == boot_dev) {
463                 ROOT_DEV = dev + part;
464                 boot_dev = 0;
465                 current_root_goodness = goodness;
466         }
467 }
468
469 static void
470 pmac_restart(char *cmd)
471 {
472 #ifdef CONFIG_ADB_CUDA
473         struct adb_request req;
474 #endif /* CONFIG_ADB_CUDA */
475
476         switch (sys_ctrler) {
477 #ifdef CONFIG_ADB_CUDA
478         case SYS_CTRLER_CUDA:
479                 cuda_request(&req, NULL, 2, CUDA_PACKET,
480                              CUDA_RESET_SYSTEM);
481                 for (;;)
482                         cuda_poll();
483                 break;
484 #endif /* CONFIG_ADB_CUDA */
485 #ifdef CONFIG_ADB_PMU
486         case SYS_CTRLER_PMU:
487                 pmu_restart();
488                 break;
489 #endif /* CONFIG_ADB_PMU */
490         default: ;
491         }
492 }
493
494 static void
495 pmac_power_off(void)
496 {
497 #ifdef CONFIG_ADB_CUDA
498         struct adb_request req;
499 #endif /* CONFIG_ADB_CUDA */
500
501         switch (sys_ctrler) {
502 #ifdef CONFIG_ADB_CUDA
503         case SYS_CTRLER_CUDA:
504                 cuda_request(&req, NULL, 2, CUDA_PACKET,
505                              CUDA_POWERDOWN);
506                 for (;;)
507                         cuda_poll();
508                 break;
509 #endif /* CONFIG_ADB_CUDA */
510 #ifdef CONFIG_ADB_PMU
511         case SYS_CTRLER_PMU:
512                 pmu_shutdown();
513                 break;
514 #endif /* CONFIG_ADB_PMU */
515         default: ;
516         }
517 }
518
519 static void
520 pmac_halt(void)
521 {
522         pmac_power_off();
523 }
524
525 void __init pmac_init(void)
526 {
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;
531         DMA_MODE_READ = 1;
532         DMA_MODE_WRITE = 2;
533
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 ... */
539
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;
544
545         ppc_md.restart        = pmac_restart;
546         ppc_md.power_off      = pmac_power_off;
547         ppc_md.halt           = pmac_halt;
548
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;
554
555         ppc_md.feature_call   = pmac_do_feature_call;
556
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) */
563
564 #ifdef CONFIG_BOOTX_TEXT
565         ppc_md.progress = pmac_progress;
566 #endif /* CONFIG_BOOTX_TEXT */
567
568         if (ppc_md.progress) ppc_md.progress("pmac_init(): exit", 0);
569
570 }
571
572 #ifdef CONFIG_BOOTX_TEXT
573 static void __init
574 pmac_progress(char *s, unsigned short hex)
575 {
576         if (boot_text_mapped) {
577                 btext_drawstring(s);
578                 btext_drawchar('\n');
579         }
580 }
581 #endif /* CONFIG_BOOTX_TEXT */
582
583 static int __init
584 pmac_declare_of_platform_devices(void)
585 {
586         struct device_node *np;
587
588         np = find_devices("uni-n");
589         if (np) {
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",
593                                                           NULL);
594                                 break;
595                         }
596         }
597         np = find_devices("u3");
598         if (np) {
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",
602                                                           NULL);
603                                 break;
604                         }
605         }
606
607         np = find_devices("valkyrie");
608         if (np)
609                 of_platform_device_create(np, "valkyrie", NULL);
610         np = find_devices("platinum");
611         if (np)
612                 of_platform_device_create(np, "platinum", NULL);
613
614         return 0;
615 }
616
617 device_initcall(pmac_declare_of_platform_devices);