setup_64.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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. #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/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/hugetlb.h>
  37. #include <asm/io.h>
  38. #include <asm/kdump.h>
  39. #include <asm/prom.h>
  40. #include <asm/processor.h>
  41. #include <asm/pgtable.h>
  42. #include <asm/smp.h>
  43. #include <asm/elf.h>
  44. #include <asm/machdep.h>
  45. #include <asm/paca.h>
  46. #include <asm/time.h>
  47. #include <asm/cputable.h>
  48. #include <asm/sections.h>
  49. #include <asm/btext.h>
  50. #include <asm/nvram.h>
  51. #include <asm/setup.h>
  52. #include <asm/rtas.h>
  53. #include <asm/iommu.h>
  54. #include <asm/serial.h>
  55. #include <asm/cache.h>
  56. #include <asm/page.h>
  57. #include <asm/mmu.h>
  58. #include <asm/firmware.h>
  59. #include <asm/xmon.h>
  60. #include <asm/udbg.h>
  61. #include <asm/kexec.h>
  62. #include <asm/mmu_context.h>
  63. #include <asm/code-patching.h>
  64. #include <asm/kvm_ppc.h>
  65. #include <asm/hugetlb.h>
  66. #include "setup.h"
  67. #ifdef DEBUG
  68. #define DBG(fmt...) udbg_printf(fmt)
  69. #else
  70. #define DBG(fmt...)
  71. #endif
  72. int boot_cpuid = 0;
  73. int __initdata spinning_secondaries;
  74. u64 ppc64_pft_size;
  75. /* Pick defaults since we might want to patch instructions
  76. * before we've read this from the device tree.
  77. */
  78. struct ppc64_caches ppc64_caches = {
  79. .dline_size = 0x40,
  80. .log_dline_size = 6,
  81. .iline_size = 0x40,
  82. .log_iline_size = 6
  83. };
  84. EXPORT_SYMBOL_GPL(ppc64_caches);
  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. int ucache_bsize;
  92. #ifdef CONFIG_SMP
  93. static char *smt_enabled_cmdline;
  94. /* Look for ibm,smt-enabled OF option */
  95. static void check_smt_enabled(void)
  96. {
  97. struct device_node *dn;
  98. const char *smt_option;
  99. /* Default to enabling all threads */
  100. smt_enabled_at_boot = threads_per_core;
  101. /* Allow the command line to overrule the OF option */
  102. if (smt_enabled_cmdline) {
  103. if (!strcmp(smt_enabled_cmdline, "on"))
  104. smt_enabled_at_boot = threads_per_core;
  105. else if (!strcmp(smt_enabled_cmdline, "off"))
  106. smt_enabled_at_boot = 0;
  107. else {
  108. long smt;
  109. int rc;
  110. rc = strict_strtol(smt_enabled_cmdline, 10, &smt);
  111. if (!rc)
  112. smt_enabled_at_boot =
  113. min(threads_per_core, (int)smt);
  114. }
  115. } else {
  116. dn = of_find_node_by_path("/options");
  117. if (dn) {
  118. smt_option = of_get_property(dn, "ibm,smt-enabled",
  119. NULL);
  120. if (smt_option) {
  121. if (!strcmp(smt_option, "on"))
  122. smt_enabled_at_boot = threads_per_core;
  123. else if (!strcmp(smt_option, "off"))
  124. smt_enabled_at_boot = 0;
  125. }
  126. of_node_put(dn);
  127. }
  128. }
  129. }
  130. /* Look for smt-enabled= cmdline option */
  131. static int __init early_smt_enabled(char *p)
  132. {
  133. smt_enabled_cmdline = p;
  134. return 0;
  135. }
  136. early_param("smt-enabled", early_smt_enabled);
  137. #else
  138. #define check_smt_enabled()
  139. #endif /* CONFIG_SMP */
  140. /** Fix up paca fields required for the boot cpu */
  141. static void fixup_boot_paca(void)
  142. {
  143. /* The boot cpu is started */
  144. get_paca()->cpu_start = 1;
  145. /* Allow percpu accesses to work until we setup percpu data */
  146. get_paca()->data_offset = 0;
  147. }
  148. /*
  149. * Early initialization entry point. This is called by head.S
  150. * with MMU translation disabled. We rely on the "feature" of
  151. * the CPU that ignores the top 2 bits of the address in real
  152. * mode so we can access kernel globals normally provided we
  153. * only toy with things in the RMO region. From here, we do
  154. * some early parsing of the device-tree to setup out MEMBLOCK
  155. * data structures, and allocate & initialize the hash table
  156. * and segment tables so we can start running with translation
  157. * enabled.
  158. *
  159. * It is this function which will call the probe() callback of
  160. * the various platform types and copy the matching one to the
  161. * global ppc_md structure. Your platform can eventually do
  162. * some very early initializations from the probe() routine, but
  163. * this is not recommended, be very careful as, for example, the
  164. * device-tree is not accessible via normal means at this point.
  165. */
  166. void __init early_setup(unsigned long dt_ptr)
  167. {
  168. static __initdata struct paca_struct boot_paca;
  169. /* -------- printk is _NOT_ safe to use here ! ------- */
  170. /* Identify CPU type */
  171. identify_cpu(0, mfspr(SPRN_PVR));
  172. /* Assume we're on cpu 0 for now. Don't write to the paca yet! */
  173. initialise_paca(&boot_paca, 0);
  174. setup_paca(&boot_paca);
  175. fixup_boot_paca();
  176. /* Initialize lockdep early or else spinlocks will blow */
  177. lockdep_init();
  178. /* -------- printk is now safe to use ------- */
  179. /* Enable early debugging if any specified (see udbg.h) */
  180. udbg_early_init();
  181. DBG(" -> early_setup(), dt_ptr: 0x%lx\n", dt_ptr);
  182. /*
  183. * Do early initialization using the flattened device
  184. * tree, such as retrieving the physical memory map or
  185. * calculating/retrieving the hash table size.
  186. */
  187. early_init_devtree(__va(dt_ptr));
  188. /* Now we know the logical id of our boot cpu, setup the paca. */
  189. setup_paca(&paca[boot_cpuid]);
  190. fixup_boot_paca();
  191. /* Probe the machine type */
  192. probe_machine();
  193. setup_kdump_trampoline();
  194. DBG("Found, Initializing memory management...\n");
  195. /* Initialize the hash table or TLB handling */
  196. early_init_mmu();
  197. /*
  198. * Reserve any gigantic pages requested on the command line.
  199. * memblock needs to have been initialized by the time this is
  200. * called since this will reserve memory.
  201. */
  202. reserve_hugetlb_gpages();
  203. DBG(" <- early_setup()\n");
  204. }
  205. #ifdef CONFIG_SMP
  206. void early_setup_secondary(void)
  207. {
  208. /* Mark interrupts enabled in PACA */
  209. get_paca()->soft_enabled = 0;
  210. /* Initialize the hash table or TLB handling */
  211. early_init_mmu_secondary();
  212. }
  213. #endif /* CONFIG_SMP */
  214. #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
  215. void smp_release_cpus(void)
  216. {
  217. unsigned long *ptr;
  218. int i;
  219. DBG(" -> smp_release_cpus()\n");
  220. /* All secondary cpus are spinning on a common spinloop, release them
  221. * all now so they can start to spin on their individual paca
  222. * spinloops. For non SMP kernels, the secondary cpus never get out
  223. * of the common spinloop.
  224. */
  225. ptr = (unsigned long *)((unsigned long)&__secondary_hold_spinloop
  226. - PHYSICAL_START);
  227. *ptr = __pa(generic_secondary_smp_init);
  228. /* And wait a bit for them to catch up */
  229. for (i = 0; i < 100000; i++) {
  230. mb();
  231. HMT_low();
  232. if (spinning_secondaries == 0)
  233. break;
  234. udelay(1);
  235. }
  236. DBG("spinning_secondaries = %d\n", spinning_secondaries);
  237. DBG(" <- smp_release_cpus()\n");
  238. }
  239. #endif /* CONFIG_SMP || CONFIG_KEXEC */
  240. /*
  241. * Initialize some remaining members of the ppc64_caches and systemcfg
  242. * structures
  243. * (at least until we get rid of them completely). This is mostly some
  244. * cache informations about the CPU that will be used by cache flush
  245. * routines and/or provided to userland
  246. */
  247. static void __init initialize_cache_info(void)
  248. {
  249. struct device_node *np;
  250. unsigned long num_cpus = 0;
  251. DBG(" -> initialize_cache_info()\n");
  252. for_each_node_by_type(np, "cpu") {
  253. num_cpus += 1;
  254. /*
  255. * We're assuming *all* of the CPUs have the same
  256. * d-cache and i-cache sizes... -Peter
  257. */
  258. if (num_cpus == 1) {
  259. const u32 *sizep, *lsizep;
  260. u32 size, lsize;
  261. size = 0;
  262. lsize = cur_cpu_spec->dcache_bsize;
  263. sizep = of_get_property(np, "d-cache-size", NULL);
  264. if (sizep != NULL)
  265. size = *sizep;
  266. lsizep = of_get_property(np, "d-cache-block-size",
  267. NULL);
  268. /* fallback if block size missing */
  269. if (lsizep == NULL)
  270. lsizep = of_get_property(np,
  271. "d-cache-line-size",
  272. NULL);
  273. if (lsizep != NULL)
  274. lsize = *lsizep;
  275. if (sizep == 0 || lsizep == 0)
  276. DBG("Argh, can't find dcache properties ! "
  277. "sizep: %p, lsizep: %p\n", sizep, lsizep);
  278. ppc64_caches.dsize = size;
  279. ppc64_caches.dline_size = lsize;
  280. ppc64_caches.log_dline_size = __ilog2(lsize);
  281. ppc64_caches.dlines_per_page = PAGE_SIZE / lsize;
  282. size = 0;
  283. lsize = cur_cpu_spec->icache_bsize;
  284. sizep = of_get_property(np, "i-cache-size", NULL);
  285. if (sizep != NULL)
  286. size = *sizep;
  287. lsizep = of_get_property(np, "i-cache-block-size",
  288. NULL);
  289. if (lsizep == NULL)
  290. lsizep = of_get_property(np,
  291. "i-cache-line-size",
  292. NULL);
  293. if (lsizep != NULL)
  294. lsize = *lsizep;
  295. if (sizep == 0 || lsizep == 0)
  296. DBG("Argh, can't find icache properties ! "
  297. "sizep: %p, lsizep: %p\n", sizep, lsizep);
  298. ppc64_caches.isize = size;
  299. ppc64_caches.iline_size = lsize;
  300. ppc64_caches.log_iline_size = __ilog2(lsize);
  301. ppc64_caches.ilines_per_page = PAGE_SIZE / lsize;
  302. }
  303. }
  304. DBG(" <- initialize_cache_info()\n");
  305. }
  306. /*
  307. * Do some initial setup of the system. The parameters are those which
  308. * were passed in from the bootloader.
  309. */
  310. void __init setup_system(void)
  311. {
  312. DBG(" -> setup_system()\n");
  313. /* Apply the CPUs-specific and firmware specific fixups to kernel
  314. * text (nop out sections not relevant to this CPU or this firmware)
  315. */
  316. do_feature_fixups(cur_cpu_spec->cpu_features,
  317. &__start___ftr_fixup, &__stop___ftr_fixup);
  318. do_feature_fixups(cur_cpu_spec->mmu_features,
  319. &__start___mmu_ftr_fixup, &__stop___mmu_ftr_fixup);
  320. do_feature_fixups(powerpc_firmware_features,
  321. &__start___fw_ftr_fixup, &__stop___fw_ftr_fixup);
  322. do_lwsync_fixups(cur_cpu_spec->cpu_features,
  323. &__start___lwsync_fixup, &__stop___lwsync_fixup);
  324. do_final_fixups();
  325. /*
  326. * Unflatten the device-tree passed by prom_init or kexec
  327. */
  328. unflatten_device_tree();
  329. /*
  330. * Fill the ppc64_caches & systemcfg structures with informations
  331. * retrieved from the device-tree.
  332. */
  333. initialize_cache_info();
  334. #ifdef CONFIG_PPC_RTAS
  335. /*
  336. * Initialize RTAS if available
  337. */
  338. rtas_initialize();
  339. #endif /* CONFIG_PPC_RTAS */
  340. /*
  341. * Check if we have an initrd provided via the device-tree
  342. */
  343. check_for_initrd();
  344. /*
  345. * Do some platform specific early initializations, that includes
  346. * setting up the hash table pointers. It also sets up some interrupt-mapping
  347. * related options that will be used by finish_device_tree()
  348. */
  349. if (ppc_md.init_early)
  350. ppc_md.init_early();
  351. /*
  352. * We can discover serial ports now since the above did setup the
  353. * hash table management for us, thus ioremap works. We do that early
  354. * so that further code can be debugged
  355. */
  356. find_legacy_serial_ports();
  357. /*
  358. * Register early console
  359. */
  360. register_early_udbg_console();
  361. /*
  362. * Initialize xmon
  363. */
  364. xmon_setup();
  365. smp_setup_cpu_maps();
  366. check_smt_enabled();
  367. #ifdef CONFIG_SMP
  368. /* Release secondary cpus out of their spinloops at 0x60 now that
  369. * we can map physical -> logical CPU ids
  370. */
  371. smp_release_cpus();
  372. #endif
  373. printk("Starting Linux PPC64 %s\n", init_utsname()->version);
  374. printk("-----------------------------------------------------\n");
  375. printk("ppc64_pft_size = 0x%llx\n", ppc64_pft_size);
  376. printk("physicalMemorySize = 0x%llx\n", memblock_phys_mem_size());
  377. if (ppc64_caches.dline_size != 0x80)
  378. printk("ppc64_caches.dcache_line_size = 0x%x\n",
  379. ppc64_caches.dline_size);
  380. if (ppc64_caches.iline_size != 0x80)
  381. printk("ppc64_caches.icache_line_size = 0x%x\n",
  382. ppc64_caches.iline_size);
  383. #ifdef CONFIG_PPC_STD_MMU_64
  384. if (htab_address)
  385. printk("htab_address = 0x%p\n", htab_address);
  386. printk("htab_hash_mask = 0x%lx\n", htab_hash_mask);
  387. #endif /* CONFIG_PPC_STD_MMU_64 */
  388. if (PHYSICAL_START > 0)
  389. printk("physical_start = 0x%llx\n",
  390. (unsigned long long)PHYSICAL_START);
  391. printk("-----------------------------------------------------\n");
  392. DBG(" <- setup_system()\n");
  393. }
  394. /* This returns the limit below which memory accesses to the linear
  395. * mapping are guarnateed not to cause a TLB or SLB miss. This is
  396. * used to allocate interrupt or emergency stacks for which our
  397. * exception entry path doesn't deal with being interrupted.
  398. */
  399. static u64 safe_stack_limit(void)
  400. {
  401. #ifdef CONFIG_PPC_BOOK3E
  402. /* Freescale BookE bolts the entire linear mapping */
  403. if (mmu_has_feature(MMU_FTR_TYPE_FSL_E))
  404. return linear_map_top;
  405. /* Other BookE, we assume the first GB is bolted */
  406. return 1ul << 30;
  407. #else
  408. /* BookS, the first segment is bolted */
  409. if (mmu_has_feature(MMU_FTR_1T_SEGMENT))
  410. return 1UL << SID_SHIFT_1T;
  411. return 1UL << SID_SHIFT;
  412. #endif
  413. }
  414. static void __init irqstack_early_init(void)
  415. {
  416. u64 limit = safe_stack_limit();
  417. unsigned int i;
  418. /*
  419. * Interrupt stacks must be in the first segment since we
  420. * cannot afford to take SLB misses on them.
  421. */
  422. for_each_possible_cpu(i) {
  423. softirq_ctx[i] = (struct thread_info *)
  424. __va(memblock_alloc_base(THREAD_SIZE,
  425. THREAD_SIZE, limit));
  426. hardirq_ctx[i] = (struct thread_info *)
  427. __va(memblock_alloc_base(THREAD_SIZE,
  428. THREAD_SIZE, limit));
  429. }
  430. }
  431. #ifdef CONFIG_PPC_BOOK3E
  432. static void __init exc_lvl_early_init(void)
  433. {
  434. extern unsigned int interrupt_base_book3e;
  435. extern unsigned int exc_debug_debug_book3e;
  436. unsigned int i;
  437. for_each_possible_cpu(i) {
  438. critirq_ctx[i] = (struct thread_info *)
  439. __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
  440. dbgirq_ctx[i] = (struct thread_info *)
  441. __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
  442. mcheckirq_ctx[i] = (struct thread_info *)
  443. __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
  444. }
  445. if (cpu_has_feature(CPU_FTR_DEBUG_LVL_EXC))
  446. patch_branch(&interrupt_base_book3e + (0x040 / 4) + 1,
  447. (unsigned long)&exc_debug_debug_book3e, 0);
  448. }
  449. #else
  450. #define exc_lvl_early_init()
  451. #endif
  452. /*
  453. * Stack space used when we detect a bad kernel stack pointer, and
  454. * early in SMP boots before relocation is enabled.
  455. */
  456. static void __init emergency_stack_init(void)
  457. {
  458. u64 limit;
  459. unsigned int i;
  460. /*
  461. * Emergency stacks must be under 256MB, we cannot afford to take
  462. * SLB misses on them. The ABI also requires them to be 128-byte
  463. * aligned.
  464. *
  465. * Since we use these as temporary stacks during secondary CPU
  466. * bringup, we need to get at them in real mode. This means they
  467. * must also be within the RMO region.
  468. */
  469. limit = min(safe_stack_limit(), ppc64_rma_size);
  470. for_each_possible_cpu(i) {
  471. unsigned long sp;
  472. sp = memblock_alloc_base(THREAD_SIZE, THREAD_SIZE, limit);
  473. sp += THREAD_SIZE;
  474. paca[i].emergency_sp = __va(sp);
  475. }
  476. }
  477. /*
  478. * Called into from start_kernel this initializes bootmem, which is used
  479. * to manage page allocation until mem_init is called.
  480. */
  481. void __init setup_arch(char **cmdline_p)
  482. {
  483. ppc64_boot_msg(0x12, "Setup Arch");
  484. *cmdline_p = cmd_line;
  485. /*
  486. * Set cache line size based on type of cpu as a default.
  487. * Systems with OF can look in the properties on the cpu node(s)
  488. * for a possibly more accurate value.
  489. */
  490. dcache_bsize = ppc64_caches.dline_size;
  491. icache_bsize = ppc64_caches.iline_size;
  492. /* reboot on panic */
  493. panic_timeout = 180;
  494. if (ppc_md.panic)
  495. setup_panic();
  496. init_mm.start_code = (unsigned long)_stext;
  497. init_mm.end_code = (unsigned long) _etext;
  498. init_mm.end_data = (unsigned long) _edata;
  499. init_mm.brk = klimit;
  500. irqstack_early_init();
  501. exc_lvl_early_init();
  502. emergency_stack_init();
  503. #ifdef CONFIG_PPC_STD_MMU_64
  504. stabs_alloc();
  505. #endif
  506. /* set up the bootmem stuff with available memory */
  507. do_init_bootmem();
  508. sparse_init();
  509. #ifdef CONFIG_DUMMY_CONSOLE
  510. conswitchp = &dummy_con;
  511. #endif
  512. if (ppc_md.setup_arch)
  513. ppc_md.setup_arch();
  514. paging_init();
  515. /* Initialize the MMU context management stuff */
  516. mmu_context_init();
  517. kvm_linear_init();
  518. /* Interrupt code needs to be 64K-aligned */
  519. if ((unsigned long)_stext & 0xffff)
  520. panic("Kernelbase not 64K-aligned (0x%lx)!\n",
  521. (unsigned long)_stext);
  522. ppc64_boot_msg(0x15, "Setup Done");
  523. }
  524. /* ToDo: do something useful if ppc_md is not yet setup. */
  525. #define PPC64_LINUX_FUNCTION 0x0f000000
  526. #define PPC64_IPL_MESSAGE 0xc0000000
  527. #define PPC64_TERM_MESSAGE 0xb0000000
  528. static void ppc64_do_msg(unsigned int src, const char *msg)
  529. {
  530. if (ppc_md.progress) {
  531. char buf[128];
  532. sprintf(buf, "%08X\n", src);
  533. ppc_md.progress(buf, 0);
  534. snprintf(buf, 128, "%s", msg);
  535. ppc_md.progress(buf, 0);
  536. }
  537. }
  538. /* Print a boot progress message. */
  539. void ppc64_boot_msg(unsigned int src, const char *msg)
  540. {
  541. ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_IPL_MESSAGE|src, msg);
  542. printk("[boot]%04x %s\n", src, msg);
  543. }
  544. #ifdef CONFIG_SMP
  545. #define PCPU_DYN_SIZE ()
  546. static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
  547. {
  548. return __alloc_bootmem_node(NODE_DATA(cpu_to_node(cpu)), size, align,
  549. __pa(MAX_DMA_ADDRESS));
  550. }
  551. static void __init pcpu_fc_free(void *ptr, size_t size)
  552. {
  553. free_bootmem(__pa(ptr), size);
  554. }
  555. static int pcpu_cpu_distance(unsigned int from, unsigned int to)
  556. {
  557. if (cpu_to_node(from) == cpu_to_node(to))
  558. return LOCAL_DISTANCE;
  559. else
  560. return REMOTE_DISTANCE;
  561. }
  562. unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
  563. EXPORT_SYMBOL(__per_cpu_offset);
  564. void __init setup_per_cpu_areas(void)
  565. {
  566. const size_t dyn_size = PERCPU_MODULE_RESERVE + PERCPU_DYNAMIC_RESERVE;
  567. size_t atom_size;
  568. unsigned long delta;
  569. unsigned int cpu;
  570. int rc;
  571. /*
  572. * Linear mapping is one of 4K, 1M and 16M. For 4K, no need
  573. * to group units. For larger mappings, use 1M atom which
  574. * should be large enough to contain a number of units.
  575. */
  576. if (mmu_linear_psize == MMU_PAGE_4K)
  577. atom_size = PAGE_SIZE;
  578. else
  579. atom_size = 1 << 20;
  580. rc = pcpu_embed_first_chunk(0, dyn_size, atom_size, pcpu_cpu_distance,
  581. pcpu_fc_alloc, pcpu_fc_free);
  582. if (rc < 0)
  583. panic("cannot initialize percpu area (err=%d)", rc);
  584. delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
  585. for_each_possible_cpu(cpu) {
  586. __per_cpu_offset[cpu] = delta + pcpu_unit_offsets[cpu];
  587. paca[cpu].data_offset = __per_cpu_offset[cpu];
  588. }
  589. }
  590. #endif
  591. #ifdef CONFIG_PPC_INDIRECT_IO
  592. struct ppc_pci_io ppc_pci_io;
  593. EXPORT_SYMBOL(ppc_pci_io);
  594. #endif /* CONFIG_PPC_INDIRECT_IO */