setup-common.c 23 KB

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