hashtable.S 18 KB

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