setup-common.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. /*
  2. * Common boot and setup code for both 32-bit and 64-bit.
  3. * Extracted from arch/powerpc/kernel/setup_64.c.
  4. *
  5. * Copyright (C) 2001 PPC64 Team, IBM Corp
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #undef DEBUG
  13. #include <linux/export.h>
  14. #include <linux/string.h>
  15. #include <linux/sched.h>
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <linux/reboot.h>
  19. #include <linux/delay.h>
  20. #include <linux/initrd.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/ioport.h>
  24. #include <linux/console.h>
  25. #include <linux/screen_info.h>
  26. #include <linux/root_dev.h>
  27. #include <linux/notifier.h>
  28. #include <linux/cpu.h>
  29. #include <linux/unistd.h>
  30. #include <linux/serial.h>
  31. #include <linux/serial_8250.h>
  32. #include <linux/debugfs.h>
  33. #include <linux/percpu.h>
  34. #include <linux/memblock.h>
  35. #include <linux/of_platform.h>
  36. #include <linux/hugetlb.h>
  37. #include <asm/io.h>
  38. #include <asm/paca.h>
  39. #include <asm/prom.h>
  40. #include <asm/processor.h>
  41. #include <asm/vdso_datapage.h>
  42. #include <asm/pgtable.h>
  43. #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>
  49. #include <asm/firmware.h>
  50. #include <asm/btext.h>
  51. #include <asm/nvram.h>
  52. #include <asm/setup.h>
  53. #include <asm/rtas.h>
  54. #include <asm/iommu.h>
  55. #include <asm/serial.h>
  56. #include <asm/cache.h>
  57. #include <asm/page.h>
  58. #include <asm/mmu.h>
  59. #include <asm/xmon.h>
  60. #include <asm/cputhreads.h>
  61. #include <mm/mmu_decl.h>
  62. #include <asm/fadump.h>
  63. #include <asm/udbg.h>
  64. #include <asm/hugetlb.h>
  65. #include <asm/livepatch.h>
  66. #include <asm/mmu_context.h>
  67. #include <asm/cpu_has_feature.h>
  68. #include "setup.h"
  69. #ifdef DEBUG
  70. #include <asm/udbg.h>
  71. #define DBG(fmt...) udbg_printf(fmt)
  72. #else
  73. #define DBG(fmt...)
  74. #endif
  75. /* The main machine-dep calls structure
  76. */
  77. struct machdep_calls ppc_md;
  78. EXPORT_SYMBOL(ppc_md);
  79. struct machdep_calls *machine_id;
  80. EXPORT_SYMBOL(machine_id);
  81. int boot_cpuid = -1;
  82. EXPORT_SYMBOL_GPL(boot_cpuid);
  83. unsigned long klimit = (unsigned long) _end;
  84. /*
  85. * This still seems to be needed... -- paulus
  86. */
  87. struct 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. #if defined(CONFIG_FB_VGA16_MODULE)
  96. EXPORT_SYMBOL(screen_info);
  97. #endif
  98. /* Variables required to store legacy IO irq routing */
  99. int of_i8042_kbd_irq;
  100. EXPORT_SYMBOL_GPL(of_i8042_kbd_irq);
  101. int of_i8042_aux_irq;
  102. EXPORT_SYMBOL_GPL(of_i8042_aux_irq);
  103. #ifdef __DO_IRQ_CANON
  104. /* XXX should go elsewhere eventually */
  105. int ppc_do_canonicalize_irqs;
  106. EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
  107. #endif
  108. /* also used by kexec */
  109. void machine_shutdown(void)
  110. {
  111. #ifdef CONFIG_FA_DUMP
  112. /*
  113. * if fadump is active, cleanup the fadump registration before we
  114. * shutdown.
  115. */
  116. fadump_cleanup();
  117. #endif
  118. if (ppc_md.machine_shutdown)
  119. ppc_md.machine_shutdown();
  120. }
  121. static void machine_hang(void)
  122. {
  123. pr_emerg("System Halted, OK to turn off power\n");
  124. local_irq_disable();
  125. while (1)
  126. ;
  127. }
  128. void machine_restart(char *cmd)
  129. {
  130. machine_shutdown();
  131. if (ppc_md.restart)
  132. ppc_md.restart(cmd);
  133. smp_send_stop();
  134. do_kernel_restart(cmd);
  135. mdelay(1000);
  136. machine_hang();
  137. }
  138. void machine_power_off(void)
  139. {
  140. machine_shutdown();
  141. if (pm_power_off)
  142. pm_power_off();
  143. smp_send_stop();
  144. machine_hang();
  145. }
  146. /* Used by the G5 thermal driver */
  147. EXPORT_SYMBOL_GPL(machine_power_off);
  148. void (*pm_power_off)(void);
  149. EXPORT_SYMBOL_GPL(pm_power_off);
  150. void machine_halt(void)
  151. {
  152. machine_shutdown();
  153. if (ppc_md.halt)
  154. ppc_md.halt();
  155. smp_send_stop();
  156. machine_hang();
  157. }
  158. #ifdef CONFIG_TAU
  159. extern u32 cpu_temp(unsigned long cpu);
  160. extern u32 cpu_temp_both(unsigned long cpu);
  161. #endif /* CONFIG_TAU */
  162. #ifdef CONFIG_SMP
  163. DEFINE_PER_CPU(unsigned int, cpu_pvr);
  164. #endif
  165. static void show_cpuinfo_summary(struct seq_file *m)
  166. {
  167. struct device_node *root;
  168. const char *model = NULL;
  169. #if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
  170. unsigned long bogosum = 0;
  171. int i;
  172. for_each_online_cpu(i)
  173. bogosum += loops_per_jiffy;
  174. seq_printf(m, "total bogomips\t: %lu.%02lu\n",
  175. bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
  176. #endif /* CONFIG_SMP && CONFIG_PPC32 */
  177. seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
  178. if (ppc_md.name)
  179. seq_printf(m, "platform\t: %s\n", ppc_md.name);
  180. root = of_find_node_by_path("/");
  181. if (root)
  182. model = of_get_property(root, "model", NULL);
  183. if (model)
  184. seq_printf(m, "model\t\t: %s\n", model);
  185. of_node_put(root);
  186. if (ppc_md.show_cpuinfo != NULL)
  187. ppc_md.show_cpuinfo(m);
  188. #ifdef CONFIG_PPC32
  189. /* Display the amount of memory */
  190. seq_printf(m, "Memory\t\t: %d MB\n",
  191. (unsigned int)(total_memory / (1024 * 1024)));
  192. #endif
  193. }
  194. static int show_cpuinfo(struct seq_file *m, void *v)
  195. {
  196. unsigned long cpu_id = (unsigned long)v - 1;
  197. unsigned int pvr;
  198. unsigned long proc_freq;
  199. unsigned short maj;
  200. unsigned short min;
  201. #ifdef CONFIG_SMP
  202. pvr = per_cpu(cpu_pvr, cpu_id);
  203. #else
  204. pvr = mfspr(SPRN_PVR);
  205. #endif
  206. maj = (pvr >> 8) & 0xFF;
  207. min = pvr & 0xFF;
  208. seq_printf(m, "processor\t: %lu\n", cpu_id);
  209. seq_printf(m, "cpu\t\t: ");
  210. if (cur_cpu_spec->pvr_mask)
  211. seq_printf(m, "%s", cur_cpu_spec->cpu_name);
  212. else
  213. seq_printf(m, "unknown (%08x)", pvr);
  214. #ifdef CONFIG_ALTIVEC
  215. if (cpu_has_feature(CPU_FTR_ALTIVEC))
  216. seq_printf(m, ", altivec supported");
  217. #endif /* CONFIG_ALTIVEC */
  218. seq_printf(m, "\n");
  219. #ifdef CONFIG_TAU
  220. if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
  221. #ifdef CONFIG_TAU_AVERAGE
  222. /* more straightforward, but potentially misleading */
  223. seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
  224. cpu_temp(cpu_id));
  225. #else
  226. /* show the actual temp sensor range */
  227. u32 temp;
  228. temp = cpu_temp_both(cpu_id);
  229. seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
  230. temp & 0xff, temp >> 16);
  231. #endif
  232. }
  233. #endif /* CONFIG_TAU */
  234. /*
  235. * Platforms that have variable clock rates, should implement
  236. * the method ppc_md.get_proc_freq() that reports the clock
  237. * rate of a given cpu. The rest can use ppc_proc_freq to
  238. * report the clock rate that is same across all cpus.
  239. */
  240. if (ppc_md.get_proc_freq)
  241. proc_freq = ppc_md.get_proc_freq(cpu_id);
  242. else
  243. proc_freq = ppc_proc_freq;
  244. if (proc_freq)
  245. seq_printf(m, "clock\t\t: %lu.%06luMHz\n",
  246. proc_freq / 1000000, proc_freq % 1000000);
  247. if (ppc_md.show_percpuinfo != NULL)
  248. ppc_md.show_percpuinfo(m, cpu_id);
  249. /* If we are a Freescale core do a simple check so
  250. * we dont have to keep adding cases in the future */
  251. if (PVR_VER(pvr) & 0x8000) {
  252. switch (PVR_VER(pvr)) {
  253. case 0x8000: /* 7441/7450/7451, Voyager */
  254. case 0x8001: /* 7445/7455, Apollo 6 */
  255. case 0x8002: /* 7447/7457, Apollo 7 */
  256. case 0x8003: /* 7447A, Apollo 7 PM */
  257. case 0x8004: /* 7448, Apollo 8 */
  258. case 0x800c: /* 7410, Nitro */
  259. maj = ((pvr >> 8) & 0xF);
  260. min = PVR_MIN(pvr);
  261. break;
  262. default: /* e500/book-e */
  263. maj = PVR_MAJ(pvr);
  264. min = PVR_MIN(pvr);
  265. break;
  266. }
  267. } else {
  268. switch (PVR_VER(pvr)) {
  269. case 0x0020: /* 403 family */
  270. maj = PVR_MAJ(pvr) + 1;
  271. min = PVR_MIN(pvr);
  272. break;
  273. case 0x1008: /* 740P/750P ?? */
  274. maj = ((pvr >> 8) & 0xFF) - 1;
  275. min = pvr & 0xFF;
  276. break;
  277. default:
  278. maj = (pvr >> 8) & 0xFF;
  279. min = pvr & 0xFF;
  280. break;
  281. }
  282. }
  283. seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
  284. maj, min, PVR_VER(pvr), PVR_REV(pvr));
  285. #ifdef CONFIG_PPC32
  286. seq_printf(m, "bogomips\t: %lu.%02lu\n",
  287. loops_per_jiffy / (500000/HZ),
  288. (loops_per_jiffy / (5000/HZ)) % 100);
  289. #endif
  290. #ifdef CONFIG_SMP
  291. seq_printf(m, "\n");
  292. #endif
  293. /* If this is the last cpu, print the summary */
  294. if (cpumask_next(cpu_id, cpu_online_mask) >= nr_cpu_ids)
  295. show_cpuinfo_summary(m);
  296. return 0;
  297. }
  298. static void *c_start(struct seq_file *m, loff_t *pos)
  299. {
  300. if (*pos == 0) /* just in case, cpu 0 is not the first */
  301. *pos = cpumask_first(cpu_online_mask);
  302. else
  303. *pos = cpumask_next(*pos - 1, cpu_online_mask);
  304. if ((*pos) < nr_cpu_ids)
  305. return (void *)(unsigned long)(*pos + 1);
  306. return NULL;
  307. }
  308. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  309. {
  310. (*pos)++;
  311. return c_start(m, pos);
  312. }
  313. static void c_stop(struct seq_file *m, void *v)
  314. {
  315. }
  316. const struct seq_operations cpuinfo_op = {
  317. .start =c_start,
  318. .next = c_next,
  319. .stop = c_stop,
  320. .show = show_cpuinfo,
  321. };
  322. void __init check_for_initrd(void)
  323. {
  324. #ifdef CONFIG_BLK_DEV_INITRD
  325. DBG(" -> check_for_initrd() initrd_start=0x%lx initrd_end=0x%lx\n",
  326. initrd_start, initrd_end);
  327. /* If we were passed an initrd, set the ROOT_DEV properly if the values
  328. * look sensible. If not, clear initrd reference.
  329. */
  330. if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) &&
  331. initrd_end > initrd_start)
  332. ROOT_DEV = Root_RAM0;
  333. else
  334. initrd_start = initrd_end = 0;
  335. if (initrd_start)
  336. pr_info("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
  337. DBG(" <- check_for_initrd()\n");
  338. #endif /* CONFIG_BLK_DEV_INITRD */
  339. }
  340. #ifdef CONFIG_SMP
  341. int threads_per_core, threads_per_subcore, threads_shift;
  342. cpumask_t threads_core_mask;
  343. EXPORT_SYMBOL_GPL(threads_per_core);
  344. EXPORT_SYMBOL_GPL(threads_per_subcore);
  345. EXPORT_SYMBOL_GPL(threads_shift);
  346. EXPORT_SYMBOL_GPL(threads_core_mask);
  347. static void __init cpu_init_thread_core_maps(int tpc)
  348. {
  349. int i;
  350. threads_per_core = tpc;
  351. threads_per_subcore = tpc;
  352. cpumask_clear(&threads_core_mask);
  353. /* This implementation only supports power of 2 number of threads
  354. * for simplicity and performance
  355. */
  356. threads_shift = ilog2(tpc);
  357. BUG_ON(tpc != (1 << threads_shift));
  358. for (i = 0; i < tpc; i++)
  359. cpumask_set_cpu(i, &threads_core_mask);
  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. * setup_cpu_maps - initialize the following cpu maps:
  366. * cpu_possible_mask
  367. * cpu_present_mask
  368. *
  369. * Having the possible map set up early allows us to restrict allocations
  370. * of things like irqstacks to nr_cpu_ids rather than NR_CPUS.
  371. *
  372. * We do not initialize the online map here; cpus set their own bits in
  373. * cpu_online_mask as they come up.
  374. *
  375. * This function is valid only for Open Firmware systems. finish_device_tree
  376. * must be called before using this.
  377. *
  378. * While we're here, we may as well set the "physical" cpu ids in the paca.
  379. *
  380. * NOTE: This must match the parsing done in early_init_dt_scan_cpus.
  381. */
  382. void __init smp_setup_cpu_maps(void)
  383. {
  384. struct device_node *dn = NULL;
  385. int cpu = 0;
  386. int nthreads = 1;
  387. DBG("smp_setup_cpu_maps()\n");
  388. while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < nr_cpu_ids) {
  389. const __be32 *intserv;
  390. __be32 cpu_be;
  391. int j, len;
  392. DBG(" * %s...\n", dn->full_name);
  393. intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s",
  394. &len);
  395. if (intserv) {
  396. DBG(" ibm,ppc-interrupt-server#s -> %d threads\n",
  397. nthreads);
  398. } else {
  399. DBG(" no ibm,ppc-interrupt-server#s -> 1 thread\n");
  400. intserv = of_get_property(dn, "reg", &len);
  401. if (!intserv) {
  402. cpu_be = cpu_to_be32(cpu);
  403. intserv = &cpu_be; /* assume logical == phys */
  404. len = 4;
  405. }
  406. }
  407. nthreads = len / sizeof(int);
  408. for (j = 0; j < nthreads && cpu < nr_cpu_ids; j++) {
  409. bool avail;
  410. DBG(" thread %d -> cpu %d (hard id %d)\n",
  411. j, cpu, be32_to_cpu(intserv[j]));
  412. avail = of_device_is_available(dn);
  413. if (!avail)
  414. avail = !of_property_match_string(dn,
  415. "enable-method", "spin-table");
  416. set_cpu_present(cpu, avail);
  417. set_hard_smp_processor_id(cpu, be32_to_cpu(intserv[j]));
  418. set_cpu_possible(cpu, true);
  419. cpu++;
  420. }
  421. }
  422. /* 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. #ifdef CONFIG_PPC64
  428. /*
  429. * On pSeries LPAR, we need to know how many cpus
  430. * could possibly be added to this partition.
  431. */
  432. if (firmware_has_feature(FW_FEATURE_LPAR) &&
  433. (dn = of_find_node_by_path("/rtas"))) {
  434. int num_addr_cell, num_size_cell, maxcpus;
  435. const __be32 *ireg;
  436. num_addr_cell = of_n_addr_cells(dn);
  437. num_size_cell = of_n_size_cells(dn);
  438. ireg = of_get_property(dn, "ibm,lrdr-capacity", NULL);
  439. if (!ireg)
  440. goto out;
  441. maxcpus = be32_to_cpup(ireg + num_addr_cell + num_size_cell);
  442. /* Double maxcpus for processors which have SMT capability */
  443. if (cpu_has_feature(CPU_FTR_SMT))
  444. maxcpus *= nthreads;
  445. if (maxcpus > nr_cpu_ids) {
  446. printk(KERN_WARNING
  447. "Partition configured for %d cpus, "
  448. "operating system maximum is %d.\n",
  449. maxcpus, nr_cpu_ids);
  450. maxcpus = nr_cpu_ids;
  451. } else
  452. printk(KERN_INFO "Partition configured for %d cpus.\n",
  453. maxcpus);
  454. for (cpu = 0; cpu < maxcpus; cpu++)
  455. set_cpu_possible(cpu, true);
  456. out:
  457. of_node_put(dn);
  458. }
  459. vdso_data->processorCount = num_present_cpus();
  460. #endif /* CONFIG_PPC64 */
  461. /* Initialize CPU <=> thread mapping/
  462. *
  463. * WARNING: We assume that the number of threads is the same for
  464. * every CPU in the system. If that is not the case, then some code
  465. * here will have to be reworked
  466. */
  467. cpu_init_thread_core_maps(nthreads);
  468. /* Now that possible cpus are set, set nr_cpu_ids for later use */
  469. setup_nr_cpu_ids();
  470. free_unused_pacas();
  471. }
  472. #endif /* CONFIG_SMP */
  473. #ifdef CONFIG_PCSPKR_PLATFORM
  474. static __init int add_pcspkr(void)
  475. {
  476. struct device_node *np;
  477. struct platform_device *pd;
  478. int ret;
  479. np = of_find_compatible_node(NULL, NULL, "pnpPNP,100");
  480. of_node_put(np);
  481. if (!np)
  482. return -ENODEV;
  483. pd = platform_device_alloc("pcspkr", -1);
  484. if (!pd)
  485. return -ENOMEM;
  486. ret = platform_device_add(pd);
  487. if (ret)
  488. platform_device_put(pd);
  489. return ret;
  490. }
  491. device_initcall(add_pcspkr);
  492. #endif /* CONFIG_PCSPKR_PLATFORM */
  493. void probe_machine(void)
  494. {
  495. extern struct machdep_calls __machine_desc_start;
  496. extern struct machdep_calls __machine_desc_end;
  497. unsigned int i;
  498. /*
  499. * Iterate all ppc_md structures until we find the proper
  500. * one for the current machine type
  501. */
  502. DBG("Probing machine type ...\n");
  503. /*
  504. * Check ppc_md is empty, if not we have a bug, ie, we setup an
  505. * entry before probe_machine() which will be overwritten
  506. */
  507. for (i = 0; i < (sizeof(ppc_md) / sizeof(void *)); i++) {
  508. if (((void **)&ppc_md)[i]) {
  509. printk(KERN_ERR "Entry %d in ppc_md non empty before"
  510. " machine probe !\n", i);
  511. }
  512. }
  513. for (machine_id = &__machine_desc_start;
  514. machine_id < &__machine_desc_end;
  515. machine_id++) {
  516. DBG(" %s ...", machine_id->name);
  517. memcpy(&ppc_md, machine_id, sizeof(struct machdep_calls));
  518. if (ppc_md.probe()) {
  519. DBG(" match !\n");
  520. break;
  521. }
  522. DBG("\n");
  523. }
  524. /* What can we do if we didn't find ? */
  525. if (machine_id >= &__machine_desc_end) {
  526. DBG("No suitable machine found !\n");
  527. for (;;);
  528. }
  529. printk(KERN_INFO "Using %s machine description\n", ppc_md.name);
  530. }
  531. /* Match a class of boards, not a specific device configuration. */
  532. int check_legacy_ioport(unsigned long base_port)
  533. {
  534. struct device_node *parent, *np = NULL;
  535. int ret = -ENODEV;
  536. switch(base_port) {
  537. case I8042_DATA_REG:
  538. if (!(np = of_find_compatible_node(NULL, NULL, "pnpPNP,303")))
  539. np = of_find_compatible_node(NULL, NULL, "pnpPNP,f03");
  540. if (np) {
  541. parent = of_get_parent(np);
  542. of_i8042_kbd_irq = irq_of_parse_and_map(parent, 0);
  543. if (!of_i8042_kbd_irq)
  544. of_i8042_kbd_irq = 1;
  545. of_i8042_aux_irq = irq_of_parse_and_map(parent, 1);
  546. if (!of_i8042_aux_irq)
  547. of_i8042_aux_irq = 12;
  548. of_node_put(np);
  549. np = parent;
  550. break;
  551. }
  552. np = of_find_node_by_type(NULL, "8042");
  553. /* Pegasos has no device_type on its 8042 node, look for the
  554. * name instead */
  555. if (!np)
  556. np = of_find_node_by_name(NULL, "8042");
  557. if (np) {
  558. of_i8042_kbd_irq = 1;
  559. of_i8042_aux_irq = 12;
  560. }
  561. break;
  562. case FDC_BASE: /* FDC1 */
  563. np = of_find_node_by_type(NULL, "fdc");
  564. break;
  565. default:
  566. /* ipmi is supposed to fail here */
  567. break;
  568. }
  569. if (!np)
  570. return ret;
  571. parent = of_get_parent(np);
  572. if (parent) {
  573. if (strcmp(parent->type, "isa") == 0)
  574. ret = 0;
  575. of_node_put(parent);
  576. }
  577. of_node_put(np);
  578. return ret;
  579. }
  580. EXPORT_SYMBOL(check_legacy_ioport);
  581. static int ppc_panic_event(struct notifier_block *this,
  582. unsigned long event, void *ptr)
  583. {
  584. /*
  585. * If firmware-assisted dump has been registered then trigger
  586. * firmware-assisted dump and let firmware handle everything else.
  587. */
  588. crash_fadump(NULL, ptr);
  589. ppc_md.panic(ptr); /* May not return */
  590. return NOTIFY_DONE;
  591. }
  592. static struct notifier_block ppc_panic_block = {
  593. .notifier_call = ppc_panic_event,
  594. .priority = INT_MIN /* may not return; must be done last */
  595. };
  596. void __init setup_panic(void)
  597. {
  598. if (!ppc_md.panic)
  599. return;
  600. atomic_notifier_chain_register(&panic_notifier_list, &ppc_panic_block);
  601. }
  602. #ifdef CONFIG_CHECK_CACHE_COHERENCY
  603. /*
  604. * For platforms that have configurable cache-coherency. This function
  605. * checks that the cache coherency setting of the kernel matches the setting
  606. * left by the firmware, as indicated in the device tree. Since a mismatch
  607. * will eventually result in DMA failures, we print * and error and call
  608. * BUG() in that case.
  609. */
  610. #ifdef CONFIG_NOT_COHERENT_CACHE
  611. #define KERNEL_COHERENCY 0
  612. #else
  613. #define KERNEL_COHERENCY 1
  614. #endif
  615. static int __init check_cache_coherency(void)
  616. {
  617. struct device_node *np;
  618. const void *prop;
  619. int devtree_coherency;
  620. np = of_find_node_by_path("/");
  621. prop = of_get_property(np, "coherency-off", NULL);
  622. of_node_put(np);
  623. devtree_coherency = prop ? 0 : 1;
  624. if (devtree_coherency != KERNEL_COHERENCY) {
  625. printk(KERN_ERR
  626. "kernel coherency:%s != device tree_coherency:%s\n",
  627. KERNEL_COHERENCY ? "on" : "off",
  628. devtree_coherency ? "on" : "off");
  629. BUG();
  630. }
  631. return 0;
  632. }
  633. late_initcall(check_cache_coherency);
  634. #endif /* CONFIG_CHECK_CACHE_COHERENCY */
  635. #ifdef CONFIG_DEBUG_FS
  636. struct dentry *powerpc_debugfs_root;
  637. EXPORT_SYMBOL(powerpc_debugfs_root);
  638. static int powerpc_debugfs_init(void)
  639. {
  640. powerpc_debugfs_root = debugfs_create_dir("powerpc", NULL);
  641. return powerpc_debugfs_root == NULL;
  642. }
  643. arch_initcall(powerpc_debugfs_init);
  644. #endif
  645. void ppc_printk_progress(char *s, unsigned short hex)
  646. {
  647. pr_info("%s\n", s);
  648. }
  649. void arch_setup_pdev_archdata(struct platform_device *pdev)
  650. {
  651. pdev->archdata.dma_mask = DMA_BIT_MASK(32);
  652. pdev->dev.dma_mask = &pdev->archdata.dma_mask;
  653. set_dma_ops(&pdev->dev, &dma_direct_ops);
  654. }
  655. static __init void print_system_info(void)
  656. {
  657. pr_info("-----------------------------------------------------\n");
  658. #ifdef CONFIG_PPC_STD_MMU_64
  659. pr_info("ppc64_pft_size = 0x%llx\n", ppc64_pft_size);
  660. #endif
  661. #ifdef CONFIG_PPC_STD_MMU_32
  662. pr_info("Hash_size = 0x%lx\n", Hash_size);
  663. #endif
  664. pr_info("phys_mem_size = 0x%llx\n",
  665. (unsigned long long)memblock_phys_mem_size());
  666. pr_info("dcache_bsize = 0x%x\n", dcache_bsize);
  667. pr_info("icache_bsize = 0x%x\n", icache_bsize);
  668. if (ucache_bsize != 0)
  669. pr_info("ucache_bsize = 0x%x\n", ucache_bsize);
  670. pr_info("cpu_features = 0x%016lx\n", cur_cpu_spec->cpu_features);
  671. pr_info(" possible = 0x%016lx\n",
  672. (unsigned long)CPU_FTRS_POSSIBLE);
  673. pr_info(" always = 0x%016lx\n",
  674. (unsigned long)CPU_FTRS_ALWAYS);
  675. pr_info("cpu_user_features = 0x%08x 0x%08x\n",
  676. cur_cpu_spec->cpu_user_features,
  677. cur_cpu_spec->cpu_user_features2);
  678. pr_info("mmu_features = 0x%08x\n", cur_cpu_spec->mmu_features);
  679. #ifdef CONFIG_PPC64
  680. pr_info("firmware_features = 0x%016lx\n", powerpc_firmware_features);
  681. #endif
  682. #ifdef CONFIG_PPC_STD_MMU_64
  683. if (htab_address)
  684. pr_info("htab_address = 0x%p\n", htab_address);
  685. if (htab_hash_mask)
  686. pr_info("htab_hash_mask = 0x%lx\n", htab_hash_mask);
  687. #endif
  688. #ifdef CONFIG_PPC_STD_MMU_32
  689. if (Hash)
  690. pr_info("Hash = 0x%p\n", Hash);
  691. if (Hash_mask)
  692. pr_info("Hash_mask = 0x%lx\n", Hash_mask);
  693. #endif
  694. if (PHYSICAL_START > 0)
  695. pr_info("physical_start = 0x%llx\n",
  696. (unsigned long long)PHYSICAL_START);
  697. pr_info("-----------------------------------------------------\n");
  698. }
  699. /*
  700. * Called into from start_kernel this initializes memblock, which is used
  701. * to manage page allocation until mem_init is called.
  702. */
  703. void __init setup_arch(char **cmdline_p)
  704. {
  705. *cmdline_p = boot_command_line;
  706. /* Set a half-reasonable default so udelay does something sensible */
  707. loops_per_jiffy = 500000000 / HZ;
  708. /* Unflatten the device-tree passed by prom_init or kexec */
  709. unflatten_device_tree();
  710. /*
  711. * Initialize cache line/block info from device-tree (on ppc64) or
  712. * just cputable (on ppc32).
  713. */
  714. initialize_cache_info();
  715. /* Initialize RTAS if available. */
  716. rtas_initialize();
  717. /* Check if we have an initrd provided via the device-tree. */
  718. check_for_initrd();
  719. /* Probe the machine type, establish ppc_md. */
  720. probe_machine();
  721. /* Setup panic notifier if requested by the platform. */
  722. setup_panic();
  723. /*
  724. * Configure ppc_md.power_save (ppc32 only, 64-bit machines do
  725. * it from their respective probe() function.
  726. */
  727. setup_power_save();
  728. /* Discover standard serial ports. */
  729. find_legacy_serial_ports();
  730. /* Register early console with the printk subsystem. */
  731. register_early_udbg_console();
  732. /* Setup the various CPU maps based on the device-tree. */
  733. smp_setup_cpu_maps();
  734. /* Initialize xmon. */
  735. xmon_setup();
  736. /* Check the SMT related command line arguments (ppc64). */
  737. check_smt_enabled();
  738. /* On BookE, setup per-core TLB data structures. */
  739. setup_tlb_core_data();
  740. /*
  741. * Release secondary cpus out of their spinloops at 0x60 now that
  742. * we can map physical -> logical CPU ids.
  743. *
  744. * Freescale Book3e parts spin in a loop provided by firmware,
  745. * so smp_release_cpus() does nothing for them.
  746. */
  747. #ifdef CONFIG_SMP
  748. smp_release_cpus();
  749. #endif
  750. /* Print various info about the machine that has been gathered so far. */
  751. print_system_info();
  752. /* Reserve large chunks of memory for use by CMA for KVM. */
  753. kvm_cma_reserve();
  754. /*
  755. * Reserve any gigantic pages requested on the command line.
  756. * memblock needs to have been initialized by the time this is
  757. * called since this will reserve memory.
  758. */
  759. reserve_hugetlb_gpages();
  760. klp_init_thread_info(&init_thread_info);
  761. init_mm.start_code = (unsigned long)_stext;
  762. init_mm.end_code = (unsigned long) _etext;
  763. init_mm.end_data = (unsigned long) _edata;
  764. init_mm.brk = klimit;
  765. #ifdef CONFIG_PPC_64K_PAGES
  766. init_mm.context.pte_frag = NULL;
  767. #endif
  768. #ifdef CONFIG_SPAPR_TCE_IOMMU
  769. mm_iommu_init(&init_mm);
  770. #endif
  771. irqstack_early_init();
  772. exc_lvl_early_init();
  773. emergency_stack_init();
  774. initmem_init();
  775. #ifdef CONFIG_DUMMY_CONSOLE
  776. conswitchp = &dummy_con;
  777. #endif
  778. if (ppc_md.setup_arch)
  779. ppc_md.setup_arch();
  780. paging_init();
  781. /* Initialize the MMU context management stuff. */
  782. mmu_context_init();
  783. #ifdef CONFIG_PPC64
  784. /* Interrupt code needs to be 64K-aligned. */
  785. if ((unsigned long)_stext & 0xffff)
  786. panic("Kernelbase not 64K-aligned (0x%lx)!\n",
  787. (unsigned long)_stext);
  788. #endif
  789. }