hash_low_32.S 17 KB

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