blob: 9774f9fed96e52c5bde8cf8dce8e069ed8fc02a4 [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>
Kumar Galad7462862009-03-19 03:40:51 +000038#include <linux/of_platform.h>
39#include <linux/platform_device.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100040#include <asm/io.h>
41#include <asm/prom.h>
42#include <asm/processor.h>
Benjamin Herrenschmidta7f290d2005-11-11 21:15:21 +110043#include <asm/vdso_datapage.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100044#include <asm/pgtable.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100045#include <asm/smp.h>
46#include <asm/elf.h>
47#include <asm/machdep.h>
48#include <asm/time.h>
49#include <asm/cputable.h>
50#include <asm/sections.h>
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110051#include <asm/firmware.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100052#include <asm/btext.h>
53#include <asm/nvram.h>
54#include <asm/setup.h>
55#include <asm/system.h>
56#include <asm/rtas.h>
57#include <asm/iommu.h>
58#include <asm/serial.h>
59#include <asm/cache.h>
60#include <asm/page.h>
61#include <asm/mmu.h>
Paul Mackerrasfca5dcd2005-11-08 22:55:08 +110062#include <asm/xmon.h>
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +100063#include <asm/cputhreads.h>
Becky Brucef465df82008-10-15 08:25:28 +000064#include <mm/mmu_decl.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100065
Stephen Rothwell66ba1352005-11-09 11:01:06 +110066#include "setup.h"
67
Paul Mackerras03501da2005-10-26 17:11:18 +100068#ifdef DEBUG
Michael Ellermanf9e4ec52005-11-15 15:16:38 +110069#include <asm/udbg.h>
Paul Mackerras03501da2005-10-26 17:11:18 +100070#define DBG(fmt...) udbg_printf(fmt)
71#else
72#define DBG(fmt...)
73#endif
74
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110075/* The main machine-dep calls structure
76 */
77struct machdep_calls ppc_md;
78EXPORT_SYMBOL(ppc_md);
79struct machdep_calls *machine_id;
80EXPORT_SYMBOL(machine_id);
Paul Mackerras799d6042005-11-10 13:37:51 +110081
Paul Mackerras49b09852005-11-10 15:53:40 +110082unsigned long klimit = (unsigned long) _end;
83
Stephen Rothwell19a8d972007-09-17 14:41:38 +100084char cmd_line[COMMAND_LINE_SIZE];
85
Paul Mackerras03501da2005-10-26 17:11:18 +100086/*
87 * This still seems to be needed... -- paulus
88 */
89struct screen_info screen_info = {
90 .orig_x = 0,
91 .orig_y = 25,
92 .orig_video_cols = 80,
93 .orig_video_lines = 25,
94 .orig_video_isVGA = 1,
95 .orig_video_points = 16
96};
97
98#ifdef __DO_IRQ_CANON
99/* XXX should go elsewhere eventually */
100int ppc_do_canonicalize_irqs;
101EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
102#endif
103
104/* also used by kexec */
105void machine_shutdown(void)
106{
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100107 if (ppc_md.machine_shutdown)
108 ppc_md.machine_shutdown();
Paul Mackerras03501da2005-10-26 17:11:18 +1000109}
110
111void machine_restart(char *cmd)
112{
113 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600114 if (ppc_md.restart)
115 ppc_md.restart(cmd);
Paul Mackerras03501da2005-10-26 17:11:18 +1000116#ifdef CONFIG_SMP
117 smp_send_stop();
118#endif
119 printk(KERN_EMERG "System Halted, OK to turn off power\n");
120 local_irq_disable();
121 while (1) ;
122}
123
124void machine_power_off(void)
125{
126 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600127 if (ppc_md.power_off)
128 ppc_md.power_off();
Paul Mackerras03501da2005-10-26 17:11:18 +1000129#ifdef CONFIG_SMP
130 smp_send_stop();
131#endif
132 printk(KERN_EMERG "System Halted, OK to turn off power\n");
133 local_irq_disable();
134 while (1) ;
135}
136/* Used by the G5 thermal driver */
137EXPORT_SYMBOL_GPL(machine_power_off);
138
139void (*pm_power_off)(void) = machine_power_off;
140EXPORT_SYMBOL_GPL(pm_power_off);
141
142void machine_halt(void)
143{
144 machine_shutdown();
Kumar Galab8e383d2006-01-13 10:15:17 -0600145 if (ppc_md.halt)
146 ppc_md.halt();
Paul Mackerras03501da2005-10-26 17:11:18 +1000147#ifdef CONFIG_SMP
148 smp_send_stop();
149#endif
150 printk(KERN_EMERG "System Halted, OK to turn off power\n");
151 local_irq_disable();
152 while (1) ;
153}
154
155
156#ifdef CONFIG_TAU
157extern u32 cpu_temp(unsigned long cpu);
158extern u32 cpu_temp_both(unsigned long cpu);
159#endif /* CONFIG_TAU */
160
161#ifdef CONFIG_SMP
162DEFINE_PER_CPU(unsigned int, pvr);
163#endif
164
165static int show_cpuinfo(struct seq_file *m, void *v)
166{
167 unsigned long cpu_id = (unsigned long)v - 1;
168 unsigned int pvr;
169 unsigned short maj;
170 unsigned short min;
171
172 if (cpu_id == NR_CPUS) {
Marian Balakowicz0276c132007-11-10 04:11:43 +1100173 struct device_node *root;
174 const char *model = NULL;
Paul Mackerras03501da2005-10-26 17:11:18 +1000175#if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
176 unsigned long bogosum = 0;
177 int i;
Andrew Morton394e3902006-03-23 03:01:05 -0800178 for_each_online_cpu(i)
179 bogosum += loops_per_jiffy;
Paul Mackerras03501da2005-10-26 17:11:18 +1000180 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
181 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
182#endif /* CONFIG_SMP && CONFIG_PPC32 */
183 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100184 if (ppc_md.name)
185 seq_printf(m, "platform\t: %s\n", ppc_md.name);
Marian Balakowicz0276c132007-11-10 04:11:43 +1100186 root = of_find_node_by_path("/");
187 if (root)
188 model = of_get_property(root, "model", NULL);
189 if (model)
190 seq_printf(m, "model\t\t: %s\n", model);
191 of_node_put(root);
192
Paul Mackerras03501da2005-10-26 17:11:18 +1000193 if (ppc_md.show_cpuinfo != NULL)
194 ppc_md.show_cpuinfo(m);
195
Becky Brucef465df82008-10-15 08:25:28 +0000196#ifdef CONFIG_PPC32
197 /* Display the amount of memory */
198 seq_printf(m, "Memory\t\t: %d MB\n",
199 (unsigned int)(total_memory / (1024 * 1024)));
200#endif
201
Paul Mackerras03501da2005-10-26 17:11:18 +1000202 return 0;
203 }
204
205 /* We only show online cpus: disable preempt (overzealous, I
206 * knew) to prevent cpu going down. */
207 preempt_disable();
208 if (!cpu_online(cpu_id)) {
209 preempt_enable();
210 return 0;
211 }
212
213#ifdef CONFIG_SMP
Paul Mackerras03501da2005-10-26 17:11:18 +1000214 pvr = per_cpu(pvr, cpu_id);
215#else
Paul Mackerras03501da2005-10-26 17:11:18 +1000216 pvr = mfspr(SPRN_PVR);
217#endif
218 maj = (pvr >> 8) & 0xFF;
219 min = pvr & 0xFF;
220
221 seq_printf(m, "processor\t: %lu\n", cpu_id);
222 seq_printf(m, "cpu\t\t: ");
223
224 if (cur_cpu_spec->pvr_mask)
225 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
226 else
227 seq_printf(m, "unknown (%08x)", pvr);
228
229#ifdef CONFIG_ALTIVEC
230 if (cpu_has_feature(CPU_FTR_ALTIVEC))
231 seq_printf(m, ", altivec supported");
232#endif /* CONFIG_ALTIVEC */
233
234 seq_printf(m, "\n");
235
236#ifdef CONFIG_TAU
237 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
238#ifdef CONFIG_TAU_AVERAGE
239 /* more straightforward, but potentially misleading */
240 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
Paul Mackerrasbccfd582005-11-02 15:06:22 +1100241 cpu_temp(cpu_id));
Paul Mackerras03501da2005-10-26 17:11:18 +1000242#else
243 /* show the actual temp sensor range */
244 u32 temp;
Paul Mackerrasbccfd582005-11-02 15:06:22 +1100245 temp = cpu_temp_both(cpu_id);
Paul Mackerras03501da2005-10-26 17:11:18 +1000246 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
247 temp & 0xff, temp >> 16);
248#endif
249 }
250#endif /* CONFIG_TAU */
251
252 /*
253 * Assume here that all clock rates are the same in a
254 * smp system. -- Cort
255 */
256 if (ppc_proc_freq)
257 seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
258 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
259
260 if (ppc_md.show_percpuinfo != NULL)
261 ppc_md.show_percpuinfo(m, cpu_id);
262
263 /* If we are a Freescale core do a simple check so
264 * we dont have to keep adding cases in the future */
265 if (PVR_VER(pvr) & 0x8000) {
Martin Langera501d8f2008-09-07 17:51:32 +1000266 switch (PVR_VER(pvr)) {
267 case 0x8000: /* 7441/7450/7451, Voyager */
268 case 0x8001: /* 7445/7455, Apollo 6 */
269 case 0x8002: /* 7447/7457, Apollo 7 */
270 case 0x8003: /* 7447A, Apollo 7 PM */
271 case 0x8004: /* 7448, Apollo 8 */
272 case 0x800c: /* 7410, Nitro */
273 maj = ((pvr >> 8) & 0xF);
274 min = PVR_MIN(pvr);
275 break;
276 default: /* e500/book-e */
277 maj = PVR_MAJ(pvr);
278 min = PVR_MIN(pvr);
279 break;
280 }
Paul Mackerras03501da2005-10-26 17:11:18 +1000281 } else {
282 switch (PVR_VER(pvr)) {
283 case 0x0020: /* 403 family */
284 maj = PVR_MAJ(pvr) + 1;
285 min = PVR_MIN(pvr);
286 break;
287 case 0x1008: /* 740P/750P ?? */
288 maj = ((pvr >> 8) & 0xFF) - 1;
289 min = pvr & 0xFF;
290 break;
291 default:
292 maj = (pvr >> 8) & 0xFF;
293 min = pvr & 0xFF;
294 break;
295 }
296 }
297
298 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
299 maj, min, PVR_VER(pvr), PVR_REV(pvr));
300
301#ifdef CONFIG_PPC32
302 seq_printf(m, "bogomips\t: %lu.%02lu\n",
303 loops_per_jiffy / (500000/HZ),
304 (loops_per_jiffy / (5000/HZ)) % 100);
305#endif
306
307#ifdef CONFIG_SMP
308 seq_printf(m, "\n");
309#endif
310
311 preempt_enable();
312 return 0;
313}
314
315static void *c_start(struct seq_file *m, loff_t *pos)
316{
317 unsigned long i = *pos;
318
319 return i <= NR_CPUS ? (void *)(i + 1) : NULL;
320}
321
322static void *c_next(struct seq_file *m, void *v, loff_t *pos)
323{
324 ++*pos;
325 return c_start(m, pos);
326}
327
328static void c_stop(struct seq_file *m, void *v)
329{
330}
331
332struct seq_operations cpuinfo_op = {
333 .start =c_start,
334 .next = c_next,
335 .stop = c_stop,
336 .show = show_cpuinfo,
337};
338
David Woodhousea82765b2005-11-02 22:34:20 +0000339void __init check_for_initrd(void)
340{
341#ifdef CONFIG_BLK_DEV_INITRD
David Gibson30437b32007-02-28 14:12:29 +1100342 DBG(" -> check_for_initrd() initrd_start=0x%lx initrd_end=0x%lx\n",
343 initrd_start, initrd_end);
David Woodhousea82765b2005-11-02 22:34:20 +0000344
345 /* If we were passed an initrd, set the ROOT_DEV properly if the values
346 * look sensible. If not, clear initrd reference.
347 */
Michael Ellerman51fae6de2005-12-04 18:39:15 +1100348 if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) &&
David Woodhousea82765b2005-11-02 22:34:20 +0000349 initrd_end > initrd_start)
350 ROOT_DEV = Root_RAM0;
David Woodhouse6761c4a2005-11-11 08:07:11 +0000351 else
David Woodhousea82765b2005-11-02 22:34:20 +0000352 initrd_start = initrd_end = 0;
David Woodhousea82765b2005-11-02 22:34:20 +0000353
354 if (initrd_start)
355 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
356
357 DBG(" <- check_for_initrd()\n");
358#endif /* CONFIG_BLK_DEV_INITRD */
359}
360
Paul Mackerras5ad57072005-11-05 10:33:55 +1100361#ifdef CONFIG_SMP
362
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000363int threads_per_core, threads_shift;
364cpumask_t threads_core_mask;
365
366static void __init cpu_init_thread_core_maps(int tpc)
367{
368 int i;
369
370 threads_per_core = tpc;
371 threads_core_mask = CPU_MASK_NONE;
372
373 /* This implementation only supports power of 2 number of threads
374 * for simplicity and performance
375 */
376 threads_shift = ilog2(tpc);
377 BUG_ON(tpc != (1 << threads_shift));
378
379 for (i = 0; i < tpc; i++)
380 cpu_set(i, threads_core_mask);
381
382 printk(KERN_INFO "CPU maps initialized for %d thread%s per core\n",
383 tpc, tpc > 1 ? "s" : "");
384 printk(KERN_DEBUG " (thread shift is %d)\n", threads_shift);
385}
386
387
Paul Mackerras5ad57072005-11-05 10:33:55 +1100388/**
389 * setup_cpu_maps - initialize the following cpu maps:
390 * cpu_possible_map
391 * cpu_present_map
Paul Mackerras5ad57072005-11-05 10:33:55 +1100392 *
393 * Having the possible map set up early allows us to restrict allocations
394 * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
395 *
396 * We do not initialize the online map here; cpus set their own bits in
397 * cpu_online_map as they come up.
398 *
399 * This function is valid only for Open Firmware systems. finish_device_tree
400 * must be called before using this.
401 *
402 * While we're here, we may as well set the "physical" cpu ids in the paca.
Anton Blanchard4df20462006-03-25 17:25:17 +1100403 *
404 * NOTE: This must match the parsing done in early_init_dt_scan_cpus.
Paul Mackerras5ad57072005-11-05 10:33:55 +1100405 */
406void __init smp_setup_cpu_maps(void)
407{
408 struct device_node *dn = NULL;
409 int cpu = 0;
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000410 int nthreads = 1;
411
412 DBG("smp_setup_cpu_maps()\n");
Paul Mackerras5ad57072005-11-05 10:33:55 +1100413
414 while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000415 const int *intserv;
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000416 int j, len;
417
418 DBG(" * %s...\n", dn->full_name);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100419
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000420 intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s",
421 &len);
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000422 if (intserv) {
Paul Mackerras5ad57072005-11-05 10:33:55 +1100423 nthreads = len / sizeof(int);
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000424 DBG(" ibm,ppc-interrupt-server#s -> %d threads\n",
425 nthreads);
426 } else {
427 DBG(" no ibm,ppc-interrupt-server#s -> 1 thread\n");
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000428 intserv = of_get_property(dn, "reg", NULL);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100429 if (!intserv)
430 intserv = &cpu; /* assume logical == phys */
431 }
432
433 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000434 DBG(" thread %d -> cpu %d (hard id %d)\n",
435 j, cpu, intserv[j]);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100436 cpu_set(cpu, cpu_present_map);
437 set_hard_smp_processor_id(cpu, intserv[j]);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100438 cpu_set(cpu, cpu_possible_map);
439 cpu++;
440 }
441 }
442
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000443 /* If no SMT supported, nthreads is forced to 1 */
444 if (!cpu_has_feature(CPU_FTR_SMT)) {
445 DBG(" SMT disabled ! nthreads forced to 1\n");
446 nthreads = 1;
447 }
448
Paul Mackerras5ad57072005-11-05 10:33:55 +1100449#ifdef CONFIG_PPC64
450 /*
451 * On pSeries LPAR, we need to know how many cpus
452 * could possibly be added to this partition.
453 */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100454 if (machine_is(pseries) && firmware_has_feature(FW_FEATURE_LPAR) &&
Paul Mackerras799d6042005-11-10 13:37:51 +1100455 (dn = of_find_node_by_path("/rtas"))) {
Paul Mackerras5ad57072005-11-05 10:33:55 +1100456 int num_addr_cell, num_size_cell, maxcpus;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000457 const unsigned int *ireg;
Paul Mackerras5ad57072005-11-05 10:33:55 +1100458
Stephen Rothwella8bda5d2007-04-03 10:56:50 +1000459 num_addr_cell = of_n_addr_cells(dn);
Stephen Rothwell9213fee2007-04-03 10:57:48 +1000460 num_size_cell = of_n_size_cells(dn);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100461
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000462 ireg = of_get_property(dn, "ibm,lrdr-capacity", NULL);
Paul Mackerras5ad57072005-11-05 10:33:55 +1100463
464 if (!ireg)
465 goto out;
466
467 maxcpus = ireg[num_addr_cell + num_size_cell];
468
469 /* Double maxcpus for processors which have SMT capability */
470 if (cpu_has_feature(CPU_FTR_SMT))
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000471 maxcpus *= nthreads;
Paul Mackerras5ad57072005-11-05 10:33:55 +1100472
473 if (maxcpus > NR_CPUS) {
474 printk(KERN_WARNING
475 "Partition configured for %d cpus, "
476 "operating system maximum is %d.\n",
477 maxcpus, NR_CPUS);
478 maxcpus = NR_CPUS;
479 } else
480 printk(KERN_INFO "Partition configured for %d cpus.\n",
481 maxcpus);
482
483 for (cpu = 0; cpu < maxcpus; cpu++)
484 cpu_set(cpu, cpu_possible_map);
485 out:
486 of_node_put(dn);
487 }
Mike Travisd5a74302007-10-16 01:24:05 -0700488 vdso_data->processorCount = num_present_cpus();
489#endif /* CONFIG_PPC64 */
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000490
491 /* Initialize CPU <=> thread mapping/
492 *
493 * WARNING: We assume that the number of threads is the same for
494 * every CPU in the system. If that is not the case, then some code
495 * here will have to be reworked
496 */
497 cpu_init_thread_core_maps(nthreads);
Mike Travisd5a74302007-10-16 01:24:05 -0700498}
Paul Mackerras5ad57072005-11-05 10:33:55 +1100499#endif /* CONFIG_SMP */
Paul Mackerrasfca5dcd2005-11-08 22:55:08 +1100500
Emil Medved33b78d2008-05-23 08:40:16 +1000501#ifdef CONFIG_PCSPKR_PLATFORM
Michael Neulinge5c6c8e2006-03-14 00:11:50 -0500502static __init int add_pcspkr(void)
503{
504 struct device_node *np;
505 struct platform_device *pd;
506 int ret;
507
508 np = of_find_compatible_node(NULL, NULL, "pnpPNP,100");
509 of_node_put(np);
510 if (!np)
511 return -ENODEV;
512
513 pd = platform_device_alloc("pcspkr", -1);
514 if (!pd)
515 return -ENOMEM;
516
517 ret = platform_device_add(pd);
518 if (ret)
519 platform_device_put(pd);
520
521 return ret;
522}
523device_initcall(add_pcspkr);
Emil Medved33b78d2008-05-23 08:40:16 +1000524#endif /* CONFIG_PCSPKR_PLATFORM */
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
Kumar Galad7462862009-03-19 03:40:51 +0000674
675static int ppc_dflt_bus_notify(struct notifier_block *nb,
676 unsigned long action, void *data)
677{
678 struct device *dev = data;
679
680 /* We are only intereted in device addition */
681 if (action != BUS_NOTIFY_ADD_DEVICE)
682 return 0;
683
684 set_dma_ops(dev, &dma_direct_ops);
685
686 return NOTIFY_DONE;
687}
688
689static struct notifier_block ppc_dflt_plat_bus_notifier = {
690 .notifier_call = ppc_dflt_bus_notify,
691 .priority = INT_MAX,
692};
693
694static struct notifier_block ppc_dflt_of_bus_notifier = {
695 .notifier_call = ppc_dflt_bus_notify,
696 .priority = INT_MAX,
697};
698
699static int __init setup_bus_notifier(void)
700{
701 bus_register_notifier(&platform_bus_type, &ppc_dflt_plat_bus_notifier);
702 bus_register_notifier(&of_platform_bus_type, &ppc_dflt_of_bus_notifier);
703
704 return 0;
705}
706
707arch_initcall(setup_bus_notifier);