setup-common.c 24 KB

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