2 * ppc64 MMU hashtable management routines
4 * (c) Copyright IBM Corp. 2003, 2005
6 * Maintained by: Benjamin Herrenschmidt
7 * <benh@kernel.crashing.org>
9 * This file is covered by the GNU Public Licence v2 as
10 * described in the kernel's COPYING file.
14 #include <asm/pgtable.h>
17 #include <asm/types.h>
18 #include <asm/ppc_asm.h>
19 #include <asm/asm-offsets.h>
20 #include <asm/cputable.h>
27 * +-> Back chain (SP + 256)
28 * | General register save area (SP + 112)
29 * | Parameter save area (SP + 48)
30 * | TOC save area (SP + 40)
31 * | link editor doubleword (SP + 32)
32 * | compiler doubleword (SP + 24)
33 * | LR save area (SP + 16)
34 * | CR save area (SP + 8)
35 * SP ---> +-- Back chain (SP + 0)
38 #ifndef CONFIG_PPC_64K_PAGES
40 /*****************************************************************************
42 * 4K SW & 4K HW pages implementation *
44 *****************************************************************************/
48 * _hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
49 * pte_t *ptep, unsigned long trap, unsigned long flags,
52 * Adds a 4K page to the hash table in a segment of 4K pages only
55 _GLOBAL(__hash_page_4K)
58 stdu r1,-STACKFRAMESIZE(r1)
59 /* Save all params that we need after a function call */
60 std r6,STK_PARAM(R6)(r1)
61 std r8,STK_PARAM(R8)(r1)
62 std r9,STK_PARAM(R9)(r1)
64 /* Save non-volatile registers.
65 * r31 will hold "old PTE"
69 * r27 is hashtab mask (maybe dynamic patched instead ?)
71 std r27,STK_REG(R27)(r1)
72 std r28,STK_REG(R28)(r1)
73 std r29,STK_REG(R29)(r1)
74 std r30,STK_REG(R30)(r1)
75 std r31,STK_REG(R31)(r1)
79 * Check permissions, atomically mark the linux PTE busy
84 /* Check access rights (access & ~(pte_val(*ptep))) */
86 bne- htab_wrong_access
87 /* Check if PTE is busy */
88 andi. r0,r31,_PAGE_BUSY
89 /* If so, just bail out and refault if needed. Someone else
90 * is changing this PTE anyway and might hash it.
94 /* Prepare new PTE value (turn access RW into DIRTY, then
95 * add BUSY,HASHPTE and ACCESSED)
97 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
99 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED | _PAGE_HASHPTE
100 /* Write the linux PTE atomically (setting busy) */
107 * Insert/Update the HPTE in the hash table. At this point,
108 * r4 (access) is re-useable, we use it for the new HPTE flags
112 cmpdi r9,0 /* check segment size */
114 END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
115 /* Calc vpn and put it in r29 */
116 sldi r29,r5,SID_SHIFT - VPN_SHIFT
117 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
120 * Calculate hash value for primary slot and store it in r28
122 * r0 = (va >> 12) & ((1ul << (28 - 12)) -1)
124 rldicl r0,r3,64-12,48
125 xor r28,r5,r0 /* hash */
128 3: /* Calc vpn and put it in r29 */
129 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
130 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
134 * calculate hash value for primary slot and
135 * store it in r28 for 1T segment
138 sldi r28,r5,25 /* vsid << 25 */
139 /* r0 = (va >> 12) & ((1ul << (40 - 12)) -1) */
140 rldicl r0,r3,64-12,36
141 xor r28,r28,r5 /* vsid ^ ( vsid << 25) */
142 xor r28,r28,r0 /* hash */
144 /* Convert linux PTE bits into HW equivalents */
145 4: andi. r3,r30,0x1fe /* Get basic set of flags */
146 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
147 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
148 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
149 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
150 andc r0,r30,r0 /* r0 = pte & ~r0 */
151 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
153 * Always add "C" bit for perf. Memory coherence is always enabled
155 ori r3,r3,HPTE_R_C | HPTE_R_M
157 /* We eventually do the icache sync here (maybe inline that
158 * code rather than call a C function...)
163 bl hash_page_do_lazy_icache
164 END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
166 /* At this point, r3 contains new PP bits, save them in
167 * place of "access" in the param area (sic)
169 std r3,STK_PARAM(R4)(r1)
171 /* Get htab_hash_mask */
172 ld r4,htab_hash_mask@got(2)
173 ld r27,0(r4) /* htab_hash_mask -> r27 */
175 /* Check if we may already be in the hashtable, in this case, we
176 * go to out-of-line code to try to modify the HPTE
178 andi. r0,r31,_PAGE_HASHPTE
182 /* Clear hpte bits in new pte (we also clear BUSY btw) and
185 lis r0,_PAGE_HPTEFLAGS@h
186 ori r0,r0,_PAGE_HPTEFLAGS@l
188 ori r30,r30,_PAGE_HASHPTE
190 /* physical address r5 */
191 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
192 sldi r5,r5,PAGE_SHIFT
194 /* Calculate primary group hash */
196 rldicr r3,r0,3,63-3 /* r3 = (hash & mask) << 3 */
198 /* Call ppc_md.hpte_insert */
199 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
200 mr r4,r29 /* Retrieve vpn */
201 li r7,0 /* !bolted, !secondary */
202 li r8,MMU_PAGE_4K /* page size */
203 li r9,MMU_PAGE_4K /* actual page size */
204 ld r10,STK_PARAM(R9)(r1) /* segment size */
205 .globl htab_call_hpte_insert1
206 htab_call_hpte_insert1:
207 bl . /* Patched by htab_finish_init() */
209 bge htab_pte_insert_ok /* Insertion successful */
210 cmpdi 0,r3,-2 /* Critical failure */
211 beq- htab_pte_insert_failure
213 /* Now try secondary slot */
215 /* physical address r5 */
216 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
217 sldi r5,r5,PAGE_SHIFT
219 /* Calculate secondary group hash */
221 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
223 /* Call ppc_md.hpte_insert */
224 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
225 mr r4,r29 /* Retrieve vpn */
226 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
227 li r8,MMU_PAGE_4K /* page size */
228 li r9,MMU_PAGE_4K /* actual page size */
229 ld r10,STK_PARAM(R9)(r1) /* segment size */
230 .globl htab_call_hpte_insert2
231 htab_call_hpte_insert2:
232 bl . /* Patched by htab_finish_init() */
234 bge+ htab_pte_insert_ok /* Insertion successful */
235 cmpdi 0,r3,-2 /* Critical failure */
236 beq- htab_pte_insert_failure
238 /* Both are full, we need to evict something */
240 /* Pick a random group based on TB */
246 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
247 /* Call ppc_md.hpte_remove */
248 .globl htab_call_hpte_remove
249 htab_call_hpte_remove:
250 bl . /* Patched by htab_finish_init() */
260 /* Insert slot number & secondary bit in PTE */
261 rldimi r30,r3,12,63-15
263 /* Write out the PTE with a normal write
264 * (maybe add eieio may be good still ?)
267 ld r6,STK_PARAM(R6)(r1)
271 ld r27,STK_REG(R27)(r1)
272 ld r28,STK_REG(R28)(r1)
273 ld r29,STK_REG(R29)(r1)
274 ld r30,STK_REG(R30)(r1)
275 ld r31,STK_REG(R31)(r1)
276 addi r1,r1,STACKFRAMESIZE
282 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
284 rlwinm r3,r31,32-12,29,31
286 /* Secondary group ? if yes, get a inverted hash value */
288 andi. r0,r31,_PAGE_SECONDARY
292 /* Calculate proper slot value for ppc_md.hpte_updatepp */
294 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
295 add r3,r0,r3 /* add slot idx */
297 /* Call ppc_md.hpte_updatepp */
299 li r6,MMU_PAGE_4K /* base page size */
300 li r7,MMU_PAGE_4K /* actual page size */
301 ld r8,STK_PARAM(R9)(r1) /* segment size */
302 ld r9,STK_PARAM(R8)(r1) /* get "flags" param */
303 .globl htab_call_hpte_updatepp
304 htab_call_hpte_updatepp:
305 bl . /* Patched by htab_finish_init() */
307 /* if we failed because typically the HPTE wasn't really here
308 * we try an insertion.
313 /* Clear the BUSY bit and Write out the PTE */
319 /* Bail out clearing reservation */
324 htab_pte_insert_failure:
325 /* Bail out restoring old PTE */
326 ld r6,STK_PARAM(R6)(r1)
332 #else /* CONFIG_PPC_64K_PAGES */
335 /*****************************************************************************
337 * 64K SW & 4K or 64K HW in a 4K segment pages implementation *
339 *****************************************************************************/
341 /* _hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
342 * pte_t *ptep, unsigned long trap, unsigned local flags,
343 * int ssize, int subpg_prot)
347 * For now, we do NOT implement Admixed pages
349 _GLOBAL(__hash_page_4K)
352 stdu r1,-STACKFRAMESIZE(r1)
353 /* Save all params that we need after a function call */
354 std r6,STK_PARAM(R6)(r1)
355 std r8,STK_PARAM(R8)(r1)
356 std r9,STK_PARAM(R9)(r1)
358 /* Save non-volatile registers.
359 * r31 will hold "old PTE"
362 * r28 is a hash value
363 * r27 is hashtab mask (maybe dynamic patched instead ?)
364 * r26 is the hidx mask
365 * r25 is the index in combo page
367 std r25,STK_REG(R25)(r1)
368 std r26,STK_REG(R26)(r1)
369 std r27,STK_REG(R27)(r1)
370 std r28,STK_REG(R28)(r1)
371 std r29,STK_REG(R29)(r1)
372 std r30,STK_REG(R30)(r1)
373 std r31,STK_REG(R31)(r1)
377 * Check permissions, atomically mark the linux PTE busy
382 /* Check access rights (access & ~(pte_val(*ptep))) */
384 bne- htab_wrong_access
385 /* Check if PTE is busy */
386 andi. r0,r31,_PAGE_BUSY
387 /* If so, just bail out and refault if needed. Someone else
388 * is changing this PTE anyway and might hash it.
391 /* Prepare new PTE value (turn access RW into DIRTY, then
392 * add BUSY and ACCESSED)
394 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
396 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED
397 oris r30,r30,_PAGE_COMBO@h
398 /* Write the linux PTE atomically (setting busy) */
405 * Insert/Update the HPTE in the hash table. At this point,
406 * r4 (access) is re-useable, we use it for the new HPTE flags
409 /* Load the hidx index */
410 rldicl r25,r3,64-12,60
413 cmpdi r9,0 /* check segment size */
415 END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
416 /* Calc vpn and put it in r29 */
417 sldi r29,r5,SID_SHIFT - VPN_SHIFT
419 * clrldi r3,r3,64 - SID_SHIFT --> ea & 0xfffffff
420 * srdi r28,r3,VPN_SHIFT
422 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
425 * Calculate hash value for primary slot and store it in r28
427 * r0 = (va >> 12) & ((1ul << (28 - 12)) -1)
429 rldicl r0,r3,64-12,48
430 xor r28,r5,r0 /* hash */
433 3: /* Calc vpn and put it in r29 */
434 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
436 * clrldi r3,r3,64 - SID_SHIFT_1T --> ea & 0xffffffffff
437 * srdi r28,r3,VPN_SHIFT
439 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
443 * Calculate hash value for primary slot and
444 * store it in r28 for 1T segment
447 sldi r28,r5,25 /* vsid << 25 */
448 /* r0 = (va >> 12) & ((1ul << (40 - 12)) -1) */
449 rldicl r0,r3,64-12,36
450 xor r28,r28,r5 /* vsid ^ ( vsid << 25) */
451 xor r28,r28,r0 /* hash */
453 /* Convert linux PTE bits into HW equivalents */
455 #ifdef CONFIG_PPC_SUBPAGE_PROT
457 andi. r3,r10,0x1fe /* Get basic set of flags */
458 rlwinm r0,r10,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
460 andi. r3,r30,0x1fe /* Get basic set of flags */
461 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
463 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
464 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
465 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
466 andc r0,r3,r0 /* r0 = pte & ~r0 */
467 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
469 * Always add "C" bit for perf. Memory coherence is always enabled
471 ori r3,r3,HPTE_R_C | HPTE_R_M
473 /* We eventually do the icache sync here (maybe inline that
474 * code rather than call a C function...)
479 bl hash_page_do_lazy_icache
480 END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
482 /* At this point, r3 contains new PP bits, save them in
483 * place of "access" in the param area (sic)
485 std r3,STK_PARAM(R4)(r1)
487 /* Get htab_hash_mask */
488 ld r4,htab_hash_mask@got(2)
489 ld r27,0(r4) /* htab_hash_mask -> r27 */
491 /* Check if we may already be in the hashtable, in this case, we
492 * go to out-of-line code to try to modify the HPTE. We look for
493 * the bit at (1 >> (index + 32))
495 rldicl. r0,r31,64-12,48
496 li r26,0 /* Default hidx */
500 * Check if the pte was already inserted into the hash table
501 * as a 64k HW page, and invalidate the 64k HPTE if so.
503 andis. r0,r31,_PAGE_COMBO@h
504 beq htab_inval_old_hpte
506 ld r6,STK_PARAM(R6)(r1)
507 ori r26,r6,PTE_PAGE_HIDX_OFFSET /* Load the hidx mask. */
509 addi r5,r25,36 /* Check actual HPTE_SUB bit, this */
510 rldcr. r0,r31,r5,0 /* must match pgtable.h definition */
514 /* real page number in r5, PTE RPN value + index */
515 andis. r0,r31,_PAGE_4K_PFN@h
516 srdi r5,r31,PTE_RPN_SHIFT
517 bne- htab_special_pfn
518 sldi r5,r5,PAGE_FACTOR
521 sldi r5,r5,HW_PAGE_SHIFT
523 /* Calculate primary group hash */
525 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
527 /* Call ppc_md.hpte_insert */
528 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
529 mr r4,r29 /* Retrieve vpn */
530 li r7,0 /* !bolted, !secondary */
531 li r8,MMU_PAGE_4K /* page size */
532 li r9,MMU_PAGE_4K /* actual page size */
533 ld r10,STK_PARAM(R9)(r1) /* segment size */
534 .globl htab_call_hpte_insert1
535 htab_call_hpte_insert1:
536 bl . /* patched by htab_finish_init() */
538 bge htab_pte_insert_ok /* Insertion successful */
539 cmpdi 0,r3,-2 /* Critical failure */
540 beq- htab_pte_insert_failure
542 /* Now try secondary slot */
544 /* real page number in r5, PTE RPN value + index */
545 andis. r0,r31,_PAGE_4K_PFN@h
546 srdi r5,r31,PTE_RPN_SHIFT
548 sldi r5,r5,PAGE_FACTOR
550 3: sldi r5,r5,HW_PAGE_SHIFT
552 /* Calculate secondary group hash */
554 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
556 /* Call ppc_md.hpte_insert */
557 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
558 mr r4,r29 /* Retrieve vpn */
559 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
560 li r8,MMU_PAGE_4K /* page size */
561 li r9,MMU_PAGE_4K /* actual page size */
562 ld r10,STK_PARAM(R9)(r1) /* segment size */
563 .globl htab_call_hpte_insert2
564 htab_call_hpte_insert2:
565 bl . /* patched by htab_finish_init() */
567 bge+ htab_pte_insert_ok /* Insertion successful */
568 cmpdi 0,r3,-2 /* Critical failure */
569 beq- htab_pte_insert_failure
571 /* Both are full, we need to evict something */
573 /* Pick a random group based on TB */
579 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
580 /* Call ppc_md.hpte_remove */
581 .globl htab_call_hpte_remove
582 htab_call_hpte_remove:
583 bl . /* patched by htab_finish_init() */
589 * Call out to C code to invalidate an 64k HW HPTE that is
590 * useless now that the segment has been switched to 4k pages.
594 mr r4,r31 /* PTE.pte */
595 li r5,0 /* PTE.hidx */
596 li r6,MMU_PAGE_64K /* psize */
597 ld r7,STK_PARAM(R9)(r1) /* ssize */
598 ld r8,STK_PARAM(R8)(r1) /* flags */
600 /* Clear out _PAGE_HPTE_SUB bits in the new linux PTE */
601 lis r0,_PAGE_HPTE_SUB@h
602 ori r0,r0,_PAGE_HPTE_SUB@l
611 /* Insert slot number & secondary bit in PTE second half,
612 * clear _PAGE_BUSY and set approriate HPTE slot bit
614 ld r6,STK_PARAM(R6)(r1)
619 subfic r5,r25,27 /* Must match bit position in */
620 sld r0,r0,r5 /* pgtable.h */
629 ori r5,r6,PTE_PAGE_HIDX_OFFSET
635 ld r25,STK_REG(R25)(r1)
636 ld r26,STK_REG(R26)(r1)
637 ld r27,STK_REG(R27)(r1)
638 ld r28,STK_REG(R28)(r1)
639 ld r29,STK_REG(R29)(r1)
640 ld r30,STK_REG(R30)(r1)
641 ld r31,STK_REG(R31)(r1)
642 addi r1,r1,STACKFRAMESIZE
648 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
653 /* Secondary group ? if yes, get a inverted hash value */
655 andi. r0,r3,0x8 /* page secondary ? */
658 1: andi. r3,r3,0x7 /* extract idx alone */
660 /* Calculate proper slot value for ppc_md.hpte_updatepp */
662 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
663 add r3,r0,r3 /* add slot idx */
665 /* Call ppc_md.hpte_updatepp */
667 li r6,MMU_PAGE_4K /* base page size */
668 li r7,MMU_PAGE_4K /* actual page size */
669 ld r8,STK_PARAM(R9)(r1) /* segment size */
670 ld r9,STK_PARAM(R8)(r1) /* get "flags" param */
671 .globl htab_call_hpte_updatepp
672 htab_call_hpte_updatepp:
673 bl . /* patched by htab_finish_init() */
675 /* if we failed because typically the HPTE wasn't really here
676 * we try an insertion.
681 /* Clear the BUSY bit and Write out the PTE */
684 ld r6,STK_PARAM(R6)(r1)
690 /* Bail out clearing reservation */
695 htab_pte_insert_failure:
696 /* Bail out restoring old PTE */
697 ld r6,STK_PARAM(R6)(r1)
702 #endif /* CONFIG_PPC_64K_PAGES */
704 #ifdef CONFIG_PPC_HAS_HASH_64K
706 /*****************************************************************************
708 * 64K SW & 64K HW in a 64K segment pages implementation *
710 *****************************************************************************/
712 _GLOBAL(__hash_page_64K)
715 stdu r1,-STACKFRAMESIZE(r1)
716 /* Save all params that we need after a function call */
717 std r6,STK_PARAM(R6)(r1)
718 std r8,STK_PARAM(R8)(r1)
719 std r9,STK_PARAM(R9)(r1)
721 /* Save non-volatile registers.
722 * r31 will hold "old PTE"
725 * r28 is a hash value
726 * r27 is hashtab mask (maybe dynamic patched instead ?)
728 std r27,STK_REG(R27)(r1)
729 std r28,STK_REG(R28)(r1)
730 std r29,STK_REG(R29)(r1)
731 std r30,STK_REG(R30)(r1)
732 std r31,STK_REG(R31)(r1)
736 * Check permissions, atomically mark the linux PTE busy
741 /* Check access rights (access & ~(pte_val(*ptep))) */
743 bne- ht64_wrong_access
744 /* Check if PTE is busy */
745 andi. r0,r31,_PAGE_BUSY
746 /* If so, just bail out and refault if needed. Someone else
747 * is changing this PTE anyway and might hash it.
751 /* Check if PTE has the cache-inhibit bit set */
752 andi. r0,r31,_PAGE_NO_CACHE
753 /* If so, bail out and refault as a 4k page */
755 END_MMU_FTR_SECTION_IFCLR(MMU_FTR_CI_LARGE_PAGE)
756 /* Prepare new PTE value (turn access RW into DIRTY, then
757 * add BUSY and ACCESSED)
759 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
761 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED
762 /* Write the linux PTE atomically (setting busy) */
769 * Insert/Update the HPTE in the hash table. At this point,
770 * r4 (access) is re-useable, we use it for the new HPTE flags
774 cmpdi r9,0 /* check segment size */
776 END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
777 /* Calc vpn and put it in r29 */
778 sldi r29,r5,SID_SHIFT - VPN_SHIFT
779 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
782 /* Calculate hash value for primary slot and store it in r28
784 * r0 = (va >> 16) & ((1ul << (28 - 16)) -1)
786 rldicl r0,r3,64-16,52
787 xor r28,r5,r0 /* hash */
790 3: /* Calc vpn and put it in r29 */
791 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
792 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
795 * calculate hash value for primary slot and
796 * store it in r28 for 1T segment
799 sldi r28,r5,25 /* vsid << 25 */
800 /* r0 = (va >> 16) & ((1ul << (40 - 16)) -1) */
801 rldicl r0,r3,64-16,40
802 xor r28,r28,r5 /* vsid ^ ( vsid << 25) */
803 xor r28,r28,r0 /* hash */
805 /* Convert linux PTE bits into HW equivalents */
806 4: andi. r3,r30,0x1fe /* Get basic set of flags */
807 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
808 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
809 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
810 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
811 andc r0,r30,r0 /* r0 = pte & ~r0 */
812 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
814 * Always add "C" bit for perf. Memory coherence is always enabled
816 ori r3,r3,HPTE_R_C | HPTE_R_M
818 /* We eventually do the icache sync here (maybe inline that
819 * code rather than call a C function...)
824 bl hash_page_do_lazy_icache
825 END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
827 /* At this point, r3 contains new PP bits, save them in
828 * place of "access" in the param area (sic)
830 std r3,STK_PARAM(R4)(r1)
832 /* Get htab_hash_mask */
833 ld r4,htab_hash_mask@got(2)
834 ld r27,0(r4) /* htab_hash_mask -> r27 */
836 /* Check if we may already be in the hashtable, in this case, we
837 * go to out-of-line code to try to modify the HPTE
839 rldicl. r0,r31,64-12,48
843 /* Clear hpte bits in new pte (we also clear BUSY btw) and
844 * add _PAGE_HPTE_SUB0
846 lis r0,_PAGE_HPTEFLAGS@h
847 ori r0,r0,_PAGE_HPTEFLAGS@l
849 #ifdef CONFIG_PPC_64K_PAGES
850 oris r30,r30,_PAGE_HPTE_SUB0@h
852 ori r30,r30,_PAGE_HASHPTE
854 /* Phyical address in r5 */
855 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
856 sldi r5,r5,PAGE_SHIFT
858 /* Calculate primary group hash */
860 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
862 /* Call ppc_md.hpte_insert */
863 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
864 mr r4,r29 /* Retrieve vpn */
865 li r7,0 /* !bolted, !secondary */
867 li r9,MMU_PAGE_64K /* actual page size */
868 ld r10,STK_PARAM(R9)(r1) /* segment size */
869 .globl ht64_call_hpte_insert1
870 ht64_call_hpte_insert1:
871 bl . /* patched by htab_finish_init() */
873 bge ht64_pte_insert_ok /* Insertion successful */
874 cmpdi 0,r3,-2 /* Critical failure */
875 beq- ht64_pte_insert_failure
877 /* Now try secondary slot */
879 /* Phyical address in r5 */
880 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
881 sldi r5,r5,PAGE_SHIFT
883 /* Calculate secondary group hash */
885 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
887 /* Call ppc_md.hpte_insert */
888 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
889 mr r4,r29 /* Retrieve vpn */
890 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
892 li r9,MMU_PAGE_64K /* actual page size */
893 ld r10,STK_PARAM(R9)(r1) /* segment size */
894 .globl ht64_call_hpte_insert2
895 ht64_call_hpte_insert2:
896 bl . /* patched by htab_finish_init() */
898 bge+ ht64_pte_insert_ok /* Insertion successful */
899 cmpdi 0,r3,-2 /* Critical failure */
900 beq- ht64_pte_insert_failure
902 /* Both are full, we need to evict something */
904 /* Pick a random group based on TB */
910 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
911 /* Call ppc_md.hpte_remove */
912 .globl ht64_call_hpte_remove
913 ht64_call_hpte_remove:
914 bl . /* patched by htab_finish_init() */
924 /* Insert slot number & secondary bit in PTE */
925 rldimi r30,r3,12,63-15
927 /* Write out the PTE with a normal write
928 * (maybe add eieio may be good still ?)
931 ld r6,STK_PARAM(R6)(r1)
935 ld r27,STK_REG(R27)(r1)
936 ld r28,STK_REG(R28)(r1)
937 ld r29,STK_REG(R29)(r1)
938 ld r30,STK_REG(R30)(r1)
939 ld r31,STK_REG(R31)(r1)
940 addi r1,r1,STACKFRAMESIZE
946 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
948 rlwinm r3,r31,32-12,29,31
950 /* Secondary group ? if yes, get a inverted hash value */
952 andi. r0,r31,_PAGE_F_SECOND
956 /* Calculate proper slot value for ppc_md.hpte_updatepp */
958 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
959 add r3,r0,r3 /* add slot idx */
961 /* Call ppc_md.hpte_updatepp */
963 li r6,MMU_PAGE_64K /* base page size */
964 li r7,MMU_PAGE_64K /* actual page size */
965 ld r8,STK_PARAM(R9)(r1) /* segment size */
966 ld r9,STK_PARAM(R8)(r1) /* get "flags" param */
967 .globl ht64_call_hpte_updatepp
968 ht64_call_hpte_updatepp:
969 bl . /* patched by htab_finish_init() */
971 /* if we failed because typically the HPTE wasn't really here
972 * we try an insertion.
977 /* Clear the BUSY bit and Write out the PTE */
983 /* Bail out clearing reservation */
988 ht64_pte_insert_failure:
989 /* Bail out restoring old PTE */
990 ld r6,STK_PARAM(R6)(r1)
996 #endif /* CONFIG_PPC_HAS_HASH_64K */
999 /*****************************************************************************
1001 * Huge pages implementation is in hugetlbpage.c *
1003 *****************************************************************************/