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, int local, int ssize)
51 * Adds a 4K page to the hash table in a segment of 4K pages only
54 _GLOBAL(__hash_page_4K)
57 stdu r1,-STACKFRAMESIZE(r1)
58 /* Save all params that we need after a function call */
59 std r6,STK_PARAM(R6)(r1)
60 std r8,STK_PARAM(R8)(r1)
61 std r9,STK_PARAM(R9)(r1)
63 /* Save non-volatile registers.
64 * r31 will hold "old PTE"
68 * r27 is hashtab mask (maybe dynamic patched instead ?)
70 std r27,STK_REG(R27)(r1)
71 std r28,STK_REG(R28)(r1)
72 std r29,STK_REG(R29)(r1)
73 std r30,STK_REG(R30)(r1)
74 std r31,STK_REG(R31)(r1)
78 * Check permissions, atomically mark the linux PTE busy
83 /* Check access rights (access & ~(pte_val(*ptep))) */
85 bne- htab_wrong_access
86 /* Check if PTE is busy */
87 andi. r0,r31,_PAGE_BUSY
88 /* If so, just bail out and refault if needed. Someone else
89 * is changing this PTE anyway and might hash it.
93 /* Prepare new PTE value (turn access RW into DIRTY, then
94 * add BUSY,HASHPTE and ACCESSED)
96 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
98 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED | _PAGE_HASHPTE
99 /* Write the linux PTE atomically (setting busy) */
106 * Insert/Update the HPTE in the hash table. At this point,
107 * r4 (access) is re-useable, we use it for the new HPTE flags
111 cmpdi r9,0 /* check segment size */
113 END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
114 /* Calc vpn and put it in r29 */
115 sldi r29,r5,SID_SHIFT - VPN_SHIFT
116 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
119 * Calculate hash value for primary slot and store it in r28
121 * r0 = (va >> 12) & ((1ul << (28 - 12)) -1)
123 rldicl r0,r3,64-12,48
124 xor r28,r5,r0 /* hash */
127 3: /* Calc vpn and put it in r29 */
128 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
129 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
133 * calculate hash value for primary slot and
134 * store it in r28 for 1T segment
137 sldi r28,r5,25 /* vsid << 25 */
138 /* r0 = (va >> 12) & ((1ul << (40 - 12)) -1) */
139 rldicl r0,r3,64-12,36
140 xor r28,r28,r5 /* vsid ^ ( vsid << 25) */
141 xor r28,r28,r0 /* hash */
143 /* Convert linux PTE bits into HW equivalents */
144 4: andi. r3,r30,0x1fe /* Get basic set of flags */
145 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
146 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
147 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
148 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
149 andc r0,r30,r0 /* r0 = pte & ~r0 */
150 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
152 * Always add "C" bit for perf. Memory coherence is always enabled
154 ori r3,r3,HPTE_R_C | HPTE_R_M
156 /* We eventually do the icache sync here (maybe inline that
157 * code rather than call a C function...)
162 bl .hash_page_do_lazy_icache
163 END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
165 /* At this point, r3 contains new PP bits, save them in
166 * place of "access" in the param area (sic)
168 std r3,STK_PARAM(R4)(r1)
170 /* Get htab_hash_mask */
171 ld r4,htab_hash_mask@got(2)
172 ld r27,0(r4) /* htab_hash_mask -> r27 */
174 /* Check if we may already be in the hashtable, in this case, we
175 * go to out-of-line code to try to modify the HPTE
177 andi. r0,r31,_PAGE_HASHPTE
181 /* Clear hpte bits in new pte (we also clear BUSY btw) and
184 lis r0,_PAGE_HPTEFLAGS@h
185 ori r0,r0,_PAGE_HPTEFLAGS@l
187 ori r30,r30,_PAGE_HASHPTE
189 /* physical address r5 */
190 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
191 sldi r5,r5,PAGE_SHIFT
193 /* Calculate primary group hash */
195 rldicr r3,r0,3,63-3 /* r3 = (hash & mask) << 3 */
197 /* Call ppc_md.hpte_insert */
198 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
199 mr r4,r29 /* Retrieve vpn */
200 li r7,0 /* !bolted, !secondary */
201 li r8,MMU_PAGE_4K /* page size */
202 li r9,MMU_PAGE_4K /* actual page size */
203 ld r10,STK_PARAM(R9)(r1) /* segment size */
204 _GLOBAL(htab_call_hpte_insert1)
205 bl . /* Patched by htab_finish_init() */
207 bge htab_pte_insert_ok /* Insertion successful */
208 cmpdi 0,r3,-2 /* Critical failure */
209 beq- htab_pte_insert_failure
211 /* Now try secondary slot */
213 /* physical address r5 */
214 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
215 sldi r5,r5,PAGE_SHIFT
217 /* Calculate secondary group hash */
219 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
221 /* Call ppc_md.hpte_insert */
222 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
223 mr r4,r29 /* Retrieve vpn */
224 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
225 li r8,MMU_PAGE_4K /* page size */
226 li r9,MMU_PAGE_4K /* actual page size */
227 ld r10,STK_PARAM(R9)(r1) /* segment size */
228 _GLOBAL(htab_call_hpte_insert2)
229 bl . /* Patched by htab_finish_init() */
231 bge+ htab_pte_insert_ok /* Insertion successful */
232 cmpdi 0,r3,-2 /* Critical failure */
233 beq- htab_pte_insert_failure
235 /* Both are full, we need to evict something */
237 /* Pick a random group based on TB */
243 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
244 /* Call ppc_md.hpte_remove */
245 _GLOBAL(htab_call_hpte_remove)
246 bl . /* Patched by htab_finish_init() */
256 /* Insert slot number & secondary bit in PTE */
257 rldimi r30,r3,12,63-15
259 /* Write out the PTE with a normal write
260 * (maybe add eieio may be good still ?)
263 ld r6,STK_PARAM(R6)(r1)
267 ld r27,STK_REG(R27)(r1)
268 ld r28,STK_REG(R28)(r1)
269 ld r29,STK_REG(R29)(r1)
270 ld r30,STK_REG(R30)(r1)
271 ld r31,STK_REG(R31)(r1)
272 addi r1,r1,STACKFRAMESIZE
278 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
280 rlwinm r3,r31,32-12,29,31
282 /* Secondary group ? if yes, get a inverted hash value */
284 andi. r0,r31,_PAGE_SECONDARY
288 /* Calculate proper slot value for ppc_md.hpte_updatepp */
290 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
291 add r3,r0,r3 /* add slot idx */
293 /* Call ppc_md.hpte_updatepp */
295 li r6,MMU_PAGE_4K /* base page size */
296 li r7,MMU_PAGE_4K /* actual page size */
297 ld r8,STK_PARAM(R9)(r1) /* segment size */
298 ld r9,STK_PARAM(R8)(r1) /* get "local" param */
299 _GLOBAL(htab_call_hpte_updatepp)
300 bl . /* Patched by htab_finish_init() */
302 /* if we failed because typically the HPTE wasn't really here
303 * we try an insertion.
308 /* Clear the BUSY bit and Write out the PTE */
314 /* Bail out clearing reservation */
319 htab_pte_insert_failure:
320 /* Bail out restoring old PTE */
321 ld r6,STK_PARAM(R6)(r1)
327 #else /* CONFIG_PPC_64K_PAGES */
330 /*****************************************************************************
332 * 64K SW & 4K or 64K HW in a 4K segment pages implementation *
334 *****************************************************************************/
336 /* _hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
337 * pte_t *ptep, unsigned long trap, int local, int ssize,
342 * For now, we do NOT implement Admixed pages
344 _GLOBAL(__hash_page_4K)
347 stdu r1,-STACKFRAMESIZE(r1)
348 /* Save all params that we need after a function call */
349 std r6,STK_PARAM(R6)(r1)
350 std r8,STK_PARAM(R8)(r1)
351 std r9,STK_PARAM(R9)(r1)
353 /* Save non-volatile registers.
354 * r31 will hold "old PTE"
357 * r28 is a hash value
358 * r27 is hashtab mask (maybe dynamic patched instead ?)
359 * r26 is the hidx mask
360 * r25 is the index in combo page
362 std r25,STK_REG(R25)(r1)
363 std r26,STK_REG(R26)(r1)
364 std r27,STK_REG(R27)(r1)
365 std r28,STK_REG(R28)(r1)
366 std r29,STK_REG(R29)(r1)
367 std r30,STK_REG(R30)(r1)
368 std r31,STK_REG(R31)(r1)
372 * Check permissions, atomically mark the linux PTE busy
377 /* Check access rights (access & ~(pte_val(*ptep))) */
379 bne- htab_wrong_access
380 /* Check if PTE is busy */
381 andi. r0,r31,_PAGE_BUSY
382 /* If so, just bail out and refault if needed. Someone else
383 * is changing this PTE anyway and might hash it.
386 /* Prepare new PTE value (turn access RW into DIRTY, then
387 * add BUSY and ACCESSED)
389 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
391 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED
392 oris r30,r30,_PAGE_COMBO@h
393 /* Write the linux PTE atomically (setting busy) */
400 * Insert/Update the HPTE in the hash table. At this point,
401 * r4 (access) is re-useable, we use it for the new HPTE flags
404 /* Load the hidx index */
405 rldicl r25,r3,64-12,60
408 cmpdi r9,0 /* check segment size */
410 END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
411 /* Calc vpn and put it in r29 */
412 sldi r29,r5,SID_SHIFT - VPN_SHIFT
414 * clrldi r3,r3,64 - SID_SHIFT --> ea & 0xfffffff
415 * srdi r28,r3,VPN_SHIFT
417 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
420 * Calculate hash value for primary slot and store it in r28
422 * r0 = (va >> 12) & ((1ul << (28 - 12)) -1)
424 rldicl r0,r3,64-12,48
425 xor r28,r5,r0 /* hash */
428 3: /* Calc vpn and put it in r29 */
429 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
431 * clrldi r3,r3,64 - SID_SHIFT_1T --> ea & 0xffffffffff
432 * srdi r28,r3,VPN_SHIFT
434 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
438 * Calculate hash value for primary slot and
439 * store it in r28 for 1T segment
442 sldi r28,r5,25 /* vsid << 25 */
443 /* r0 = (va >> 12) & ((1ul << (40 - 12)) -1) */
444 rldicl r0,r3,64-12,36
445 xor r28,r28,r5 /* vsid ^ ( vsid << 25) */
446 xor r28,r28,r0 /* hash */
448 /* Convert linux PTE bits into HW equivalents */
450 #ifdef CONFIG_PPC_SUBPAGE_PROT
452 andi. r3,r10,0x1fe /* Get basic set of flags */
453 rlwinm r0,r10,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
455 andi. r3,r30,0x1fe /* Get basic set of flags */
456 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
458 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
459 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
460 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
461 andc r0,r3,r0 /* r0 = pte & ~r0 */
462 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
464 * Always add "C" bit for perf. Memory coherence is always enabled
466 ori r3,r3,HPTE_R_C | HPTE_R_M
468 /* We eventually do the icache sync here (maybe inline that
469 * code rather than call a C function...)
474 bl .hash_page_do_lazy_icache
475 END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
477 /* At this point, r3 contains new PP bits, save them in
478 * place of "access" in the param area (sic)
480 std r3,STK_PARAM(R4)(r1)
482 /* Get htab_hash_mask */
483 ld r4,htab_hash_mask@got(2)
484 ld r27,0(r4) /* htab_hash_mask -> r27 */
486 /* Check if we may already be in the hashtable, in this case, we
487 * go to out-of-line code to try to modify the HPTE. We look for
488 * the bit at (1 >> (index + 32))
490 rldicl. r0,r31,64-12,48
491 li r26,0 /* Default hidx */
495 * Check if the pte was already inserted into the hash table
496 * as a 64k HW page, and invalidate the 64k HPTE if so.
498 andis. r0,r31,_PAGE_COMBO@h
499 beq htab_inval_old_hpte
501 ld r6,STK_PARAM(R6)(r1)
502 ori r26,r6,PTE_PAGE_HIDX_OFFSET /* Load the hidx mask. */
504 addi r5,r25,36 /* Check actual HPTE_SUB bit, this */
505 rldcr. r0,r31,r5,0 /* must match pgtable.h definition */
509 /* real page number in r5, PTE RPN value + index */
510 andis. r0,r31,_PAGE_4K_PFN@h
511 srdi r5,r31,PTE_RPN_SHIFT
512 bne- htab_special_pfn
513 sldi r5,r5,PAGE_SHIFT-HW_PAGE_SHIFT
516 sldi r5,r5,HW_PAGE_SHIFT
518 /* Calculate primary group hash */
520 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
522 /* Call ppc_md.hpte_insert */
523 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
524 mr r4,r29 /* Retrieve vpn */
525 li r7,0 /* !bolted, !secondary */
526 li r8,MMU_PAGE_4K /* page size */
527 li r9,MMU_PAGE_4K /* actual page size */
528 ld r10,STK_PARAM(R9)(r1) /* segment size */
529 _GLOBAL(htab_call_hpte_insert1)
530 bl . /* patched by htab_finish_init() */
532 bge htab_pte_insert_ok /* Insertion successful */
533 cmpdi 0,r3,-2 /* Critical failure */
534 beq- htab_pte_insert_failure
536 /* Now try secondary slot */
538 /* real page number in r5, PTE RPN value + index */
539 andis. r0,r31,_PAGE_4K_PFN@h
540 srdi r5,r31,PTE_RPN_SHIFT
542 sldi r5,r5,PAGE_SHIFT-HW_PAGE_SHIFT
544 3: sldi r5,r5,HW_PAGE_SHIFT
546 /* Calculate secondary group hash */
548 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
550 /* Call ppc_md.hpte_insert */
551 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
552 mr r4,r29 /* Retrieve vpn */
553 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
554 li r8,MMU_PAGE_4K /* page size */
555 li r9,MMU_PAGE_4K /* actual page size */
556 ld r10,STK_PARAM(R9)(r1) /* segment size */
557 _GLOBAL(htab_call_hpte_insert2)
558 bl . /* patched by htab_finish_init() */
560 bge+ htab_pte_insert_ok /* Insertion successful */
561 cmpdi 0,r3,-2 /* Critical failure */
562 beq- htab_pte_insert_failure
564 /* Both are full, we need to evict something */
566 /* Pick a random group based on TB */
572 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
573 /* Call ppc_md.hpte_remove */
574 _GLOBAL(htab_call_hpte_remove)
575 bl . /* patched by htab_finish_init() */
581 * Call out to C code to invalidate an 64k HW HPTE that is
582 * useless now that the segment has been switched to 4k pages.
586 mr r4,r31 /* PTE.pte */
587 li r5,0 /* PTE.hidx */
588 li r6,MMU_PAGE_64K /* psize */
589 ld r7,STK_PARAM(R9)(r1) /* ssize */
590 ld r8,STK_PARAM(R8)(r1) /* local */
592 /* Clear out _PAGE_HPTE_SUB bits in the new linux PTE */
593 lis r0,_PAGE_HPTE_SUB@h
594 ori r0,r0,_PAGE_HPTE_SUB@l
603 /* Insert slot number & secondary bit in PTE second half,
604 * clear _PAGE_BUSY and set approriate HPTE slot bit
606 ld r6,STK_PARAM(R6)(r1)
611 subfic r5,r25,27 /* Must match bit position in */
612 sld r0,r0,r5 /* pgtable.h */
621 ori r5,r6,PTE_PAGE_HIDX_OFFSET
627 ld r25,STK_REG(R25)(r1)
628 ld r26,STK_REG(R26)(r1)
629 ld r27,STK_REG(R27)(r1)
630 ld r28,STK_REG(R28)(r1)
631 ld r29,STK_REG(R29)(r1)
632 ld r30,STK_REG(R30)(r1)
633 ld r31,STK_REG(R31)(r1)
634 addi r1,r1,STACKFRAMESIZE
640 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
645 /* Secondary group ? if yes, get a inverted hash value */
647 andi. r0,r3,0x8 /* page secondary ? */
650 1: andi. r3,r3,0x7 /* extract idx alone */
652 /* Calculate proper slot value for ppc_md.hpte_updatepp */
654 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
655 add r3,r0,r3 /* add slot idx */
657 /* Call ppc_md.hpte_updatepp */
659 li r6,MMU_PAGE_4K /* base page size */
660 li r7,MMU_PAGE_4K /* actual page size */
661 ld r8,STK_PARAM(R9)(r1) /* segment size */
662 ld r9,STK_PARAM(R8)(r1) /* get "local" param */
663 _GLOBAL(htab_call_hpte_updatepp)
664 bl . /* patched by htab_finish_init() */
666 /* if we failed because typically the HPTE wasn't really here
667 * we try an insertion.
672 /* Clear the BUSY bit and Write out the PTE */
675 ld r6,STK_PARAM(R6)(r1)
681 /* Bail out clearing reservation */
686 htab_pte_insert_failure:
687 /* Bail out restoring old PTE */
688 ld r6,STK_PARAM(R6)(r1)
693 #endif /* CONFIG_PPC_64K_PAGES */
695 #ifdef CONFIG_PPC_HAS_HASH_64K
697 /*****************************************************************************
699 * 64K SW & 64K HW in a 64K segment pages implementation *
701 *****************************************************************************/
703 _GLOBAL(__hash_page_64K)
706 stdu r1,-STACKFRAMESIZE(r1)
707 /* Save all params that we need after a function call */
708 std r6,STK_PARAM(R6)(r1)
709 std r8,STK_PARAM(R8)(r1)
710 std r9,STK_PARAM(R9)(r1)
712 /* Save non-volatile registers.
713 * r31 will hold "old PTE"
716 * r28 is a hash value
717 * r27 is hashtab mask (maybe dynamic patched instead ?)
719 std r27,STK_REG(R27)(r1)
720 std r28,STK_REG(R28)(r1)
721 std r29,STK_REG(R29)(r1)
722 std r30,STK_REG(R30)(r1)
723 std r31,STK_REG(R31)(r1)
727 * Check permissions, atomically mark the linux PTE busy
732 /* Check access rights (access & ~(pte_val(*ptep))) */
734 bne- ht64_wrong_access
735 /* Check if PTE is busy */
736 andi. r0,r31,_PAGE_BUSY
737 /* If so, just bail out and refault if needed. Someone else
738 * is changing this PTE anyway and might hash it.
742 /* Check if PTE has the cache-inhibit bit set */
743 andi. r0,r31,_PAGE_NO_CACHE
744 /* If so, bail out and refault as a 4k page */
746 END_MMU_FTR_SECTION_IFCLR(MMU_FTR_CI_LARGE_PAGE)
747 /* Prepare new PTE value (turn access RW into DIRTY, then
748 * add BUSY and ACCESSED)
750 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
752 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED
753 /* Write the linux PTE atomically (setting busy) */
760 * Insert/Update the HPTE in the hash table. At this point,
761 * r4 (access) is re-useable, we use it for the new HPTE flags
765 cmpdi r9,0 /* check segment size */
767 END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
768 /* Calc vpn and put it in r29 */
769 sldi r29,r5,SID_SHIFT - VPN_SHIFT
770 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
773 /* Calculate hash value for primary slot and store it in r28
775 * r0 = (va >> 16) & ((1ul << (28 - 16)) -1)
777 rldicl r0,r3,64-16,52
778 xor r28,r5,r0 /* hash */
781 3: /* Calc vpn and put it in r29 */
782 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
783 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
786 * calculate hash value for primary slot and
787 * store it in r28 for 1T segment
790 sldi r28,r5,25 /* vsid << 25 */
791 /* r0 = (va >> 16) & ((1ul << (40 - 16)) -1) */
792 rldicl r0,r3,64-16,40
793 xor r28,r28,r5 /* vsid ^ ( vsid << 25) */
794 xor r28,r28,r0 /* hash */
796 /* Convert linux PTE bits into HW equivalents */
797 4: andi. r3,r30,0x1fe /* Get basic set of flags */
798 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
799 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
800 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
801 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
802 andc r0,r30,r0 /* r0 = pte & ~r0 */
803 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
805 * Always add "C" bit for perf. Memory coherence is always enabled
807 ori r3,r3,HPTE_R_C | HPTE_R_M
809 /* We eventually do the icache sync here (maybe inline that
810 * code rather than call a C function...)
815 bl .hash_page_do_lazy_icache
816 END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
818 /* At this point, r3 contains new PP bits, save them in
819 * place of "access" in the param area (sic)
821 std r3,STK_PARAM(R4)(r1)
823 /* Get htab_hash_mask */
824 ld r4,htab_hash_mask@got(2)
825 ld r27,0(r4) /* htab_hash_mask -> r27 */
827 /* Check if we may already be in the hashtable, in this case, we
828 * go to out-of-line code to try to modify the HPTE
830 rldicl. r0,r31,64-12,48
834 /* Clear hpte bits in new pte (we also clear BUSY btw) and
835 * add _PAGE_HPTE_SUB0
837 lis r0,_PAGE_HPTEFLAGS@h
838 ori r0,r0,_PAGE_HPTEFLAGS@l
840 #ifdef CONFIG_PPC_64K_PAGES
841 oris r30,r30,_PAGE_HPTE_SUB0@h
843 ori r30,r30,_PAGE_HASHPTE
845 /* Phyical address in r5 */
846 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
847 sldi r5,r5,PAGE_SHIFT
849 /* Calculate primary group hash */
851 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
853 /* Call ppc_md.hpte_insert */
854 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
855 mr r4,r29 /* Retrieve vpn */
856 li r7,0 /* !bolted, !secondary */
858 li r9,MMU_PAGE_64K /* actual page size */
859 ld r10,STK_PARAM(R9)(r1) /* segment size */
860 _GLOBAL(ht64_call_hpte_insert1)
861 bl . /* patched by htab_finish_init() */
863 bge ht64_pte_insert_ok /* Insertion successful */
864 cmpdi 0,r3,-2 /* Critical failure */
865 beq- ht64_pte_insert_failure
867 /* Now try secondary slot */
869 /* Phyical address in r5 */
870 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
871 sldi r5,r5,PAGE_SHIFT
873 /* Calculate secondary group hash */
875 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
877 /* Call ppc_md.hpte_insert */
878 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
879 mr r4,r29 /* Retrieve vpn */
880 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
882 li r9,MMU_PAGE_64K /* actual page size */
883 ld r10,STK_PARAM(R9)(r1) /* segment size */
884 _GLOBAL(ht64_call_hpte_insert2)
885 bl . /* patched by htab_finish_init() */
887 bge+ ht64_pte_insert_ok /* Insertion successful */
888 cmpdi 0,r3,-2 /* Critical failure */
889 beq- ht64_pte_insert_failure
891 /* Both are full, we need to evict something */
893 /* Pick a random group based on TB */
899 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
900 /* Call ppc_md.hpte_remove */
901 _GLOBAL(ht64_call_hpte_remove)
902 bl . /* patched by htab_finish_init() */
912 /* Insert slot number & secondary bit in PTE */
913 rldimi r30,r3,12,63-15
915 /* Write out the PTE with a normal write
916 * (maybe add eieio may be good still ?)
919 ld r6,STK_PARAM(R6)(r1)
923 ld r27,STK_REG(R27)(r1)
924 ld r28,STK_REG(R28)(r1)
925 ld r29,STK_REG(R29)(r1)
926 ld r30,STK_REG(R30)(r1)
927 ld r31,STK_REG(R31)(r1)
928 addi r1,r1,STACKFRAMESIZE
934 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
936 rlwinm r3,r31,32-12,29,31
938 /* Secondary group ? if yes, get a inverted hash value */
940 andi. r0,r31,_PAGE_F_SECOND
944 /* Calculate proper slot value for ppc_md.hpte_updatepp */
946 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
947 add r3,r0,r3 /* add slot idx */
949 /* Call ppc_md.hpte_updatepp */
951 li r6,MMU_PAGE_64K /* base page size */
952 li r7,MMU_PAGE_64K /* actual page size */
953 ld r8,STK_PARAM(R9)(r1) /* segment size */
954 ld r9,STK_PARAM(R8)(r1) /* get "local" param */
955 _GLOBAL(ht64_call_hpte_updatepp)
956 bl . /* patched by htab_finish_init() */
958 /* if we failed because typically the HPTE wasn't really here
959 * we try an insertion.
964 /* Clear the BUSY bit and Write out the PTE */
970 /* Bail out clearing reservation */
975 ht64_pte_insert_failure:
976 /* Bail out restoring old PTE */
977 ld r6,STK_PARAM(R6)(r1)
983 #endif /* CONFIG_PPC_HAS_HASH_64K */
986 /*****************************************************************************
988 * Huge pages implementation is in hugetlbpage.c *
990 *****************************************************************************/