tlb_low_64e.S 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. /*
  2. * Low level TLB miss handlers for Book3E
  3. *
  4. * Copyright (C) 2008-2009
  5. * Ben. Herrenschmidt (benh@kernel.crashing.org), 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. #include <asm/processor.h>
  13. #include <asm/reg.h>
  14. #include <asm/page.h>
  15. #include <asm/mmu.h>
  16. #include <asm/ppc_asm.h>
  17. #include <asm/asm-offsets.h>
  18. #include <asm/cputable.h>
  19. #include <asm/pgtable.h>
  20. #include <asm/exception-64e.h>
  21. #include <asm/ppc-opcode.h>
  22. #include <asm/kvm_asm.h>
  23. #include <asm/kvm_booke_hv_asm.h>
  24. #ifdef CONFIG_PPC_64K_PAGES
  25. #define VPTE_PMD_SHIFT (PTE_INDEX_SIZE+1)
  26. #else
  27. #define VPTE_PMD_SHIFT (PTE_INDEX_SIZE)
  28. #endif
  29. #define VPTE_PUD_SHIFT (VPTE_PMD_SHIFT + PMD_INDEX_SIZE)
  30. #define VPTE_PGD_SHIFT (VPTE_PUD_SHIFT + PUD_INDEX_SIZE)
  31. #define VPTE_INDEX_SIZE (VPTE_PGD_SHIFT + PGD_INDEX_SIZE)
  32. /**********************************************************************
  33. * *
  34. * TLB miss handling for Book3E with a bolted linear mapping *
  35. * No virtual page table, no nested TLB misses *
  36. * *
  37. **********************************************************************/
  38. /*
  39. * Note that, unlike non-bolted handlers, TLB_EXFRAME is not
  40. * modified by the TLB miss handlers themselves, since the TLB miss
  41. * handler code will not itself cause a recursive TLB miss.
  42. *
  43. * TLB_EXFRAME will be modified when crit/mc/debug exceptions are
  44. * entered/exited.
  45. */
  46. .macro tlb_prolog_bolted intnum addr
  47. mtspr SPRN_SPRG_GEN_SCRATCH,r12
  48. mfspr r12,SPRN_SPRG_TLB_EXFRAME
  49. std r13,EX_TLB_R13(r12)
  50. std r10,EX_TLB_R10(r12)
  51. mfspr r13,SPRN_SPRG_PACA
  52. mfcr r10
  53. std r11,EX_TLB_R11(r12)
  54. #ifdef CONFIG_KVM_BOOKE_HV
  55. BEGIN_FTR_SECTION
  56. mfspr r11, SPRN_SRR1
  57. END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
  58. #endif
  59. DO_KVM \intnum, SPRN_SRR1
  60. std r16,EX_TLB_R16(r12)
  61. mfspr r16,\addr /* get faulting address */
  62. std r14,EX_TLB_R14(r12)
  63. ld r14,PACAPGD(r13)
  64. std r15,EX_TLB_R15(r12)
  65. std r10,EX_TLB_CR(r12)
  66. TLB_MISS_PROLOG_STATS
  67. .endm
  68. .macro tlb_epilog_bolted
  69. ld r14,EX_TLB_CR(r12)
  70. ld r10,EX_TLB_R10(r12)
  71. ld r11,EX_TLB_R11(r12)
  72. ld r13,EX_TLB_R13(r12)
  73. mtcr r14
  74. ld r14,EX_TLB_R14(r12)
  75. ld r15,EX_TLB_R15(r12)
  76. TLB_MISS_RESTORE_STATS
  77. ld r16,EX_TLB_R16(r12)
  78. mfspr r12,SPRN_SPRG_GEN_SCRATCH
  79. .endm
  80. /* Data TLB miss */
  81. START_EXCEPTION(data_tlb_miss_bolted)
  82. tlb_prolog_bolted BOOKE_INTERRUPT_DTLB_MISS SPRN_DEAR
  83. /* We need _PAGE_PRESENT and _PAGE_ACCESSED set */
  84. /* We do the user/kernel test for the PID here along with the RW test
  85. */
  86. /* We pre-test some combination of permissions to avoid double
  87. * faults:
  88. *
  89. * We move the ESR:ST bit into the position of _PAGE_BAP_SW in the PTE
  90. * ESR_ST is 0x00800000
  91. * _PAGE_BAP_SW is 0x00000010
  92. * So the shift is >> 19. This tests for supervisor writeability.
  93. * If the page happens to be supervisor writeable and not user
  94. * writeable, we will take a new fault later, but that should be
  95. * a rare enough case.
  96. *
  97. * We also move ESR_ST in _PAGE_DIRTY position
  98. * _PAGE_DIRTY is 0x00001000 so the shift is >> 11
  99. *
  100. * MAS1 is preset for all we need except for TID that needs to
  101. * be cleared for kernel translations
  102. */
  103. mfspr r11,SPRN_ESR
  104. srdi r15,r16,60 /* get region */
  105. rldicl. r10,r16,64-PGTABLE_EADDR_SIZE,PGTABLE_EADDR_SIZE+4
  106. bne- dtlb_miss_fault_bolted /* Bail if fault addr is invalid */
  107. rlwinm r10,r11,32-19,27,27
  108. rlwimi r10,r11,32-16,19,19
  109. cmpwi r15,0 /* user vs kernel check */
  110. ori r10,r10,_PAGE_PRESENT
  111. oris r11,r10,_PAGE_ACCESSED@h
  112. TLB_MISS_STATS_SAVE_INFO_BOLTED
  113. bne tlb_miss_kernel_bolted
  114. tlb_miss_common_bolted:
  115. /*
  116. * This is the guts of the TLB miss handler for bolted-linear.
  117. * We are entered with:
  118. *
  119. * r16 = faulting address
  120. * r15 = crap (free to use)
  121. * r14 = page table base
  122. * r13 = PACA
  123. * r11 = PTE permission mask
  124. * r10 = crap (free to use)
  125. */
  126. rldicl r15,r16,64-PGDIR_SHIFT+3,64-PGD_INDEX_SIZE-3
  127. cmpldi cr0,r14,0
  128. clrrdi r15,r15,3
  129. beq tlb_miss_fault_bolted /* No PGDIR, bail */
  130. BEGIN_MMU_FTR_SECTION
  131. /* Set the TLB reservation and search for existing entry. Then load
  132. * the entry.
  133. */
  134. PPC_TLBSRX_DOT(0,R16)
  135. ldx r14,r14,r15 /* grab pgd entry */
  136. beq tlb_miss_done_bolted /* tlb exists already, bail */
  137. MMU_FTR_SECTION_ELSE
  138. ldx r14,r14,r15 /* grab pgd entry */
  139. ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_USE_TLBRSRV)
  140. #ifndef CONFIG_PPC_64K_PAGES
  141. rldicl r15,r16,64-PUD_SHIFT+3,64-PUD_INDEX_SIZE-3
  142. clrrdi r15,r15,3
  143. cmpdi cr0,r14,0
  144. bge tlb_miss_fault_bolted /* Bad pgd entry or hugepage; bail */
  145. ldx r14,r14,r15 /* grab pud entry */
  146. #endif /* CONFIG_PPC_64K_PAGES */
  147. rldicl r15,r16,64-PMD_SHIFT+3,64-PMD_INDEX_SIZE-3
  148. clrrdi r15,r15,3
  149. cmpdi cr0,r14,0
  150. bge tlb_miss_fault_bolted
  151. ldx r14,r14,r15 /* Grab pmd entry */
  152. rldicl r15,r16,64-PAGE_SHIFT+3,64-PTE_INDEX_SIZE-3
  153. clrrdi r15,r15,3
  154. cmpdi cr0,r14,0
  155. bge tlb_miss_fault_bolted
  156. ldx r14,r14,r15 /* Grab PTE, normal (!huge) page */
  157. /* Check if required permissions are met */
  158. andc. r15,r11,r14
  159. rldicr r15,r14,64-(PTE_RPN_SHIFT-PAGE_SHIFT),63-PAGE_SHIFT
  160. bne- tlb_miss_fault_bolted
  161. /* Now we build the MAS:
  162. *
  163. * MAS 0 : Fully setup with defaults in MAS4 and TLBnCFG
  164. * MAS 1 : Almost fully setup
  165. * - PID already updated by caller if necessary
  166. * - TSIZE need change if !base page size, not
  167. * yet implemented for now
  168. * MAS 2 : Defaults not useful, need to be redone
  169. * MAS 3+7 : Needs to be done
  170. */
  171. clrrdi r11,r16,12 /* Clear low crap in EA */
  172. clrldi r15,r15,12 /* Clear crap at the top */
  173. rlwimi r11,r14,32-19,27,31 /* Insert WIMGE */
  174. rlwimi r15,r14,32-8,22,25 /* Move in U bits */
  175. mtspr SPRN_MAS2,r11
  176. andi. r11,r14,_PAGE_DIRTY
  177. rlwimi r15,r14,32-2,26,31 /* Move in BAP bits */
  178. /* Mask out SW and UW if !DIRTY (XXX optimize this !) */
  179. bne 1f
  180. li r11,MAS3_SW|MAS3_UW
  181. andc r15,r15,r11
  182. 1:
  183. mtspr SPRN_MAS7_MAS3,r15
  184. tlbwe
  185. tlb_miss_done_bolted:
  186. TLB_MISS_STATS_X(MMSTAT_TLB_MISS_NORM_OK)
  187. tlb_epilog_bolted
  188. rfi
  189. itlb_miss_kernel_bolted:
  190. li r11,_PAGE_PRESENT|_PAGE_BAP_SX /* Base perm */
  191. oris r11,r11,_PAGE_ACCESSED@h
  192. tlb_miss_kernel_bolted:
  193. mfspr r10,SPRN_MAS1
  194. ld r14,PACA_KERNELPGD(r13)
  195. cmpldi cr0,r15,8 /* Check for vmalloc region */
  196. rlwinm r10,r10,0,16,1 /* Clear TID */
  197. mtspr SPRN_MAS1,r10
  198. beq+ tlb_miss_common_bolted
  199. tlb_miss_fault_bolted:
  200. /* We need to check if it was an instruction miss */
  201. andi. r10,r11,_PAGE_EXEC|_PAGE_BAP_SX
  202. bne itlb_miss_fault_bolted
  203. dtlb_miss_fault_bolted:
  204. TLB_MISS_STATS_D(MMSTAT_TLB_MISS_NORM_FAULT)
  205. tlb_epilog_bolted
  206. b exc_data_storage_book3e
  207. itlb_miss_fault_bolted:
  208. TLB_MISS_STATS_I(MMSTAT_TLB_MISS_NORM_FAULT)
  209. tlb_epilog_bolted
  210. b exc_instruction_storage_book3e
  211. /* Instruction TLB miss */
  212. START_EXCEPTION(instruction_tlb_miss_bolted)
  213. tlb_prolog_bolted BOOKE_INTERRUPT_ITLB_MISS SPRN_SRR0
  214. rldicl. r10,r16,64-PGTABLE_EADDR_SIZE,PGTABLE_EADDR_SIZE+4
  215. srdi r15,r16,60 /* get region */
  216. TLB_MISS_STATS_SAVE_INFO_BOLTED
  217. bne- itlb_miss_fault_bolted
  218. li r11,_PAGE_PRESENT|_PAGE_EXEC /* Base perm */
  219. /* We do the user/kernel test for the PID here along with the RW test
  220. */
  221. cmpldi cr0,r15,0 /* Check for user region */
  222. oris r11,r11,_PAGE_ACCESSED@h
  223. beq tlb_miss_common_bolted
  224. b itlb_miss_kernel_bolted
  225. #ifdef CONFIG_PPC_FSL_BOOK3E
  226. /*
  227. * TLB miss handling for e6500 and derivatives, using hardware tablewalk.
  228. *
  229. * Linear mapping is bolted: no virtual page table or nested TLB misses
  230. * Indirect entries in TLB1, hardware loads resulting direct entries
  231. * into TLB0
  232. * No HES or NV hint on TLB1, so we need to do software round-robin
  233. * No tlbsrx. so we need a spinlock, and we have to deal
  234. * with MAS-damage caused by tlbsx
  235. * 4K pages only
  236. */
  237. START_EXCEPTION(instruction_tlb_miss_e6500)
  238. tlb_prolog_bolted BOOKE_INTERRUPT_ITLB_MISS SPRN_SRR0
  239. ld r11,PACA_TCD_PTR(r13)
  240. srdi. r15,r16,60 /* get region */
  241. ori r16,r16,1
  242. TLB_MISS_STATS_SAVE_INFO_BOLTED
  243. bne tlb_miss_kernel_e6500 /* user/kernel test */
  244. b tlb_miss_common_e6500
  245. START_EXCEPTION(data_tlb_miss_e6500)
  246. tlb_prolog_bolted BOOKE_INTERRUPT_DTLB_MISS SPRN_DEAR
  247. ld r11,PACA_TCD_PTR(r13)
  248. srdi. r15,r16,60 /* get region */
  249. rldicr r16,r16,0,62
  250. TLB_MISS_STATS_SAVE_INFO_BOLTED
  251. bne tlb_miss_kernel_e6500 /* user vs kernel check */
  252. /*
  253. * This is the guts of the TLB miss handler for e6500 and derivatives.
  254. * We are entered with:
  255. *
  256. * r16 = page of faulting address (low bit 0 if data, 1 if instruction)
  257. * r15 = crap (free to use)
  258. * r14 = page table base
  259. * r13 = PACA
  260. * r11 = tlb_per_core ptr
  261. * r10 = crap (free to use)
  262. */
  263. tlb_miss_common_e6500:
  264. crmove cr2*4+2,cr0*4+2 /* cr2.eq != 0 if kernel address */
  265. BEGIN_FTR_SECTION /* CPU_FTR_SMT */
  266. /*
  267. * Search if we already have an indirect entry for that virtual
  268. * address, and if we do, bail out.
  269. *
  270. * MAS6:IND should be already set based on MAS4
  271. */
  272. 1: lbarx r15,0,r11
  273. lhz r10,PACAPACAINDEX(r13)
  274. cmpdi r15,0
  275. cmpdi cr1,r15,1 /* set cr1.eq = 0 for non-recursive */
  276. addi r10,r10,1
  277. bne 2f
  278. stbcx. r10,0,r11
  279. bne 1b
  280. 3:
  281. .subsection 1
  282. 2: cmpd cr1,r15,r10 /* recursive lock due to mcheck/crit/etc? */
  283. beq cr1,3b /* unlock will happen if cr1.eq = 0 */
  284. lbz r15,0(r11)
  285. cmpdi r15,0
  286. bne 2b
  287. b 1b
  288. .previous
  289. /*
  290. * Erratum A-008139 says that we can't use tlbwe to change
  291. * an indirect entry in any way (including replacing or
  292. * invalidating) if the other thread could be in the process
  293. * of a lookup. The workaround is to invalidate the entry
  294. * with tlbilx before overwriting.
  295. */
  296. lbz r15,TCD_ESEL_NEXT(r11)
  297. rlwinm r10,r15,16,0xff0000
  298. oris r10,r10,MAS0_TLBSEL(1)@h
  299. mtspr SPRN_MAS0,r10
  300. isync
  301. tlbre
  302. mfspr r15,SPRN_MAS1
  303. andis. r15,r15,MAS1_VALID@h
  304. beq 5f
  305. BEGIN_FTR_SECTION_NESTED(532)
  306. mfspr r10,SPRN_MAS8
  307. rlwinm r10,r10,0,0x80000fff /* tgs,tlpid -> sgs,slpid */
  308. mtspr SPRN_MAS5,r10
  309. END_FTR_SECTION_NESTED(CPU_FTR_EMB_HV,CPU_FTR_EMB_HV,532)
  310. mfspr r10,SPRN_MAS1
  311. rlwinm r15,r10,0,0x3fff0000 /* tid -> spid */
  312. rlwimi r15,r10,20,0x00000003 /* ind,ts -> sind,sas */
  313. mfspr r10,SPRN_MAS6
  314. mtspr SPRN_MAS6,r15
  315. mfspr r15,SPRN_MAS2
  316. isync
  317. tlbilxva 0,r15
  318. isync
  319. mtspr SPRN_MAS6,r10
  320. 5:
  321. BEGIN_FTR_SECTION_NESTED(532)
  322. li r10,0
  323. mtspr SPRN_MAS8,r10
  324. mtspr SPRN_MAS5,r10
  325. END_FTR_SECTION_NESTED(CPU_FTR_EMB_HV,CPU_FTR_EMB_HV,532)
  326. tlbsx 0,r16
  327. mfspr r10,SPRN_MAS1
  328. andis. r15,r10,MAS1_VALID@h
  329. bne tlb_miss_done_e6500
  330. FTR_SECTION_ELSE
  331. mfspr r10,SPRN_MAS1
  332. ALT_FTR_SECTION_END_IFSET(CPU_FTR_SMT)
  333. oris r10,r10,MAS1_VALID@h
  334. beq cr2,4f
  335. rlwinm r10,r10,0,16,1 /* Clear TID */
  336. 4: mtspr SPRN_MAS1,r10
  337. /* Now, we need to walk the page tables. First check if we are in
  338. * range.
  339. */
  340. rldicl. r10,r16,64-PGTABLE_EADDR_SIZE,PGTABLE_EADDR_SIZE+4
  341. bne- tlb_miss_fault_e6500
  342. rldicl r15,r16,64-PGDIR_SHIFT+3,64-PGD_INDEX_SIZE-3
  343. cmpldi cr0,r14,0
  344. clrrdi r15,r15,3
  345. beq- tlb_miss_fault_e6500 /* No PGDIR, bail */
  346. ldx r14,r14,r15 /* grab pgd entry */
  347. rldicl r15,r16,64-PUD_SHIFT+3,64-PUD_INDEX_SIZE-3
  348. clrrdi r15,r15,3
  349. cmpdi cr0,r14,0
  350. bge tlb_miss_fault_e6500 /* Bad pgd entry or hugepage; bail */
  351. ldx r14,r14,r15 /* grab pud entry */
  352. rldicl r15,r16,64-PMD_SHIFT+3,64-PMD_INDEX_SIZE-3
  353. clrrdi r15,r15,3
  354. cmpdi cr0,r14,0
  355. bge tlb_miss_fault_e6500
  356. ldx r14,r14,r15 /* Grab pmd entry */
  357. mfspr r10,SPRN_MAS0
  358. cmpdi cr0,r14,0
  359. bge tlb_miss_fault_e6500
  360. /* Now we build the MAS for a 2M indirect page:
  361. *
  362. * MAS 0 : ESEL needs to be filled by software round-robin
  363. * MAS 1 : Fully set up
  364. * - PID already updated by caller if necessary
  365. * - TSIZE for now is base ind page size always
  366. * - TID already cleared if necessary
  367. * MAS 2 : Default not 2M-aligned, need to be redone
  368. * MAS 3+7 : Needs to be done
  369. */
  370. ori r14,r14,(BOOK3E_PAGESZ_4K << MAS3_SPSIZE_SHIFT)
  371. mtspr SPRN_MAS7_MAS3,r14
  372. clrrdi r15,r16,21 /* make EA 2M-aligned */
  373. mtspr SPRN_MAS2,r15
  374. lbz r15,TCD_ESEL_NEXT(r11)
  375. lbz r16,TCD_ESEL_MAX(r11)
  376. lbz r14,TCD_ESEL_FIRST(r11)
  377. rlwimi r10,r15,16,0x00ff0000 /* insert esel_next into MAS0 */
  378. addi r15,r15,1 /* increment esel_next */
  379. mtspr SPRN_MAS0,r10
  380. cmpw r15,r16
  381. iseleq r15,r14,r15 /* if next == last use first */
  382. stb r15,TCD_ESEL_NEXT(r11)
  383. tlbwe
  384. tlb_miss_done_e6500:
  385. .macro tlb_unlock_e6500
  386. BEGIN_FTR_SECTION
  387. beq cr1,1f /* no unlock if lock was recursively grabbed */
  388. li r15,0
  389. isync
  390. stb r15,0(r11)
  391. 1:
  392. END_FTR_SECTION_IFSET(CPU_FTR_SMT)
  393. .endm
  394. tlb_unlock_e6500
  395. TLB_MISS_STATS_X(MMSTAT_TLB_MISS_NORM_OK)
  396. tlb_epilog_bolted
  397. rfi
  398. tlb_miss_kernel_e6500:
  399. ld r14,PACA_KERNELPGD(r13)
  400. cmpldi cr1,r15,8 /* Check for vmalloc region */
  401. beq+ cr1,tlb_miss_common_e6500
  402. tlb_miss_fault_e6500:
  403. tlb_unlock_e6500
  404. /* We need to check if it was an instruction miss */
  405. andi. r16,r16,1
  406. bne itlb_miss_fault_e6500
  407. dtlb_miss_fault_e6500:
  408. TLB_MISS_STATS_D(MMSTAT_TLB_MISS_NORM_FAULT)
  409. tlb_epilog_bolted
  410. b exc_data_storage_book3e
  411. itlb_miss_fault_e6500:
  412. TLB_MISS_STATS_I(MMSTAT_TLB_MISS_NORM_FAULT)
  413. tlb_epilog_bolted
  414. b exc_instruction_storage_book3e
  415. #endif /* CONFIG_PPC_FSL_BOOK3E */
  416. /**********************************************************************
  417. * *
  418. * TLB miss handling for Book3E with TLB reservation and HES support *
  419. * *
  420. **********************************************************************/
  421. /* Data TLB miss */
  422. START_EXCEPTION(data_tlb_miss)
  423. TLB_MISS_PROLOG
  424. /* Now we handle the fault proper. We only save DEAR in normal
  425. * fault case since that's the only interesting values here.
  426. * We could probably also optimize by not saving SRR0/1 in the
  427. * linear mapping case but I'll leave that for later
  428. */
  429. mfspr r14,SPRN_ESR
  430. mfspr r16,SPRN_DEAR /* get faulting address */
  431. srdi r15,r16,60 /* get region */
  432. cmpldi cr0,r15,0xc /* linear mapping ? */
  433. TLB_MISS_STATS_SAVE_INFO
  434. beq tlb_load_linear /* yes -> go to linear map load */
  435. /* The page tables are mapped virtually linear. At this point, though,
  436. * we don't know whether we are trying to fault in a first level
  437. * virtual address or a virtual page table address. We can get that
  438. * from bit 0x1 of the region ID which we have set for a page table
  439. */
  440. andi. r10,r15,0x1
  441. bne- virt_page_table_tlb_miss
  442. std r14,EX_TLB_ESR(r12); /* save ESR */
  443. std r16,EX_TLB_DEAR(r12); /* save DEAR */
  444. /* We need _PAGE_PRESENT and _PAGE_ACCESSED set */
  445. li r11,_PAGE_PRESENT
  446. oris r11,r11,_PAGE_ACCESSED@h
  447. /* We do the user/kernel test for the PID here along with the RW test
  448. */
  449. cmpldi cr0,r15,0 /* Check for user region */
  450. /* We pre-test some combination of permissions to avoid double
  451. * faults:
  452. *
  453. * We move the ESR:ST bit into the position of _PAGE_BAP_SW in the PTE
  454. * ESR_ST is 0x00800000
  455. * _PAGE_BAP_SW is 0x00000010
  456. * So the shift is >> 19. This tests for supervisor writeability.
  457. * If the page happens to be supervisor writeable and not user
  458. * writeable, we will take a new fault later, but that should be
  459. * a rare enough case.
  460. *
  461. * We also move ESR_ST in _PAGE_DIRTY position
  462. * _PAGE_DIRTY is 0x00001000 so the shift is >> 11
  463. *
  464. * MAS1 is preset for all we need except for TID that needs to
  465. * be cleared for kernel translations
  466. */
  467. rlwimi r11,r14,32-19,27,27
  468. rlwimi r11,r14,32-16,19,19
  469. beq normal_tlb_miss
  470. /* XXX replace the RMW cycles with immediate loads + writes */
  471. 1: mfspr r10,SPRN_MAS1
  472. cmpldi cr0,r15,8 /* Check for vmalloc region */
  473. rlwinm r10,r10,0,16,1 /* Clear TID */
  474. mtspr SPRN_MAS1,r10
  475. beq+ normal_tlb_miss
  476. /* We got a crappy address, just fault with whatever DEAR and ESR
  477. * are here
  478. */
  479. TLB_MISS_STATS_D(MMSTAT_TLB_MISS_NORM_FAULT)
  480. TLB_MISS_EPILOG_ERROR
  481. b exc_data_storage_book3e
  482. /* Instruction TLB miss */
  483. START_EXCEPTION(instruction_tlb_miss)
  484. TLB_MISS_PROLOG
  485. /* If we take a recursive fault, the second level handler may need
  486. * to know whether we are handling a data or instruction fault in
  487. * order to get to the right store fault handler. We provide that
  488. * info by writing a crazy value in ESR in our exception frame
  489. */
  490. li r14,-1 /* store to exception frame is done later */
  491. /* Now we handle the fault proper. We only save DEAR in the non
  492. * linear mapping case since we know the linear mapping case will
  493. * not re-enter. We could indeed optimize and also not save SRR0/1
  494. * in the linear mapping case but I'll leave that for later
  495. *
  496. * Faulting address is SRR0 which is already in r16
  497. */
  498. srdi r15,r16,60 /* get region */
  499. cmpldi cr0,r15,0xc /* linear mapping ? */
  500. TLB_MISS_STATS_SAVE_INFO
  501. beq tlb_load_linear /* yes -> go to linear map load */
  502. /* We do the user/kernel test for the PID here along with the RW test
  503. */
  504. li r11,_PAGE_PRESENT|_PAGE_EXEC /* Base perm */
  505. oris r11,r11,_PAGE_ACCESSED@h
  506. cmpldi cr0,r15,0 /* Check for user region */
  507. std r14,EX_TLB_ESR(r12) /* write crazy -1 to frame */
  508. beq normal_tlb_miss
  509. li r11,_PAGE_PRESENT|_PAGE_BAP_SX /* Base perm */
  510. oris r11,r11,_PAGE_ACCESSED@h
  511. /* XXX replace the RMW cycles with immediate loads + writes */
  512. mfspr r10,SPRN_MAS1
  513. cmpldi cr0,r15,8 /* Check for vmalloc region */
  514. rlwinm r10,r10,0,16,1 /* Clear TID */
  515. mtspr SPRN_MAS1,r10
  516. beq+ normal_tlb_miss
  517. /* We got a crappy address, just fault */
  518. TLB_MISS_STATS_I(MMSTAT_TLB_MISS_NORM_FAULT)
  519. TLB_MISS_EPILOG_ERROR
  520. b exc_instruction_storage_book3e
  521. /*
  522. * This is the guts of the first-level TLB miss handler for direct
  523. * misses. We are entered with:
  524. *
  525. * r16 = faulting address
  526. * r15 = region ID
  527. * r14 = crap (free to use)
  528. * r13 = PACA
  529. * r12 = TLB exception frame in PACA
  530. * r11 = PTE permission mask
  531. * r10 = crap (free to use)
  532. */
  533. normal_tlb_miss:
  534. /* So we first construct the page table address. We do that by
  535. * shifting the bottom of the address (not the region ID) by
  536. * PAGE_SHIFT-3, clearing the bottom 3 bits (get a PTE ptr) and
  537. * or'ing the fourth high bit.
  538. *
  539. * NOTE: For 64K pages, we do things slightly differently in
  540. * order to handle the weird page table format used by linux
  541. */
  542. ori r10,r15,0x1
  543. #ifdef CONFIG_PPC_64K_PAGES
  544. /* For the top bits, 16 bytes per PTE */
  545. rldicl r14,r16,64-(PAGE_SHIFT-4),PAGE_SHIFT-4+4
  546. /* Now create the bottom bits as 0 in position 0x8000 and
  547. * the rest calculated for 8 bytes per PTE
  548. */
  549. rldicl r15,r16,64-(PAGE_SHIFT-3),64-15
  550. /* Insert the bottom bits in */
  551. rlwimi r14,r15,0,16,31
  552. #else
  553. rldicl r14,r16,64-(PAGE_SHIFT-3),PAGE_SHIFT-3+4
  554. #endif
  555. sldi r15,r10,60
  556. clrrdi r14,r14,3
  557. or r10,r15,r14
  558. BEGIN_MMU_FTR_SECTION
  559. /* Set the TLB reservation and search for existing entry. Then load
  560. * the entry.
  561. */
  562. PPC_TLBSRX_DOT(0,R16)
  563. ld r14,0(r10)
  564. beq normal_tlb_miss_done
  565. MMU_FTR_SECTION_ELSE
  566. ld r14,0(r10)
  567. ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_USE_TLBRSRV)
  568. finish_normal_tlb_miss:
  569. /* Check if required permissions are met */
  570. andc. r15,r11,r14
  571. bne- normal_tlb_miss_access_fault
  572. /* Now we build the MAS:
  573. *
  574. * MAS 0 : Fully setup with defaults in MAS4 and TLBnCFG
  575. * MAS 1 : Almost fully setup
  576. * - PID already updated by caller if necessary
  577. * - TSIZE need change if !base page size, not
  578. * yet implemented for now
  579. * MAS 2 : Defaults not useful, need to be redone
  580. * MAS 3+7 : Needs to be done
  581. *
  582. * TODO: mix up code below for better scheduling
  583. */
  584. clrrdi r11,r16,12 /* Clear low crap in EA */
  585. rlwimi r11,r14,32-19,27,31 /* Insert WIMGE */
  586. mtspr SPRN_MAS2,r11
  587. /* Check page size, if not standard, update MAS1 */
  588. rldicl r11,r14,64-8,64-8
  589. #ifdef CONFIG_PPC_64K_PAGES
  590. cmpldi cr0,r11,BOOK3E_PAGESZ_64K
  591. #else
  592. cmpldi cr0,r11,BOOK3E_PAGESZ_4K
  593. #endif
  594. beq- 1f
  595. mfspr r11,SPRN_MAS1
  596. rlwimi r11,r14,31,21,24
  597. rlwinm r11,r11,0,21,19
  598. mtspr SPRN_MAS1,r11
  599. 1:
  600. /* Move RPN in position */
  601. rldicr r11,r14,64-(PTE_RPN_SHIFT-PAGE_SHIFT),63-PAGE_SHIFT
  602. clrldi r15,r11,12 /* Clear crap at the top */
  603. rlwimi r15,r14,32-8,22,25 /* Move in U bits */
  604. rlwimi r15,r14,32-2,26,31 /* Move in BAP bits */
  605. /* Mask out SW and UW if !DIRTY (XXX optimize this !) */
  606. andi. r11,r14,_PAGE_DIRTY
  607. bne 1f
  608. li r11,MAS3_SW|MAS3_UW
  609. andc r15,r15,r11
  610. 1:
  611. BEGIN_MMU_FTR_SECTION
  612. srdi r16,r15,32
  613. mtspr SPRN_MAS3,r15
  614. mtspr SPRN_MAS7,r16
  615. MMU_FTR_SECTION_ELSE
  616. mtspr SPRN_MAS7_MAS3,r15
  617. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_PAIRED_MAS)
  618. tlbwe
  619. normal_tlb_miss_done:
  620. /* We don't bother with restoring DEAR or ESR since we know we are
  621. * level 0 and just going back to userland. They are only needed
  622. * if you are going to take an access fault
  623. */
  624. TLB_MISS_STATS_X(MMSTAT_TLB_MISS_NORM_OK)
  625. TLB_MISS_EPILOG_SUCCESS
  626. rfi
  627. normal_tlb_miss_access_fault:
  628. /* We need to check if it was an instruction miss */
  629. andi. r10,r11,_PAGE_EXEC
  630. bne 1f
  631. ld r14,EX_TLB_DEAR(r12)
  632. ld r15,EX_TLB_ESR(r12)
  633. mtspr SPRN_DEAR,r14
  634. mtspr SPRN_ESR,r15
  635. TLB_MISS_STATS_D(MMSTAT_TLB_MISS_NORM_FAULT)
  636. TLB_MISS_EPILOG_ERROR
  637. b exc_data_storage_book3e
  638. 1: TLB_MISS_STATS_I(MMSTAT_TLB_MISS_NORM_FAULT)
  639. TLB_MISS_EPILOG_ERROR
  640. b exc_instruction_storage_book3e
  641. /*
  642. * This is the guts of the second-level TLB miss handler for direct
  643. * misses. We are entered with:
  644. *
  645. * r16 = virtual page table faulting address
  646. * r15 = region (top 4 bits of address)
  647. * r14 = crap (free to use)
  648. * r13 = PACA
  649. * r12 = TLB exception frame in PACA
  650. * r11 = crap (free to use)
  651. * r10 = crap (free to use)
  652. *
  653. * Note that this should only ever be called as a second level handler
  654. * with the current scheme when using SW load.
  655. * That means we can always get the original fault DEAR at
  656. * EX_TLB_DEAR-EX_TLB_SIZE(r12)
  657. *
  658. * It can be re-entered by the linear mapping miss handler. However, to
  659. * avoid too much complication, it will restart the whole fault at level
  660. * 0 so we don't care too much about clobbers
  661. *
  662. * XXX That code was written back when we couldn't clobber r14. We can now,
  663. * so we could probably optimize things a bit
  664. */
  665. virt_page_table_tlb_miss:
  666. /* Are we hitting a kernel page table ? */
  667. andi. r10,r15,0x8
  668. /* The cool thing now is that r10 contains 0 for user and 8 for kernel,
  669. * and we happen to have the swapper_pg_dir at offset 8 from the user
  670. * pgdir in the PACA :-).
  671. */
  672. add r11,r10,r13
  673. /* If kernel, we need to clear MAS1 TID */
  674. beq 1f
  675. /* XXX replace the RMW cycles with immediate loads + writes */
  676. mfspr r10,SPRN_MAS1
  677. rlwinm r10,r10,0,16,1 /* Clear TID */
  678. mtspr SPRN_MAS1,r10
  679. 1:
  680. BEGIN_MMU_FTR_SECTION
  681. /* Search if we already have a TLB entry for that virtual address, and
  682. * if we do, bail out.
  683. */
  684. PPC_TLBSRX_DOT(0,R16)
  685. beq virt_page_table_tlb_miss_done
  686. END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_TLBRSRV)
  687. /* Now, we need to walk the page tables. First check if we are in
  688. * range.
  689. */
  690. rldicl. r10,r16,64-(VPTE_INDEX_SIZE+3),VPTE_INDEX_SIZE+3+4
  691. bne- virt_page_table_tlb_miss_fault
  692. /* Get the PGD pointer */
  693. ld r15,PACAPGD(r11)
  694. cmpldi cr0,r15,0
  695. beq- virt_page_table_tlb_miss_fault
  696. /* Get to PGD entry */
  697. rldicl r11,r16,64-VPTE_PGD_SHIFT,64-PGD_INDEX_SIZE-3
  698. clrrdi r10,r11,3
  699. ldx r15,r10,r15
  700. cmpdi cr0,r15,0
  701. bge virt_page_table_tlb_miss_fault
  702. #ifndef CONFIG_PPC_64K_PAGES
  703. /* Get to PUD entry */
  704. rldicl r11,r16,64-VPTE_PUD_SHIFT,64-PUD_INDEX_SIZE-3
  705. clrrdi r10,r11,3
  706. ldx r15,r10,r15
  707. cmpdi cr0,r15,0
  708. bge virt_page_table_tlb_miss_fault
  709. #endif /* CONFIG_PPC_64K_PAGES */
  710. /* Get to PMD entry */
  711. rldicl r11,r16,64-VPTE_PMD_SHIFT,64-PMD_INDEX_SIZE-3
  712. clrrdi r10,r11,3
  713. ldx r15,r10,r15
  714. cmpdi cr0,r15,0
  715. bge virt_page_table_tlb_miss_fault
  716. /* Ok, we're all right, we can now create a kernel translation for
  717. * a 4K or 64K page from r16 -> r15.
  718. */
  719. /* Now we build the MAS:
  720. *
  721. * MAS 0 : Fully setup with defaults in MAS4 and TLBnCFG
  722. * MAS 1 : Almost fully setup
  723. * - PID already updated by caller if necessary
  724. * - TSIZE for now is base page size always
  725. * MAS 2 : Use defaults
  726. * MAS 3+7 : Needs to be done
  727. *
  728. * So we only do MAS 2 and 3 for now...
  729. */
  730. clrldi r11,r15,4 /* remove region ID from RPN */
  731. ori r10,r11,1 /* Or-in SR */
  732. BEGIN_MMU_FTR_SECTION
  733. srdi r16,r10,32
  734. mtspr SPRN_MAS3,r10
  735. mtspr SPRN_MAS7,r16
  736. MMU_FTR_SECTION_ELSE
  737. mtspr SPRN_MAS7_MAS3,r10
  738. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_PAIRED_MAS)
  739. tlbwe
  740. BEGIN_MMU_FTR_SECTION
  741. virt_page_table_tlb_miss_done:
  742. /* We have overriden MAS2:EPN but currently our primary TLB miss
  743. * handler will always restore it so that should not be an issue,
  744. * if we ever optimize the primary handler to not write MAS2 on
  745. * some cases, we'll have to restore MAS2:EPN here based on the
  746. * original fault's DEAR. If we do that we have to modify the
  747. * ITLB miss handler to also store SRR0 in the exception frame
  748. * as DEAR.
  749. *
  750. * However, one nasty thing we did is we cleared the reservation
  751. * (well, potentially we did). We do a trick here thus if we
  752. * are not a level 0 exception (we interrupted the TLB miss) we
  753. * offset the return address by -4 in order to replay the tlbsrx
  754. * instruction there
  755. */
  756. subf r10,r13,r12
  757. cmpldi cr0,r10,PACA_EXTLB+EX_TLB_SIZE
  758. bne- 1f
  759. ld r11,PACA_EXTLB+EX_TLB_SIZE+EX_TLB_SRR0(r13)
  760. addi r10,r11,-4
  761. std r10,PACA_EXTLB+EX_TLB_SIZE+EX_TLB_SRR0(r13)
  762. 1:
  763. END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_TLBRSRV)
  764. /* Return to caller, normal case */
  765. TLB_MISS_STATS_X(MMSTAT_TLB_MISS_PT_OK);
  766. TLB_MISS_EPILOG_SUCCESS
  767. rfi
  768. virt_page_table_tlb_miss_fault:
  769. /* If we fault here, things are a little bit tricky. We need to call
  770. * either data or instruction store fault, and we need to retrieve
  771. * the original fault address and ESR (for data).
  772. *
  773. * The thing is, we know that in normal circumstances, this is
  774. * always called as a second level tlb miss for SW load or as a first
  775. * level TLB miss for HW load, so we should be able to peek at the
  776. * relevant information in the first exception frame in the PACA.
  777. *
  778. * However, we do need to double check that, because we may just hit
  779. * a stray kernel pointer or a userland attack trying to hit those
  780. * areas. If that is the case, we do a data fault. (We can't get here
  781. * from an instruction tlb miss anyway).
  782. *
  783. * Note also that when going to a fault, we must unwind the previous
  784. * level as well. Since we are doing that, we don't need to clear or
  785. * restore the TLB reservation neither.
  786. */
  787. subf r10,r13,r12
  788. cmpldi cr0,r10,PACA_EXTLB+EX_TLB_SIZE
  789. bne- virt_page_table_tlb_miss_whacko_fault
  790. /* We dig the original DEAR and ESR from slot 0 */
  791. ld r15,EX_TLB_DEAR+PACA_EXTLB(r13)
  792. ld r16,EX_TLB_ESR+PACA_EXTLB(r13)
  793. /* We check for the "special" ESR value for instruction faults */
  794. cmpdi cr0,r16,-1
  795. beq 1f
  796. mtspr SPRN_DEAR,r15
  797. mtspr SPRN_ESR,r16
  798. TLB_MISS_STATS_D(MMSTAT_TLB_MISS_PT_FAULT);
  799. TLB_MISS_EPILOG_ERROR
  800. b exc_data_storage_book3e
  801. 1: TLB_MISS_STATS_I(MMSTAT_TLB_MISS_PT_FAULT);
  802. TLB_MISS_EPILOG_ERROR
  803. b exc_instruction_storage_book3e
  804. virt_page_table_tlb_miss_whacko_fault:
  805. /* The linear fault will restart everything so ESR and DEAR will
  806. * not have been clobbered, let's just fault with what we have
  807. */
  808. TLB_MISS_STATS_X(MMSTAT_TLB_MISS_PT_FAULT);
  809. TLB_MISS_EPILOG_ERROR
  810. b exc_data_storage_book3e
  811. /**************************************************************
  812. * *
  813. * TLB miss handling for Book3E with hw page table support *
  814. * *
  815. **************************************************************/
  816. /* Data TLB miss */
  817. START_EXCEPTION(data_tlb_miss_htw)
  818. TLB_MISS_PROLOG
  819. /* Now we handle the fault proper. We only save DEAR in normal
  820. * fault case since that's the only interesting values here.
  821. * We could probably also optimize by not saving SRR0/1 in the
  822. * linear mapping case but I'll leave that for later
  823. */
  824. mfspr r14,SPRN_ESR
  825. mfspr r16,SPRN_DEAR /* get faulting address */
  826. srdi r11,r16,60 /* get region */
  827. cmpldi cr0,r11,0xc /* linear mapping ? */
  828. TLB_MISS_STATS_SAVE_INFO
  829. beq tlb_load_linear /* yes -> go to linear map load */
  830. /* We do the user/kernel test for the PID here along with the RW test
  831. */
  832. cmpldi cr0,r11,0 /* Check for user region */
  833. ld r15,PACAPGD(r13) /* Load user pgdir */
  834. beq htw_tlb_miss
  835. /* XXX replace the RMW cycles with immediate loads + writes */
  836. 1: mfspr r10,SPRN_MAS1
  837. cmpldi cr0,r11,8 /* Check for vmalloc region */
  838. rlwinm r10,r10,0,16,1 /* Clear TID */
  839. mtspr SPRN_MAS1,r10
  840. ld r15,PACA_KERNELPGD(r13) /* Load kernel pgdir */
  841. beq+ htw_tlb_miss
  842. /* We got a crappy address, just fault with whatever DEAR and ESR
  843. * are here
  844. */
  845. TLB_MISS_STATS_D(MMSTAT_TLB_MISS_NORM_FAULT)
  846. TLB_MISS_EPILOG_ERROR
  847. b exc_data_storage_book3e
  848. /* Instruction TLB miss */
  849. START_EXCEPTION(instruction_tlb_miss_htw)
  850. TLB_MISS_PROLOG
  851. /* If we take a recursive fault, the second level handler may need
  852. * to know whether we are handling a data or instruction fault in
  853. * order to get to the right store fault handler. We provide that
  854. * info by keeping a crazy value for ESR in r14
  855. */
  856. li r14,-1 /* store to exception frame is done later */
  857. /* Now we handle the fault proper. We only save DEAR in the non
  858. * linear mapping case since we know the linear mapping case will
  859. * not re-enter. We could indeed optimize and also not save SRR0/1
  860. * in the linear mapping case but I'll leave that for later
  861. *
  862. * Faulting address is SRR0 which is already in r16
  863. */
  864. srdi r11,r16,60 /* get region */
  865. cmpldi cr0,r11,0xc /* linear mapping ? */
  866. TLB_MISS_STATS_SAVE_INFO
  867. beq tlb_load_linear /* yes -> go to linear map load */
  868. /* We do the user/kernel test for the PID here along with the RW test
  869. */
  870. cmpldi cr0,r11,0 /* Check for user region */
  871. ld r15,PACAPGD(r13) /* Load user pgdir */
  872. beq htw_tlb_miss
  873. /* XXX replace the RMW cycles with immediate loads + writes */
  874. 1: mfspr r10,SPRN_MAS1
  875. cmpldi cr0,r11,8 /* Check for vmalloc region */
  876. rlwinm r10,r10,0,16,1 /* Clear TID */
  877. mtspr SPRN_MAS1,r10
  878. ld r15,PACA_KERNELPGD(r13) /* Load kernel pgdir */
  879. beq+ htw_tlb_miss
  880. /* We got a crappy address, just fault */
  881. TLB_MISS_STATS_I(MMSTAT_TLB_MISS_NORM_FAULT)
  882. TLB_MISS_EPILOG_ERROR
  883. b exc_instruction_storage_book3e
  884. /*
  885. * This is the guts of the second-level TLB miss handler for direct
  886. * misses. We are entered with:
  887. *
  888. * r16 = virtual page table faulting address
  889. * r15 = PGD pointer
  890. * r14 = ESR
  891. * r13 = PACA
  892. * r12 = TLB exception frame in PACA
  893. * r11 = crap (free to use)
  894. * r10 = crap (free to use)
  895. *
  896. * It can be re-entered by the linear mapping miss handler. However, to
  897. * avoid too much complication, it will save/restore things for us
  898. */
  899. htw_tlb_miss:
  900. /* Search if we already have a TLB entry for that virtual address, and
  901. * if we do, bail out.
  902. *
  903. * MAS1:IND should be already set based on MAS4
  904. */
  905. PPC_TLBSRX_DOT(0,R16)
  906. beq htw_tlb_miss_done
  907. /* Now, we need to walk the page tables. First check if we are in
  908. * range.
  909. */
  910. rldicl. r10,r16,64-PGTABLE_EADDR_SIZE,PGTABLE_EADDR_SIZE+4
  911. bne- htw_tlb_miss_fault
  912. /* Get the PGD pointer */
  913. cmpldi cr0,r15,0
  914. beq- htw_tlb_miss_fault
  915. /* Get to PGD entry */
  916. rldicl r11,r16,64-(PGDIR_SHIFT-3),64-PGD_INDEX_SIZE-3
  917. clrrdi r10,r11,3
  918. ldx r15,r10,r15
  919. cmpdi cr0,r15,0
  920. bge htw_tlb_miss_fault
  921. #ifndef CONFIG_PPC_64K_PAGES
  922. /* Get to PUD entry */
  923. rldicl r11,r16,64-(PUD_SHIFT-3),64-PUD_INDEX_SIZE-3
  924. clrrdi r10,r11,3
  925. ldx r15,r10,r15
  926. cmpdi cr0,r15,0
  927. bge htw_tlb_miss_fault
  928. #endif /* CONFIG_PPC_64K_PAGES */
  929. /* Get to PMD entry */
  930. rldicl r11,r16,64-(PMD_SHIFT-3),64-PMD_INDEX_SIZE-3
  931. clrrdi r10,r11,3
  932. ldx r15,r10,r15
  933. cmpdi cr0,r15,0
  934. bge htw_tlb_miss_fault
  935. /* Ok, we're all right, we can now create an indirect entry for
  936. * a 1M or 256M page.
  937. *
  938. * The last trick is now that because we use "half" pages for
  939. * the HTW (1M IND is 2K and 256M IND is 32K) we need to account
  940. * for an added LSB bit to the RPN. For 64K pages, there is no
  941. * problem as we already use 32K arrays (half PTE pages), but for
  942. * 4K page we need to extract a bit from the virtual address and
  943. * insert it into the "PA52" bit of the RPN.
  944. */
  945. #ifndef CONFIG_PPC_64K_PAGES
  946. rlwimi r15,r16,32-9,20,20
  947. #endif
  948. /* Now we build the MAS:
  949. *
  950. * MAS 0 : Fully setup with defaults in MAS4 and TLBnCFG
  951. * MAS 1 : Almost fully setup
  952. * - PID already updated by caller if necessary
  953. * - TSIZE for now is base ind page size always
  954. * MAS 2 : Use defaults
  955. * MAS 3+7 : Needs to be done
  956. */
  957. #ifdef CONFIG_PPC_64K_PAGES
  958. ori r10,r15,(BOOK3E_PAGESZ_64K << MAS3_SPSIZE_SHIFT)
  959. #else
  960. ori r10,r15,(BOOK3E_PAGESZ_4K << MAS3_SPSIZE_SHIFT)
  961. #endif
  962. BEGIN_MMU_FTR_SECTION
  963. srdi r16,r10,32
  964. mtspr SPRN_MAS3,r10
  965. mtspr SPRN_MAS7,r16
  966. MMU_FTR_SECTION_ELSE
  967. mtspr SPRN_MAS7_MAS3,r10
  968. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_PAIRED_MAS)
  969. tlbwe
  970. htw_tlb_miss_done:
  971. /* We don't bother with restoring DEAR or ESR since we know we are
  972. * level 0 and just going back to userland. They are only needed
  973. * if you are going to take an access fault
  974. */
  975. TLB_MISS_STATS_X(MMSTAT_TLB_MISS_PT_OK)
  976. TLB_MISS_EPILOG_SUCCESS
  977. rfi
  978. htw_tlb_miss_fault:
  979. /* We need to check if it was an instruction miss. We know this
  980. * though because r14 would contain -1
  981. */
  982. cmpdi cr0,r14,-1
  983. beq 1f
  984. mtspr SPRN_DEAR,r16
  985. mtspr SPRN_ESR,r14
  986. TLB_MISS_STATS_D(MMSTAT_TLB_MISS_PT_FAULT)
  987. TLB_MISS_EPILOG_ERROR
  988. b exc_data_storage_book3e
  989. 1: TLB_MISS_STATS_I(MMSTAT_TLB_MISS_PT_FAULT)
  990. TLB_MISS_EPILOG_ERROR
  991. b exc_instruction_storage_book3e
  992. /*
  993. * This is the guts of "any" level TLB miss handler for kernel linear
  994. * mapping misses. We are entered with:
  995. *
  996. *
  997. * r16 = faulting address
  998. * r15 = crap (free to use)
  999. * r14 = ESR (data) or -1 (instruction)
  1000. * r13 = PACA
  1001. * r12 = TLB exception frame in PACA
  1002. * r11 = crap (free to use)
  1003. * r10 = crap (free to use)
  1004. *
  1005. * In addition we know that we will not re-enter, so in theory, we could
  1006. * use a simpler epilog not restoring SRR0/1 etc.. but we'll do that later.
  1007. *
  1008. * We also need to be careful about MAS registers here & TLB reservation,
  1009. * as we know we'll have clobbered them if we interrupt the main TLB miss
  1010. * handlers in which case we probably want to do a full restart at level
  1011. * 0 rather than saving / restoring the MAS.
  1012. *
  1013. * Note: If we care about performance of that core, we can easily shuffle
  1014. * a few things around
  1015. */
  1016. tlb_load_linear:
  1017. /* For now, we assume the linear mapping is contiguous and stops at
  1018. * linear_map_top. We also assume the size is a multiple of 1G, thus
  1019. * we only use 1G pages for now. That might have to be changed in a
  1020. * final implementation, especially when dealing with hypervisors
  1021. */
  1022. ld r11,PACATOC(r13)
  1023. ld r11,linear_map_top@got(r11)
  1024. ld r10,0(r11)
  1025. tovirt(10,10)
  1026. cmpld cr0,r16,r10
  1027. bge tlb_load_linear_fault
  1028. /* MAS1 need whole new setup. */
  1029. li r15,(BOOK3E_PAGESZ_1GB<<MAS1_TSIZE_SHIFT)
  1030. oris r15,r15,MAS1_VALID@h /* MAS1 needs V and TSIZE */
  1031. mtspr SPRN_MAS1,r15
  1032. /* Already somebody there ? */
  1033. PPC_TLBSRX_DOT(0,R16)
  1034. beq tlb_load_linear_done
  1035. /* Now we build the remaining MAS. MAS0 and 2 should be fine
  1036. * with their defaults, which leaves us with MAS 3 and 7. The
  1037. * mapping is linear, so we just take the address, clear the
  1038. * region bits, and or in the permission bits which are currently
  1039. * hard wired
  1040. */
  1041. clrrdi r10,r16,30 /* 1G page index */
  1042. clrldi r10,r10,4 /* clear region bits */
  1043. ori r10,r10,MAS3_SR|MAS3_SW|MAS3_SX
  1044. BEGIN_MMU_FTR_SECTION
  1045. srdi r16,r10,32
  1046. mtspr SPRN_MAS3,r10
  1047. mtspr SPRN_MAS7,r16
  1048. MMU_FTR_SECTION_ELSE
  1049. mtspr SPRN_MAS7_MAS3,r10
  1050. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_PAIRED_MAS)
  1051. tlbwe
  1052. tlb_load_linear_done:
  1053. /* We use the "error" epilog for success as we do want to
  1054. * restore to the initial faulting context, whatever it was.
  1055. * We do that because we can't resume a fault within a TLB
  1056. * miss handler, due to MAS and TLB reservation being clobbered.
  1057. */
  1058. TLB_MISS_STATS_X(MMSTAT_TLB_MISS_LINEAR)
  1059. TLB_MISS_EPILOG_ERROR
  1060. rfi
  1061. tlb_load_linear_fault:
  1062. /* We keep the DEAR and ESR around, this shouldn't have happened */
  1063. cmpdi cr0,r14,-1
  1064. beq 1f
  1065. TLB_MISS_EPILOG_ERROR_SPECIAL
  1066. b exc_data_storage_book3e
  1067. 1: TLB_MISS_EPILOG_ERROR_SPECIAL
  1068. b exc_instruction_storage_book3e
  1069. #ifdef CONFIG_BOOK3E_MMU_TLB_STATS
  1070. .tlb_stat_inc:
  1071. 1: ldarx r8,0,r9
  1072. addi r8,r8,1
  1073. stdcx. r8,0,r9
  1074. bne- 1b
  1075. blr
  1076. #endif