hashtable.S
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:18k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

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