blob: 705fc4bf3800af690b9d3edff25c915b52d811c6 [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>
Becky Brucef465df82008-10-15 08:25:28 +000062#include <mm/mmu_decl.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100063
Stephen Rothwell66ba1352005-11-09 11:01:06 +110064#include "setup.h"
65
Paul Mackerras03501da2005-10-26 17:11:18 +100066#ifdef DEBUG
Michael Ellermanf9e4ec52005-11-15 15:16:38 +110067#include <asm/udbg.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100068#define DBG(fmt...) udbg_printf(fmt)
69#else
70#define DBG(fmt...)
71#endif
72
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110073/* The main machine-dep calls structure
74 */
75struct machdep_calls ppc_md;
76EXPORT_SYMBOL(ppc_md);
77struct machdep_calls *machine_id;
78EXPORT_SYMBOL(machine_id);
Paul Mackerras799d6042005-11-10 13:37:51 +110079
Paul Mackerras49b09852005-11-10 15:53:40 +110080unsigned long klimit = (unsigned long) _end;
81
Stephen Rothwell19a8d972007-09-17 14:41:38 +100082char cmd_line[COMMAND_LINE_SIZE];
83
Paul Mackerras03501da2005-10-26 17:11:18 +100084/*
85 * This still seems to be needed... -- paulus
86 */
87struct screen_info screen_info = {
88 .orig_x = 0,
89 .orig_y = 25,
90 .orig_video_cols = 80,
91 .orig_video_lines = 25,
92 .orig_video_isVGA = 1,
93 .orig_video_points = 16
94};
95
96#ifdef __DO_IRQ_CANON
97/* XXX should go elsewhere eventually */
98int ppc_do_canonicalize_irqs;
99EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
100#endif
101
102/* also used by kexec */
103void machine_shutdown(void)
104{
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100105 if (ppc_md.machine_shutdown)
106 ppc_md.machine_shutdown();
Paul Mackerras03501da2005-10-26 17:11:18 +1000107}
108
109void machine_restart(char *cmd)
110{
111 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600112 if (ppc_md.restart)
113 ppc_md.restart(cmd);
Paul Mackerras03501da2005-10-26 17:11:18 +1000114#ifdef CONFIG_SMP
115 smp_send_stop();
116#endif
117 printk(KERN_EMERG "System Halted, OK to turn off power\n");
118 local_irq_disable();
119 while (1) ;
120}
121
122void machine_power_off(void)
123{
124 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600125 if (ppc_md.power_off)
126 ppc_md.power_off();
Paul Mackerras03501da2005-10-26 17:11:18 +1000127#ifdef CONFIG_SMP
128 smp_send_stop();
129#endif
130 printk(KERN_EMERG "System Halted, OK to turn off power\n");
131 local_irq_disable();
132 while (1) ;
133}
134/* Used by the G5 thermal driver */
135EXPORT_SYMBOL_GPL(machine_power_off);
136
137void (*pm_power_off)(void) = machine_power_off;
138EXPORT_SYMBOL_GPL(pm_power_off);
139
140void machine_halt(void)
141{
142 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600143 if (ppc_md.halt)
144 ppc_md.halt();
Paul Mackerras03501da2005-10-26 17:11:18 +1000145#ifdef CONFIG_SMP
146 smp_send_stop();
147#endif
148 printk(KERN_EMERG "System Halted, OK to turn off power\n");
149 local_irq_disable();
150 while (1) ;
151}
152
153
154#ifdef CONFIG_TAU
155extern u32 cpu_temp(unsigned long cpu);
156extern u32 cpu_temp_both(unsigned long cpu);
157#endif /* CONFIG_TAU */
158
159#ifdef CONFIG_SMP
160DEFINE_PER_CPU(unsigned int, pvr);
161#endif
162
163static int show_cpuinfo(struct seq_file *m, void *v)
164{
165 unsigned long cpu_id = (unsigned long)v - 1;
166 unsigned int pvr;
167 unsigned short maj;
168 unsigned short min;
169
170 if (cpu_id == NR_CPUS) {
Marian Balakowicz0276c132007-11-10 04:11:43 +1100171 struct device_node *root;
172 const char *model = NULL;
Paul Mackerras03501da2005-10-26 17:11:18 +1000173#if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
174 unsigned long bogosum = 0;
175 int i;
Andrew Morton394e3902006-03-23 03:01:05 -0800176 for_each_online_cpu(i)
177 bogosum += loops_per_jiffy;
Paul Mackerras03501da2005-10-26 17:11:18 +1000178 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
179 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
180#endif /* CONFIG_SMP && CONFIG_PPC32 */
181 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100182 if (ppc_md.name)
183 seq_printf(m, "platform\t: %s\n", ppc_md.name);
Marian Balakowicz0276c132007-11-10 04:11:43 +1100184 root = of_find_node_by_path("/");
185 if (root)
186 model = of_get_property(root, "model", NULL);
187 if (model)
188 seq_printf(m, "model\t\t: %s\n", model);
189 of_node_put(root);
190
Paul Mackerras03501da2005-10-26 17:11:18 +1000191 if (ppc_md.show_cpuinfo != NULL)
192 ppc_md.show_cpuinfo(m);
193
Becky Brucef465df82008-10-15 08:25:28 +0000194#ifdef CONFIG_PPC32
195 /* Display the amount of memory */
196 seq_printf(m, "Memory\t\t: %d MB\n",
197 (unsigned int)(total_memory / (1024 * 1024)));
198#endif
199
Paul Mackerras03501da2005-10-26 17:11:18 +1000200 return 0;
201 }
202
203 /* We only show online cpus: disable preempt (overzealous, I
204 * knew) to prevent cpu going down. */
205 preempt_disable();
206 if (!cpu_online(cpu_id)) {
207 preempt_enable();
208 return 0;
209 }
210
211#ifdef CONFIG_SMP
Paul Mackerras03501da2005-10-26 17:11:18 +1000212 pvr = per_cpu(pvr, cpu_id);
213#else
Paul Mackerras03501da2005-10-26 17:11:18 +1000214 pvr = mfspr(SPRN_PVR);
215#endif
216 maj = (pvr >> 8) & 0xFF;
217 min = pvr & 0xFF;
218
219 seq_printf(m, "processor\t: %lu\n", cpu_id);
220 seq_printf(m, "cpu\t\t: ");
221
222 if (cur_cpu_spec->pvr_mask)
223 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
224 else
225 seq_printf(m, "unknown (%08x)", pvr);
226
227#ifdef CONFIG_ALTIVEC
228 if (cpu_has_feature(CPU_FTR_ALTIVEC))
229 seq_printf(m, ", altivec supported");
230#endif /* CONFIG_ALTIVEC */
231
232 seq_printf(m, "\n");
233
234#ifdef CONFIG_TAU
235 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
236#ifdef CONFIG_TAU_AVERAGE
237 /* more straightforward, but potentially misleading */
238 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
Paul Mackerrasbccfd582005-11-02 15:06:22 +1100239 cpu_temp(cpu_id));
Paul Mackerras03501da2005-10-26 17:11:18 +1000240#else
241 /* show the actual temp sensor range */
242 u32 temp;
Paul Mackerrasbccfd582005-11-02 15:06:22 +1100243 temp = cpu_temp_both(cpu_id);
Paul Mackerras03501da2005-10-26 17:11:18 +1000244 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
245 temp & 0xff, temp >> 16);
246#endif
247 }
248#endif /* CONFIG_TAU */
249
250 /*
251 * Assume here that all clock rates are the same in a
252 * smp system. -- Cort
253 */
254 if (ppc_proc_freq)
255 seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
256 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
257
258 if (ppc_md.show_percpuinfo != NULL)
259 ppc_md.show_percpuinfo(m, cpu_id);
260
261 /* If we are a Freescale core do a simple check so
262 * we dont have to keep adding cases in the future */
263 if (PVR_VER(pvr) & 0x8000) {
Martin Langera501d8f2008-09-07 17:51:32 +1000264 switch (PVR_VER(pvr)) {
265 case 0x8000: /* 7441/7450/7451, Voyager */
266 case 0x8001: /* 7445/7455, Apollo 6 */
267 case 0x8002: /* 7447/7457, Apollo 7 */
268 case 0x8003: /* 7447A, Apollo 7 PM */
269 case 0x8004: /* 7448, Apollo 8 */
270 case 0x800c: /* 7410, Nitro */
271 maj = ((pvr >> 8) & 0xF);
272 min = PVR_MIN(pvr);
273 break;
274 default: /* e500/book-e */
275 maj = PVR_MAJ(pvr);
276 min = PVR_MIN(pvr);
277 break;
278 }
Paul Mackerras03501da2005-10-26 17:11:18 +1000279 } else {
280 switch (PVR_VER(pvr)) {
281 case 0x0020: /* 403 family */
282 maj = PVR_MAJ(pvr) + 1;
283 min = PVR_MIN(pvr);
284 break;
285 case 0x1008: /* 740P/750P ?? */
286 maj = ((pvr >> 8) & 0xFF) - 1;
287 min = pvr & 0xFF;
288 break;
289 default:
290 maj = (pvr >> 8) & 0xFF;
291 min = pvr & 0xFF;
292 break;
293 }
294 }
295
296 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
297 maj, min, PVR_VER(pvr), PVR_REV(pvr));
298
299#ifdef CONFIG_PPC32
300 seq_printf(m, "bogomips\t: %lu.%02lu\n",
301 loops_per_jiffy / (500000/HZ),
302 (loops_per_jiffy / (5000/HZ)) % 100);
303#endif
304
305#ifdef CONFIG_SMP
306 seq_printf(m, "\n");
307#endif
308
309 preempt_enable();
310 return 0;
311}
312
313static void *c_start(struct seq_file *m, loff_t *pos)
314{
315 unsigned long i = *pos;
316
317 return i <= NR_CPUS ? (void *)(i + 1) : NULL;
318}
319
320static void *c_next(struct seq_file *m, void *v, loff_t *pos)
321{
322 ++*pos;
323 return c_start(m, pos);
324}
325
326static void c_stop(struct seq_file *m, void *v)
327{
328}
329
330struct seq_operations cpuinfo_op = {
331 .start =c_start,
332 .next = c_next,
333 .stop = c_stop,
334 .show = show_cpuinfo,
335};
336
David Woodhousea82765b2005-11-02 22:34:20 +0000337void __init check_for_initrd(void)
338{
339#ifdef CONFIG_BLK_DEV_INITRD
David Gibson30437b32007-02-28 14:12:29 +1100340 DBG(" -> check_for_initrd() initrd_start=0x%lx initrd_end=0x%lx\n",
341 initrd_start, initrd_end);
David Woodhousea82765b2005-11-02 22:34:20 +0000342
343 /* If we were passed an initrd, set the ROOT_DEV properly if the values
344 * look sensible. If not, clear initrd reference.
345 */
Michael Ellerman51fae6de2005-12-04 18:39:15 +1100346 if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) &&
David Woodhousea82765b2005-11-02 22:34:20 +0000347 initrd_end > initrd_start)
348 ROOT_DEV = Root_RAM0;
David Woodhouse6761c4a2005-11-11 08:07:11 +0000349 else
David Woodhousea82765b2005-11-02 22:34:20 +0000350 initrd_start = initrd_end = 0;
David Woodhousea82765b2005-11-02 22:34:20 +0000351
352 if (initrd_start)
353 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
354
355 DBG(" <- check_for_initrd()\n");
356#endif /* CONFIG_BLK_DEV_INITRD */
357}
358
Paul Mackerras5ad57072005-11-05 10:33:55 +1100359#ifdef CONFIG_SMP
360
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000361int threads_per_core, threads_shift;
362cpumask_t threads_core_mask;
363
364static void __init cpu_init_thread_core_maps(int tpc)
365{
366 int i;
367
368 threads_per_core = tpc;
369 threads_core_mask = CPU_MASK_NONE;
370
371 /* This implementation only supports power of 2 number of threads
372 * for simplicity and performance
373 */
374 threads_shift = ilog2(tpc);
375 BUG_ON(tpc != (1 << threads_shift));
376
377 for (i = 0; i < tpc; i++)
378 cpu_set(i, threads_core_mask);
379
380 printk(KERN_INFO "CPU maps initialized for %d thread%s per core\n",
381 tpc, tpc > 1 ? "s" : "");
382 printk(KERN_DEBUG " (thread shift is %d)\n", threads_shift);
383}
384
385
Paul Mackerras5ad57072005-11-05 10:33:55 +1100386/**
387 * setup_cpu_maps - initialize the following cpu maps:
388 * cpu_possible_map
389 * cpu_present_map
Paul Mackerras5ad57072005-11-05 10:33:55 +1100390 *
391 * Having the possible map set up early allows us to restrict allocations
392 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
393 *
394 * We do not initialize the online map here; cpus set their own bits in
395 * cpu_online_map as they come up.
396 *
397 * This function is valid only for Open Firmware systems. finish_device_tree
398 * must be called before using this.
399 *
400 * While we're here, we may as well set the "physical" cpu ids in the paca.
Anton Blanchard4df20462006-03-25 17:25:17 +1100401 *
402 * NOTE: This must match the parsing done in early_init_dt_scan_cpus.
Paul Mackerras5ad57072005-11-05 10:33:55 +1100403 */
404void __init smp_setup_cpu_maps(void)
405{
406 struct device_node *dn = NULL;
407 int cpu = 0;
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000408 int nthreads = 1;
409
410 DBG("smp_setup_cpu_maps()\n");
Paul Mackerras5ad57072005-11-05 10:33:55 +1100411
412 while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000413 const int *intserv;
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000414 int j, len;
415
416 DBG(" * %s...\n", dn->full_name);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100417
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000418 intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s",
419 &len);
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000420 if (intserv) {
Paul Mackerras5ad57072005-11-05 10:33:55 +1100421 nthreads = len / sizeof(int);
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000422 DBG(" ibm,ppc-interrupt-server#s -> %d threads\n",
423 nthreads);
424 } else {
425 DBG(" no ibm,ppc-interrupt-server#s -> 1 thread\n");
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000426 intserv = of_get_property(dn, "reg", NULL);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100427 if (!intserv)
428 intserv = &cpu; /* assume logical == phys */
429 }
430
431 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000432 DBG(" thread %d -> cpu %d (hard id %d)\n",
433 j, cpu, intserv[j]);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100434 cpu_set(cpu, cpu_present_map);
435 set_hard_smp_processor_id(cpu, intserv[j]);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100436 cpu_set(cpu, cpu_possible_map);
437 cpu++;
438 }
439 }
440
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000441 /* If no SMT supported, nthreads is forced to 1 */
442 if (!cpu_has_feature(CPU_FTR_SMT)) {
443 DBG(" SMT disabled ! nthreads forced to 1\n");
444 nthreads = 1;
445 }
446
Paul Mackerras5ad57072005-11-05 10:33:55 +1100447#ifdef CONFIG_PPC64
448 /*
449 * On pSeries LPAR, we need to know how many cpus
450 * could possibly be added to this partition.
451 */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100452 if (machine_is(pseries) && firmware_has_feature(FW_FEATURE_LPAR) &&
Paul Mackerras799d6042005-11-10 13:37:51 +1100453 (dn = of_find_node_by_path("/rtas"))) {
Paul Mackerras5ad57072005-11-05 10:33:55 +1100454 int num_addr_cell, num_size_cell, maxcpus;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000455 const unsigned int *ireg;
Paul Mackerras5ad57072005-11-05 10:33:55 +1100456
Stephen Rothwella8bda5d2007-04-03 10:56:50 +1000457 num_addr_cell = of_n_addr_cells(dn);
Stephen Rothwell9213fee2007-04-03 10:57:48 +1000458 num_size_cell = of_n_size_cells(dn);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100459
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000460 ireg = of_get_property(dn, "ibm,lrdr-capacity", NULL);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100461
462 if (!ireg)
463 goto out;
464
465 maxcpus = ireg[num_addr_cell + num_size_cell];
466
467 /* Double maxcpus for processors which have SMT capability */
468 if (cpu_has_feature(CPU_FTR_SMT))
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000469 maxcpus *= nthreads;
Paul Mackerras5ad57072005-11-05 10:33:55 +1100470
471 if (maxcpus > NR_CPUS) {
472 printk(KERN_WARNING
473 "Partition configured for %d cpus, "
474 "operating system maximum is %d.\n",
475 maxcpus, NR_CPUS);
476 maxcpus = NR_CPUS;
477 } else
478 printk(KERN_INFO "Partition configured for %d cpus.\n",
479 maxcpus);
480
481 for (cpu = 0; cpu < maxcpus; cpu++)
482 cpu_set(cpu, cpu_possible_map);
483 out:
484 of_node_put(dn);
485 }
Mike Travisd5a74302007-10-16 01:24:05 -0700486 vdso_data->processorCount = num_present_cpus();
487#endif /* CONFIG_PPC64 */
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000488
489 /* Initialize CPU <=> thread mapping/
490 *
491 * WARNING: We assume that the number of threads is the same for
492 * every CPU in the system. If that is not the case, then some code
493 * here will have to be reworked
494 */
495 cpu_init_thread_core_maps(nthreads);
Mike Travisd5a74302007-10-16 01:24:05 -0700496}
Paul Mackerras5ad57072005-11-05 10:33:55 +1100497#endif /* CONFIG_SMP */
Paul Mackerrasfca5dcd2005-11-08 22:55:08 +1100498
Emil Medved33b78d2008-05-23 08:40:16 +1000499#ifdef CONFIG_PCSPKR_PLATFORM
Michael Neulinge5c6c8e2006-03-14 00:11:50 -0500500static __init int add_pcspkr(void)
501{
502 struct device_node *np;
503 struct platform_device *pd;
504 int ret;
505
506 np = of_find_compatible_node(NULL, NULL, "pnpPNP,100");
507 of_node_put(np);
508 if (!np)
509 return -ENODEV;
510
511 pd = platform_device_alloc("pcspkr", -1);
512 if (!pd)
513 return -ENOMEM;
514
515 ret = platform_device_add(pd);
516 if (ret)
517 platform_device_put(pd);
518
519 return ret;
520}
521device_initcall(add_pcspkr);
Emil Medved33b78d2008-05-23 08:40:16 +1000522#endif /* CONFIG_PCSPKR_PLATFORM */
Dmitry Torokhov95d465f2006-04-02 00:08:05 -0500523
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100524void probe_machine(void)
525{
526 extern struct machdep_calls __machine_desc_start;
527 extern struct machdep_calls __machine_desc_end;
528
529 /*
530 * Iterate all ppc_md structures until we find the proper
531 * one for the current machine type
532 */
533 DBG("Probing machine type ...\n");
534
535 for (machine_id = &__machine_desc_start;
536 machine_id < &__machine_desc_end;
537 machine_id++) {
538 DBG(" %s ...", machine_id->name);
539 memcpy(&ppc_md, machine_id, sizeof(struct machdep_calls));
540 if (ppc_md.probe()) {
541 DBG(" match !\n");
542 break;
543 }
544 DBG("\n");
545 }
546 /* What can we do if we didn't find ? */
547 if (machine_id >= &__machine_desc_end) {
548 DBG("No suitable machine found !\n");
549 for (;;);
550 }
551
552 printk(KERN_INFO "Using %s machine description\n", ppc_md.name);
553}
David Woodhouse1269277a2006-04-24 23:22:17 +0100554
Olaf Hering8d8a0242007-04-26 06:36:56 +1000555/* Match a class of boards, not a specific device configuration. */
David Woodhouse1269277a2006-04-24 23:22:17 +0100556int check_legacy_ioport(unsigned long base_port)
557{
Olaf Hering8d8a0242007-04-26 06:36:56 +1000558 struct device_node *parent, *np = NULL;
559 int ret = -ENODEV;
560
561 switch(base_port) {
562 case I8042_DATA_REG:
Wade Farnsworthdb0dbae2007-06-20 10:15:10 +1000563 if (!(np = of_find_compatible_node(NULL, NULL, "pnpPNP,303")))
564 np = of_find_compatible_node(NULL, NULL, "pnpPNP,f03");
565 if (np) {
566 parent = of_get_parent(np);
567 of_node_put(np);
568 np = parent;
569 break;
570 }
Olaf Hering8d8a0242007-04-26 06:36:56 +1000571 np = of_find_node_by_type(NULL, "8042");
Alan Curryf5d834f2007-07-25 11:28:32 +1000572 /* Pegasos has no device_type on its 8042 node, look for the
573 * name instead */
574 if (!np)
575 np = of_find_node_by_name(NULL, "8042");
Olaf Hering8d8a0242007-04-26 06:36:56 +1000576 break;
577 case FDC_BASE: /* FDC1 */
578 np = of_find_node_by_type(NULL, "fdc");
579 break;
580#ifdef CONFIG_PPC_PREP
581 case _PIDXR:
582 case _PNPWRP:
583 case PNPBIOS_BASE:
584 /* implement me */
585#endif
586 default:
587 /* ipmi is supposed to fail here */
588 break;
589 }
590 if (!np)
591 return ret;
592 parent = of_get_parent(np);
593 if (parent) {
594 if (strcmp(parent->type, "isa") == 0)
595 ret = 0;
596 of_node_put(parent);
597 }
598 of_node_put(np);
599 return ret;
David Woodhouse1269277a2006-04-24 23:22:17 +0100600}
601EXPORT_SYMBOL(check_legacy_ioport);
Kumar Gala7e990262006-05-05 00:02:08 -0500602
603static int ppc_panic_event(struct notifier_block *this,
604 unsigned long event, void *ptr)
605{
606 ppc_md.panic(ptr); /* May not return */
607 return NOTIFY_DONE;
608}
609
610static struct notifier_block ppc_panic_block = {
611 .notifier_call = ppc_panic_event,
612 .priority = INT_MIN /* may not return; must be done last */
613};
614
615void __init setup_panic(void)
616{
617 atomic_notifier_chain_register(&panic_notifier_list, &ppc_panic_block);
618}
Dale Farnsworth06cce432007-05-12 10:57:35 +1000619
620#ifdef CONFIG_CHECK_CACHE_COHERENCY
621/*
622 * For platforms that have configurable cache-coherency. This function
623 * checks that the cache coherency setting of the kernel matches the setting
624 * left by the firmware, as indicated in the device tree. Since a mismatch
625 * will eventually result in DMA failures, we print * and error and call
626 * BUG() in that case.
627 */
628
629#ifdef CONFIG_NOT_COHERENT_CACHE
630#define KERNEL_COHERENCY 0
631#else
632#define KERNEL_COHERENCY 1
633#endif
634
635static int __init check_cache_coherency(void)
636{
637 struct device_node *np;
638 const void *prop;
639 int devtree_coherency;
640
641 np = of_find_node_by_path("/");
642 prop = of_get_property(np, "coherency-off", NULL);
643 of_node_put(np);
644
645 devtree_coherency = prop ? 0 : 1;
646
647 if (devtree_coherency != KERNEL_COHERENCY) {
648 printk(KERN_ERR
649 "kernel coherency:%s != device tree_coherency:%s\n",
650 KERNEL_COHERENCY ? "on" : "off",
651 devtree_coherency ? "on" : "off");
652 BUG();
653 }
654
655 return 0;
656}
657
658late_initcall(check_cache_coherency);
659#endif /* CONFIG_CHECK_CACHE_COHERENCY */
Michael Ellerman94a38072007-06-20 10:54:19 +1000660
661#ifdef CONFIG_DEBUG_FS
662struct dentry *powerpc_debugfs_root;
663
664static int powerpc_debugfs_init(void)
665{
666 powerpc_debugfs_root = debugfs_create_dir("powerpc", NULL);
667
668 return powerpc_debugfs_root == NULL;
669}
670arch_initcall(powerpc_debugfs_init);
671#endif