setup_64.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. /*
  2. *
  3. * Common boot and setup code.
  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. #define 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/seq_file.h>
  22. #include <linux/ioport.h>
  23. #include <linux/console.h>
  24. #include <linux/utsname.h>
  25. #include <linux/tty.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/bootmem.h>
  33. #include <linux/pci.h>
  34. #include <linux/lockdep.h>
  35. #include <linux/memblock.h>
  36. #include <linux/memory.h>
  37. #include <linux/nmi.h>
  38. #include <asm/io.h>
  39. #include <asm/kdump.h>
  40. #include <asm/prom.h>
  41. #include <asm/processor.h>
  42. #include <asm/pgtable.h>
  43. #include <asm/smp.h>
  44. #include <asm/elf.h>
  45. #include <asm/machdep.h>
  46. #include <asm/paca.h>
  47. #include <asm/time.h>
  48. #include <asm/cputable.h>
  49. #include <asm/sections.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/firmware.h>
  60. #include <asm/xmon.h>
  61. #include <asm/udbg.h>
  62. #include <asm/kexec.h>
  63. #include <asm/code-patching.h>
  64. #include <asm/livepatch.h>
  65. #include <asm/opal.h>
  66. #include <asm/cputhreads.h>
  67. #ifdef DEBUG
  68. #define DBG(fmt...) udbg_printf(fmt)
  69. #else
  70. #define DBG(fmt...)
  71. #endif
  72. int spinning_secondaries;
  73. u64 ppc64_pft_size;
  74. struct ppc64_caches ppc64_caches = {
  75. .l1d = {
  76. .block_size = 0x40,
  77. .log_block_size = 6,
  78. },
  79. .l1i = {
  80. .block_size = 0x40,
  81. .log_block_size = 6
  82. },
  83. };
  84. EXPORT_SYMBOL_GPL(ppc64_caches);
  85. #if defined(CONFIG_PPC_BOOK3E) && defined(CONFIG_SMP)
  86. void __init setup_tlb_core_data(void)
  87. {
  88. int cpu;
  89. BUILD_BUG_ON(offsetof(struct tlb_core_data, lock) != 0);
  90. for_each_possible_cpu(cpu) {
  91. int first = cpu_first_thread_sibling(cpu);
  92. /*
  93. * If we boot via kdump on a non-primary thread,
  94. * make sure we point at the thread that actually
  95. * set up this TLB.
  96. */
  97. if (cpu_first_thread_sibling(boot_cpuid) == first)
  98. first = boot_cpuid;
  99. paca[cpu].tcd_ptr = &paca[first].tcd;
  100. /*
  101. * If we have threads, we need either tlbsrx.
  102. * or e6500 tablewalk mode, or else TLB handlers
  103. * will be racy and could produce duplicate entries.
  104. * Should we panic instead?
  105. */
  106. WARN_ONCE(smt_enabled_at_boot >= 2 &&
  107. !mmu_has_feature(MMU_FTR_USE_TLBRSRV) &&
  108. book3e_htw_mode != PPC_HTW_E6500,
  109. "%s: unsupported MMU configuration\n", __func__);
  110. }
  111. }
  112. #endif
  113. #ifdef CONFIG_SMP
  114. static char *smt_enabled_cmdline;
  115. /* Look for ibm,smt-enabled OF option */
  116. void __init check_smt_enabled(void)
  117. {
  118. struct device_node *dn;
  119. const char *smt_option;
  120. /* Default to enabling all threads */
  121. smt_enabled_at_boot = threads_per_core;
  122. /* Allow the command line to overrule the OF option */
  123. if (smt_enabled_cmdline) {
  124. if (!strcmp(smt_enabled_cmdline, "on"))
  125. smt_enabled_at_boot = threads_per_core;
  126. else if (!strcmp(smt_enabled_cmdline, "off"))
  127. smt_enabled_at_boot = 0;
  128. else {
  129. int smt;
  130. int rc;
  131. rc = kstrtoint(smt_enabled_cmdline, 10, &smt);
  132. if (!rc)
  133. smt_enabled_at_boot =
  134. min(threads_per_core, smt);
  135. }
  136. } else {
  137. dn = of_find_node_by_path("/options");
  138. if (dn) {
  139. smt_option = of_get_property(dn, "ibm,smt-enabled",
  140. NULL);
  141. if (smt_option) {
  142. if (!strcmp(smt_option, "on"))
  143. smt_enabled_at_boot = threads_per_core;
  144. else if (!strcmp(smt_option, "off"))
  145. smt_enabled_at_boot = 0;
  146. }
  147. of_node_put(dn);
  148. }
  149. }
  150. }
  151. /* Look for smt-enabled= cmdline option */
  152. static int __init early_smt_enabled(char *p)
  153. {
  154. smt_enabled_cmdline = p;
  155. return 0;
  156. }
  157. early_param("smt-enabled", early_smt_enabled);
  158. #endif /* CONFIG_SMP */
  159. /** Fix up paca fields required for the boot cpu */
  160. static void __init fixup_boot_paca(void)
  161. {
  162. /* The boot cpu is started */
  163. get_paca()->cpu_start = 1;
  164. /* Allow percpu accesses to work until we setup percpu data */
  165. get_paca()->data_offset = 0;
  166. }
  167. static void __init configure_exceptions(void)
  168. {
  169. /*
  170. * Setup the trampolines from the lowmem exception vectors
  171. * to the kdump kernel when not using a relocatable kernel.
  172. */
  173. setup_kdump_trampoline();
  174. /* Under a PAPR hypervisor, we need hypercalls */
  175. if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
  176. /* Enable AIL if possible */
  177. pseries_enable_reloc_on_exc();
  178. /*
  179. * Tell the hypervisor that we want our exceptions to
  180. * be taken in little endian mode.
  181. *
  182. * We don't call this for big endian as our calling convention
  183. * makes us always enter in BE, and the call may fail under
  184. * some circumstances with kdump.
  185. */
  186. #ifdef __LITTLE_ENDIAN__
  187. pseries_little_endian_exceptions();
  188. #endif
  189. } else {
  190. /* Set endian mode using OPAL */
  191. if (firmware_has_feature(FW_FEATURE_OPAL))
  192. opal_configure_cores();
  193. /* AIL on native is done in cpu_ready_for_interrupts() */
  194. }
  195. }
  196. static void cpu_ready_for_interrupts(void)
  197. {
  198. /*
  199. * Enable AIL if supported, and we are in hypervisor mode. This
  200. * is called once for every processor.
  201. *
  202. * If we are not in hypervisor mode the job is done once for
  203. * the whole partition in configure_exceptions().
  204. */
  205. if (early_cpu_has_feature(CPU_FTR_HVMODE) &&
  206. early_cpu_has_feature(CPU_FTR_ARCH_207S)) {
  207. unsigned long lpcr = mfspr(SPRN_LPCR);
  208. mtspr(SPRN_LPCR, lpcr | LPCR_AIL_3);
  209. }
  210. /* Set IR and DR in PACA MSR */
  211. get_paca()->kernel_msr = MSR_KERNEL;
  212. }
  213. /*
  214. * Early initialization entry point. This is called by head.S
  215. * with MMU translation disabled. We rely on the "feature" of
  216. * the CPU that ignores the top 2 bits of the address in real
  217. * mode so we can access kernel globals normally provided we
  218. * only toy with things in the RMO region. From here, we do
  219. * some early parsing of the device-tree to setup out MEMBLOCK
  220. * data structures, and allocate & initialize the hash table
  221. * and segment tables so we can start running with translation
  222. * enabled.
  223. *
  224. * It is this function which will call the probe() callback of
  225. * the various platform types and copy the matching one to the
  226. * global ppc_md structure. Your platform can eventually do
  227. * some very early initializations from the probe() routine, but
  228. * this is not recommended, be very careful as, for example, the
  229. * device-tree is not accessible via normal means at this point.
  230. */
  231. void __init early_setup(unsigned long dt_ptr)
  232. {
  233. static __initdata struct paca_struct boot_paca;
  234. /* -------- printk is _NOT_ safe to use here ! ------- */
  235. /* Identify CPU type */
  236. identify_cpu(0, mfspr(SPRN_PVR));
  237. /* Assume we're on cpu 0 for now. Don't write to the paca yet! */
  238. initialise_paca(&boot_paca, 0);
  239. setup_paca(&boot_paca);
  240. fixup_boot_paca();
  241. /* -------- printk is now safe to use ------- */
  242. /* Enable early debugging if any specified (see udbg.h) */
  243. udbg_early_init();
  244. DBG(" -> early_setup(), dt_ptr: 0x%lx\n", dt_ptr);
  245. /*
  246. * Do early initialization using the flattened device
  247. * tree, such as retrieving the physical memory map or
  248. * calculating/retrieving the hash table size.
  249. */
  250. early_init_devtree(__va(dt_ptr));
  251. /* Now we know the logical id of our boot cpu, setup the paca. */
  252. setup_paca(&paca[boot_cpuid]);
  253. fixup_boot_paca();
  254. /*
  255. * Configure exception handlers. This include setting up trampolines
  256. * if needed, setting exception endian mode, etc...
  257. */
  258. configure_exceptions();
  259. /* Apply all the dynamic patching */
  260. apply_feature_fixups();
  261. setup_feature_keys();
  262. /* Initialize the hash table or TLB handling */
  263. early_init_mmu();
  264. /*
  265. * At this point, we can let interrupts switch to virtual mode
  266. * (the MMU has been setup), so adjust the MSR in the PACA to
  267. * have IR and DR set and enable AIL if it exists
  268. */
  269. cpu_ready_for_interrupts();
  270. DBG(" <- early_setup()\n");
  271. #ifdef CONFIG_PPC_EARLY_DEBUG_BOOTX
  272. /*
  273. * This needs to be done *last* (after the above DBG() even)
  274. *
  275. * Right after we return from this function, we turn on the MMU
  276. * which means the real-mode access trick that btext does will
  277. * no longer work, it needs to switch to using a real MMU
  278. * mapping. This call will ensure that it does
  279. */
  280. btext_map();
  281. #endif /* CONFIG_PPC_EARLY_DEBUG_BOOTX */
  282. }
  283. #ifdef CONFIG_SMP
  284. void early_setup_secondary(void)
  285. {
  286. /* Mark interrupts disabled in PACA */
  287. get_paca()->soft_enabled = 0;
  288. /* Initialize the hash table or TLB handling */
  289. early_init_mmu_secondary();
  290. /*
  291. * At this point, we can let interrupts switch to virtual mode
  292. * (the MMU has been setup), so adjust the MSR in the PACA to
  293. * have IR and DR set.
  294. */
  295. cpu_ready_for_interrupts();
  296. }
  297. #endif /* CONFIG_SMP */
  298. #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC_CORE)
  299. static bool use_spinloop(void)
  300. {
  301. if (!IS_ENABLED(CONFIG_PPC_BOOK3E))
  302. return true;
  303. /*
  304. * When book3e boots from kexec, the ePAPR spin table does
  305. * not get used.
  306. */
  307. return of_property_read_bool(of_chosen, "linux,booted-from-kexec");
  308. }
  309. void smp_release_cpus(void)
  310. {
  311. unsigned long *ptr;
  312. int i;
  313. if (!use_spinloop())
  314. return;
  315. DBG(" -> smp_release_cpus()\n");
  316. /* All secondary cpus are spinning on a common spinloop, release them
  317. * all now so they can start to spin on their individual paca
  318. * spinloops. For non SMP kernels, the secondary cpus never get out
  319. * of the common spinloop.
  320. */
  321. ptr = (unsigned long *)((unsigned long)&__secondary_hold_spinloop
  322. - PHYSICAL_START);
  323. *ptr = ppc_function_entry(generic_secondary_smp_init);
  324. /* And wait a bit for them to catch up */
  325. for (i = 0; i < 100000; i++) {
  326. mb();
  327. HMT_low();
  328. if (spinning_secondaries == 0)
  329. break;
  330. udelay(1);
  331. }
  332. DBG("spinning_secondaries = %d\n", spinning_secondaries);
  333. DBG(" <- smp_release_cpus()\n");
  334. }
  335. #endif /* CONFIG_SMP || CONFIG_KEXEC_CORE */
  336. /*
  337. * Initialize some remaining members of the ppc64_caches and systemcfg
  338. * structures
  339. * (at least until we get rid of them completely). This is mostly some
  340. * cache informations about the CPU that will be used by cache flush
  341. * routines and/or provided to userland
  342. */
  343. static void init_cache_info(struct ppc_cache_info *info, u32 size, u32 lsize,
  344. u32 bsize, u32 sets)
  345. {
  346. info->size = size;
  347. info->sets = sets;
  348. info->line_size = lsize;
  349. info->block_size = bsize;
  350. info->log_block_size = __ilog2(bsize);
  351. info->blocks_per_page = PAGE_SIZE / bsize;
  352. if (sets == 0)
  353. info->assoc = 0xffff;
  354. else
  355. info->assoc = size / (sets * lsize);
  356. }
  357. static bool __init parse_cache_info(struct device_node *np,
  358. bool icache,
  359. struct ppc_cache_info *info)
  360. {
  361. static const char *ipropnames[] __initdata = {
  362. "i-cache-size",
  363. "i-cache-sets",
  364. "i-cache-block-size",
  365. "i-cache-line-size",
  366. };
  367. static const char *dpropnames[] __initdata = {
  368. "d-cache-size",
  369. "d-cache-sets",
  370. "d-cache-block-size",
  371. "d-cache-line-size",
  372. };
  373. const char **propnames = icache ? ipropnames : dpropnames;
  374. const __be32 *sizep, *lsizep, *bsizep, *setsp;
  375. u32 size, lsize, bsize, sets;
  376. bool success = true;
  377. size = 0;
  378. sets = -1u;
  379. lsize = bsize = cur_cpu_spec->dcache_bsize;
  380. sizep = of_get_property(np, propnames[0], NULL);
  381. if (sizep != NULL)
  382. size = be32_to_cpu(*sizep);
  383. setsp = of_get_property(np, propnames[1], NULL);
  384. if (setsp != NULL)
  385. sets = be32_to_cpu(*setsp);
  386. bsizep = of_get_property(np, propnames[2], NULL);
  387. lsizep = of_get_property(np, propnames[3], NULL);
  388. if (bsizep == NULL)
  389. bsizep = lsizep;
  390. if (lsizep != NULL)
  391. lsize = be32_to_cpu(*lsizep);
  392. if (bsizep != NULL)
  393. bsize = be32_to_cpu(*bsizep);
  394. if (sizep == NULL || bsizep == NULL || lsizep == NULL)
  395. success = false;
  396. /*
  397. * OF is weird .. it represents fully associative caches
  398. * as "1 way" which doesn't make much sense and doesn't
  399. * leave room for direct mapped. We'll assume that 0
  400. * in OF means direct mapped for that reason.
  401. */
  402. if (sets == 1)
  403. sets = 0;
  404. else if (sets == 0)
  405. sets = 1;
  406. init_cache_info(info, size, lsize, bsize, sets);
  407. return success;
  408. }
  409. void __init initialize_cache_info(void)
  410. {
  411. struct device_node *cpu = NULL, *l2, *l3 = NULL;
  412. u32 pvr;
  413. DBG(" -> initialize_cache_info()\n");
  414. /*
  415. * All shipping POWER8 machines have a firmware bug that
  416. * puts incorrect information in the device-tree. This will
  417. * be (hopefully) fixed for future chips but for now hard
  418. * code the values if we are running on one of these
  419. */
  420. pvr = PVR_VER(mfspr(SPRN_PVR));
  421. if (pvr == PVR_POWER8 || pvr == PVR_POWER8E ||
  422. pvr == PVR_POWER8NVL) {
  423. /* size lsize blk sets */
  424. init_cache_info(&ppc64_caches.l1i, 0x8000, 128, 128, 32);
  425. init_cache_info(&ppc64_caches.l1d, 0x10000, 128, 128, 64);
  426. init_cache_info(&ppc64_caches.l2, 0x80000, 128, 0, 512);
  427. init_cache_info(&ppc64_caches.l3, 0x800000, 128, 0, 8192);
  428. } else
  429. cpu = of_find_node_by_type(NULL, "cpu");
  430. /*
  431. * We're assuming *all* of the CPUs have the same
  432. * d-cache and i-cache sizes... -Peter
  433. */
  434. if (cpu) {
  435. if (!parse_cache_info(cpu, false, &ppc64_caches.l1d))
  436. DBG("Argh, can't find dcache properties !\n");
  437. if (!parse_cache_info(cpu, true, &ppc64_caches.l1i))
  438. DBG("Argh, can't find icache properties !\n");
  439. /*
  440. * Try to find the L2 and L3 if any. Assume they are
  441. * unified and use the D-side properties.
  442. */
  443. l2 = of_find_next_cache_node(cpu);
  444. of_node_put(cpu);
  445. if (l2) {
  446. parse_cache_info(l2, false, &ppc64_caches.l2);
  447. l3 = of_find_next_cache_node(l2);
  448. of_node_put(l2);
  449. }
  450. if (l3) {
  451. parse_cache_info(l3, false, &ppc64_caches.l3);
  452. of_node_put(l3);
  453. }
  454. }
  455. /* For use by binfmt_elf */
  456. dcache_bsize = ppc64_caches.l1d.block_size;
  457. icache_bsize = ppc64_caches.l1i.block_size;
  458. DBG(" <- initialize_cache_info()\n");
  459. }
  460. /* This returns the limit below which memory accesses to the linear
  461. * mapping are guarnateed not to cause a TLB or SLB miss. This is
  462. * used to allocate interrupt or emergency stacks for which our
  463. * exception entry path doesn't deal with being interrupted.
  464. */
  465. static __init u64 safe_stack_limit(void)
  466. {
  467. #ifdef CONFIG_PPC_BOOK3E
  468. /* Freescale BookE bolts the entire linear mapping */
  469. if (mmu_has_feature(MMU_FTR_TYPE_FSL_E))
  470. return linear_map_top;
  471. /* Other BookE, we assume the first GB is bolted */
  472. return 1ul << 30;
  473. #else
  474. /* BookS, the first segment is bolted */
  475. if (mmu_has_feature(MMU_FTR_1T_SEGMENT))
  476. return 1UL << SID_SHIFT_1T;
  477. return 1UL << SID_SHIFT;
  478. #endif
  479. }
  480. void __init irqstack_early_init(void)
  481. {
  482. u64 limit = safe_stack_limit();
  483. unsigned int i;
  484. /*
  485. * Interrupt stacks must be in the first segment since we
  486. * cannot afford to take SLB misses on them.
  487. */
  488. for_each_possible_cpu(i) {
  489. softirq_ctx[i] = (struct thread_info *)
  490. __va(memblock_alloc_base(THREAD_SIZE,
  491. THREAD_SIZE, limit));
  492. hardirq_ctx[i] = (struct thread_info *)
  493. __va(memblock_alloc_base(THREAD_SIZE,
  494. THREAD_SIZE, limit));
  495. }
  496. }
  497. #ifdef CONFIG_PPC_BOOK3E
  498. void __init exc_lvl_early_init(void)
  499. {
  500. unsigned int i;
  501. unsigned long sp;
  502. for_each_possible_cpu(i) {
  503. sp = memblock_alloc(THREAD_SIZE, THREAD_SIZE);
  504. critirq_ctx[i] = (struct thread_info *)__va(sp);
  505. paca[i].crit_kstack = __va(sp + THREAD_SIZE);
  506. sp = memblock_alloc(THREAD_SIZE, THREAD_SIZE);
  507. dbgirq_ctx[i] = (struct thread_info *)__va(sp);
  508. paca[i].dbg_kstack = __va(sp + THREAD_SIZE);
  509. sp = memblock_alloc(THREAD_SIZE, THREAD_SIZE);
  510. mcheckirq_ctx[i] = (struct thread_info *)__va(sp);
  511. paca[i].mc_kstack = __va(sp + THREAD_SIZE);
  512. }
  513. if (cpu_has_feature(CPU_FTR_DEBUG_LVL_EXC))
  514. patch_exception(0x040, exc_debug_debug_book3e);
  515. }
  516. #endif
  517. /*
  518. * Stack space used when we detect a bad kernel stack pointer, and
  519. * early in SMP boots before relocation is enabled. Exclusive emergency
  520. * stack for machine checks.
  521. */
  522. void __init emergency_stack_init(void)
  523. {
  524. u64 limit;
  525. unsigned int i;
  526. /*
  527. * Emergency stacks must be under 256MB, we cannot afford to take
  528. * SLB misses on them. The ABI also requires them to be 128-byte
  529. * aligned.
  530. *
  531. * Since we use these as temporary stacks during secondary CPU
  532. * bringup, we need to get at them in real mode. This means they
  533. * must also be within the RMO region.
  534. */
  535. limit = min(safe_stack_limit(), ppc64_rma_size);
  536. for_each_possible_cpu(i) {
  537. struct thread_info *ti;
  538. ti = __va(memblock_alloc_base(THREAD_SIZE, THREAD_SIZE, limit));
  539. klp_init_thread_info(ti);
  540. paca[i].emergency_sp = (void *)ti + THREAD_SIZE;
  541. #ifdef CONFIG_PPC_BOOK3S_64
  542. /* emergency stack for machine check exception handling. */
  543. ti = __va(memblock_alloc_base(THREAD_SIZE, THREAD_SIZE, limit));
  544. klp_init_thread_info(ti);
  545. paca[i].mc_emergency_sp = (void *)ti + THREAD_SIZE;
  546. #endif
  547. }
  548. }
  549. #ifdef CONFIG_SMP
  550. #define PCPU_DYN_SIZE ()
  551. static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
  552. {
  553. return __alloc_bootmem_node(NODE_DATA(cpu_to_node(cpu)), size, align,
  554. __pa(MAX_DMA_ADDRESS));
  555. }
  556. static void __init pcpu_fc_free(void *ptr, size_t size)
  557. {
  558. free_bootmem(__pa(ptr), size);
  559. }
  560. static int pcpu_cpu_distance(unsigned int from, unsigned int to)
  561. {
  562. if (cpu_to_node(from) == cpu_to_node(to))
  563. return LOCAL_DISTANCE;
  564. else
  565. return REMOTE_DISTANCE;
  566. }
  567. unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
  568. EXPORT_SYMBOL(__per_cpu_offset);
  569. void __init setup_per_cpu_areas(void)
  570. {
  571. const size_t dyn_size = PERCPU_MODULE_RESERVE + PERCPU_DYNAMIC_RESERVE;
  572. size_t atom_size;
  573. unsigned long delta;
  574. unsigned int cpu;
  575. int rc;
  576. /*
  577. * Linear mapping is one of 4K, 1M and 16M. For 4K, no need
  578. * to group units. For larger mappings, use 1M atom which
  579. * should be large enough to contain a number of units.
  580. */
  581. if (mmu_linear_psize == MMU_PAGE_4K)
  582. atom_size = PAGE_SIZE;
  583. else
  584. atom_size = 1 << 20;
  585. rc = pcpu_embed_first_chunk(0, dyn_size, atom_size, pcpu_cpu_distance,
  586. pcpu_fc_alloc, pcpu_fc_free);
  587. if (rc < 0)
  588. panic("cannot initialize percpu area (err=%d)", rc);
  589. delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
  590. for_each_possible_cpu(cpu) {
  591. __per_cpu_offset[cpu] = delta + pcpu_unit_offsets[cpu];
  592. paca[cpu].data_offset = __per_cpu_offset[cpu];
  593. }
  594. }
  595. #endif
  596. #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
  597. unsigned long memory_block_size_bytes(void)
  598. {
  599. if (ppc_md.memory_block_size)
  600. return ppc_md.memory_block_size();
  601. return MIN_MEMORY_BLOCK_SIZE;
  602. }
  603. #endif
  604. #if defined(CONFIG_PPC_INDIRECT_PIO) || defined(CONFIG_PPC_INDIRECT_MMIO)
  605. struct ppc_pci_io ppc_pci_io;
  606. EXPORT_SYMBOL(ppc_pci_io);
  607. #endif
  608. #ifdef CONFIG_HARDLOCKUP_DETECTOR
  609. u64 hw_nmi_get_sample_period(int watchdog_thresh)
  610. {
  611. return ppc_proc_freq * watchdog_thresh;
  612. }
  613. /*
  614. * The hardlockup detector breaks PMU event based branches and is likely
  615. * to get false positives in KVM guests, so disable it by default.
  616. */
  617. static int __init disable_hardlockup_detector(void)
  618. {
  619. hardlockup_detector_disable();
  620. return 0;
  621. }
  622. early_initcall(disable_hardlockup_detector);
  623. #endif