hash_low_32.S 17 KB

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