tlb_nohash.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /*
  2. * This file contains the routines for TLB flushing.
  3. * On machines where the MMU does not use a hash table to store virtual to
  4. * physical translations (ie, SW loaded TLBs or Book3E compilant processors,
  5. * this does -not- include 603 however which shares the implementation with
  6. * hash based processors)
  7. *
  8. * -- BenH
  9. *
  10. * Copyright 2008,2009 Ben Herrenschmidt <benh@kernel.crashing.org>
  11. * IBM Corp.
  12. *
  13. * Derived from arch/ppc/mm/init.c:
  14. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  15. *
  16. * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
  17. * and Cort Dougan (PReP) (cort@cs.nmt.edu)
  18. * Copyright (C) 1996 Paul Mackerras
  19. *
  20. * Derived from "arch/i386/mm/init.c"
  21. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  22. *
  23. * This program is free software; you can redistribute it and/or
  24. * modify it under the terms of the GNU General Public License
  25. * as published by the Free Software Foundation; either version
  26. * 2 of the License, or (at your option) any later version.
  27. *
  28. */
  29. #include <linux/kernel.h>
  30. #include <linux/export.h>
  31. #include <linux/mm.h>
  32. #include <linux/init.h>
  33. #include <linux/highmem.h>
  34. #include <linux/pagemap.h>
  35. #include <linux/preempt.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/memblock.h>
  38. #include <linux/of_fdt.h>
  39. #include <linux/hugetlb.h>
  40. #include <asm/tlbflush.h>
  41. #include <asm/tlb.h>
  42. #include <asm/code-patching.h>
  43. #include <asm/hugetlb.h>
  44. #include "mmu_decl.h"
  45. /*
  46. * This struct lists the sw-supported page sizes. The hardawre MMU may support
  47. * other sizes not listed here. The .ind field is only used on MMUs that have
  48. * indirect page table entries.
  49. */
  50. #ifdef CONFIG_PPC_BOOK3E_MMU
  51. #ifdef CONFIG_PPC_FSL_BOOK3E
  52. struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT] = {
  53. [MMU_PAGE_4K] = {
  54. .shift = 12,
  55. .enc = BOOK3E_PAGESZ_4K,
  56. },
  57. [MMU_PAGE_4M] = {
  58. .shift = 22,
  59. .enc = BOOK3E_PAGESZ_4M,
  60. },
  61. [MMU_PAGE_16M] = {
  62. .shift = 24,
  63. .enc = BOOK3E_PAGESZ_16M,
  64. },
  65. [MMU_PAGE_64M] = {
  66. .shift = 26,
  67. .enc = BOOK3E_PAGESZ_64M,
  68. },
  69. [MMU_PAGE_256M] = {
  70. .shift = 28,
  71. .enc = BOOK3E_PAGESZ_256M,
  72. },
  73. [MMU_PAGE_1G] = {
  74. .shift = 30,
  75. .enc = BOOK3E_PAGESZ_1GB,
  76. },
  77. };
  78. #else
  79. struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT] = {
  80. [MMU_PAGE_4K] = {
  81. .shift = 12,
  82. .ind = 20,
  83. .enc = BOOK3E_PAGESZ_4K,
  84. },
  85. [MMU_PAGE_16K] = {
  86. .shift = 14,
  87. .enc = BOOK3E_PAGESZ_16K,
  88. },
  89. [MMU_PAGE_64K] = {
  90. .shift = 16,
  91. .ind = 28,
  92. .enc = BOOK3E_PAGESZ_64K,
  93. },
  94. [MMU_PAGE_1M] = {
  95. .shift = 20,
  96. .enc = BOOK3E_PAGESZ_1M,
  97. },
  98. [MMU_PAGE_16M] = {
  99. .shift = 24,
  100. .ind = 36,
  101. .enc = BOOK3E_PAGESZ_16M,
  102. },
  103. [MMU_PAGE_256M] = {
  104. .shift = 28,
  105. .enc = BOOK3E_PAGESZ_256M,
  106. },
  107. [MMU_PAGE_1G] = {
  108. .shift = 30,
  109. .enc = BOOK3E_PAGESZ_1GB,
  110. },
  111. };
  112. #endif /* CONFIG_FSL_BOOKE */
  113. static inline int mmu_get_tsize(int psize)
  114. {
  115. return mmu_psize_defs[psize].enc;
  116. }
  117. #else
  118. static inline int mmu_get_tsize(int psize)
  119. {
  120. /* This isn't used on !Book3E for now */
  121. return 0;
  122. }
  123. #endif /* CONFIG_PPC_BOOK3E_MMU */
  124. /* The variables below are currently only used on 64-bit Book3E
  125. * though this will probably be made common with other nohash
  126. * implementations at some point
  127. */
  128. #ifdef CONFIG_PPC64
  129. int mmu_linear_psize; /* Page size used for the linear mapping */
  130. int mmu_pte_psize; /* Page size used for PTE pages */
  131. int mmu_vmemmap_psize; /* Page size used for the virtual mem map */
  132. int book3e_htw_enabled; /* Is HW tablewalk enabled ? */
  133. unsigned long linear_map_top; /* Top of linear mapping */
  134. #endif /* CONFIG_PPC64 */
  135. #ifdef CONFIG_PPC_FSL_BOOK3E
  136. /* next_tlbcam_idx is used to round-robin tlbcam entry assignment */
  137. DEFINE_PER_CPU(int, next_tlbcam_idx);
  138. EXPORT_PER_CPU_SYMBOL(next_tlbcam_idx);
  139. #endif
  140. /*
  141. * Base TLB flushing operations:
  142. *
  143. * - flush_tlb_mm(mm) flushes the specified mm context TLB's
  144. * - flush_tlb_page(vma, vmaddr) flushes one page
  145. * - flush_tlb_range(vma, start, end) flushes a range of pages
  146. * - flush_tlb_kernel_range(start, end) flushes kernel pages
  147. *
  148. * - local_* variants of page and mm only apply to the current
  149. * processor
  150. */
  151. /*
  152. * These are the base non-SMP variants of page and mm flushing
  153. */
  154. void local_flush_tlb_mm(struct mm_struct *mm)
  155. {
  156. unsigned int pid;
  157. preempt_disable();
  158. pid = mm->context.id;
  159. if (pid != MMU_NO_CONTEXT)
  160. _tlbil_pid(pid);
  161. preempt_enable();
  162. }
  163. EXPORT_SYMBOL(local_flush_tlb_mm);
  164. void __local_flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,
  165. int tsize, int ind)
  166. {
  167. unsigned int pid;
  168. preempt_disable();
  169. pid = mm ? mm->context.id : 0;
  170. if (pid != MMU_NO_CONTEXT)
  171. _tlbil_va(vmaddr, pid, tsize, ind);
  172. preempt_enable();
  173. }
  174. void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  175. {
  176. __local_flush_tlb_page(vma ? vma->vm_mm : NULL, vmaddr,
  177. mmu_get_tsize(mmu_virtual_psize), 0);
  178. }
  179. EXPORT_SYMBOL(local_flush_tlb_page);
  180. /*
  181. * And here are the SMP non-local implementations
  182. */
  183. #ifdef CONFIG_SMP
  184. static DEFINE_RAW_SPINLOCK(tlbivax_lock);
  185. static int mm_is_core_local(struct mm_struct *mm)
  186. {
  187. return cpumask_subset(mm_cpumask(mm),
  188. topology_thread_cpumask(smp_processor_id()));
  189. }
  190. struct tlb_flush_param {
  191. unsigned long addr;
  192. unsigned int pid;
  193. unsigned int tsize;
  194. unsigned int ind;
  195. };
  196. static void do_flush_tlb_mm_ipi(void *param)
  197. {
  198. struct tlb_flush_param *p = param;
  199. _tlbil_pid(p ? p->pid : 0);
  200. }
  201. static void do_flush_tlb_page_ipi(void *param)
  202. {
  203. struct tlb_flush_param *p = param;
  204. _tlbil_va(p->addr, p->pid, p->tsize, p->ind);
  205. }
  206. /* Note on invalidations and PID:
  207. *
  208. * We snapshot the PID with preempt disabled. At this point, it can still
  209. * change either because:
  210. * - our context is being stolen (PID -> NO_CONTEXT) on another CPU
  211. * - we are invaliating some target that isn't currently running here
  212. * and is concurrently acquiring a new PID on another CPU
  213. * - some other CPU is re-acquiring a lost PID for this mm
  214. * etc...
  215. *
  216. * However, this shouldn't be a problem as we only guarantee
  217. * invalidation of TLB entries present prior to this call, so we
  218. * don't care about the PID changing, and invalidating a stale PID
  219. * is generally harmless.
  220. */
  221. void flush_tlb_mm(struct mm_struct *mm)
  222. {
  223. unsigned int pid;
  224. preempt_disable();
  225. pid = mm->context.id;
  226. if (unlikely(pid == MMU_NO_CONTEXT))
  227. goto no_context;
  228. if (!mm_is_core_local(mm)) {
  229. struct tlb_flush_param p = { .pid = pid };
  230. /* Ignores smp_processor_id() even if set. */
  231. smp_call_function_many(mm_cpumask(mm),
  232. do_flush_tlb_mm_ipi, &p, 1);
  233. }
  234. _tlbil_pid(pid);
  235. no_context:
  236. preempt_enable();
  237. }
  238. EXPORT_SYMBOL(flush_tlb_mm);
  239. void __flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,
  240. int tsize, int ind)
  241. {
  242. struct cpumask *cpu_mask;
  243. unsigned int pid;
  244. preempt_disable();
  245. pid = mm ? mm->context.id : 0;
  246. if (unlikely(pid == MMU_NO_CONTEXT))
  247. goto bail;
  248. cpu_mask = mm_cpumask(mm);
  249. if (!mm_is_core_local(mm)) {
  250. /* If broadcast tlbivax is supported, use it */
  251. if (mmu_has_feature(MMU_FTR_USE_TLBIVAX_BCAST)) {
  252. int lock = mmu_has_feature(MMU_FTR_LOCK_BCAST_INVAL);
  253. if (lock)
  254. raw_spin_lock(&tlbivax_lock);
  255. _tlbivax_bcast(vmaddr, pid, tsize, ind);
  256. if (lock)
  257. raw_spin_unlock(&tlbivax_lock);
  258. goto bail;
  259. } else {
  260. struct tlb_flush_param p = {
  261. .pid = pid,
  262. .addr = vmaddr,
  263. .tsize = tsize,
  264. .ind = ind,
  265. };
  266. /* Ignores smp_processor_id() even if set in cpu_mask */
  267. smp_call_function_many(cpu_mask,
  268. do_flush_tlb_page_ipi, &p, 1);
  269. }
  270. }
  271. _tlbil_va(vmaddr, pid, tsize, ind);
  272. bail:
  273. preempt_enable();
  274. }
  275. void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  276. {
  277. #ifdef CONFIG_HUGETLB_PAGE
  278. if (is_vm_hugetlb_page(vma))
  279. flush_hugetlb_page(vma, vmaddr);
  280. #endif
  281. __flush_tlb_page(vma ? vma->vm_mm : NULL, vmaddr,
  282. mmu_get_tsize(mmu_virtual_psize), 0);
  283. }
  284. EXPORT_SYMBOL(flush_tlb_page);
  285. #endif /* CONFIG_SMP */
  286. #ifdef CONFIG_PPC_47x
  287. void __init early_init_mmu_47x(void)
  288. {
  289. #ifdef CONFIG_SMP
  290. unsigned long root = of_get_flat_dt_root();
  291. if (of_get_flat_dt_prop(root, "cooperative-partition", NULL))
  292. mmu_clear_feature(MMU_FTR_USE_TLBIVAX_BCAST);
  293. #endif /* CONFIG_SMP */
  294. }
  295. #endif /* CONFIG_PPC_47x */
  296. /*
  297. * Flush kernel TLB entries in the given range
  298. */
  299. void flush_tlb_kernel_range(unsigned long start, unsigned long end)
  300. {
  301. #ifdef CONFIG_SMP
  302. preempt_disable();
  303. smp_call_function(do_flush_tlb_mm_ipi, NULL, 1);
  304. _tlbil_pid(0);
  305. preempt_enable();
  306. #else
  307. _tlbil_pid(0);
  308. #endif
  309. }
  310. EXPORT_SYMBOL(flush_tlb_kernel_range);
  311. /*
  312. * Currently, for range flushing, we just do a full mm flush. This should
  313. * be optimized based on a threshold on the size of the range, since
  314. * some implementation can stack multiple tlbivax before a tlbsync but
  315. * for now, we keep it that way
  316. */
  317. void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  318. unsigned long end)
  319. {
  320. flush_tlb_mm(vma->vm_mm);
  321. }
  322. EXPORT_SYMBOL(flush_tlb_range);
  323. void tlb_flush(struct mmu_gather *tlb)
  324. {
  325. flush_tlb_mm(tlb->mm);
  326. }
  327. /*
  328. * Below are functions specific to the 64-bit variant of Book3E though that
  329. * may change in the future
  330. */
  331. #ifdef CONFIG_PPC64
  332. /*
  333. * Handling of virtual linear page tables or indirect TLB entries
  334. * flushing when PTE pages are freed
  335. */
  336. void tlb_flush_pgtable(struct mmu_gather *tlb, unsigned long address)
  337. {
  338. int tsize = mmu_psize_defs[mmu_pte_psize].enc;
  339. if (book3e_htw_enabled) {
  340. unsigned long start = address & PMD_MASK;
  341. unsigned long end = address + PMD_SIZE;
  342. unsigned long size = 1UL << mmu_psize_defs[mmu_pte_psize].shift;
  343. /* This isn't the most optimal, ideally we would factor out the
  344. * while preempt & CPU mask mucking around, or even the IPI but
  345. * it will do for now
  346. */
  347. while (start < end) {
  348. __flush_tlb_page(tlb->mm, start, tsize, 1);
  349. start += size;
  350. }
  351. } else {
  352. unsigned long rmask = 0xf000000000000000ul;
  353. unsigned long rid = (address & rmask) | 0x1000000000000000ul;
  354. unsigned long vpte = address & ~rmask;
  355. #ifdef CONFIG_PPC_64K_PAGES
  356. vpte = (vpte >> (PAGE_SHIFT - 4)) & ~0xfffful;
  357. #else
  358. vpte = (vpte >> (PAGE_SHIFT - 3)) & ~0xffful;
  359. #endif
  360. vpte |= rid;
  361. __flush_tlb_page(tlb->mm, vpte, tsize, 0);
  362. }
  363. }
  364. static void setup_page_sizes(void)
  365. {
  366. unsigned int tlb0cfg;
  367. unsigned int tlb0ps;
  368. unsigned int eptcfg;
  369. int i, psize;
  370. #ifdef CONFIG_PPC_FSL_BOOK3E
  371. unsigned int mmucfg = mfspr(SPRN_MMUCFG);
  372. if (((mmucfg & MMUCFG_MAVN) == MMUCFG_MAVN_V1) &&
  373. (mmu_has_feature(MMU_FTR_TYPE_FSL_E))) {
  374. unsigned int tlb1cfg = mfspr(SPRN_TLB1CFG);
  375. unsigned int min_pg, max_pg;
  376. min_pg = (tlb1cfg & TLBnCFG_MINSIZE) >> TLBnCFG_MINSIZE_SHIFT;
  377. max_pg = (tlb1cfg & TLBnCFG_MAXSIZE) >> TLBnCFG_MAXSIZE_SHIFT;
  378. for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
  379. struct mmu_psize_def *def;
  380. unsigned int shift;
  381. def = &mmu_psize_defs[psize];
  382. shift = def->shift;
  383. if (shift == 0)
  384. continue;
  385. /* adjust to be in terms of 4^shift Kb */
  386. shift = (shift - 10) >> 1;
  387. if ((shift >= min_pg) && (shift <= max_pg))
  388. def->flags |= MMU_PAGE_SIZE_DIRECT;
  389. }
  390. goto no_indirect;
  391. }
  392. #endif
  393. tlb0cfg = mfspr(SPRN_TLB0CFG);
  394. tlb0ps = mfspr(SPRN_TLB0PS);
  395. eptcfg = mfspr(SPRN_EPTCFG);
  396. /* Look for supported direct sizes */
  397. for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
  398. struct mmu_psize_def *def = &mmu_psize_defs[psize];
  399. if (tlb0ps & (1U << (def->shift - 10)))
  400. def->flags |= MMU_PAGE_SIZE_DIRECT;
  401. }
  402. /* Indirect page sizes supported ? */
  403. if ((tlb0cfg & TLBnCFG_IND) == 0)
  404. goto no_indirect;
  405. /* Now, we only deal with one IND page size for each
  406. * direct size. Hopefully all implementations today are
  407. * unambiguous, but we might want to be careful in the
  408. * future.
  409. */
  410. for (i = 0; i < 3; i++) {
  411. unsigned int ps, sps;
  412. sps = eptcfg & 0x1f;
  413. eptcfg >>= 5;
  414. ps = eptcfg & 0x1f;
  415. eptcfg >>= 5;
  416. if (!ps || !sps)
  417. continue;
  418. for (psize = 0; psize < MMU_PAGE_COUNT; psize++) {
  419. struct mmu_psize_def *def = &mmu_psize_defs[psize];
  420. if (ps == (def->shift - 10))
  421. def->flags |= MMU_PAGE_SIZE_INDIRECT;
  422. if (sps == (def->shift - 10))
  423. def->ind = ps + 10;
  424. }
  425. }
  426. no_indirect:
  427. /* Cleanup array and print summary */
  428. pr_info("MMU: Supported page sizes\n");
  429. for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
  430. struct mmu_psize_def *def = &mmu_psize_defs[psize];
  431. const char *__page_type_names[] = {
  432. "unsupported",
  433. "direct",
  434. "indirect",
  435. "direct & indirect"
  436. };
  437. if (def->flags == 0) {
  438. def->shift = 0;
  439. continue;
  440. }
  441. pr_info(" %8ld KB as %s\n", 1ul << (def->shift - 10),
  442. __page_type_names[def->flags & 0x3]);
  443. }
  444. }
  445. static void __patch_exception(int exc, unsigned long addr)
  446. {
  447. extern unsigned int interrupt_base_book3e;
  448. unsigned int *ibase = &interrupt_base_book3e;
  449. /* Our exceptions vectors start with a NOP and -then- a branch
  450. * to deal with single stepping from userspace which stops on
  451. * the second instruction. Thus we need to patch the second
  452. * instruction of the exception, not the first one
  453. */
  454. patch_branch(ibase + (exc / 4) + 1, addr, 0);
  455. }
  456. #define patch_exception(exc, name) do { \
  457. extern unsigned int name; \
  458. __patch_exception((exc), (unsigned long)&name); \
  459. } while (0)
  460. static void setup_mmu_htw(void)
  461. {
  462. /* Check if HW tablewalk is present, and if yes, enable it by:
  463. *
  464. * - patching the TLB miss handlers to branch to the
  465. * one dedicates to it
  466. *
  467. * - setting the global book3e_htw_enabled
  468. */
  469. unsigned int tlb0cfg = mfspr(SPRN_TLB0CFG);
  470. if ((tlb0cfg & TLBnCFG_IND) &&
  471. (tlb0cfg & TLBnCFG_PT)) {
  472. patch_exception(0x1c0, exc_data_tlb_miss_htw_book3e);
  473. patch_exception(0x1e0, exc_instruction_tlb_miss_htw_book3e);
  474. book3e_htw_enabled = 1;
  475. }
  476. pr_info("MMU: Book3E HW tablewalk %s\n",
  477. book3e_htw_enabled ? "enabled" : "not supported");
  478. }
  479. /*
  480. * Early initialization of the MMU TLB code
  481. */
  482. static void __early_init_mmu(int boot_cpu)
  483. {
  484. unsigned int mas4;
  485. /* XXX This will have to be decided at runtime, but right
  486. * now our boot and TLB miss code hard wires it. Ideally
  487. * we should find out a suitable page size and patch the
  488. * TLB miss code (either that or use the PACA to store
  489. * the value we want)
  490. */
  491. mmu_linear_psize = MMU_PAGE_1G;
  492. /* XXX This should be decided at runtime based on supported
  493. * page sizes in the TLB, but for now let's assume 16M is
  494. * always there and a good fit (which it probably is)
  495. */
  496. mmu_vmemmap_psize = MMU_PAGE_16M;
  497. /* XXX This code only checks for TLB 0 capabilities and doesn't
  498. * check what page size combos are supported by the HW. It
  499. * also doesn't handle the case where a separate array holds
  500. * the IND entries from the array loaded by the PT.
  501. */
  502. if (boot_cpu) {
  503. /* Look for supported page sizes */
  504. setup_page_sizes();
  505. /* Look for HW tablewalk support */
  506. setup_mmu_htw();
  507. }
  508. /* Set MAS4 based on page table setting */
  509. mas4 = 0x4 << MAS4_WIMGED_SHIFT;
  510. if (book3e_htw_enabled) {
  511. mas4 |= mas4 | MAS4_INDD;
  512. #ifdef CONFIG_PPC_64K_PAGES
  513. mas4 |= BOOK3E_PAGESZ_256M << MAS4_TSIZED_SHIFT;
  514. mmu_pte_psize = MMU_PAGE_256M;
  515. #else
  516. mas4 |= BOOK3E_PAGESZ_1M << MAS4_TSIZED_SHIFT;
  517. mmu_pte_psize = MMU_PAGE_1M;
  518. #endif
  519. } else {
  520. #ifdef CONFIG_PPC_64K_PAGES
  521. mas4 |= BOOK3E_PAGESZ_64K << MAS4_TSIZED_SHIFT;
  522. #else
  523. mas4 |= BOOK3E_PAGESZ_4K << MAS4_TSIZED_SHIFT;
  524. #endif
  525. mmu_pte_psize = mmu_virtual_psize;
  526. }
  527. mtspr(SPRN_MAS4, mas4);
  528. /* Set the global containing the top of the linear mapping
  529. * for use by the TLB miss code
  530. */
  531. linear_map_top = memblock_end_of_DRAM();
  532. #ifdef CONFIG_PPC_FSL_BOOK3E
  533. if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
  534. unsigned int num_cams;
  535. /* use a quarter of the TLBCAM for bolted linear map */
  536. num_cams = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) / 4;
  537. linear_map_top = map_mem_in_cams(linear_map_top, num_cams);
  538. /* limit memory so we dont have linear faults */
  539. memblock_enforce_memory_limit(linear_map_top);
  540. patch_exception(0x1c0, exc_data_tlb_miss_bolted_book3e);
  541. patch_exception(0x1e0, exc_instruction_tlb_miss_bolted_book3e);
  542. }
  543. #endif
  544. /* A sync won't hurt us after mucking around with
  545. * the MMU configuration
  546. */
  547. mb();
  548. memblock_set_current_limit(linear_map_top);
  549. }
  550. void __init early_init_mmu(void)
  551. {
  552. __early_init_mmu(1);
  553. }
  554. void __cpuinit early_init_mmu_secondary(void)
  555. {
  556. __early_init_mmu(0);
  557. }
  558. void setup_initial_memory_limit(phys_addr_t first_memblock_base,
  559. phys_addr_t first_memblock_size)
  560. {
  561. /* On non-FSL Embedded 64-bit, we adjust the RMA size to match
  562. * the bolted TLB entry. We know for now that only 1G
  563. * entries are supported though that may eventually
  564. * change.
  565. *
  566. * on FSL Embedded 64-bit, we adjust the RMA size to match the
  567. * first bolted TLB entry size. We still limit max to 1G even if
  568. * the TLB could cover more. This is due to what the early init
  569. * code is setup to do.
  570. *
  571. * We crop it to the size of the first MEMBLOCK to
  572. * avoid going over total available memory just in case...
  573. */
  574. #ifdef CONFIG_PPC_FSL_BOOK3E
  575. if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
  576. unsigned long linear_sz;
  577. linear_sz = calc_cam_sz(first_memblock_size, PAGE_OFFSET,
  578. first_memblock_base);
  579. ppc64_rma_size = min_t(u64, linear_sz, 0x40000000);
  580. } else
  581. #endif
  582. ppc64_rma_size = min_t(u64, first_memblock_size, 0x40000000);
  583. /* Finally limit subsequent allocations */
  584. memblock_set_current_limit(first_memblock_base + ppc64_rma_size);
  585. }
  586. #else /* ! CONFIG_PPC64 */
  587. void __init early_init_mmu(void)
  588. {
  589. #ifdef CONFIG_PPC_47x
  590. early_init_mmu_47x();
  591. #endif
  592. }
  593. #endif /* CONFIG_PPC64 */