hash_low_32.S 17 KB

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