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 */
120 rldicl r5,r5,0,25 /* vsid & 0x0000007fffffffff */
121 rldicl r0,r3,64-12,48 /* (ea >> 12) & 0xffff */
125 3: /* Calc vpn and put it in r29 */
126 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
127 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
131 * calculate hash value for primary slot and
132 * store it in r28 for 1T segment
134 rldic r28,r5,25,25 /* (vsid << 25) & 0x7fffffffff */
135 clrldi r5,r5,40 /* vsid & 0xffffff */
136 rldicl r0,r3,64-12,36 /* (ea >> 12) & 0xfffffff */
138 xor r28,r28,r0 /* hash */
140 /* Convert linux PTE bits into HW equivalents */
141 4: andi. r3,r30,0x1fe /* Get basic set of flags */
142 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
143 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
144 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
145 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
146 andc r0,r30,r0 /* r0 = pte & ~r0 */
147 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
148 ori r3,r3,HPTE_R_C /* Always add "C" bit for perf. */
150 /* We eventually do the icache sync here (maybe inline that
151 * code rather than call a C function...)
156 bl .hash_page_do_lazy_icache
157 END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
159 /* At this point, r3 contains new PP bits, save them in
160 * place of "access" in the param area (sic)
162 std r3,STK_PARAM(R4)(r1)
164 /* Get htab_hash_mask */
165 ld r4,htab_hash_mask@got(2)
166 ld r27,0(r4) /* htab_hash_mask -> r27 */
168 /* Check if we may already be in the hashtable, in this case, we
169 * go to out-of-line code to try to modify the HPTE
171 andi. r0,r31,_PAGE_HASHPTE
175 /* Clear hpte bits in new pte (we also clear BUSY btw) and
178 lis r0,_PAGE_HPTEFLAGS@h
179 ori r0,r0,_PAGE_HPTEFLAGS@l
181 ori r30,r30,_PAGE_HASHPTE
183 /* physical address r5 */
184 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
185 sldi r5,r5,PAGE_SHIFT
187 /* Calculate primary group hash */
189 rldicr r3,r0,3,63-3 /* r3 = (hash & mask) << 3 */
191 /* Call ppc_md.hpte_insert */
192 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
193 mr r4,r29 /* Retrieve vpn */
194 li r7,0 /* !bolted, !secondary */
195 li r8,MMU_PAGE_4K /* page size */
196 ld r9,STK_PARAM(R9)(r1) /* segment size */
197 _GLOBAL(htab_call_hpte_insert1)
198 bl . /* Patched by htab_finish_init() */
200 bge htab_pte_insert_ok /* Insertion successful */
201 cmpdi 0,r3,-2 /* Critical failure */
202 beq- htab_pte_insert_failure
204 /* Now try secondary slot */
206 /* physical address r5 */
207 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
208 sldi r5,r5,PAGE_SHIFT
210 /* Calculate secondary group hash */
212 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
214 /* Call ppc_md.hpte_insert */
215 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
216 mr r4,r29 /* Retrieve vpn */
217 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
218 li r8,MMU_PAGE_4K /* page size */
219 ld r9,STK_PARAM(R9)(r1) /* segment size */
220 _GLOBAL(htab_call_hpte_insert2)
221 bl . /* Patched by htab_finish_init() */
223 bge+ htab_pte_insert_ok /* Insertion successful */
224 cmpdi 0,r3,-2 /* Critical failure */
225 beq- htab_pte_insert_failure
227 /* Both are full, we need to evict something */
229 /* Pick a random group based on TB */
235 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
236 /* Call ppc_md.hpte_remove */
237 _GLOBAL(htab_call_hpte_remove)
238 bl . /* Patched by htab_finish_init() */
248 /* Insert slot number & secondary bit in PTE */
249 rldimi r30,r3,12,63-15
251 /* Write out the PTE with a normal write
252 * (maybe add eieio may be good still ?)
255 ld r6,STK_PARAM(R6)(r1)
259 ld r27,STK_REG(R27)(r1)
260 ld r28,STK_REG(R28)(r1)
261 ld r29,STK_REG(R29)(r1)
262 ld r30,STK_REG(R30)(r1)
263 ld r31,STK_REG(R31)(r1)
264 addi r1,r1,STACKFRAMESIZE
270 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
272 rlwinm r3,r31,32-12,29,31
274 /* Secondary group ? if yes, get a inverted hash value */
276 andi. r0,r31,_PAGE_SECONDARY
280 /* Calculate proper slot value for ppc_md.hpte_updatepp */
282 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
283 add r3,r0,r3 /* add slot idx */
285 /* Call ppc_md.hpte_updatepp */
287 li r6,MMU_PAGE_4K /* page size */
288 ld r7,STK_PARAM(R9)(r1) /* segment size */
289 ld r8,STK_PARAM(R8)(r1) /* get "local" param */
290 _GLOBAL(htab_call_hpte_updatepp)
291 bl . /* Patched by htab_finish_init() */
293 /* if we failed because typically the HPTE wasn't really here
294 * we try an insertion.
299 /* Clear the BUSY bit and Write out the PTE */
305 /* Bail out clearing reservation */
310 htab_pte_insert_failure:
311 /* Bail out restoring old PTE */
312 ld r6,STK_PARAM(R6)(r1)
318 #else /* CONFIG_PPC_64K_PAGES */
321 /*****************************************************************************
323 * 64K SW & 4K or 64K HW in a 4K segment pages implementation *
325 *****************************************************************************/
327 /* _hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
328 * pte_t *ptep, unsigned long trap, int local, int ssize,
333 * For now, we do NOT implement Admixed pages
335 _GLOBAL(__hash_page_4K)
338 stdu r1,-STACKFRAMESIZE(r1)
339 /* Save all params that we need after a function call */
340 std r6,STK_PARAM(R6)(r1)
341 std r8,STK_PARAM(R8)(r1)
342 std r9,STK_PARAM(R9)(r1)
344 /* Save non-volatile registers.
345 * r31 will hold "old PTE"
348 * r28 is a hash value
349 * r27 is hashtab mask (maybe dynamic patched instead ?)
350 * r26 is the hidx mask
351 * r25 is the index in combo page
353 std r25,STK_REG(R25)(r1)
354 std r26,STK_REG(R26)(r1)
355 std r27,STK_REG(R27)(r1)
356 std r28,STK_REG(R28)(r1)
357 std r29,STK_REG(R29)(r1)
358 std r30,STK_REG(R30)(r1)
359 std r31,STK_REG(R31)(r1)
363 * Check permissions, atomically mark the linux PTE busy
368 /* Check access rights (access & ~(pte_val(*ptep))) */
370 bne- htab_wrong_access
371 /* Check if PTE is busy */
372 andi. r0,r31,_PAGE_BUSY
373 /* If so, just bail out and refault if needed. Someone else
374 * is changing this PTE anyway and might hash it.
377 /* Prepare new PTE value (turn access RW into DIRTY, then
378 * add BUSY and ACCESSED)
380 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
382 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED
383 oris r30,r30,_PAGE_COMBO@h
384 /* Write the linux PTE atomically (setting busy) */
391 * Insert/Update the HPTE in the hash table. At this point,
392 * r4 (access) is re-useable, we use it for the new HPTE flags
395 /* Load the hidx index */
396 rldicl r25,r3,64-12,60
399 cmpdi r9,0 /* check segment size */
401 END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
402 /* Calc vpn and put it in r29 */
403 sldi r29,r5,SID_SHIFT - VPN_SHIFT
405 * clrldi r3,r3,64 - SID_SHIFT --> ea & 0xfffffff
406 * srdi r28,r3,VPN_SHIFT
408 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
411 /* Calculate hash value for primary slot and store it in r28 */
412 rldicl r5,r5,0,25 /* vsid & 0x0000007fffffffff */
413 rldicl r0,r3,64-12,48 /* (ea >> 12) & 0xffff */
417 3: /* Calc vpn and put it in r29 */
418 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
420 * clrldi r3,r3,64 - SID_SHIFT_1T --> ea & 0xffffffffff
421 * srdi r28,r3,VPN_SHIFT
423 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
427 * Calculate hash value for primary slot and
428 * store it in r28 for 1T segment
430 rldic r28,r5,25,25 /* (vsid << 25) & 0x7fffffffff */
431 clrldi r5,r5,40 /* vsid & 0xffffff */
432 rldicl r0,r3,64-12,36 /* (ea >> 12) & 0xfffffff */
434 xor r28,r28,r0 /* hash */
436 /* Convert linux PTE bits into HW equivalents */
438 #ifdef CONFIG_PPC_SUBPAGE_PROT
440 andi. r3,r10,0x1fe /* Get basic set of flags */
441 rlwinm r0,r10,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
443 andi. r3,r30,0x1fe /* Get basic set of flags */
444 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
446 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
447 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
448 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
449 andc r0,r3,r0 /* r0 = pte & ~r0 */
450 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
451 ori r3,r3,HPTE_R_C /* Always add "C" bit for perf. */
453 /* We eventually do the icache sync here (maybe inline that
454 * code rather than call a C function...)
459 bl .hash_page_do_lazy_icache
460 END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
462 /* At this point, r3 contains new PP bits, save them in
463 * place of "access" in the param area (sic)
465 std r3,STK_PARAM(R4)(r1)
467 /* Get htab_hash_mask */
468 ld r4,htab_hash_mask@got(2)
469 ld r27,0(r4) /* htab_hash_mask -> r27 */
471 /* Check if we may already be in the hashtable, in this case, we
472 * go to out-of-line code to try to modify the HPTE. We look for
473 * the bit at (1 >> (index + 32))
475 rldicl. r0,r31,64-12,48
476 li r26,0 /* Default hidx */
480 * Check if the pte was already inserted into the hash table
481 * as a 64k HW page, and invalidate the 64k HPTE if so.
483 andis. r0,r31,_PAGE_COMBO@h
484 beq htab_inval_old_hpte
486 ld r6,STK_PARAM(R6)(r1)
487 ori r26,r6,0x8000 /* Load the hidx mask */
489 addi r5,r25,36 /* Check actual HPTE_SUB bit, this */
490 rldcr. r0,r31,r5,0 /* must match pgtable.h definition */
494 /* real page number in r5, PTE RPN value + index */
495 andis. r0,r31,_PAGE_4K_PFN@h
496 srdi r5,r31,PTE_RPN_SHIFT
497 bne- htab_special_pfn
498 sldi r5,r5,PAGE_SHIFT-HW_PAGE_SHIFT
501 sldi r5,r5,HW_PAGE_SHIFT
503 /* Calculate primary group hash */
505 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
507 /* Call ppc_md.hpte_insert */
508 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
509 mr r4,r29 /* Retrieve vpn */
510 li r7,0 /* !bolted, !secondary */
511 li r8,MMU_PAGE_4K /* page size */
512 ld r9,STK_PARAM(R9)(r1) /* segment size */
513 _GLOBAL(htab_call_hpte_insert1)
514 bl . /* patched by htab_finish_init() */
516 bge htab_pte_insert_ok /* Insertion successful */
517 cmpdi 0,r3,-2 /* Critical failure */
518 beq- htab_pte_insert_failure
520 /* Now try secondary slot */
522 /* real page number in r5, PTE RPN value + index */
523 andis. r0,r31,_PAGE_4K_PFN@h
524 srdi r5,r31,PTE_RPN_SHIFT
526 sldi r5,r5,PAGE_SHIFT-HW_PAGE_SHIFT
528 3: sldi r5,r5,HW_PAGE_SHIFT
530 /* Calculate secondary group hash */
532 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
534 /* Call ppc_md.hpte_insert */
535 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
536 mr r4,r29 /* Retrieve vpn */
537 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
538 li r8,MMU_PAGE_4K /* page size */
539 ld r9,STK_PARAM(R9)(r1) /* segment size */
540 _GLOBAL(htab_call_hpte_insert2)
541 bl . /* patched by htab_finish_init() */
543 bge+ htab_pte_insert_ok /* Insertion successful */
544 cmpdi 0,r3,-2 /* Critical failure */
545 beq- htab_pte_insert_failure
547 /* Both are full, we need to evict something */
549 /* Pick a random group based on TB */
555 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
556 /* Call ppc_md.hpte_remove */
557 _GLOBAL(htab_call_hpte_remove)
558 bl . /* patched by htab_finish_init() */
564 * Call out to C code to invalidate an 64k HW HPTE that is
565 * useless now that the segment has been switched to 4k pages.
569 mr r4,r31 /* PTE.pte */
570 li r5,0 /* PTE.hidx */
571 li r6,MMU_PAGE_64K /* psize */
572 ld r7,STK_PARAM(R9)(r1) /* ssize */
573 ld r8,STK_PARAM(R8)(r1) /* local */
575 /* Clear out _PAGE_HPTE_SUB bits in the new linux PTE */
576 lis r0,_PAGE_HPTE_SUB@h
577 ori r0,r0,_PAGE_HPTE_SUB@l
586 /* Insert slot number & secondary bit in PTE second half,
587 * clear _PAGE_BUSY and set approriate HPTE slot bit
589 ld r6,STK_PARAM(R6)(r1)
594 subfic r5,r25,27 /* Must match bit position in */
595 sld r0,r0,r5 /* pgtable.h */
610 ld r25,STK_REG(R25)(r1)
611 ld r26,STK_REG(R26)(r1)
612 ld r27,STK_REG(R27)(r1)
613 ld r28,STK_REG(R28)(r1)
614 ld r29,STK_REG(R29)(r1)
615 ld r30,STK_REG(R30)(r1)
616 ld r31,STK_REG(R31)(r1)
617 addi r1,r1,STACKFRAMESIZE
623 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
628 /* Secondary group ? if yes, get a inverted hash value */
630 andi. r0,r3,0x8 /* page secondary ? */
633 1: andi. r3,r3,0x7 /* extract idx alone */
635 /* Calculate proper slot value for ppc_md.hpte_updatepp */
637 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
638 add r3,r0,r3 /* add slot idx */
640 /* Call ppc_md.hpte_updatepp */
642 li r6,MMU_PAGE_4K /* page size */
643 ld r7,STK_PARAM(R9)(r1) /* segment size */
644 ld r8,STK_PARAM(R8)(r1) /* get "local" param */
645 _GLOBAL(htab_call_hpte_updatepp)
646 bl . /* patched by htab_finish_init() */
648 /* if we failed because typically the HPTE wasn't really here
649 * we try an insertion.
654 /* Clear the BUSY bit and Write out the PTE */
657 ld r6,STK_PARAM(R6)(r1)
663 /* Bail out clearing reservation */
668 htab_pte_insert_failure:
669 /* Bail out restoring old PTE */
670 ld r6,STK_PARAM(R6)(r1)
675 #endif /* CONFIG_PPC_64K_PAGES */
677 #ifdef CONFIG_PPC_HAS_HASH_64K
679 /*****************************************************************************
681 * 64K SW & 64K HW in a 64K segment pages implementation *
683 *****************************************************************************/
685 _GLOBAL(__hash_page_64K)
688 stdu r1,-STACKFRAMESIZE(r1)
689 /* Save all params that we need after a function call */
690 std r6,STK_PARAM(R6)(r1)
691 std r8,STK_PARAM(R8)(r1)
692 std r9,STK_PARAM(R9)(r1)
694 /* Save non-volatile registers.
695 * r31 will hold "old PTE"
698 * r28 is a hash value
699 * r27 is hashtab mask (maybe dynamic patched instead ?)
701 std r27,STK_REG(R27)(r1)
702 std r28,STK_REG(R28)(r1)
703 std r29,STK_REG(R29)(r1)
704 std r30,STK_REG(R30)(r1)
705 std r31,STK_REG(R31)(r1)
709 * Check permissions, atomically mark the linux PTE busy
714 /* Check access rights (access & ~(pte_val(*ptep))) */
716 bne- ht64_wrong_access
717 /* Check if PTE is busy */
718 andi. r0,r31,_PAGE_BUSY
719 /* If so, just bail out and refault if needed. Someone else
720 * is changing this PTE anyway and might hash it.
724 /* Check if PTE has the cache-inhibit bit set */
725 andi. r0,r31,_PAGE_NO_CACHE
726 /* If so, bail out and refault as a 4k page */
728 END_MMU_FTR_SECTION_IFCLR(MMU_FTR_CI_LARGE_PAGE)
729 /* Prepare new PTE value (turn access RW into DIRTY, then
730 * add BUSY and ACCESSED)
732 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
734 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED
735 /* Write the linux PTE atomically (setting busy) */
742 * Insert/Update the HPTE in the hash table. At this point,
743 * r4 (access) is re-useable, we use it for the new HPTE flags
747 cmpdi r9,0 /* check segment size */
749 END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
750 /* Calc vpn and put it in r29 */
751 sldi r29,r5,SID_SHIFT - VPN_SHIFT
752 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
755 /* Calculate hash value for primary slot and store it in r28 */
756 rldicl r5,r5,0,25 /* vsid & 0x0000007fffffffff */
757 rldicl r0,r3,64-16,52 /* (ea >> 16) & 0xfff */
761 3: /* Calc vpn and put it in r29 */
762 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
763 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
767 * calculate hash value for primary slot and
768 * store it in r28 for 1T segment
770 rldic r28,r5,25,25 /* (vsid << 25) & 0x7fffffffff */
771 clrldi r5,r5,40 /* vsid & 0xffffff */
772 rldicl r0,r3,64-16,40 /* (ea >> 16) & 0xffffff */
774 xor r28,r28,r0 /* hash */
776 /* Convert linux PTE bits into HW equivalents */
777 4: andi. r3,r30,0x1fe /* Get basic set of flags */
778 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
779 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
780 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
781 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
782 andc r0,r30,r0 /* r0 = pte & ~r0 */
783 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
784 ori r3,r3,HPTE_R_C /* Always add "C" bit for perf. */
786 /* We eventually do the icache sync here (maybe inline that
787 * code rather than call a C function...)
792 bl .hash_page_do_lazy_icache
793 END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
795 /* At this point, r3 contains new PP bits, save them in
796 * place of "access" in the param area (sic)
798 std r3,STK_PARAM(R4)(r1)
800 /* Get htab_hash_mask */
801 ld r4,htab_hash_mask@got(2)
802 ld r27,0(r4) /* htab_hash_mask -> r27 */
804 /* Check if we may already be in the hashtable, in this case, we
805 * go to out-of-line code to try to modify the HPTE
807 rldicl. r0,r31,64-12,48
811 /* Clear hpte bits in new pte (we also clear BUSY btw) and
812 * add _PAGE_HPTE_SUB0
814 lis r0,_PAGE_HPTEFLAGS@h
815 ori r0,r0,_PAGE_HPTEFLAGS@l
817 #ifdef CONFIG_PPC_64K_PAGES
818 oris r30,r30,_PAGE_HPTE_SUB0@h
820 ori r30,r30,_PAGE_HASHPTE
822 /* Phyical address in r5 */
823 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
824 sldi r5,r5,PAGE_SHIFT
826 /* Calculate primary group hash */
828 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
830 /* Call ppc_md.hpte_insert */
831 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
832 mr r4,r29 /* Retrieve vpn */
833 li r7,0 /* !bolted, !secondary */
835 ld r9,STK_PARAM(R9)(r1) /* segment size */
836 _GLOBAL(ht64_call_hpte_insert1)
837 bl . /* patched by htab_finish_init() */
839 bge ht64_pte_insert_ok /* Insertion successful */
840 cmpdi 0,r3,-2 /* Critical failure */
841 beq- ht64_pte_insert_failure
843 /* Now try secondary slot */
845 /* Phyical address in r5 */
846 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
847 sldi r5,r5,PAGE_SHIFT
849 /* Calculate secondary 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,HPTE_V_SECONDARY /* !bolted, secondary */
858 ld r9,STK_PARAM(R9)(r1) /* segment size */
859 _GLOBAL(ht64_call_hpte_insert2)
860 bl . /* patched by htab_finish_init() */
862 bge+ ht64_pte_insert_ok /* Insertion successful */
863 cmpdi 0,r3,-2 /* Critical failure */
864 beq- ht64_pte_insert_failure
866 /* Both are full, we need to evict something */
868 /* Pick a random group based on TB */
874 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
875 /* Call ppc_md.hpte_remove */
876 _GLOBAL(ht64_call_hpte_remove)
877 bl . /* patched by htab_finish_init() */
887 /* Insert slot number & secondary bit in PTE */
888 rldimi r30,r3,12,63-15
890 /* Write out the PTE with a normal write
891 * (maybe add eieio may be good still ?)
894 ld r6,STK_PARAM(R6)(r1)
898 ld r27,STK_REG(R27)(r1)
899 ld r28,STK_REG(R28)(r1)
900 ld r29,STK_REG(R29)(r1)
901 ld r30,STK_REG(R30)(r1)
902 ld r31,STK_REG(R31)(r1)
903 addi r1,r1,STACKFRAMESIZE
909 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
911 rlwinm r3,r31,32-12,29,31
913 /* Secondary group ? if yes, get a inverted hash value */
915 andi. r0,r31,_PAGE_F_SECOND
919 /* Calculate proper slot value for ppc_md.hpte_updatepp */
921 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
922 add r3,r0,r3 /* add slot idx */
924 /* Call ppc_md.hpte_updatepp */
927 ld r7,STK_PARAM(R9)(r1) /* segment size */
928 ld r8,STK_PARAM(R8)(r1) /* get "local" param */
929 _GLOBAL(ht64_call_hpte_updatepp)
930 bl . /* patched by htab_finish_init() */
932 /* if we failed because typically the HPTE wasn't really here
933 * we try an insertion.
938 /* Clear the BUSY bit and Write out the PTE */
944 /* Bail out clearing reservation */
949 ht64_pte_insert_failure:
950 /* Bail out restoring old PTE */
951 ld r6,STK_PARAM(R6)(r1)
957 #endif /* CONFIG_PPC_HAS_HASH_64K */
960 /*****************************************************************************
962 * Huge pages implementation is in hugetlbpage.c *
964 *****************************************************************************/