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 .globl htab_call_hpte_insert1
205 htab_call_hpte_insert1:
206 bl . /* Patched by htab_finish_init() */
208 bge htab_pte_insert_ok /* Insertion successful */
209 cmpdi 0,r3,-2 /* Critical failure */
210 beq- htab_pte_insert_failure
212 /* Now try secondary slot */
214 /* physical address r5 */
215 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
216 sldi r5,r5,PAGE_SHIFT
218 /* Calculate secondary group hash */
220 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
222 /* Call ppc_md.hpte_insert */
223 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
224 mr r4,r29 /* Retrieve vpn */
225 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
226 li r8,MMU_PAGE_4K /* page size */
227 li r9,MMU_PAGE_4K /* actual page size */
228 ld r10,STK_PARAM(R9)(r1) /* segment size */
229 .globl htab_call_hpte_insert2
230 htab_call_hpte_insert2:
231 bl . /* Patched by htab_finish_init() */
233 bge+ htab_pte_insert_ok /* Insertion successful */
234 cmpdi 0,r3,-2 /* Critical failure */
235 beq- htab_pte_insert_failure
237 /* Both are full, we need to evict something */
239 /* Pick a random group based on TB */
245 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
246 /* Call ppc_md.hpte_remove */
247 .globl htab_call_hpte_remove
248 htab_call_hpte_remove:
249 bl . /* Patched by htab_finish_init() */
259 /* Insert slot number & secondary bit in PTE */
260 rldimi r30,r3,12,63-15
262 /* Write out the PTE with a normal write
263 * (maybe add eieio may be good still ?)
266 ld r6,STK_PARAM(R6)(r1)
270 ld r27,STK_REG(R27)(r1)
271 ld r28,STK_REG(R28)(r1)
272 ld r29,STK_REG(R29)(r1)
273 ld r30,STK_REG(R30)(r1)
274 ld r31,STK_REG(R31)(r1)
275 addi r1,r1,STACKFRAMESIZE
281 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
283 rlwinm r3,r31,32-12,29,31
285 /* Secondary group ? if yes, get a inverted hash value */
287 andi. r0,r31,_PAGE_SECONDARY
291 /* Calculate proper slot value for ppc_md.hpte_updatepp */
293 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
294 add r3,r0,r3 /* add slot idx */
296 /* Call ppc_md.hpte_updatepp */
298 li r6,MMU_PAGE_4K /* base page size */
299 li r7,MMU_PAGE_4K /* actual page size */
300 ld r8,STK_PARAM(R9)(r1) /* segment size */
301 ld r9,STK_PARAM(R8)(r1) /* get "local" param */
302 .globl htab_call_hpte_updatepp
303 htab_call_hpte_updatepp:
304 bl . /* Patched by htab_finish_init() */
306 /* if we failed because typically the HPTE wasn't really here
307 * we try an insertion.
312 /* Clear the BUSY bit and Write out the PTE */
318 /* Bail out clearing reservation */
323 htab_pte_insert_failure:
324 /* Bail out restoring old PTE */
325 ld r6,STK_PARAM(R6)(r1)
331 #else /* CONFIG_PPC_64K_PAGES */
334 /*****************************************************************************
336 * 64K SW & 4K or 64K HW in a 4K segment pages implementation *
338 *****************************************************************************/
340 /* _hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
341 * pte_t *ptep, unsigned long trap, int local, int ssize,
346 * For now, we do NOT implement Admixed pages
348 _GLOBAL(__hash_page_4K)
351 stdu r1,-STACKFRAMESIZE(r1)
352 /* Save all params that we need after a function call */
353 std r6,STK_PARAM(R6)(r1)
354 std r8,STK_PARAM(R8)(r1)
355 std r9,STK_PARAM(R9)(r1)
357 /* Save non-volatile registers.
358 * r31 will hold "old PTE"
361 * r28 is a hash value
362 * r27 is hashtab mask (maybe dynamic patched instead ?)
363 * r26 is the hidx mask
364 * r25 is the index in combo page
366 std r25,STK_REG(R25)(r1)
367 std r26,STK_REG(R26)(r1)
368 std r27,STK_REG(R27)(r1)
369 std r28,STK_REG(R28)(r1)
370 std r29,STK_REG(R29)(r1)
371 std r30,STK_REG(R30)(r1)
372 std r31,STK_REG(R31)(r1)
376 * Check permissions, atomically mark the linux PTE busy
381 /* Check access rights (access & ~(pte_val(*ptep))) */
383 bne- htab_wrong_access
384 /* Check if PTE is busy */
385 andi. r0,r31,_PAGE_BUSY
386 /* If so, just bail out and refault if needed. Someone else
387 * is changing this PTE anyway and might hash it.
390 /* Prepare new PTE value (turn access RW into DIRTY, then
391 * add BUSY and ACCESSED)
393 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
395 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED
396 oris r30,r30,_PAGE_COMBO@h
397 /* Write the linux PTE atomically (setting busy) */
404 * Insert/Update the HPTE in the hash table. At this point,
405 * r4 (access) is re-useable, we use it for the new HPTE flags
408 /* Load the hidx index */
409 rldicl r25,r3,64-12,60
412 cmpdi r9,0 /* check segment size */
414 END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
415 /* Calc vpn and put it in r29 */
416 sldi r29,r5,SID_SHIFT - VPN_SHIFT
418 * clrldi r3,r3,64 - SID_SHIFT --> ea & 0xfffffff
419 * srdi r28,r3,VPN_SHIFT
421 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
424 * Calculate hash value for primary slot and store it in r28
426 * r0 = (va >> 12) & ((1ul << (28 - 12)) -1)
428 rldicl r0,r3,64-12,48
429 xor r28,r5,r0 /* hash */
432 3: /* Calc vpn and put it in r29 */
433 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
435 * clrldi r3,r3,64 - SID_SHIFT_1T --> ea & 0xffffffffff
436 * srdi r28,r3,VPN_SHIFT
438 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
442 * Calculate hash value for primary slot and
443 * store it in r28 for 1T segment
446 sldi r28,r5,25 /* vsid << 25 */
447 /* r0 = (va >> 12) & ((1ul << (40 - 12)) -1) */
448 rldicl r0,r3,64-12,36
449 xor r28,r28,r5 /* vsid ^ ( vsid << 25) */
450 xor r28,r28,r0 /* hash */
452 /* Convert linux PTE bits into HW equivalents */
454 #ifdef CONFIG_PPC_SUBPAGE_PROT
456 andi. r3,r10,0x1fe /* Get basic set of flags */
457 rlwinm r0,r10,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
459 andi. r3,r30,0x1fe /* Get basic set of flags */
460 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
462 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
463 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
464 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
465 andc r0,r3,r0 /* r0 = pte & ~r0 */
466 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
468 * Always add "C" bit for perf. Memory coherence is always enabled
470 ori r3,r3,HPTE_R_C | HPTE_R_M
472 /* We eventually do the icache sync here (maybe inline that
473 * code rather than call a C function...)
478 bl hash_page_do_lazy_icache
479 END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
481 /* At this point, r3 contains new PP bits, save them in
482 * place of "access" in the param area (sic)
484 std r3,STK_PARAM(R4)(r1)
486 /* Get htab_hash_mask */
487 ld r4,htab_hash_mask@got(2)
488 ld r27,0(r4) /* htab_hash_mask -> r27 */
490 /* Check if we may already be in the hashtable, in this case, we
491 * go to out-of-line code to try to modify the HPTE. We look for
492 * the bit at (1 >> (index + 32))
494 rldicl. r0,r31,64-12,48
495 li r26,0 /* Default hidx */
499 * Check if the pte was already inserted into the hash table
500 * as a 64k HW page, and invalidate the 64k HPTE if so.
502 andis. r0,r31,_PAGE_COMBO@h
503 beq htab_inval_old_hpte
505 ld r6,STK_PARAM(R6)(r1)
506 ori r26,r6,PTE_PAGE_HIDX_OFFSET /* Load the hidx mask. */
508 addi r5,r25,36 /* Check actual HPTE_SUB bit, this */
509 rldcr. r0,r31,r5,0 /* must match pgtable.h definition */
513 /* real page number in r5, PTE RPN value + index */
514 andis. r0,r31,_PAGE_4K_PFN@h
515 srdi r5,r31,PTE_RPN_SHIFT
516 bne- htab_special_pfn
517 sldi r5,r5,PAGE_SHIFT-HW_PAGE_SHIFT
520 sldi r5,r5,HW_PAGE_SHIFT
522 /* Calculate primary group hash */
524 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
526 /* Call ppc_md.hpte_insert */
527 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
528 mr r4,r29 /* Retrieve vpn */
529 li r7,0 /* !bolted, !secondary */
530 li r8,MMU_PAGE_4K /* page size */
531 li r9,MMU_PAGE_4K /* actual page size */
532 ld r10,STK_PARAM(R9)(r1) /* segment size */
533 .globl htab_call_hpte_insert1
534 htab_call_hpte_insert1:
535 bl . /* patched by htab_finish_init() */
537 bge htab_pte_insert_ok /* Insertion successful */
538 cmpdi 0,r3,-2 /* Critical failure */
539 beq- htab_pte_insert_failure
541 /* Now try secondary slot */
543 /* real page number in r5, PTE RPN value + index */
544 andis. r0,r31,_PAGE_4K_PFN@h
545 srdi r5,r31,PTE_RPN_SHIFT
547 sldi r5,r5,PAGE_SHIFT-HW_PAGE_SHIFT
549 3: sldi r5,r5,HW_PAGE_SHIFT
551 /* Calculate secondary group hash */
553 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
555 /* Call ppc_md.hpte_insert */
556 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
557 mr r4,r29 /* Retrieve vpn */
558 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
559 li r8,MMU_PAGE_4K /* page size */
560 li r9,MMU_PAGE_4K /* actual page size */
561 ld r10,STK_PARAM(R9)(r1) /* segment size */
562 .globl htab_call_hpte_insert2
563 htab_call_hpte_insert2:
564 bl . /* patched by htab_finish_init() */
566 bge+ htab_pte_insert_ok /* Insertion successful */
567 cmpdi 0,r3,-2 /* Critical failure */
568 beq- htab_pte_insert_failure
570 /* Both are full, we need to evict something */
572 /* Pick a random group based on TB */
578 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
579 /* Call ppc_md.hpte_remove */
580 .globl htab_call_hpte_remove
581 htab_call_hpte_remove:
582 bl . /* patched by htab_finish_init() */
588 * Call out to C code to invalidate an 64k HW HPTE that is
589 * useless now that the segment has been switched to 4k pages.
593 mr r4,r31 /* PTE.pte */
594 li r5,0 /* PTE.hidx */
595 li r6,MMU_PAGE_64K /* psize */
596 ld r7,STK_PARAM(R9)(r1) /* ssize */
597 ld r8,STK_PARAM(R8)(r1) /* local */
599 /* Clear out _PAGE_HPTE_SUB bits in the new linux PTE */
600 lis r0,_PAGE_HPTE_SUB@h
601 ori r0,r0,_PAGE_HPTE_SUB@l
610 /* Insert slot number & secondary bit in PTE second half,
611 * clear _PAGE_BUSY and set approriate HPTE slot bit
613 ld r6,STK_PARAM(R6)(r1)
618 subfic r5,r25,27 /* Must match bit position in */
619 sld r0,r0,r5 /* pgtable.h */
628 ori r5,r6,PTE_PAGE_HIDX_OFFSET
634 ld r25,STK_REG(R25)(r1)
635 ld r26,STK_REG(R26)(r1)
636 ld r27,STK_REG(R27)(r1)
637 ld r28,STK_REG(R28)(r1)
638 ld r29,STK_REG(R29)(r1)
639 ld r30,STK_REG(R30)(r1)
640 ld r31,STK_REG(R31)(r1)
641 addi r1,r1,STACKFRAMESIZE
647 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
652 /* Secondary group ? if yes, get a inverted hash value */
654 andi. r0,r3,0x8 /* page secondary ? */
657 1: andi. r3,r3,0x7 /* extract idx alone */
659 /* Calculate proper slot value for ppc_md.hpte_updatepp */
661 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
662 add r3,r0,r3 /* add slot idx */
664 /* Call ppc_md.hpte_updatepp */
666 li r6,MMU_PAGE_4K /* base page size */
667 li r7,MMU_PAGE_4K /* actual page size */
668 ld r8,STK_PARAM(R9)(r1) /* segment size */
669 ld r9,STK_PARAM(R8)(r1) /* get "local" param */
670 .globl htab_call_hpte_updatepp
671 htab_call_hpte_updatepp:
672 bl . /* patched by htab_finish_init() */
674 /* if we failed because typically the HPTE wasn't really here
675 * we try an insertion.
680 /* Clear the BUSY bit and Write out the PTE */
683 ld r6,STK_PARAM(R6)(r1)
689 /* Bail out clearing reservation */
694 htab_pte_insert_failure:
695 /* Bail out restoring old PTE */
696 ld r6,STK_PARAM(R6)(r1)
701 #endif /* CONFIG_PPC_64K_PAGES */
703 #ifdef CONFIG_PPC_HAS_HASH_64K
705 /*****************************************************************************
707 * 64K SW & 64K HW in a 64K segment pages implementation *
709 *****************************************************************************/
711 _GLOBAL(__hash_page_64K)
714 stdu r1,-STACKFRAMESIZE(r1)
715 /* Save all params that we need after a function call */
716 std r6,STK_PARAM(R6)(r1)
717 std r8,STK_PARAM(R8)(r1)
718 std r9,STK_PARAM(R9)(r1)
720 /* Save non-volatile registers.
721 * r31 will hold "old PTE"
724 * r28 is a hash value
725 * r27 is hashtab mask (maybe dynamic patched instead ?)
727 std r27,STK_REG(R27)(r1)
728 std r28,STK_REG(R28)(r1)
729 std r29,STK_REG(R29)(r1)
730 std r30,STK_REG(R30)(r1)
731 std r31,STK_REG(R31)(r1)
735 * Check permissions, atomically mark the linux PTE busy
740 /* Check access rights (access & ~(pte_val(*ptep))) */
742 bne- ht64_wrong_access
743 /* Check if PTE is busy */
744 andi. r0,r31,_PAGE_BUSY
745 /* If so, just bail out and refault if needed. Someone else
746 * is changing this PTE anyway and might hash it.
750 /* Check if PTE has the cache-inhibit bit set */
751 andi. r0,r31,_PAGE_NO_CACHE
752 /* If so, bail out and refault as a 4k page */
754 END_MMU_FTR_SECTION_IFCLR(MMU_FTR_CI_LARGE_PAGE)
755 /* Prepare new PTE value (turn access RW into DIRTY, then
756 * add BUSY and ACCESSED)
758 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
760 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED
761 /* Write the linux PTE atomically (setting busy) */
768 * Insert/Update the HPTE in the hash table. At this point,
769 * r4 (access) is re-useable, we use it for the new HPTE flags
773 cmpdi r9,0 /* check segment size */
775 END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
776 /* Calc vpn and put it in r29 */
777 sldi r29,r5,SID_SHIFT - VPN_SHIFT
778 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
781 /* Calculate hash value for primary slot and store it in r28
783 * r0 = (va >> 16) & ((1ul << (28 - 16)) -1)
785 rldicl r0,r3,64-16,52
786 xor r28,r5,r0 /* hash */
789 3: /* Calc vpn and put it in r29 */
790 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
791 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
794 * calculate hash value for primary slot and
795 * store it in r28 for 1T segment
798 sldi r28,r5,25 /* vsid << 25 */
799 /* r0 = (va >> 16) & ((1ul << (40 - 16)) -1) */
800 rldicl r0,r3,64-16,40
801 xor r28,r28,r5 /* vsid ^ ( vsid << 25) */
802 xor r28,r28,r0 /* hash */
804 /* Convert linux PTE bits into HW equivalents */
805 4: andi. r3,r30,0x1fe /* Get basic set of flags */
806 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
807 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
808 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
809 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
810 andc r0,r30,r0 /* r0 = pte & ~r0 */
811 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
813 * Always add "C" bit for perf. Memory coherence is always enabled
815 ori r3,r3,HPTE_R_C | HPTE_R_M
817 /* We eventually do the icache sync here (maybe inline that
818 * code rather than call a C function...)
823 bl hash_page_do_lazy_icache
824 END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
826 /* At this point, r3 contains new PP bits, save them in
827 * place of "access" in the param area (sic)
829 std r3,STK_PARAM(R4)(r1)
831 /* Get htab_hash_mask */
832 ld r4,htab_hash_mask@got(2)
833 ld r27,0(r4) /* htab_hash_mask -> r27 */
835 /* Check if we may already be in the hashtable, in this case, we
836 * go to out-of-line code to try to modify the HPTE
838 rldicl. r0,r31,64-12,48
842 /* Clear hpte bits in new pte (we also clear BUSY btw) and
843 * add _PAGE_HPTE_SUB0
845 lis r0,_PAGE_HPTEFLAGS@h
846 ori r0,r0,_PAGE_HPTEFLAGS@l
848 #ifdef CONFIG_PPC_64K_PAGES
849 oris r30,r30,_PAGE_HPTE_SUB0@h
851 ori r30,r30,_PAGE_HASHPTE
853 /* Phyical address in r5 */
854 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
855 sldi r5,r5,PAGE_SHIFT
857 /* Calculate primary group hash */
859 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
861 /* Call ppc_md.hpte_insert */
862 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
863 mr r4,r29 /* Retrieve vpn */
864 li r7,0 /* !bolted, !secondary */
866 li r9,MMU_PAGE_64K /* actual page size */
867 ld r10,STK_PARAM(R9)(r1) /* segment size */
868 .globl ht64_call_hpte_insert1
869 ht64_call_hpte_insert1:
870 bl . /* patched by htab_finish_init() */
872 bge ht64_pte_insert_ok /* Insertion successful */
873 cmpdi 0,r3,-2 /* Critical failure */
874 beq- ht64_pte_insert_failure
876 /* Now try secondary slot */
878 /* Phyical address in r5 */
879 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
880 sldi r5,r5,PAGE_SHIFT
882 /* Calculate secondary group hash */
884 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
886 /* Call ppc_md.hpte_insert */
887 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
888 mr r4,r29 /* Retrieve vpn */
889 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
891 li r9,MMU_PAGE_64K /* actual page size */
892 ld r10,STK_PARAM(R9)(r1) /* segment size */
893 .globl ht64_call_hpte_insert2
894 ht64_call_hpte_insert2:
895 bl . /* patched by htab_finish_init() */
897 bge+ ht64_pte_insert_ok /* Insertion successful */
898 cmpdi 0,r3,-2 /* Critical failure */
899 beq- ht64_pte_insert_failure
901 /* Both are full, we need to evict something */
903 /* Pick a random group based on TB */
909 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
910 /* Call ppc_md.hpte_remove */
911 .globl ht64_call_hpte_remove
912 ht64_call_hpte_remove:
913 bl . /* patched by htab_finish_init() */
923 /* Insert slot number & secondary bit in PTE */
924 rldimi r30,r3,12,63-15
926 /* Write out the PTE with a normal write
927 * (maybe add eieio may be good still ?)
930 ld r6,STK_PARAM(R6)(r1)
934 ld r27,STK_REG(R27)(r1)
935 ld r28,STK_REG(R28)(r1)
936 ld r29,STK_REG(R29)(r1)
937 ld r30,STK_REG(R30)(r1)
938 ld r31,STK_REG(R31)(r1)
939 addi r1,r1,STACKFRAMESIZE
945 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
947 rlwinm r3,r31,32-12,29,31
949 /* Secondary group ? if yes, get a inverted hash value */
951 andi. r0,r31,_PAGE_F_SECOND
955 /* Calculate proper slot value for ppc_md.hpte_updatepp */
957 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
958 add r3,r0,r3 /* add slot idx */
960 /* Call ppc_md.hpte_updatepp */
962 li r6,MMU_PAGE_64K /* base page size */
963 li r7,MMU_PAGE_64K /* actual page size */
964 ld r8,STK_PARAM(R9)(r1) /* segment size */
965 ld r9,STK_PARAM(R8)(r1) /* get "local" param */
966 .globl ht64_call_hpte_updatepp
967 ht64_call_hpte_updatepp:
968 bl . /* patched by htab_finish_init() */
970 /* if we failed because typically the HPTE wasn't really here
971 * we try an insertion.
976 /* Clear the BUSY bit and Write out the PTE */
982 /* Bail out clearing reservation */
987 ht64_pte_insert_failure:
988 /* Bail out restoring old PTE */
989 ld r6,STK_PARAM(R6)(r1)
995 #endif /* CONFIG_PPC_HAS_HASH_64K */
998 /*****************************************************************************
1000 * Huge pages implementation is in hugetlbpage.c *
1002 *****************************************************************************/