setup_64.c 21 KB

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