hashtable.S 17 KB

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