replace redundant code with helper functions
pte_get_hash_gslot() and pte_set_hash_slot()

Signed-off-by: Ram Pai <linux...@us.ibm.com>
---
 arch/powerpc/mm/hash64_4k.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/mm/hash64_4k.c b/arch/powerpc/mm/hash64_4k.c
index 6fa450c..a1eebc1 100644
--- a/arch/powerpc/mm/hash64_4k.c
+++ b/arch/powerpc/mm/hash64_4k.c
@@ -20,6 +20,7 @@ int __hash_page_4K(unsigned long ea, unsigned long access, 
unsigned long vsid,
                   pte_t *ptep, unsigned long trap, unsigned long flags,
                   int ssize, int subpg_prot)
 {
+       real_pte_t rpte;
        unsigned long hpte_group;
        unsigned long rflags, pa;
        unsigned long old_pte, new_pte;
@@ -54,6 +55,7 @@ int __hash_page_4K(unsigned long ea, unsigned long access, 
unsigned long vsid,
         * need to add in 0x1 if it's a read-only user page
         */
        rflags = htab_convert_pte_flags(new_pte);
+       rpte = __real_pte(__pte(old_pte), ptep);
 
        if (cpu_has_feature(CPU_FTR_NOEXECUTE) &&
            !cpu_has_feature(CPU_FTR_COHERENT_ICACHE))
@@ -64,13 +66,10 @@ int __hash_page_4K(unsigned long ea, unsigned long access, 
unsigned long vsid,
                /*
                 * There MIGHT be an HPTE for this pte
                 */
-               hash = hpt_hash(vpn, shift, ssize);
-               if (old_pte & H_PAGE_F_SECOND)
-                       hash = ~hash;
-               slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
-               slot += (old_pte & H_PAGE_F_GIX) >> H_PAGE_F_GIX_SHIFT;
+               unsigned long gslot = pte_get_hash_gslot(vpn, shift,
+                                               ssize, rpte, 0);
 
-               if (mmu_hash_ops.hpte_updatepp(slot, rflags, vpn, MMU_PAGE_4K,
+               if (mmu_hash_ops.hpte_updatepp(gslot, rflags, vpn, MMU_PAGE_4K,
                                               MMU_PAGE_4K, ssize, flags) == -1)
                        old_pte &= ~_PAGE_HPTEFLAGS;
        }
@@ -118,8 +117,7 @@ int __hash_page_4K(unsigned long ea, unsigned long access, 
unsigned long vsid,
                        return -1;
                }
                new_pte = (new_pte & ~_PAGE_HPTEFLAGS) | H_PAGE_HASHPTE;
-               new_pte |= (slot << H_PAGE_F_GIX_SHIFT) &
-                       (H_PAGE_F_SECOND | H_PAGE_F_GIX);
+               new_pte |= pte_set_hash_slot(ptep, rpte, 0, slot);
        }
        *ptep = __pte(new_pte & ~H_PAGE_BUSY);
        return 0;
-- 
1.7.1

Reply via email to