tlb_nohash.c 18 KB

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