hashtable.S 18 KB

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