blob: 8b6ada66060b5ae87c7daae74c5833b8b3e90648 [file] [log] [blame]
Paul Mackerras03501da2005-10-26 17:11:18 +10001/*
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 */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110012
13#undef DEBUG
14
Paul Mackerras03501da2005-10-26 17:11:18 +100015#include <linux/module.h>
16#include <linux/string.h>
17#include <linux/sched.h>
18#include <linux/init.h>
19#include <linux/kernel.h>
20#include <linux/reboot.h>
21#include <linux/delay.h>
22#include <linux/initrd.h>
Michael Neulinge5c6c8e2006-03-14 00:11:50 -050023#include <linux/platform_device.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100024#include <linux/seq_file.h>
25#include <linux/ioport.h>
26#include <linux/console.h>
Jon Smirl894673e2006-07-10 04:44:13 -070027#include <linux/screen_info.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100028#include <linux/root_dev.h>
29#include <linux/notifier.h>
30#include <linux/cpu.h>
31#include <linux/unistd.h>
32#include <linux/serial.h>
33#include <linux/serial_8250.h>
Michael Ellerman94a38072007-06-20 10:54:19 +100034#include <linux/debugfs.h>
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +100035#include <linux/percpu.h>
David S. Millerd9b2b2a2008-02-13 16:56:49 -080036#include <linux/lmb.h>
Kumar Galad7462862009-03-19 03:40:51 +000037#include <linux/of_platform.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100038#include <asm/io.h>
Michael Ellerman1426d5a2010-01-28 13:23:22 +000039#include <asm/paca.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100040#include <asm/prom.h>
41#include <asm/processor.h>
Benjamin Herrenschmidta7f290d2005-11-11 21:15:21 +110042#include <asm/vdso_datapage.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100043#include <asm/pgtable.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100044#include <asm/smp.h>
45#include <asm/elf.h>
46#include <asm/machdep.h>
47#include <asm/time.h>
48#include <asm/cputable.h>
49#include <asm/sections.h>
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110050#include <asm/firmware.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100051#include <asm/btext.h>
52#include <asm/nvram.h>
53#include <asm/setup.h>
54#include <asm/system.h>
55#include <asm/rtas.h>
56#include <asm/iommu.h>
57#include <asm/serial.h>
58#include <asm/cache.h>
59#include <asm/page.h>
60#include <asm/mmu.h>
Paul Mackerrasfca5dcd2005-11-08 22:55:08 +110061#include <asm/xmon.h>
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +100062#include <asm/cputhreads.h>
Becky Brucef465df82008-10-15 08:25:28 +000063#include <mm/mmu_decl.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100064
Stephen Rothwell66ba1352005-11-09 11:01:06 +110065#include "setup.h"
66
Paul Mackerras03501da2005-10-26 17:11:18 +100067#ifdef DEBUG
Michael Ellermanf9e4ec52005-11-15 15:16:38 +110068#include <asm/udbg.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100069#define DBG(fmt...) udbg_printf(fmt)
70#else
71#define DBG(fmt...)
72#endif
73
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110074/* The main machine-dep calls structure
75 */
76struct machdep_calls ppc_md;
77EXPORT_SYMBOL(ppc_md);
78struct machdep_calls *machine_id;
79EXPORT_SYMBOL(machine_id);
Paul Mackerras799d6042005-11-10 13:37:51 +110080
Paul Mackerras49b09852005-11-10 15:53:40 +110081unsigned long klimit = (unsigned long) _end;
82
Stephen Rothwell19a8d972007-09-17 14:41:38 +100083char cmd_line[COMMAND_LINE_SIZE];
84
Paul Mackerras03501da2005-10-26 17:11:18 +100085/*
86 * This still seems to be needed... -- paulus
87 */
88struct screen_info screen_info = {
89 .orig_x = 0,
90 .orig_y = 25,
91 .orig_video_cols = 80,
92 .orig_video_lines = 25,
93 .orig_video_isVGA = 1,
94 .orig_video_points = 16
95};
96
Martyn Welch540c6c32010-05-24 22:09:16 +000097/* Variables required to store legacy IO irq routing */
98int of_i8042_kbd_irq;
99int of_i8042_aux_irq;
100
Paul Mackerras03501da2005-10-26 17:11:18 +1000101#ifdef __DO_IRQ_CANON
102/* XXX should go elsewhere eventually */
103int ppc_do_canonicalize_irqs;
104EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
105#endif
106
107/* also used by kexec */
108void machine_shutdown(void)
109{
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100110 if (ppc_md.machine_shutdown)
111 ppc_md.machine_shutdown();
Paul Mackerras03501da2005-10-26 17:11:18 +1000112}
113
114void machine_restart(char *cmd)
115{
116 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600117 if (ppc_md.restart)
118 ppc_md.restart(cmd);
Paul Mackerras03501da2005-10-26 17:11:18 +1000119#ifdef CONFIG_SMP
120 smp_send_stop();
121#endif
122 printk(KERN_EMERG "System Halted, OK to turn off power\n");
123 local_irq_disable();
124 while (1) ;
125}
126
127void machine_power_off(void)
128{
129 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600130 if (ppc_md.power_off)
131 ppc_md.power_off();
Paul Mackerras03501da2005-10-26 17:11:18 +1000132#ifdef CONFIG_SMP
133 smp_send_stop();
134#endif
135 printk(KERN_EMERG "System Halted, OK to turn off power\n");
136 local_irq_disable();
137 while (1) ;
138}
139/* Used by the G5 thermal driver */
140EXPORT_SYMBOL_GPL(machine_power_off);
141
142void (*pm_power_off)(void) = machine_power_off;
143EXPORT_SYMBOL_GPL(pm_power_off);
144
145void machine_halt(void)
146{
147 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600148 if (ppc_md.halt)
149 ppc_md.halt();
Paul Mackerras03501da2005-10-26 17:11:18 +1000150#ifdef CONFIG_SMP
151 smp_send_stop();
152#endif
153 printk(KERN_EMERG "System Halted, OK to turn off power\n");
154 local_irq_disable();
155 while (1) ;
156}
157
158
159#ifdef CONFIG_TAU
160extern u32 cpu_temp(unsigned long cpu);
161extern u32 cpu_temp_both(unsigned long cpu);
162#endif /* CONFIG_TAU */
163
164#ifdef CONFIG_SMP
Tejun Heo6b7487f2009-10-29 22:34:14 +0900165DEFINE_PER_CPU(unsigned int, cpu_pvr);
Paul Mackerras03501da2005-10-26 17:11:18 +1000166#endif
167
Anton Blanchard2c2df032010-04-26 15:32:39 +0000168static void show_cpuinfo_summary(struct seq_file *m)
169{
170 struct device_node *root;
171 const char *model = NULL;
172#if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
173 unsigned long bogosum = 0;
174 int i;
175 for_each_online_cpu(i)
176 bogosum += loops_per_jiffy;
177 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
178 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
179#endif /* CONFIG_SMP && CONFIG_PPC32 */
180 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
181 if (ppc_md.name)
182 seq_printf(m, "platform\t: %s\n", ppc_md.name);
183 root = of_find_node_by_path("/");
184 if (root)
185 model = of_get_property(root, "model", NULL);
186 if (model)
187 seq_printf(m, "model\t\t: %s\n", model);
188 of_node_put(root);
189
190 if (ppc_md.show_cpuinfo != NULL)
191 ppc_md.show_cpuinfo(m);
192
193#ifdef CONFIG_PPC32
194 /* Display the amount of memory */
195 seq_printf(m, "Memory\t\t: %d MB\n",
196 (unsigned int)(total_memory / (1024 * 1024)));
197#endif
198}
199
Paul Mackerras03501da2005-10-26 17:11:18 +1000200static int show_cpuinfo(struct seq_file *m, void *v)
201{
202 unsigned long cpu_id = (unsigned long)v - 1;
203 unsigned int pvr;
204 unsigned short maj;
205 unsigned short min;
206
Paul Mackerras03501da2005-10-26 17:11:18 +1000207 /* We only show online cpus: disable preempt (overzealous, I
208 * knew) to prevent cpu going down. */
209 preempt_disable();
210 if (!cpu_online(cpu_id)) {
211 preempt_enable();
212 return 0;
213 }
214
215#ifdef CONFIG_SMP
Tejun Heo6b7487f2009-10-29 22:34:14 +0900216 pvr = per_cpu(cpu_pvr, cpu_id);
Paul Mackerras03501da2005-10-26 17:11:18 +1000217#else
Paul Mackerras03501da2005-10-26 17:11:18 +1000218 pvr = mfspr(SPRN_PVR);
219#endif
220 maj = (pvr >> 8) & 0xFF;
221 min = pvr & 0xFF;
222
223 seq_printf(m, "processor\t: %lu\n", cpu_id);
224 seq_printf(m, "cpu\t\t: ");
225
226 if (cur_cpu_spec->pvr_mask)
227 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
228 else
229 seq_printf(m, "unknown (%08x)", pvr);
230
231#ifdef CONFIG_ALTIVEC
232 if (cpu_has_feature(CPU_FTR_ALTIVEC))
233 seq_printf(m, ", altivec supported");
234#endif /* CONFIG_ALTIVEC */
235
236 seq_printf(m, "\n");
237
238#ifdef CONFIG_TAU
239 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
240#ifdef CONFIG_TAU_AVERAGE
241 /* more straightforward, but potentially misleading */
242 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
Paul Mackerrasbccfd582005-11-02 15:06:22 +1100243 cpu_temp(cpu_id));
Paul Mackerras03501da2005-10-26 17:11:18 +1000244#else
245 /* show the actual temp sensor range */
246 u32 temp;
Paul Mackerrasbccfd582005-11-02 15:06:22 +1100247 temp = cpu_temp_both(cpu_id);
Paul Mackerras03501da2005-10-26 17:11:18 +1000248 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
249 temp & 0xff, temp >> 16);
250#endif
251 }
252#endif /* CONFIG_TAU */
253
254 /*
255 * Assume here that all clock rates are the same in a
256 * smp system. -- Cort
257 */
258 if (ppc_proc_freq)
259 seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
260 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
261
262 if (ppc_md.show_percpuinfo != NULL)
263 ppc_md.show_percpuinfo(m, cpu_id);
264
265 /* If we are a Freescale core do a simple check so
266 * we dont have to keep adding cases in the future */
267 if (PVR_VER(pvr) & 0x8000) {
Martin Langera501d8f2008-09-07 17:51:32 +1000268 switch (PVR_VER(pvr)) {
269 case 0x8000: /* 7441/7450/7451, Voyager */
270 case 0x8001: /* 7445/7455, Apollo 6 */
271 case 0x8002: /* 7447/7457, Apollo 7 */
272 case 0x8003: /* 7447A, Apollo 7 PM */
273 case 0x8004: /* 7448, Apollo 8 */
274 case 0x800c: /* 7410, Nitro */
275 maj = ((pvr >> 8) & 0xF);
276 min = PVR_MIN(pvr);
277 break;
278 default: /* e500/book-e */
279 maj = PVR_MAJ(pvr);
280 min = PVR_MIN(pvr);
281 break;
282 }
Paul Mackerras03501da2005-10-26 17:11:18 +1000283 } else {
284 switch (PVR_VER(pvr)) {
285 case 0x0020: /* 403 family */
286 maj = PVR_MAJ(pvr) + 1;
287 min = PVR_MIN(pvr);
288 break;
289 case 0x1008: /* 740P/750P ?? */
290 maj = ((pvr >> 8) & 0xFF) - 1;
291 min = pvr & 0xFF;
292 break;
293 default:
294 maj = (pvr >> 8) & 0xFF;
295 min = pvr & 0xFF;
296 break;
297 }
298 }
299
300 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
301 maj, min, PVR_VER(pvr), PVR_REV(pvr));
302
303#ifdef CONFIG_PPC32
304 seq_printf(m, "bogomips\t: %lu.%02lu\n",
305 loops_per_jiffy / (500000/HZ),
306 (loops_per_jiffy / (5000/HZ)) % 100);
307#endif
308
309#ifdef CONFIG_SMP
310 seq_printf(m, "\n");
311#endif
312
313 preempt_enable();
Anton Blancharde6532c62010-04-26 15:32:40 +0000314
315 /* If this is the last cpu, print the summary */
316 if (cpumask_next(cpu_id, cpu_online_mask) >= nr_cpu_ids)
317 show_cpuinfo_summary(m);
318
Paul Mackerras03501da2005-10-26 17:11:18 +1000319 return 0;
320}
321
322static void *c_start(struct seq_file *m, loff_t *pos)
323{
Anton Blancharde6532c62010-04-26 15:32:40 +0000324 if (*pos == 0) /* just in case, cpu 0 is not the first */
325 *pos = cpumask_first(cpu_online_mask);
326 else
327 *pos = cpumask_next(*pos - 1, cpu_online_mask);
328 if ((*pos) < nr_cpu_ids)
329 return (void *)(unsigned long)(*pos + 1);
330 return NULL;
Paul Mackerras03501da2005-10-26 17:11:18 +1000331}
332
333static void *c_next(struct seq_file *m, void *v, loff_t *pos)
334{
Anton Blancharde6532c62010-04-26 15:32:40 +0000335 (*pos)++;
Paul Mackerras03501da2005-10-26 17:11:18 +1000336 return c_start(m, pos);
337}
338
339static void c_stop(struct seq_file *m, void *v)
340{
341}
342
James Morris88e9d342009-09-22 16:43:43 -0700343const struct seq_operations cpuinfo_op = {
Paul Mackerras03501da2005-10-26 17:11:18 +1000344 .start =c_start,
345 .next = c_next,
346 .stop = c_stop,
347 .show = show_cpuinfo,
348};
349
David Woodhousea82765b2005-11-02 22:34:20 +0000350void __init check_for_initrd(void)
351{
352#ifdef CONFIG_BLK_DEV_INITRD
David Gibson30437b32007-02-28 14:12:29 +1100353 DBG(" -> check_for_initrd() initrd_start=0x%lx initrd_end=0x%lx\n",
354 initrd_start, initrd_end);
David Woodhousea82765b2005-11-02 22:34:20 +0000355
356 /* If we were passed an initrd, set the ROOT_DEV properly if the values
357 * look sensible. If not, clear initrd reference.
358 */
Michael Ellerman51fae6d2005-12-04 18:39:15 +1100359 if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) &&
David Woodhousea82765b2005-11-02 22:34:20 +0000360 initrd_end > initrd_start)
361 ROOT_DEV = Root_RAM0;
David Woodhouse6761c4a2005-11-11 08:07:11 +0000362 else
David Woodhousea82765b2005-11-02 22:34:20 +0000363 initrd_start = initrd_end = 0;
David Woodhousea82765b2005-11-02 22:34:20 +0000364
365 if (initrd_start)
366 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
367
368 DBG(" <- check_for_initrd()\n");
369#endif /* CONFIG_BLK_DEV_INITRD */
370}
371
Paul Mackerras5ad57072005-11-05 10:33:55 +1100372#ifdef CONFIG_SMP
373
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000374int threads_per_core, threads_shift;
375cpumask_t threads_core_mask;
376
377static void __init cpu_init_thread_core_maps(int tpc)
378{
379 int i;
380
381 threads_per_core = tpc;
382 threads_core_mask = CPU_MASK_NONE;
383
384 /* This implementation only supports power of 2 number of threads
385 * for simplicity and performance
386 */
387 threads_shift = ilog2(tpc);
388 BUG_ON(tpc != (1 << threads_shift));
389
390 for (i = 0; i < tpc; i++)
391 cpu_set(i, threads_core_mask);
392
393 printk(KERN_INFO "CPU maps initialized for %d thread%s per core\n",
394 tpc, tpc > 1 ? "s" : "");
395 printk(KERN_DEBUG " (thread shift is %d)\n", threads_shift);
396}
397
398
Paul Mackerras5ad57072005-11-05 10:33:55 +1100399/**
400 * setup_cpu_maps - initialize the following cpu maps:
Anton Blanchard828a6982010-04-26 15:32:44 +0000401 * cpu_possible_mask
402 * cpu_present_mask
Paul Mackerras5ad57072005-11-05 10:33:55 +1100403 *
404 * Having the possible map set up early allows us to restrict allocations
405 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
406 *
407 * We do not initialize the online map here; cpus set their own bits in
Anton Blanchard828a6982010-04-26 15:32:44 +0000408 * cpu_online_mask as they come up.
Paul Mackerras5ad57072005-11-05 10:33:55 +1100409 *
410 * This function is valid only for Open Firmware systems. finish_device_tree
411 * must be called before using this.
412 *
413 * While we're here, we may as well set the "physical" cpu ids in the paca.
Anton Blanchard4df20462006-03-25 17:25:17 +1100414 *
415 * NOTE: This must match the parsing done in early_init_dt_scan_cpus.
Paul Mackerras5ad57072005-11-05 10:33:55 +1100416 */
417void __init smp_setup_cpu_maps(void)
418{
419 struct device_node *dn = NULL;
420 int cpu = 0;
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000421 int nthreads = 1;
422
423 DBG("smp_setup_cpu_maps()\n");
Paul Mackerras5ad57072005-11-05 10:33:55 +1100424
425 while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000426 const int *intserv;
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000427 int j, len;
428
429 DBG(" * %s...\n", dn->full_name);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100430
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000431 intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s",
432 &len);
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000433 if (intserv) {
Paul Mackerras5ad57072005-11-05 10:33:55 +1100434 nthreads = len / sizeof(int);
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000435 DBG(" ibm,ppc-interrupt-server#s -> %d threads\n",
436 nthreads);
437 } else {
438 DBG(" no ibm,ppc-interrupt-server#s -> 1 thread\n");
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000439 intserv = of_get_property(dn, "reg", NULL);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100440 if (!intserv)
441 intserv = &cpu; /* assume logical == phys */
442 }
443
444 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000445 DBG(" thread %d -> cpu %d (hard id %d)\n",
446 j, cpu, intserv[j]);
Rusty Russellea0f1ca2009-09-24 09:34:48 -0600447 set_cpu_present(cpu, true);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100448 set_hard_smp_processor_id(cpu, intserv[j]);
Rusty Russellea0f1ca2009-09-24 09:34:48 -0600449 set_cpu_possible(cpu, true);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100450 cpu++;
451 }
452 }
453
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000454 /* If no SMT supported, nthreads is forced to 1 */
455 if (!cpu_has_feature(CPU_FTR_SMT)) {
456 DBG(" SMT disabled ! nthreads forced to 1\n");
457 nthreads = 1;
458 }
459
Paul Mackerras5ad57072005-11-05 10:33:55 +1100460#ifdef CONFIG_PPC64
461 /*
462 * On pSeries LPAR, we need to know how many cpus
463 * could possibly be added to this partition.
464 */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100465 if (machine_is(pseries) && firmware_has_feature(FW_FEATURE_LPAR) &&
Paul Mackerras799d6042005-11-10 13:37:51 +1100466 (dn = of_find_node_by_path("/rtas"))) {
Paul Mackerras5ad57072005-11-05 10:33:55 +1100467 int num_addr_cell, num_size_cell, maxcpus;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000468 const unsigned int *ireg;
Paul Mackerras5ad57072005-11-05 10:33:55 +1100469
Stephen Rothwella8bda5d2007-04-03 10:56:50 +1000470 num_addr_cell = of_n_addr_cells(dn);
Stephen Rothwell9213fee2007-04-03 10:57:48 +1000471 num_size_cell = of_n_size_cells(dn);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100472
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000473 ireg = of_get_property(dn, "ibm,lrdr-capacity", NULL);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100474
475 if (!ireg)
476 goto out;
477
478 maxcpus = ireg[num_addr_cell + num_size_cell];
479
480 /* Double maxcpus for processors which have SMT capability */
481 if (cpu_has_feature(CPU_FTR_SMT))
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000482 maxcpus *= nthreads;
Paul Mackerras5ad57072005-11-05 10:33:55 +1100483
484 if (maxcpus > NR_CPUS) {
485 printk(KERN_WARNING
486 "Partition configured for %d cpus, "
487 "operating system maximum is %d.\n",
488 maxcpus, NR_CPUS);
489 maxcpus = NR_CPUS;
490 } else
491 printk(KERN_INFO "Partition configured for %d cpus.\n",
492 maxcpus);
493
494 for (cpu = 0; cpu < maxcpus; cpu++)
Rusty Russellea0f1ca2009-09-24 09:34:48 -0600495 set_cpu_possible(cpu, true);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100496 out:
497 of_node_put(dn);
498 }
Mike Travisd5a74302007-10-16 01:24:05 -0700499 vdso_data->processorCount = num_present_cpus();
500#endif /* CONFIG_PPC64 */
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000501
502 /* Initialize CPU <=> thread mapping/
503 *
504 * WARNING: We assume that the number of threads is the same for
505 * every CPU in the system. If that is not the case, then some code
506 * here will have to be reworked
507 */
508 cpu_init_thread_core_maps(nthreads);
Michael Ellerman1426d5a2010-01-28 13:23:22 +0000509
510 free_unused_pacas();
Mike Travisd5a74302007-10-16 01:24:05 -0700511}
Paul Mackerras5ad57072005-11-05 10:33:55 +1100512#endif /* CONFIG_SMP */
Paul Mackerrasfca5dcd2005-11-08 22:55:08 +1100513
Emil Medved33b78d2008-05-23 08:40:16 +1000514#ifdef CONFIG_PCSPKR_PLATFORM
Michael Neulinge5c6c8e2006-03-14 00:11:50 -0500515static __init int add_pcspkr(void)
516{
517 struct device_node *np;
518 struct platform_device *pd;
519 int ret;
520
521 np = of_find_compatible_node(NULL, NULL, "pnpPNP,100");
522 of_node_put(np);
523 if (!np)
524 return -ENODEV;
525
526 pd = platform_device_alloc("pcspkr", -1);
527 if (!pd)
528 return -ENOMEM;
529
530 ret = platform_device_add(pd);
531 if (ret)
532 platform_device_put(pd);
533
534 return ret;
535}
536device_initcall(add_pcspkr);
Emil Medved33b78d2008-05-23 08:40:16 +1000537#endif /* CONFIG_PCSPKR_PLATFORM */
Dmitry Torokhov95d465f2006-04-02 00:08:05 -0500538
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100539void probe_machine(void)
540{
541 extern struct machdep_calls __machine_desc_start;
542 extern struct machdep_calls __machine_desc_end;
543
544 /*
545 * Iterate all ppc_md structures until we find the proper
546 * one for the current machine type
547 */
548 DBG("Probing machine type ...\n");
549
550 for (machine_id = &__machine_desc_start;
551 machine_id < &__machine_desc_end;
552 machine_id++) {
553 DBG(" %s ...", machine_id->name);
554 memcpy(&ppc_md, machine_id, sizeof(struct machdep_calls));
555 if (ppc_md.probe()) {
556 DBG(" match !\n");
557 break;
558 }
559 DBG("\n");
560 }
561 /* What can we do if we didn't find ? */
562 if (machine_id >= &__machine_desc_end) {
563 DBG("No suitable machine found !\n");
564 for (;;);
565 }
566
567 printk(KERN_INFO "Using %s machine description\n", ppc_md.name);
568}
David Woodhouse12692772006-04-24 23:22:17 +0100569
Olaf Hering8d8a0242007-04-26 06:36:56 +1000570/* Match a class of boards, not a specific device configuration. */
David Woodhouse12692772006-04-24 23:22:17 +0100571int check_legacy_ioport(unsigned long base_port)
572{
Olaf Hering8d8a0242007-04-26 06:36:56 +1000573 struct device_node *parent, *np = NULL;
574 int ret = -ENODEV;
575
576 switch(base_port) {
577 case I8042_DATA_REG:
Wade Farnsworthdb0dbae2007-06-20 10:15:10 +1000578 if (!(np = of_find_compatible_node(NULL, NULL, "pnpPNP,303")))
579 np = of_find_compatible_node(NULL, NULL, "pnpPNP,f03");
580 if (np) {
581 parent = of_get_parent(np);
Martyn Welch540c6c32010-05-24 22:09:16 +0000582
583 of_i8042_kbd_irq = irq_of_parse_and_map(parent, 0);
584 if (!of_i8042_kbd_irq)
585 of_i8042_kbd_irq = 1;
586
587 of_i8042_aux_irq = irq_of_parse_and_map(parent, 1);
588 if (!of_i8042_aux_irq)
589 of_i8042_aux_irq = 12;
590
Wade Farnsworthdb0dbae2007-06-20 10:15:10 +1000591 of_node_put(np);
592 np = parent;
593 break;
594 }
Olaf Hering8d8a0242007-04-26 06:36:56 +1000595 np = of_find_node_by_type(NULL, "8042");
Alan Curryf5d834f2007-07-25 11:28:32 +1000596 /* Pegasos has no device_type on its 8042 node, look for the
597 * name instead */
598 if (!np)
599 np = of_find_node_by_name(NULL, "8042");
Olaf Hering8d8a0242007-04-26 06:36:56 +1000600 break;
601 case FDC_BASE: /* FDC1 */
602 np = of_find_node_by_type(NULL, "fdc");
603 break;
604#ifdef CONFIG_PPC_PREP
605 case _PIDXR:
606 case _PNPWRP:
607 case PNPBIOS_BASE:
608 /* implement me */
609#endif
610 default:
611 /* ipmi is supposed to fail here */
612 break;
613 }
614 if (!np)
615 return ret;
616 parent = of_get_parent(np);
617 if (parent) {
618 if (strcmp(parent->type, "isa") == 0)
619 ret = 0;
620 of_node_put(parent);
621 }
622 of_node_put(np);
623 return ret;
David Woodhouse12692772006-04-24 23:22:17 +0100624}
625EXPORT_SYMBOL(check_legacy_ioport);
Kumar Gala7e990262006-05-05 00:02:08 -0500626
627static int ppc_panic_event(struct notifier_block *this,
628 unsigned long event, void *ptr)
629{
630 ppc_md.panic(ptr); /* May not return */
631 return NOTIFY_DONE;
632}
633
634static struct notifier_block ppc_panic_block = {
635 .notifier_call = ppc_panic_event,
636 .priority = INT_MIN /* may not return; must be done last */
637};
638
639void __init setup_panic(void)
640{
641 atomic_notifier_chain_register(&panic_notifier_list, &ppc_panic_block);
642}
Dale Farnsworth06cce432007-05-12 10:57:35 +1000643
644#ifdef CONFIG_CHECK_CACHE_COHERENCY
645/*
646 * For platforms that have configurable cache-coherency. This function
647 * checks that the cache coherency setting of the kernel matches the setting
648 * left by the firmware, as indicated in the device tree. Since a mismatch
649 * will eventually result in DMA failures, we print * and error and call
650 * BUG() in that case.
651 */
652
653#ifdef CONFIG_NOT_COHERENT_CACHE
654#define KERNEL_COHERENCY 0
655#else
656#define KERNEL_COHERENCY 1
657#endif
658
659static int __init check_cache_coherency(void)
660{
661 struct device_node *np;
662 const void *prop;
663 int devtree_coherency;
664
665 np = of_find_node_by_path("/");
666 prop = of_get_property(np, "coherency-off", NULL);
667 of_node_put(np);
668
669 devtree_coherency = prop ? 0 : 1;
670
671 if (devtree_coherency != KERNEL_COHERENCY) {
672 printk(KERN_ERR
673 "kernel coherency:%s != device tree_coherency:%s\n",
674 KERNEL_COHERENCY ? "on" : "off",
675 devtree_coherency ? "on" : "off");
676 BUG();
677 }
678
679 return 0;
680}
681
682late_initcall(check_cache_coherency);
683#endif /* CONFIG_CHECK_CACHE_COHERENCY */
Michael Ellerman94a38072007-06-20 10:54:19 +1000684
685#ifdef CONFIG_DEBUG_FS
686struct dentry *powerpc_debugfs_root;
Anton Blanchard907b1f42009-10-26 18:52:24 +0000687EXPORT_SYMBOL(powerpc_debugfs_root);
Michael Ellerman94a38072007-06-20 10:54:19 +1000688
689static int powerpc_debugfs_init(void)
690{
691 powerpc_debugfs_root = debugfs_create_dir("powerpc", NULL);
692
693 return powerpc_debugfs_root == NULL;
694}
695arch_initcall(powerpc_debugfs_init);
696#endif
Kumar Galad7462862009-03-19 03:40:51 +0000697
698static int ppc_dflt_bus_notify(struct notifier_block *nb,
699 unsigned long action, void *data)
700{
701 struct device *dev = data;
702
703 /* We are only intereted in device addition */
704 if (action != BUS_NOTIFY_ADD_DEVICE)
705 return 0;
706
707 set_dma_ops(dev, &dma_direct_ops);
708
709 return NOTIFY_DONE;
710}
711
712static struct notifier_block ppc_dflt_plat_bus_notifier = {
713 .notifier_call = ppc_dflt_bus_notify,
714 .priority = INT_MAX,
715};
716
717static struct notifier_block ppc_dflt_of_bus_notifier = {
718 .notifier_call = ppc_dflt_bus_notify,
719 .priority = INT_MAX,
720};
721
722static int __init setup_bus_notifier(void)
723{
724 bus_register_notifier(&platform_bus_type, &ppc_dflt_plat_bus_notifier);
725 bus_register_notifier(&of_platform_bus_type, &ppc_dflt_of_bus_notifier);
726
727 return 0;
728}
729
730arch_initcall(setup_bus_notifier);