hash_low_32.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
  5. * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
  6. * Adapted for Power Macintosh by Paul Mackerras.
  7. * Low-level exception handlers and MMU support
  8. * rewritten by Paul Mackerras.
  9. * Copyright (C) 1996 Paul Mackerras.
  10. *
  11. * This file contains low-level assembler routines for managing
  12. * the PowerPC MMU hash table. (PPC 8xx processors don't use a
  13. * hash table, so this file is not used on them.)
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. *
  20. */
  21. #include <asm/reg.h>
  22. #include <asm/page.h>
  23. #include <asm/pgtable.h>
  24. #include <asm/cputable.h>
  25. #include <asm/ppc_asm.h>
  26. #include <asm/thread_info.h>
  27. #include <asm/asm-offsets.h>
  28. #include <asm/export.h>
  29. #ifdef CONFIG_SMP
  30. .section .bss
  31. .align 2
  32. .globl mmu_hash_lock
  33. mmu_hash_lock:
  34. .space 4
  35. EXPORT_SYMBOL(mmu_hash_lock)
  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. * r9 contains the SRR1 value, from which we use the MSR_PR bit.
  42. * SPRG_THREAD 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, r3 - r8, r10, ctr, lr.
  48. */
  49. .text
  50. _GLOBAL(hash_page)
  51. tophys(r7,0) /* gets -KERNELBASE into r7 */
  52. #ifdef CONFIG_SMP
  53. addis r8,r7,mmu_hash_lock@h
  54. ori r8,r8,mmu_hash_lock@l
  55. lis r0,0x0fff
  56. b 10f
  57. 11: lwz r6,0(r8)
  58. cmpwi 0,r6,0
  59. bne 11b
  60. 10: lwarx r6,0,r8
  61. cmpwi 0,r6,0
  62. bne- 11b
  63. stwcx. r0,0,r8
  64. bne- 10b
  65. isync
  66. #endif
  67. /* Get PTE (linux-style) and check access */
  68. lis r0,KERNELBASE@h /* check if kernel address */
  69. cmplw 0,r4,r0
  70. mfspr r8,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
  71. ori r3,r3,_PAGE_USER|_PAGE_PRESENT /* test low addresses as user */
  72. lwz r5,PGDIR(r8) /* virt page-table root */
  73. blt+ 112f /* assume user more likely */
  74. lis r5,swapper_pg_dir@ha /* if kernel address, use */
  75. addi r5,r5,swapper_pg_dir@l /* kernel page table */
  76. rlwimi r3,r9,32-12,29,29 /* MSR_PR -> _PAGE_USER */
  77. 112: add r5,r5,r7 /* convert to phys addr */
  78. #ifndef CONFIG_PTE_64BIT
  79. rlwimi r5,r4,12,20,29 /* insert top 10 bits of address */
  80. lwz r8,0(r5) /* get pmd entry */
  81. rlwinm. r8,r8,0,0,19 /* extract address of pte page */
  82. #else
  83. rlwinm r8,r4,13,19,29 /* Compute pgdir/pmd offset */
  84. lwzx r8,r8,r5 /* Get L1 entry */
  85. rlwinm. r8,r8,0,0,20 /* extract pt base address */
  86. #endif
  87. #ifdef CONFIG_SMP
  88. beq- hash_page_out /* return if no mapping */
  89. #else
  90. /* XXX it seems like the 601 will give a machine fault on the
  91. rfi if its alignment is wrong (bottom 4 bits of address are
  92. 8 or 0xc) and we have had a not-taken conditional branch
  93. to the address following the rfi. */
  94. beqlr-
  95. #endif
  96. #ifndef CONFIG_PTE_64BIT
  97. rlwimi r8,r4,22,20,29 /* insert next 10 bits of address */
  98. #else
  99. rlwimi r8,r4,23,20,28 /* compute pte address */
  100. #endif
  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. * If PTE_64BIT is set, the low word is the flags word; use that
  110. * word for locking since it contains all the interesting bits.
  111. */
  112. #if (PTE_FLAGS_OFFSET != 0)
  113. addi r8,r8,PTE_FLAGS_OFFSET
  114. #endif
  115. retry:
  116. lwarx r6,0,r8 /* get linux-style pte, flag word */
  117. andc. r5,r3,r6 /* check access & ~permission */
  118. #ifdef CONFIG_SMP
  119. bne- hash_page_out /* return if access not permitted */
  120. #else
  121. bnelr-
  122. #endif
  123. or r5,r0,r6 /* set accessed/dirty bits */
  124. #ifdef CONFIG_PTE_64BIT
  125. #ifdef CONFIG_SMP
  126. subf r10,r6,r8 /* create false data dependency */
  127. subi r10,r10,PTE_FLAGS_OFFSET
  128. lwzx r10,r6,r10 /* Get upper PTE word */
  129. #else
  130. lwz r10,-PTE_FLAGS_OFFSET(r8)
  131. #endif /* CONFIG_SMP */
  132. #endif /* CONFIG_PTE_64BIT */
  133. stwcx. r5,0,r8 /* attempt to update PTE */
  134. bne- retry /* retry if someone got there first */
  135. mfsrin r3,r4 /* get segment reg for segment */
  136. mfctr r0
  137. stw r0,_CTR(r11)
  138. bl create_hpte /* add the hash table entry */
  139. #ifdef CONFIG_SMP
  140. eieio
  141. addis r8,r7,mmu_hash_lock@ha
  142. li r0,0
  143. stw r0,mmu_hash_lock@l(r8)
  144. #endif
  145. /* Return from the exception */
  146. lwz r5,_CTR(r11)
  147. mtctr r5
  148. lwz r0,GPR0(r11)
  149. lwz r7,GPR7(r11)
  150. lwz r8,GPR8(r11)
  151. b fast_exception_return
  152. #ifdef CONFIG_SMP
  153. hash_page_out:
  154. eieio
  155. addis r8,r7,mmu_hash_lock@ha
  156. li r0,0
  157. stw r0,mmu_hash_lock@l(r8)
  158. blr
  159. #endif /* CONFIG_SMP */
  160. /*
  161. * Add an entry for a particular page to the hash table.
  162. *
  163. * add_hash_page(unsigned context, unsigned long va, unsigned long pmdval)
  164. *
  165. * We assume any necessary modifications to the pte (e.g. setting
  166. * the accessed bit) have already been done and that there is actually
  167. * a hash table in use (i.e. we're not on a 603).
  168. */
  169. _GLOBAL(add_hash_page)
  170. mflr r0
  171. stw r0,4(r1)
  172. /* Convert context and va to VSID */
  173. mulli r3,r3,897*16 /* multiply context by context skew */
  174. rlwinm r0,r4,4,28,31 /* get ESID (top 4 bits of va) */
  175. mulli r0,r0,0x111 /* multiply by ESID skew */
  176. add r3,r3,r0 /* note create_hpte trims to 24 bits */
  177. #ifdef CONFIG_SMP
  178. CURRENT_THREAD_INFO(r8, r1) /* use cpu number to make tag */
  179. lwz r8,TI_CPU(r8) /* to go in mmu_hash_lock */
  180. oris r8,r8,12
  181. #endif /* CONFIG_SMP */
  182. /*
  183. * We disable interrupts here, even on UP, because we don't
  184. * want to race with hash_page, and because we want the
  185. * _PAGE_HASHPTE bit to be a reliable indication of whether
  186. * the HPTE exists (or at least whether one did once).
  187. * We also turn off the MMU for data accesses so that we
  188. * we can't take a hash table miss (assuming the code is
  189. * covered by a BAT). -- paulus
  190. */
  191. mfmsr r9
  192. SYNC
  193. rlwinm r0,r9,0,17,15 /* clear bit 16 (MSR_EE) */
  194. rlwinm r0,r0,0,28,26 /* clear MSR_DR */
  195. mtmsr r0
  196. SYNC_601
  197. isync
  198. tophys(r7,0)
  199. #ifdef CONFIG_SMP
  200. addis r6,r7,mmu_hash_lock@ha
  201. addi r6,r6,mmu_hash_lock@l
  202. 10: lwarx r0,0,r6 /* take the mmu_hash_lock */
  203. cmpi 0,r0,0
  204. bne- 11f
  205. stwcx. r8,0,r6
  206. beq+ 12f
  207. 11: lwz r0,0(r6)
  208. cmpi 0,r0,0
  209. beq 10b
  210. b 11b
  211. 12: isync
  212. #endif
  213. /*
  214. * Fetch the linux pte and test and set _PAGE_HASHPTE atomically.
  215. * If _PAGE_HASHPTE was already set, we don't replace the existing
  216. * HPTE, so we just unlock and return.
  217. */
  218. mr r8,r5
  219. #ifndef CONFIG_PTE_64BIT
  220. rlwimi r8,r4,22,20,29
  221. #else
  222. rlwimi r8,r4,23,20,28
  223. addi r8,r8,PTE_FLAGS_OFFSET
  224. #endif
  225. 1: lwarx r6,0,r8
  226. andi. r0,r6,_PAGE_HASHPTE
  227. bne 9f /* if HASHPTE already set, done */
  228. #ifdef CONFIG_PTE_64BIT
  229. #ifdef CONFIG_SMP
  230. subf r10,r6,r8 /* create false data dependency */
  231. subi r10,r10,PTE_FLAGS_OFFSET
  232. lwzx r10,r6,r10 /* Get upper PTE word */
  233. #else
  234. lwz r10,-PTE_FLAGS_OFFSET(r8)
  235. #endif /* CONFIG_SMP */
  236. #endif /* CONFIG_PTE_64BIT */
  237. ori r5,r6,_PAGE_HASHPTE
  238. stwcx. r5,0,r8
  239. bne- 1b
  240. bl create_hpte
  241. 9:
  242. #ifdef CONFIG_SMP
  243. addis r6,r7,mmu_hash_lock@ha
  244. addi r6,r6,mmu_hash_lock@l
  245. eieio
  246. li r0,0
  247. stw r0,0(r6) /* clear mmu_hash_lock */
  248. #endif
  249. /* reenable interrupts and DR */
  250. mtmsr r9
  251. SYNC_601
  252. isync
  253. lwz r0,4(r1)
  254. mtlr r0
  255. blr
  256. /*
  257. * This routine adds a hardware PTE to the hash table.
  258. * It is designed to be called with the MMU either on or off.
  259. * r3 contains the VSID, r4 contains the virtual address,
  260. * r5 contains the linux PTE, r6 contains the old value of the
  261. * linux PTE (before setting _PAGE_HASHPTE) and r7 contains the
  262. * offset to be added to addresses (0 if the MMU is on,
  263. * -KERNELBASE if it is off). r10 contains the upper half of
  264. * the PTE if CONFIG_PTE_64BIT.
  265. * On SMP, the caller should have the mmu_hash_lock held.
  266. * We assume that the caller has (or will) set the _PAGE_HASHPTE
  267. * bit in the linux PTE in memory. The value passed in r6 should
  268. * be the old linux PTE value; if it doesn't have _PAGE_HASHPTE set
  269. * this routine will skip the search for an existing HPTE.
  270. * This procedure modifies r0, r3 - r6, r8, cr0.
  271. * -- paulus.
  272. *
  273. * For speed, 4 of the instructions get patched once the size and
  274. * physical address of the hash table are known. These definitions
  275. * of Hash_base and Hash_bits below are just an example.
  276. */
  277. Hash_base = 0xc0180000
  278. Hash_bits = 12 /* e.g. 256kB hash table */
  279. Hash_msk = (((1 << Hash_bits) - 1) * 64)
  280. /* defines for the PTE format for 32-bit PPCs */
  281. #define HPTE_SIZE 8
  282. #define PTEG_SIZE 64
  283. #define LG_PTEG_SIZE 6
  284. #define LDPTEu lwzu
  285. #define LDPTE lwz
  286. #define STPTE stw
  287. #define CMPPTE cmpw
  288. #define PTE_H 0x40
  289. #define PTE_V 0x80000000
  290. #define TST_V(r) rlwinm. r,r,0,0,0
  291. #define SET_V(r) oris r,r,PTE_V@h
  292. #define CLR_V(r,t) rlwinm r,r,0,1,31
  293. #define HASH_LEFT 31-(LG_PTEG_SIZE+Hash_bits-1)
  294. #define HASH_RIGHT 31-LG_PTEG_SIZE
  295. _GLOBAL(create_hpte)
  296. /* Convert linux-style PTE (r5) to low word of PPC-style PTE (r8) */
  297. rlwinm r8,r5,32-10,31,31 /* _PAGE_RW -> PP lsb */
  298. rlwinm r0,r5,32-7,31,31 /* _PAGE_DIRTY -> PP lsb */
  299. and r8,r8,r0 /* writable if _RW & _DIRTY */
  300. rlwimi r5,r5,32-1,30,30 /* _PAGE_USER -> PP msb */
  301. rlwimi r5,r5,32-2,31,31 /* _PAGE_USER -> PP lsb */
  302. ori r8,r8,0xe04 /* clear out reserved bits */
  303. andc r8,r5,r8 /* PP = user? (rw&dirty? 2: 3): 0 */
  304. BEGIN_FTR_SECTION
  305. rlwinm r8,r8,0,~_PAGE_COHERENT /* clear M (coherence not required) */
  306. END_FTR_SECTION_IFCLR(CPU_FTR_NEED_COHERENT)
  307. #ifdef CONFIG_PTE_64BIT
  308. /* Put the XPN bits into the PTE */
  309. rlwimi r8,r10,8,20,22
  310. rlwimi r8,r10,2,29,29
  311. #endif
  312. /* Construct the high word of the PPC-style PTE (r5) */
  313. rlwinm r5,r3,7,1,24 /* put VSID in 0x7fffff80 bits */
  314. rlwimi r5,r4,10,26,31 /* put in API (abbrev page index) */
  315. SET_V(r5) /* set V (valid) bit */
  316. /* Get the address of the primary PTE group in the hash table (r3) */
  317. _GLOBAL(hash_page_patch_A)
  318. addis r0,r7,Hash_base@h /* base address of hash table */
  319. rlwimi r0,r3,LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT /* VSID -> hash */
  320. rlwinm r3,r4,20+LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT /* PI -> hash */
  321. xor r3,r3,r0 /* make primary hash */
  322. li r0,8 /* PTEs/group */
  323. /*
  324. * Test the _PAGE_HASHPTE bit in the old linux PTE, and skip the search
  325. * if it is clear, meaning that the HPTE isn't there already...
  326. */
  327. andi. r6,r6,_PAGE_HASHPTE
  328. beq+ 10f /* no PTE: go look for an empty slot */
  329. tlbie r4
  330. addis r4,r7,htab_hash_searches@ha
  331. lwz r6,htab_hash_searches@l(r4)
  332. addi r6,r6,1 /* count how many searches we do */
  333. stw r6,htab_hash_searches@l(r4)
  334. /* Search the primary PTEG for a PTE whose 1st (d)word matches r5 */
  335. mtctr r0
  336. addi r4,r3,-HPTE_SIZE
  337. 1: LDPTEu r6,HPTE_SIZE(r4) /* get next PTE */
  338. CMPPTE 0,r6,r5
  339. bdnzf 2,1b /* loop while ctr != 0 && !cr0.eq */
  340. beq+ found_slot
  341. /* Search the secondary PTEG for a matching PTE */
  342. ori r5,r5,PTE_H /* set H (secondary hash) bit */
  343. _GLOBAL(hash_page_patch_B)
  344. xoris r4,r3,Hash_msk>>16 /* compute secondary hash */
  345. xori r4,r4,(-PTEG_SIZE & 0xffff)
  346. addi r4,r4,-HPTE_SIZE
  347. mtctr r0
  348. 2: LDPTEu r6,HPTE_SIZE(r4)
  349. CMPPTE 0,r6,r5
  350. bdnzf 2,2b
  351. beq+ found_slot
  352. xori r5,r5,PTE_H /* clear H bit again */
  353. /* Search the primary PTEG for an empty slot */
  354. 10: mtctr r0
  355. addi r4,r3,-HPTE_SIZE /* search primary PTEG */
  356. 1: LDPTEu r6,HPTE_SIZE(r4) /* get next PTE */
  357. TST_V(r6) /* test valid bit */
  358. bdnzf 2,1b /* loop while ctr != 0 && !cr0.eq */
  359. beq+ found_empty
  360. /* update counter of times that the primary PTEG is full */
  361. addis r4,r7,primary_pteg_full@ha
  362. lwz r6,primary_pteg_full@l(r4)
  363. addi r6,r6,1
  364. stw r6,primary_pteg_full@l(r4)
  365. /* Search the secondary PTEG for an empty slot */
  366. ori r5,r5,PTE_H /* set H (secondary hash) bit */
  367. _GLOBAL(hash_page_patch_C)
  368. xoris r4,r3,Hash_msk>>16 /* compute secondary hash */
  369. xori r4,r4,(-PTEG_SIZE & 0xffff)
  370. addi r4,r4,-HPTE_SIZE
  371. mtctr r0
  372. 2: LDPTEu r6,HPTE_SIZE(r4)
  373. TST_V(r6)
  374. bdnzf 2,2b
  375. beq+ found_empty
  376. xori r5,r5,PTE_H /* clear H bit again */
  377. /*
  378. * Choose an arbitrary slot in the primary PTEG to overwrite.
  379. * Since both the primary and secondary PTEGs are full, and we
  380. * have no information that the PTEs in the primary PTEG are
  381. * more important or useful than those in the secondary PTEG,
  382. * and we know there is a definite (although small) speed
  383. * advantage to putting the PTE in the primary PTEG, we always
  384. * put the PTE in the primary PTEG.
  385. *
  386. * In addition, we skip any slot that is mapping kernel text in
  387. * order to avoid a deadlock when not using BAT mappings if
  388. * trying to hash in the kernel hash code itself after it has
  389. * already taken the hash table lock. This works in conjunction
  390. * with pre-faulting of the kernel text.
  391. *
  392. * If the hash table bucket is full of kernel text entries, we'll
  393. * lockup here but that shouldn't happen
  394. */
  395. 1: addis r4,r7,next_slot@ha /* get next evict slot */
  396. lwz r6,next_slot@l(r4)
  397. addi r6,r6,HPTE_SIZE /* search for candidate */
  398. andi. r6,r6,7*HPTE_SIZE
  399. stw r6,next_slot@l(r4)
  400. add r4,r3,r6
  401. LDPTE r0,HPTE_SIZE/2(r4) /* get PTE second word */
  402. clrrwi r0,r0,12
  403. lis r6,etext@h
  404. ori r6,r6,etext@l /* get etext */
  405. tophys(r6,r6)
  406. cmpl cr0,r0,r6 /* compare and try again */
  407. blt 1b
  408. #ifndef CONFIG_SMP
  409. /* Store PTE in PTEG */
  410. found_empty:
  411. STPTE r5,0(r4)
  412. found_slot:
  413. STPTE r8,HPTE_SIZE/2(r4)
  414. #else /* CONFIG_SMP */
  415. /*
  416. * Between the tlbie above and updating the hash table entry below,
  417. * another CPU could read the hash table entry and put it in its TLB.
  418. * There are 3 cases:
  419. * 1. using an empty slot
  420. * 2. updating an earlier entry to change permissions (i.e. enable write)
  421. * 3. taking over the PTE for an unrelated address
  422. *
  423. * In each case it doesn't really matter if the other CPUs have the old
  424. * PTE in their TLB. So we don't need to bother with another tlbie here,
  425. * which is convenient as we've overwritten the register that had the
  426. * address. :-) The tlbie above is mainly to make sure that this CPU comes
  427. * and gets the new PTE from the hash table.
  428. *
  429. * We do however have to make sure that the PTE is never in an invalid
  430. * state with the V bit set.
  431. */
  432. found_empty:
  433. found_slot:
  434. CLR_V(r5,r0) /* clear V (valid) bit in PTE */
  435. STPTE r5,0(r4)
  436. sync
  437. TLBSYNC
  438. STPTE r8,HPTE_SIZE/2(r4) /* put in correct RPN, WIMG, PP bits */
  439. sync
  440. SET_V(r5)
  441. STPTE r5,0(r4) /* finally set V bit in PTE */
  442. #endif /* CONFIG_SMP */
  443. sync /* make sure pte updates get to memory */
  444. blr
  445. .section .bss
  446. .align 2
  447. next_slot:
  448. .space 4
  449. primary_pteg_full:
  450. .space 4
  451. htab_hash_searches:
  452. .space 4
  453. .previous
  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. #ifndef CONFIG_PTE_64BIT
  481. rlwimi r5,r4,22,20,29
  482. #else
  483. rlwimi r5,r4,23,20,28
  484. #endif
  485. 1: lwz r0,PTE_FLAGS_OFFSET(r5)
  486. cmpwi cr1,r6,1
  487. andi. r0,r0,_PAGE_HASHPTE
  488. bne 2f
  489. ble cr1,19f
  490. addi r4,r4,0x1000
  491. addi r5,r5,PTE_SIZE
  492. addi r6,r6,-1
  493. b 1b
  494. /* Convert context and va to VSID */
  495. 2: mulli r3,r3,897*16 /* multiply context by context skew */
  496. rlwinm r0,r4,4,28,31 /* get ESID (top 4 bits of va) */
  497. mulli r0,r0,0x111 /* multiply by ESID skew */
  498. add r3,r3,r0 /* note code below trims to 24 bits */
  499. /* Construct the high word of the PPC-style PTE (r11) */
  500. rlwinm r11,r3,7,1,24 /* put VSID in 0x7fffff80 bits */
  501. rlwimi r11,r4,10,26,31 /* put in API (abbrev page index) */
  502. SET_V(r11) /* set V (valid) bit */
  503. #ifdef CONFIG_SMP
  504. addis r9,r7,mmu_hash_lock@ha
  505. addi r9,r9,mmu_hash_lock@l
  506. CURRENT_THREAD_INFO(r8, r1)
  507. add r8,r8,r7
  508. lwz r8,TI_CPU(r8)
  509. oris r8,r8,9
  510. 10: lwarx r0,0,r9
  511. cmpi 0,r0,0
  512. bne- 11f
  513. stwcx. r8,0,r9
  514. beq+ 12f
  515. 11: lwz r0,0(r9)
  516. cmpi 0,r0,0
  517. beq 10b
  518. b 11b
  519. 12: isync
  520. #endif
  521. /*
  522. * Check the _PAGE_HASHPTE bit in the linux PTE. If it is
  523. * already clear, we're done (for this pte). If not,
  524. * clear it (atomically) and proceed. -- paulus.
  525. */
  526. #if (PTE_FLAGS_OFFSET != 0)
  527. addi r5,r5,PTE_FLAGS_OFFSET
  528. #endif
  529. 33: lwarx r8,0,r5 /* fetch the pte flags word */
  530. andi. r0,r8,_PAGE_HASHPTE
  531. beq 8f /* done if HASHPTE is already clear */
  532. rlwinm r8,r8,0,31,29 /* clear HASHPTE bit */
  533. stwcx. r8,0,r5 /* update the pte */
  534. bne- 33b
  535. EXPORT_SYMBOL(flush_hash_pages)
  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,-HPTE_SIZE
  546. 1: LDPTEu r0,HPTE_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,-HPTE_SIZE
  557. mtctr r0
  558. 2: LDPTEu r0,HPTE_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,PTE_SIZE
  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
  587. /*
  588. * Flush an entry from the TLB
  589. */
  590. _GLOBAL(_tlbie)
  591. #ifdef CONFIG_SMP
  592. CURRENT_THREAD_INFO(r8, r1)
  593. lwz r8,TI_CPU(r8)
  594. oris r8,r8,11
  595. mfmsr r10
  596. SYNC
  597. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  598. rlwinm r0,r0,0,28,26 /* clear DR */
  599. mtmsr r0
  600. SYNC_601
  601. isync
  602. lis r9,mmu_hash_lock@h
  603. ori r9,r9,mmu_hash_lock@l
  604. tophys(r9,r9)
  605. 10: lwarx r7,0,r9
  606. cmpwi 0,r7,0
  607. bne- 10b
  608. stwcx. r8,0,r9
  609. bne- 10b
  610. eieio
  611. tlbie r3
  612. sync
  613. TLBSYNC
  614. li r0,0
  615. stw r0,0(r9) /* clear mmu_hash_lock */
  616. mtmsr r10
  617. SYNC_601
  618. isync
  619. #else /* CONFIG_SMP */
  620. tlbie r3
  621. sync
  622. #endif /* CONFIG_SMP */
  623. blr
  624. /*
  625. * Flush the entire TLB. 603/603e only
  626. */
  627. _GLOBAL(_tlbia)
  628. #if defined(CONFIG_SMP)
  629. CURRENT_THREAD_INFO(r8, r1)
  630. lwz r8,TI_CPU(r8)
  631. oris r8,r8,10
  632. mfmsr r10
  633. SYNC
  634. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  635. rlwinm r0,r0,0,28,26 /* clear DR */
  636. mtmsr r0
  637. SYNC_601
  638. isync
  639. lis r9,mmu_hash_lock@h
  640. ori r9,r9,mmu_hash_lock@l
  641. tophys(r9,r9)
  642. 10: lwarx r7,0,r9
  643. cmpwi 0,r7,0
  644. bne- 10b
  645. stwcx. r8,0,r9
  646. bne- 10b
  647. sync
  648. tlbia
  649. sync
  650. TLBSYNC
  651. li r0,0
  652. stw r0,0(r9) /* clear mmu_hash_lock */
  653. mtmsr r10
  654. SYNC_601
  655. isync
  656. #else /* CONFIG_SMP */
  657. sync
  658. tlbia
  659. sync
  660. #endif /* CONFIG_SMP */
  661. blr