]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/powerpc/kernel/setup-common.c
[PATCH] powerpc: merge code values for identifying platforms
[linux-2.6-omap-h63xx.git] / arch / powerpc / kernel / setup-common.c
1 /*
2  * Common boot and setup code for both 32-bit and 64-bit.
3  * Extracted from arch/powerpc/kernel/setup_64.c.
4  *
5  * Copyright (C) 2001 PPC64 Team, IBM Corp
6  *
7  *      This program is free software; you can redistribute it and/or
8  *      modify it under the terms of the GNU General Public License
9  *      as published by the Free Software Foundation; either version
10  *      2 of the License, or (at your option) any later version.
11  */
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/string.h>
15 #include <linux/sched.h>
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/reboot.h>
19 #include <linux/delay.h>
20 #include <linux/initrd.h>
21 #include <linux/ide.h>
22 #include <linux/seq_file.h>
23 #include <linux/ioport.h>
24 #include <linux/console.h>
25 #include <linux/utsname.h>
26 #include <linux/tty.h>
27 #include <linux/root_dev.h>
28 #include <linux/notifier.h>
29 #include <linux/cpu.h>
30 #include <linux/unistd.h>
31 #include <linux/serial.h>
32 #include <linux/serial_8250.h>
33 #include <asm/io.h>
34 #include <asm/prom.h>
35 #include <asm/processor.h>
36 #include <asm/systemcfg.h>
37 #include <asm/pgtable.h>
38 #include <asm/smp.h>
39 #include <asm/elf.h>
40 #include <asm/machdep.h>
41 #include <asm/time.h>
42 #include <asm/cputable.h>
43 #include <asm/sections.h>
44 #include <asm/btext.h>
45 #include <asm/nvram.h>
46 #include <asm/setup.h>
47 #include <asm/system.h>
48 #include <asm/rtas.h>
49 #include <asm/iommu.h>
50 #include <asm/serial.h>
51 #include <asm/cache.h>
52 #include <asm/page.h>
53 #include <asm/mmu.h>
54 #include <asm/lmb.h>
55 #include <asm/xmon.h>
56
57 #include "setup.h"
58
59 #undef DEBUG
60
61 #ifdef DEBUG
62 #define DBG(fmt...) udbg_printf(fmt)
63 #else
64 #define DBG(fmt...)
65 #endif
66
67 #ifdef CONFIG_PPC_MULTIPLATFORM
68 int _machine = 0;
69 EXPORT_SYMBOL(_machine);
70 #endif
71
72 /*
73  * This still seems to be needed... -- paulus
74  */ 
75 struct screen_info screen_info = {
76         .orig_x = 0,
77         .orig_y = 25,
78         .orig_video_cols = 80,
79         .orig_video_lines = 25,
80         .orig_video_isVGA = 1,
81         .orig_video_points = 16
82 };
83
84 #ifdef __DO_IRQ_CANON
85 /* XXX should go elsewhere eventually */
86 int ppc_do_canonicalize_irqs;
87 EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
88 #endif
89
90 /* also used by kexec */
91 void machine_shutdown(void)
92 {
93         if (ppc_md.nvram_sync)
94                 ppc_md.nvram_sync();
95 }
96
97 void machine_restart(char *cmd)
98 {
99         machine_shutdown();
100         ppc_md.restart(cmd);
101 #ifdef CONFIG_SMP
102         smp_send_stop();
103 #endif
104         printk(KERN_EMERG "System Halted, OK to turn off power\n");
105         local_irq_disable();
106         while (1) ;
107 }
108
109 void machine_power_off(void)
110 {
111         machine_shutdown();
112         ppc_md.power_off();
113 #ifdef CONFIG_SMP
114         smp_send_stop();
115 #endif
116         printk(KERN_EMERG "System Halted, OK to turn off power\n");
117         local_irq_disable();
118         while (1) ;
119 }
120 /* Used by the G5 thermal driver */
121 EXPORT_SYMBOL_GPL(machine_power_off);
122
123 void (*pm_power_off)(void) = machine_power_off;
124 EXPORT_SYMBOL_GPL(pm_power_off);
125
126 void machine_halt(void)
127 {
128         machine_shutdown();
129         ppc_md.halt();
130 #ifdef CONFIG_SMP
131         smp_send_stop();
132 #endif
133         printk(KERN_EMERG "System Halted, OK to turn off power\n");
134         local_irq_disable();
135         while (1) ;
136 }
137
138
139 #ifdef CONFIG_TAU
140 extern u32 cpu_temp(unsigned long cpu);
141 extern u32 cpu_temp_both(unsigned long cpu);
142 #endif /* CONFIG_TAU */
143
144 #ifdef CONFIG_SMP
145 DEFINE_PER_CPU(unsigned int, pvr);
146 #endif
147
148 static int show_cpuinfo(struct seq_file *m, void *v)
149 {
150         unsigned long cpu_id = (unsigned long)v - 1;
151         unsigned int pvr;
152         unsigned short maj;
153         unsigned short min;
154
155         if (cpu_id == NR_CPUS) {
156 #if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
157                 unsigned long bogosum = 0;
158                 int i;
159                 for (i = 0; i < NR_CPUS; ++i)
160                         if (cpu_online(i))
161                                 bogosum += loops_per_jiffy;
162                 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
163                            bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
164 #endif /* CONFIG_SMP && CONFIG_PPC32 */
165                 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
166
167                 if (ppc_md.show_cpuinfo != NULL)
168                         ppc_md.show_cpuinfo(m);
169
170                 return 0;
171         }
172
173         /* We only show online cpus: disable preempt (overzealous, I
174          * knew) to prevent cpu going down. */
175         preempt_disable();
176         if (!cpu_online(cpu_id)) {
177                 preempt_enable();
178                 return 0;
179         }
180
181 #ifdef CONFIG_SMP
182         pvr = per_cpu(pvr, cpu_id);
183 #else
184         pvr = mfspr(SPRN_PVR);
185 #endif
186         maj = (pvr >> 8) & 0xFF;
187         min = pvr & 0xFF;
188
189         seq_printf(m, "processor\t: %lu\n", cpu_id);
190         seq_printf(m, "cpu\t\t: ");
191
192         if (cur_cpu_spec->pvr_mask)
193                 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
194         else
195                 seq_printf(m, "unknown (%08x)", pvr);
196
197 #ifdef CONFIG_ALTIVEC
198         if (cpu_has_feature(CPU_FTR_ALTIVEC))
199                 seq_printf(m, ", altivec supported");
200 #endif /* CONFIG_ALTIVEC */
201
202         seq_printf(m, "\n");
203
204 #ifdef CONFIG_TAU
205         if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
206 #ifdef CONFIG_TAU_AVERAGE
207                 /* more straightforward, but potentially misleading */
208                 seq_printf(m,  "temperature \t: %u C (uncalibrated)\n",
209                            cpu_temp(cpu_id));
210 #else
211                 /* show the actual temp sensor range */
212                 u32 temp;
213                 temp = cpu_temp_both(cpu_id);
214                 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
215                            temp & 0xff, temp >> 16);
216 #endif
217         }
218 #endif /* CONFIG_TAU */
219
220         /*
221          * Assume here that all clock rates are the same in a
222          * smp system.  -- Cort
223          */
224         if (ppc_proc_freq)
225                 seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
226                            ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
227
228         if (ppc_md.show_percpuinfo != NULL)
229                 ppc_md.show_percpuinfo(m, cpu_id);
230
231         /* If we are a Freescale core do a simple check so
232          * we dont have to keep adding cases in the future */
233         if (PVR_VER(pvr) & 0x8000) {
234                 maj = PVR_MAJ(pvr);
235                 min = PVR_MIN(pvr);
236         } else {
237                 switch (PVR_VER(pvr)) {
238                         case 0x0020:    /* 403 family */
239                                 maj = PVR_MAJ(pvr) + 1;
240                                 min = PVR_MIN(pvr);
241                                 break;
242                         case 0x1008:    /* 740P/750P ?? */
243                                 maj = ((pvr >> 8) & 0xFF) - 1;
244                                 min = pvr & 0xFF;
245                                 break;
246                         default:
247                                 maj = (pvr >> 8) & 0xFF;
248                                 min = pvr & 0xFF;
249                                 break;
250                 }
251         }
252
253         seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
254                    maj, min, PVR_VER(pvr), PVR_REV(pvr));
255
256 #ifdef CONFIG_PPC32
257         seq_printf(m, "bogomips\t: %lu.%02lu\n",
258                    loops_per_jiffy / (500000/HZ),
259                    (loops_per_jiffy / (5000/HZ)) % 100);
260 #endif
261
262 #ifdef CONFIG_SMP
263         seq_printf(m, "\n");
264 #endif
265
266         preempt_enable();
267         return 0;
268 }
269
270 static void *c_start(struct seq_file *m, loff_t *pos)
271 {
272         unsigned long i = *pos;
273
274         return i <= NR_CPUS ? (void *)(i + 1) : NULL;
275 }
276
277 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
278 {
279         ++*pos;
280         return c_start(m, pos);
281 }
282
283 static void c_stop(struct seq_file *m, void *v)
284 {
285 }
286
287 struct seq_operations cpuinfo_op = {
288         .start =c_start,
289         .next = c_next,
290         .stop = c_stop,
291         .show = show_cpuinfo,
292 };
293
294 #ifdef CONFIG_PPC_MULTIPLATFORM
295 static int __init set_preferred_console(void)
296 {
297         struct device_node *prom_stdout = NULL;
298         char *name;
299         u32 *spd;
300         int offset = 0;
301
302         DBG(" -> set_preferred_console()\n");
303
304         /* The user has requested a console so this is already set up. */
305         if (strstr(saved_command_line, "console=")) {
306                 DBG(" console was specified !\n");
307                 return -EBUSY;
308         }
309
310         if (!of_chosen) {
311                 DBG(" of_chosen is NULL !\n");
312                 return -ENODEV;
313         }
314         /* We are getting a weird phandle from OF ... */
315         /* ... So use the full path instead */
316         name = (char *)get_property(of_chosen, "linux,stdout-path", NULL);
317         if (name == NULL) {
318                 DBG(" no linux,stdout-path !\n");
319                 return -ENODEV;
320         }
321         prom_stdout = of_find_node_by_path(name);
322         if (!prom_stdout) {
323                 DBG(" can't find stdout package %s !\n", name);
324                 return -ENODEV;
325         }       
326         DBG("stdout is %s\n", prom_stdout->full_name);
327
328         name = (char *)get_property(prom_stdout, "name", NULL);
329         if (!name) {
330                 DBG(" stdout package has no name !\n");
331                 goto not_found;
332         }
333         spd = (u32 *)get_property(prom_stdout, "current-speed", NULL);
334
335         if (0)
336                 ;
337 #ifdef CONFIG_SERIAL_8250_CONSOLE
338         else if (strcmp(name, "serial") == 0) {
339                 int i;
340                 u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i);
341                 if (i > 8) {
342                         switch (reg[1]) {
343                                 case 0x3f8:
344                                         offset = 0;
345                                         break;
346                                 case 0x2f8:
347                                         offset = 1;
348                                         break;
349                                 case 0x898:
350                                         offset = 2;
351                                         break;
352                                 case 0x890:
353                                         offset = 3;
354                                         break;
355                                 default:
356                                         /* We dont recognise the serial port */
357                                         goto not_found;
358                         }
359                 }
360         }
361 #endif /* CONFIG_SERIAL_8250_CONSOLE */
362 #ifdef CONFIG_PPC_PSERIES
363         else if (strcmp(name, "vty") == 0) {
364                 u32 *reg = (u32 *)get_property(prom_stdout, "reg", NULL);
365                 char *compat = (char *)get_property(prom_stdout, "compatible", NULL);
366
367                 if (reg && compat && (strcmp(compat, "hvterm-protocol") == 0)) {
368                         /* Host Virtual Serial Interface */
369                         switch (reg[0]) {
370                                 case 0x30000000:
371                                         offset = 0;
372                                         break;
373                                 case 0x30000001:
374                                         offset = 1;
375                                         break;
376                                 default:
377                                         goto not_found;
378                         }
379                         of_node_put(prom_stdout);
380                         DBG("Found hvsi console at offset %d\n", offset);
381                         return add_preferred_console("hvsi", offset, NULL);
382                 } else {
383                         /* pSeries LPAR virtual console */
384                         of_node_put(prom_stdout);
385                         DBG("Found hvc console\n");
386                         return add_preferred_console("hvc", 0, NULL);
387                 }
388         }
389 #endif /* CONFIG_PPC_PSERIES */
390 #ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
391         else if (strcmp(name, "ch-a") == 0)
392                 offset = 0;
393         else if (strcmp(name, "ch-b") == 0)
394                 offset = 1;
395 #endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */
396         else
397                 goto not_found;
398         of_node_put(prom_stdout);
399
400         DBG("Found serial console at ttyS%d\n", offset);
401
402         if (spd) {
403                 static char __initdata opt[16];
404                 sprintf(opt, "%d", *spd);
405                 return add_preferred_console("ttyS", offset, opt);
406         } else
407                 return add_preferred_console("ttyS", offset, NULL);
408
409  not_found:
410         DBG("No preferred console found !\n");
411         of_node_put(prom_stdout);
412         return -ENODEV;
413 }
414 console_initcall(set_preferred_console);
415 #endif /* CONFIG_PPC_MULTIPLATFORM */
416
417 void __init check_for_initrd(void)
418 {
419 #ifdef CONFIG_BLK_DEV_INITRD
420         unsigned long *prop;
421
422         DBG(" -> check_for_initrd()\n");
423
424         if (of_chosen) {
425                 prop = (unsigned long *)get_property(of_chosen,
426                                 "linux,initrd-start", NULL);
427                 if (prop != NULL) {
428                         initrd_start = (unsigned long)__va(*prop);
429                         prop = (unsigned long *)get_property(of_chosen,
430                                         "linux,initrd-end", NULL);
431                         if (prop != NULL) {
432                                 initrd_end = (unsigned long)__va(*prop);
433                                 initrd_below_start_ok = 1;
434                         } else
435                                 initrd_start = 0;
436                 }
437         }
438
439         /* If we were passed an initrd, set the ROOT_DEV properly if the values
440          * look sensible. If not, clear initrd reference.
441          */
442         if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
443             initrd_end > initrd_start)
444                 ROOT_DEV = Root_RAM0;
445         else {
446                 printk("Bogus initrd %08lx %08lx\n", initrd_start, initrd_end);
447                 initrd_start = initrd_end = 0;
448         }
449
450         if (initrd_start)
451                 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
452
453         DBG(" <- check_for_initrd()\n");
454 #endif /* CONFIG_BLK_DEV_INITRD */
455 }
456
457 #ifdef CONFIG_SMP
458
459 /**
460  * setup_cpu_maps - initialize the following cpu maps:
461  *                  cpu_possible_map
462  *                  cpu_present_map
463  *                  cpu_sibling_map
464  *
465  * Having the possible map set up early allows us to restrict allocations
466  * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
467  *
468  * We do not initialize the online map here; cpus set their own bits in
469  * cpu_online_map as they come up.
470  *
471  * This function is valid only for Open Firmware systems.  finish_device_tree
472  * must be called before using this.
473  *
474  * While we're here, we may as well set the "physical" cpu ids in the paca.
475  */
476 void __init smp_setup_cpu_maps(void)
477 {
478         struct device_node *dn = NULL;
479         int cpu = 0;
480         int swap_cpuid = 0;
481
482         while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
483                 int *intserv;
484                 int j, len = sizeof(u32), nthreads = 1;
485
486                 intserv = (int *)get_property(dn, "ibm,ppc-interrupt-server#s",
487                                               &len);
488                 if (intserv)
489                         nthreads = len / sizeof(int);
490                 else {
491                         intserv = (int *) get_property(dn, "reg", NULL);
492                         if (!intserv)
493                                 intserv = &cpu; /* assume logical == phys */
494                 }
495
496                 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
497                         cpu_set(cpu, cpu_present_map);
498                         set_hard_smp_processor_id(cpu, intserv[j]);
499
500                         if (intserv[j] == boot_cpuid_phys)
501                                 swap_cpuid = cpu;
502                         cpu_set(cpu, cpu_possible_map);
503                         cpu++;
504                 }
505         }
506
507         /* Swap CPU id 0 with boot_cpuid_phys, so we can always assume that
508          * boot cpu is logical 0.
509          */
510         if (boot_cpuid_phys != get_hard_smp_processor_id(0)) {
511                 u32 tmp;
512                 tmp = get_hard_smp_processor_id(0);
513                 set_hard_smp_processor_id(0, boot_cpuid_phys);
514                 set_hard_smp_processor_id(swap_cpuid, tmp);
515         }
516
517 #ifdef CONFIG_PPC64
518         /*
519          * On pSeries LPAR, we need to know how many cpus
520          * could possibly be added to this partition.
521          */
522         if (_machine == PLATFORM_PSERIES_LPAR &&
523             (dn = of_find_node_by_path("/rtas"))) {
524                 int num_addr_cell, num_size_cell, maxcpus;
525                 unsigned int *ireg;
526
527                 num_addr_cell = prom_n_addr_cells(dn);
528                 num_size_cell = prom_n_size_cells(dn);
529
530                 ireg = (unsigned int *)
531                         get_property(dn, "ibm,lrdr-capacity", NULL);
532
533                 if (!ireg)
534                         goto out;
535
536                 maxcpus = ireg[num_addr_cell + num_size_cell];
537
538                 /* Double maxcpus for processors which have SMT capability */
539                 if (cpu_has_feature(CPU_FTR_SMT))
540                         maxcpus *= 2;
541
542                 if (maxcpus > NR_CPUS) {
543                         printk(KERN_WARNING
544                                "Partition configured for %d cpus, "
545                                "operating system maximum is %d.\n",
546                                maxcpus, NR_CPUS);
547                         maxcpus = NR_CPUS;
548                 } else
549                         printk(KERN_INFO "Partition configured for %d cpus.\n",
550                                maxcpus);
551
552                 for (cpu = 0; cpu < maxcpus; cpu++)
553                         cpu_set(cpu, cpu_possible_map);
554         out:
555                 of_node_put(dn);
556         }
557
558         /*
559          * Do the sibling map; assume only two threads per processor.
560          */
561         for_each_cpu(cpu) {
562                 cpu_set(cpu, cpu_sibling_map[cpu]);
563                 if (cpu_has_feature(CPU_FTR_SMT))
564                         cpu_set(cpu ^ 0x1, cpu_sibling_map[cpu]);
565         }
566
567         _systemcfg->processorCount = num_present_cpus();
568 #endif /* CONFIG_PPC64 */
569 }
570 #endif /* CONFIG_SMP */
571
572 #ifdef CONFIG_XMON
573 static int __init early_xmon(char *p)
574 {
575         /* ensure xmon is enabled */
576         if (p) {
577                 if (strncmp(p, "on", 2) == 0)
578                         xmon_init(1);
579                 if (strncmp(p, "off", 3) == 0)
580                         xmon_init(0);
581                 if (strncmp(p, "early", 5) != 0)
582                         return 0;
583         }
584         xmon_init(1);
585         debugger(NULL);
586
587         return 0;
588 }
589 early_param("xmon", early_xmon);
590 #endif