]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/powerpc/platforms/powermac/setup.c
powerpc: Start merging 64-bit support into powermac files
[karo-tx-linux.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 int
108 pmac_show_cpuinfo(struct seq_file *m)
109 {
110         struct device_node *np;
111         char *pp;
112         int plen;
113         int mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO,
114                 NULL, PMAC_MB_INFO_MODEL, 0);
115         unsigned int mbflags = (unsigned int)pmac_call_feature(PMAC_FTR_GET_MB_INFO,
116                 NULL, PMAC_MB_INFO_FLAGS, 0);
117         char* mbname;
118
119         if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME, (int)&mbname) != 0)
120                 mbname = "Unknown";
121
122         /* find motherboard type */
123         seq_printf(m, "machine\t\t: ");
124         np = find_devices("device-tree");
125         if (np != NULL) {
126                 pp = (char *) get_property(np, "model", NULL);
127                 if (pp != NULL)
128                         seq_printf(m, "%s\n", pp);
129                 else
130                         seq_printf(m, "PowerMac\n");
131                 pp = (char *) get_property(np, "compatible", &plen);
132                 if (pp != NULL) {
133                         seq_printf(m, "motherboard\t:");
134                         while (plen > 0) {
135                                 int l = strlen(pp) + 1;
136                                 seq_printf(m, " %s", pp);
137                                 plen -= l;
138                                 pp += l;
139                         }
140                         seq_printf(m, "\n");
141                 }
142         } else
143                 seq_printf(m, "PowerMac\n");
144
145         /* print parsed model */
146         seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname);
147         seq_printf(m, "pmac flags\t: %08x\n", mbflags);
148
149         /* find l2 cache info */
150         np = find_devices("l2-cache");
151         if (np == 0)
152                 np = find_type_devices("cache");
153         if (np != 0) {
154                 unsigned int *ic = (unsigned int *)
155                         get_property(np, "i-cache-size", NULL);
156                 unsigned int *dc = (unsigned int *)
157                         get_property(np, "d-cache-size", NULL);
158                 seq_printf(m, "L2 cache\t:");
159                 has_l2cache = 1;
160                 if (get_property(np, "cache-unified", NULL) != 0 && dc) {
161                         seq_printf(m, " %dK unified", *dc / 1024);
162                 } else {
163                         if (ic)
164                                 seq_printf(m, " %dK instruction", *ic / 1024);
165                         if (dc)
166                                 seq_printf(m, "%s %dK data",
167                                            (ic? " +": ""), *dc / 1024);
168                 }
169                 pp = get_property(np, "ram-type", NULL);
170                 if (pp)
171                         seq_printf(m, " %s", pp);
172                 seq_printf(m, "\n");
173         }
174
175         /* find ram info */
176         np = find_devices("memory");
177         if (np != 0) {
178                 int n;
179                 struct reg_property *reg = (struct reg_property *)
180                         get_property(np, "reg", &n);
181
182                 if (reg != 0) {
183                         unsigned long total = 0;
184
185                         for (n /= sizeof(struct reg_property); n > 0; --n)
186                                 total += (reg++)->size;
187                         seq_printf(m, "memory\t\t: %luMB\n", total >> 20);
188                 }
189         }
190
191         /* Checks "l2cr-value" property in the registry */
192         np = find_devices("cpus");
193         if (np == 0)
194                 np = find_type_devices("cpu");
195         if (np != 0) {
196                 unsigned int *l2cr = (unsigned int *)
197                         get_property(np, "l2cr-value", NULL);
198                 if (l2cr != 0) {
199                         seq_printf(m, "l2cr override\t: 0x%x\n", *l2cr);
200                 }
201         }
202
203         /* Indicate newworld/oldworld */
204         seq_printf(m, "pmac-generation\t: %s\n",
205                    pmac_newworld ? "NewWorld" : "OldWorld");
206
207
208         return 0;
209 }
210
211 static int
212 pmac_show_percpuinfo(struct seq_file *m, int i)
213 {
214 #ifdef CONFIG_CPU_FREQ_PMAC
215         extern unsigned int pmac_get_one_cpufreq(int i);
216         unsigned int freq = pmac_get_one_cpufreq(i);
217         if (freq != 0) {
218                 seq_printf(m, "clock\t\t: %dMHz\n", freq/1000);
219                 return 0;
220         }
221 #endif /* CONFIG_CPU_FREQ_PMAC */
222         return of_show_percpuinfo(m, i);
223 }
224
225 static volatile u32 *sysctrl_regs;
226
227 void __init
228 pmac_setup_arch(void)
229 {
230         struct device_node *cpu;
231         int *fp;
232         unsigned long pvr;
233
234         pvr = PVR_VER(mfspr(SPRN_PVR));
235
236         /* Set loops_per_jiffy to a half-way reasonable value,
237            for use until calibrate_delay gets called. */
238         cpu = find_type_devices("cpu");
239         if (cpu != 0) {
240                 fp = (int *) get_property(cpu, "clock-frequency", NULL);
241                 if (fp != 0) {
242                         if (pvr == 4 || pvr >= 8)
243                                 /* 604, G3, G4 etc. */
244                                 loops_per_jiffy = *fp / HZ;
245                         else
246                                 /* 601, 603, etc. */
247                                 loops_per_jiffy = *fp / (2*HZ);
248                 } else
249                         loops_per_jiffy = 50000000 / HZ;
250         }
251
252         /* this area has the CPU identification register
253            and some registers used by smp boards */
254         sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000);
255         ohare_init();
256
257         /* Lookup PCI hosts */
258         pmac_find_bridges();
259
260         /* Checks "l2cr-value" property in the registry */
261         if (cpu_has_feature(CPU_FTR_L2CR)) {
262                 struct device_node *np = find_devices("cpus");
263                 if (np == 0)
264                         np = find_type_devices("cpu");
265                 if (np != 0) {
266                         unsigned int *l2cr = (unsigned int *)
267                                 get_property(np, "l2cr-value", NULL);
268                         if (l2cr != 0) {
269                                 ppc_override_l2cr = 1;
270                                 ppc_override_l2cr_value = *l2cr;
271                                 _set_L2CR(0);
272                                 _set_L2CR(ppc_override_l2cr_value);
273                         }
274                 }
275         }
276
277         if (ppc_override_l2cr)
278                 printk(KERN_INFO "L2CR overriden (0x%x), backside cache is %s\n",
279                         ppc_override_l2cr_value, (ppc_override_l2cr_value & 0x80000000)
280                                 ? "enabled" : "disabled");
281
282 #ifdef CONFIG_KGDB
283         zs_kgdb_hook(0);
284 #endif
285
286 #ifdef CONFIG_ADB_CUDA
287         find_via_cuda();
288 #else
289         if (find_devices("via-cuda")) {
290                 printk("WARNING ! Your machine is Cuda based but your kernel\n");
291                 printk("          wasn't compiled with CONFIG_ADB_CUDA option !\n");
292         }
293 #endif
294 #ifdef CONFIG_ADB_PMU
295         find_via_pmu();
296 #else
297         if (find_devices("via-pmu")) {
298                 printk("WARNING ! Your machine is PMU based but your kernel\n");
299                 printk("          wasn't compiled with CONFIG_ADB_PMU option !\n");
300         }
301 #endif
302 #ifdef CONFIG_NVRAM
303         pmac_nvram_init();
304 #endif
305 #ifdef CONFIG_BLK_DEV_INITRD
306         if (initrd_start)
307                 ROOT_DEV = Root_RAM0;
308         else
309 #endif
310                 ROOT_DEV = DEFAULT_ROOT_DEVICE;
311
312 #ifdef CONFIG_SMP
313         /* Check for Core99 */
314         if (find_devices("uni-n") || find_devices("u3"))
315                 ppc_md.smp_ops = &core99_smp_ops;
316         else
317                 ppc_md.smp_ops = &psurge_smp_ops;
318 #endif /* CONFIG_SMP */
319
320         pci_create_OF_bus_map();
321 }
322
323 static void __init ohare_init(void)
324 {
325         /*
326          * Turn on the L2 cache.
327          * We assume that we have a PSX memory controller iff
328          * we have an ohare I/O controller.
329          */
330         if (find_devices("ohare") != NULL) {
331                 if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) {
332                         if (sysctrl_regs[4] & 0x10)
333                                 sysctrl_regs[4] |= 0x04000020;
334                         else
335                                 sysctrl_regs[4] |= 0x04000000;
336                         if(has_l2cache)
337                                 printk(KERN_INFO "Level 2 cache enabled\n");
338                 }
339         }
340 }
341
342 char *bootpath;
343 char *bootdevice;
344 void *boot_host;
345 int boot_target;
346 int boot_part;
347 extern dev_t boot_dev;
348
349 #ifdef CONFIG_SCSI
350 void __init
351 note_scsi_host(struct device_node *node, void *host)
352 {
353         int l;
354         char *p;
355
356         l = strlen(node->full_name);
357         if (bootpath != NULL && bootdevice != NULL
358             && strncmp(node->full_name, bootdevice, l) == 0
359             && (bootdevice[l] == '/' || bootdevice[l] == 0)) {
360                 boot_host = host;
361                 /*
362                  * There's a bug in OF 1.0.5.  (Why am I not surprised.)
363                  * If you pass a path like scsi/sd@1:0 to canon, it returns
364                  * something like /bandit@F2000000/gc@10/53c94@10000/sd@0,0
365                  * That is, the scsi target number doesn't get preserved.
366                  * So we pick the target number out of bootpath and use that.
367                  */
368                 p = strstr(bootpath, "/sd@");
369                 if (p != NULL) {
370                         p += 4;
371                         boot_target = simple_strtoul(p, NULL, 10);
372                         p = strchr(p, ':');
373                         if (p != NULL)
374                                 boot_part = simple_strtoul(p + 1, NULL, 10);
375                 }
376         }
377 }
378 EXPORT_SYMBOL(note_scsi_host);
379 #endif
380
381 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
382 static dev_t __init
383 find_ide_boot(void)
384 {
385         char *p;
386         int n;
387         dev_t __init pmac_find_ide_boot(char *bootdevice, int n);
388
389         if (bootdevice == NULL)
390                 return 0;
391         p = strrchr(bootdevice, '/');
392         if (p == NULL)
393                 return 0;
394         n = p - bootdevice;
395
396         return pmac_find_ide_boot(bootdevice, n);
397 }
398 #endif /* CONFIG_BLK_DEV_IDE && CONFIG_BLK_DEV_IDE_PMAC */
399
400 static void __init
401 find_boot_device(void)
402 {
403 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
404         boot_dev = find_ide_boot();
405 #endif
406 }
407
408 static int initializing = 1;
409 /* TODO: Merge the suspend-to-ram with the common code !!!
410  * currently, this is a stub implementation for suspend-to-disk
411  * only
412  */
413
414 #ifdef CONFIG_SOFTWARE_SUSPEND
415
416 static int pmac_pm_prepare(suspend_state_t state)
417 {
418         printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
419
420         return 0;
421 }
422
423 static int pmac_pm_enter(suspend_state_t state)
424 {
425         printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
426
427         /* Giveup the lazy FPU & vec so we don't have to back them
428          * up from the low level code
429          */
430         enable_kernel_fp();
431
432 #ifdef CONFIG_ALTIVEC
433         if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
434                 enable_kernel_altivec();
435 #endif /* CONFIG_ALTIVEC */
436
437         return 0;
438 }
439
440 static int pmac_pm_finish(suspend_state_t state)
441 {
442         printk(KERN_DEBUG "%s(%d)\n", __FUNCTION__, state);
443
444         /* Restore userland MMU context */
445         set_context(current->active_mm->context, current->active_mm->pgd);
446
447         return 0;
448 }
449
450 static struct pm_ops pmac_pm_ops = {
451         .pm_disk_mode   = PM_DISK_SHUTDOWN,
452         .prepare        = pmac_pm_prepare,
453         .enter          = pmac_pm_enter,
454         .finish         = pmac_pm_finish,
455 };
456
457 #endif /* CONFIG_SOFTWARE_SUSPEND */
458
459 static int pmac_late_init(void)
460 {
461         initializing = 0;
462 #ifdef CONFIG_SOFTWARE_SUSPEND
463         pm_set_ops(&pmac_pm_ops);
464 #endif /* CONFIG_SOFTWARE_SUSPEND */
465         return 0;
466 }
467
468 late_initcall(pmac_late_init);
469
470 /* can't be __init - can be called whenever a disk is first accessed */
471 void
472 note_bootable_part(dev_t dev, int part, int goodness)
473 {
474         static int found_boot = 0;
475         char *p;
476
477         if (!initializing)
478                 return;
479         if ((goodness <= current_root_goodness) &&
480             ROOT_DEV != DEFAULT_ROOT_DEVICE)
481                 return;
482         p = strstr(saved_command_line, "root=");
483         if (p != NULL && (p == saved_command_line || p[-1] == ' '))
484                 return;
485
486         if (!found_boot) {
487                 find_boot_device();
488                 found_boot = 1;
489         }
490         if (!boot_dev || dev == boot_dev) {
491                 ROOT_DEV = dev + part;
492                 boot_dev = 0;
493                 current_root_goodness = goodness;
494         }
495 }
496
497 static void
498 pmac_restart(char *cmd)
499 {
500 #ifdef CONFIG_ADB_CUDA
501         struct adb_request req;
502 #endif /* CONFIG_ADB_CUDA */
503
504         switch (sys_ctrler) {
505 #ifdef CONFIG_ADB_CUDA
506         case SYS_CTRLER_CUDA:
507                 cuda_request(&req, NULL, 2, CUDA_PACKET,
508                              CUDA_RESET_SYSTEM);
509                 for (;;)
510                         cuda_poll();
511                 break;
512 #endif /* CONFIG_ADB_CUDA */
513 #ifdef CONFIG_ADB_PMU
514         case SYS_CTRLER_PMU:
515                 pmu_restart();
516                 break;
517 #endif /* CONFIG_ADB_PMU */
518         default: ;
519         }
520 }
521
522 static void
523 pmac_power_off(void)
524 {
525 #ifdef CONFIG_ADB_CUDA
526         struct adb_request req;
527 #endif /* CONFIG_ADB_CUDA */
528
529         switch (sys_ctrler) {
530 #ifdef CONFIG_ADB_CUDA
531         case SYS_CTRLER_CUDA:
532                 cuda_request(&req, NULL, 2, CUDA_PACKET,
533                              CUDA_POWERDOWN);
534                 for (;;)
535                         cuda_poll();
536                 break;
537 #endif /* CONFIG_ADB_CUDA */
538 #ifdef CONFIG_ADB_PMU
539         case SYS_CTRLER_PMU:
540                 pmu_shutdown();
541                 break;
542 #endif /* CONFIG_ADB_PMU */
543         default: ;
544         }
545 }
546
547 static void
548 pmac_halt(void)
549 {
550         pmac_power_off();
551 }
552
553 void __init pmac_init(void)
554 {
555         /* isa_io_base gets set in pmac_find_bridges */
556         isa_mem_base = PMAC_ISA_MEM_BASE;
557         pci_dram_offset = PMAC_PCI_DRAM_OFFSET;
558         ISA_DMA_THRESHOLD = ~0L;
559         DMA_MODE_READ = 1;
560         DMA_MODE_WRITE = 2;
561
562         ppc_md.setup_arch     = pmac_setup_arch;
563         ppc_md.show_cpuinfo   = pmac_show_cpuinfo;
564         ppc_md.show_percpuinfo = pmac_show_percpuinfo;
565         ppc_md.irq_canonicalize = NULL;
566         ppc_md.init_IRQ       = pmac_pic_init;
567         ppc_md.get_irq        = pmac_get_irq; /* Changed later on ... */
568
569         ppc_md.pcibios_fixup  = pmac_pcibios_fixup;
570         ppc_md.pcibios_enable_device_hook = pmac_pci_enable_device_hook;
571         ppc_md.pcibios_after_init = pmac_pcibios_after_init;
572         ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
573
574         ppc_md.restart        = pmac_restart;
575         ppc_md.power_off      = pmac_power_off;
576         ppc_md.halt           = pmac_halt;
577
578         ppc_md.time_init      = pmac_time_init;
579         ppc_md.set_rtc_time   = pmac_set_rtc_time;
580         ppc_md.get_rtc_time   = pmac_get_rtc_time;
581         ppc_md.calibrate_decr = pmac_calibrate_decr;
582
583         ppc_md.feature_call   = pmac_do_feature_call;
584
585 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
586 #ifdef CONFIG_BLK_DEV_IDE_PMAC
587         ppc_ide_md.ide_init_hwif        = pmac_ide_init_hwif_ports;
588         ppc_ide_md.default_io_base      = pmac_ide_get_base;
589 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
590 #endif /* defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE) */
591
592 #ifdef CONFIG_BOOTX_TEXT
593         ppc_md.progress = pmac_progress;
594 #endif /* CONFIG_BOOTX_TEXT */
595
596         if (ppc_md.progress) ppc_md.progress("pmac_init(): exit", 0);
597
598 }
599
600 #ifdef CONFIG_BOOTX_TEXT
601 static void __init
602 pmac_progress(char *s, unsigned short hex)
603 {
604         if (boot_text_mapped) {
605                 btext_drawstring(s);
606                 btext_drawchar('\n');
607         }
608 }
609 #endif /* CONFIG_BOOTX_TEXT */
610
611 static int __init
612 pmac_declare_of_platform_devices(void)
613 {
614         struct device_node *np;
615
616         np = find_devices("uni-n");
617         if (np) {
618                 for (np = np->child; np != NULL; np = np->sibling)
619                         if (strncmp(np->name, "i2c", 3) == 0) {
620                                 of_platform_device_create(np, "uni-n-i2c",
621                                                           NULL);
622                                 break;
623                         }
624         }
625         np = find_devices("u3");
626         if (np) {
627                 for (np = np->child; np != NULL; np = np->sibling)
628                         if (strncmp(np->name, "i2c", 3) == 0) {
629                                 of_platform_device_create(np, "u3-i2c",
630                                                           NULL);
631                                 break;
632                         }
633         }
634
635         np = find_devices("valkyrie");
636         if (np)
637                 of_platform_device_create(np, "valkyrie", NULL);
638         np = find_devices("platinum");
639         if (np)
640                 of_platform_device_create(np, "platinum", NULL);
641
642         return 0;
643 }
644
645 device_initcall(pmac_declare_of_platform_devices);