hash_low.S 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * PowerPC version
  4. * Copyright (C) 1995-1996 Gary Thomas ([email protected])
  5. * Rewritten by Cort Dougan ([email protected]) for PReP
  6. * Copyright (C) 1996 Cort Dougan <[email protected]>
  7. * Adapted for Power Macintosh by Paul Mackerras.
  8. * Low-level exception handlers and MMU support
  9. * rewritten by Paul Mackerras.
  10. * Copyright (C) 1996 Paul Mackerras.
  11. *
  12. * This file contains low-level assembler routines for managing
  13. * the PowerPC MMU hash table. (PPC 8xx processors don't use a
  14. * hash table, so this file is not used on them.)
  15. */
  16. #include <linux/pgtable.h>
  17. #include <linux/init.h>
  18. #include <asm/reg.h>
  19. #include <asm/page.h>
  20. #include <asm/cputable.h>
  21. #include <asm/ppc_asm.h>
  22. #include <asm/thread_info.h>
  23. #include <asm/asm-offsets.h>
  24. #include <asm/export.h>
  25. #include <asm/feature-fixups.h>
  26. #include <asm/code-patching-asm.h>
  27. #ifdef CONFIG_PTE_64BIT
  28. #define PTE_T_SIZE 8
  29. #define PTE_FLAGS_OFFSET 4 /* offset of PTE flags, in bytes */
  30. #else
  31. #define PTE_T_SIZE 4
  32. #define PTE_FLAGS_OFFSET 0
  33. #endif
  34. /*
  35. * Load a PTE into the hash table, if possible.
  36. * The address is in r4, and r3 contains an access flag:
  37. * _PAGE_RW (0x400) if a write.
  38. * r9 contains the SRR1 value, from which we use the MSR_PR bit.
  39. * SPRG_THREAD contains the physical address of the current task's thread.
  40. *
  41. * Returns to the caller if the access is illegal or there is no
  42. * mapping for the address. Otherwise it places an appropriate PTE
  43. * in the hash table and returns from the exception.
  44. * Uses r0, r3 - r6, r8, r10, ctr, lr.
  45. */
  46. .text
  47. _GLOBAL(hash_page)
  48. #ifdef CONFIG_SMP
  49. lis r8, (mmu_hash_lock - PAGE_OFFSET)@h
  50. ori r8, r8, (mmu_hash_lock - PAGE_OFFSET)@l
  51. lis r0,0x0fff
  52. b 10f
  53. 11: lwz r6,0(r8)
  54. cmpwi 0,r6,0
  55. bne 11b
  56. 10: lwarx r6,0,r8
  57. cmpwi 0,r6,0
  58. bne- 11b
  59. stwcx. r0,0,r8
  60. bne- 10b
  61. isync
  62. #endif
  63. /* Get PTE (linux-style) and check access */
  64. lis r0, TASK_SIZE@h /* check if kernel address */
  65. cmplw 0,r4,r0
  66. mfspr r8,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
  67. ori r3,r3,_PAGE_USER|_PAGE_PRESENT /* test low addresses as user */
  68. lwz r5,PGDIR(r8) /* virt page-table root */
  69. blt+ 112f /* assume user more likely */
  70. lis r5,swapper_pg_dir@ha /* if kernel address, use */
  71. addi r5,r5,swapper_pg_dir@l /* kernel page table */
  72. rlwimi r3,r9,32-12,29,29 /* MSR_PR -> _PAGE_USER */
  73. 112: tophys(r5, r5)
  74. #ifndef CONFIG_PTE_64BIT
  75. rlwimi r5,r4,12,20,29 /* insert top 10 bits of address */
  76. lwz r8,0(r5) /* get pmd entry */
  77. rlwinm. r8,r8,0,0,19 /* extract address of pte page */
  78. #else
  79. rlwinm r8,r4,13,19,29 /* Compute pgdir/pmd offset */
  80. lwzx r8,r8,r5 /* Get L1 entry */
  81. rlwinm. r8,r8,0,0,20 /* extract pt base address */
  82. #endif
  83. #ifdef CONFIG_SMP
  84. beq- .Lhash_page_out /* return if no mapping */
  85. #else
  86. /* XXX it seems like the 601 will give a machine fault on the
  87. rfi if its alignment is wrong (bottom 4 bits of address are
  88. 8 or 0xc) and we have had a not-taken conditional branch
  89. to the address following the rfi. */
  90. beqlr-
  91. #endif
  92. #ifndef CONFIG_PTE_64BIT
  93. rlwimi r8,r4,22,20,29 /* insert next 10 bits of address */
  94. #else
  95. rlwimi r8,r4,23,20,28 /* compute pte address */
  96. /*
  97. * If PTE_64BIT is set, the low word is the flags word; use that
  98. * word for locking since it contains all the interesting bits.
  99. */
  100. addi r8,r8,PTE_FLAGS_OFFSET
  101. #endif
  102. /*
  103. * Update the linux PTE atomically. We do the lwarx up-front
  104. * because almost always, there won't be a permission violation
  105. * and there won't already be an HPTE, and thus we will have
  106. * to update the PTE to set _PAGE_HASHPTE. -- paulus.
  107. */
  108. .Lretry:
  109. lwarx r6,0,r8 /* get linux-style pte, flag word */
  110. #ifdef CONFIG_PPC_KUAP
  111. mfsrin r5,r4
  112. rlwinm r0,r9,28,_PAGE_RW /* MSR[PR] => _PAGE_RW */
  113. rlwinm r5,r5,12,_PAGE_RW /* Ks => _PAGE_RW */
  114. andc r5,r5,r0 /* Ks & ~MSR[PR] */
  115. andc r5,r6,r5 /* Clear _PAGE_RW when Ks = 1 && MSR[PR] = 0 */
  116. andc. r5,r3,r5 /* check access & ~permission */
  117. #else
  118. andc. r5,r3,r6 /* check access & ~permission */
  119. #endif
  120. rlwinm r0,r3,32-3,24,24 /* _PAGE_RW access -> _PAGE_DIRTY */
  121. ori r0,r0,_PAGE_ACCESSED|_PAGE_HASHPTE
  122. #ifdef CONFIG_SMP
  123. bne- .Lhash_page_out /* return if access not permitted */
  124. #else
  125. bnelr-
  126. #endif
  127. or r5,r0,r6 /* set accessed/dirty bits */
  128. #ifdef CONFIG_PTE_64BIT
  129. #ifdef CONFIG_SMP
  130. subf r10,r6,r8 /* create false data dependency */
  131. subi r10,r10,PTE_FLAGS_OFFSET
  132. lwzx r10,r6,r10 /* Get upper PTE word */
  133. #else
  134. lwz r10,-PTE_FLAGS_OFFSET(r8)
  135. #endif /* CONFIG_SMP */
  136. #endif /* CONFIG_PTE_64BIT */
  137. stwcx. r5,0,r8 /* attempt to update PTE */
  138. bne- .Lretry /* retry if someone got there first */
  139. mfsrin r3,r4 /* get segment reg for segment */
  140. bl create_hpte /* add the hash table entry */
  141. #ifdef CONFIG_SMP
  142. eieio
  143. lis r8, (mmu_hash_lock - PAGE_OFFSET)@ha
  144. li r0,0
  145. stw r0, (mmu_hash_lock - PAGE_OFFSET)@l(r8)
  146. #endif
  147. b fast_hash_page_return
  148. #ifdef CONFIG_SMP
  149. .Lhash_page_out:
  150. eieio
  151. lis r8, (mmu_hash_lock - PAGE_OFFSET)@ha
  152. li r0,0
  153. stw r0, (mmu_hash_lock - PAGE_OFFSET)@l(r8)
  154. blr
  155. #endif /* CONFIG_SMP */
  156. _ASM_NOKPROBE_SYMBOL(hash_page)
  157. /*
  158. * Add an entry for a particular page to the hash table.
  159. *
  160. * add_hash_page(unsigned context, unsigned long va, unsigned long pmdval)
  161. *
  162. * We assume any necessary modifications to the pte (e.g. setting
  163. * the accessed bit) have already been done and that there is actually
  164. * a hash table in use (i.e. we're not on a 603).
  165. */
  166. _GLOBAL(add_hash_page)
  167. mflr r0
  168. stw r0,4(r1)
  169. #ifdef CONFIG_SMP
  170. lwz r8,TASK_CPU(r2) /* to go in mmu_hash_lock */
  171. oris r8,r8,12
  172. #endif /* CONFIG_SMP */
  173. /*
  174. * We disable interrupts here, even on UP, because we don't
  175. * want to race with hash_page, and because we want the
  176. * _PAGE_HASHPTE bit to be a reliable indication of whether
  177. * the HPTE exists (or at least whether one did once).
  178. * We also turn off the MMU for data accesses so that we
  179. * we can't take a hash table miss (assuming the code is
  180. * covered by a BAT). -- paulus
  181. */
  182. mfmsr r9
  183. rlwinm r0,r9,0,17,15 /* clear bit 16 (MSR_EE) */
  184. rlwinm r0,r0,0,28,26 /* clear MSR_DR */
  185. mtmsr r0
  186. isync
  187. #ifdef CONFIG_SMP
  188. lis r6, (mmu_hash_lock - PAGE_OFFSET)@ha
  189. addi r6, r6, (mmu_hash_lock - PAGE_OFFSET)@l
  190. 10: lwarx r0,0,r6 /* take the mmu_hash_lock */
  191. cmpi 0,r0,0
  192. bne- 11f
  193. stwcx. r8,0,r6
  194. beq+ 12f
  195. 11: lwz r0,0(r6)
  196. cmpi 0,r0,0
  197. beq 10b
  198. b 11b
  199. 12: isync
  200. #endif
  201. /*
  202. * Fetch the linux pte and test and set _PAGE_HASHPTE atomically.
  203. * If _PAGE_HASHPTE was already set, we don't replace the existing
  204. * HPTE, so we just unlock and return.
  205. */
  206. mr r8,r5
  207. #ifndef CONFIG_PTE_64BIT
  208. rlwimi r8,r4,22,20,29
  209. #else
  210. rlwimi r8,r4,23,20,28
  211. addi r8,r8,PTE_FLAGS_OFFSET
  212. #endif
  213. 1: lwarx r6,0,r8
  214. andi. r0,r6,_PAGE_HASHPTE
  215. bne 9f /* if HASHPTE already set, done */
  216. #ifdef CONFIG_PTE_64BIT
  217. #ifdef CONFIG_SMP
  218. subf r10,r6,r8 /* create false data dependency */
  219. subi r10,r10,PTE_FLAGS_OFFSET
  220. lwzx r10,r6,r10 /* Get upper PTE word */
  221. #else
  222. lwz r10,-PTE_FLAGS_OFFSET(r8)
  223. #endif /* CONFIG_SMP */
  224. #endif /* CONFIG_PTE_64BIT */
  225. ori r5,r6,_PAGE_HASHPTE
  226. stwcx. r5,0,r8
  227. bne- 1b
  228. /* Convert context and va to VSID */
  229. mulli r3,r3,897*16 /* multiply context by context skew */
  230. rlwinm r0,r4,4,28,31 /* get ESID (top 4 bits of va) */
  231. mulli r0,r0,0x111 /* multiply by ESID skew */
  232. add r3,r3,r0 /* note create_hpte trims to 24 bits */
  233. bl create_hpte
  234. 9:
  235. #ifdef CONFIG_SMP
  236. lis r6, (mmu_hash_lock - PAGE_OFFSET)@ha
  237. addi r6, r6, (mmu_hash_lock - PAGE_OFFSET)@l
  238. eieio
  239. li r0,0
  240. stw r0,0(r6) /* clear mmu_hash_lock */
  241. #endif
  242. /* reenable interrupts and DR */
  243. mtmsr r9
  244. isync
  245. lwz r0,4(r1)
  246. mtlr r0
  247. blr
  248. _ASM_NOKPROBE_SYMBOL(add_hash_page)
  249. /*
  250. * This routine adds a hardware PTE to the hash table.
  251. * It is designed to be called with the MMU either on or off.
  252. * r3 contains the VSID, r4 contains the virtual address,
  253. * r5 contains the linux PTE, r6 contains the old value of the
  254. * linux PTE (before setting _PAGE_HASHPTE). r10 contains the
  255. * upper half of the PTE if CONFIG_PTE_64BIT.
  256. * On SMP, the caller should have the mmu_hash_lock held.
  257. * We assume that the caller has (or will) set the _PAGE_HASHPTE
  258. * bit in the linux PTE in memory. The value passed in r6 should
  259. * be the old linux PTE value; if it doesn't have _PAGE_HASHPTE set
  260. * this routine will skip the search for an existing HPTE.
  261. * This procedure modifies r0, r3 - r6, r8, cr0.
  262. * -- paulus.
  263. *
  264. * For speed, 4 of the instructions get patched once the size and
  265. * physical address of the hash table are known. These definitions
  266. * of Hash_base and Hash_bits below are for the early hash table.
  267. */
  268. Hash_base = early_hash
  269. Hash_bits = 12 /* e.g. 256kB hash table */
  270. Hash_msk = (((1 << Hash_bits) - 1) * 64)
  271. /* defines for the PTE format for 32-bit PPCs */
  272. #define HPTE_SIZE 8
  273. #define PTEG_SIZE 64
  274. #define LG_PTEG_SIZE 6
  275. #define LDPTEu lwzu
  276. #define LDPTE lwz
  277. #define STPTE stw
  278. #define CMPPTE cmpw
  279. #define PTE_H 0x40
  280. #define PTE_V 0x80000000
  281. #define TST_V(r) rlwinm. r,r,0,0,0
  282. #define SET_V(r) oris r,r,PTE_V@h
  283. #define CLR_V(r,t) rlwinm r,r,0,1,31
  284. #define HASH_LEFT 31-(LG_PTEG_SIZE+Hash_bits-1)
  285. #define HASH_RIGHT 31-LG_PTEG_SIZE
  286. __REF
  287. _GLOBAL(create_hpte)
  288. /* Convert linux-style PTE (r5) to low word of PPC-style PTE (r8) */
  289. rlwinm r8,r5,32-9,30,30 /* _PAGE_RW -> PP msb */
  290. rlwinm r0,r5,32-6,30,30 /* _PAGE_DIRTY -> PP msb */
  291. and r8,r8,r0 /* writable if _RW & _DIRTY */
  292. rlwimi r5,r5,32-1,30,30 /* _PAGE_USER -> PP msb */
  293. rlwimi r5,r5,32-2,31,31 /* _PAGE_USER -> PP lsb */
  294. ori r8,r8,0xe04 /* clear out reserved bits */
  295. andc r8,r5,r8 /* PP = user? (rw&dirty? 1: 3): 0 */
  296. BEGIN_FTR_SECTION
  297. rlwinm r8,r8,0,~_PAGE_COHERENT /* clear M (coherence not required) */
  298. END_FTR_SECTION_IFCLR(CPU_FTR_NEED_COHERENT)
  299. #ifdef CONFIG_PTE_64BIT
  300. /* Put the XPN bits into the PTE */
  301. rlwimi r8,r10,8,20,22
  302. rlwimi r8,r10,2,29,29
  303. #endif
  304. /* Construct the high word of the PPC-style PTE (r5) */
  305. rlwinm r5,r3,7,1,24 /* put VSID in 0x7fffff80 bits */
  306. rlwimi r5,r4,10,26,31 /* put in API (abbrev page index) */
  307. SET_V(r5) /* set V (valid) bit */
  308. patch_site 0f, patch__hash_page_A0
  309. patch_site 1f, patch__hash_page_A1
  310. patch_site 2f, patch__hash_page_A2
  311. /* Get the address of the primary PTE group in the hash table (r3) */
  312. 0: lis r0, (Hash_base - PAGE_OFFSET)@h /* base address of hash table */
  313. 1: rlwimi r0,r3,LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT /* VSID -> hash */
  314. 2: rlwinm r3,r4,20+LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT /* PI -> hash */
  315. xor r3,r3,r0 /* make primary hash */
  316. li r0,8 /* PTEs/group */
  317. /*
  318. * Test the _PAGE_HASHPTE bit in the old linux PTE, and skip the search
  319. * if it is clear, meaning that the HPTE isn't there already...
  320. */
  321. andi. r6,r6,_PAGE_HASHPTE
  322. beq+ 10f /* no PTE: go look for an empty slot */
  323. tlbie r4
  324. /* Search the primary PTEG for a PTE whose 1st (d)word matches r5 */
  325. mtctr r0
  326. addi r4,r3,-HPTE_SIZE
  327. 1: LDPTEu r6,HPTE_SIZE(r4) /* get next PTE */
  328. CMPPTE 0,r6,r5
  329. bdnzf 2,1b /* loop while ctr != 0 && !cr0.eq */
  330. beq+ .Lfound_slot
  331. patch_site 0f, patch__hash_page_B
  332. /* Search the secondary PTEG for a matching PTE */
  333. ori r5,r5,PTE_H /* set H (secondary hash) bit */
  334. 0: xoris r4,r3,Hash_msk>>16 /* compute secondary hash */
  335. xori r4,r4,(-PTEG_SIZE & 0xffff)
  336. addi r4,r4,-HPTE_SIZE
  337. mtctr r0
  338. 2: LDPTEu r6,HPTE_SIZE(r4)
  339. CMPPTE 0,r6,r5
  340. bdnzf 2,2b
  341. beq+ .Lfound_slot
  342. xori r5,r5,PTE_H /* clear H bit again */
  343. /* Search the primary PTEG for an empty slot */
  344. 10: mtctr r0
  345. addi r4,r3,-HPTE_SIZE /* search primary PTEG */
  346. 1: LDPTEu r6,HPTE_SIZE(r4) /* get next PTE */
  347. TST_V(r6) /* test valid bit */
  348. bdnzf 2,1b /* loop while ctr != 0 && !cr0.eq */
  349. beq+ .Lfound_empty
  350. patch_site 0f, patch__hash_page_C
  351. /* Search the secondary PTEG for an empty slot */
  352. ori r5,r5,PTE_H /* set H (secondary hash) bit */
  353. 0: xoris r4,r3,Hash_msk>>16 /* compute secondary hash */
  354. xori r4,r4,(-PTEG_SIZE & 0xffff)
  355. addi r4,r4,-HPTE_SIZE
  356. mtctr r0
  357. 2: LDPTEu r6,HPTE_SIZE(r4)
  358. TST_V(r6)
  359. bdnzf 2,2b
  360. beq+ .Lfound_empty
  361. xori r5,r5,PTE_H /* clear H bit again */
  362. /*
  363. * Choose an arbitrary slot in the primary PTEG to overwrite.
  364. * Since both the primary and secondary PTEGs are full, and we
  365. * have no information that the PTEs in the primary PTEG are
  366. * more important or useful than those in the secondary PTEG,
  367. * and we know there is a definite (although small) speed
  368. * advantage to putting the PTE in the primary PTEG, we always
  369. * put the PTE in the primary PTEG.
  370. */
  371. lis r4, (next_slot - PAGE_OFFSET)@ha /* get next evict slot */
  372. lwz r6, (next_slot - PAGE_OFFSET)@l(r4)
  373. addi r6,r6,HPTE_SIZE /* search for candidate */
  374. andi. r6,r6,7*HPTE_SIZE
  375. stw r6,next_slot@l(r4)
  376. add r4,r3,r6
  377. #ifndef CONFIG_SMP
  378. /* Store PTE in PTEG */
  379. .Lfound_empty:
  380. STPTE r5,0(r4)
  381. .Lfound_slot:
  382. STPTE r8,HPTE_SIZE/2(r4)
  383. #else /* CONFIG_SMP */
  384. /*
  385. * Between the tlbie above and updating the hash table entry below,
  386. * another CPU could read the hash table entry and put it in its TLB.
  387. * There are 3 cases:
  388. * 1. using an empty slot
  389. * 2. updating an earlier entry to change permissions (i.e. enable write)
  390. * 3. taking over the PTE for an unrelated address
  391. *
  392. * In each case it doesn't really matter if the other CPUs have the old
  393. * PTE in their TLB. So we don't need to bother with another tlbie here,
  394. * which is convenient as we've overwritten the register that had the
  395. * address. :-) The tlbie above is mainly to make sure that this CPU comes
  396. * and gets the new PTE from the hash table.
  397. *
  398. * We do however have to make sure that the PTE is never in an invalid
  399. * state with the V bit set.
  400. */
  401. .Lfound_empty:
  402. .Lfound_slot:
  403. CLR_V(r5,r0) /* clear V (valid) bit in PTE */
  404. STPTE r5,0(r4)
  405. sync
  406. TLBSYNC
  407. STPTE r8,HPTE_SIZE/2(r4) /* put in correct RPN, WIMG, PP bits */
  408. sync
  409. SET_V(r5)
  410. STPTE r5,0(r4) /* finally set V bit in PTE */
  411. #endif /* CONFIG_SMP */
  412. sync /* make sure pte updates get to memory */
  413. blr
  414. .previous
  415. _ASM_NOKPROBE_SYMBOL(create_hpte)
  416. .section .bss
  417. .align 2
  418. next_slot:
  419. .space 4
  420. .previous
  421. /*
  422. * Flush the entry for a particular page from the hash table.
  423. *
  424. * flush_hash_pages(unsigned context, unsigned long va, unsigned long pmdval,
  425. * int count)
  426. *
  427. * We assume that there is a hash table in use (Hash != 0).
  428. */
  429. __REF
  430. _GLOBAL(flush_hash_pages)
  431. /*
  432. * We disable interrupts here, even on UP, because we want
  433. * the _PAGE_HASHPTE bit to be a reliable indication of
  434. * whether the HPTE exists (or at least whether one did once).
  435. * We also turn off the MMU for data accesses so that we
  436. * we can't take a hash table miss (assuming the code is
  437. * covered by a BAT). -- paulus
  438. */
  439. mfmsr r10
  440. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  441. rlwinm r0,r0,0,28,26 /* clear MSR_DR */
  442. mtmsr r0
  443. isync
  444. /* First find a PTE in the range that has _PAGE_HASHPTE set */
  445. #ifndef CONFIG_PTE_64BIT
  446. rlwimi r5,r4,22,20,29
  447. #else
  448. rlwimi r5,r4,23,20,28
  449. addi r5,r5,PTE_FLAGS_OFFSET
  450. #endif
  451. 1: lwz r0,0(r5)
  452. cmpwi cr1,r6,1
  453. andi. r0,r0,_PAGE_HASHPTE
  454. bne 2f
  455. ble cr1,19f
  456. addi r4,r4,0x1000
  457. addi r5,r5,PTE_T_SIZE
  458. addi r6,r6,-1
  459. b 1b
  460. /* Convert context and va to VSID */
  461. 2: mulli r3,r3,897*16 /* multiply context by context skew */
  462. rlwinm r0,r4,4,28,31 /* get ESID (top 4 bits of va) */
  463. mulli r0,r0,0x111 /* multiply by ESID skew */
  464. add r3,r3,r0 /* note code below trims to 24 bits */
  465. /* Construct the high word of the PPC-style PTE (r11) */
  466. rlwinm r11,r3,7,1,24 /* put VSID in 0x7fffff80 bits */
  467. rlwimi r11,r4,10,26,31 /* put in API (abbrev page index) */
  468. SET_V(r11) /* set V (valid) bit */
  469. #ifdef CONFIG_SMP
  470. lis r9, (mmu_hash_lock - PAGE_OFFSET)@ha
  471. addi r9, r9, (mmu_hash_lock - PAGE_OFFSET)@l
  472. tophys (r8, r2)
  473. lwz r8, TASK_CPU(r8)
  474. oris r8,r8,9
  475. 10: lwarx r0,0,r9
  476. cmpi 0,r0,0
  477. bne- 11f
  478. stwcx. r8,0,r9
  479. beq+ 12f
  480. 11: lwz r0,0(r9)
  481. cmpi 0,r0,0
  482. beq 10b
  483. b 11b
  484. 12: isync
  485. #endif
  486. /*
  487. * Check the _PAGE_HASHPTE bit in the linux PTE. If it is
  488. * already clear, we're done (for this pte). If not,
  489. * clear it (atomically) and proceed. -- paulus.
  490. */
  491. 33: lwarx r8,0,r5 /* fetch the pte flags word */
  492. andi. r0,r8,_PAGE_HASHPTE
  493. beq 8f /* done if HASHPTE is already clear */
  494. rlwinm r8,r8,0,31,29 /* clear HASHPTE bit */
  495. stwcx. r8,0,r5 /* update the pte */
  496. bne- 33b
  497. patch_site 0f, patch__flush_hash_A0
  498. patch_site 1f, patch__flush_hash_A1
  499. patch_site 2f, patch__flush_hash_A2
  500. /* Get the address of the primary PTE group in the hash table (r3) */
  501. 0: lis r8, (Hash_base - PAGE_OFFSET)@h /* base address of hash table */
  502. 1: rlwimi r8,r3,LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT /* VSID -> hash */
  503. 2: rlwinm r0,r4,20+LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT /* PI -> hash */
  504. xor r8,r0,r8 /* make primary hash */
  505. /* Search the primary PTEG for a PTE whose 1st (d)word matches r5 */
  506. li r0,8 /* PTEs/group */
  507. mtctr r0
  508. addi r12,r8,-HPTE_SIZE
  509. 1: LDPTEu r0,HPTE_SIZE(r12) /* get next PTE */
  510. CMPPTE 0,r0,r11
  511. bdnzf 2,1b /* loop while ctr != 0 && !cr0.eq */
  512. beq+ 3f
  513. patch_site 0f, patch__flush_hash_B
  514. /* Search the secondary PTEG for a matching PTE */
  515. ori r11,r11,PTE_H /* set H (secondary hash) bit */
  516. li r0,8 /* PTEs/group */
  517. 0: xoris r12,r8,Hash_msk>>16 /* compute secondary hash */
  518. xori r12,r12,(-PTEG_SIZE & 0xffff)
  519. addi r12,r12,-HPTE_SIZE
  520. mtctr r0
  521. 2: LDPTEu r0,HPTE_SIZE(r12)
  522. CMPPTE 0,r0,r11
  523. bdnzf 2,2b
  524. xori r11,r11,PTE_H /* clear H again */
  525. bne- 4f /* should rarely fail to find it */
  526. 3: li r0,0
  527. STPTE r0,0(r12) /* invalidate entry */
  528. 4: sync
  529. tlbie r4 /* in hw tlb too */
  530. sync
  531. 8: ble cr1,9f /* if all ptes checked */
  532. 81: addi r6,r6,-1
  533. addi r5,r5,PTE_T_SIZE
  534. addi r4,r4,0x1000
  535. lwz r0,0(r5) /* check next pte */
  536. cmpwi cr1,r6,1
  537. andi. r0,r0,_PAGE_HASHPTE
  538. bne 33b
  539. bgt cr1,81b
  540. 9:
  541. #ifdef CONFIG_SMP
  542. TLBSYNC
  543. li r0,0
  544. stw r0,0(r9) /* clear mmu_hash_lock */
  545. #endif
  546. 19: mtmsr r10
  547. isync
  548. blr
  549. .previous
  550. EXPORT_SYMBOL(flush_hash_pages)
  551. _ASM_NOKPROBE_SYMBOL(flush_hash_pages)