setup-common.c 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Common boot and setup code for both 32-bit and 64-bit.
  4. * Extracted from arch/powerpc/kernel/setup_64.c.
  5. *
  6. * Copyright (C) 2001 PPC64 Team, IBM Corp
  7. */
  8. #undef DEBUG
  9. #include <linux/export.h>
  10. #include <linux/panic_notifier.h>
  11. #include <linux/string.h>
  12. #include <linux/sched.h>
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/reboot.h>
  16. #include <linux/delay.h>
  17. #include <linux/initrd.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/printk.h>
  20. #include <linux/seq_file.h>
  21. #include <linux/ioport.h>
  22. #include <linux/console.h>
  23. #include <linux/screen_info.h>
  24. #include <linux/root_dev.h>
  25. #include <linux/cpu.h>
  26. #include <linux/unistd.h>
  27. #include <linux/seq_buf.h>
  28. #include <linux/serial.h>
  29. #include <linux/serial_8250.h>
  30. #include <linux/percpu.h>
  31. #include <linux/memblock.h>
  32. #include <linux/of_irq.h>
  33. #include <linux/of_fdt.h>
  34. #include <linux/of_platform.h>
  35. #include <linux/hugetlb.h>
  36. #include <linux/pgtable.h>
  37. #include <asm/io.h>
  38. #include <asm/paca.h>
  39. #include <asm/processor.h>
  40. #include <asm/vdso_datapage.h>
  41. #include <asm/smp.h>
  42. #include <asm/elf.h>
  43. #include <asm/machdep.h>
  44. #include <asm/time.h>
  45. #include <asm/cputable.h>
  46. #include <asm/sections.h>
  47. #include <asm/firmware.h>
  48. #include <asm/btext.h>
  49. #include <asm/nvram.h>
  50. #include <asm/setup.h>
  51. #include <asm/rtas.h>
  52. #include <asm/iommu.h>
  53. #include <asm/serial.h>
  54. #include <asm/cache.h>
  55. #include <asm/page.h>
  56. #include <asm/mmu.h>
  57. #include <asm/xmon.h>
  58. #include <asm/cputhreads.h>
  59. #include <mm/mmu_decl.h>
  60. #include <asm/fadump.h>
  61. #include <asm/udbg.h>
  62. #include <asm/hugetlb.h>
  63. #include <asm/livepatch.h>
  64. #include <asm/mmu_context.h>
  65. #include <asm/cpu_has_feature.h>
  66. #include <asm/kasan.h>
  67. #include <asm/mce.h>
  68. #include "setup.h"
  69. #ifdef DEBUG
  70. #define DBG(fmt...) udbg_printf(fmt)
  71. #else
  72. #define DBG(fmt...)
  73. #endif
  74. /* The main machine-dep calls structure
  75. */
  76. struct machdep_calls ppc_md;
  77. EXPORT_SYMBOL(ppc_md);
  78. struct machdep_calls *machine_id;
  79. EXPORT_SYMBOL(machine_id);
  80. int boot_cpuid = -1;
  81. EXPORT_SYMBOL_GPL(boot_cpuid);
  82. #ifdef CONFIG_PPC64
  83. int boot_cpu_hwid = -1;
  84. #endif
  85. /*
  86. * These are used in binfmt_elf.c to put aux entries on the stack
  87. * for each elf executable being started.
  88. */
  89. int dcache_bsize;
  90. int icache_bsize;
  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. /*
  123. * if fadump is active, cleanup the fadump registration before we
  124. * shutdown.
  125. */
  126. fadump_cleanup();
  127. if (ppc_md.machine_shutdown)
  128. ppc_md.machine_shutdown();
  129. }
  130. static void machine_hang(void)
  131. {
  132. pr_emerg("System Halted, OK to turn off power\n");
  133. local_irq_disable();
  134. while (1)
  135. ;
  136. }
  137. void machine_restart(char *cmd)
  138. {
  139. machine_shutdown();
  140. if (ppc_md.restart)
  141. ppc_md.restart(cmd);
  142. smp_send_stop();
  143. do_kernel_restart(cmd);
  144. mdelay(1000);
  145. machine_hang();
  146. }
  147. void machine_power_off(void)
  148. {
  149. machine_shutdown();
  150. do_kernel_power_off();
  151. smp_send_stop();
  152. machine_hang();
  153. }
  154. /* Used by the G5 thermal driver */
  155. EXPORT_SYMBOL_GPL(machine_power_off);
  156. void (*pm_power_off)(void);
  157. EXPORT_SYMBOL_GPL(pm_power_off);
  158. size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs)
  159. {
  160. if (max_longs && ppc_md.get_random_seed && ppc_md.get_random_seed(v))
  161. return 1;
  162. return 0;
  163. }
  164. EXPORT_SYMBOL(arch_get_random_seed_longs);
  165. void machine_halt(void)
  166. {
  167. machine_shutdown();
  168. if (ppc_md.halt)
  169. ppc_md.halt();
  170. smp_send_stop();
  171. machine_hang();
  172. }
  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. unsigned long bogosum = 0;
  181. int i;
  182. if (IS_ENABLED(CONFIG_SMP) && IS_ENABLED(CONFIG_PPC32)) {
  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. }
  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. /* Display the amount of memory */
  200. if (IS_ENABLED(CONFIG_PPC32))
  201. seq_printf(m, "Memory\t\t: %d MB\n",
  202. (unsigned int)(total_memory / (1024 * 1024)));
  203. }
  204. static int show_cpuinfo(struct seq_file *m, void *v)
  205. {
  206. unsigned long cpu_id = (unsigned long)v - 1;
  207. unsigned int pvr;
  208. unsigned long proc_freq;
  209. unsigned short maj;
  210. unsigned short min;
  211. #ifdef CONFIG_SMP
  212. pvr = per_cpu(cpu_pvr, cpu_id);
  213. #else
  214. pvr = mfspr(SPRN_PVR);
  215. #endif
  216. maj = (pvr >> 8) & 0xFF;
  217. min = pvr & 0xFF;
  218. seq_printf(m, "processor\t: %lu\ncpu\t\t: ", cpu_id);
  219. if (cur_cpu_spec->pvr_mask && cur_cpu_spec->cpu_name)
  220. seq_puts(m, cur_cpu_spec->cpu_name);
  221. else
  222. seq_printf(m, "unknown (%08x)", pvr);
  223. if (cpu_has_feature(CPU_FTR_ALTIVEC))
  224. seq_puts(m, ", altivec supported");
  225. seq_putc(m, '\n');
  226. #ifdef CONFIG_TAU
  227. if (cpu_has_feature(CPU_FTR_TAU)) {
  228. if (IS_ENABLED(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. }
  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 we are a Freescale core do a simple check so
  255. * we don't have to keep adding cases in the future */
  256. if (PVR_VER(pvr) & 0x8000) {
  257. switch (PVR_VER(pvr)) {
  258. case 0x8000: /* 7441/7450/7451, Voyager */
  259. case 0x8001: /* 7445/7455, Apollo 6 */
  260. case 0x8002: /* 7447/7457, Apollo 7 */
  261. case 0x8003: /* 7447A, Apollo 7 PM */
  262. case 0x8004: /* 7448, Apollo 8 */
  263. case 0x800c: /* 7410, Nitro */
  264. maj = ((pvr >> 8) & 0xF);
  265. min = PVR_MIN(pvr);
  266. break;
  267. default: /* e500/book-e */
  268. maj = PVR_MAJ(pvr);
  269. min = PVR_MIN(pvr);
  270. break;
  271. }
  272. } else {
  273. switch (PVR_VER(pvr)) {
  274. case 0x1008: /* 740P/750P ?? */
  275. maj = ((pvr >> 8) & 0xFF) - 1;
  276. min = pvr & 0xFF;
  277. break;
  278. case 0x004e: /* POWER9 bits 12-15 give chip type */
  279. case 0x0080: /* POWER10 bit 12 gives SMT8/4 */
  280. maj = (pvr >> 8) & 0x0F;
  281. min = pvr & 0xFF;
  282. break;
  283. default:
  284. maj = (pvr >> 8) & 0xFF;
  285. min = pvr & 0xFF;
  286. break;
  287. }
  288. }
  289. seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
  290. maj, min, PVR_VER(pvr), PVR_REV(pvr));
  291. if (IS_ENABLED(CONFIG_PPC32))
  292. seq_printf(m, "bogomips\t: %lu.%02lu\n", loops_per_jiffy / (500000 / HZ),
  293. (loops_per_jiffy / (5000 / HZ)) % 100);
  294. seq_putc(m, '\n');
  295. /* If this is the last cpu, print the summary */
  296. if (cpumask_next(cpu_id, cpu_online_mask) >= nr_cpu_ids)
  297. show_cpuinfo_summary(m);
  298. return 0;
  299. }
  300. static void *c_start(struct seq_file *m, loff_t *pos)
  301. {
  302. if (*pos == 0) /* just in case, cpu 0 is not the first */
  303. *pos = cpumask_first(cpu_online_mask);
  304. else
  305. *pos = cpumask_next(*pos - 1, cpu_online_mask);
  306. if ((*pos) < nr_cpu_ids)
  307. return (void *)(unsigned long)(*pos + 1);
  308. return NULL;
  309. }
  310. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  311. {
  312. (*pos)++;
  313. return c_start(m, pos);
  314. }
  315. static void c_stop(struct seq_file *m, void *v)
  316. {
  317. }
  318. const struct seq_operations cpuinfo_op = {
  319. .start = c_start,
  320. .next = c_next,
  321. .stop = c_stop,
  322. .show = show_cpuinfo,
  323. };
  324. void __init check_for_initrd(void)
  325. {
  326. #ifdef CONFIG_BLK_DEV_INITRD
  327. DBG(" -> check_for_initrd() initrd_start=0x%lx initrd_end=0x%lx\n",
  328. initrd_start, initrd_end);
  329. /* If we were passed an initrd, set the ROOT_DEV properly if the values
  330. * look sensible. If not, clear initrd reference.
  331. */
  332. if (is_kernel_addr(initrd_start) && is_kernel_addr(initrd_end) &&
  333. initrd_end > initrd_start)
  334. ROOT_DEV = Root_RAM0;
  335. else
  336. initrd_start = initrd_end = 0;
  337. if (initrd_start)
  338. pr_info("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
  339. DBG(" <- check_for_initrd()\n");
  340. #endif /* CONFIG_BLK_DEV_INITRD */
  341. }
  342. #ifdef CONFIG_SMP
  343. int threads_per_core, threads_per_subcore, threads_shift __read_mostly;
  344. cpumask_t threads_core_mask __read_mostly;
  345. EXPORT_SYMBOL_GPL(threads_per_core);
  346. EXPORT_SYMBOL_GPL(threads_per_subcore);
  347. EXPORT_SYMBOL_GPL(threads_shift);
  348. EXPORT_SYMBOL_GPL(threads_core_mask);
  349. static void __init cpu_init_thread_core_maps(int tpc)
  350. {
  351. int i;
  352. threads_per_core = tpc;
  353. threads_per_subcore = tpc;
  354. cpumask_clear(&threads_core_mask);
  355. /* This implementation only supports power of 2 number of threads
  356. * for simplicity and performance
  357. */
  358. threads_shift = ilog2(tpc);
  359. BUG_ON(tpc != (1 << threads_shift));
  360. for (i = 0; i < tpc; i++)
  361. cpumask_set_cpu(i, &threads_core_mask);
  362. printk(KERN_INFO "CPU maps initialized for %d thread%s per core\n",
  363. tpc, tpc > 1 ? "s" : "");
  364. printk(KERN_DEBUG " (thread shift is %d)\n", threads_shift);
  365. }
  366. u32 *cpu_to_phys_id = NULL;
  367. /**
  368. * setup_cpu_maps - initialize the following cpu maps:
  369. * cpu_possible_mask
  370. * cpu_present_mask
  371. *
  372. * Having the possible map set up early allows us to restrict allocations
  373. * of things like irqstacks to nr_cpu_ids rather than NR_CPUS.
  374. *
  375. * We do not initialize the online map here; cpus set their own bits in
  376. * cpu_online_mask as they come up.
  377. *
  378. * This function is valid only for Open Firmware systems. finish_device_tree
  379. * must be called before using this.
  380. *
  381. * While we're here, we may as well set the "physical" cpu ids in the paca.
  382. *
  383. * NOTE: This must match the parsing done in early_init_dt_scan_cpus.
  384. */
  385. void __init smp_setup_cpu_maps(void)
  386. {
  387. struct device_node *dn;
  388. int cpu = 0;
  389. int nthreads = 1;
  390. DBG("smp_setup_cpu_maps()\n");
  391. cpu_to_phys_id = memblock_alloc(nr_cpu_ids * sizeof(u32),
  392. __alignof__(u32));
  393. if (!cpu_to_phys_id)
  394. panic("%s: Failed to allocate %zu bytes align=0x%zx\n",
  395. __func__, nr_cpu_ids * sizeof(u32), __alignof__(u32));
  396. for_each_node_by_type(dn, "cpu") {
  397. const __be32 *intserv;
  398. __be32 cpu_be;
  399. int j, len;
  400. DBG(" * %pOF...\n", dn);
  401. intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s",
  402. &len);
  403. if (intserv) {
  404. DBG(" ibm,ppc-interrupt-server#s -> %lu threads\n",
  405. (len / sizeof(int)));
  406. } else {
  407. DBG(" no ibm,ppc-interrupt-server#s -> 1 thread\n");
  408. intserv = of_get_property(dn, "reg", &len);
  409. if (!intserv) {
  410. cpu_be = cpu_to_be32(cpu);
  411. /* XXX: what is this? uninitialized?? */
  412. intserv = &cpu_be; /* assume logical == phys */
  413. len = 4;
  414. }
  415. }
  416. nthreads = len / sizeof(int);
  417. for (j = 0; j < nthreads && cpu < nr_cpu_ids; j++) {
  418. bool avail;
  419. DBG(" thread %d -> cpu %d (hard id %d)\n",
  420. j, cpu, be32_to_cpu(intserv[j]));
  421. avail = of_device_is_available(dn);
  422. if (!avail)
  423. avail = !of_property_match_string(dn,
  424. "enable-method", "spin-table");
  425. set_cpu_present(cpu, avail);
  426. set_cpu_possible(cpu, true);
  427. cpu_to_phys_id[cpu] = be32_to_cpu(intserv[j]);
  428. cpu++;
  429. }
  430. if (cpu >= nr_cpu_ids) {
  431. of_node_put(dn);
  432. break;
  433. }
  434. }
  435. /* If no SMT supported, nthreads is forced to 1 */
  436. if (!cpu_has_feature(CPU_FTR_SMT)) {
  437. DBG(" SMT disabled ! nthreads forced to 1\n");
  438. nthreads = 1;
  439. }
  440. #ifdef CONFIG_PPC64
  441. /*
  442. * On pSeries LPAR, we need to know how many cpus
  443. * could possibly be added to this partition.
  444. */
  445. if (firmware_has_feature(FW_FEATURE_LPAR) &&
  446. (dn = of_find_node_by_path("/rtas"))) {
  447. int num_addr_cell, num_size_cell, maxcpus;
  448. const __be32 *ireg;
  449. num_addr_cell = of_n_addr_cells(dn);
  450. num_size_cell = of_n_size_cells(dn);
  451. ireg = of_get_property(dn, "ibm,lrdr-capacity", NULL);
  452. if (!ireg)
  453. goto out;
  454. maxcpus = be32_to_cpup(ireg + num_addr_cell + num_size_cell);
  455. /* Double maxcpus for processors which have SMT capability */
  456. if (cpu_has_feature(CPU_FTR_SMT))
  457. maxcpus *= nthreads;
  458. if (maxcpus > nr_cpu_ids) {
  459. printk(KERN_WARNING
  460. "Partition configured for %d cpus, "
  461. "operating system maximum is %u.\n",
  462. maxcpus, nr_cpu_ids);
  463. maxcpus = nr_cpu_ids;
  464. } else
  465. printk(KERN_INFO "Partition configured for %d cpus.\n",
  466. maxcpus);
  467. for (cpu = 0; cpu < maxcpus; cpu++)
  468. set_cpu_possible(cpu, true);
  469. out:
  470. of_node_put(dn);
  471. }
  472. vdso_data->processorCount = num_present_cpus();
  473. #endif /* CONFIG_PPC64 */
  474. /* Initialize CPU <=> thread mapping/
  475. *
  476. * WARNING: We assume that the number of threads is the same for
  477. * every CPU in the system. If that is not the case, then some code
  478. * here will have to be reworked
  479. */
  480. cpu_init_thread_core_maps(nthreads);
  481. /* Now that possible cpus are set, set nr_cpu_ids for later use */
  482. setup_nr_cpu_ids();
  483. free_unused_pacas();
  484. }
  485. #endif /* CONFIG_SMP */
  486. #ifdef CONFIG_PCSPKR_PLATFORM
  487. static __init int add_pcspkr(void)
  488. {
  489. struct device_node *np;
  490. struct platform_device *pd;
  491. int ret;
  492. np = of_find_compatible_node(NULL, NULL, "pnpPNP,100");
  493. of_node_put(np);
  494. if (!np)
  495. return -ENODEV;
  496. pd = platform_device_alloc("pcspkr", -1);
  497. if (!pd)
  498. return -ENOMEM;
  499. ret = platform_device_add(pd);
  500. if (ret)
  501. platform_device_put(pd);
  502. return ret;
  503. }
  504. device_initcall(add_pcspkr);
  505. #endif /* CONFIG_PCSPKR_PLATFORM */
  506. static char ppc_hw_desc_buf[128] __initdata;
  507. struct seq_buf ppc_hw_desc __initdata = {
  508. .buffer = ppc_hw_desc_buf,
  509. .size = sizeof(ppc_hw_desc_buf),
  510. .len = 0,
  511. .readpos = 0,
  512. };
  513. static __init void probe_machine(void)
  514. {
  515. extern struct machdep_calls __machine_desc_start;
  516. extern struct machdep_calls __machine_desc_end;
  517. unsigned int i;
  518. /*
  519. * Iterate all ppc_md structures until we find the proper
  520. * one for the current machine type
  521. */
  522. DBG("Probing machine type ...\n");
  523. /*
  524. * Check ppc_md is empty, if not we have a bug, ie, we setup an
  525. * entry before probe_machine() which will be overwritten
  526. */
  527. for (i = 0; i < (sizeof(ppc_md) / sizeof(void *)); i++) {
  528. if (((void **)&ppc_md)[i]) {
  529. printk(KERN_ERR "Entry %d in ppc_md non empty before"
  530. " machine probe !\n", i);
  531. }
  532. }
  533. for (machine_id = &__machine_desc_start;
  534. machine_id < &__machine_desc_end;
  535. machine_id++) {
  536. DBG(" %s ...", machine_id->name);
  537. memcpy(&ppc_md, machine_id, sizeof(struct machdep_calls));
  538. if (ppc_md.probe()) {
  539. DBG(" match !\n");
  540. break;
  541. }
  542. DBG("\n");
  543. }
  544. /* What can we do if we didn't find ? */
  545. if (machine_id >= &__machine_desc_end) {
  546. pr_err("No suitable machine description found !\n");
  547. for (;;);
  548. }
  549. // Append the machine name to other info we've gathered
  550. seq_buf_puts(&ppc_hw_desc, ppc_md.name);
  551. // Set the generic hardware description shown in oopses
  552. dump_stack_set_arch_desc(ppc_hw_desc.buffer);
  553. pr_info("Hardware name: %s\n", ppc_hw_desc.buffer);
  554. }
  555. /* Match a class of boards, not a specific device configuration. */
  556. int check_legacy_ioport(unsigned long base_port)
  557. {
  558. struct device_node *parent, *np = NULL;
  559. int ret = -ENODEV;
  560. switch(base_port) {
  561. case I8042_DATA_REG:
  562. if (!(np = of_find_compatible_node(NULL, NULL, "pnpPNP,303")))
  563. np = of_find_compatible_node(NULL, NULL, "pnpPNP,f03");
  564. if (np) {
  565. parent = of_get_parent(np);
  566. of_i8042_kbd_irq = irq_of_parse_and_map(parent, 0);
  567. if (!of_i8042_kbd_irq)
  568. of_i8042_kbd_irq = 1;
  569. of_i8042_aux_irq = irq_of_parse_and_map(parent, 1);
  570. if (!of_i8042_aux_irq)
  571. of_i8042_aux_irq = 12;
  572. of_node_put(np);
  573. np = parent;
  574. break;
  575. }
  576. np = of_find_node_by_type(NULL, "8042");
  577. /* Pegasos has no device_type on its 8042 node, look for the
  578. * name instead */
  579. if (!np)
  580. np = of_find_node_by_name(NULL, "8042");
  581. if (np) {
  582. of_i8042_kbd_irq = 1;
  583. of_i8042_aux_irq = 12;
  584. }
  585. break;
  586. case FDC_BASE: /* FDC1 */
  587. np = of_find_node_by_type(NULL, "fdc");
  588. break;
  589. default:
  590. /* ipmi is supposed to fail here */
  591. break;
  592. }
  593. if (!np)
  594. return ret;
  595. parent = of_get_parent(np);
  596. if (parent) {
  597. if (of_node_is_type(parent, "isa"))
  598. ret = 0;
  599. of_node_put(parent);
  600. }
  601. of_node_put(np);
  602. return ret;
  603. }
  604. EXPORT_SYMBOL(check_legacy_ioport);
  605. /*
  606. * Panic notifiers setup
  607. *
  608. * We have 3 notifiers for powerpc, each one from a different "nature":
  609. *
  610. * - ppc_panic_fadump_handler() is a hypervisor notifier, which hard-disables
  611. * IRQs and deal with the Firmware-Assisted dump, when it is configured;
  612. * should run early in the panic path.
  613. *
  614. * - dump_kernel_offset() is an informative notifier, just showing the KASLR
  615. * offset if we have RANDOMIZE_BASE set.
  616. *
  617. * - ppc_panic_platform_handler() is a low-level handler that's registered
  618. * only if the platform wishes to perform final actions in the panic path,
  619. * hence it should run late and might not even return. Currently, only
  620. * pseries and ps3 platforms register callbacks.
  621. */
  622. static int ppc_panic_fadump_handler(struct notifier_block *this,
  623. unsigned long event, void *ptr)
  624. {
  625. /*
  626. * panic does a local_irq_disable, but we really
  627. * want interrupts to be hard disabled.
  628. */
  629. hard_irq_disable();
  630. /*
  631. * If firmware-assisted dump has been registered then trigger
  632. * its callback and let the firmware handles everything else.
  633. */
  634. crash_fadump(NULL, ptr);
  635. return NOTIFY_DONE;
  636. }
  637. static int dump_kernel_offset(struct notifier_block *self, unsigned long v,
  638. void *p)
  639. {
  640. pr_emerg("Kernel Offset: 0x%lx from 0x%lx\n",
  641. kaslr_offset(), KERNELBASE);
  642. return NOTIFY_DONE;
  643. }
  644. static int ppc_panic_platform_handler(struct notifier_block *this,
  645. unsigned long event, void *ptr)
  646. {
  647. /*
  648. * This handler is only registered if we have a panic callback
  649. * on ppc_md, hence NULL check is not needed.
  650. * Also, it may not return, so it runs really late on panic path.
  651. */
  652. ppc_md.panic(ptr);
  653. return NOTIFY_DONE;
  654. }
  655. static struct notifier_block ppc_fadump_block = {
  656. .notifier_call = ppc_panic_fadump_handler,
  657. .priority = INT_MAX, /* run early, to notify the firmware ASAP */
  658. };
  659. static struct notifier_block kernel_offset_notifier = {
  660. .notifier_call = dump_kernel_offset,
  661. };
  662. static struct notifier_block ppc_panic_block = {
  663. .notifier_call = ppc_panic_platform_handler,
  664. .priority = INT_MIN, /* may not return; must be done last */
  665. };
  666. void __init setup_panic(void)
  667. {
  668. /* Hard-disables IRQs + deal with FW-assisted dump (fadump) */
  669. atomic_notifier_chain_register(&panic_notifier_list,
  670. &ppc_fadump_block);
  671. if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && kaslr_offset() > 0)
  672. atomic_notifier_chain_register(&panic_notifier_list,
  673. &kernel_offset_notifier);
  674. /* Low-level platform-specific routines that should run on panic */
  675. if (ppc_md.panic)
  676. atomic_notifier_chain_register(&panic_notifier_list,
  677. &ppc_panic_block);
  678. }
  679. #ifdef CONFIG_CHECK_CACHE_COHERENCY
  680. /*
  681. * For platforms that have configurable cache-coherency. This function
  682. * checks that the cache coherency setting of the kernel matches the setting
  683. * left by the firmware, as indicated in the device tree. Since a mismatch
  684. * will eventually result in DMA failures, we print * and error and call
  685. * BUG() in that case.
  686. */
  687. #define KERNEL_COHERENCY (!IS_ENABLED(CONFIG_NOT_COHERENT_CACHE))
  688. static int __init check_cache_coherency(void)
  689. {
  690. struct device_node *np;
  691. const void *prop;
  692. bool devtree_coherency;
  693. np = of_find_node_by_path("/");
  694. prop = of_get_property(np, "coherency-off", NULL);
  695. of_node_put(np);
  696. devtree_coherency = prop ? false : true;
  697. if (devtree_coherency != KERNEL_COHERENCY) {
  698. printk(KERN_ERR
  699. "kernel coherency:%s != device tree_coherency:%s\n",
  700. KERNEL_COHERENCY ? "on" : "off",
  701. devtree_coherency ? "on" : "off");
  702. BUG();
  703. }
  704. return 0;
  705. }
  706. late_initcall(check_cache_coherency);
  707. #endif /* CONFIG_CHECK_CACHE_COHERENCY */
  708. void ppc_printk_progress(char *s, unsigned short hex)
  709. {
  710. pr_info("%s\n", s);
  711. }
  712. static __init void print_system_info(void)
  713. {
  714. pr_info("-----------------------------------------------------\n");
  715. pr_info("phys_mem_size = 0x%llx\n",
  716. (unsigned long long)memblock_phys_mem_size());
  717. pr_info("dcache_bsize = 0x%x\n", dcache_bsize);
  718. pr_info("icache_bsize = 0x%x\n", icache_bsize);
  719. pr_info("cpu_features = 0x%016lx\n", cur_cpu_spec->cpu_features);
  720. pr_info(" possible = 0x%016lx\n",
  721. (unsigned long)CPU_FTRS_POSSIBLE);
  722. pr_info(" always = 0x%016lx\n",
  723. (unsigned long)CPU_FTRS_ALWAYS);
  724. pr_info("cpu_user_features = 0x%08x 0x%08x\n",
  725. cur_cpu_spec->cpu_user_features,
  726. cur_cpu_spec->cpu_user_features2);
  727. pr_info("mmu_features = 0x%08x\n", cur_cpu_spec->mmu_features);
  728. #ifdef CONFIG_PPC64
  729. pr_info("firmware_features = 0x%016lx\n", powerpc_firmware_features);
  730. #ifdef CONFIG_PPC_BOOK3S
  731. pr_info("vmalloc start = 0x%lx\n", KERN_VIRT_START);
  732. pr_info("IO start = 0x%lx\n", KERN_IO_START);
  733. pr_info("vmemmap start = 0x%lx\n", (unsigned long)vmemmap);
  734. #endif
  735. #endif
  736. if (!early_radix_enabled())
  737. print_system_hash_info();
  738. if (PHYSICAL_START > 0)
  739. pr_info("physical_start = 0x%llx\n",
  740. (unsigned long long)PHYSICAL_START);
  741. pr_info("-----------------------------------------------------\n");
  742. }
  743. #ifdef CONFIG_SMP
  744. static void __init smp_setup_pacas(void)
  745. {
  746. int cpu;
  747. for_each_possible_cpu(cpu) {
  748. if (cpu == smp_processor_id())
  749. continue;
  750. allocate_paca(cpu);
  751. set_hard_smp_processor_id(cpu, cpu_to_phys_id[cpu]);
  752. }
  753. memblock_free(cpu_to_phys_id, nr_cpu_ids * sizeof(u32));
  754. cpu_to_phys_id = NULL;
  755. }
  756. #endif
  757. /*
  758. * Called into from start_kernel this initializes memblock, which is used
  759. * to manage page allocation until mem_init is called.
  760. */
  761. void __init setup_arch(char **cmdline_p)
  762. {
  763. kasan_init();
  764. *cmdline_p = boot_command_line;
  765. /* Set a half-reasonable default so udelay does something sensible */
  766. loops_per_jiffy = 500000000 / HZ;
  767. /* Unflatten the device-tree passed by prom_init or kexec */
  768. unflatten_device_tree();
  769. /*
  770. * Initialize cache line/block info from device-tree (on ppc64) or
  771. * just cputable (on ppc32).
  772. */
  773. initialize_cache_info();
  774. /* Initialize RTAS if available. */
  775. rtas_initialize();
  776. /* Check if we have an initrd provided via the device-tree. */
  777. check_for_initrd();
  778. /* Probe the machine type, establish ppc_md. */
  779. probe_machine();
  780. /* Setup panic notifier if requested by the platform. */
  781. setup_panic();
  782. /*
  783. * Configure ppc_md.power_save (ppc32 only, 64-bit machines do
  784. * it from their respective probe() function.
  785. */
  786. setup_power_save();
  787. /* Discover standard serial ports. */
  788. find_legacy_serial_ports();
  789. /* Register early console with the printk subsystem. */
  790. register_early_udbg_console();
  791. /* Setup the various CPU maps based on the device-tree. */
  792. smp_setup_cpu_maps();
  793. /* Initialize xmon. */
  794. xmon_setup();
  795. /* Check the SMT related command line arguments (ppc64). */
  796. check_smt_enabled();
  797. /* Parse memory topology */
  798. mem_topology_setup();
  799. /* Set max_mapnr before paging_init() */
  800. set_max_mapnr(max_pfn);
  801. /*
  802. * Release secondary cpus out of their spinloops at 0x60 now that
  803. * we can map physical -> logical CPU ids.
  804. *
  805. * Freescale Book3e parts spin in a loop provided by firmware,
  806. * so smp_release_cpus() does nothing for them.
  807. */
  808. #ifdef CONFIG_SMP
  809. smp_setup_pacas();
  810. /* On BookE, setup per-core TLB data structures. */
  811. setup_tlb_core_data();
  812. #endif
  813. /* Print various info about the machine that has been gathered so far. */
  814. print_system_info();
  815. klp_init_thread_info(&init_task);
  816. setup_initial_init_mm(_stext, _etext, _edata, _end);
  817. mm_iommu_init(&init_mm);
  818. irqstack_early_init();
  819. exc_lvl_early_init();
  820. emergency_stack_init();
  821. mce_init();
  822. smp_release_cpus();
  823. initmem_init();
  824. /*
  825. * Reserve large chunks of memory for use by CMA for KVM and hugetlb. These must
  826. * be called after initmem_init(), so that pageblock_order is initialised.
  827. */
  828. kvm_cma_reserve();
  829. gigantic_hugetlb_cma_reserve();
  830. early_memtest(min_low_pfn << PAGE_SHIFT, max_low_pfn << PAGE_SHIFT);
  831. if (ppc_md.setup_arch)
  832. ppc_md.setup_arch();
  833. setup_barrier_nospec();
  834. setup_spectre_v2();
  835. paging_init();
  836. /* Initialize the MMU context management stuff. */
  837. mmu_context_init();
  838. /* Interrupt code needs to be 64K-aligned. */
  839. if (IS_ENABLED(CONFIG_PPC64) && (unsigned long)_stext & 0xffff)
  840. panic("Kernelbase not 64K-aligned (0x%lx)!\n",
  841. (unsigned long)_stext);
  842. }