hashtable.S
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:18k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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