blob: db540eab09f45befe7ebfbcd64984b5c76d528ea [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>
27#include <linux/utsname.h>
Jon Smirl894673e2006-07-10 04:44:13 -070028#include <linux/screen_info.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100029#include <linux/root_dev.h>
30#include <linux/notifier.h>
31#include <linux/cpu.h>
32#include <linux/unistd.h>
33#include <linux/serial.h>
34#include <linux/serial_8250.h>
Michael Ellerman94a38072007-06-20 10:54:19 +100035#include <linux/debugfs.h>
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +100036#include <linux/percpu.h>
David S. Millerd9b2b2a2008-02-13 16:56:49 -080037#include <linux/lmb.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100038#include <asm/io.h>
39#include <asm/prom.h>
40#include <asm/processor.h>
Benjamin Herrenschmidta7f290d2005-11-11 21:15:21 +110041#include <asm/vdso_datapage.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100042#include <asm/pgtable.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100043#include <asm/smp.h>
44#include <asm/elf.h>
45#include <asm/machdep.h>
46#include <asm/time.h>
47#include <asm/cputable.h>
48#include <asm/sections.h>
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110049#include <asm/firmware.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100050#include <asm/btext.h>
51#include <asm/nvram.h>
52#include <asm/setup.h>
53#include <asm/system.h>
54#include <asm/rtas.h>
55#include <asm/iommu.h>
56#include <asm/serial.h>
57#include <asm/cache.h>
58#include <asm/page.h>
59#include <asm/mmu.h>
Paul Mackerrasfca5dcd2005-11-08 22:55:08 +110060#include <asm/xmon.h>
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +100061#include <asm/cputhreads.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100062
Stephen Rothwell66ba1352005-11-09 11:01:06 +110063#include "setup.h"
64
Paul Mackerras03501da2005-10-26 17:11:18 +100065#ifdef DEBUG
Michael Ellermanf9e4ec52005-11-15 15:16:38 +110066#include <asm/udbg.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100067#define DBG(fmt...) udbg_printf(fmt)
68#else
69#define DBG(fmt...)
70#endif
71
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110072/* The main machine-dep calls structure
73 */
74struct machdep_calls ppc_md;
75EXPORT_SYMBOL(ppc_md);
76struct machdep_calls *machine_id;
77EXPORT_SYMBOL(machine_id);
Paul Mackerras799d6042005-11-10 13:37:51 +110078
Paul Mackerras49b09852005-11-10 15:53:40 +110079unsigned long klimit = (unsigned long) _end;
80
Stephen Rothwell19a8d972007-09-17 14:41:38 +100081char cmd_line[COMMAND_LINE_SIZE];
82
Paul Mackerras03501da2005-10-26 17:11:18 +100083/*
84 * This still seems to be needed... -- paulus
85 */
86struct screen_info screen_info = {
87 .orig_x = 0,
88 .orig_y = 25,
89 .orig_video_cols = 80,
90 .orig_video_lines = 25,
91 .orig_video_isVGA = 1,
92 .orig_video_points = 16
93};
94
95#ifdef __DO_IRQ_CANON
96/* XXX should go elsewhere eventually */
97int ppc_do_canonicalize_irqs;
98EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
99#endif
100
101/* also used by kexec */
102void machine_shutdown(void)
103{
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100104 if (ppc_md.machine_shutdown)
105 ppc_md.machine_shutdown();
Paul Mackerras03501da2005-10-26 17:11:18 +1000106}
107
108void machine_restart(char *cmd)
109{
110 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600111 if (ppc_md.restart)
112 ppc_md.restart(cmd);
Paul Mackerras03501da2005-10-26 17:11:18 +1000113#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
121void machine_power_off(void)
122{
123 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600124 if (ppc_md.power_off)
125 ppc_md.power_off();
Paul Mackerras03501da2005-10-26 17:11:18 +1000126#ifdef CONFIG_SMP
127 smp_send_stop();
128#endif
129 printk(KERN_EMERG "System Halted, OK to turn off power\n");
130 local_irq_disable();
131 while (1) ;
132}
133/* Used by the G5 thermal driver */
134EXPORT_SYMBOL_GPL(machine_power_off);
135
136void (*pm_power_off)(void) = machine_power_off;
137EXPORT_SYMBOL_GPL(pm_power_off);
138
139void machine_halt(void)
140{
141 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600142 if (ppc_md.halt)
143 ppc_md.halt();
Paul Mackerras03501da2005-10-26 17:11:18 +1000144#ifdef CONFIG_SMP
145 smp_send_stop();
146#endif
147 printk(KERN_EMERG "System Halted, OK to turn off power\n");
148 local_irq_disable();
149 while (1) ;
150}
151
152
153#ifdef CONFIG_TAU
154extern u32 cpu_temp(unsigned long cpu);
155extern u32 cpu_temp_both(unsigned long cpu);
156#endif /* CONFIG_TAU */
157
158#ifdef CONFIG_SMP
159DEFINE_PER_CPU(unsigned int, pvr);
160#endif
161
162static int show_cpuinfo(struct seq_file *m, void *v)
163{
164 unsigned long cpu_id = (unsigned long)v - 1;
165 unsigned int pvr;
166 unsigned short maj;
167 unsigned short min;
168
169 if (cpu_id == NR_CPUS) {
Marian Balakowicz0276c132007-11-10 04:11:43 +1100170 struct device_node *root;
171 const char *model = NULL;
Paul Mackerras03501da2005-10-26 17:11:18 +1000172#if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
173 unsigned long bogosum = 0;
174 int i;
Andrew Morton394e3902006-03-23 03:01:05 -0800175 for_each_online_cpu(i)
176 bogosum += loops_per_jiffy;
Paul Mackerras03501da2005-10-26 17:11:18 +1000177 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);
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100181 if (ppc_md.name)
182 seq_printf(m, "platform\t: %s\n", ppc_md.name);
Marian Balakowicz0276c132007-11-10 04:11:43 +1100183 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
Paul Mackerras03501da2005-10-26 17:11:18 +1000190 if (ppc_md.show_cpuinfo != NULL)
191 ppc_md.show_cpuinfo(m);
192
193 return 0;
194 }
195
196 /* We only show online cpus: disable preempt (overzealous, I
197 * knew) to prevent cpu going down. */
198 preempt_disable();
199 if (!cpu_online(cpu_id)) {
200 preempt_enable();
201 return 0;
202 }
203
204#ifdef CONFIG_SMP
Paul Mackerras03501da2005-10-26 17:11:18 +1000205 pvr = per_cpu(pvr, cpu_id);
206#else
Paul Mackerras03501da2005-10-26 17:11:18 +1000207 pvr = mfspr(SPRN_PVR);
208#endif
209 maj = (pvr >> 8) & 0xFF;
210 min = pvr & 0xFF;
211
212 seq_printf(m, "processor\t: %lu\n", cpu_id);
213 seq_printf(m, "cpu\t\t: ");
214
215 if (cur_cpu_spec->pvr_mask)
216 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
217 else
218 seq_printf(m, "unknown (%08x)", pvr);
219
220#ifdef CONFIG_ALTIVEC
221 if (cpu_has_feature(CPU_FTR_ALTIVEC))
222 seq_printf(m, ", altivec supported");
223#endif /* CONFIG_ALTIVEC */
224
225 seq_printf(m, "\n");
226
227#ifdef CONFIG_TAU
228 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
229#ifdef CONFIG_TAU_AVERAGE
230 /* more straightforward, but potentially misleading */
231 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
Paul Mackerrasbccfd582005-11-02 15:06:22 +1100232 cpu_temp(cpu_id));
Paul Mackerras03501da2005-10-26 17:11:18 +1000233#else
234 /* show the actual temp sensor range */
235 u32 temp;
Paul Mackerrasbccfd582005-11-02 15:06:22 +1100236 temp = cpu_temp_both(cpu_id);
Paul Mackerras03501da2005-10-26 17:11:18 +1000237 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
238 temp & 0xff, temp >> 16);
239#endif
240 }
241#endif /* CONFIG_TAU */
242
243 /*
244 * Assume here that all clock rates are the same in a
245 * smp system. -- Cort
246 */
247 if (ppc_proc_freq)
248 seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
249 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
250
251 if (ppc_md.show_percpuinfo != NULL)
252 ppc_md.show_percpuinfo(m, cpu_id);
253
254 /* If we are a Freescale core do a simple check so
255 * we dont have to keep adding cases in the future */
256 if (PVR_VER(pvr) & 0x8000) {
257 maj = PVR_MAJ(pvr);
258 min = PVR_MIN(pvr);
259 } else {
260 switch (PVR_VER(pvr)) {
261 case 0x0020: /* 403 family */
262 maj = PVR_MAJ(pvr) + 1;
263 min = PVR_MIN(pvr);
264 break;
265 case 0x1008: /* 740P/750P ?? */
266 maj = ((pvr >> 8) & 0xFF) - 1;
267 min = pvr & 0xFF;
268 break;
269 default:
270 maj = (pvr >> 8) & 0xFF;
271 min = pvr & 0xFF;
272 break;
273 }
274 }
275
276 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
277 maj, min, PVR_VER(pvr), PVR_REV(pvr));
278
279#ifdef CONFIG_PPC32
280 seq_printf(m, "bogomips\t: %lu.%02lu\n",
281 loops_per_jiffy / (500000/HZ),
282 (loops_per_jiffy / (5000/HZ)) % 100);
283#endif
284
285#ifdef CONFIG_SMP
286 seq_printf(m, "\n");
287#endif
288
289 preempt_enable();
290 return 0;
291}
292
293static void *c_start(struct seq_file *m, loff_t *pos)
294{
295 unsigned long i = *pos;
296
297 return i <= NR_CPUS ? (void *)(i + 1) : NULL;
298}
299
300static void *c_next(struct seq_file *m, void *v, loff_t *pos)
301{
302 ++*pos;
303 return c_start(m, pos);
304}
305
306static void c_stop(struct seq_file *m, void *v)
307{
308}
309
310struct seq_operations cpuinfo_op = {
311 .start =c_start,
312 .next = c_next,
313 .stop = c_stop,
314 .show = show_cpuinfo,
315};
316
David Woodhousea82765b2005-11-02 22:34:20 +0000317void __init check_for_initrd(void)
318{
319#ifdef CONFIG_BLK_DEV_INITRD
David Gibson30437b32007-02-28 14:12:29 +1100320 DBG(" -> check_for_initrd() initrd_start=0x%lx initrd_end=0x%lx\n",
321 initrd_start, initrd_end);
David Woodhousea82765b2005-11-02 22:34:20 +0000322
323 /* If we were passed an initrd, set the ROOT_DEV properly if the values
324 * look sensible. If not, clear initrd reference.
325 */
Michael Ellerman51fae6d2005-12-04 18:39:15 +1100326 if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) &&
David Woodhousea82765b2005-11-02 22:34:20 +0000327 initrd_end > initrd_start)
328 ROOT_DEV = Root_RAM0;
David Woodhouse6761c4a2005-11-11 08:07:11 +0000329 else
David Woodhousea82765b2005-11-02 22:34:20 +0000330 initrd_start = initrd_end = 0;
David Woodhousea82765b2005-11-02 22:34:20 +0000331
332 if (initrd_start)
333 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
334
335 DBG(" <- check_for_initrd()\n");
336#endif /* CONFIG_BLK_DEV_INITRD */
337}
338
Paul Mackerras5ad57072005-11-05 10:33:55 +1100339#ifdef CONFIG_SMP
340
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000341int threads_per_core, threads_shift;
342cpumask_t threads_core_mask;
343
344static void __init cpu_init_thread_core_maps(int tpc)
345{
346 int i;
347
348 threads_per_core = tpc;
349 threads_core_mask = CPU_MASK_NONE;
350
351 /* This implementation only supports power of 2 number of threads
352 * for simplicity and performance
353 */
354 threads_shift = ilog2(tpc);
355 BUG_ON(tpc != (1 << threads_shift));
356
357 for (i = 0; i < tpc; i++)
358 cpu_set(i, threads_core_mask);
359
360 printk(KERN_INFO "CPU maps initialized for %d thread%s per core\n",
361 tpc, tpc > 1 ? "s" : "");
362 printk(KERN_DEBUG " (thread shift is %d)\n", threads_shift);
363}
364
365
Paul Mackerras5ad57072005-11-05 10:33:55 +1100366/**
367 * setup_cpu_maps - initialize the following cpu maps:
368 * cpu_possible_map
369 * cpu_present_map
370 * cpu_sibling_map
371 *
372 * Having the possible map set up early allows us to restrict allocations
373 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
374 *
375 * We do not initialize the online map here; cpus set their own bits in
376 * cpu_online_map as they come up.
377 *
378 * This function is valid only for Open Firmware systems. finish_device_tree
379 * must be called before using this.
380 *
381 * While we're here, we may as well set the "physical" cpu ids in the paca.
Anton Blanchard4df20462006-03-25 17:25:17 +1100382 *
383 * NOTE: This must match the parsing done in early_init_dt_scan_cpus.
Paul Mackerras5ad57072005-11-05 10:33:55 +1100384 */
385void __init smp_setup_cpu_maps(void)
386{
387 struct device_node *dn = NULL;
388 int cpu = 0;
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000389 int nthreads = 1;
390
391 DBG("smp_setup_cpu_maps()\n");
Paul Mackerras5ad57072005-11-05 10:33:55 +1100392
393 while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000394 const int *intserv;
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000395 int j, len;
396
397 DBG(" * %s...\n", dn->full_name);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100398
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000399 intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s",
400 &len);
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000401 if (intserv) {
Paul Mackerras5ad57072005-11-05 10:33:55 +1100402 nthreads = len / sizeof(int);
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000403 DBG(" ibm,ppc-interrupt-server#s -> %d threads\n",
404 nthreads);
405 } else {
406 DBG(" no ibm,ppc-interrupt-server#s -> 1 thread\n");
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000407 intserv = of_get_property(dn, "reg", NULL);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100408 if (!intserv)
409 intserv = &cpu; /* assume logical == phys */
410 }
411
412 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000413 DBG(" thread %d -> cpu %d (hard id %d)\n",
414 j, cpu, intserv[j]);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100415 cpu_set(cpu, cpu_present_map);
416 set_hard_smp_processor_id(cpu, intserv[j]);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100417 cpu_set(cpu, cpu_possible_map);
418 cpu++;
419 }
420 }
421
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000422 /* If no SMT supported, nthreads is forced to 1 */
423 if (!cpu_has_feature(CPU_FTR_SMT)) {
424 DBG(" SMT disabled ! nthreads forced to 1\n");
425 nthreads = 1;
426 }
427
Paul Mackerras5ad57072005-11-05 10:33:55 +1100428#ifdef CONFIG_PPC64
429 /*
430 * On pSeries LPAR, we need to know how many cpus
431 * could possibly be added to this partition.
432 */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100433 if (machine_is(pseries) && firmware_has_feature(FW_FEATURE_LPAR) &&
Paul Mackerras799d6042005-11-10 13:37:51 +1100434 (dn = of_find_node_by_path("/rtas"))) {
Paul Mackerras5ad57072005-11-05 10:33:55 +1100435 int num_addr_cell, num_size_cell, maxcpus;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000436 const unsigned int *ireg;
Paul Mackerras5ad57072005-11-05 10:33:55 +1100437
Stephen Rothwella8bda5d2007-04-03 10:56:50 +1000438 num_addr_cell = of_n_addr_cells(dn);
Stephen Rothwell9213fee2007-04-03 10:57:48 +1000439 num_size_cell = of_n_size_cells(dn);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100440
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000441 ireg = of_get_property(dn, "ibm,lrdr-capacity", NULL);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100442
443 if (!ireg)
444 goto out;
445
446 maxcpus = ireg[num_addr_cell + num_size_cell];
447
448 /* Double maxcpus for processors which have SMT capability */
449 if (cpu_has_feature(CPU_FTR_SMT))
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000450 maxcpus *= nthreads;
Paul Mackerras5ad57072005-11-05 10:33:55 +1100451
452 if (maxcpus > NR_CPUS) {
453 printk(KERN_WARNING
454 "Partition configured for %d cpus, "
455 "operating system maximum is %d.\n",
456 maxcpus, NR_CPUS);
457 maxcpus = NR_CPUS;
458 } else
459 printk(KERN_INFO "Partition configured for %d cpus.\n",
460 maxcpus);
461
462 for (cpu = 0; cpu < maxcpus; cpu++)
463 cpu_set(cpu, cpu_possible_map);
464 out:
465 of_node_put(dn);
466 }
Mike Travisd5a74302007-10-16 01:24:05 -0700467 vdso_data->processorCount = num_present_cpus();
468#endif /* CONFIG_PPC64 */
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000469
470 /* Initialize CPU <=> thread mapping/
471 *
472 * WARNING: We assume that the number of threads is the same for
473 * every CPU in the system. If that is not the case, then some code
474 * here will have to be reworked
475 */
476 cpu_init_thread_core_maps(nthreads);
Mike Travisd5a74302007-10-16 01:24:05 -0700477}
478
479/*
480 * Being that cpu_sibling_map is now a per_cpu array, then it cannot
481 * be initialized until the per_cpu areas have been created. This
482 * function is now called from setup_per_cpu_areas().
483 */
484void __init smp_setup_cpu_sibling_map(void)
485{
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000486#ifdef CONFIG_PPC64
487 int i, cpu, base;
Mike Travisd5a74302007-10-16 01:24:05 -0700488
KAMEZAWA Hiroyuki0e551952006-03-28 14:50:51 -0800489 for_each_possible_cpu(cpu) {
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000490 DBG("Sibling map for CPU %d:", cpu);
491 base = cpu_first_thread_in_core(cpu);
492 for (i = 0; i < threads_per_core; i++) {
493 cpu_set(base + i, per_cpu(cpu_sibling_map, cpu));
494 DBG(" %d", base + i);
495 }
496 DBG("\n");
Paul Mackerras5ad57072005-11-05 10:33:55 +1100497 }
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000498
Paul Mackerras5ad57072005-11-05 10:33:55 +1100499#endif /* CONFIG_PPC64 */
500}
501#endif /* CONFIG_SMP */
Paul Mackerrasfca5dcd2005-11-08 22:55:08 +1100502
Michael Neulinge5c6c8e2006-03-14 00:11:50 -0500503static __init int add_pcspkr(void)
504{
505 struct device_node *np;
506 struct platform_device *pd;
507 int ret;
508
509 np = of_find_compatible_node(NULL, NULL, "pnpPNP,100");
510 of_node_put(np);
511 if (!np)
512 return -ENODEV;
513
514 pd = platform_device_alloc("pcspkr", -1);
515 if (!pd)
516 return -ENOMEM;
517
518 ret = platform_device_add(pd);
519 if (ret)
520 platform_device_put(pd);
521
522 return ret;
523}
524device_initcall(add_pcspkr);
Dmitry Torokhov95d465f2006-04-02 00:08:05 -0500525
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100526void probe_machine(void)
527{
528 extern struct machdep_calls __machine_desc_start;
529 extern struct machdep_calls __machine_desc_end;
530
531 /*
532 * Iterate all ppc_md structures until we find the proper
533 * one for the current machine type
534 */
535 DBG("Probing machine type ...\n");
536
537 for (machine_id = &__machine_desc_start;
538 machine_id < &__machine_desc_end;
539 machine_id++) {
540 DBG(" %s ...", machine_id->name);
541 memcpy(&ppc_md, machine_id, sizeof(struct machdep_calls));
542 if (ppc_md.probe()) {
543 DBG(" match !\n");
544 break;
545 }
546 DBG("\n");
547 }
548 /* What can we do if we didn't find ? */
549 if (machine_id >= &__machine_desc_end) {
550 DBG("No suitable machine found !\n");
551 for (;;);
552 }
553
554 printk(KERN_INFO "Using %s machine description\n", ppc_md.name);
555}
David Woodhouse12692772006-04-24 23:22:17 +0100556
Olaf Hering8d8a0242007-04-26 06:36:56 +1000557/* Match a class of boards, not a specific device configuration. */
David Woodhouse12692772006-04-24 23:22:17 +0100558int check_legacy_ioport(unsigned long base_port)
559{
Olaf Hering8d8a0242007-04-26 06:36:56 +1000560 struct device_node *parent, *np = NULL;
561 int ret = -ENODEV;
562
563 switch(base_port) {
564 case I8042_DATA_REG:
Wade Farnsworthdb0dbae2007-06-20 10:15:10 +1000565 if (!(np = of_find_compatible_node(NULL, NULL, "pnpPNP,303")))
566 np = of_find_compatible_node(NULL, NULL, "pnpPNP,f03");
567 if (np) {
568 parent = of_get_parent(np);
569 of_node_put(np);
570 np = parent;
571 break;
572 }
Olaf Hering8d8a0242007-04-26 06:36:56 +1000573 np = of_find_node_by_type(NULL, "8042");
Alan Curryf5d834f2007-07-25 11:28:32 +1000574 /* Pegasos has no device_type on its 8042 node, look for the
575 * name instead */
576 if (!np)
577 np = of_find_node_by_name(NULL, "8042");
Olaf Hering8d8a0242007-04-26 06:36:56 +1000578 break;
579 case FDC_BASE: /* FDC1 */
580 np = of_find_node_by_type(NULL, "fdc");
581 break;
582#ifdef CONFIG_PPC_PREP
583 case _PIDXR:
584 case _PNPWRP:
585 case PNPBIOS_BASE:
586 /* implement me */
587#endif
588 default:
589 /* ipmi is supposed to fail here */
590 break;
591 }
592 if (!np)
593 return ret;
594 parent = of_get_parent(np);
595 if (parent) {
596 if (strcmp(parent->type, "isa") == 0)
597 ret = 0;
598 of_node_put(parent);
599 }
600 of_node_put(np);
601 return ret;
David Woodhouse12692772006-04-24 23:22:17 +0100602}
603EXPORT_SYMBOL(check_legacy_ioport);
Kumar Gala7e990262006-05-05 00:02:08 -0500604
605static int ppc_panic_event(struct notifier_block *this,
606 unsigned long event, void *ptr)
607{
608 ppc_md.panic(ptr); /* May not return */
609 return NOTIFY_DONE;
610}
611
612static struct notifier_block ppc_panic_block = {
613 .notifier_call = ppc_panic_event,
614 .priority = INT_MIN /* may not return; must be done last */
615};
616
617void __init setup_panic(void)
618{
619 atomic_notifier_chain_register(&panic_notifier_list, &ppc_panic_block);
620}
Dale Farnsworth06cce432007-05-12 10:57:35 +1000621
622#ifdef CONFIG_CHECK_CACHE_COHERENCY
623/*
624 * For platforms that have configurable cache-coherency. This function
625 * checks that the cache coherency setting of the kernel matches the setting
626 * left by the firmware, as indicated in the device tree. Since a mismatch
627 * will eventually result in DMA failures, we print * and error and call
628 * BUG() in that case.
629 */
630
631#ifdef CONFIG_NOT_COHERENT_CACHE
632#define KERNEL_COHERENCY 0
633#else
634#define KERNEL_COHERENCY 1
635#endif
636
637static int __init check_cache_coherency(void)
638{
639 struct device_node *np;
640 const void *prop;
641 int devtree_coherency;
642
643 np = of_find_node_by_path("/");
644 prop = of_get_property(np, "coherency-off", NULL);
645 of_node_put(np);
646
647 devtree_coherency = prop ? 0 : 1;
648
649 if (devtree_coherency != KERNEL_COHERENCY) {
650 printk(KERN_ERR
651 "kernel coherency:%s != device tree_coherency:%s\n",
652 KERNEL_COHERENCY ? "on" : "off",
653 devtree_coherency ? "on" : "off");
654 BUG();
655 }
656
657 return 0;
658}
659
660late_initcall(check_cache_coherency);
661#endif /* CONFIG_CHECK_CACHE_COHERENCY */
Michael Ellerman94a38072007-06-20 10:54:19 +1000662
663#ifdef CONFIG_DEBUG_FS
664struct dentry *powerpc_debugfs_root;
665
666static int powerpc_debugfs_init(void)
667{
668 powerpc_debugfs_root = debugfs_create_dir("powerpc", NULL);
669
670 return powerpc_debugfs_root == NULL;
671}
672arch_initcall(powerpc_debugfs_init);
673#endif