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 */
151 ori r3,r3,HPTE_R_C /* Always add "C" bit for perf. */
153 /* We eventually do the icache sync here (maybe inline that
154 * code rather than call a C function...)
159 bl .hash_page_do_lazy_icache
160 END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
162 /* At this point, r3 contains new PP bits, save them in
163 * place of "access" in the param area (sic)
165 std r3,STK_PARAM(R4)(r1)
167 /* Get htab_hash_mask */
168 ld r4,htab_hash_mask@got(2)
169 ld r27,0(r4) /* htab_hash_mask -> r27 */
171 /* Check if we may already be in the hashtable, in this case, we
172 * go to out-of-line code to try to modify the HPTE
174 andi. r0,r31,_PAGE_HASHPTE
178 /* Clear hpte bits in new pte (we also clear BUSY btw) and
181 lis r0,_PAGE_HPTEFLAGS@h
182 ori r0,r0,_PAGE_HPTEFLAGS@l
184 ori r30,r30,_PAGE_HASHPTE
186 /* physical address r5 */
187 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
188 sldi r5,r5,PAGE_SHIFT
190 /* Calculate primary group hash */
192 rldicr r3,r0,3,63-3 /* r3 = (hash & mask) << 3 */
194 /* Call ppc_md.hpte_insert */
195 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
196 mr r4,r29 /* Retrieve vpn */
197 li r7,0 /* !bolted, !secondary */
198 li r8,MMU_PAGE_4K /* page size */
199 li r9,MMU_PAGE_4K /* actual page size */
200 ld r10,STK_PARAM(R9)(r1) /* segment size */
201 _GLOBAL(htab_call_hpte_insert1)
202 bl . /* Patched by htab_finish_init() */
204 bge htab_pte_insert_ok /* Insertion successful */
205 cmpdi 0,r3,-2 /* Critical failure */
206 beq- htab_pte_insert_failure
208 /* Now try secondary slot */
210 /* physical address r5 */
211 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
212 sldi r5,r5,PAGE_SHIFT
214 /* Calculate secondary group hash */
216 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
218 /* Call ppc_md.hpte_insert */
219 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
220 mr r4,r29 /* Retrieve vpn */
221 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
222 li r8,MMU_PAGE_4K /* page size */
223 li r9,MMU_PAGE_4K /* actual page size */
224 ld r10,STK_PARAM(R9)(r1) /* segment size */
225 _GLOBAL(htab_call_hpte_insert2)
226 bl . /* Patched by htab_finish_init() */
228 bge+ htab_pte_insert_ok /* Insertion successful */
229 cmpdi 0,r3,-2 /* Critical failure */
230 beq- htab_pte_insert_failure
232 /* Both are full, we need to evict something */
234 /* Pick a random group based on TB */
240 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
241 /* Call ppc_md.hpte_remove */
242 _GLOBAL(htab_call_hpte_remove)
243 bl . /* Patched by htab_finish_init() */
253 /* Insert slot number & secondary bit in PTE */
254 rldimi r30,r3,12,63-15
256 /* Write out the PTE with a normal write
257 * (maybe add eieio may be good still ?)
260 ld r6,STK_PARAM(R6)(r1)
264 ld r27,STK_REG(R27)(r1)
265 ld r28,STK_REG(R28)(r1)
266 ld r29,STK_REG(R29)(r1)
267 ld r30,STK_REG(R30)(r1)
268 ld r31,STK_REG(R31)(r1)
269 addi r1,r1,STACKFRAMESIZE
275 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
277 rlwinm r3,r31,32-12,29,31
279 /* Secondary group ? if yes, get a inverted hash value */
281 andi. r0,r31,_PAGE_SECONDARY
285 /* Calculate proper slot value for ppc_md.hpte_updatepp */
287 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
288 add r3,r0,r3 /* add slot idx */
290 /* Call ppc_md.hpte_updatepp */
292 li r6,MMU_PAGE_4K /* base page size */
293 li r7,MMU_PAGE_4K /* actual page size */
294 ld r8,STK_PARAM(R9)(r1) /* segment size */
295 ld r9,STK_PARAM(R8)(r1) /* get "local" param */
296 _GLOBAL(htab_call_hpte_updatepp)
297 bl . /* Patched by htab_finish_init() */
299 /* if we failed because typically the HPTE wasn't really here
300 * we try an insertion.
305 /* Clear the BUSY bit and Write out the PTE */
311 /* Bail out clearing reservation */
316 htab_pte_insert_failure:
317 /* Bail out restoring old PTE */
318 ld r6,STK_PARAM(R6)(r1)
324 #else /* CONFIG_PPC_64K_PAGES */
327 /*****************************************************************************
329 * 64K SW & 4K or 64K HW in a 4K segment pages implementation *
331 *****************************************************************************/
333 /* _hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
334 * pte_t *ptep, unsigned long trap, int local, int ssize,
339 * For now, we do NOT implement Admixed pages
341 _GLOBAL(__hash_page_4K)
344 stdu r1,-STACKFRAMESIZE(r1)
345 /* Save all params that we need after a function call */
346 std r6,STK_PARAM(R6)(r1)
347 std r8,STK_PARAM(R8)(r1)
348 std r9,STK_PARAM(R9)(r1)
350 /* Save non-volatile registers.
351 * r31 will hold "old PTE"
354 * r28 is a hash value
355 * r27 is hashtab mask (maybe dynamic patched instead ?)
356 * r26 is the hidx mask
357 * r25 is the index in combo page
359 std r25,STK_REG(R25)(r1)
360 std r26,STK_REG(R26)(r1)
361 std r27,STK_REG(R27)(r1)
362 std r28,STK_REG(R28)(r1)
363 std r29,STK_REG(R29)(r1)
364 std r30,STK_REG(R30)(r1)
365 std r31,STK_REG(R31)(r1)
369 * Check permissions, atomically mark the linux PTE busy
374 /* Check access rights (access & ~(pte_val(*ptep))) */
376 bne- htab_wrong_access
377 /* Check if PTE is busy */
378 andi. r0,r31,_PAGE_BUSY
379 /* If so, just bail out and refault if needed. Someone else
380 * is changing this PTE anyway and might hash it.
383 /* Prepare new PTE value (turn access RW into DIRTY, then
384 * add BUSY and ACCESSED)
386 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
388 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED
389 oris r30,r30,_PAGE_COMBO@h
390 /* Write the linux PTE atomically (setting busy) */
397 * Insert/Update the HPTE in the hash table. At this point,
398 * r4 (access) is re-useable, we use it for the new HPTE flags
401 /* Load the hidx index */
402 rldicl r25,r3,64-12,60
405 cmpdi r9,0 /* check segment size */
407 END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
408 /* Calc vpn and put it in r29 */
409 sldi r29,r5,SID_SHIFT - VPN_SHIFT
411 * clrldi r3,r3,64 - SID_SHIFT --> ea & 0xfffffff
412 * srdi r28,r3,VPN_SHIFT
414 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
417 * Calculate hash value for primary slot and store it in r28
419 * r0 = (va >> 12) & ((1ul << (28 - 12)) -1)
421 rldicl r0,r3,64-12,48
422 xor r28,r5,r0 /* hash */
425 3: /* Calc vpn and put it in r29 */
426 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
428 * clrldi r3,r3,64 - SID_SHIFT_1T --> ea & 0xffffffffff
429 * srdi r28,r3,VPN_SHIFT
431 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
435 * Calculate hash value for primary slot and
436 * store it in r28 for 1T segment
439 sldi r28,r5,25 /* vsid << 25 */
440 /* r0 = (va >> 12) & ((1ul << (40 - 12)) -1) */
441 rldicl r0,r3,64-12,36
442 xor r28,r28,r5 /* vsid ^ ( vsid << 25) */
443 xor r28,r28,r0 /* hash */
445 /* Convert linux PTE bits into HW equivalents */
447 #ifdef CONFIG_PPC_SUBPAGE_PROT
449 andi. r3,r10,0x1fe /* Get basic set of flags */
450 rlwinm r0,r10,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
452 andi. r3,r30,0x1fe /* Get basic set of flags */
453 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
455 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
456 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
457 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
458 andc r0,r3,r0 /* r0 = pte & ~r0 */
459 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
460 ori r3,r3,HPTE_R_C /* Always add "C" bit for perf. */
462 /* We eventually do the icache sync here (maybe inline that
463 * code rather than call a C function...)
468 bl .hash_page_do_lazy_icache
469 END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
471 /* At this point, r3 contains new PP bits, save them in
472 * place of "access" in the param area (sic)
474 std r3,STK_PARAM(R4)(r1)
476 /* Get htab_hash_mask */
477 ld r4,htab_hash_mask@got(2)
478 ld r27,0(r4) /* htab_hash_mask -> r27 */
480 /* Check if we may already be in the hashtable, in this case, we
481 * go to out-of-line code to try to modify the HPTE. We look for
482 * the bit at (1 >> (index + 32))
484 rldicl. r0,r31,64-12,48
485 li r26,0 /* Default hidx */
489 * Check if the pte was already inserted into the hash table
490 * as a 64k HW page, and invalidate the 64k HPTE if so.
492 andis. r0,r31,_PAGE_COMBO@h
493 beq htab_inval_old_hpte
495 ld r6,STK_PARAM(R6)(r1)
496 ori r26,r6,PTE_PAGE_HIDX_OFFSET /* Load the hidx mask. */
498 addi r5,r25,36 /* Check actual HPTE_SUB bit, this */
499 rldcr. r0,r31,r5,0 /* must match pgtable.h definition */
503 /* real page number in r5, PTE RPN value + index */
504 andis. r0,r31,_PAGE_4K_PFN@h
505 srdi r5,r31,PTE_RPN_SHIFT
506 bne- htab_special_pfn
507 sldi r5,r5,PAGE_SHIFT-HW_PAGE_SHIFT
510 sldi r5,r5,HW_PAGE_SHIFT
512 /* Calculate primary group hash */
514 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
516 /* Call ppc_md.hpte_insert */
517 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
518 mr r4,r29 /* Retrieve vpn */
519 li r7,0 /* !bolted, !secondary */
520 li r8,MMU_PAGE_4K /* page size */
521 li r9,MMU_PAGE_4K /* actual page size */
522 ld r10,STK_PARAM(R9)(r1) /* segment size */
523 _GLOBAL(htab_call_hpte_insert1)
524 bl . /* patched by htab_finish_init() */
526 bge htab_pte_insert_ok /* Insertion successful */
527 cmpdi 0,r3,-2 /* Critical failure */
528 beq- htab_pte_insert_failure
530 /* Now try secondary slot */
532 /* real page number in r5, PTE RPN value + index */
533 andis. r0,r31,_PAGE_4K_PFN@h
534 srdi r5,r31,PTE_RPN_SHIFT
536 sldi r5,r5,PAGE_SHIFT-HW_PAGE_SHIFT
538 3: sldi r5,r5,HW_PAGE_SHIFT
540 /* Calculate secondary group hash */
542 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
544 /* Call ppc_md.hpte_insert */
545 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
546 mr r4,r29 /* Retrieve vpn */
547 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
548 li r8,MMU_PAGE_4K /* page size */
549 li r9,MMU_PAGE_4K /* actual page size */
550 ld r10,STK_PARAM(R9)(r1) /* segment size */
551 _GLOBAL(htab_call_hpte_insert2)
552 bl . /* patched by htab_finish_init() */
554 bge+ htab_pte_insert_ok /* Insertion successful */
555 cmpdi 0,r3,-2 /* Critical failure */
556 beq- htab_pte_insert_failure
558 /* Both are full, we need to evict something */
560 /* Pick a random group based on TB */
566 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
567 /* Call ppc_md.hpte_remove */
568 _GLOBAL(htab_call_hpte_remove)
569 bl . /* patched by htab_finish_init() */
575 * Call out to C code to invalidate an 64k HW HPTE that is
576 * useless now that the segment has been switched to 4k pages.
580 mr r4,r31 /* PTE.pte */
581 li r5,0 /* PTE.hidx */
582 li r6,MMU_PAGE_64K /* psize */
583 ld r7,STK_PARAM(R9)(r1) /* ssize */
584 ld r8,STK_PARAM(R8)(r1) /* local */
586 /* Clear out _PAGE_HPTE_SUB bits in the new linux PTE */
587 lis r0,_PAGE_HPTE_SUB@h
588 ori r0,r0,_PAGE_HPTE_SUB@l
597 /* Insert slot number & secondary bit in PTE second half,
598 * clear _PAGE_BUSY and set approriate HPTE slot bit
600 ld r6,STK_PARAM(R6)(r1)
605 subfic r5,r25,27 /* Must match bit position in */
606 sld r0,r0,r5 /* pgtable.h */
615 ori r5,r6,PTE_PAGE_HIDX_OFFSET
621 ld r25,STK_REG(R25)(r1)
622 ld r26,STK_REG(R26)(r1)
623 ld r27,STK_REG(R27)(r1)
624 ld r28,STK_REG(R28)(r1)
625 ld r29,STK_REG(R29)(r1)
626 ld r30,STK_REG(R30)(r1)
627 ld r31,STK_REG(R31)(r1)
628 addi r1,r1,STACKFRAMESIZE
634 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
639 /* Secondary group ? if yes, get a inverted hash value */
641 andi. r0,r3,0x8 /* page secondary ? */
644 1: andi. r3,r3,0x7 /* extract idx alone */
646 /* Calculate proper slot value for ppc_md.hpte_updatepp */
648 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
649 add r3,r0,r3 /* add slot idx */
651 /* Call ppc_md.hpte_updatepp */
653 li r6,MMU_PAGE_4K /* base page size */
654 li r7,MMU_PAGE_4K /* actual page size */
655 ld r8,STK_PARAM(R9)(r1) /* segment size */
656 ld r9,STK_PARAM(R8)(r1) /* get "local" param */
657 _GLOBAL(htab_call_hpte_updatepp)
658 bl . /* patched by htab_finish_init() */
660 /* if we failed because typically the HPTE wasn't really here
661 * we try an insertion.
666 /* Clear the BUSY bit and Write out the PTE */
669 ld r6,STK_PARAM(R6)(r1)
675 /* Bail out clearing reservation */
680 htab_pte_insert_failure:
681 /* Bail out restoring old PTE */
682 ld r6,STK_PARAM(R6)(r1)
687 #endif /* CONFIG_PPC_64K_PAGES */
689 #ifdef CONFIG_PPC_HAS_HASH_64K
691 /*****************************************************************************
693 * 64K SW & 64K HW in a 64K segment pages implementation *
695 *****************************************************************************/
697 _GLOBAL(__hash_page_64K)
700 stdu r1,-STACKFRAMESIZE(r1)
701 /* Save all params that we need after a function call */
702 std r6,STK_PARAM(R6)(r1)
703 std r8,STK_PARAM(R8)(r1)
704 std r9,STK_PARAM(R9)(r1)
706 /* Save non-volatile registers.
707 * r31 will hold "old PTE"
710 * r28 is a hash value
711 * r27 is hashtab mask (maybe dynamic patched instead ?)
713 std r27,STK_REG(R27)(r1)
714 std r28,STK_REG(R28)(r1)
715 std r29,STK_REG(R29)(r1)
716 std r30,STK_REG(R30)(r1)
717 std r31,STK_REG(R31)(r1)
721 * Check permissions, atomically mark the linux PTE busy
726 /* Check access rights (access & ~(pte_val(*ptep))) */
728 bne- ht64_wrong_access
729 /* Check if PTE is busy */
730 andi. r0,r31,_PAGE_BUSY
731 /* If so, just bail out and refault if needed. Someone else
732 * is changing this PTE anyway and might hash it.
736 /* Check if PTE has the cache-inhibit bit set */
737 andi. r0,r31,_PAGE_NO_CACHE
738 /* If so, bail out and refault as a 4k page */
740 END_MMU_FTR_SECTION_IFCLR(MMU_FTR_CI_LARGE_PAGE)
741 /* Prepare new PTE value (turn access RW into DIRTY, then
742 * add BUSY and ACCESSED)
744 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
746 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED
747 /* Write the linux PTE atomically (setting busy) */
754 * Insert/Update the HPTE in the hash table. At this point,
755 * r4 (access) is re-useable, we use it for the new HPTE flags
759 cmpdi r9,0 /* check segment size */
761 END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
762 /* Calc vpn and put it in r29 */
763 sldi r29,r5,SID_SHIFT - VPN_SHIFT
764 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
767 /* Calculate hash value for primary slot and store it in r28
769 * r0 = (va >> 16) & ((1ul << (28 - 16)) -1)
771 rldicl r0,r3,64-16,52
772 xor r28,r5,r0 /* hash */
775 3: /* Calc vpn and put it in r29 */
776 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
777 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
780 * calculate hash value for primary slot and
781 * store it in r28 for 1T segment
784 sldi r28,r5,25 /* vsid << 25 */
785 /* r0 = (va >> 16) & ((1ul << (40 - 16)) -1) */
786 rldicl r0,r3,64-16,40
787 xor r28,r28,r5 /* vsid ^ ( vsid << 25) */
788 xor r28,r28,r0 /* hash */
790 /* Convert linux PTE bits into HW equivalents */
791 4: andi. r3,r30,0x1fe /* Get basic set of flags */
792 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
793 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
794 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
795 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
796 andc r0,r30,r0 /* r0 = pte & ~r0 */
797 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
798 ori r3,r3,HPTE_R_C /* Always add "C" bit for perf. */
800 /* We eventually do the icache sync here (maybe inline that
801 * code rather than call a C function...)
806 bl .hash_page_do_lazy_icache
807 END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
809 /* At this point, r3 contains new PP bits, save them in
810 * place of "access" in the param area (sic)
812 std r3,STK_PARAM(R4)(r1)
814 /* Get htab_hash_mask */
815 ld r4,htab_hash_mask@got(2)
816 ld r27,0(r4) /* htab_hash_mask -> r27 */
818 /* Check if we may already be in the hashtable, in this case, we
819 * go to out-of-line code to try to modify the HPTE
821 rldicl. r0,r31,64-12,48
825 /* Clear hpte bits in new pte (we also clear BUSY btw) and
826 * add _PAGE_HPTE_SUB0
828 lis r0,_PAGE_HPTEFLAGS@h
829 ori r0,r0,_PAGE_HPTEFLAGS@l
831 #ifdef CONFIG_PPC_64K_PAGES
832 oris r30,r30,_PAGE_HPTE_SUB0@h
834 ori r30,r30,_PAGE_HASHPTE
836 /* Phyical address in r5 */
837 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
838 sldi r5,r5,PAGE_SHIFT
840 /* Calculate primary group hash */
842 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
844 /* Call ppc_md.hpte_insert */
845 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
846 mr r4,r29 /* Retrieve vpn */
847 li r7,0 /* !bolted, !secondary */
849 li r9,MMU_PAGE_64K /* actual page size */
850 ld r10,STK_PARAM(R9)(r1) /* segment size */
851 _GLOBAL(ht64_call_hpte_insert1)
852 bl . /* patched by htab_finish_init() */
854 bge ht64_pte_insert_ok /* Insertion successful */
855 cmpdi 0,r3,-2 /* Critical failure */
856 beq- ht64_pte_insert_failure
858 /* Now try secondary slot */
860 /* Phyical address in r5 */
861 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
862 sldi r5,r5,PAGE_SHIFT
864 /* Calculate secondary group hash */
866 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
868 /* Call ppc_md.hpte_insert */
869 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
870 mr r4,r29 /* Retrieve vpn */
871 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
873 li r9,MMU_PAGE_64K /* actual page size */
874 ld r10,STK_PARAM(R9)(r1) /* segment size */
875 _GLOBAL(ht64_call_hpte_insert2)
876 bl . /* patched by htab_finish_init() */
878 bge+ ht64_pte_insert_ok /* Insertion successful */
879 cmpdi 0,r3,-2 /* Critical failure */
880 beq- ht64_pte_insert_failure
882 /* Both are full, we need to evict something */
884 /* Pick a random group based on TB */
890 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
891 /* Call ppc_md.hpte_remove */
892 _GLOBAL(ht64_call_hpte_remove)
893 bl . /* patched by htab_finish_init() */
903 /* Insert slot number & secondary bit in PTE */
904 rldimi r30,r3,12,63-15
906 /* Write out the PTE with a normal write
907 * (maybe add eieio may be good still ?)
910 ld r6,STK_PARAM(R6)(r1)
914 ld r27,STK_REG(R27)(r1)
915 ld r28,STK_REG(R28)(r1)
916 ld r29,STK_REG(R29)(r1)
917 ld r30,STK_REG(R30)(r1)
918 ld r31,STK_REG(R31)(r1)
919 addi r1,r1,STACKFRAMESIZE
925 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
927 rlwinm r3,r31,32-12,29,31
929 /* Secondary group ? if yes, get a inverted hash value */
931 andi. r0,r31,_PAGE_F_SECOND
935 /* Calculate proper slot value for ppc_md.hpte_updatepp */
937 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
938 add r3,r0,r3 /* add slot idx */
940 /* Call ppc_md.hpte_updatepp */
942 li r6,MMU_PAGE_64K /* base page size */
943 li r7,MMU_PAGE_64K /* actual page size */
944 ld r8,STK_PARAM(R9)(r1) /* segment size */
945 ld r9,STK_PARAM(R8)(r1) /* get "local" param */
946 _GLOBAL(ht64_call_hpte_updatepp)
947 bl . /* patched by htab_finish_init() */
949 /* if we failed because typically the HPTE wasn't really here
950 * we try an insertion.
955 /* Clear the BUSY bit and Write out the PTE */
961 /* Bail out clearing reservation */
966 ht64_pte_insert_failure:
967 /* Bail out restoring old PTE */
968 ld r6,STK_PARAM(R6)(r1)
974 #endif /* CONFIG_PPC_HAS_HASH_64K */
977 /*****************************************************************************
979 * Huge pages implementation is in hugetlbpage.c *
981 *****************************************************************************/