hash_low_32.S 19 KB

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